From: skodak Date: Fri, 30 May 2008 22:11:31 +0000 (+0000) Subject: MDL-14679 towards /user conversion X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5d910388bbc70f89f142dcd5efe4f6af95f9d3fb;p=moodle.git MDL-14679 towards /user conversion --- diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 4511b81e8e..ba81acf10e 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -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) { diff --git a/auth/email/auth.php b/auth/email/auth.php index 602336ba8b..8109d6c81d 100644 --- a/auth/email/auth.php +++ b/auth/email/auth.php @@ -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'); } diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 22bb9ec39e..77d01971d0 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -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'); } diff --git a/lib/adminlib.php b/lib/adminlib.php index 670c549d37..690b9305da 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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) { diff --git a/lib/authlib.php b/lib/authlib.php index 5521dbe5ef..d076646d70 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -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) { diff --git a/login/signup.php b/login/signup.php index a3e6e2fcbe..26f5d3a2ca 100644 --- a/login/signup.php +++ b/login/signup.php @@ -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(); diff --git a/user/edit.php b/user/edit.php index d237145aff..f0f3df6663 100644 --- a/user/edit.php +++ b/user/edit.php @@ -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", ''); @@ -97,14 +97,14 @@ $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.'); } @@ -133,7 +133,7 @@ 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; } diff --git a/user/edit_form.php b/user/edit_form.php index 9f96fd902a..0f08437d0f 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -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'); } diff --git a/user/editadvanced.php b/user/editadvanced.php index 3be1401a80..2fa03183d8 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -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)) { @@ -88,17 +88,17 @@ $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.'); } @@ -141,7 +141,7 @@ 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; } diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index f26aee5c9c..d9985a6696 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -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'); } } diff --git a/user/filters/courserole.php b/user/filters/courserole.php index dcab916ff9..523a15f990 100644 --- a/user/filters/courserole.php +++ b/user/filters/courserole.php @@ -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 ''.get_string('courserolelabelerror', 'filters', $a).''; } } else { diff --git a/user/filters/lib.php b/user/filters/lib.php index e3ad9a1453..160647e7f7 100644 --- a/user/filters/lib.php +++ b/user/filters/lib.php @@ -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(); diff --git a/user/filters/profilefield.php b/user/filters/profilefield.php index 650d715e7b..925cca3295 100644 --- a/user/filters/profilefield.php +++ b/user/filters/profilefield.php @@ -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')); diff --git a/user/profile/definelib.php b/user/profile/definelib.php index 2852db2a9c..4a1191ac7e 100644 --- a/user/profile/definelib.php +++ b/user/profile/definelib.php @@ -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 "
";var_dump($f);echo"
"; + $DB->update_record('user_info_field', $f); + //echo "
";var_dump($f);echo"
"; } } } /// 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; } diff --git a/user/profile/index.php b/user/profile/index.php index ce32ecf156..61acf9facb 100644 --- a/user/profile/index.php +++ b/user/profile/index.php @@ -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 = ''.$stredit.' '; @@ -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 = ''.$stredit.' '; diff --git a/user/profile/index_category_form.php b/user/profile/index_category_form.php index 51c585ccf3..44af21cad6 100644 --- a/user/profile/index_category_form.php +++ b/user/profile/index_category_form.php @@ -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'); } diff --git a/user/profile/lib.php b/user/profile/lib.php index 84878f6a38..cfdf6a4fdc 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -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; diff --git a/userpix/index.php b/userpix/index.php index 543af8976e..db102f8c53 100644 --- a/userpix/index.php +++ b/userpix/index.php @@ -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!"); } diff --git a/userpix/upgrade.php b/userpix/upgrade.php index 43f2575041..d4f7a9ac23 100644 --- a/userpix/upgrade.php +++ b/userpix/upgrade.php @@ -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!"); }