📄 continue.php
字号:
if ($correctanswerid == 0) { $correctanswerid = $answer->id; } // ...also save any response from the correct answers... if (trim(strip_tags($answer->response))) { $correctresponse = $answer->response; } } else { // save the first jumpto page id, may be needed!... if (!isset($wrongpageid)) { // leave in its "raw" state - will converted into a proper page id later $wrongpageid = $answer->jumpto; } // save the answer id for scoring if ($wronganswerid == 0) { $wronganswerid = $answer->id; } // ...and from the incorrect ones, don't know which to use at this stage if (trim(strip_tags($answer->response))) { $wrongresponse = $answer->response; } } } } else { foreach ($answers as $answer) { if (lesson_iscorrect($pageid, $answer->jumpto)) { $ncorrect++; foreach ($useranswers as $key => $answerid) { if ($answerid == $answer->id) { $nhits++; } } // save the first jumpto page id, may be needed!... if (!isset($correctpageid)) { // leave in its "raw" state - will converted into a proper page id later $correctpageid = $answer->jumpto; } // save the answer id for scoring if ($correctanswerid == 0) { $correctanswerid = $answer->id; } // ...also save any response from the correct answers... if (trim(strip_tags($answer->response))) { $correctresponse = $answer->response; } } else { // save the first jumpto page id, may be needed!... if (!isset($wrongpageid)) { // leave in its "raw" state - will converted into a proper page id later $wrongpageid = $answer->jumpto; } // save the answer id for scoring if ($wronganswerid == 0) { $wronganswerid = $answer->id; } // ...and from the incorrect ones, don't know which to use at this stage if (trim(strip_tags($answer->response))) { $wrongresponse = $answer->response; } } } } if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { $correctanswer = true; $response = $correctresponse; $newpageid = $correctpageid; $answerid = $correctanswerid; } else { $response = $wrongresponse; $newpageid = $wrongpageid; $answerid = $wronganswerid; } } else { // only one answer allowed if (empty($_POST['answerid'])) { $noanswer = true; break; } $answerid = required_param('answerid', PARAM_INT); if (!$answer = get_record("lesson_answers", "id", $answerid)) { error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; } if ($lesson->custom) { if ($answer->score > 0) { $correctanswer = true; } else { $correctanswer = false; } } $newpageid = $answer->jumpto; $response = trim($answer->response); $studentanswer = $answer->answer; } break; case LESSON_MATCHING : if (isset($_POST['response']) && is_array($_POST['response'])) { // only arrays should be submitted $response = array(); foreach ($_POST['response'] as $key => $value) { $response[$key] = stripslashes($value); } } else { $noanswer = true; break; } if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } $ncorrect = 0; $i = 0; foreach ($answers as $answer) { if ($i == 0 || $i == 1) { // ignore first two answers, they are correct response // and wrong response $i++; continue; } if ($answer->response == $response[$answer->id]) { $ncorrect++; } if ($i == 2) { $correctpageid = $answer->jumpto; $correctanswerid = $answer->id; } if ($i == 3) { $wrongpageid = $answer->jumpto; $wronganswerid = $answer->id; } $i++; } // get he users exact responses for record keeping $userresponse = array(); foreach ($response as $key => $value) { foreach($answers as $answer) { if ($value == $answer->response) { $userresponse[] = $answer->id; } } $studentanswer .= '<br />'.$answers[$key]->answer.' = '.$value; } $userresponse = implode(",", $userresponse); $response = ''; if ($ncorrect == count($answers)-2) { // dont count correct/wrong responses in the total. foreach ($answers as $answer) { if ($answer->response == NULL && $answer->answer != NULL) { $response = $answer->answer; break; } } if (isset($correctpageid)) { $newpageid = $correctpageid; } if (isset($correctanswerid)) { $answerid = $correctanswerid; } $correctanswer = true; } else { $t = 0; foreach ($answers as $answer) { if ($answer->response == NULL && $answer->answer != NULL) { if ($t == 1) { $response = $answer->answer; break; } $t++; } } $newpageid = $wrongpageid; $answerid = $wronganswerid; } break; case LESSON_NUMERICAL : // set defaults $response = ''; $newpageid = 0; if (isset($_POST['answer'])) { $useranswer = (float) optional_param('answer'); // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float } else { $noanswer = true; break; } $studentanswer = $userresponse = $useranswer; if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } foreach ($answers as $answer) { if (strpos($answer->answer, ':')) { // there's a pairs of values list($min, $max) = explode(':', $answer->answer); $minimum = (float) $min; $maximum = (float) $max; } else { // there's only one value $minimum = (float) $answer->answer; $maximum = $minimum; } if (($useranswer >= $minimum) and ($useranswer <= $maximum)) { $newpageid = $answer->jumpto; $response = trim($answer->response); if (lesson_iscorrect($pageid, $newpageid)) { $correctanswer = true; } if ($lesson->custom) { if ($answer->score > 0) { $correctanswer = true; } else { $correctanswer = false; } } $answerid = $answer->id; break; } } break; case LESSON_BRANCHTABLE: $noanswer = false; $newpageid = optional_param('jumpto', NULL, PARAM_INT); // going to insert into lesson_branch if ($newpageid == LESSON_RANDOMBRANCH) { $branchflag = 1; } else { $branchflag = 0; } if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", "grade DESC")) { $retries = count($grades); } else { $retries = 0; } $branch = new stdClass; $branch->lessonid = $lesson->id; $branch->userid = $USER->id; $branch->pageid = $pageid; $branch->retry = $retries; $branch->flag = $branchflag; $branch->timeseen = time(); if (!insert_record("lesson_branch", $branch)) { error("Error: could not insert row into lesson_branch table"); } // this is called when jumping to random from a branch table if($newpageid == LESSON_UNSEENBRANCHPAGE) { if (has_capability('mod/lesson:manage', $context)) { $newpageid = LESSON_NEXTPAGE; } else { $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); // this may return 0 } } // convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $pageid; } elseif ($newpageid == LESSON_NEXTPAGE) { if (!$newpageid = $page->nextpageid) { // no nextpage go to end of lesson $newpageid = LESSON_EOL; } } elseif ($newpageid == LESSON_PREVIOUSPAGE) { $newpageid = $page->prevpageid; } elseif ($newpageid == LESSON_RANDOMPAGE) { $newpageid = lesson_random_question_jump($lesson->id, $pageid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -