Fixed warning when "HTTP_USER_AGENT" was not set
[www.energie.vellum.cz.git] / common.php
index 1749106..63fb898 100644 (file)
@@ -19,7 +19,7 @@
        if (isset($detect_js) && !$have_js)
                $head.='<script type="text/javascript" src="have_js.js"></script>'."\n";
 
-       $user_agent=$HTTP_SERVER_VARS["HTTP_USER_AGENT"];
+       $user_agent=(!isset($HTTP_SERVER_VARS["HTTP_USER_AGENT"]) ? "" : $HTTP_SERVER_VARS["HTTP_USER_AGENT"]);
        if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$user_agent,$msie_major_a))
                $msie_major=$msie_major_a[1];
        else if (ereg("[[:<:]]Mozilla/([0-9]+)\\.",$user_agent,$mozilla_major_a))
@@ -105,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);
@@ -210,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)
@@ -304,6 +315,30 @@ function image_supported($mime)
        return(false);
 }
 
+// PHP dirname() is broken: ("/1/2/3"=>"/1/2", "/1"->"/")
+function dirnameslashed($filename)
+{
+       $r=dirname($filename);
+       if (substr($r,-1)!="/")
+               $r.="/";
+       return($r);
+}
+
+function usersize($size)
+{
+       $suffix_a=array("","k","M","G","T");
+       while ($size>=1000 && sizeof($suffix_a)>=2) {
+               $size/=1000;
+               array_shift($suffix_a);
+               }
+       return(round($size)." ".$suffix_a[0]."B");
+}
+
+function data_href($filename,$text)
+{
+       return("<a href=\"$filename\">$text (".usersize(filesize($filename)).")</a>");
+}
+
 function footer($delimit=true)
 {
        // deadlock prevention:
@@ -327,7 +362,7 @@ function footer($delimit=true)
                <?php print(img_size(88,31)); ?> alt="Valid CSS!" /></a></td></tr>
 </table>
 </body></html>
-       <?php
+<?php
        exit();
 }
 
@@ -340,11 +375,11 @@ function no_cache()
        header("Pragma: no-cache");                                // HTTP/1.0
 }
 
-function heading()
+function heading($title=false)
 {
        global $msie_major,$mozilla_major,$title_tail,$head_css,$have_css,$head;
 
-       header("Content-type: text/html; charset=iso-8859-2");
+       header("Content-type: text/html");
        if (!isset($msie_major) || $msie_major>=4)
                print('<?xml version="1.0" encoding="iso-8859-2"?>'."\n");
 ?>
@@ -352,13 +387,15 @@ 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");
+               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; }
+.cvs-id   { font-family: monospace; }
+.error    { color: red;   background-color: transparent; }
+.quote    { font-family: monospace; }
+.nowrap   { white-space: nowrap; }
+.centered { text-align: center; }
 body {
                background-color: black;
                color: white;
@@ -377,5 +414,9 @@ h1,h2    { color: yellow; background-color: transparent; }
        if (isset($mozilla_major) && $mozilla_major==4)
                print(" bgcolor=\"black\" text=\"white\" link=\"cyan\" vlink=\"teal\"");
        print(">\n");
+       if ($title)
+               print("<h1 class=\"centered\">"
+                               .img("img/eap-title.".(image_supported("image/png") ? "png" : "gif"),"Energie & Peníze")
+                               ."</h1>\n");
 }
 ?>