\n";
}
if($imaging) {
$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. \n";
return;
}
if($length == '')
$length = 480;
}
else {
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$resources["image"] = removeNoCheckout($resources["image"]);
}
if((! in_array("imageCheckOut", $user["privileges"]) &&
! in_array("imageAdmin", $user["privileges"])) ||
empty($resources['image'])) {
print "You don't have access to any environments and, therefore, cannot ";
print "make any reservations. \n";
return;
}
if($imaging) {
print "Please select the environment you will be updating or using as a ";
print "base for a new image: \n";
}
else
print "Please select the environment you want to use from the list: \n";
$images = getImages();
$maxTimes = getUserMaxTimes();
if(! $imaging) {
print "\n";
}
print "\n";
$cont = addContinuationsEntry('AJupdateWaitTime', array('imaging' => $imaging));
print "\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn AJupdateWaitTime()
///
/// \brief generates html update for ajax call to display estimated wait time
/// for current selection on new reservation page
///
////////////////////////////////////////////////////////////////////////////////
function AJupdateWaitTime() {
global $user, $requestInfo;
# proccess length
$length = processInputVar('length', ARG_NUMERIC);
$times = getUserMaxTimes();
$imaging = getContinuationVar('imaging');
if(empty($length) ||
($length > $times['initial'] && ! $imaging ) ||
($length > $times['initial'] && $imaging && $length > 720)) {
return;
}
# process imageid
$imageid = processInputVar('imageid', ARG_NUMERIC);
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$validImageids = array_keys($resources['image']);
if(! in_array($imageid, $validImageids))
return;
$desconly = processInputVar('desconly', ARG_NUMERIC, 1);
$imagenotes = getImageNotes($imageid);
if(preg_match('/\w/', $imagenotes['description'])) {
$desc = preg_replace("/\n/", ' ', $imagenotes['description']);
$desc = preg_replace("/\r/", '', $desc);
$desc = preg_replace("/'/", ''', $desc);
print "dojo.byId('imgdesc').innerHTML = 'Image Description: ";
print "$desc
'; ";
}
if($desconly) {
if($imaging)
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'Create Imaging Reservation';";
else
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'Create Reservation';";
return;
}
$images = getImages();
$now = time();
$start = unixFloor15($now);
$end = $start + $length * 60;
if($start < $now)
$end += 15 * 60;
$imagerevisionid = getProductionRevisionid($imageid);
$rc = isAvailable($images, $imageid, $imagerevisionid, $start, $end);
semUnlock();
print "dojo.byId('waittime').innerHTML = ";
if($rc == -2) {
print "'Selection not currently available due to scheduled system downtime for maintenance'; ";
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'View Time Table';";
}
if($rc < 1) {
print "'Selection not currently available'; ";
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'View Time Table';";
}
elseif(array_key_exists(0, $requestInfo['loaded']) &&
$requestInfo['loaded'][0]) {
print "'Estimated load time: < 1 minute';";
}
else {
$loadtime = (int)(getImageLoadEstimate($imageid) / 60);
if($loadtime == 0)
print "'Estimated load time: < {$images[$imageid]['reloadtime']} minutes';";
else
printf("'Estimated load time: < %2.0f minutes';", $loadtime + 1);
}
if($rc > 0) {
if($imaging)
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'Create Imaging Reservation';";
else
print "if(dojo.byId('newsubmit')) dojo.byId('newsubmit').value = 'Create Reservation';";
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitRequest()
///
/// \brief checks to see if the request can fit in the schedule; adds it if
/// it fits; notifies the user either way
///
////////////////////////////////////////////////////////////////////////////////
function submitRequest() {
global $submitErr, $user, $HTMLheader, $mode, $printedHTMLheader;
if($mode == 'submitTestProd') {
$data = getContinuationVar();
$data["revisionid"] = $_POST['revisionid'];
# TODO check for valid revisionids for each image
if(! empty($data["revisionid"])) {
foreach($data['revisionid'] as $val) {
foreach($val as $val2) {
if(! is_numeric($val2) || $val2 < 0) {
unset($data['revisionid']);
break 2; // TODO make sure this breaks as far as needed
}
}
}
}
}
else {
$data = processRequestInput(1);
}
$imaging = $data['imaging'];
if($submitErr) {
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
newReservation();
print getFooter();
return;
}
// if user attempts to make a reservation for an image he does not have
// access to, just make it for the first one he does have access to
$resources = getUserResources(array("imageAdmin", "imageCheckOut"));
$validImageids = array_keys($resources['image']);
if(! in_array($data['imageid'], $validImageids))
$data['imageid'] = array_shift($validImageids);
$showrevisions = 0;
$subimages = 0;
$images = getImages();
$revcount = count($images[$data['imageid']]['imagerevision']);
if($revcount > 1)
$showrevisions = 1;
if($images[$data['imageid']]['imagemetaid'] != NULL &&
count($images[$data['imageid']]['subimages'])) {
$subimages = 1;
foreach($images[$data['imageid']]['subimages'] as $subimage) {
$revcount = count($images[$subimage]['imagerevision']);
if($revcount > 1)
$showrevisions = 1;
}
}
if($data["time"] == "now") {
$nowArr = getdate();
if($nowArr["minutes"] == 0) {
$subtract = 0;
$add = 0;
}
elseif($nowArr["minutes"] < 15) {
$subtract = $nowArr["minutes"] * 60;
$add = 900;
}
elseif($nowArr["minutes"] < 30) {
$subtract = ($nowArr["minutes"] - 15) * 60;
$add = 900;
}
elseif($nowArr["minutes"] < 45) {
$subtract = ($nowArr["minutes"] - 30) * 60;
$add = 900;
}
elseif($nowArr["minutes"] < 60) {
$subtract = ($nowArr["minutes"] - 45) * 60;
$add = 900;
}
$start = time() - $subtract;
$start -= $start % 60;
$nowfuture = "now";
}
else {
$add = 0;
$hour = $data["hour"];
if($data["hour"] == 12) {
if($data["meridian"] == "am") {
$hour = 0;
}
}
elseif($data["meridian"] == "pm") {
$hour = $data["hour"] + 12;
}
$tmp = explode('/', $data["day"]);
$start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
if($start < time()) {
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
print "The time you requested is in the past.";
print " Please select \"Now\" or use a time in the future. \n";
$submitErr = 1;
newReservation();
print getFooter();
return;
}
$nowfuture = "future";
}
if($data["ending"] == "length")
$end = $start + $data["length"] * 60 + $add;
else {
$end = datetimeToUnix($data["enddate"]);
if($end % (15 * 60))
$end = unixFloor15($end) + (15 * 60);
}
// get semaphore lock
if(! semLock())
abort(3);
if(array_key_exists('revisionid', $data) &&
array_key_exists($data['imageid'], $data['revisionid']) &&
array_key_exists(0, $data['revisionid'][$data['imageid']])) {
$revisionid = $data['revisionid'][$data['imageid']][0];
}
else
$revisionid = getProductionRevisionid($data['imageid']);
$availablerc = isAvailable($images, $data["imageid"], $revisionid, $start,
$end, 0, 0, 0, $imaging);
$max = getMaxOverlap($user['id']);
if($availablerc != 0 && checkOverlap($start, $end, $max)) {
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
if($max == 0) {
print "The time you requested overlaps with ";
print "another reservation you currently have. You are only allowed ";
print "to have a single reservation at any given time. Please select ";
print "another time to use the application. If you are finished with ";
print "an active reservation, click \"Current Reservations\", ";
print "then click the \"End\" button of your active reservation.";
print "
\n";
}
else {
print "The time you requested overlaps with ";
print "another reservation you currently have. You are allowed ";
print "to have $max overlapping reservations at any given time. ";
print "Please select another time to use the application. If you are ";
print "finished with an active reservation, click \"Current ";
print "Reservations\", then click the \"End\" button of your active ";
print "reservation.
\n";
}
$submitErr = 1;
newReservation();
print getFooter();
return;
}
// if user is owner of the image and there is a test version of the image
# available, ask user if production or test image desired
if($mode != "submitTestProd" && $showrevisions &&
$images[$data["imageid"]]["ownerid"] == $user["id"]) {
#unset($data["testprod"]);
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
if($subimages) {
print "This is a cluster environment. At least one image in the ";
print "cluster has more than one version available. Please select ";
print "the version you desire for each image listed below: \n";
}
else {
print "There are multiple versions of this environment available. Please ";
print "select the version you would like to check out: \n";
}
print "\n";
print getFooter();
return;
}
if($availablerc == -1) {
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
print "You have requested an environment that is limited in the number ";
print "of concurrent reservations that can be made. No further ";
print "reservations for the environment can be made for the time you ";
print "have selected. Please select another time to use the ";
print "environment. ";
addLogEntry($nowfuture, unixToDatetime($start),
unixToDatetime($end), 0, $data["imageid"]);
print getFooter();
}
elseif($availablerc > 0) {
$requestid = addRequest($imaging, $data["revisionid"]);
if($data["time"] == "now") {
$cdata = array('lengthchanged' => $data['lengthchanged']);
$cont = addContinuationsEntry('viewRequests', $cdata);
header("Location: " . BASEURL . SCRIPT . "?continuation=$cont");
return;
}
else {
if($data["minute"] == 0)
$data["minute"] = "00";
$printedHTMLheader = 1;
print $HTMLheader;
if($imaging)
print "
Create / Update an Image
\n";
else
print "
New Reservation
\n";
if($data["ending"] == "length") {
$time = prettyLength($data["length"]);
if($data['testjavascript'] == 0 && $data['lengthchanged']) {
print "NOTE: The maximum allowed reservation ";
print "length for this environment is $time, and the length of ";
print "this reservation has been adjusted accordingly.\n";
print "
\n";
}
print "Your request to use " . $images[$data["imageid"]]["prettyname"];
print " on " . prettyDatetime($start) . " for $time has been ";
print "accepted.
\n";
}
else {
print "Your request to use " . $images[$data["imageid"]]["prettyname"];
print " starting " . prettyDatetime($start) . " and ending ";
print prettyDatetime($end) . " has been accepted.
\n";
}
print "When your reservation time has been reached, the ";
print "Current Reservations page will have further ";
print "instructions on connecting to the reserved computer. If you ";
print "would like to modify your reservation, you can do that from ";
print "the Current Reservations page as well. \n";
print getFooter();
}
}
else {
$cdata = array('imageid' => $data['imageid'],
'length' => $data['length'],
'showmessage' => 1,
'imaging' => $imaging);
$cont = addContinuationsEntry('selectTimeTable', $cdata);
addLogEntry($nowfuture, unixToDatetime($start),
unixToDatetime($end), 0, $data["imageid"]);
header("Location: " . BASEURL . SCRIPT . "?continuation=$cont");
/*print "
New Reservation
\n";
print "The reservation you have requested is not available. You may ";
print "";
print "view a timetable of free and reserved times to find ";
print "a time that will work for you. \n";*/
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn viewRequests
///
/// \brief prints user's reservations
///
////////////////////////////////////////////////////////////////////////////////
function viewRequests() {
global $user, $inContinuation, $mode;
if($inContinuation)
$lengthchanged = getContinuationVar('lengthchanged', 0);
else
$lengthchanged = processInputVar('lengthchanged', ARG_NUMERIC, 0);
$incPaneDetails = processInputVar('incdetails', ARG_NUMERIC, 0);
$refreqid = processInputVar('reqid', ARG_NUMERIC, 0);
$requests = getUserRequests("all");
$images = getImages();
$computers = getComputers();
if($mode != 'AJviewRequests')
print "
\n";
if(requestIsReady($requests[$i])) {
$connect = 1;
# request is ready, print Connect! and End buttons
$cdata = array('requestid' => $requests[$i]['id']);
$text .= "
\n";
$text .= " \n";
$text .= "
\n";
if($requests[$i]['forimaging']) {
# this is the imaging case, need to do sanity check here for if the request
# state currstateid or laststateid are "inuse", otherwise disable out the
# create image button
$noedit = 1;
$text .= "
\n";
if($requests[$i]['currstateid'] == 8 || $requests[$i]['laststateid'] == 8) {
# the user has connected successfully so we will allow create image button
# to be displayed
$text .= " \n";
}
$text .= "
\n";
if(! empty($normal)) {
if(! empty($imaging) || ! empty($long))
$text .= "You currently have the following normal reservations: \n";
else
$text .= "You currently have the following normal reservations: \n";
if($lengthchanged) {
$text .= "NOTE: The maximum allowed reservation ";
$text .= "length for one of these reservations was less than the ";
$text .= "length you submitted, and the length of that reservation ";
$text .= "has been adjusted accordingly.\n";
}
$text .= "
\n";
}
if(! empty($long)) {
if(! empty($normal) || ! empty($imaging))
$text .= "\n";
$text .= "You currently have the following long term reservations: \n";
$text .= "
Click the ";
$text .= "Connect! button to get further ";
$text .= "information about connecting to the reserved system. You must ";
$text .= "click the button from a web browser running on the same computer ";
$text .= "from which you will be connecting to the remote computer; ";
$text .= "otherwise, you may be denied access to the machine.\n";
}
if($refresh) {
$text .= "
This page will automatically update ";
$text .= "every 20 seconds until the Pending...";
#$text .= " reservation is ready.
An error has occurred that has kept one of your reservations ";
$text .= "from being processed. We apologize for any inconvenience ";
$text .= "this may have caused.\n";
if(! $refresh) {
$cont = addContinuationsEntry('AJviewRequests', $cdata, SECINDAY);
$text .= "\n";
}
}
if(empty($normal) && empty($imaging) && empty($long))
$text .= "You have no current reservations. \n";
$text .= "\n";
if($mode != 'AJviewRequests') {
if($refresh || $failed) {
$text .= "
\n";
}
print $text;
}
else {
$text = str_replace("\n", ' ', $text);
if($refresh)
print "refresh_timer = setTimeout(resRefresh, 20000);\n";
print(setAttribute('subcontent', 'innerHTML', $text));
print "AJdojoCreate('subcontent');";
if($incPaneDetails) {
$text = detailStatusHTML($refreqid);
print(setAttribute('resStatusText', 'innerHTML', $text));
}
dbDisconnect();
exit;
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn detailStatusHTML($reqid)
///
/// \param $reqid - a request id
///
/// \return html text showing detailed status from computerloadlog for specified
/// request
///
/// \brief gathers information about the state flow for $reqid and formats it
/// nicely for a user to view
///
////////////////////////////////////////////////////////////////////////////////
function detailStatusHTML($reqid) {
$requests = getUserRequests("all");
$found = 0;
foreach($requests as $request) {
if($request['id'] == $reqid) {
$found = 1;
break;
}
}
if(! $found) {
$text = "The selected reservation is no longer available. Go to ";
$text .= "New ";
$text .= "Reservations to request a new reservation or ";
$text .= "select another one that is available.";
return $text;
}
if($request['imageid'] == $request['compimageid'])
$nowreq = 1;
else
$nowreq = 0;
$flow = getCompStateFlow($request['computerid']);
# cluster reservations not supported here yet
if(empty($flow) || count($request['reservations']) > 0) {
$noinfo = "No detailed loading information is available for this ";
$noinfo .= "reservation.";
return $noinfo;
}
$logdata = getCompLoadLog($request['resid']);
# determine an estimated load time for the image
$imgLoadTime = getImageLoadEstimate($request['imageid']);
if($imgLoadTime == 0) {
$images = getImages(0, $request['imageid']);
$imgLoadTime = $images[$request['imageid']]['reloadtime'] * 60;
}
$time = 0;
$now = time();
$text = "
";
$text .= "
";
$text .= "
";
$text .= "
";
$text .= "
";
$text .= "
";
$text .= "
";
$text .= "
State
";
$text .= "
Est/Act Time
";
$text .= "
Total Time
";
$text .= "
";
$slash = "/";
$total = 0;
$id = "";
$last = array();
$logstateids = array();
$skippedstates = array();
# loop through all states in the log data
foreach($logdata as $data) {
# keep track of the states in the log data
array_push($logstateids, $data['loadstateid']);
# keep track of any skipped states
if(! empty($last) &&
$last['loadstateid'] != $flow['repeatid'] &&
$data['loadstateid'] != $flow['data'][$last['loadstateid']]['nextstateid']) {
array_push($skippedstates, $flow['data'][$last['loadstateid']]['nextstateid']);
}
// if we reach a repeat state, include a message about having to go back
if($data['loadstateid'] == $flow['repeatid']) {
if(empty($id))
return $noinfo;
$text .= "
";
$text .= "
problem at state ";
$text .= "\"{$flow['data'][$id]['nextstate']}\"";
$query = "SELECT additionalinfo "
. "FROM computerloadlog "
. "WHERE loadstateid = {$flow['repeatid']} AND "
. "reservationid = {$request['resid']} AND "
. "timestamp = '" . unixToDatetime($data['ts']) . "'";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
$reason = $row['additionalinfo'];
$text .= " retrying at state \"$reason\"";
}
$text .= "
";
$total += $data['time'];
$last = $data;
continue;
}
$id = $data['loadstateid'];
// if in post config state, compute estimated time for the state
if($flow['data'][$id]['statename'] == 'loadimagecomplete') {
$addtime = 0;
foreach($skippedstates as $stateid)
$addtime += $flow['data'][$stateid]['statetime'];
# this state's time is (avg image load time - all other states time +
# state time for any skipped states)
$tmp = $imgLoadTime - $flow['totaltime'] + $addtime;
if($tmp < 0)
$flow['data'][$id]['statetime'] = 0;
else
$flow['data'][$id]['statetime'] = $tmp;
}
$total += $data['time'];
$text .= "
";
$last = $data;
}
# $id will be set if there was log data, use the first state in the flow
# if it isn't set
if(! empty($id))
$id = $flow['nextstates'][$id];
else
$id = $flow['stateids'][0];
# determine any skipped states
$matchingstates = array();
foreach($flow['stateids'] as $stateid) {
if($stateid == $id)
break;
array_push($matchingstates, $stateid);
}
$skippedstates = array_diff($matchingstates, $logstateids);
$addtime = 0;
foreach($skippedstates as $stateid)
$addtime += $flow['data'][$stateid]['statetime'];
$first = 1;
$count = 0;
# loop through the states in the flow that haven't been reached yet
# $count is included to protect against an infinite loop
while(! is_null($id) && $count < 100) {
$count++;
// if in post config state, compute estimated time for the state
if($flow['data'][$id]['statename'] == 'loadimagecomplete') {
# this state's time is (avg image load time - all other states time +
# state time for any skipped states)
$tmp = $imgLoadTime - $flow['totaltime'] + $addtime;
if($tmp < 0)
$flow['data'][$id]['statetime'] = 0;
else
$flow['data'][$id]['statetime'] = $tmp;
}
// if first time through this loop, this is the current state
if($first) {
// if request has failed, it was during this state, get reason
if($request['currstateid'] == 5) {
$query = "SELECT additionalInfo, "
. "UNIX_TIMESTAMP(timestamp) AS ts "
. "FROM computerloadlog "
. "WHERE loadstateid = (SELECT id "
. "FROM computerloadstate "
. "WHERE loadstatename = 'failed') AND "
. "reservationid = {$request['resid']} "
. "ORDER BY id "
. "LIMIT 1";
$qh = doQuery($query, 101);
if($row = mysql_fetch_assoc($qh)) {
$reason = $row['additionalInfo'];
if(! empty($data))
$currtime = $row['ts'] - $data['ts'];
else
$currtime = $row['ts'] -
datetimeToUnix($request['daterequested']);
}
else {
$text = "No detailed information is available for this ";
$text .= "reservation.";
return $text;
}
$text .= "
\n";
foreach($request["reservations"] as $res) {
print "
\n";
print "
Image:
\n";
print "
{$res["prettyimage"]}
\n";
print "
\n";
print "
\n";
print "
Hostname:
\n";
print "
{$res["hostname"]}
\n";
print "
\n";
print "
\n";
print "
IP Address:
\n";
print "
{$res["reservedIP"]}
\n";
print "
\n";
}
print "
\n";
}
print "
\n";
print "
\n";
/*print "
\n";
print " \n";
print "
\n";*/
print "
\n";
print " \n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn editRequest()
///
/// \brief prints a page for a user to edit a previous request
///
////////////////////////////////////////////////////////////////////////////////
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();
$timeToNext = timeToNextReservation($request);
print "
Modify Reservation
\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. \n";
printEditNewUpdate($request, $reservation);
return;
}
$timeToNext = timeToNextReservation($request);
}
if($timeToNext >= 15)
$timeToNext -= 15;
$started = 1;
if(! $openend) {
if($timeToNext == -1) {
print "Because this reservation has already started, you can only ";
print "extend the length of the reservation. ";
print "You can extend this reservation ";
print "by up to " . minToHourMin($maxtimes["extend"]) . ", but not ";
print "exceeding " . minToHourMin($maxtimes["total"]) . " for your ";
print "total reservation time.
\n";
}
elseif($timeToNext < 15) {
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. \n";
printEditNewUpdate($request, $reservation);
return;
}
else {
print "Because this reservation has already started, you can only ";
print "extend the length of the reservation. ";
print "The computer you are using has another reservation following ";
print "yours. Therefore, you can only extend this reservation for ";
print "another " . prettyLength($timeToNext) . ".
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitEditRequest()
///
/// \brief submits changes to a request and prints that it has been changed
///
////////////////////////////////////////////////////////////////////////////////
function submitEditRequest() {
global $user, $submitErr, $mode;
$data = getContinuationVar();
$request = getRequestInfo($data["requestid"]);
print "
Modify Reservation
\n";
$hour = $data["hour"];
if($data["hour"] == 12) {
if($data["meridian"] == "am") {
$hour = 0;
}
}
elseif($data["meridian"] == "pm") {
$hour = $data["hour"] + 12;
}
$tmp = explode('/', $data["day"]);
$start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
if($data['openend'] && $data['ending'] == 'date')
$end = datetimeToUnix($data['enddate']);
else {
if(datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"]))
$end = $start + $data["length"] * 60 + 900;
else
$end = $start + $data["length"] * 60;
}
// get semaphore lock
if(! semLock())
abort(3);
$max = getMaxOverlap($user['id']);
if(checkOverlap($start, $end, $max, $data["requestid"])) {
if($max == 0) {
print "The time you requested overlaps with ";
print "another reservation you currently have. You are only allowed ";
print "to have a single reservation at any given time. Please select ";
print "another time to use the application.
\n";
}
else {
print "The time you requested overlaps with ";
print "another reservation you currently have. You are allowed ";
print "to have $max overlapping reservations at any given time. ";
print "Please select another time to use the application. ";
print " \n";
}
$submitErr = 1;
editRequest();
return;
}
$rc = isAvailable(getImages(), $data["imageid"], $data['imagerevisionid'],
$start, $end, $data["requestid"]);
if($rc == -1) {
print "You have requested an environment that is limited in the number ";
print "of concurrent reservations that can be made. No further ";
print "reservations for the environment can be made for the time you ";
print "have selected. Please select another time to use the ";
print "environment. ";
addChangeLogEntry($request["logid"], NULL, unixToDatetime($end),
unixToDatetime($start), NULL, NULL, 0);
}
elseif($rc > 0) {
updateRequest($data["requestid"]);
if($data["started"]) {
if($data['openend'] && $data['ending'] == 'date') {
print "Your request to change the ending of your reservation for ";
print "{$data["prettyimage"]} to {$data['enddate']} ";
print "has been accepted.
\n";
}
else {
$remaining = (int)(($end - time()) / 60);
print "Your request to extend your reservation for ";
print "{$data["prettyimage"]} by " . prettyLength($data["extend"]);
print " has been accepted.
\n";
print "You now have " . prettyLength($remaining) . " remaining for ";
print "your reservation \n";
}
}
else {
print "Your request to use " . $data["prettyimage"] . " on ";
if(datetimeToUnix($request["start"]) <
datetimeToUnix($request["daterequested"])) {
print prettyDatetime($request["daterequested"]);
}
else
print prettyDatetime($start);
if($data['openend'] && $data['ending'] == 'date')
print " until " . prettyDatetime($end);
else
print " for " . prettyLength($data["length"]);
print " has been accepted. \n";
}
}
else {
$cdata = array('imageid' => $data['imageid'],
'length' => $data['length'],
'requestid' => $data['requestid']);
$cont = addContinuationsEntry('selectTimeTable', $cdata);
if($rc == -2) {
print "The time you have requested is not available due to scheduled ";
print "system downtime for maintenance. ";
}
else
print "The time you have requested is not available. ";
print "You may ";
print "view a timetable of free and reserved times to find ";
print "a time that will work for you. \n";
addChangeLogEntry($request["logid"], NULL, unixToDatetime($end),
unixToDatetime($start), NULL, NULL, 0);
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn confirmDeleteRequest()
///
/// \brief prints a confirmation page about deleting a request
///
////////////////////////////////////////////////////////////////////////////////
function confirmDeleteRequest() {
$requestid = getContinuationVar('requestid', 0);
$notbyowner = getContinuationVar('notbyowner', 0);
$request = getRequestInfo($requestid);
if($request['forimaging'])
$reservation = $request['reservations'][0];
else {
foreach($request["reservations"] as $res) {
if($res["forcheckout"]) {
$reservation = $res;
break;
}
}
}
if(datetimeToUnix($request["start"]) > time()) {
$title = "Delete Reservation";
$text = "Delete reservation for " . $reservation["prettyimage"]
. " starting " . prettyDatetime($request["start"]) . "? \n";
}
else {
if(! $reservation["production"]) {
confirmDeleteRequestProduction($request);
return;
}
else {
$title = "End Reservation";
if($notbyowner == 0) {
$text = "Are you finished with your reservation for "
. $reservation["prettyimage"] . " that started ";
}
else {
$userinfo = getUserInfo($request["userid"], 1, 1);
$text = "Delete reservation by {$userinfo['unityid']}@"
. "{$userinfo['affiliation']} for "
. "{$reservation["prettyimage"]} that started ";
}
if(datetimeToUnix($request["start"]) <
datetimeToUnix($request["daterequested"])) {
$text .= prettyDatetime($request["daterequested"]);
}
else {
$text .= prettyDatetime($request["start"]);
}
$text .= "? \n";
}
}
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn confirmDeleteRequestProduction($request)
///
/// \param $request - a request array as returend from getRequestInfo
///
/// \brief prints a page asking if the user is ready to make the image
/// production or just end this reservation
///
////////////////////////////////////////////////////////////////////////////////
function confirmDeleteRequestProduction($request) {
$cdata = array('requestid' => $request['id']);
print "
End Reservation/Make Production
\n";
print "Are you satisfied that this environment is ready to be made production ";
print "and replace the current production version, or would you just like to ";
print "end this reservation and test it again later?\n";
if(isImageBlockTimeActive($request['reservations'][0]['imageid'])) {
print "
WARNING: This environment is part of ";
print "an active block allocation. Changing the production version of ";
print "the environment at this time will result in new reservations ";
print "under the block allocation to have full reload times instead of ";
print "a < 1 minutes wait. You can change the production version ";
print "later by going to Manage Images->Edit Image Profiles and ";
print "clicking Edit for this environment. \n";
}
print "
\n";
$cont = addContinuationsEntry('setImageProduction', $cdata, SECINDAY, 0, 1);
print " Make this the production version \n";
$cont = addContinuationsEntry('submitDeleteRequest', $cdata, SECINDAY, 0, 0);
print " Just end the reservation \n";
$cont = addContinuationsEntry('viewRequests');
print " Neither, go back to Current Reservations";
print "
\n";
print "\n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitDeleteRequest()
///
/// \brief submits deleting a request and prints that it has been deleted
///
////////////////////////////////////////////////////////////////////////////////
function submitDeleteRequest() {
$requestid = getContinuationVar('requestid', 0);
$request = getRequestInfo($requestid);
if($request['forimaging'])
$reservation = $request['reservations'][0];
else {
foreach($request["reservations"] as $res) {
if($res["forcheckout"]) {
$reservation = $res;
break;
}
}
}
deleteRequest($request);
if(datetimeToUnix($request["start"]) > time()) {
print "
Delete Reservation
";
print "The reservation for " . $reservation["prettyimage"];
print " starting " . prettyDatetime($request["start"]);
print " has been deleted. \n";
}
else {
print "
";
/*else
print " ";*/
if($openend) {
print " ";
}
print "Duration: \n";
}
else {
print "\n";
print "\n";
print "\n";
print "\n";
}
// check for a "now" reservation that got 15 min added to it
if($length % 30) {
$length -= 15;
}
// if ! $modifystart, we return at this point because we don't
# know enough about the current reservation to determine how
# long they can extend it for, the calling function would have
# to determine that and print a length dropdown box
if(! $modifystart)
return;
# create an array of usage times based on the user's max times
$maxtimes = getUserMaxTimes();
if($maxlength > 0 && $maxlength < $maxtimes['initial'])
$maxtimes['initial'] = $maxlength;
if($imaging && $maxtimes['initial'] < 720) # make sure at least 12 hours available for imaging reservations
$maxtimes['initial'] = 720;
$lengths = array();
if($maxtimes["initial"] >= 30)
$lengths["30"] = "30 minutes";
if($maxtimes["initial"] >= 60)
$lengths["60"] = "1 hour";
for($i = 120; $i <= $maxtimes["initial"] && $i < 2880; $i += 120)
$lengths[$i] = $i / 60 . " hours";
for($i = 2880; $i <= $maxtimes["initial"]; $i += 1440)
$lengths[$i] = $i / 1440 . " days";
printSelectInput("length", $lengths, $length, 0, 0, 'reqlength', "onChange='updateWaitTime(0);'");
print " \n";
if($openend) {
print " Until\n";
print "(YYYY-MM-DD HH:MM:SS)\n";
printSubmitErr(ENDDATEERR);
print " \n";
}
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn connectRequest()
///
/// \brief sets IPaddress for the request; tells the user how to connect
///
////////////////////////////////////////////////////////////////////////////////
function connectRequest() {
global $remoteIP, $user, $inContinuation;
if($inContinuation)
$requestid = getContinuationVar('requestid', 0);
else
$requestid = processInputVar("requestid", ARG_NUMERIC);
$requestData = getRequestInfo($requestid);
if($requestData['reservations'][0]['remoteIP'] != $remoteIP) {
$setback = unixToDatetime(time() - 600);
$query = "UPDATE reservation "
. "SET remoteIP = '$remoteIP', "
. "lastcheck = '$setback' "
. "WHERE requestid = $requestid";
$qh = doQuery($query, 226);
addChangeLogEntry($requestData["logid"], $remoteIP);
}
print "
Connect!
\n";
if($requestData['forimaging']) {
print "NOTICE: Later in this process, you must accept a
click-through agreement about software licensing.
\n";
}
if(count($requestData["reservations"]) == 1) {
$serverIP = $requestData["reservations"][0]["reservedIP"];
$osname = $requestData["reservations"][0]["OS"];
$passwd = $requestData["reservations"][0]["password"];
if(preg_match("/windows/i", $osname)) {
print "You will need to use a ";
print "Remote Desktop program to connect to the ";
print "system. If you did not click on the Connect! button from ";
print "the computer you will be using to access the VCL system, you ";
print "will need to return to the Current Reservations ";
print "page and click the Connect! button from ";
print "a web browser running on the same computer from which you will ";
print "be connecting to the VCL system. Otherwise, you may be denied ";
print "access to the remote computer.
\n";
print "Use the following information when you are ready to connect: \n";
print "
\n";
print "NOTE: The given password is for this reservation ";
print "only. You will be given a different password for any other ";
print "reservations. \n";
}
else {
print "
Password: (use your campus password)
\n";
print "\n";
}
/*print " \n";
print "
\n";
print "
NEW!
\n";
print "Connect to the server using a java applet: \n";
print "\n";
print "\n";
print "\n";
print "
\n";*/
print "For automatic connection, you can download an RDP file that can ";
print "be opened by the Remote Desktop Connection program.
\n";
}
else {
print "You will need to have an ";
print "X server running on your local computer and use an ";
print "ssh client to connect to the system. If you did not ";
print "click on the Connect! button from ";
print "the computer you will be using to access the VCL system, you ";
print "will need to return to the Current Reservations ";
print "page and click the Connect! button from ";
print "a web browser running on the same computer from which you will ";
print "be connecting to the VCL system. Otherwise, you may be denied ";
print "access to the remote computer.
\n";
print "Use the following information when you are ready to connect: \n";
print "
\n";
print "NOTE: The given password is for this reservation ";
print "only. You will be given a different password for any other ";
print "reservations. \n";
}
else {
print "
Password: (use your campus password)
\n";
print "\n";
}
print "NOTE: You cannot use the Windows Remote ";
print "Desktop Connection to connect to this computer. You must use an ";
print "ssh client.\n";
/*if(preg_match("/windows/i", $_SERVER["HTTP_USER_AGENT"])) {
print "
NEW!
\n";
print "Connect to the server using a java applet: \n";
print "
\n";
print "\n";
print "\n";
print "\n";
print "
\n";
}*/
}
}
else {
print "You will need an ";
print "ssh client to connect to any unix systems. \n";
print "You will need a ";
print "Remote Desktop program to connect to any windows systems.
\n";
print "Use the following information when you are ready to connect: \n";
$total = count($requestData["reservations"]);
$count = 0;
foreach($requestData["reservations"] as $key => $res) {
$count++;
print "
\n";
print "NOTE: The given password is for this reservation ";
print "only. You will be given a different password for any other ";
print "reservations. \n";
}
else {
print "
Password: (use your campus password)
\n";
print "\n";
}
/*print "Connect to the server using a java applet: \n";
print "\n";
print "\n";
print "\n";
print "\n";
print "
\n";*/
print "Automatic connection using an RDP file: \n";
print "
\n";
print "\n";
print "NOTE: The given password is for this reservation ";
print "only. You will be given a different password for any other ";
print "reservations. \n";
}
else {
print "
Password: (use your campus password)
\n";
print "\n";
}
/*if(preg_match("/windows/i", $_SERVER["HTTP_USER_AGENT"])) {
print "Connect to the server using a java applet: \n";
print "