From 7b28fea35cdc9a16dc5afe2baa228ffbbfd644c9 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Tue, 24 Jan 2023 15:12:37 +0100 Subject: [PATCH] =?UTF-8?q?Code-Modernisierungen=20f=C3=BCr=20PHP-8-Kompat?= =?UTF-8?q?ibilit=C3=A4t.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zusätzlich Charsets, Linebreaks und Kommentar-Blöcke korrigiert. --- antworten.inc.php | 75 +-- barrierefreiheit.inc.php | 27 +- class.template.inc.php | 1212 +++++++++++++++++++++----------------- db.php | 124 ++-- functions.inc.php | 577 +++++++++--------- home.inc.php | 134 +++-- index.php | 218 ++++--- init.inc.php | 177 +++--- pruefbogen.inc.php | 435 +++++++------- rg-styles.css | 64 +- robots.txt | 16 +- styles.css | 246 ++++---- zufallsfragen.inc.php | 439 +++++++------- 13 files changed, 1934 insertions(+), 1810 deletions(-) diff --git a/antworten.inc.php b/antworten.inc.php index 0da6c99..936bca7 100644 --- a/antworten.inc.php +++ b/antworten.inc.php @@ -8,7 +8,7 @@ * of the * * Bundesanstalt Technisches Hilfswerk - * Provinzialstra�e 93 + * Provinzialstraße 93 * D-53127 Bonn * Germany * E-Mail: redaktion@thw.de @@ -27,15 +27,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /* - Aufl�sungen zu allen Fragen + Auflösungen zu allen Fragen */ -$tpl->addVars('navAntworten', 'current'); +$GLOBALS['tpl']->addVars('navAntworten', 'current'); $katalog = -1; if (isset($_REQUEST['katalog'])) { @@ -44,27 +44,26 @@ if (isset($_REQUEST['katalog'])) { $abschnitte = getTopics(); foreach ($abschnitte as $nr => $description) { - $tpl->addVars(Array( - 'abschnittNr' => $nr, - 'abschnittName' => htmlspecialchars($description), - 'navAntwortenAbschnitt' => ($katalog == $nr) ? 'current':'' + $GLOBALS['tpl']->addVars(array( + 'abschnittNr' => $nr, + 'abschnittName' => htmlspecialchars($description), + 'navAntwortenAbschnitt' => ($katalog == $nr) ? 'current' : '' )); - - $tpl->parseBlock('page-body', 'NavAntworten', 'Sublinks', TRUE); + + $GLOBALS['tpl']->parseBlock('page-body', 'NavAntworten', 'Sublinks', TRUE); } if (isset($_SESSION['zufallsfragen']) || isset($_SESSION['bogen'])) { - if (isset($_GET['clear']) && intval($_GET['clear']) == '1') { + if (isset($_GET['clear']) && intval($_GET['clear']) == '1') { unset($_SESSION['bogen']); unset($_SESSION['zufallsfragen']); unset($_SESSION['frage_nr']); unset($_SESSION['fragen_cnt']); unset($_SESSION['zufallstats']); unset($_SESSION['bogen']); - } - else { - $tpl->addTemplates(Array('content' => 'aufloesung-error')); - return; + } else { + $GLOBALS['tpl']->addTemplates(array('content' => 'aufloesung-error')); + return; } } @@ -78,20 +77,20 @@ if ($katalog > 0) { $stmt->bind_result($selectedNr, $selectedDescription); $stmt->fetch(); - addBreadcrumb($_REQUEST['show'].'&katalog=' . $selectedNr, $selectedDescription); + addBreadcrumb($_REQUEST['show'] . '&katalog=' . $selectedNr, $selectedDescription); - $tpl->addTemplates(Array( - 'content' => 'aufloesung-antworten' + $GLOBALS['tpl']->addTemplates(array( + 'content' => 'aufloesung-antworten' )); - $tpl->addVars(Array( - 'abschnittNr' => $selectedNr, - 'abschnittName' => htmlspecialchars($selectedDescription) + $GLOBALS['tpl']->addVars(array( + 'abschnittNr' => $selectedNr, + 'abschnittName' => htmlspecialchars($selectedDescription) )); $stmt->close(); - $stmt = $GLOBALS['db']->prepare('SELECT * FROM `fragen` WHERE `Abschnitt` = ? AND `Jahr` = ? ORDER BY Abschnitt,Nr ASC'); + $stmt = $GLOBALS['db']->prepare('SELECT * FROM `fragen` WHERE `Abschnitt` = ? AND `Jahr` = ? ORDER BY Abschnitt,Nr'); $stmt->bind_param('ii', $katalog, $_SESSION['jahr']); $stmt->execute(); $questions = $stmt->get_result(); @@ -99,33 +98,35 @@ if ($katalog > 0) { $I = 1; while ($question = $questions->fetch_array(MYSQLI_ASSOC)) { - ShowAnswer($question); - $tpl->parseBlock('content', 'Antworten', 'Row', TRUE, TRUE); - if ($I%10==0) { - $tpl->parseBlock('content', 'Antworten', 'Topline', TRUE); + ShowAnswer($question); + $GLOBALS['tpl']->parseBlock('content', 'Antworten', 'Row', TRUE, TRUE); + if ($I % 10 == 0) { + $GLOBALS['tpl']->parseBlock('content', 'Antworten', 'Topline', TRUE); } - $I++; + $I++; } $questions->close(); $stmt->close(); -} -else { +} else { - $tpl->addTemplates('content', 'aufloesung-abschnitte'); + $GLOBALS['tpl']->addTemplates('content', 'aufloesung-abschnitte'); - $stmt = $GLOBALS['db']->prepare('SELECT `Nr`,`Beschreibung` FROM `abschnitte` WHERE `Jahr` = ? ORDER BY Nr ASC'); + $nr = 0; + $description = ''; + + $stmt = $GLOBALS['db']->prepare('SELECT `Nr`,`Beschreibung` FROM `abschnitte` WHERE `Jahr` = ? ORDER BY Nr'); $stmt->bind_param('i', $_SESSION['jahr']); $stmt->execute(); $stmt->bind_result($nr, $description); while ($stmt->fetch()) { - $tpl->addVars(Array( - 'abschnittNr' => $nr, - 'abschnittName' => $description + $GLOBALS['tpl']->addVars(array( + 'abschnittNr' => $nr, + 'abschnittName' => $description )); - - $tpl->parseBlock('content', 'Abschnitte', 'Row', TRUE); + + $GLOBALS['tpl']->parseBlock('content', 'Abschnitte', 'Row', TRUE); } } -?> + diff --git a/barrierefreiheit.inc.php b/barrierefreiheit.inc.php index d58d267..4066577 100644 --- a/barrierefreiheit.inc.php +++ b/barrierefreiheit.inc.php @@ -1,15 +1,12 @@ -addVars('extraStyleSheet', ''); -} - -if (isset($_POST['barrierefrei'])) { - setcookie("stylesheet", "barrierefrei", time()+60*60*24*365); -} - -$tpl->addTemplates(Array("content" => "barrierefreiheit")); - -?> \ No newline at end of file +addVars('extraStyleSheet', ''); +} + +if (isset($_POST['barrierefrei'])) { + setcookie("stylesheet", "barrierefrei", time()+60*60*24*365); +} + +$GLOBALS['tpl']->addTemplates(Array("content" => "barrierefreiheit")); diff --git a/class.template.inc.php b/class.template.inc.php index a549228..33cee92 100644 --- a/class.template.inc.php +++ b/class.template.inc.php @@ -1,551 +1,661 @@ - - * - * The included "THW Thema" templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/************************************************************ -* Template class -* -* This class is capable of replacing variables with text, -* including other templates, and it can parse dynamic blocks -* which can be nested inside other blocks. -* -* Predefined variables: -* -* {templatePath} Contains the template path -* {templateLang} Contains the country code, if set -* -* If you don't need them, remove them immediately after -* creating the class instance or setting a new template path. -* -* $id: class Template v1.0 / Kai Blaschke $ -* -**************************************************************/ - - -class Template { - -// ************************************************************ -// Member variables - - var $TPLFILES = array(); // Contains all template filenames - var $TPLDATA = array(); // Contains all template data - var $LOADED = array(); // Already loaded templates are - // stored as $LOADED[HANDLE]=>TRUE - var $PARSEVARS = array(); // Array of variable/value pairs - // to be replaced in templates - var $HANDLES = array(); // Handles which contain parsed templates - - var $BLOCKS = array(); // Array with dynamic block data - var $H_BLOCKS = array(); // Parsed block data - - // Filename: $TPLDIR/filename[.$LANG].tpl - var $TPLDIR; // Path to template files - var $LANG; // Country code (en, de, fr, ...) - var $TPLEXT; // Filename extension (default is .tpl) - - -// ************************************************************ -// Global settings - - var $RPLBRACES = TRUE; // Safely replaces curly braces with HTML - // entities in variable values if - // set to TRUE. - var $WIN32 = FALSE; // Set to "TRUE" on Win32 systems, if - // you encounter problems with paths. - var $DIEONERR = TRUE; // If set to TRUE, die() is called in error - - - - -// ************************************************************ -// Constructor - - function Template($tpldir, $lang = "", $tplext = "tpl") - { - $this->setPath($tpldir); - $this->LANG = strtolower($lang); - $this->TPLEXT = $tplext; - - $this->addVars("templateLang", $this->LANG); - } - -// ************************************************************ -// Sets or changes the template search path - - function setPath($path) - { - if ($this->WIN32) { - if (ord(substr($path, -1)) != 92) $path .= chr(92); - } else { - if (ord(substr($path, -1)) != 47) $path .= chr(47); - } - - if (is_dir($path)) { - $this->TPLDIR = $path; - - // Add a path variable for use in templates - $this->addVars("templatePath", $path); - - return TRUE; - } else { - echo "[TEMPLATE ENGINE] The specified template path " - ."'".$path."' is invalid!
"; - - $this->TPLDIR = ""; - - if ($this->DIEONERR == TRUE) die(); - return FALSE; - } - } - -// ************************************************************ -// Get dynamic blocks recursively to enable nested blocks - - function getDynamicBlocks($tplFilename, $contents) - { - preg_match_all("/(\{\|([a-zA-Z0-9]+)\})(.*?)\\1/s", - $contents, $blocks); - - if (empty($blocks[0])) return; - - // Go through all blocks and save them in $this->BLOCKS - for ($I=0; $IgetDynamicBlocks($tplFilename, $blockparts[3][$J]); - - // Replace block data with placeholders - $blockparts[3][$J] = - preg_replace("/(\{\|([a-zA-Z0-9]+)\})(.*?)\\1/s", - "\\1", $blockparts[3][$J]); - - // Save block data - $this->BLOCKS[$tplFilename][$blocks[2][$I]][$blockparts[2][$J]] - = $blockparts[3][$J]; - - } - } - } - -// ************************************************************ -// Loads a template, runs some checks and extracts dynamic blocks - - function loadTemplate($tplFilename) - { - // Template already loaded? - if (isset($this->LOADED[$tplFilename])) return TRUE; - - // Has the path been set? - if (empty($this->TPLDIR)) { - echo "[TEMPLATE ENGINE] Template path not set or invalid!
"; - - if ($this->DIEONERR == TRUE) die(); - return FALSE; - } - - // Is a user-defined county code set? - if (!empty($this->LANG)) { - // Yes. Try to find template with the specified CC - if (file_exists($this->TPLDIR.$this->TPLFILES[$tplFilename]."." - .$this->LANG.".".$this->TPLEXT)) { - $filename = $this->TPLDIR.$this->TPLFILES[$tplFilename].".". - $this->LANG.".".$this->TPLEXT; - } else { - // Otherwise, use template filename without CC - if (file_exists($this->TPLDIR.$this->TPLFILES[$tplFilename]."." - .$this->TPLEXT)) { - $filename = $this->TPLDIR.$this->TPLFILES[$tplFilename]."." - .$this->TPLEXT; - } else { - echo "[TEMPLATE ENGINE] Can't find template " - ."'".$tplFilename."'!
"; - - if ($this->DIEONERR == TRUE) die(); - return FALSE; - } - } - } else { - // No. Use template filename without CC - if (file_exists($this->TPLDIR.$this->TPLFILES[$tplFilename]."." - .$this->TPLEXT)) { - $filename = $this->TPLDIR.$this->TPLFILES[$tplFilename]."." - .$this->TPLEXT; - } else { - echo "[TEMPLATE ENGINE] Can't find template " - ."'".$tplFilename."'!
"; - - if ($this->DIEONERR == TRUE) die(); - return FALSE; - } - } - - // Load template file - $contents = implode("", (@file($filename))); - - if (!$contents || empty($contents)) { - echo "[TEMPLATE ENGINE] Can't load template '" - .$tplFilename."'!
"; - - if ($this->DIEONERR == TRUE) die(); - return FALSE; - } - - // Parse dynamic blocks recursively - $this->getDynamicBlocks($tplFilename, $contents); - - // Replace all block data with placeholders - $contents = preg_replace("/(\{\|([a-zA-Z0-9]+)\})(.*?)\\1/s", "\\1", - $contents); - - $this->TPLDATA[$tplFilename] = $contents; - $this->LOADED[$tplFilename] = 1; - - return TRUE; - - } - -// ************************************************************ -// Parses a template and loads it if neccessary. -// The result is assigned or concatenated to the specified handle. - - function parse($handle = "", - $file = "", - $append = FALSE, - $delunused = FALSE) - { - // Check if all prerequisites are met - if (empty($handle) || empty($file)) - return FALSE; - - if (!isset($this->TPLFILES[$file])) - return FALSE; - - if (!isset($this->LOADED[$file])&&!$this->loadTemplate($file)) - return FALSE; - - $templateCopy = $this->TPLDATA[$file]; - - // Reset array pointers - reset($this->HANDLES); - reset($this->PARSEVARS); - - // Replace blocks - if (isset($this->H_BLOCKS[$file])) { - reset($this->H_BLOCKS[$file]); - - while (list($varname, $value) = each($this->H_BLOCKS[$file])) - $templateCopy = preg_replace("/\{\|".$varname."\}/i", - $value, $templateCopy); - } - - // Replace variables - while (list($varname, $value) = each($this->PARSEVARS)) - $templateCopy = preg_replace("/\{".$varname."\}/i", - $value, $templateCopy); - - // Replace {~name} placeholders with already parsed handle of - // the same name - while (list($varname, $value) = each($this->HANDLES)) - $templateCopy = preg_replace("/\{\~".$varname."\}/i", - $value, $templateCopy); - - // Delete unused variables and placeholders - if ($delunused) - $templateCopy = preg_replace("/\{[~|\|]?(\w*?)\}/", "", - $templateCopy); - - // Assign to handle - if ($append && isset($this->HANDLES[$handle])) { - $this->HANDLES[$handle] .= $templateCopy; - } else { - $this->HANDLES[$handle] = $templateCopy; - } - - return TRUE; - } - -// ************************************************************ -// Parses multiple templates. -// $list is an associative array of the type "handle"=>"template". -// Note that concatenation is not possible. Use the parse() method instead. - - function multiParse($list) - { - if (!is_array($list)) return FALSE; - - while (list($handle, $file) = each($list)) - if (!$this->parse($handle, $file)) return FALSE; - - return TRUE; - } - -// ************************************************************ -// Parses a template and prints the result. - - function printParse($handle = "", $file = "", $append = FALSE) - { - if ($this->parse($handle, $file, $append)) { - $this->printHandle($handle); - return TRUE; - } - - return FALSE; - } - -// ************************************************************ -// Parses a block and replaces or appends the result to the block handle. -// -// Note: First argument is the template file name containing the blocks, -// not a handle name! -// -// Note: This function has no effect on any template handle. -// Parsed block data is inserted into the template handle in the -// parse() method. - - function parseBlock($file = "", - $block = "", - $blockpart = "", - $append = FALSE, - $delunused = FALSE) - { - if (empty($file) || empty($block) || empty($blockpart)) - return FALSE; - - if (!isset($this->TPLFILES[$file])) - return FALSE; - - if (!isset($this->LOADED[$file])&&!$this->loadTemplate($file)) - return FALSE; - - $blockCopy = $this->BLOCKS[$file][$block][$blockpart]; - - // Reset array pointers - reset($this->H_BLOCKS); - reset($this->PARSEVARS); - - // Replace blocks - if (isset($this->H_BLOCKS[$file])) { - reset($this->H_BLOCKS[$file]); - - while (list($varname, $value) = each($this->H_BLOCKS[$file])) - $blockCopy = preg_replace("/\{\|".$varname."\}/i", - $value, $blockCopy); - } - - // Replace variables - while (list($varname, $value) = each($this->PARSEVARS)) - $blockCopy = preg_replace("/\{".$varname."\}/i", - $value, $blockCopy); - - // Replace {~name} placeholders with already parsed handle of - // the same name - while (list($varname, $value) = each($this->HANDLES)) - $blockCopy = preg_replace("/\{\~".$varname."\}/i", - $value, $blockCopy); - - // Delete unused variables and placeholders - if ($delunused) - $blockCopy = preg_replace("/\{[~|]?(\w*?)\}/", "", $blockCopy); - - // Assign to handle - if ($append && isset($this->H_BLOCKS[$file][$block])) { - $this->H_BLOCKS[$file][$block] .= $blockCopy; - } else { - $this->H_BLOCKS[$file][$block] = $blockCopy; - } - - return TRUE; - } - -// ************************************************************ -// Deletes all block handles - - function clearBlockHandles() - { - if (!empty($this->H_BLOCKS)) { - reset($this->H_BLOCKS); - while (list($ref, $val) = each($this->H_BLOCKS)) - unset($this->H_BLOCKS[$ref]); - } - } - -// ************************************************************ -// Deletes the specified block handle - - function delBlockHandle($file, $block) - { - if (!empty($file) && !empty($block)) - if (isset($this->H_BLOCKS[$file][$block])) - unset($this->H_BLOCKS[$file][$block]); - } - -// ************************************************************ -// Adds one or more templates -// You can pass one associative array with $handle=>$filename pairs, -// or two strings ($handle, $filename) to this function. - - function addTemplates($tplList, $tplFilename = "") - { - if (is_array($tplList)) { - reset($tplList); - while (list($handle, $filename) = each($tplList)) { - // Add handle to list - $this->TPLFILES[$handle] = $filename; - // Delete loaded flag if set - unset($this->LOADED[$handle]); - } - } else { - $this->TPLFILES[$tplList] = $tplFilename; - unset($this->LOADED[$tplList]); - } - } - -// ************************************************************ -// Deletes all template handles - - function clearHandles() - { - if (!empty($this->HANDLES)) { - reset($this->HANDLES); - while (list($ref, $val) = each($this->HANDLES)) - unset($this->HANDLES[$ref]); - } - } - -// ************************************************************ -// Deletes the specified template handle - - function delHandle($handleName = "") - { - if (!empty($handleName)) - if (isset($this->HANDLES[$handleName])) - unset($this->HANDLES[$handleName]); - } - -// ************************************************************ -// Returns the contents of the specified template handle - - function getHandle($handleName = "") - { - if (empty($handleName)) - return FALSE; - - if (isset($this->HANDLES[$handleName])) - return $this->HANDLES[$handleName]; - - return FALSE; - } - -// ************************************************************ -// Prints a parsed template handle - - function printHandle($handleName = "") - { - if (empty($handleName)) return FALSE; - - // Remove all remaining placeholders - $this->HANDLES[$handleName] = preg_replace("/\{[~|\|]?(\w*?)\}/", - "", $this->HANDLES[$handleName]); - - if (isset($this->HANDLES[$handleName])) { - echo $this->HANDLES[$handleName]; - return TRUE; - } - - return FALSE; - } - -// ************************************************************ -// Deletes all variables set with the addVars() method - - function clearVars() - { - if (!empty($this->PARSEVARS)) { - reset($this->PARSEVARS); - while (list($ref, $val) = each ($this->PARSEVARS)) - unset($this->PARSEVARS[$ref]); - } - } - -// ************************************************************ -// Adds one or more variables. -// You can pass one associative array with $varname=>$value pairs -// or two strings ($varname, $value) to this function. - - function addVars($varList, $varValue = "") - { - if (is_array($varList)) { - reset($varList); - while (list($varname, $value) = each($varList)) { - // Replace curly braces - if ($this->RPLBRACES == TRUE) { - $value = preg_replace(Array("/(\{)/", "/(\})/"), - Array("{", "}"), - $value); - } - - // Add/replace variable - if (!preg_match("/[^0-9a-z\-\_]/i", $varname)) - $this->PARSEVARS[$varname] = $value; - } - } else { - // Replace curly braces - if ($this->RPLBRACES == TRUE) { - $varValue = preg_replace(Array("/(\{)/", "/(\})/"), - Array("{", "}"), - $varValue); - } - - // Add/replace variable - if (!preg_match("/[^0-9a-z\-\_]/i", $varList)) - $this->PARSEVARS[$varList] = $varValue; - } - } - -// ************************************************************ -// Returns a value set by the addVars() method - - function getVar($varName = "") - { - if (empty($varName)) return FALSE; - if (isset($this->PARSEVARS[$varName])) - return $this->PARSEVARS[$varName]; - return FALSE; - } - -// ************************************************************ - -} // End of class 'Template' - -?> \ No newline at end of file + + * + * The included "THW Thema" templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/************************************************************ + * Template class + * + * This class is capable of replacing variables with text, + * including other templates, and it can parse dynamic blocks + * which can be nested inside other blocks. + * + * Predefined template variables: + * + * - {templatePath} Contains the template path + * - {templateLang} Contains the country code, if set + * + * If you don't need them, remove them immediately after + * creating the class instance or setting a new template path. + * + **************************************************************/ +class Template +{ + /** + * @var array Contains all template filenames + */ + private array $templateFiles = array(); + + /** + * @var array Contains all template data + */ + private array $templateData = array(); + + /** + * @var array Already loaded templates. + */ + private array $loadedTemplates = array(); + + /** + * @var array Array of variable/value pairs stored as $LOADED[HANDLE]=>true + */ + private array $parserVariables = array(); + + /** + * @var array Handles which contain parsed templates to be replaced in templates + */ + private array $templateHandles = array(); + + /** + * @var array Array with dynamic block data + */ + private array $templateBlocks = array(); + + /** + * @var array Parsed block data + */ + private array $parsedBlocks = array(); + + /** + * @var string Path to template files. Filename: $templateDirectory/filename[.$languageCode].tpl + */ + private string $templateDirectory; + + /** + * @var string Country code (en, de, fr, ...) + */ + private string $languageCode; + + /** + * @var string Filename extension (default is .tpl) + */ + private string $templateExtension; + + /** + * @var bool Safely replaces curly braces with HTML entities in variable values if set to true. + */ + public bool $replaceBraces = true; + + /** + * @var bool Set to "true" on Windows systems, if you encounter problems with paths. + */ + public bool $useWindowsPathSeparator = false; + + /** + * @var bool If set to true, die() is called in error + */ + public bool $dieOnError = true; + + /** + * constructor. + * @param string $tpldir The template base directory. + * @param string $lang The browser language code. + * @param string $tplext Optional. The template file extension. + */ + function __construct(string $tpldir, + string $lang = "", + string $tplext = "tpl") + { + $this->setPath($tpldir); + $this->languageCode = strtolower($lang); + $this->templateExtension = $tplext; + + $this->addVars("templateLang", $this->languageCode); + } + + /** + * Sets or changes the template search path + * @param string $path New template base directory. + * @return bool true if the path was set correctly, false if an error occurred. + */ + function setPath(string $path): bool + { + if ($this->useWindowsPathSeparator) { + if (ord(substr($path, -1)) != 92) { + $path .= chr(92); + } + } else { + if (ord(substr($path, -1)) != 47) { + $path .= chr(47); + } + } + + if (is_dir($path)) { + $this->templateDirectory = $path; + + // Add a path variable for use in templates + $this->addVars("templatePath", $path); + + return true; + } else { + echo "[TEMPLATE ENGINE] The specified template path " + . "'" . $path . "' is invalid!
"; + + $this->templateDirectory = ""; + + if ($this->dieOnError) { + die(); + } + return false; + } + } + + /** + * Get dynamic blocks recursively to enable nested blocks. + * @param string $tplFilename Template base filename. + * @param string $contents Content to search for dynamic blocks. + * @return void + */ + function getDynamicBlocks(string $tplFilename, + string $contents): void + { + preg_match_all("/(\{\|([a-zA-Z0-9]+)})(.*?)\\1/s", $contents, $blocks); + + if (empty($blocks[0])) { + return; + } + + // Go through all blocks and save them in $this->BLOCKS + for ($I = 0; $I < count($blocks[0]); $I++) { + $blockparts = array(); + + preg_match_all("/(\{\|" . $blocks[2][$I] . "\*([a-zA-Z0-9]+)})(.*?)\\1/s", $blocks[3][$I], $blockparts); + + for ($J = 0; $J < count($blockparts[0]); $J++) { + // Get nested blocks + $this->getDynamicBlocks($tplFilename, $blockparts[3][$J]); + + // Replace block data with placeholders + $blockparts[3][$J] = preg_replace("/(\{\|([a-zA-Z0-9]+)})(.*?)\\1/s", "\\1", $blockparts[3][$J]); + + // Save block data + $this->templateBlocks[$tplFilename][$blocks[2][$I]][$blockparts[2][$J]] = $blockparts[3][$J]; + + } + } + } + + /** + * Loads a template, runs some checks and extracts dynamic blocks. + * @param string $tplFilename Template base filename. + * @return bool true if the template is loaded, false if an error occurred. + */ + function loadTemplate(string $tplFilename): bool + { + // Template already loaded? + if (isset($this->loadedTemplates[$tplFilename])) { + return true; + } + + // Has the path been set? + if (empty($this->templateDirectory)) { + echo "[TEMPLATE ENGINE] Template path not set or invalid!
"; + + if ($this->dieOnError) { + die(); + } + + return false; + } + + // Is a user-defined county code set? + if (!empty($this->languageCode)) { + // Yes. Try to find template with the specified CC + if (file_exists($this->templateDirectory . $this->templateFiles[$tplFilename] . "." . $this->languageCode . "." . $this->templateExtension)) { + $filename = $this->templateDirectory . $this->templateFiles[$tplFilename] . "." . $this->languageCode . "." . $this->templateExtension; + } else { + // Otherwise, use template filename without CC + if (file_exists($this->templateDirectory . $this->templateFiles[$tplFilename] . "." . $this->templateExtension)) { + $filename = $this->templateDirectory . $this->templateFiles[$tplFilename] . "." + . $this->templateExtension; + } else { + echo "[TEMPLATE ENGINE] Can't find template " . "'" . $tplFilename . "'!
"; + + if ($this->dieOnError) { + die(); + } + + return false; + } + } + } else { + // No. Use template filename without CC + if (file_exists($this->templateDirectory . $this->templateFiles[$tplFilename] . "." . $this->templateExtension)) { + $filename = $this->templateDirectory . $this->templateFiles[$tplFilename] . "." . $this->templateExtension; + } else { + echo "[TEMPLATE ENGINE] Can't find template " . "'" . $tplFilename . "'!
"; + + if ($this->dieOnError) { + die(); + } + + return false; + } + } + + // Load template file + $contents = implode("", (@file($filename))); + + if (empty($contents)) { + echo "[TEMPLATE ENGINE] Can't load template '" . $tplFilename . "'!
"; + + if ($this->dieOnError) { + die(); + } + + return false; + } + + // Parse dynamic blocks recursively + $this->getDynamicBlocks($tplFilename, $contents); + + // Replace all block data with placeholders + $contents = preg_replace("/(\{\|([a-zA-Z0-9]+)})(.*?)\\1/s", "\\1", $contents); + + $this->templateData[$tplFilename] = $contents; + $this->loadedTemplates[$tplFilename] = 1; + + return true; + + } + + /** + * Parses a template and loads it if necessary. + * The result is assigned or concatenated to the specified handle. + * @param string $handle Result handle to store the parsed template in. + * @param string $file Template file to parse. + * @param bool $append true to append the parsed template to the given handle, false replaces the contents. + * @param bool $delunused true to delete unused variable placeholders, false to keep them for later processing. + * @return bool true if the file was parsed correctly, false if an error occurred. + */ + function parse(string $handle = "", + string $file = "", + bool $append = false, + bool $delunused = false): bool + { + // Check if all prerequisites are met + if (empty($handle) || empty($file)) { + return false; + } + + if (!isset($this->templateFiles[$file])) { + return false; + } + + if (!isset($this->loadedTemplates[$file]) && !$this->loadTemplate($file)) { + return false; + } + + $templateCopy = $this->templateData[$file]; + + // Reset array pointers + reset($this->templateHandles); + reset($this->parserVariables); + + // Replace blocks + if (isset($this->parsedBlocks[$file])) { + reset($this->parsedBlocks[$file]); + + foreach ($this->parsedBlocks[$file] as $varname => $value) { + $templateCopy = preg_replace("/\{\|" . $varname . "}/i", + $value, $templateCopy); + } + } + + // Replace variables + foreach ($this->parserVariables as $varname => $value) { + $templateCopy = preg_replace("/\{" . $varname . "}/i", + $value, $templateCopy); + } + + // Replace {~name} placeholders with already parsed handle of + // the same name + foreach ($this->templateHandles as $varname => $value) { + $templateCopy = preg_replace("/\{~" . $varname . "}/i", + $value, $templateCopy); + } + + // Delete unused variables and placeholders + if ($delunused) { + $templateCopy = preg_replace("/\{[~|]?(\w*?)}/", "", $templateCopy); + } + + // Assign to handle + if ($append && isset($this->templateHandles[$handle])) { + $this->templateHandles[$handle] .= $templateCopy; + } else { + $this->templateHandles[$handle] = $templateCopy; + } + + return true; + } + + + /** + * Parses multiple templates. + * + * $list is an associative array of the type "handle"=>"template". + * Note that concatenation is not possible. Use the parse() method instead. + * @param array $list Associative array with handles as key and files as values. + * @return bool true if all templates were parsed correctly, false if an error occurred. + */ + function multiParse(array $list): bool + { + foreach ($list as $handle => $file) { + if (!$this->parse($handle, $file)) return false; + } + + return true; + } + + /** + * Parses a template and prints the result. + * @param string $handle Result handle to store the parsed template in. + * @param string $file Template base filename to parse. + * @param bool $append true to append the parsed template to the given handle, false replaces the contents. + * @return bool true if the template was parsed correctly, false if an error occurred. + */ + function printParse(string $handle = "", + string $file = "", + bool $append = false): bool + { + if ($this->parse($handle, $file, $append)) { + $this->printHandle($handle); + return true; + } + + return false; + } + + /** + * Parses a block and replaces or appends the result to the block handle. + * + * Note: First argument is the template file name containing the blocks, + * not a handle name! + * + * Note: This function has no effect on any template handle. + * Parsed block data is inserted into the template handle in the + * parse() method. + * @param string $file Template base filename to parse. + * @param string $block Block name to parse. + * @param string $blockpart Block part to parse. + * @param bool $append true appends the parsed data to the block contents, false replaces it. + * @param bool $delunused true removes unused variable placeholders, false keeps them for later processing. + * @return bool true if the bock was parsed successfully, false if an error occurred. + */ + function parseBlock(string $file = "", + string $block = "", + string $blockpart = "", + bool $append = false, + bool $delunused = false): bool + { + if (empty($file) || empty($block) || empty($blockpart)) + return false; + + if (!isset($this->templateFiles[$file])) + return false; + + if (!isset($this->loadedTemplates[$file]) && !$this->loadTemplate($file)) + return false; + + $blockCopy = $this->templateBlocks[$file][$block][$blockpart]; + + // Reset array pointers + reset($this->parsedBlocks); + reset($this->parserVariables); + + // Replace blocks + if (isset($this->parsedBlocks[$file])) { + reset($this->parsedBlocks[$file]); + + foreach ($this->parsedBlocks[$file] as $varname => $value) { + $blockCopy = preg_replace("/\{\|" . $varname . "}/i", + $value, $blockCopy); + } + } + + // Replace variables + foreach ($this->parserVariables as $varname => $value) { + $blockCopy = preg_replace("/\{" . $varname . "}/i", + $value, $blockCopy); + } + + // Replace {~name} placeholders with already parsed handle of + // the same name + foreach ($this->templateHandles as $varname => $value) { + $blockCopy = preg_replace("/\{~" . $varname . "}/i", + $value, $blockCopy); + } + + // Delete unused variables and placeholders + if ($delunused) { + $blockCopy = preg_replace("/\{[~|]?(\w*?)}/", "", $blockCopy); + } + + // Assign to handle + if ($append && isset($this->parsedBlocks[$file][$block])) { + $this->parsedBlocks[$file][$block] .= $blockCopy; + } else { + $this->parsedBlocks[$file][$block] = $blockCopy; + } + + return true; + } + + /** + * Deletes all block handles. + * @return void + */ + function clearBlockHandles(): void + { + if (!empty($this->parsedBlocks)) { + reset($this->parsedBlocks); + foreach ($this->parsedBlocks as $ref => $val) { + unset($this->parsedBlocks[$ref]); + } + } + } + + /** + * Deletes the specified block handle + * @param string $file The template base file the block is found ion. + * @param string $block The block name to delete. + * @return void + */ + function delBlockHandle(string $file, + string $block): void + { + if (!empty($file) && !empty($block)) { + if (isset($this->parsedBlocks[$file][$block])) { + unset($this->parsedBlocks[$file][$block]); + } + } + } + + /** + * Adds one or more templates + * You can pass one associative array with $handle=>$filename pairs, + * or two strings ($handle, $filename) to this function. + * @param mixed $tplList A template handle or an associative array with template handles as keys and filenames as values. + * @param string $tplFilename A template base filename. Only used if $tplList is a single string. + * @return void + */ + function addTemplates(mixed $tplList, + string $tplFilename = ""): void + { + if (is_array($tplList)) { + reset($tplList); + foreach ($tplList as $handle => $filename) { + // Add handle to list + $this->templateFiles[$handle] = $filename; + // Delete loaded flag if set + unset($this->loadedTemplates[$handle]); + } + } else { + $this->templateFiles[$tplList] = $tplFilename; + unset($this->loadedTemplates[$tplList]); + } + } + + /** + * Deletes all template handles + * @return void + */ + function clearHandles(): void + { + if (!empty($this->templateHandles)) { + reset($this->templateHandles); + foreach ($this->templateHandles as $ref => $val) { + unset($this->templateHandles[$ref]); + } + } + } + + /** + * Deletes the specified template handle + * @param string $handleName Template handle to delete. + * @return void + */ + function delHandle(string $handleName = ""): void + { + if (!empty($handleName)) { + if (isset($this->templateHandles[$handleName])) { + unset($this->templateHandles[$handleName]); + } + } + } + + /** + * Returns the contents of the specified template handle. + * @param string $handleName The handle to return the contents for. + * @return bool|string false if the handle doesn't exist, or a string with the contents. + */ + function getHandle(string $handleName = ""): bool|string + { + if (empty($handleName)) + return false; + + if (isset($this->templateHandles[$handleName])) + return $this->templateHandles[$handleName]; + + return false; + } + + /** + * Prints a parsed template handle to the output stream. + * @param string $handleName The handle to print. + * @return bool false if the handle doesn't exist, true if the handle was printed. + */ + function printHandle(string $handleName = ""): bool + { + if (empty($handleName)) return false; + + // Remove all remaining placeholders + $this->templateHandles[$handleName] = preg_replace("/\{[~|]?(\w*?)}/", + "", $this->templateHandles[$handleName]); + + if (isset($this->templateHandles[$handleName])) { + echo $this->templateHandles[$handleName]; + return true; + } + + return false; + } + + /** + * Deletes all variables set with the addVars() method. + * @return void + */ + function clearVars(): void + { + if (!empty($this->parserVariables)) { + reset($this->parserVariables); + foreach ($this->parserVariables as $ref => $val) { + unset($this->parserVariables[$ref]); + } + } + } + + /** + * Adds one or more variables. + * You can pass one associative array with $varname=>$value pairs + * or two strings ($varname, $value) to this function. + * @param mixed $varList Either an associative array with variable names as keys and values as values, or a string with the variable name. + * @param string $varValue the value to insert for this variable. Only used if $varList is a string with the name of the variable. + * @return void + */ + function addVars(mixed $varList, + string $varValue = ""): void + { + if (is_array($varList)) { + reset($varList); + foreach ($varList as $varname => $value) { + // Replace curly braces + if ($this->replaceBraces == true) { + $value = preg_replace(array("/(\{)/", "/(})/"), + array("{", "}"), + $value); + } + + // Add/replace variable + if (!preg_match("/[^0-9a-z\-_]/i", $varname)) + $this->parserVariables[$varname] = $value; + } + } else { + // Replace curly braces + if ($this->replaceBraces == true) { + $varValue = preg_replace(array("/(\{)/", "/(})/"), + array("{", "}"), + $varValue); + } + + // Add/replace variable + if (!preg_match("/[^0-9a-z\-_]/i", $varList)) + $this->parserVariables[$varList] = $varValue; + } + } + + /** + * Returns a value set by the addVars() method. + * @param string $varName The variable to return the value of. + * @return bool|string false, if the variable didn't exist, or a string with the contents. + */ + function getVar(string $varName = ""): bool|string + { + if (empty($varName)) { + return false; + } + + if (isset($this->parserVariables[$varName])) { + return $this->parserVariables[$varName]; + } + + return false; + } + +} diff --git a/db.php b/db.php index 9d3eece..31938a8 100644 --- a/db.php +++ b/db.php @@ -1,61 +1,63 @@ - - * - * The included "THW Thema" templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -$GLOBALS['db'] = new mysqli("localhost", "DBUSER", "DBPASSWD", "DBDATABASE"); - -if ($GLOBALS['db']->connect_error) { - header("HTTP/1.0 500 Internal Server Error"); - readfile('templates/db-error.html'); - die(); -} - -function callBindParamArray($stmt, $bindArguments = null) { - if ($bindArguments === null) { - return; - } - - $args = array(); - foreach($bindArguments as $k => &$arg){ - $args[$k] = &$arg; - } - - call_user_func_array(array($stmt, "bind_param"), $args); -} - -function getSingleResult($query, $bindArguments = null) { - $stmt = $GLOBALS['db']->prepare($query); - callBindParamArray($stmt, $bindArguments); - $stmt->execute(); - $stmt->bind_result($retVal); - $stmt->fetch(); - $stmt->close(); - - return $retVal; -} \ No newline at end of file + + * + * The included "THW Thema" templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +$GLOBALS['db'] = new mysqli("localhost", "DBUSER", "DBPASSWD", "DBDATABASE"); + +if ($GLOBALS['db']->connect_error) { + header("HTTP/1.0 500 Internal Server Error"); + readfile('templates/db-error.html'); + die(); +} + +function callBindParamArray($stmt, $bindArguments = null) { + if ($bindArguments === null) { + return; + } + + $args = array(); + foreach($bindArguments as $k => &$arg){ + $args[$k] = &$arg; + } + + call_user_func_array(array($stmt, "bind_param"), $args); +} + +function getSingleResult($query, $bindArguments = null) { + $retVal = ''; + + $stmt = $GLOBALS['db']->prepare($query); + callBindParamArray($stmt, $bindArguments); + $stmt->execute(); + $stmt->bind_result($retVal); + $stmt->fetch(); + $stmt->close(); + + return $retVal; +} diff --git a/functions.inc.php b/functions.inc.php index aa76f05..a85b52d 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1,284 +1,293 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/** - * Holt eine Einzelne Frage aus der DB - * - * @param $id Die Frage-ID - * - * @return array Die Frage - */ -function getQuestionById($id) { - $stmt = $GLOBALS['db']->prepare('SELECT * FROM fragen WHERE ID=?'); - $stmt->bind_param('i', $id); - $stmt->execute(); - $result = $stmt->get_result(); - - $question = $result->fetch_array(MYSQLI_ASSOC); - - return $question; -} - -/** - * Holt eine Liste aller Abschnitte im aktuellen Jahr - * - * @return array - */ -function getTopics() { - $stmt = $GLOBALS['db']->prepare('SELECT `Nr`,`Beschreibung` FROM `abschnitte` WHERE `Jahr` = ? ORDER BY `Nr` ASC'); - $stmt->bind_param('i', $_SESSION['jahr']); - $stmt->execute(); - $stmt->bind_result($nr, $description); - - $topics = array(); - while ($stmt->fetch()) { - $topics[$nr] = $description; - } - $stmt->close(); - - return $topics; -} - -/****************************************************************************** - * - * Kopfzeile mit Informationen über Fragennummer und Lernabschnitt - * -/******************************************************************************/ - -function questionHeader($id, $nr, $questionCount) -{ - $section = getSingleResult('SELECT Abschnitt FROM fragen WHERE ID=? AND Jahr=?', - array('ii', $id, $_SESSION['jahr'])); - - $sectionName = getSingleResult('SELECT Beschreibung FROM abschnitte WHERE Nr=? AND Jahr=?', - array('ii', $section, $_SESSION['jahr'])); - - $GLOBALS['tpl']->addVars(Array( - 'aktuelleFrage' => $nr, - 'fragenCnt' => $questionCount, - 'abschnittNr' => $section, - 'abschnitt' => $sectionName - )); - - $GLOBALS['tpl']->parseBlock('content', 'Kopf', 'Content'); -} - -/****************************************************************************** - * - * Eine einzelne Frage mit Kopfzeile ausgeben - * -/******************************************************************************/ - -function SingleQuestion($id, $Nr, $questionCount) -{ - questionHeader($id, $Nr, $questionCount); - showQuestion($id); -} - -/****************************************************************************** - * - * Fragengenerator - * Erzeugt eine Tabelle mit Frage, Antworten und Formularinformationen - * zur übergebenen Fragen-ID - * -/******************************************************************************/ - -function showQuestion($id) -{ - // Frage aus DB holen - $stmt = $GLOBALS['db']->prepare('SELECT * FROM fragen WHERE ID=?'); - $stmt->bind_param('i', $id); - $stmt->execute(); - $result = $stmt->get_result(); - - $question = $result->fetch_array(MYSQLI_ASSOC); - - $GLOBALS['tpl']->addVars(Array( - 'frageID' => $id, - 'frageNr' => $question['Nr'], - 'abschnittNr' => $question['Abschnitt'], - 'frageText' => $question['Frage'], - 'Antwort1' => $question['Antwort1'], - 'Antwort2' => $question['Antwort2'], - 'Antwort3' => $question['Antwort3'] - )); - - if ($question['Antwort3'] == '') { - $GLOBALS['tpl']->addVars('rowCnt', '2'); - $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); - } - else { - $GLOBALS['tpl']->addVars('rowCnt', '3'); - $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row', TRUE); - } - - $result->close(); - $stmt->close(); -} - -/****************************************************************************** - * - * Auswertung - * Erzeugt eine Tabelle mit Frage, Antworten und Markiert richtige/falsche - * Antworten farblich (grün=richtig, rot=falsch) - * -/******************************************************************************/ - -function Answer($id, $answer, $showStatus = TRUE) -{ - // Frage aus DB holen - $question = getQuestionById($id); - - // Einzelne Antworten aus Flag in Array splitten - $solution = array( 1 => ( $question['Loesung'] & 0x1), - 2 => (($question['Loesung'] & 0x2) >> 1), - 3 => (($question['Loesung'] & 0x4) >> 2)); - - $correct = (($solution[1] == (isset($answer[$id][1]) ? $answer[$id][1] : 0)) - && ($solution[2] == (isset($answer[$id][2]) ? $answer[$id][2] : 0)) - && ($solution[3] == (isset($answer[$id][3]) ? $answer[$id][3] : 0))); - - // Aufräumen - $GLOBALS['tpl']->delHandle('antwortStatus'); - $GLOBALS['tpl']->delHandle('antwort1Loesung'); - $GLOBALS['tpl']->delHandle('antwort2Loesung'); - $GLOBALS['tpl']->delHandle('antwort3Loesung'); - - $GLOBALS['tpl']->delBlockHandle('content', 'A1L'); - $GLOBALS['tpl']->delBlockHandle('content', 'A2L'); - $GLOBALS['tpl']->delBlockHandle('content', 'A3L'); - - if ($showStatus) { - if ($correct) - $GLOBALS['tpl']->parseBlock('content', 'Status', 'Richtig'); - else - $GLOBALS['tpl']->parseBlock('content', 'Status', 'Falsch'); - } else { - if ($correct) - $GLOBALS['tpl']->parseBlock('content', 'BogenStatus', 'Richtig'); - else - $GLOBALS['tpl']->parseBlock('content', 'BogenStatus', 'Falsch'); - } - - $GLOBALS['tpl']->addVars(Array( - 'abschnittNr' => $question['Abschnitt'], - 'frageNr' => $question['Nr'], - 'frageText' => $question['Frage'], - 'antwort1Status' => $solution[1] ? 'korrekt' : 'falsch', - 'antwort2Status' => $solution[2] ? 'korrekt' : 'falsch', - 'antwort3Status' => $solution[3] ? 'korrekt' : 'falsch', - 'Antwort1' => $question['Antwort1'], - 'Antwort2' => $question['Antwort2'], - 'Antwort3' => $question['Antwort3'] - )); - - if ($question['Antwort3'] == '') { - $GLOBALS['tpl']->addVars('rowCnt', '2'); - $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); - } - else { - $GLOBALS['tpl']->addVars('rowCnt', '3'); - $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row'); - } - - if (isset($answer[$id][1]) && $answer[$id][1] === '1') $GLOBALS['tpl']->parseBlock('content', 'A1L', 'Haken'); - if (isset($answer[$id][2]) && $answer[$id][2] === '1') $GLOBALS['tpl']->parseBlock('content', 'A2L', 'Haken'); - if (isset($answer[$id][3]) && $answer[$id][3] === '1') $GLOBALS['tpl']->parseBlock('content', 'A3L', 'Haken'); - - // Anhängen per default - $GLOBALS['tpl']->parse('content', 'antwort', TRUE, TRUE); - - return $correct; - -} - -/****************************************************************************** - * - * Antwort - * Zeigt die Frage und die zugehörigen korrekten Antworten an - * Antworten sind farblich gekennzeichnet (grün=richtig, rot=falsch) - * -/******************************************************************************/ - -function addBreadcrumb($params, $title) -{ - $GLOBALS['tpl']->addVars(Array( - 'page' => htmlspecialchars($params), - 'pageTitle' => htmlspecialchars($title) - )); - $GLOBALS['tpl']->parseBlock('page-body', 'Breadcrumb', 'Link', TRUE); -} - -function ShowAnswer(&$frage) -{ - - - // Einzelne Antworten aus Flag in Array splitten - $loesung = array( 1 => ( $frage['Loesung'] & 0x1), - 2 => (($frage['Loesung'] & 0x2) >> 1), - 3 => (($frage['Loesung'] & 0x4) >> 2)); - - // Aufräumen - $GLOBALS['tpl']->delHandle('antwortStatus'); - $GLOBALS['tpl']->delHandle('antwort1Loesung'); - $GLOBALS['tpl']->delHandle('antwort2Loesung'); - $GLOBALS['tpl']->delHandle('antwort3Loesung'); - - $GLOBALS['tpl']->addVars(Array( - 'abschnittNr' => $frage['Abschnitt'], - 'frageNr' => $frage['Nr'], - 'frageText' => $frage['Frage'], - 'antwort1Status' => $loesung[1]?'korrekt':'falsch', - 'antwort2Status' => $loesung[2]?'korrekt':'falsch', - 'antwort3Status' => $loesung[3]?'korrekt':'falsch', - 'Antwort1' => $frage['Antwort1'], - 'Antwort2' => $frage['Antwort2'], - 'Antwort3' => $frage['Antwort3'] - )); - - $GLOBALS['tpl']->delBlockHandle('content', 'A1L'); - $GLOBALS['tpl']->delBlockHandle('content', 'A2L'); - $GLOBALS['tpl']->delBlockHandle('content', 'A3L'); - - if ($loesung[1]) $GLOBALS['tpl']->parseBlock('content', 'A1L', 'Haken'); - if ($loesung[2]) $GLOBALS['tpl']->parseBlock('content', 'A2L', 'Haken'); - if ($loesung[3]) $GLOBALS['tpl']->parseBlock('content', 'A3L', 'Haken'); - - if ($frage['Antwort3'] == '') { - $GLOBALS['tpl']->addVars('rowCnt', '2'); - $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); - } - else { - $GLOBALS['tpl']->addVars('rowCnt', '3'); - $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row'); - } -} - -?> + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * Holt eine einzelne Frage aus der Datenbank. + * @param int $id Die Frage-ID + * @return array Die Fragen-Inhalte als assoziatives Array. + */ +function getQuestionById(int $id): array +{ + $stmt = $GLOBALS['db']->prepare('SELECT * FROM fragen WHERE ID=?'); + $stmt->bind_param('i', $id); + $stmt->execute(); + $result = $stmt->get_result(); + + $question = $result->fetch_array(MYSQLI_ASSOC); + + return $question; +} + +/** + * Holt eine Liste aller Abschnitte im aktuellen Jahr + * @return array Liste der Themenbereiche. + */ +function getTopics(): array +{ + $nr = 0; + $description = ''; + + $stmt = $GLOBALS['db']->prepare('SELECT `Nr`,`Beschreibung` FROM `abschnitte` WHERE `Jahr` = ? ORDER BY `Nr`'); + $stmt->bind_param('i', $_SESSION['jahr']); + $stmt->execute(); + $stmt->bind_result($nr, $description); + + $topics = array(); + while ($stmt->fetch()) { + $topics[$nr] = $description; + } + $stmt->close(); + + return $topics; +} + +/** + * Kopfzeile mit Informationen über Fragen-Nummer und Lernabschnitt. + * @param int $id Frage-ID + * @param int $nr Frage-Nummer + * @param int $questionCount Anzahl Fragen + * @return void + */ +function questionHeader(int $id, int $nr, int $questionCount): void +{ + $section = getSingleResult('SELECT Abschnitt FROM fragen WHERE ID=? AND Jahr=?', + array('ii', $id, $_SESSION['jahr'])); + + $sectionName = getSingleResult('SELECT Beschreibung FROM abschnitte WHERE Nr=? AND Jahr=?', + array('ii', $section, $_SESSION['jahr'])); + + $GLOBALS['tpl']->addVars(Array( + 'aktuelleFrage' => $nr, + 'fragenCnt' => $questionCount, + 'abschnittNr' => $section, + 'abschnitt' => $sectionName + )); + + $GLOBALS['tpl']->parseBlock('content', 'Kopf', 'Content'); +} + +/** + * Eine einzelne Frage mit Kopfzeile ausgeben. + * @param int $id Frage-ID + * @param int $nr Frage-Nummer + * @param int $questionCount Anzahl Fragen + * @return void + */ +function SingleQuestion(int $id, int $nr, int $questionCount): void +{ + questionHeader($id, $nr, $questionCount); + showQuestion($id); +} + +/** + * Fragengenerator + * + * Erzeugt eine Tabelle mit Frage, Antworten und Formularinformationen + * zur übergebenen Fragen-ID + * @param int $id Fragen-ID + * @return void + */ +function showQuestion(int $id): void +{ + // Frage aus DB holen + $stmt = $GLOBALS['db']->prepare('SELECT * FROM fragen WHERE ID=?'); + $stmt->bind_param('i', $id); + $stmt->execute(); + $result = $stmt->get_result(); + + $question = $result->fetch_array(MYSQLI_ASSOC); + + $GLOBALS['tpl']->addVars(Array( + 'frageID' => $id, + 'frageNr' => $question['Nr'], + 'abschnittNr' => $question['Abschnitt'], + 'frageText' => $question['Frage'], + 'Antwort1' => $question['Antwort1'], + 'Antwort2' => $question['Antwort2'], + 'Antwort3' => $question['Antwort3'] + )); + + if ($question['Antwort3'] == '') { + $GLOBALS['tpl']->addVars('rowCnt', '2'); + $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); + } + else { + $GLOBALS['tpl']->addVars('rowCnt', '3'); + $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row', TRUE); + } + + $result->close(); + $stmt->close(); +} + +/** + * Auswertung + * + * Erzeugt eine Tabelle mit Frage, Antworten und Markiert richtige/falsche + * Antworten farblich (grün=richtig, rot=falsch) + * @param int $id Frage-ID + * @param array $answer Antwort-Array + * @param bool $showStatus Status anzeigen + * @return bool true, falls korrekt beantwortet, sonst false. + */ +function Answer(int $id, array $answer, bool $showStatus = true): bool +{ + // Frage aus DB holen + $question = getQuestionById($id); + + // Einzelne Antworten aus Flag in Array splitten + $solution = array( 1 => ( $question['Loesung'] & 0x1), + 2 => (($question['Loesung'] & 0x2) >> 1), + 3 => (($question['Loesung'] & 0x4) >> 2)); + + $correct = (($solution[1] == (isset($answer[$id][1]) ? $answer[$id][1] : 0)) + && ($solution[2] == (isset($answer[$id][2]) ? $answer[$id][2] : 0)) + && ($solution[3] == (isset($answer[$id][3]) ? $answer[$id][3] : 0))); + + // Aufräumen + $GLOBALS['tpl']->delHandle('antwortStatus'); + $GLOBALS['tpl']->delHandle('antwort1Loesung'); + $GLOBALS['tpl']->delHandle('antwort2Loesung'); + $GLOBALS['tpl']->delHandle('antwort3Loesung'); + + $GLOBALS['tpl']->delBlockHandle('content', 'A1L'); + $GLOBALS['tpl']->delBlockHandle('content', 'A2L'); + $GLOBALS['tpl']->delBlockHandle('content', 'A3L'); + + if ($showStatus) { + if ($correct) + $GLOBALS['tpl']->parseBlock('content', 'Status', 'Richtig'); + else + $GLOBALS['tpl']->parseBlock('content', 'Status', 'Falsch'); + } else { + if ($correct) + $GLOBALS['tpl']->parseBlock('content', 'BogenStatus', 'Richtig'); + else + $GLOBALS['tpl']->parseBlock('content', 'BogenStatus', 'Falsch'); + } + + $GLOBALS['tpl']->addVars(Array( + 'abschnittNr' => $question['Abschnitt'], + 'frageNr' => $question['Nr'], + 'frageText' => $question['Frage'], + 'antwort1Status' => $solution[1] ? 'korrekt' : 'falsch', + 'antwort2Status' => $solution[2] ? 'korrekt' : 'falsch', + 'antwort3Status' => $solution[3] ? 'korrekt' : 'falsch', + 'Antwort1' => $question['Antwort1'], + 'Antwort2' => $question['Antwort2'], + 'Antwort3' => $question['Antwort3'] + )); + + if ($question['Antwort3'] == '') { + $GLOBALS['tpl']->addVars('rowCnt', '2'); + $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); + } + else { + $GLOBALS['tpl']->addVars('rowCnt', '3'); + $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row'); + } + + if (isset($answer[$id][1]) && $answer[$id][1] === '1') $GLOBALS['tpl']->parseBlock('content', 'A1L', 'Haken'); + if (isset($answer[$id][2]) && $answer[$id][2] === '1') $GLOBALS['tpl']->parseBlock('content', 'A2L', 'Haken'); + if (isset($answer[$id][3]) && $answer[$id][3] === '1') $GLOBALS['tpl']->parseBlock('content', 'A3L', 'Haken'); + + // Anhängen per default + $GLOBALS['tpl']->parse('content', 'antwort', TRUE, TRUE); + + return $correct; + +} + +/** + * Brotkrumen-Navigation. + * + * Fügt einen Link zur Brotkrumen-Navigation hinzu. + * @param string $page Seiten-Link + * @param string $title Seiten-Titel + * @return void + */ +function addBreadcrumb(string $page, string $title): void +{ + $GLOBALS['tpl']->addVars(Array( + 'page' => htmlspecialchars($page), + 'pageTitle' => htmlspecialchars($title) + )); + $GLOBALS['tpl']->parseBlock('page-body', 'Breadcrumb', 'Link', TRUE); +} + +/** + * Zeigt die Auflösung an. + * @param array $frage Referenz auf das assoziative Fragen-Array + * @return void + */ +function ShowAnswer(array &$frage): void +{ + + + // Einzelne Antworten aus Flag in Array splitten + $loesung = array( 1 => ( $frage['Loesung'] & 0x1), + 2 => (($frage['Loesung'] & 0x2) >> 1), + 3 => (($frage['Loesung'] & 0x4) >> 2)); + + // Aufräumen + $GLOBALS['tpl']->delHandle('antwortStatus'); + $GLOBALS['tpl']->delHandle('antwort1Loesung'); + $GLOBALS['tpl']->delHandle('antwort2Loesung'); + $GLOBALS['tpl']->delHandle('antwort3Loesung'); + + $GLOBALS['tpl']->addVars(Array( + 'abschnittNr' => $frage['Abschnitt'], + 'frageNr' => $frage['Nr'], + 'frageText' => $frage['Frage'], + 'antwort1Status' => $loesung[1]?'korrekt':'falsch', + 'antwort2Status' => $loesung[2]?'korrekt':'falsch', + 'antwort3Status' => $loesung[3]?'korrekt':'falsch', + 'Antwort1' => $frage['Antwort1'], + 'Antwort2' => $frage['Antwort2'], + 'Antwort3' => $frage['Antwort3'] + )); + + $GLOBALS['tpl']->delBlockHandle('content', 'A1L'); + $GLOBALS['tpl']->delBlockHandle('content', 'A2L'); + $GLOBALS['tpl']->delBlockHandle('content', 'A3L'); + + if ($loesung[1]) $GLOBALS['tpl']->parseBlock('content', 'A1L', 'Haken'); + if ($loesung[2]) $GLOBALS['tpl']->parseBlock('content', 'A2L', 'Haken'); + if ($loesung[3]) $GLOBALS['tpl']->parseBlock('content', 'A3L', 'Haken'); + + if ($frage['Antwort3'] == '') { + $GLOBALS['tpl']->addVars('rowCnt', '2'); + $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); + } + else { + $GLOBALS['tpl']->addVars('rowCnt', '3'); + $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row'); + } +} diff --git a/home.inc.php b/home.inc.php index b97da9a..db3474b 100644 --- a/home.inc.php +++ b/home.inc.php @@ -1,61 +1,73 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -function getStats() { - $stmt = $GLOBALS['db']->prepare('SELECT fragen,richtig,falsch,boegen,bestanden,durchgefallen FROM statistik'); - $stmt->execute(); - $stmt->bind_result( - $fragen, - $richtig, - $falsch, - $boegen, - $bestanden, - $durchgefallen - ); - - $stmt->fetch(); - - $GLOBALS['tpl']->addVars(Array( - 'statsFragen' => sprintf('%0.d', $fragen), - 'statsFragenRichtig' => sprintf('%0.d (%0.2f %%)', $richtig, ($fragen > 0 ? $richtig / $fragen * 100 : 0)), - 'statsFragenFalsch' => sprintf('%0.d (%0.2f %%)', $falsch, ($fragen > 0 ? $falsch / $fragen * 100 : 0)), - 'statsBoegen' => sprintf('%0.d', $boegen), - 'statsBoegenRichtig' => sprintf('%0.d (%0.2f %%)', $bestanden, ($boegen > 0 ? $bestanden / $boegen * 100 : 0)), - 'statsBoegenFalsch' => sprintf('%0.d (%0.2f %%)', $durchgefallen, ($boegen > 0 ? $durchgefallen / $boegen * 100 : 0)) - )); - - -} - -getStats(); -$GLOBALS['tpl']->addTemplates(Array( - 'content' => 'home' -)); -?> \ No newline at end of file + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * Holt die Gesamt-Statistiken aus der Datenbank und füllt das Template. + * @return void + */ +function getStats(): void +{ + $fragen = 0; + $richtig = 0; + $falsch = 0; + $boegen = 0; + $bestanden = 0; + $durchgefallen = 0; + + $stmt = $GLOBALS['db']->prepare('SELECT fragen,richtig,falsch,boegen,bestanden,durchgefallen FROM statistik'); + $stmt->execute(); + $stmt->bind_result( + $fragen, + $richtig, + $falsch, + $boegen, + $bestanden, + $durchgefallen + ); + + $stmt->fetch(); + + $GLOBALS['tpl']->addVars(array( + 'statsFragen' => sprintf('%0.d', $fragen), + 'statsFragenRichtig' => sprintf('%0.d (%0.2f %%)', $richtig, ($fragen > 0 ? $richtig / $fragen * 100 : 0)), + 'statsFragenFalsch' => sprintf('%0.d (%0.2f %%)', $falsch, ($fragen > 0 ? $falsch / $fragen * 100 : 0)), + 'statsBoegen' => sprintf('%0.d', $boegen), + 'statsBoegenRichtig' => sprintf('%0.d (%0.2f %%)', $bestanden, ($boegen > 0 ? $bestanden / $boegen * 100 : 0)), + 'statsBoegenFalsch' => sprintf('%0.d (%0.2f %%)', $durchgefallen, ($boegen > 0 ? $durchgefallen / $boegen * 100 : 0)) + )); + + +} + +getStats(); + +$GLOBALS['tpl']->addTemplates(array( + 'content' => 'home' +)); diff --git a/index.php b/index.php index 97088b4..0237135 100644 --- a/index.php +++ b/index.php @@ -1,110 +1,108 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - - require_once 'db.php'; - require_once 'class.template.inc.php'; - require_once 'functions.inc.php'; - require_once 'init.inc.php'; - - if (!isset($_REQUEST['show'])) { - $_REQUEST['show'] = 'home'; - } - - switch ($_REQUEST['show']) { - case 'fragen': - addBreadcrumb($_REQUEST['show'], 'Zufallsfragen beantworten'); - include ('zufallsfragen.inc.php'); - break; - - case 'bogen': - addBreadcrumb($_REQUEST['show'], 'Prüfungsbogen üben'); - include ('pruefbogen.inc.php'); - break; - - case 'loesung': - addBreadcrumb($_REQUEST['show'], 'Antworten anzeigen'); - include ('antworten.inc.php'); - break; - - case 'ordnung': - addBreadcrumb($_REQUEST['show'], 'Prüfungsordnung'); - $tpl->addVars('navOrdnung', 'current'); - $tpl->addTemplates(Array('content' => 'ordnung')); - break; - - case 'stats': - $tpl->addVars(Array( - // Statistik Zufallsfragen - 'fragenBisher' => $_SESSION['stats']['Fragen_Bisher'], - 'fragenRichtig' => $_SESSION['stats']['Fragen_Richtig'], - 'fragenFalsch' => $_SESSION['stats']['Fragen_Falsch'], - 'fragenQuote' => (($_SESSION['stats']['Fragen_Bisher']>0)?(preg_replace('/\./is', ',', number_format($_SESSION['stats']['Fragen_Richtig']/$_SESSION['stats']['Fragen_Bisher']*100,2))):('0')) . '%', - - // Statistik Prüfungsbögen - 'boegenBisher' => $_SESSION['stats']['Boegen_Bisher'], - 'boegenRichtig' => $_SESSION['stats']['Boegen_Bestanden'], - 'boegenFalsch' => $_SESSION['stats']['Boegen_Durchgefallen'], - 'boegenQuote' => (($_SESSION['stats']['Boegen_Bisher']>0)?(preg_replace('/\./is', ',', number_format($_SESSION['stats']['Boegen_Bestanden']/$_SESSION['stats']['Boegen_Bisher']*100,2))):('0')) . '%' - )); - addBreadcrumb($_REQUEST['show'], 'Statistiken'); - $tpl->addVars('navStats', 'current'); - $tpl->addTemplates(Array('content' => 'stats')); - break; - - case "barrierefreiheit": - addBreadcrumb($_REQUEST["show"], "Barrierefreiheit"); - include "barrierefreiheit.inc.php"; - break; - - case 'impressum': - addBreadcrumb($_REQUEST['show'], 'Impressum'); - $tpl->addTemplates(Array('content' => 'impressum')); - break; - - case 'datenschutz': - addBreadcrumb($_REQUEST['show'], 'Datenschutzhinweis'); - $tpl->addTemplates(Array('content' => 'datenschutz')); - break; - - case "downloads": - addBreadcrumb($_REQUEST["show"], "Offline-Version"); - $tpl->addVars("navOffline", "current"); - $tpl->addTemplates(Array("content" => "offline")); - break; - - default: - $title = ''; - include('home.inc.php'); - } - - $tpl->parse('pageContent', 'content'); - $tpl->printParse('pageMain', 'page-body'); - -?> \ No newline at end of file + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +require_once 'db.php'; +require_once 'class.template.inc.php'; +require_once 'functions.inc.php'; +require_once 'init.inc.php'; + +if (!isset($_REQUEST['show'])) { + $_REQUEST['show'] = 'home'; +} + +switch ($_REQUEST['show']) { + case 'fragen': + addBreadcrumb($_REQUEST['show'], 'Zufallsfragen beantworten'); + include('zufallsfragen.inc.php'); + break; + + case 'bogen': + addBreadcrumb($_REQUEST['show'], 'Prüfungsbogen üben'); + include('pruefbogen.inc.php'); + break; + + case 'loesung': + addBreadcrumb($_REQUEST['show'], 'Antworten anzeigen'); + include('antworten.inc.php'); + break; + + case 'ordnung': + addBreadcrumb($_REQUEST['show'], 'Prüfungsordnung'); + $GLOBALS['tpl']->addVars('navOrdnung', 'current'); + $GLOBALS['tpl']->addTemplates(array('content' => 'ordnung')); + break; + + case 'stats': + $GLOBALS['tpl']->addVars(array( + // Statistik Zufallsfragen + 'fragenBisher' => $_SESSION['stats']['Fragen_Bisher'], + 'fragenRichtig' => $_SESSION['stats']['Fragen_Richtig'], + 'fragenFalsch' => $_SESSION['stats']['Fragen_Falsch'], + 'fragenQuote' => (($_SESSION['stats']['Fragen_Bisher'] > 0) ? (preg_replace('/\./is', ',', number_format($_SESSION['stats']['Fragen_Richtig'] / $_SESSION['stats']['Fragen_Bisher'] * 100, 2))) : ('0')) . '%', + + // Statistik Prüfungsbögen + 'boegenBisher' => $_SESSION['stats']['Boegen_Bisher'], + 'boegenRichtig' => $_SESSION['stats']['Boegen_Bestanden'], + 'boegenFalsch' => $_SESSION['stats']['Boegen_Durchgefallen'], + 'boegenQuote' => (($_SESSION['stats']['Boegen_Bisher'] > 0) ? (preg_replace('/\./is', ',', number_format($_SESSION['stats']['Boegen_Bestanden'] / $_SESSION['stats']['Boegen_Bisher'] * 100, 2))) : ('0')) . '%' + )); + addBreadcrumb($_REQUEST['show'], 'Statistiken'); + $GLOBALS['tpl']->addVars('navStats', 'current'); + $GLOBALS['tpl']->addTemplates(array('content' => 'stats')); + break; + + case "barrierefreiheit": + addBreadcrumb($_REQUEST["show"], "Barrierefreiheit"); + include "barrierefreiheit.inc.php"; + break; + + case 'impressum': + addBreadcrumb($_REQUEST['show'], 'Impressum'); + $GLOBALS['tpl']->addTemplates(array('content' => 'impressum')); + break; + + case 'datenschutz': + addBreadcrumb($_REQUEST['show'], 'Datenschutzhinweis'); + $GLOBALS['tpl']->addTemplates(array('content' => 'datenschutz')); + break; + + case "downloads": + addBreadcrumb($_REQUEST["show"], "Offline-Version"); + $GLOBALS['tpl']->addVars("navOffline", "current"); + $GLOBALS['tpl']->addTemplates(array("content" => "offline")); + break; + + default: + $title = ''; + include('home.inc.php'); +} + +$GLOBALS['tpl']->parse('pageContent', 'content'); +$GLOBALS['tpl']->printParse('pageMain', 'page-body'); diff --git a/init.inc.php b/init.inc.php index 13ab6d2..9e6e4c8 100644 --- a/init.inc.php +++ b/init.inc.php @@ -1,91 +1,86 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstra�e 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -header('Content-Type: text/html; charset=utf-8'); - -$GLOBALS['tpl'] = new Template('./templates/'); -$tpl =& $GLOBALS['tpl']; - -$tpl->addTemplates(Array( - 'page-body' => 'page-body', - 'top-line' => 'top-line' -)); - -session_start(); - -if (isset($_REQUEST['resetstats']) && intval($_REQUEST['resetstats']) == '1') { - unset($_SESSION['stats']); -} - -if (!isset($_SESSION['stats'])) { - - $_SESSION['stats'] = array('Fragen_Bisher' => '0', - 'Fragen_Richtig' => '0', - 'Fragen_Falsch' => '0', - 'Boegen_Bisher' => '0', - 'Boegen_Bestanden' => '0', - 'Boegen_Durchgefallen' => '0' ); -} - -if (isset($_REQUEST['jahr'])) { - $_SESSION['jahr'] = intval($_REQUEST['jahr']); -} elseif (!isset($_SESSION['jahr'])) { - $_SESSION['jahr'] = 2020; -} - -srand(microtime()*(double)10000); - -if ((isset($_COOKIE['stylesheet']) && $_COOKIE['stylesheet'] == 'barrierefrei') - || isset($_POST['barrierefrei']) - || (isset($_GET['style']) && $_GET['style'] == 'rg')) { - $tpl->addVars('extraStyleSheet', ''); -} else { - -} - -if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { - $protocol = 'https'; - // HSTS Policy aktivieren - header('Strict-Transport-Security: max-age=31536000; includeSubDomains;'); -} else { - $protocol = 'http'; -} - -$tpl->addVars(Array( - // Globale Variablen - 'scriptName' => $_SERVER['SCRIPT_NAME'], - 'catalogYear' => $_SESSION['jahr'], - 'baseUrl' => $protocol . '://thw-theorie.de/' -)); - - -$tpl->parse('topLine', 'top-line'); - -?> \ No newline at end of file + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstra�e 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +header('Content-Type: text/html; charset=utf-8'); + +$GLOBALS['tpl'] = new Template(__DIR__ . '/templates/'); + +$GLOBALS['tpl']->addTemplates(Array( + 'page-body' => 'page-body', + 'top-line' => 'top-line' +)); + +session_start(); + +if (isset($_REQUEST['resetstats']) && intval($_REQUEST['resetstats']) == '1') { + unset($_SESSION['stats']); +} + +if (!isset($_SESSION['stats'])) { + + $_SESSION['stats'] = array('Fragen_Bisher' => '0', + 'Fragen_Richtig' => '0', + 'Fragen_Falsch' => '0', + 'Boegen_Bisher' => '0', + 'Boegen_Bestanden' => '0', + 'Boegen_Durchgefallen' => '0' ); +} + +if (isset($_REQUEST['jahr'])) { + $_SESSION['jahr'] = intval($_REQUEST['jahr']); +} elseif (!isset($_SESSION['jahr'])) { + $_SESSION['jahr'] = 2020; +} + +mt_srand(intval(microtime()) * 10000); + +if ((isset($_COOKIE['stylesheet']) && $_COOKIE['stylesheet'] == 'barrierefrei') + || isset($_POST['barrierefrei']) + || (isset($_GET['style']) && $_GET['style'] == 'rg')) { + $GLOBALS['tpl']->addVars('extraStyleSheet', ''); +} + +if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { + $protocol = 'https'; + // HSTS Policy aktivieren + header('Strict-Transport-Security: max-age=31536000; includeSubDomains;'); +} else { + $protocol = 'http'; +} + +$GLOBALS['tpl']->addVars(Array( + // Globale Variablen + 'scriptName' => $_SERVER['SCRIPT_NAME'], + 'catalogYear' => $_SESSION['jahr'], + 'baseUrl' => $protocol . '://' . $_SERVER['HTTP_HOST'] . '/' +)); + + +$GLOBALS['tpl']->parse('topLine', 'top-line'); diff --git a/pruefbogen.inc.php b/pruefbogen.inc.php index a471e73..0e418d2 100644 --- a/pruefbogen.inc.php +++ b/pruefbogen.inc.php @@ -1,216 +1,219 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* -* -* Vollständiger Prüfungsbogen mit zufälligen Fragen -* -*/ - -$tpl->parseBlock('page-body', 'NavBogen', 'Sublinks'); -$tpl->addVars('navBogen', 'current'); - -if (isset($_REQUEST['create']) && $_REQUEST['create'] == '1') { - // Neuen Bogen erstellen - unset($_SESSION['bogen']); - - // Werte initialisieren - $_SESSION['bogen']['StartTime'] = time(); - $_SESSION['bogen']['Fragen'] = Array(); - - // Anz. Abschnitte und Fragen aus der DB holen - $sectionCount = getSingleResult('SELECT COUNT(*) FROM abschnitte WHERE Jahr = ?', array('i', $_SESSION['jahr'])); - - $stmt = $GLOBALS['db']->prepare('SELECT ID, Abschnitt FROM fragen WHERE Jahr = ? ORDER BY Abschnitt, Nr ASC'); - $stmt->bind_param('i', $_SESSION['jahr']); - $stmt->execute(); - $stmt->bind_result($questionId, $questionSection); - - // Fragen in Array übertragen - while ($stmt->fetch()) { - $fragen[$questionId] = $questionSection; - } - $stmt->close(); - - // Gesamtanzahl Fragen - $count_ab = array_count_values($fragen); - - // Eine Frage pro Themengebiet aus der DB holen - for ($i = 1; $i <= $sectionCount; $i++) { - $nr = rand(1, $count_ab[$i]); - $id = getSingleResult('SELECT ID FROM fragen WHERE Nr = ? AND Abschnitt = ? AND Jahr = ?', - array('iii', $nr, $i, $_SESSION['jahr'])); - - array_push($_SESSION['bogen']['Fragen'], (int)$id); - - // Frage entfernen - unset($fragen[$id]); - } - - // Restliche Fragen zufällig auffüllen - // Dazu verbliebene Keys von $fragen als Values in neues Array $fragen2 kopieren, - // da shuffle() die Keys verwirft! - $fragen2 = Array(); - foreach ($fragen As $key => $value) { - array_push($fragen2, $key); - } - shuffle($fragen2); - for ($i = 0; $i < 40 - $sectionCount; $i++) { - array_push($_SESSION['bogen']['Fragen'], array_shift($fragen2)); - } - - // Fragen erneut mischen - shuffle($_SESSION['bogen']['Fragen']); - -} - -if (isset($_SESSION['bogen'])) { - if (isset($_POST['antwort'])) { - // Fragen beantwortet - $richtig = 0; - $falsch = 0; - $fragen_cnt = count($_SESSION['bogen']['Fragen']); - $zeit = time()-$_SESSION['bogen']['StartTime']; - - for ($i = 0; $i < $fragen_cnt; $i++) { - $id = $_SESSION['bogen']['Fragen'][$i]; - $solutionBitmask = getSingleResult('SELECT `Loesung` FROM `fragen` WHERE `ID` = ?', - array('i', $id)); - - $loesung = array( 1 => ( $solutionBitmask & 0x1), - 2 => (($solutionBitmask & 0x2) >> 1), - 3 => (($solutionBitmask & 0x4) >> 2)); - - if (isset($_POST['antwort'][$id])) { - $korrekt = (($loesung[1] == (isset($_POST['antwort'][$id][1]) ? $_POST['antwort'][$id][1] : 0)) - && ($loesung[2] == (isset($_POST['antwort'][$id][2]) ? $_POST['antwort'][$id][2] : 0)) - && ($loesung[3] == (isset($_POST['antwort'][$id][3]) ? $_POST['antwort'][$id][3] : 0))); - } else{ - $korrekt = false; - } - - if ($korrekt) { - $_SESSION["stats"]['Fragen_Richtig']++; - $richtig++; - } else { - $_SESSION["stats"]['Fragen_Falsch']++; - $falsch++; - } - $_SESSION["stats"]['Fragen_Bisher']++; - } - - $_SESSION["stats"]['Boegen_Bisher']++; - - if (($richtig / $fragen_cnt) >= 0.8) - $_SESSION["stats"]['Boegen_Bestanden']++; - else - $_SESSION["stats"]['Boegen_Durchgefallen']++; - - $GLOBALS['db']->query('UPDATE statistik SET fragen=fragen+' . $fragen_cnt - .',richtig=richtig+' . $richtig - .',falsch=falsch+' . $falsch - .',boegen=boegen+1' - .',bestanden=bestanden+' . (($richtig / $fragen_cnt) >= 0.8?1:0) - .',durchgefallen=durchgefallen+' . (($richtig / $fragen_cnt) < 0.8?1:0)); - - $tpl->addTemplates('content', 'bogen-ende'); - - $tpl->addVars(Array( - 'anzFragen' => count($_SESSION['bogen']['Fragen']), - 'zeit' => sprintf('%02d:%02d\'%02d', $zeit / 3600, ($zeit/60)%60, $zeit%60), - 'fragenRichtig' => $richtig, - 'fragenRichtigQuote' => sprintf('%.2f %%', $richtig / $fragen_cnt * 100), - 'fragenFalsch' => $falsch, - 'fragenFalschQuote' => sprintf('%.2f %%', $falsch / $fragen_cnt * 100) - )); - - if (($richtig / $fragen_cnt) >= 0.8) - $tpl->parseBlock('content', 'Bestanden', 'Ja'); - else - $tpl->parseBlock('content', 'Bestanden', 'Nein'); - - for ($i=0; $i0 && $i%10==0) { - // 'Nach oben'-Zeile an Handle anhängen - $tpl->parseBlock('content', 'Aufloesung', 'Topline', TRUE); - } - Answer($_SESSION['bogen']['Fragen'][$i], $_POST['antwort'], FALSE); - $tpl->parseBlock('content', 'Aufloesung', 'Antwort', TRUE, TRUE); - } - - unset($_SESSION['bogen']); - } - else { - // Fragen anzeigen - $tpl->addTemplates(Array( - 'content' => 'bogen-fragen' - )); - - $tpl->addVars(Array( - 'zeit' => date('G:i', $_SESSION['bogen']['StartTime']) - )); - - for ($i=0; $i0 && $i%10==0) { - $tpl->parseBlock('content', 'Bogen', 'Topline', TRUE); - } - - // Frage aus DB holen - $question = getQuestionById($_SESSION['bogen']['Fragen'][$i]); - - $tpl->addVars(Array( - 'frageIndex' => $i + 1, - 'frageID' => $question['ID'], - 'frageNr' => $question['Nr'], - 'abschnittNr' => $question['Abschnitt'], - 'frageText' => $question['Frage'], - 'Antwort1' => $question['Antwort1'], - 'Antwort2' => $question['Antwort2'], - 'Antwort3' => $question['Antwort3'] - )); - - if ($question['Antwort3'] == '') { - $tpl->addVars('rowCnt', '2'); - $tpl->delBlockHandle('content', 'ThreeRows'); - } - else { - $tpl->addVars('rowCnt', '3'); - $tpl->parseBlock('content', 'ThreeRows', 'Row'); - } - - $tpl->parseBlock('content', 'Bogen', 'Frage', TRUE, TRUE); - } - - } -} -else { - $tpl->addVars('navBogenNeu', 'current'); - $tpl->addTemplates(Array('content' => 'bogen-start')); -} + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* +* +* Vollständiger Prüfungsbogen mit zufälligen Fragen +* +*/ + +$GLOBALS['tpl']->parseBlock('page-body', 'NavBogen', 'Sublinks'); +$GLOBALS['tpl']->addVars('navBogen', 'current'); + +if (isset($_REQUEST['create']) && $_REQUEST['create'] == '1') { + // Neuen Bogen erstellen + unset($_SESSION['bogen']); + + // Werte initialisieren + $_SESSION['bogen']['StartTime'] = time(); + $_SESSION['bogen']['Fragen'] = array(); + + // Anz. Abschnitte und Fragen aus der DB holen + $sectionCount = getSingleResult('SELECT COUNT(*) FROM abschnitte WHERE Jahr = ?', array('i', $_SESSION['jahr'])); + + $questionId = 0; + $questionSection = 0; + + $stmt = $GLOBALS['db']->prepare('SELECT ID, Abschnitt FROM fragen WHERE Jahr = ? ORDER BY Abschnitt, Nr'); + $stmt->bind_param('i', $_SESSION['jahr']); + $stmt->execute(); + $stmt->bind_result($questionId, $questionSection); + + // Fragen in Array übertragen + while ($stmt->fetch()) { + $fragen[$questionId] = $questionSection; + } + $stmt->close(); + + // Gesamtanzahl Fragen + $count_ab = array_count_values($fragen); + + // Eine Frage pro Themengebiet aus der DB holen + for ($i = 1; $i <= $sectionCount; $i++) { + $nr = rand(1, $count_ab[$i]); + $id = getSingleResult('SELECT ID FROM fragen WHERE Nr = ? AND Abschnitt = ? AND Jahr = ?', + array('iii', $nr, $i, $_SESSION['jahr'])); + + array_push($_SESSION['bogen']['Fragen'], (int)$id); + + // Frage entfernen + unset($fragen[$id]); + } + + // Restliche Fragen zufällig auffüllen. + // Dazu verbliebene Keys von $fragen als Values in neues Array $fragen2 kopieren, + // da shuffle() die Keys verwirft! + $fragen2 = array(); + foreach ($fragen as $key => $value) { + array_push($fragen2, $key); + } + + shuffle($fragen2); + for ($i = 0; $i < 40 - $sectionCount; $i++) { + array_push($_SESSION['bogen']['Fragen'], array_shift($fragen2)); + } + + // Fragen erneut mischen + shuffle($_SESSION['bogen']['Fragen']); + +} + +if (isset($_SESSION['bogen'])) { + if (isset($_POST['antwort'])) { + // Fragen beantwortet + $richtig = 0; + $falsch = 0; + $fragen_cnt = count($_SESSION['bogen']['Fragen']); + $zeit = time() - $_SESSION['bogen']['StartTime']; + + for ($i = 0; $i < $fragen_cnt; $i++) { + $id = $_SESSION['bogen']['Fragen'][$i]; + $solutionBitmask = getSingleResult('SELECT `Loesung` FROM `fragen` WHERE `ID` = ?', + array('i', $id)); + + $loesung = array(1 => ($solutionBitmask & 0x1), + 2 => (($solutionBitmask & 0x2) >> 1), + 3 => (($solutionBitmask & 0x4) >> 2)); + + if (isset($_POST['antwort'][$id])) { + $korrekt = (($loesung[1] == (isset($_POST['antwort'][$id][1]) ? $_POST['antwort'][$id][1] : 0)) + && ($loesung[2] == (isset($_POST['antwort'][$id][2]) ? $_POST['antwort'][$id][2] : 0)) + && ($loesung[3] == (isset($_POST['antwort'][$id][3]) ? $_POST['antwort'][$id][3] : 0))); + } else { + $korrekt = false; + } + + if ($korrekt) { + $_SESSION["stats"]['Fragen_Richtig']++; + $richtig++; + } else { + $_SESSION["stats"]['Fragen_Falsch']++; + $falsch++; + } + $_SESSION["stats"]['Fragen_Bisher']++; + } + + $_SESSION["stats"]['Boegen_Bisher']++; + + if (($richtig / $fragen_cnt) >= 0.8) + $_SESSION["stats"]['Boegen_Bestanden']++; + else + $_SESSION["stats"]['Boegen_Durchgefallen']++; + + $GLOBALS['db']->query('UPDATE statistik SET fragen=fragen+' . $fragen_cnt + . ',richtig=richtig+' . $richtig + . ',falsch=falsch+' . $falsch + . ',boegen=boegen+1' + . ',bestanden=bestanden+' . (($richtig / $fragen_cnt) >= 0.8 ? 1 : 0) + . ',durchgefallen=durchgefallen+' . (($richtig / $fragen_cnt) < 0.8 ? 1 : 0)); + + $GLOBALS['tpl']->addTemplates('content', 'bogen-ende'); + + $GLOBALS['tpl']->addVars(array( + 'anzFragen' => count($_SESSION['bogen']['Fragen']), + 'zeit' => sprintf('%02d:%02d\'%02d', $zeit / 3600, ($zeit / 60) % 60, $zeit % 60), + 'fragenRichtig' => $richtig, + 'fragenRichtigQuote' => sprintf('%.2f %%', $richtig / $fragen_cnt * 100), + 'fragenFalsch' => $falsch, + 'fragenFalschQuote' => sprintf('%.2f %%', $falsch / $fragen_cnt * 100) + )); + + if (($richtig / $fragen_cnt) >= 0.8) { + $GLOBALS['tpl']->parseBlock('content', 'Bestanden', 'Ja'); + } + else { + $GLOBALS['tpl']->parseBlock('content', 'Bestanden', 'Nein'); + } + + for ($i = 0; $i < count($_SESSION['bogen']['Fragen']); $i++) { + if ($i > 0 && $i % 10 == 0) { + // 'Nach oben'-Zeile an Handle anhängen + $GLOBALS['tpl']->parseBlock('content', 'Aufloesung', 'Topline', TRUE); + } + Answer($_SESSION['bogen']['Fragen'][$i], $_POST['antwort'], FALSE); + $GLOBALS['tpl']->parseBlock('content', 'Aufloesung', 'Antwort', TRUE, TRUE); + } + + unset($_SESSION['bogen']); + } else { + // Fragen anzeigen + $GLOBALS['tpl']->addTemplates(array( + 'content' => 'bogen-fragen' + )); + + $GLOBALS['tpl']->addVars(array( + 'zeit' => date('G:i', $_SESSION['bogen']['StartTime']) + )); + + for ($i = 0; $i < count($_SESSION['bogen']['Fragen']); $i++) { + if ($i > 0 && $i % 10 == 0) { + $GLOBALS['tpl']->parseBlock('content', 'Bogen', 'Topline', TRUE); + } + + // Frage aus DB holen + $question = getQuestionById($_SESSION['bogen']['Fragen'][$i]); + + $GLOBALS['tpl']->addVars(array( + 'frageIndex' => $i + 1, + 'frageID' => $question['ID'], + 'frageNr' => $question['Nr'], + 'abschnittNr' => $question['Abschnitt'], + 'frageText' => $question['Frage'], + 'Antwort1' => $question['Antwort1'], + 'Antwort2' => $question['Antwort2'], + 'Antwort3' => $question['Antwort3'] + )); + + if ($question['Antwort3'] == '') { + $GLOBALS['tpl']->addVars('rowCnt', '2'); + $GLOBALS['tpl']->delBlockHandle('content', 'ThreeRows'); + } else { + $GLOBALS['tpl']->addVars('rowCnt', '3'); + $GLOBALS['tpl']->parseBlock('content', 'ThreeRows', 'Row'); + } + + $GLOBALS['tpl']->parseBlock('content', 'Bogen', 'Frage', TRUE, TRUE); + } + + } +} else { + $GLOBALS['tpl']->addVars('navBogenNeu', 'current'); + $GLOBALS['tpl']->addTemplates(array('content' => 'bogen-start')); +} diff --git a/rg-styles.css b/rg-styles.css index 2fa57ae..a9c5cf1 100644 --- a/rg-styles.css +++ b/rg-styles.css @@ -1,32 +1,32 @@ -/* - * Copyright (C) 2001 Kai Blaschke - * - * The included "THW Thema" templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -.korrekt { padding-left: 22px; background-image: url(img/richtig.gif); background-position: left center; background-repeat: no-repeat; color: #00A000; } -.falsch { padding-left: 22px; background-image: url(img/falsch.gif); background-position: left center; background-repeat: no-repeat; color: #400000; } -.fragebkg tr td.korrekt { background-color: white; color: #00A000;} -.fragebkg tr td.falsch { background-color: white; color: #400000; } +/* + * Copyright (C) 2001 Kai Blaschke + * + * The included "THW Thema" templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +.korrekt { padding-left: 22px; background-image: url(img/richtig.gif); background-position: left center; background-repeat: no-repeat; color: #00A000; } +.falsch { padding-left: 22px; background-image: url(img/falsch.gif); background-position: left center; background-repeat: no-repeat; color: #400000; } +.fragebkg tr td.korrekt { background-color: white; color: #00A000;} +.fragebkg tr td.falsch { background-color: white; color: #400000; } diff --git a/robots.txt b/robots.txt index 15bf958..c2c3f03 100644 --- a/robots.txt +++ b/robots.txt @@ -1,8 +1,8 @@ -User-agent: * -Disallow: - -User-agent: WebReaper -Disallow: / - -User-agent: Slurp -Crawl-delay: 180 +User-agent: * +Disallow: + +User-agent: WebReaper +Disallow: / + +User-agent: Slurp +Crawl-delay: 180 diff --git a/styles.css b/styles.css index 6f9a0d4..ad08328 100644 --- a/styles.css +++ b/styles.css @@ -1,124 +1,124 @@ -/* - * Copyright (C) 2001 Kai Blaschke - * - * The included "THW Thema" templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -html, body { height: 100%; } -body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 100%; margin: 0px; padding: 0px;background-color: white; color: black; background-image:url(img/bg.gif); background-color: transparent; background-position: top left; background-repeat: repeat-y; display: block; } -img { border: none; } -acronym { border-bottom: 1px dashed #00F; cursor: help; } -.contentspalte a { text-decoration:underline; color:#000000;} -.contentspalte a:hover { text-decoration:underline; color:#3A428C;} -.korrekt { background-color: transparent; color: #008000; } -.falsch { background-color: transparent; color: #800000; } -.fragebkg { background-color: #A0A0A0; color: white; max-width: 1000px; width:100%; margin-bottom: 1em; margin-top: 1em; } -.fragebkg tr td { background-color: white; color: black; } -.fragebkg tr td.korrekt { background-color: white; color: #008000;} -.fragebkg tr td.falsch { background-color: white; color: #800000; } -.nav { font-size: 70%; margin-bottom: 40px; line-height: 1.4em; } -.nav ul { margin: 0px; padding: 0px; list-style-type: none; } -.nav li { margin: 0px; padding: 0px; } -.nav a { text-decoration: none; color: #fff; display: block; } -.nav a:hover { text-decoration: none; color: #fff; background-image: url('img/pfeil.gif'); background-repeat: no-repeat; background-position: top left; } -.nav ul a { background-color: #003399; border-bottom: 1px solid #001689; border-top: 1px solid #1443A1; width: 172px; padding: 4px 4px 4px 20px; } -.nav ul ul a { background-color: #436EB2; border-bottom: 1px solid #001689; border-top: 1px solid #6288BE; width: 164px; padding: 4px 4px 4px 28px; } -.nav ul ul ul a { background-color: #6288BE; border-bottom: 1px solid #001689; border-top: 1px solid #85A4CC; width: 156px; padding: 4px 4px 4px 36px; } -ul#navlist li a#current { background-image: url('img/pfeil.gif'); background-repeat: no-repeat; background-position: top left; } -#service { font-size:70%; color:#000000; padding-right:12px; width:100%; height:20px; text-align:right;} -#service a { text-decoration:none; color:#000000; } -#service a:hover { text-decoration:underline; color:#000000; } -#breadcrumb { font-size:69%; color:#FFFFFF; background-color:#003399; padding-top:3px; padding-bottom:2px; padding-left:20px; } -#breadcrumb a { text-decoration:none; color:#FFFFFF; } -#breadcrumb a:hover { text-decoration:underline; } -table.layout { width:100%; } -table.layout td.randlinks { width:12px; height:20px; } -table.layout td.navspalte { background-color:#FFFFFF; width:196px; height:20px; } -table.layout td.navvor { border-bottom:solid 1px #001272; height:20px; } -table.identitaet { width:100%; } -table.identitaet td.thema { border-bottom:solid 1px #6288BE; width:360px; height:78px; } -table.identitaet td.logo { background-color:#003399; border-bottom:solid 1px #6288BE; width:100%; height:78px; text-align:right; } -.content { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:80%; padding-top:20px; padding-right:12px; padding-left:20px; width:100%; } -.contentspalte { padding-right:20px; padding-bottom:20px; width:100%; } -.contentspalte .rubrik { font-weight:normal; font-size:80%; color:#003399; border-top:solid 1px #003399; margin-bottom:2px; text-align:right; } -.contentspalte h1 { font-style:normal; font-size:125%; color:#000000; margin-top:0px; margin-bottom:13px; } -.contentspalte h2 { font-size:100%; color:#000000; margin-top:16px; margin-bottom:14px; font-weight: bold; } -.contentspalte h3 { font-style:normal; font-size:125%; color:#000000; margin-top:0px; margin-bottom:16px; } -.contentspalte p { margin-top:0px; margin-bottom:14px; padding-top:0px; line-height: 1.4em; } -.contentspalte .textblau { color:#003399; } -.contentspalte .seitenueberschrift { font-weight:bold; font-size:125%; color:#000000; border-bottom:solid 1px #003399; margin-bottom:11px; padding-bottom:2px; text-align:left; } -.contentspalte .caption { padding-top: 0px; padding-bottom: 8px;} -.contentspalte .autor { margin-left:1px; font-style: italic; } -.contentspalte .topspacer4px { margin-top:15px; } -.contentspalte ul { margin-top:0px; margin-bottom:13px; margin-left:24px; padding-top:0px; padding-bottom:0px; } -.contentspalte ul li { margin: 0; padding: 0px 0px 0px 6px;} -.contentspalte ol { margin-top:0px; margin-bottom:13px; margin-left:30px; padding-top:0px; padding-bottom:0px; } -.contentspalte ol li { margin: 0; padding: 0;} -.contentspalte ul.seitenanfang { border-bottom:1px solid #003399; list-style-type: none; margin: 24px 0px 16px 0px; padding: .5em 0 .5em 0px; clear: both;} -.contentspalte ul.seitenanfang li a { text-decoration:none; text-align:center; display: block; margin: 0; padding: 0;} -.contentspalte ul.seitenanfang .left { float: left; padding:0;} -.contentspalte ul.seitenanfang .right { float: right;} -.only-print { display: none } -.fragenr { font-size: 1.5em; font-weight: bold; margin-bottom: 0.5em } - -@media print { - html, body { font-size: 80%; } - td.randlinks, - td.navspalte, - .nav, - .navvor, - table.identitaet, - #breadcrumb, - #service, - ul.seitenanfang, - input, - .no-print { display: none; } - .only-print { display: initial } - - table.fragebkg { - page-break-inside: avoid; - margin-bottom: 0.5em; - margin-top: 0.5em; - max-width: none; - border-collapse: collapse; - } - table.fragebkg td { - border: 1px solid black; - } - - .korrekt, - .falsch, - .fragebkg tr td.korrekt, - .fragebkg tr td.falsch { color: black; } - - .print-checkbox { - width: 0.4cm; - height: 0.4cm; - border: 1px solid black; - } - - acronym { border-bottom: none; } - .contentspalte h1 { font-size: 2em; } +/* + * Copyright (C) 2001 Kai Blaschke + * + * The included "THW Thema" templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +html, body { height: 100%; } +body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 100%; margin: 0px; padding: 0px;background-color: white; color: black; background-image:url(img/bg.gif); background-color: transparent; background-position: top left; background-repeat: repeat-y; display: block; } +img { border: none; } +acronym { border-bottom: 1px dashed #00F; cursor: help; } +.contentspalte a { text-decoration:underline; color:#000000;} +.contentspalte a:hover { text-decoration:underline; color:#3A428C;} +.korrekt { background-color: transparent; color: #008000; } +.falsch { background-color: transparent; color: #800000; } +.fragebkg { background-color: #A0A0A0; color: white; max-width: 1000px; width:100%; margin-bottom: 1em; margin-top: 1em; } +.fragebkg tr td { background-color: white; color: black; } +.fragebkg tr td.korrekt { background-color: white; color: #008000;} +.fragebkg tr td.falsch { background-color: white; color: #800000; } +.nav { font-size: 70%; margin-bottom: 40px; line-height: 1.4em; } +.nav ul { margin: 0px; padding: 0px; list-style-type: none; } +.nav li { margin: 0px; padding: 0px; } +.nav a { text-decoration: none; color: #fff; display: block; } +.nav a:hover { text-decoration: none; color: #fff; background-image: url('img/pfeil.gif'); background-repeat: no-repeat; background-position: top left; } +.nav ul a { background-color: #003399; border-bottom: 1px solid #001689; border-top: 1px solid #1443A1; width: 172px; padding: 4px 4px 4px 20px; } +.nav ul ul a { background-color: #436EB2; border-bottom: 1px solid #001689; border-top: 1px solid #6288BE; width: 164px; padding: 4px 4px 4px 28px; } +.nav ul ul ul a { background-color: #6288BE; border-bottom: 1px solid #001689; border-top: 1px solid #85A4CC; width: 156px; padding: 4px 4px 4px 36px; } +ul#navlist li a#current { background-image: url('img/pfeil.gif'); background-repeat: no-repeat; background-position: top left; } +#service { font-size:70%; color:#000000; padding-right:12px; width:100%; height:20px; text-align:right;} +#service a { text-decoration:none; color:#000000; } +#service a:hover { text-decoration:underline; color:#000000; } +#breadcrumb { font-size:69%; color:#FFFFFF; background-color:#003399; padding-top:3px; padding-bottom:2px; padding-left:20px; } +#breadcrumb a { text-decoration:none; color:#FFFFFF; } +#breadcrumb a:hover { text-decoration:underline; } +table.layout { width:100%; } +table.layout td.randlinks { width:12px; height:20px; } +table.layout td.navspalte { background-color:#FFFFFF; width:196px; height:20px; } +table.layout td.navvor { border-bottom:solid 1px #001272; height:20px; } +table.identitaet { width:100%; } +table.identitaet td.thema { border-bottom:solid 1px #6288BE; width:360px; height:78px; } +table.identitaet td.logo { background-color:#003399; border-bottom:solid 1px #6288BE; width:100%; height:78px; text-align:right; } +.content { font-family:Verdana, Arial, Helvetica, sans-serif; font-size:80%; padding-top:20px; padding-right:12px; padding-left:20px; width:100%; } +.contentspalte { padding-right:20px; padding-bottom:20px; width:100%; } +.contentspalte .rubrik { font-weight:normal; font-size:80%; color:#003399; border-top:solid 1px #003399; margin-bottom:2px; text-align:right; } +.contentspalte h1 { font-style:normal; font-size:125%; color:#000000; margin-top:0px; margin-bottom:13px; } +.contentspalte h2 { font-size:100%; color:#000000; margin-top:16px; margin-bottom:14px; font-weight: bold; } +.contentspalte h3 { font-style:normal; font-size:125%; color:#000000; margin-top:0px; margin-bottom:16px; } +.contentspalte p { margin-top:0px; margin-bottom:14px; padding-top:0px; line-height: 1.4em; } +.contentspalte .textblau { color:#003399; } +.contentspalte .seitenueberschrift { font-weight:bold; font-size:125%; color:#000000; border-bottom:solid 1px #003399; margin-bottom:11px; padding-bottom:2px; text-align:left; } +.contentspalte .caption { padding-top: 0px; padding-bottom: 8px;} +.contentspalte .autor { margin-left:1px; font-style: italic; } +.contentspalte .topspacer4px { margin-top:15px; } +.contentspalte ul { margin-top:0px; margin-bottom:13px; margin-left:24px; padding-top:0px; padding-bottom:0px; } +.contentspalte ul li { margin: 0; padding: 0px 0px 0px 6px;} +.contentspalte ol { margin-top:0px; margin-bottom:13px; margin-left:30px; padding-top:0px; padding-bottom:0px; } +.contentspalte ol li { margin: 0; padding: 0;} +.contentspalte ul.seitenanfang { border-bottom:1px solid #003399; list-style-type: none; margin: 24px 0px 16px 0px; padding: .5em 0 .5em 0px; clear: both;} +.contentspalte ul.seitenanfang li a { text-decoration:none; text-align:center; display: block; margin: 0; padding: 0;} +.contentspalte ul.seitenanfang .left { float: left; padding:0;} +.contentspalte ul.seitenanfang .right { float: right;} +.only-print { display: none } +.fragenr { font-size: 1.5em; font-weight: bold; margin-bottom: 0.5em } + +@media print { + html, body { font-size: 80%; } + td.randlinks, + td.navspalte, + .nav, + .navvor, + table.identitaet, + #breadcrumb, + #service, + ul.seitenanfang, + input, + .no-print { display: none; } + .only-print { display: initial } + + table.fragebkg { + page-break-inside: avoid; + margin-bottom: 0.5em; + margin-top: 0.5em; + max-width: none; + border-collapse: collapse; + } + table.fragebkg td { + border: 1px solid black; + } + + .korrekt, + .falsch, + .fragebkg tr td.korrekt, + .fragebkg tr td.falsch { color: black; } + + .print-checkbox { + width: 0.4cm; + height: 0.4cm; + border: 1px solid black; + } + + acronym { border-bottom: none; } + .contentspalte h1 { font-size: 2em; } } \ No newline at end of file diff --git a/zufallsfragen.inc.php b/zufallsfragen.inc.php index 773e6db..35b2379 100644 --- a/zufallsfragen.inc.php +++ b/zufallsfragen.inc.php @@ -1,221 +1,218 @@ - - * - * The included 'THW Thema' templates, logos and the Q&A catalog are protected - * by copyright laws, and must not be used without the written permission - * of the - * - * Bundesanstalt Technisches Hilfswerk - * Provinzialstraße 93 - * D-53127 Bonn - * Germany - * E-Mail: redaktion@thw.de - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* -* -* Fragen in zufälliger Reihenfolge üben -* -*/ - -$tpl->parseBlock('page-body', 'NavZufall', 'Sublinks'); -$tpl->addVars('navZufall', 'current'); - -if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'neu') { - // Fragenkatalog löschen - unset($_SESSION['zufallsfragen']); -} - -if (isset($_SESSION['zufallsfragen'])) { - // Fragenkatalog schon vorhanden. Zu nächster unbeantworteter Frage - // bzw. Antwort der letzten Frage springen - // Wenn keine Fragen mehr im Katalog vorhanden sind, - // Statistik anzeigen. - - if (count($_SESSION['zufallsfragen'])==0) { - // Alle Fragen beantwortet, Ergebnis zeigen - $tpl->addVars(Array( - 'anzFragen' => $_SESSION['fragen_cnt'], - 'fragenRichtig' => $_SESSION['zufallstats']['Richtig'], - 'fragenRichtigQuote' => sprintf('%.2f %%', $_SESSION['zufallstats']['Richtig'] / $_SESSION['fragen_cnt'] * 100), - 'fragenFalsch' => $_SESSION['zufallstats']['Falsch'], - 'fragenFalschQuote' => sprintf('%.2f %%', $_SESSION['zufallstats']['Falsch'] / $_SESSION['fragen_cnt'] * 100), - )); - - $tpl->addTemplates('content', 'zufallsfragen-ende'); - - - - if (($_SESSION['zufallstats']['Richtig'] / $_SESSION['fragen_cnt']) >= 0.8) { - $tpl->parseBlock('content', 'Bestanden', 'Ja'); - } else { - $tpl->parseBlock('content', 'Bestanden', 'Nein'); - } - - // Sessiondaten löschen - unset($_SESSION['zufallsfragen']); - unset($_SESSION['frage_nr']); - unset($_SESSION['fragen_cnt']); - unset($_SESSION['zufallstats']); - unset($_SESSION['bogen']); - - return; - - } - - - if (!isset($_REQUEST['frage_id']) || $_REQUEST['frage_id'][0] <> $_SESSION['zufallsfragen'][0]) { - $tpl->addTemplates(Array('content' => 'zufallsfragen-frage')); - - // Frage stellen - SingleQuestion($_SESSION['zufallsfragen'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt']); - - return; - } - - $tpl->addTemplates(Array('content' => 'zufallsfragen-aufloesung')); - - // Antwort auswerten - - questionHeader($_REQUEST['frage_id'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt'], $_SESSION['jahr']); - $korrekt = Answer($_REQUEST['frage_id'][0], $_REQUEST['antwort']); - - // Statistik anpassen - if ($korrekt) { - $_SESSION['zufallstats']['Richtig']++; - $_SESSION['stats']['Fragen_Richtig']++; - $stmt = $GLOBALS['db']->prepare('UPDATE statistik SET fragen=fragen+1,richtig=richtig+1'); - $stmt->execute(); - } else { - $_SESSION['zufallstats']['Falsch']++; - $_SESSION['stats']['Fragen_Falsch']++; - $stmt = $GLOBALS['db']->prepare('UPDATE statistik SET fragen=fragen+1,falsch=falsch+1'); - $stmt->execute(); - } - - $tpl->addVars(Array( - 'submitText' => ($_SESSION['frage_nr']==$_SESSION['fragen_cnt'])?'Gesamtstatistik':'Nächste Frage', - 'aktuelleFrage' => $_SESSION['frage_nr'], - 'fragenRichtig' => $_SESSION['zufallstats']['Richtig'], - 'fragenFalsch' => $_SESSION['zufallstats']['Falsch'], - 'fragenQuote' => sprintf('%0.2f', $_SESSION['zufallstats']['Falsch']/$_SESSION['frage_nr']*100) . '%' - )); - - // Frage entfernen - array_shift($_SESSION['zufallsfragen']); - - $_SESSION['frage_nr']++; - $_SESSION['stats']['Fragen_Bisher']++; - - return; -} - -// Neuen Fragenkatalog erstellen -if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'start') { - - $topicCount = getSingleResult('SELECT COUNT(*) AS Cnt FROM abschnitte WHERE Jahr = ?', - array('i', $_SESSION['jahr'])); - - // Gewählte Abschnitte in Query einsetzen - $selectedTopics = array(); - for ($topic = 1; $topic <= $topicCount; $topic++){ - if (isset($_REQUEST['abschnitt'][$topic]) && $_REQUEST['abschnitt'][$topic] == '1') { - array_push($selectedTopics, $topic); - } - } - - if (count($selectedTopics) == 0) - { - // Kein Themenabschnitt gewählt - $tpl->addTemplates(Array('content' => 'zufallsfragen-error')); - - return; - } - - // Sessiondaten löschen - unset($_SESSION['zufallsfragen']); - unset($_SESSION['frage_nr']); - unset($_SESSION['fragen_cnt']); - unset($_SESSION['zufallstats']); - unset($_SESSION['bogen']); - - // Sessions-Variablen initialisieren - $_SESSION['zufallsfragen'] = array(); - $_SESSION['frage_nr'] = 1; - $_SESSION['zufallstats'] = array('Richtig' => '0', 'Falsch' => '0'); - - $tpl->addTemplates(Array('content' => 'zufallsfragen-frage')); - - // Fragen holen - $inClauseParams = implode(',', array_fill(0, count($selectedTopics), '?')); - $inClauseTypes = str_repeat('i', count($selectedTopics)); - $params = array_merge(array('i'.$inClauseTypes, $_SESSION['jahr']), $selectedTopics); - - $stmt = $GLOBALS['db']->prepare('SELECT ID FROM fragen WHERE Jahr = ? AND Abschnitt IN (' . $inClauseParams . ')'); - callBindParamArray($stmt, $params); - $stmt->execute(); - $stmt->bind_result($id); - - // Fragen in Array übertragen - while ($stmt->fetch()) { - array_push($_SESSION['zufallsfragen'], $id); - } - $stmt->close(); - - // Fragen zufällig mischen - shuffle($_SESSION['zufallsfragen']); - - // Nur gewählte Anzahl Fragen zulassen - if ($_REQUEST['fragen'] > 0 && $_REQUEST['fragen'] < count($_SESSION['zufallsfragen'])) { - $_SESSION['zufallsfragen'] = array_slice($_SESSION['zufallsfragen'], 0, $_REQUEST['fragen']); - } - - // Anzahl in Session speichern - $_SESSION['fragen_cnt'] = count($_SESSION['zufallsfragen']); - - // Erste Frage stellen - SingleQuestion($_SESSION['zufallsfragen'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt']); - - return; - -} - -// Startseite mit Abschnittsauswahl -$tpl->addVars('navZufallNeu', 'current'); -$abschnitte = getTopics(); -$topicCount = getSingleResult('SELECT COUNT(*) AS Cnt FROM abschnitte WHERE Jahr = ?', - array('i', $_SESSION['jahr'])); -$maxFragen = getSingleResult('SELECT COUNT(*) AS Cnt FROM fragen WHERE Jahr = ?', - array('i', $_SESSION['jahr'])); - -$tpl->addVars(Array( - 'abschnitteAnz' => $topicCount, - 'maxFragen' => $maxFragen -)); - -$tpl->addTemplates('content', 'zufallsfragen-start'); - -foreach ($abschnitte as $nr => $description) { - $tpl->addVars(Array( - 'abschnittNr' => $nr, - 'abschnittDesc' => htmlspecialchars($description) - )); - - $tpl->parseBlock('content', 'Abschnitte', 'Row', TRUE); -} + + * + * The included 'THW Thema' templates, logos and the Q&A catalog are protected + * by copyright laws, and must not be used without the written permission + * of the + * + * Bundesanstalt Technisches Hilfswerk + * Provinzialstraße 93 + * D-53127 Bonn + * Germany + * E-Mail: redaktion@thw.de + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/* +* +* Fragen in zufälliger Reihenfolge üben +* +*/ + +$GLOBALS['tpl']->parseBlock('page-body', 'NavZufall', 'Sublinks'); +$GLOBALS['tpl']->addVars('navZufall', 'current'); + +if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'neu') { + // Fragenkatalog löschen + unset($_SESSION['zufallsfragen']); +} + +if (isset($_SESSION['zufallsfragen'])) { + // Fragenkatalog schon vorhanden. Zu nächster unbeantworteter Frage + // bzw. Antwort der letzten Frage springen. + // Wenn keine Fragen mehr im Katalog vorhanden sind, + // Statistik anzeigen. + + if (count($_SESSION['zufallsfragen']) == 0) { + // Alle Fragen beantwortet, Ergebnis zeigen + $GLOBALS['tpl']->addVars(array( + 'anzFragen' => $_SESSION['fragen_cnt'], + 'fragenRichtig' => $_SESSION['zufallstats']['Richtig'], + 'fragenRichtigQuote' => sprintf('%.2f %%', $_SESSION['zufallstats']['Richtig'] / $_SESSION['fragen_cnt'] * 100), + 'fragenFalsch' => $_SESSION['zufallstats']['Falsch'], + 'fragenFalschQuote' => sprintf('%.2f %%', $_SESSION['zufallstats']['Falsch'] / $_SESSION['fragen_cnt'] * 100), + )); + + $GLOBALS['tpl']->addTemplates('content', 'zufallsfragen-ende'); + + + if (($_SESSION['zufallstats']['Richtig'] / $_SESSION['fragen_cnt']) >= 0.8) { + $GLOBALS['tpl']->parseBlock('content', 'Bestanden', 'Ja'); + } else { + $GLOBALS['tpl']->parseBlock('content', 'Bestanden', 'Nein'); + } + + // Sessiondaten löschen + unset($_SESSION['zufallsfragen']); + unset($_SESSION['frage_nr']); + unset($_SESSION['fragen_cnt']); + unset($_SESSION['zufallstats']); + unset($_SESSION['bogen']); + + return; + } + + + if (!isset($_REQUEST['frage_id']) || $_REQUEST['frage_id'][0] <> $_SESSION['zufallsfragen'][0]) { + $GLOBALS['tpl']->addTemplates(array('content' => 'zufallsfragen-frage')); + + // Frage stellen + SingleQuestion($_SESSION['zufallsfragen'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt']); + + return; + } + + $GLOBALS['tpl']->addTemplates(array('content' => 'zufallsfragen-aufloesung')); + + // Antwort auswerten + + questionHeader($_REQUEST['frage_id'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt']); + $korrekt = Answer($_REQUEST['frage_id'][0], $_REQUEST['antwort']); + + // Statistik anpassen + if ($korrekt) { + $_SESSION['zufallstats']['Richtig']++; + $_SESSION['stats']['Fragen_Richtig']++; + $stmt = $GLOBALS['db']->prepare('UPDATE statistik SET fragen=fragen+1,richtig=richtig+1'); + } else { + $_SESSION['zufallstats']['Falsch']++; + $_SESSION['stats']['Fragen_Falsch']++; + $stmt = $GLOBALS['db']->prepare('UPDATE statistik SET fragen=fragen+1,falsch=falsch+1'); + } + $stmt->execute(); + + $GLOBALS['tpl']->addVars(array( + 'submitText' => ($_SESSION['frage_nr'] == $_SESSION['fragen_cnt']) ? 'Gesamtstatistik' : 'Nächste Frage', + 'aktuelleFrage' => $_SESSION['frage_nr'], + 'fragenRichtig' => $_SESSION['zufallstats']['Richtig'], + 'fragenFalsch' => $_SESSION['zufallstats']['Falsch'], + 'fragenQuote' => sprintf('%0.2f', $_SESSION['zufallstats']['Falsch'] / $_SESSION['frage_nr'] * 100) . '%' + )); + + // Frage entfernen + array_shift($_SESSION['zufallsfragen']); + + $_SESSION['frage_nr']++; + $_SESSION['stats']['Fragen_Bisher']++; + + return; +} + +// Neuen Fragenkatalog erstellen +if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'start') { + + $topicCount = getSingleResult('SELECT COUNT(*) AS Cnt FROM abschnitte WHERE Jahr = ?', array('i', $_SESSION['jahr'])); + + // Gewählte Abschnitte in Query einsetzen + $selectedTopics = array(); + for ($topic = 1; $topic <= $topicCount; $topic++) { + if (isset($_REQUEST['abschnitt'][$topic]) && $_REQUEST['abschnitt'][$topic] == '1') { + $selectedTopics[] = $topic; + } + } + + if (count($selectedTopics) == 0) { + // Kein Themenabschnitt gewählt + $GLOBALS['tpl']->addTemplates(array('content' => 'zufallsfragen-error')); + + return; + } + + // Sessiondaten löschen + unset($_SESSION['zufallsfragen']); + unset($_SESSION['frage_nr']); + unset($_SESSION['fragen_cnt']); + unset($_SESSION['zufallstats']); + unset($_SESSION['bogen']); + + // Sessions-Variablen initialisieren + $_SESSION['zufallsfragen'] = array(); + $_SESSION['frage_nr'] = 1; + $_SESSION['zufallstats'] = array('Richtig' => '0', 'Falsch' => '0'); + + $GLOBALS['tpl']->addTemplates(array('content' => 'zufallsfragen-frage')); + + // Fragen holen + $inClauseParams = implode(',', array_fill(0, count($selectedTopics), '?')); + $inClauseTypes = str_repeat('i', count($selectedTopics)); + $params = array_merge(array('i' . $inClauseTypes, $_SESSION['jahr']), $selectedTopics); + + $id = 0; + + $stmt = $GLOBALS['db']->prepare('SELECT ID FROM fragen WHERE Jahr = ? AND Abschnitt IN (' . $inClauseParams . ')'); + callBindParamArray($stmt, $params); + $stmt->execute(); + $stmt->bind_result($id); + + // Fragen in Array übertragen + while ($stmt->fetch()) { + $_SESSION['zufallsfragen'][] = $id; + } + $stmt->close(); + + // Fragen zufällig mischen + shuffle($_SESSION['zufallsfragen']); + + // Nur gewählte Anzahl Fragen zulassen + if ($_REQUEST['fragen'] > 0 && $_REQUEST['fragen'] < count($_SESSION['zufallsfragen'])) { + $_SESSION['zufallsfragen'] = array_slice($_SESSION['zufallsfragen'], 0, $_REQUEST['fragen']); + } + + // Anzahl in Session speichern + $_SESSION['fragen_cnt'] = count($_SESSION['zufallsfragen']); + + // Erste Frage stellen + SingleQuestion($_SESSION['zufallsfragen'][0], $_SESSION['frage_nr'], $_SESSION['fragen_cnt']); + + return; + +} + +// Startseite mit Abschnittsauswahl +$GLOBALS['tpl']->addVars('navZufallNeu', 'current'); +$abschnitte = getTopics(); +$topicCount = getSingleResult('SELECT COUNT(*) AS Cnt FROM abschnitte WHERE Jahr = ?', + array('i', $_SESSION['jahr'])); +$maxFragen = getSingleResult('SELECT COUNT(*) AS Cnt FROM fragen WHERE Jahr = ?', + array('i', $_SESSION['jahr'])); + +$GLOBALS['tpl']->addVars(array( + 'abschnitteAnz' => $topicCount, + 'maxFragen' => $maxFragen +)); + +$GLOBALS['tpl']->addTemplates('content', 'zufallsfragen-start'); + +foreach ($abschnitte as $nr => $description) { + $GLOBALS['tpl']->addVars(array( + 'abschnittNr' => $nr, + 'abschnittDesc' => htmlspecialchars($description) + )); + + $GLOBALS['tpl']->parseBlock('content', 'Abschnitte', 'Row', TRUE); +}