Пример #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
 }
Пример #2
0
Input of questions into the database.
*/
$unparsed = '';
$lastErr = error_get_clear();
if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > convert_to_bytes(ini_get('post_max_size'))) {
    echo 'File(s) too large.';
    $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"]);