1 package C4::Output; #asummes C4/Output
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
10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
12 # set the version for version checking
16 @EXPORT = qw(&startpage &endpage &mktablehdr &mktableft &mktablerow &mklink
17 &startmenu &endmenu &mkheadr ¢er &endcenter &mkform &mkform2 &bold
18 &gotopage &mkformnotable &mkform3);
19 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
21 # your exported package globals go here,
22 # as well as any optionally exported functions
24 @EXPORT_OK = qw($Var1 %Hashit);
27 # non-exported package globals go here
28 use vars qw(@more $stuff);
30 # initalize package globals, first exported ones
36 # then the others (which are still accessible as $Some::Module::stuff)
40 # all file-scoped lexicals must be created before
41 # the functions below that use them.
44 # Change this value to reflect where you will store your includes
47 open (KC, "/etc/koha.conf");
51 if (/(.*)\s*=\s*(.*)/) {
54 # Clean up white space at beginning and end
59 $configfile{$variable}=$value;
62 my $path=$configfile{'includes'};
63 ($path) || ($path="/usr/local/www/hdl/htdocs/includes");
66 # here's a file-private function as a closure,
67 # callable as &$priv_func; it cannot be prototyped.
72 # make all your functions, whether exported or not;
80 #print "<br>goto target = $target<br>";
81 my $string = "<META HTTP-EQUIV=Refresh CONTENT=\"0;URL=http:$target\">";
87 # edit the paths in here
89 if ($type eq 'issue') {
90 open (FILE,"$path/issues-top.inc") || die;
91 } elsif ($type eq 'opac') {
92 open (FILE,"$path/opac-top.inc") || die;
93 } elsif ($type eq 'member') {
94 open (FILE,"$path/members-top.inc") || die;
95 } elsif ($type eq 'acquisitions'){
96 open (FILE,"$path/acquisitions-top.inc")|| die;
97 } elsif ($type eq 'report'){
98 open (FILE,"$path/reports-top.inc") || die;
99 } elsif ($type eq 'circulation') {
100 open (FILE,"$path/circulation-top.inc") || die;
102 open (FILE,"$path/cat-top.inc") || die;
107 # $string[$count]="<BLOCKQUOTE>";
114 if ($type eq 'issue'){
115 open (FILE,"$path/issues-bottom.inc") || die;
116 } elsif ($type eq 'opac') {
117 open (FILE,"$path/opac-bottom.inc") || die;
118 } elsif ($type eq 'member') {
119 open (FILE,"$path/members-bottom.inc") || die;
120 } elsif ($type eq 'acquisitions') {
121 open (FILE,"$path/acquisitions-bottom.inc") || die;
122 } elsif ($type eq 'report') {
123 open (FILE,"$path/reports-bottom.inc") || die;
124 } elsif ($type eq 'circulation') {
125 open (FILE,"$path/circulation-bottom.inc") || die;
127 open (FILE,"$path/cat-bottom.inc") || die;
135 return("<table border=0 cellspacing=0 cellpadding=5>\n");
140 #the last item in data may be a backgroundimage
143 # should this be a foreach (1..$cols) loop?
145 my ($cols,$colour,@data)=@_;
147 my $string="<tr valign=top bgcolor=$colour>";
149 if (defined $data[$cols]) { # if there is a background image
150 $string.="<td background=\"$data[$cols]\">";
151 } else { # if there's no background image
154 if ($data[$i] eq "") {
155 $string.=" </td>";
157 $string.="$data[$i]</td>";
161 $string=$string."</tr>\n";
166 return("</table>\n");
170 my ($action,%inputs)=@_;
171 my $string="<form action=$action method=post>\n";
172 $string=$string.mktablehdr();
174 my @keys=sort keys %inputs;
178 while ( $i2<$count) {
179 my $value=$inputs{$keys[$i2]};
180 my @data=split('\t',$value);
181 #my $posn = shift(@data);
182 if ($data[0] eq 'hidden'){
183 $string=$string."<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
186 if ($data[0] eq 'radio') {
187 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
188 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
190 if ($data[0] eq 'text') {
191 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\">";
193 if ($data[0] eq 'textarea') {
194 $text="<textarea name=$keys[$i2] wrap=physical cols=40 rows=4>$data[1]</textarea>";
196 if ($data[0] eq 'select') {
197 $text="<select name=$keys[$i2]>";
199 while ($data[$i] ne "") {
200 my $val = $data[$i+1];
201 $text = $text."<option value=$data[$i]>$val";
204 $text=$text."</select>";
206 $string=$string.mktablerow(2,'white',$keys[$i2],$text);
207 #@order[$posn] =mktablerow(2,'white',$keys[$i2],$text);
211 #$string=$string.join("\n",@order);
212 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
213 $string=$string.mktableft;
214 $string=$string."</form>";
218 my ($action,%inputs)=@_;
219 my $string="<form action=$action method=post>\n";
220 $string=$string.mktablehdr();
222 my @keys=sort keys %inputs;
226 while ( $i2<$count) {
227 my $value=$inputs{$keys[$i2]};
228 my @data=split('\t',$value);
230 if ($data[0] eq 'hidden'){
231 $order[$posn]="<input type=hidden name=$keys[$i2] value=\"$data[1]\">\n";
234 if ($data[0] eq 'radio') {
235 $text="<input type=radio name=$keys[$i2] value=$data[1]>$data[1]
236 <input type=radio name=$keys[$i2] value=$data[2]>$data[2]";
238 if ($data[0] eq 'text') {
239 $text="<input type=$data[0] name=$keys[$i2] value=\"$data[1]\" size=40>";
241 if ($data[0] eq 'textarea') {
242 $text="<textarea name=$keys[$i2] cols=40 rows=4>$data[1]</textarea>";
244 if ($data[0] eq 'select') {
245 $text="<select name=$keys[$i2]>";
247 while ($data[$i] ne "") {
248 my $val = $data[$i+1];
249 $text = $text."<option value=$data[$i]>$val";
252 $text=$text."</select>";
254 # $string=$string.mktablerow(2,'white',$keys[$i2],$text);
255 $order[$posn]=mktablerow(2,'white',$keys[$i2],$text);
259 my $temp=join("\n",@order);
260 $string=$string.$temp;
261 $string=$string.mktablerow(1,'white','<input type=submit>');
262 $string=$string.mktableft;
263 $string=$string."</form>";
267 my ($action,@inputs)=@_;
268 my $string="<form action=$action method=post>\n";
269 foreach my $input (@inputs){
270 if ($$input[0] eq 'textarea') {
272 "<textarea name=$$input[1] wrap=physical cols=40 rows=4>";
274 "$$input[2]</textarea>";
277 "<input type=$$input[0] name=$$input[1] value=\"$$input[2]\">";
278 if ($$input[0] eq 'radio') {
285 $string=$string."</form>";
290 # no POD and no tests yet. Once tests are written,
291 # this function can be cleaned up with the following steps:
292 # turn the while loop into a foreach loop
293 # pull the nested if,elsif structure back up to the main level
294 # pull the code for the different kinds of inputs into separate
296 my ($action,%inputs)=@_;
297 my $string="<form action=$action method=post>\n";
298 $string=$string.mktablehdr();
301 while ( my ($key, $value) = each %inputs) {
302 my @data=split('\t',$value);
303 my $posn = shift(@data);
304 my $reqd = shift(@data);
305 my $ltext = shift(@data);
306 if ($data[0] eq 'hidden'){
307 $string=$string."<input type=hidden name=$key value=\"$data[1]\">\n";
310 if ($data[0] eq 'radio') {
311 $text="<input type=radio name=$key value=$data[1]>$data[1]
312 <input type=radio name=$key value=$data[2]>$data[2]";
313 } elsif ($data[0] eq 'text') {
318 $text="<input type=$data[0] name=$key size=$size value=\"$data[2]\">";
319 } elsif ($data[0] eq 'textarea') {
320 my @size=split("x",$data[1]);
321 if ($data[1] eq "") {
325 $text="<textarea name=$key wrap=physical cols=$size[0] rows=$size[1]>$data[2]</textarea>";
326 } elsif ($data[0] eq 'select') {
327 $text="<select name=$key>";
330 while ($data[$i] ne "") {
331 my $val = $data[$i+1];
332 $text = $text."<option value=\"$data[$i]\"";
333 if ($data[$i] eq $sel) {
334 $text = $text." selected";
336 $text = $text.">$val";
339 $text=$text."</select>";
342 $ltext = $ltext." (Req)";
344 $order[$posn] =mktablerow(2,'white',$ltext,$text);
347 $string=$string.join("\n",@order);
348 $string=$string.mktablerow(2,'white','<input type=submit>','<input type=reset>');
349 $string=$string.mktableft;
350 $string=$string."</form>";
357 &endpage does not expect any arguments, it returns the string:
364 return("</body></html>\n");
371 &mklink expects two arguments, the url to link to and the text of the link.
372 It returns this string:
373 <a href="$url">$text</a>
374 where $url is the first argument and $text is the second.
381 my $string="<a href=\"$url\">$text</a>";
389 &mkeadr expects two strings, a type and the text to use in the header.
394 =item 1 ends with <br>
396 =item 2 no special ending tag
398 =item 3 ends with <p>
402 Other than this, the return value is the same:
403 <FONT SIZE=6><em>$text</em></FONT>$string
404 Where $test is the text passed in and $string is the tag generated from
412 # would it be better to make this more generic by accepting an optional
413 # argument with a closing tag instead of a numeric type?
419 } elsif ($type eq '3') {
424 return ("<FONT SIZE=6><em>$text</em></FONT>$string");
429 =head2 ¢er and &endcenter
431 ¢er and &endcenter take no arguments and return html tags <CENTER> and
432 </CENTER> respectivley.
437 return ("<CENTER>\n");
441 return ("</CENTER>\n");
448 &bold requires that a single string be passed in by the caller. &bold
449 will return "<b>$text</b>" where $text is the string passed in.
455 return("<b>$text</b>");
458 END { } # module clean-up code here (global destructor)