function checkExpiredDemoUser($userid, $groups = 0) { global $mode, $skin, $noHTMLwrappers; if ($groups == 0) { $groups = getUsersGroups($userid, 1); } if (count($groups) != 1) { return; } $tmp = array_values($groups); if ($tmp[0] != 'demo') { return; } $query = "SELECT start " . "FROM log " . "WHERE userid = {$userid} " . "AND finalend < NOW() " . "ORDER BY start " . "LIMIT 3"; $qh = doQuery($query, 101); $expire = time() - SECINDAY * 3; $rows = mysql_num_rows($qh); if ($row = mysql_fetch_assoc($qh)) { if ($rows >= 3 || datetimeToUnix($row['start']) < $expire) { if (in_array($mode, $noHTMLwrappers)) { # do a redirect and handle removal on next page load so user can # be notified - doesn't always work, but handles a few extra # cases header("Location: " . BASEURL . SCRIPT); } else { $nodemoid = getUserGroupID('nodemo', getAffiliationID('ITECS')); $query = "DELETE FROM usergroupmembers " . "WHERE userid = {$userid}"; # because updateGroups doesn't # delete from custom groups doQuery($query, 101); updateGroups(array($nodemoid), $userid); checkUpdateServerRequestGroups($groupid); if (empty($skin)) { $skin = 'default'; require_once "themes/{$skin}/page.php"; } $mode = 'expiredemouser'; printHTMLHeader(); print "<h2>Account Expired</h2>\n"; print "The account you are using is a demo account that has now expired. "; print "You cannot make any more reservations. Please contact <a href=\""; print "mailto:" . HELPEMAIL . "\">" . HELPEMAIL . "</a> if you need "; print "further access to VCL.<br>\n"; } cleanSemaphore(); # probably not needed but ensures we do not leave stale entries printHTMLFooter(); dbDisconnect(); exit; } } }
function updateGroups($newusergroups, $userid) { $query = "SELECT m.usergroupid " . "FROM usergroupmembers m, " . "usergroup u " . "WHERE m.userid = {$userid} AND " . "m.usergroupid = u.id AND " . "u.custom = 0 AND " . "u.courseroll = 0"; $qh = doQuery($query, 305); $oldusergroups = array(); while ($row = mysql_fetch_row($qh)) { array_push($oldusergroups, $row[0]); } if (count(array_diff($oldusergroups, $newusergroups)) || count(array_diff($newusergroups, $oldusergroups))) { $query = "DELETE m " . "FROM usergroupmembers m, " . "usergroup u " . "WHERE m.userid = {$userid} AND " . "m.usergroupid = u.id AND " . "u.custom = 0 AND " . "u.courseroll = 0"; doQuery($query, 306); foreach ($newusergroups as $id) { $query = "INSERT INTO usergroupmembers " . "(userid, usergroupid) " . "VALUES ({$userid}, {$id}) " . "ON DUPLICATE KEY UPDATE " . "userid = {$userid}, usergroupid = {$id}"; doQuery($query, 307); checkUpdateServerRequestGroups($id); } } return $newusergroups; }