diff --git a/lib/pagelib.php b/lib/pagelib.php index 089cd7d03530d..73d0dbe668059 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -335,7 +335,7 @@ function init_full() { if ($this->id == $COURSE->id) { $this->courserecord = $COURSE; } else { - $this->courserecord = $DB->get_record('course', 'id', $this->id); + $this->courserecord = $DB->get_record('course', array('id'=>$this->id)); } if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) { diff --git a/notes/add.php b/notes/add.php index cab3524be3441..00f4ed77d48cb 100644 --- a/notes/add.php +++ b/notes/add.php @@ -8,7 +8,7 @@ $userid = required_param('user', PARAM_INT); /// locate course information - if (!($course = get_record('course', 'id', $courseid))) { + if (!($course = $DB->get_record('course', array('id'=>$courseid)))) { print_error('Incorrect course id found'); } @@ -23,7 +23,7 @@ /// locate user information - if (!($user = get_record('user', 'id', $userid))) { + if (!($user = $DB->get_record('user', array('id'=>$userid)))) { print_error('Incorrect user id found'); } @@ -39,12 +39,12 @@ } /// if data was submitted and validated, then save it to database - if ($formdata = $noteform->get_data()) { + if ($formdata = $noteform->get_data(false)) { $note = new object(); - $note->courseid = $formdata->course; - $note->content = $formdata->content; - $note->format = FORMAT_PLAIN; - $note->userid = $formdata->user; + $note->courseid = $formdata->course; + $note->content = $formdata->content; + $note->format = FORMAT_PLAIN; + $note->userid = $formdata->user; $note->publishstate = $formdata->publishstate; if (note_save($note)) { add_to_log($note->courseid, 'notes', 'add', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id , 'add note'); @@ -53,15 +53,15 @@ redirect($CFG->wwwroot . '/notes/index.php?course=' . $note->courseid . '&user=' . $note->userid); } - if($noteform->is_submitted()) { + if ($noteform->is_submitted()) { // if data was submitted with errors, then use it as default for new form $note = $noteform->get_submitted_data(false); } else { // if data was not submitted yet, then use default values $note = new object(); - $note->id = 0; - $note->course = $courseid; - $note->user = $userid; + $note->id = 0; + $note->course = $courseid; + $note->user = $userid; $note->publishstate = optional_param('state', NOTES_STATE_PUBLIC, PARAM_ALPHA); } $noteform->set_data($note); diff --git a/notes/delete.php b/notes/delete.php index 4faceeb6235b9..242eb90b81de6 100644 --- a/notes/delete.php +++ b/notes/delete.php @@ -12,12 +12,12 @@ } // locate course information -if (!$course = get_record('course', 'id', $note->courseid)) { +if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) { print_error('Incorrect course id found'); } // locate user information - if (!$user = get_record('user', 'id', $note->userid)) { + if (!$user = $DB->get_record('user', array('id'=>$note->userid))) { print_error('Incorrect user id found'); } @@ -32,7 +32,7 @@ print_error('You may not delete this note'); } -if (data_submitted() && confirm_sesskey()) { +if (data_submitted(false) && confirm_sesskey()) { //if data was submitted and is valid, then delete note $returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid; if (note_delete($noteid)) { diff --git a/notes/edit.php b/notes/edit.php index f6ffe05ecae75..65b539c65f7b2 100644 --- a/notes/edit.php +++ b/notes/edit.php @@ -12,12 +12,12 @@ } /// locate course information - if (!$course = get_record('course', 'id', $note->courseid)) { + if (!$course = $DB->get_record('course', array('id'=>$note->courseid))) { print_error('Incorrect course id found'); } /// locate user information - if (!$user = get_record('user', 'id', $note->userid)) { + if (!$user = $DB->get_record('user', array('id'=>$note->userid))) { print_error('Incorrect user id found'); } @@ -45,10 +45,10 @@ /// if data was submitted and validated, then save it to database if ($formdata = $noteform->get_data()){ - $note->courseid = $formdata->course; - $note->userid = $formdata->user; - $note->content = $formdata->content; - $note->format = FORMAT_PLAIN; + $note->courseid = $formdata->course; + $note->userid = $formdata->user; + $note->content = $formdata->content; + $note->format = FORMAT_PLAIN; $note->publishstate = $formdata->publishstate; if (note_save($note)) { add_to_log($note->courseid, 'notes', 'update', 'index.php?course='.$note->courseid.'&user='.$note->userid . '#note-' . $note->id, 'update note'); @@ -63,9 +63,9 @@ $note = $noteform->get_submitted_data(false); } else { // if data was not submitted yet, then used values retrieved from the database - $note->user = $note->userid; + $note->user = $note->userid; $note->course = $note->courseid; - $note->note = $note->id; + $note->note = $note->id; } $noteform->set_data($note); $strnotes = get_string('editnote', 'notes'); diff --git a/notes/index.php b/notes/index.php index 8b82b04e203e4..bc93c4c507fdf 100644 --- a/notes/index.php +++ b/notes/index.php @@ -26,13 +26,13 @@ } /// locate course information - if (!$course = get_record('course', 'id', $courseid)) { + if (!$course = $DB->get_record('course', array('id'=>$courseid))) { print_error('Incorrect course id specified'); } /// locate user information if ($userid) { - if (!$user = get_record('user', 'id', $userid)) { + if (!$user = $DB->get_record('user', array('id'=>$userid))) { print_error('Incorrect user id specified'); } $filtertype = 'user'; diff --git a/notes/lib.php b/notes/lib.php index e7276c3b076a4..94162606a0d01 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -32,26 +32,34 @@ * @return array of note objects */ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='lastmodified DESC', $limitfrom=0, $limitnum=0) { + global $DB; + // setup filters $selects = array(); - if($courseid) { - $selects[] = 'courseid=' . $courseid; + $params = array(); + if ($courseid) { + $selects[] = 'courseid=?'; + $params[] = $courseid; } - if($userid) { - $selects[] = 'userid=' . $userid; + if ($userid) { + $selects[] = 'userid=?'; + $params[] = $userid; } - if($author) { - $selects[] = 'usermodified=' . $author; + if ($author) { + $selects[] = 'usermodified=?'; + $params[] = $author; } - if($state) { - $selects[] = "publishstate='$state'"; + if ($state) { + $selects[] = 'publishstate=?'; + $params[] = $state; } - $selects[] = "module='notes'"; + $selects[] = "module=?"; + $params[] = 'notes'; + $select = implode(' AND ', $selects); $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate'; // retrieve data - $rs =& get_recordset_select('post', $select, $order, $fields, $limitfrom, $limitnum); - return recordset_to_array($rs); + return $DB->get_records_select('post', $select, $params, $order, $fields, $limitfrom, $limitnum); } /** @@ -61,8 +69,10 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las * @return note object */ function note_load($note_id) { + global $DB; + $fields = 'id,courseid,userid,content,format,created,lastmodified,usermodified,publishstate'; - return get_record_select('post', "id=$note_id AND module='notes'", $fields); + return $DB->get_record('post', array('id'=>$note_id, 'module'=>'notes'), $fields); } /** @@ -73,9 +83,10 @@ function note_load($note_id) { * @return boolean true if the object was saved; false otherwise */ function note_save(&$note) { - global $USER; + global $USER, $DB; + // setup & clean fields - $note->module = 'notes'; + $note->module = 'notes'; $note->lastmodified = time(); $note->usermodified = $USER->id; if(empty($note->format)) { @@ -88,7 +99,7 @@ function note_save(&$note) { if(empty($note->id)) { // insert new note $note->created = $note->lastmodified; - if($id = insert_record('post', $note)) { + if ($id = $DB->insert_record('post', $note)) { $note->id = $id; $result = true; } else { @@ -96,7 +107,7 @@ function note_save(&$note) { } } else { // update old note - $result = update_record('post', $note); + $result = $DB->update_record('post', $note); } unset($note->module); return $result; @@ -109,7 +120,9 @@ function note_save(&$note) { * @return boolean true if the object was deleted; false otherwise */ function note_delete($noteid) { - return delete_records_select('post', "id=$noteid AND module='notes'"); + global $DB; + + return $DB->delete_records('post', array('id'=>$noteid, 'module'=>'notes')); } /** @@ -124,7 +137,11 @@ function note_get_state_name($state) { if (empty($states)) { $states = note_get_state_names(); } - return @$states[$state]; + if (isset($states[$state])) { + return $states[$state]; + } else { + return null; + } } /** @@ -147,20 +164,20 @@ function note_get_state_names() { * @param int $detail OR-ed NOTES_SHOW_xyz flags that specify which note parts to print */ function note_print($note, $detail = NOTES_SHOW_FULL) { + global $CFG, $USER, $DB; - global $CFG, $USER; - if (!$user = get_record('user','id',$note->userid)) { + if (!$user = $DB->get_record('user', array('id'=>$note->userid))) { debugging("User $note->userid not found"); return; } - if (!$author = get_record('user','id',$note->usermodified)) { + if (!$author = $DB->get_record('user', array('id'=>$note->usermodified))) { debugging("User $note->usermodified not found"); return; } $context = get_context_instance(CONTEXT_COURSE, $note->courseid); $sitecontext = get_context_instance(CONTEXT_SYSTEM); - $authoring = new object; + $authoring = new object(); $authoring->name = ''.fullname($author).''; $authoring->date = userdate($note->lastmodified); @@ -227,9 +244,9 @@ function note_print_list($notes, $detail = NOTES_SHOW_FULL) { * @param string $state state of the notes (i.e. draft, public, site) ('' means any) * @param int $author id of the user who modified the note last time (0 means any) */ -function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) -{ +function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $courseid = 0, $userid = 0, $state = '', $author = 0) { global $CFG; + if ($header) { echo '

' . $header . '

'; echo '
'; @@ -242,7 +259,7 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei } } if ($viewnotes) { - $notes =& note_list($courseid, $userid, $state, $author); + $notes = note_list($courseid, $userid, $state, $author); if ($notes) { note_print_list($notes); } @@ -260,6 +277,8 @@ function note_print_notes($header, $addcourseid = 0, $viewnotes = true, $coursei * @return bool success */ function note_delete_all($courseid) { - return delete_records('post', 'module', 'notes', 'courseid', $courseid); + global $DB; + + return $DB->delete_records('post', array('module'=>'notes', 'courseid'=>$courseid)); } ?> diff --git a/rss/file.php b/rss/file.php index a110e87bf2dba..4f349416dcbd4 100644 --- a/rss/file.php +++ b/rss/file.php @@ -61,7 +61,7 @@ } - if (!$course = get_record('course', 'id', $courseid)) { + if (!$course = $DB->get_record('course', array('id'=>$courseid))) { rss_not_found(); }