]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards /user conversion
authorskodak <skodak>
Fri, 30 May 2008 22:11:31 +0000 (22:11 +0000)
committerskodak <skodak>
Fri, 30 May 2008 22:11:31 +0000 (22:11 +0000)
19 files changed:
admin/uploaduser.php
auth/email/auth.php
auth/ldap/auth.php
lib/adminlib.php
lib/authlib.php
login/signup.php
user/edit.php
user/edit_form.php
user/editadvanced.php
user/editadvanced_form.php
user/filters/courserole.php
user/filters/lib.php
user/filters/profilefield.php
user/profile/definelib.php
user/profile/index.php
user/profile/index_category_form.php
user/profile/lib.php
userpix/index.php
userpix/upgrade.php

index 4511b81e8e75f9ed06b9b56542d01119dc59bded..ba81acf10ec693999dc958aa9cb2cc036dea06e6 100755 (executable)
@@ -483,7 +483,7 @@ if ($formdata = $mform->is_cancelled()) {
                     continue;
                 }
                 // save custom profile fields data from csv file
-                profile_save_data(addslashes_recursive($existinguser));
+                profile_save_data($existinguser);
             }
 
             if ($bulk == 2 or $bulk == 3) {
index 602336ba8b9e79dd2adc11decc74c40e717d4ccc..8109d6c81d0ef4e04929fcf3f9911b66b9f23da6 100644 (file)
@@ -70,16 +70,16 @@ class auth_plugin_email extends auth_plugin_base {
      * Sign up a new user ready for confirmation.
      * Password is passed in plaintext.
      *
-     * @param object $user new user object (with system magic quotes)
+     * @param object $user new user object
      * @param boolean $notify print notice with link and terminate
      */
     function user_signup($user, $notify=true) {
-        global $CFG;
+        global $CFG, $DB;
         require_once($CFG->dirroot.'/user/profile/lib.php');
         
         $user->password = hash_internal_user_password($user->password);
 
-        if (! ($user->id = insert_record('user', $user)) ) {
+        if (! ($user->id = $DB->insert_record('user', $user)) ) {
             print_error('auth_emailnoinsert','auth');
         }
         
index 22bb9ec39e30af9ad948407016023fa86428065d..77d01971d075b4d9802cbf9fc30e8ec9accc4c4d 100644 (file)
@@ -375,7 +375,7 @@ class auth_plugin_ldap extends auth_plugin_base {
      * Sign up a new user ready for confirmation.
      * Password is passed in plaintext.
      *
-     * @param object $user new user object (with system magic quotes)
+     * @param object $user new user object
      * @param boolean $notify print notice with link and terminate
      */
     function user_signup($user, $notify=true) {
@@ -393,7 +393,7 @@ class auth_plugin_ldap extends auth_plugin_base {
             print_error('auth_ldap_create_error', 'auth');
         }
 
-        if (! ($user->id = insert_record('user', $user)) ) {
+        if (! ($user->id = $DB->insert_record('user', $user)) ) {
             print_error('auth_emailnoinsert', 'auth');
         }
 
index 670c549d37aabf4207965cc4dfa5199dcc49f1d8..690b9305daf1b449bb77f53688560d52f328ec49 100644 (file)
@@ -4173,14 +4173,14 @@ function admin_apply_default_settings($node=NULL, $unconditional=true) {
 
 /**
  * Store changed settings, this function updates the errors variable in $ADMIN
- * @param object $formdata from form (without magic quotes)
+ * @param object $formdata from form
  * @return int number of changed settings
  */
 function admin_write_settings($formdata) {
     global $CFG, $SITE, $COURSE, $DB;
 
     $olddbsessions = !empty($CFG->dbsessions);
-    $formdata = (array)stripslashes_recursive($formdata);
+    $formdata = (array)$formdata;
 
     $data = array();
     foreach ($formdata as $fullname=>$value) {
index 5521dbe5ef33c9bfda9b5c57ce790646031fc919..d076646d701915193475b3918f6300c14b526e38 100644 (file)
@@ -194,7 +194,7 @@ class auth_plugin_base {
      * Sign up a new user ready for confirmation.
      * Password is passed in plaintext.
      *
-     * @param object $user new user object (with system magic quotes)
+     * @param object $user new user object
      * @param boolean $notify print notice with link and terminate
      */
     function user_signup($user, $notify=true) {
index a3e6e2fcbe54e47d8ccbfff73a4ed3b00b96a137..26f5d3a2ca0de9caf3d2ba4be2bbe5cc73c13487 100644 (file)
@@ -31,7 +31,7 @@
     if ($mform_signup->is_cancelled()) {
         redirect($CFG->httpswwwroot.'/login/index.php');
 
-    } else if ($user = $mform_signup->get_data()) {
+    } else if ($user = $mform_signup->get_data(false)) {
         $user->confirmed   = 0;
         $user->lang        = current_language();
         $user->firstaccess = time();
index d237145aff78f9dbfca477163e4cb772793ae1e7..f0f3df6663d5a08694db033e7c67ae2dca7e0caf 100644 (file)
@@ -11,7 +11,7 @@
     $userid = optional_param('id', $USER->id, PARAM_INT);    // user id
     $course = optional_param('course', SITEID, PARAM_INT);   // course id (defaults to Site)
 
-    if (!$course = get_record('course', 'id', $course)) {
+    if (!$course = $DB->get_record('course', array('id'=>$course))) {
         print_error('Course ID was incorrect');
     }
 
@@ -30,7 +30,7 @@
     }
 
     // The user profile we are editing
-    if (!$user = get_record('user', 'id', $userid)) {
+    if (!$user = $DB->get_record('user', array('id'=>$userid))) {
         print_error('User ID was incorrect');
     }
 
@@ -89,7 +89,7 @@
     $userform = new user_edit_form();
     $userform->set_data($user);
 
-    if ($usernew = $userform->get_data()) {
+    if ($usernew = $userform->get_data(false)) {
 
         add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
 
 
         $usernew->timemodified = time();
 
-        if (!update_record('user', $usernew)) {
+        if (!$DB->update_record('user', $usernew)) {
             print_error('Error updating user record');
         }
 
         // pass a true $userold here
         if (! $authplugin->user_update($user, $userform->get_data(false))) {
             // auth update failed, rollback for moodle
-            update_record('user', addslashes_object($user));
+            $DB->update_record('user', $user);
             print_error('Failed to update user data on external auth: '.$user->auth.
                     '. See the server logs for more details.');
         }
 
         if ($USER->id == $user->id) {
             // Override old $USER session variable if needed
-            $usernew = (array)get_record('user', 'id', $user->id); // reload from db
+            $usernew = $DB->get_record('user', array('id'=>$user->id)); // reload from db
             foreach ($usernew as $variable => $value) {
                 $USER->$variable = $value;
             }
index 9f96fd902aebadfae40a24f404d590dbc82e4edb..0f08437d0f978aacbaad6678cbaefa916c15c0a5 100644 (file)
@@ -39,7 +39,7 @@ class user_edit_form extends moodleform {
     }
 
     function definition_after_data() {
-        global $CFG;
+        global $CFG, $DB;
 
         $mform =& $this->_form;
         $userid = $mform->getElementValue('id');
@@ -54,7 +54,7 @@ class user_edit_form extends moodleform {
             }
         }
 
-        if ($user = get_record('user', 'id', $userid)) {
+        if ($user = $DB->get_record('user', array('id'=>$userid))) {
 
             // print picture
             if (!empty($CFG->gdversion)) {
@@ -92,17 +92,17 @@ class user_edit_form extends moodleform {
     }
 
     function validation($usernew, $files) {
-        global $CFG;
+        global $CFG, $DB;
 
         $errors = parent::validation($usernew, $files);
 
         $usernew = (object)$usernew;
-        $user    = get_record('user', 'id', $usernew->id);
+        $user    = $DB->get_record('user', array('id'=>$usernew->id));
 
         // validate email
         if (!validate_email($usernew->email)) {
             $errors['email'] = get_string('invalidemail');
-        } else if (($usernew->email !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
+        } else if (($usernew->email !== $user->email) and $DB->record_exists('user', array('email'=>$usernew->email, 'mnethostid'=>$CFG->mnet_localhost_id))) {
             $errors['email'] = get_string('emailexists');
         }
 
index 3be1401a805d234f96c2ceaffaef42126c1a3978..2fa03183d832af6b13492c35d67b0c2dbe32201a 100644 (file)
@@ -12,7 +12,7 @@
     $id     = optional_param('id', $USER->id, PARAM_INT);    // user id; -1 if creating new user
     $course = optional_param('course', SITEID, PARAM_INT);   // course id (defaults to Site)
 
-    if (!$course = get_record('course', 'id', $course)) {
+    if (!$course = $DB->get_record('course', array('id'=>$course))) {
         print_error('Course ID was incorrect');
     }
     require_login($course->id);
@@ -34,7 +34,7 @@
     } else {
         // editing existing user
         require_capability('moodle/user:update', $systemcontext);
-        if (!$user = get_record('user', 'id', $id)) {
+        if (!$user = $DB->get_record('user', array('id'=>$id))) {
             print_error('User ID was incorrect');
         }
     }
@@ -68,7 +68,7 @@
     $userform = new user_editadvanced_form();
     $userform->set_data($user);
 
-    if ($usernew = $userform->get_data()) {
+    if ($usernew = $userform->get_data(false)) {
         add_to_log($course->id, 'user', 'update', "view.php?id=$user->id&course=$course->id", '');
 
         if (empty($usernew->auth)) {
             $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
             $usernew->confirmed  = 1;
             $usernew->password = hash_internal_user_password($usernew->newpassword);
-            if (!$usernew->id = insert_record('user', $usernew)) {
+            if (!$usernew->id = $DB->insert_record('user', $usernew)) {
                 print_error('Error creating user record');
             }
         } else {
-            if (!update_record('user', $usernew)) {
+            if (!$DB->update_record('user', $usernew)) {
                 print_error('Error updating user record');
             }
             // pass a true $userold here
             if (! $authplugin->user_update($user, $userform->get_data(false))) {
                 // auth update failed, rollback for moodle
-                update_record('user', addslashes_object($user));
+                $DB->update_record('user', $user);
                 print_error('Failed to update user data on external auth: '.$user->auth.
                         '. See the server logs for more details.');
             }
 
         if ($user->id == $USER->id) {
             // Override old $USER session variable
-            $usernew = (array)get_record('user', 'id', $usernew->id); // reload from db
+            $usernew = $DB->get_record('user', array('id'=>$usernew->id)); // reload from db
             foreach ($usernew as $variable => $value) {
                 $USER->$variable = $value;
             }
index f26aee5c9c1e1014480b7c623eaedfc767ca70eb..d9985a66965f52d2ac8a0a1a350a8c9285c7cc36 100644 (file)
@@ -53,11 +53,11 @@ class user_editadvanced_form extends moodleform {
     }
 
     function definition_after_data() {
-        global $USER, $CFG;
+        global $USER, $CFG, $DB;
 
         $mform =& $this->_form;
         if ($userid = $mform->getElementValue('id')) {
-            $user = get_record('user', 'id', $userid);
+            $user = $DB->get_record('user', array('id'=>$userid));
         } else {
             $user = false;
         }
@@ -108,12 +108,12 @@ class user_editadvanced_form extends moodleform {
     }
 
     function validation($usernew, $files) {
-        global $CFG;
+        global $CFG, $DB;
 
         $usernew = (object)$usernew;
         $usernew->username = trim($usernew->username);
 
-        $user = get_record('user', 'id', $usernew->id);
+        $user = $DB->get_record('user', array('id'=>$usernew->id));
         $err = array();
 
         if (!empty($usernew->newpassword)) {
@@ -128,7 +128,7 @@ class user_editadvanced_form extends moodleform {
             $err['username'] = get_string('required');
         } else if (!$user or $user->username !== $usernew->username) {
             //check new username does not exist
-            if (record_exists('user', 'username', $usernew->username, 'mnethostid', $CFG->mnet_localhost_id)) {
+            if ($DB->record_exists('user', array('username'=>$usernew->username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
                 $err['username'] = get_string('usernameexists');
             }
             //check allowed characters
@@ -147,7 +147,7 @@ class user_editadvanced_form extends moodleform {
         if (!$user or $user->email !== $usernew->email) {
             if (!validate_email($usernew->email)) {
                 $err['email'] = get_string('invalidemail');
-            } else if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
+            } else if ($DB->record_exists('user', array('email'=>$usernew->email, 'mnethostid'=>$CFG->mnet_localhost_id))) {
                 $err['email'] = get_string('emailexists');
             }
         }
index dcab916ff9125b7ba23342ede50889b332479421..523a15f99055e62011ffc3924a28e3d260a1f4d2 100644 (file)
@@ -120,6 +120,8 @@ class user_filter_courserole extends user_filter_type {
      * @return string active filter label
      */
     function get_label($data) {
+        global $DB;
+
         $value      = $data['value'];
         $roleid     = $data['roleid'];
         $categoryid = $data['categoryid'];
@@ -128,14 +130,14 @@ class user_filter_courserole extends user_filter_type {
         $a->label = $this->_label;
 
         if ($roleid) {
-            $rolename = get_field('role', 'name', 'id', $roleid);
+            $rolename = $DB->get_field('role', 'name', array('id'=>$roleid));
             $a->rolename = '"'.format_string($rolename).'"';
         } else {
             $a->rolename = get_string('anyrole', 'filters');
         }
 
         if ($categoryid) {
-            $catname = get_field('course_categories', 'name', 'id', $categoryid);
+            $catname = $DB->get_field('course_categories', 'name', array('id'=>$categoryid));
             $a->categoryname = '"'.format_string($catname).'"';
         } else {
             $a->categoryname = get_string('anycategory', 'filters');
@@ -143,7 +145,7 @@ class user_filter_courserole extends user_filter_type {
 
         if ($value) {
             $a->coursename = '"'.s($value).'"';
-            if (!record_exists('course', 'shortname', addslashes($value))) {
+            if (!$DB->record_exists('course', array('shortname'=>$value))) {
                 return '<span class="notifyproblem">'.get_string('courserolelabelerror', 'filters', $a).'</span>';
             }
         } else {
index e3ad9a145325c3778cd6a21eb0a502eefdc3d478..160647e7f721b0299a693021837d72e7c0357c45 100644 (file)
@@ -120,7 +120,7 @@ class user_filtering {
                 return new user_filter_simpleselect('auth', get_string('authentication'), $advanced, 'auth', $choices);
 
             case 'mnethostid':
-                if (!$hosts = get_records('mnet_host', '', '', 'id', 'id, wwwroot, name')) {
+                if (!$hosts = $DB->get_records('mnet_host', null, 'id', 'id, wwwroot, name')) {
                     return null;
                 }
                 $choices = array();
index 650d715e7baef78183a60f8be62e35daa09b2402..925cca3295e3107305cd404608dcccf8a840c8ac 100644 (file)
@@ -37,7 +37,8 @@ class user_filter_profilefield extends user_filter_type {
      * @return array of profile fields
      */
     function get_profile_fields() {
-        if (!$fields = get_records_select('user_info_field', '', 'shortname', 'id,shortname')) {
+        global $DB;
+        if (!$fields = $DB->get_records('user_info_field', null, 'shortname', 'id,shortname')) {
             return null;
         }
         $res = array(0 => get_string('anyfield', 'filters'));
index 2852db2a9c6369508612b16551514928e58d22c4..4a1191ac7e5d939b607fd389eb3458be7503eadb 100644 (file)
@@ -89,8 +89,7 @@ class profile_define_base {
      * @return  array    associative array of error messages
      */
     function define_validate_common($data, $files) {
-
-        global $USER;
+        global $USER, $DB;
 
         $err = array();
 
@@ -100,7 +99,7 @@ class profile_define_base {
 
         } else {
         /// Fetch field-record from DB
-            $field = get_record('user_info_field', 'shortname', $data->shortname);
+            $field = $DB->get_record('user_info_field', array('shortname'=>$data->shortname));
         /// Check the shortname is unique
             if ($field and $field->id <> $data->id) {
                 $err['shortname'] = get_string('profileshortnamenotunique', 'admin');
@@ -140,24 +139,25 @@ class profile_define_base {
      * @return  boolean  status of the insert/update record
      */
     function define_save($data) {
+        global $DB;
 
         $data = $this->define_save_preprocess($data); /// hook for child classes
 
-        $old = get_record('user_info_field', 'id', $data->id);
+        $old = $DB->get_record('user_info_field', array('id'=>(int)$data->id));
 
         /// check to see if the category has changed
         if (!$old or $old->categoryid != $data->categoryid) {
-            $data->sortorder = count_records_select('user_info_field', 'categoryid='.$data->categoryid) + 1;
+            $data->sortorder = $DB->count_records('user_info_field', array('categoryid'=>$data->categoryid)) + 1;
         }
 
 
         if (empty($data->id)) {
             unset($data->id);
-            if (!$data->id = insert_record('user_info_field', $data)) {
+            if (!$data->id = $DB->insert_record('user_info_field', $data)) {
                 print_error('Error creating new field');
             }
         } else {
-            if (!update_record('user_info_field', $data)) {
+            if (!$DB->update_record('user_info_field', $data)) {
                 print_error('Error updating field');
             }
         }
@@ -184,15 +184,17 @@ class profile_define_base {
  * at the field at the given startorder
  */
 function profile_reorder_fields() {
-    if ($categories = get_records_select('user_info_category')) {
+    global $DB;
+
+    if ($categories = $DB->get_records('user_info_category')) {
         foreach ($categories as $category) {
             $i = 1;
-            if ($fields = get_records_select('user_info_field', 'categoryid='.$category->id, 'sortorder ASC')) {
+            if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
                 foreach ($fields as $field) {
                     $f = new object();
                     $f->id = $field->id;
                     $f->sortorder = $i++;
-                    update_record('user_info_field', $f);
+                    $DB->update_record('user_info_field', $f);
                 }
             }
         }
@@ -204,13 +206,15 @@ function profile_reorder_fields() {
  * at the given startorder
  */
 function profile_reorder_categories() {
+    global $DB;
+
     $i = 1;
-    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
+    if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
         foreach ($categories as $cat) {
             $c = new object();
             $c->id = $cat->id;
             $c->sortorder = $i++;
-            update_record('user_info_category', $c);
+            $DB->update_record('user_info_category', $c);
         }
     }
 }
@@ -221,12 +225,14 @@ function profile_reorder_categories() {
  * @return  boolean   success of operation
  */
 function profile_delete_category($id) {
+    global $DB;
+
     /// Retrieve the category
-    if (!$category = get_record('user_info_category', 'id', $id)) {
+    if (!$category = $DB->get_record('user_info_category', array('id'=>$id))) {
         print_error('Incorrect category id');
     }
 
-    if (!$categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
+    if (!$categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
         print_error('Error no categories!?!?');
     }
 
@@ -246,22 +252,22 @@ function profile_delete_category($id) {
             $newcategory = reset($categories); // get first category if sortorder broken
         }
 
-        $sortorder = count_records('user_info_field', 'categoryid', $newcategory->id) + 1;
+        $sortorder = $DB->count_records('user_info_field', array('categoryid'=>$newcategory->id)) + 1;
 
-        if ($fields = get_records_select('user_info_field', 'categoryid='.$category->id, 'sortorder ASC')) {
+        if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
             foreach ($fields as $field) {
                 $f = new object();
                 $f->id = $field->id;
                 $f->sortorder = $sortorder++;
                 $f->categoryid = $newcategory->id;
-                update_record('user_info_field', $f);
-                echo "<pre>";var_dump($f);echo"</pre>";
+                $DB->update_record('user_info_field', $f);
+                //echo "<pre>";var_dump($f);echo"</pre>";
             }
         }
     }
 
     /// Finally we get to delete the category
-    if (!delete_records('user_info_category', 'id', $category->id)) {
+    if (!$DB->delete_records('user_info_category', array('id'=>$category->id))) {
         print_error('Error while deliting category');
     }
     profile_reorder_categories();
@@ -270,14 +276,15 @@ function profile_delete_category($id) {
 
 
 function profile_delete_field($id) {
+    global $DB;
 
     /// Remove any user data associated with this field
-    if (!delete_records('user_info_data', 'fieldid', $id)) {
+    if (!$DB->delete_records('user_info_data', array('fieldid'=>$id))) {
         print_error('Error deleting custom field data');
     }
 
     /// Try to remove the record from the database
-    delete_records('user_info_field', 'id', $id);
+    $DB->delete_records('user_info_field', array('id'=>$id));
 
     /// Reorder the remaining fields in the same category
     profile_reorder_fields();
@@ -290,12 +297,14 @@ function profile_delete_field($id) {
  * @return  boolean   success of operation
  */
 function profile_move_field($id, $move) {
+    global $DB;
+
     /// Get the field object
-    if (!$field = get_record('user_info_field', 'id', $id, '', '', '', '', 'id, sortorder, categoryid')) {
+    if (!$field = $DB->get_record('user_info_field', array('id'=>$id), 'id, sortorder, categoryid')) {
         return false;
     }
     /// Count the number of fields in this category
-    $fieldcount = count_records_select('user_info_field', 'categoryid='.$field->categoryid);
+    $fieldcount = $DB->count_records('user_info_field', array('categoryid'=>$field->categoryid));
 
     /// Calculate the new sortorder
     if ( ($move == 'up') and ($field->sortorder > 1)) {
@@ -307,15 +316,15 @@ function profile_move_field($id, $move) {
     }
 
     /// Retrieve the field object that is currently residing in the new position
-    if ($swapfield = get_record('user_info_field', 'categoryid', $field->categoryid, 'sortorder', $neworder, '', '', 'id, sortorder')) {
+    if ($swapfield = $DB->get_record('user_info_field', array('categoryid'=>$field->categoryid, 'sortorder'=>$neworder), 'id, sortorder')) {
 
         /// Swap the sortorders
         $swapfield->sortorder = $field->sortorder;
         $field->sortorder     = $neworder;
 
         /// Update the field records
-        update_record('user_info_field', $field);
-        update_record('user_info_field', $swapfield);
+        $DB->update_record('user_info_field', $field);
+        $DB->update_record('user_info_field', $swapfield);
     }
 
     profile_reorder_fields();
@@ -328,13 +337,14 @@ function profile_move_field($id, $move) {
  * @return  boolean   success of operation
  */
 function profile_move_category($id, $move) {
+    global $DB;
     /// Get the category object
-    if (!($category = get_record('user_info_category', 'id', $id, '', '', '', '', 'id, sortorder'))) {
+    if (!($category = $DB->get_record('user_info_category', array('id'=>$id), 'id, sortorder'))) {
         return false;
     }
 
     /// Count the number of categories
-    $categorycount = count_records('user_info_category');
+    $categorycount = $DB->count_records('user_info_category');
 
     /// Calculate the new sortorder
     if ( ($move == 'up') and ($category->sortorder > 1)) {
@@ -346,14 +356,14 @@ function profile_move_category($id, $move) {
     }
 
     /// Retrieve the category object that is currently residing in the new position
-    if ($swapcategory = get_record('user_info_category', 'sortorder', $neworder, '', '', '', '', 'id, sortorder')) {
+    if ($swapcategory = $DB->get_record('user_info_category', array('sortorder'=>$neworder),'id, sortorder')) {
 
         /// Swap the sortorders
         $swapcategory->sortorder = $category->sortorder;
         $category->sortorder     = $neworder;
 
         /// Update the category records
-        if (update_record('user_info_category', $category) and update_record('user_info_category', $swapcategory)) {
+        if ($DB->update_record('user_info_category', $category) and $DB->update_record('user_info_category', $swapcategory)) {
             return true;
         }
     }
@@ -388,7 +398,8 @@ function profile_list_datatypes() {
  * @return   array
  */
 function profile_list_categories() {
-    if (!$categories = get_records_select_menu('user_info_category', '', 'sortorder ASC', 'id, name')) {
+    global $DB;
+    if (!$categories = $DB->get_records_menu('user_info_category', NULL, 'sortorder ASC', 'id, name')) {
         $categories = array();
     }
     return $categories;
@@ -397,27 +408,27 @@ function profile_list_categories() {
 
 /// Are we adding or editing a cateogory?
 function profile_edit_category($id, $redirect) {
-    global $CFG;
+    global $CFG, $DB;
 
     require_once('index_category_form.php');
     $categoryform = new category_form();
 
-    if ($category = get_record('user_info_category', 'id', $id)) {
+    if ($category = $DB->get_record('user_info_category', array('id'=>$id))) {
         $categoryform->set_data($category);
     }
 
     if ($categoryform->is_cancelled()) {
         redirect($redirect);
     } else {
-        if ($data = $categoryform->get_data()) {
+        if ($data = $categoryform->get_data(false)) {
             if (empty($data->id)) {
                 unset($data->id);
                 $data->sortorder = count_records('user_info_category') + 1;
-                if (!insert_record('user_info_category', $data, false)) {
+                if (!$DB->insert_record('user_info_category', $data, false)) {
                     print_error('There was a problem adding the record to the database');
                 }
             } else {
-                if (!update_record('user_info_category', $data)) {
+                if (!$DB->update_record('user_info_category', $data)) {
                     print_error('There was a problem updating the record in the database');
                 }
             }
@@ -443,9 +454,9 @@ function profile_edit_category($id, $redirect) {
 }
 
 function profile_edit_field($id, $datatype, $redirect) {
-    global $CFG;
+    global $CFG, $DB;
 
-    if (!$field = get_record('user_info_field', 'id', $id)) {
+    if (!$field = $DB->get_record('user_info_field', array('id'=>$id))) {
         $field = new object();
         $field->datatype = $datatype;
     }
index ce32ecf15665f6118900ac257f5a56386bb87276..61acf9facb94b809564f04d675828ade47115333 100644 (file)
@@ -106,7 +106,7 @@ if (count_records('user_info_category') == 0) {
 }
 
 /// Show all categories
-$categories = get_records_select('user_info_category', '', 'sortorder ASC');
+$categories = $DB->get_records('user_info_category', null, 'sortorder ASC');
 
 foreach ($categories as $category) {
     $table = new object();
@@ -116,7 +116,7 @@ foreach ($categories as $category) {
     $table->class = 'generaltable profilefield';
     $table->data = array();
 
-    if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
+    if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
         foreach ($fields as $field) {
             $table->data[] = array($field->name, profile_field_icons($field));
         }
@@ -159,15 +159,15 @@ die;
  * @return  string   the icon string
  */
 function profile_category_icons ($category) {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
     $strdelete   = get_string('delete');
     $strmoveup   = get_string('moveup');
     $strmovedown = get_string('movedown');
     $stredit     = get_string('edit');
 
-    $categorycount = count_records('user_info_category');
-    $fieldcount    = count_records('user_info_field', 'categoryid', $category->id);
+    $categorycount = $DB->count_records('user_info_category');
+    $fieldcount    = $DB->count_records('user_info_field', array('categoryid'=>$category->id));
 
     /// Edit
     $editstr = '<a title="'.$stredit.'" href="index.php?id='.$category->id.'&amp;action=editcategory"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
@@ -203,8 +203,8 @@ function profile_category_icons ($category) {
  * @param   object   the field object
  * @return  string   the icon string
  */
-function profile_field_icons ($field) {
-    global $CFG, $USER;
+function profile_field_icons($field) {
+    global $CFG, $USER, $DB;
 
     if (empty($str)) {
         $strdelete   = get_string('delete');
@@ -213,8 +213,8 @@ function profile_field_icons ($field) {
         $stredit     = get_string('edit');
     }
 
-    $fieldcount = count_records('user_info_field', 'categoryid',$field->categoryid);
-    $datacount  = count_records('user_info_data', 'fieldid', $field->id);
+    $fieldcount = $DB->count_records('user_info_field', array('categoryid'=>$field->categoryid));
+    $datacount  = $DB->count_records('user_info_data', array('fieldid'=>$field->id));
 
     /// Edit
     $editstr = '<a title="'.$stredit.'" href="index.php?id='.$field->id.'&amp;action=editfield"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
index 51c585ccf382e8974259c9f3b71743fee19916a5..44af21cad6f7ca4909d2443493e8afb2c6ed97a3 100644 (file)
@@ -26,15 +26,15 @@ class category_form extends moodleform {
 
 /// perform some moodle validation
     function validation($data, $files) {
-        global $CFG;
+        global $CFG, $DB;
         $errors = parent::validation($data, $files);
 
         $data  = (object)$data;
 
-        $category = get_record('user_info_category', 'id', $data->id);
+        $category = $DB->get_record('user_info_category', array('id'=>$data->id));
 
         /// Check the name is unique
-        if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
+        if ($category and ($category->name !== $data->name) and ($DB->record_exists('user_info_category', array('name'=>$data->name)))) {
             $errors['name'] = get_string('profilecategorynamenotunique', 'admin');
         }
 
index 84878f6a384b4133e9462bab0abaccb345b3a68d..cfdf6a4fdcfc5822614a0841de1077cffdfae36d 100644 (file)
@@ -53,6 +53,7 @@ class profile_field_base {
      * Display the data for this field
      */
     function display_data() {
+        $options = new object();
         $options->para = false;
         return format_text($this->data, FORMAT_MOODLE, $options);
     }
@@ -80,6 +81,7 @@ class profile_field_base {
      * @return  mixed   returns data id if success of db insert/update, false on fail, 0 if not permitted
      */
     function edit_save_data($usernew) {
+        global $DB;
 
         if (!isset($usernew->{$this->inputname})) {
             // field not present in form, probably locked and invisible - skip it
@@ -93,13 +95,13 @@ class profile_field_base {
         $data->fieldid = $this->field->id;
         $data->data    = $usernew->{$this->inputname};
 
-        if ($dataid = get_field('user_info_data', 'id', 'userid', $data->userid, 'fieldid', $data->fieldid)) {
+        if ($dataid = $DB->get_field('user_info_data', 'id', array('userid'=>$data->userid, 'fieldid'=>$data->fieldid))) {
             $data->id = $dataid;
-            if (!update_record('user_info_data', $data)) {
+            if (!$DB->update_record('user_info_data', $data)) {
                 print_error('Error updating custom profile field!');
             }
         } else {
-            insert_record('user_info_data', $data);
+            $DB->insert_record('user_info_data', $data);
         }
     }
 
@@ -196,8 +198,10 @@ class profile_field_base {
      * object's fieldid and userid
      */
     function load_data() {
+        global $DB;
+
         /// Load the field object
-        if (($this->fieldid == 0) or (!($field = get_record('user_info_field', 'id', $this->fieldid)))) {
+        if (($this->fieldid == 0) or (!($field = $DB->get_record('user_info_field', array('id'=>$this->fieldid))))) {
             $this->field = NULL;
             $this->inputname = '';
         } else {
@@ -206,7 +210,7 @@ class profile_field_base {
         }
 
         if (!empty($this->field)) {
-            if ($datafield = get_field('user_info_data', 'data', 'userid', $this->userid, 'fieldid', $this->fieldid)) {
+            if ($datafield = $DB->get_field('user_info_data', 'data', array('userid'=>$this->userid, 'fieldid'=>$this->fieldid))) {
                 $this->data = $datafield;
             } else {
                 $this->data = $this->field->defaultdata;
@@ -280,9 +284,9 @@ class profile_field_base {
 /***** General purpose functions for customisable user profiles *****/
 
 function profile_load_data(&$user) {
-    global $CFG;
+    global $CFG, $DB;
 
-    if ($fields = get_records_select('user_info_field')) {
+    if ($fields = $DB->get_records('user_info_field')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
@@ -297,11 +301,11 @@ function profile_load_data(&$user) {
  * @param  object   instance of the moodleform class
  */
 function profile_definition(&$mform) {
-    global $CFG;
+    global $CFG, $DB;
 
-    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
+    if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
         foreach ($categories as $category) {
-            if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
+            if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
                 $mform->addElement('header', 'category_'.$category->id, format_string($category->name));
                 foreach ($fields as $field) {
                     require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
@@ -316,9 +320,9 @@ function profile_definition(&$mform) {
 }
 
 function profile_definition_after_data(&$mform) {
-    global $CFG;
+    global $CFG, $DB;
 /*
-    if ($fields = get_records('user_info_field')) {
+    if ($fields = $DB->get_records('user_info_field')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
@@ -330,10 +334,10 @@ function profile_definition_after_data(&$mform) {
 }
 
 function profile_validation($usernew, $files) {
-    global $CFG;
+    global $CFG, $DB;
 
     $err = array();
-    if ($fields = get_records('user_info_field')) {
+    if ($fields = $DB->get_records('user_info_field')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
@@ -345,9 +349,9 @@ function profile_validation($usernew, $files) {
 }
 
 function profile_save_data($usernew) {
-    global $CFG;
+    global $CFG, $DB;
 
-    if ($fields = get_records_select('user_info_field')) {
+    if ($fields = $DB->get_records_select('user_info_field')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
@@ -358,11 +362,11 @@ function profile_save_data($usernew) {
 }
 
 function profile_display_fields($userid) {
-    global $CFG, $USER;
+    global $CFG, $USER, $DB;
 
-    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
+    if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
         foreach ($categories as $category) {
-            if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
+            if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
                 foreach ($fields as $field) {
                     require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
                     $newfield = 'profile_field_'.$field->datatype;
@@ -382,9 +386,9 @@ function profile_display_fields($userid) {
  * @param  object  moodle form object
  */
 function profile_signup_fields(&$mform) {
-    global $CFG;
+    global $CFG, $DB;
     
-    if ($fields = get_records('user_info_field', 'signup', 1, 'sortorder ASC')) {
+    if ($fields = $DB->get_records('user_info_field', array('signup'=>1), 'sortorder ASC')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
@@ -400,11 +404,11 @@ function profile_signup_fields(&$mform) {
  * @return  object
  */
 function profile_user_record($userid) {
-    global $CFG;
+    global $CFG, $DB;
 
     $user = new object();
 
-    if ($fields = get_records_select('user_info_field')) {
+    if ($fields = $DB->get_records('user_info_field')) {
         foreach ($fields as $field) {
             require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
             $newfield = 'profile_field_'.$field->datatype;
index 543af8976e3303840404feab08ee15cbf55d9fcd..db102f8c53b9716fc8ee75c9e29db55739d65812 100644 (file)
@@ -13,7 +13,7 @@
 /// Remove the following three lines if you want everyone to access it
     require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
 
-    if (!$users = get_records("user", "picture", "1", "lastaccess DESC", "id,firstname,lastname")) {
+    if (!$users = $DB->get_records("user", array("picture"=>"1"), "lastaccess DESC", "id,firstname,lastname")) {
         print_error("no users!");
     }
 
index 43f25750416c1ef47fe3815a55c670f2fc3dee0f..d4f7a9ac2378fb7d8eddc597771397b56cf26e71 100644 (file)
@@ -9,7 +9,7 @@
 
     require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
 
-    if (!$users = get_records("user", "picture", "1", "lastaccess DESC", "id,firstname,lastname")) {
+    if (!$users = $DB->get_records("user", array("picture"=>"1"), "lastaccess DESC", "id,firstname,lastname")) {
         print_error("no users!");
     }