示例#1
0
function updateEXAMPLE1Groups($user)
{
    global $authMechs;
    $auth = $authMechs['EXAMPLE1 LDAP'];
    $ds = ldap_connect("ldaps://{$auth['server']}/");
    if (!$ds) {
        return 0;
    }
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
    $res = ldap_bind($ds, $auth['masterlogin'], $auth['masterpwd']);
    if (!$res) {
        return 0;
    }
    $search = ldap_search($ds, $auth['binddn'], "{$auth['unityid']}={$user['unityid']}", array('memberof'), 0, 10, 15);
    if (!$search) {
        return 0;
    }
    $data = ldap_get_entries($ds, $search);
    $newusergroups = array();
    if (!array_key_exists('memberof', $data[0])) {
        return;
    }
    for ($i = 0; $i < $data[0]['memberof']['count']; $i++) {
        if (preg_match('/^CN=(.+),OU=CourseRolls,DC=example1,DC=com/', $data[0]['memberof'][$i], $match) || preg_match('/^CN=(Students_Enrolled),OU=Students,DC=example1,DC=com$/', $data[0]['memberof'][$i], $match) || preg_match('/^CN=(Staff),OU=IT,DC=example1,DC=com$/', $data[0]['memberof'][$i], $match)) {
            array_push($newusergroups, getUserGroupID($match[1], $user['affiliationid']));
        }
    }
    $newusergroups = array_unique($newusergroups);
    updateGroups($newusergroups, $user["id"]);
}
示例#2
0
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;
        }
    }
}
示例#3
0
function editOrAddGroup($state)
{
    global $submitErr, $user, $mode;
    $usergroups = getUserGroups();
    $type = getContinuationVar("type");
    if ($state) {
        $isowner = 1;
    } elseif ($type == 'resource') {
        $isowner = getContinuationVar('isowner');
    }
    if (!$state) {
        $groupid = getContinuationVar('groupid', processInputVar('groupid', ARG_NUMERIC));
        if ($type == 'user') {
            if (!array_key_exists($groupid, $usergroups)) {
                print "<h2>Edit User Group</h2>\n";
                print "The selected user group does not exist.\n";
                return;
            }
            $isowner = 0;
            if ($usergroups[$groupid]['ownerid'] != $user['id']) {
                if ($usergroups[$groupid]['custom'] == 0 || $usergroups[$groupid]['courseroll'] == 1) {
                    if (!checkUserHasPerm('Manage Federated User Groups (global)') && (!checkUserHasPerm('Manage Federated User Groups (affiliation only)') || $usergroups[$groupid]['groupaffiliationid'] != $user['affiliationid'])) {
                        print "<h2>Edit User Group</h2>\n";
                        print "You do not have access to modify the selected user group.\n";
                        return;
                    } else {
                        $isowner = 1;
                    }
                } elseif (!array_key_exists("editgroupid", $usergroups[$groupid]) || !array_key_exists($usergroups[$groupid]["editgroupid"], $user["groups"])) {
                    print "<h2>Edit User Group</h2>\n";
                    print "You do not have access to modify the selected user group.\n";
                    return;
                }
            } else {
                $isowner = 1;
            }
        } else {
            $userresources = getUserResources(array("groupAdmin"), array("manageGroup"), 1);
            $noaccess = 1;
            foreach (array_keys($userresources) as $rtype) {
                if (array_key_exists($groupid, $userresources[$rtype])) {
                    $noaccess = 0;
                    break;
                }
            }
            if ($noaccess) {
                print "<h2>Edit Resource Group</h2>\n";
                print "You do not have access to modify the selected resource group.\n";
                return;
            }
        }
    }
    $allcustomgroups = getUserGroups(1);
    if ($user['showallgroups']) {
        $affilusergroups = $allcustomgroups;
    } else {
        $affilusergroups = getUserGroups(1, $user['affiliationid']);
    }
    $defaultusergroupid = getUserGroupID('Default for Editable by', 1);
    if ($type == 'resource') {
        $dispUserGrpIDs = array();
        $dispUserGrpIDsAllAffils = array();
        foreach (array_keys($allcustomgroups) as $id) {
            # figure out if user is owner or in editor group
            $owner = 0;
            $editor = 0;
            if ($allcustomgroups[$id]["ownerid"] == $user["id"]) {
                $owner = 1;
            }
            if (array_key_exists("editgroupid", $allcustomgroups[$id]) && array_key_exists($allcustomgroups[$id]["editgroupid"], $user["groups"])) {
                $editor = 1;
            }
            if (!$owner && !$editor) {
                continue;
            }
            if ($user['showallgroups']) {
                $dispUserGrpIDs[$id] = $allcustomgroups[$id]['name'];
            } elseif (array_key_exists($id, $affilusergroups) && $allcustomgroups[$id]['groupaffiliation'] == $user['affiliation']) {
                $dispUserGrpIDs[$id] = $allcustomgroups[$id]['name'];
            }
            $dispUserGrpIDsAllAffils[$id] = $allcustomgroups[$id]['name'];
        }
    }
    $resourcegroups = getResourceGroups();
    $affils = getAffiliations();
    $resourcetypes = getTypes("resources");
    if ($submitErr) {
        $data = processGroupInput(0);
        if ($mode == "submitEditGroup") {
            $id = $data["groupid"];
            if ($data["type"] == "resource") {
                list($grouptype, $junk) = explode('/', $resourcegroups[$id]["name"]);
                $ownerid = $resourcegroups[$id]["ownerid"];
            }
        } else {
            if ($data["type"] == "resource") {
                if ($state) {
                    $grouptype = $resourcetypes['resources'][$data['resourcetypeid']];
                } else {
                    list($grouptype, $junk) = explode('/', $resourcegroups[$data['groupid']]["name"]);
                }
                $ownerid = $data["ownergroup"];
            } else {
                $selectAffil = getContinuationVar('selectAffil');
                if (empty($selectAffil) && $user['showallgroups']) {
                    $selectAffil = 1;
                }
            }
        }
    } else {
        $data["groupid"] = getContinuationVar("groupid");
        $data["type"] = getContinuationVar("type");
        $data["isowner"] = $isowner;
        if (!$state) {
            $id = $groupid;
            $data['groupid'] = $id;
        } else {
            $id = $data["groupid"];
        }
        if ($data["type"] == "user") {
            if ($state) {
                $data["name"] = '';
                $data["affiliationid"] = $user['affiliationid'];
                $data["owner"] = $user['unityid'];
                if (array_key_exists('VCLEDITGROUPID', $_COOKIE) && (array_key_exists($_COOKIE['VCLEDITGROUPID'], $affilusergroups) || $_COOKIE['VCLEDITGROUPID'] == $defaultusergroupid)) {
                    $data["editgroupid"] = $_COOKIE['VCLEDITGROUPID'];
                } else {
                    $data["editgroupid"] = $defaultusergroupid;
                }
                if (!array_key_exists($data['editgroupid'], $affilusergroups)) {
                    if ($user['showallgroups']) {
                        $affil = getAffiliationName(1);
                        $affilusergroups[$data['editgroupid']]['name'] = "Default for Editable by@{$affil}";
                    } else {
                        $affilusergroups[$data['editgroupid']]['name'] = 'Default for Editable by';
                    }
                }
                $data["initialmax"] = 240;
                $data["totalmax"] = 360;
                $data["maxextend"] = 30;
                $data["overlap"] = 0;
                $data["custom"] = 1;
                $data["courseroll"] = 0;
                $tmp = explode('@', $data['name']);
                $data['name'] = $tmp[0];
                if ($user['showallgroups']) {
                    $selectAffil = 1;
                } else {
                    $selectAffil = 0;
                }
            } else {
                $data["name"] = $usergroups[$id]["name"];
                $data["affiliationid"] = $usergroups[$id]["groupaffiliationid"];
                $data["owner"] = $usergroups[$id]["owner"];
                $data["editgroupid"] = $usergroups[$id]["editgroupid"];
                $data["initialmax"] = $usergroups[$id]["initialmaxtime"];
                $data["totalmax"] = $usergroups[$id]["totalmaxtime"];
                $data["maxextend"] = $usergroups[$id]["maxextendtime"];
                $data["overlap"] = $usergroups[$id]["overlapResCount"];
                $data["custom"] = $usergroups[$id]["custom"];
                $data["courseroll"] = $usergroups[$id]["courseroll"];
                $tmp = explode('@', $data['name']);
                $data['name'] = $tmp[0];
                if ($user['showallgroups'] || array_key_exists(1, $tmp) && $tmp[1] != $user['affiliation']) {
                    $selectAffil = 1;
                } else {
                    $selectAffil = 0;
                }
            }
        } else {
            unset($affilusergroups[$defaultusergroupid]);
            if ($state) {
                $grouptype = 'computer';
                $data['name'] = '';
                if (array_key_exists('VCLOWNERGROUPID', $_COOKIE) && array_key_exists($_COOKIE['VCLOWNERGROUPID'], $user['groups'])) {
                    $ownerid = $_COOKIE['VCLOWNERGROUPID'];
                } else {
                    $ownerid = "";
                    foreach (array_keys($user["groups"]) as $grpid) {
                        if (array_key_exists($grpid, $dispUserGrpIDs)) {
                            $ownerid = $grpid;
                            break;
                        }
                    }
                }
            } else {
                list($grouptype, $data["name"]) = explode('/', $resourcegroups[$id]["name"]);
                $ownerid = $resourcegroups[$id]["ownerid"];
            }
        }
    }
    if ($data['type'] == 'user' && !array_key_exists($defaultusergroupid, $affilusergroups)) {
        if ($user['showallgroups']) {
            $affil = getAffiliationName(1);
            $affilusergroups[$defaultusergroupid]['name'] = "Default for Editable by@{$affil}";
        } else {
            $affilusergroups[$defaultusergroupid]['name'] = 'Default for Editable by';
        }
        uasort($affilusergroups, "sortKeepIndex");
    }
    $editusergroup = 0;
    if ($data['type'] != 'user') {
        print "<FORM action=\"" . BASEURL . SCRIPT . "#resources\" method=post>\n";
    } else {
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    }
    print "<DIV align=center>\n";
    if ($state) {
        if ($data["type"] == "user") {
            print "<H2>Add User Group</H2>\n";
        } else {
            print "<H2>Add Resource Group</H2>\n";
        }
    } else {
        if ($data["type"] == "user") {
            print "<H2>Edit User Group</H2>\n";
            print "{$usergroups[$data['groupid']]['name']}<br><br>\n";
            if ($data['courseroll'] == 1) {
                print "Type: Course Roll<br><br>\n";
            } elseif ($data['custom'] == 0) {
                print "Type: Federated<br><br>\n";
            }
            $editusergroup = 1;
        } else {
            print "<H2>Edit Resource Group</H2>\n";
        }
    }
    if ($state && $data["type"] == "user" || $data["isowner"] || $data["type"] == "resource") {
        print "<TABLE>\n";
        if ($data["type"] == "resource") {
            print "  <TR>\n";
            print "    <TH align=right>Type:</TH>\n";
            print "    <TD>\n";
            if ($state && $submitErr) {
                $resourcetypeid = $data['resourcetypeid'];
            } else {
                $resourcetypeid = array_search($grouptype, $resourcetypes["resources"]);
            }
            if ($state) {
                printSelectInput("resourcetypeid", $resourcetypes["resources"], $resourcetypeid);
            } else {
                print "      {$grouptype}\n";
            }
            print "    </TD>\n";
            print "    <TD></TD>\n";
            print "  </TR>\n";
        }
        $editname = 1;
        if ($data['type'] == 'user' && $state == 0 && $usergroups[$groupid]['groupaffiliationid'] == 1) {
            $tmp = explode('@', $usergroups[$groupid]['name']);
            if ($tmp[0] == 'Specify End Time' || $tmp[0] == 'Allow No User Check' || $tmp[0] == 'Default for Editable by') {
                $editname = 0;
            }
        }
        if ($data['type'] == 'resource' || $editname && $data['courseroll'] == 0 && $data['custom'] == 1) {
            print "  <TR>\n";
            print "    <TH align=right>Name:</TH>\n";
            print "    <TD><INPUT type=text name=name value=\"{$data['name']}\" ";
            print "maxlength=30>";
            if ($data['type'] == 'user' && $selectAffil) {
                print "@";
                printSelectInput('affiliationid', $affils, $data['affiliationid']);
            }
            print "</TD>\n";
            print "    <TD>";
            printSubmitErr(GRPNAMEERR);
            print "</TD>\n";
            print "  </TR>\n";
        }
        if ($editname == 0) {
            print "<TR><TD colspan=2 align=\"center\">\n";
            print "(This is a system group whose name cannot be modified.)\n";
            print "</TD></TR>\n";
        }
        if ($data["type"] == "user") {
            if ($data['courseroll'] == 0 && $data['custom'] == 1) {
                print "  <TR>\n";
                print "    <TH align=right>Owner:</TH>\n";
                print "    <TD><INPUT type=text name=owner value=\"" . $data["owner"];
                print "\"></TD>\n";
                print "    <TD>";
                printSubmitErr(GRPOWNER);
                print "</TD>\n";
                print "  </TR>\n";
                print "  <TR>\n";
                print "    <TH align=right>Editable by:</TH>\n";
                print "    <TD valign=\"top\">\n";
                $groupwasnone = 0;
                if ($submitErr & EDITGROUPERR) {
                    if ($state == 0) {
                        $data['editgroupid'] = $usergroups[$data['groupid']]['editgroupid'];
                    } elseif (count($affilusergroups)) {
                        $tmp = array_keys($affilusergroups);
                        $data['editgroupid'] = $tmp[0];
                    }
                }
                $notice = '';
                if ($state == 0 && empty($usergroups[$data['groupid']]["editgroup"])) {
                    $affilusergroups = array_reverse($affilusergroups, TRUE);
                    $affilusergroups[0] = array('name' => 'None');
                    $affilusergroups = array_reverse($affilusergroups, TRUE);
                    $groupwasnone = 1;
                    $notice = "<strong>Note:</strong> You are the only person that can<br>" . "edit membership of this group. Select a<br>user group here " . "to allow members of that<br>group to edit membership of this one.";
                } elseif (!array_key_exists($data['editgroupid'], $affilusergroups) && $data['editgroupid'] != 0) {
                    $affilusergroups[$data['editgroupid']] = array('name' => getUserGroupName($data['editgroupid'], 1));
                    uasort($affilusergroups, "sortKeepIndex");
                }
                if ($state == 1 && $data['editgroupid'] == 0) {
                    print "None\n";
                } else {
                    printSelectInput("editgroupid", $affilusergroups, $data["editgroupid"]);
                }
                print "    </TD>\n";
                print "    <TD>";
                if ($submitErr & EDITGROUPERR) {
                    printSubmitErr(EDITGROUPERR);
                } else {
                    print $notice;
                }
                print "</TD>";
                print "  </TR>\n";
            } else {
                $groupwasnone = 1;
            }
            print "  <TR>\n";
            print "    <TH align=right>Initial Max Time:</TH>\n";
            print "    <TD>";
            $lengths = getReservationLengths(65535);
            if (!array_key_exists($data['initialmax'], $lengths)) {
                $data['initialmax'] = getReservationLengthCeiling($data['initialmax']);
            }
            printSelectInput("initialmax", $lengths, $data['initialmax']);
            print "    </TD>";
            print "    <TD>";
            printSubmitErr(INITIALMAXERR);
            print "</TD>\n";
            print "  </TR>\n";
            print "  <TR>\n";
            print "    <TH align=right>Total Max Time:</TH>\n";
            print "    <TD>";
            if (!array_key_exists($data['totalmax'], $lengths)) {
                $data['totalmax'] = getReservationLengthCeiling($data['totalmax']);
            }
            printSelectInput("totalmax", $lengths, $data['totalmax']);
            print "    </TD>\n";
            print "    <TD>";
            printSubmitErr(TOTALMAXERR);
            print "</TD>\n";
            print "  </TR>\n";
            print "  <TR>\n";
            print "    <TH align=right>Max Extend Time:</TH>\n";
            print "    <TD>";
            if (!array_key_exists($data['maxextend'], $lengths)) {
                $data['maxextend'] = getReservationLengthCeiling($data['maxextend']);
            }
            printSelectInput("maxextend", $lengths, $data['maxextend']);
            print "    </TD>\n";
            print "    <TD>";
            printSubmitErr(MAXEXTENDERR);
            print "</TD>\n";
            print "  </TR>\n";
            if (checkUserHasPerm('Set Overlapping Reservation Count')) {
                print "  <TR>\n";
                print "    <TH align=right>Max Overlapping Reservations:</TH>\n";
                print "    <TD><INPUT type=text name=overlap value=\"";
                print $data["overlap"] . "\" maxlength=4></TD>\n";
                print "    <TD>";
                printSubmitErr(MAXOVERLAPERR);
                print "</TD>\n";
                print "  </TR>\n";
            }
        } else {
            print "  <TR>\n";
            print "    <TH align=right>Owning User Group:</TH>\n";
            print "    <TD>\n";
            if ($submitErr & EDITGROUPERR) {
                $ownerid = $resourcegroups[$groupid]['ownerid'];
            }
            if ($state == 0 && $ownerid != '' && !array_key_exists($ownerid, $dispUserGrpIDs)) {
                $dispUserGrpIDs[$ownerid] = $usergroups[$ownerid]['name'];
                uasort($dispUserGrpIDs, "sortKeepIndex");
            }
            if (!empty($dispUserGrpIDs)) {
                printSelectInput("ownergroup", $dispUserGrpIDs, $ownerid);
            } else {
                printSelectInput("ownergroup", $dispUserGrpIDsAllAffils, $ownerid);
            }
            print "    </TD>\n";
            print "    <TD>\n";
            if ($submitErr & EDITGROUPERR) {
                printSubmitErr(EDITGROUPERR);
            }
            print "    </TD>\n";
            print "  </TR>\n";
        }
        print "</TABLE>\n";
        print "<TABLE>\n";
        print "  <TR valign=top>\n";
        print "    <TD>\n";
        if ($state) {
            $cdata = array('type' => $data['type']);
            if ($data['type'] == 'user') {
                $cdata['isowner'] = $data['isowner'];
                if ($data['editgroupid'] == 0) {
                    $cdata['editgroupid'] = 0;
                    $cdata['groupwasnone'] = 1;
                }
                $cdata['editgroupids'] = implode(',', array_keys($affilusergroups));
            } else {
                if (!empty($dispUserGrpIDs)) {
                    $cdata['ownergroupids'] = implode(',', array_keys($dispUserGrpIDs));
                } else {
                    $cdata['ownergroupids'] = implode(',', array_keys($dispUserGrpIDsAllAffils));
                }
            }
            $cont = addContinuationsEntry('submitAddGroup', $cdata);
            print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
            print "      <INPUT type=submit value=\"Add Group\">\n";
        } else {
            $cdata = array('type' => $data['type'], 'groupid' => $data['groupid'], 'isowner' => $data['isowner'], 'editname' => $editname);
            if ($data['type'] == 'resource') {
                $cdata['resourcetypeid'] = $resourcetypeid;
                if (!empty($dispUserGrpIDs)) {
                    $cdata['ownergroupids'] = implode(',', array_keys($dispUserGrpIDs));
                } else {
                    $cdata['ownergroupids'] = implode(',', array_keys($dispUserGrpIDsAllAffils));
                }
            } else {
                if ($data['courseroll'] == 1 || $data['custom'] == 0 || $editname == 0) {
                    $cdata['name'] = $data['name'];
                    $cdata['affiliationid'] = $data['affiliationid'];
                }
                $cdata['selectAffil'] = $selectAffil;
                $cdata['groupwasnone'] = $groupwasnone;
                $cdata['custom'] = $data['custom'];
                $cdata['courseroll'] = $data['courseroll'];
                $cdata['editgroupids'] = implode(',', array_keys($affilusergroups));
            }
            $cont = addContinuationsEntry('confirmEditGroup', $cdata);
            print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
            print "      <INPUT type=submit value=\"Confirm Changes\">\n";
        }
        print "      </FORM>\n";
        print "    </TD>\n";
        print "    <TD>\n";
        print "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
        print "      <INPUT type=hidden name=mode value=viewGroups>\n";
        print "      <INPUT type=submit value=Cancel>\n";
        print "      </FORM>\n";
        print "    </TD>\n";
        print "  </TR>\n";
        print "</TABLE>\n";
    }
    if ($data["type"] != "user") {
        print "</DIV>\n";
        return;
    }
    if ($editusergroup) {
        $newuser = processInputVar("newuser", ARG_STRING);
        print "<H3>Group Membership</H3>\n";
        if ($mode == "addGroupUser" && !($submitErr & IDNAMEERR)) {
            print "<font color=\"#008000\">{$newuser} successfully added to group";
            print "</font><br><br>\n";
        }
        if ($mode == "deleteGroupUser") {
            print "<font color=\"#008000\">{$newuser} successfully deleted from ";
            print "group</font><br><br>\n";
        }
        $groupmembers = getUserGroupMembers($data["groupid"]);
        $edit = 1;
        if ($data['courseroll'] == 1 || $data['custom'] == 0) {
            $edit = 0;
        }
        if (empty($groupmembers) && !$edit) {
            print "(empty group)<br>\n";
        }
        print "<TABLE border=1>\n";
        if ($edit) {
            print "  <TR>\n";
            print "  <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
            print "    <TD align=right><INPUT type=submit value=Add></TD>\n";
            print "    <TD><INPUT type=text name=newuser maxlength=80 size=40 ";
            if ($submitErr & IDNAMEERR) {
                print "value=\"{$newuser}\"></TD>\n";
            } else {
                print "></TD>\n";
            }
            if ($submitErr) {
                print "    <TD>\n";
                printSubmitErr(IDNAMEERR);
                print "    </TD>\n";
            }
            $cont = addContinuationsEntry('addGroupUser', $data);
            print "  <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
            print "  </FORM>\n";
            print "  </TR>\n";
        }
        foreach ($groupmembers as $id => $login) {
            print "  <TR>\n";
            if ($edit) {
                print "    <TD>\n";
                print "      <FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
                print "      <INPUT type=submit value=Delete>\n";
                $data['userid'] = $id;
                $data['newuser'] = $login;
                $cont = addContinuationsEntry('deleteGroupUser', $data);
                print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
                print "      </FORM>\n";
                print "    </TD>\n";
            }
            print "    <TD>{$login}</TD>\n";
            print "  </TR>\n";
        }
        print "</TABLE>\n";
    }
    print "</DIV>\n";
}
示例#4
0
function AJeditRequest()
{
    global $submitErr, $user;
    $requestid = getContinuationVar('requestid', 0);
    $request = getRequestInfo($requestid, 1);
    # check to see if reservation exists
    if (is_null($request) || $request['stateid'] == 11 || $request['stateid'] == 12 || $request['stateid'] == 14 && ($request['laststateid'] == 11 || $request['laststateid'] == 12)) {
        sendJSON(array('status' => 'resgone'));
        return;
    }
    $unixstart = datetimeToUnix($request["start"]);
    $unixend = datetimeToUnix($request["end"]);
    $duration = $unixend - $unixstart;
    $now = time();
    $maxtimes = getUserMaxTimes();
    $groupid = getUserGroupID('Specify End Time', 1);
    $members = getUserGroupMembers($groupid);
    if (array_key_exists($user['id'], $members) || $request['serverrequest']) {
        $openend = 1;
    } else {
        $openend = 0;
    }
    $groupid = getUserGroupID('Allow No User Check', 1);
    $members = getUserGroupMembers($groupid);
    if (array_key_exists($user['id'], $members)) {
        $nousercheck = 1;
    } else {
        $nousercheck = 0;
    }
    $h = '';
    # determine the current total length of the reservation
    $reslen = ($unixend - unixFloor15($unixstart)) / 60;
    $timeval = getdate($unixstart);
    if ($timeval["minutes"] % 15 != 0) {
        $reslen -= 15;
    }
    $cdata = array('requestid' => $requestid, 'openend' => $openend, 'nousercheck' => $nousercheck, 'modifystart' => 0, 'allowindefiniteend' => 0);
    # generate HTML
    if ($request['serverrequest']) {
        if (empty($request['servername'])) {
            $request['servername'] = $request['reservations'][0]['prettyimage'];
        }
        $h .= i("Name") . ": <input type=\"text\" name=\"servername\" id=\"servername\" ";
        $h .= "dojoType=\"dijit.form.TextBox\" style=\"width: 330px\" ";
        $h .= "value=\"{$request['servername']}\"><br>";
        if ($user['showallgroups']) {
            $groups = getUserGroups();
        } else {
            $groups = getUserGroups(0, $user['affiliationid']);
        }
        $h .= "<div style=\"display: table-row;\">\n";
        $h .= "<div style=\"display: table-cell;\">\n";
        $h .= i("Admin User Group") . ": ";
        $h .= "</div>\n";
        $h .= "<div style=\"display: table-cell;\">\n";
        $disabled = '';
        if ($request['stateid'] == 14 && $request['laststateid'] == 24) {
            $disabled = "disabled=\"true\"";
        }
        if (USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) {
            $h .= "<select dojoType=\"dijit.form.FilteringSelect\" id=\"admingrpsel\" ";
            $h .= "{$disabled} highlightMatch=\"all\" autoComplete=\"false\">";
        } else {
            $h .= "<select id=\"admingrpsel\" {$disabled}>";
        }
        if (!empty($request['admingroupid']) && !array_key_exists($request['admingroupid'], $groups)) {
            $id = $request['admingroupid'];
            $name = getUserGroupName($request['admingroupid'], 1);
            $h .= "<option value=\"{$id}\">{$name}</option>\n";
        }
        $h .= "<option value=\"0\">" . i("None") . "</option>\n";
        foreach ($groups as $id => $group) {
            if ($id == $request['admingroupid']) {
                $h .= "<option value=\"{$id}\" selected>{$group['name']}</option>";
            } else {
                $h .= "<option value=\"{$id}\">{$group['name']}</option>";
            }
        }
        $h .= "</select><br>";
        $imageinfo = getImages(0, $request['reservations'][0]['imageid']);
        if ($imageinfo[$request['reservations'][0]['imageid']]['rootaccess'] == 0) {
            $h .= "<div style=\"width: 240px; margin: 3px 0 3px 0; padding: 1px; border: 1px solid;\">";
            $h .= i("Administrative access has been disabled for this image. Users in the Admin User Group will have control of the reservaion on the Reservations page but will not have administrative access within the reservation.");
            $h .= "</div>\n";
        }
        $h .= "</div>\n";
        $h .= "</div>\n";
        $h .= i("Access User Group") . ": ";
        if (USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) {
            $h .= "<select dojoType=\"dijit.form.FilteringSelect\" id=\"logingrpsel\" ";
            $h .= "{$disabled} highlightMatch=\"all\" autoComplete=\"false\">";
        } else {
            $h .= "<select id=\"logingrpsel\" {$disabled}>";
        }
        if (!empty($request['logingroupid']) && !array_key_exists($request['logingroupid'], $groups)) {
            $id = $request['logingroupid'];
            $name = getUserGroupName($request['logingroupid'], 1);
            $h .= "<option value=\"{$id}\">{$name}</option>\n";
        }
        $h .= "<option value=\"0\">None</option>\n";
        foreach ($groups as $id => $group) {
            if ($id == $request['logingroupid']) {
                $h .= "<option value=\"{$id}\" selected>{$group['name']}</option>";
            } else {
                $h .= "<option value=\"{$id}\">{$group['name']}</option>";
            }
        }
        $h .= "</select><br><br>";
    } elseif ($nousercheck) {
        $extra = array();
        if ($request['checkuser'] == 0) {
            $extra['checked'] = 'checked';
        }
        $h .= labeledFormItem('newnousercheck', i('Disable timeout for disconnected users'), 'check', '', '', '1', '', '', $extra);
        $h .= "<br>\n";
    }
    // if future, allow start to be modified
    if ($unixstart > $now) {
        $cdata['modifystart'] = 1;
        $txt = i("Modify reservation for") . " <b>{$request['reservations'][0]['prettyimage']}</b> ";
        $txt .= i("starting") . " " . prettyDatetime($request["start"]) . ": <br>";
        $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $txt);
        $days = array();
        $startday = date('l', $unixstart);
        for ($cur = time(), $end = $cur + DAYSAHEAD * SECINDAY; $cur < $end; $cur += SECINDAY) {
            $index = date('Ymd', $cur);
            $days[$index] = date('l', $cur);
        }
        $cdata['startdays'] = array_keys($days);
        $h .= i("Start") . ": <select dojoType=\"dijit.form.Select\" id=\"day\" ";
        $h .= "onChange=\"resetEditResBtn();\">";
        foreach ($days as $id => $name) {
            if ($name == $startday) {
                $h .= "<option value=\"{$id}\" selected=\"selected\">{$name}</option>";
            } else {
                $h .= "<option value=\"{$id}\">{$name}</option>";
            }
        }
        $h .= "</select>";
        $h .= i("&nbsp;At&nbsp;");
        $tmp = explode(' ', $request['start']);
        $stime = $tmp[1];
        $h .= "<div type=\"text\" dojoType=\"dijit.form.TimeTextBox\" ";
        $h .= "id=\"editstarttime\" style=\"width: 78px\" value=\"T{$stime}\" ";
        $h .= "onChange=\"resetEditResBtn();\"></div>";
        $h .= "<small>(" . date('T') . ")</small><br><br>";
        $durationmatch = 0;
        if ($request['serverrequest']) {
            $cdata['allowindefiniteend'] = 1;
            if ($request['end'] == '2038-01-01 00:00:00') {
                $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"indefiniteradio\" ";
                $h .= "checked onChange=\"resetEditResBtn();\">";
            } else {
                $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"indefiniteradio\" ";
                $h .= "onChange=\"resetEditResBtn();\">";
            }
            $h .= "<label for=\"indefiniteradio\">" . i("Indefinite Ending") . "</label>";
        } else {
            $durationmin = $duration / 60;
            if ($request['forimaging'] && $maxtimes['initial'] < 720) {
                # make sure at least 12 hours available for imaging reservations
                $maxtimes['initial'] = 720;
            }
            $imgdata = getImages(1, $request['reservations'][0]['imageid']);
            $maxlen = $imgdata[$request['reservations'][0]['imageid']]['maxinitialtime'];
            if ($maxlen > 0 && $maxlen < $maxtimes['initial']) {
                $maxtimes['initial'] = $maxlen;
            }
            $lengths = array();
            if ($maxtimes["initial"] >= 30) {
                $lengths["30"] = "30 " . i("minutes");
                if ($durationmin == 30) {
                    $durationmatch = 1;
                }
            }
            if ($maxtimes["initial"] >= 45) {
                $lengths["45"] = "45 " . i("minutes");
                if ($durationmin == 45) {
                    $durationmatch = 1;
                }
            }
            if ($maxtimes["initial"] >= 60) {
                $lengths["60"] = "1 " . i("hour");
                if ($durationmin == 60) {
                    $durationmatch = 1;
                }
            }
            for ($i = 120; $i <= $maxtimes["initial"] && $i < 2880; $i += 120) {
                $lengths[$i] = $i / 60 . " " . i("hours");
                if ($durationmin == $i) {
                    $durationmatch = 1;
                }
            }
            for ($i = 2880; $i <= $maxtimes["initial"]; $i += 1440) {
                $lengths[$i] = $i / 1440 . " " . i("days");
                if ($durationmin == $i) {
                    $durationmatch = 1;
                }
            }
            if ($openend) {
                if ($durationmatch) {
                    $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"lengthradio\" ";
                    $h .= "onChange=\"resetEditResBtn();\" checked>";
                } else {
                    $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"lengthradio\" ";
                    $h .= "onChange=\"resetEditResBtn();\">";
                }
                $h .= "<label for=\"lengthradio\">";
            }
            $h .= i("Duration") . ':';
            if ($openend) {
                $h .= "</label>";
            }
            $h .= "<select dojoType=\"dijit.form.Select\" id=\"length\" ";
            $h .= "onChange=\"selectLength();\">";
            $cdata['lengths'] = array_keys($lengths);
            foreach ($lengths as $id => $name) {
                if ($id == $duration / 60) {
                    $h .= "<option value=\"{$id}\" selected=\"selected\">{$name}</option>";
                } else {
                    $h .= "<option value=\"{$id}\">{$name}</option>";
                }
            }
            $h .= "</select>";
        }
        if ($openend) {
            if ($request['serverrequest'] && $request['end'] == '2038-01-01 00:00:00') {
                $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
                $h .= "onChange=\"resetEditResBtn();\">";
                $edate = '';
                $etime = '';
            } else {
                if (!$request['serverrequest'] && $durationmatch) {
                    $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
                    $h .= "onChange=\"resetEditResBtn();\">";
                } else {
                    $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
                    $h .= "checked onChange=\"resetEditResBtn();\">";
                }
                $tmp = explode(' ', $request['end']);
                $edate = $tmp[0];
                $etime = $tmp[1];
            }
            $h .= "<label for=\"dateradio\">";
            $h .= i("End:");
            $h .= "</label>";
            $h .= "<div type=\"text\" dojoType=\"dijit.form.DateTextBox\" ";
            $h .= "id=\"openenddate\" style=\"width: 78px\" value=\"{$edate}\" ";
            $h .= "onChange=\"selectEnding();\"></div>";
            $h .= "<div type=\"text\" dojoType=\"dijit.form.TimeTextBox\" ";
            $h .= "id=\"openendtime\" style=\"width: 78px\" value=\"T{$etime}\" ";
            $h .= "onChange=\"selectEnding();\"></div>";
            $h .= "<small>(" . date('T') . ")</small>";
        }
        $h .= "<br><br>";
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data = array('status' => 'modify', 'html' => $h, 'requestid' => $requestid, 'cont' => $cont);
        sendJSON($data);
        return;
    }
    # check for max time being reached
    if ($request['forimaging'] && $maxtimes['total'] < 720) {
        $maxcheck = 720;
    } else {
        $maxcheck = $maxtimes['total'];
    }
    if (!$openend && $reslen >= $maxcheck) {
        $h = sprintf(i("You are only allowed to extend your reservation such that it has a total length of %s. "), minToHourMin($maxcheck));
        $h .= i("This reservation already meets that length. Therefore, you are not allowed to extend your reservation any further.");
        $h = preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $h) . "<br>";
        sendJSON(array('status' => 'nomodify', 'html' => $h));
        return;
    }
    // if started, only allow end to be modified
    # check for following reservations
    $timeToNext = timeToNextReservation($request);
    # check for 30 minutes because need 15 minute buffer and min can
    # extend by is 15 min
    if ($timeToNext < 30) {
        $movedall = 1;
        $lockedall = 1;
        if (count($request['reservations']) > 1) {
            # get semaphore on each existing node in cluster so that nothing
            # can get moved to the nodes during this process
            $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
            $tmp = array_keys($resources['image']);
            $semimageid = $tmp[0];
            $semrevid = getProductionRevisionid($semimageid);
            $checkend = unixToDatetime($unixend + 900);
            foreach ($request["reservations"] as $res) {
                if (!retryGetSemaphore($semimageid, $semrevid, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) {
                    $lockedall = 0;
                    break;
                }
            }
        }
        if ($lockedall) {
            foreach ($request["reservations"] as $res) {
                if (!moveReservationsOffComputer($res["computerid"], 1)) {
                    $movedall = 0;
                    break;
                }
            }
        }
        cleanSemaphore();
        if (!$request['serverrequest'] && (!$movedall || !$lockedall)) {
            $msg = i("The computer you are using has another reservation immediately following yours. Therefore, you cannot extend your reservation because it would overlap with the next one.");
            $h = preg_replace("/(.{1,60}( |\$))/", '\\1<br>', $msg) . "<br>";
            sendJSON(array('status' => 'nomodify', 'html' => $h));
            return;
        }
        $timeToNext = timeToNextReservation($request);
    }
    if ($timeToNext >= 15) {
        $timeToNext -= 15;
    }
    //if have time left to extend it, create an array of lengths based on maxextend that has a cap
    # so we don't run into another reservation and we can't extend past the totalmax
    $lengths = array();
    if ($request['forimaging'] && $maxtimes['total'] < 720) {
        # make sure at least 12 hours available for imaging reservations
        $maxtimes['total'] = 720;
    }
    if ($timeToNext == -1) {
        // there is no following reservation
        if ($reslen + 15 <= $maxtimes["total"] && 15 <= $maxtimes["extend"]) {
            $lengths["15"] = "15 " . i("minutes");
        }
        if ($reslen + 30 <= $maxtimes["total"] && 30 <= $maxtimes["extend"]) {
            $lengths["30"] = "30 " . i("minutes");
        }
        if ($reslen + 45 <= $maxtimes["total"] && 45 <= $maxtimes["extend"]) {
            $lengths["45"] = "45 " . i("minutes");
        }
        if ($reslen + 60 <= $maxtimes["total"] && 60 <= $maxtimes["extend"]) {
            $lengths["60"] = i("1 hour");
        }
        for ($i = 120; $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"] && $i < 2880; $i += 120) {
            $lengths[$i] = $i / 60 . " " . i("hours");
        }
        for ($i = 2880; $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"]; $i += 1440) {
            $lengths[$i] = $i / 1440 . " " . i("days");
        }
    } else {
        if ($timeToNext >= 15 && $reslen + 15 <= $maxtimes["total"] && 15 <= $maxtimes["extend"]) {
            $lengths["15"] = "15 " . i("minutes");
        }
        if ($timeToNext >= 30 && $reslen + 30 <= $maxtimes["total"] && 30 <= $maxtimes["extend"]) {
            $lengths["30"] = "30 " . i("minutes");
        }
        if ($timeToNext >= 45 && $reslen + 45 <= $maxtimes["total"] && 45 <= $maxtimes["extend"]) {
            $lengths["45"] = "45 " . i("minutes");
        }
        if ($timeToNext >= 60 && $reslen + 60 <= $maxtimes["total"] && 60 <= $maxtimes["extend"]) {
            $lengths["60"] = i("1 hour");
        }
        for ($i = 120; $i <= $timeToNext && $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"] && $i < 2880; $i += 120) {
            $lengths[$i] = $i / 60 . " " . i("hours");
        }
        for ($i = 2880; $i <= $timeToNext && $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"]; $i += 1440) {
            $lengths[$i] = $i / 1440 . " " . i("days");
        }
    }
    $cdata['lengths'] = array_keys($lengths);
    if ($timeToNext == -1 || $timeToNext >= $maxtimes['total']) {
        if ($openend) {
            if (!empty($lengths)) {
                $m = i("You can extend this reservation by a selected amount or change the end time to a specified date and time.");
                $h .= preg_replace("/(.{1,55}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
            } else {
                $h .= i("Modify the end time for this reservation:") . "<br><br>";
            }
        } else {
            if ($request['forimaging'] && $maxtimes['total'] < 720) {
                $maxcheck = 720;
            } else {
                $maxcheck = $maxtimes['total'];
            }
            $m = sprintf(i("You can extend this reservation by up to %s but not exceeding %s for your total reservation time."), minToHourMin($maxtimes['extend']), minToHourMin($maxcheck));
            $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        }
    } elseif (!$request['serverrequest']) {
        $m = sprintf(i("The computer you are using has another reservation following yours. Therefore, you can only extend this reservation for another %s."), prettyLength($timeToNext));
        $h .= preg_replace("/(.{1,60}( |\$))/", '\\1<br>', $m);
    }
    # extend by drop down
    # extend by specifying end time if $openend
    $noindefinite = 0;
    if ($openend) {
        if ($request['serverrequest']) {
            $cdata['allowindefiniteend'] = 1;
            $endchecked = 0;
            if ($request['end'] == '2038-01-01 00:00:00') {
                $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"indefiniteradio\" ";
                $h .= "checked onChange=\"resetEditResBtn();\">";
                $h .= "<label for=\"indefiniteradio\">" . i("Indefinite Ending") . "</label>";
                $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
                $h .= "onChange=\"resetEditResBtn();\">";
            } else {
                $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"indefiniteradio\" ";
                $h .= "onChange=\"resetEditResBtn();\">";
                $h .= "<label id=\"indefinitelabel\" for=\"indefiniteradio\">";
                $h .= i("Indefinite Ending") . "</label>";
                $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
                $h .= "checked onChange=\"resetEditResBtn();\">";
                $endchecked = 1;
            }
            $h .= "<label for=\"dateradio\">";
        } elseif (!empty($lengths)) {
            $h .= "<INPUT type=\"radio\" name=\"ending\" id=\"lengthradio\" ";
            $h .= "checked onChange=\"resetEditResBtn();\">";
            $h .= "<label for=\"lengthradio\">" . i("Extend reservation by:") . "</label>";
            $h .= "<select dojoType=\"dijit.form.Select\" id=\"length\" ";
            $h .= "onChange=\"selectLength();\" maxHeight=\"250\">";
            foreach ($lengths as $id => $name) {
                $h .= "<option value=\"{$id}\">{$name}</option>";
            }
            $h .= "</select>";
            $h .= "<br><INPUT type=\"radio\" name=\"ending\" id=\"dateradio\" ";
            $h .= "onChange=\"resetEditResBtn();\">";
            $h .= "<label for=\"dateradio\">";
        }
        if ($request['serverrequest']) {
            $h .= i("End:");
            if ($endchecked) {
                $tmp = explode(' ', $request['end']);
                $edate = $tmp[0];
                $etime = $tmp[1];
            } else {
                $edate = '';
                $etime = '';
            }
        } else {
            $h .= i("Change ending to:");
            $tmp = explode(' ', $request['end']);
            $edate = $tmp[0];
            $etime = $tmp[1];
        }
        if (!empty($lengths) || $request['serverrequest']) {
            $h .= "</label>";
        }
        $h .= "<div type=\"text\" dojoType=\"dijit.form.DateTextBox\" ";
        $h .= "id=\"openenddate\" style=\"width: 78px\" value=\"{$edate}\" ";
        $h .= "onChange=\"selectEnding();\"></div>";
        $h .= "<div type=\"text\" dojoType=\"dijit.form.TimeTextBox\" ";
        $h .= "id=\"openendtime\" style=\"width: 78px\" value=\"T{$etime}\" ";
        $h .= "onChange=\"selectEnding();\"></div>";
        $h .= "<small>(" . date('T') . ")</small>";
        $h .= "<INPUT type=\"hidden\" name=\"enddate\" id=\"enddate\">";
        if ($request['serverrequest'] && $timeToNext == 0) {
            $h .= "<br><br><font color=red>";
            $m = "<strong>" . i("NOTE:") . "</strong> ";
            $m .= i("Due to an upcoming reservation on the same computer, you cannot extend this reservation.");
            $h .= preg_replace("/(.{1,80}([ \n]|\$))/", '\\1<br>', $m);
            $h .= "</font>";
            $noindefinite = 1;
        } elseif ($timeToNext > -1) {
            $extend = $unixend + $timeToNext * 60;
            $extend = date('m/d/Y g:i A', $extend);
            $h .= "<br><br><font color=red>";
            $m = "<strong>" . i("NOTE:") . "</strong> ";
            $m .= sprintf(i("Due to an upcoming reservation on the same computer, you can only extend this reservation until %s."), $extend);
            $h .= preg_replace("/(.{1,80}([ \n]|\$))/", '\\1<br>', $m);
            $h .= "</font>";
            $cdata['maxextend'] = $extend;
            $noindefinite = 1;
        }
    } else {
        $h .= i("Extend reservation by:");
        $h .= "<select dojoType=\"dijit.form.Select\" id=\"length\">";
        foreach ($lengths as $id => $name) {
            $h .= "<option value=\"{$id}\">{$name}</option>";
        }
        $h .= "</select>";
    }
    $h .= "<br>";
    $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
    $data = array('status' => 'modify', 'html' => $h, 'requestid' => $requestid, 'cont' => $cont);
    if ($noindefinite) {
        $data['status'] = 'noindefinite';
    }
    sendJSON($data);
    return;
}
示例#5
0
function printReserveItems($modifystart = 1, $day = NULL, $hour = NULL, $minute = NULL, $meridian = NULL, $length = 60, $oneline = 0, $nolength = 0)
{
    global $user;
    $enddate = processInputVar("enddate", ARG_STRING);
    $groupid = getUserGroupID('Specify End Time', 1);
    $members = getUserGroupMembers($groupid);
    if (array_key_exists($user['id'], $members)) {
        $openend = 1;
    } else {
        $openend = 0;
    }
    $days = array();
    $inputday = "";
    for ($cur = time(), $end = $cur + DAYSAHEAD * SECINDAY; $cur < $end; $cur += SECINDAY) {
        $tmp = getdate($cur);
        $index = $tmp["mon"] . "/" . $tmp["mday"] . "/" . $tmp["year"];
        $days[$index] = $tmp["weekday"];
        if ($tmp["weekday"] == $day) {
            $inputday = $index;
        }
    }
    if ($modifystart) {
        printSelectInput("day", $days, $inputday);
        print "&nbsp;At&nbsp;\n";
        $tmpArr = array();
        for ($i = 1; $i < 13; $i++) {
            $tmpArr[$i] = $i;
        }
        printSelectInput("hour", $tmpArr, $hour);
        $minutes = array("zero" => "00", "15" => "15", "30" => "30", "45" => "45");
        printSelectInput("minute", $minutes, $minute);
        printSelectInput("meridian", array("am" => "a.m.", "pm" => "p.m."), $meridian);
        print "<small>(Eastern Time Zone)</small>";
        //if(! $oneline)
        print "<br><br>";
        /*else
        		print "&nbsp;&nbsp;";*/
        if (!$nolength) {
            if ($openend) {
                print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=ending ";
                print "onclick='updateWaitTime(0);' value=length checked>";
            }
            print "Duration:&nbsp;\n";
        }
    } else {
        print "<INPUT type=hidden name=day value={$inputday}>\n";
        print "<INPUT type=hidden name=hour value={$hour}>\n";
        print "<INPUT type=hidden name=minute value={$minute}>\n";
        print "<INPUT type=hidden name=meridian value={$meridian}>\n";
    }
    // check for a "now" reservation that got 15 min added to it
    if ($length % 30) {
        $length -= 15;
    }
    // if ! $modifystart, we return at this point because we don't
    # know enough about the current reservation to determine how
    # long they can extend it for, the calling function would have
    # to determine that and print a length dropdown box
    if (!$modifystart) {
        return;
    }
    # create an array of usage times based on the user's max times
    $maxtimes = getUserMaxTimes("initialmaxtime");
    $lengths = array();
    if ($maxtimes["initial"] >= 30) {
        $lengths["30"] = "30 minutes";
    }
    if ($maxtimes["initial"] >= 60) {
        $lengths["60"] = "1 hour";
    }
    for ($i = 120; $i <= $maxtimes["initial"]; $i += 120) {
        $lengths[$i] = $i / 60 . " hours";
    }
    if ($nolength) {
        print "Reservation will be for 8 hours<br>\n";
    } else {
        printSelectInput("length", $lengths, $length, 0, 0, 'reqlength', "onChange='updateWaitTime(0);'");
        print "<br>\n";
        if ($openend) {
            print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=ending id=openend ";
            print "onclick='updateWaitTime(0);' value=date>Until\n";
            print "<INPUT type=text name=enddate size=20 value=\"{$enddate}\">(YYYY-MM-DD HH:MM:SS)\n";
            printSubmitErr(ENDDATEERR);
            print "<br>\n";
        }
    }
}
示例#6
0
文件: utils.php 项目: gw-acadtech/VCL
function validateAPIgroupInput($items, $exists)
{
    # initialMaxTime
    if (array_key_exists('initialMaxTime', $items)) {
        if (!is_numeric($items['initialMaxTime']) || $items['initialMaxTime'] < 1 || $items['initialMaxTime'] > 65535) {
            return array('status' => 'error', 'errorcode' => 21, 'errormsg' => 'submitted initialMaxTime is invalid');
        }
    }
    # totalMaxTime
    if (array_key_exists('totalMaxTime', $items)) {
        if (!is_numeric($items['totalMaxTime']) || $items['totalMaxTime'] < 1 || $items['totalMaxTime'] > 65535) {
            return array('status' => 'error', 'errorcode' => 22, 'errormsg' => 'submitted totalMaxTime is invalid');
        }
    }
    # maxExtendTime
    if (array_key_exists('maxExtendTime', $items)) {
        if (!is_numeric($items['maxExtendTime']) || $items['maxExtendTime'] < 1 || $items['maxExtendTime'] > 65535) {
            return array('status' => 'error', 'errorcode' => 23, 'errormsg' => 'submitted maxExtendTime is invalid');
        }
    }
    # affiliation
    if (array_key_exists('affiliation', $items)) {
        $esc_affiliation = mysql_escape_string($items['affiliation']);
        $affilid = getAffiliationID($esc_affiliation);
        if (is_null($affilid)) {
            return array('status' => 'error', 'errorcode' => 17, 'errormsg' => 'unknown affiliation');
        }
        $items['affiliationid'] = $affilid;
    }
    # name
    if (array_key_exists('name', $items)) {
        if (!ereg('^[-a-zA-Z0-9_\\.: ]{3,30}$', $items['name'])) {
            return array('status' => 'error', 'errorcode' => 19, 'errormsg' => 'Name must be between 3 and 30 characters ' . 'and can only contain letters, numbers, and ' . 'these characters: - _ . :');
        }
        $esc_name = mysql_escape_string($items['name']);
        $doesexist = checkForGroupName($esc_name, 'user', '', $affilid);
        if ($exists && !$doesexist) {
            return array('status' => 'error', 'errorcode' => 18, 'errormsg' => 'user group with submitted name and affiliation does not exist');
        } elseif (!$exists && $doesexist) {
            return array('status' => 'error', 'errorcode' => 27, 'errormsg' => 'existing user group with submitted name and affiliation');
        } elseif ($exists && $doesexist) {
            $items['id'] = getUserGroupID($esc_name, $affilid);
        }
    }
    # owner
    if (array_key_exists('owner', $items)) {
        if (!validateUserid(mysql_escape_string($items['owner']))) {
            return array('status' => 'error', 'errorcode' => 20, 'errormsg' => 'submitted owner is invalid');
        }
    }
    # managingGroup
    if (array_key_exists('managingGroup', $items)) {
        $parts = explode('@', $items['managingGroup']);
        if (count($parts) != 2) {
            return array('status' => 'error', 'errorcode' => 24, 'errormsg' => 'submitted managingGroup is invalid');
        }
        $esc_mgName = mysql_escape_string($parts[0]);
        $esc_mgAffil = mysql_escape_string($parts[1]);
        $mgaffilid = getAffiliationID($esc_mgAffil);
        if (!checkForGroupName($esc_mgName, 'user', '', $mgaffilid)) {
            return array('status' => 'error', 'errorcode' => 25, 'errormsg' => 'submitted managingGroup does not exist');
        }
        $items['managingGroupID'] = getUserGroupID($esc_mgName, $mgaffilid);
        $items['managingGroupName'] = $parts[0];
        $items['managingGroupAffilid'] = $mgaffilid;
    }
    $items['status'] = 'success';
    return $items;
}
示例#7
0
function updateShibGroups($usernid, $groups)
{
    $groups = explode(';', $groups);
    $newusergroups = array();
    foreach ($groups as $group) {
        # make sure $group contains non-whitespace
        if (!preg_match('/\\w/', $group)) {
            continue;
        }
        list($name, $shibaffil) = explode('@', $group);
        # get id for the group's affiliation
        $query = "SELECT id FROM affiliation WHERE shibname = '{$shibaffil}'";
        $qh = doQuery($query, 101);
        $row = mysql_fetch_assoc($qh);
        $affilid = $row['id'];
        # prepend shib- and escape it for mysql
        $grp = mysql_escape_string("shib-" . $name);
        array_push($newusergroups, getUserGroupID($grp, $affilid));
    }
    $newusergroups = array_unique($newusergroups);
    if (!empty($newusergroups)) {
        updateGroups($newusergroups, $usernid);
    }
}
示例#8
0
function updateITECSUser($userid)
{
    global $ENABLE_ITECSAUTH;
    if (!$ENABLE_ITECSAUTH) {
        return NULL;
    }
    $query = "SELECT id AS uid, " . "first, " . "last, " . "email, " . "created " . "FROM user " . "WHERE email = '{$userid}'";
    $qh = doQuery($query, 101, "accounts");
    if (!($userData = mysql_fetch_assoc($qh))) {
        return NULL;
    }
    $now = unixToDatetime(time());
    // select desired data from db
    $query = "SELECT i.name AS IMtype, " . "u.IMid AS IMid, " . "u.affiliationid, " . "af.name AS affiliation, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.preferredname AS preferredname, " . "u.uid AS uid, " . "u.id AS id, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.uid = " . $userData["uid"];
    $qh = doQuery($query, 255);
    // if get a row
    //    update db
    //    update results from select
    $esc_userid = mysql_escape_string($userid);
    $first = mysql_escape_string($userData['first']);
    $last = mysql_escape_string($userData['last']);
    $email = mysql_escape_string($userData['email']);
    if ($user = mysql_fetch_assoc($qh)) {
        $user["unityid"] = $userid;
        $user["firstname"] = $userData['first'];
        $user["lastname"] = $userData["last"];
        $user["email"] = $userData["email"];
        $user["lastupdated"] = $now;
        $query = "UPDATE user " . "SET unityid = '{$esc_userid}', " . "firstname = '{$first}', " . "lastname = '{$last}', " . "email = '{$email}', " . "lastupdated = '{$now}' " . "WHERE uid = " . $userData["uid"];
        doQuery($query, 256, 'vcl', 1);
    } else {
        //    call addITECSUser
        $id = addITECSUser($userid);
        $query = "SELECT u.unityid AS unityid, " . "u.affiliationid, " . "af.name AS affiliation, " . "u.firstname AS firstname, " . "u.lastname AS lastname, " . "u.preferredname AS preferredname, " . "u.email AS email, " . "i.name AS IMtype, " . "u.IMid AS IMid, " . "u.uid AS uid, " . "u.id AS id, " . "a.name AS adminlevel, " . "a.id AS adminlevelid, " . "u.width AS width, " . "u.height AS height, " . "u.bpp AS bpp, " . "u.audiomode AS audiomode, " . "u.mapdrives AS mapdrives, " . "u.mapprinters AS mapprinters, " . "u.mapserial AS mapserial, " . "u.showallgroups, " . "u.lastupdated AS lastupdated " . "FROM user u, " . "IMtype i, " . "affiliation af, " . "adminlevel a " . "WHERE u.IMtypeid = i.id AND " . "u.adminlevelid = a.id AND " . "u.affiliationid = af.id AND " . "u.id = {$id}";
        $qh = doQuery($query, 101);
        $user = mysql_fetch_assoc($qh);
        # add account to demo group
        $demoid = getUserGroupID('demo', getAffiliationID('ITECS'));
        updateGroups(array($demoid), $user['id']);
    }
    $user["groups"] = getUsersGroups($user["id"], 1);
    checkExpiredDemoUser($user['id'], $user['groups']);
    $user["privileges"] = getOverallUserPrivs($user["id"]);
    $tmparr = explode('@', $user['unityid']);
    $user['login'] = $tmparr[0];
    return $user;
}
示例#9
0
function XMLRPCsetRequestEnding($requestid, $end)
{
    global $user;
    $requestid = processInputData($requestid, ARG_NUMERIC);
    $userRequests = getUserRequests('all', $user['id']);
    $found = 0;
    foreach ($userRequests as $req) {
        if ($req['id'] == $requestid) {
            $request = getRequestInfo($requestid);
            $found = 1;
            break;
        }
    }
    if (!$found) {
        return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid');
    }
    // make sure user is a member of the 'Specify End Time' group
    $groupid = getUserGroupID('Specify End Time');
    $members = getUserGroupMembers($groupid);
    if (!$request['serverrequest'] && !array_key_exists($user['id'], $members)) {
        return array('status' => 'error', 'errorcode' => 35, 'errormsg' => "access denied to specify end time");
    }
    $end = processInputData($end, ARG_NUMERIC);
    $maxend = datetimeToUnix("2038-01-01 00:00:00");
    if ($end < 0 || $end > $maxend) {
        return array('status' => 'error', 'errorcode' => 36, 'errormsg' => "received invalid input for end");
    }
    $startts = datetimeToUnix($request['start']);
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    // check that reservation has started
    if ($startts > time()) {
        return array('status' => 'error', 'errorcode' => 38, 'errormsg' => 'reservation has not started');
    }
    // check for overlap
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $end, $max, $requestid)) {
        return array('status' => 'error', 'errorcode' => 41, 'errormsg' => 'overlapping reservation restriction', 'maxoverlap' => $max);
    }
    // check for computer being available for extended time?
    $timeToNext = timeToNextReservation($request);
    $movedall = 1;
    if ($timeToNext > -1) {
        $lockedall = 1;
        if (count($request['reservations']) > 1) {
            # get semaphore on each existing node in cluster so that nothing
            # can get moved to the nodes during this process
            $unixend = datetimeToUnix($request['end']);
            $checkend = unixToDatetime($unixend + 900);
            $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
            $tmp = array_keys($resources['image']);
            $semimageid = $tmp[0];
            $semrevid = getProductionRevisionid($semimageid);
            foreach ($request["reservations"] as $res) {
                if (!retryGetSemaphore($semimageid, $semrevid, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) {
                    $lockedall = 0;
                    break;
                }
            }
        }
        if ($lockedall) {
            foreach ($request["reservations"] as $res) {
                if (!moveReservationsOffComputer($res["computerid"])) {
                    $movedall = 0;
                    break;
                }
            }
        } else {
            cleanSemaphore();
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        }
        cleanSemaphore();
    }
    if (!$movedall) {
        $timeToNext = timeToNextReservation($request);
        if ($timeToNext >= 15) {
            $timeToNext -= 15;
        }
        $oldendts = datetimeToUnix($request['end']);
        // reservation immediately after this one, cannot extend
        if ($timeToNext < 15) {
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        } elseif (($end - $oldendts) / 60 > $timeToNext) {
            $maxend = $oldendts + $timeToNext * 60;
            return array('status' => 'error', 'errorcode' => 43, 'errormsg' => 'cannot extend by requested amount due to another reservation', 'maxend' => $maxend);
        }
    }
    $rc = isAvailable(getImages(), $request['reservations'][0]["imageid"], $request['reservations'][0]['imagerevisionid'], $startts, $end, 1, $requestid);
    // conflicts with scheduled maintenance
    if ($rc == -2) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 46, 'errormsg' => 'requested time is during a maintenance window');
    } elseif ($rc == -1) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 44, 'errormsg' => 'concurrent license restriction');
    } elseif ($rc == 0) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 45, 'errormsg' => 'cannot extend at this time');
    }
    // success
    updateRequest($requestid);
    cleanSemaphore();
    return array('status' => 'success');
}