if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
// first find candidate records
$rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
- if ($rs and $rs->RecordCount() > 0) {
+ if ($rs) {
while (!$rs->EOF) {
$text = $rs->fields[$column];
$id = $rs->fields['id'];
execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false);
}
}
+ rs_close($rs);
}
}
}
// don't track passwords
$rs = $authdb->Execute("SELECT * FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ");
- $authdb->Close();
-
if (!$rs) {
+ $authdb->Close();
print_error('auth_dbcantconnect','auth');
return false;
}
- if ( $rs->RecordCount() ) {
+ if ( !$rs->EOF ) {
+ $rs->Close();
+ $authdb->Close();
// user exists exterally
// check username/password internally
if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
return validate_internal_user_password($user, $password);
}
} else {
+ $rs->Close();
+ $authdb->Close();
// user does not exist externally
return false;
}
$rs = $authdb->Execute("SELECT * FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'
AND {$this->config->fieldpass} = '".$this->ext_addslashes($extpassword)."' ");
- $authdb->Close();
-
if (!$rs) {
+ $authdb->Close();
print_error('auth_dbcantconnect','auth');
return false;
}
- if ($rs->RecordCount()) {
+ if (!$rs->EOF) {
+ $rs->Close();
+ $authdb->Close();
return true;
} else {
+ $rs->Close();
+ $authdb->Close();
return false;
}
" FROM {$this->config->table}" .
" WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'";
if ($rs = $authdb->Execute($sql)) {
- if ( $rs->RecordCount() == 1 ) {
+ if ( !$rs->EOF ) {
$fields_obj = rs_fetch_record($rs);
foreach ($selectfields as $localname=>$externalname) {
$result[$localname] = $textlib->convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
if (!$rs) {
print_error('auth_dbcantconnect','auth');
- } else if ( $rs->RecordCount() ) {
+ } else if ( !$rs->EOF ) {
// user exists exterally
- $result = $rs->RecordCount();
+ $result = true;
}
$authdb->Close();
if (!$rs) {
print_error('auth_dbcantconnect','auth');
- } else if ( $rs->RecordCount() ) {
+ } else if ( !$rs->EOF ) {
while ($rec = rs_fetch_next_record($rs)) {
array_push($result, $rec->username);
}
b.table_name = 'user'");
//If we have users to backup
- if ($users && $users->RecordCount()) {
+ if ($users && !rs_EOF($users)) {
//Begin Users tag
fwrite ($bf,start_tag("USERS",2,true));
$counter = 0;
//With every user
- while ($user = $users->FetchNextObj()) {
+ while ($user = rs_fetch_next_record($users)) {
//Begin User tag
fwrite ($bf,start_tag("USER",3,true));
//Output all user data
$status = true;
}
+ if ($users) {
+ rs_close($users);
+ }
+
return $status;
}
$existing = array();
}
- //error_log('[ENROL_DB] Found '.count($existing).' existing roles and '.$rs->RecordCount().' in external database');
- if ($rs->RecordCount() > 0) { // We found some courses
+ if (!$rs->EOF) { // We found some courses
+ //$count = 0;
$courselist = array();
while ($fields_obj = rs_fetch_next_record($rs)) { // Make a nice little array of courses to process
$courselist[] = $fields_obj->enrolremotecoursefield;
+ //$count++;
}
rs_close($rs);
+ //error_log('[ENROL_DB] Found '.count($existing).' existing roles and '.$count.' in external database');
+
foreach ($courselist as $coursefield) { /// Check the list of courses against existing
$course = get_record('course', $CFG->enrol_localcoursefield, $coursefield);
if (!is_object($course)) {
trigger_error($enroldb->ErrorMsg() .' STATEMENT: '. $sql);
return false;
}
- if ( $rs->RecordCount() == 0 ) { // no courses! outta here...
+ if ( $rs->EOF ) { // no courses! outta here...
return true;
}
trigger_error($enroldb->ErrorMsg() .' STATEMENT: '. $sql);
return false;
}
- if ( $crs->RecordCount() == 0 ) { // shouldn't happen, but cover all bases
+ if ( $crs->EOF ) { // shouldn't happen, but cover all bases
continue;
}
trigger_error($db->ErrorMsg() .' STATEMENT: '. $sql);
return false;
}
- if ( $ers->RecordCount() == 0 ) { // if this returns empty, it means we don't have the student record.
+ if ( $ers->EOF ) { // if this returns empty, it means we don't have the student record.
// should not happen -- but skip it anyway
trigger_error('weird! no user record entry?');
continue;
trigger_error($db->ErrorMsg() .' STATEMENT: '. $sql);
return false;
}
- if ( $ers->RecordCount() > 0 ) {
+ if ( !$ers->EOF ) {
while ($user_obj = rs_fetch_next_record($ers)) {
$roleid = $user_obj->roleid;
$user = $user_obj->userid;
* @return mixed array of user info, all grades and feedback or null when no more users found
*/
function next_user() {
- if (!$this->users_rs or !$this->users_rs->RecordCount()) {
+ if (!$this->users_rs) {
return false; // no users present
}
*/
function _pop() {
if (empty($this->gradestack)) {
- if (!$this->grades_rs or !$this->grades_rs->RecordCount()) {
+ if (!$this->grades_rs) {
return NULL; // no grades present
}
AND ctx.contextlevel <= ".CONTEXT_COURSE."
ORDER BY ctx.depth, ctx.path";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
- unset($rd);
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
+ unset($rd);
rs_close($rs);
}
ORDER BY ctx.depth, ctx.path";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
- unset($rd);
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
+ unset($rd);
rs_close($rs);
}
ORDER BY ctx.depth";
$rs = get_recordset_sql($sql);
$catpaths = array();
- if ($rs->RecordCount()) {
- while ($catctx = rs_fetch_next_record($rs)) {
- if ($catctx->path != ''
- && has_capability_in_accessdata($cap, $catctx, $accessdata, $doanything)) {
- $catpaths[] = $catctx->path;
- }
+ while ($catctx = rs_fetch_next_record($rs)) {
+ if ($catctx->path != ''
+ && has_capability_in_accessdata($cap, $catctx, $accessdata, $doanything)) {
+ $catpaths[] = $catctx->path;
}
}
rs_close($rs);
}
$courses = array();
$cc = 0; // keep count
- if ($rs->RecordCount()) {
- while ($c = rs_fetch_next_record($rs)) {
- // build the context obj
- $c = make_context_subobj($c);
-
- if (has_capability_in_accessdata($cap, $c->context, $accessdata, $doanything)) {
- $courses[] = $c;
- if ($limit > 0 && $cc++ > $limit) {
- break;
- }
+ while ($c = rs_fetch_next_record($rs)) {
+ // build the context obj
+ $c = make_context_subobj($c);
+
+ if (has_capability_in_accessdata($cap, $c->context, $accessdata, $doanything)) {
+ $courses[] = $c;
+ if ($limit > 0 && $cc++ > $limit) {
+ break;
}
}
}
$users = array();
$cc = 0; // keep count
- if ($rs->RecordCount()) {
- while ($u = rs_fetch_next_record($rs)) {
- // build the context obj
- $u = make_context_subobj($u);
+ while ($u = rs_fetch_next_record($rs)) {
+ // build the context obj
+ $u = make_context_subobj($u);
- $users[] = $u;
- if ($limit > 0 && $cc++ > $limit) {
- break;
- }
+ $users[] = $u;
+ if ($limit > 0 && $cc++ > $limit) {
+ break;
}
}
rs_close($rs);
WHERE rc.capability = '$capability'
AND rc.contextid IN ($contexts)";
$rs = get_recordset_sql($sql);
- if ($rs->RecordCount()) {
- while ($u = rs_fetch_next_record($rs)) {
- $roles[] = $u->roleid;
- }
+ while ($u = rs_fetch_next_record($rs)) {
+ $roles[] = $u->roleid;
}
rs_close($rs);
$roles = implode(',', $roles);
$users = array();
$cc = 0; // keep count
- if ($rs->RecordCount()) {
- while ($u = rs_fetch_next_record($rs)) {
- // build the context obj
- $u = make_context_subobj($u);
+ while ($u = rs_fetch_next_record($rs)) {
+ // build the context obj
+ $u = make_context_subobj($u);
- $users[] = $u;
- if ($limit > 0 && $cc++ > $limit) {
- break;
- }
+ $users[] = $u;
+ if ($limit > 0 && $cc++ > $limit) {
+ break;
}
}
rs_close($rs);
$raparents = array();
$lastseen = '';
if ($rs) {
- if ($rs->RecordCount()) {
- while ($ra = rs_fetch_next_record($rs)) {
- // RAs leafs are arrays to support multi
- // role assignments...
- if (!isset($accessdata['ra'][$ra->path])) {
- $accessdata['ra'][$ra->path] = array();
- }
- // only add if is not a repeat caused
- // by capability join...
- // (this check is cheaper than in_array())
- if ($lastseen !== $ra->path.':'.$ra->roleid) {
- $lastseen = $ra->path.':'.$ra->roleid;
- array_push($accessdata['ra'][$ra->path], $ra->roleid);
- $parentids = explode('/', $ra->path);
- array_shift($parentids); // drop empty leading "context"
- array_pop($parentids); // drop _this_ context
-
- if (isset($raparents[$ra->roleid])) {
- $raparents[$ra->roleid] = array_merge($raparents[$ra->roleid],
- $parentids);
- } else {
- $raparents[$ra->roleid] = $parentids;
- }
- }
- // Always add the roleded
- if (!empty($ra->capability)) {
- $k = "{$ra->path}:{$ra->roleid}";
- $accessdata['rdef'][$k][$ra->capability] = $ra->permission;
+ while ($ra = rs_fetch_next_record($rs)) {
+ // RAs leafs are arrays to support multi
+ // role assignments...
+ if (!isset($accessdata['ra'][$ra->path])) {
+ $accessdata['ra'][$ra->path] = array();
+ }
+ // only add if is not a repeat caused
+ // by capability join...
+ // (this check is cheaper than in_array())
+ if ($lastseen !== $ra->path.':'.$ra->roleid) {
+ $lastseen = $ra->path.':'.$ra->roleid;
+ array_push($accessdata['ra'][$ra->path], $ra->roleid);
+ $parentids = explode('/', $ra->path);
+ array_shift($parentids); // drop empty leading "context"
+ array_pop($parentids); // drop _this_ context
+
+ if (isset($raparents[$ra->roleid])) {
+ $raparents[$ra->roleid] = array_merge($raparents[$ra->roleid],
+ $parentids);
+ } else {
+ $raparents[$ra->roleid] = $parentids;
}
}
- unset($ra);
+ // Always add the roleded
+ if (!empty($ra->capability)) {
+ $k = "{$ra->path}:{$ra->roleid}";
+ $accessdata['rdef'][$k][$ra->capability] = $ra->permission;
+ }
}
+ unset($ra);
rs_close($rs);
}
$rs = get_recordset_sql($sql);
unset($clauses);
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$rd->roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
- unset($rd);
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$rd->roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
+ unset($rd);
rs_close($rs);
}
ORDER BY sctx.depth, sctx.path, ra.roleid";
$rs = get_recordset_sql($sql);
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$rd->roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
- unset($rd);
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$rd->roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
+ unset($rd);
rs_close($rs);
return $accessdata;
// Read in the RAs
//
$localroles = array();
- if ($rs->RecordCount()) {
- while ($ra = rs_fetch_next_record($rs)) {
- if (!isset($accessdata['ra'][$ra->path])) {
- $accessdata['ra'][$ra->path] = array();
- }
- array_push($accessdata['ra'][$ra->path], $ra->roleid);
- array_push($localroles, $ra->roleid);
+ while ($ra = rs_fetch_next_record($rs)) {
+ if (!isset($accessdata['ra'][$ra->path])) {
+ $accessdata['ra'][$ra->path] = array();
}
+ array_push($accessdata['ra'][$ra->path], $ra->roleid);
+ array_push($localroles, $ra->roleid);
}
rs_close($rs);
ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$rd->roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$rd->roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
rs_close($rs);
} else {
ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
$rs = get_recordset_sql($sql);
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
rs_close($rs);
AND rc.roleid = {$roleid}
ORDER BY ctx.depth, ctx.path";
$rs = get_recordset_sql($sql);
- if ($rs->RecordCount()) {
- while ($rd = rs_fetch_next_record($rs)) {
- $k = "{$rd->path}:{$roleid}";
- $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
- }
+ while ($rd = rs_fetch_next_record($rs)) {
+ $k = "{$rd->path}:{$roleid}";
+ $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
}
rs_close($rs);
WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_GROUP . "
";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount()) {
- begin_sql();
- $tx = true;
- while ($tx && $ctx = rs_fetch_next_record($rs)) {
- $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
- }
- rs_close($rs);
- if ($tx) {
- commit_sql();
- return true;
- }
- rollback_sql();
- return false;
+ begin_sql();
+ $tx = true;
+ while ($tx && $ctx = rs_fetch_next_record($rs)) {
+ $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
}
rs_close($rs);
+ if ($tx) {
+ commit_sql();
+ return true;
+ }
+ rollback_sql();
+ return false;
+ rs_close($rs);
}
return true;
}
";
$rs = get_recordset_sql($sql);
$records = array();
- if ($rs->RecordCount()) {
- while ($rec = rs_fetch_next_record($rs)) {
- $records[$rec->id] = $rec;
- $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
- }
- }
+ while ($rec = rs_fetch_next_record($rs)) {
+ $records[$rec->id] = $rec;
+ $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
+ }
rs_close($rs);
return $records;
break;
";
$rs = get_recordset_sql($sql);
$records = array();
- if ($rs->RecordCount()) {
- while ($rec = rs_fetch_next_record($rs)) {
- $records[$rec->id] = $rec;
- $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
- }
+ while ($rec = rs_fetch_next_record($rs)) {
+ $records[$rec->id] = $rec;
+ $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
}
rs_close($rs);
return $records;
$rs = get_recordset_sql($sql);
$roles = array();
- if ($rs->RecordCount()) {
- while ($r = rs_fetch_next_record($rs)) {
- $roles[$r->id] = $r->{$field};
- }
+ while ($r = rs_fetch_next_record($rs)) {
+ $roles[$r->id] = $r->{$field};
}
+ rs_close($rs);
foreach ($roles as $roleid => $rolename) {
$roles[$roleid] = strip_tags(format_string($rolename, true));
}
* Checks if user exists in external db
*
* @param string $username (with system magic quotes)
+ * @return bool
*/
function user_exists() {
//override if needed
}
$totalcount = 0;
- if (!$limitnum) {
- $limitnum = $rs->RecordCount();
- }
-
if (!$limitfrom) {
$limitfrom = 0;
}
// iteration will have to be done inside loop to keep track of the limitfrom and limitnum
- if ($rs->RecordCount()) {
- while ($course = rs_fetch_next_record($rs)) {
- $course = make_context_subobj($course);
- if ($course->visible <= 0) {
- // for hidden courses, require visibility check
- if (has_capability('moodle/course:viewhiddencourses', $course->context)) {
- $totalcount++;
- if ($totalcount > $limitfrom && count($visiblecourses) < $limitnum) {
- $visiblecourses [] = $course;
- }
- }
- } else {
+ while ($course = rs_fetch_next_record($rs)) {
+ $course = make_context_subobj($course);
+ if ($course->visible <= 0) {
+ // for hidden courses, require visibility check
+ if (has_capability('moodle/course:viewhiddencourses', $course->context)) {
$totalcount++;
- if ($totalcount > $limitfrom && count($visiblecourses) < $limitnum) {
+ if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
$visiblecourses [] = $course;
}
}
+ } else {
+ $totalcount++;
+ if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
+ $visiblecourses [] = $course;
+ }
}
}
+ rs_close($rs);
return $visiblecourses;
/**
// This loop is fairly stupid as it stands - might get better
// results doing an initial pass clustering RAs by path.
- if ($rs->RecordCount()) {
- while ($ra = rs_fetch_next_record($rs)) {
- $user = new StdClass;
- $user->id = $ra->userid; unset($ra->userid);
- $user->firstname = $ra->firstname; unset($ra->firstname);
- $user->lastname = $ra->lastname; unset($ra->lastname);
- $ra->user = $user;
- if ($ra->contextlevel == CONTEXT_SYSTEM) {
+ while ($ra = rs_fetch_next_record($rs)) {
+ $user = new StdClass;
+ $user->id = $ra->userid; unset($ra->userid);
+ $user->firstname = $ra->firstname; unset($ra->firstname);
+ $user->lastname = $ra->lastname; unset($ra->lastname);
+ $ra->user = $user;
+ if ($ra->contextlevel == CONTEXT_SYSTEM) {
+ foreach ($courses as $k => $course) {
+ $courses[$k]->managers[] = $ra;
+ }
+ } elseif ($ra->contextlevel == CONTEXT_COURSECAT) {
+ if ($allcats === false) {
+ // It always applies
foreach ($courses as $k => $course) {
$courses[$k]->managers[] = $ra;
}
- } elseif ($ra->contextlevel == CONTEXT_COURSECAT) {
- if ($allcats === false) {
- // It always applies
- foreach ($courses as $k => $course) {
+ } else {
+ foreach ($courses as $k => $course) {
+ // Note that strpos() returns 0 as "matched at pos 0"
+ if (strpos($course->context->path, $ra->path.'/')===0) {
+ // Only add it to subpaths
$courses[$k]->managers[] = $ra;
}
- } else {
- foreach ($courses as $k => $course) {
- // Note that strpos() returns 0 as "matched at pos 0"
- if (strpos($course->context->path, $ra->path.'/')===0) {
- // Only add it to subpaths
- $courses[$k]->managers[] = $ra;
- }
- }
}
- } else { // course-level
- if(!array_key_exists($ra->instanceid, $courses)) {
- //this course is not in a list, probably a frontpage course
- continue;
- }
- $courses[$ra->instanceid]->managers[] = $ra;
}
+ } else { // course-level
+ if(!array_key_exists($ra->instanceid, $courses)) {
+ //this course is not in a list, probably a frontpage course
+ continue;
+ }
+ $courses[$ra->instanceid]->managers[] = $ra;
}
}
-
-
-
+ rs_close($rs);
}
return $courses;
$rs = get_recordset_sql($sql);
$courses = array();
$cc = 0; // keep count
- if ($rs->RecordCount()) {
- while ($c = rs_fetch_next_record($rs)) {
- // build the context obj
- $c = make_context_subobj($c);
+ while ($c = rs_fetch_next_record($rs)) {
+ // build the context obj
+ $c = make_context_subobj($c);
- $courses[$c->id] = $c;
- if ($limit > 0 && $cc++ > $limit) {
- break;
- }
+ $courses[$c->id] = $c;
+ if ($limit > 0 && $cc++ > $limit) {
+ break;
}
}
rs_close($rs);
// Using a temporary array instead of $cats here, to avoid a "true" result when isnull($cats) further down
$categories = array();
- if ($rs->RecordCount()) {
- while ($course_cat = rs_fetch_next_record($rs)) {
- // build the context obj
- $course_cat = make_context_subobj($course_cat);
- $categories[$course_cat->id] = $course_cat;
- }
+ while ($course_cat = rs_fetch_next_record($rs)) {
+ // build the context obj
+ $course_cat = make_context_subobj($course_cat);
+ $categories[$course_cat->id] = $course_cat;
}
+ rs_close($rs);
if (!empty($categories)) {
$cats = $categories;
}
unset($course_cat);
- rs_close($rs);
}
//
// Strangely, get_my_courses() is expected to return the
$rs = get_recordset_sql($sql);
- if ($rs->RecordCount()){ // we have some orphans
+ if (!rs_EOF($rs)) { // we have some orphans
// the "default" category is the lowest numbered...
$default = get_field_sql("SELECT MIN(id)
rollback_sql();
}
}
+ rs_close($rs);
}
/**
modify_database('', "ALTER TABLE prefix_log_display ADD UNIQUE `moduleaction`(`module` , `action`)");
// Insert the records back in, sans duplicates.
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs) {
while (!$rs->EOF) {
$sql = "INSERT INTO {$CFG->prefix}log_display ".
"VALUES('', '".$rs->fields['module']."', ".
execute_sql($sql, false);
$rs->MoveNext();
}
+ rs_close($rs);
}
}
modify_database('', 'CREATE INDEX prefix_log_display_moduleaction ON prefix_log_display (module,action)');
// Insert the records back in, sans duplicates.
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs) {
while (!$rs->EOF) {
$sql = "INSERT INTO {$CFG->prefix}log_display ".
"VALUES('', '".$rs->fields['module']."', ".
execute_sql($sql, false);
$rs->MoveNext();
}
+ rs_close($rs);
}
}
if ($result) {
require_once($CFG->libdir.'/db/upgradelib.php');
if ($rs = get_recordset('course')) {
- if ($rs->RecordCount() > 0) {
- while ($course = rs_fetch_next_record($rs)) {
- // this function uses SQL only, it must not be changed after 1.9 goes stable!!
- if (!upgrade_18_gradebook($course->id)) {
- $result = false;
- break;
- }
+ while ($course = rs_fetch_next_record($rs)) {
+ // this function uses SQL only, it must not be changed after 1.9 goes stable!!
+ if (!upgrade_18_gradebook($course->id)) {
+ $result = false;
+ break;
}
}
rs_close($rs);
$tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
if ($rs = get_recordset('tags')) {
$db->debug = false;
- if ($rs->RecordCount() > 0) {
- while ($oldtag = rs_fetch_next_record($rs)) {
- $raw_normalized = clean_param($oldtag->text, PARAM_TAG);
- $normalized = moodle_strtolower($raw_normalized);
- // if this tag does not exist in tag table yet
- if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
- $itag = new object();
- $itag->name = $normalized;
- $itag->rawname = $raw_normalized;
- $itag->userid = $oldtag->userid;
- $itag->timemodified = time();
- $itag->descriptionformat = 0; // default format
- if ($oldtag->type == 'official') {
- $itag->tagtype = 'official';
- } else {
- $itag->tagtype = 'default';
- }
-
- if ($idx = insert_record('tag', $itag)) {
- $tagrefs[$oldtag->id] = $idx;
- }
- // if this tag is already used by tag table
+ while ($oldtag = rs_fetch_next_record($rs)) {
+ $raw_normalized = clean_param($oldtag->text, PARAM_TAG);
+ $normalized = moodle_strtolower($raw_normalized);
+ // if this tag does not exist in tag table yet
+ if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
+ $itag = new object();
+ $itag->name = $normalized;
+ $itag->rawname = $raw_normalized;
+ $itag->userid = $oldtag->userid;
+ $itag->timemodified = time();
+ $itag->descriptionformat = 0; // default format
+ if ($oldtag->type == 'official') {
+ $itag->tagtype = 'official';
} else {
- $tagrefs[$oldtag->id] = $newtag->id;
+ $itag->tagtype = 'default';
}
+
+ if ($idx = insert_record('tag', $itag)) {
+ $tagrefs[$oldtag->id] = $idx;
+ }
+ // if this tag is already used by tag table
+ } else {
+ $tagrefs[$oldtag->id] = $newtag->id;
}
}
$db->debug = true;
// fetch all the tag instances and migrate them as well
if ($rs = get_recordset('blog_tag_instance')) {
$db->debug = false;
- if ($rs->RecordCount() > 0) {
- while ($blogtag = rs_fetch_next_record($rs)) {
- if (array_key_exists($blogtag->tagid, $tagrefs)) {
- $tag_instance = new object();
- $tag_instance->tagid = $tagrefs[$blogtag->tagid];
- $tag_instance->itemtype = 'blog';
- $tag_instance->itemid = $blogtag->entryid;
- $tag_instance->ordering = 1; // does not matter much, because originally there was no ordering in blogs
- $tag_instance->timemodified = time();
- insert_record('tag_instance', $tag_instance);
- }
+ while ($blogtag = rs_fetch_next_record($rs)) {
+ if (array_key_exists($blogtag->tagid, $tagrefs)) {
+ $tag_instance = new object();
+ $tag_instance->tagid = $tagrefs[$blogtag->tagid];
+ $tag_instance->itemtype = 'blog';
+ $tag_instance->itemid = $blogtag->entryid;
+ $tag_instance->ordering = 1; // does not matter much, because originally there was no ordering in blogs
+ $tag_instance->timemodified = time();
+ insert_record('tag_instance', $tag_instance);
}
}
$db->debug = true;
$limitfrom = 0; /// Number of records to skip
$limitnum = 1; /// Number of records to retrieve
- $rs = get_recordset_sql($sql, $limitfrom, $limitnum);
+ if (!$rs = get_recordset_sql($sql, $limitfrom, $limitnum)) {
+ return false;
+ }
- if ($rs && $rs->RecordCount() > 0) {
- return true;
+ if (rs_EOF($rs)) {
+ $result = false;
} else {
- return false;
+ $result = true;
}
+
+ rs_close($rs);
+ return $result;
}
/**
global $CFG;
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs && !rs_EOF($rs)) {
/// First of all, we are going to get the name of the first column
/// to introduce it back after transforming the recordset to assoc array
/// See http://docs.moodle.org/en/XMLDB_Problems, fetch mode problem.
function recordset_to_menu($rs) {
global $CFG;
$menu = array();
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs && !rs_EOF($rs)) {
$keys = array_keys($rs->fields);
$key0=$keys[0];
$key1=$keys[1];
return false;
}
- if ( $rs->RecordCount() > 0 ) {
+ if ( !rs_EOF($rs) ) {
$keys = array_keys($rs->fields);
$key0 = $keys[0];
$results = array();
array_walk($results, 'onespace2empty');
}
/// End of DIRTY HACK
+ rs_close($rs);
return $results;
} else {
+ rs_close($rs);
return false;
}
}
}
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($qhandler = rs_fetch_next_record($rs)) {
- if (in_array($qhandler->handlerid, $failed)) {
- // do not try to dispatch any later events when one already failed
- continue;
- }
- $status = events_process_queued_handler($qhandler);
- if ($status === false) {
- $failed[] = $qhandler->handlerid;
- } else {
- $processed++;
- }
+ while ($qhandler = rs_fetch_next_record($rs)) {
+ if (in_array($qhandler->handlerid, $failed)) {
+ // do not try to dispatch any later events when one already failed
+ continue;
+ }
+ $status = events_process_queued_handler($qhandler);
+ if ($status === false) {
+ $failed[] = $qhandler->handlerid;
+ } else {
+ $processed++;
}
}
rs_close($rs);
// group the results by userid and aggregate the grades for this user
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- $prevuser = 0;
- $grade_values = array();
- $excluded = array();
- $oldgrade = null;
- while ($used = rs_fetch_next_record($rs)) {
- if ($used->userid != $prevuser) {
- $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);
- $prevuser = $used->userid;
- $grade_values = array();
- $excluded = array();
- $oldgrade = null;
- }
- $grade_values[$used->itemid] = $used->finalgrade;
- if ($used->excluded) {
- $excluded[] = $used->itemid;
- }
- if ($this->grade_item->id == $used->itemid) {
- $oldgrade = $used;
- }
+ $prevuser = 0;
+ $grade_values = array();
+ $excluded = array();
+ $oldgrade = null;
+ while ($used = rs_fetch_next_record($rs)) {
+ if ($used->userid != $prevuser) {
+ $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);
+ $prevuser = $used->userid;
+ $grade_values = array();
+ $excluded = array();
+ $oldgrade = null;
+ }
+ $grade_values[$used->itemid] = $used->finalgrade;
+ if ($used->excluded) {
+ $excluded[] = $used->itemid;
+ }
+ if ($this->grade_item->id == $used->itemid) {
+ $oldgrade = $used;
}
- $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
}
+ $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
rs_close($rs);
}
$now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
if ($rs = get_recordset_select('grade_grades', "itemid IN ($items_sql) AND locked = 0 AND locktime > 0 AND locktime < $now")) {
- if ($rs->RecordCount() > 0) {
- while ($grade = rs_fetch_next_record($rs)) {
- $grade_grade = new grade_grade($grade, false);
- $grade_grade->locked = time();
- $grade_grade->update('locktime');
- }
+ while ($grade = rs_fetch_next_record($rs)) {
+ $grade_grade = new grade_grade($grade, false);
+ $grade_grade->locked = time();
+ $grade_grade->update('locktime');
}
rs_close($rs);
}
$rs = get_recordset('grade_grades', 'itemid', $this->id, '', $fields);
}
if ($rs) {
- if ($rs->RecordCount() > 0) {
- while ($grade_record = rs_fetch_next_record($rs)) {
- $grade = new grade_grade($grade_record, false);
+ while ($grade_record = rs_fetch_next_record($rs)) {
+ $grade = new grade_grade($grade_record, false);
- if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
- // this grade is locked - final grade must be ok
- continue;
- }
+ if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
+ // this grade is locked - final grade must be ok
+ continue;
+ }
- $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
+ $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
- if ($grade_record->finalgrade !== $grade->finalgrade) {
- if (!$grade->update('system')) {
- $result = "Internal error updating final grade";
- }
+ if ($grade_record->finalgrade !== $grade->finalgrade) {
+ if (!$grade->update('system')) {
+ $result = "Internal error updating final grade";
}
}
}
// group the grades by userid and use formula on the group
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- $prevuser = 0;
- $grade_records = array();
- $oldgrade = null;
- while ($used = rs_fetch_next_record($rs)) {
- if ($used->userid != $prevuser) {
- if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
- $return = false;
- }
- $prevuser = $used->userid;
- $grade_records = array();
- $oldgrade = null;
- }
- if ($used->itemid == $this->id) {
- $oldgrade = $used;
+ $prevuser = 0;
+ $grade_records = array();
+ $oldgrade = null;
+ while ($used = rs_fetch_next_record($rs)) {
+ if ($used->userid != $prevuser) {
+ if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
+ $return = false;
}
- $grade_records['gi'.$used->itemid] = $used->finalgrade;
+ $prevuser = $used->userid;
+ $grade_records = array();
+ $oldgrade = null;
}
- if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
- $return = false;
+ if ($used->itemid == $this->id) {
+ $oldgrade = $used;
}
+ $grade_records['gi'.$used->itemid] = $used->finalgrade;
+ }
+ if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
+ $return = false;
}
- rs_close($rs);
}
+ rs_close($rs);
return $return;
}
// 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');
- }
+ 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);
}
// 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');
- }
+ 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);
}
switch ($dbfamily) {
case 'mysql':
$rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs && !$rs->EOF) { // rs_EOF() not available yet
$records = $rs->GetAssoc(true);
$encoding = $records['character_set_database']['Value'];
if (strtoupper($encoding) == 'UTF8') {
case 'postgres':
/// Get PostgreSQL server_encoding value
$rs = $db->Execute("SHOW server_encoding");
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs && !$rs->EOF) { // rs_EOF() not available yet
$encoding = $rs->fields['server_encoding'];
if (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8') {
$unicodedb = true;
case 'oracle':
/// Get Oracle DB character set value
$rs = $db->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
- if ($rs && $rs->RecordCount() > 0) {
+ if ($rs && !$rs->EOF) { // rs_EOF() not available yet
$encoding = $rs->fields['value'];
if (strtoupper($encoding) == 'AL32UTF8') {
$unicodedb = true;
if ($CFG->dbfamily == 'postgres') {
$rs = $db->Execute("SELECT relname FROM pg_class WHERE relname = '{$tablename}_id_seq' AND relkind = 'S';");
- if ($rs && $rs->RecordCount()) {
+ if ($rs && !rs_EOF($rs)) {
_private_execute_sql("DROP SEQUENCE {$tablename}_id_seq;", $db);
}
}
FROM {$CFG->prefix}assignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($assignment = rs_fetch_next_record($rs)) {
- assignment_grade_item_update($assignment);
- if ($assignment->grade != 0) {
- assignment_update_grades($assignment);
- }
+ while ($assignment = rs_fetch_next_record($rs)) {
+ assignment_grade_item_update($assignment);
+ if ($assignment->grade != 0) {
+ assignment_update_grades($assignment);
}
}
rs_close($rs);
ORDER BY timestamp DESC", 1)) {
return false;
}
- if ($rs->RecordCount() == 1) {
- return rs_fetch_record($rs);
- } else {
- return false; // Found no records
- }
+
+ $result = rs_fetch_record($rs);
+
+ rs_close($result);
+
+ return $result;
}
FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($data = rs_fetch_next_record($rs)) {
- data_grade_item_update($data);
- if ($data->assessed) {
- data_update_grades($data, 0, false);
- }
+ while ($data = rs_fetch_next_record($rs)) {
+ data_grade_item_update($data);
+ if ($data->assessed) {
+ data_update_grades($data, 0, false);
}
}
rs_close($rs);
FROM {$CFG->prefix}forum f, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($forum = rs_fetch_next_record($rs)) {
- forum_grade_item_update($forum);
- if ($forum->assessed) {
- forum_update_grades($forum, 0, false);
- }
+ while ($forum = rs_fetch_next_record($rs)) {
+ forum_grade_item_update($forum);
+ if ($forum->assessed) {
+ forum_update_grades($forum, 0, false);
}
}
rs_close($rs);
FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($glossary = rs_fetch_next_record($rs)) {
- glossary_grade_item_update($glossary);
- if ($glossary->assessed) {
- glossary_update_grades($glossary, 0, false);
- }
+ while ($glossary = rs_fetch_next_record($rs)) {
+ glossary_grade_item_update($glossary);
+ if ($glossary->assessed) {
+ glossary_update_grades($glossary, 0, false);
}
}
rs_close($rs);
GROUP BY userid, hotpot
HAVING COUNT(*)>1 AND MIN(status)=1
");
- if ($rs && $rs->RecordCount()) {
+ if ($rs && !$rs->EOF) {
$records = $rs->GetArray();
// start message to browser
switch (strtolower($CFG->dbfamily)) {
case 'mysql' :
$rs = $db->Execute("SHOW INDEX FROM `$table`");
- if ($rs && $rs->RecordCount()>0) {
+ if ($rs && !$rs->EOF) {
$records = $rs->GetArray();
foreach ($records as $record) {
if (isset($record['Key_name']) && $record['Key_name']==$index) {
break;
case 'postgres' :
$rs = $db->Execute("SELECT relname FROM pg_class WHERE relname = '$index' AND relkind='i'");
- if ($rs && $rs->RecordCount()>0) {
+ if ($rs && !$rs->EOF) {
$exists = true;
}
break;
if (empty($rs) && debugging()) {
notify($db->ErrorMsg()."<br /><br />$sql");
}
- return ($rs && $rs->RecordCount()>0);
+ return ($rs && !$rs->EOF);
}
function hotpot_db_remove_table($table, $feedback=true) {
global $CFG;
// (except lib/adodb/drivers/adodb-postgre64-inc.php)
$dbversion = '';
$rs = $db->Execute("SELECT version()");
- if ($rs && $rs->RecordCount()>0) {
+ if ($rs && !$rs->EOF) {
$records = $rs->GetArray();
if (preg_match('/\d+\.\d+/', $records[0][0], $matches)) {
$dbversion = $matches[0];
FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($hotpot = rs_fetch_next_record($rs)) {
- hotpot_grade_item_update($hotpot);
- hotpot_update_grades($hotpot, 0, false);
- }
+ while ($hotpot = rs_fetch_next_record($rs)) {
+ hotpot_grade_item_update($hotpot);
+ hotpot_update_grades($hotpot, 0, false);
}
rs_close($rs);
}
FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($lesson = rs_fetch_next_record($rs)) {
- lesson_grade_item_update($lesson);
- if ($lesson->grade != 0) {
- lesson_update_grades($lesson, 0, false);
- }
+ while ($lesson = rs_fetch_next_record($rs)) {
+ lesson_grade_item_update($lesson);
+ if ($lesson->grade != 0) {
+ lesson_update_grades($lesson, 0, false);
}
}
rs_close($rs);
FROM {$CFG->prefix}quiz a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
if ($rs = get_recordset_sql($sql)) {
- if ($rs->RecordCount() > 0) {
- while ($quiz = rs_fetch_next_record($rs)) {
- quiz_grade_item_update($quiz);
- if ($quiz->grade != 0) {
- quiz_update_grades($quiz, 0, false);
- }
+ while ($quiz = rs_fetch_next_record($rs)) {
+ quiz_grade_item_update($quiz);
+ if ($quiz->grade != 0) {
+ quiz_update_grades($quiz, 0, false);
}
}
rs_close($rs);
FROM {$CFG->prefix}scorm s, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
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);
- }
+ while ($scorm = rs_fetch_next_record($rs)) {
+ scorm_grade_item_update($scorm);
+ scorm_update_grades($scorm, 0, false);
}
rs_close($rs);
}
if (PHP_OS == "WINNT") {
$ldb =& $this->connect_win($filename);
$qset = $ldb->Execute("$sql");
- if ( $qset->RecordCount() > 0 ) {
+ if ( !$qset->EOF ) {
$records = $qset->GetAssoc(true);
} else {
$this->err("There were no records in the database.",$dsn);
if (PHP_OS == "WINNT") {
$ldb =& $this->connect_win($filename);
$qset = $ldb->Execute("$sql");
- if ( $qset->RecordCount() > 0 ) {
+ if ( !$qset->EOF ) {
$records = $qset->GetArray(true);
foreach ($records as $record) {
$categories[$record[0]] = $record[0];
$timeformat = get_string('strftimedate');
- if ($userlist->RecordCount() > 0) {
+ if ($userlist) {
while ($user = rs_fetch_next_record($userlist)) {
$user = make_context_subobj($user);
if ($user->hidden) {
print_footer($course);
-
+ if ($userlist) {
+ rs_close($userlist);
+ }
function get_lastaccess_sql($accesssince='') {