function solution() {
global $CFG;
if (optional_param('resetsesserrorcounter', 0, PARAM_BOOL)) {
- if (get_field('config', 'name', 'name', 'session_error_counter')) {
+ if ($DB->get_field('config', 'name', array('name'=>'session_error_counter'))) {
delete_records('config', 'name', 'session_error_counter');
}
return 'Error counter was cleared.';
}
/// If no recently cron run
- $lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
+ $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}');
if (time() - $lastcron > 3600 * 24) {
$strinstallation = get_string('installation', 'install');
$helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
$hosts = $enrolment->list_remote_servers();
foreach ($hosts as $host) {
$coursesurl = "$CFG->wwwroot/$CFG->admin/mnet/enr_courses.php?host={$host->id}&sesskey={$USER->sesskey}";
- $coursecount = get_field_sql("SELECT count(id) FROM {$CFG->prefix}mnet_enrol_course WHERE hostid={$host->id}");
+ $coursecount = $DB->get_field_sql("SELECT COUNT(id) FROM {mnet_enrol_course} WHERE hostid=?", array($host->id));
if (empty($coursecount)) {
$coursecount = '?';
}
- $enrolcount = get_field_sql("SELECT count(id) FROM {$CFG->prefix}mnet_enrol_assignments WHERE hostid={$host->id}");
+ $enrolcount = $DB->get_field_sql("SELECT COUNT(id) FROM {mnet_enrol_assignments} WHERE hostid=?", array($host->id));
echo '<tr>'
. "<td><a href=\"{$coursesurl}\">{$host->name}</a></td>"
}
unset($temp_wwwroot);
$mnet_peer->set_applicationid($form->applicationid);
- $application = get_field('mnet_application', 'name', 'id', $form->applicationid);
+ $application = $DB->get_field('mnet_application', 'name', array('id'=>$form->applicationid));
$mnet_peer->bootstrap($form->wwwroot, null, $application);
}
echo "<td nowrap=\"nowrap\" align=\"center\"><font size=\"3\">$strnext</font></td></tr>";
foreach ($courses as $course) {
/// Get the course shortname
- $coursename = get_field ("course","fullname","id",$course->courseid);
+ $coursename = $DB->get_field ("course", "fullname", array("id"=>$course->courseid));
if ($coursename) {
echo "<tr>";
echo "<td nowrap=\"nowrap\"><font size=\"2\"><a href=\"index.php?courseid=$course->courseid\">".$coursename."</a></font></td>";
} else {
print_heading($backuplogdetailed);
- $coursename = get_field("course","fullname","id","$courseid");
+ $coursename = $DB->get_field("course", "fullname", array("id"=>"$courseid"));
print_heading("$strcourse: $coursename");
print_simple_box_start('center');
$tableprefix = $CFG->prefix.'stats_';
- $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT timeend FROM {daily} ORDER BY timeend');
+ $earliestweek = $DB->get_field_sql('SELECT timeend FROM {weekly} ORDER BY timeend');
+ $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {monthly} ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
foreach ($courses as $c) {
$a = array();
- $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.get_field('course','shortname','id',$c->courseid).'</a>';
+ $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>';
$a[] = $c->line1;
if (isset($c->line2)) {
}
foreach ($courses as $c) {
- $graph->x_data[] = get_field('course','shortname','id',$c->courseid);
+ $graph->x_data[] = $DB->get_field('course', 'shortname', array('id'=>$c->courseid));
$graph->y_data['bar1'][] = $c->{$param->graphline};
}
$graph->y_order = array('bar1');
}
foreach ($assignableroles as $roleid => $rolename) {
- $description = format_string(get_field('role', 'description', 'id', $roleid));
+ $description = format_string($DB->get_field('role', 'description', array('id'=>$roleid)));
$row = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>',$description, $rolehodlercount[$roleid]);
if ($showroleholders) {
$row[] = $rolehodlernames[$roleid];
// reset a role sitewide...
mark_context_dirty($sitecontext->path);
- $rolename = get_field('role', 'name', 'id', $roleid);
+ $rolename = $DB->get_field('role', 'name', array('id'=>$roleid));
add_to_log(SITEID, 'role', 'reset', 'admin/roles/manage.php?roleid='.$roleid.'&action=reset', $rolename, '', $USER->id);
redirect('manage.php?action=view&roleid='.$roleid);
foreach ($overridableroles as $roleid => $rolename) {
$countusers = 0;
$overridecount = $DB->count_records_select('role_capabilities', "roleid = ? AND contextid = ?", array($roleid, $context->id));
- $description = format_string(get_field('role', 'description', 'id', $roleid));
+ $description = format_string($DB->get_field('role', 'description', array('id'=>$roleid)));
$table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>', $description, $overridecount);
}
continue;
}
if (my_save_profile_image($user->id, $zipdir.'/'.$item)) {
- set_field('user', 'picture', 1, 'id', $user->id);
+ $DB->set_field('user', 'picture', 1, array('id'=>$user->id));
$usersupdated++;
notify(get_string('uploadpicture_userupdated', 'admin', $user->username));
} else {
$tests['update record '. $textlen . ' cc. (text) and ' . $imglen . ' bytes (binary)'] = $test;
}
- /// 50th test. set_field with TEXT contents
+ /// 50th test. $DB->set_field with TEXT contents
if ($test->status) {
$test = new stdClass;
$test->status = false;
* @return array The local user record.
*/
function confirm_mnet_session($token, $remotewwwroot) {
- global $CFG, $MNET, $SESSION;
+ global $CFG, $MNET, $SESSION, $DB;
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
// verify the remote host is configured locally before attempting RPC call
$extra = get_records_sql($sql);
$keys = array_keys($courses);
- $defaultrolename = get_field('role', 'shortname', 'id', $CFG->defaultcourseroleid);
+ $defaultrolename = $DB->get_field('role', 'shortname', array('id'=>$CFG->defaultcourseroleid));
foreach ($keys AS $id) {
if ($courses[$id]->visible == 0) {
unset($courses[$id]);
* @todo finish documenting this function
*/
function instance_config_save($data,$pinned=false) {
- $data = stripslashes_recursive($data);
+ global $DB;
+
+ $data = $data;
$this->config = $data;
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
- return set_field($table, 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
+ return $DB->set_field($table, 'configdata', base64_encode(serialize($data)), array('id'=>$this->instance->id));
}
/**
* @todo finish documenting this function
*/
function instance_config_commit($pinned=false) {
+ global $DB;
+
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
- return set_field($table, 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
+ return $DB->set_field($table, 'configdata', base64_encode(serialize($this->config)), array('id'=>$this->instance->id));
}
/**
}
if (!empty($USER->id)) {
- $display = get_field('course_display', 'display', 'course', $this->instance->pageid, 'userid', $USER->id);
+ $display = $DB->get_field('course_display', 'display', array('course'=>$this->instance->pageid, 'userid'=>$USER->id));
}
if (!empty($display)) {
$link = $CFG->wwwroot.'/course/view.php?id='.$this->instance->pageid.'&'.$sectionname.'=';
break;
case 'group':
$group = groups_get_group($id, false);
- $info = $group->name; //TODO: get_field('groups', 'name', 'id', $id)
+ $info = $group->name; //TODO: $DB->get_field('groups', 'name', array('id'=>$id))
break;
default:
$info = '';
$count = $count->max + 100;
begin_sql();
foreach ($courses as $course) {
- set_field('course', 'sortorder', $count, 'id', $course->id);
+ $DB->set_field('course', 'sortorder', $count, array('id'=>$course->id));
$count++;
}
commit_sql();
$visible = 1;
}
if ($category) {
- if (! set_field("course_categories", "visible", $visible, "id", $category->id)) {
+ if (! $DB->set_field("course_categories", "visible", $visible, array("id"=>$category->id))) {
notify("Could not update that category!");
}
}
if ($swapcourse and $movecourse) { // Renumber everything for robustness
begin_sql();
- if (!( set_field("course", "sortorder", $max, "id", $swapcourse->id)
- && set_field("course", "sortorder", $swapcourse->sortorder, "id", $movecourse->id)
- && set_field("course", "sortorder", $movecourse->sortorder, "id", $swapcourse->id)
+ if (!( $DB->set_field("course", "sortorder", $max, aray("id"=>$swapcourse->id))
+ && $DB->set_field("course", "sortorder", $swapcourse->sortorder, array("id"=>$movecourse->id))
+ && $DB->set_field("course", "sortorder", $movecourse->sortorder, array("id"=>$swapcourse->id))
)) {
notify("Could not update that course!");
}
}
if (has_capability('moodle/course:create', $sysctx)) { // Print link to create a new course
/// Get the 1st available category
- $options = array('category' => get_field('course_categories', 'id', 'parent', '0'));
+ $options = array('category' => $DB->get_field('course_categories', 'id', array('parent'=>'0')));
print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
}
if (has_capability('moodle/site:approvecourse', $sysctx) and !empty($CFG->enablecourserequests)) {
if (has_capability('moodle/course:create', $sysctx)) {
// print create course link to first category
$options = array();
- $options = array('category' => get_field('course_categories', 'id', 'parent', '0'));
+ $options = array('category' => $DB->get_field('course_categories', 'id', array('parent'=>'0')));
print_single_button('edit.php', $options, get_string('addnewcourse'), 'get');
}
}
}
}
if (!isset($mod[$seq]->name)) {
- $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
+ $mod[$seq]->name = urlencode($DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance)));
}
}
}
function set_coursemodule_groupmode($id, $groupmode) {
global $DB;
- return set_field("course_modules", "groupmode", $groupmode, array("id"=>$id));
+ return $DB->set_field("course_modules", "groupmode", $groupmode, array("id"=>$id));
}
function set_coursemodule_groupingid($id, $groupingid) {
global $DB;
- return set_field("course_modules", "groupingid", $groupingid, array("id"=>$id));
+ return $DB->set_field("course_modules", "groupingid", $groupingid, array("id"=>$id));
}
function set_coursemodule_groupmembersonly($id, $groupmembersonly) {
global $DB;
- return set_field("course_modules", "groupmembersonly", $groupmembersonly, array("id"=>$id));
+ return $DB->set_field("course_modules", "groupmembersonly", $groupmembersonly, array("id"=>$id));
}
function set_coursemodule_idnumber($id, $idnumber) {
global $DB;
- return set_field("course_modules", "idnumber", $idnumber, array("id"=>$id));
+ return $DB->set_field("course_modules", "idnumber", $idnumber, array("id"=>$id));
}
/**
* $prevstateoverrides = true will set the visibility of the course module
print_heading(format_string($course->fullname));
- if (!$logstart = get_field_sql("SELECT MIN(time) FROM {$CFG->prefix}log")) {
+ if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
print_error('logfilenotavailable');
}
function report_stats_timeoptions($mode) {
- global $CFG;
+ global $CFG, $DB;
$tableprefix = $CFG->prefix.'stats_';
$tableprefix = $CFG->prefix.'stats_user_';
}
- $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
- $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
- $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
+ $earliestday = $DB->get_field_sql('SELECT timeend FROM {daily} ORDER BY timeend');
+ $earliestweek = $DB->get_field_sql('SELECT timeend FROM {weekly} ORDER BY timeend');
+ $earliestmonth = $DB->get_field_sql('SELECT timeend FROM {monthly} ORDER BY timeend');
if (empty($earliestday)) $earliestday = time();
if (empty($earliestweek)) $earliestweek = time();
print_heading(format_string($course->shortname).' - '.get_string('statsreport'.$report)
.((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')
- .((!empty($roleid)) ? ' '.get_field('role','name','id',$roleid) : ''));
+ .((!empty($roleid)) ? ' '.$DB->get_field('role','name', array('id'=>$roleid)) : ''));
if (empty($CFG->gdversion)) {
* For example, IMS role '01' is 'Learner', so may map to 'student' in Moodle.
*/
function determine_default_rolemapping($imscode) {
+ global $DB;
+
switch($imscode) {
case '01':
case '04':
default:
return 0; // Zero for no match
}
- return get_field('role', 'id', 'shortname', $shortname);
+ return $DB->get_field('role', 'id', array('shortname'=>$shortname));
}
/* -----------Course aliasing is DEACTIVATED until a more general method is in place---------------
// Second, look in the course alias table to see if the code should be translated to something else
- if($aliases = get_field('enrol_coursealias', 'toids', 'fromid', $group->coursecode)){
+ if($aliases = $DB->get_field('enrol_coursealias', 'toids', array('fromid'=>$group->coursecode))){
$this->log_line("Found alias of course code: Translated $group->coursecode to $aliases");
// Alias is allowed to be a comma-separated list, so let's split it
$group->coursecode = explode(',', $aliases);
$this->log_line('Failed to create course '.$coursecode.' in Moodle');
}
}
- }elseif($recstatus==3 && ($courseid = get_field('course', 'id', 'idnumber', $coursecode))){
+ }elseif($recstatus==3 && ($courseid = $DB->get_field('course', 'id', array('idnumber'=>$coursecode)))){
// If course does exist, but recstatus==3 (delete), then set the course as hidden
$DB->set_field('course', 'visible', '0', array('id'=>$courseid));
}
case STATS_REPORT_ACTIVITYBYROLE;
$param->fields = 'stat1 AS line1, stat2 AS line2';
$param->stattype = 'activity';
- $rolename = get_field('role','name','id',$roleid);
+ $rolename = $DB->get_field('role','name', array('id'=>$roleid));
$param->line1 = $rolename . get_string('statsreads');
$param->line2 = $rolename . get_string('statswrites');
if ($courseid == SITEID) {
// Clear secret so that it can not be used again
$user->secret = '';
- if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
+ if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('Error resetting user secret string');
}
// set 'secret' string
$user->secret = random_string(15);
- if (!set_field('user', 'secret', $user->secret, 'id', $user->id)) {
+ if (!$DB->set_field('user', 'secret', $user->secret, array('id'=>$user->id))) {
print_error('error setting user secret string');
}
}
function get_keypair() {
+ global $DB;
+
// We don't generate keys on install/upgrade because we want the USER
// record to have an email address, city and country already.
if (!empty($_SESSION['upgraderunning'])) return true;
if (!empty($this->keypair)) return true;
$this->keypair = array();
- $keypair = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl');
+ $keypair = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl'));
if (!empty($keypair)) {
// Explode/Implode is faster than Unserialize/Serialize
// Key generation/rotation
// 1. Archive the current key (if there is one).
- $result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl_history');
+ $result = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl_history'));
if(empty($result)) {
set_config('openssl_history', serialize(array()), 'mnet');
$openssl_history = array();
// 2. How many old keys do we want to keep? Use array_slice to get
// rid of any we don't want
- $openssl_generations = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl_generations');
+ $openssl_generations = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl_generations'));
if(empty($openssl_generations)) {
set_config('openssl_generations', 3, 'mnet');
$openssl_generations = 3;
* @return string The signature over that text
*/
function mnet_get_keypair() {
- global $CFG;
+ global $CFG, $DB;;
static $keypair = null;
if (!is_null($keypair)) return $keypair;
- if ($result = get_field('config_plugins', 'value', 'plugin', 'mnet', 'name', 'openssl')) {
+ if ($result = $DB->get_field('config_plugins', 'value', array('plugin'=>'mnet', 'name'=>'openssl'))) {
list($keypair['certificate'], $keypair['keypair_PEM']) = explode('@@@@@@@@', $result);
$keypair['privatekey'] = openssl_pkey_get_private($keypair['keypair_PEM']);
$keypair['publickey'] = openssl_pkey_get_public($keypair['certificate']);
}
function useredit_update_picture(&$usernew, &$userform) {
- global $CFG;
+ global $CFG, $DB;
if (isset($usernew->deletepicture) and $usernew->deletepicture) {
$location = make_user_directory($usernew->id, true);
@remove_dir($location);
- set_field('user', 'picture', 0, 'id', $usernew->id);
+ $DB->set_field('user', 'picture', 0, array('id'=>$usernew->id));
} else if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
- set_field('user', 'picture', 1, 'id', $usernew->id);
+ $DB->set_field('user', 'picture', 1, array('id'=>$usernew->id));
}
}
* @return string active filter label
*/
function get_label($data) {
- $rolename = get_field('role', 'name', 'id', $data['value']);
+ global $DB;
+
+ $rolename = $DB->get_field('role', 'name', array('id'=>$data['value']));
$a = new object();
$a->label = $this->_label;
if ($agree and confirm_sesskey()) { // User has agreed
if (!isguestuser()) { // Don't remember guests
- if (!set_field('user', 'policyagreed', 1, 'id', $USER->id)) {
+ if (!$DB->set_field('user', 'policyagreed', 1, array('id'=>$USER->id))) {
print_error('Could not save your agreement');
}
}
if (has_capability('moodle/course:useremail', $coursecontext) or $currentuser) { /// Can use the enable/disable email stuff
if (!empty($enable)) { /// Recieved a parameter to enable the email address
- set_field('user', 'emailstop', 0, 'id', $user->id);
+ $DB->set_field('user', 'emailstop', 0, array('id'=>$user->id));
$user->emailstop = 0;
}
if (!empty($disable)) { /// Recieved a parameter to disable the email address
- set_field('user', 'emailstop', 1, 'id', $user->id);
+ $DB->set_field('user', 'emailstop', 1, array('id'=>$user->id));
$user->emailstop = 1;
}
}