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