Example #1
0
        $choice[$i] = array($_POST["choice{$i}"], isset($_POST["correct{$i}"]) ? 'true' : 'false', isset($_POST["exclusive{$i}"]) ? 'true' : 'false');
    }
    $db->begin();
    try {
        if (($subject = $_POST['subject']) == 0) {
            $newsubject = $_POST['newsubject'];
            try {
                $subject = $db->insertSubject($newsubject);
            } catch (Exception $e) {
                echo "<center>Không thể tạo <b>Môn</b> mới với tên '{$newsubject}'.</center>";
                throw $e;
            }
        }
        $questionID = $db->insertQuestion($question, $subject, isset($_POST['shuffleable']) ? 'true' : 'false', 0.5);
        foreach ($choice as $c) {
            $db->insertChoice($questionID, $c[0], $c[1], $c[2]);
        }
        $db->commit();
        echo "<center>Tạo câu hỏi mới thành công!</center>";
    } catch (Exception $e) {
        $db->rollback();
        ?>
				<center>Không thể tạo <b>Câu hỏi</b> mới.</center>
				<center>Xin hãy kiểm tra thông tin đã nhập.</center>
				<center><button onClick='history.back()'>Trở lại</button></center>
			<?php 
        echo $e->getMessage();
        return -1;
    }
}
?>
Example #2
0
 $txtGen = new TXTGen();
 $subjects = $db->getColumn('ID', 'oes_Subject');
 foreach ($subjects as $subject) {
     for ($i = 0; $i < 100; ++$i) {
         $question = $txtGen->randParagraph(mt_rand(1, 6));
         $rank = mt_rand() / mt_getrandmax();
         $type = mt_rand(0, 2);
         switch ($type) {
             case 0:
                 // single choice
                 $questionID = $db->insertQuestion($question, $subject, 'true', $rank);
                 $n = mt_rand(3, 5);
                 $c = mt_rand(0, $n - 1);
                 for ($j = 0; $j < $n; ++$j) {
                     $choice = $txtGen->randSentence();
                     $db->insertChoice($questionID, $choice, $j == $c ? 'true' : 'false', 'true');
                 }
                 break;
             case 1:
                 // multiple choice with an exclusive "no right answer" option
                 $questionID = $db->insertQuestion($question, $subject, 'false', $rank);
                 $n = mt_rand(3, 4);
                 $nc = 'true';
                 for ($j = 0; $j < $n; ++$j) {
                     $choice = $txtGen->randSentence();
                     if (mt_rand(0, 9) < 4) {
                         $db->insertChoice($questionID, $choice, 'true', 'false');
                         $nc = 'false';
                     } else {
                         $db->insertChoice($questionID, $choice, 'false', 'false');
                     }