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 }
$_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> <br>ANSWER: <span class='hiddenanswer'><span class='ans'>%ANSWER%</span> <span class='hov'>[hover to show]</span></span> <br> <a href="#">Back to Top</a> </div--> <script> $.fn.editable.defaults.mode = 'inline';
$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) {