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
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
14 # set the version for version checking
18 @EXPORT = qw(&startpage &endpage
19 &mktablehdr &mktableft &mktablerow &mklink
20 &startmenu &endmenu &mkheadr
22 &mkform &mkform2 &bold
23 &gotopage &mkformnotable &mkform3
24 &getkeytableselectoptions
26 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
28 # your exported package globals go here,
29 # as well as any optionally exported functions
31 @EXPORT_OK = qw($Var1 %Hashit);
34 # non-exported package globals go here
35 use vars qw(@more $stuff);
37 # initalize package globals, first exported ones
43 # then the others (which are still accessible as $Some::Module::stuff)
47 # all file-scoped lexicals must be created before
48 # the functions below that use them.
51 # Change this value to reflect where you will store your includes
54 open (KC, "/etc/koha.conf");
58 if (/(.*)\s*=\s*(.*)/) {
62 $variable =~ s/^\s*//g;
63 $variable =~ s/\s*$//g;
66 $configfile{$variable}=$value;
71 my $path=$configfile{'includes'};
72 ($path) || ($path="/usr/local/www/hdl/htdocs/includes");
74 # make all your functions, whether exported or not;
77 my ($includes, $base) = @_;
80 opendir (D, "$includes/templates");
81 my @dirlist=readdir D;
84 #(next) unless (/\.tmpl$/);
85 (next) unless (-e "$includes/templates/$_/$base");
88 my $sth=$dbh->prepare("select value from systempreferences where
89 variable='template'");
91 my ($preftemplate) = $sth->fetchrow;
94 if ($templates->{$preftemplate}) {
107 my ($target) = shift;
108 #print "<br>goto target = $target<br>";
109 my $string = "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=http:$target\">";
115 # edit the paths in here
117 if ($type eq 'issue') {
118 open (FILE,"$path/issues-top.inc") || die;
119 } elsif ($type eq 'opac') {
120 open (FILE,"$path/opac-top.inc") || die;
121 } elsif ($type eq 'member') {
122 open (FILE,"$path/members-top.inc") || die;
123 } elsif ($type eq 'acquisitions'){
124 open (FILE,"$path/acquisitions-top.inc") || die;
125 } elsif ($type eq 'report'){
126 open (FILE,"$path/reports-top.inc") || die;
127 } elsif ($type eq 'circulation') {
128 open (FILE,"$path/circulation-top.inc") || die;
130 open (FILE,"$path/cat-top.inc") || die;
135 # $string[$count]="<BLOCKQUOTE>";
142 if ( ! defined $type ) { $type=''; }
143 if ($type eq 'issue') {
144 open (FILE,"$path/issues-bottom.inc") || die;
145 } elsif ($type eq 'opac') {
146 open (FILE,"$path/opac-bottom.inc") || die;
147 } elsif ($type eq 'member') {
148 open (FILE,"$path/members-bottom.inc") || die;
149 } elsif ($type eq 'acquisitions') {
150 open (FILE,"$path/acquisitions-bottom.inc") || die;
151 } elsif ($type eq 'report') {
152 open (FILE,"$path/reports-bottom.inc") || die;
153 } elsif ($type eq 'circulation') {
154 open (FILE,"$path/circulation-bottom.inc") || die;
156 open (FILE,"$path/cat-bottom.inc") || die;
164 return("<table border=0 cellspacing=0 cellpadding=5>\n");
169 #the last item in data may be a backgroundimage
172 # should this be a foreach (1..$cols) loop?
174 my ($cols,$colour,@data)=@_;
176 my $string="<tr valign=top bgcolor=$colour>";
178 if (defined $data[$cols]) { # if there is a background image
179 $string.="<td background=\"$data[$cols]\">";
180 } else { # if there's no background image
183 if ($data[$i] eq "") {
184 $string.=" </td>";
186 $string.="$data[$i]</td>";
190 $string=$string."</tr>\n";
195 return("</table>\n");
199 my ($action,%inputs)=@_;
200 my $string="<form action=$action method=post>\n";
201 $string=$string.mktablehdr();
203 my @keys=sort keys %inputs;
207 while ( $i2<$count) {
208 my $value=$inputs{$keys[$i2]};
209 my @data=split('\t',$value);
210 #my $posn = shift(@data);
211 if ($data[0] eq 'hidden'){
212 $string=$string."<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
215 if ($data[0] eq 'radio') {
216 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
217 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
219 if ($data[0] eq 'text') {
220 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\">";
222 if ($data[0] eq 'textarea') {
223 $text="<textarea name=$keys[$i2] wrap=physical cols=40 rows=4>$data[1]</textarea>";
225 if ($data[0] eq 'select') {
226 $text="<select name=$keys[$i2]>";
228 while ($data[$i] ne "") {
229 my $val = $data[$i+1];
230 $text = $text."<option value=$data[$i]>$val";
233 $text=$text."</select>";
235 $string=$string.mktablerow(2,'white',$keys[$i2],$text);
236 #@order[$posn] =mktablerow(2,'white',$keys[$i2],$text);
240 #$string=$string.join("\n",@order);
241 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
242 $string=$string.mktableft;
243 $string=$string."</form>";
247 my ($action, %inputs) = @_;
248 my $string = "<form action=\"$action\" method=\"post\">\n";
249 $string .= mktablehdr();
251 my @keys = sort(keys(%inputs));
255 while ($i2 < $count) {
256 my $value=$inputs{$keys[$i2]};
257 my @data=split('\t',$value);
259 if ($data[0] eq 'hidden'){
260 $order[$posn]="<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
263 if ($data[0] eq 'radio') {
264 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
265 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
267 if ($data[0] eq 'text') {
268 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\" size=40>";
270 if ($data[0] eq 'textarea') {
271 $text="<textarea name=$keys[$i2] cols=40 rows=4>$data[1]</textarea>";
273 if ($data[0] eq 'select') {
274 $text="<select name=$keys[$i2]>";
276 while ($data[$i] ne "") {
277 my $val = $data[$i+1];
278 $text = $text."<option value=$data[$i]>$val";
281 $text=$text."</select>";
283 # $string=$string.mktablerow(2,'white',$keys[$i2],$text);
284 $order[$posn]=mktablerow(2,'white',$keys[$i2],$text);
288 my $temp=join("\n",@order);
289 $string=$string.$temp;
290 $string=$string.mktablerow(1,'white','<input type=submit>');
291 $string=$string.mktableft;
292 $string=$string."</form>";
296 my ($action,@inputs)=@_;
297 my $string="<form action=$action method=post>\n";
299 for (my $i=0; $i<$count; $i++){
300 if ($inputs[$i][0] eq 'hidden'){
301 $string=$string."<input type=hidden name=$inputs[$i][1] value=\"$inputs[$i][2]\">\n";
303 if ($inputs[$i][0] eq 'radio') {
304 $string.="<input type=radio name=$inputs[1] value=$inputs[$i][2]>$inputs[$i][2]";
306 if ($inputs[$i][0] eq 'text') {
307 $string.="<input type=$inputs[$i][0] name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
309 if ($inputs[$i][0] eq 'textarea') {
310 $string.="<textarea name=$inputs[$i][1] wrap=physical cols=40 rows=4>$inputs[$i][2]</textarea>";
312 if ($inputs[$i][0] eq 'reset'){
313 $string.="<input type=reset name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
315 if ($inputs[$i][0] eq 'submit'){
316 $string.="<input type=submit name=$inputs[$i][1] value=\"$inputs[$i][2]\">";
319 $string=$string."</form>";
324 # no POD and no tests yet. Once tests are written,
325 # this function can be cleaned up with the following steps:
326 # turn the while loop into a foreach loop
327 # pull the nested if,elsif structure back up to the main level
328 # pull the code for the different kinds of inputs into separate
330 my ($action,%inputs)=@_;
331 my $string="<form action=$action method=post>\n";
332 $string=$string.mktablehdr();
335 while ( my ($key, $value) = each %inputs) {
336 my @data=split('\t',$value);
337 my $posn = shift(@data);
338 my $reqd = shift(@data);
339 my $ltext = shift(@data);
340 if ($data[0] eq 'hidden'){
341 $string=$string."<input type=hidden name=$key value=\"$data[1]\">\n";
344 if ($data[0] eq 'radio') {
345 $text="<input type=radio name=$key value=$data[1]>$data[1]
346 <input type=radio name=$key value=$data[2]>$data[2]";
347 } elsif ($data[0] eq 'text') {
352 $text="<input type=$data[0] name=$key size=$size value=\"$data[2]\">";
353 } elsif ($data[0] eq 'textarea') {
354 my @size=split("x",$data[1]);
355 if ($data[1] eq "") {
359 $text="<textarea name=$key wrap=physical cols=$size[0] rows=$size[1]>$data[2]</textarea>";
360 } elsif ($data[0] eq 'select') {
361 $text="<select name=$key>";
364 while ($data[$i] ne "") {
365 my $val = $data[$i+1];
366 $text = $text."<option value=\"$data[$i]\"";
367 if ($data[$i] eq $sel) {
368 $text = $text." selected";
370 $text = $text.">$val";
373 $text=$text."</select>";
376 $ltext = $ltext." (Req)";
378 $order[$posn] =mktablerow(2,'white',$ltext,$text);
381 $string=$string.join("\n",@order);
382 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
383 $string=$string.mktableft;
384 $string=$string."</form>";
391 &endpage does not expect any arguments, it returns the string:
397 return("</body></html>\n");
404 &mklink expects two arguments, the url to link to and the text of the link.
405 It returns this string:
406 <a href="$url">$text</a>
407 where $url is the first argument and $text is the second.
413 my $string="<a href=\"$url\">$text</a>";
421 &mkeadr expects two strings, a type and the text to use in the header.
426 =item 1 ends with <br>
428 =item 2 no special ending tag
430 =item 3 ends with <p>
434 Other than this, the return value is the same:
435 <FONT SIZE=6><em>$text</em></FONT>$string
436 Where $test is the text passed in and $string is the tag generated from
443 # would it be better to make this more generic by accepting an optional
444 # argument with a closing tag instead of a numeric type?
449 $string="<FONT SIZE=6><em>$text</em></FONT><br>";
452 $string="<FONT SIZE=6><em>$text</em></FONT><br>";
455 $string="<FONT SIZE=6><em>$text</em></FONT><p>";
462 =head2 ¢er and &endcenter
464 ¢er and &endcenter take no arguments and return html tags <CENTER> and
465 </CENTER> respectivley.
470 return ("<CENTER>\n");
474 return ("</CENTER>\n");
481 &bold requires that a single string be passed in by the caller. &bold
482 will return "<b>$text</b>" where $text is the string passed in.
488 return("<b>$text</b>");
491 #---------------------------------------------
492 # Create an HTML option list for a <SELECT> form tag by using
493 # values from a DB file
494 sub getkeytableselectoptions {
499 $tablename, # name of table containing list of choices
500 $keyfieldname, # column name of code to use in option list
501 $descfieldname, # column name of descriptive field
502 $showkey, # flag to show key in description
503 $default, # optional default key
505 my $selectclause; # return value
509 $key, $desc, $orderfieldname,
513 requireDBI($dbh,"getkeytableselectoptions");
516 $orderfieldname=$keyfieldname;
518 $orderfieldname=$descfieldname;
520 $query= "select $keyfieldname,$descfieldname
522 order by $orderfieldname ";
523 print "<PRE>Query=$query </PRE>\n" if $debug;
524 $sth=$dbh->prepare($query);
526 while ( ($key, $desc) = $sth->fetchrow) {
527 if ($showkey || ! $desc ) { $desc="$key - $desc"; }
528 $selectclause.="<option";
529 if (defined $default && $default eq $key) {
530 $selectclause.=" selected";
532 $selectclause.=" value='$key'>$desc\n";
533 print "<PRE>Sel=$selectclause </PRE>\n" if $debug;
535 return $selectclause;
536 } # sub getkeytableselectoptions
538 #---------------------------------
540 END { } # module clean-up code here (global destructor)