print_error("unknowcategory");
}
- if (!$category = get_record("course_categories", "id", $id)) {
+ if (!$category = $DB->get_record("course_categories", array("id"=>$id))) {
print_error("unknowcategory");
}
$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', array('id'=>$movedown));
- $swapcourse = get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1)));
+ $movecourse = $DB->get_record('course', array('id'=>$movedown));
+ $swapcourse = $DB->get_record('course', array('category'=>$category->id, 'sortorder'=>($movecourse->sortorder+1)));
}
if ($swapcourse and $movecourse) { // Renumber everything for robustness
} elseif (!is_null($id) && !$categoryadd) { // Show Edit category form: $id is given as the identifier of the category being edited
$strtitle = get_string("editcategorysettings");
$context = get_context_instance(CONTEXT_COURSECAT, $id);
- if (!$category = get_record("course_categories", "id", $id)) {
+ if (!$category = $DB->get_record("course_categories", array("id"=>$id))) {
print_error("unknowcategory");
}
}
if ($resort and confirm_sesskey()) {
if ($courses = get_courses($id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
// move it off the range
- $count = get_record_sql('SELECT MAX(sortorder) AS max, 1
+ $count = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1
FROM ' . $CFG->prefix . 'course WHERE category=' . $category->id);
$count = $count->max + 100;
begin_sql();
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))) {
pritn_error("unknowcategory");
}
// TODO function to move the category
if ((!empty($hide) or !empty($show)) and confirm_sesskey()) {
require_capability('moodle/category:visibility', $context);
if (!empty($hide)) {
- $category = get_record("course_categories", "id", $hide);
+ $category = $DB->get_record("course_categories", array("id"=>$hide));
$visible = 0;
} else {
- $category = get_record("course_categories", "id", $show);
+ $category = $DB->get_record("course_categories", array("id"=>$show));
$visible = 1;
}
if ($category) {
// TODO something like fix_course_sortorder() ?
// we are going to need to know the range
- $max = get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
+ $max = $DB->get_record_sql('SELECT MAX(sortorder) AS max, 1 FROM ' . $CFG->prefix . 'course_categories WHERE id=' . $category->id);
$max = $max->max + 100;
if (!empty($moveup)) {
- $movecategory = get_record('course_categories', 'id', $moveup);
- $swapcategory = get_record('course_categories',
- 'category', $category->id,
- 'sortorder', $movecategory->sortorder - 1);
+ $movecategory = $DB->get_record('course_categories', array('id'=>$moveup));
+ $swapcategory = $DB->get_record('course_categories',
+ array('category'=>$category->id,
+ 'sortorder'=>$movecategory->sortorder - 1));
} else {
- $movecategory = get_record('course_categories', 'id', $movedown);
- $swapcategory = get_record('course_categories',
- 'category', $category->id,
- 'sortorder', $movecategory->sortorder + 1);
+ $movecategory = $DB->get_record('course_categories', array('id'=>$movedown));
+ $swapcategory = $DB->get_record('course_categories',
+ array('category'=> $category->id,
+ 'sortorder'=>$movecategory->sortorder + 1));
}
if ($swapcourse and $movecourse) { // Renumber everything for robustness
} // End of editing stuff
// 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)) {
print_error("invalidshortname");
}
} else {
- if (!$course = get_record("course", array("id"=>$id))) {
+ if (!$course = $DB->get_record("course", array("id"=>$id))) {
print_error("invalidcourseid");
}
}
if ($managerroles = get_config('', 'coursemanager')) {
$coursemanagerroles = split(',', $managerroles);
foreach ($coursemanagerroles as $roleid) {
- $role = get_record('role','id',$roleid);
+ $role = $DB->get_record('role', array('id'=>$roleid));
$canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
$roleid = (int) $roleid;
if ($users = get_role_users($roleid, $context, true, '', 'u.lastname ASC', $canseehidden)) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
- $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
+ $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if (0 && $ld && !empty($log->info)) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
- $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
+ $ld = $DB->get_record('log_display', array('module'=>$log->module, 'action'=>$log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && !empty($log->info)) {
function print_overview($courses) {
- global $CFG, $USER;
+ global $CFG, $USER, $DB;
$htmlarray = array();
- if ($modules = get_records('modules')) {
+ if ($modules = $DB->get_records('modules')) {
foreach ($modules as $mod) {
if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
$rejectnotice = optional_param('rejectnotice', '', PARAM_CLEANHTML);
if (!empty($approve) and confirm_sesskey()) {
- if ($course = get_record("course_request","id",$approve)) {
+ if ($course = $DB->get_record("course_request", array("id"=>$approve))) {
foreach (array_keys((array)$course) as $key) {
$course->$key = addslashes($course->$key);
}
// place at beginning of category
fix_course_sortorder();
- if (empty($CFG->defaultrequestcategory) or !record_exists('course_categories', 'id', $CFG->defaultrequestcategory)) {
+ if (empty($CFG->defaultrequestcategory) or !$DB->record_exists('course_categories', array('id'=>$CFG->defaultrequestcategory))) {
// default to first top level directory, hacky but means things don't break
- $CFG->defaultrequestcategory = get_field('course_categories', 'id', 'parent', '0');
+ $CFG->defaultrequestcategory = $DB->get_field('course_categories', 'id', array('parent'=>'0'));
}
$course->category = $CFG->defaultrequestcategory;
- $course->sortorder = get_field_sql("SELECT min(sortorder)-1 FROM {$CFG->prefix}course WHERE category=$course->category");
+ $course->sortorder = $DB->get_field_sql("SELECT min(sortorder)-1 FROM {course} WHERE category=?", array($course->category));
if (empty($course->sortorder)) {
$course->sortorder = 1000;
}
if (!empty($CFG->restrictmodulesfor) && $CFG->restrictmodulesfor != 'none' && !empty($CFG->restrictbydefault)) {
$course->restrictmodules = 1;
}
- if ($courseid = insert_record("course",$course)) {
+ if ($courseid = $DB->insert_record("course",$course)) {
$page = page_create_object(PAGE_COURSE_VIEW, $courseid);
blocks_repopulate_page($page); // Return value not checked because you can always edit later
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$allowedmods = explode(',',$CFG->defaultallowedmodules);
update_restricted_mods($course,$allowedmods);
}
- delete_records('course_request','id',$approve);
+ $DB->delete_records('course_request', array('id'=>$approve));
$success = 1;
}
if (!empty($success)) {
- $user = get_record('user','id',$teacherid);
+ $user = $DB->get_record('user', array('id'=>$teacherid));
$a->name = $course->fullname;
$a->url = $CFG->wwwroot.'/course/view.php?id='.$courseid;
$a->teacher = $course->teacher;
print_header($strtitle,$strheading,build_navigation(array(array('name'=>$strheading,'link'=>'','type'=>'misc'))));
if (!empty($reject) and confirm_sesskey()) {
- if ($reject = get_record("course_request","id",$reject)) {
+ if ($reject = $DB->get_record("course_request", array("id"=>$reject))) {
if (empty($rejectnotice)) {
// display a form for writing a reason
print_simple_box_start('center');
print_simple_box_end();
}
else {
- $user = get_record("user","id",$reject->requester);
+ $user = $DB->get_record("user", array("id"=>$reject->requester));
email_to_user($user,$USER,get_string('courserejectsubject'),get_string('courserejectemail','moodle',$rejectnotice));
- delete_records("course_request","id",$reject->id);
+ $DB->delete_records("course_request", array("id"=>$reject->id));
notice(get_string('courserejected'),'pending.php');
}
}
- } else if ($pending = get_records("course_request")) {
+ } else if ($pending = $DB->get_records("course_request")) {
// loop through
$table->cellpadding = 4;
$table->cellspacing = 3;
get_string('requestreason'),'');
$strrequireskey = get_string('requireskey');
foreach ($pending as $course) {
- $requester = get_record('user','id',$course->requester);
+ $requester = $DB->get_record('user', array('id'=>$course->requester));
// check here for shortname collisions and warn about them.
- if ($match = get_record("course","shortname",$course->shortname)) {
+ if ($match = $DB->get_record("course", array("shortname"=>$course->shortname))) {
$course->shortname .= ' [*]';
$collision = 1;
}
$id = required_param('id', PARAM_INT);
- if (!$course = get_record('course', 'id', $id) ) {
+ if (!$course = $DB->get_record('course', array('id'=>$id))) {
print_error("That's an invalid course id");
}
$dateinfo = get_string('alldays');
if (!empty($param->user)) {
- if (!$u = get_record('user', 'id', $param->user) ) {
+ if (!$u = $DB->get_record('user', array('id'=>$param->user))) {
print_error("That's an invalid user!");
}
$userinfo = fullname($u);
$hiddenfilter = "AND cs.visible = 1";
}
$sections = array();
- if ($ss = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
- FROM {$CFG->prefix}course_sections cs
- WHERE cs.course = $course->id AND cs.section <= $course->numsections
- $hiddenfilter
- ORDER BY section")) {
+ if ($ss = $DB->get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
+ FROM {course_sections} cs
+ WHERE cs.course = ? AND cs.section <= ?
+ $hiddenfilter
+ ORDER BY section", array($course->id, $course->numsections))) {
foreach ($ss as $section) {
$sections[$section->section] = $section;
}
class course_reset_form extends moodleform {
function definition (){
- global $CFG, $COURSE;
+ global $CFG, $COURSE, $DB;
$mform =& $this->_form;
}
$unsupported_mods = array();
- if ($allmods = get_records('modules') ) {
+ if ($allmods = $DB->get_records('modules') ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
if (!count_records($modname, 'course', $COURSE->id)) {
}
function load_defaults() {
- global $CFG, $COURSE;
+ global $CFG, $COURSE, $DB;
$mform =& $this->_form;
$defaults['reset_roles'] = array($CFG->defaultcourseroleid);
}
- if ($allmods = get_records('modules') ) {
+ if ($allmods = $DB->get_records('modules') ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
// Authorise the user and verify some incoming data
-if (!$course = get_record('course', 'id', $courseid)) {
+if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
error_log('AJAX commands.php: Course does not exist');
die;
}
case 'section':
- if (!record_exists('course_sections','course',$course->id,'section',$id)) {
+ if (!$DB->record_exists('course_sections', array('course'=>$course->id, 'section'=>$id))) {
error_log('AJAX commands.php: Bad Section ID '.$id);
die;
}
break;
case 'resource':
- if (!$mod = get_record('course_modules', 'id', $id, 'course', $course->id)) {
+ if (!$mod = $DB->get_record('course_modules', array('id'=>$id, 'course'=>$course->id))) {
error_log('AJAX commands.php: Bad course module ID '.$id);
die;
}
break;
case 'move':
- if (!$section = get_record('course_sections','course',$course->id,'section',$sectionid)) {
+ if (!$section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$sectionid))) {
error_log('AJAX commands.php: Bad section ID '.$sectionid);
die;
}
if ($beforeid > 0){
- $beforemod = get_record('course_modules', 'id', $beforeid);
+ $beforemod = $DB->get_record('course_modules', array('id'=>$beforeid));
} else {
$beforemod = NULL;
}
$newcourse = new object;
$newcourse->id = $course->id;
$newcourse->marker = $value;
- if (!update_record('course',$newcourse)) {
+ if (!$DB->update_record('course', $newcourse)) {
error_log('AJAX commands.php: Failed to update course marker for course '.$newcourse->id);
die;
}
break;
case 'resource':
- if (!$cm = get_record('course_modules', 'id', $id, 'course', $course->id)) {
+ if (!$cm = $DB->get_record('course_modules', array('id'=>$id, 'course'=>$course->id))) {
error_log('AJAX rest.php: Bad course module ID '.$id);
die;
}
- if (!$mod = get_record('modules', 'id', $cm->module)) {
+ if (!$mod = $DB->get_record('modules', array('id'=>$cm->module))) {
error_log('AJAX rest.php: Bad module ID '.$cm->module);
die;
}
print_header($strscales);
- if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
+ if ($scales = $DB->get_records("scale", array("courseid"=>$course->id), "name ASC")) {
print_heading($strcustomscales);
if (has_capability('moodle/course:managescales', $context)) {
}
}
- if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
+ if ($scales = $DB->get_records("scale", array("courseid"=>0), "name ASC")) {
print_heading($strstandardscales);
foreach ($scales as $scale) {
$scalemenu = make_menu_from_list($scale->scale);
if ($hide or $show and confirm_sesskey()) {
if ($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!");
}
}
exit;
}
- 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
- 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);
}
// get list of courses containing blocks if required
if (!empty($blocklist) and confirm_sesskey()) {
$blockid = $blocklist;
- if (!$blocks = get_records('block_instance', 'blockid', $blockid)) {
- print_error( 'blockcannotread', '', '', $blockid);
+ if (!$blocks = $DB->get_records('block_instance', array('blockid'=>$blockid))) {
+ print_error('blockcannotread', '', '', $blockid);
}
// run through blocks and get (unique) courses
if ($courseid==0 || $block->pagetype != 'course-view') {
continue;
}
- if (!$course = get_record('course', 'id', $courseid)) {
+ if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid', '', '', $courseid);
}
$courses[$courseid] = $course;
// get list of courses containing modules if required
elseif (!empty($modulelist) and confirm_sesskey()) {
$modulename = $modulelist;
- if (!$modules = get_records($modulename)) {
+ if (!$modules = $DB->get_records($modulename)) {
print_error('invalidmodulename', '', '', $modulename);
}
if ($courseid==0) {
continue;
}
- if (!$course = get_record('course', 'id', $courseid)) {
+ if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid', '', '', $courseid);
}
$courses[$courseid] = $course;
$navlinks = array();
$navlinks[] = array('name' => $strcourses, 'link' => 'index.php', 'type' => 'misc');
$navlinks[] = array('name' => $strsearch, 'link' => 'search.php', 'type' => 'misc');
- $navlinks[] = array('name' => "'".s($search, true)."'", 'link' => null, 'type' => 'misc');
+ $navlinks[] = array('name' => "'".s($search)."'", 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("$site->fullname : $strsearchresults", $site->fullname, $navigation, "", "", "", $searchform);
print_heading("$strsearchresults: $totalcount");
- $encodedsearch = urlencode(stripslashes($search));
+ $encodedsearch = urlencode($search);
print_paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch&perpage=$perpage&",'page',($perpage == 99999));
if ($perpage != 99999 && $totalcount > $perpage) {
echo "<form id=\"movecourses\" action=\"search.php\" method=\"post\">\n";
echo "<div><input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
- echo "<input type=\"hidden\" name=\"search\" value=\"".s($search, true)."\" />\n";
+ echo "<input type=\"hidden\" name=\"search\" value=\"".s($search)."\" />\n";
echo "<input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
echo "<input type=\"hidden\" name=\"perpage\" value=\"$perpage\" /></div>\n";
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\" class=\"generalbox boxaligncenter\">\n<tr>\n";
} else {
if (!empty($search)) {
- print_heading(get_string("nocoursesfound", "", s($search, true)));
+ print_heading(get_string("nocoursesfound", "", s($search)));
}
else {
print_heading( $strnovalidcourses );
print_header("$course->shortname: $strunenrol", $course->fullname, $navigation);
if ($userid) {
- if (!$user = get_record('user', 'id', $userid)) {
+ if (!$user = $DB->get_record('user', array('id'=>$userid))) {
print_error('nousers');
}
$strunenrolsure = get_string('unenrolsure', '', fullname($user, true));
print_error('invalidcourseid', 'error');
}
- if (! $user = get_record("user", "id", $user)) {
+ if (! $user = $DB->get_record("user", array("id"=>$user))) {
print_error('invaliduserid', 'error');
}
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php';
- $course = get_record('course', 'id', required_param('id', PARAM_INT));
+ $course = $DB->get_record('course', array('id'=>required_param('id', PARAM_INT)));
$functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport';
if (function_exists($functionname)) {
$functionname($course, $user);
notify ($statsstatus);
}
- $earliestday = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_daily ORDER BY timeend');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_weekly ORDER BY timeend');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$CFG->prefix.'stats_user_monthly ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT timeend FROM {stats_user_daily} ORDER BY timeend');
+ $earliestweek = $DB_>get_field_sql('SELECT timeend FROM {stats_user_weekly} ORDER BY timeend');
+ $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {stats_user_monthly} ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
$time = array_pop(array_keys($timeoptions));
$param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
+ $params = $param->params;
$param->table = 'user_'.$param->table;
- $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE '
+ $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE '
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
- .' userid = '.$user->id
- .' AND timeend >= '.$param->timeafter
- .$param->extras
+ .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras
.' ORDER BY timeend DESC';
- $stats = get_records_sql($sql);
+ $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!!
if (empty($stats)) {
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
continue;
}
- $instance = get_record("$mod->modname", "id", "$mod->instance");
+ $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance));
$libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
if (file_exists($libfile)) {
}
if (!empty($name)) {
- if (! ($course = get_record('course', 'shortname', $name)) ) {
+ if (! ($course = $DB->get_record('course', array('shortname'=>$name)))) {
print_error('invalidcoursenameshort', 'error');
}
} else if (!empty($idnumber)) {
- if (! ($course = get_record('course', 'idnumber', $idnumber)) ) {
+ if (! ($course = $DB->get_record('course', array('idnumber'=>$idnumber)))) {
print_error('invalidcourseid', 'error');
}
} else {
- if (! ($course = get_record('course', 'id', $id)) ) {
+ if (! ($course = $DB->get_record('course', array('id'=>$id)))) {
print_error('invalidcourseid', 'error');
}
}
if (! $sections = get_all_sections($course->id)) { // No sections found
// Double-check to be extra sure
- if (! $section = get_record('course_sections', 'course', $course->id, 'section', 0)) {
+ if (! $section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>0))) {
$section->course = $course->id; // Create a default section.
$section->section = 0;
$section->visible = 1;
- $section->id = insert_record('course_sections', $section);
+ $section->id = $DB->insert_record('course_sections', $section);
}
if (! $sections = get_all_sections($course->id) ) { // Try again
print_error('cannotcreateorfindstructs', 'error');