3 #package to deal with marking up output
4 #You will need to edit parts of this pm
5 #set the value of path to be where your html lives
13 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
15 # set the version for version checking
19 @EXPORT = qw(&startpage &endpage
20 &mktablehdr &mktableft &mktablerow &mklink
21 &startmenu &endmenu &mkheadr
23 &mkform &mkform2 &bold
24 &gotopage &mkformnotable &mkform3
25 &getkeytableselectoptions
27 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
29 # your exported package globals go here,
30 # as well as any optionally exported functions
32 @EXPORT_OK = qw($Var1 %Hashit);
35 # non-exported package globals go here
36 use vars qw(@more $stuff);
38 # initalize package globals, first exported ones
44 # then the others (which are still accessible as $Some::Module::stuff)
48 # all file-scoped lexicals must be created before
49 # the functions below that use them.
52 # Change this value to reflect where you will store your includes
55 open (KC, "/etc/koha.conf");
59 if (/(.*)\s*=\s*(.*)/) {
63 $variable =~ s/^\s*//g;
64 $variable =~ s/\s*$//g;
67 $configfile{$variable}=$value;
72 my $path=$configfile{'includes'};
73 ($path) || ($path="/usr/local/www/hdl/htdocs/includes");
75 # make all your functions, whether exported or not;
78 my ($includes, $base) = @_;
81 opendir (D, "$includes/templates");
82 my @dirlist=readdir D;
85 #(next) unless (/\.tmpl$/);
86 (next) unless (-e "$includes/templates/$_/$base");
89 my $sth=$dbh->prepare("select value from systempreferences where
90 variable='template'");
92 my ($preftemplate) = $sth->fetchrow;
95 if ($templates->{$preftemplate}) {
109 #print "<br>goto target = $target<br>";
110 my $string = "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=http:$target\">";
116 # edit the paths in here
118 if ($type eq 'issue') {
119 open (FILE,"$path/issues-top.inc") || die;
120 } elsif ($type eq 'opac') {
121 open (FILE,"$path/opac-top.inc") || die;
122 } elsif ($type eq 'member') {
123 open (FILE,"$path/members-top.inc") || die;
124 } elsif ($type eq 'acquisitions'){
125 open (FILE,"$path/acquisitions-top.inc") || die;
126 } elsif ($type eq 'report'){
127 open (FILE,"$path/reports-top.inc") || die;
128 } elsif ($type eq 'circulation') {
129 open (FILE,"$path/circulation-top.inc") || die;
131 open (FILE,"$path/cat-top.inc") || die;
136 # $string[$count]="<BLOCKQUOTE>";
143 if ( ! defined $type ) { $type=''; }
144 if ($type eq 'issue') {
145 open (FILE,"$path/issues-bottom.inc") || die;
146 } elsif ($type eq 'opac') {
147 open (FILE,"$path/opac-bottom.inc") || die;
148 } elsif ($type eq 'member') {
149 open (FILE,"$path/members-bottom.inc") || die;
150 } elsif ($type eq 'acquisitions') {
151 open (FILE,"$path/acquisitions-bottom.inc") || die;
152 } elsif ($type eq 'report') {
153 open (FILE,"$path/reports-bottom.inc") || die;
154 } elsif ($type eq 'circulation') {
155 open (FILE,"$path/circulation-bottom.inc") || die;
157 open (FILE,"$path/cat-bottom.inc") || die;
165 return("<table border=0 cellspacing=0 cellpadding=5>\n");
170 #the last item in data may be a backgroundimage
173 # should this be a foreach (1..$cols) loop?
175 my ($cols,$colour,@data)=@_;
177 my $string="<tr valign=top bgcolor=$colour>";
179 if (defined $data[$cols]) { # if there is a background image
180 $string.="<td background=\"$data[$cols]\">";
181 } else { # if there's no background image
184 if ($data[$i] eq "") {
185 $string.=" </td>";
187 $string.="$data[$i]</td>";
191 $string=$string."</tr>\n";
196 return("</table>\n");
200 my ($action,%inputs)=@_;
201 my $string="<form action=$action method=post>\n";
202 $string=$string.mktablehdr();
204 my @keys=sort keys %inputs;
208 while ( $i2<$count) {
209 my $value=$inputs{$keys[$i2]};
210 my @data=split('\t',$value);
211 #my $posn = shift(@data);
212 if ($data[0] eq 'hidden'){
213 $string=$string."<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
216 if ($data[0] eq 'radio') {
217 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
218 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
220 if ($data[0] eq 'text') {
221 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\">";
223 if ($data[0] eq 'textarea') {
224 $text="<textarea name=$keys[$i2] wrap=physical cols=40 rows=4>$data[1]</textarea>";
226 if ($data[0] eq 'select') {
227 $text="<select name=$keys[$i2]>";
229 while ($data[$i] ne "") {
230 my $val = $data[$i+1];
231 $text = $text."<option value=$data[$i]>$val";
234 $text=$text."</select>";
236 $string=$string.mktablerow(2,'white',$keys[$i2],$text);
237 #@order[$posn] =mktablerow(2,'white',$keys[$i2],$text);
241 #$string=$string.join("\n",@order);
242 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
243 $string=$string.mktableft;
244 $string=$string."</form>";
248 my ($action, %inputs) = @_;
249 my $string = "<form action=\"$action\" method=\"post\">\n";
250 $string .= mktablehdr();
252 my @keys = sort(keys(%inputs));
256 while ($i2 < $count) {
257 my $value=$inputs{$keys[$i2]};
258 my @data=split('\t',$value);
260 if ($data[0] eq 'hidden'){
261 $order[$posn]="<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
264 if ($data[0] eq 'radio') {
265 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
266 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
268 if ($data[0] eq 'text') {
269 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\" size=40>";
271 if ($data[0] eq 'textarea') {
272 $text="<textarea name=$keys[$i2] cols=40 rows=4>$data[1]</textarea>";
274 if ($data[0] eq 'select') {
275 $text="<select name=$keys[$i2]>";
277 while ($data[$i] ne "") {
278 my $val = $data[$i+1];
279 $text = $text."<option value=$data[$i]>$val";
282 $text=$text."</select>";
284 # $string=$string.mktablerow(2,'white',$keys[$i2],$text);
285 $order[$posn]=mktablerow(2,'white',$keys[$i2],$text);
289 my $temp=join("\n",@order);
290 $string=$string.$temp;
291 $string=$string.mktablerow(1,'white','<input type=submit>');
292 $string=$string.mktableft;
293 $string=$string."</form>";
297 my ($action,@inputs)=@_;
298 my $string="<form action=$action method=post>\n";
300 for (my $i=0; $i<$count; $i++){
301 if ($inputs[$i][0] eq 'hidden'){
302 $string=$string."<input type=hidden name=$inputs[$i][1] value=\"$inputs[$i][2]\">\n";
304 if ($inputs[$i][0] eq 'radio') {
305 $string.="<input type=radio name=$inputs[1] value=$inputs[$i][2]>$inputs[$i][2]";
307 if ($inputs[$i][0] eq 'text') {
308 $string.="<input type=$inputs[$i][0] name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
310 if ($inputs[$i][0] eq 'textarea') {
311 $string.="<textarea name=$inputs[$i][1] wrap=physical cols=40 rows=4>$inputs[$i][2]</textarea>";
313 if ($inputs[$i][0] eq 'reset'){
314 $string.="<input type=reset name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
316 if ($inputs[$i][0] eq 'submit'){
317 $string.="<input type=submit name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
320 $string=$string."</form>";
325 # no POD and no tests yet. Once tests are written,
326 # this function can be cleaned up with the following steps:
327 # turn the while loop into a foreach loop
328 # pull the nested if,elsif structure back up to the main level
329 # pull the code for the different kinds of inputs into separate
331 my ($action,%inputs)=@_;
332 my $string="<form action=$action method=post>\n";
333 $string=$string.mktablehdr();
336 while ( my ($key, $value) = each %inputs) {
337 my @data=split('\t',$value);
338 my $posn = shift(@data);
339 my $reqd = shift(@data);
340 my $ltext = shift(@data);
341 if ($data[0] eq 'hidden'){
342 $string=$string."<input type=hidden name=$key value=\"$data[1]\">\n";
345 if ($data[0] eq 'radio') {
346 $text="<input type=radio name=$key value=$data[1]>$data[1]
347 <input type=radio name=$key value=$data[2]>$data[2]";
348 } elsif ($data[0] eq 'text') {
353 $text="<input type=$data[0] name=$key size=$size value=\"$data[2]\">";
354 } elsif ($data[0] eq 'textarea') {
355 my @size=split("x",$data[1]);
356 if ($data[1] eq "") {
360 $text="<textarea name=$key wrap=physical cols=$size[0] rows=$size[1]>$data[2]</textarea>";
361 } elsif ($data[0] eq 'select') {
362 $text="<select name=$key>";
365 while ($data[$i] ne "") {
366 my $val = $data[$i+1];
367 $text = $text."<option value=\"$data[$i]\"";
368 if ($data[$i] eq $sel) {
369 $text = $text." selected";
371 $text = $text.">$val";
374 $text=$text."</select>";
377 $ltext = $ltext." (Req)";
379 $order[$posn] =mktablerow(2,'white',$ltext,$text);
382 $string=$string.join("\n",@order);
383 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
384 $string=$string.mktableft;
385 $string=$string."</form>";
392 &endpage does not expect any arguments, it returns the string:
398 return("</body></html>\n");
405 &mklink expects two arguments, the url to link to and the text of the link.
406 It returns this string:
407 <a href="$url">$text</a>
408 where $url is the first argument and $text is the second.
414 my $string="<a href=\"$url\">$text</a>";
422 &mkeadr expects two strings, a type and the text to use in the header.
427 =item 1 ends with <br>
429 =item 2 no special ending tag
431 =item 3 ends with <p>
435 Other than this, the return value is the same:
436 <FONT SIZE=6><em>$text</em></FONT>$string
437 Where $test is the text passed in and $string is the tag generated from
444 # would it be better to make this more generic by accepting an optional
445 # argument with a closing tag instead of a numeric type?
450 $string="<FONT SIZE=6><em>$text</em></FONT><br>";
453 $string="<FONT SIZE=6><em>$text</em></FONT><br>";
456 $string="<FONT SIZE=6><em>$text</em></FONT><p>";
463 =head2 ¢er and &endcenter
465 ¢er and &endcenter take no arguments and return html tags <CENTER> and
466 </CENTER> respectivley.
471 return ("<CENTER>\n");
475 return ("</CENTER>\n");
482 &bold requires that a single string be passed in by the caller. &bold
483 will return "<b>$text</b>" where $text is the string passed in.
489 return("<b>$text</b>");
492 #---------------------------------------------
493 # Create an HTML option list for a <SELECT> form tag by using
494 # values from a DB file
495 sub getkeytableselectoptions {
500 $tablename, # name of table containing list of choices
501 $keyfieldname, # column name of code to use in option list
502 $descfieldname, # column name of descriptive field
503 $showkey, # flag to show key in description
504 $default, # optional default key
506 my $selectclause; # return value
510 $key, $desc, $orderfieldname,
514 requireDBI($dbh,"getkeytableselectoptions");
517 $orderfieldname=$keyfieldname;
519 $orderfieldname=$descfieldname;
521 $query= "select $keyfieldname,$descfieldname
523 order by $orderfieldname ";
524 print "<PRE>Query=$query </PRE>\n" if $debug;
525 $sth=$dbh->prepare($query);
527 while ( ($key, $desc) = $sth->fetchrow) {
528 if ($showkey || ! $desc ) { $desc="$key - $desc"; }
529 $selectclause.="<option";
530 if (defined $default && $default eq $key) {
531 $selectclause.=" selected";
533 $selectclause.=" value='$key'>$desc\n";
534 print "<PRE>Sel=$selectclause </PRE>\n" if $debug;
536 return $selectclause;
537 } # sub getkeytableselectoptions
539 #---------------------------------
541 END { } # module clean-up code here (global destructor)