MSIE 2.0 workaround to not to display "<?xml", MSIE 3.0 not tested & not trusted
[www.energie.vellum.cz.git] / common.php
1 <?php // $Id$
2
3         error_reporting(E_ALL);
4
5         $admin_mail="short@ucw.cz";
6         $viewcvs=ereg_replace("^/~short/","\\0cgi-bin/viewcvs/",$HTTP_SERVER_VARS["SCRIPT_NAME"]);
7         if ($viewcvs==$HTTP_SERVER_VARS["SCRIPT_NAME"])
8                 unset($viewcvs);
9         $cvs_id_split=split(" ",$cvs_id);
10         if (count($cvs_id_split)==8) {
11                 $cvs_id_split[1]="<a href=\"$viewcvs\">".$cvs_id_split[1]."</a>";
12                 $cvs_id_split[5]="<a href=\"mailto:".$cvs_id_split[5]."@".$HTTP_SERVER_VARS["HTTP_HOST"]."\">".$cvs_id_split[5]."</a>";
13                 }
14         $cvs_id_html=join(" ",$cvs_id_split);
15
16         $have_js=(isset($HTTP_GET_VARS["have_js"]) || isset($HTTP_POST_VARS["have_js"])
17                         ? "?have_js=1" : "");
18         if (isset($detect_js) && !$have_js)
19                 $head.='<script type="text/javascript" src="have_js.js"></script>'."\n";
20
21         if (ereg("[[:<:]]MSIE ([0-9]+)\\.",$HTTP_SERVER_VARS["HTTP_USER_AGENT"],$msie_major_a))
22                 $msie_major=$msie_major_a[1];
23
24 function addpercents($url)
25 {
26         $r=$c="";
27         foreach(preg_split('//', $url, -1, PREG_SPLIT_NO_EMPTY) as $c)
28                 if (ereg("[a-zA-Z0-9]",$c))
29                         $r.=$c;
30                 else
31                         $r.=sprintf("%%%02X",ord($c));
32         return($r);
33 }
34
35 function fatal($msg="UNKNOWN")
36 {
37         global $admin_mail;
38
39         print("\n<br /><h1 class=\"error\">Nastala chyba pøi zpracování: $msg!</h1>\n"
40                         ."<p>Mù¾ete tento problém nahlásit <a href=\"mailto:$admin_mail\">správci tohoto webu</a>.</p>\n");
41         footer();
42 }
43
44 function footer()
45 {
46         // deadlock prevention:
47         global $footer_passed;
48         if (isset($footer_passed))
49                 exit();
50         $footer_passed=true;
51
52         global $cvs_id_html,$viewcvs,$viewcvs,$HTTP_SERVER_VARS;
53         ?>
54 <hr />
55 <table border="0" width="100%">
56 <tr><td align="left"><span class="cvs-id"><?php print($cvs_id_html); ?></span></td><td align="right"><a
57         href="http://validator.w3.org/check/referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
58                 style="border:0;width:88px;height:31px" width="88" height="31" alt="Valid XHTML 1.0!" /></a><a
59         href="http://jigsaw.w3.org/css-validator/validator?warning=2&amp;profile=css2&amp;uri=<?php
60                 print(addpercents("http://".$HTTP_SERVER_VARS["HTTP_HOST"].$HTTP_SERVER_VARS["REQUEST_URI"]));
61                 ?>"><img src="http://jigsaw.w3.org/css-validator/images/vcss"
62                 style="border:0;width:88px;height:31px" width="88" height="31" alt="Valid CSS!" /></a></td></tr>
63 </table>
64 </body></html>
65         <?php
66         exit();
67 }
68
69         header("Content-type: text/html; charset=iso-8859-2");
70         if (!isset($msie_major) || $msie_major>=4)
71                 print('<?xml version="1.0" encoding="iso-8859-2"?>'."\n");
72 ?>
73 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
74 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
75 <head><title>Energie &amp; peníze<?php
76         if (isset($title_tail))
77                 print(": $title_tail");
78 ?></title>
79 <style type="text/css"><!--
80 .cvs-id { font-family: monospace; }
81 .error  { color: red; }<?php
82         if (isset($head_css))
83                 print($head_css);
84         print("--></style>\n");
85         if (isset($head))
86                 print($head);
87 ?>
88 </head><body>