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