php/heslo/lib/funkce.inc.php
author František Kučera <franta-hg@frantovo.cz>
Wed, 06 May 2009 00:47:06 +0200
changeset 8 26a5c15e3049
parent 4 e6abafe31efb
child 11 c1fd9aa6a6af
permissions -rwxr-xr-x
Oprava názvu obrázku → pruh.gif
     1 <?php
     2 
     3 require('nastaveni.php');
     4 
     5 $zacatek = getMicrotime();
     6 
     7 function exception_handler($exception) {
     8   html("Došlo k chybě: " . $exception->getMessage());
     9   //header("Location: chyba_db.php");
    10   exit();
    11 }
    12 
    13 set_exception_handler('exception_handler');
    14 
    15 
    16 if (empty($_SERVER['HTTP_ACCEPT'])) {
    17 	$mimeTyp = 'application/xhtml+xml';
    18 } else {
    19 	$mimeTyp = (( stristr( $_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml' ) && !preg_match("/application\/xhtml\+xml;\s*q=0(\.0)?\s*(,|$)/",$_SERVER['HTTP_ACCEPT']) ) ? 'application/xhtml+xml' : 'text/html' );
    20 }
    21 header("Content-Type: $mimeTyp");
    22 
    23 /** $nadpis = titulek stránky + h1 */
    24 function zahlavi($nadpis) {
    25 	global $mimeTyp;
    26 	
    27 	html('<?xml version="1.0" encoding="UTF-8"?>
    28 <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    29 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
    30   <head>
    31     <meta http-equiv="content-language" content="cs"/>
    32     <meta http-equiv="content-type" content="' . $mimeTyp . '; charset=UTF-8"/>
    33     <meta name="GOOGLEBOT" content="NOINDEX, NOFOLLOW"/>
    34     <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/>
    35     <link href="styl.css" type="text/css" rel="StyleSheet"/>
    36     <script type="text/javaScript" src="hlavni.js"></script>
    37     <script type="text/javaScript" src="tridenitabulky.js"></script>
    38     <title>' . $nadpis . '</title>
    39   </head>
    40   <body>  
    41 <h1>' . $nadpis . '</h1>');
    42 }
    43 
    44 function zapati() {
    45     html('</body>');
    46     htmlInfoKomentar();
    47     html('</html>');
    48 }
    49 
    50 function htmlInfoKomentar() {	
    51 	global $zacatek, $mimeTyp, $NASTAVENI;
    52 	if ($NASTAVENI['ladiciKomentare']) {
    53 		$konec = getMicrotime();
    54 		html('<!--');
    55 		html('Stránka: ' . $_SERVER['REQUEST_URI']);
    56 		html('Klient:  ' . $_SERVER['REMOTE_ADDR']);
    57 		html('MIME:    ' . $mimeTyp);
    58 		html("Začátek zpracování: $zacatek");
    59 		html("Konec zpracování:   $konec");
    60 		html('Doba zpracování:    ' . ($konec - $zacatek) . 's');	
    61 		html('-->');
    62 	}
    63 }
    64 
    65 function htmlOdstavec($text) {
    66 	html("<p>\n$text\n</p>");
    67 }
    68 
    69 function html($text) {	
    70 	global $stranka;	
    71 	/** Odstraníme odkazy, které vedou na tutéž stránku */
    72 	$text = str_replace(' href="' . $stranka . '"', '', $text);
    73 	
    74 	echo("$text\n");
    75 }
    76 
    77 function htmlZnacka($znacka, $text) {
    78 	html("<$znacka>$text</$znacka>");
    79 }
    80 
    81 function htmlTlacitkovyOdkaz($url, $text) {
    82 	html('<form action="' . $url . '"><fieldset><button>' . $text . '</button></fieldset></form>');
    83 }
    84 
    85 function sqlZjistiHodnotu($dotaz, $parametry = null) {
    86 	global $db;
    87 	
    88 	$dotaz = $db->prepare($dotaz);
    89 	
    90 	if ($parametry != null) {
    91 		for($i = 0; $i < count($parametry); $i++) {
    92 			$dotaz->bindParam($i+1, $parametry[$i]);
    93 		}
    94 	}
    95 	
    96 	$dotaz->execute();
    97 	$r = $dotaz->fetchAll();
    98 	
    99 	foreach ($r as $x) {
   100 		return $x[0];		
   101 	}
   102 	return null;
   103 }
   104 
   105 function getMicrotime(){
   106    list($usec, $sec) = explode(" ",microtime());
   107    return ((float)$usec + (float)$sec);
   108 } 
   109 
   110 function logujChybu($popis, $chyba = null) {
   111 	htmlOdstavec($popis);
   112 }
   113 
   114 ?>