CSS disabled for "Mozilla/4.[5-7]" as they will corrupt the page
[www.energie.vellum.cz.git] / common.php
index 0f9a035..89ead4d 100644 (file)
@@ -25,6 +25,8 @@
        else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
                $mozilla_major=$mozilla_major_a[1];
 
+       $have_css=!ereg("Mozilla/4\\.[5-7]",$user_agent);
+
 function addpercents($url)
 {
        $r=$c="";
@@ -108,32 +110,58 @@ function db_item($query)
        return($row[0]);
 }
 
-function month_a($year,$month,$month_last=0)
+function num2greg($num)
 {
-       global $tb_obsah;
+       $r="";
+       $vals=array(1=>"I",5=>"V",10=>"X",50=>"L",100=>"C",500=>"D",1000=>"M");
+       krsort($vals,SORT_NUMERIC);
+       foreach($vals as $val=>$sym) {
+               while ($num<0 && $num+$val<-$num) {
+                       $r=substr($r,0,-1).$sym.substr($r,-1,1);
+                       $num+=$val;
+                       }
+               while (10*$num>=8*$val+(substr($val,0,1)=="1")) {
+                       $r=$r.$sym;
+                       $num-=$val;
+                       }
+               }
+       return($r);
+}
 
-       if (!$month_last)
-               $month_last=db_item("select month_last from $tb_obsah where year='$year' and month='$month'");
+function month_a($year,$month,$month_last=0,$sequential=0)
+{
+       global $tb_obsah,$obsah_year_base;
+
+       if (!$month_last || !$sequential)
+               list($month_last,$sequential)=db_row("select month_last,sequential from $tb_obsah where year='$year' and month='$month'");
        $month_full=sprintf("%02d".($month==$month_last ? "" : "-%02d"),$month,$month_last);
 
        $r=array("year"=>$year,"month"=>$month,"month_last"=>$month_last,"month_full"=>$month_full,
-                       "name"=>"$year/${month_full}",
+                       "name"=>"$month"    .($month==$month_last ? "" : "-$month_last")."/$year",
                        "img" =>"img/eap-$year-${month_full}.jpeg",
                        "icon"=>"img/eap-$year-${month_full}s.jpeg",
                        );
+       $r["name_full"]=$r["name"]
+                       ." ($sequential".($month==$month_last ? "" : "-".($sequential+$month_last-$month)).")"
+                       ." - ".num2greg($year-$obsah_year_base+1).". roèník";
        return($r);
 }
 
-function img_size($width,$height=0)
+function img_size($width,$height)
 {
-       if (!$height)
-               list($width,$height)=getimagesize($width);
        return("style=\"border:0;width:${width}px;height:${height}px\" width=\"$width\" height=\"$height\"");
 }
 
+function img($file,$alt,$attrs="")
+{
+       list($width,$height)=getimagesize($file);
+       return("<img src=\"$file\" alt=\"".htmlspecialchars($alt)."\" ".img_size($width,$height)
+                       .($attrs=="" ? "" : " ".$attrs)." />");
+}
+
 function gsm_banking()
 {
-       return("<img src=\"img/sluzby_bankovni_pggsm.gif\"".img_size(89,31)." alt=\"Paegas GSM banking\" class=\"img-align\" />");
+       return(img("img/sluzby_bankovni_pggsm.gif","Paegas GSM banking","class=\"img-align\""));
 }
 
 function price_a()
@@ -156,12 +184,12 @@ function title_name($year,$month)
 {
             if (isset($year) && isset($month)) {
                $month_a=month_a($year,$month);
-               return("Titulní strana èísla ".$month_a["name"]);
+               return("Èíslo ".$month_a["name_full"]);
                }
        else if (isset($year))
-               return("Titulní strany roèníku $year");
+               return("Roèník $year");
        else
-               return("Titulní strany");
+               return("V¹echny roèníky");
 }
 
 function title_month($year,$month)
@@ -170,20 +198,17 @@ function title_month($year,$month)
        return(""
                        ."<table border=\"0\" width=\"100%\">\n"
                        ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
-                       ."<tr><th align=\"center\">".title_name($year,$month)."</th></tr>\n"
-                       ."<tr><td align=\"center\"><img src=\"".$month_a["img"]."\" ".img_size($month_a["img"])
-                       ." alt=\"titulní stránka ".$month_a["name"]."\" /></td></tr>\n"
+                       ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
                        ."</table></td></tr>\n"
                        ."</table>\n"
                        );
 }
 
-function title_icons_table_month($year,$month,$month_last)
+function title_icons_table_month($year,$month,$month_last,$sequential)
 {
-       $month_a=month_a($year,$month,$month_last);
+       $month_a=month_a($year,$month,$month_last,$sequential);
        print("<a href=\"title.php?year=$year&amp;month=$month\">"
-                               ."<img src=\"".$month_a["icon"]."\" ".img_size($month_a["icon"])
-                               ." alt=\"titulní stránka ".$month_a["name"]."\" /></a><br />"
+                               .img($month_a["icon"],"titulní stránka ".$month_a["name_full"])."</a><br />"
                        ."<a href=\"obsah.php?year=$year&amp;month=$month\">obsah ".$month_a["name"]."</a>"
                        );
 }
@@ -198,7 +223,7 @@ function title_icons($year,$month)
                .(isset($year) ? "</a>" : "")
                ."</h2>\n");
 
-       $result=db_query("select year,month,month_last from $tb_obsah"
+       $result=db_query("select year,month,month_last,sequential from $tb_obsah"
                        .(isset($year) || isset($month) ? " where" : "")
                        .(isset($year ) ? " year=$year"   : "")
                        .(isset($year) && isset($month) ? " and" : "")
@@ -244,7 +269,7 @@ function title_icons($year,$month)
                print("<td align=\"center\""
                                .($row["month_last"]!=$row["month"] ? " colspan=\"".($row["month_last"]+1-$row["month"])."\"" : "")
                                .">");
-               title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1);
+               title_icons_table_month($year,$row["month"]+1,$row["month_last"]+1,$row["sequential"]);
                print("</td>\n");
                $month=$row["month_last"];
                }
@@ -264,6 +289,8 @@ function image_supported($mime)
 {
        global $HTTP_SERVER_VARS;
 
+       if (!isset($HTTP_SERVER_VARS["HTTP_ACCEPT"]))
+               return(false);
        $exp=explode(",",$HTTP_SERVER_VARS["HTTP_ACCEPT"]);
        while (($s=array_shift($exp))) {
                $s=trim(ereg_replace(";.*","",$s));
@@ -310,7 +337,7 @@ function no_cache()
 
 function heading()
 {
-       global $msie_major,$mozilla_major,$title_tail,$head_css,$head;
+       global $msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head;
 
        header("Content-type: text/html; charset=iso-8859-2");
        if (!isset($msie_major) || $msie_major>=4)
@@ -321,8 +348,9 @@ function heading()
 <head><title>Energie &amp; peníze<?php
        if (isset($title_tail))
                print(": $title_tail");
-?></title>
-<style type="text/css"><!--
+       print("</title>\n");
+       if ($have_css) {
+?><style type="text/css"><!--
 .cvs-id  { font-family: monospace; }
 .error   { color: red;    background-color: transparent; }
 .quote   { font-family: monospace; }
@@ -334,9 +362,10 @@ body {
 :visited { color: teal;   background-color: transparent; }
 h1,h2    { color: yellow; background-color: transparent; }
 <?php
-       if (isset($head_css))
-               print(trim($head_css)."\n");
-       print("--></style>\n");
+               if (isset($head_css))
+                       print(trim($head_css)."\n");
+               print("--></style>\n");
+               }
        if (isset($head))
                print($head);
        print("</head><body");