Example #1
0
 public function addRand($QParts, $Subjects, $QTypes, $num)
 {
     //arrays of the numbers to include eg subj [0,1,4] for b,c,e
     global $MARK_AS_BAD_THRESHOLD, $ruleSet, $MAX_NUMQS, $DEFAULT_NUMQS;
     $num = normRange($num, 1, $MAX_NUMQS, $DEFAULT_NUMQS);
     $where = new WhereClause('and');
     $where->add('MarkBad<%i', $MARK_AS_BAD_THRESHOLD);
     $where->add('Deleted=0');
     $db = array("isB", "Subject", "isSA");
     foreach (array("QParts", "Subjects", "QTypes") as $i => $name) {
         if (!val('*i+', $indices = eval('$' . $name . ';'))) {
             continue;
         }
         //Fetches and verifies array of index values that the user may want.
         $indices = array_values(array_unique($indices));
         //Eliminates stupidity
         $sub = $where->addClause('or');
         foreach ($indices as $index) {
             if (inRange($index, 0, count($ruleSet[$name]) - 1)) {
                 //Make sure the index is correct.
                 $sub->add('%b=%i', $db[$i], $index);
             }
         }
         //Inserts the index into the proper DB field
     }
     $qresult = DB::queryRaw("SELECT * FROM questions WHERE %l ORDER BY TimesViewed ASC, " . SQLRAND('QID') . " LIMIT %i", $where, $num);
     //Order by TimesViewed, and then randomize within each TimesViewed value.
     //NOTE: TimesViewed is despite categories, and if you have something like 2 10 10 10, you'll get the 2 at least 8 times in a row.
     //The assumption that there is a large pool for _each_ possible classification (2*5*2=20 of them) eliminates this problem.
     if ($qresult->num_rows != $num) {
         $this->user_err("Not enough such questions exist.");
     }
     $this->addQResult($qresult);
     $this->updateIs(range(count($this->Questions) - $num, count($this->Questions) - 1), "TimesViewed=TimesViewed+1");
     //--todo-- do this in user-specific storage instead.
     return $this;
 }
Example #2
0
}
foreach ($fullname as $name => $full) {
    $count = count($ruleSet[$name]);
    $checkboxoptions .= '<div><b>' . $full . '</b> ';
    if (csrfVerify() && posted($name)) {
        $_SESSION["randq"][$name] = $_POST[$name];
    } elseif (!array_key_exists($name, $_SESSION["randq"])) {
        $_SESSION["randq"][$name] = NULL;
    }
    //Remembering in $_SESSION
    for ($i = 0; $i < $count; $i++) {
        $checkboxoptions .= '<label>' . $ruleSet[$name][$i] . ' <input type="checkbox" name="' . $name . '[]" value="' . $i . '" ' . (is_array($_SESSION["randq"][$name]) && in_array($i, $_SESSION["randq"][$name]) || $_SESSION["randq"][$name] === NULL ? 'checked' : '') . ' /></label> ';
    }
    $checkboxoptions .= '</div>';
}
$_SESSION["randq"]["numqs"] = normRange(csrfVerify() ? POST("numqs") : NULL, 1, $MAX_NUMQS, $DEFAULT_NUMQS);
$checkboxoptions .= "<b>Number of Questions</b> (max {$MAX_NUMQS}) <input type='number' name='numqs' value='{$_SESSION["randq"]["numqs"]}' min='1' max='{$MAX_NUMQS}'/>";
//Using the session variables set above to get random questions.
//--todo-- what's the point of "add" if you're only doing it this once? Overhead w/ $Q? Really OP.
if ($E = $q->clear()->addRand($_SESSION["randq"]["QParts"], $_SESSION["randq"]["Subjects"], $_SESSION["randq"]["QTypes"], $_SESSION["randq"]["numqs"])->error) {
    alert($E, -1);
}
$checkboxoptions .= '<input type="hidden" name="qidcsv" value="' . implode(',', $q->getQIDs()) . '" />' . '<br><input type="submit" value="Next" onclick="return confirm(\'Not all questions are revealed. Are you sure?\');"/>' . '<br><br><div><b>Export Below as Document:</b> <select name="docexport"><option value="QIDCSV">Question-ID comma-separated values</option><option value="HTML">HTML</option></select><input type="submit" name="getDoc" value="Export"/></div>';
?>
<!--div class='question'>
	<span style='display:inline-block;width:40%;'>[QID %QID%]</span><span style='display:inline-block;width:59%;text-align:right;font-size:0.8em;'><a href="#" class="editbtn">[Edit]</a></span>
	<div>Mark as Bad: <input type="checkbox" name="markBad[]" value="%N%"/></div>
	<input type="hidden" name="qids[]" value="%QID%"/>
	<div style='font-weight:bold;text-align:center;' class="part">%PART%</div>
	<div><span class="subject">%SUBJECT%</span> <i><span class="type">%TYPE%</span></i> <span class="qtext">%QUESTION%</span></div>
	<div style="font-size:0.9em;">%MCOPTIONS%</div>