Fixed typo in the page title
[www.energie.vellum.cz.git] / common.php
1 <?php // $Id$
2
3         error_reporting(E_ALL);
4         setlocale(LC_ALL,"cs_CZ.iso-8859-2");
5         fixampvars();
6
7         include("config.php");
8
9         // $viewcvs prepared by "config.php"
10         if ($viewcvs==$HTTP_SERVER_VARS["SCRIPT_NAME"])
11                 unset($viewcvs);
12         $cvs_id_split=split(" ",$cvs_id);
13         if (count($cvs_id_split)==8) {
14                 $cvs_id_split[1]="<a href=\"$viewcvs\">".$cvs_id_split[1]."</a>";
15                 $cvs_id_split[5]="<a href=\"mailto:".$cvs_id_split[5]."@$cvs_mailhost\">".$cvs_id_split[5]."</a>";
16                 }
17         $cvs_id_html=join(" ",$cvs_id_split);
18
19         $have_js=(isset($HTTP_GET_VARS["have_js"]) || isset($HTTP_POST_VARS["have_js"])
20                         ? "?have_js=1" : "");
21         if (isset($detect_js) && !$have_js)
22                 $head.='<script type="text/javascript" src="have_js.js"></script>'."\n";
23
24         $user_agent=(!isset($HTTP_SERVER_VARS["HTTP_USER_AGENT"]) ? "" : $HTTP_SERVER_VARS["HTTP_USER_AGENT"]);
25         if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a))
26                 $msie_major=$msie_major_a[1];
27         else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
28                 $mozilla_major=$mozilla_major_a[1];
29
30         $have_style=!isset($mozilla_major) || $mozilla_major!=4;
31         $have_css=true; // doesn't hurt anybody AFAIK
32
33 function fixampvars()
34 {
35         $ars=array("HTTP_GET_VARS","HTTP_POST_VARS");
36         foreach ($ars as $ar) {
37                 foreach ($GLOBALS[$ar] as $key=>$val) {
38                         if (substr($key,0,4)!="amp;")
39                                 continue;
40                         unset($GLOBALS[$ar][$key]);
41                         $GLOBALS[$ar][substr($key,4)]=$val;
42                         }
43                 }
44 }
45
46 function addpercents($url)
47 {
48         $r=$c="";
49         foreach(preg_split('//', $url, -1, PREG_SPLIT_NO_EMPTY) as $c)
50                 if (ereg("[a-zA-Z0-9]",$c))
51                         $r.=$c;
52                 else
53                         $r.=sprintf("%%%02X",ord($c));
54         return($r);
55 }
56
57 function fatal($msg="UNKNOWN")
58 {
59         global $admin_mail;
60
61         heading(false/*title*/); // it is always safe
62         print("\n<p>&nbsp;<br />&nbsp;</p><hr /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
63                         ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
64         footer();
65 }
66
67 function prepvar($name,$regex=".*",$require=true)
68 {
69         global $HTTP_GET_VARS,$HTTP_POST_VARS;
70
71              if (isset($HTTP_GET_VARS[$name]))
72                 $v=$HTTP_GET_VARS[$name];
73         else if (isset($HTTP_POST_VARS[$name]))
74                 $v=$HTTP_POST_VARS[$name];
75         else
76                 unset($v);
77
78         $name_html="Parametr <span class=\"quote\">".htmlspecialchars($name)."</span>";
79
80         $regex="^$regex\$";
81         if (isset($v) && !ereg($regex,$v))
82                 fatal("$name_html nevyhovuje po¾adovanému regexu <span class=\"quote\">".htmlspecialchars($regex)."</span>");
83         if (!isset($v) && $require)
84                 fatal("$name_html je vy¾adován");
85
86         if (!isset($v))
87                 return(0);
88
89         $GLOBALS[$name]=$v;
90         return($v);
91 }
92
93 function db_connect()
94 {
95         global $db_host,$db_user,$db_pwd,$db_name;
96         global $db_link;
97
98         if (isset($db_link))
99                 return;
100         if (!($db_link=mysql_connect($db_host,$db_user,$db_pwd)))
101                 fatal("MySQL connect: ".mysql_error());
102         if (!mysql_select_db($db_name,$db_link))
103                 fatal("MySQL database select: ".mysql_error());
104 }
105
106 function db_query($query)
107 {
108         global $db_link;
109
110         db_connect();
111         if (!($r=mysql_query($query,$db_link)))
112                 fatal("MySQL query \"$query\": ".mysql_error());
113         return($r);
114 }
115
116 function db_row($query) // pure indexes
117 {
118         $q=db_query($query);
119         $r=mysql_fetch_row($q);
120         mysql_free_result($q);
121         return($r);
122 }
123
124 function db_array($query) // field-names associative
125 {
126         $q=db_query($query);
127         $r=mysql_fetch_array($q);
128         mysql_free_result($q);
129         return($r);
130 }
131
132 function db_item($query)
133 {
134         $row=db_row($query);
135         return($row[0]);
136 }
137
138 function num2greg($num)
139 {
140         $r="";
141         $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M");
142         krsort($vals,SORT_NUMERIC);
143         foreach($vals as $val=>$sym) {
144                 while ($num<0 && $num+$val<-$num) {
145                         $r=substr($r,0,-1).$sym.substr($r,-1,1);
146                         $num+=$val;
147                         }
148                 while (10*$num>=8*$val+(substr($val,0,1)=="1")) {
149                         $r=$r.$sym;
150                         $num-=$val;
151                         }
152                 }
153         return($r);
154 }
155
156 function month_a($year,$month,$month_last=0,$sequential=0)
157 {
158         global $tb_obsah,$obsah_year_base;
159
160         if (!$month_last || !$sequential)
161                 list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'");
162         $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last);
163
164         $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full,
165                         "name"=>"$month"    .($month==$month_last ? "" : "-$month_last")."/$year",
166                         "img" =>"img/eap-$year-${month_full}.jpeg",
167                         "icon"=>"img/eap-$year-${month_full}s.jpeg",
168                         );
169         $r["name_full"]=$r["name"]
170                         ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")"
171                         ." - ".num2greg($year-$obsah_year_base+1).". roèník";
172         return($r);
173 }
174
175 function img_size($width,$height)
176 {
177         global $have_style;
178
179         return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"")
180                         ." width=\"$width\" height=\"$height\"");
181 }
182
183 function img($file,$alt,$attrs="")
184 {
185         list($width,$height)=getimagesize($file);
186         $alt=htmlspecialchars($alt);
187         return("<img src=\"$file\" alt=\"$alt\" title=\"$alt\" ".img_size($width,$height)
188                         .($attrs=="" ? "" : " ".$attrs)." />");
189 }
190
191 function gsm_banking()
192 {
193         return(img("img/sluzby_bankovni_pggsm.gif","Paegas GSM banking","class=\"img-align\""));
194 }
195
196 function price_a()
197 {
198         if (!($f=fopen("objednavka.js","r")))
199                 fatal("Nepodaøilo se naèíst seznam dostupného zbo¾í");
200         $r=array();
201         while (($s=fgets($f,0x1000))) {
202                 if (!($s=trim($s)))
203                         break;
204                 if (!(ereg("^want_price\\[ *'([^']*)'\\]=([0-9]*);$",$s,$matched)))
205                         continue;
206                 $r[$matched[1]]=$matched[2];
207                 }
208         fclose($f);
209         return($r);
210 }
211
212 function title_name($year,$month)
213 {
214              if (isset($year) && isset($month)) {
215                 $month_a=month_a($year,$month);
216                 return("Èíslo ".$month_a["name_full"]);
217                 }
218         else if (isset($year))
219                 return("Roèník $year");
220         else
221                 return("V¹echny roèníky");
222 }
223
224 function title_month($year,$month)
225 {
226   $month_a=month_a($year,$month);
227         return(""
228                         ."<table border=\"0\" width=\"100%\">\n"
229                         ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
230                         ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
231                         ."</table></td></tr>\n"
232                         ."</table>\n"
233                         );
234 }
235
236 function title_icons_table_month($year,$month,$month_last,$sequential)
237 {
238         global $tb_clanek;
239
240         $month_a=month_a($year,$month,$month_last,$sequential);
241         print("<table border=\"0\">"
242                         ."<tr><th align=\"center\">".$month_a["name"]."</th></tr>\n"
243                         ."<tr><td align=\"center\" valign=\"top\">"
244                                 .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."</td></tr>\n"
245                         ."<tr><td align=\"left\" valign=\"top\" class=\"nowrap\">\n"
246                                 ."&bull;&nbsp;<a href=\"title.php?year=$year&amp;month=$month\">titulní strana</a><br />\n"
247                                 ."&bull;&nbsp;<a href=\"obsah.php?year=$year&amp;month=$month\">obsah</a><br />\n");
248         $result=db_query("select name,id from $tb_clanek where year=$year and month=$month order by id");
249         while ($row=mysql_fetch_array($result))
250                 print("&bull;&nbsp;<a href=\"clanek.php?year=$year&amp;month=$month&amp;id=".$row["id"]."\">"
251                                 .htmlspecialchars($row["name"])."</a><br />\n");
252         mysql_free_result($result);
253         print("</td></tr></table>");
254 }
255
256 function title_icons($year,$month)
257 {
258         global $tb_obsah;
259
260         print("<h2>"
261                 .(isset($year) ? "<a id=\"year_$year\">" : "")
262                 .title_name(&$year,&$month)
263                 .(isset($year) ? "</a>" : "")
264                 ."</h2>\n");
265
266         $result=db_query("select year,month,month_last,sequential from $tb_obsah"
267                         .(isset($year) || isset($month) ? " where" : "")
268                         .(isset($year ) ? " year=$year"   : "")
269                         .(isset($year) && isset($month) ? " and" : "")
270                         .(isset($month) ?   " month=$month" : "")
271                         ." order by year,month");
272         $split=4;
273
274         // $year variable changes its meaning here!!!
275         if (isset($year))
276                 $wanted_year=$year;
277         $year=0;
278
279         $fin_split="";
280         $fin_year="";
281         while ($row=mysql_fetch_array($result)) {
282                 $row["month"     ]--;
283                 $row["month_last"]--;
284
285                 if ($row["year"]!=$year) {
286                         print($fin_split.$fin_year);
287
288                         $year=$row["year"];
289                         print(""
290                                         .(!isset($wanted_year) ? "<p><a id=\"year_$year\">&nbsp;</a></p>" : "")
291                                         ."<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><table border=\"1\" cellpadding=\"5\">\n"
292                                         ."<tr><th colspan=\"$split\">Roèník $year (<a href=\"obsah.php?year=$year\">obsahy èísel</a>)</th></tr>\n"
293                                         );
294                         $fin_year="</table></td></tr></table>\n";
295                         $fin_split="";
296                         $month=-1;
297                         $floor=-1;
298                         }
299                 while ($floor<floor($row["month"]/$split)) {
300                         print($fin_split."<tr>");
301                         $fin_split="</tr>\n";
302                         $floor++;
303                         $month=$floor*$split-1;
304                         }
305                 while ($month+1<$row["month"]) {
306                         print("<td></td>");
307                         $month++;
308                         }
309                 print("<td align=\"center\" valign=\"top\""
310                                 .($row["month_last"]!=$row["month"] ? " colspan=\"".($row["month_last"]+1-$row["month"])."\"" : "")
311                                 .">");
312                 title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"]);
313                 print("</td>\n");
314                 $month=$row["month_last"];
315                 }
316         mysql_free_result($result);
317         print($fin_split.$fin_year);
318 }
319
320 function title($year,$month)
321 {
322         if (isset($year) && isset($month))
323                 return(title_month( $year, $month));
324         else
325                 return(title_icons(&$year,&$month));
326 }
327
328 function image_supported($mime)
329 {
330         global $HTTP_SERVER_VARS;
331
332         if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"]))
333                 return(false);
334         $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]);
335         while (($s=array_shift($exp))) {
336                 $s=trim(ereg_replace(";.*","",$s));
337                 if ($s==$mime)
338                         return(true);
339                 }
340         return(false);
341 }
342
343 // PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
344 function dirnameslashed($filename)
345 {
346         $r=dirname($filename);
347         if (substr($r,-1)!="/")
348                 $r.="/";
349         return($r);
350 }
351
352 function usersize($size)
353 {
354         $suffix_a=array("","k","M","G","T");
355         while ($size>=1000 && sizeof($suffix_a)>=2) {
356                 $size/=1000;
357                 array_shift($suffix_a);
358                 }
359         return(round($size)." ".$suffix_a[0]."B");
360 }
361
362 function data_href($filename,$text,$details="")
363 {
364         return("<a href=\"$filename\">$text (".usersize(filesize($filename))."$details)</a>");
365 }
366
367 function img_href($filename,$text)
368 {
369         list($width,$height)=getimagesize($filename);
370         return(data_href($filename,$text,", ${width}x${height} bodù"));
371 }
372
373 function print_pdf_layout($name,$base)
374 {
375         $imgfmt=(image_supported("image/png") ? "png" : "gif");
376         ?>
377 <p>Shodný <?php print($name); ?> je dostupný ve dvou rùzných formátech souboru. V&nbsp;pøípadì,
378 ¾e nemáte/nechcete instalovat
379 <a href="http://www.adobe.com/products/acrobat/readstep.html">Adobe Acrobat Reader</a>,
380 zvolte prosím druhou mo¾nost:</p>
381
382 <table border="0">
383 <tr><td><table border="0" cellpadding="1" style="border: ridge;">
384 <tr><td align="center"><?php
385         print(img("${base}s.$imgfmt",ucfirst($name)));
386 ?></td></tr></table></td>
387 <td valign="top"><ul>
388
389 <li>
390 <table border="0">
391 <tr><td><?php print("<a href=\"$base.pdf\">".img("img/adobe-pdficon-alpha.gif","Adobe PDF")."</a>"); ?></td>
392         <td><?php print(data_href("$base.pdf","Dokument PDF")); ?></td>
393         </tr>
394 </table>
395 <blockquote>
396 <table border="0">
397 <tr><td><a href="http://www.adobe.com/products/acrobat/readstep.html"><?php
398         print(img("img/adobe-getacro.gif","Get Adobe Acrobat Reader"));
399         ?></a></td>
400         <td class="smaller">Soubor je ve formátu <span class="italic">Adobe Acrobat</span>,
401         pro jeho pøeètení si prosím nainstalujte
402         <a href="http://www.adobe.com/products/acrobat/readstep.html">Adobe Acrobat Reader</a>.</td>
403         </tr>
404 </table>
405 </blockquote>
406 </li>
407
408 <li>
409 <?php print(img_href("$base.$imgfmt","Obrázkový formát ".strtoupper($imgfmt))); ?>
410 </li>
411
412 </ul></td></tr></table>
413 <?php
414 }
415
416 function format_fields_to_text($title="",$pfx="")
417 {
418         global $HTTP_POST_VARS;
419         $fields=array(
420                         "Název"  ,"name",
421                         "Adresa" ,"adresa",
422                         "Ulice"  ,"ulice",
423                         "Mìsto"  ,"mesto",
424                         "PSÈ"    ,"psc",
425                         "IÈO"    ,"ico",
426                         "DIÈ"    ,"dic",
427                         "Kontakt","contact",
428                         "Tel"    ,"tel",
429                         "Fax"    ,"fax",
430                         "Poèet"  ,"pocet",
431                         "e-mail" ,"mail",
432                         );
433         $bools=array(
434                         "Doklad" ,"doklad",
435                         );
436         $texts=array(
437                         "Text inzerátu","text",
438                         "Jiné sdìlení" ,"comments",
439                         );
440
441         $r="";
442         $tab=($title=="" ? "" : "\t");
443         while ($fields) {
444                 $pretty=array_shift($fields);
445                 $var=$pfx.array_shift($fields);
446                 if (!isset($HTTP_POST_VARS[$var]))
447                         continue;
448                 if (""==($value=trim($HTTP_POST_VARS[$var])))
449                         continue;
450                 $r.="$tab$pretty:\t$value\n";
451                 }
452         while ($bools) {
453                 $pretty=array_shift($bools);
454                 $var=$pfx.array_shift($bools);
455                 if (!isset($HTTP_POST_VARS[$var]))
456                         continue;
457                 $r.="$tab$pretty:\t".($HTTP_POST_VARS[$var] ? "ANO" : "NE")."\n";
458                 }
459         while ($texts) {
460                 $pretty=array_shift($texts);
461                 $var=$pfx.array_shift($texts);
462                 if (!isset($HTTP_POST_VARS[$var]))
463                         continue;
464                 if (""==($value=trim(ereg_replace("[\r\n]+","\n",$HTTP_POST_VARS[$var]))))
465                         continue;
466                 $r.="$tab$pretty:".ereg_replace("\n","\\0\t","\n".$value)."\n";
467                 }
468         if ($r!="" && $title!="")
469                 $r="$title\n".$r;
470         return($r);
471 }
472
473 function stamp_line()
474 {
475         return("stamp:\t".date("r")."\n");
476 }
477
478 function return_back($what)
479 {
480         global $have_js;
481
482         return(""
483                         .(!$have_js ? "" : "<input type=\"button\" value=\"")
484                         .$what
485                         .(!$have_js ? " (tlaèítkem "
486                                                         ."&quot;<span class=\"quote\">Zpìt</span>&quot; èi "
487                                                         ."&quot;<span class=\"quote\">Back</span>&quot; prohlí¾eèe)"
488                                         : "\" onclick=\"history.back()\" />")
489                         );
490 }
491
492 // Data acquision error checking:
493 function datacheck_fail()
494 {
495         print("<p>Nyní se prosím ".return_back("vra»te zpìt")
496                         ." na pøedchozí stránku a chybu zadaných dat opravte.</p>\n");
497         footer();
498 }
499
500 function mail_data($title,$data)
501 {
502         global $admin_mail,$mail_to;
503
504         // 5th mail argument is supported from PHP-4.0.5
505         return (!mail($mail_to,"EnergieWeb: $title",$data,
506 "From: EnergieWeb <$admin_mail>
507 Mime-Version: 1.0
508 Content-Type: text/plain; charset=iso-8859-2
509 Content-Disposition: inline
510 Content-Transfer-Encoding: 8bit
511 "));
512 }
513
514 function gsm_row($name,$value)
515 {
516         return("<tr><td align=\"left\">$name</td>"
517                         ."<td align=\"right\">".($value=="" ? "neuvádìjte" : $value)."</td>"
518                         ."<td align=\"right\">".strtr($value,"/.","#*")."</td></tr>\n");
519 }
520
521 function gsm_table($total,$varsym)
522 {
523         global $firma_ucet,$firma_konstsym,$firma_specsym;
524
525         return("<blockquote><table border=\"1\" cellpadding=\"5\">\n"
526                         ."<tr><th>polo¾ka</th><th>bankovní pøíkaz</th><th>".gsm_banking()."</th></tr>\n"
527                         .gsm_row("Èíslo úètu",$firma_ucet)
528                         .gsm_row("Èástka",sprintf("%.2f",$total))
529                         .gsm_row("Konstantní symbol",$firma_konstsym)
530                         .gsm_row("Variabilní symbol",$varsym)
531                         .gsm_row("Specifický symbol",$firma_specsym)
532                         ."</table></blockquote>\n"
533                         );
534 }
535
536 function return_to_homepage()
537 {
538         global $HTTP_SERVER_VARS;
539
540         return("<p>Nyní se mù¾ete vrátit na <a href=\"".dirnameslashed($HTTP_SERVER_VARS["SCRIPT_NAME"])."\">úvodní stránku</a>.</p>\n");
541 }
542
543 function input_text($name,$size,$default_value="",$addons="")
544 {
545         $r="<input type=\"text\" name=\"$name\" size=\"$size\"";
546         $value=(isset($GLOBALS[$name]) ? $GLOBALS[$name] : $default_value);
547         if (""!=$value)
548                 $r.=" value=\"".htmlspecialchars($value)."\"";
549         $r.=$addons." />";
550         return($r);
551 }
552
553 function print_form_radkova_inzerce($readonly,$total,$submit_name,$submit_value)
554 {
555         global $have_js,$text,$doklad;
556
557         $addons=(!$readonly ? "" : " readonly=\"readonly\"");
558         ?>
559 <blockquote>
560 <form action="inzerat-submit.php<?php print($have_js); ?>" method="post">
561 <table border="1" width="100%" cellpadding="5">
562 <tr><td align="center"><table border="0">
563         <tr><td align="left" class="tab-head">Text inzerátu</td></tr>
564         <tr><td align="center"><?php
565                         print("<textarea name=\"text\" rows=\"7\" cols=\"60\""
566                                         .($readonly ? "" : " onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")
567                                         .$addons.">"
568                                         .(!isset($text) ? "" : htmlspecialchars(trim($text)))
569                                         ."</textarea>");
570                         ?></td></tr>
571         <?php
572                 if ($have_js || $total!="") {
573                         ?>
574                 <tr><td colspan="3"><hr /></td></tr>
575                 <tr><td colspan="3" id="celkova_cena">Celková cena:
576                                 <input type="text" name="total" value="<?php
577                                                 print(htmlspecialchars($total));
578                                                 ?>" size="8" readonly="readonly" /></td></tr>
579                         <?php
580                         }
581         ?>
582         </table></td></tr>
583 <tr><td align="left"><table border ="0" width="100%">
584         <tr><td>Název firmy / Jméno:</td ><td colspan="3"><?php print(input_text("name"  ,60,"",$addons)); ?></td></tr>
585         <tr><td>Úplná adresa:</td        ><td colspan="3"><?php print(input_text("adresa",60,"",$addons)); ?></td></tr>
586         <tr><td>Telefon:</td             ><td colspan="3"><?php print(input_text("tel"   ,25,"",$addons)); ?></td></tr>
587         <tr><td>IÈO:</td                 ><td            ><?php print(input_text("ico"   ,20,"",$addons)); ?></td>
588                         <td>DIÈ</td                  ><td            ><?php print(input_text("dic"   ,20,"",$addons)); ?></td></tr>
589         <tr><td id="danovy_doklad"
590                >Zaslat daòový doklad?</td><td colspan="3"><input type="checkbox" name="doklad"<?php
591                         print(""
592                                         // some hacks as "readonly" not supported for "checkbox"es (->"disabled" for them)
593                                         .($readonly ? "" : " onclick=\"sum_total(this)\"")
594                                         .(!($have_js || $readonly) ? "" : " disabled=\"disabled\"")
595                                         .(!isset($doklad) ? "" : " checked=\"checked\"")
596                                         .ereg_replace(" readonly=\"readonly\"","",$addons)." />");
597                         ?></td></tr>
598         <tr><td id="pocet_zverejneni"
599                >Poèet zveøejnìní:</td    ><td            ><?php print(input_text("pocet",5,1,
600                                         $addons." onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")); ?></td>
601                         <td>e-mail:</td              ><td            ><?php print(input_text("mail",40,"",$addons)); ?></td></tr>
602         </table></td></tr>
603 <tr><td align="center" id="submit_button"><?php
604                 print("<input type=\"submit\" name=\"$submit_name\" value=\"".htmlspecialchars($submit_value)."\""
605                                 ." onclick=\"return(validate(this.form))\" />");
606                 ?></td></tr>
607 </table></form>
608 </blockquote>
609 <?php
610 }
611
612 function footer_img($url,$text,$size)
613 {
614         global $footer_LOCAL;
615         if (!isset($footer_LOCAL))
616                 return("<img src=\"$url\" $size alt=\"$text\" />");
617         else
618                 return($text);
619 }
620
621 function footer($delimit=true)
622 {
623         // deadlock prevention:
624         global $footer_passed;
625         if (isset($footer_passed))
626                 exit();
627         $footer_passed=true;
628
629         global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS;
630         if ($delimit)
631                 print("<p>&nbsp;</p>\n");
632         $uri="uri=".addpercents("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]);
633         ?>
634 <hr />
635 <table border="0" width="100%">
636 <tr><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><a
637         href="http://validator.w3.org/check?<?php
638                 print($uri); ?>"><?php
639                                 print footer_img("http://www.w3.org/Icons/valid-xhtml11","Valid XHTML 1.1!",img_size(88,31));
640                                 ?></a><a href="http://jigsaw.w3.org/css-validator/validator?warning=2&amp;profile=css2&amp;<?php
641                 print($uri); ?>"><?php
642                                 print footer_img("http://jigsaw.w3.org/css-validator/images/vcss","Valid CSS!",img_size(88,31));
643                                 ?></a></td></tr>
644 </table>
645 </body></html>
646 <?php
647         exit();
648 }
649
650 // Stolen from: php-manual.html#function.header
651 function no_cache()
652 {
653         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");          // Date in the past
654         header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified
655         header("Cache-Control: no-cache, must-revalidate");        // HTTP/1.1
656         header("Pragma: no-cache");                                // HTTP/1.0
657 }
658
659 function heading($title=false)
660 {
661         global $HTTP_SERVER_VARS,$msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head,$heading_done,$title_prefix,$force_charset;
662
663         if (isset($heading_done))
664                 return;
665         $heading_done=1;
666
667         if (isset($force_charset))
668                 $client_charset=$force_charset;
669         else
670                 $client_charset=(!isset($HTTP_SERVER_VARS["CLIENT_CHARSET"]) ? "iso-8859-2" : $HTTP_SERVER_VARS["CLIENT_CHARSET"]);
671         // When "CLIENT_CHARSET" is set we MUST NOT explicitely specify our "charset"
672         header("Content-type: text/html".(isset($HTTP_SERVER_VARS["CLIENT_CHARSET"]) ? "" : "; charset=$client_charset"));
673         header("Content-Style-Type: text/css");
674         if (!isset($msie_major) || $msie_major>=4) {
675                 print('<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n");
676                 }
677 ?>
678 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
679 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">
680 <head><?php
681         print("<title>$title_prefix");
682         if (isset($title_tail))
683                 print(": ".htmlspecialchars($title_tail));
684         print("</title>\n");
685         if ($have_css) {
686 ?><style type="text/css"><!--
687 .cvs-id   { font-family: monospace; }
688 .error    { color: red;   background-color: transparent; }
689 .quote    { font-family: monospace; }
690 .nowrap   { white-space: nowrap; }
691 .centered { text-align: center; }
692 .tab-bold { font-weight: bold; }
693 .tab-head { font-weight: bold; color: yellow; background-color: transparent; }
694 body {
695                 background-color: black;
696                 color: white;
697                 }
698 :link    { color: aqua;   background-color: transparent; }
699 :visited { color: teal;   background-color: transparent; }
700 h1,h2    { color: yellow; background-color: transparent; }
701 <?php
702                 if (isset($head_css))
703                         print(trim($head_css)."\n");
704                 print("--></style>\n");
705                 }
706         if (isset($head))
707                 print($head);
708         print("</head><body");
709         if (isset($mozilla_major) && $mozilla_major==4)
710                 print(" bgcolor=\"black\" text=\"white\" link=\"aqua\" vlink=\"teal\"");
711         print(">\n");
712         if ($title)
713                 print("<h1 class=\"centered\">"
714                                 .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze")
715                                 ."</h1>\n");
716 }
717 ?>