| 1 | package HTML::FormWizard::FileTemplate; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | HTML::FormWizard::FileTemplate - Template para o Modulo | ||
| 6 | HTML::FormWizard | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use HTML::FormWizard::FileTemplate(); | ||
| 11 | use HTML::FormWizard(); | ||
| 12 | |||
| 13 | my $template=HTML::FormWizard::FileTemplate->new( | ||
| 14 | "formxpto", #Template | ||
| 15 | "./", #base_dir | ||
| 16 | "red", #descriptions background | ||
| 17 | "white", #fields background | ||
| 18 | "green" #error messages background | ||
| 19 | ); | ||
| 20 | |||
| 21 | my $form = HTML::FormWizard->new( | ||
| 22 | -title => 'Form Title', | ||
| 23 | -fields => [ ], | ||
| 24 | -template => $template | ||
| 25 | ); #see perldoc HTML::FormWizard for details. | ||
| 26 | |||
| 27 | if (my $data=$form->run()) { | ||
| 28 | #do things with data.! | ||
| 29 | } | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | This is a template used to print forms with HTML header and footers. | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub new { | ||
| 38 | my $self={}; | ||
| 39 | |||
| 40 | bless $self, shift; | ||
| 41 | |||
| 42 | $self->{template}=shift; | ||
| 43 | $self->{base_dir}= shift||"./"; | ||
| 44 | $self->{cor1}=shift||"blue"; | ||
| 45 | $self->{cor2}=shift||"white"; | ||
| 46 | $self->{cor3}=shift||"red"; | ||
| 47 | |||
| 48 | return $self; | ||
| 49 | } | ||
| 50 | |||
| 51 | sub header { | ||
| 52 | my $self=shift; | ||
| 53 | my $fname= $self->{base_dir}.$self->{template}."_header.html"; | ||
| 54 | open FH, $fname; | ||
| 55 | $/=""; | ||
| 56 | my $header=""; | ||
| 57 | while (<FH>) { | ||
| 58 | $header .= $_; | ||
| 59 | } | ||
| 60 | return $header; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub form_header { | ||
| 64 | my $self=shift; | ||
| 65 | my $title=shift; | ||
| 66 | my $url = shift; | ||
| 67 | my $meth=shift; | ||
| 68 | my $encod=shift; | ||
| 69 | my $erro=shift; | ||
| 70 | my $field=shift; | ||
| 71 | my $html = qq( <H1>$title</H1><br>\n); | ||
| 72 | $html .= qq(<font color=$self->{cor3} align=center>$erro</font><br> | ||
| 73 | ) if $erro; | ||
| 74 | $html .= qq(<font color=$self->{cor3} align=center> | ||
| 75 | The value you typed in '$field' is invalid</font><br>) | ||
| 76 | if $field and not $erro; | ||
| 77 | $html .= qq(<form action='$url'); | ||
| 78 | $html .= qq( METHOD=$meth) if $meth; | ||
| 79 | $html .= qq( ENCTYPE='$encod') if $encod; | ||
| 80 | $html .= qq(> | ||
| 81 | <table border=0 cellpadding=5 cellspacing=0 align=center> | ||
| 82 | ); | ||
| 83 | return $html; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub form_field { | ||
| 87 | my $self=shift; | ||
| 88 | my $name=shift; | ||
| 89 | my $field=shift; | ||
| 90 | my $needed=shift; | ||
| 91 | my $errado=shift; | ||
| 92 | $name="<b>$name</b>"; | ||
| 93 | $name="<font color=$self->{cor3}>$name</font>"; | ||
| 94 | return | ||
| 95 | qq(<tr><td bgcolor=$self->{cor1} width=100>$name</td> | ||
| 96 | <td bgcolor=$self->{cor2}>$field</td> | ||
| 97 | </tr> | ||
| 98 | ); | ||
| 99 | } | ||
| 100 | |||
| 101 | sub form_group_init { | ||
| 102 | my $self=shift; | ||
| 103 | my $group = shift; | ||
| 104 | |||
| 105 | return | ||
| 106 | qq(<tr><td colspan=2 bgcolor=$self->{cor1}><strong>$group</strong></td></tr> | ||
| 107 | ); | ||
| 108 | } | ||
| 109 | |||
| 110 | sub form_group_end { | ||
| 111 | my $self=shift; | ||
| 112 | return "<tr><td colspan=2 bgcolor=$self->{cor1} height=3></td></tr>"; | ||
| 113 | } | ||
| 114 | |||
| 115 | sub form_actions { | ||
| 116 | my $self=shift; | ||
| 117 | my $html= | ||
| 118 | qq(<tr><td bgcolor=$self->{cor1} colspan=2 align=right>); | ||
| 119 | $html .= qq($_) for @_; | ||
| 120 | $html .= | ||
| 121 | q(</td></tr> | ||
| 122 | ); | ||
| 123 | return $html; | ||
| 124 | } | ||
| 125 | |||
| 126 | sub form_footer { | ||
| 127 | return | ||
| 128 | q( </table> | ||
| 129 | </form> | ||
| 130 | ); | ||
| 131 | } | ||
| 132 | |||
| 133 | sub footer { | ||
| 134 | my $self=shift; | ||
| 135 | my $fname= $self->{base_dir}.$self->{template}."_footer.html"; | ||
| 136 | open FH,$fname; | ||
| 137 | $/ = ""; | ||
| 138 | my $footer=""; | ||
| 139 | while (<FH>) { | ||
| 140 | $footer .= $_; | ||
| 141 | } | ||
| 142 | return $footer; | ||
| 143 | } | ||
| 144 | |||
| 145 | 1; |