Beispiel #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;
}
function AJgetBlockAllocatedMachineData()
{
    global $user;
    $start = processInputVar('start', ARG_STRING);
    if (!preg_match('/^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}$/', $start)) {
        $start = unixFloor15(time() - 3600);
        $startdt = unixToDatetime($start);
    } else {
        $startdt = "{$start}:00";
        $start = datetimeToUnix($startdt);
    }
    $end = $start + 12 * 3600;
    $enddt = unixToDatetime($end);
    $alldata = array();
    # bare
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'blade'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype != 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['bare'] = $data;
    # virtual
    $data = array();
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT COUNT(id) " . "FROM computer " . "WHERE stateid IN (2, 3, 6, 8, 11) AND " . "type = 'virtualmachine'";
        $qh = doQuery($query, 101);
        if ($row = mysql_fetch_row($qh)) {
            $data['total'] = $row[0];
        }
    } else {
        // TODO once we allow limiting total machines by affiliation, put that value here
        $data['total'] = 0;
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    if (checkUserHasPerm('Manage Block Allocations (global)')) {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware'";
    } else {
        $query = "SELECT UNIX_TIMESTAMP(bt.start) as start, " . "UNIX_TIMESTAMP(bt.end) as end, " . "br.numMachines " . "FROM blockTimes bt, " . "blockRequest br, " . "image i, " . "OS o, " . "user u " . "WHERE bt.blockRequestid = br.id AND " . "bt.skip = 0 AND " . "bt.start < '{$enddt}' AND " . "bt.end > '{$startdt}' AND " . "br.imageid = i.id AND " . "i.OSid = o.id AND " . "o.installtype = 'vmware' AND " . "br.ownerid = u.id AND " . "u.affiliationid = {$user['affiliationid']}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        for ($binstart = $start, $binend = $start + 900, $binindex = 0; $binend <= $end; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y'] += $row['numMachines'];
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $start, $i = 0; $time < $end; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    $alldata['virtual'] = $data;
    $val = getContinuationVar('val') + 1;
    $cont = addContinuationsEntry('AJgetBlockAllocatedMachineData', array('val' => $val), SECINDAY, 1, 0);
    $alldata['cont'] = $cont;
    sendJSON($alldata);
}
Beispiel #3
0
function editRequest()
{
    global $submitErr, $user;
    $requestid = getContinuationVar('requestid', 0);
    $request = getRequestInfo($requestid);
    if (!array_key_exists("stateid", $request)) {
        viewRequests();
        return;
    }
    if ($request['forimaging']) {
        $reservation = $request['reservations'][0];
    } else {
        foreach ($request["reservations"] as $res) {
            if ($res["forcheckout"]) {
                $reservation = $res;
                break;
            }
        }
    }
    if ($submitErr) {
        $data = processRequestInput(0);
    }
    $groupid = getUserGroupID('Specify End Time', 1);
    $members = getUserGroupMembers($groupid);
    if (array_key_exists($user['id'], $members)) {
        $openend = 1;
    } else {
        $openend = 0;
    }
    $unixstart = datetimeToUnix($request["start"]);
    $unixend = datetimeToUnix($request["end"]);
    $maxtimes = getUserMaxTimes("initialmaxtime");
    $timeToNext = timeToNextReservation($request);
    print "<H2>Modify Reservation</H2>\n";
    $now = time();
    if ($unixstart > $now) {
        $started = 0;
    } else {
        # \todo if $timeToNext is anything < 30, try moving reservations off until it is >= 30
        if ($timeToNext == 0) {
            $movedall = 1;
            foreach ($request["reservations"] as $res) {
                if (!moveReservationsOffComputer($res["computerid"], 1)) {
                    $movedall = 0;
                    break;
                }
            }
            if (!$movedall) {
                // cannot extend the reservation unless we move the next one to another computer
                print "The computer you are using has another reservation ";
                print "immediately following yours. Therefore, you cannot extend ";
                print "your reservation because it would overlap with the next ";
                print "one.<br>\n";
                return;
            }
            $timeToNext = timeToNextReservation($request);
        }
        $started = 1;
        print "Because this reservation has already started, you can only ";
        print "extend the length of the reservation. ";
        if (!$openend) {
            print "If there are no reservations following yours, ";
            print "you can extend your reservation ";
            print "by up to " . minToHourMin($maxtimes["extend"]) . ", but not ";
            print "exceeding " . minToHourMin($maxtimes["total"]) . " for your ";
            print "total reservation time.<br><br>\n";
        }
    }
    print "Modify reservation for <b>" . $reservation["prettyimage"];
    print "</b> starting ";
    if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
        print prettyDatetime($request["daterequested"]);
    } else {
        print prettyDatetime($request["start"]);
    }
    print ":<br><br>\n";
    $start = date('l,g,i,a', datetimeToUnix($request["start"]));
    $startArr = explode(',', $start);
    $len = ($unixend - $unixstart) / 60;
    $cdata = array();
    if ($started) {
        $inputday = date('n/j/Y', datetimeToUnix($request["start"]));
        $cdata['day'] = $inputday;
        $cdata['hour'] = $startArr[1];
        $cdata['minute'] = $startArr[2];
        $cdata['meridian'] = $startArr[3];
        # determine the current total length of the reservation
        $reslen = ($unixend - unixFloor15($unixstart)) / 60;
        $timeval = getdate($unixstart);
        if ($timeval["minutes"] % 15 != 0) {
            $reslen -= 15;
        }
        if (!$openend && $reslen >= $maxtimes["total"]) {
            print "You are only allowed to extend your reservation such that it ";
            print "has a total length of " . minToHourMin($maxtimes["total"]);
            print ". This reservation already meets that length. Therefore, ";
            print "you are not allowed to extend your reservation any further.<br><br>\n";
            printEditNewUpdate($request, $reservation);
            return;
        }
        //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 ($timeToNext == -1) {
            // there is no following reservation
            if ($reslen + 15 <= $maxtimes["total"] && 15 <= $maxtimes["extend"]) {
                $lengths["15"] = "15 minutes";
            }
            if ($reslen + 30 <= $maxtimes["total"] && 30 <= $maxtimes["extend"]) {
                $lengths["30"] = "30 minutes";
            }
            if ($reslen + 60 <= $maxtimes["total"] && 60 <= $maxtimes["extend"]) {
                $lengths["60"] = "1 hour";
            }
            for ($i = 120; $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"]; $i += 60) {
                $lengths[$i] = $i / 60 . " hours";
            }
        } else {
            if ($timeToNext >= 15 && $reslen + 15 <= $maxtimes["total"] && 15 <= $maxtimes["extend"]) {
                $lengths["15"] = "15 minutes";
            }
            if ($timeToNext >= 30 && $reslen + 30 <= $maxtimes["total"] && 30 <= $maxtimes["extend"]) {
                $lengths["30"] = "30 minutes";
            }
            if ($timeToNext >= 60 && $reslen + 60 <= $maxtimes["total"] && 60 <= $maxtimes["extend"]) {
                $lengths["60"] = "1 hour";
            }
            for ($i = 120; $i <= $timeToNext && $reslen + $i <= $maxtimes["total"] && $i <= $maxtimes["extend"]; $i += 60) {
                $lengths[$i] = $i / 60 . " hours";
            }
        }
        # do we need this?
        /*if($timeToNext > 60 && (($reslen + $timeToNext) <= $maxtimes["total"]) && ($timeToNext <= $maxtimes["extend"]))
        		if($timeToNext % 60 == 0)
        			$lengths[$timeToNext] = $timeToNext / 60 . " hours";
        		else
        			$lengths[$timeToNext] = sprintf("%.2f hours", $timeToNext / 60);*/
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
        if ($openend) {
            if (!empty($lengths)) {
                if ($submitErr && $data['ending'] == 'date') {
                    $chk['length'] = '';
                    $chk['date'] = 'checked';
                } else {
                    $chk['length'] = 'checked';
                    $chk['date'] = '';
                }
                print "<INPUT type=radio name=ending value=length {$chk['length']}>";
                print "Extend reservation by:\n";
                if ($submitErr) {
                    printSelectInput("length", $lengths, $data['length']);
                } else {
                    printSelectInput("length", $lengths, 30);
                }
                print "<br><INPUT type=radio name=ending value=date {$chk['date']}>";
            } else {
                print "<INPUT type=hidden name=ending value=date>\n";
            }
            print "Change ending to:\n";
            $enddate = $request['end'];
            if ($submitErr) {
                $enddate = $data['enddate'];
            }
            print "<INPUT type=text name=enddate size=20 value=\"{$enddate}\">(YYYY-MM-DD HH:MM:SS)\n";
            printSubmitErr(ENDDATEERR);
            if ($timeToNext > -1) {
                $extend = $unixend + ($timeToNext - 15) * 60;
                $extend = unixToDatetime($extend);
                print "<br><font color=red><strong>NOTE:</strong> Due to an upcoming ";
                print "reservation on the same computer,<br>\n";
                print "you can only extend this reservation until {$extend}.</font>\n";
            }
        } else {
            print "Extend reservation by: \n";
            printSelectInput("length", $lengths, 30);
        }
        print "<br>\n";
        $cdata['started'] = 1;
    } else {
        print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
        printReserveItems(1, $startArr[0], $startArr[1], $startArr[2], $startArr[3], $len, 1);
        $cdata['started'] = 0;
    }
    print "<br>\n";
    print "<table summary=\"\">\n";
    print "  <TR valign=top>\n";
    print "    <TD>\n";
    $cdata['requestid'] = $requestid;
    $cdata['openend'] = $openend;
    $cdata['imageid'] = $reservation['imageid'];
    $cont = addContinuationsEntry('confirmEditRequest', $cdata, SECINDAY, 0, 1, 1);
    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";
    $cont = addContinuationsEntry('viewRequests');
    print "      <INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "      <INPUT type=submit value=Cancel>\n";
    print "      </FORM>\n";
    print "    </TD>\n";
    print "  </TR>\n";
    print "</table>\n";
    printEditNewUpdate($request, $reservation);
}
Beispiel #4
0
function getTimeSlots($compids, $end = 0, $start = 0)
{
    global $viewmode;
    if (empty($compids)) {
        return array();
    }
    $requestid = processInputVar("requestid", ARG_NUMERIC, 0);
    $platsel = getContinuationVar("platforms");
    if (empty($platsel)) {
        $platsel = processInputVar("platforms", ARG_MULTINUMERIC);
    }
    $schsel = getContinuationVar("schedules");
    if (empty($schsel)) {
        $schsel = processInputVar("schedules", ARG_MULTINUMERIC);
    }
    # all computations done with unix timestamps
    if ($end != 0) {
        $enddate = unixToDatetime($end);
    }
    if ($start != 0) {
        $startdate = unixToDatetime($start);
    }
    $computerids = array();
    $reservedComputerids = array();
    $schedules = getSchedules();
    $times = array();
    $scheduleids = array();
    $compinlist = implode(",", $compids);
    $query = "SELECT id, scheduleid " . "FROM computer " . "WHERE scheduleid IS NOT NULL AND " . "scheduleid != 0 AND " . "id IN ({$compinlist}) ";
    if (!empty($schsel) && !empty($platsel)) {
        $schinlist = implode(',', $schsel);
        $platinlist = implode(',', $platsel);
        $query .= "AND scheduleid IN ({$schinlist}) " . "AND platformid IN ({$platinlist})";
    }
    $qh = doQuery($query, 155);
    while ($row = mysql_fetch_row($qh)) {
        array_push($computerids, $row[0]);
        $times[$row[0]] = array();
        $scheduleids[$row[0]] = $row[1];
    }
    if ($start != 0 && $end != 0) {
        $query = "SELECT rs.computerid, " . "rq.start, " . "rq.end + INTERVAL 900 SECOND AS end, " . "rq.id, " . "u.unityid, " . "i.prettyname " . "FROM reservation rs, " . "request rq, " . "user u, " . "image i " . "WHERE (rq.start < '{$enddate}' AND " . "rq.end > '{$startdate}') AND " . "rq.id = rs.requestid AND " . "u.id = rq.userid AND " . "i.id = rs.imageid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY rs.computerid, " . "rq.start";
    } else {
        $query = "SELECT rs.computerid, " . "rq.start, " . "rq.end + INTERVAL 900 SECOND AS end, " . "rq.id, " . "u.unityid, " . "i.prettyname " . "FROM reservation rs, " . "request rq, " . "user u, " . "image i " . "WHERE rq.end > NOW() AND " . "rq.id = rs.requestid AND " . "u.id = rq.userid AND " . "i.id = rs.imageid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY rs.computerid, " . "rq.start";
    }
    $qh = doQuery($query, 156);
    $id = "";
    while ($row = mysql_fetch_row($qh)) {
        if ($row[3] == $requestid) {
            continue;
        }
        if ($id != $row[0]) {
            $count = 0;
            $id = $row[0];
            array_push($reservedComputerids, $id);
        }
        $times[$id][$count] = array();
        $times[$id][$count]["start"] = datetimeToUnix($row[1]);
        $times[$id][$count]["end"] = datetimeToUnix($row[2]);
        $times[$id][$count]["requestid"] = $row[3];
        $times[$id][$count]["unityid"] = $row[4];
        $times[$id][$count++]["prettyimage"] = $row[5];
    }
    # use floor function to get to a 15 min increment for start
    if ($start != 0) {
        $start = unixFloor15($start);
    } else {
        $start = unixFloor15() + 900;
    }
    # last time to look at
    if ($end != 0) {
        $endtime = $end;
    } else {
        $endtime = $start + DAYSAHEAD * SECINDAY;
    }
    $blockData = getBlockTimeData($start, $endtime);
    $reserveInfo = array();
    // 0 = reserved, 1 = available
    foreach ($computerids as $id) {
        $reserveInfo[$id] = array();
        $first = 1;
        # loop from $start to $endtime by 15 minute increments
        for ($current = $start, $count = 0, $max = count($times[$id]); $current < $endtime; $current += 900) {
            /*print "compid - $id<br>\n";
            		print "count - $count<br>\n";
            		print "current - " . unixToDatetime($current) . "<br>\n";
            		if(array_key_exists($count, $times[$id])) {
            			print "start - " . unixToDatetime($times[$id][$count]["start"]) . "<br>\n";
            			print "end - " . unixToDatetime($times[$id][$count]["end"]) . "<br>\n";
            		}
            		print "-----------------------------------------------------<br>\n";*/
            $reserveInfo[$id][$current]['blockRequest'] = 0;
            if (scheduleClosed($id, $current, $schedules[$scheduleids[$id]])) {
                $reserveInfo[$id][$current]["available"] = 0;
                $reserveInfo[$id][$current]["scheduleclosed"] = 1;
                continue;
            }
            if ($blockid = isBlockRequestTime($id, $current, $blockData)) {
                $reserveInfo[$id][$current]['blockRequest'] = 1;
                $reserveInfo[$id][$current]['blockRequestInfo']['groupid'] = $blockData[$blockid]['groupid'];
                $reserveInfo[$id][$current]['blockRequestInfo']['imageid'] = $blockData[$blockid]['imageid'];
                $reserveInfo[$id][$current]['blockRequestInfo']['name'] = $blockData[$blockid]['name'];
                $reserveInfo[$id][$current]['blockRequestInfo']['image'] = $blockData[$blockid]['image'];
            }
            $reserveInfo[$id][$current]["scheduleclosed"] = 0;
            //if computer not in $reservedComputerids, it is free
            if (!in_array($id, $reservedComputerids)) {
                $reserveInfo[$id][$current]["available"] = 1;
                continue;
            }
            //if past an end
            if ($count != $max && $current >= $times[$id][$count]["end"]) {
                $count++;
            }
            # past the end of all reservations
            if ($count == $max) {
                $reserveInfo[$id][$current]["available"] = 1;
                continue;
            }
            //if before any start times
            if ($count == 0 && $current < $times[$id][0]["start"]) {
                $reserveInfo[$id][$current]["available"] = 1;
                continue;
            }
            //if between a start and end time
            if ($current >= $times[$id][$count]["start"] && $current < $times[$id][$count]["end"]) {
                if ($first) {
                    # set the previous 15 minute block to show as busy to allow for load time
                    $first = 0;
                    $reserveInfo[$id][$current - 900]['blockRequest'] = 0;
                    $reserveInfo[$id][$current - 900]["scheduleclosed"] = 0;
                    $reserveInfo[$id][$current - 900]["available"] = 0;
                    $reserveInfo[$id][$current - 900]["requestid"] = $times[$id][$count]["requestid"];
                    $reserveInfo[$id][$current - 900]["unityid"] = $times[$id][$count]["unityid"];
                    $reserveInfo[$id][$current - 900]["prettyimage"] = $times[$id][$count]["prettyimage"];
                }
                $reserveInfo[$id][$current]["available"] = 0;
                $reserveInfo[$id][$current]["requestid"] = $times[$id][$count]["requestid"];
                $reserveInfo[$id][$current]["unityid"] = $times[$id][$count]["unityid"];
                $reserveInfo[$id][$current]["prettyimage"] = $times[$id][$count]["prettyimage"];
                continue;
            }
            //if after previous end but before this start
            if ($current >= $times[$id][$count - 1]["end"] && $current < $times[$id][$count]["start"]) {
                $reserveInfo[$id][$current]["available"] = 1;
                continue;
            }
            # shouldn't get here; print debug info if we do
            if ($viewmode == ADMIN_DEVELOPER) {
                print "******************************************************<br>\n";
                print "current - " . unixToDatetime($current) . "<br>\n";
                print "endtime - " . unixToDatetime($endtime) . "<br>\n";
                print "count - {$count}<br>\n";
                print "max - {$max}<br>\n";
                print "start - " . unixToDatetime($times[$id][$count]["start"]) . "<br>\n";
                print "end - " . unixToDatetime($times[$id][$count]["end"]) . "<br>\n";
                print "------------------------------------------------------<br>\n";
            }
        }
    }
    return $reserveInfo;
}
Beispiel #5
0
function getActiveResChartData()
{
    $data = array();
    $chartstart = unixFloor15(time() - 12 * 3600);
    $chartend = $chartstart + 12 * 3600 + 900;
    for ($time = $chartstart, $i = 0; $time < $chartend; $time += 900, $i++) {
        $fmttime = date('g:i a', $time);
        $data["points"][$i] = array('x' => $i, 'y' => 0, 'value' => $i, 'text' => $fmttime);
    }
    $data['maxy'] = 0;
    $reloadid = getUserlistID('vclreload@Local');
    $affilid = getDashboardAffilID();
    if ($affilid == 0) {
        $query = "SELECT l.id, " . "UNIX_TIMESTAMP(l.start) AS start, " . "UNIX_TIMESTAMP(l.finalend) AS end, " . "rq.stateid, " . "rq.laststateid " . "FROM log l " . "LEFT JOIN request rq ON (l.requestid = rq.id) " . "WHERE l.start < NOW() AND " . "l.finalend > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND " . "l.ending NOT IN ('failed', 'failedtest') AND " . "l.wasavailable = 1 AND " . "l.userid != {$reloadid}";
    } else {
        $query = "SELECT l.id, " . "UNIX_TIMESTAMP(l.start) AS start, " . "UNIX_TIMESTAMP(l.finalend) AS end, " . "rq.stateid, " . "rq.laststateid " . "FROM user u, " . "log l " . "LEFT JOIN request rq ON (l.requestid = rq.id) " . "WHERE l.userid = u.id AND " . "u.affiliationid = {$affilid} AND " . "l.start < NOW() AND " . "l.finalend > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND " . "l.ending NOT IN ('failed', 'failedtest') AND " . "l.wasavailable = 1 AND " . "l.userid != {$reloadid}";
    }
    $qh = doQuery($query, 101);
    while ($row = mysql_fetch_assoc($qh)) {
        if ($row['stateid'] == 14) {
            $row['stateid'] = $row['laststateid'];
        }
        if ($row['end'] > time() && (is_null($row['stateid']) || preg_match('/^(1|5|10|11|12|16|17|18|19|21|22)$/', $row['stateid']))) {
            continue;
        }
        for ($binstart = $chartstart, $binend = $chartstart + 900, $binindex = 0; $binend <= $chartend; $binstart += 900, $binend += 900, $binindex++) {
            if ($binend <= $row['start']) {
                continue;
            } elseif ($row['start'] < $binend && $row['end'] > $binstart) {
                $data["points"][$binindex]['y']++;
            } elseif ($binstart >= $row['end']) {
                break;
            }
        }
    }
    for ($time = $chartstart, $i = 0; $time < $chartend; $time += 900, $i++) {
        if ($data["points"][$i]['y'] > $data['maxy']) {
            $data['maxy'] = $data['points'][$i]['y'];
        }
        $data["points"][$i]['tooltip'] = "{$data['points'][$i]['text']}: {$data['points'][$i]['y']}";
    }
    return $data;
}
Beispiel #6
0
function XMLRPCaddRequest($imageid, $start, $length, $foruser = '')
{
    global $user;
    $imageid = processInputData($imageid, ARG_NUMERIC);
    $start = processInputData($start, ARG_STRING, 1);
    $length = processInputData($length, ARG_NUMERIC);
    #$foruser = processInputData($foruser, ARG_STRING, 1);
    // make sure user didn't submit a request for an image he
    // doesn't have access to
    $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
    $validImageids = array_keys($resources['image']);
    if (!in_array($imageid, $validImageids)) {
        return array('status' => 'error', 'errorcode' => 3, 'errormsg' => "access denied to {$imageid}");
    }
    # validate $start
    if ($start != 'now' && !is_numeric($start)) {
        return array('status' => 'error', 'errorcode' => 4, 'errormsg' => "received invalid input");
    }
    # validate $length
    $maxtimes = getUserMaxTimes();
    if ($maxtimes['initial'] < $length) {
        return array('status' => 'error', 'errorcode' => 6, 'errormsg' => "max allowed initial length is {$maxtimes['initial']} minutes");
    }
    $nowfuture = 'future';
    if ($start == 'now') {
        $start = time();
        $nowfuture = 'now';
    } else {
        if ($start < time() - 30) {
            return array('status' => 'error', 'errorcode' => 5, 'errormsg' => "start time is in the past");
        }
    }
    $start = unixFloor15($start);
    $end = $start + $length * 60;
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max)) {
        return array('status' => 'error', 'errorcode' => 7, 'errormsg' => "reservation overlaps with another one you " . "have, and you are allowed {$max} " . "overlapping reservations at a time");
    }
    $images = getImages();
    $rc = isAvailable($images, $imageid, $start, $end, '');
    if ($rc < 1) {
        addLogEntry($nowfuture, unixToDatetime($start), unixToDatetime($end), 0, $imageid);
        return array('status' => 'notavailable');
    }
    $return['requestid'] = addRequest();
    $return['status'] = 'success';
    return $return;
}
Beispiel #7
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');
}