Contents appendixes implemented
[www.energie.vellum.cz.git] / common.php
index 327304b..1d4c8c7 100644 (file)
@@ -108,19 +108,40 @@ 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);
 }
 
@@ -161,7 +182,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 +202,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 +221,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 +267,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"];
                }