+EaP 4/2010 (164)
[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:$admin_mail\">".$cvs_id_split[5]."</a>";
18                 }
19         $cvs_id_html=join(" ",$cvs_id_split);
20
21         if (!isset($head))
22                 $head="";
23         if (!isset($energie_base))
24                 $energie_base="";
25
26         unset($have_ent);
27         if (isset($HTTP_GET_VARS[    "have_ent"]))
28                 $have_ent=true;
29         if (isset($HTTP_GET_VARS["amp;have_ent"]))
30                 $have_ent=false;
31         if ((!isset($detect_ent) || $detect_ent) && !isset($have_ent) && $HTTP_SERVER_VARS["REQUEST_METHOD"]=="GET")
32                 $head.='<meta http-equiv="Refresh" content="0; URL='
33                                 .htmlspecialchars("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["PHP_SELF"]
34                                                 ."?".(strlen($HTTP_SERVER_VARS["QUERY_STRING"]) ? $HTTP_SERVER_VARS["QUERY_STRING"] : "detect_ent_glue=1")
35                                                                 ."&have_ent=detect")
36                                 .'" />'."\n";
37         fixampvars();
38
39         $have_js=(isset($HTTP_GET_VARS["have_js"]) || isset($HTTP_POST_VARS["have_js"])
40                         ? "?have_js=1" : "");
41         if (isset($detect_js) && !$have_js)
42                 $head.='<script type="text/javascript" src="'.$energie_base.'have_js.js"></script>'."\n";
43
44         $user_agent=(!isset($HTTP_SERVER_VARS["HTTP_USER_AGENT"]) ? "" : $HTTP_SERVER_VARS["HTTP_USER_AGENT"]);
45         if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a))
46                 $msie_major=$msie_major_a[1];
47         else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
48                 $mozilla_major=$mozilla_major_a[1];
49
50         $have_style=!isset($mozilla_major) || $mozilla_major!=4;
51         $have_css=true; // doesn't hurt anybody AFAIK
52
53 function fixampvars()
54 {
55         $ars=array("HTTP_GET_VARS","HTTP_POST_VARS");
56         foreach ($ars as $ar) {
57                 foreach ($GLOBALS[$ar] as $key=>$val) {
58                         if (substr($key,0,4)!="amp;")
59                                 continue;
60                         unset($GLOBALS[$ar][$key]);
61                         $GLOBALS[$ar][substr($key,4)]=$val;
62                         }
63                 }
64 }
65
66 function fatal($msg="UNKNOWN")
67 {
68         global $admin_mail;
69
70         heading(false/*title*/,false/*indexme*/); // notitle is always safe, don't index the error message
71         print("\n<p>&nbsp;<br />&nbsp;</p><hr /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
72                         ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
73         footer();
74 }
75
76 function prepvar($name,$regex=".*",$require=true)
77 {
78         global $HTTP_GET_VARS,$HTTP_POST_VARS;
79
80              if (isset($HTTP_GET_VARS[$name]))
81                 $v=$HTTP_GET_VARS[$name];
82         else if (isset($HTTP_POST_VARS[$name]))
83                 $v=$HTTP_POST_VARS[$name];
84         else
85                 unset($v);
86
87         $name_html="Parametr <span class=\"quote\">".htmlspecialchars($name)."</span>";
88
89         $regex="^$regex\$";
90         if (isset($v) && !ereg($regex,$v))
91                 fatal("$name_html nevyhovuje po¾adovanému regexu <span class=\"quote\">".htmlspecialchars($regex)."</span>");
92         if (!isset($v) && $require)
93                 fatal("$name_html je vy¾adován");
94
95         if (!isset($v))
96                 return(0);
97
98         $GLOBALS[$name]=$v;
99         return($v);
100 }
101
102 function db_connect()
103 {
104         global $db_host,$db_user,$db_pwd,$db_name;
105         global $db_link;
106
107         if (isset($db_link))
108                 return;
109         if (!($db_link=mysql_connect($db_host,$db_user,$db_pwd)))
110                 fatal("MySQL connect: ".mysql_error());
111         if (!mysql_select_db($db_name,$db_link))
112                 fatal("MySQL database select: ".mysql_error());
113 }
114
115 function db_query($query)
116 {
117         global $db_link;
118
119         db_connect();
120         if (!($r=mysql_query($query,$db_link)))
121                 fatal("MySQL query \"$query\": ".mysql_error());
122         return($r);
123 }
124
125 function db_row($query) // pure indexes
126 {
127         $q=db_query($query);
128         $r=mysql_fetch_row($q);
129         mysql_free_result($q);
130         return($r);
131 }
132
133 function db_array($query) // field-names associative
134 {
135         $q=db_query($query);
136         $r=mysql_fetch_array($q);
137         mysql_free_result($q);
138         return($r);
139 }
140
141 function db_item($query)
142 {
143         $row=db_row($query);
144         return($row[0]);
145 }
146
147 function num2greg($num)
148 {
149         $r="";
150         $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M");
151         krsort($vals,SORT_NUMERIC);
152         foreach($vals as $val=>$sym) {
153                 while ($num<0 && $num+$val<-$num) {
154                         $r=substr($r,0,-1).$sym.substr($r,-1,1);
155                         $num+=$val;
156                         }
157                 while (10*$num>=8*$val+(substr($val,0,1)=="1")) {
158                         $r=$r.$sym;
159                         $num-=$val;
160                         }
161                 }
162         return($r);
163 }
164
165 function month_a($year,$month,$month_last=0,$sequential=0)
166 {
167         global $tb_obsah,$obsah_year_base;
168
169         if (!$month_last || !$sequential)
170                 list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'");
171         $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last);
172
173         $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full,
174                         "name"=>"$month"    .($month==$month_last ? "" : "-$month_last")."/$year",
175                         "img" =>"img/eap-$year-${month_full}.jpeg",
176                         "icon"=>"img/eap-$year-${month_full}s.jpeg",
177                         );
178         $r["name_full"]=$r["name"]
179                         ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")"
180                         ." - ".num2greg($year-$obsah_year_base+1).". roèník";
181         return($r);
182 }
183
184 function img_size($width,$height)
185 {
186         global $have_style;
187
188         return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"")
189                         ." width=\"$width\" height=\"$height\"");
190 }
191
192 function img($file,$alt,$attrs="")
193 {
194         list($width,$height)=getimagesize(ereg_replace("\\.mng\$",".gif",$file));
195         $alt=htmlspecialchars($alt);
196         return("<img src=\"$file\" alt=\"$alt\" title=\"$alt\" ".img_size($width,$height)
197                         .($attrs=="" ? "" : " ".$attrs)." />");
198 }
199
200 function price_a()
201 {
202         if (!($f=fopen("objednavka.js","r")))
203                 fatal("Nepodaøilo se naèíst seznam dostupného zbo¾í");
204         $r=array();
205         while (($s=fgets($f,0x1000))) {
206                 if (!($s=trim($s)))
207                         break;
208                 if (!(ereg("^want_price\\[ *'([^']*)'\\]=([0-9]*);$",$s,$matched)))
209                         continue;
210                 $r[$matched[1]]=$matched[2];
211                 }
212         fclose($f);
213         return($r);
214 }
215
216 function title_name($year,$month)
217 {
218              if (isset($year) && isset($month)) {
219                 $month_a=month_a($year,$month);
220                 return("Èíslo ".$month_a["name_full"]);
221                 }
222         else if (isset($year))
223                 return("Roèník $year");
224         else
225                 return("V¹echny roèníky");
226 }
227
228 function title_month($year,$month)
229 {
230   $month_a=month_a($year,$month);
231         return(""
232                         ."<table border=\"0\" width=\"100%\">\n"
233                         ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
234                         ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
235                         ."</table></td></tr>\n"
236                         ."</table>\n"
237                         );
238 }
239
240 function title_icons_table_month($year,$month,$month_last,$sequential,$has_contents)
241 {
242         global $tb_clanek;
243
244         $month_a=month_a($year,$month,$month_last,$sequential);
245         print("<table border=\"0\">"
246                         ."<tr><th align=\"center\">".$month_a["name"]."</th></tr>\n"
247                         ."<tr><td align=\"center\" valign=\"top\">"
248                                 .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."</td></tr>\n"
249                         ."<tr><td align=\"left\" valign=\"top\" class=\"nowrap\">\n"
250                                 ."&bull;&nbsp;<a href=\"title.php?year=$year&amp;month=$month\">titulní strana</a><br />\n"
251                         );
252         if ($has_contents)
253                 print("&bull;&nbsp;<a href=\"obsah.php?year=$year&amp;month=$month\">obsah</a><br />\n");
254         $result=db_query("select name,id from $tb_clanek where year=$year and month=$month order by id");
255         while ($row=mysql_fetch_array($result))
256                 print("&bull;&nbsp;<a href=\"clanek.php?year=$year&amp;month=$month&amp;id=".$row["id"]."\">"
257                                 .htmlspecialchars(ereg_replace("^.*\\|","",$row["name"]))."</a><br />\n");
258         mysql_free_result($result);
259         print("</td></tr></table>");
260 }
261
262 function title_icons($year,$month)
263 {
264         global $tb_obsah;
265
266         print("<h2>"
267                 .(isset($year) ? "<a id=\"year_$year\">" : "")
268                 .title_name(&$year,&$month)
269                 .(isset($year) ? "</a>" : "")
270                 ."</h2>\n");
271
272         $result=db_query("select year,month,month_last,sequential,contents is not null as has_contents from $tb_obsah"
273                         .(isset($year) || isset($month) ? " where" : "")
274                         .(isset($year ) ? " year=$year"   : "")
275                         .(isset($year) && isset($month) ? " and" : "")
276                         .(isset($month) ?   " month=$month" : "")
277                         ." order by year,month");
278         $split=4;
279
280         // $year variable changes its meaning here!!!
281         if (isset($year))
282                 $wanted_year=$year;
283         $year=0;
284
285         $fin_split="";
286         $fin_year="";
287         while ($row=mysql_fetch_array($result)) {
288                 $row["month"     ]--;
289                 $row["month_last"]--;
290
291                 if ($row["year"]!=$year) {
292                         print($fin_split.$fin_year);
293
294                         $year=$row["year"];
295                         print(""
296                                         .(!isset($wanted_year) ? "<p><a id=\"year_$year\">&nbsp;</a></p>" : "")
297                                         ."<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><table border=\"1\" cellpadding=\"5\">\n"
298                                         ."<tr><th colspan=\"$split\">Roèník $year (<a href=\"obsah.php?year=$year\">obsahy èísel</a>)</th></tr>\n"
299                                         );
300                         $fin_year="</table></td></tr></table>\n";
301                         $fin_split="";
302                         $month=-1;
303                         $floor=-1;
304                         }
305                 while ($floor<floor($row["month"]/$split)) {
306                         print($fin_split."<tr>");
307                         $fin_split="</tr>\n";
308                         $floor++;
309                         $month=$floor*$split-1;
310                         }
311                 while ($month+1<$row["month"]) {
312                         print("<td></td>");
313                         $month++;
314                         }
315                 print("<td align=\"center\" valign=\"top\""
316                                 .($row["month_last"]!=$row["month"] ? " colspan=\"".($row["month_last"]+1-$row["month"])."\"" : "")
317                                 .">");
318                 title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"],$row["has_contents"]);
319                 print("</td>\n");
320                 $month=$row["month_last"];
321                 }
322         mysql_free_result($result);
323         print($fin_split.$fin_year);
324 }
325
326 function title($year,$month)
327 {
328         if (isset($year) && isset($month))
329                 return(title_month( $year, $month));
330         else
331                 return(title_icons(&$year,&$month));
332 }
333
334 function image_supported($mime)
335 {
336         global $HTTP_SERVER_VARS;
337
338         if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"]))
339                 return(false);
340         $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]);
341         while (($s=array_shift($exp))) {
342                 $s=trim(ereg_replace(";.*","",$s));
343                 if ($s==$mime)
344                         return(true);
345                 }
346         return(false);
347 }
348
349 // PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
350 function dirnameslashed($filename)
351 {
352         $r=dirname($filename);
353         if (substr($r,-1)!="/")
354                 $r.="/";
355         return($r);
356 }
357
358 function usersize($size)
359 {
360         $suffix_a=array("","k","M","G","T");
361         while ($size>=1000 && sizeof($suffix_a)>=2) {
362                 $size/=1000;
363                 array_shift($suffix_a);
364                 }
365         return(round($size)." ".$suffix_a[0]."B");
366 }
367
368 function data_href($filename,$text,$details="")
369 {
370         return("<a href=\"$filename\">$text (".usersize(filesize($filename))."$details)</a>");
371 }
372
373 function img_href($filename,$text)
374 {
375         list($width,$height)=getimagesize($filename);
376         return(data_href($filename,$text,", ${width}x${height} bodù"));
377 }
378
379 function print_pdf_layout($name,$base)
380 {
381         global $energie_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($energie_base."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($energie_base."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                         ."</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></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 form_charset()
563 {
564         // CSacek-2.1.9+ required (mod_czech support dropped!)
565         // We MUST have input coded in "iso-8859-2" as we use
566         // "csacekRecodeInput Off", CSacek otherwise tries to recode input but CSacek
567         // _cannot_ know the encoding used by the client (moreover it IGNORES POST
568         // data MIME type, even if provided by Lynx 2.8.4dev.11, Mozilla 1.0.0
569         // doesn't provide anything).
570         // "iso-8859-2" should be replaced by $HTTP_SERVER_VARS["HTTP_X_CLIENT_CHARSET"]
571         // and "csacekRecodeInput On"(default) when CSacek fixes support of "utf-8"
572         // input-decoding, details in my mail <20020620134930.GA18761@short.ucw.cz>.
573
574         return('enctype="application/x-www-form-urlencoded" accept-charset="iso-8859-2"');
575 }
576
577 function print_form_radkova_inzerce($readonly,$total,$submit_name,$submit_value)
578 {
579         global $have_js,$text,$doklad;
580
581         $addons=(!$readonly ? "" : " readonly=\"readonly\"");
582         ?>
583 <blockquote>
584 <form action="inzerat-submit.php<?php print($have_js); ?>" method="post" <?php print(form_charset()); ?>>
585 <table border="1" width="100%" cellpadding="5">
586 <tr><td align="center"><table border="0">
587         <tr><td align="left" class="tab-head">Text inzerátu</td></tr>
588         <tr><td align="center"><?php
589                         print("<textarea name=\"text\" rows=\"7\" cols=\"60\""
590                                         .($readonly ? "" : " onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")
591                                         .$addons.">"
592                                         .(!isset($text) ? "" : htmlspecialchars(trim($text)))
593                                         ."</textarea>");
594                         ?></td></tr>
595         <?php
596                 if ($have_js || $total!="") {
597                         ?>
598                 <tr><td colspan="3"><hr /></td></tr>
599                 <tr><td colspan="3" id="celkova_cena">Celková cena:
600                                 <input type="text" name="total" value="<?php
601                                                 print(htmlspecialchars($total));
602                                                 ?>" size="8" readonly="readonly" /></td></tr>
603                         <?php
604                         }
605         ?>
606         </table></td></tr>
607 <tr><td align="left"><table border ="0" width="100%">
608         <tr><td>Název firmy / Jméno:</td ><td colspan="3"><?php print(input_text("name"  ,60,"",$addons)); ?></td></tr>
609         <tr><td>Úplná adresa:</td        ><td colspan="3"><?php print(input_text("adresa",60,"",$addons)); ?></td></tr>
610         <tr><td>Telefon:</td             ><td colspan="3"><?php print(input_text("tel"   ,25,"",$addons)); ?></td></tr>
611         <tr><td>IÈO:</td                 ><td            ><?php print(input_text("ico"   ,20,"",$addons)); ?></td>
612                         <td>DIÈ</td                  ><td            ><?php print(input_text("dic"   ,20,"",$addons)); ?></td></tr>
613         <tr><td id="danovy_doklad"
614                >Zaslat daòový doklad?</td><td colspan="3"><input type="checkbox" name="doklad"<?php
615                         print(""
616                                         // some hacks as "readonly" not supported for "checkbox"es (->"disabled" for them)
617                                         .(!($have_js || $readonly) ? "" : " onclick=\"sum_total(this)\"")
618                                         .(!($have_js || $readonly) ? "" : " disabled=\"disabled\"")
619                                         .(!isset($doklad) ? "" : " checked=\"checked\"")
620                                         .ereg_replace(" readonly=\"readonly\"","",$addons)." />");
621                         ?></td></tr>
622         <tr><td id="pocet_zverejneni"
623                >Poèet zveøejnìní:</td    ><td            ><?php print(input_text("pocet",5,1,
624                                         $addons." onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")); ?></td>
625                         <td>e-mail:</td              ><td            ><?php print(input_text("mail",40,"",$addons)); ?></td></tr>
626         </table></td></tr>
627 <tr><td align="center" id="submit_button"><?php
628                 print("<input type=\"submit\" name=\"$submit_name\" value=\"".htmlspecialchars($submit_value)."\""
629                                 .(!($have_js || $readonly) ? "" : " onclick=\"return(validate(this.form))\"")
630                                 ." />");
631                 ?></td></tr>
632 </table></form>
633 </blockquote>
634 <?php
635 }
636
637 function footer_img($url,$text,$size)
638 {
639         global $footer_LOCAL;
640         if (!isset($footer_LOCAL))
641                 return("<img src=\"$url\" $size alt=\"$text\" title=\"$text\" />");
642         else
643                 return($text);
644 }
645
646 function a_href($url,$contents)
647 {
648         global $have_ent,$energie_base;
649
650         $r="<a href=\"";
651         $urlent=htmlspecialchars($url);
652              if ($url==$urlent)
653                 $r.=$url;
654         else if (!ereg("^[a-z]+://",$url))      // $url is our resource
655                 $r.=$urlent;
656         else if (isset($have_ent) && !$have_ent)        // non-ent client
657                 $r.=$url;
658         else if ($have_ent) // ent client
659                 $r.=$urlent;
660         else // unknown client, htmlspecialchars() should not be needed here
661                 $r.=htmlspecialchars($energie_base."redirect.php?location=".urlencode($url));
662         $r.="\">$contents</a>";
663         return($r);
664 }
665
666 function footer($delimit=true)
667 {
668         // deadlock prevention:
669         global $footer_passed;
670         if (isset($footer_passed))
671                 exit();
672         $footer_passed=true;
673
674         global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS,$energie_base;
675         if ($delimit)
676                 print("<p>&nbsp;</p>\n");
677         $uri="uri=".urlencode("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]);
678         ?>
679 <hr />
680 <table border="0" width="100%">
681 <tr class="footer"><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><?php
682                         print(""
683                                         .a_href("http://validator.w3.org/check?$uri",
684                                                         img($energie_base."img/valid-xhtml11.".(image_supported("image/png") ? "png" : "gif"),"Valid XHTML 1.1!"))
685                                         .a_href("http://jigsaw.w3.org/css-validator/validator?warning=2&profile=css2&$uri",
686                                                         img($energie_base."img/vcss."         .(image_supported("image/png") ? "png" : "gif"),"Valid CSS!"))
687                                         // missing trailing '/' is required by http://www.w3.org/Style/CSS/Buttons/Menu #<li> 4
688                                         .a_href("http://www.w3.org/Style/CSS/Buttons",'<span style="background-color: #ffcc66;">'
689                                                         .img($energie_base."img/mwcts."        .(image_supported("image/png") ? "png" : "gif"),"Made with CSS").'</span>')
690                                         );
691                         ?></td></tr>
692 </table>
693 </body></html>
694 <?php
695         exit();
696 }
697
698 // Stolen from: php-manual.html#function.header
699 function no_cache()
700 {
701         header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");          // Date in the past
702         header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified
703         header("Cache-Control: no-cache, must-revalidate");        // HTTP/1.1
704         header("Pragma: no-cache");                                // HTTP/1.0
705 }
706
707 function heading($title=true,$indexme=true)
708 {
709         global $msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head,$heading_done,$title_prefix,$force_charset;
710
711         if (isset($heading_done))
712                 return;
713         $heading_done=true;
714
715         // $HTTP_SERVER_VARS["CLIENT_CHARSET"] ignored (mod_czech support dropped!)
716         $client_charset=(isset($force_charset) ? $force_charset : "iso-8859-2");
717         header("Content-type: text/html; charset=$client_charset");
718         header("Content-Style-Type: text/css");
719         if (!isset($msie_major) || $msie_major>=4) {
720                 print('<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n");
721                 }
722 ?>
723 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
724 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">
725 <head><?php
726         print("<title>$title_prefix");
727         if (isset($title_tail))
728                 print(": ".htmlspecialchars($title_tail));
729         print("</title>\n");
730         if ($have_css) {
731 ?><style type="text/css"><!--
732 .cvs-id   { font-family: monospace; }
733 .error    { color: red;   background-color: transparent; }
734 .quote    { font-family: monospace; }
735 .nowrap   { white-space: nowrap; }
736 .centered { text-align: center; }
737 .tab-bold { font-weight: bold; }
738 .tab-head { font-weight: bold; color: yellow; background-color: transparent; }
739 body {
740                 background-color: black;
741                 color: white;
742                 }
743 :link    { color: aqua;   background-color: transparent; }
744 :visited { color: teal;   background-color: transparent; }
745 h1,h2    { color: yellow; background-color: transparent; }
746 .footer img { vertical-align: middle; }
747 <?php
748                 if (isset($head_css))
749                         print(trim($head_css)."\n");
750                 print("--></style>\n");
751                 }
752         print('<meta name="robots" content="'.($indexme ? "" : "no" ).'index,follow" />'."\n");
753         if (isset($head))
754                 print($head);
755         print("</head><body");
756         if (isset($mozilla_major) && $mozilla_major==4)
757                 print(" bgcolor=\"black\" text=\"white\" link=\"aqua\" vlink=\"teal\"");
758         print(">\n");
759         if ($title)
760                 print("<h1 class=\"centered\"><a href=\"/\">"
761                                 .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze")
762                                 ."</a></h1>\n");
763 }
764 ?>