From 96c245363402f29e95069c0ce1eec9ba92d111af Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 1 Aug 2002 05:34:00 +0000 Subject: [PATCH] Clean up - modernised choice mod.php --- mod/choice/mod.php | 68 ++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/mod/choice/mod.php b/mod/choice/mod.php index 59374eb8d1..702a682bf0 100644 --- a/mod/choice/mod.php +++ b/mod/choice/mod.php @@ -9,56 +9,27 @@ // ///////////////////////////////////////////////////////////// -function add_instance($form) { +function add_instance($choice) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function // will create a new instance and return the id number // of the new instance. -// - GLOBAL $db; - - $timenow = time(); - - if (!$rs = $db->Execute("INSERT into choice - SET course = '$form->course', - name = '$form->name', - text = '$form->text', - answer1 = '$form->answer1', - answer2 = '$form->answer2', - timemodified = '$timenow'")) { - return 0; - } - - // Get it out again - this is the most compatible way to determine the ID - if ($rs = $db->Execute("SELECT id FROM choice - WHERE course = $form->course AND timemodified = '$timenow'")) { - return $rs->fields[0]; - } else { - return 0; - } + + $choice->timemodified = time(); + + return insert_record("choice", $choice); } -function update_instance($form) { +function update_instance($choice) { // Given an object containing all the necessary data, // (defined by the form in mod.html) this function // will update an existing instance with new data. -// - GLOBAL $db; - - $timenow = time(); - - if (!$rs = $db->Execute("UPDATE choice - SET course = '$form->course', - name = '$form->name', - text = '$form->text', - answer1 = '$form->answer1', - answer2 = '$form->answer2', - timemodified = '$timenow' - WHERE id = '$form->instance' ")) { - return false; - } - return true; + + $choice->id = $choice->instance; + $choice->timemodified = time(); + + return update_record("choice", $choice); } @@ -66,15 +37,22 @@ function delete_instance($id) { // Given an ID of an instance of this module, // this function will permanently delete the instance // and any data that depends on it. -// - GLOBAL $db; - if (!$rs = $db->Execute("DELETE from choice WHERE id = '$id' ")) { + if (! $choice = get_record("choice", "id", "$id")) { return false; } - return true; - + $result = true; + + if (! delete_records("choice_answers", "choice", "$choice->id")) { + $result = false; + } + + if (! delete_records("choice", "id", "$choice->id")) { + $result = false; + } + + return $result; } -- 2.39.5