From: skodak Date: Sun, 1 Jun 2008 21:36:11 +0000 (+0000) Subject: MDL-14679 towards modform conversion X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c18269c7e58a7152c4830c532769cf69c359a7b6;p=moodle.git MDL-14679 towards modform conversion --- diff --git a/course/modedit.php b/course/modedit.php index d87b573ea4..106599d9c1 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -17,7 +17,7 @@ $section = required_param('section', PARAM_INT); $course = required_param('course', PARAM_INT); - if (! $course = get_record("course", "id", $course)) { + if (! $course = $DB->get_record("course", array("id"=>$course))) { print_error("invalidcourseid"); } @@ -25,7 +25,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('moodle/course:manageactivities', $context); - if (! $module = get_record("modules", "name", $add)) { + if (! $module = $DB->get_record("modules", array("name"=>$add))) { print_error("moduledoesnotexist"); } @@ -37,6 +37,7 @@ $cm = null; + $form = new object(); $form->section = $section; // The section number itself - relative!!! (section column in course_sections) $form->visible = $cw->visible; $form->course = $course->id; @@ -73,12 +74,13 @@ } $navlinksinstancename = ''; + } else if (!empty($update)) { - if (! $cm = get_record("course_modules", "id", $update)) { + if (! $cm = $DB->get_record("course_modules", array("id"=>$update))) { print_error("cmunknown"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { print_error("invalidcourseid"); } @@ -86,18 +88,15 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('moodle/course:manageactivities', $context); - if (! $module = get_record("modules", "id", $cm->module)) { + if (! $module = $DB->get_record("modules", array("id"=>$cm->module))) { print_error("moduledoesnotexist"); } - if (! $form = get_record($module->name, "id", $cm->instance)) { - print_error("moduleinstancedoesnotexist"); - } - - if (! $cw = get_record("course_sections", "id", $cm->section)) { + if (! $cw = $DB->get_record("course_sections", array("id"=>$cm->section))) { print_error("sectionnotexist"); } + $form = clone($cm); $form->coursemodule = $cm->id; $form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) $form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides @@ -188,20 +187,20 @@ } else { redirect("$CFG->wwwroot/course/view.php?id=$course->id#section-".$cw->section); } - } else if ($fromform = $mform->get_data()) { + } else if ($fromform = $mform->get_data(false)) { if (empty($fromform->coursemodule)) { //add $cm = null; - if (! $course = get_record("course", "id", $fromform->course)) { + if (! $course = $DB->get_record("course", array("id"=>$fromform->course))) { print_error("invalidcourseid"); } $fromform->instance = ''; $fromform->coursemodule = ''; } else { //update - if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) { + if (! $cm = $DB->get_record("course_modules", array("id"=>$fromform->coursemodule))) { print_error("cmunknown"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { print_error("invalidcourseid"); } $fromform->instance = $cm->instance; @@ -296,7 +295,7 @@ print_error("cannotaddcmtosection"); } - if (! set_field("course_modules", "section", $sectionid, "id", $fromform->coursemodule)) { + if (! $DB->set_field("course_modules", "section", $sectionid, array("id"=>$fromform->coursemodule))) { print_error("cannotupdatecm"); } diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index d0ea7acef5..52710e9000 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -174,7 +174,7 @@ class moodleform_mod extends moodleform { * @param mixed array or object describing supported features - groups, groupings, groupmembersonly, etc. */ function standard_coursemodule_elements($features=null){ - global $COURSE, $CFG; + global $COURSE, $CFG, $DB; $mform =& $this->_form; // deal with legacy $supportgroups param @@ -242,7 +242,7 @@ class moodleform_mod extends moodleform { //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly $options = array(); $options[0] = get_string('none'); - if ($groupings = get_records('groupings', 'courseid', $COURSE->id)) { + if ($groupings = $DB->get_records('groupings', array('courseid'=>$COURSE->id))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 12ca8e8286..f41dedd454 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -342,12 +342,12 @@ class assignment_base { * @return int The id of the assignment */ function add_instance($assignment) { - global $COURSE; + global $COURSE, $DB; $assignment->timemodified = time(); $assignment->courseid = $assignment->course; - if ($returnid = insert_record("assignment", $assignment)) { + if ($returnid = $DB->insert_record("assignment", $assignment)) { $assignment->id = $returnid; if ($assignment->timedue) { @@ -366,7 +366,6 @@ class assignment_base { add_event($event); } - $assignment = stripslashes_recursive($assignment); assignment_grade_item_update($assignment); } @@ -383,21 +382,21 @@ class assignment_base { * @return boolean False indicates error */ function delete_instance($assignment) { - global $CFG; + global $CFG, $DB; $assignment->courseid = $assignment->course; $result = true; - if (! delete_records('assignment_submissions', 'assignment', $assignment->id)) { + if (! $DB->delete_records('assignment_submissions', array('assignment'=>$assignment->id))) { $result = false; } - if (! delete_records('assignment', 'id', $assignment->id)) { + if (! $DB->delete_records('assignment', array('id'=>$assignment->id))) { $result = false; } - if (! delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id)) { + if (! $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { $result = false; } @@ -423,21 +422,21 @@ class assignment_base { * @return int The assignment id */ function update_instance($assignment) { - global $COURSE; + global $COURSE, $DB; $assignment->timemodified = time(); $assignment->id = $assignment->instance; $assignment->courseid = $assignment->course; - if (!update_record('assignment', $assignment)) { + if (!$DB->update_record('assignment', $assignment)) { return false; } if ($assignment->timedue) { $event = new object(); - if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) { + if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'assignment', 'instance'=>$assignment->id))) { $event->name = $assignment->name; $event->description = $assignment->description; @@ -460,12 +459,10 @@ class assignment_base { add_event($event); } } else { - delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id); + $DB->delete_records('event', array('modulename'=>'assignment', 'instance'=>$assignment->id)); } // get existing grade item - $assignment = stripslashes_recursive($assignment); - assignment_grade_item_update($assignment); return true; @@ -1940,9 +1937,9 @@ class assignment_base { * This is done by calling the delete_instance() method of the assignment type class */ function assignment_delete_instance($id){ - global $CFG; + global $CFG, $DB; - if (! $assignment = get_record('assignment', 'id', $id)) { + if (! $assignment = $DB->get_record('assignment', array('id'=>$id))) { return false; } diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index b9ffcb3e96..450385cc5a 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -4,12 +4,12 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_assignment_mod_form extends moodleform_mod { function definition() { - global $CFG; + global $CFG, $DB; $mform =& $this->_form; // this hack is needed for different settings of each subtype if (!empty($this->_instance)) { - if($ass = get_record('assignment', 'id', (int)$this->_instance)) { + if($ass = $DB->get_record('assignment', array('id', $this->_instance))) { $type = $ass->assignmenttype; } else { print_error('invalidassignment', 'assignment'); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index c88b4fa4a1..baa5dd9622 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -23,6 +23,7 @@ $CHAT_HTMLHEAD_MSGINPUT_JS = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; function chat_add_instance($chat) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will create a new instance and return the id number @@ -30,7 +31,7 @@ function chat_add_instance($chat) { $chat->timemodified = time(); - if ($returnid = insert_record("chat", $chat)) { + if ($returnid = $DB->insert_record("chat", $chat)) { $event = NULL; $event->name = $chat->name; @@ -52,6 +53,7 @@ function chat_add_instance($chat) { function chat_update_instance($chat) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will update an existing instance with new data. @@ -60,11 +62,11 @@ function chat_update_instance($chat) { $chat->id = $chat->instance; - if ($returnid = update_record("chat", $chat)) { + if ($returnid = $DB->update_record("chat", $chat)) { $event = new object(); - if ($event->id = get_field('event', 'id', 'modulename', 'chat', 'instance', $chat->id)) { + if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'chat', 'instance'=>$chat->id))) { $event->name = $chat->name; $event->description = $chat->intro; @@ -79,11 +81,12 @@ function chat_update_instance($chat) { function chat_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $chat = get_record('chat', 'id', $id)) { + if (! $chat = $DB->get_record('chat', array('id'=>$id))) { return false; } @@ -91,24 +94,24 @@ function chat_delete_instance($id) { # Delete any dependent records here # - if (! delete_records('chat', 'id', $chat->id)) { + if (! $DB->delete_records('chat', array('id'=>$chat->id))) { $result = false; } - if (! delete_records('chat_messages', 'chatid', $chat->id)) { + if (! $DB->delete_records('chat_messages', array('chatid'=>$chat->id))) { $result = false; } - if (! delete_records('chat_users', 'chatid', $chat->id)) { + if (! $DB->delete_records('chat_users', array('chatid'=>$chat->id))) { $result = false; } $pagetypes = page_import_types('mod/chat/'); foreach($pagetypes as $pagetype) { - if(!delete_records('block_instance', 'pageid', $chat->id, 'pagetype', $pagetype)) { + if (!$DB->delete_records('block_instance', array('pageid'=>$chat->id, 'pagetype'=>$pagetype))) { $result = false; } } - if (! delete_records('event', 'modulename', 'chat', 'instance', $chat->id)) { + if (! $DB->delete_records('event', array('modulename'=>'chat', 'instance'=>$chat->id))) { $result = false; } diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index af8a6032e1..ad5139ff7f 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -4,8 +4,7 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_chat_mod_form extends moodleform_mod { function definition() { - - global $CFG; + global $CFG, $DB; $mform =& $this->_form; //------------------------------------------------------------------------------- diff --git a/mod/choice/lib.php b/mod/choice/lib.php index a46916a6db..19c5beb103 100644 --- a/mod/choice/lib.php +++ b/mod/choice/lib.php @@ -48,6 +48,7 @@ function choice_user_complete($course, $user, $mod, $choice) { function choice_add_instance($choice) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will create a new instance and return the id number @@ -61,7 +62,7 @@ function choice_add_instance($choice) { } //insert answers - if ($choice->id = insert_record("choice", $choice)) { + if ($choice->id = $DB->insert_record("choice", $choice)) { foreach ($choice->option as $key => $value) { $value = trim($value); if (isset($value) && $value <> '') { @@ -72,7 +73,7 @@ function choice_add_instance($choice) { $option->maxanswers = $choice->limit[$key]; } $option->timemodified = time(); - insert_record("choice_options", $option); + $DB->insert_record("choice_options", $option); } } } @@ -81,6 +82,7 @@ function choice_add_instance($choice) { function choice_update_instance($choice) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will update an existing instance with new data. @@ -107,18 +109,18 @@ function choice_update_instance($choice) { if (isset($choice->optionid[$key]) && !empty($choice->optionid[$key])){//existing choice record $option->id=$choice->optionid[$key]; if (isset($value) && $value <> '') { - update_record("choice_options", $option); + $DB->update_record("choice_options", $option); } else { //empty old option - needs to be deleted. - delete_records("choice_options", "id", $option->id); + $DB->delete_records("choice_options", array("id"=>$option->id)); } } else { if (isset($value) && $value <> '') { - insert_record("choice_options", $option); + $DB->insert_record("choice_options", $option); } } } - return update_record('choice', $choice); + return $DB->update_record('choice', $choice); } @@ -575,25 +577,26 @@ function choice_delete_responses($attemptids, $choiceid) { function choice_delete_instance($id) { + global $DB; // Given an ID of an instance of this module, // this function will permanently delete the instance // and any data that depends on it. - if (! $choice = get_record("choice", "id", "$id")) { + if (! $choice = $DB->get_record("choice", array("id"=>"$id"))) { return false; } $result = true; - if (! delete_records("choice_answers", "choiceid", "$choice->id")) { + if (! $DB->delete_records("choice_answers", array("choiceid"=>"$choice->id"))) { $result = false; } - if (! delete_records("choice_options", "choiceid", "$choice->id")) { + if (! $DB->delete_records("choice_options", array("choiceid"=>"$choice->id"))) { $result = false; } - if (! delete_records("choice", "id", "$choice->id")) { + if (! $DB->delete_records("choice", array("id"=>"$choice->id"))) { $result = false; } diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 32ae30e182..70caf0d370 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -4,7 +4,7 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_choice_mod_form extends moodleform_mod { function definition() { - global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY; + global $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY, $DB; $mform =& $this->_form; @@ -37,7 +37,7 @@ class mod_choice_mod_form extends moodleform_mod { $mform->setHelpButton('limitanswers', array('limit', get_string('limit', 'choice'), 'choice')); if ($this->_instance){ - $repeatno=count_records('choice_options', 'choiceid', $this->_instance); + $repeatno = $DB->count_records('choice_options', array('choiceid'=>$this->_instance)); $repeatno += 2; } else { $repeatno = 5; diff --git a/mod/data/lib.php b/mod/data/lib.php index 89d82a1583..fd812ba6f5 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -631,7 +631,7 @@ function data_tags_check($dataid, $template){ * Adds an instance of a data * ************************************************************************/ function data_add_instance($data) { - global $CFG; + global $CFG, $DB; if (empty($data->assessed)) { $data->assessed = 0; @@ -639,11 +639,10 @@ function data_add_instance($data) { $data->timemodified = time(); - if (! $data->id = insert_record('data', $data)) { + if (! $data->id = $DB->insert_record('data', $data)) { return false; } - $data = stripslashes_recursive($data); data_grade_item_update($data); return $data->id; @@ -653,7 +652,7 @@ function data_add_instance($data) { * updates an instance of a data * ************************************************************************/ function data_update_instance($data) { - global $CFG; + global $CFG, $DB; $data->timemodified = time(); $data->id = $data->instance; @@ -666,11 +665,10 @@ function data_update_instance($data) { $data->notification = 0; } - if (! update_record('data', $data)) { + if (! $DB->update_record('data', $data)) { return false; } - $data = stripslashes_recursive($data); data_grade_item_update($data); return true; @@ -681,39 +679,37 @@ function data_update_instance($data) { * deletes an instance of a data * ************************************************************************/ function data_delete_instance($id) { // takes the dataid + global $CFG, $DB; - global $CFG; - - if (! $data = get_record('data', 'id', $id)) { + if (! $data = $DB->get_record('data', array('id'=>$id))) { return false; } // Delete all the associated information // get all the records in this data - $sql = 'SELECT c.* FROM '.$CFG->prefix.'data_records r LEFT JOIN '. - $CFG->prefix.'data_content c ON c.recordid = r.id WHERE r.dataid = '.$id; + $sql = 'SELECT c.* FROM {data_records} r LEFT JOIN {data_content} c ON c.recordid = r.id WHERE r.dataid =?'; - if ($contents = get_records_sql($sql)){ + if ($contents = $DB->get_records_sql($sql, array($id))){ foreach($contents as $content){ - $field = get_record('data_fields','id',$content->fieldid); + $field = $DB->get_record('data_fields', array('id'=>$content->fieldid)); if ($g = data_get_field($field, $data)){ $g->delete_content_files($id, $content->recordid, $content->content); } //delete the content itself - delete_records('data_content','id', $content->id); + $DB->delete_records('data_content', array('id'=>$content->id)); } } // delete all the records and fields - delete_records('data_records', 'dataid', $id); - delete_records('data_fields','dataid',$id); + $DB->delete_records('data_records', array('dataid'=>$id)); + $DB->delete_records('data_fields', array('dataid'=>$id)); // Delete the instance itself - $result = delete_records('data', 'id', $id); + $result = $DB->delete_records('data', array('id'=>$id)); data_grade_item_delete($data); diff --git a/mod/data/mod_form.php b/mod/data/mod_form.php index 2d53ea6f6c..a7e912bef7 100644 --- a/mod/data/mod_form.php +++ b/mod/data/mod_form.php @@ -4,8 +4,8 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_data_mod_form extends moodleform_mod { function definition() { + global $CFG, $DB; - global $CFG; $mform =& $this->_form; //------------------------------------------------------------------------------- diff --git a/mod/data/preset_class.php b/mod/data/preset_class.php index 895be858b9..89a4852b09 100644 --- a/mod/data/preset_class.php +++ b/mod/data/preset_class.php @@ -442,7 +442,7 @@ class Data_Preset * TODO document */ function import() { - global $CFG; + global $CFG, $DB; list($settings, $newfields, $currentfields) = $this->load_from_file(); $preservedfields = array(); @@ -507,13 +507,13 @@ class Data_Preset } } */ - delete_records('data_content', 'fieldid', $id); - delete_records('data_fields', 'id', $id); + $DB->delete_records('data_content', array('fieldid'=>$id)); + $DB->delete_records('data_fields', array('id'=>$id)); } } } - data_update_instance(addslashes_object($settings)); + data_update_instance($settings); if (strstr($this->directory, '/temp/')) clean_preset($this->directory); /* Removes the temporary files */ return true; diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index c4cb02bfef..c0735f4341 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -29,6 +29,7 @@ $feedback_names = feedback_load_feedback_items('mod/feedback/item'); * @return int */ function feedback_add_instance($feedback) { + global $DB; $feedback->timemodified = time(); $feedback->id = ''; @@ -45,7 +46,7 @@ function feedback_add_instance($feedback) { } //saving the feedback in db - if(!$feedbackid = insert_record("feedback", $feedback)) { + if (!$feedbackid = $DB->insert_record("feedback", $feedback)) { return false; } @@ -60,6 +61,7 @@ function feedback_add_instance($feedback) { * @return boolean */ function feedback_update_instance($feedback) { + global $DB; $feedback->timemodified = time(); $feedback->id = $feedback->instance; @@ -76,7 +78,7 @@ function feedback_update_instance($feedback) { } //save the feedback into the db - if(!update_record("feedback", $feedback)) { + if (!$DB->update_record("feedback", $feedback)) { return false; } @@ -93,30 +95,32 @@ function feedback_update_instance($feedback) { * @return boolean */ function feedback_delete_instance($id) { + global $DB; + //get all referenced items - $feedbackitems = get_records('feedback_item', 'feedback', $id); + $feedbackitems = $DB->get_records('feedback_item', array('feedback'=>$id)); //deleting all referenced items and values if (is_array($feedbackitems)){ foreach($feedbackitems as $feedbackitem){ - @delete_records("feedback_value", "item", $feedbackitem->id); - @delete_records("feedback_valuetmp", "item", $feedbackitem->id); + $DB->delete_records("feedback_value", array("item"=>$feedbackitem->id)); + $DB->delete_records("feedback_valuetmp", array("item"=>$feedbackitem->id)); } - @delete_records("feedback_item", "feedback", $id); + $DB->delete_records("feedback_item", array("feedback"=>$id)); } //deleting the referenced tracking data - @delete_records('feedback_tracking', 'feedback', $id); + $DB->delete_records('feedback_tracking', array('feedback'=>$id)); //deleting the completeds - @delete_records("feedback_completed", "feedback", $id); + $DB->delete_records("feedback_completed", array("feedback"=>$id)); //deleting the unfinished completeds - @delete_records("feedback_completedtmp", "feedback", $id); + $DB->delete_records("feedback_completedtmp", array("feedback"=>$id)); //deleting old events - @delete_records('event', 'modulename', 'feedback', 'instance', $id); - return @delete_records("feedback", "id", $id); + $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$id)); + return $DB->delete_records("feedback", array("id"=>$id)); } /** @@ -292,8 +296,10 @@ function feedback_reset_course_form($course) { * @return void */ function feedback_set_events($feedback) { + global $DB; + // adding the feedback to the eventtable (I have seen this at quiz-module) - delete_records('event', 'modulename', 'feedback', 'instance', $feedback->id); + $DB->delete_records('event', array('modulename'=>'feedback', 'instance'=>$feedback->id)); // the open-event if($feedback->timeopen > 0) { @@ -304,7 +310,7 @@ function feedback_set_events($feedback) { $event->groupid = 0; $event->userid = 0; $event->modulename = 'feedback'; - $event->instance = $feedbackid; + $event->instance = $feedback->id; $event->eventtype = 'open'; $event->timestart = $feedback->timeopen; $event->visible = instance_is_visible('feedback', $feedback); @@ -326,7 +332,7 @@ function feedback_set_events($feedback) { $event->groupid = 0; $event->userid = 0; $event->modulename = 'feedback'; - $event->instance = $feedbackid; + $event->instance = $feedback->id; $event->eventtype = 'close'; $event->timestart = $feedback->timeclose; $event->visible = instance_is_visible('feedback', $feedback); diff --git a/mod/feedback/mod_form.php b/mod/feedback/mod_form.php index 18b1bbce2b..457cde7336 100644 --- a/mod/feedback/mod_form.php +++ b/mod/feedback/mod_form.php @@ -13,7 +13,7 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_feedback_mod_form extends moodleform_mod { function definition() { - global $CFG; + global $CFG, $DB; $mform =& $this->_form; @@ -58,7 +58,7 @@ class mod_feedback_mod_form extends moodleform_mod { $mform->setHelpButton('email_notification', array('emailnotification', get_string('email_notification', 'feedback'), 'feedback')); // check if there is existing responses to this feedback - if (is_numeric($this->_instance) AND $this->_instance and $feedback = get_record("feedback", "id", $this->_instance)) { + if (is_numeric($this->_instance) AND $this->_instance and $feedback = $DB->get_record("feedback", array("id"=>$this->_instance))) { $completedFeedbackCount = feedback_get_completeds_group_count($feedback); } else { $completedFeedbackCount = false; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cd11711361..b2c44c9701 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -37,7 +37,7 @@ define ('FORUM_AGGREGATE_SUM', 5); * @return int intance id */ function forum_add_instance($forum) { - global $CFG; + global $CFG, $DB; $forum->timemodified = time(); @@ -50,7 +50,7 @@ function forum_add_instance($forum) { $forum->assesstimefinish = 0; } - if (!$forum->id = insert_record('forum', $forum)) { + if (!$forum->id = $DB->insert_record('forum', $forum)) { return false; } @@ -79,7 +79,6 @@ function forum_add_instance($forum) { } } - $forum = stripslashes_recursive($forum); forum_grade_item_update($forum); return $forum->id; @@ -94,6 +93,8 @@ function forum_add_instance($forum) { * @return bool success */ function forum_update_instance($forum) { + global $DB; + $forum->timemodified = time(); $forum->id = $forum->instance; @@ -106,7 +107,7 @@ function forum_update_instance($forum) { $forum->assesstimefinish = 0; } - $oldforum = get_record('forum', 'id', $forum->id); + $oldforum = $DB->get_record('forum', array('id'=>$forum->id)); // MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum // if scale changes - do we need to recheck the ratings, if ratings higher than scale how do we want to respond? @@ -116,15 +117,15 @@ function forum_update_instance($forum) { } if ($forum->type == 'single') { // Update related discussion and post. - if (! $discussion = get_record('forum_discussions', 'forum', $forum->id)) { - if ($discussions = get_records('forum_discussions', 'forum', $forum->id, 'timemodified ASC')) { + if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) { + if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC')) { notify('Warning! There is more than one discussion in this forum - using the most recent'); $discussion = array_pop($discussions); } else { error('Could not find the discussion in this forum'); } } - if (! $post = get_record('forum_posts', 'id', $discussion->firstpost)) { + if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) { error('Could not find the first post in this forum discussion'); } @@ -132,22 +133,21 @@ function forum_update_instance($forum) { $post->message = $forum->intro; $post->modified = $forum->timemodified; - if (! update_record('forum_posts', ($post))) { + if (! $DB->update_record('forum_posts', ($post))) { error('Could not update the first post'); } $discussion->name = $forum->name; - if (! update_record('forum_discussions', ($discussion))) { + if (! $DB->update_record('forum_discussions', ($discussion))) { error('Could not update the discussion'); } } - if (!update_record('forum', $forum)) { + if (!$DB->update_record('forum', $forum)) { error('Can not update forum'); } - $forum = stripslashes_recursive($forum); forum_grade_item_update($forum); return true; @@ -162,14 +162,15 @@ function forum_update_instance($forum) { * @return bool success */ function forum_delete_instance($id) { + global $DB; - if (!$forum = get_record('forum', 'id', $id)) { + if (!$forum = $DB->get_record('forum', array('id'=>$id))) { return false; } $result = true; - if ($discussions = get_records('forum_discussions', 'forum', $forum->id)) { + if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id))) { foreach ($discussions as $discussion) { if (!forum_delete_discussion($discussion, true)) { $result = false; @@ -177,13 +178,13 @@ function forum_delete_instance($id) { } } - if (!delete_records('forum_subscriptions', 'forum', $forum->id)) { + if (!$DB->delete_records('forum_subscriptions', array('forum'=>$forum->id))) { $result = false; } forum_tp_delete_read_records(-1, -1, -1, $forum->id); - if (!delete_records('forum', 'id', $forum->id)) { + if (!$DF->delete_records('forum', array('id'=>$forum->id))) { $result = false; } @@ -3681,14 +3682,13 @@ function forum_print_attachments($post, $return=NULL) { * */ function forum_add_attachment($post, $inputname,&$message) { + global $CFG, $DB; - global $CFG; - - if (!$forum = get_record("forum", "id", $post->forum)) { + if (!$forum = $DB->get_record("forum", array("id"=>$post->forum))) { return ""; } - if (!$course = get_record("course", "id", $forum->course)) { + if (!$course = $DB->get_record("course", array("id"=>$forum->course))) { return ""; } @@ -3783,15 +3783,14 @@ function forum_update_post($post,&$message) { * create a new discussion and return the id */ function forum_add_discussion($discussion,&$message) { - - global $USER, $CFG; + global $USER, $CFG, $DB; $timenow = time(); // The first post is stored as a real post, and linked // to from the discuss entry. - $forum = get_record('forum', 'id', $discussion->forum); + $forum = $DB->get_record('forum', array('id'=>$discussion->forum)); $post = new object(); $post->discussion = 0; @@ -3808,12 +3807,12 @@ function forum_add_discussion($discussion,&$message) { $post->format = $discussion->format; $post->mailnow = $discussion->mailnow; - if (! $post->id = insert_record("forum_posts", $post) ) { + if (! $post->id = $DB->insert_record("forum_posts", $post) ) { return 0; } if ($post->attachment = forum_add_attachment($post, 'attachment',$message)) { - set_field("forum_posts", "attachment", $post->attachment, "id", $post->id); //ignore errors + $DB->set_field("forum_posts", "attachment", $post->attachment, array("id"=>$post->id)); //ignore errors } // Now do the main entry for the discussion, @@ -3824,15 +3823,15 @@ function forum_add_discussion($discussion,&$message) { $discussion->usermodified = $post->userid; $discussion->userid = $USER->id; - if (! $post->discussion = insert_record("forum_discussions", $discussion) ) { - delete_records("forum_posts", "id", $post->id); + if (! $post->discussion = $DB->insert_record("forum_discussions", $discussion) ) { + $DB->delete_records("forum_posts", array("id"=>$post->id)); return 0; } // Finally, set the pointer on the post. - if (! set_field("forum_posts", "discussion", $post->discussion, "id", $post->id)) { - delete_records("forum_posts", "id", $post->id); - delete_records("forum_discussions", "id", $post->discussion); + if (! $DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id))) { + $DB->delete_records("forum_posts", array("id"=>$post->id)); + $DB->delete_records("forum_discussions", array("id"=>$post->discussion)); return 0; } diff --git a/mod/forum/mod_form.php b/mod/forum/mod_form.php index 0b7ab14f24..1b615b7439 100644 --- a/mod/forum/mod_form.php +++ b/mod/forum/mod_form.php @@ -4,8 +4,8 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_forum_mod_form extends moodleform_mod { function definition() { + global $CFG, $COURSE, $DB; - global $CFG, $COURSE; $mform =& $this->_form; //------------------------------------------------------------------------------- diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 26bf0b8bb1..ca1b8c5b53 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -88,44 +88,44 @@ if ( $xmlglossary['NAME'][0]['#'] ) { unset($glossary); - $glossary->name = addslashes($xmlglossary['NAME'][0]['#']); + $glossary->name = ($xmlglossary['NAME'][0]['#']); $glossary->course = $course->id; - $glossary->globalglossary = addslashes($xmlglossary['GLOBALGLOSSARY'][0]['#']); - $glossary->intro = addslashes($xmlglossary['INTRO'][0]['#']); - $glossary->showspecial = addslashes($xmlglossary['SHOWSPECIAL'][0]['#']); - $glossary->showalphabet = addslashes($xmlglossary['SHOWALPHABET'][0]['#']); - $glossary->showall = addslashes($xmlglossary['SHOWALL'][0]['#']); + $glossary->globalglossary = ($xmlglossary['GLOBALGLOSSARY'][0]['#']); + $glossary->intro = ($xmlglossary['INTRO'][0]['#']); + $glossary->showspecial = ($xmlglossary['SHOWSPECIAL'][0]['#']); + $glossary->showalphabet = ($xmlglossary['SHOWALPHABET'][0]['#']); + $glossary->showall = ($xmlglossary['SHOWALL'][0]['#']); $glossary->timecreated = time(); $glossary->timemodified = time(); // Setting the default values if no values were passed if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) { - $glossary->entbypage = addslashes($xmlglossary['ENTBYPAGE'][0]['#']); + $glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']); } else { $glossary->entbypage = $CFG->glossary_entbypage; } if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) { - $glossary->allowduplicatedentries = addslashes($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']); + $glossary->allowduplicatedentries = ($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']); } else { $glossary->allowduplicatedentries = $CFG->glossary_dupentries; } if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) { - $glossary->displayformat = addslashes($xmlglossary['DISPLAYFORMAT'][0]['#']); + $glossary->displayformat = ($xmlglossary['DISPLAYFORMAT'][0]['#']); } else { $glossary->displayformat = 2; } if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) { - $glossary->allowcomments = addslashes($xmlglossary['ALLOWCOMMENTS'][0]['#']); + $glossary->allowcomments = ($xmlglossary['ALLOWCOMMENTS'][0]['#']); } else { $glossary->allowcomments = $CFG->glossary_allowcomments; } if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) { - $glossary->usedynalink = addslashes($xmlglossary['USEDYNALINK'][0]['#']); + $glossary->usedynalink = ($xmlglossary['USEDYNALINK'][0]['#']); } else { $glossary->usedynalink = $CFG->glossary_linkentries; } if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) { - $glossary->defaultapproval = addslashes($xmlglossary['DEFAULTAPPROVAL'][0]['#']); + $glossary->defaultapproval = ($xmlglossary['DEFAULTAPPROVAL'][0]['#']); } else { $glossary->defaultapproval = $CFG->glossary_defaultapproval; } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 74b41a56e8..b1cfc98345 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -21,6 +21,7 @@ define("GLOSSARY_APPROVAL_VIEW", 7); /// STANDARD FUNCTIONS /////////////////////////////////////////////////////////// function glossary_add_instance($glossary) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will create a new instance and return the id number @@ -52,9 +53,8 @@ function glossary_add_instance($glossary) { print_error("This format doesn't exist!"); } - if ($returnid = insert_record("glossary", $glossary)) { + if ($returnid = $DB->insert_record("glossary", $glossary)) { $glossary->id = $returnid; - $glossary = stripslashes_recursive($glossary); glossary_grade_item_update($glossary); } @@ -66,7 +66,7 @@ function glossary_update_instance($glossary) { /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will update an existing instance with new data. - global $CFG; + global $CFG, $DB; if (empty($glossary->globalglossary)) { $glossary->globalglossary = 0; @@ -95,11 +95,10 @@ function glossary_update_instance($glossary) { print_error("This format doesn't exist!"); } - if ($return = update_record("glossary", $glossary)) { + if ($return = $DB->update_record("glossary", $glossary)) { if ($glossary->defaultapproval) { - execute_sql("update {$CFG->prefix}glossary_entries SET approved = 1 where approved != 1 and glossaryid = " . $glossary->id,false); + $DB->execute("UPDATE {glossary_entries} SET approved = 1 where approved <> 1 and glossaryid = ?", array($glossary->id)); } - $glossary = stripslashes_recursive($glossary); glossary_grade_item_update($glossary); } @@ -108,11 +107,12 @@ function glossary_update_instance($glossary) { function glossary_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $glossary = get_record("glossary", "id", "$id")) { + if (! $glossary = $DB->get_record("glossary", array("id"=>"$id"))) { return false; } @@ -120,40 +120,40 @@ function glossary_delete_instance($id) { # Delete any dependent records here # - if (! delete_records("glossary", "id", "$glossary->id")) { + if (! $DB->delete_records("glossary", array("id"=>$glossary->id))) { $result = false; } else { - if ($categories = get_records("glossary_categories","glossaryid",$glossary->id)) { + if ($categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id))) { $cats = ""; foreach ( $categories as $cat ) { $cats .= "$cat->id,"; } $cats = substr($cats,0,-1); if ($cats) { - delete_records_select("glossary_entries_categories", "categoryid in ($cats)"); - delete_records("glossary_categories", "glossaryid", $glossary->id); + $DB->delete_records_select("glossary_entries_categories", "categoryid in ($cats)"); + $DB->delete_records("glossary_categories", array("glossaryid"=>$glossary->id)); } } - if ( $entries = get_records("glossary_entries", "glossaryid", $glossary->id) ) { + if ( $entries = $DB->get_records("glossary_entries", array("glossaryid"=>$glossary->id))) { $ents = ""; foreach ( $entries as $entry ) { if ( $entry->sourceglossaryid ) { $entry->glossaryid = $entry->sourceglossaryid; $entry->sourceglossaryid = 0; - update_record("glossary_entries",$entry); + $DB->update_record("glossary_entries",$entry); } else { $ents .= "$entry->id,"; } } $ents = substr($ents,0,-1); if ($ents) { - delete_records_select("glossary_comments", "entryid in ($ents)"); - delete_records_select("glossary_alias", "entryid in ($ents)"); - delete_records_select("glossary_ratings", "entryid in ($ents)"); + $DB->delete_records_select("glossary_comments", "entryid in ($ents)"); + $DB->delete_records_select("glossary_alias", "entryid in ($ents)"); + $DB->delete_records_select("glossary_ratings", "entryid in ($ents)"); } } glossary_delete_attachments($glossary); - delete_records("glossary_entries", "glossaryid", "$glossary->id"); + $DB->delete_records("glossary_entries", array("glossaryid"=>$glossary->id)); } glossary_grade_item_delete($glossary); diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index 86f0f51c28..cba6ee12ba 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -4,8 +4,8 @@ require_once ($CFG->dirroot.'/course/moodleform_mod.php'); class mod_glossary_mod_form extends moodleform_mod { function definition() { + global $CFG, $COURSE, $DB; - global $CFG, $COURSE; $mform =& $this->_form; //------------------------------------------------------------------------------- diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 905b2df367..0ec25ca3ff 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -194,12 +194,14 @@ define("HOTPOT_MAX_EVENT_LENGTH", "432000"); // 5 days maximum // $hotpot->mode : 'add' or 'update' // $hotpot->sesskey : unique string required for Moodle's session management -function hotpot_add_instance(&$hotpot) { +function hotpot_add_instance($hotpot) { + global $DB; + if (hotpot_set_form_values($hotpot)) { - if ($result = insert_record('hotpot', $hotpot)) { + if ($result = $DB->insert_record('hotpot', $hotpot)) { $hotpot->id = $result; hotpot_update_events($hotpot); - hotpot_grade_item_update(stripslashes_recursive($hotpot)); + hotpot_grade_item_update($hotpot); } } else { $result= false; @@ -207,12 +209,14 @@ function hotpot_add_instance(&$hotpot) { return $result; } -function hotpot_update_instance(&$hotpot) { +function hotpot_update_instance($hotpot) { + global $DB; + if (hotpot_set_form_values($hotpot)) { $hotpot->id = $hotpot->instance; - if ($result = update_record('hotpot', $hotpot)) { + if ($result = $DB->update_record('hotpot', $hotpot)) { hotpot_update_events($hotpot); - hotpot_grade_item_update(stripslashes_recursive($hotpot)); + hotpot_grade_item_update($hotpot); } } else { $result= false; @@ -220,9 +224,10 @@ function hotpot_update_instance(&$hotpot) { return $result; } function hotpot_update_events($hotpot) { + global $DB; // remove any previous calendar events for this hotpot - delete_records('event', 'modulename', 'hotpot', 'instance', $hotpot->id); + $DB->delete_records('event', array('modulename'=>'hotpot', 'instance'=>$hotpot->id)); $event = new stdClass(); $event->description = $hotpot->summary; @@ -259,12 +264,12 @@ function hotpot_update_events($hotpot) { add_event($event); } } elseif ($hotpot->timeopen) { // only an open date - $event->name = addslashes($hotpot->name).' ('.get_string('hotpotopens', 'hotpot').')'; + $event->name = $hotpot->name.' ('.get_string('hotpotopens', 'hotpot').')'; $event->eventtype = 'open'; $event->timeduration = 0; add_event($event); } elseif ($hotpot->timeclose) { // only a closing date - $event->name = addslashes($hotpot->name).' ('.get_string('hotpotcloses', 'hotpot').')'; + $event->name = $hotpot->name.' ('.get_string('hotpotcloses', 'hotpot').')'; $event->timestart = $hotpot->timeclose; $event->eventtype = 'close'; $event->timeduration = 0; @@ -878,28 +883,29 @@ function hotpot_update_chain(&$hotpot) { return $ok; } function hotpot_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $hotpot = get_record("hotpot", "id", $id)) { + if (! $hotpot = $DB->get_record("hotpot", array("id"=>$id))) { return false; } - if (! delete_records("hotpot", "id", "$id")) { + if (! $DB->delete_records("hotpot", array("id"=>$id))) { return false; } - delete_records("hotpot_questions", "hotpot", "$id"); - if ($attempts = get_records_select("hotpot_attempts", "hotpot='$id'")) { + $DB->delete_records("hotpot_questions", array("hotpot"=>$id)); + if ($attempts = $DB->get_records("hotpot_attempts", array("hotpot"=>$id))) { $ids = implode(',', array_keys($attempts)); - delete_records_select("hotpot_attempts", "id IN ($ids)"); - delete_records_select("hotpot_details", "attempt IN ($ids)"); - delete_records_select("hotpot_responses", "attempt IN ($ids)"); + $DB->delete_records_select("hotpot_attempts", "id IN ($ids)"); + $DB->delete_records_select("hotpot_details", "attempt IN ($ids)"); + $DB->delete_records_select("hotpot_responses", "attempt IN ($ids)"); } // remove calendar events for this hotpot - delete_records('event', 'modulename', 'hotpot', 'instance', $id); + $DB->delete_records('event', array('modulename'=>'hotpot', 'instance'=>$id)); // remove grade item for this hotpot hotpot_grade_item_delete($hotpot); diff --git a/mod/label/lib.php b/mod/label/lib.php index f8a3524140..9a7d6959c1 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -6,51 +6,54 @@ define("LABEL_MAX_NAME_LENGTH", 50); function label_add_instance($label) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will create a new instance and return the id number /// of the new instance. $textlib = textlib_get_instance(); - $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true))); + $label->name = strip_tags(format_string($label->content)); if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; } $label->timemodified = time(); - return insert_record("label", $label); + return $DB->insert_record("label", $label); } function label_update_instance($label) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will update an existing instance with new data. $textlib = textlib_get_instance(); - $label->name = addslashes(strip_tags(format_string(stripslashes($label->content),true))); + $label->name = strip_tags(format_string($label->content)); if ($textlib->strlen($label->name) > LABEL_MAX_NAME_LENGTH) { $label->name = $textlib->substr($label->name, 0, LABEL_MAX_NAME_LENGTH)."..."; } $label->timemodified = time(); $label->id = $label->instance; - return update_record("label", $label); + return $DB->update_record("label", $label); } function label_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $label = get_record("label", "id", "$id")) { + if (! $label = $DB->get_record("label", array("id"=>$id))) { return false; } $result = true; - if (! delete_records("label", "id", "$label->id")) { + if (! $DB->delete_records("label", array("id"=>$label->id))) { $result = false; } diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 22106567f0..f7996b20db 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -19,17 +19,17 @@ define("LESSON_MAX_EVENT_LENGTH", "432000"); // 5 days maximum * @return int **/ function lesson_add_instance($lesson) { - global $SESSION; + global $SESSION, $DB; lesson_process_pre_save($lesson); - if (!$lesson->id = insert_record("lesson", $lesson)) { + if (!$lesson->id = $DB->insert_record("lesson", $lesson)) { return false; // bad } lesson_process_post_save($lesson); - lesson_grade_item_update(stripslashes_recursive($lesson)); + lesson_grade_item_update($lesson); return $lesson->id; } @@ -43,22 +43,23 @@ function lesson_add_instance($lesson) { * @return boolean **/ function lesson_update_instance($lesson) { + global $DB; $lesson->id = $lesson->instance; lesson_process_pre_save($lesson); - if (!$result = update_record("lesson", $lesson)) { + if (!$result = $DB->update_record("lesson", $lesson)) { return false; // Awe man! } lesson_process_post_save($lesson); // update grade item definition - lesson_grade_item_update(stripslashes_recursive($lesson)); + lesson_grade_item_update($lesson); // update grades - TODO: do it only when grading style changes - lesson_update_grades(stripslashes_recursive($lesson), 0, false); + lesson_update_grades($lesson, 0, false); return $result; } @@ -66,48 +67,49 @@ function lesson_update_instance($lesson) { /*******************************************************************/ function lesson_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $lesson = get_record("lesson", "id", "$id")) { + if (! $lesson = $DB->get_record("lesson", array("id"=>$id))) { return false; } $result = true; - if (! delete_records("lesson", "id", "$lesson->id")) { + if (! $DB->delete_records("lesson", array("id"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_pages", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_pages", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_answers", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_answers", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_attempts", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_attempts", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_grades", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_grades", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_timer", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_timer", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_branch", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_branch", array("lessonid"=>$lesson->id))) { $result = false; } - if (! delete_records("lesson_high_scores", "lessonid", "$lesson->id")) { + if (! $DB->delete_records("lesson_high_scores", array("lessonid"=>$lesson->id))) { $result = false; } - if ($events = get_records_select('event', "modulename = 'lesson' and instance = '$lesson->id'")) { + if ($events = $DB->get_records('event', array("modulename"=>'lesson', "instance"=>$lesson->id))) { foreach($events as $event) { delete_event($event->id); } } $pagetypes = page_import_types('mod/lesson/'); foreach ($pagetypes as $pagetype) { - if (!delete_records('block_instance', 'pageid', $lesson->id, 'pagetype', $pagetype)) { + if (!$DB->delete_records('block_instance', array('pageid'=>$lesson->id, 'pagetype'=>$pagetype))) { $result = false; } } @@ -540,7 +542,9 @@ function lesson_process_pre_save(&$lesson) { * @return void **/ function lesson_process_post_save(&$lesson) { - if ($events = get_records_select('event', "modulename = 'lesson' and instance = '$lesson->id'")) { + global $DB; + + if ($events = $DB->get_records('event', array('modulename'=>'lesson', 'instance'=>$lesson->id))) { foreach($events as $event) { delete_event($event->id); } diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 79b1414c22..57a3ba6277 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -14,7 +14,7 @@ require_once('locallib.php'); class mod_lesson_mod_form extends moodleform_mod { function definition() { - global $LESSON_NEXTPAGE_ACTION, $COURSE; + global $LESSON_NEXTPAGE_ACTION, $COURSE, $DB; $mform =& $this->_form; diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index eae9c35122..e9db294e6d 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -68,6 +68,7 @@ define("QUIZ_MAX_EVENT_LENGTH", 5*24*60*60); // 5 days maximum * false or a string error message on failure. */ function quiz_add_instance($quiz) { + global $DB; // Process the options from the form. $quiz->created = time(); @@ -78,7 +79,7 @@ function quiz_add_instance($quiz) { } // Try to store it in the database. - if (!$quiz->id = insert_record("quiz", $quiz)) { + if (!$quiz->id = $DB->insert_record("quiz", $quiz)) { return false; } @@ -97,6 +98,7 @@ function quiz_add_instance($quiz) { * @return mixed true on success, false or a string error message on failure. */ function quiz_update_instance($quiz) { + global $DB; // Process the options from the form. $result = quiz_process_options($quiz); @@ -106,7 +108,7 @@ function quiz_update_instance($quiz) { // Update the database. $quiz->id = $quiz->instance; - if (!update_record("quiz", $quiz)) { + if (!$DB->update_record("quiz", $quiz)) { return false; // some error occurred } @@ -114,30 +116,31 @@ function quiz_update_instance($quiz) { quiz_after_add_or_update($quiz); // Delete any previous preview attempts - delete_records('quiz_attempts', 'preview', '1', 'quiz', $quiz->id); + $DB->delete_records('quiz_attempts', 'preview', '1', array('quiz'=>$quiz->id)); return true; } function quiz_delete_instance($id) { + global $DB; /// Given an ID of an instance of this module, /// this function will permanently delete the instance /// and any data that depends on it. - if (! $quiz = get_record("quiz", "id", "$id")) { + if (! $quiz = $DB->get_record("quiz", array("id"=>$id))) { return false; } $result = true; - if ($attempts = get_records("quiz_attempts", "quiz", "$quiz->id")) { + if ($attempts = $DB->get_records("quiz_attempts", array("quiz"=>$quiz->id))) { foreach ($attempts as $attempt) { // TODO: this should use the delete_attempt($attempt->uniqueid) function in questionlib.php - if (! delete_records("question_states", "attempt", "$attempt->uniqueid")) { + if (! $DB->delete_records("question_states", array("attempt"=>$attempt->uniqueid))) { $result = false; } - if (! delete_records("question_sessions", "attemptid", "$attempt->uniqueid")) { + if (! $DB->delete_records("question_sessions", array("attemptid"=>$attempt->uniqueid))) { $result = false; } } @@ -152,19 +155,19 @@ function quiz_delete_instance($id) { 'quiz' => 'id' ); foreach ($tables_to_purge as $table => $keyfield) { - if (!delete_records($table, $keyfield, $quiz->id)) { + if (!$DB->delete_records($table, array($keyfield=>$quiz->id))) { $result = false; } } $pagetypes = page_import_types('mod/quiz/'); foreach($pagetypes as $pagetype) { - if(!delete_records('block_instance', 'pageid', $quiz->id, 'pagetype', $pagetype)) { + if (!$DB->delete_records('block_instance', array('pageid'=>$quiz->id, 'pagetype'=>$pagetype))) { $result = false; } } - if ($events = get_records_select('event', "modulename = 'quiz' and instance = '$quiz->id'")) { + if ($events = $DB->get_records('event', array("modulename"=>'quiz', "instance"=>$quiz->id))) { foreach($events as $event) { delete_event($event->id); } @@ -855,9 +858,10 @@ function quiz_process_options(&$quiz) { * @param object $quiz the quiz object. */ function quiz_after_add_or_update($quiz) { + global $DB; // Save the feedback - delete_records('quiz_feedback', 'quizid', $quiz->id); + $DB->delete_records('quiz_feedback', array('quizid'=>$quiz->id)); for ($i = 0; $i <= $quiz->feedbackboundarycount; $i += 1) { $feedback = new stdClass; @@ -865,7 +869,7 @@ function quiz_after_add_or_update($quiz) { $feedback->feedbacktext = $quiz->feedbacktext[$i]; $feedback->mingrade = $quiz->feedbackboundaries[$i]; $feedback->maxgrade = $quiz->feedbackboundaries[$i - 1]; - if (!insert_record('quiz_feedback', $feedback, false)) { + if (!$DB->insert_record('quiz_feedback', $feedback, false)) { return "Could not save quiz feedback."; } } @@ -874,7 +878,7 @@ function quiz_after_add_or_update($quiz) { // Update the events relating to this quiz. // This is slightly inefficient, deleting the old events and creating new ones. However, // there are at most two events, and this keeps the code simpler. - if ($events = get_records_select('event', "modulename = 'quiz' and instance = '$quiz->id'")) { + if ($events = $DB->get_records('event', array('modulename'=>'quiz', 'instance'=>$quiz->id))) { foreach($events as $event) { delete_event($event->id); } @@ -913,7 +917,7 @@ function quiz_after_add_or_update($quiz) { } //update related grade item - quiz_grade_item_update(stripslashes_recursive($quiz)); + quiz_grade_item_update($quiz); } function quiz_get_view_actions() { diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index abbbe8dc1f..7b59e85db9 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -8,7 +8,7 @@ class mod_quiz_mod_form extends moodleform_mod { function definition() { - global $COURSE, $CFG; + global $COURSE, $CFG, $DB; $mform =& $this->_form; //------------------------------------------------------------------------------- @@ -227,7 +227,7 @@ class mod_quiz_mod_form extends moodleform_mod { $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10)); if (!empty($this->_instance)) { - $this->_feedbacks = get_records('quiz_feedback', 'quizid', $this->_instance, 'mingrade DESC'); + $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid'=>$this->_instance), 'mingrade DESC'); } else { $this->_feedbacks = array(); } diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 9faff6245e..e25846f8f7 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -205,6 +205,7 @@ class resource_base { function add_instance($resource) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will create a new instance and return the id number @@ -212,11 +213,12 @@ class resource_base { $resource->timemodified = time(); - return insert_record("resource", $resource); + return $DB->insert_record("resource", $resource); } function update_instance($resource) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will update an existing instance with new data. @@ -224,18 +226,19 @@ class resource_base { $resource->id = $resource->instance; $resource->timemodified = time(); - return update_record("resource", $resource); + return $DB->update_record("resource", $resource); } function delete_instance($resource) { + global $DB; // Given an object containing the resource data // this function will permanently delete the instance // and any data that depends on it. $result = true; - if (! delete_records("resource", "id", "$resource->id")) { + if (! $DB->delete_records("resource", array("id"=>$resource->id))) { $result = false; } @@ -279,9 +282,9 @@ function resource_update_instance($resource) { } function resource_delete_instance($id) { - global $CFG; + global $CFG, $DB; - if (! $resource = get_record("resource", "id", "$id")) { + if (! $resource = $DB->get_record("resource", array("id"=>$id))) { return false; } diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index b3dbe33a5a..4a17566280 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -5,12 +5,12 @@ class mod_resource_mod_form extends moodleform_mod { var $_resinstance; function definition() { - global $CFG; + global $CFG, $DB; $mform =& $this->_form; // this hack is needed for different settings of each subtype if (!empty($this->_instance)) { - if($res = get_record('resource', 'id', (int)$this->_instance)) { + if($res = $DB->get_record('resource', array('id', $this->_instance))) { $type = $res->type; } else { print_error('incorrect assignment'); diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 1a5eb46913..a401888e10 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -11,7 +11,7 @@ */ //require_once('locallib.php'); function scorm_add_instance($scorm) { - global $CFG; + global $CFG, $DB; require_once('locallib.php'); @@ -42,7 +42,7 @@ function scorm_add_instance($scorm) { } $scorm->grademethod = ($scorm->whatgrade * 10) + $scorm->grademethod; - $id = insert_record('scorm', $scorm); + $id = $DB->insert_record('scorm', $scorm); if (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#'))) { // Rename temp scorm dir to scorm id @@ -54,10 +54,10 @@ function scorm_add_instance($scorm) { if ($scorm->parse == 1) { $scorm->id = $id; $scorm->launch = scorm_parse($scorm); - set_field('scorm','launch',$scorm->launch,'id',$scorm->id); + $DB->set_field('scorm', 'launch', $scorm->launch, array('id'=>$scorm->id)); } - scorm_grade_item_update(stripslashes_recursive($scorm)); + scorm_grade_item_update($scorm); return $id; } else { @@ -74,7 +74,7 @@ function scorm_add_instance($scorm) { * @return int */ function scorm_update_instance($scorm) { - global $CFG; + global $CFG, $DB; require_once('locallib.php'); @@ -119,12 +119,12 @@ function scorm_update_instance($scorm) { $scorm->launch = scorm_parse($scorm); } else { - $oldscorm = get_record('scorm','id',$scorm->id); + $oldscorm = $DB->get_record('scorm', array('id'=>$scorm->id)); $scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question } - if ($result = update_record('scorm', $scorm)) { - scorm_grade_item_update(stripslashes_recursive($scorm)); + if ($result = $DB->update_record('scorm', $scorm)) { + scorm_grade_item_update($scorm); } return $result; @@ -139,10 +139,9 @@ function scorm_update_instance($scorm) { * @return boolean */ function scorm_delete_instance($id) { + global $CFG, $DB; - global $CFG; - - if (! $scorm = get_record('scorm', 'id', $id)) { + if (! $scorm = $DB->get_record('scorm', array('id'=>$id))) { return false; } @@ -156,46 +155,46 @@ function scorm_delete_instance($id) { } // Delete any dependent records - if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_scoes_track', array('scormid'=>$scorm->id))) { $result = false; } - if ($scoes = get_records('scorm_scoes','scorm',$scorm->id)) { + if ($scoes = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id))) { foreach ($scoes as $sco) { - if (! delete_records('scorm_scoes_data', 'scoid', $sco->id)) { + if (! $DB->delete_records('scorm_scoes_data', array('scoid'=>$sco->id))) { $result = false; } } - delete_records('scorm_scoes', 'scorm', $scorm->id); + $DB->delete_records('scorm_scoes', array('scorm'=>$scorm->id)); } else { $result = false; } - if (! delete_records('scorm', 'id', $scorm->id)) { + if (! $DB->delete_records('scorm', array('id'=>$scorm->id))) { $result = false; } - /*if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) { + /*if (! $DB->delete_records('scorm_sequencing_controlmode', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_rolluprules', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_rolluprule', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_rolluprule', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_rollupruleconditions', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_rollupruleconditions', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_rolluprulecondition', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_rolluprulecondition', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_rulecondition', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_rulecondition', array('scormid'=>$scorm->id))) { $result = false; } - if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) { + if (! $DB->delete_records('scorm_sequencing_ruleconditions', array('scormid'=>$scorm->id))) { $result = false; }*/ - scorm_grade_item_delete(stripslashes_recursive($scorm)); + scorm_grade_item_delete($scorm); return $result; } diff --git a/mod/survey/lib.php b/mod/survey/lib.php index 085f6c6201..d5158f54f4 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -25,12 +25,13 @@ define("SURVEY_CIQ", "5"); // STANDARD FUNCTIONS //////////////////////////////////////////////////////// function survey_add_instance($survey) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will create a new instance and return the id number // of the new instance. - if (!$template = get_record("survey", "id", $survey->template)) { + if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) { return 0; } @@ -38,17 +39,18 @@ function survey_add_instance($survey) { $survey->timecreated = time(); $survey->timemodified = $survey->timecreated; - return insert_record("survey", $survey); + return $DB->insert_record("survey", $survey); } function survey_update_instance($survey) { + global $DB; // Given an object containing all the necessary data, // (defined by the form in mod_form.php) this function // will update an existing instance with new data. - if (!$template = get_record("survey", "id", $survey->template)) { + if (!$template = $DB->get_record("survey", array("id"=>$survey->template))) { return 0; } @@ -56,29 +58,30 @@ function survey_update_instance($survey) { $survey->questions = $template->questions; $survey->timemodified = time(); - return update_record("survey", $survey); + return $DB->update_record("survey", $survey); } function survey_delete_instance($id) { + global $DB; // Given an ID of an instance of this module, // this function will permanently delete the instance // and any data that depends on it. - if (! $survey = get_record("survey", "id", "$id")) { + if (! $survey = $DB->get_record("survey", array("id"=>$id))) { return false; } $result = true; - if (! delete_records("survey_analysis", "survey", "$survey->id")) { + if (! $DB->delete_records("survey_analysis", array("survey"=>$survey->id))) { $result = false; } - if (! delete_records("survey_answers", "survey", "$survey->id")) { + if (! $DB->delete_records("survey_answers", array("survey"=>$survey->id))) { $result = false; } - if (! delete_records("survey", "id", "$survey->id")) { + if (! $DB->delete_records("survey", array("id"=>$survey->id))) { $result = false; } diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index 43a6b8feb0..a75e734401 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -56,6 +56,7 @@ function wiki_get_students($wiki, $groups='', $sort='u.lastaccess', $fields='u.* function wiki_add_instance($wiki) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will create a new instance and return the id number @@ -68,11 +69,12 @@ function wiki_add_instance($wiki) { /// Determine the pagename for this wiki and save. $wiki->pagename = wiki_page_name($wiki); - return insert_record("wiki", $wiki); + return $DB->insert_record("wiki", $wiki); } function wiki_update_instance($wiki) { + global $DB; /// Given an object containing all the necessary data, /// (defined by the form in mod_form.php) this function /// will update an existing instance with new data. @@ -82,7 +84,7 @@ function wiki_update_instance($wiki) { $wiki->timemodified = time(); $wiki->id = $wiki->instance; - return update_record("wiki", $wiki); + return $DB->update_record("wiki", $wiki); } /// Delete all Directories recursively @@ -103,9 +105,9 @@ function wiki_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 $CFG; + global $CFG, $DB; - if (! $wiki = get_record("wiki", "id", $id)) { + if (! $wiki = $DB->get_record("wiki", array("id"=>$id))) { return false; } @@ -130,21 +132,21 @@ function wiki_delete_instance($id) { } # Delete any dependent records here # - if(!delete_records("wiki_locks","wikiid",$wiki->id)) { + if(!$DB->delete_records("wiki_locks", array("wikiid"=>$wiki->id))) { $result = false; } - if (! delete_records("wiki", "id", $wiki->id)) { + if (! $DB->delete_records("wiki", array("id"=>$wiki->id))) { $result = false; } /// Delete all wiki_entries and wiki_pages. if (($wiki_entries = wiki_get_entries($wiki)) !== false) { foreach ($wiki_entries as $wiki_entry) { - if (! delete_records("wiki_pages", "wiki", "$wiki_entry->id")) { + if (! $DB->delete_records("wiki_pages", array("wiki"=>$wiki_entry->id))) { $result = false; } - if (! delete_records("wiki_entries", "id", "$wiki_entry->id")) { + if (! $DB->delete_records("wiki_entries", array("id"=>$wiki_entry->id))) { $result = false; } }