"have_style" detection code cleanup
[www.energie.vellum.cz.git] / common.php
index 327304b..aae2fe0 100644 (file)
@@ -25,6 +25,9 @@
        else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
                $mozilla_major=$mozilla_major_a[1];
 
+       $have_style=!isset($mozilla_major) || $mozilla_major!=4;
+       $have_css=true; // doesn't hurt anybody AFAIK
+
 function addpercents($url)
 {
        $r=$c="";
@@ -108,25 +111,49 @@ 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);
+}
+
+function month_a($year,$month,$month_last=0,$sequential=0)
+{
+       global $tb_obsah,$obsah_year_base;
 
-       if (!$month_last)
-               $month_last=db_item("select month_last from $tb_obsah where year='$year' and month='$month'");
+       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"=>"$month".($month==$month_last ? "" : "-$month_last")."/$year",
+                       "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)
 {
-       return("style=\"border:0;width:${width}px;height:${height}px\" width=\"$width\" height=\"$height\"");
+       global $have_style;
+
+       return(($have_style ? "style=\"border:0;width:${width}px;height:${height}px\"" : "border=\"0\"")
+                       ." width=\"$width\" height=\"$height\"");
 }
 
 function img($file,$alt,$attrs="")
@@ -161,7 +188,7 @@ function title_name($year,$month)
 {
             if (isset($year) && isset($month)) {
                $month_a=month_a($year,$month);
-               return("Èíslo ".$month_a["name"]);
+               return("Èíslo ".$month_a["name_full"]);
                }
        else if (isset($year))
                return("Roèník $year");
@@ -181,11 +208,11 @@ function title_month($year,$month)
                        );
 }
 
-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($month_a["icon"],"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>"
                        );
 }
@@ -200,7 +227,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" : "")
@@ -246,7 +273,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"];
                }
@@ -314,7 +341,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)
@@ -325,8 +352,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; }
@@ -338,9 +366,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");