3 error_reporting(E_ALL);
4 setlocale(LC_ALL,"cs_CZ.iso-8859-2");
9 // $viewcvs prepared by "config.php"
10 if ($viewcvs==$HTTP_SERVER_VARS["SCRIPT_NAME"])
12 $cvs_id_split=split(" ",$cvs_id);
13 if (count($cvs_id_split)==8) {
14 $cvs_id_split[1]="<a href=\"$viewcvs\">".$cvs_id_split[1]."</a>";
15 $cvs_id_split[5]="<a href=\"mailto:".$cvs_id_split[5]."@$cvs_mailhost\">".$cvs_id_split[5]."</a>";
17 $cvs_id_html=join(" ",$cvs_id_split);
19 $have_js=(isset($HTTP_GET_VARS["have_js"]) || isset($HTTP_POST_VARS["have_js"])
21 if (isset($detect_js) && !$have_js)
22 $head.='<script type="text/javascript" src="'.(!isset($energie_base) ? "" : $energie_base).'have_js.js"></script>'."\n";
24 $user_agent=(!isset($HTTP_SERVER_VARS["HTTP_USER_AGENT"]) ? "" : $HTTP_SERVER_VARS["HTTP_USER_AGENT"]);
25 if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a))
26 $msie_major=$msie_major_a[1];
27 else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
28 $mozilla_major=$mozilla_major_a[1];
30 $have_style=!isset($mozilla_major) || $mozilla_major!=4;
31 $have_css=true; // doesn't hurt anybody AFAIK
35 $ars=array("HTTP_GET_VARS","HTTP_POST_VARS");
36 foreach ($ars as $ar) {
37 foreach ($GLOBALS[$ar] as $key=>$val) {
38 if (substr($key,0,4)!="amp;")
40 unset($GLOBALS[$ar][$key]);
41 $GLOBALS[$ar][substr($key,4)]=$val;
46 function addpercents($url)
49 foreach(preg_split('//', $url, -1, PREG_SPLIT_NO_EMPTY) as $c)
50 if (ereg("[a-zA-Z0-9]",$c))
53 $r.=sprintf("%%%02X",ord($c));
57 function fatal($msg="UNKNOWN")
61 heading(false/*title*/); // it is always safe
62 print("\n<p> <br /> </p><hr /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
63 ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
67 function prepvar($name,$regex=".*",$require=true)
69 global $HTTP_GET_VARS,$HTTP_POST_VARS;
71 if (isset($HTTP_GET_VARS[$name]))
72 $v=$HTTP_GET_VARS[$name];
73 else if (isset($HTTP_POST_VARS[$name]))
74 $v=$HTTP_POST_VARS[$name];
78 $name_html="Parametr <span class=\"quote\">".htmlspecialchars($name)."</span>";
81 if (isset($v) && !ereg($regex,$v))
82 fatal("$name_html nevyhovuje po¾adovanému regexu <span class=\"quote\">".htmlspecialchars($regex)."</span>");
83 if (!isset($v) && $require)
84 fatal("$name_html je vy¾adován");
95 global $db_host,$db_user,$db_pwd,$db_name;
100 if (!($db_link=mysql_connect($db_host,$db_user,$db_pwd)))
101 fatal("MySQL connect: ".mysql_error());
102 if (!mysql_select_db($db_name,$db_link))
103 fatal("MySQL database select: ".mysql_error());
106 function db_query($query)
111 if (!($r=mysql_query($query,$db_link)))
112 fatal("MySQL query \"$query\": ".mysql_error());
116 function db_row($query) // pure indexes
119 $r=mysql_fetch_row($q);
120 mysql_free_result($q);
124 function db_array($query) // field-names associative
127 $r=mysql_fetch_array($q);
128 mysql_free_result($q);
132 function db_item($query)
138 function num2greg($num)
141 $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M");
142 krsort($vals,SORT_NUMERIC);
143 foreach($vals as $val=>$sym) {
144 while ($num<0 && $num+$val<-$num) {
145 $r=substr($r,0,-1).$sym.substr($r,-1,1);
148 while (10*$num>=8*$val+(substr($val,0,1)=="1")) {
156 function month_a($year,$month,$month_last=0,$sequential=0)
158 global $tb_obsah,$obsah_year_base;
160 if (!$month_last || !$sequential)
161 list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'");
162 $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last);
164 $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full,
165 "name"=>"$month" .($month==$month_last ? "" : "-$month_last")."/$year",
166 "img" =>"img/eap-$year-${month_full}.jpeg",
167 "icon"=>"img/eap-$year-${month_full}s.jpeg",
169 $r["name_full"]=$r["name"]
170 ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")"
171 ." - ".num2greg($year-$obsah_year_base+1).". roèník";
175 function img_size($width,$height)
179 return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"")
180 ." width=\"$width\" height=\"$height\"");
183 function img($file,$alt,$attrs="")
185 list($width,$height)=getimagesize(ereg_replace("\\.mng",".gif",$file));
186 $alt=htmlspecialchars($alt);
187 return("<img src=\"$file\" alt=\"$alt\" title=\"$alt\" ".img_size($width,$height)
188 .($attrs=="" ? "" : " ".$attrs)." />");
191 function gsm_banking()
193 return(img("img/sluzby_bankovni_pggsm.".(image_supported("video/x-mng") ? "mng" : "gif"),
194 "Paegas GSM banking","class=\"img-align\""));
199 if (!($f=fopen("objednavka.js","r")))
200 fatal("Nepodaøilo se naèíst seznam dostupného zbo¾í");
202 while (($s=fgets($f,0x1000))) {
205 if (!(ereg("^want_price\\[ *'([^']*)'\\]=([0-9]*);$",$s,$matched)))
207 $r[$matched[1]]=$matched[2];
213 function title_name($year,$month)
215 if (isset($year) && isset($month)) {
216 $month_a=month_a($year,$month);
217 return("Èíslo ".$month_a["name_full"]);
219 else if (isset($year))
220 return("Roèník $year");
222 return("V¹echny roèníky");
225 function title_month($year,$month)
227 $month_a=month_a($year,$month);
229 ."<table border=\"0\" width=\"100%\">\n"
230 ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
231 ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
232 ."</table></td></tr>\n"
237 function title_icons_table_month($year,$month,$month_last,$sequential)
241 $month_a=month_a($year,$month,$month_last,$sequential);
242 print("<table border=\"0\">"
243 ."<tr><th align=\"center\">".$month_a["name"]."</th></tr>\n"
244 ."<tr><td align=\"center\" valign=\"top\">"
245 .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."</td></tr>\n"
246 ."<tr><td align=\"left\" valign=\"top\" class=\"nowrap\">\n"
247 ."• <a href=\"title.php?year=$year&month=$month\">titulní strana</a><br />\n"
248 ."• <a href=\"obsah.php?year=$year&month=$month\">obsah</a><br />\n");
249 $result=db_query("select name,id from $tb_clanek where year=$year and month=$month order by id");
250 while ($row=mysql_fetch_array($result))
251 print("• <a href=\"clanek.php?year=$year&month=$month&id=".$row["id"]."\">"
252 .htmlspecialchars($row["name"])."</a><br />\n");
253 mysql_free_result($result);
254 print("</td></tr></table>");
257 function title_icons($year,$month)
262 .(isset($year) ? "<a id=\"year_$year\">" : "")
263 .title_name(&$year,&$month)
264 .(isset($year) ? "</a>" : "")
267 $result=db_query("select year,month,month_last,sequential from $tb_obsah"
268 .(isset($year) || isset($month) ? " where" : "")
269 .(isset($year ) ? " year=$year" : "")
270 .(isset($year) && isset($month) ? " and" : "")
271 .(isset($month) ? " month=$month" : "")
272 ." order by year,month");
275 // $year variable changes its meaning here!!!
282 while ($row=mysql_fetch_array($result)) {
284 $row["month_last"]--;
286 if ($row["year"]!=$year) {
287 print($fin_split.$fin_year);
291 .(!isset($wanted_year) ? "<p><a id=\"year_$year\"> </a></p>" : "")
292 ."<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><table border=\"1\" cellpadding=\"5\">\n"
293 ."<tr><th colspan=\"$split\">Roèník $year (<a href=\"obsah.php?year=$year\">obsahy èísel</a>)</th></tr>\n"
295 $fin_year="</table></td></tr></table>\n";
300 while ($floor<floor($row["month"]/$split)) {
301 print($fin_split."<tr>");
302 $fin_split="</tr>\n";
304 $month=$floor*$split-1;
306 while ($month+1<$row["month"]) {
310 print("<td align=\"center\" valign=\"top\""
311 .($row["month_last"]!=$row["month"] ? " colspan=\"".($row["month_last"]+1-$row["month"])."\"" : "")
313 title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"]);
315 $month=$row["month_last"];
317 mysql_free_result($result);
318 print($fin_split.$fin_year);
321 function title($year,$month)
323 if (isset($year) && isset($month))
324 return(title_month( $year, $month));
326 return(title_icons(&$year,&$month));
329 function image_supported($mime)
331 global $HTTP_SERVER_VARS;
333 if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"]))
335 $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]);
336 while (($s=array_shift($exp))) {
337 $s=trim(ereg_replace(";.*","",$s));
344 // PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
345 function dirnameslashed($filename)
347 $r=dirname($filename);
348 if (substr($r,-1)!="/")
353 function usersize($size)
355 $suffix_a=array("","k","M","G","T");
356 while ($size>=1000 && sizeof($suffix_a)>=2) {
358 array_shift($suffix_a);
360 return(round($size)." ".$suffix_a[0]."B");
363 function data_href($filename,$text,$details="")
365 return("<a href=\"$filename\">$text (".usersize(filesize($filename))."$details)</a>");
368 function img_href($filename,$text)
370 list($width,$height)=getimagesize($filename);
371 return(data_href($filename,$text,", ${width}x${height} bodù"));
374 function print_pdf_layout($name,$base)
376 $imgfmt=(image_supported("image/png") ? "png" : "gif");
378 <p>Shodný <?php print($name); ?> je dostupný ve dvou rùzných formátech souboru. V pøípadì,
379 ¾e nemáte/nechcete instalovat
380 <a href="http://www.adobe.com/products/acrobat/readstep.html">Adobe Acrobat Reader</a>,
381 zvolte prosím druhou mo¾nost:</p>
384 <tr><td><table border="0" cellpadding="1" style="border: ridge;">
385 <tr><td align="center"><?php
386 print(img("${base}s.$imgfmt",ucfirst($name)));
387 ?></td></tr></table></td>
388 <td valign="top"><ul>
392 <tr><td><?php print("<a href=\"$base.pdf\">".img("img/adobe-pdficon-alpha.".(image_supported("image/png") ? "png" : "gif"),
393 "Adobe PDF")."</a>"); ?></td>
394 <td><?php print(data_href("$base.pdf","Dokument PDF")); ?></td>
399 <tr><td><a href="http://www.adobe.com/products/acrobat/readstep.html"><?php
400 print(img("img/adobe-getacro.".(image_supported("image/png") ? "png" : "gif"),"Get Adobe Acrobat Reader"));
402 <td class="smaller">Soubor je ve formátu <span class="italic">Adobe Acrobat</span>,
403 pro jeho pøeètení si prosím nainstalujte
404 <a href="http://www.adobe.com/products/acrobat/readstep.html">Adobe Acrobat Reader</a>.</td>
411 <?php print(img_href("$base.$imgfmt","Obrázkový formát ".strtoupper($imgfmt))); ?>
414 </ul></td></tr></table>
418 function format_fields_to_text($title="",$pfx="")
420 global $HTTP_POST_VARS;
439 "Text inzerátu","text",
440 "Jiné sdìlení" ,"comments",
444 $tab=($title=="" ? "" : "\t");
446 $pretty=array_shift($fields);
447 $var=$pfx.array_shift($fields);
448 if (!isset($HTTP_POST_VARS[$var]))
450 if (""==($value=trim($HTTP_POST_VARS[$var])))
452 $r.="$tab$pretty:\t$value\n";
455 $pretty=array_shift($bools);
456 $var=$pfx.array_shift($bools);
457 if (!isset($HTTP_POST_VARS[$var]))
459 $r.="$tab$pretty:\t".($HTTP_POST_VARS[$var] ? "ANO" : "NE")."\n";
462 $pretty=array_shift($texts);
463 $var=$pfx.array_shift($texts);
464 if (!isset($HTTP_POST_VARS[$var]))
466 if (""==($value=trim(ereg_replace("[\r\n]+","\n",$HTTP_POST_VARS[$var]))))
468 $r.="$tab$pretty:".ereg_replace("\n","\\0\t","\n".$value)."\n";
470 if ($r!="" && $title!="")
475 function stamp_line()
477 return("stamp:\t".date("r")."\n");
480 function return_back($what)
485 .(!$have_js ? "" : "<input type=\"button\" value=\"")
487 .(!$have_js ? " (tlaèítkem "
488 .""<span class=\"quote\">Zpìt</span>" èi "
489 .""<span class=\"quote\">Back</span>" prohlí¾eèe)"
490 : "\" onclick=\"history.back()\" />")
494 // Data acquision error checking:
495 function datacheck_fail()
497 print("<p>Nyní se prosím ".return_back("vra»te zpìt")
498 ." na pøedchozí stránku a chybu zadaných dat opravte.</p>\n");
502 function mail_data($title,$data)
504 global $admin_mail,$mail_to;
506 // 5th mail argument is supported from PHP-4.0.5
507 return (!mail($mail_to,"EnergieWeb: $title",$data,
508 "From: EnergieWeb <$admin_mail>
510 Content-Type: text/plain; charset=iso-8859-2
511 Content-Disposition: inline
512 Content-Transfer-Encoding: 8bit
516 function gsm_row($name,$value)
518 return("<tr><td align=\"left\">$name</td>"
519 ."<td align=\"right\">".($value=="" ? "neuvádìjte" : $value)."</td>"
520 ."<td align=\"right\">".strtr($value,"/.","#*")."</td></tr>\n");
523 function gsm_table($total,$varsym)
525 global $firma_ucet,$firma_konstsym,$firma_specsym;
527 return("<blockquote><table border=\"1\" cellpadding=\"5\">\n"
528 ."<tr><th>polo¾ka</th><th>bankovní pøíkaz</th><th>".gsm_banking()."</th></tr>\n"
529 .gsm_row("Èíslo úètu",$firma_ucet)
530 .gsm_row("Èástka",sprintf("%.2f",$total))
531 .gsm_row("Konstantní symbol",$firma_konstsym)
532 .gsm_row("Variabilní symbol",$varsym)
533 .gsm_row("Specifický symbol",$firma_specsym)
534 ."</table></blockquote>\n"
538 function return_to_homepage()
540 global $HTTP_SERVER_VARS;
542 return("<p>Nyní se mù¾ete vrátit na <a href=\"".dirnameslashed($HTTP_SERVER_VARS["SCRIPT_NAME"])."\">úvodní stránku</a>.</p>\n");
545 function input_text($name,$size,$default_value="",$addons="")
547 $r="<input type=\"text\" name=\"$name\" size=\"$size\"";
548 $value=(isset($GLOBALS[$name]) ? $GLOBALS[$name] : $default_value);
550 $r.=" value=\"".htmlspecialchars($value)."\"";
555 function print_form_radkova_inzerce($readonly,$total,$submit_name,$submit_value)
557 global $have_js,$text,$doklad;
559 $addons=(!$readonly ? "" : " readonly=\"readonly\"");
562 <form action="inzerat-submit.php<?php print($have_js); ?>" method="post">
563 <table border="1" width="100%" cellpadding="5">
564 <tr><td align="center"><table border="0">
565 <tr><td align="left" class="tab-head">Text inzerátu</td></tr>
566 <tr><td align="center"><?php
567 print("<textarea name=\"text\" rows=\"7\" cols=\"60\""
568 .($readonly ? "" : " onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")
570 .(!isset($text) ? "" : htmlspecialchars(trim($text)))
574 if ($have_js || $total!="") {
576 <tr><td colspan="3"><hr /></td></tr>
577 <tr><td colspan="3" id="celkova_cena">Celková cena:
578 <input type="text" name="total" value="<?php
579 print(htmlspecialchars($total));
580 ?>" size="8" readonly="readonly" /></td></tr>
585 <tr><td align="left"><table border ="0" width="100%">
586 <tr><td>Název firmy / Jméno:</td ><td colspan="3"><?php print(input_text("name" ,60,"",$addons)); ?></td></tr>
587 <tr><td>Úplná adresa:</td ><td colspan="3"><?php print(input_text("adresa",60,"",$addons)); ?></td></tr>
588 <tr><td>Telefon:</td ><td colspan="3"><?php print(input_text("tel" ,25,"",$addons)); ?></td></tr>
589 <tr><td>IÈO:</td ><td ><?php print(input_text("ico" ,20,"",$addons)); ?></td>
590 <td>DIÈ</td ><td ><?php print(input_text("dic" ,20,"",$addons)); ?></td></tr>
591 <tr><td id="danovy_doklad"
592 >Zaslat daòový doklad?</td><td colspan="3"><input type="checkbox" name="doklad"<?php
594 // some hacks as "readonly" not supported for "checkbox"es (->"disabled" for them)
595 .($readonly ? "" : " onclick=\"sum_total(this)\"")
596 .(!($have_js || $readonly) ? "" : " disabled=\"disabled\"")
597 .(!isset($doklad) ? "" : " checked=\"checked\"")
598 .ereg_replace(" readonly=\"readonly\"","",$addons)." />");
600 <tr><td id="pocet_zverejneni"
601 >Poèet zveøejnìní:</td ><td ><?php print(input_text("pocet",5,1,
602 $addons." onkeyup=\"sum_total(this)\" onchange=\"sum_total(this)\"")); ?></td>
603 <td>e-mail:</td ><td ><?php print(input_text("mail",40,"",$addons)); ?></td></tr>
605 <tr><td align="center" id="submit_button"><?php
606 print("<input type=\"submit\" name=\"$submit_name\" value=\"".htmlspecialchars($submit_value)."\""
607 ." onclick=\"return(validate(this.form))\" />");
614 function footer_img($url,$text,$size)
616 global $footer_LOCAL;
617 if (!isset($footer_LOCAL))
618 return("<img src=\"$url\" $size alt=\"$text\" />");
623 function footer($delimit=true)
625 // deadlock prevention:
626 global $footer_passed;
627 if (isset($footer_passed))
631 global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS;
633 print("<p> </p>\n");
634 $uri="uri=".addpercents("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]);
637 <table border="0" width="100%">
638 <tr><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><a
639 href="http://validator.w3.org/check?<?php
640 print($uri); ?>"><?php
641 print footer_img("http://www.w3.org/Icons/valid-xhtml11","Valid XHTML 1.1!",img_size(88,31));
642 ?></a><a href="http://jigsaw.w3.org/css-validator/validator?warning=2&profile=css2&<?php
643 print($uri); ?>"><?php
644 print footer_img("http://jigsaw.w3.org/css-validator/images/vcss","Valid CSS!",img_size(88,31));
652 // Stolen from: php-manual.html#function.header
655 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
656 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified
657 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
658 header("Pragma: no-cache"); // HTTP/1.0
661 function heading($title=false)
663 global $HTTP_SERVER_VARS,$msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head,$heading_done,$title_prefix,$force_charset;
665 if (isset($heading_done))
669 if (isset($force_charset))
670 $client_charset=$force_charset;
672 $client_charset=(!isset($HTTP_SERVER_VARS["CLIENT_CHARSET"]) ? "iso-8859-2" : $HTTP_SERVER_VARS["CLIENT_CHARSET"]);
673 // When "CLIENT_CHARSET" is set we MUST NOT explicitely specify our "charset"
674 header("Content-type: text/html".(isset($HTTP_SERVER_VARS["CLIENT_CHARSET"]) ? "" : "; charset=$client_charset"));
675 header("Content-Style-Type: text/css");
676 if (!isset($msie_major) || $msie_major>=4) {
677 print('<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n");
680 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
681 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs">
683 print("<title>$title_prefix");
684 if (isset($title_tail))
685 print(": ".htmlspecialchars($title_tail));
688 ?><style type="text/css"><!--
689 .cvs-id { font-family: monospace; }
690 .error { color: red; background-color: transparent; }
691 .quote { font-family: monospace; }
692 .nowrap { white-space: nowrap; }
693 .centered { text-align: center; }
694 .tab-bold { font-weight: bold; }
695 .tab-head { font-weight: bold; color: yellow; background-color: transparent; }
697 background-color: black;
700 :link { color: aqua; background-color: transparent; }
701 :visited { color: teal; background-color: transparent; }
702 h1,h2 { color: yellow; background-color: transparent; }
704 if (isset($head_css))
705 print(trim($head_css)."\n");
706 print("--></style>\n");
710 print("</head><body");
711 if (isset($mozilla_major) && $mozilla_major==4)
712 print(" bgcolor=\"black\" text=\"white\" link=\"aqua\" vlink=\"teal\"");
715 print("<h1 class=\"centered\">"
716 .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze")