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) {
* 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');
}
* 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) {
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');
}
/**
* 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) {
* 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) {
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();
$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');
}
}
// 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');
}
$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;
}
}
function definition_after_data() {
- global $CFG;
+ global $CFG, $DB;
$mform =& $this->_form;
$userid = $mform->getElementValue('id');
}
}
- if ($user = get_record('user', 'id', $userid)) {
+ if ($user = $DB->get_record('user', array('id'=>$userid))) {
// print picture
if (!empty($CFG->gdversion)) {
}
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');
}
$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);
} 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');
}
}
$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;
}
}
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;
}
}
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)) {
$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
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');
}
}
* @return string active filter label
*/
function get_label($data) {
+ global $DB;
+
$value = $data['value'];
$roleid = $data['roleid'];
$categoryid = $data['categoryid'];
$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');
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 {
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();
* @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'));
* @return array associative array of error messages
*/
function define_validate_common($data, $files) {
-
- global $USER;
+ global $USER, $DB;
$err = array();
} 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');
* @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');
}
}
* 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);
}
}
}
* 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);
}
}
}
* @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!?!?');
}
$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();
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();
* @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)) {
}
/// 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();
* @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)) {
}
/// 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;
}
}
* @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;
/// 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');
}
}
}
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;
}
}
/// 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();
$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));
}
* @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.'&action=editcategory"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
* @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');
$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.'&action=editfield"><img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" class="iconsmall" /></a> ';
/// 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');
}
* Display the data for this field
*/
function display_data() {
+ $options = new object();
$options->para = false;
return format_text($this->data, FORMAT_MOODLE, $options);
}
* @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
$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);
}
}
* 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 {
}
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;
/***** 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;
* @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');
}
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;
}
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;
}
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;
}
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;
* @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;
* @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;
/// 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!");
}
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!");
}