Exemplo n.º 1
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);
}
Exemplo n.º 2
0
function createSelectImage()
{
    global $submitErr, $user;
    $timestamp = processInputVar("stamp", ARG_NUMERIC);
    $imageid = processInputVar("imageid", ARG_STRING);
    $length = processInputVar("length", ARG_NUMERIC);
    $day = processInputVar("day", ARG_STRING);
    $hour = processInputVar("hour", ARG_NUMERIC);
    $minute = processInputVar("minute", ARG_NUMERIC);
    $meridian = processInputVar("meridian", ARG_STRING);
    if (!$submitErr) {
        print "<H2>Create / Update an Image</H2>\n";
    }
    $resources = getUserResources(array("imageAdmin"));
    if (empty($resources['image'])) {
        print "You don't have access to any base images from which to create ";
        print "new images.<br>\n";
        return;
    }
    print "Please select the environment you will be updating or using as a ";
    print "base for a new image:<br>\n";
    $OSs = getOSList();
    print "<FORM action=\"" . BASEURL . SCRIPT . "\" method=post>\n";
    // list of images
    uasort($resources["image"], "sortKeepIndex");
    #printSelectInput("imageid", $resources["image"], $imageid, 1);
    printSelectInput("imageid", $resources["image"], $imageid, 1, 0, 'imagesel', "onChange=\"updateWaitTime(1);\" tabIndex=1");
    print "<br><br>\n";
    $imagenotes = getImageNotes($imageid);
    $desc = '';
    if (preg_match('/\\w/', $imagenotes['description'])) {
        $desc = preg_replace("/\n/", '<br>', $imagenotes['description']);
        $desc = preg_replace("/\r/", '', $desc);
        $desc = "<strong>Image Description</strong>:<br>\n{$desc}<br><br>\n";
    }
    print "<div id=imgdesc>{$desc}</div>\n";
    print "When would you like to start the imaging process?<br><br>\n";
    print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=time id=timenow ";
    print "onclick='updateWaitTime(0);' value=now>Now<br>\n";
    print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=time value=future ";
    print "onclick='updateWaitTime(0);' checked>Later:\n";
    #print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=time value=now>Now<br>\n";
    #print "&nbsp;&nbsp;&nbsp;<INPUT type=radio name=time value=future checked>Later:\n";
    if ($submitErr) {
        $hour24 = $hour;
        if ($hour24 == 12) {
            if ($meridian == "am") {
                $hour24 = 0;
            }
        } elseif ($meridian == "pm") {
            $hour24 += 12;
        }
        list($month, $day, $year) = explode('/', $day);
        $stamp = datetimeToUnix("{$year}-{$month}-{$day} {$hour24}:{$minute}:00");
        $day = date('l', $stamp);
        printReserveItems(1, $day, $hour, $minute, $meridian, 0, 0, 1);
    } elseif (empty($timestamp)) {
        printReserveItems(1, NULL, NULL, NULL, NULL, 0, 0, 1);
    } else {
        $timeArr = explode(',', date('l,g,i,a', $timestamp));
        printReserveItems(1, $timeArr[0], $timeArr[1], $timeArr[2], $timeArr[3], 0, 0, 1);
    }
    print "<div id=waittime class=hidden></div><br>\n";
    $cdata = array('length' => 480);
    $cont = addContinuationsEntry('submitCreateImage', $cdata, SECINDAY, 1, 0);
    print "<INPUT type=hidden name=continuation value=\"{$cont}\">\n";
    print "<INPUT type=submit value=\"Create Imaging Reservation\">\n";
    print "</FORM>\n";
    $cont = addContinuationsEntry('AJupdateWaitTime');
    print "<INPUT type=hidden name=waitcontinuation id=waitcontinuation value=\"{$cont}\">\n";
}