Implemented automatic MySQL updating from "energie.txt" datafile
[www.energie.vellum.cz.git] / common.php
index 1d4c8c7..4c6a1aa 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="";
@@ -40,7 +43,7 @@ function fatal($msg="UNKNOWN")
 {
        global $admin_mail;
 
-       print("\n<br /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
+       print("\n<p>&nbsp;<br />&nbsp;</p><hr /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
                        ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
        footer();
 }
@@ -102,6 +105,14 @@ function db_row($query)
        return($r);
 }
 
+function db_array($query)
+{
+       $q=db_query($query);
+       $r=mysql_fetch_array($q);
+       mysql_free_result($q);
+       return($r);
+}
+
 function db_item($query)
 {
        $row=db_row($query);
@@ -147,7 +158,10 @@ function month_a($year,$month,$month_last=0,$sequential=0)
 
 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="")
@@ -204,11 +218,14 @@ function title_month($year,$month)
 
 function title_icons_table_month($year,$month,$month_last,$sequential)
 {
+       global $tb_clanek;
+
        $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_full"])."</a><br />"
-                       ."<a href=\"obsah.php?year=$year&amp;month=$month\">obsah ".$month_a["name"]."</a>"
-                       );
+                       ."<a href=\"obsah.php?year=$year&amp;month=$month\">obsah ".$month_a["name"]."</a>");
+       if (db_item("select count(*) from $tb_clanek where year=$year and month=$month"))
+               print("<br /><a href=\"clanek.php?year=$year&amp;month=$month\">ukázka èlánkù</a>");
 }
 
 function title_icons($year,$month)
@@ -298,7 +315,16 @@ function image_supported($mime)
        return(false);
 }
 
-function footer()
+// PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
+function dirnameslashed($filename)
+{
+       $r=dirname($filename);
+       if (substr($r,-1)!="/")
+               $r.="/";
+       return($r);
+}
+
+function footer($delimit=true)
 {
        // deadlock prevention:
        global $footer_passed;
@@ -307,8 +333,9 @@ function footer()
        $footer_passed=true;
 
        global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS;
+       if ($delimit)
+               print("<p>&nbsp;</p>\n");
        ?>
-<p>&nbsp;</p>
 <hr />
 <table border="0" width="100%">
 <tr><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><a
@@ -335,7 +362,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)
@@ -345,9 +372,10 @@ function heading()
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
 <head><title>Energie &amp; peníze<?php
        if (isset($title_tail))
-               print(": $title_tail");
-?></title>
-<style type="text/css"><!--
+               print(": ".htmlspecialchars($title_tail));
+       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; }
@@ -359,9 +387,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");