From 12734da8826299ffd24c0a15f6dbf205892d7221 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 14 Apr 2014 08:35:13 +0200 Subject: Pushed to v3 --- www/quote.php | 68 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) (limited to 'www/quote.php') diff --git a/www/quote.php b/www/quote.php index b0bc136..70b1b84 100644 --- a/www/quote.php +++ b/www/quote.php @@ -3,26 +3,29 @@ /* Copyright Maximilian Möhring, 2013 Licensed under the GPL. Read LICENSE for more Information.*/ -include('auth.php'); -include("header.php"); +function print_quote($db){ + include("static/header.php"); -$zufall = $_GET["id"]; + if(!empty($_GET["id"])){ + $zufall = $_GET["id"]; + } else { + $zufall = ""; + } -/*__Datenbank___*/ -$db = new SQLite3("../database/database.sqlite"); -$rows = $db->query("SELECT count(*) as count FROM sprueche;"); -$row = $rows->fetchArray(); -$numRows = $row["count"]; + /*__Datenbank___*/ + $rows = $db->query("SELECT count(*) as count FROM sprueche;"); + $row = $rows->fetchArray(); + $numRows = $row["count"]; -if ($zufall == ""){ - $zufall = mt_rand(1,$numRows); -} + if ($zufall == ""){ + $zufall = mt_rand(1,$numRows); + } -$safe_zufall = SQLite3::escapeString("$zufall"); -$ergebnis = $db->query("SELECT * FROM sprueche where id=$safe_zufall;"); + $safe_zufall = SQLite3::escapeString("$zufall"); + $ergebnis = $db->query("SELECT * FROM sprueche where id=$safe_zufall;"); -echo" + echo"

@@ -33,23 +36,24 @@ echo"


-Zitat Nummer #$zufall

"; +Zitat Nummer #$zufall

+ "; -if (preg_match('/[0-9]/',$zufall)){ // I really need this hack to get the 404 when /[0-9][a-zA-Z]/ is happening. Bad PHP! - if (preg_match('/[^0-9]/',$zufall)){ - $zufall = 0; + if (preg_match('/[0-9]/',$zufall)){ // I really need this hack to get the 404 when /[0-9][a-zA-Z]/ is happening. Bad PHP! + if (preg_match('/[^0-9]/',$zufall)){ + $zufall = 0; + } } -} -if ($zufall > 0 && $zufall <= ($numRows)){ - while($row=$ergebnis->fetchArray()){ - echo $row["spruch"]; - } -} else { -echo "\"Sorry, can't find the quote, but a cat is fine too, right?\"

+ if ($zufall > 0 && $zufall <= ($numRows)){ + while($row=$ergebnis->fetchArray()){ + echo $row["spruch"]; + } + } else { + echo "\"Sorry, can't find the quote, but a cat is fine too, right?\"

       ,/|         _.--''^``-...___.._.,;
      /, \'.     _-'          ,--,,,--'''
@@ -58,15 +62,16 @@ echo "\"Sorry, can't find the quote, but a cat is fine too, right?\"

._.--'' ._,,, _..' .;.' (,_....----''' (,..--''


-404 - Eintrag nicht vorhanden."; -} +404 - Eintrag nicht vorhanden. + "; + } -echo "
+ echo "



-----------------------------------------------------------------

Es sind momentan $numRows Zitate in der Datenbank enthalten.

-Du suchst ein bestimmtes Zitat? Gib hier dessen Nummer ein:
+Du suchst ein bestimmtes Zitat? Gib hier dessen Nummer ein: @@ -74,6 +79,5 @@ Du suchst ein bestimmtes Zitat? Gib hier dessen Nummer ein:
-"; - -?> +"; +} -- cgit v1.2.3