3 error_reporting(E_ALL);
7 // $viewcvs prepared by "config.php"
8 if ($viewcvs==$HTTP_SERVER_VARS["SCRIPT_NAME"])
10 $cvs_id_split=split(" ",$cvs_id);
11 if (count($cvs_id_split)==8) {
12 $cvs_id_split[1]="<a href=\"$viewcvs\">".$cvs_id_split[1]."</a>";
13 $cvs_id_split[5]="<a href=\"mailto:".$cvs_id_split[5]."@".$HTTP_SERVER_VARS["HTTP_HOST"]."\">".$cvs_id_split[5]."</a>";
15 $cvs_id_html=join(" ",$cvs_id_split);
17 $have_js=(isset($HTTP_GET_VARS["have_js"]) || isset($HTTP_POST_VARS["have_js"])
19 if (isset($detect_js) && !$have_js)
20 $head.='<script type="text/javascript" src="have_js.js"></script>'."\n";
22 $user_agent=$HTTP_SERVER_VARS["HTTP_USER_AGENT"];
23 if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a))
24 $msie_major=$msie_major_a[1];
25 else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
26 $mozilla_major=$mozilla_major_a[1];
28 $have_style=!isset($mozilla_major) || $mozilla_major!=4;
29 $have_css=true; // doesn't hurt anybody AFAIK
31 function addpercents($url)
34 foreach(preg_split('//', $url, -1, PREG_SPLIT_NO_EMPTY) as $c)
35 if (ereg("[a-zA-Z0-9]",$c))
38 $r.=sprintf("%%%02X",ord($c));
42 function fatal($msg="UNKNOWN")
46 print("\n<p> <br /> </p><hr /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
47 ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
51 function prepvar($name,$regex=".",$require=true)
53 global $HTTP_GET_VARS,$HTTP_POST_VARS;
55 if (isset($HTTP_GET_VARS[$name]))
56 $v=$HTTP_GET_VARS[$name];
57 else if (isset($HTTP_POST_VARS[$name]))
58 $v=$HTTP_POST_VARS[$name];
62 $name_html="Parametr <span class=\"quote\">".htmlspecialchars($name)."</span>";
65 if (isset($v) && !ereg($regex,$v))
66 fatal("$name_html nevyhovuje po¾adovanému regexu <span class=\"quote\">".htmlspecialchars($regex)."</span>");
67 if (!isset($v) && $require)
68 fatal("$name_html je vy¾adován");
79 global $db_host,$db_user,$db_pwd,$db_name;
84 if (!($db_link=mysql_connect($db_host,$db_user,$db_pwd)))
85 fatal("MySQL connect: ".mysql_error());
86 if (!mysql_select_db($db_name,$db_link))
87 fatal("MySQL database select: ".mysql_error());
90 function db_query($query)
95 if (!($r=mysql_query($query,$db_link)))
96 fatal("MySQL query \"$query\": ".mysql_error());
100 function db_row($query)
103 $r=mysql_fetch_row($q);
104 mysql_free_result($q);
108 function db_array($query)
111 $r=mysql_fetch_array($q);
112 mysql_free_result($q);
116 function db_item($query)
122 function num2greg($num)
125 $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M");
126 krsort($vals,SORT_NUMERIC);
127 foreach($vals as $val=>$sym) {
128 while ($num<0 && $num+$val<-$num) {
129 $r=substr($r,0,-1).$sym.substr($r,-1,1);
132 while (10*$num>=8*$val+(substr($val,0,1)=="1")) {
140 function month_a($year,$month,$month_last=0,$sequential=0)
142 global $tb_obsah,$obsah_year_base;
144 if (!$month_last || !$sequential)
145 list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'");
146 $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last);
148 $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full,
149 "name"=>"$month" .($month==$month_last ? "" : "-$month_last")."/$year",
150 "img" =>"img/eap-$year-${month_full}.jpeg",
151 "icon"=>"img/eap-$year-${month_full}s.jpeg",
153 $r["name_full"]=$r["name"]
154 ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")"
155 ." - ".num2greg($year-$obsah_year_base+1).". roèník";
159 function img_size($width,$height)
163 return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"")
164 ." width=\"$width\" height=\"$height\"");
167 function img($file,$alt,$attrs="")
169 list($width,$height)=getimagesize($file);
170 return("<img src=\"$file\" alt=\"".htmlspecialchars($alt)."\" ".img_size($width,$height)
171 .($attrs=="" ? "" : " ".$attrs)." />");
174 function gsm_banking()
176 return(img("img/sluzby_bankovni_pggsm.gif","Paegas GSM banking","class=\"img-align\""));
181 if (!($f=fopen("objednavka.js","r")))
182 fatal("Nepodaøilo se naèíst seznam dostupného zbo¾í");
184 while (($s=fgets($f,0x1000))) {
187 if (!(ereg("^want_price\\[ *'([^']*)'\\]=([0-9]*);$",$s,$matched)))
189 $r[$matched[1]]=$matched[2];
195 function title_name($year,$month)
197 if (isset($year) && isset($month)) {
198 $month_a=month_a($year,$month);
199 return("Èíslo ".$month_a["name_full"]);
201 else if (isset($year))
202 return("Roèník $year");
204 return("V¹echny roèníky");
207 function title_month($year,$month)
209 $month_a=month_a($year,$month);
211 ."<table border=\"0\" width=\"100%\">\n"
212 ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
213 ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
214 ."</table></td></tr>\n"
219 function title_icons_table_month($year,$month,$month_last,$sequential)
223 $month_a=month_a($year,$month,$month_last,$sequential);
224 print("<a href=\"title.php?year=$year&month=$month\">"
225 .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."</a><br />"
226 ."<a href=\"obsah.php?year=$year&month=$month\">obsah ".$month_a["name"]."</a>");
227 if (db_item("select count(*) from $tb_clanek where year=$year and month=$month"))
228 print("<br /><a href=\"clanek.php?year=$year&month=$month\">ukázka èlánkù</a>");
231 function title_icons($year,$month)
236 .(isset($year) ? "<a name=\"year_$year\">" : "")
237 .title_name(&$year,&$month)
238 .(isset($year) ? "</a>" : "")
241 $result=db_query("select year,month,month_last,sequential from $tb_obsah"
242 .(isset($year) || isset($month) ? " where" : "")
243 .(isset($year ) ? " year=$year" : "")
244 .(isset($year) && isset($month) ? " and" : "")
245 .(isset($month) ? " month=$month" : "")
246 ." order by year,month");
249 // $year variable changes its meaning here!!!
256 while ($row=mysql_fetch_array($result)) {
258 $row["month_last"]--;
260 if ($row["year"]!=$year) {
261 print($fin_split.$fin_year);
265 .(!isset($wanted_year) ? "<p><a name=\"year_$year\"> </a></p>" : "")
266 ."<table border=\"0\" width=\"100%\"><tr><td align=\"center\"><table border=\"1\" cellpadding=\"5\">\n"
267 ."<tr><th colspan=\"$split\">Roèník $year (<a href=\"obsah.php?year=$year\">obsahy èísel</a>)</th></tr>\n"
269 $fin_year="</table></td></tr></table>\n";
274 while ($floor<floor($row["month"]/$split)) {
275 print($fin_split."<tr>");
276 $fin_split="</tr>\n";
278 $month=$floor*$split-1;
280 while ($month+1<$row["month"]) {
284 print("<td align=\"center\""
285 .($row["month_last"]!=$row["month"] ? " colspan=\"".($row["month_last"]+1-$row["month"])."\"" : "")
287 title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"]);
289 $month=$row["month_last"];
291 mysql_free_result($result);
292 print($fin_split.$fin_year);
295 function title($year,$month)
297 if (isset($year) && isset($month))
298 return(title_month( $year, $month));
300 return(title_icons(&$year,&$month));
303 function image_supported($mime)
305 global $HTTP_SERVER_VARS;
307 if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"]))
309 $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]);
310 while (($s=array_shift($exp))) {
311 $s=trim(ereg_replace(";.*","",$s));
318 // PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
319 function dirnameslashed($filename)
321 $r=dirname($filename);
322 if (substr($r,-1)!="/")
327 function usersize($size)
329 $suffix_a=array("","k","M","G","T");
330 while ($size>=1000 && sizeof($suffix_a)>=2) {
332 array_shift($suffix_a);
334 return(round($size)." ".$suffix_a[0]."B");
337 function data_href($filename,$text)
339 return("<a href=\"$filename\">$text (".usersize(filesize($filename)).")</a>");
342 function footer($delimit=true)
344 // deadlock prevention:
345 global $footer_passed;
346 if (isset($footer_passed))
350 global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS;
352 print("<p> </p>\n");
355 <table border="0" width="100%">
356 <tr><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><a
357 href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
358 <?php print(img_size(88,31)); ?> alt="Valid XHTML 1.0!" /></a><a
359 href="http://jigsaw.w3.org/css-validator/validator?warning=2&profile=css2&uri=<?php
360 print(addpercents("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]));
361 ?>"><img src="http://jigsaw.w3.org/css-validator/images/vcss"
362 <?php print(img_size(88,31)); ?> alt="Valid CSS!" /></a></td></tr>
369 // Stolen from: php-manual.html#function.header
372 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
373 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); // always modified
374 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
375 header("Pragma: no-cache"); // HTTP/1.0
378 function heading($title=false)
380 global $msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head;
382 header("Content-type: text/html; charset=iso-8859-2");
383 if (!isset($msie_major) || $msie_major>=4)
384 print('<?xml version="1.0" encoding="iso-8859-2"?>'."\n");
386 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
387 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
388 <head><title>Energie & peníze<?php
389 if (isset($title_tail))
390 print(": ".htmlspecialchars($title_tail));
393 ?><style type="text/css"><!--
394 .cvs-id { font-family: monospace; }
395 .error { color: red; background-color: transparent; }
396 .quote { font-family: monospace; }
397 .nowrap { white-space: nowrap; }
398 .centered { text-align: center; }
400 background-color: black;
403 :link { color: aqua; background-color: transparent; }
404 :visited { color: teal; background-color: transparent; }
405 h1,h2 { color: yellow; background-color: transparent; }
407 if (isset($head_css))
408 print(trim($head_css)."\n");
409 print("--></style>\n");
413 print("</head><body");
414 if (isset($mozilla_major) && $mozilla_major==4)
415 print(" bgcolor=\"black\" text=\"white\" link=\"cyan\" vlink=\"teal\"");
418 print("<h1 class=\"centered\">"
419 .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze")