]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards course conversion
authorskodak <skodak>
Mon, 2 Jun 2008 08:13:24 +0000 (08:13 +0000)
committerskodak <skodak>
Mon, 2 Jun 2008 08:13:24 +0000 (08:13 +0000)
13 files changed:
course/category.php
course/editcategory.php
course/info.php
course/lib.php
course/pending.php
course/recent.php
course/reset_form.php
course/rest.php
course/scales.php
course/search.php
course/unenrol.php
course/user.php
course/view.php

index ac7cd6b48047652d9a070e26028a1389458cfe98..1b1c7e4df0aa05dd3232267237baae00edbdfda2 100644 (file)
@@ -37,7 +37,7 @@
         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
index cb308f4f7f58474cb83d6f76615d87de10d36b16..e699ea9b3d780aa61d62f49c5e5cdec5c74f820b 100644 (file)
@@ -32,7 +32,7 @@ if ($categoryadd) { // Show Add category form: if $id is given, it is used as th
 } 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");
     }
 }
@@ -128,7 +128,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
     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();
@@ -209,7 +209,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
             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
@@ -219,10 +219,10 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
         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) {
@@ -242,19 +242,19 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
             // 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
@@ -273,7 +273,7 @@ if ($id && !$categoryadd && !$categoryupdate && false) {
     } // 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)) {
index b810806ee0b6b0f3acdb03c44d80ca76bcacdc1a..92b40c9b14ef646f2589e6d3985789ea48cdbf18 100644 (file)
@@ -19,7 +19,7 @@
             print_error("invalidshortname");
         }
     } else {
-        if (!$course = get_record("course", array("id"=>$id))) {
+        if (!$course = $DB->get_record("course", array("id"=>$id))) {
             print_error("invalidcourseid");
         }
     }
@@ -61,7 +61,7 @@
     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)) {
index ff393bdd3b9e71c731370fce2884bdcad39c91ae..8756df8f73748b2915b316d26835114f3d9a6454 100644 (file)
@@ -414,7 +414,7 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC",
         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)) {
@@ -511,7 +511,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
         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)) {
@@ -781,10 +781,10 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
 
 
 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');
index 6d6fcf352a66583b21d685b73139f2040bb3c83b..387f0b32fe44c45c2a371df076f6c571e6b5b07c 100644 (file)
@@ -15,7 +15,7 @@
     $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;
             }
@@ -45,7 +45,7 @@
             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;
@@ -80,7 +80,7 @@
     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;
             }
index 086e9dceaba8a0cca22644f56918516599475b47..a9ce454b2f766200e2a21036403ae29101719ce8 100644 (file)
@@ -8,7 +8,7 @@
 
     $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");
     }
 
@@ -45,7 +45,7 @@
     $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;
         }
index 37b47c077412e6e68b41b46d035bd6b9f277c222..1053e700a9da87d12ba4b92f1cb1a4b861f9ca67 100644 (file)
@@ -3,7 +3,7 @@ require_once $CFG->libdir.'/formslib.php';
 
 class course_reset_form extends moodleform {
     function definition (){
-        global $CFG, $COURSE;
+        global $CFG, $COURSE, $DB;
 
         $mform =& $this->_form;
 
@@ -49,7 +49,7 @@ class course_reset_form extends moodleform {
         }
 
         $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)) {
@@ -91,7 +91,7 @@ class course_reset_form extends moodleform {
     }
 
     function load_defaults() {
-        global $CFG, $COURSE;
+        global $CFG, $COURSE, $DB;
 
         $mform =& $this->_form;
 
@@ -103,7 +103,7 @@ class course_reset_form extends moodleform {
             $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";
index 302ff15142b67253acbad15ca53805322dd0e724..76abd0c03eea617951cc6bcd921bbdc40b394e44 100644 (file)
@@ -23,7 +23,7 @@ $visible    = optional_param('visible', 0, PARAM_INT);
 
 
 // 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;
 }
@@ -69,7 +69,7 @@ switch($_SERVER['REQUEST_METHOD']) {
 
             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;
                 }
@@ -87,7 +87,7 @@ switch($_SERVER['REQUEST_METHOD']) {
                 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;
                 }
@@ -113,13 +113,13 @@ switch($_SERVER['REQUEST_METHOD']) {
                         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;
                         }
@@ -140,7 +140,7 @@ switch($_SERVER['REQUEST_METHOD']) {
                         $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;
                         }
@@ -157,11 +157,11 @@ switch($_SERVER['REQUEST_METHOD']) {
                 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;
                 }
index 6b5d1586722d1b532eb4d1f67f1fed28518c86a8..88d517bb239f75f73ed151f9bfd61c0789f36b3b 100644 (file)
@@ -28,7 +28,7 @@
 
     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)) {
@@ -58,7 +58,7 @@
         }
     }
 
-    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);
index e09d78b1dd36f3e1e724f6817c1a5df69ad1561e..5c551cacebcb14fb71e66aa8b4fe193a2bfce4c2 100644 (file)
 
         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&amp;perpage=$perpage&amp;",'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 );
index 6a81254e89abdb02bb392e4ecdb730fd028b376c..cc465a4e800f4547e801722ceb68c7831a965980 100644 (file)
@@ -90,7 +90,7 @@
     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));
index 39162fbb8e83ce742042b14da09327acb69a7d04..5519ce87ecae18814b1a7c1864a9bfb8584ea123 100644 (file)
@@ -17,7 +17,7 @@
         print_error('invalidcourseid', 'error');
     }
 
-    if (! $user = get_record("user", "id", $user)) {
+    if (! $user = $DB->get_record("user", array("id"=>$user))) {
         print_error('invaliduserid', 'error');
     }
 
@@ -77,7 +77,7 @@
             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)) {
index 5fc275c5f20f7cb3612d4bedf698a92b2263b949..8d66fc82a171a6c9c89f5056831c80002a85c10e 100644 (file)
     }
 
     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');