$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();
}
/// 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
/// 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');
}
}
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);
}
}
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);
}
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!");
}
}
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();
}
}
}
/// 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)) {
$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) {
} 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;
}
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);
$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) {
$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");
}
/// 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");
}
if (empty($form)) {
$form = $section;
- } else {
- $form = stripslashes_safe($form);
}
// !! no db access using data from $form beyond this point !!
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");
}
$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');
}
//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
}
//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
}
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");
}
$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");
}
$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");
}
$userid = 0;
}
- if (! $course = $DB->get_record('course', array('id'=>$id) )) {
+ if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error('invalidcourseid');
}
$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');
}
$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');
}
// 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');
}
$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');
}
$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");
}
$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);
$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.");
}
$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");
}
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");
}
$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");
}
$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 {
$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");
}
$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");
}