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