function rightAnswersCount() { $questions = checkAnswers(); $count = 0; foreach ($questions as $q) { if ($q['valid']) { $count++; } } return $count; }
function router() { $view = BASE . 'views/home.part.php'; if (isset($_GET['go'])) { $view = BASE . 'views/edit.part.php'; } if (!empty($_POST)) { checkAnswers(); $view = BASE . 'views/show.part.php'; } require $view; }
<?php require BASE . 'views/header.part.php'; ?> <h1>yatta</h1> <!-- on fait une boucle sur les reponses traitées, la version de foreach qui finit par deux points est plus commode dans le contexte d'une page html --> <?php foreach (checkAnswers() as $key => $p) { ?> <div> <h2><i class="icon <?php echo $p['valid'] ? 'green checkmark' : 'red close'; ?> "></i> <?php echo $p['question']; ?> </h2> <?php if ($p['valid']) { ?> Bravo <?php } else { ?> Bouuuuuh ! <?php
} else { if ($mode == MODE_TEST_SUBMIT) { $username = $_GET["username"]; $password = $_GET["password"]; $sAnsArrCsv = $_GET["ans"]; $testModeDb = new TestModeDatabase(); $params = $testModeDb->getTestParams(); $qSeed = $params["seed"]; $qAmt = $params["questionAmount"]; $qTopics = $params["topics"]; for ($i = 0; $i < count($sAnsArrCsv); $i++) { $sAnsArr[] = explode(",", $sAnsArrCsv[$i]); } $score = 0; // Question generator checkAnswers($qAmt, $qTopics); $submissionParams = array(); $submissionParams["answer"] = $sAnsArr; $submissionParams["grade"] = $score; $testModeDb->submit($username, $password, $submissionParams); echo $score; } else { if ($mode == MODE_TEST_GET_INFO) { $username = $_GET["username"]; $password = $_GET["password"]; $testModeDb = new TestModeDatabase(); $userDb = new UserDatabase(); $testParams = $testModeDb->getTestParams(); $info = array(); $info["timeElapsed"] = $testModeDb->getTimeElapsed($username, $password); $info["name"] = $userDb->getName($username, $password);
$answers[2] = '02'; $answers[3] = '1'; function checkAnswers() { global $totalPoints; global $earnedPoints; if (!isset($_POST['btn'])) { return; } checkRadio('0'); checkSelect('1'); checkCheckboxs('2'); checkCheckboxs('3'); echo 'Sait pisteet ' . $earnedPoints . '/' . $totalPoints; } checkAnswers(); function checkRadio($question = '0') { global $answers; global $totalPoints; global $earnedPoints; $totalPoints += 1; if (!isset($_POST['q' . $question])) { return; } if ($_POST['q' . $question] == $answers[$question]) { $earnedPoints += 1; } } function checkSelect($question = '0') {