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