Exemplo n.º 1
0
 public function parse($qstr)
 {
     global $ruleSet;
     if (str_replace([" ", "\t", "\n", "\r"], '', $qstr) === '') {
         echo "Error: No text submitted/empty file.";
         return '';
     }
     //$t=microtime();
     $nMatches = preg_match_all($this->qregex(), $qstr, $qtext);
     //echo '(TIME-millis:'.(microtime()-$t).':TIME)';
     $qs = new qIO();
     for ($i = 0; $i < $nMatches; $i++) {
         try {
             //0 full match
             //1 QPart
             //2 Number
             //3 Subj
             //4 QType
             //5 QuestionText
             //6-9 W-Z
             //10 Answer
             //Indices: 0 full match, Part, Number, Subject, MCQText, ChoicesW, ChoicesX, ChoicesY, ChoicesZ, SAQText, MCa, AnswerText
             $qs->addByArray(array(array("isB" => strpos('tb', strtolower(substr($qtext[1][$i], 0, 1))), "Subject" => array_search(strtolower(substr($qtext[2][$i], 0, 1)), $ruleSet["SubjChars"]), "isSA" => $qtext[4][$i] == 'Short Answer', "Question" => str_replace(["\r", "\n"], '', $qtext[5][$i]), "MCW" => $qtext[6][$i], "MCX" => $qtext[7][$i], "MCY" => $qtext[8][$i], "MCZ" => $qtext[9][$i], "MCa" => substr($qtext[10][$i], 0, 1), "Answer" => $qtext[10][$i])));
         } catch (Exception $e) {
             echo "ERROR: " . $e->getMessage();
             //--todo-- DISPLAY ERRORS? OR JUST IGNORING? OR IDK IT SHOULDN'T EVEN HAPPEN
         }
     }
     $qs->commit();
     $parsedQIDs = $qs->getQIDs();
     /*echo "Duplicates: none<br><br>";*/
     echo "<b>Total uploaded Question-IDs: " . (count($parsedQIDs) == 0 ? "no questions entered" : arrayToRanges($parsedQIDs) . " (" . count($parsedQIDs) . " total entered)") . "</b>";
     return preg_replace($this->qregex(), '', $qstr);
     //stuff remaining after questions detected
 }
Exemplo n.º 2
0
*/
$q = new qIO();
//docexport functionality
if (csrfVerify() && posted('getDoc', 'qidcsv', 'docexport')) {
    if ($_POST['docexport'] == 'QIDCSV') {
        sendfile('text/plain', 'txt', $_POST['qidcsv']);
    } elseif ($_POST['docexport'] == 'HTML') {
        sendfile('text/html', 'html', $q->clear()->addByQID(explode(',', $_POST['qidcsv']))->allToHTML('<div>[QID %QID%]<br><center><b>%PART%</b></center><br>%SUBJECT% <i>%TYPE%</i> %QUESTION%<br><small>%MCOPTIONS%</small><br>ANSWER: <b>%ANSWER%</b></div><br><br>'));
    } else {
        alert('Invalid format for export.', -1);
    }
}
//MarkBad functionality
if (csrfVerify() && posted("markBad", "qids")) {
    //--todo-- should be able to EDIT instead of just marking wrong. Also store history of questions viewed - "Views" table (hugeness) so can look back, mark for look back, etc.
    alert('Marked question(s) ' . arrayToRanges($q->clear()->addByQID(array_intersect_key($_POST["qids"], array_flip($_POST["markBad"])))->markBad()->getQIDs()) . ' as bad.', 1);
}
$counts = array("QParts" => count($ruleSet["QParts"]), "Subjects" => count($ruleSet["Subjects"]), "QTypes" => count($ruleSet["QTypes"]));
$fullname = array("QParts" => "Question Part", "Subjects" => "Subject", "QTypes" => "Question Type");
//Config options, and setting the SESSION variables to new values based on POST variables
$checkboxoptions = "<div style='font-size:1.5em;font-weight:bold;'>Options</div>";
if (!sessioned('randq')) {
    $_SESSION["randq"] = array();
}
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;
Exemplo n.º 3
0
    $error = true;
}
if (csrfVerify() && (posted("copypaste") || filed("fileupload") || posted("directentry"))) {
    echo '<div style="font-size:0.8em;border:solid 1px #000000;display:inline-block;padding:5px;">
		<i>We are processing your questions right now...</i><br><br>';
    if (posted("directentry")) {
        $err = '';
        try {
            $q = new qIO();
            $q->addByArray($_POST["Q"]);
            $q->commit();
        } catch (Exception $e) {
            $err = "Error: " . $e->getMessage();
        }
        if ($err == '') {
            echo "Questions entered successfully, with Question-IDs <b>" . arrayToRanges($q->getQIDs()) . "</b><br><br><br>";
        } else {
            echo $err;
        }
    } else {
        require_class("qIO", "qParser");
        $qp = new qParser();
        $error = false;
        if (posted("copypaste")) {
            $unparsed = $qp->parse($_POST["copypaste"]);
        } elseif (filed("fileupload")) {
            require_class("fileToStr");
            $fs = new fileToStr();
            if (is_array($_FILES["fileupload"]["tmp_name"])) {
                //for multiple-supporting browsers
                foreach ($_FILES["fileupload"]["tmp_name"] as $ind => $tmp_name) {