From 6821bec5d73568a5e5c882c6e5bb97612baf4c30 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 12 Aug 2002 08:56:36 +0000 Subject: [PATCH] Modernised insert and update of answers (using standard functions) --- mod/choice/lib.php | 22 ---------------------- mod/choice/view.php | 12 ++++++++++-- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/mod/choice/lib.php b/mod/choice/lib.php index 25b2083c50..5021879704 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -83,28 +83,6 @@ function choice_delete_instance($id) { } -function choice_add_new_to_database($choice, $answer) { - global $db; - global $USER; - - $timenow = time(); - - $rs = $db->Execute("INSERT INTO choice_answers (choice, user, answer, timemodified) - VALUES ( '$choice->id', '$USER->id', '$answer', '$timenow')"); - return $rs; -} - -function choice_update_in_database($current, $answer) { - global $db; - - $timenow = time(); - - $rs = $db->Execute("UPDATE choice_answers - SET answer='$answer', timemodified='$timenow' - WHERE id = '$current->id'"); - return $rs; -} - function choice_get_answer($choice, $code) { // Returns text string which is the answer that matches the code switch ($code) { diff --git a/mod/choice/view.php b/mod/choice/view.php index 3161db6d22..93dba902ec 100644 --- a/mod/choice/view.php +++ b/mod/choice/view.php @@ -30,13 +30,21 @@ if (match_referer() && isset($HTTP_POST_VARS)) { // form submitted $form = (object)$HTTP_POST_VARS; + $timenow = time(); if ($current) { - if (! choice_update_in_database($current, $form->answer)) { + $newanswer = $current; + $newanswer->answer = $form->answer; + $newanswer->timemodified = $timenow; + if (! update_record("choice_answers", $newanswer)) { error("Could not update your choice"); } add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", "$choice->id"); } else { - if (! choice_add_new_to_database($choice, $form->answer)) { + $newanswer->choice = $choice->id; + $newanswer->user = $USER->id; + $newanswer->answer = $form->answer; + $newanswer->timemodified = $timenow; + if (! insert_record("choice_answers", $newanswer)) { error("Could not save your choice"); } add_to_log($course->id, "choice", "add", "view.php?id=$cm->id", "$choice->id"); -- 2.39.5