franta-hg@3: getMessage()); franta-hg@3: //header("Location: chyba_db.php"); franta-hg@3: exit(); franta-hg@3: } franta-hg@3: franta-hg@3: set_exception_handler('exception_handler'); franta-hg@3: franta-hg@3: session_set_cookie_params(0, $NASTAVENI['cookie_cesta']); franta-hg@3: session_start(); franta-hg@3: franta-hg@3: franta-hg@3: $strankaP = split('/', $_SERVER['REQUEST_URI']); franta-hg@3: $stranka = $strankaP[count($strankaP)-1]; franta-hg@3: franta-hg@3: franta-hg@3: if (empty($_SERVER['HTTP_ACCEPT'])) { franta-hg@3: $mimeTyp = 'application/xhtml+xml'; franta-hg@3: } else { franta-hg@3: $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: } franta-hg@3: header("Content-Type: $mimeTyp"); franta-hg@3: //header("Content-Type: text/html"); franta-hg@3: //header("Content-Type: application/xhtml+xml"); franta-hg@3: franta-hg@3: /** $nadpis = titulek stránky + h1 */ franta-hg@3: function zahlavi($nadpis, $autorizace = true) { franta-hg@3: global $mimeTyp; franta-hg@3: if ($autorizace) { franta-hg@3: overPristup(); franta-hg@3: } franta-hg@3: franta-hg@3: html(' franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: franta-hg@3: ' . $nadpis . ' franta-hg@3: franta-hg@3: franta-hg@3:

' . $nadpis . '

'); franta-hg@3: if ($autorizace) { franta-hg@3: html('

Uživatel: ' . $_SESSION['login'] . '

'); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: /** $zobrazitNabidku = zobrazí postranní menu */ franta-hg@3: function zapati($zobrazitNabidku = true) { franta-hg@3: if ($zobrazitNabidku) { franta-hg@3: html('

Obsah

franta-hg@3: franta-hg@3: '); franta-hg@3: htmlInfoKomentar(); franta-hg@3: html(''); franta-hg@3: } else { franta-hg@3: html(''); franta-hg@3: htmlInfoKomentar(); franta-hg@3: html(''); franta-hg@3: } franta-hg@3: franta-hg@3: } franta-hg@3: franta-hg@3: function htmlInfoKomentar() { franta-hg@3: global $zacatek, $mimeTyp, $NASTAVENI; franta-hg@3: if ($NASTAVENI['ladiciKomentare']) { franta-hg@3: $konec = getMicrotime(); franta-hg@3: html(''); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: function htmlOdstavec($text) { franta-hg@3: html("

\n$text\n

"); franta-hg@3: } franta-hg@3: franta-hg@3: function html($text) { franta-hg@3: global $stranka; franta-hg@3: /** Odstraníme odkazy, které vedou na tutéž stránku */ franta-hg@3: $text = str_replace(' href="' . $stranka . '"', '', $text); franta-hg@3: franta-hg@3: echo("$text\n"); franta-hg@3: } franta-hg@3: franta-hg@3: function htmlZnacka($znacka, $text) { franta-hg@3: html("<$znacka>$text"); franta-hg@3: } franta-hg@3: franta-hg@3: function htmlTlacitkovyOdkaz($url, $text) { franta-hg@3: html('
'); franta-hg@3: } franta-hg@3: franta-hg@3: function escapuj($text, $delka = 256) { franta-hg@3: $text = str_replace("\n", "[br]", $text); franta-hg@3: $text = substr(mysql_escape_string(htmlspecialchars($text)), 0, $delka); franta-hg@3: $text = str_replace("[br]", "
", $text); franta-hg@3: //$retezec = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "\\0", $retezec); franta-hg@3: return $text; franta-hg@3: } franta-hg@3: franta-hg@3: function htmlIkonaKontrolyIP () { franta-hg@3: global $NASTAVENI; franta-hg@3: if ($NASTAVENI['kontrolovatIPadresu']) { franta-hg@3: html('Kontrola IP'); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: /** volá se na všech strákách, které vyžadují autorizaci (všechny kromě prihlaseni.php) */ franta-hg@3: function overPristup() { franta-hg@3: global $NASTAVENI; franta-hg@3: franta-hg@3: if ($_SESSION['login'] == null || !isset($_SESSION['login']) || ($NASTAVENI['kontrolovatIPadresu'] && $_SERVER['REMOTE_ADDR'] != $_SESSION['ip_adresa_klienta'])) { franta-hg@3: header("Location: prihlaseni.php"); franta-hg@3: exit(); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: /** volá se v prihlaseni.php */ franta-hg@3: function zkontrolujUzivatele($jmeno, $heslo) { franta-hg@3: global $db, $NASTAVENI; franta-hg@3: franta-hg@3: if ($NASTAVENI['hashovatHesla']) { franta-hg@3: $dotaz = $db->prepare("SELECT * FROM bg_uzivatel WHERE login = ? AND sha1(concat(?, heslo)) = ?"); franta-hg@3: $dotaz->bindParam(1, $jmeno); franta-hg@3: $dotaz->bindParam(2, $_SESSION['hesloBordel']); franta-hg@3: $dotaz->bindParam(3, $heslo); franta-hg@3: $dotaz->execute(); franta-hg@3: $r = $dotaz->fetchAll(); franta-hg@3: } else { franta-hg@3: $dotaz = $db->prepare("SELECT * FROM bg_uzivatel WHERE login = ? AND heslo = sha1(?)"); franta-hg@3: $dotaz->bindParam(1, $jmeno); franta-hg@3: $dotaz->bindParam(2, $heslo); franta-hg@3: $dotaz->execute(); franta-hg@3: $r = $dotaz->fetchAll(); franta-hg@3: } franta-hg@3: franta-hg@3: foreach ($r as $x) { franta-hg@3: $_SESSION['login'] = $x['login']; franta-hg@3: $_SESSION['ip_adresa_klienta'] = $_SERVER['REMOTE_ADDR']; franta-hg@3: return true; franta-hg@3: } franta-hg@3: franta-hg@3: $_SESSION['login'] = null; franta-hg@3: return false; franta-hg@3: } franta-hg@3: franta-hg@3: franta-hg@3: function sqlZjistiHodnotu($dotaz, $parametry = null) { franta-hg@3: global $db; franta-hg@3: franta-hg@3: $dotaz = $db->prepare($dotaz); franta-hg@3: franta-hg@3: if ($parametry != null) { franta-hg@3: for($i = 0; $i < count($parametry); $i++) { franta-hg@3: $dotaz->bindParam($i+1, $parametry[$i]); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: $dotaz->execute(); franta-hg@3: $r = $dotaz->fetchAll(); franta-hg@3: franta-hg@3: foreach ($r as $x) { franta-hg@3: return $x[0]; franta-hg@3: } franta-hg@3: return null; franta-hg@3: } franta-hg@3: franta-hg@3: function sqlDotaz($dotaz, $parametry = null) { franta-hg@3: global $db; franta-hg@3: try { franta-hg@3: $dotaz = $db->prepare($dotaz); franta-hg@3: franta-hg@3: if ($parametry != null) { franta-hg@3: for($i = 0; $i < count($parametry); $i++) { franta-hg@3: $dotaz->bindParam($i+1, $parametry[$i]); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: $dotaz->execute(); franta-hg@3: $r = $dotaz->fetchAll(); franta-hg@3: franta-hg@3: return $r; franta-hg@3: } catch (PDOException $e) { franta-hg@3: logujChybu("sqlDotaz($dotaz)"); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: function getMicrotime(){ franta-hg@3: list($usec, $sec) = explode(" ",microtime()); franta-hg@3: return ((float)$usec + (float)$sec); franta-hg@3: } franta-hg@3: franta-hg@3: function sqlHtmlTabulka($dotaz, $hlavicky = null, $parametry = null, $htmlID = null) { franta-hg@3: global $db; franta-hg@3: franta-hg@3: $dotaz = $db->prepare($dotaz); franta-hg@3: franta-hg@3: if ($parametry != null) { franta-hg@3: for($i = 0; $i < count($parametry); $i++) { franta-hg@3: $dotaz->bindParam($i+1, $parametry[$i]); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: $dotaz->execute(); franta-hg@3: $r = $dotaz->fetchAll(); franta-hg@3: franta-hg@3: if ($htmlID == null) { franta-hg@3: $htmlID = getMicrotime(); franta-hg@3: } franta-hg@3: franta-hg@3: franta-hg@3: html(''); franta-hg@3: if ($hlavicky != null) { franta-hg@3: html(''); franta-hg@3: foreach ($hlavicky as $h) { franta-hg@3: htmlZnacka('td', $h); franta-hg@3: } franta-hg@3: html(''); franta-hg@3: $pocet = count($hlavicky); franta-hg@3: } else { franta-hg@3: $pocet = null; franta-hg@3: } franta-hg@3: html(''); franta-hg@3: franta-hg@3: foreach ($r as $x) { franta-hg@3: html(''); franta-hg@3: if ($pocet == null) { franta-hg@3: /** děleno 2 protože jsou tam číselné i řetězcové klíče */ franta-hg@3: $pocet = count($x) / 2; franta-hg@3: } franta-hg@3: franta-hg@3: for ($i = 0; $i < $pocet; $i++) { franta-hg@3: htmlZnacka('td', $x[$i]); franta-hg@3: } franta-hg@3: html(''); franta-hg@3: } franta-hg@3: html('
'); franta-hg@3: } franta-hg@3: franta-hg@3: franta-hg@3: function htmlTabulkaUzivatelu() { franta-hg@3: sqlHtmlTabulka('SELECT concat(concat(concat(concat(\'\'),login),\'\'), jmeno, prijmeni, email FROM bg_uzivatel', array('Login', 'Jméno', 'Příjmení', 'e-mail')); franta-hg@3: } franta-hg@3: franta-hg@3: function htmlTabulkaProduktu() { franta-hg@3: sqlHtmlTabulka('SELECT kod, nazev, popis FROM bg_produkt', array('Kód', 'Název', 'Popis')); franta-hg@3: } franta-hg@3: franta-hg@3: franta-hg@3: function sqlHtmlTabulkaBugu($r) { franta-hg@3: if (count($r) > 0) { franta-hg@3: $htmlID = getMicrotime(); franta-hg@3: html(''); franta-hg@3: html(''); franta-hg@3: htmlZnacka('td', 'Číslo'); franta-hg@3: htmlZnacka('td', 'Název'); franta-hg@3: htmlZnacka('td', 'Zadavatel'); franta-hg@3: htmlZnacka('td', 'Řešitel'); franta-hg@3: //htmlZnacka('td', 'Datum'); franta-hg@3: html(''); franta-hg@3: franta-hg@3: foreach ($r as $x) { franta-hg@3: html(''); franta-hg@3: htmlZnacka('td', '' . $x['id'] . ''); franta-hg@3: htmlZnacka('td', $x['nazev']); franta-hg@3: htmlZnacka('td', odkazNaUzivatele($x['zadavatel'])); franta-hg@3: htmlZnacka('td', odkazNaUzivatele($x['resitel'])); franta-hg@3: //htmlZnacka('td', $x['datum']); franta-hg@3: html(''); franta-hg@3: } franta-hg@3: html('
'); franta-hg@3: } else { franta-hg@3: htmlOdstavec('Nic nenalezeno.'); franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: function odkazNaUzivatele($uzivatel) { franta-hg@3: if ($uzivatel == '-') { franta-hg@3: return '-'; franta-hg@3: } else { franta-hg@3: return '' . $uzivatel . ''; franta-hg@3: } franta-hg@3: } franta-hg@3: franta-hg@3: function logujChybu($popis, $chyba = null) { franta-hg@3: htmlOdstavec($popis); franta-hg@3: } franta-hg@3: franta-hg@3: ?>