本文整理汇总了PHP中rs_close函数的典型用法代码示例。如果您正苦于以下问题:PHP rs_close函数的具体用法?PHP rs_close怎么用?PHP rs_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rs_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: block_openshare_updategroup
function block_openshare_updategroup($courseid, $groupid)
{
$sql = 'SELECT u.id FROM mdl_user u
JOIN mdl_role_assignments ra ON ra.userid = u.id
JOIN mdl_role r ON ra.roleid = r.id
JOIN mdl_context con ON ra.contextid = con.id
JOIN mdl_course c ON c.id = con.instanceid AND con.contextlevel = 50 WHERE (r.shortname = \'student\' OR r.shortname = \'teacher\' OR r.shortname = \'editingteacher\' OR r.shortname = \'coursecreator\') AND c.id = ' . $courseid;
$rs = get_recordset_sql($sql);
if (!empty($rs)) {
while ($rec = rs_fetch_next_record($rs)) {
//prep dataobject for door
$groupenroll = new object();
$groupenroll->timeadded = time();
$groupenroll->groupid = $groupid;
$groupenroll->userid = $rec->id;
$ingroup = get_record("groups_members", "groupid", $groupid, "userid", $rec->id);
if (empty($ingroup)) {
insert_record("groups_members", $groupenroll);
print 'updated' . $groupenroll->groupid . $groupenroll->userid . '<br/>';
}
}
} else {
print_error("No users in this course!");
}
// Close the recordset to save memory
rs_close($rs);
}
示例2: webquestscorm_update_grades
/**
* Update grades by firing grade_updated event
*
* @param object $assignment null means all assignments
* @param int $userid specific user only, 0 mean all
*/
function webquestscorm_update_grades($webquestscorm = null, $userid = 0, $nullifnone = true)
{
global $CFG;
if (!function_exists('grade_update')) {
//workaround for buggy PHP versions
require_once $CFG->libdir . '/gradelib.php';
}
if ($webquestscorm != null) {
if ($grades = webquestscorm_get_user_grades($webquestscorm, $userid)) {
foreach ($grades as $k => $v) {
if ($v->rawgrade == -1) {
$grades[$k]->rawgrade = null;
}
}
webquestscorm_grade_item_update($webquestscorm, $grades);
} else {
webquestscorm_grade_item_update($webquestscorm);
}
} else {
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid\n FROM {$CFG->prefix}webquestscorm a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='webquestscorm' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = get_recordset_sql($sql)) {
while ($webquestscorm = rs_fetch_next_record($rs)) {
if ($webquestscorm->grade != 0) {
webquestscorm_update_grades($webquestscorm);
} else {
webquestscorm_grade_item_update($webquestscorm);
}
}
rs_close($rs);
}
}
}
示例3: xmldb_forum_upgrade
function xmldb_forum_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2007101000) {
/// Define field timemodified to be added to forum_queue
$table = new XMLDBTable('forum_queue');
$field = new XMLDBField('timemodified');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'postid');
/// Launch add field timemodified
$result = $result && add_field($table, $field);
}
//===== 1.9.0 upgrade line ======//
if ($result and $oldversion < 2007101511) {
notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
//MDL-13866 - send forum ratins to gradebook again
require_once $CFG->dirroot . '/mod/forum/lib.php';
// too much debug output
$db->debug = false;
forum_update_grades();
$db->debug = true;
}
if ($result && $oldversion < 2007101512) {
/// Cleanup the forum subscriptions
notify('Removing stale forum subscriptions', 'notifysuccess');
$roles = get_roles_with_capability('moodle/course:view', CAP_ALLOW);
$roles = array_keys($roles);
$roles = implode(',', $roles);
$sql = "SELECT fs.userid, f.id AS forumid\n FROM {$CFG->prefix}forum f\n JOIN {$CFG->prefix}course c ON c.id = f.course\n JOIN {$CFG->prefix}context ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = " . CONTEXT_COURSE . ")\n JOIN {$CFG->prefix}forum_subscriptions fs ON fs.forum = f.id\n LEFT JOIN {$CFG->prefix}role_assignments ra ON (ra.contextid = ctx.id AND ra.userid = fs.userid AND ra.roleid IN ({$roles}))\n WHERE ra.id IS NULL";
if ($rs = get_recordset_sql($sql)) {
$db->debug = false;
while ($remove = rs_fetch_next_record($rs)) {
delete_records('forum_subscriptions', 'userid', $remove->userid, 'forum', $remove->forumid);
echo '.';
}
$db->debug = true;
rs_close($rs);
}
}
if ($result && $oldversion < 2007101513) {
delete_records('forum_ratings', 'post', 0);
/// Clean existing wrong rates. MDL-18227
}
return $result;
}
示例4: get_group_list
/**
* Return a list of groups the user belongs to that apply to this forum (same grouping)
* @param int $userid
* @param int $forumid
* @return an array of group lists or an empty array
*/
function get_group_list($userid, $forumid)
{
global $CFG;
//$courseid = forum::get_from_id($forumng->id, forum::CLONE_DIRECT)->get_course_id();
$sql_group = "\nSELECT\n g.id AS groupid\nFROM\n {$CFG->prefix}forumng f\n INNER JOIN {$CFG->prefix}course_modules cm on f.id = cm.instance \n INNER JOIN {$CFG->prefix}modules m on cm.module = m.id \n INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = {$userid} \n INNER JOIN {$CFG->prefix}groups g ON gm.groupid = g.id AND g.courseid = cm.course \n LEFT JOIN {$CFG->prefix}groupings_groups gg ON gg.groupid = g.id AND cm.groupingid = gg.groupingid \nWHERE\n f.id = {$forumid}\n AND m.name = 'forumng'\n AND (cm.groupingid = 0 or gg.id IS NOT NULL)";
$rs = forum_utils::get_recordset_sql($sql_group);
$results = array();
while ($rec = rs_fetch_next_record($rs)) {
$results[] = $rec->groupid;
}
rs_close($rs);
return $results;
}
示例5: display_search_field
function display_search_field($value = '')
{
global $CFG;
$varcharlat = sql_compare_text('content');
$varcharlong = sql_compare_text('content1');
$latlongsrs = get_recordset_sql("SELECT DISTINCT {$varcharlat} AS la, {$varcharlong} AS lo\n FROM {$CFG->prefix}data_content\n WHERE fieldid = {$this->field->id}\n ORDER BY {$varcharlat}, {$varcharlong}");
$options = array();
while ($latlong = rs_fetch_next_record($latlongsrs)) {
$options[$latlong->la . ',' . $latlong->lo] = $latlong->la . ',' . $latlong->lo;
}
rs_close($latlongsrs);
return choose_from_menu($options, 'f_' . $this->field->id, $value, 'choose', '', 0, true);
}
示例6: query_drafts
/**
* Queries for draft posts, including necessary joins with other fields.
* @param string $where Text of WHERE clause e.g. 'fdr.id=14'. May refer
* to aliases fdr (drafts), fd (discussions), fp (posts; post being
* replied to), fpfirst (first post in discussion), and u (user being
* replied to)
* @return array Array of forum_draft objects (empty if none)
*/
static function query_drafts($where)
{
global $CFG;
$result = array();
$rs = get_recordset_sql("\nSELECT\n fdr.*, fd.id AS discussionid, fpfirst.subject AS discussionsubject, \n f.course AS courseid,\n " . forum_utils::select_username_fields('u', false) . "\nFROM\n {$CFG->prefix}forumng_drafts fdr\n LEFT JOIN {$CFG->prefix}forumng_posts fp ON fdr.parentpostid = fp.id\n LEFT JOIN {$CFG->prefix}forumng_discussions fd ON fp.discussionid = fd.id\n LEFT JOIN {$CFG->prefix}forumng_posts fpfirst ON fd.postid = fpfirst.id\n LEFT JOIN {$CFG->prefix}user u ON fp.userid = u.id\n INNER JOIN {$CFG->prefix}forumng f ON fdr.forumid = f.id\nWHERE\n {$where}\nORDER BY\n fdr.saved DESC\n ");
if (!$rs) {
throw new forum_exception("Failed to query for draft posts");
}
while ($rec = rs_fetch_next_record($rs)) {
$result[] = new forum_draft($rec);
}
rs_close($rs);
return $result;
}
示例7: add_selection_all
function add_selection_all($ufiltering)
{
global $SESSION;
$guest = get_guest();
$sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1");
if ($rs = get_recordset_select('user', $sqlwhere, 'fullname', 'id,' . sql_fullname() . ' AS fullname')) {
while ($user = rs_fetch_next_record($rs)) {
if (!isset($SESSION->bulk_users[$user->id])) {
$SESSION->bulk_users[$user->id] = $user->id;
}
}
rs_close($rs);
}
}
示例8: question_multianswer_fix_subquestion_parents_and_categories
/**
* Due to MDL-14750, subquestions of multianswer questions restored from backup will
* have the wrong parent, and due to MDL-10899 subquestions of multianswer questions
* that have been moved between categories will be in the wrong category, This code fixes these up.
*/
function question_multianswer_fix_subquestion_parents_and_categories()
{
global $CFG;
$result = true;
$rs = get_recordset_sql('SELECT q.id, q.category, qma.sequence FROM ' . $CFG->prefix . 'question q JOIN ' . $CFG->prefix . 'question_multianswer qma ON q.id = qma.question');
if ($rs) {
while ($q = rs_fetch_next_record($rs)) {
if (!empty($q->sequence)) {
$result = $result && execute_sql('UPDATE ' . $CFG->prefix . 'question' . ' SET parent = ' . $q->id . ', category = ' . $q->category . ' WHERE id IN (' . $q->sequence . ') AND parent <> 0');
}
}
rs_close($rs);
} else {
$result = false;
}
return $result;
}
示例9: validation
function validation($data, $files)
{
global $CFG, $db, $USER;
$errors = parent::validation($data, $files);
$sql = stripslashes($data['querysql']);
$sql = trim($sql);
// Simple test to avoid evil stuff in the SQL.
if (preg_match('/\\b(ALTER|CREATE|DELETE|DROP|GRANT|INSERT|INTO|TRUNCATE|UPDATE)\\b/i', $sql)) {
$errors['querysql'] = get_string('notallowedwords', 'block_configurable_reports');
// Do not allow any semicolons.
} else {
if (strpos($sql, ';') !== false) {
$errors['querysql'] = get_string('nosemicolon', 'report_customsql');
// Make sure prefix is prefix_, not explicit.
} else {
if ($CFG->prefix != '' && preg_match('/\\b' . $CFG->prefix . '\\w+/i', $sql)) {
$errors['querysql'] = get_string('noexplicitprefix', 'block_configurable_reports', $CFG->prefix);
// Now try running the SQL, and ensure it runs without errors.
} else {
$sql = $this->_customdata['reportclass']->prepare_sql($sql);
$rs = $this->_customdata['reportclass']->execute_query($sql, 2);
if (!$rs) {
$errors['querysql'] = get_string('queryfailed', 'block_configurable_reports', $db->ErrorMsg());
} else {
if (!empty($data['singlerow'])) {
if (rs_EOF($rs)) {
$errors['querysql'] = get_string('norowsreturned', 'block_configurable_reports');
}
}
}
if ($rs) {
rs_close($rs);
}
}
}
}
return $errors;
}
示例10: report_customsql_generate_csv
function report_customsql_generate_csv($report, $timenow, $limitnum = REPORT_CUSTOMSQL_MAX_RECORDS)
{
global $db;
$starttime = microtime(true);
$sql = report_customsql_prepare_sql($report, $timenow);
$rs = report_customsql_execute_query($sql, $limitnum);
if (!$rs) {
throw new Exception($db->ErrorMsg());
}
$cvstimestamp = null;
while ($row = rs_fetch_next_record($rs)) {
if (!$cvstimestamp) {
list($csvfilename, $cvstimestamp) = report_customsql_csv_filename($report, $timenow);
if (!file_exists($csvfilename)) {
$handle = fopen($csvfilename, 'w');
report_customsql_start_csv($handle, $row, $report->singlerow);
} else {
$handle = fopen($csvfilename, 'a');
}
}
$data = get_object_vars($row);
if ($report->singlerow) {
array_unshift($data, strftime('%Y-%m-%d', $timenow));
}
report_customsql_write_csv_row($handle, $data);
}
rs_close($rs);
if (!empty($handle)) {
fclose($handle);
}
// Update the execution time in the DB.
$updaterecord = new stdClass();
$updaterecord->id = $report->id;
$updaterecord->lastrun = time();
$updaterecord->lastexecutiontime = round((microtime(true) - $starttime) * 1000);
update_record('report_customsql_queries', $updaterecord);
return $cvstimestamp;
}
示例11: get_userinfo
/**
* Reads any other information for a user from external database,
* then returns it in an array
*
* @param string $username (with system magic quotes)
*
* @return array without magic quotes
*/
function get_userinfo($username)
{
global $CFG;
$textlib = textlib_get_instance();
$extusername = $textlib->convert(stripslashes($username), 'utf-8', $this->config->extencoding);
$authdb = $this->db_init();
//Array to map local fieldnames we want, to external fieldnames
$selectfields = $this->db_attributes();
$result = array();
//If at least one field is mapped from external db, get that mapped data:
if ($selectfields) {
$select = '';
foreach ($selectfields as $localname => $externalname) {
$select .= ", {$externalname} AS {$localname}";
}
$select = 'SELECT ' . substr($select, 1);
$sql = $select . " FROM {$this->config->table}" . " WHERE {$this->config->fielduser} = '" . $this->ext_addslashes($extusername) . "'";
if ($rs = $authdb->Execute($sql)) {
if ($rs->RecordCount() == 1) {
$fields_obj = rs_fetch_record($rs);
foreach ($selectfields as $localname => $externalname) {
$result[$localname] = $textlib->convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
}
}
rs_close($rs);
}
}
$authdb->Close();
return $result;
}
示例12: grade_cron
/**
* Grading cron job
*/
function grade_cron()
{
global $CFG;
$now = time();
$sql = "SELECT i.*\n FROM {$CFG->prefix}grade_items i\n WHERE i.locked = 0 AND i.locktime > 0 AND i.locktime < {$now} AND EXISTS (\n SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
// go through all courses that have proper final grades and lock them if needed
if ($rs = get_recordset_sql($sql)) {
if ($rs->RecordCount() > 0) {
while ($item = rs_fetch_next_record($rs)) {
$grade_item = new grade_item($item, false);
$grade_item->locked = $now;
$grade_item->update('locktime');
}
}
rs_close($rs);
}
$grade_inst = new grade_grade();
$fields = 'g.' . implode(',g.', $grade_inst->required_fields);
$sql = "SELECT {$fields}\n FROM {$CFG->prefix}grade_grades g, {$CFG->prefix}grade_items i\n WHERE g.locked = 0 AND g.locktime > 0 AND g.locktime < {$now} AND g.itemid=i.id AND EXISTS (\n SELECT 'x' FROM {$CFG->prefix}grade_items c WHERE c.itemtype='course' AND c.needsupdate=0 AND c.courseid=i.courseid)";
// go through all courses that have proper final grades and lock them if needed
if ($rs = get_recordset_sql($sql)) {
if ($rs->RecordCount() > 0) {
while ($grade = rs_fetch_next_record($rs)) {
$grade_grade = new grade_grade($grade, false);
$grade_grade->locked = $now;
$grade_grade->update('locktime');
}
}
rs_close($rs);
}
}
示例13: scorm_update_grades
/**
* Update grades in central gradebook
*
* @param object $scorm null means all scormbases
* @param int $userid specific user only, 0 mean all
*/
function scorm_update_grades($scorm = null, $userid = 0, $nullifnone = true)
{
global $CFG;
if (!function_exists('grade_update')) {
//workaround for buggy PHP versions
require_once $CFG->libdir . '/gradelib.php';
}
if ($scorm != null) {
if ($grades = scorm_get_user_grades($scorm, $userid)) {
grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grades);
} else {
if ($userid and $nullifnone) {
$grade = new object();
$grade->userid = $userid;
$grade->rawgrade = NULL;
grade_update('mod/scorm', $scorm->course, 'mod', 'scorm', $scorm->id, 0, $grade);
}
}
} else {
$sql = "SELECT s.*, cm.idnumber as cmidnumber\n FROM {$CFG->prefix}scorm s, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
if ($rs = get_recordset_sql($sql)) {
if ($rs->RecordCount() > 0) {
while ($scorm = rs_fetch_next_record($rs)) {
scorm_grade_item_update($scorm);
scorm_update_grades($scorm, 0, false);
}
}
rs_close($rs);
}
}
}
示例14: report_security_check_riskbackup
/**
* Lists all roles that have the ability to backup user data, as well as users
* @param bool $detailed
* @return object result
*/
function report_security_check_riskbackup($detailed = false)
{
global $CFG;
$result = new object();
$result->issue = 'report_security_check_riskbackup';
$result->name = get_string('check_riskbackup_name', 'report_security');
$result->info = null;
$result->details = null;
$result->status = null;
$result->link = null;
$syscontext = get_context_instance(CONTEXT_SYSTEM);
$systemroles = get_records_sql("SELECT DISTINCT r.*\n FROM {$CFG->prefix}role r\n JOIN {$CFG->prefix}role_capabilities rc ON rc.roleid = r.id\n WHERE rc.capability = 'moodle/backup:userinfo' AND rc.contextid = {$syscontext->id} AND rc.permission = " . CAP_ALLOW . "");
$overriddenroles = get_records_sql("SELECT DISTINCT r.*, rc.contextid\n FROM {$CFG->prefix}role r\n JOIN {$CFG->prefix}role_capabilities rc ON rc.roleid = r.id\n WHERE rc.capability = 'moodle/backup:userinfo' AND rc.contextid <> {$syscontext->id} AND rc.permission = " . CAP_ALLOW . "");
// list of users that are able to backup personal info
// note: "sc" is context where is role assigned,
// "c" is context where is role overriden or system context if in role definition
$sqluserinfo = "\n FROM (SELECT rcx.*\n FROM {$CFG->prefix}role_capabilities rcx\n WHERE rcx.permission = " . CAP_ALLOW . " AND rcx.capability = 'moodle/backup:userinfo') rc,\n {$CFG->prefix}context c,\n {$CFG->prefix}context sc,\n {$CFG->prefix}role_assignments ra,\n {$CFG->prefix}user u\n WHERE c.id = rc.contextid\n AND (sc.path = c.path OR sc.path LIKE " . sql_concat('c.path', "'/%'") . " OR c.path LIKE " . sql_concat('sc.path', "'/%'") . ")\n AND u.id = ra.userid AND u.deleted = 0\n AND ra.contextid = sc.id AND ra.roleid = rc.roleid\n AND sc.contextlevel <= " . CONTEXT_COURSE . " AND c.contextlevel <= " . CONTEXT_COURSE . "";
$usercount = count_records_sql("SELECT COUNT('x') FROM (SELECT DISTINCT u.id {$sqluserinfo}) userinfo");
$systemrolecount = empty($systemroles) ? 0 : count($systemroles);
$overriddenrolecount = empty($overriddenroles) ? 0 : count($overriddenroles);
$result->status = REPORT_SECURITY_WARNING;
// there is always at least one admin
$a = (object) array('rolecount' => $systemrolecount, 'overridecount' => $overriddenrolecount, 'usercount' => $usercount);
$result->info = get_string('check_riskbackup_warning', 'report_security', $a);
if ($detailed) {
$result->details = '';
// Will be added to later
// Make a list of roles
if ($systemroles) {
$links = array();
foreach ($systemroles as $role) {
$role->url = "{$CFG->wwwroot}/{$CFG->admin}/roles/manage.php?action=edit&roleid={$role->id}";
$links[] = '<li>' . get_string('check_riskbackup_editrole', 'report_security', $role) . '</li>';
}
$links = '<ul>' . implode($links) . '</ul>';
$result->details .= get_string('check_riskbackup_details_systemroles', 'report_security', $links);
}
// Make a list of overrides to roles
$rolelinks2 = array();
if ($overriddenroles) {
$links = array();
foreach ($overriddenroles as $role) {
$context = get_context_instance_by_id($role->contextid);
if ($context->contextlevel == CONTEXT_COURSE) {
$role->name = role_get_name($role, $context);
}
$role->contextname = print_context_name($context);
$role->url = "{$CFG->wwwroot}/{$CFG->admin}/roles/override.php?contextid={$role->contextid}&roleid={$role->id}";
$links[] = '<li>' . get_string('check_riskbackup_editoverride', 'report_security', $role) . '</li>';
}
$links = '<ul>' . implode($links) . '</ul>';
$result->details .= get_string('check_riskbackup_details_overriddenroles', 'report_security', $links);
}
// Get a list of affected users as well
$rs = get_recordset_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, u.picture, u.imagealt, u.email, ra.contextid, ra.roleid\n {$sqluserinfo} ORDER BY u.lastname, u.firstname");
$users = array();
while ($user = rs_fetch_next_record($rs)) {
$context = get_context_instance_by_id($user->contextid);
$url = "{$CFG->wwwroot}/{$CFG->admin}/roles/assign.php?contextid={$user->contextid}&roleid={$user->roleid}";
$a = (object) array('fullname' => fullname($user), 'url' => $url, 'email' => $user->email, 'contextname' => print_context_name($context));
$users[] = '<li>' . get_string('check_riskbackup_unassign', 'report_security', $a) . '</li>';
}
rs_close($rs);
if (!empty($users)) {
$users = '<ul>' . implode($users) . '</ul>';
$result->details .= get_string('check_riskbackup_details_users', 'report_security', $users);
}
}
return $result;
}
示例15: backup_copy_user_files
function backup_copy_user_files($preferences)
{
global $CFG;
$status = true;
//First we check that "user_files" exists and create it if necessary
//in temp/backup/$backup_code dir
$status = check_and_create_user_files_dir($preferences->backup_unique_code);
//now get a list of users that we need for this backup.
$backup_users = get_recordset_select("backup_ids", "backup_code='{$preferences->backup_unique_code}' AND table_name='user'", "", "id, old_id");
while ($user = rs_fetch_next_record($backup_users)) {
//If this user's directory exists, copy it
$userdir = make_user_directory($user->old_id, true);
if (check_dir_exists($userdir)) {
//first remove dirroot so we can split out the folders.
$parts = explode('/', str_replace($CFG->dataroot . '/user/', '', $userdir));
$status = true;
if (is_array($parts)) {
$group = $parts[0];
$userid = $parts[1];
// Create group dir first
$status = check_dir_exists("{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/user_files/" . $group, true);
}
$status = $status && backup_copy_file($userdir, "{$CFG->dataroot}/temp/backup/{$preferences->backup_unique_code}/user_files/{$group}/{$user->old_id}");
}
//Do some output
backup_flush(30);
}
rs_close($backup_users);
return $status;
}