Esempio n. 1
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;
}
Esempio n. 2
0
function AJblockAllocationSubmit()
{
    global $user;
    $data = processBlockAllocationInput();
    if ($data['err']) {
        return;
    }
    $method = getContinuationVar('method');
    if ($method == 'new') {
        $managementnodes = getManagementNodes('future');
        if (empty($managementnodes)) {
            print "alert('" . i("Error encountered while trying to create block allocation:") . "\\n";
            print i("No active management nodes were found. Please try creating the block allocation at a later time.") . "');";
            $data = array('extragroups' => getContinuationVar('extragroups'), 'method' => $method);
            if ($method == 'edit') {
                $data['blockid'] = getContinuationVar('blockid');
            }
            $cont = addContinuationsEntry('AJblockAllocationSubmit', $data, SECINWEEK, 1, 0);
            print "dojo.byId('submitcont').value = '{$cont}';";
            return;
        }
        $mnid = array_rand($managementnodes);
        $escname = mysql_real_escape_string($data['name']);
        $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "managementnodeid, " . "expireTime, " . "status) " . "VALUES " . "('{$escname}', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$data['ownerid']}, " . "{$mnid}, " . "'{$data['expiretime']}', " . "'accepted')";
        doQuery($query, 101);
        $blockreqid = dbLastInsertID();
    } elseif ($method == 'edit') {
        $blockreqid = getContinuationVar('blockid');
        # FIXME need to handle creation of a block time that we're currently in the
        #    middle of if there wasn't already one we're in the middle of
        # get blockTime entry for this allocation if we're in the middle of one
        $checkCurBlockTime = 0;
        $query = "SELECT id, " . "start, " . "end " . "FROM blockTimes " . "WHERE start <= NOW() AND " . "end > NOW() AND " . "blockRequestid = {$blockreqid}";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_assoc($qh)) {
            $checkCurBlockTime = 1;
            $curBlockTime = $row;
        }
        # delete entries from blockTimes that start later than now
        $query = "DELETE FROM blockTimes " . "WHERE blockRequestid = {$blockreqid} AND " . "start > NOW() AND " . "skip = 0";
        doQuery($query, 101);
        # delete entries from blockWebDate and blockWebTime
        $query = "DELETE FROM blockWebDate WHERE blockRequestid = {$blockreqid}";
        doQuery($query, 101);
        $query = "DELETE FROM blockWebTime WHERE blockRequestid = {$blockreqid}";
        doQuery($query, 101);
        $escname = mysql_real_escape_string($data['name']);
        $query = "UPDATE blockRequest " . "SET name = '{$escname}', " . "imageid = {$data['imageid']}, " . "numMachines = {$data['seats']}, " . "groupid = {$data['groupid']}, " . "ownerid = {$data['ownerid']}, " . "repeating = '{$data['type']}', " . "expireTime = '{$data['expiretime']}' " . "WHERE  id = {$blockreqid}";
        doQuery($query, 101);
    } elseif ($method == 'request') {
        $esccomments = mysql_real_escape_string($data['comments']);
        $query = "INSERT INTO blockRequest " . "(name, " . "imageid, " . "numMachines, " . "groupid, " . "repeating, " . "ownerid, " . "expireTime, " . "status, " . "comments) " . "VALUES " . "('(" . i("awaiting approval") . ")', " . "{$data['imageid']}, " . "{$data['seats']}, " . "{$data['groupid']}, " . "'{$data['type']}', " . "{$user['id']}, " . "'{$data['expiretime']}', " . "'requested', " . "'{$esccomments}')";
        doQuery($query, 101);
        $blockreqid = dbLastInsertID();
        # send email notifying about a new block allocation request
        $imagedata = getImages(0, $data['imageid']);
        if ($data['groupid'] == 0) {
            $grpname = "(Unspecified)";
        } else {
            $grpname = getUserGroupName($data['groupid']);
        }
        if (!empty($data['comments'])) {
            $comments = "Comments:\n{$data['comments']}\n";
        } else {
            $comments = '';
        }
        $message = "A new block allocation request has been submitted by ";
        if (!empty($user['firstname']) && !empty($user['lastname']) && !empty($user['email'])) {
            $message .= "{$user['firstname']} {$user['lastname']} ({$user['email']}). ";
        } elseif (!empty($user['email'])) {
            $message .= "{$user['email']}. ";
        } else {
            $message .= "{$user['unityid']}. ";
        }
        $message .= "Please visit the following URL to accept or reject it:\n\n" . BASEURL . SCRIPT . "?mode=blockAllocations\n\n" . "Image: {$imagedata[$data['imageid']]['prettyname']}\n" . "Seats: {$data['seats']}\n" . "User Group: {$grpname}\n{$comments}\n\n" . "This is an automated message sent by VCL.\n" . "You are receiving this message because you have access " . "to create and approve block allocations.";
        $mailParams = "-f" . ENVELOPESENDER;
        $blockNotifyUsers = getBlockNotifyUsers($user['affiliationid']);
        mail($blockNotifyUsers, "VCL Block Allocation Request ({$user['unityid']})", $message, '', $mailParams);
    }
    if ($data['type'] == 'weekly') {
        $query = "INSERT INTO blockWebDate " . "(blockRequestid, " . "start, " . "end, " . "days) " . "VALUES " . "({$blockreqid}, " . "'{$data['startdate']}', " . "'{$data['enddate']}', " . "{$data['daymask']})";
        doQuery($query, 101);
        $today = mktime(0, 0, 0);
        if ($method == 'edit' && $data['startts'] < $today) {
            createWeeklyBlockTimes($blockreqid, $today, $data['endts'], $data['daymask'], $data['times']);
        } elseif ($method == 'new' || $method == 'edit') {
            createWeeklyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['daymask'], $data['times']);
        }
    } elseif ($data['type'] == 'monthly') {
        $query = "INSERT INTO blockWebDate " . "(blockRequestid, " . "start, " . "end, " . "days, " . "weeknum) " . "VALUES " . "({$blockreqid}, " . "'{$data['startdate']}', " . "'{$data['enddate']}', " . "{$data['day']}, " . "{$data['weeknum']})";
        doQuery($query, 101);
        $today = mktime(0, 0, 0);
        if ($method == 'edit' && $data['startts'] < $today) {
            createMonthlyBlockTimes($blockreqid, $today, $data['endts'], $data['day'], $data['weeknum'], $data['times']);
        } elseif ($method == 'new' || $method == 'edit') {
            createMonthlyBlockTimes($blockreqid, $data['startts'], $data['endts'], $data['day'], $data['weeknum'], $data['times']);
        }
    }
    if ($data['type'] == 'weekly' || $data['type'] == 'monthly') {
        $vals = array();
        $i = 0;
        foreach ($data['times'] as $time) {
            $tmp = explode('|', $time);
            $start = explode(':', $tmp[0]);
            $startmin = $start[1];
            list($starth, $startm) = hour24to12($start[0]);
            $end = explode(':', $tmp[1]);
            $endmin = $end[1];
            list($endh, $endm) = hour24to12($end[0]);
            $vals[] = "({$blockreqid}, " . "'{$starth}', " . "'{$startmin}', " . "'{$startm}', " . "'{$endh}', " . "'{$endmin}', " . "'{$endm}', " . "{$i})";
            $i++;
        }
        $allvals = implode(',', $vals);
        $query = "INSERT INTO blockWebTime " . "(blockRequestid, " . "starthour, " . "startminute, " . "startmeridian, " . "endhour, " . "endminute, " . "endmeridian, " . "`order`) " . "VALUES {$allvals}";
        doQuery($query, 101);
    }
    if ($data['type'] == 'list') {
        createListBlockData($blockreqid, $data['slots'], $method);
    }
    if ($method == 'edit' && $checkCurBlockTime) {
        $query = "SELECT id, " . "start, " . "end " . "FROM blockTimes " . "WHERE start <= NOW() AND " . "end > NOW() AND " . "blockRequestid = {$blockreqid} AND " . "id != {$curBlockTime['id']}";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_assoc($qh)) {
            if ($curBlockTime['end'] != $row['end']) {
                # update old end time
                $query = "UPDATE blockTimes " . "SET end = '{$row['end']}' " . "WHERE id = {$curBlockTime['id']}";
                doQuery($query, 101);
            }
            # delete $row entry
            doQuery("DELETE FROM blockTimes WHERE id = {$row['id']}", 101);
        } else {
            # the blockTime we were in the middle of was not recreated, so
            #    delete the old one
            doQuery("DELETE FROM blockTimes WHERE id = {$curBlockTime['id']}", 101);
        }
    }
    if ($method == 'request') {
        print "clearHideConfirmForm();";
        $txt = "<h2>" . i("Request New Block Allocation") . "</h2>";
        $txt .= i("Your request for a Block Allocation has been submitted for approval.") . " ";
        if (!empty($user['email'])) {
            $txt .= i("You should be notified within a few business days of its acceptance or rejection.");
        } else {
            $txt .= "<br><br><font color=\"red\"><strong>" . i("Note:") . "</strong> ";
            $h = "      " . i("You do not have an email address registered with VCL. Therefore, you will not receive automatic notification when this block allocation is accepted or rejected.");
            $txt .= preg_replace("/(.{1,50}([ \n]|\$))/", '\\1<br>', $h) . "</font>";
        }
        print "dojo.byId('content').innerHTML = '{$txt}';";
        print "scroll(0, 0);";
        return;
    }
    print "window.location.href = '" . BASEURL . SCRIPT . "?mode=blockAllocations';";
}
Esempio n. 3
0
function checkForGroupUsage($groupid, $type, &$msg = '')
{
    global $user;
    $msgs = array();
    if ($type == "user") {
        $name = getUserGroupName($groupid, 1);
        if ($name === 0) {
            return 0;
        }
        # resourcegroup.ownerusergroupid
        $query = "SELECT CONCAT(rt.name, '/', rg.name) AS name " . "FROM resourcegroup rg, " . "resourcetype rt " . "WHERE ownerusergroupid = {$groupid} AND " . "rg.resourcetypeid = rt.id";
        $usedby = array();
        $qh = doQuery($query, 310);
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Owning User Group for Resource Groups</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # usergroup.editusergroupid
        $query = "SELECT CONCAT(ug.name, '@', a.name) AS name " . "FROM usergroup ug, " . "affiliation a " . "WHERE ug.editusergroupid = {$groupid} AND " . "ug.id != {$groupid} AND " . "ug.affiliationid = a.id";
        $usedby = array();
        $qh = doQuery($query, 313);
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>'Editable by' Group for User Groups</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # userpriv.usergroupid
        $query = "SELECT DISTINCT privnodeid " . "FROM userpriv " . "WHERE usergroupid = {$groupid}";
        $qh = doQuery($query);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = getNodePath($row['privnodeid']);
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Assigned at Privilege Nodes</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # blockRequest.groupid
        $query = "SELECT name " . "FROM blockRequest " . "WHERE groupid = {$groupid} " . "AND status IN ('requested', 'accepted')";
        $qh = doQuery($query, 311);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Assigned for Block Allocations</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # serverprofile.admingroupid
        $query = "SELECT name FROM serverprofile WHERE admingroupid = {$groupid}";
        $qh = doQuery($query);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Admin User Group for Server Profiles</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # serverprofile.logingroupid
        $query = "SELECT name FROM serverprofile WHERE logingroupid = {$groupid}";
        $qh = doQuery($query);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Access User Group for Server Profiles</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # serverrequest.admingroupid
        $query = "SELECT s.name " . "FROM serverrequest s, " . "request rq " . "WHERE s.admingroupid = {$groupid} AND " . "s.requestid = rq.id";
        $qh = doQuery($query);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Admin User Group for Server Requests</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        # serverrequest.logingroupid
        $query = "SELECT s.name " . "FROM serverrequest s, " . "request rq " . "WHERE s.logingroupid = {$groupid} AND " . "s.requestid = rq.id";
        $qh = doQuery($query);
        $usedby = array();
        while ($row = mysql_fetch_assoc($qh)) {
            $usedby[] = $row['name'];
        }
        if (count($usedby)) {
            $msgs[] = "<h3>Access User Group for Server Requests</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
        }
        if (count($msgs)) {
            $msg = "{$name} is currently in use in the following ways. It " . "cannot be deleted until it is no longer in use.<br><br>\n" . implode("<br>\n", $msgs);
            return 1;
        }
        return 0;
    }
    $name = getResourceGroupName($groupid);
    if (is_null($name)) {
        return 0;
    }
    # managementnode.imagelibgroupid
    $query = "SELECT hostname FROM managementnode WHERE imagelibgroupid = {$groupid}";
    $qh = doQuery($query);
    $usedby = array();
    while ($row = mysql_fetch_assoc($qh)) {
        $usedby[] = $row['hostname'];
    }
    if (count($usedby)) {
        $msgs[] = "<h3>Management Node Image Library Group</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
    }
    # resourcepriv.resourcegroupid
    $query = "SELECT DISTINCT privnodeid FROM resourcepriv WHERE resourcegroupid = {$groupid}";
    $qh = doQuery($query);
    $usedby = array();
    while ($row = mysql_fetch_assoc($qh)) {
        $usedby[] = getNodePath($row['privnodeid']);
    }
    if (count($usedby)) {
        $msgs[] = "<h3>Assigned at Privilege Nodes</h3>\n" . implode("<br>\n", $usedby) . "<br>\n";
    }
    if (count($msgs)) {
        $msg = "{$name} is currently in use in the following ways. It " . "cannot be deleted until it is no longer in use.<br><br>\n" . implode("<br>\n", $msgs);
        return 1;
    }
    return 0;
}
Esempio n. 4
0
function confirmBlockRequest()
{
    global $submitErr, $user, $days, $mode;
    $data = processBlockRequestInput();
    if ($submitErr) {
        newBlockRequest();
        return;
    }
    $images = getImages();
    // FIXME should we limit the course groups that show up?
    $groups = getUserGroups(0, $user['affiliationid']);
    if (!array_key_exists($data['usergroupid'], $groups)) {
        $groups[$data['usergroupid']] = array('name' => getUserGroupName($data['usergroupid'], 1));
    }
    if (!array_key_exists($data['admingroupid'], $groups)) {
        $groups[$data['admingroupid']] = array('name' => getUserGroupName($data['admingroupid'], 1));
    }
    $groups[0] = array('name' => 'None (owner only)');
    if ($data['state'] == 2) {
        print "<H2>Delete Block Reservation</H2>\n";
        print "Delete the following block reservation?<br>\n";
    } elseif ($data['state'] == 1) {
        print "<H2>Edit Block Reservation</H2>\n";
        print "Modify the following block reservation?<br>\n";
    } else {
        print "<H2>New Block Reservation</H2>\n";
        print "Create the following block reservation?<br>\n";
    }
    print "<table summary=\"\">\n";
    print "  <TR>\n";
    print "    <TH align=right nowrap>Name:</TH>\n";
    print "    <TD>{$data['blockname']}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right nowrap>Image:</TH>\n";
    print "    <TD>{$images[$data['imageid']]['prettyname']}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right nowrap>Reserved Machines:</TH>\n";
    print "    <TD>{$data['machinecnt']}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right nowrap>Reserved for:</TH>\n";
    print "    <TD>{$groups[$data['usergroupid']]['name']}</TD>\n";
    print "  </TR>\n";
    print "  <TR>\n";
    print "    <TH align=right nowrap>Manageable by:</TH>\n";
    print "    <TD>{$groups[$data['admingroupid']]['name']}</TD>\n";
    print "  </TR>\n";
    if ($data['available'] == 'weekly') {
        print "  <TR>\n";
        print "    <TH align=right nowrap>Repeating:</TH>\n";
        print "    <TD>Weekly</TD>\n";
        print "  </TR>\n";
        print "  <TR valign='top'>\n";
        print "    <TH valign='top' align=right nowrap>On these days:</TH>\n";
        print "    <TD>";
        foreach ($data['wdays'] as $day) {
            print "{$day}<br>";
        }
        print "</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>For these timeslots on<br>each of the above days:</TH>\n";
        print "    <TD>";
        for ($i = 0; $i < 4; $i++) {
            if ($data['stime'][$i] == $data['etime'][$i]) {
                continue;
            }
            if ($data['swminute'][$i] == 0) {
                $data['swminute'][$i] = "00";
            }
            if ($data['ewminute'][$i] == 0) {
                $data['ewminute'][$i] = "00";
            }
            print "{$data['swhour'][$i]}:{$data['swminute'][$i]} {$data['swmeridian'][$i]} - ";
            print "{$data['ewhour'][$i]}:{$data['ewminute'][$i]} {$data['ewmeridian'][$i]}<br>\n";
        }
        print "</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right nowrap>Starting:</TH>\n";
        print "    <TD>{$data['swdate']}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right nowrap>Ending:</TH>\n";
        print "    <TD>{$data['ewdate']}</TD>\n";
        print "  </TR>\n";
    } elseif ($data['available'] == 'monthly') {
        $weeknumArr = array(1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", 5 => "5th");
        print "  <TR>\n";
        print "    <TH align=right nowrap>Repeating:</TH>\n";
        print "    <TD>The {$weeknumArr[$data['weeknum']]} {$days[$data['day'] - 1]} of each month</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right>For these timeslots on<br>the above day of the month:</TH>\n";
        print "    <TD>";
        for ($i = 0; $i < 4; $i++) {
            if ($data['stime'][$i] == $data['etime'][$i]) {
                continue;
            }
            if ($data['smminute'][$i] == 0) {
                $data['smminute'][$i] = "00";
            }
            if ($data['emminute'][$i] == 0) {
                $data['emminute'][$i] = "00";
            }
            print "{$data['smhour'][$i]}:{$data['smminute'][$i]} {$data['smmeridian'][$i]} - ";
            print "{$data['emhour'][$i]}:{$data['emminute'][$i]} {$data['emmeridian'][$i]}<br>\n";
        }
        print "</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right nowrap>Starting:</TH>\n";
        print "    <TD>{$data['smdate']}</TD>\n";
        print "  </TR>\n";
        print "  <TR>\n";
        print "    <TH align=right nowrap>Ending:</TH>\n";
        print "    <TD>{$data['emdate']}</TD>\n";
        print "  </TR>\n";
    } elseif ($data['available'] == 'list') {
        print "  <TR valign=top>\n";
        print "    <TH align=right>For the following dates and times:</TH>\n";
        print "    <TD>\n";
        for ($i = 0; $i < 4; $i++) {
            if ($data['slhour'][$i] == $data['elhour'][$i] && $data['slminute'][$i] == $data['elminute'][$i] && $data['slmeridian'][$i] == $data['elmeridian'][$i]) {
                continue;
            }
            if ($data['slminute'][$i] == 0) {
                $data['slminute'][$i] = '00';
            }
            if ($data['elminute'][$i] == 0) {
                $data['elminute'][$i] = '00';
            }
            print "{$data['date'][$i]} {$data['slhour'][$i]}:{$data['slminute'][$i]} {$data['slmeridian'][$i]} to {$data['elhour'][$i]}:{$data['elminute'][$i]} {$data['elmeridian'][$i]}<br>\n";
        }
        print "    </TD>\n";
        print "  </TR>\n";
    }
    print "</table>\n";
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    if ($data['state'] == 2) {
        print "<INPUT type=submit value=Delete>\n";
        $cont = addContinuationsEntry('submitDeleteBlockRequest', $data, SECINDAY, 0, 0);
    } else {
        print "<INPUT type=submit value=Submit>\n";
        $cont = addContinuationsEntry('submitBlockRequest', $data, SECINDAY, 0, 0);
    }
    print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "</FORM>\n";
}
Esempio n. 5
0
function AJchangeUserGroupPrivs()
{
    global $user;
    $node = processInputVar("activeNode", ARG_NUMERIC);
    if (!checkUserHasPriv("userGrant", $user["id"], $node)) {
        $text = "You do not have rights to modify user privileges at this node.";
        print "alert('{$text}');";
        dbDisconnect();
        exit;
    }
    $newusergrpid = processInputVar("item", ARG_NUMERIC);
    $newusergrp = getUserGroupName($newusergrpid);
    $newpriv = processInputVar('priv', ARG_STRING);
    $newprivval = processInputVar('value', ARG_STRING);
    //print "alert('node: $node; newuser:grp $newuser;grp newpriv: $newpriv; newprivval: $newprivval');";
    # get cascade privs at this node
    $cascadePrivs = getNodeCascadePrivileges($node, "usergroups");
    // if $newprivval is true and $newusergrp already has $newpriv
    //   cascaded to it, do nothing
    if ($newprivval == 'true') {
        if (array_key_exists($newusergrp, $cascadePrivs['usergroups']) && in_array($newpriv, $cascadePrivs['usergroups'][$newusergrp]['privs'])) {
            dbDisconnect();
            exit;
        }
        // add priv
        $adds = array($newpriv);
        $removes = array();
    } else {
        // remove priv
        $adds = array();
        $removes = array($newpriv);
    }
    updateUserOrGroupPrivs($newusergrpid, $node, $adds, $removes, "group");
    $_SESSION['dirtyprivs'] = 1;
    dbDisconnect();
    exit;
}
Esempio n. 6
0
function editOrAddGroup($state)
{
    global $submitErr, $user, $mode, $viewmode;
    $usergroups = getUserGroups(1);
    if ($user['showallgroups']) {
        $affilusergroups = $usergroups;
    } else {
        $affilusergroups = getUserGroups(1, $user['affiliationid']);
    }
    $resourcegroups = getResourceGroups();
    $affils = getAffiliations();
    $resourcetypes = getTypes("resources");
    if ($submitErr) {
        $data = processGroupInput(0);
        $newuser = processInputVar("newuser", ARG_STRING);
        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 {
        $newuser = processInputVar("newuser", ARG_STRING);
        $data["groupid"] = getContinuationVar("groupid");
        $data["type"] = getContinuationVar("type");
        $data["isowner"] = getContinuationVar("isowner");
        $id = $data["groupid"];
        if ($data["type"] == "user") {
            $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"];
            $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 {
            list($grouptype, $data["name"]) = explode('/', $resourcegroups[$id]["name"]);
            $ownerid = $resourcegroups[$id]["ownerid"];
        }
    }
    $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>\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";
        }
        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 ($data["type"] == "user") {
            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>\n";
            if (!empty($data['editgroupid']) && !array_key_exists($data['editgroupid'], $affilusergroups)) {
                $affilusergroups[$data['editgroupid']] = array('name' => getUserGroupName($data['editgroupid'], 1));
                uasort($affilusergroups, "sortKeepIndex");
            }
            printSelectInput("editgroupid", $affilusergroups, $data["editgroupid"]);
            print "    </TD>\n";
            print "    <TD></TD>";
            print "  </TR>\n";
            print "  <TR>\n";
            print "    <TH align=right>Initial Max Time (minutes):</TH>\n";
            print "    <TD><INPUT type=text name=initialmax value=\"";
            print $data["initialmax"] . "\" maxlength=4></TD>\n";
            print "    <TD>";
            printSubmitErr(INITIALMAXERR);
            print "</TD>\n";
            print "  </TR>\n";
            print "  <TR>\n";
            print "    <TH align=right>Total Max Time (minutes):</TH>\n";
            print "    <TD><INPUT type=text name=totalmax value=\"";
            print $data["totalmax"] . "\" maxlength=4></TD>\n";
            print "    <TD>";
            printSubmitErr(TOTALMAXERR);
            print "</TD>\n";
            print "  </TR>\n";
            print "  <TR>\n";
            print "    <TH align=right>Max Extend Time (minutes):</TH>\n";
            print "    <TD><INPUT type=text name=maxextend value=\"";
            print $data["maxextend"] . "\" maxlength=4></TD>\n";
            print "    <TD>";
            printSubmitErr(MAXEXTENDERR);
            print "</TD>\n";
            print "  </TR>\n";
            if ($viewmode == ADMIN_DEVELOPER) {
                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 (!array_key_exists($ownerid, $affilusergroups)) {
                $affilusergroups[$ownerid] = $usergroups[$ownerid];
                uasort($affilusergroups, "sortKeepIndex");
            }
            printSelectInput("ownergroup", $affilusergroups, $ownerid);
            print "    </TD>\n";
            print "    <TD></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'], 'isowner' => $data['isowner']);
            $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']);
            if ($data['type'] == 'resource') {
                $cdata['resourcetypeid'] = $resourcetypeid;
            } else {
                $cdata['selectAffil'] = $selectAffil;
            }
            $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") {
        return;
    }
    if ($editusergroup) {
        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"]);
        print "<TABLE border=1>\n";
        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";
            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";
    }
}
Esempio n. 7
0
function AJsubmitAddUserGroupPriv()
{
    global $user;
    $node = processInputVar("activeNode", ARG_NUMERIC);
    if (!checkUserHasPriv("userGrant", $user["id"], $node)) {
        $text = "You do not have rights to add new user groups at this node.";
        print "addUserGroupPaneHide(); ";
        print "alert('{$text}');";
        return;
    }
    $newgroupid = processInputVar("newgroupid", ARG_NUMERIC);
    $newgroup = getUserGroupName($newgroupid);
    if ($newgroup === 0) {
        $text = "Invalid user group submitted.";
        print "alert('{$text}');";
        return;
    }
    $perms = explode(':', processInputVar('perms', ARG_STRING));
    $usertypes = getTypes("users");
    array_push($usertypes["users"], "block");
    array_push($usertypes["users"], "cascade");
    $newgroupprivs = array();
    foreach ($usertypes["users"] as $type) {
        if (in_array($type, $perms)) {
            array_push($newgroupprivs, $type);
        }
    }
    if (empty($newgroupprivs) || count($newgroupprivs) == 1 && in_array("cascade", $newgroupprivs)) {
        $text = "<font color=red>No user group privileges were specified</font>";
        print setAttribute('addUserGroupPrivStatus', 'innerHTML', $text);
        return;
    }
    updateUserOrGroupPrivs($newgroupid, $node, $newgroupprivs, array(), "group");
    clearPrivCache();
    print "refreshPerms(); ";
    print "addUserGroupPaneHide(); ";
}