\n"; $newbtnh .= " " . _("New Reservation") . "\n"; $newbtnh .= " \n"; $newbtnh .= "

\n"; } if($mode != 'AJviewRequests') { print "

" . _("Current Reservations") . "

\n"; if(count($requests) == 0) print "\n"; else print "\n"; if($newbtnh == '') print _("You have no current reservations and do not have access to create new ones.") . "

\n"; else print _("You have no current reservations.") . "

\n"; print "
\n"; print $newbtnh; } if($newbtnh == '') return; if($mode != 'AJviewRequests') print "
\n"; $refresh = 0; $connect = 0; $failed = 0; $normal = ''; $imaging = ''; $long = ''; $server = ''; $pendingcnt = 0; $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('AJconnectRequest', $cdata, SECINDAY); $text .= getViewRequestHTMLitem('connectbtn', $cont); if($requests[$i]['serveradmin']) { $cdata2 = $cdata; $cdata2['notbyowner'] = 0; if($user['id'] != $requests[$i]['userid']) $cdata2['notbyowner'] = 1; $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, 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 $pendingcnt++; $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'] != 24 && ($requests[$i]["currstateid"] != 14 || ($requests[$i]['laststateid'] != 26 && $requests[$i]['laststateid'] != 27 && $requests[$i]['laststateid'] != 28 && $requests[$i]['laststateid'] != 24))) $data['text'] = _("
Est: ") . $remaining . _(" min remaining\n"); $text .= getViewRequestHTMLitem('pendingblock', $requests[$i]['id'], $data); $refresh = 1; if($requests[$i]['serveradmin'] && $requests[$i]['laststateid'] != 24) { $cdata2 = $cdata; $cdata2['notbyowner'] = 0; if($user['id'] != $requests[$i]['userid']) $cdata2['notbyowner'] = 1; $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, SECINDAY); $text .= getViewRequestHTMLitem('deletebtn', $cont); } else $text .= " \n"; } } else { # reservation is in the future $text .= " \n"; if($requests[$i]['serveradmin']) { $cdata2 = $cdata; $cdata2['notbyowner'] = 0; if($user['id'] != $requests[$i]['userid']) $cdata2['notbyowner'] = 1; $cont = addContinuationsEntry('AJconfirmDeleteRequest', $cdata2, SECINDAY); $text .= getViewRequestHTMLitem('deletebtn', $cont); } else $text .= " \n"; } if(! $failed && ! $timedout) { # print edit button $editcont = addContinuationsEntry('AJeditRequest', $cdata, SECINDAY); $imgcont = addContinuationsEntry('AJstartImage', $cdata, SECINDAY); 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 $text .= getViewRequestHTMLitem('endcreateoption', $imgcont); } /*else $text .= getViewRequestHTMLitem('endcreateoptiondisable');*/ if(array_key_exists($imageid, $resources['image']) && ! $cluster && $requests[$i]['server'] && ($requests[$i]['currstateid'] == 8 || ($requests[$i]['currstateid'] == 14 && $requests[$i]['laststateid'] == 8))) { $chkcdata = $cdata; $chkcdata['checkpoint'] = 1; $imgcont = addContinuationsEntry('AJstartImage', $chkcdata, SECINDAY); $text .= getViewRequestHTMLitem('checkpointoption', $imgcont); } 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; } } 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 .= ""; $text .= _("NOTE: The maximum allowed reservation length for one of these reservations was less than the length you submitted, and the length of that reservation has been adjusted accordingly."); $text .= "\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 .= "
" . _("Environment") . "" . _("Starting") . "" . _("Ending") . "" . _("Initially requested") . "" . _("Req 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 .= "
" . _("Environment") . "" . _("Starting") . "" . _("Ending") . "" . _("Initially requested") . "Req 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 .= "
" . _("Environment") . "" . _("Starting") . "" . _("Ending") . "" . _("Initially requested") . "Req 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 .= "

"; $text .= _("Click the Connect! button to get further information about connecting to the reserved system. You must click the button from a web browser running on the same computer from which you will be connecting to the remote computer; otherwise, you may be denied access to the machine.") . "\n"; } if($refresh) { $text .= "

"; $text .= _("This page will automatically update every 20 seconds until the Pending... reservation is ready.") . "\n"; } if($failed) { $text .= "

"; $text .= _("An error has occurred that has kept one of your reservations from being processed. We apologize for any inconvenience this may have caused.") . "\n"; } $cont = addContinuationsEntry('AJviewRequests', array(), SECINDAY); $text .= "\n"; $cont = addContinuationsEntry('AJpreviewClickThrough', array()); $text .= "\n"; $text .= "\n"; if($mode != 'AJviewRequests') { $text .= newReservationHTML(); $text .= newReservationConfigHTML(); /*$text .= "
\n"; #$text .= " style=\"height: 80%; width: 50%;\">\n"; $text .= " style=\"width: 50%;\">\n"; #$text .= "
\n"; #$text .= "
\n"; $text .= _("There are multiple versions of this environment available."); $text .= "
" . _("Please select the version you would like to check out:"); #$text .= "\n
\n"; # ContentPane #$text .= "
\n"; #$text .= "
\n"; $text .= "
\n"; #$text .= "
\n"; # ContentPane #$text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; # center #$text .= "
\n"; # ContentPane #$text .= "
\n"; # BorderContainer $text .= "
\n"; # Dialog*/ $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 .= "
\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 .= "
"; $h = _("You can select either a soft or a hard reboot. A soft reboot issues a reboot command to the operating system. A hard reboot is akin to toggling the power switch on a computer. After issuing the reboot, it may take several minutes before the machine is available again. It is also possible that it will not come back up at all. Are you sure you want to continue?"); $text .= preg_replace("/(.{1,60}([ \n]|$))/", '\1
', $h); $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 .= " 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"; $text .= "
\n"; $text .= " hideStartImageDlg();\n"; $text .= " \n"; $text .= "
\n"; $text .= "

" . _("Create / Update an Image") . "

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

" . _("Keep Reservation & Create / Update an Image") . "

\n"; $h = _("This process will create a new image or new revision of the image while allowing you to keep your reservation. The node will be taken offline during the image capture process."); $h .= "\n \n"; $h .= "" . _("NOTE: The same sanitizing that occurs during normal image capture will take place. This includes things such as deleting temporary files, cleaning out firewall rules, removing user home space, and removing user accounts."); $h .= "\n \n"; $h .= _("After the imaging occurs, you will be able to connect to the reservation again. The image will appear to you as if you had just made a new reservation for it."); $h .= "\n \n"; $text .= preg_replace("/(.{1,80}([ \n]|$))/", '\1
', $h); $text .= "
\n"; # imagekeeprescontent $text .= _("Are you creating a new image or updating an existing image?") . "

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

\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= "\n"; $text .= "
', $h); $text .= "

\n"; $text .= "
\n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "\n"; $obj = new Image(); $text .= $obj->addEditDialogHTML(1); $text .= "
\n"; $text .= " hideUpdateImageDlg();\n"; $text .= " \n"; $text .= "
\n"; $text .= "

" . _("New Revision Comments") . "

\n"; $h = _("Enter any notes for yourself and other admins about the current state of the image. These are optional and are not visible to end users:"); $text .= preg_replace("/(.{1,85}([ \n]|$))/", '\1
', $h); $text .= " \n"; $text .= "

" . _("Previous Revision Comments") . "

\n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= " \n"; $text .= " \n"; $text .= "
\n"; $text .= "
\n"; $text .= "
\n"; $text .= " hideClickThroughDlg();\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 .= "

Confirm Server Delete

\n"; $text .= " \n"; $warn = _("WARNING: You are not the owner of this reservation. You have been granted access to manage this reservation by another user. Hover over the details icon to see who the owner is. You should not delete this reservation unless the owner is aware that you are deleting it."); $text .= preg_replace("/(.{1,80}([ \n]|$))/", '\1
', $warn); $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(count($requests) == 0) print "dojo.removeClass('noresspan', 'hidden');"; else print "dojo.addClass('noresspan', 'hidden');"; 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) . ");"; if($pendingcnt) print "document.title = '$pendingcnt Pending :: VCL :: Virtual Computing Lab';"; else print "document.title = 'VCL :: Virtual Computing Lab';"; 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()) { global $user; $r = ''; if($item == 'connectbtn') { $r .= " \n"; $r .= dijitButton('', _("Connect!"), "connectRequest('$var1');"); $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"; $r .= "
\n"; return $r; } if($item == 'endcreateoptiondisable') { $r .= "
\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') { $timeout = getReservationNextTimeout($data['resid']); $end = datetimeToUnix($data['end']); if(! is_null($timeout)) { if($timeout > $end) $timeout = $end; $r .= " \n"; } else { $timeout = getVariable("reconnecttimeout|{$user['affiliation']}"); if(is_null($timeout)) $timeout = getVariable("reconnecttimeout", 900); $timeout = time() + $timeout + 15; if($timeout > $end) $timeout = $end; $r .= " \n"; } return $r; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn newReservationHTML() /// /// \return html /// /// \brief generates HTML for dialog for creating new reservation /// //////////////////////////////////////////////////////////////////////////////// function newReservationHTML() { global $user, $skin; $forimaging = getContinuationVar('imaging', processInputVar('imaging', ARG_NUMERIC, 0)); $checkout = getUserResources(array("imageAdmin", "imageCheckOut")); $imaging = getUserResources(array("imageAdmin")); $server = getUserResources(array("serverCheckOut"), array("available")); $imagedata = getImages(); $baseaccess = 0; $imagingaccess = 0; $serveraccess = 0; $images = array(); $serverimages = array(); $dorevisionscont = 0; if(in_array('imageAdmin', $user['privileges']) && count($imaging['image'])) { $imagingaccess = 1; } if(in_array('imageCheckOut', $user['privileges']) && count($checkout['image'])) { $baseaccess = 1; foreach($checkout['image'] as $id => $name) { $images[$id] = array('name' => $name, 'basic' => 1, 'imaging' => 0, 'server' => 1, 'checkout' => 1, 'maxinitialtime' => 0, 'revisions' => 0); if(array_key_exists($id, $imagedata) && ! $imagedata[$id]["forcheckout"]) $images[$id]['checkout'] = 0; if($imagingaccess && array_key_exists($id, $imaging['image'])) $images[$id]['imaging'] = 1; if(array_key_exists($id, $imagedata) && $imagedata[$id]["maxinitialtime"] != 0) $images[$id]['maxinitialtime'] = $imagedata[$id]['maxinitialtime']; $subowner = 0; if(array_key_exists($id, $imagedata) && $imagedata[$id]['imagemetaid'] != NULL && count($imagedata[$id]['subimages'])) { foreach($imagedata[$id]['subimages'] as $subid) { if(array_key_exists($subid, $imagedata) && $imagedata[$subid]['ownerid'] == $user['id'] && count($imagedata[$subid]['imagerevision']) > 1) $subowner = 1; } } if($subowner || (array_key_exists($id, $imagedata) && count($imagedata[$id]['imagerevision']) > 1 && ($imagedata[$id]['ownerid'] == $user['id'] || checkUserHasPerm('View Debug Information')))) { $images[$id]['revisions'] = 1; $dorevisionscont = 1; } } } if(in_array('serverCheckOut', $user['privileges']) && count($checkout['image'])) { $serveraccess = 1; $extraimages = getServerProfileImages($user['id']); foreach($extraimages as $id => $name) { if(! array_key_exists($id, $images)) { $images[$id] = array('name' => $name, 'basic' => 0, 'imaging' => 0, 'server' => 1, 'checkout' => 1, 'maxinitialtime' => 0, 'revisions' => 0); if(array_key_exists($id, $imagedata) && ! $imagedata[$id]["forcheckout"]) $images[$id]['checkout'] = 0; if(array_key_exists($id, $imagedata) && $imagedata[$id]["maxinitialtime"] != 0) $images[$id]['maxinitialtime'] = $imagedata[$id]['maxinitialtime']; $subowner = 0; if(array_key_exists($id, $imagedata) && $imagedata[$id]['imagemetaid'] != NULL && count($imagedata[$id]['subimages'])) { foreach($imagedata[$id]['subimages'] as $subid) { if(array_key_exists($subid, $imagedata) && $imagedata[$subid]['ownerid'] == $user['id'] && count($imagedata[$subid]['imagerevision']) > 1) $subowner = 1; } } if($subowner || (array_key_exists($id, $imagedata) && count($imagedata[$id]['imagerevision']) > 1 && ($imagedata[$id]['ownerid'] == $user['id'] || checkUserHasPerm('View Debug Information')))) { $images[$id]['revisions'] = 1; $dorevisionscont = 1; } } } } $imageid = getUsersLastImage($user['id']); if(is_null($imageid) && count($images)) { $tmp = array_keys($images); $imageid = $tmp[0]; } uasort($images, "sortKeepIndex"); $groupid = getUserGroupID('Specify End Time', 1); $members = getUserGroupMembers($groupid); if(array_key_exists($user['id'], $members)) $openend = 1; else $openend = 0; $groupid = getUserGroupID('Allow No User Check', 1); $members = getUserGroupMembers($groupid); if(array_key_exists($user['id'], $members)) $nousercheck = 1; else $nousercheck = 0; $cdata = array('baseaccess' => $baseaccess, 'imagingaccess' => $imagingaccess, 'serveraccess' => $serveraccess, 'openend' => $openend, 'nousercheck' => $nousercheck, 'imaging' => $forimaging); $debug = processInputVar('debug', ARG_NUMERIC, 0); if($debug && checkUserHasPerm('View Debug Information')) $cdata['debug'] = 1; $h = ''; $h = "
\n"; $h .= "
\n"; /*$cbtn = "

\n"; $cbtn .= " \n"; $cbtn .= "
\n"; # center if($forimaging) { $h .= "

" . _("Create / Update an Image") . "

\n"; if($imagingaccess == 0) { $h .= _("You don't have access to any base images from which to create new images.") . "
\n"; return $h . $cbtn; } } else*/ $h .= "

" . _("New Reservation") . "

\n"; if(! count($images)) { $h .= _("You do not have access to any images."); $h .= "

\n"; $h .= "

\n"; $h .= " \n"; $h .= "
\n"; # center $h .= "
\n"; # newResDlgContent $h .= "
\n"; # newResDlg return $h; } $chk = array('base' => '', 'imaging' => '', 'server' => ''); if(! $baseaccess && $serveraccess) $chk['server'] = 'checked'; elseif($forimaging) $chk['imaging'] = 'checked'; else $chk['base'] = 'checked'; $showradios = 0; if($baseaccess + $imagingaccess + $serveraccess > 1) $showradios = 1; if($showradios) $h .= _("Reservation type:") . "
\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; if($showradios) $h .= "

\n"; $h .= "\n"; $h .= "
\n"; $h .= _("Profile:") . " "; $h .= "
\n"; $h .= "
\n"; $h .= "" . _("Description:") . "\n"; $h .= "
\n"; $h .= "
\n"; $cont = addContinuationsEntry('AJserverProfileData', array('mode' => 'checkout')); $h .= ""; $h .= "

\n"; $h .= "\n"; $h .= "
\n"; # deployprofileslist $h .= "
\n"; # directions $h .= ""; $h .= _("Please select the environment you want to use from the list:"); $h .= "
\n"; # javascript for max duration and image store $maxTimes = getUserMaxTimes(); $maximaging = $maxTimes['initial']; if($imagingaccess && $maxTimes['initial'] < MAXINITIALIMAGINGTIME) $maximaging = MAXINITIALIMAGINGTIME; $h .= "\n"; $cdata['maxinitial'] = $maxTimes['initial']; # image $h .= ""; $h .= resourceStore('image', 1, 'detailimagestore'); $h .= "
\n"; $h .= "\n"; $h .= "


\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"; } $h .= "
$desc
\n"; # name $h .= "
\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "
\n"; $h .= ""; # admin group if($user['showallgroups']) $admingroups = getUserGroups(); else $admingroups = getUserGroups(0, $user['affiliationid']); $h .= ""; if(USEFILTERINGSELECT && count($admingroups) < FILTERINGSELECTTHRESHOLD) { $h .= "\n"; $h .= " \n"; foreach($admingroups as $id => $group) { if($group['name'] == 'None' || preg_match('/^None@.*$/', $group['name'])) continue; $h .= " \n"; } $h .= "
\n"; # login group $logingroups = $admingroups; $h .= ""; if(USEFILTERINGSELECT && count($logingroups) < FILTERINGSELECTTHRESHOLD) { $h .= "\n"; $h .= " \n"; foreach($logingroups as $id => $group) { if($group['name'] == 'None' || preg_match('/^None@.*$/', $group['name'])) continue; $h .= " \n"; } $h .= "
\n"; # fixed MAC /*$h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "(optional)"; $h .= "
\n";*/ # monitored /*$h .= "\n"; $h .= "\n"; $h .= "
\n";*/ # fixed IP block $h .= "
\n"; $h .= "
\n"; # ip addr $regip1 = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"; $regip4 = "$regip1\\.$regip1\\.$regip1\\.$regip1"; $h .= "\n"; $h .= "" . _("(optional)") . "
\n"; # netmask $h .= "\n"; $h .= "" . _("Router:") . "\n"; $h .= "" . _("DNS Server(s):") . "\n"; $h .= "
\n"; $h .= "
\n"; # nrfixedipdiv $h .= "

"; $h .= "
\n"; # nrfixedipdiv2 $h .= "
\n"; # newreslabelfields $h .= ""; $h .= _("When would you like to use the environment?"); $h .= "\n"; $h .= ""; $h .= _("When would you like to start the imaging process?"); $h .= "\n"; $h .= ""; $h .= _("When would you like to deploy the server?"); $h .= ""; $h .= "
\n"; # duration radios $h .= "   "; $h .= "\n"; $h .= "
\n"; $h .= "   "; $h .= "\n"; $h .= "\n"; # limited start $days = getReserveDayData(); $h .= "\n"; $h .= selectInputHTML('day', $days, 'deploystartday', "onChange='setStartLater();'"); $h .= " " . _("At") . " \n"; $tmpArr = array(); for($i = 1; $i < 13; $i++) $tmpArr[$i] = $i; $timestamp = unixFloor15(time() + 4500); $timeArr = explode(',', date('g,i,a', $timestamp)); $h .= selectInputHTML('hour', $tmpArr, 'deployhour', "onChange='setStartLater();'", $timeArr[0]); $minutes = array("0" => "00", "15" => "15", "30" => "30", "45" => "45"); $h .= selectInputHTML('minute', $minutes, 'deploymin', "onChange='setStartLater();'", $timeArr[1]); $h .= selectInputHTML('meridian', array("am" => "a.m.", "pm" => "p.m."), 'deploymeridian', "onChange='setStartLater();'", $timeArr[2]); $h .= "\n"; # any start $h .= "\n"; $h .= "
\n"; $h .= "
\n"; $h .= "
\n"; $h .= "(" . date('T') . ")

\n"; $h .= "\n"; # ending by duration $h .= "\n"; $h .= "   "; if($openend) { $h .= "\n"; $h .= "\n"; $maxtimes = getUserMaxTimes(); if($imaging && $maxtimes['initial'] < 720) # make sure at least 12 hours available for imaging reservations $maxtimes['initial'] = 720; $lengths = getReservationLengths($maxtimes['initial']); $h .= selectInputHTML('length', $lengths, 'reqlength', "onChange='updateWaitTime(0); setEndDuration(); durationChange();'", 60); $h .= "
\n"; # ending is indefinite $h .= "\n"; if($serveraccess) { $h .= "   "; $h .= "\n"; $h .= "
\n"; } $h .= "
\n"; # ending by date/time $h .= "\n"; $h .= "\n"; $h .= "
\n"; $h .= "
\n"; $h .= "(" . date('T') . ")
\n"; } $h .= "

\n"; $h .= "
\n"; $h .= "

\n"; $h .= "
\n"; # deployprofilediv $h .= "
\n"; $h .= " \n"; $h .= "
\n"; /*$h .= " \n";*/ $h .= dijitButton('newResDlgBtn', _("Create Reservation"), "submitNewReservation();"); $h .= dijitButton('', _("Cancel"), "dijit.byId('newResDlg').hide();"); $h .= "
\n"; $cont = addContinuationsEntry('AJnewRequest', $cdata, SECINDAY); $h .= "\n"; if($serveraccess) { $cont = addContinuationsEntry('AJfetchRouterDNS'); $h .= "\n"; } $cont = addContinuationsEntry('AJupdateWaitTime', $cdata); $h .= "\n"; $h .= "
\n"; return $h; } //////////////////////////////////////////////////////////////////////////////// /// /// \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; $imageid = processInputVar('imageid', ARG_NUMERIC); $baseaccess = getContinuationVar('baseaccess'); $imagingaccess = getContinuationVar('imagingaccess'); $serveraccess = getContinuationVar('serveraccess'); $openend = getContinuationVar('openend'); $imaging = getContinuationVar('imaging'); $type = processInputVar('type', ARG_STRING); $desconly = processInputVar('desconly', ARG_NUMERIC, 0); # process imageid $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $validImageids = array_keys($resources['image']); if($type == 'server') { $extraimages = getServerProfileImages($user['id']); $validImageids = array_merge($validImageids, array_keys($extraimages)); } if(! in_array($imageid, $validImageids)) return; if($desconly) { printImageDescription($imageid); return; } # process type if(! preg_match('/^basic|imaging|server$/', $type)) return; if(($type == 'basic' && ! $baseaccess) || ($type == 'imaging' && ! $imagingaccess) || ($type == 'server' && ! $serveraccess)) return; # process start $start = processInputVar('start', ARG_NUMERIC); $now = time(); if($start == 0) { $start = unixFloor15($now); } else { if($start < $now) $start = unixFloor15($now); if($type == 'basic' || $type == 'imaging') { # compute maxstart based on 11:45 pm on start day $tmp = $now + DAYSAHEAD * SECINDAY; $maxstart = mktime(23, 45, 0, date('n', $tmp), date('j', $tmp), date('Y', $tmp)); if($start > $maxstart) return; } } # process length/end $ending = processInputVar('ending', ARG_STRING); if(! preg_match('/^indefinite|endat|duration$/', $ending)) return; if($ending == 'indefinite') { $end = datetimeToUnix('2038-01-01 00:00:00'); } elseif($ending == 'endat') { $end = processInputVar('end', ARG_NUMERIC); } elseif($ending == 'duration') { $length = processInputVar('duration', ARG_NUMERIC); $maxinitial = getContinuationVar('maxinitial'); if(($type == 'basic' || $type == 'imaging') && ! $openend) { if($length > $maxinitial) $length = $maxinitial; } $end = $start + $length * 60; } if($end < $start) { print "dojo.byId('deployerr').innerHTML = '"; print _("The end time must be later than the start time.") . "';"; print "dojo.removeClass('deployerr', 'hidden');"; return; } if($start < $now) $end += 15 * 60; # process fixed IP $fixedIP = processInputVar('fixedIP', ARG_STRING, ''); if($type == 'server' && $fixedIP != '') { if(! validateIPv4addr($fixedIP)) { print "dojo.byId('deployerr').innerHTML = '"; print _("Invalid IP address specified.") . "';"; print "dojo.removeClass('deployerr', 'hidden');"; return; } $mappedmns = getMnsFromImage($imageid); $mnnets = checkAvailableNetworks($fixedIP); $intersect = array_intersect($mappedmns, $mnnets); if(empty($intersect)) { print "dojo.byId('deployerr').innerHTML = '"; print _("There are no management nodes that can deploy the selected image with the specified IP address.") . "';"; print "dojo.removeClass('deployerr', 'hidden');"; return; } } printImageDescription($imageid); $images = getImages(); $imagerevisionid = getProductionRevisionid($imageid); # TODO initially, this is a hack where we munge the datastructure # finishconfigs /*if($type == 'server') { $tmp = getConfigClusters($imageid, 1); if(count($tmp)) { $subimages = array(); foreach($tmp as $cluster) { for($i = 0; $i < $cluster['maxinstance']; $i++) $subimages[] = $cluster['childimageid']; } $images[$imageid]['subimages'] = $subimages; if($images[$imageid]['imagemetaid'] == NULL) $images[$imageid]['imagemetaid'] = 1; } elseif($images[$imageid]['imagemetaid'] != NULL && count($images[$imageid]['subimages'])) { $images[$imageid]['subimages'] = array(); } }*/ # check for exceeding max overlaps $max = getMaxOverlap($user['id']); if(checkOverlap($start, $end, $max)) { print "dojo.byId('deployerr').innerHTML = '"; print _("The selected time overlaps with another reservation you have."); print "
"; if($max == 0) print _("You cannot have any overlapping reservations."); else printf(_("You can have up to %d overlapping reservations."), $max); print "'; dojo.removeClass('deployerr', 'hidden');"; return; } $rc = isAvailable($images, $imageid, $imagerevisionid, $start, $end, 0, 0, 0, 0, $imaging, $fixedIP); if($rc < 1) { $cdata = array('now' => 0, 'start' => $start, 'end' => $end, 'server' => 0, 'imageid' => $imageid); if($start < $now) $cdata['now'] = 1; $cont = addContinuationsEntry('AJshowRequestSuggestedTimes', $cdata); if(array_key_exists('subimages', $images[$imageid]) && count($images[$imageid]['subimages'])) { print "dojo.byId('suggestcont').value = 'cluster';"; print "dijit.byId('newResDlgBtn').set('disabled', true);"; } else print "dojo.byId('suggestcont').value = '$cont';"; print "if(dijit.byId('newResDlgBtn')) {"; print "if(dijit.byId('newResDlgBtn').get('label') != _('View Available Times')) "; print "resbtntxt = dijit.byId('newResDlgBtn').get('label'); "; print "dijit.byId('newResDlgBtn').set('label', _('View Available Times'));"; print "}"; } if($rc < 1) { print "dojo.removeClass('deployerr', 'hidden');"; print "showSuggestedTimes();"; print "dojo.byId('deployerr').innerHTML = '"; } else { print "dojo.removeClass('waittime', 'hidden');"; print "dojo.addClass('deployerr', 'hidden');"; print "dojo.byId('waittime').innerHTML = '"; } if($rc == -2) print _("Selection not currently available due to scheduled system downtime for maintenance"); elseif($rc == -3) print _("IP address not available for selected time"); elseif($rc == -4) print _("IP address not available"); elseif($rc < 1) if(array_key_exists('subimages', $images[$imageid]) && count($images[$imageid]['subimages'])) print _("Selection not currently available. Times cannot be suggested for cluster reservations."); else print _("Selection not currently available"); elseif(array_key_exists(0, $requestInfo['loaded']) && $requestInfo['loaded'][0]) { print _("Estimated load time:"); if($start < $now) { print " < "; print _("1 minute"); } else print ' ' . _("Ready at start of reservation"); } else { print _("Estimated load time:"); $loadtime = getImageLoadEstimate($imageid); if($start < $now) { $loadtime = (int)($loadtime / 60); print " < "; if($loadtime == 0) print $images[$imageid]['reloadtime']; else printf("%2.0f", $loadtime + 1); print " " . _("minutes"); } elseif($loadtime != 0 && ($start - $now < $loadtime)) print ' ' . _("Ready at") . date(" g:i a", ($now + $loadtime)); else print ' ' . _("Ready at start of reservation"); } print "';"; if($requestInfo['ipwarning']) { print "dojo.removeClass('deployerr', 'hidden');"; print "dojo.byId('deployerr').innerHTML = '"; $h = _("WARNING: Current conflict with specified IP address. If the conflict is not resolved by the start of your reservation, the reservation will fail."); print preg_replace("/(.{1,68}([ ]|$))/", '\1
', $h); print "
';"; } if($rc > 0) print "resetDeployBtnLabel();"; print "resizeRecenterDijitDialog('newResDlg');"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn printImageDescription($imageid) /// /// \param $imageid - id of image /// /// \brief prints the image description /// //////////////////////////////////////////////////////////////////////////////// function printImageDescription($imageid) { $imagenotes = getImageNotes($imageid); if(! preg_match('/^\s*$/', $imagenotes['description'])) { $desc = preg_replace("/\n/", '
', $imagenotes['description']); $desc = preg_replace("/\r/", '', $desc); $desc = preg_replace("/'/", ''', $desc); $desc = preg_replace("/(.{1,60}([ \n]|$))/", '\1
', $desc); print "dojo.byId('imgdesc').innerHTML = '"; print _("Image Description") . ":
"; print "$desc
'; "; } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJshowRequestSuggestedTimes() /// /// \brief builds html to display list of available times the selected image /// can be used /// //////////////////////////////////////////////////////////////////////////////// function AJshowRequestSuggestedTimes() { global $user; # TODO remove slots with overlapping IP address $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)) { $h = _("There are no available times that the selected image can be used."); $data['html'] = preg_replace("/(.{1,33}([ \n]|$))/", '\1
', $h) . "
"; $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) { $h = _('This reservation can no longer be extended due to a reservation immediately following yours.'); $data['html'] = preg_replace("/(.{1,50}([ \n]|$))/", '\1
', $h) . "
"; $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 AJconfigSystem() /// /// \brief generates data for setting up configs for server reservation /// //////////////////////////////////////////////////////////////////////////////// function AJconfigSystem() { $imageid = processInputVar('imageid', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin", "imageCheckOut")); $validImageids = array_keys($resources['image']); if(! in_array($imageid, $validImageids)) { sendJSON(array('status' => 'noaccess')); return; } $configs = getMappedConfigs($imageid); $configs = array_values($configs); $configvars = getImageConfigVariables($configs); $configvars = array_values($configvars); $data = array('status' => 'success', 'configs' => $configs, 'variables' => $configvars, 'cluster' => 0); $subs = getConfigClusters($imageid); if(! empty($subs)) { $data['cluster'] = 1; $data['subimages'] = $subs; } sendJSON($data); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJnewRequest() /// /// \brief handles submitting a new reservation /// //////////////////////////////////////////////////////////////////////////////// function AJnewRequest() { global $user, $remoteIP; $data = processRequestInput(); #$data['err'] = 1; #$data['errmsg'] = 'none'; if($data['err']) { sendJSON($data); return; } if($data['start'] == 0) { $nowfuture = 'now'; $startts = unixFloor15(); if($data['ending'] == 'duration') { $endts = $startts + ($data['duration'] * 60); $nowArr = getdate(); if(($nowArr['minutes'] % 15) != 0) $endts += 900; } } else { $nowfuture = 'future'; $startts = $data['start']; if($data['ending'] == 'duration') $endts = $startts + ($data['duration'] * 60); } if($data['ending'] == 'indefinite') $endts = datetimeToUnix('2038-01-01 00:00:00'); elseif($data['ending'] == 'endat') $endts = $data['end']; $images = getImages(); # TODO initially, this is a hack where we munge the datastructure # finishconfigs /*if($data['type'] == 'server') { $tmp = getConfigClusters($data['imageid'], 1); if(count($tmp)) { $subimages = array(); foreach($tmp as $cluster) { for($i = 0; $i < $cluster['maxinstance']; $i++) $subimages[] = $cluster['childimageid']; } $images[$data['imageid']]['subimages'] = $subimages; if($images[$data['imageid']]['imagemetaid'] == NULL) $images[$data['imageid']]['imagemetaid'] = 1; } elseif($images[$data['imageid']]['imagemetaid'] != NULL && count($images[$data['imageid']]['subimages'])) { $images[$data['imageid']]['subimages'] = array(); } }*/ # check for exceeding max overlaps $max = getMaxOverlap($user['id']); if(checkOverlap($startts, $endts, $max)) { print "dojo.byId('deployerr').innerHTML = '"; print _("The selected time overlaps with another reservation you have."); print "
"; if($max == 0) print _("You cannot have any overlapping reservations."); else printf(_("You can have up to %d overlapping reservations."), $max); print "'; dojo.removeClass('deployerr', 'hidden');"; return; } $imaging = 0; if($data['type'] == 'imaging') $imaging = 1; $availablerc = isAvailable($images, $data['imageid'], $data['revisionids'], $startts, $endts, 1, 0, 0, 0, $imaging, $data['ipaddr'], $data['macaddr']); if($availablerc == -4) { $msg = _("The IP address you specified is assigned to another VCL node and cannot be used at this time. Submitting a time in the future may allow you to make the reservation, but if the IP remains assigned to the other node, the reservation will fail at deploy time."); $data = array('err' => 1, 'errmsg' => $msg); sendJSON($data); return; } elseif($availablerc == -3) { $msg = _("The IP or MAC address you specified overlaps with another reservation using the same IP or MAC address you specified. Please use a different IP or MAC or select a different time to deploy the server."); $data = array('err' => 1, 'errmsg' => $msg); sendJSON($data); return; } elseif($availablerc == -2) { $msg = _("The time you requested overlaps with a maintenance window."); $data = array('err' => 1, 'errmsg' => $msg); sendJSON($data); return; } elseif($availablerc == -1) { cleanSemaphore(); $msg = _("You have requested an environment that is limited in the number of concurrent reservations that can be made. No further reservations for the environment can be made for the time you have selected."); $data = array('err' => 1, 'errmsg' => $msg); sendJSON($data); return; } elseif($availablerc == 0) { cleanSemaphore(); $data = array('err' => 2); sendJSON($data); return; } $requestid = addRequest($imaging, $data['revisionids'], (1 - $data['nousercheck'])); if($data['type'] == 'server') { if($data['ipaddr'] != '') { # save additional network info in variable table $allnets = getVariable('fixedIPavailnetworks', array()); $key = long2ip($data['network']) . "/{$data['netmask']}"; $allnets[$key] = array('router' => $data['router'], 'dns' => $data['dnsArr']); setVariable('fixedIPavailnetworks', $allnets, 'yaml'); } $query = "UPDATE reservation " . "SET remoteIP = '$remoteIP' " . "WHERE requestid = $requestid"; doQuery($query); $fields = array('requestid', 'serverprofileid'); $values = array($requestid, $data['profileid']); if($data['name'] == '') { $fields[] = 'name'; $name = $images[$data['imageid']]['prettyname']; $values[] = "'$name'"; } else { $fields[] = 'name'; $name = mysql_real_escape_string($data['name']); $values[] = "'$name'"; } if($data['ipaddr'] != '') { $fields[] = 'fixedIP'; $values[] = "'{$data['ipaddr']}'"; } if($data['macaddr'] != '') { $fields[] = 'fixedMAC'; $values[] = "'{$data['macaddr']}'"; } if($data['admingroupid'] != 0) { $fields[] = 'admingroupid'; $values[] = $data['admingroupid']; } if($data['logingroupid'] != 0) { $fields[] = 'logingroupid'; $values[] = $data['logingroupid']; } if($data['monitored'] != 0) { $fields[] = 'monitored'; $values[] = 1; } $allfields = implode(',', $fields); $allvalues = implode(',', $values); $query = "INSERT INTO serverrequest ($allfields) VALUES ($allvalues)"; doQuery($query, 101); if($data['ipaddr'] != '') { $srqid = dbLastInsertID(); $var = array('netmask' => $data['netmask'], 'router' => $data['router'], 'dns' => $data['dnsArr']); setVariable("fixedIPsr$srqid", $var, 'yaml'); } # TODO configs //saveRequestConfigs($requestid, $data['imageid'], $data['configs'], $data['configvars']); } $data = array('err' => 0); sendJSON($data); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn saveRequestConfigs($reqid, $imageid, $configs, $vars) /// /// \param $reqid - id of request /// \param $imageid - id of image of reservation /// \param $configs - array of config data /// \param $vars - array of config variable data /// /// \brief creates config entries for reservation /// //////////////////////////////////////////////////////////////////////////////// function saveRequestConfigs($reqid, $imageid, $configs, $vars) { global $user; $query = "SELECT id, " . "imageid " . "FROM reservation " . "WHERE requestid = $reqid " . "ORDER BY id"; $qh = doQuery($query); $resids = array(); while($row = mysql_fetch_assoc($qh)) { if(! array_key_exists($row['imageid'], $resids)) $resids[$row['imageid']] = array(); $resids[$row['imageid']][] = $row['id']; } $bysubimage = array(0 => array('imageid' => $imageid)); foreach($configs as $id => $cfg) { if(preg_match('|^([0-9]+)/([0-9]+)-([0-9]+)$|', $id, $keys)) { $bysubimage[$keys[1]][$keys[2]] = $cfg['configid']; $bysubimage[$keys[3]]['imageid'] = $cfg['imageid']; } elseif(preg_match('|^([0-9]+)/([-0-9]+)$|', $id, $keys)) { $bysubimage[$keys[1]][$keys[2]] = $cfg['configid']; } } $qbase = "INSERT INTO configinstance " . "(reservationid, " . "configid, " . "configmapid, " . "configinstancestatusid) " . "VALUES "; $qbase2 = "INSERT INTO configinstancevariable " . "(configinstanceid, " . "configvariableid, " . "value) " . "VALUES "; $qbase3 = "INSERT INTO configmap " . "(configid, " . "configmaptypeid, " . "subid, " . "affiliationid, " . "disabled, " . "configstageid) " . "VALUES "; $residmaps = array(); foreach($bysubimage as $cfgsubimgid => $data) { $resid = array_pop($resids[$data['imageid']]); unset($data['imageid']); foreach($data as $mapid => $cfgid) { $insmapid = $mapid; if($mapid < 0) { $query = $qbase3; $query .= "($cfgid, "; $query .= "(SELECT id FROM configmaptype WHERE name = 'reservation'), "; $query .= "$resid, {$user['affiliationid']}, 0, "; $query .= $configs["$cfgsubimgid/$mapid"]['configstageid'] . ")"; doQuery($query); $insmapid = dbLastInsertID(); } $query = $qbase; $query .= "($resid, $cfgid, $insmapid, 1)"; doQuery($query); $instid = dbLastInsertID(); if(array_key_exists("$cfgsubimgid/$mapid", $vars)) { $sets = array(); foreach($vars["$cfgsubimgid/$mapid"] as $varid => $varval) { $_val = mysql_real_escape_string($varval['value']); $sets[] = "($instid, $varid, '$_val')"; } $query = $qbase2 . implode(',', $sets); doQuery($query); } } } } //////////////////////////////////////////////////////////////////////////////// /// /// \fn newReservationConfigHTML() /// /// \return html /// /// \brief generates HTML for setting up configs for a server reservation /// //////////////////////////////////////////////////////////////////////////////// function newReservationConfigHTML() { $h = ''; $h = "
\n"; $h .= "
\n"; # cluster tree $h .= "
\n"; $h .= "Cluster:
\n"; $h .= "(select an image to configure any associated configs)
\n"; $h .= "
\n"; # TODO edit CSS to set icons for tree nodes $h .= "\n"; $h .= "
\n"; $h .= "
\n"; $h .= "
\n"; # clusterdiv # configs $h .= "Add config for this reservation:
\n"; $h .= resourceStore('config', 1, 'configdetailstore', 1); $h .= "\n"; $h .= "
\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; # end list of configs $h .= "\n"; # end config variables $h .= "\n"; $h .= "
\n"; # list of configs $h .= "Configs mapped to system:
\n"; $h .= "
\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "\n"; $h .= "
\n"; $h .= "
\n"; $h .= "
\n"; # config variables $h .= _("Type:") . "
\n"; $h .= _("Apply this config:") . "
\n"; $h .= "
\n"; $h .= "
\n"; $h .= " " . _("View Config Data") . "\n"; $h .= "
\n"; $h .= "

\n"; # variables $h .= "
\n"; $h .= _("Config variables:") . "
\n"; # select $h .= "
\n"; # key $h .= _("Key:") . "
\n"; $h .= _("Value:"); # bool $h .= "\n"; $h .= selectInputAutoDijitHTML('', array('true', 'false'), 'configvaluebool', 'onChange="saveSelectedConfigVar();"'); $h .= "\n"; # int $h .= ""; $h .= "\n"; # float $h .= ""; $h .= "\n"; # string $h .= ""; $h .= "\n"; # text $h .= ""; $h .= "
\n"; $h .= "
\n"; $h .= _("Required:") . "
\n"; $h .= "
\n"; # configvariablediv $h .= "
\n"; # configdatadiv $h .= "
\n"; $h .= "
\n"; $h .= "
\n"; $h .= " \n"; $h .= "
\n"; $h .= "
\n"; return $h; } //////////////////////////////////////////////////////////////////////////////// /// /// \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. You can request a new reservation or select another one that is available."); return $text; } if($request['currstateid'] == 11 || ($request['currstateid'] == 12 && $request['laststateid'] == 11)) return "
" . _("The selected reservation has timed out and is no longer available.") . ""; 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'] == 24) || /*($request['currstateid'] == 14 && $request['laststateid'] == 27) ||*/ ($request['currstateid'] == 14 && $request['laststateid'] == 28)) { $noinfo = _("No detailed loading information is available for this 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 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) || $request['stateid'] == 11 || $request['stateid'] == 12 || ($request['stateid'] == 14 && ($request['laststateid'] == 11 || $request['laststateid'] == 12))) { sendJSON(array('status' => 'resgone')); return; } $unixstart = datetimeToUnix($request["start"]); $unixend = datetimeToUnix($request["end"]); $duration = $unixend - $unixstart; $now = time(); $maxtimes = getUserMaxTimes(); $groupid = getUserGroupID('Specify End Time', 1); $members = getUserGroupMembers($groupid); if(array_key_exists($user['id'], $members) || $request['serverrequest']) $openend = 1; else $openend = 0; $groupid = getUserGroupID('Allow No User Check', 1); $members = getUserGroupMembers($groupid); if(array_key_exists($user['id'], $members)) $nousercheck = 1; else $nousercheck = 0; $h = ''; # determine the current total length of the reservation $reslen = ($unixend - unixFloor15($unixstart)) / 60; $timeval = getdate($unixstart); if(($timeval["minutes"] % 15) != 0) $reslen -= 15; $cdata = array('requestid' => $requestid, 'openend' => $openend, 'nousercheck' => $nousercheck, 'modifystart' => 0, 'allowindefiniteend' => 0); # generate HTML if($request['serverrequest']) { if(empty($request['servername'])) $request['servername'] = $request['reservations'][0]['prettyimage']; $h .= _("Name") . ":
"; if($user['showallgroups']) $groups = getUserGroups(); else $groups = getUserGroups(0, $user['affiliationid']); $h .= _("Admin User Group") . ": "; $disabled = ''; if($request['stateid'] == 14 && $request['laststateid'] == 24) $disabled = "disabled=\"true\""; 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 .= "

"; } elseif($nousercheck) { $extra = array(); if($request['checkuser'] == 0) $extra['checked'] = 'checked'; $h .= labeledFormItem('newnousercheck', _('Disable timeout for disconnected users'), 'check', '', '', '1', '', '', $extra); $h .= "
\n"; } // 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 = sprintf(_("You are only allowed to extend your reservation such that it has a total length of %s. "), minToHourMin($maxcheck)); $h .=_("This reservation already meets that length. Therefore, you are not allowed to extend your reservation any further."); $h = preg_replace("/(.{1,60}([ \n]|$))/", '\1
', $h) . "
"; sendJSON(array('status' => 'nomodify', 'html' => $h)); return; } // if started, only allow end to be modified # check for following reservations $timeToNext = timeToNextReservation($request); # check for 30 minutes because need 15 minute buffer and min can # extend by is 15 min if($timeToNext < 30) { $movedall = 1; $lockedall = 1; if(count($request['reservations']) > 1) { # get semaphore on each existing node in cluster so that nothing # can get moved to the nodes during this process $checkend = unixToDatetime($unixend + 900); foreach($request["reservations"] as $res) { if(! retryGetSemaphore(1, 1, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) { $lockedall = 0; break; } } } if($lockedall) { foreach($request["reservations"] as $res) { if(! moveReservationsOffComputer($res["computerid"], 1)) { $movedall = 0; break; } } } cleanSemaphore(); if(! $request['serverrequest'] && (! $movedall || ! $lockedall)) { $msg = _("The computer you are using has another reservation immediately following yours. Therefore, you cannot extend your reservation because it would overlap with the next one."); $h = preg_replace("/(.{1,60}( |$))/", '\1
', $msg) . "
"; 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)) { $m = _("You can extend this reservation by a selected amount or change the end time to a specified date and time."); $h .= preg_replace("/(.{1,55}([ \n]|$))/", '\1
', $m) . "
"; } else $h .= _("Modify the end time for this reservation:") . "

"; } else { if($request['forimaging'] && $maxtimes['total'] < 720) $maxcheck = 720; else $maxcheck = $maxtimes['total']; $m = sprintf(_("You can extend this reservation by up to %s but not exceeding %s for your total reservation time."), minToHourMin($maxtimes['extend']), minToHourMin($maxcheck)); $h .= preg_replace("/(.{1,60}([ \n]|$))/", '\1
', $m) . "
"; } } elseif(! $request['serverrequest']) { $m = sprintf(_("The computer you are using has another reservation following yours. Therefore, you can only extend this reservation for another %s."), prettyLength($timeToNext)); $h .= preg_replace("/(.{1,60}( |$))/", '\1
', $m); } # extend by drop down # extend by specifying end time if $openend $noindefinite = 0; if($openend) { if($request['serverrequest']) { $cdata['allowindefiniteend'] = 1; $endchecked = 0; if($request['end'] == '2038-01-01 00:00:00') { $h .= ""; $h .= ""; $h .= "
"; } else { $h .= ""; $h .= ""; $h .= "
"; $endchecked = 1; } $h .= "