]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards /user conversion
authorskodak <skodak>
Sat, 31 May 2008 11:13:21 +0000 (11:13 +0000)
committerskodak <skodak>
Sat, 31 May 2008 11:13:21 +0000 (11:13 +0000)
lib/dml/oci8po_adodb_moodle_recordset.php
user/addnote.php
user/extendenrol.php
user/groupaddnote.php
user/groupextendenrol.php
user/index.php
user/messageselect.php
user/tabs.php
user/view.php

index 7e9769584a41b8a9f60f48a577895a7a59a670ac..5e56dfca321cb0b7d7d08f381acf30ff5c580370 100644 (file)
@@ -30,6 +30,8 @@ class oci8po_adodb_moodle_recordset extends adodb_moodle_recordset {
     }
 
     public function rewind() {
+        //TODO - this does not work in Oracle :-(
+        error('Implement rewind in oracle by doing query again');
         $this->rs->MoveFirst();
     }
 
index 56fafed8485c2b82119ab4e3b33b91d0e3a70fc9..fce7e91e49ae382a6b118dab0561982048ff8133 100644 (file)
@@ -6,7 +6,7 @@ $id    = required_param('id', PARAM_INT);              // course id
 $users = optional_param('userid', array(), PARAM_INT); // array of user id
 $contents = optional_param('contents', array(), PARAM_RAW); // array of user notes
 $states = optional_param('states', array(), PARAM_ALPHA); // array of notes states
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
     print_error("Course ID is incorrect");
 }
 
@@ -25,7 +25,7 @@ if (!empty($users) && confirm_sesskey()) {
     $note->courseid = $id;
     $note->format = FORMAT_PLAIN;
     foreach ($users as $k => $v) {
-        if(!$user = get_record('user', 'id', $v) || empty($contents[$k])) {
+        if(!$user = $DB->get_record('user', array('id'=>$v)) || empty($contents[$k])) {
             continue;
         }
         $note->id = 0;
@@ -74,7 +74,7 @@ if (empty($users)) {
 }
 
 foreach ($users as $k => $v) {
-    if(!$user = get_record('user', 'id', $v)) {
+    if(!$user = $DB->get_record('user', array('id'=>$v))) {
         continue;
     }
     $checkbox = choose_from_menu($state_names, 'states[' . $k . ']', empty($states[$k]) ? NOTES_STATE_PUBLIC : $states[$k], '', '', '0', true);
index 1054766ac3e5e843e0c982c41631b0679ff39894..a84f13a9a757013fd4d537e084dbcc5942600781 100644 (file)
@@ -4,7 +4,7 @@ require_once("../config.php");
 $id    = required_param('id', PARAM_INT);              // course id
 $users = optional_param('userid', array(), PARAM_INT); // array of user id
 
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
     print_error("Course ID is incorrect");
 }
 
@@ -22,10 +22,10 @@ if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
 
     foreach ($form->userid as $k => $v) {
         // find all roles this student have in this course
-        if ($students = get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
-                                       FROM {$CFG->prefix}role_assignments ra
-                                       WHERE userid = $v
-                                       AND contextid = $context->id")) {
+        if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
+                                                FROM {role_assignments} ra
+                                               WHERE userid = ?
+                                                     AND contextid = ?", array($v, $context->id))) {
             // enrol these users again, with time extension
             // not that this is not necessarily a student role
             foreach ($students as $student) {
@@ -124,9 +124,10 @@ $notavailable = get_string('notavailable');
 foreach ($_POST as $k => $v) {
     if (preg_match('/^user(\d+)$/',$k,$m)) {
 
-        if (!($user = get_record_sql("SELECT * FROM {$CFG->prefix}user u
-                                    INNER JOIN {$CFG->prefix}role_assignments ra ON u.id=ra.userid
-                                    WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) {
+        if (!($user = $DB->get_record_sql("SELECT *
+                                             FROM {user} u
+                                             JOIN {role_assignments} ra ON u.id=ra.userid
+                                            WHERE u.id=? AND ra.contextid = ?", array($m[1], $context->id)))) {
             continue;
         }
         $userbasemenu = $basemenu;
index faaa4d90b75d5b69cbe82da646b61f9534b42abc..0deff44691fbfae6e4fa8cc9f7d2ebaa571a1ed7 100644 (file)
@@ -7,7 +7,7 @@ $users = optional_param('userid', array(), PARAM_INT); // array of user id
 $content = optional_param('content', '', PARAM_RAW); // note content
 $state = optional_param('state', '', PARAM_ALPHA); // note publish state
 
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
     print_error("Course ID is incorrect");
 }
 
@@ -24,7 +24,7 @@ if (!empty($users) && !empty($content) && confirm_sesskey()) {
     $note->content = $content;
     $note->publishstate = $state;
     foreach ($users as $k => $v) {
-        if(!$user = get_record('user', 'id', $v)) {
+        if(!$user = $DB->get_record('user', array('id'=>$v))) {
             continue;
         }
         $note->id = 0;
@@ -69,7 +69,7 @@ $strpublishstate = get_string('publishstate', 'notes');
 
 $userlist = array();
 foreach ($users as $k => $v) {
-    if(!$user = get_record('user', 'id', $v)) {
+    if (!$user = $DB->get_record('user', array('id'=>$v))) {
         continue;
     }
     echo '<input type="hidden" name="userid['.$k.']" value="'.$v.'" />';
index 76a28133990786197ce3d9222539d13ed95209be..de0897c5a7bf6087b0b5575b081f6937c56814e4 100755 (executable)
@@ -4,7 +4,7 @@ require_once("../config.php");
 $id    = required_param('id', PARAM_INT);              // course id
 $users = optional_param('userid', array(), PARAM_INT); // array of user id
 
-if (! $course = get_record('course', 'id', $id)) {
+if (! $course = $DB->get_record('course', array('id'=>$id))) {
     print_error("Course ID is incorrect");
 }
 
@@ -20,10 +20,10 @@ if ((count($users) > 0) and ($form = data_submitted()) and confirm_sesskey()) {
 
     foreach ($form->userid as $k => $v) {
         // find all roles this student have in this course
-        if ($students = get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
-                                       FROM {$CFG->prefix}role_assignments ra
-                                       WHERE userid = $v
-                                       AND contextid = $context->id")) {
+        if ($students = $DB->get_records_sql("SELECT ra.id, ra.roleid, ra.timestart, ra.timeend
+                                                FROM {role_assignments} ra
+                                               WHERE userid = ?
+                                                     AND contextid = ?", array($v, $context->id))) {
             // enrol these users again, with time extension
             // not that this is not necessarily a student role
             foreach ($students as $student) {
@@ -122,9 +122,10 @@ $notavailable = get_string('notavailable');
 foreach ($_POST as $k => $v) {
     if (preg_match('/^user(\d+)$/',$k,$m)) {
 
-        if (!($user = get_record_sql("SELECT * FROM {$CFG->prefix}user u
-                                    INNER JOIN {$CFG->prefix}role_assignments ra ON u.id=ra.userid
-                                    WHERE u.id={$m[1]} AND ra.contextid = $context->id"))) {
+        if (!($user = $DB->get_record_sql("SELECT *
+                                             FROM {user} u
+                                             JOIN {role_assignments} ra ON u.id=ra.userid
+                                    WHERE u.id=? AND ra.contextid = ?", array($m[1], $context->id)))) {
             continue;
         }
         if ($user->timestart) {
index 0c31b1d5ceac8c8c13f774962650009b0a4738f4..229f31c846107ebbfe65e6b8ad403b862eb860e2 100644 (file)
         if (! $context = get_context_instance_by_id($contextid)) {
             error("Context ID is incorrect");
         }
-        if (! $course = get_record('course', 'id', $context->instanceid)) {
+        if (! $course = $DB->get_record('course', array('id'=>$context->instanceid))) {
             error("Course ID is incorrect");
         }
     } else {
-        if (! $course = get_record('course', 'id', $courseid)) {
+        if (! $course = $DB->get_record('course', array('id'=>$courseid))) {
             error("Course ID is incorrect");
         }
         if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
     // get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
     // we need to make it diferently for normal courses and site course
     if ($context->id != $frontpagectx->id) {
-        $minlastaccess = get_field_sql('SELECT min(timeaccess)
-                                          FROM '.$CFG->prefix.'user_lastaccess
-                                         WHERE courseid = '.$course->id.'
-                                           AND timeaccess != 0');
-        $lastaccess0exists = record_exists('user_lastaccess', 'courseid', $course->id, 'timeaccess', 0);
+        $minlastaccess = $DB->get_field_sql('SELECT min(timeaccess)
+                                               FROM {user_lastaccess}
+                                              WHERE courseid = ?
+                                                    AND timeaccess != 0', array($course->id));
+        $lastaccess0exists = $DB->record_exists('user_lastaccess', array('courseid'=>$course->id, 'timeaccess'=>0));
     } else {
-        $minlastaccess = get_field_sql('SELECT min(lastaccess)
-                                          FROM '.$CFG->prefix.'user
-                                         WHERE lastaccess != 0');
-        $lastaccess0exists = record_exists('user','lastaccess',0);
+        $minlastaccess = $DB->get_field_sql('SELECT min(lastaccess)
+                                               FROM {user}
+                                              WHERE lastaccess != 0');
+        $lastaccess0exists = $DB->record_exists('user', array('lastaccess'=>0));
     }
 
     $now = usergetmidnight(time());
                 ));
     $table->setup();
 
-
+    $params = array();
     // we are looking for all users with this role assigned in this context or higher
     if ($usercontexts = get_parent_contexts($context)) {
         $listofcontexts = '('.implode(',', $usercontexts).')';
         $listofcontexts = '('.$sitecontext->id.')'; // must be site
     }
     if ($roleid > 0) {
-        $selectrole = " AND r.roleid = $roleid ";
+        $selectrole = " AND r.roleid = :roleid ";
+        $params['roleid'] = $roleid;
     } else {
         $selectrole = " ";
     }
     }
 
     if ($context->id != $frontpagectx->id or $roleid >= 0) {
-        $from   = "FROM {$CFG->prefix}user u
-                LEFT OUTER JOIN {$CFG->prefix}context ctx
-                    ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
-                JOIN {$CFG->prefix}role_assignments r
-                    ON u.id=r.userid
-                LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul
-                    ON (r.userid=ul.userid and ul.courseid = $course->id) ";
+        $from   = "FROM {user} u
+                   LEFT OUTER JOIN {context} ctx
+                        ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.")
+                   JOIN {role_assignments} r
+                        ON u.id=r.userid
+                   LEFT OUTER JOIN {user_lastaccess} ul
+                        ON (r.userid=ul.userid and ul.courseid = :courseid) ";
+        $params['courseid'] = $course->id;
     } else {
         // on frontpage and we want all registered users
-        $from = "FROM {$CFG->prefix}user u
-                LEFT OUTER JOIN {$CFG->prefix}context ctx
-                    ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
+        $from = "FROM {user} u
+                 LEFT OUTER JOIN {context} ctx
+                      ON (u.id=ctx.instanceid AND ctx.contextlevel = ".CONTEXT_USER.") ";
     }
 
     $hiddensql = has_capability('moodle/role:viewhiddenassigns', $context)? '':' AND r.hidden = 0 ';
 
     if ($context->id != $frontpagectx->id) {
         $where  = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
-            AND u.deleted = 0 $selectrole
-            AND (ul.courseid = $course->id OR ul.courseid IS NULL)
-            AND u.username != 'guest'
-            $adminroles
-            $hiddensql ";
+                         AND u.deleted = 0 $selectrole
+                         AND (ul.courseid = $course->id OR ul.courseid IS NULL)
+                         AND u.username != 'guest'
+                         $adminroles
+                         $hiddensql ";
             $where .= get_course_lastaccess_sql($accesssince);
     } else {
         if ($roleid >= 0) {
             $where = "WHERE (r.contextid = $context->id OR r.contextid in $listofcontexts)
-                AND u.deleted = 0 $selectrole
-                AND u.username != 'guest'";
-                $where .= get_user_lastaccess_sql($accesssince);
+                      AND u.deleted = 0 $selectrole
+                      AND u.username != 'guest'";
+            $where .= get_user_lastaccess_sql($accesssince);
         } else {
             $where = "WHERE u.deleted = 0
                 AND u.username != 'guest'";
     $wheresearch = '';
 
     if (!empty($search)) {
-        $LIKE = sql_ilike();
-        $fullname  = sql_fullname('u.firstname','u.lastname');
-        $wheresearch .= ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
-
+        $LIKE = $DB->sql_ilike();
+        $fullname = $DB->sql_fullname('u.firstname','u.lastname');
+        $wheresearch .= " AND ($fullname $LIKE :search1 OR email $LIKE :search2 OR idnumber $LIKE :search3) ";
+        $params['search1'] = "%$search%";
+        $params['search2'] = "%$search%";
+        $params['search3'] = "%$search%";
     }
 
     if ($currentgroup) {    // Displaying a group by choice
         // FIX: TODO: This will not work if $currentgroup == 0, i.e. "those not in a group"
-        $from  .= 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid ';
-        $where .= ' AND gm.groupid = '.$currentgroup;
+        $from  .= 'LEFT JOIN {groups_members} gm ON u.id = gm.userid ';
+        $where .= ' AND gm.groupid = :currentgroup';
+        $params['curentgroup'] = $currentgroup;
     }
 
-    $totalcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where);   // Each user could have > 1 role
+    $totalcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where", $params);   // Each user could have > 1 role
 
     if ($table->get_sql_where()) {
         $where .= ' AND '.$table->get_sql_where();
         }
     }
 
-    $matchcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where.$wheresearch);
+    $matchcount = $DB->count_records_sql("SELECT COUNT(distinct u.id) $from $where $wheresearch", $params);
 
     $table->initialbars(true);
     $table->pagesize($perpage, $matchcount);
 
-    $userlist = get_recordset_sql($select.$from.$where.$wheresearch.$sort,
+    $userlist = $DB->get_recordset_sql("$select $from $where $wheresearch $sort", $params,
             $table->get_page_start(),  $table->get_page_size());
 
     //
     if ($mode===MODE_ENROLDETAILS) {
         $userids = array();
 
-        while ($user = rs_fetch_next_record($userlist)) {
+        foreach ($userlist as $user) {
             $userids[] = $user->id;
         }
         $userlist_extra = get_participants_extra($userids, $avoidroles, $course, $context);
 
         // Only Oracle cannot seek backwards
         // and must re-query...
-        if ($userlist->canSeek === true) {
-            $userlist->MoveFirst();
-        } else {
-            $userlist = get_recordset_sql($select.$from.$where.$wheresearch.$sort,
-                                          $table->get_page_start(),  $table->get_page_size());
-        }
+        $userlist->rewind();
     }
 
     if ($context->id == $frontpagectx->id) {
         $strallsiteusers = get_string('allsiteusers', 'role');
         if ($CFG->defaultfrontpageroleid) {
-            if ($fprole = get_record('role', 'id', $CFG->defaultfrontpageroleid)) {
+            if ($fprole = $DB->get_record('role', array('id'=>$CFG->defaultfrontpageroleid))) {
                 $fprole = role_get_name($fprole, $frontpagectx);
                 $strallsiteusers = "$strallsiteusers ($fprole)";
             }
     }
 
     if ($roleid > 0) {
-        if (!$currentrole = get_record('role','id',$roleid)) {
+        if (!$currentrole = $DB->get_record('role', array('id'=>$roleid))) {
             error('That role does not exist');
         }
         $a->number = $totalcount;
 
             if ($matchcount > 0) {
                 $usersprinted = array();
-                while ($user = rs_fetch_next_record($userlist)) {
+                foreach ($userlist as $user) {
                     if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
                         continue;
                     }
             }
 
             $usersprinted = array();
-            while ($user = rs_fetch_next_record($userlist)) {
+            foreach ($userlist as $user) {
                 if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935
                     continue;
                 }
     print_footer($course);
 
     if ($userlist) {
-        rs_close($userlist);
+        $userlist->close();
     }
 
 
@@ -925,13 +925,14 @@ function get_user_lastaccess_sql($accesssince='') {
 }
 
 function get_participants_extra ($userids, $avoidroles, $course, $context) {
-
-    global $CFG;
+    global $CFG, $DB;
 
     if (count($userids) === 0 || count($avoidroles) === 0) {
         return array();
     }
 
+    $params = array();
+
     $userids = implode(',', $userids);
 
     // turn the path into a list of context ids
@@ -946,10 +947,10 @@ function get_participants_extra ($userids, $avoidroles, $course, $context) {
     }
 
     if (!empty($CFG->enablegroupings)) {
-        $gpjoin = "LEFT OUTER JOIN {$CFG->prefix}groupings_groups gpg
-                     ON gpg.groupid=g.id
-                   LEFT OUTER JOIN {$CFG->prefix}groupings gp
-                     ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
+        $gpjoin = "LEFT OUTER JOIN {groupings_groups} gpg
+                        ON gpg.groupid=g.id
+                   LEFT OUTER JOIN {groupings} gp
+                        ON (gp.courseid={$course->id} AND gp.id=gpg.groupingid)";
         $gpselect = ',gp.id AS gpid, gp.name AS gpname ';
     } else {
         $gpjoin   = '';
@@ -967,27 +968,27 @@ function get_participants_extra ($userids, $avoidroles, $course, $context) {
                    ra.enrol AS enrolplugin,
                    g.id     AS gid, g.name AS gname
                    $gpselect
-            FROM {$CFG->prefix}role_assignments ra
-            JOIN {$CFG->prefix}context ctx
-              ON (ra.contextid=ctx.id)
-            LEFT OUTER JOIN {$CFG->prefix}course_categories cc
-              ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
+              FROM {role_assignments} ra
+              JOIN {context} ctx
+                   ON (ra.contextid=ctx.id)
+              LEFT JOIN {course_categories} cc
+                   ON (ctx.contextlevel=40 AND ctx.instanceid=cc.id)
 
             /* only if groups active */
-            LEFT OUTER JOIN {$CFG->prefix}groups_members gm
-              ON (ra.userid=gm.userid)
-            LEFT OUTER JOIN {$CFG->prefix}groups g
-              ON (gm.groupid=g.id AND g.courseid={$course->id})
+              LEFT JOIN {groups_members} gm
+                   ON (ra.userid=gm.userid)
+              LEFT JOIN {groups} g
+                   ON (gm.groupid=g.id AND g.courseid={$course->id})
             /* and if groupings is enabled... */
             $gpjoin
 
-            WHERE ra.userid IN ( $userids ) 
-                  AND ra.contextid in ( $contextids ) 
-                  $avoidrolescond
+             WHERE ra.userid IN ( $userids ) 
+                   AND ra.contextid in ( $contextids ) 
+                   $avoidrolescond
 
-            ORDER BY ra.userid, ctx.depth DESC";
+          ORDER BY ra.userid, ctx.depth DESC";
 
-    $rs = get_recordset_sql($sql);
+    $rs = $DB->get_recordset_sql($sql, $params);
     $extra = array();
 
     // Data structure -
@@ -1005,7 +1006,7 @@ function get_participants_extra ($userids, $avoidroles, $course, $context) {
     // and modifierid (with an outer join to mdl_user!
     //
 
-    while ($rec = rs_fetch_next_record($rs)) {
+    foreach ($rs as $rec) {
         $userid = $rec->userid;
 
         // Prime an initial user rec...
@@ -1032,6 +1033,7 @@ function get_participants_extra ($userids, $avoidroles, $course, $context) {
 
         }
     }
+    $rs->close();
     return $extra;
 
 }
index e023a4304eb5967ad647747c5bcef8a7cd25b3ea..492e3bd4092f2b65a60489994c73a1d86aec5d60 100644 (file)
@@ -12,7 +12,7 @@
     $format = optional_param('format',FORMAT_MOODLE,PARAM_INT);
     $deluser = optional_param('deluser',0,PARAM_INT);
 
-    if (!$course = get_record('course','id',$id)) {
+    if (!$course = $DB->get_record('course', array('id'=>$id))) {
         print_error("Invalid course id");
     }
 
@@ -46,7 +46,7 @@
     foreach ($_POST as $k => $v) {
         if (preg_match('/^(user|teacher)(\d+)$/',$k,$m)) {
             if (!array_key_exists($m[2],$SESSION->emailto[$id])) {
-                if ($user = get_record_select('user','id = '.$m[2],'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
+                if ($user = $DB->get_record_select('user', "id = ?", array($m[2]), 'id,firstname,lastname,idnumber,email,emailstop,mailformat,lastaccess')) {
                     $SESSION->emailto[$id][$m[2]] = $user;
                     $SESSION->emailto[$id][$m[2]]->teacher = ($m[1] == 'teacher');
                     $count++;
@@ -79,7 +79,7 @@
 
     if ($count) {
         if ($count == 1) {
-            $heading =  get_string('addedrecip','moodle',$count);
+            $heading = get_string('addedrecip','moodle',$count);
         } else {
             $heading = get_string('addedrecips','moodle',$count);
         }
index fd729e6bce05631da0b87a4cdfff10425f293e31..1b6062bbd8ef3d41fec32f35b5676eb7d5669f68 100644 (file)
@@ -18,7 +18,7 @@
     }
 
     if (($filtertype == 'site' && $filterselect) || ($filtertype=='user' && $filterselect)) {
-        $user = get_record('user','id',$filterselect);
+        $user = $DB->get_record('user', array('id'=>$filterselect));
     }
 
     $inactive = NULL;
@@ -48,7 +48,7 @@
      **************************************/
     } else if ($filtertype == 'course' && $filterselect) {
 
-        $course = get_record('course','id',$filterselect);
+        $course = $DB->get_record('course', array('id'=>$filterselect));
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
         print_heading(format_string($course->fullname));
 
@@ -85,7 +85,7 @@
      **************************************/
     } else {
         if (isset($userid)) {
-            $user = get_record('user','id', $userid);
+            $user = $DB->get_record('user', array('id'=>$userid));
         }
         print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
 
index c42633307fc712fc9dbfb33ef37c1783116e4f33..875efa786de9ba91a3d468dae07607cd8cb46637 100644 (file)
         $id = $USER->id;
     }
 
-    if (! $user = get_record("user", "id", $id) ) {
+    if (! $user = $DB->get_record("user", array("id"=>$id))) {
         print_error("No such user in this course");
     }
 
-    if (! $course = get_record("course", "id", $course) ) {
+    if (! $course = $DB->get_record("course", array("id"=>$course))) {
         print_error("No such course id");
     }
 
@@ -42,7 +42,7 @@
 
     if (!empty($CFG->forcelogin) || $course->id != SITEID) {
         // do not force parents to enrol
-        if (!get_record('role_assignments', 'userid', $USER->id, 'contextid', $usercontext->id)) {
+        if (!$DB->get_record('role_assignments', array('userid'=>$USER->id, 'contextid'=>$usercontext->id))) {
             require_login($course->id);
         }
     }
 
     if ($course->id != SITEID) {
         $user->lastaccess = false;
-        if ($lastaccess = get_record('user_lastaccess', 'userid', $user->id, 'courseid', $course->id)) {
+        if ($lastaccess = $DB->get_record('user_lastaccess', array('userid'=>$user->id, 'courseid'=>$course->id))) {
             $user->lastaccess = $lastaccess->timeaccess;
         }
     }
 
     if (is_mnet_remote_user($user)) {
         $sql = "
-             SELECT DISTINCT
-                 h.id,
-                 h.name,
-                 h.wwwroot,
-                 a.name as application,
-                 a.display_name
-             FROM
-                 {$CFG->prefix}mnet_host h,
-                 {$CFG->prefix}mnet_application a
-             WHERE
-                 h.id = '{$user->mnethostid}' AND
-                 h.applicationid = a.id
-             ORDER BY
-                 a.display_name,
-                 h.name";
-
-        $remotehost = get_record_sql($sql);
+             SELECT DISTINCT h.id, h.name, h.wwwroot,
+                             a.name as application, a.display_name
+               FROM {mnet_host} h, {mnet_application} a
+              WHERE h.id = ? AND h.applicationid = a.id
+           ORDER BY a.display_name, h.name";
+
+        $remotehost = $DB->get_record_sql($sql, array($user->mnethostid));
 
         echo '<p class="errorboxcontent">'.get_string('remote'.$remotehost->application.'user')." <br />\n";
         if ($USER->id == $user->id) {