if (isset($type) && isset($qquestion_group_id) && $type == 1) {
     $PROCESSED["qquestion_group_id"] = $qquestion_group_id;
 }
 if ($ENTRADA_ACL->amIAllowed(new QuizQuestionResource(null, $quiz_record->getQuizID()), 'create')) {
     $quiz_question = new Models_Quiz_Question($PROCESSED);
     if ($quiz_question->insert()) {
         $qquestion_id = $quiz_question->getQquestionID();
         if ($qquestion_id) {
             /**
              * Add the quiz question responses to the quiz_question_responses table.
              * Ummm... we really need to switch to InnoDB tables to get transaction support.
              */
             if (is_array($PROCESSED["quiz_question_responses"]) && count($PROCESSED["quiz_question_responses"])) {
                 foreach ($PROCESSED["quiz_question_responses"] as $quiz_question_response) {
                     $PROCESSED = array("qquestion_id" => $qquestion_id, "response_text" => $quiz_question_response["response_text"], "response_order" => $quiz_question_response["response_order"], "response_correct" => $quiz_question_response["response_correct"], "response_is_html" => $quiz_question_response["response_is_html"], "response_feedback" => $quiz_question_response["response_feedback"]);
                     $quiz_question_response = new Models_Quiz_Question_Response($PROCESSED);
                     if (!$quiz_question_response->insert()) {
                         add_error("There was an error while trying to attach a <strong>Question Response</strong> to this quiz question.<br /><br />The system administrator was informed of this error; please try again later.");
                         application_log("error", "Unable to insert a new quiz_question_responses record while adding a new quiz question [" . $qquestion_id . "] to quiz_id [" . $RECORD_ID . "]. Database said: " . $db->ErrorMsg());
                     }
                 }
             }
             switch (clean_input($_SESSION[APPLICATION_IDENTIFIER]["tmp"]["post_action"], "alpha")) {
                 case "new":
                     $url = ENTRADA_URL . "/admin/" . $MODULE . "?section=add-question&id=" . $RECORD_ID . "&type=" . ((int) clean_input($_SESSION[APPLICATION_IDENTIFIER]["tmp"]["post_action"], "numeric") ? (int) clean_input($_SESSION[APPLICATION_IDENTIFIER]["tmp"]["post_action"], "numeric") : 1);
                     $msg = "You will now be redirected to add another quiz question to this quiz; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . $url . "\" style=\"font-weight: bold\">click here</a> to continue.";
                     break;
                 case "index":
                     $url = ENTRADA_URL . "/admin/" . $MODULE;
                     $msg = "You will now be redirected back to the quiz index page; this will happen <strong>automatically</strong> in 5 seconds or <a href=\"" . $url . "\" style=\"font-weight: bold\">click here</a> to continue.";
                     break;
 $question_feedback = "";
 echo "<li id=\"question_" . $question["qquestion_id"] . "\" class=\"" . ($question["questiontype_id"] == 4 ? "group" : "") . "\">";
 echo "\t<div class=\"question noneditable\">\n";
 echo "\t\t<span id=\"question_text_" . $question["qquestion_id"] . "\" class=\"question\">" . clean_input($question["question_text"], "trim") . "</span>";
 echo "\t</div>\n";
 if ($q->getQuestionTypeID() == "4") {
     $grouped_qquestions = Models_Quiz_Question::fetchGroupedQuestions($q->getQquestionID());
     if ($grouped_qquestions) {
         echo "<ul>";
         foreach ($grouped_qquestions as $q) {
             $question = $q->toArray();
             echo "<li id=\"question_" . $question["qquestion_id"] . "\">";
             echo "\t<div class=\"question noneditable\">\n";
             echo "\t\t<span id=\"question_text_" . $question["qquestion_id"] . "\" class=\"question\">" . clean_input($question["question_text"], "trim") . "</span>";
             echo "\t</div>\n";
             $responses = Models_Quiz_Question_Response::fetchAllRecords($q->getQquestionID());
             if ($responses) {
                 echo "\t<ul class=\"responses\">\n";
                 foreach ($responses as $r) {
                     $response = $r->toArray();
                     $response_selected = false;
                     $response_correct = false;
                     if ($PROCESSED[$question["qquestion_id"]] == $response["qqresponse_id"]) {
                         $response_selected = true;
                         if ($response["response_correct"] == 1) {
                             $response_correct = true;
                             $question_correct = true;
                         } else {
                             $response_correct = false;
                         }
                         if ($tmp_input = clean_input($response["response_feedback"], array("notags", "trim"))) {
Beispiel #3
0
 $new_qquestion_ids = array();
 foreach ($questions as $q) {
     $question = $q->toArray();
     $old_qquestion_id = $question["qquestion_id"];
     unset($question["qquestion_id"]);
     $question["quiz_id"] = $new_quiz_id;
     $new_question = new Models_Quiz_Question($question);
     if ($new_question->insert()) {
         $new_qquestion_id = $new_question->getQquestionID();
         if ($new_question->getQuestiontypeID() == "1" || $new_question->getQuestiontypeID() == "4") {
             $responses = Models_Quiz_Question_Response::fetchAllRecords($old_qquestion_id);
             foreach ($responses as $r) {
                 $response_data = $r->toArray();
                 unset($response_data["qqresponse_id"]);
                 $response_data["qquestion_id"] = $new_qquestion_id;
                 $response = new Models_Quiz_Question_Response($response_data);
                 if (!$response->insert()) {
                     $ERROR++;
                 }
             }
         }
     } else {
         application_log("error", "Unable to insert new quiz_questions record when attempting to copy quiz_id [" . $RECORD_ID . "]. Database said: " . $db->ErrorMsg());
     }
 }
 if ($ERROR) {
     if (count($new_qquestion_ids) > 0) {
         foreach ($new_qquestion_ids as $new_qquestion_id) {
             $qquestion_responses = Models_Quiz_Question_Response::fetchAllRecords($new_qquestion_id);
             if ($qquestion_responses) {
                 foreach ($qquestion_responses as $qquestion_response) {