Example #1
0
<?php

require "inc/functions.php";
autoLoader();
$questions = getAllQuestions();
if (!isQuizStarted()) {
    //ilk çalıştırma, oturumu başlat
    startQuiz(count($questions));
}
// cevap geldiyse
//      cevabı kontrol et, değerleri artır
if (isset($_POST['answer'])) {
    if ($_POST['answer'] == $questions[$_SESSION['answeredQuestionCount']]['answer']) {
        // cevap doğru, işlem yap
        $_SESSION['correctAnswerCount']++;
    }
    $_SESSION['answeredQuestionCount']++;
}
// sıradaki soruyu seç, göster
// son soru görüntüleniyorsa
//      butonun metnini değiştir
if ($_SESSION['answeredQuestionCount'] == $_SESSION['totalQuestionCount'] - 1) {
    $btnText = "Testi Bitir";
} else {
    $btnText = "Sonraki Soru";
}
//  tüm sorular yanıtlandıysa
//      testi bitir, sonuca yönlendir
if ($_SESSION['answeredQuestionCount'] == $_SESSION['totalQuestionCount']) {
    if (empty($_SESSION['finishTime'])) {
        $_SESSION['finishTime'] = time();
<?php

// soru formu göstereceğim
// bunu bir sayfaya post edeceğim
// gelen veri geçerliyse kaydedeceğim
if ($_POST) {
    require "../inc/functions.php";
    autoLoader();
    $questions = getAllQuestions("../");
    // veriyi yazacağımız dosya yolu
    $questionsDataFilePath = "../data/questions.txt";
    $message = "Soru eklenemedi";
    // eski sorulara yenisini ekliyoruz
    array_push($questions, $_POST);
    // yeni soru eklenmiş haliyle sorular değişkeni
    $encodedQuestions = json_encode($questions);
    // dosya bulunmuyorsa oluşturuyoruz
    if (!file_exists($questionsDataFilePath)) {
        touch($questionsDataFilePath);
    }
    // dosyayı açıp veriyi yazıp kapatıyoruz
    $questionsDataFile = fopen($questionsDataFilePath, "w");
    if (fwrite($questionsDataFile, $encodedQuestions)) {
        $message = "Soru eklendi.";
    }
    fclose($questionsDataFile);
}
include "../inc/header.php";
if (isset($message)) {
    echo $message . "<hr>";
}
Example #3
0
function test_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $question['name'] = test_input($_POST['name']);
    $question['email'] = test_input($_POST['email']);
    $question['topic'] = test_input($_POST['topic']);
    $question['content'] = test_input($_POST['content']);
    $question['q_id'] = $_POST['q_id'];
    updateQuestion($question);
}
$tabQuestion = getAllQuestions();
$nQuestion = mysqli_num_rows($tabQuestion);
?>
<div class="view">
  <h1>Simple Stack Exchange</h1><br>
  <form id="search">
    <input type="text" name="search">
    <input type="submit" value="Search">
  </form>
  <div class="ask-here">
    <div>Cannot find what are you looking for?</div>
    <div><a href="ask.php" >Ask here</a></div>
  </div>

  <p id='head'>Recently Asked Question</p>
  <hr>
 * Generate Bebras JSON for each tasks
 */
require_once "../../shared/common.php";
require_once 'Bebras.php';
function getAllQuestions($db)
{
    $stmt = $db->prepare("SELECT `question`.`ID`, `question`.`key`, `question`.`folder`, `question`.`name`, `question`.`answerType`, `question`.`expectedAnswer` FROM `question`");
    $stmt->execute();
    $questionsData = array();
    while ($row = $stmt->fetchObject()) {
        $questionsData[$row->ID] = $row;
    }
    return $questionsData;
}
$questionsDir = Bebras::getQuestionsDirectory();
$questions = getAllQuestions($db);
foreach ($questions as $curQuestion) {
    $curQuestionDir = $questionsDir . '/' . $curQuestion->folder . '/' . $curQuestion->key;
    if (is_dir($curQuestionDir)) {
        $content = file_get_contents($curQuestionDir . '/index.html');
        // Add id
        //$content = preg_replace('#(var json = {.*\"id\": \")(\",)#isU', '$1http://castor-informatique.fr/tasks/'.$curQuestion->folder . '/' . $curQuestion->key.'/$2', $content);
        // Windows to UNIX conversion
        //$content = str_replace(chr(13).chr(10), chr(10), $content);
        //file_put_contents($curQuestionDir.'/index.html', $content);
        // Add postmessage
        $content = str_replace('<script class="remove" type="text/javascript" src="../../modules/gen_task_resources.js"></script>', '<script class="remove" type="text/javascript" src="../../modules/gen_task_resources.js"></script>' . "\r\n" . '<script class="module beaver" type="text/javascript" src="../../modules/jquery.ba-postmessage.min.js" id="http://castor-informatique.fr/tasks/modules/jquery.ba-postmessage.min.js"></script>' . "\r\n" . '<script class="module beaver" type="text/javascript" src="../../modules/pm_task_interface.js" id="http://castor-informatique.fr/tasks/modules/pm_task_interface.js"></script>' . "\r\n", $content);
        file_put_contents($curQuestionDir . '/index.html', $content);
        echo $curQuestionDir . '<br />';
        /*$bebras = new Bebras($curQuestion, $curQuestionDir);
          $bebras->generateJsonFile();
               
            </select>
            <input type="submit"  name = "go" value="GO">

            </form>
            <h3>
            	<?php 
if (isset($_POST['go'])) {
    $courseId = $_POST['course_id'];
    if ($courseId == "none") {
        echo "Please select a course";
    } else {
        //print_array(questionsAvailable($courseId));die();
        list($questions, $options) = questionsAvailable($courseId);
        echo $questions . " questions with" . " " . $options . " alternatives";
        /*foreach($counter as $count)
         	{
                            echo  $count[0]." questions with"." ".$count[1]." alternatives";
                            echo "note<br><br>";
                            echo "difficulty level 1: ".$count[2]."<br>";
                            echo "difficulty level 2: ".$count[3]."<br>";
                            echo "difficulty level 3: ".$count[4]."<br>";
         	}*/
    }
} elseif (isset($_POST['total'])) {
    echo getAllQuestions();
}
?>
            </h3>
</body>
</html>