Create / Update an Image\n"; else print _("

New Reservation


\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"; // list of images uasort($resources["image"], "sortKeepIndex"); printSubmitErr(IMAGEIDERR); if($submitErr & IMAGEIDERR) print "
\n"; if($imaging) { if(USEFILTERINGSELECT && count($resources['image']) < FILTERINGSELECTTHRESHOLD) { print " \n"; } else printSelectInput('imageid', $resources['image'], $imageid, 1, 0, 'imagesel', "onChange=\"updateWaitTime(1);\""); } else { if(USEFILTERINGSELECT && count($resources['image']) < FILTERINGSELECTTHRESHOLD) { print " \n"; } else printSelectInput('imageid', $resources['image'], $imageid, 1, 0, 'imagesel', "onChange=\"selectEnvironment();\""); } print "

\n"; $imagenotes = getImageNotes($imageid); $desc = ''; if(! preg_match('/^\s*$/', $imagenotes['description'])) { $desc = preg_replace("/\n/", '
', $imagenotes['description']); $desc = preg_replace("/\r/", '', $desc); $desc = _("Image Description:
\n") . "$desc

\n"; } print "
$desc
\n"; print "
\n"; if($imaging) print "When would you like to start the imaging process?\n"; else print _("When would you like to use the application?\n"); print "   "; print _("
\n"); print "   "; print _("\n"); if(array_key_exists($imageid, $images)) $maxlen = $images[$imageid]['maxinitialtime']; else $maxlen = 0; 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, $imaging, $length, $maxlen, $day, $hour, $minute, $meridian); } else { if(empty($timestamp)) $timestamp = unixFloor15(time() + 4500); $timeArr = explode(',', date('l,g,i,a', $timestamp)); printReserveItems(1, $imaging, $length, $maxlen, $timeArr[0], $timeArr[1], $timeArr[2], $timeArr[3]); } print "
\n"; print "
\n"; $cont = addContinuationsEntry('submitRequest', array('imaging' => $imaging), SECINDAY, 1, 0); print "\n"; if($imaging) print "\n"; print "\n"; print "
\n"; $cont = addContinuationsEntry('AJupdateWaitTime', array('imaging' => $imaging)); print "\n"; print "
\n"; print "
"; print " " . _("Loading...") . "
\n"; print "
\n"; print " \n"; print " \n"; print "
\n"; print " \n"; print " \n"; print "
\n"; 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('/^\s*$/', $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(); if($rc < 1) { $cdata = array('now' => 1, 'start' => $start, 'end' => $end, 'server' => 0, 'imageid' => $imageid); $cont = addContinuationsEntry('AJshowRequestSuggestedTimes', $cdata); if(array_key_exists('subimages', $images[$imageid]) && count($images[$imageid]['subimages'])) print "dojo.byId('suggestcont').value = 'cluster';"; else print "dojo.byId('suggestcont').value = '$cont';"; print "if(dojo.byId('newsubmit')) {"; print "if(dojo.byId('newsubmit').value != _('View Available Times')) "; print "resbtntxt = dojo.byId('newsubmit').value; "; print "dojo.byId('newsubmit').value = _('View Available Times');"; print "}"; } print "dojo.byId('waittime').innerHTML = "; if($rc == -2) print _("'Selection not currently available due to scheduled system downtime for maintenance'; "); elseif($rc < 1) { print _("'Selection not currently available'; "); print "showSuggestedTimes(); "; } 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 AJshowRequestSuggestedTimes() /// /// \brief builds html to display list of available times the selected image /// can be used /// //////////////////////////////////////////////////////////////////////////////// function AJshowRequestSuggestedTimes() { global $user; $data = array(); $start = getContinuationVar('start'); $end = getContinuationVar('end'); $imageid = getContinuationVar('imageid'); $now = getContinuationVar('now'); $server = getContinuationVar('server'); $ip = getContinuationVar('ip', ''); $mac = getContinuationVar('mac', ''); $requestid = getContinuationVar('requestid', ''); $extendonly = getContinuationVar('extendonly', 0); if($now && $start < time()) { # $start should have been decreased by 15 minutes $start = $start + 900; } if($server) $slots = findAvailableTimes($start, $end, $imageid, $user['id'], 0, $requestid, $extendonly, $ip, $mac); else $slots = findAvailableTimes($start, $end, $imageid, $user['id'], 1, $requestid, $extendonly); $data['status'] = 'success'; if($requestid != '') { $reqdata = getRequestInfo($requestid, 0); if(is_null($reqdata)) { $data['status'] = 'resgone'; sendJSON($data); return; } } if(empty($slots)) { $data['html'] = _("There are no available times that
the selected image can be used.

"); $data['status'] = 'error'; sendJSON($data); return; } $data['data'] = $slots; $html = ''; $html .= ""; if($extendonly) { $slot = array_pop($slots); $maxextend = $slot['duration'] - (datetimeToUnix($reqdata['end']) - datetimeToUnix($reqdata['start'])); if($maxextend < 900) { $data['html'] = _('This reservation can no longer be extended due to
') . _('a reservation immediately following yours.

'); $data['status'] = 'noextend'; sendJSON($data); return; } $html .= ""; $html .= ""; $html .= ""; $html .= ""; $html .= ""; $cnt = 0; $e = datetimeToUnix($reqdata['end']); $slots = array(); for($cnt = 0, $amount = 900, $e = datetimeToUnix($reqdata['end']) + 900; $cnt < 15 && $amount <= $maxextend && $amount < 7200; $cnt++, $amount += 900, $e += 900) { $end = strftime('%x %l:%M %P', $e); $extenstion = getReservationExtenstion($amount / 60); if($cnt % 2) $html .= ""; else $html .= ""; $html .= ""; $html .= ""; $html .= ""; $slots[$e] = array('duration' => $amount, 'startts' => $slot['startts']); } for(; $cnt < 15 && $amount <= $maxextend; $cnt++, $amount += 3600, $e += 3600) { $end = strftime('%x %l:%M %P', $e); $extenstion = getReservationExtenstion($amount / 60); if($cnt % 2) $html .= ""; else $html .= ""; $html .= ""; $html .= ""; $html .= ""; $slots[$e] = array('duration' => $amount, 'startts' => $slot['startts']); } $data['data'] = $slots; } else { $html .= ""; $html .= ""; $html .= ""; $html .= ""; if(checkUserHasPerm('View Debug Information')) $html .= ""; $html .= ""; $cnt = 0; foreach($slots as $key => $slot) { $cnt++; $start = strftime('%x %l:%M %P', $slot['startts']); if(($slot['startts'] - time()) + $slot['startts'] + $slot['duration'] >= 2114402400) # end time >= 2037-01-01 00:00:00 $duration = 'indefinite'; else $duration = getReservationLength($slot['duration'] / 60); if($cnt % 2) $html .= ""; else $html .= ""; $html .= ""; $html .= ""; $html .= ""; if(checkUserHasPerm('View Debug Information')) $html .= ""; $html .= ""; if($cnt >= 15) break; } } $html .= "
" . _("End Time") . "" . _("Extend By") . "
"; $html .= "
"; $html .= "
" . _("Start Time") . "" . _("Duration") . "" . _("Comp. ID") . "
"; $html .= "{$slot['compid']}
"; $data['html'] = $html; $cdata = array('slots' => $slots); sendJSON($data); } //////////////////////////////////////////////////////////////////////////////// /// /// \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 = 5000; 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 = 5000; 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"] || checkUserHasPerm('View Debug Information'))) { #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"; if(! array_key_exists('subimages', $images[$data['imageid']])) $images[$data['imageid']]['subimages'] = array(); array_unshift($images[$data['imageid']]['subimages'], $data['imageid']); $cnt = 0; foreach($images[$data['imageid']]['subimages'] as $subimage) { print "{$images[$subimage]['prettyname']}:
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($images[$subimage]['imagerevision'] as $revision) { print " \n"; // if revision was selected or it wasn't selected but it is the production revision, show checked if((array_key_exists('revisionid', $data) && array_key_exists($subimage, $data['revisionid']) && array_key_exists($cnt, $data['revisionid'][$subimage]) && $data['revisionid'][$subimage][$cnt] == $revisionid['id']) || $revision['production']) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if($revision['production']) print _(" \n"); else print _(" \n"); print " \n"; } print "
" . _("Version") . "" . _("Creator") . "" . _("Created") . "" . _("Currently in Production") . "
{$revision['revision']}{$revision['user']}{$revision['prettydate']}YesNo
\n"; $cnt++; } $cont = addContinuationsEntry('submitTestProd', $data); print "
\n"; if($imaging) print "\n"; else print _("\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"); } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewRequests /// /// \brief prints user's reservations /// //////////////////////////////////////////////////////////////////////////////// function viewRequests() { global $user, $inContinuation, $mode, $skin; 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(); $resources = getUserResources(array("imageAdmin")); if(count($requests) == 0) { if($mode == 'AJviewRequests') print "document.body.style.cursor = 'default';"; $text = _("

Current Reservations

"); $text .= _("You have no current reservations.
"); if($mode == 'AJviewRequests') print(setAttribute('subcontent', 'innerHTML', $text)); else print $text; return; } if($mode != 'AJviewRequests') print "
\n"; $refresh = 0; $connect = 0; $failed = 0; $normal = ''; $imaging = ''; $long = ''; $server = ''; $reqids = array(); if(checkUserHasPerm('View Debug Information')) $nodes = getManagementNodes(); if($count = count($requests)) { $now = time(); for($i = 0, $failed = 0, $timedout = 0, $text = '', $showcreateimage = 0, $cluster = 0; $i < $count; $i++, $failed = 0, $timedout = 0, $text = '', $cluster = 0) { if($requests[$i]['forcheckout'] == 0 && $requests[$i]['forimaging'] == 0) continue; if(count($requests[$i]['reservations'])) $cluster = 1; $cdata = array('requestid' => $requests[$i]['id']); $reqids[] = $requests[$i]['id']; $imageid = $requests[$i]["imageid"]; $text .= " \n"; if(requestIsReady($requests[$i]) && $requests[$i]['useraccountready']) { $connect = 1; # request is ready, print Connect! and End buttons $cont = addContinuationsEntry('connectRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('connectbtn', $cont); if($requests[$i]['serveradmin']) { $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('deletebtn', $cont); } else $text .= " \n"; } elseif($requests[$i]["currstateid"] == 5) { # request has failed $text .= getViewRequestHTMLitem('failedblock', $requests[$i]['id']); if($requests[$i]['serveradmin']) { $cont = addContinuationsEntry('AJconfirmRemoveRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('removebtn', $cont); } else $text .= " \n"; $failed = 1; } elseif(datetimeToUnix($requests[$i]["start"]) < $now) { # other cases where the reservation start time has been reached if(($requests[$i]["currstateid"] == 12 && $requests[$i]['laststateid'] == 11) || $requests[$i]["currstateid"] == 11 || ($requests[$i]["currstateid"] == 14 && $requests[$i]["laststateid"] == 11)) { # request has timed out $text .= getViewRequestHTMLitem('timeoutblock'); $timedout = 1; if($requests[$i]['serveradmin']) { $cont = addContinuationsEntry('AJconfirmRemoveRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('removebtn', $cont); } else $text .= " \n"; } else { # computer is loading, print Pending... and Delete button # TODO figure out a different way to estimate for reboot and reinstall states # TODO if user account not ready, print accurate information in details $remaining = 1; if(isComputerLoading($requests[$i], $computers)) { if(datetimeToUnix($requests[$i]["daterequested"]) >= datetimeToUnix($requests[$i]["start"])) { $startload = datetimeToUnix($requests[$i]["daterequested"]); } else { $startload = datetimeToUnix($requests[$i]["start"]); } $imgLoadTime = getImageLoadEstimate($imageid); if($imgLoadTime == 0) $imgLoadTime = $images[$imageid]['reloadtime'] * 60; $tmp = ($imgLoadTime - ($now - $startload)) / 60; $remaining = sprintf("%d", $tmp) + 1; if($remaining < 1) { $remaining = 1; } } $data = array('text' => ''); if($requests[$i]['currstateid'] != 26 && $requests[$i]['currstateid'] != 27 && $requests[$i]['currstateid'] != 28 && ($requests[$i]["currstateid"] != 14 || ($requests[$i]['laststateid'] != 26 && $requests[$i]['laststateid'] != 27 && $requests[$i]['laststateid'] != 28))) $data['text'] = _("
Est: ") . $remaining . _(" min remaining\n"); $text .= getViewRequestHTMLitem('pendingblock', $requests[$i]['id'], $data); $refresh = 1; if($requests[$i]['serveradmin']) { $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('deletebtn', $cont); } else $text .= " \n"; } } else { # reservation is in the future $text .= " \n"; if($requests[$i]['serveradmin']) { $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('deletebtn', $cont); } else $text .= " \n"; } if(! $failed && ! $timedout) { # print edit button $editcont = addContinuationsEntry('AJeditRequest', $cdata, SECINDAY); $imgcont = addContinuationsEntry('startImage', $cdata, SECINDAY); $imgurl = BASEURL . SCRIPT . "?continuation=$imgcont"; if($requests[$i]['serveradmin']) { $text .= getViewRequestHTMLitem('openmoreoptions'); $text .= getViewRequestHTMLitem('editoption', $editcont); if(array_key_exists($imageid, $resources['image']) && ! $cluster && # imageAdmin access, not a cluster, ($requests[$i]['currstateid'] == 8 || $requests[$i]['laststateid'] == 8)) { # reservation has been in inuse state $data = array('doescape' => 0); if($mode == 'AJviewRequests') $data['doescape'] = 1; $text .= getViewRequestHTMLitem('endcreateoption', $imgurl, $data); } /*else $text .= getViewRequestHTMLitem('endcreateoptiondisable');*/ // todo uncomment the following when live imaging works // todo add a check to ensure it is a VM /*if($requests[$i]['server'] && ($requests[$i]['currstateid'] == 8 || ($requests[$i]['currstateid'] == 14 && $requests[$i]['laststateid'] == 8))) { $cont = addContinuationsEntry('startCheckpoint', $cdata, SECINDAY); $url = BASEURL . SCRIPT . "?continuation=$cont"; $data = array('doescape' => 0); if($mode == 'AJviewRequests') $data['doescape'] = 1; $text .= getViewRequestHTMLitem('checkpointoption', $imgurl, $data); } elseif($requests[$i]['server'] && $requests[$i]['currstateid'] == 24) $text .= getViewRequestHTMLitem('checkpointoptiondisable');*/ if($requests[$i]['currstateid'] == 8 || (! $cluster && $requests[$i]['OSinstalltype'] != 'none' && $requests[$i]['currstateid'] != 3 && $requests[$i]['laststateid'] != 3 && $requests[$i]['currstateid'] != 13 && $requests[$i]['laststateid'] != 13 && $requests[$i]['currstateid'] != 24 && $requests[$i]['laststateid'] != 24 && $requests[$i]['currstateid'] != 16 && $requests[$i]['laststateid'] != 16 && $requests[$i]['currstateid'] != 26 && $requests[$i]['laststateid'] != 26 && $requests[$i]['currstateid'] != 28 && $requests[$i]['laststateid'] != 28 && $requests[$i]['currstateid'] != 27 && $requests[$i]['laststateid'] != 27)) { $cont = addContinuationsEntry('AJrebootRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('rebootoption', $cont); $cont = addContinuationsEntry('AJshowReinstallRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('reinstalloption', $cont); } else { $text .= getViewRequestHTMLitem('rebootoptiondisable'); $text .= getViewRequestHTMLitem('reinstalloptiondisable'); } $text .= "
\n"; $text .= " \n"; $text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]); $text .= " \n"; } else { $text .= " "; $text .= getViewRequestHTMLitem('timeoutdata', $requests[$i]['id'], $requests[$i]); $text .= "\n"; } } else $text .= " \n"; # print name of server request if($requests[$i]['server']) { if($requests[$i]['servername'] == '') $text .= getViewRequestHTMLitem('servername', $requests[$i]['prettyimage']); else $text .= getViewRequestHTMLitem('servername', $requests[$i]['servername']); } # print name of image, add (Testing) if it is the test version of an image if(!$requests[$i]['server']) { $data = array('addtest' => 0); if($requests[$i]["test"]) $data['addtest'] = 1; $text .= getViewRequestHTMLitem('imagename', $requests[$i]['prettyimage'], $data); } # print start time if(! $requests[$i]['server']) { $data = array('start' => $requests[$i]['start'], 'requested' => $requests[$i]['daterequested']); $text .= getViewRequestHTMLitem('starttime', '', $data); } # print end time $data = array('end' => $requests[$i]['end']); $text .= getViewRequestHTMLitem('endtime', '', $data); # print date requested if(! $requests[$i]['server']) $text .= getViewRequestHTMLitem('requesttime', $requests[$i]['daterequested']); # print server request details if($requests[$i]['server']) { $data = array('owner' => getUserUnityID($requests[$i]['userid']), 'requesttime' => $requests[$i]['daterequested'], 'admingroup' => $requests[$i]['serveradmingroup'], 'logingroup' => $requests[$i]['serverlogingroup'], 'image' => $requests[$i]['prettyimage'], 'starttime' => $requests[$i]['start']); if($requests[$i]['currstateid'] == 14) $data['stateid'] = $requests[$i]['laststateid']; else $data['stateid'] = $requests[$i]['currstateid']; $text .= getViewRequestHTMLitem('serverdetails', $requests[$i]['id'], $data); } if(checkUserHasPerm('View Debug Information')) { if(! is_null($requests[$i]['vmhostid'])) { $query = "SELECT c.hostname " . "FROM computer c, " . "vmhost v " . "WHERE v.id = {$requests[$i]['vmhostid']} AND " . "v.computerid = c.id"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); $vmhost = $row['hostname']; } $text .= " \n"; $text .= "
"; $text .= "Mgmt node: {$nodes[$requests[$i]["managementnodeid"]]['hostname']}
\n"; $text .= "Computer ID: {$requests[$i]['computerid']}
\n"; $text .= "Comp hostname: {$computers[$requests[$i]["computerid"]]["hostname"]}
\n"; $text .= "Comp IP: {$requests[$i]["IPaddress"]}
\n"; $text .= "Comp State ID: {$computers[$requests[$i]["computerid"]]["stateid"]}
\n"; $text .= "Comp Type: {$requests[$i]['comptype']}
\n"; if(! is_null($requests[$i]['vmhostid'])) $text .= "VM Host: $vmhost
\n"; $text .= "Current State ID: {$requests[$i]["currstateid"]}
\n"; $text .= "Last State ID: {$requests[$i]["laststateid"]}
\n"; $text .= "
\n"; } $text .= " \n"; if($requests[$i]['server']) $server .= $text; elseif($requests[$i]['forimaging']) $imaging .= $text; elseif($requests[$i]['longterm']) $long .= $text; else $normal .= $text; } } $text = _("

Current Reservations

\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"; $text .= " \n"; $text .= " \n"; $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); if(checkUserHasPerm('View Debug Information')) $text .= _(" \n"); $text .= " \n"; $text .= $normal; $text .= "
EnvironmentStartingEndingInitially requestedReq ID
\n"; } if(! empty($imaging)) { if(! empty($normal)) $text .= "
\n"; $text .= _("You currently have the following imaging reservations:
\n"); $text .= "\n"; $text .= " \n"; $text .= " \n"; $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); $computers = getComputers(); if(checkUserHasPerm('View Debug Information')) $text .= " \n"; $text .= " \n"; $text .= $imaging; $text .= "
EnvironmentStartingEndingInitially requestedReq ID
\n"; } if(! empty($long)) { if(! empty($normal) || ! empty($imaging)) $text .= "
\n"; $text .= _("You currently have the following long term reservations:
\n"); $text .= "\n"; $text .= " \n"; $text .= " \n"; $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); $text .= _(" \n"); $computers = getComputers(); if(checkUserHasPerm('View Debug Information')) $text .= " \n"; $text .= " \n"; $text .= $long; $text .= "
EnvironmentStartingEndingInitially requestedReq ID
\n"; } if(! empty($server)) { if(! empty($normal) || ! empty($imaging) || ! empty($long)) $text .= "
\n"; $text .= _("You currently have the following server reservations:
\n"); $text .= "\n"; $text .= " \n"; $text .= " \n"; $text .= " \n"; $text .= _(" \n"); $computers = getComputers(); $text .= " \n"; if(checkUserHasPerm('View Debug Information')) $text .= " \n"; $text .= " \n"; $text .= $server; $text .= "
" . _("Name") . "Ending" . _("Details") . "" . _("Req ID") . "
\n"; } # connect div if($connect) { $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.\n"); } if($failed) { $text .= _("

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"); } $cont = addContinuationsEntry('AJviewRequests', array(), SECINDAY); $text .= "\n"; $text .= "\n"; if($mode != 'AJviewRequests') { $text .= "
\n"; $text .= " this.hide();\n"; $text .= "\n"; $text .= "\n"; $text .= "
\n"; $text .= "\n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "\n"; $text .= "
\n"; $text .= " hideEditResDlg();\n"; $text .= " \n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= " hideRebootResDlg();\n"; $text .= " \n"; $text .= "
" . _("You can select either a "); $text .= _("soft or a hard reboot. A soft reboot
issues a reboot "); $text .= _("command to the operating system. A hard reboot
is akin to "); $text .= _("toggling the power switch on a computer. After
issuing the "); $text .= _("reboot, it may take several minutes before the
machine is "); $text .= _("available again. It is also possible that it will
not come "); $text .= _("back up at all. Are you sure you want to continue?") . "

\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= " \n"; $text .= "

\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= " hideReinstallResDlg();\n"; $text .= " \n"; $text .= "
"; $text .= " " . _("Loading...") . "
\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "
"; $text .= " " . _("Loading...") . "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "\n"; print $text; } else { $text = str_replace("\n", ' ', $text); $text = str_replace("('", "(\'", $text); $text = str_replace("')", "\')", $text); print "document.body.style.cursor = 'default';"; 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)); } print "checkResGone(" . json_encode($reqids) . ");"; return; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getViewRequestHTMLitem($item, $var1, $data) /// /// \param $item - name of HTML section to be generated /// \param $var1 - generic variable to be used in HTML /// \param $data - an array of any extra data to be used in HTML /// /// \return a string of HTML /// /// \brief generates HTML for a specific portion of the current reservations /// page /// //////////////////////////////////////////////////////////////////////////////// function getViewRequestHTMLitem($item, $var1='', $data=array()) { $r = ''; if($item == 'connectbtn') { $r .= " \n"; $r .= "
\n"; $r .= " \n"; $r .= " \n"; $r .= "
\n"; $r .= " \n"; return $r; } if($item == 'deletebtn') { $r .= " \n"; $r .= " \n"; $r .= " \n"; return $r; } if($item == 'failedblock') { $r .= " \n"; $r .= " \n"; $r .= " "; $r .= "
" . _("Reservation failed") . "\n"; $r .= " \n"; $r .= " \n"; $r .= " \n"; return $r; } if($item == 'removebtn') { $r .= " \n"; $r .= " \n"; $r .= " \n"; return $r; } if($item == 'timeoutblock') { $r .= " \n"; $r .= " " . _("Reservation has timed out") . "\n"; $r .= " \n"; return $r; } if($item == 'pendingblock') { $r .= " \n"; $r .= " \n"; $r .= " "; $r .= "" . _("Pending...") . "\n"; $r .= " \n"; $r .= " \n"; if(! empty($data['text'])) $r .= " {$data['text']}"; $r .= " \n"; return $r; } if($item == 'openmoreoptions') { $r .= " \n"; $r .= "
\n"; $r .= " " . _("More Options") . "...\n"; $r .= "
\n"; return $r; } if($item == 'editoption') { $r .= "
\n"; $r .= "
\n"; return $r; } if($item == 'endcreateoption') { $r .= "
\n"; else $r .= " onClick=\"window.location.href='$var1';\">\n"; $r .= "
\n"; return $r; } if($item == 'endcreateoptiondisable') { $r .= "
\n"; else $r .= " onClick=\"window.location.href='$var1';\">\n"; $r .= "
\n"; return $r; } if($item == 'checkpointoptiondisable') { $r .= "
\n"; $r .= " \n"; $r .= "
\n"; return $r; } if($item == 'rebootoptiondisable') { $r .= "
\n"; $r .= "
\n"; return $r; } if($item == 'reinstalloption') { $r .= "
\n"; $r .= " \n"; $r .= "
\n"; return $r; } if($item == 'reinstalloptiondisable') { $r .= "
\n"; $r .= "
\n"; return $r; } if($item == 'imagename') { $r .= " " . str_replace("'", "'", $var1); if($data['addtest']) $r .= _(" (Testing)"); $r .= "\n"; return $r; } if($item == 'starttime') { if(datetimeToUnix($data['start']) < datetimeToUnix($data['requested'])) $r .= " " . prettyDatetime($data['requested'], 1) . "\n"; else $r .= " " . prettyDatetime($data['start'], 1) . "\n"; return $r; } if($item == 'endtime') { if($data['end'] == '2038-01-01 00:00:00') $r .= " " . _("(none)") . "\n"; else $r .= " " . prettyDatetime($data['end'], 1) . "\n"; return $r; } if($item == 'requesttime') { $r .= " " . prettyDatetime($var1, 1) . "\n"; return $r; } if($item == 'servername') { $r .= " $var1\n"; return $r; } if($item == 'serverdetails') { $r .= "\n"; $r .= ""; $r .= "\"details\"\n"; $r .= "
\n"; $r .= "" . _("Owner") . ":" . " {$data['owner']}
\n"; $r .= "" . _("Environment") . ":" . " {$data['image']}
\n"; $r .= "" . _("Start Time") . ": " . prettyDatetime($data['starttime'], 1) . "
\n"; $r .= "" . _("Initially Requested") . ": " . prettyDatetime($data['requesttime'], 1) . "
\n"; if(empty($data['admingroup'])) $r .= "" . _("Admin User Group") . ": (" . _("none") . ")
\n"; else $r .= "" . _("Admin User Group") . ":" . " {$data['admingroup']}
\n"; if(empty($data['logingroup'])) $r .= "" . _("Access User Group") . ": " . _("(none)") . "
\n"; else $r .= "" . _("Access User Group") . ":" . " {$data['logingroup']}
\n"; if($data['stateid'] == 8) $r .= "" . _("Status") . ": " . _("In Use") . "\n"; elseif($data['stateid'] == 24) $r .= "" . _("Status") . ": " . _("Checkpointing") . "\n"; elseif($data['stateid'] == 5) $r .= "" . _("Status") . ": " . _("Failed") . "\n"; elseif($data['stateid'] == 13) $r .= "" . _("Status") . ": " . _("New") . "\n"; elseif($data['stateid'] == 28) $r .= "" . _("Status") . ": " . _("Hard Rebooting") . "\n"; elseif($data['stateid'] == 26) $r .= "" . _("Status") . ": " . _("Soft Rebooting") . "\n"; elseif($data['stateid'] == 27) $r .= "" . _("Status") . ": " . _("Reinstalling") . "\n"; elseif($data['stateid'] == 6) $r .= "" . _("Status") . ": " . _("Loading") . "\n"; elseif($data['stateid'] == 3) $r .= "" . _("Status") . ": " . _("In Use") . "\n"; elseif($data['stateid'] == 11) $r .= "" . _("Status") . ": " . _("Timed Out") . "\n"; $r .= "
\n"; $r .= "\n"; return $r; } if($item == 'timeoutdata') { if($data['currstateid'] == 8 || ($data['currstateid'] == 14 && $data['laststateid'] == 8)) { $end = datetimeToUnix($data['end']) + 15; $r .= " \n"; } else { $timeout = getReservationNextTimeout($data['resid']); if(! is_null($timeout)) $r .= " \n"; } return $r; } } //////////////////////////////////////////////////////////////////////////////// /// /// \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 .= ""; $text .= _("New 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 # info on reboots/reinstalls not available yet if(empty($flow) || count($request['reservations']) > 0 || ($request['currstateid'] == 14 && $request['laststateid'] == 26) || /*($request['currstateid'] == 14 && $request['laststateid'] == 27) ||*/ ($request['currstateid'] == 14 && $request['laststateid'] == 28)) { $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 .= _(""); $text .= _(""); $text .= _(""); $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 .= _(""; $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 .= ""; $text .= ""; $text .= ""; $text .= ""; $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 .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= ""; $text .= "

State
Est/Act
Time
Total
Time

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 .= "
"; $text .= _($flow['data'][$id]['state']) . "($id)"; $text .= secToMinSec($flow['data'][$id]['statetime']) . $slash; $text .= secToMinSec($data['time']) . ""; $text .= secToMinSec($total) . "
"; $text .= _($flow['data'][$id]['state']) . "($id)"; $text .= secToMinSec($flow['data'][$id]['statetime']); $text .= $slash . secToMinSec($currtime) . ""; $text .= secToMinSec($total + $currtime) . "
"; if(strlen($reason)) $text .= _("
failed: ") . "$reason"; return $text; } # otherwise add text about current state else { if(! empty($data)) $currtime = $now - $data['ts']; else $currtime = $now - datetimeToUnix($request['daterequested']); $text .= ""; $text .= _($flow['data'][$id]['state']) . "($id)"; $text .= ""; $text .= secToMinSec($flow['data'][$id]['statetime']); $text .= $slash . secToMinSec($currtime) . ""; $text .= ""; $text .= secToMinSec($total + $currtime) . ""; $text .= ""; $first = 0; } } # add text about future states else { $text .= ""; $text .= _($flow['data'][$id]['state']) . "($id)"; $text .= ""; $text .= secToMinSec($flow['data'][$id]['statetime']) . ""; $text .= ""; $text .= ""; } $id = $flow['nextstates'][$id]; } $text .= ""; return $text; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewRequestInfo() /// /// \brief prints a page with information about a specific request /// //////////////////////////////////////////////////////////////////////////////// function viewRequestInfo() { $requestid = getContinuationVar('requestid'); $request = getRequestInfo($requestid); if($request['forimaging'] || $request['stateid'] == 18 || $request['laststateid'] == 18) $reservation = $request['reservations'][0]; else { foreach($request["reservations"] as $res) { if($res["forcheckout"]) { $reservation = $res; break; } } } $states = getStates(); $userinfo = getUserInfo($request["userid"], 1, 1); print "
\n"; print "

View Reservation

\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) { print " \n"; } else { print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(! empty($request["datemodified"])) { print " \n"; } else { 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"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
User:" . $userinfo["unityid"] . "
Start Time:" . prettyDatetime($request["daterequested"]) . "" . prettyDatetime($request["start"]) . "
End Time:" . prettyDatetime($request["end"]) . "
Request Time:" . prettyDatetime($request["daterequested"]) . "
Last Modified:" . prettyDatetime($request["datemodified"]) . "Never Modified
Current State:" . $states[$request["stateid"]] . "
Last State:"; if($request["laststateid"]) { print $states[$request["laststateid"]]; } else { print "None"; } print "
Image:{$reservation['prettyimage']}
Hostname:{$request['reservations'][0]["hostname"]}
IP Address:{$request['reservations'][0]["reservedIP"]}
\n"; if(count($request['reservations'] > 1)) { array_shift($request['reservations']); print "Subimages:
\n"; print "\n"; foreach($request["reservations"] as $res) { 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 "
Image:{$res["prettyimage"]}
Hostname:{$res["hostname"]}
IP Address:{$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"; $cdata = array('requestid' => $requestid, 'notbyowner' => 1, 'ttdata' => getContinuationVar('ttdata'), 'fromtimetable' => 1); $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata, SECINDAY); 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 AJeditRequest() /// /// \brief prints a page for a user to edit a previous request /// //////////////////////////////////////////////////////////////////////////////// function AJeditRequest() { global $submitErr, $user; $requestid = getContinuationVar('requestid', 0); $request = getRequestInfo($requestid, 1); # check to see if reservation exists if(is_null($request)) { 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; $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, 'modifystart' => 0, 'allowindefiniteend' => 0); if($request['serverrequest']) { if(empty($request['servername'])) $request['servername'] = $request['reservations'][0]['prettyimage']; $h .= _("Name") . ":
"; if($user['showallgroups']) $groups = getUserGroups(); else $groups = getUserGroups(0, $user['affiliationid']); $h .= _("Admin User Group") . ": "; if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { $h .= ""; if(! empty($request['admingroupid']) && ! array_key_exists($request['admingroupid'], $groups)) { $id = $request['admingroupid']; $name = getUserGroupName($request['admingroupid'], 1); $h .= "\n"; } $h .= "\n"; foreach($groups as $id => $group) { if($id == $request['admingroupid']) $h .= ""; else $h .= ""; } $h .= "
"; $h .= _("Access User Group") . ": "; if(USEFILTERINGSELECT && count($groups) < FILTERINGSELECTTHRESHOLD) { $h .= ""; if(! empty($request['logingroupid']) && ! array_key_exists($request['logingroupid'], $groups)) { $id = $request['logingroupid']; $name = getUserGroupName($request['logingroupid'], 1); $h .= "\n"; } $h .= "\n"; foreach($groups as $id => $group) { if($id == $request['logingroupid']) $h .= ""; else $h .= ""; } $h .= "

"; } // if future, allow start to be modified if($unixstart > $now) { $cdata['modifystart'] = 1; $txt = _("Modify reservation for") . " {$request['reservations'][0]['prettyimage']} "; $txt .= _("starting ") . prettyDatetime($request["start"]) . ":
"; $h .= preg_replace("/(.{1,60}[ \n])/", '\1
', $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 .= _("Start") . ": "; $h .= _(" At "); $tmp = explode(' ' , $request['start']); $stime = $tmp[1]; $h .= "
"; $h .= "(" . date('T') . ")

"; $durationmatch = 0; if($request['serverrequest']) { $cdata['allowindefiniteend'] = 1; if($request['end'] == '2038-01-01 00:00:00') { $h .= ""; } else { $h .= ""; } $h .= _(""); } 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 " . _("minutes"); if($durationmin == 30) $durationmatch = 1; } if($maxtimes["initial"] >= 45) { $lengths["45"] = "45 " . _("minutes"); if($durationmin == 45) $durationmatch = 1; } if($maxtimes["initial"] >= 60) { $lengths["60"] = "1 " . _("hour"); if($durationmin == 60) $durationmatch = 1; } for($i = 120; $i <= $maxtimes["initial"] && $i < 2880; $i += 120) { $lengths[$i] = $i / 60 . _(" hours"); if($durationmin == $i) $durationmatch = 1; } for($i = 2880; $i <= $maxtimes["initial"]; $i += 1440) { $lengths[$i] = $i / 1440 . _(" days"); if($durationmin == $i) $durationmatch = 1; } if($openend) { if($durationmatch) { $h .= ""; } else { $h .= ""; } $h .= ""; $h .= ""; } if($openend) { if($request['serverrequest'] && $request['end'] == '2038-01-01 00:00:00') { $h .= "
"; $edate = ''; $etime = ''; } else { if(! $request['serverrequest'] && $durationmatch) { $h .= "
"; } else { $h .= "
"; } $tmp = explode(' ', $request['end']); $edate = $tmp[0]; $etime = $tmp[1]; } $h .= ""; $h .= "
"; $h .= "
"; $h .= "(" . date('T') . ")"; } $h .= "

"; $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 .= _("You are only allowed to extend your reservation such that it "); $h .= _("has a total length of ") . minToHourMin($maxcheck); $h .= _(". This reservation
already meets that length. Therefore, "); $h .= _("you are not allowed to extend your reservation any further.

"); 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; foreach($request["reservations"] as $res) { if(! moveReservationsOffComputer($res["computerid"], 1)) { $movedall = 0; break; } } if(! $movedall) { $h .= _("The computer you are using has another reservation
"); $h .= _("immediately following yours. Therefore, you cannot
extend "); $h .= _("your reservation because it would overlap
with the next "); $h .= _("one.
"); 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 " . _("minutes"); if((($reslen + 30) <= $maxtimes["total"]) && (30 <= $maxtimes["extend"])) $lengths["30"] = "30 " . _("minutes"); if((($reslen + 45) <= $maxtimes["total"]) && (45 <= $maxtimes["extend"])) $lengths["45"] = "45 " . _("minutes"); if((($reslen + 60) <= $maxtimes["total"]) && (60 <= $maxtimes["extend"])) $lengths["60"] = _("1 hour"); for($i = 120; (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]) && $i < 2880; $i += 120) $lengths[$i] = $i / 60 . _(" hours"); for($i = 2880; (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]); $i += 1440) $lengths[$i] = $i / 1440 . _(" days"); } 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 >= 45 && (($reslen + 45) <= $maxtimes["total"]) && (45 <= $maxtimes["extend"])) $lengths["45"] = "45 " . _("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 < 2880; $i += 120) $lengths[$i] = $i / 60 . _(" hours"); for($i = 2880; ($i <= $timeToNext) && (($reslen + $i) <= $maxtimes["total"]) && ($i <= $maxtimes["extend"]); $i += 1440) $lengths[$i] = $i / 1440 . _(" days"); } $cdata['lengths'] = array_keys($lengths); if($timeToNext == -1 || $timeToNext >= $maxtimes['total']) { if($openend) { if(! empty($lengths)) { $h .= _("You can extend this reservation by a selected amount or
"); $h .= _("change the end time to a specified date and time.

"); } else $h .= _("Modify the end time for this reservation:

"); } else { if($request['forimaging'] && $maxtimes['total'] < 720) $maxcheck = 720; else $maxcheck = $maxtimes['total']; $h .= _("You can extend this reservation by up to "); $h .= minToHourMin($maxtimes["extend"]) . _(", but not
exceeding "); $h .= minToHourMin($maxcheck) . _(" for your total reservation time."); $h .= "

"; } } else { $t = _("The computer you are using has another reservation following "); $t .= _("yours. Therefore, you can only extend this reservation for "); $t .= _("another ") . prettyLength($timeToNext) . ".
"; $h .= preg_replace("/(.{1,60}[ ])/", '\1
', $t); } # extend by drop down # extend by specifying end time if $openend if($openend) { if($request['serverrequest']) { $cdata['allowindefiniteend'] = 1; $endchecked = 0; if($request['end'] == '2038-01-01 00:00:00') { $h .= ""; $h .= ""; $h .= "
"; } else { $h .= ""; $h .= ""; $h .= "
"; $endchecked = 1; } $h .= "