}
-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) {
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");