// fetch the record in question
$id = required_param('id', PARAM_INT);
- if (!$idrec = get_record('mnet_sso_access_control', 'id', $id)) {
+ if (!$idrec = $DB->get_record('mnet_sso_access_control', array('id'=>$id))) {
print_error('recordnoexists','mnet', "$CFG->wwwroot/$CFG->admin/mnet/access_control.php");
}
switch ($action) {
case "delete":
- delete_records('mnet_sso_access_control', 'id', $id);
+ $DB->delete_records('mnet_sso_access_control', array('id'=>$id));
redirect('access_control.php', get_string('deleteuserrecord', 'mnet', array($idrec->username, $mnethosts[$idrec->mnet_host_id])));
break;
// process the form results
-if ($form = data_submitted() and confirm_sesskey()) {
+if ($form = data_submitted(false) and confirm_sesskey()) {
// check permissions and verify form input
if (!has_capability('moodle/user:delete', $sitecontext)) {
$headings[$column] = "<a href=\"?sort=$column&dir=$columndir&\">".$string[$column]."</a>$columnicon";
}
$headings['delete'] = '';
-$acl = get_records('mnet_sso_access_control', '', '', "$sort $dir", '*'); //, $page * $perpage, $perpage);
-$aclcount = count_records('mnet_sso_access_control');
+$acl = $DB->get_records('mnet_sso_access_control', null, "$sort $dir", '*'); //, $page * $perpage, $perpage);
+$aclcount = $DB->count_records('mnet_sso_access_control');
if (!$acl) {
print_heading(get_string('noaclentries','mnet'));
* @return bool True on success, else false
*/
function mnet_get_functions($type, $parentname) {
- global $CFG;
+ global $CFG, $DB;
+
$dataobject = new stdClass();
$docname = $type.'.php';
$publishes = array();
// Disable functions that don't exist (any more) in the source
// Should these be deleted? What about their permissions records?
- $rpcrecords = get_records_select('mnet_rpc', ' parent=\''.$parentname.'\' AND parent_type=\''.$type.'\' ', 'function_name ASC ');
+ $rpcrecords = $DB->get_records('mnet_rpc', array('parent'=>$parentname, 'parent_type'=>$type), 'function_name ASC ');
if (!empty($rpcrecords)) {
foreach($rpcrecords as $rpc) {
if (!array_key_exists($rpc->function_name, $methodServiceArray)) {
$rpc->enabled = 0;
- update_record('mnet_rpc', $rpc);
+ $DB->update_record('mnet_rpc', $rpc);
}
}
}
$dataobject->parent = $parentname;
$dataobject->enabled = '0';
- if ($record_exists = get_record('mnet_rpc', 'xmlrpc_path', $dataobject->xmlrpc_path)) {
+ if ($record_exists = $DB->get_record('mnet_rpc', array('xmlrpc_path'=>$dataobject->xmlrpc_path))) {
$dataobject->id = $record_exists->id;
$dataobject->enabled = $record_exists->enabled;
- update_record('mnet_rpc', $dataobject);
+ $DB->update_record('mnet_rpc', $dataobject);
} else {
$dataobject->id = insert_record('mnet_rpc', $dataobject, true);
}
foreach($servicearray as $service) {
- $serviceobj = get_record('mnet_service', 'name', $service['name']);
+ $serviceobj = $DB->get_record('mnet_service', array('name'=>$service['name']));
if (false == $serviceobj) {
$serviceobj = new stdClass();
$serviceobj->name = $service['name'];
$serviceobj->id = insert_record('mnet_service', $serviceobj, true);
}
- if (false == get_record('mnet_service2rpc', 'rpcid', $dataobject->id, 'serviceid', $serviceobj->id)) {
+ if (false == $DB->get_record('mnet_service2rpc', array('rpcid'=>$dataobject->id, 'serviceid'=>$serviceobj->id))) {
$obj = new stdClass();
$obj->rpcid = $dataobject->id;
$obj->serviceid = $serviceobj->id;
- insert_record('mnet_service2rpc', $obj, true);
+ $DB->insert_record('mnet_service2rpc', $obj, true);
}
}
}
</td>
<td></td>
<td valign="top">
- <?php print_string('potentialusers', 'role', $availableusers->_numOfRows); ?>
+ <?php print_string('potentialusers', 'role', $availablecount); ?>
</td>
</tr>
<tr>
<?php
if (!empty($searchtext)) {
- echo "<optgroup label=\"$strsearchresults (" . $availableusers->_numOfRows . ")\">\n";
- while ($user = rs_fetch_next_record($availableusers)) {
+ echo "<optgroup label=\"$strsearchresults (" . $availablecount . ")\">\n";
+ foreach ($availableusers as $user) {
if (!isset($enrolledusers[$user->id])) {
$fullname = fullname($user, true);
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
echo "</optgroup>\n";
} else {
- if ($availableusers->_numOfRows > MAX_USERS_PER_PAGE) {
+ if ($availablecount > MAX_USERS_PER_PAGE) {
echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
.'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
} else {
- while ($user = rs_fetch_next_record($availableusers)) {
+ foreach ($availableusers as $user) {
$fullname = fullname($user, true);
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
}
include_once($CFG->dirroot.'/mnet/xmlrpc/client.php');
if (!confirm_sesskey()) {
- error(get_string('confirmsesskeybad', 'error'));
+ print_error('confirmsesskeybad', 'error');
}
admin_externalpage_setup('mnetenrol');
print_error('hostcoursenotfound','mnet');
}
- $course = get_record('mnet_enrol_course', 'id', $courseid, 'hostid', $mnet_peer->id);
+ $course = $DB->get_record('mnet_enrol_course', array('id'=>$courseid, 'hostid'=>$mnet_peer->id));
if (empty($course)) {
print_error('hostcoursenotfound','mnet');
/// Process incoming role assignment
- if ($frm = data_submitted()) {
+ if ($frm = data_submitted(false)) {
if ($add and !empty($frm->addselect) and confirm_sesskey()) {
$timemodified = time();
unset($mnet_request);
- $select = '';
$all_enrolled_usernames = '';
$timemodified = array();
/// List all the users (homed on this server) who are enrolled on the course
/// This will include mnet-enrolled users, and those who have enrolled
/// themselves, etc.
if (is_array($all_enrolled_users) && count($all_enrolled_users)) {
- foreach($all_enrolled_users as $username => $data) {
- $all_enrolled_usernames .= "'$username', ";
- }
- $select = ' u.username IN (' .substr($all_enrolled_usernames, 0, -2) .') AND ';
+ list($select, $params) = $DB->get_in_or_equal(array_keys($all_enrolled_users), SQL_PARAMS_NAMED, 'un0');
+ $select = " u.username $select AND ";
+
} else {
$all_enrolled_users = array();
+ $params = array();
+ $select = '';
}
/// Synch our mnet_enrol_assignments with remote server
COALESCE(a.hostid, 0) as wehaverecord,
a.courseid
FROM
- {$CFG->prefix}user u
+ {user} u
LEFT JOIN
- {$CFG->prefix}mnet_enrol_assignments a
+ {mnet_enrol_assignments} a
ON
- a.userid = u.id AND a.courseid={$courseid}
+ a.userid = u.id AND a.courseid=:courseid
WHERE
$select
u.deleted = 0 AND
u.confirmed = 1 AND
- u.mnethostid = {$CFG->mnet_localhost_id}
+ u.mnethostid = :mnetid
ORDER BY
u.firstname ASC,
u.lastname ASC";
+ $params['courseid'] = $courseid;
+ $params['mnetid'] = $CFG->mnet_localhost_id;
- if (!$enrolledusers = get_records_sql($sql)) {
+ if (!$enrolledusers = $DB->get_records_sql($sql, $params)) {
$enrolledusers = array();
}
$dataobj->id = insert_record('mnet_enrol_assignments', $dataobj);
} elseif (array_key_exists($user->username, $all_enrolled_users)) {
$dataobj->id = $user->enrolid;
- update_record('mnet_enrol_assignments', $dataobj);
+ $DB->update_record('mnet_enrol_assignments', $dataobj);
} elseif (is_array($all_enrolled_users) && count($all_enrolled_users)) {
- delete_record('mnet_enrol_assignments', 'id', $user->enrolid);
+ $DB->delete_record('mnet_enrol_assignments', array('id'=>$user->enrolid));
}
}
unset($enrolledusers);
a.enroltype,
a.courseid
FROM
- {$CFG->prefix}user u,
- {$CFG->prefix}mnet_enrol_assignments a
+ {user} u,
+ {mnet_enrol_assignments} a
WHERE
a.userid = u.id AND
- a.courseid={$courseid} AND
+ a.courseid=:courseid AND
a.enroltype = 'mnet' AND
u.deleted = 0 AND
u.confirmed = 1 AND
- u.mnethostid = {$CFG->mnet_localhost_id}
+ u.mnethostid = :mnetid
ORDER BY
u.firstname ASC,
u.lastname ASC";
+ $params = array();
+ $params['courseid'] = $courseid;
+ $params['mnetid'] = $CFG->mnet_localhost_id;
- if (!$mnetenrolledusers = get_records_sql($sql)) {
+ if (!$mnetenrolledusers = $DB->get_records_sql($sql, $params)) {
$mnetenrolledusers = array();
}
$sql = "
a.enroltype,
a.courseid
FROM
- {$CFG->prefix}user u,
- {$CFG->prefix}mnet_enrol_assignments a
+ {user} u,
+ {mnet_enrol_assignments} a
WHERE
a.userid = u.id AND
- a.courseid={$courseid} AND
+ a.courseid=:courseid AND
a.enroltype != 'mnet' AND
u.deleted = 0 AND
u.confirmed = 1 AND
- u.mnethostid = {$CFG->mnet_localhost_id}
+ u.mnethostid = :mnetid
ORDER BY
u.firstname ASC,
u.lastname ASC";
+ $params = array();
+ $params['courseid'] = $courseid;
+ $params['mnetid'] = $CFG->mnet_localhost_id;
- if (!$remtenrolledusers = get_records_sql($sql)) {
+ if (!$remtenrolledusers = $DB->get_records_sql($sql, $params)) {
$remtenrolledusers = array();
}
+ $params = array();
+
$select = '';
$exclude = array_merge(array_keys($mnetenrolledusers), array_keys($remtenrolledusers));
$exclude[] = 0;
$searchtext = trim($searchtext);
if ($searchtext !== '') { // Search for a subset of remaining users
- $LIKE = sql_ilike();
- $FULLNAME = sql_fullname();
+ $LIKE = $DB->sql_ilike();
+ $FULLNAME = $DB->sql_fullname();
- $select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
+ $select .= " AND ($FULLNAME $LIKE :search1 OR email $LIKE :search2) ";
+ $params['search1'] = "%$searchtext%";
+ $params['search2'] = "%$searchtext%";
}
- $sql = ('SELECT id, firstname, lastname, email
- FROM '.$CFG->prefix.'user u
- WHERE deleted = 0 AND confirmed = 1
- AND mnethostid = '.$CFG->mnet_localhost_id.' '
- .$select
- .'ORDER BY lastname ASC, firstname ASC');
-
- $availableusers = get_recordset_sql($sql, 0, MAX_USERS_PER_PAGE);
+ $sql = ("SELECT id, firstname, lastname, email
+ FROM {user} u
+ WHERE deleted = 0 AND confirmed = 1
+ AND mnethostid = :mnetid
+ $select
+ ORDER BY lastname ASC, firstname ASC");
+ $params['mnetid'] = $CFG->mnet_localhost_id;
+
+ $availableusers = $DB->get_recordset_sql($sql, $params, 0, MAX_USERS_PER_PAGE);
+
+ $sql = ("SELECT COUNT('x')
+ FROM {user} u
+ WHERE deleted = 0 AND confirmed = 1
+ AND mnethostid = :mnetid
+ $select");
+ $availablecount = $DB->count_records_sql($sql, $params);
require_once($CFG->libdir.'/adminlib.php');
if (!confirm_sesskey()) {
- error(get_string('confirmsesskeybad', 'error'));
+ print_error('confirmsesskeybad', 'error');
}
$enrolment = enrolment_factory::factory('mnet');
$mnethost = required_param('host', PARAM_INT);
- $host = get_record('mnet_host', 'id', $mnethost);
+ $host = $DB->get_record('mnet_host', array('id'=>$mnethost));
$courses = $enrolment->fetch_remote_courses($mnethost);
}
/// If data submitted, process and store
- if (($form = data_submitted()) && confirm_sesskey()) {
+ if (($form = data_submitted(false)) && confirm_sesskey()) {
if (!empty($form->submit) && $form->submit == get_string('savechanges')) {
if (in_array($form->mode, array("off", "strict", "dangerous"))) {
if (set_config('mnet_dispatcher_mode', $form->mode)) {
exit;
}
}
- $hosts = get_records_select('mnet_host', " id != '{$CFG->mnet_localhost_id}' AND deleted = '0' ",'wwwroot ASC' );
+ $hosts = $DB->get_records_select('mnet_host', "id <> ? AND deleted = 0", array($CFG->mnet_localhost_id), 'wwwroot ASC');
admin_externalpage_print_header();
?>
$mnet_peer->set_id($hostid);
$treevals = array();
foreach($_POST['exists'] as $key => $value) {
- $host2service = get_record('mnet_host2service', 'hostid', $_POST['hostid'], 'serviceid', $key);
+ $host2service = $DB->get_record('mnet_host2service', array('hostid'=>$_POST['hostid'], 'serviceid'=>$key));
$publish = (isset($_POST['publish'][$key]) && $_POST['publish'][$key] == 'on')? 1 : 0;
$subscribe = (isset($_POST['subscribe'][$key]) && $_POST['subscribe'][$key] == 'on')? 1 : 0;
// We don't have or need a record - do nothing!
} else {
// We don't need the record - delete it
- delete_records('mnet_host2service', 'hostid', $_POST['hostid'], 'serviceid', $key);
+ $DB->delete_records('mnet_host2service', array('hostid', $_POST['hostid'], 'serviceid'=>$key));
}
} elseif (false == $host2service && ($publish == 1 || $subscribe == 1)) {
$host2service = new stdClass();
$host2service->publish = $publish;
$host2service->subscribe = $subscribe;
- $host2service->id = insert_record('mnet_host2service', $host2service);
+ $host2service->id = $DB->insert_record('mnet_host2service', $host2service);
} elseif ($host2service->publish != $publish || $host2service->subscribe != $subscribe) {
$host2service->publish = $publish;
$host2service->subscribe = $subscribe;
- $tf = update_record('mnet_host2service', $host2service);
+ $tf = $DB->update_record('mnet_host2service', $host2service);
}
}
}
$id_list .= ', '.$CFG->mnet_all_hosts_id;
}
- $concat = sql_concat('COALESCE(h2s.id,0) ', ' \'-\' ', ' svc.id');
+ $concat = $DB->sql_concat('COALESCE(h2s.id,0) ', ' \'-\' ', ' svc.id');
$query = "
SELECT DISTINCT
h2s.publish,
h2s.subscribe
FROM
- {$CFG->prefix}mnet_service2rpc s2r,
- {$CFG->prefix}mnet_rpc r,
- {$CFG->prefix}mnet_service svc
+ {mnet_service2rpc} s2r,
+ {mnet_rpc} r,
+ {mnet_service} svc
LEFT JOIN
- {$CFG->prefix}mnet_host2service h2s
+ {mnet_host2service} h2s
ON
h2s.hostid in ($id_list) AND
h2s.serviceid = svc.id
ORDER BY
svc.name ASC";
- $resultset = get_records_sql($query);
+ $resultset = $DB->get_records_sql($query);
if (is_array($resultset)) {
$resultset = array_values($resultset);
include('./mnet_review_allhosts.html');
}
} else {
- $hosts = get_records_sql(' SELECT
+ $hosts = $DB->get_records_sql(' SELECT
h.id,
h.wwwroot,
h.ip_address,
a.display_name as app_display_name,
a.xmlrpc_server_url
FROM
- '.$CFG->prefix.'mnet_host h,
- '.$CFG->prefix.'mnet_application a
+ {mnet_host} h,
+ {mnet_application} a
WHERE
- h.id != \''.$CFG->mnet_localhost_id.'\' AND
- h.deleted = \'0\' AND
+ h.id <> ? AND
+ h.deleted = 0 AND
h.applicationid=a.id');
if (empty($hosts)) $hosts = array();
- $applications = get_records('mnet_application');
+ $applications = $DB->get_records('mnet_application', array($CFG->mnet_localhost_id));
include('./peers.html');
}
?>