From 579d45b434e519c8bc79a4ae5b5a2e929cbe2cb1 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 1 Jun 2008 18:12:24 +0000 Subject: [PATCH] MDL-14679 converted some get courses --- course/category.php | 52 ++++++++++++++---------------- course/delete.php | 4 +-- course/editcategory.php | 14 ++++---- course/editsection.php | 10 +++--- course/enrol.php | 2 +- course/import/groups/index.php | 6 ++-- course/importstudents.php | 2 +- course/mod.php | 2 +- course/scales.php | 2 +- course/unenrol.php | 2 +- course/user.php | 2 +- mod/assignment/index.php | 2 +- mod/assignment/type/online/all.php | 2 +- mod/choice/index.php | 2 +- mod/data/index.php | 2 +- mod/feedback/index.php | 2 +- mod/forum/search.php | 2 +- mod/glossary/index.php | 2 +- mod/hotpot/index.php | 2 +- mod/resource/index.php | 2 +- mod/scorm/index.php | 2 +- mod/survey/index.php | 2 +- mod/wiki/index.php | 2 +- 23 files changed, 58 insertions(+), 64 deletions(-) diff --git a/course/category.php b/course/category.php index 1a1c23f491..ac7cd6b480 100644 --- a/course/category.php +++ b/course/category.php @@ -19,6 +19,8 @@ $resort = optional_param('resort', 0, PARAM_BOOL); $categorytheme= optional_param('categorytheme', false, PARAM_CLEAN); + $rename = stripslashes($rename); // TODO: remove soon + if ($CFG->forcelogin) { require_login(); } @@ -60,7 +62,7 @@ /// Rename the category if requested if (!empty($rename) and confirm_sesskey()) { $category->name = $rename; - if (! set_field("course_categories", "name", $category->name, "id", $category->id)) { + if (!$DB->set_field("course_categories", "name", $category->name, array("id"=>$category->id))) { notify("An error occurred while renaming the category"); } // MDL-9983 @@ -70,7 +72,7 @@ /// Set the category theme if requested if (($categorytheme !== false) and confirm_sesskey()) { $category->theme = $categorytheme; - if (! set_field('course_categories', 'theme', $category->theme, 'id', $category->id)) { + if (!$DB->set_field('course_categories', 'theme', $category->theme, array('id'=>$category->id))) { notify('An error occurred while setting the theme'); } } @@ -80,15 +82,14 @@ if ($resort and confirm_sesskey()) { if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) { // move it off the range - $count = get_record_sql('SELECT MAX(sortorder) AS max, 1 - FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); + $count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course} WHERE category= ?', array($category->id)); $count = $count->max + 100; - begin_sql(); + $DB->begin_sql(); foreach ($courses as $course) { - set_field('course', 'sortorder', $count, 'id', $course->id); + $DB->set_field('course', 'sortorder', $count, array('id'=>$course->id)); $count++; } - commit_sql(); + $DB->commit_sql(); fix_course_sortorder($category->id); } } @@ -163,13 +164,13 @@ if ($creatorediting) { /// Move a specified course to a new category - if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) { // Some courses are being moved + if (!empty($moveto) and $data = data_submitted(false) and confirm_sesskey()) { // Some courses are being moved // user must have category update in both cats to perform this require_capability('moodle/category:update', $context); require_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $moveto)); - if (! $destcategory = get_record("course_categories", "id", $data->moveto)) { + if (! $destcategory = $DB->get_record("course_categories", array("id"=>$data->moveto))) { print_error("cannotfindcategory", '', '', $data->moveto); } @@ -188,14 +189,14 @@ if ((!empty($hide) or !empty($show)) and confirm_sesskey()) { require_capability('moodle/course:visibility', $context); if (!empty($hide)) { - $course = get_record("course", "id", $hide); + $course = $DB->get_record("course", array("id"=>$hide)); $visible = 0; } else { - $course = get_record("course", "id", $show); + $course = $DB->get_record("course", array("id"=>$show)); $visible = 1; } if ($course) { - if (! set_field("course", "visible", $visible, "id", $course->id)) { + if (!$DB->set_field("course", "visible", $visible, array("id"=>$course->id))) { notify("Could not update that course!"); } } @@ -214,31 +215,26 @@ fix_course_sortorder($category->id); // we are going to need to know the range - $max = get_record_sql('SELECT MAX(sortorder) AS max, 1 - FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id); + $max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM {course} WHERE category=?', array($category->id)); $max = $max->max + 100; if (!empty($moveup)) { - $movecourse = get_record('course', 'id', $moveup); - $swapcourse = get_record('course', - 'category', $category->id, - 'sortorder', $movecourse->sortorder - 1); + $movecourse = $DB->get_record('course', array('id'=>$moveup)); + $swapcourse = $DB->get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder-1))); } else { - $movecourse = get_record('course', 'id', $movedown); - $swapcourse = get_record('course', - 'category', $category->id, - 'sortorder', $movecourse->sortorder + 1); + $movecourse = get_record('course', array('id'=>$movedown)); + $swapcourse = get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1))); } if ($swapcourse and $movecourse) { // Renumber everything for robustness - begin_sql(); - if (!( set_field("course", "sortorder", $max, "id", $swapcourse->id) - && set_field("course", "sortorder", $swapcourse->sortorder, "id", $movecourse->id) - && set_field("course", "sortorder", $movecourse->sortorder, "id", $swapcourse->id) + $DB->begin_sql(); + if (!( $DB->set_field("course", "sortorder", $max, array("id"=>$swapcourse->id)) + && $DB->set_field("course", "sortorder", $swapcourse->sortorder, array("id"=>$movecourse->id)) + && $DB->set_field("course", "sortorder", $movecourse->sortorder, array("id"=>$swapcourse->id)) )) { notify("Could not update that course!"); } - commit_sql(); + $DB->commit_sql(); } } @@ -264,7 +260,7 @@ } /// Print out all the sub-categories - if ($subcategories = get_records("course_categories", "parent", $category->id, "sortorder ASC")) { + if ($subcategories = $DB->get_records("course_categories", array("parent"=>$category->id), "sortorder ASC")) { $firstentry = true; foreach ($subcategories as $subcategory) { if ($subcategory->visible or has_capability('moodle/course:create', $context)) { diff --git a/course/delete.php b/course/delete.php index 9f07a5f8f9..36d1bac8ef 100644 --- a/course/delete.php +++ b/course/delete.php @@ -20,11 +20,11 @@ $stradministration = get_string("administration"); $strcategories = get_string("categories"); - if (! $course = get_record("course", "id", $id)) { + if (! $course = $DB->get_record("course", array("id"=>$id))) { print_error("invalidcourseid"); } - $category = get_record("course_categories", "id", $course->category); + $category = $DB->get_record("course_categories", array("id"=>$course->category)); $navlinks = array(); if (! $delete) { diff --git a/course/editcategory.php b/course/editcategory.php index 0292caedf0..cb308f4f7f 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -54,12 +54,12 @@ if ($mform->is_cancelled()){ } else { redirect($CFG->wwwroot.'/course/category.php?categoryedit=on&id='.$category->id); } -} else if (($data = $mform->get_data())) { +} else if (($data = $mform->get_data(false))) { $newcategory = new stdClass(); - $newcategory->name = $data->name; + $newcategory->name = $data->name; $newcategory->description = $data->description; - $newcategory->sortorder = 999; - $newcategory->parent = $data->parent; // if $id = 0, the new category will be a top-level category + $newcategory->sortorder = 999; + $newcategory->parent = $data->parent; // if $id = 0, the new category will be a top-level category if (!empty($data->theme) && !empty($CFG->allowcategorythemes)) { $newcategory->theme = $data->theme; @@ -67,7 +67,7 @@ if ($mform->is_cancelled()){ } if (empty($category) && has_capability('moodle/category:create', $context)) { // Create a new category - if (!$newcategory->id = insert_record('course_categories', $newcategory)) { + if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) { notify( "Could not insert the new category '$newcategory->name' "); } else { $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id); @@ -78,11 +78,11 @@ if ($mform->is_cancelled()){ $newcategory->id = $category->id; if ($newcategory->parent != $category->parent) { - $parent_cat = get_record('course_categories', 'id', $newcategory->parent); + $parent_cat = $DB->get_record('course_categories', array('id'=>$newcategory->parent)); move_category($newcategory, $parent_cat); } - if (!update_record('course_categories', $newcategory)) { + if (!$DB->update_record('course_categories', $newcategory)) { print_error( "cannotupdatecategory", '', '', $newcategory->name); } else { if ($newcategory->parent == 0) { diff --git a/course/editsection.php b/course/editsection.php index 13f9f0a0b3..96234511ad 100644 --- a/course/editsection.php +++ b/course/editsection.php @@ -6,11 +6,11 @@ $id = required_param('id',PARAM_INT); // Week ID - if (! $section = get_record("course_sections", "id", $id)) { + if (! $section = $DB->get_record("course_sections", array("id"=>$id))) { print_error("sectionnotexist"); } - if (! $course = get_record("course", "id", $section->course)) { + if (! $course = $DB->get_record("course", array("id"=>$section->course))) { print_error("invalidcourseid"); } @@ -20,11 +20,11 @@ /// If data submitted, then process and store. - if ($form = data_submitted() and confirm_sesskey()) { + if ($form = data_submitted(false) and confirm_sesskey()) { $timenow = time(); - if (! set_field("course_sections", "summary", $form->summary, "id", $section->id)) { + if ($DB->set_field("course_sections", "summary", $form->summary, array("id"=>$section->id))) { print_error("cannotupdatesummary"); } @@ -38,8 +38,6 @@ if (empty($form)) { $form = $section; - } else { - $form = stripslashes_safe($form); } // !! no db access using data from $form beyond this point !! diff --git a/course/enrol.php b/course/enrol.php index 218d0aa2ce..9f645fe551 100644 --- a/course/enrol.php +++ b/course/enrol.php @@ -19,7 +19,7 @@ redirect($wwwroot.'/login/index.php'); } - if (! $course = $DB->get_record('course', array('id'=>$id) )) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("That's an invalid course id"); } diff --git a/course/import/groups/index.php b/course/import/groups/index.php index 4d9fe14fa9..30f715a292 100755 --- a/course/import/groups/index.php +++ b/course/import/groups/index.php @@ -8,7 +8,7 @@ $id = required_param('id', PARAM_INT); // Course id - if (! $course = $DB->get_record('course', array('id'=>$id) )) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } @@ -140,7 +140,7 @@ //if idnumber is set, we use that. //unset invalid courseid if (isset($newgroup->idnumber)){ - if (!$mycourse = get_record('course', 'idnumber',$newgroup->idnumber)){ + if (!$mycourse = $DB->get_record('course', array('idnumber'=>$newgroup->idnumber))) { notify(get_string('unknowncourseidnumber', 'error', $newgroup->idnumber)); unset($newgroup->courseid);//unset so 0 doesnt' get written to database } @@ -150,7 +150,7 @@ //unset invalid coursename (if no id) else if (isset($newgroup->coursename)){ - if (!$mycourse = get_record('course', 'shortname',$newgroup->coursename)){ + if (!$mycourse = $DB->get_record('course', array('shortname', $newgroup->coursename))) { notify(get_string('unknowncourse', 'error', $newgroup->coursename)); unset($newgroup->courseid);//unset so 0 doesnt' get written to database } diff --git a/course/importstudents.php b/course/importstudents.php index f60e28f3f3..43fab82fb8 100644 --- a/course/importstudents.php +++ b/course/importstudents.php @@ -21,7 +21,7 @@ redirect("$CFG->wwwroot/$CFG->admin/index.php"); } - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("invalidcourseid"); } diff --git a/course/mod.php b/course/mod.php index 3ceb89addf..63d790141f 100644 --- a/course/mod.php +++ b/course/mod.php @@ -626,7 +626,7 @@ $id = required_param('id',PARAM_INT); $section = required_param('section',PARAM_INT); - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("invalidcourseid"); } diff --git a/course/scales.php b/course/scales.php index 7250eed67c..6b5d158672 100644 --- a/course/scales.php +++ b/course/scales.php @@ -6,7 +6,7 @@ $id = required_param('id', PARAM_INT); // course id - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("invalidcourseid"); } diff --git a/course/unenrol.php b/course/unenrol.php index 26a1cb6f4d..6a81254e89 100644 --- a/course/unenrol.php +++ b/course/unenrol.php @@ -21,7 +21,7 @@ $userid = 0; } - if (! $course = $DB->get_record('course', array('id'=>$id) )) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } diff --git a/course/user.php b/course/user.php index 8806e66139..39162fbb8e 100644 --- a/course/user.php +++ b/course/user.php @@ -13,7 +13,7 @@ $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', 100, PARAM_INT); - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid', 'error'); } diff --git a/mod/assignment/index.php b/mod/assignment/index.php index 646f35c5a5..ed2f5c8fbb 100644 --- a/mod/assignment/index.php +++ b/mod/assignment/index.php @@ -6,7 +6,7 @@ $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } diff --git a/mod/assignment/type/online/all.php b/mod/assignment/type/online/all.php index 1025e33bfd..50dacce7c5 100644 --- a/mod/assignment/type/online/all.php +++ b/mod/assignment/type/online/all.php @@ -18,7 +18,7 @@ // get parameter $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourse'); } diff --git a/mod/choice/index.php b/mod/choice/index.php index 3d6d89cd38..8a76d6664a 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -5,7 +5,7 @@ $id = required_param('id',PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error('invalidcourseid'); } diff --git a/mod/data/index.php b/mod/data/index.php index 648f0549b3..13a7666a79 100755 --- a/mod/data/index.php +++ b/mod/data/index.php @@ -27,7 +27,7 @@ $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { error("Course ID is incorrect"); } diff --git a/mod/feedback/index.php b/mod/feedback/index.php index 6374b9831a..f89f53bb36 100644 --- a/mod/feedback/index.php +++ b/mod/feedback/index.php @@ -13,7 +13,7 @@ $id = required_param('id', PARAM_INT); - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { error("Course ID is incorrect"); } $capabilities = feedback_load_course_capabilities($course->id); diff --git a/mod/forum/search.php b/mod/forum/search.php index 9e59099254..7a0d6a240d 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -84,7 +84,7 @@ $search = forum_clean_search_terms($search); } - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { error("Course id is incorrect."); } diff --git a/mod/glossary/index.php b/mod/glossary/index.php index 5537e15d8b..8386a22e1c 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -10,7 +10,7 @@ $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } diff --git a/mod/hotpot/index.php b/mod/hotpot/index.php index 1ab3df6008..4d63ad520c 100644 --- a/mod/hotpot/index.php +++ b/mod/hotpot/index.php @@ -7,7 +7,7 @@ require_once("lib.php"); $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } diff --git a/mod/resource/index.php b/mod/resource/index.php index a611aa9245..d250991c5c 100644 --- a/mod/resource/index.php +++ b/mod/resource/index.php @@ -4,7 +4,7 @@ $id = required_param( 'id', PARAM_INT ); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } diff --git a/mod/scorm/index.php b/mod/scorm/index.php index 72089d765e..96f801dbcb 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -6,7 +6,7 @@ $id = required_param('id', PARAM_INT); // course id if (!empty($id)) { - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } } else { diff --git a/mod/survey/index.php b/mod/survey/index.php index 26327b212f..9c7ef54d7e 100644 --- a/mod/survey/index.php +++ b/mod/survey/index.php @@ -5,7 +5,7 @@ $id = required_param('id', PARAM_INT); // Course Module ID - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } diff --git a/mod/wiki/index.php b/mod/wiki/index.php index 20927812ec..eb7e80a4e3 100644 --- a/mod/wiki/index.php +++ b/mod/wiki/index.php @@ -8,7 +8,7 @@ $id = required_param('id', PARAM_INT); // course - if (! $course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record('course', array('id'=>$id))) { print_error("Course ID is incorrect"); } -- 2.39.5