Manage Images\n"; print "
\n"; if($imgAdminCnt) { $cont = addContinuationsEntry('viewImages'); print "Edit "; print "Image Profiles
\n"; print "Include details
\n"; } if($imgGroupCnt) { $cont = addContinuationsEntry('viewImageGrouping'); print "Edit "; print "Image Grouping
\n"; if($compGroupCnt) { $cont = addContinuationsEntry('viewImageMapping'); print "Edit "; print "Image Mapping
\n"; } } if($imgCnt) { $cont = addContinuationsEntry('newRequest', array('imaging' => 1)); print "Create /"; print " Update an Image
\n"; } if($imgAdminCnt || $imgGroupCnt || $imgCnt) print "
\n"; else print "You don't have access to manage any images.
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewImages() /// /// \brief prints a page to view image information /// //////////////////////////////////////////////////////////////////////////////// function viewImages() { global $viewmode, $user, $mode; $showdeleted = getContinuationVar("showdeleted", 0); $deleted = getContinuationVar("deleted"); $details = processInputVar("details", ARG_NUMERIC); if($showdeleted) { $images = getImages(1); $resources = getUserResources(array("imageAdmin"), array("administer"), 0, 1); } else { $images = getImages(); $resources = getUserResources(array("imageAdmin"), array("administer")); } $userImageIDs = array_keys($resources["image"]); $platforms = getPlatforms(); $oslist = getOSList(); print "

Image Profiles

\n"; if($mode == "submitDeleteImage") { if($deleted) { print "Image successfully undeleted"; print "

\n"; } else { print "Image successfully set to deleted "; print "state

\n"; } } elseif($mode == "submitEditImage") { print "Image successfully updated"; print "

\n"; } print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($details) { print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } if($showdeleted) { print " \n"; } print " \n"; foreach(array_keys($images) as $id) { if(! in_array($id, $userImageIDs)) continue; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($details) { print " \n"; print " \n"; print " \n"; print " \n"; if($images[$id]['maxconcurrent'] == '') print " \n"; else print " \n"; } if($showdeleted) { print " \n"; } print " \n"; } print "

Name
OwnerPlatform
OS
Estimated Reload Time (min)Minimum RAM (MB)Minimum Num of ProcessorsMinimum Processor Speed (MHz)Minimum Network Speed (Mbps)Maximum Concurrent UsageDeleted
\n"; print "
\n"; $cdata = array('imageid' => $id); $cont = addContinuationsEntry('submitImageButton', $cdata); print " \n"; if($showdeleted && $images[$id]["deleted"] == 1) { print " \n"; } else { print " \n"; print "
\n"; } print " \n"; print "
\n"; print "
" . $images[$id]["prettyname"] . "" . $images[$id]["owner"] . "" . $images[$id]["platform"] . "" . $oslist[$images[$id]["osid"]]["prettyname"] . "" . $images[$id]["reloadtime"] . "" . $images[$id]["minram"] . "" . $images[$id]["minprocnumber"] . "" . $images[$id]["minprocspeed"] . "" . $images[$id]["minnetwork"] . "N/A" . $images[$id]["maxconcurrent"] . "" . $images[$id]["deleted"] . "
\n"; print "
\n"; if($showdeleted) { $cdata = array('showdeleted' => 0); print "\n"; } else { $cdata = array('showdeleted' => 1); print "\n"; } $cont = addContinuationsEntry('viewImages', $cdata); print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewImageGrouping() /// /// \brief prints a page to view and modify image grouping /// //////////////////////////////////////////////////////////////////////////////// function viewImageGrouping() { global $mode; $resources = getUserResources(array("imageAdmin"), array("manageGroup")); if(! count($resources["image"])) { print "

Image Grouping

\n"; print "You don't have access to modify any image groups.
\n"; return; } if($mode == 'submitImageGroups') $gridSelected = "selected=\"true\""; else $gridSelected = ""; print "

Image Grouping

\n"; print "
\n"; # by image tab print "
\n"; print "Select an image and click \"Get Groups\" to see all of the groups "; print "it is in. Then,
select a group it is in and click the Remove "; print "button to remove it from that group,
or select a group it is not "; print "in and click the Add button to add it to that group.

\n"; print "Image:\n"; print "\n"; print "\n"; # select for groups image is in print "\n"; # transfer buttons print "\n"; # select for groups image is not in print "\n"; print "
\n"; print "Groups is in:
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Groups is not in:
\n"; print "\n"; print "
\n"; print "
\n"; # by group tab print "
\n"; print "Select a group and click \"Get Images\" to see all of the images "; print "in it. Then,
select an image in it and click the Remove "; print "button to remove it from the group,
or select an image that is not "; print "in it and click the Add button to add it to the group.

\n"; print "Group:\n"; print "\n"; print "\n"; # select for images in group print "\n"; # transfer buttons print "\n"; # images not in group select print "\n"; print "
\n"; print "Images in :
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Images not in :
\n"; print "\n"; print "
\n"; print "
\n"; # grid tab $cont = addContinuationsEntry('imageGroupingGrid'); $loadingmsg = "Loading page (this may take a really long time)"; print "\n"; print " Checkbox Grid\n"; print "
\n"; # end of main tab container $cont = addContinuationsEntry('jsonImageGroupingImages'); print "\n"; $cont = addContinuationsEntry('jsonImageGroupingGroups'); print "\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn imageGroupingGrid() /// /// \brief prints a page to view and modify image grouping /// //////////////////////////////////////////////////////////////////////////////// function imageGroupingGrid() { global $mode; $imagemembership = getResourceGroupMemberships("image"); $resources = getUserResources(array("imageAdmin"), array("manageGroup")); $tmp = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $imagegroups = $tmp["image"]; uasort($imagegroups, "sortKeepIndex"); uasort($resources["image"], "sortKeepIndex"); print "
\n"; print "\n"; print " \n"; foreach(array_keys($imagegroups) as $id) { print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($imagegroups as $id => $group) { print " \n"; } print " \n"; $count = 1; foreach($resources["image"] as $imageid => $image) { if($image == "No Image") continue; if($count % 8 == 0) { print " \n"; print " \n"; foreach($imagegroups as $id => $group) { print " \n"; } print " \n"; } print " \n"; print " \n"; foreach(array_keys($imagegroups) as $groupid) { $name = "imagegroup[" . $imageid . ":" . $groupid . "]"; if(array_key_exists($imageid, $imagemembership["image"]) && in_array($groupid, $imagemembership["image"][$imageid])) { $checked = "checked"; } else { $checked = ""; } print " \n"; } print " \n"; $count++; } print "
ImageGroups
$group
$group
$image\n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('submitImageGroups', array(), SECINWEEK, 1, 0, 1); print "\n"; print "\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewImageMapping() /// /// \brief prints a page to modify image group to computer group mappings /// //////////////////////////////////////////////////////////////////////////////// function viewImageMapping() { global $mode; $tmp = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $imagegroups = $tmp["image"]; uasort($imagegroups, "sortKeepIndex"); $imagecompmapping = getResourceMapping("image", "computer"); $resources = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $resources["computer"]; uasort($compgroups, "sortKeepIndex"); if(! count($imagegroups) || ! count($compgroups)) { print "

Image Group to Computer Group Mapping

\n"; print "You don't have access to manage any image group to computer "; print "group mappings.
\n"; return; } if($mode == 'submitImageMapping') $gridSelected = "selected=\"true\""; else $gridSelected = ""; print "

Image Group to Computer Group Mapping

\n"; print "
\n"; # by image group print "
\n"; print "Select an image group and click \"Get Computer Groups\" to see all "; print "of the computer groups it maps to. Then,
select a computer group "; print "it maps to and click the Remove button to unmap it from that group, "; print "or select a
computer group it does not map to and click the Add "; print "button to map it to that group.

\n"; print "Image Group:\n"; print "\n"; print "\n"; # select for comp groups image groups maps to print "\n"; # transfer buttons print "\n"; # select for comp groups image groups does not map to print "\n"; print "
\n"; print "Computer groups maps to:
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Computer groups does not map to:
\n"; print "\n"; print "
\n"; print "
\n"; # by computer group tab print "
\n"; print "Select a computer group and click \"Get Images Groups\" to see all "; print "of the image groups it maps to. Then,
select an image group "; print "it maps to and click the Remove button to unmap it from that group, "; print "or select an
image group it does not map to and click the Add "; print "button to map it to that group.

\n"; print "Computer Group:\n"; print "\n"; print "\n"; # select for image groups comp group maps to print "\n"; # transfer buttons print "\n"; # select for image groups comp group does not map to print "\n"; print "
\n"; print "Image groups maps to:
\n"; print "\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "Images groups does not map to:
\n"; print "\n"; print "
\n"; print "
\n"; # grid tab $cont = addContinuationsEntry('imageMappingGrid'); $loadingmsg = "Loading page (this may take a really long time)"; print "\n"; print " Checkbox Grid\n"; print "
\n"; # end of main tab container $cont = addContinuationsEntry('jsonImageMapCompGroups'); print "\n"; $cont = addContinuationsEntry('jsonImageMapImgGroups'); print "\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn imageMappingGrid($imagegroups) /// /// \param $imagegroups - (optional) array of imagegroups as returned by /// getUserResources /// /// \brief prints a page to view and edit image mapping /// //////////////////////////////////////////////////////////////////////////////// function imageMappingGrid() { global $mode; $tmp = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $imagegroups = $tmp["image"]; uasort($imagegroups, "sortKeepIndex"); $imagecompmapping = getResourceMapping("image", "computer"); $resources2 = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $resources2["computer"]; uasort($compgroups, "sortKeepIndex"); if(! count($imagegroups) || ! count($compgroups)) { print "You don't have access to manage any image group to computer group "; print "mappings.
\n"; return; } print "
\n"; print "\n"; print " \n"; foreach(array_keys($compgroups) as $id) { print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; foreach($compgroups as $id => $group) { print " \n"; } print " \n"; $count = 1; foreach($imagegroups as $imgid => $imgname) { if($count % 12 == 0) { print " \n"; print " \n"; foreach($compgroups as $id => $group) { print " \n"; } print " \n"; } print " \n"; print " \n"; foreach($compgroups as $compid => $compname) { $name = "mapping[" . $imgid . ":" . $compid . "]"; if(array_key_exists($imgid, $imagecompmapping) && in_array($compid, $imagecompmapping[$imgid])) { $checked = "checked"; } else $checked = ""; print " \n"; } print " \n"; $count++; } print "
Image GroupComputer Groups
$group
$group
$imgname\n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('submitImageMapping', array(), SECINWEEK, 1, 0, 1); print "\n"; print "\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn startImage() /// /// \brief prints page prompting user if updating existing image or creating a /// new image /// //////////////////////////////////////////////////////////////////////////////// function startImage() { global $user; $requestid = getContinuationVar("requestid"); $data = getRequestInfo($requestid); $disableUpdate = 1; $imageid = ''; foreach($data["reservations"] as $res) { if($res["forcheckout"]) { $imageid = $res["imageid"]; break; } } if(! empty($imageid)) { $imageData = getImages(0, $imageid); if($imageData[$imageid]['ownerid'] == $user['id']) $disableUpdate = 0; } print "

Create / Update an Image

\n"; print "Are you creating a new image from a base image or updating an "; print "existing image?

\n"; print "
\n"; $cdata = array('requestid' => $requestid); $cont = addContinuationsEntry('newImage', $cdata, SECINDAY, 0); print ""; print "
\n"; if($disableUpdate) { print ""; } else { $cdata['nextmode'] = 'updateExistingImageComments'; $cdata['multicall'] = 1; $cont = addContinuationsEntry('imageClickThroughAgreement', $cdata, SECINDAY, 0); print ""; } print "

\n"; print "\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitImageButton /// /// \brief wrapper for confirmDeleteImage, editOrAddImage(0), and /// viewImageDetails /// //////////////////////////////////////////////////////////////////////////////// function submitImageButton() { $submode = processInputVar("submode", ARG_STRING); if($submode == "Edit") editOrAddImage(0); elseif($submode == "Delete" || $submode == "Undelete") confirmDeleteImage(); elseif($submode == "Details") viewImageDetails(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn editOrAddImage($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief prints a form for editing an image /// //////////////////////////////////////////////////////////////////////////////// function editOrAddImage($state) { global $submitErr, $mode, $submode, $user; $images = getImages(); $platforms = getPlatforms(); $oslist = getOSList(); $groups = getUserGroups(0, $user['affiliationid']); $groups = array_reverse($groups, TRUE); $groups[0] = array("name" => "Any"); $groups = array_reverse($groups, TRUE); if($submitErr || $state == 1 || $mode == "submitEditImageButtons") { $data = processImageInput(0); if(get_magic_quotes_gpc()) { $data["description"] = stripslashes($data['description']); $data["usage"] = stripslashes($data['usage']); $data["comments"] = stripslashes($data['comments']); } $data['imageid'] = getContinuationVar('imageid'); if($mode == "newImage") { $requestdata = getRequestInfo($data['requestid']); $imagedata = getImages(0, $requestdata["reservations"][0]["imageid"]); $data["platformid"] = $imagedata[$requestdata["reservations"][0]["imageid"]]["platformid"]; $data["osid"] = $imagedata[$requestdata["reservations"][0]["imageid"]]["osid"]; } } else { $id = getContinuationVar("imageid"); $data = $images[$id]; $data["imageid"] = $id; $tmp = getImageNotes($id); $data['description'] = $tmp['description']; $data['usage'] = $tmp['usage']; } print "
\n"; print "
\n"; if($state) print "

Add Image

\n"; else print "

Edit Image

\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 " \n"; print "
Name:"; printSubmitErr(PRETTYNAMEERR); print "
Owner:"; printSubmitErr(IMGOWNERERR); print "
Platform:\n"; printSelectInput("platformid", $platforms, $data["platformid"]); print "
OS:\n"; printSelectInput("osid", $oslist, $data["osid"]); print "
\n"; print "
\n"; print "Image Description\n"; print "Description of image (required - users will
\nsee this on the "; print "New Reservations page):
\n"; printSubmitErr(IMAGEDESCRIPTIONERR); print "\n"; print "
\n"; print "
\n"; print "Usage Notes\n"; print "Optional notes to the user explaining how to use the image
"; print "(users will see this on the Connect! page):
\n"; print "\n"; print "
\n"; if($state) { print "
\n"; print "Revision Comments\n"; print "Notes for yourself and other admins about how the image "; print "was setup/installed.
\nThese are optional and not visible to end "; print "users.
\n"; print "\n"; print "
\n"; } print "

\n"; print "
(click to "; print "expand)\" open=false style=\"width: 500px\">\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 " "; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " "; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " "; print " \n"; if(! $state) { print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if(array_key_exists("checkuser", $data) && ! $data["checkuser"]) $default = 0; else $default = 1; print " \n"; print " \n"; print " \n"; print " \n"; if(array_key_exists("rootaccess", $data) && ! $data["rootaccess"]) $default = 0; else $default = 1; print " \n"; print " \n"; # finally just limited access so only high level access people see this # because it confused too many people if($user["adminlevel"] == "developer") { print " \n"; print " \n"; print " \n"; print " \n"; } if($state) { if(array_key_exists("sysprep", $data) && ! $data["sysprep"]) $default = 0; else $default = 1; print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print "

Advanced Options - leave default values unless you really know what you are doing

Minimum RAM (MB):"; printSubmitErr(MINRAMERR); print "
Minimum Num of Processors:\n"; $tmpArr = array("1" => "1", "2" => "2", "4" => "4", "8" => "8"); printSelectInput("minprocnumber", $tmpArr, $data["minprocnumber"]); print "
Minimum Processor Speed (MHz):"; printSubmitErr(MINPROCSPEEDERR); print "
Minimum Network Speed (Mbps):\n"; $tmpArr = array("10" => "10", "100" => "100", "1000" => "1000"); printSelectInput("minnetwork", $tmpArr, $data["minnetwork"]); print "
Maximum Concurrent Usage:(leave empty for unlimited)"; printSubmitErr(MAXCONCURRENTERR); print "
Estimated Reload Time (min):"; printSubmitErr(RELOADTIMEERR); print "
Available for checkout:\n"; $yesno = array(1 => "Yes", 0 => "No"); printSelectInput("forcheckout", $yesno, $data["forcheckout"]); print "
Check for logged in user:\n"; printSelectInput("checkuser", $yesno, $default); print "
Users have administrative access:\n"; printSelectInput("rootaccess", $yesno, $default); print "
User group allowed to log in:
\n"; print " (This does not grant permission to
\n"; print "make a reservation for the image)
\n"; if(! empty($data["usergroupid"])) { $default = $data["usergroupid"]; if(! array_key_exists($default, $groups)) { if($submitErr || $mode == 'submitEditImageButtons') $groups[$data['usergroupid']] = array('name' => $images[$data['imageid']]['usergroup']); else $groups[$data['usergroupid']] = array('name' => $data['usergroup']); uasort($groups, 'sortKeepIndex'); } } else $default = 0; printSelectInput("usergroupid", $groups, $default); print "
Use sysprep:\n"; printSelectInput("sysprep", $yesno, $default); print "

\n"; if(! $state) { $cont = addContinuationsEntry('subimageDialogContent', array('imageid' => $data['imageid'])); print "
"; print " Manage Subimages\n"; $url = BASEURL . SCRIPT . "?continuation=$cont"; print "
\n"; print "
\n"; } print "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; if($state) { $cdata = array('requestid' => $data['requestid'], 'imageid' => $data['imageid']); $cont = addContinuationsEntry('submitEditImageButtons', $cdata, SECINDAY, 0); print " \n"; # confirmAddImage print " \n"; } else { $cdata = array('imageid' => $data['imageid']); $cont = addContinuationsEntry('submitEditImageButtons', $cdata, SECINDAY, 0, 1, 1); print " \n"; # confirmEditImage print " \n"; } print " \n"; print " \n"; print "
\n"; if($state) $cont = addContinuationsEntry('viewRequests'); else $cont = addContinuationsEntry('viewImages'); print " \n"; print " \n"; print "
\n"; print "
\n"; if($state) return; print "
\n"; print getRevisionHTML($data['imageid']); print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn getRevisionHTML($imageid) /// /// \param $imageid - id of an image /// /// \return string of HTML data /// /// \brief builds HTML table for in place editing of image revision data /// //////////////////////////////////////////////////////////////////////////////// function getRevisionHTML($imageid) { $revisions = getImageRevisions($imageid); $rt = ''; $rt .= "

Revisions of this Image

\n"; $rt .= "
\n"; if(count($revisions) > 1 && isImageBlockTimeActive($imageid)) { $rt .= "WARNING: This image is part of an active "; $rt .= "block allocation. Changing the production revision of the image "; $rt .= "at this time will result in new reservations under the block "; $rt .= "allocation to have full reload times instead of a < 1 minutes "; $rt .= "wait.

\n"; } $rt .= "\n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; $rt .= " \n"; foreach($revisions AS $rev) { $rt .= " \n"; $rt .= " \n"; } $cdata = array('imageid' => $imageid, 'revisionid' => $rev['id']); $cont = addContinuationsEntry('AJupdateRevisionComments', $cdata); $rt .= " \n"; $rt .= " \n"; } $rt .= "
RevisionCreatorCreatedIn ProductionComments (click to edit)
$imageid, 'revisionid' => $rev['id']); $cont = addContinuationsEntry('AJupdateRevisionProduction', $cdata); if($rev['production']) { $rt .= " \n"; $rt .= " \n"; $rt .= " {$rev['comments']}
\n"; $rt .= "
\n"; $keys = array_keys($revisions); $cdata = array('revids' => $keys, 'imageid' => $imageid); $cont = addContinuationsEntry('AJdeleteRevisions', $cdata); $ids = implode(',', $keys); $rt .= "\n"; $rt .= "
\n"; $rt .= "
\n"; return $rt; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn subimageDialogContent() /// /// \brief prints content to fill in the dojo dialog for managing subimages /// //////////////////////////////////////////////////////////////////////////////// function subimageDialogContent() { $imageid = getContinuationVar('imageid'); $images = getImages(0); $image = $images[$imageid]; $resources = getUserResources(array("imageAdmin")); if(empty($resources['image'])) { print "You do not have access to add any subimages to this image."; return; } $content = "

Add New Subimage

"; $content .= ""; $content .= "
"; $content .= "

Current Subimages

"; $subimgcnt = 0; if(array_key_exists("subimages", $image) && count($image["subimages"])) { $subimages = array(); foreach($image["subimages"] as $imgid) $subimages[] = array('id' => $imgid, 'name' => $images[$imgid]['prettyname']); uasort($subimages, "sortKeepIndex"); $content .= ""; $image['subimages'] = array(); $content .= ""; } $content .= "
"; $content .= "total subimages: $subimgcnt
"; $content .= "
"; $adminimages = getUserResources(array("imageAdmin"), array("administer")); $adminids = array_keys($adminimages["image"]); $data = array('imageid' => $imageid, 'adminids' => $adminids, 'imagemetaid' => $image['imagemetaid'], 'userimages' => $resources['image'], 'subimages' => $image['subimages']); $cont = addContinuationsEntry('AJaddSubimage', $data, SECINDAY, 1, 0); $content .= ""; $cont = addContinuationsEntry('AJremSubimage', $data, SECINDAY, 1, 0); $content .= ""; $content .= "NOTE: Subimage changes take effect immediately; you do
"; $content .= "not need to click \"Confirm Changes\" to submit them."; print $content; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddSubimage() /// /// \brief adds a subimage to an image /// //////////////////////////////////////////////////////////////////////////////// function AJaddSubimage() { $imageid = getContinuationVar('imageid'); $adminids = getContinuationVar('adminids'); $userimages = getContinuationVar('userimages'); $subimages = getContinuationVar('subimages'); $imagemetaid = getContinuationVar('imagemetaid'); if(! in_array($imageid, $adminids)) { $arr = array('error' => 'noimageaccess', 'msg' => 'You do not have access to manage this image.'); sendJSON($arr); return; } $newid = processInputVar('imageid', ARG_NUMERIC); if(! array_key_exists($newid, $userimages)) { $arr = array('error' => 'nosubimageaccess', 'msg' => 'You do not have access to add this subimage.'); sendJSON($arr); return; } if(is_null($imagemetaid)) { $query = "INSERT INTO imagemeta " . "(subimages) " . "VALUES (1)"; doQuery($query, 101); $imagemetaid = dbLastInsertID(); $query = "UPDATE image " . "SET imagemetaid = $imagemetaid " . "WHERE id = $imageid"; doQuery($query, 101); } elseif(! count($subimages)) { $query = "UPDATE imagemeta " . "SET subimages = 1 " . "WHERE id = $imagemetaid"; doQuery($query, 101); } $query = "INSERT INTO subimages " . "(imagemetaid, " . "imageid) " . "VALUES ($imagemetaid, " . "$newid)"; doQuery($query, 101); $subimages[] = $newid; $data = array('imageid' => $imageid, 'adminids' => $adminids, 'imagemetaid' => $imagemetaid, 'userimages' => $userimages, 'subimages' => $subimages); $addcont = addContinuationsEntry('AJaddSubimage', $data, SECINDAY, 1, 0); $remcont = addContinuationsEntry('AJremSubimage', $data, SECINDAY, 1, 0); $image = getImages(0, $newid); $name = $image[$newid]['prettyname']; $arr = array('newid' => $newid, 'name' => $name, 'addcont' => $addcont, 'remcont' => $remcont); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremSubimage() /// /// \brief removes subimages from an image /// //////////////////////////////////////////////////////////////////////////////// function AJremSubimage() { $imageid = getContinuationVar('imageid'); $adminids = getContinuationVar('adminids'); $userimages = getContinuationVar('userimages'); $subimages = getContinuationVar('subimages'); $imagemetaid = getContinuationVar('imagemetaid'); if(! in_array($imageid, $adminids)) { $arr = array('error' => 'noimageaccess', 'msg' => 'You do not have access to manage this image.'); sendJSON($arr); return; } $remids = processInputVar('imageids', ARG_STRING); $remids = explode(',', $remids); foreach($remids as $id) { if(! is_numeric($id)) { $arr = array('error' => 'invalidinput', 'msg' => 'Non-numeric data was submitted for an image id.'); sendJSON($arr); return; } } if(is_null($imagemetaid)) { $arr = array('error' => 'nullimagemetaid', 'msg' => 'Invalid infomation id database. Contact your system administrator.'); sendJSON($arr); return; } foreach($remids as $id) { $query = "DELETE FROM subimages " . "WHERE imagemetaid = $imagemetaid AND " . "imageid = $id " . "LIMIT 1"; doQuery($query, 101); } # check to see if any subimages left; if not, update imagemeta table $query = "SELECT COUNT(imageid) " . "FROM subimages " . "WHERE imagemetaid = $imagemetaid"; $qh = doQuery($query, 101); $row = mysql_fetch_row($qh); if($row[0] == 0) { $rc = checkClearImageMeta($imagemetaid, $imageid, 'subimages'); if($rc) $imagemetaid = NULL; else { $query = "UPDATE imagemeta SET subimages = 0 WHERE id = $imagemetaid"; doQuery($query, 101); } $subimages = array(); } # rebuild list of subimages else { $query = "SELECT imageid FROM subimages WHERE imagemetaid = $imagemetaid"; $qh = doQuery($query, 101); $subimages = array(); while($row = mysql_fetch_assoc($qh)) $subimages[] = $row['imageid']; } $data = array('imageid' => $imageid, 'adminids' => $adminids, 'imagemetaid' => $imagemetaid, 'userimages' => $userimages, 'subimages' => $subimages); $addcont = addContinuationsEntry('AJaddSubimage', $data, SECINDAY, 1, 0); $remcont = addContinuationsEntry('AJremSubimage', $data, SECINDAY, 1, 0); $arr = array('addcont' => $addcont, 'remcont' => $remcont); sendJSON($arr); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitEditImageButtons() /// /// \brief wrapper for confirmEditOrAddImage, addSubimage, and removeSubimages /// //////////////////////////////////////////////////////////////////////////////// function submitEditImageButtons() { $submode = processInputVar("submode", ARG_STRING); if($submode == "Confirm Image") # confirmAddImage confirmEditOrAddImage(1); elseif($submode == "Confirm Changes") # confirmEditImage confirmEditOrAddImage(0); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmEditOrAddImage($state) /// /// \param $state - 0 for edit, 1 for add /// /// \brief prints a form for confirming changes to an image /// //////////////////////////////////////////////////////////////////////////////// function confirmEditOrAddImage($state) { global $submitErr, $user; $data = processImageInput(1); if($submitErr) { editOrAddImage($state); return; } if(get_magic_quotes_gpc()) { $data['description'] = stripslashes($data['description']); $data['usage'] = stripslashes($data['usage']); $data['comments'] = stripslashes($data['comments']); } $groups = getUserGroups(); $groups[0] = array("name" => "Any"); if(! $state) $images = getImages(); if($state) { $nextmode = "imageClickThroughAgreement"; $title = "Add Image"; $question = "Add the following image?"; } else { $nextmode = "submitEditImage"; $title = "Edit Image"; $question = "Submit changes to the image?"; } $platforms = getPlatforms(); $oslist = getOSList(); print "
\n"; print "
\n"; print "

$title

\n"; print "$question

\n"; print "\n"; if(! $state) { /*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 " \n"; print "
Short Name:" . $data["name"] . "
Name:" . $data["prettyname"] . "
Owner:" . $data["owner"] . "
Platform:" . $platforms[$data["platformid"]] . "
OS:" . $oslist[$data["osid"]]["prettyname"] . "
\n"; print "
Image Description:
\n"; print "{$data['description']}

\n"; print "Usage Notes:
\n"; print "{$data['usage']}

\n"; if($state) { print "Revision Comments:
\n"; print "{$data['comments']}

\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 " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($data['maxconcurrent'] == '') print " \n"; else print " \n"; print " \n"; if(! $state) { print " \n"; print " \n"; print " \n"; print " \n"; } print " \n"; print " \n"; if($data["forcheckout"]) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if($data["checkuser"]) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if($data["rootaccess"]) print " \n"; else print " \n"; print " \n"; if($user["adminlevel"] == "developer" || $user['adminlevel'] == 'full') { print " \n"; print " \n"; $tmp = explode('@', $groups[$data["usergroupid"]]["name"]); if(array_key_exists(1, $tmp) && $tmp[1] != $user['affiliation']) print " \n"; else print " \n"; print " \n"; } if(! $state) { print " \n"; print " \n"; print " \n"; print " \n"; } else { print " \n"; print " \n"; if($data["sysprep"]) print " \n"; else print " \n"; print " \n"; } print " \n"; print " \n"; print " \n"; print "
Advanced Options:

Minimum RAM (MB):" . $data["minram"] . "
Minimum Num of Processors:" . $data["minprocnumber"] . "
Minimum Processor Speed (MHz):" . $data["minprocspeed"] . "
Minimum Network Speed (Mbps):" . $data["minnetwork"] . "
Maximum Concurrent Usage:N/A" . $data["maxconcurrent"] . "
Estimated Reload Time (min):" . $data["reloadtime"] . "
Available for checkout:YesNo
Check for logged in user:YesNo
Users have administrative access:YesNo
User group allowed to log in:" . $groups[$data["usergroupid"]]["name"] . "{$tmp[0]}
Subimages:\n"; if(array_key_exists("subimages", $images[$data["imageid"]]) && count($images[$data["imageid"]]["subimages"])) { foreach($images[$data["imageid"]]["subimages"] as $imgid) { print "{$images[$imgid]["prettyname"]}
\n"; } } else print "None"; print "
Use sysprep:YesNo

\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $data['description'] = mysql_real_escape_string($data['description']); $data['usage'] = mysql_real_escape_string($data['usage']); $data['comments'] = mysql_real_escape_string($data['comments']); if($state) { $data['nextmode'] = 'submitAddImage'; $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0); } else $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, 0); print " \n"; if($state) print " \n"; else print " \n"; print " \n"; print " \n"; print "
\n"; if($state) $cont = addContinuationsEntry('viewRequests'); else $cont = addContinuationsEntry('viewImages'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitEditImage() /// /// \brief submits changes to image and notifies user /// //////////////////////////////////////////////////////////////////////////////// function submitEditImage() { $data = getContinuationVar(); updateImage($data); viewImages(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn imageClickThrough() /// /// \brief prints a page with the software license agreement /// //////////////////////////////////////////////////////////////////////////////// function imageClickThrough() { global $clickThroughText; printf($clickThroughText, ""); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn imageClickThroughAgreement() /// /// \brief prints a page where the user must agree to the software licensing /// agreement before actually creating the new image /// //////////////////////////////////////////////////////////////////////////////// function imageClickThroughAgreement() { global $clickThroughText; $data = getContinuationVar(); $nextmode = $data['nextmode']; $multicall = getContinuationVar('multicall', 0); unset($data['nextmode']); $data['fromAgreement'] = 1; $buttons = "
\n"; $buttons .= "\n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= " \n"; $buttons .= "
\n"; $buttons .= "
\n"; $cont = addContinuationsEntry($nextmode, $data, SECINDAY, 0, $multicall); $buttons .= " \n"; $buttons .= " \n"; $buttons .= "
\n"; $buttons .= "
\n"; $buttons .= " \"\"\n"; $buttons .= " \n"; $buttons .= "
\n"; $cont = addContinuationsEntry('viewRequests'); $buttons .= " \n"; $buttons .= " \n"; $buttons .= "
\n"; $buttons .= "
\n"; $buttons .= " Clicking I agree will start the imaging process.\n"; $buttons .= "
\n"; $buttons .= "
\n"; printf($clickThroughText, "$buttons"); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitAddImage() /// /// \brief adds the image and notifies user /// //////////////////////////////////////////////////////////////////////////////// function submitAddImage() { global $user, $clickThroughText; $data = getContinuationVar(); // get platformid and osid $requestdata = getRequestInfo($data['requestid']); $imagedata = getImages(0, $requestdata["reservations"][0]["imageid"]); $data["platformid"] = $imagedata[$requestdata["reservations"][0]["imageid"]]["platformid"]; $data["osid"] = $imagedata[$requestdata["reservations"][0]["imageid"]]["osid"]; $data["basedoffrevisionid"] = $requestdata["reservations"][0]["imagerevisionid"]; // add estimated reload time $data["reloadtime"] = 20; // FIXME check for existance of image again if(! $imageid = addImage($data)) abort(10); // change imageid in request and reservation table and set state to image(16) # FIXME will need to figure out which reservation to update for multi-image # requests // get imagerevisionid $query = "SELECT id " . "FROM imagerevision " . "WHERE imageid = $imageid"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); $imagerevisionid = $row['id']; $requestid = $data["requestid"]; $query = "UPDATE request rq, " . "reservation rs " . "SET rs.imageid = $imageid, " . "rs.imagerevisionid = $imagerevisionid, " . "rq.stateid = 16," . "rq.forimaging = 1 " . "WHERE rq.id = $requestid AND " . "rq.id = rs.requestid"; doQuery($query, 101); if(array_key_exists('fromAgreement', $data) && $data['fromAgreement']) { $agreement = sprintf($clickThroughText, ""); $query = "INSERT INTO clickThroughs " . "(userid, " . "imageid, " . "imagerevisionid, " . "accepted, " . "agreement) " . "VALUES " . "({$user['id']}, " . "$imageid, " . "$imagerevisionid, " . "NOW(), " . "'$agreement')"; doQuery($query, 101); } print "

Add Image

\n"; print "The image creation process has been started. It normally takes "; print "about 25 minutes to complete (though can sometimes be more than "; print "two hours). You will be notified by email "; print "when the image has been created. At that point, you will be able "; print "to make a new reservation for the image. Once you have done so "; print "and tested that it works as expected, you can add it to an image "; print "group on the Manage Images page if you have "; print "sufficient access or have your computing support add it for you.
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn updateExistingImageComments() /// /// \brief prints a page for getting install comments about the revision before /// continuing on to actually creating the revision /// //////////////////////////////////////////////////////////////////////////////// function updateExistingImageComments() { $cdata = getContinuationVar(); $data = getRequestInfo($cdata['requestid']); foreach($data["reservations"] as $res) { if($res["forcheckout"]) { $imageid = $res["imageid"]; $revisionid = $res['imagerevisionid']; break; } } $revisions = getImageRevisions($imageid); print "

Update Existing Image

\n"; print "

New Revision Comments

\n"; print "Enter any notes for yourself and other admins about how the image "; print "was setup/installed.
\nThese are optional and not visible to end "; print "users:
\n"; print "
\n"; print "\n"; print "

Previous Revision Comments

\n"; if(preg_match('/\w/', $revisions[$revisionid]['comments'])) { print "These are the comments from the previous revision "; print "({$revisions[$revisionid]['revision']}):
\n"; print "{$revisions[$revisionid]['comments']}

\n"; } else print "The previous revision did not have any comments.
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('updateExistingImage', $cdata, SECINDAY, 0, 0); print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('viewRequests'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn updateExistingImage() /// /// \brief sets test flag on image to 1, sets state of request to 'image' and /// notifies the user that the imaging process has started /// //////////////////////////////////////////////////////////////////////////////// function updateExistingImage() { global $user, $clickThroughText; $requestid = getContinuationVar("requestid"); $fromAgreement = getContinuationVar('fromAgreement', 0); $comments = processInputVar("comments", ARG_STRING); $comments = preg_replace("/\r/", '', $comments); $comments = htmlspecialchars($comments); #$comments = preg_replace("/\n/", '
', $comments); $comments = preg_replace("/\n/", '', $comments); if(get_magic_quotes_gpc()) $comments = stripslashes($comments); $comments = mysql_real_escape_string($comments); $data = getRequestInfo($requestid); foreach($data["reservations"] as $res) { if($res["forcheckout"]) { $imageid = $res["imageid"]; break; } } $imageData = getImages(0, $imageid); if($imageData[$imageid]['ownerid'] != $user['id']) { editOrAddImage(1); return; } // set the test flag on the image in the image table $query = "UPDATE image SET test = 1 WHERE id = $imageid"; doQuery($query, 101); # add entry to imagerevision table $query = "SELECT revision, " . "imagename " . "FROM imagerevision " . "WHERE imageid = $imageid " . "ORDER BY revision DESC " . "LIMIT 1"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); $newrevision = $row['revision'] + 1; $newname = preg_replace("/{$row['revision']}$/", $newrevision, $row['imagename']); $query = "INSERT INTO imagerevision " . "(imageid, " . "revision, " . "userid, " . "datecreated, " . "deleted, " . "production, " . "comments, " . "imagename) " . "VALUES ($imageid, " . "$newrevision, " . "{$user['id']}, " . "NOW(), " . "1, " . "0, " . "'$comments', " . "'$newname')"; doQuery($query, 101); $qh = doQuery("SELECT LAST_INSERT_ID() FROM imagerevision", 101); $row = mysql_fetch_row($qh); $imagerevisionid = $row[0]; # update request and reservation $query = "UPDATE request rq, " . "reservation rs " . "SET rs.imagerevisionid = $imagerevisionid, " . "rq.stateid = 16," . "rq.forimaging = 1 " . "WHERE rq.id = $requestid AND " . "rq.id = rs.requestid AND " . "rs.imageid = $imageid"; doQuery($query, 101); if($fromAgreement) { $agreement = strip_tags(sprintf($clickThroughText, "")); $query = "INSERT INTO clickThroughs " . "(userid, " . "imageid, " . "accepted, " . "agreement) " . "VALUES " . "({$user['id']}, " . "$imageid, " . "NOW(), " . "'$agreement')"; doQuery($query, 101); } print "

Update Image

\n"; print "The image creation process has been started. It normally takes "; print "about 20-25 minutes to complete. You will be notified by email "; print "when the image has been created. Afterward, there are a few steps "; print "you need to follow to make it the production revision of the image:"; print "
    \n"; print "
  1. Make a new reservation for the environment (it will have the "; print "same name in the drop-down list).
  2. \n"; print "
  3. After clicking Submit on the New Reservations "; print "page, you will be prompted to select the revision of the environment "; print "you want
  4. \n"; print "
  5. Select the most recent revision and click Submit"; print "
  6. \n"; print "
  7. Test the environment to make sure it works correctly
  8. \n"; print "
  9. After you are satisfied that it works correctly, click the "; print "End button on the Current Reservations page
  10. \n"; print "
  11. You will be prompted to make the revision production or just end "; print "the reservation
  12. \n"; print "
  13. Select the Make this the production revision "; print "radio button
  14. and click Submit\n"; print "
\n"; print "Once the revision is made production, everyone that selects it will "; print "get the new revision
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn setImageProduction() /// /// \brief prompts user if really ready to set image to production /// //////////////////////////////////////////////////////////////////////////////// function setImageProduction() { $requestid = getContinuationVar('requestid'); $data = getRequestInfo($requestid); foreach($data["reservations"] as $res) { if($res["forcheckout"]) { $prettyimage = $res["prettyimage"]; break; } } print "

Change Test Image to Production

\n"; print "This will update the $prettyimage "; print "environment to be the newly created revision so that people will "; print "start getting it when they checkout the environment. It will also "; print "cause all the blades that currently have this image preloaded to be "; print "reloaded with this new image. Are you sure the image works "; print "correctly?
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; print "
\n"; $cdata = array('requestid' => $requestid); $cont = addContinuationsEntry('submitSetImageProduction', $cdata, SECINDAY, 0, 0); print " \n"; print " \n"; print "
\n"; print "
\n"; print "
\n"; $cont = addContinuationsEntry('viewRequests'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitSetImageProduction() /// /// \brief sets request state to 'makeproduction', notifies user that /// "productioning" process has started /// //////////////////////////////////////////////////////////////////////////////// function submitSetImageProduction() { $requestid = getContinuationVar('requestid'); $data = getRequestInfo($requestid); foreach($data["reservations"] as $res) { if($res["forcheckout"]) { $prettyimage = $res["prettyimage"]; break; } } $query = "UPDATE request SET stateid = 17 WHERE id = $requestid"; doQuery($query, 101); print "

Change Test Image to Production

\n"; print "$prettyimage is in the process of being "; print "updated to use the newly created image.
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn confirmDeleteImage() /// /// \brief prints a form to confirm the deletion of an image /// //////////////////////////////////////////////////////////////////////////////// function confirmDeleteImage() { $imageid = getContinuationVar("imageid"); $images = getImages(1); if($images[$imageid]["deleted"] == 0) { $deleted = 0; $title = "Delete Image"; $question = "Delete the following image?"; } else { $deleted = 1; $title = "Undelete Image"; $question = "Undelete the following image?"; } if(! $deleted && checkForImageUsage($imageid)) { print "

Delete Image

\n"; print "The image you selected is currently in use. You cannot delete "; print "the image until it is no longer being used.
\n"; return; } $platforms = getPlatforms(); $oslist = getOSList(); print "
\n"; print "
\n"; print "

$title

\n"; print "$question

\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 " \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 "
Short Name:" . $images[$imageid]["name"] . "
Long Name:" . $images[$imageid]["prettyname"] . "
Owner:" . $images[$imageid]["owner"] . "
Platform:" . $platforms[$images[$imageid]["platformid"]] . "
OS:" . $oslist[$images[$imageid]["osid"]]["prettyname"] . "
Minimum RAM (MB):" . $images[$imageid]["minram"] . "
Minimum Num of Processors:" . $images[$imageid]["minprocnumber"] . "
Minimum Processor Speed (MHz):" . $images[$imageid]["minprocspeed"] . "
Minimum Network Speed (Mbps):" . $images[$imageid]["minnetwork"] . "
Estimated Reload Time (min):" . $images[$imageid]["reloadtime"] . "
\n"; print "\n"; print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cdata = array('deleted' => $deleted, 'imageid' => $imageid); $cont = addContinuationsEntry('submitDeleteImage', $cdata, SECINDAY, 0, 0); print " \n"; print " \n"; print " \n"; print " \n"; print "
\n"; $cont = addContinuationsEntry('viewImages'); print " \n"; print " \n"; print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitDeleteImage() /// /// \brief deletes an image from the database and notifies the user /// //////////////////////////////////////////////////////////////////////////////// function submitDeleteImage() { $imageid = getContinuationVar("imageid"); $deleted = getContinuationVar("deleted"); if($deleted) { $query = "UPDATE image " . "SET deleted = 0 " . "WHERE id = $imageid"; $qh = doQuery($query, 210); } else { $query = "UPDATE image " . "SET deleted = 1 " . "WHERE id = $imageid"; $qh = doQuery($query, 211); $query = "UPDATE computer " . "SET nextimageid = 0 " . "WHERE nextimageid = $imageid"; doQuery($query, 212); } viewImages(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn viewImageDetails /// /// \brief prints a page with all information about an image /// //////////////////////////////////////////////////////////////////////////////// function viewImageDetails() { $imageid = getContinuationVar("imageid"); $images = getImages(1); $platforms = getPlatforms(); $oslist = getOSList(); print "
\n"; print "

Image Details

\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 " \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"; if($images[$imageid]['maxconcurrent'] == '') print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; if($images[$imageid]["forcheckout"]) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if(array_key_exists("checkuser", $images[$imageid]) && $images[$imageid]["checkuser"] == 0) print " \n"; else print " \n"; print " \n"; print " \n"; print " \n"; if(array_key_exists("rootaccess", $images[$imageid]) && $images[$imageid]["rootaccess"] == 0) print " \n"; else print " \n"; print " \n"; if(! empty($images[$imageid]["usergroupid"])) { print " \n"; print " \n"; print " \n"; print " \n"; } if($oslist[$images[$imageid]["osid"]]["type"] == 'windows') { print " \n"; print " \n"; if(array_key_exists("sysprep", $images[$imageid]) && $images[$imageid]["sysprep"] == 0) print " \n"; else print " \n"; print " \n"; } if(array_key_exists("subimages", $images[$imageid]) && count($images[$imageid]["subimages"])) { print " \n"; print " \n"; print " \n"; print " \n"; } print "
Short Name:" . $images[$imageid]["name"] . "
Long Name:" . $images[$imageid]["prettyname"] . "
Owner:" . $images[$imageid]["owner"] . "
Platform:" . $platforms[$images[$imageid]["platformid"]] . "
OS:" . $oslist[$images[$imageid]["osid"]]["prettyname"] . "
Minimum RAM (MB):" . $images[$imageid]["minram"] . "
Minimum Num of Processors:" . $images[$imageid]["minprocnumber"] . "
Minimum Processor Speed (MHz):" . $images[$imageid]["minprocspeed"] . "
Minimum Network Speed (Mbps):" . $images[$imageid]["minnetwork"] . "
Maximum Concurrent Usage:N/A" . $images[$imageid]["maxconcurrent"] . "
Estimated Reload Time (min):" . $images[$imageid]["reloadtime"] . "
Available for checkout:yesno
Check for logged in user:noyes
Users have administrative access:noyes
User group allowed to log in:{$images[$imageid]["usergroup"]}
Use sysprep:noyes
"; print "Subimages:\n"; foreach($images[$imageid]["subimages"] as $imgid) { print "{$images[$imgid]["prettyname"]}
\n"; } print "
\n"; print "
\n"; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitImageGroups /// /// \brief updates image groupings /// //////////////////////////////////////////////////////////////////////////////// function submitImageGroups() { $groupinput = processInputVar("imagegroup", ARG_MULTINUMERIC); $images = getImages(); # build an array of memberships currently in the db $tmp = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $imagegroupsIDs = array_keys($tmp["image"]); // ids of groups that user can manage $resources = getUserResources(array("imageAdmin"), array("manageGroup")); $userImageIDs = array_keys($resources["image"]); // ids of images that user can manage $imagemembership = getResourceGroupMemberships("image"); $baseimagegroups = $imagemembership["image"]; // all image group memberships $imagegroups = array(); foreach(array_keys($baseimagegroups) as $imageid) { if(in_array($imageid, $userImageIDs)) { foreach($baseimagegroups[$imageid] as $grpid) { if(in_array($grpid, $imagegroupsIDs)) { if(array_key_exists($imageid, $imagegroups)) array_push($imagegroups[$imageid], $grpid); else $imagegroups[$imageid] = array($grpid); } } } } # build an array of posted in memberships $newmembers = array(); foreach(array_keys($groupinput) as $key) { list($imageid, $grpid) = explode(':', $key); if(array_key_exists($imageid, $newmembers)) { array_push($newmembers[$imageid], $grpid); } else { $newmembers[$imageid] = array($grpid); } } $adds = array(); $removes = array(); foreach(array_keys($images) as $imageid) { $id = $images[$imageid]["resourceid"]; // if $imageid not in $userImageIds, don't bother with it if(! in_array($imageid, $userImageIDs)) continue; // if $imageid is not in $newmembers and not in $imagegroups, do nothing if(! array_key_exists($imageid, $newmembers) && ! array_key_exists($imageid, $imagegroups)) { continue; } // check that $imageid is in $newmembers, if not, remove it from all groups // user has access to if(! array_key_exists($imageid, $newmembers)) { $removes[$id] = $imagegroups[$imageid]; continue; } // check that $imageid is in $imagegroups, if not, add all groups in // $newmembers if(! array_key_exists($imageid, $imagegroups)) { $adds[$id] = $newmembers[$imageid]; continue; } // adds are groupids that are in $newmembers, but not in $imagegroups $adds[$id] = array_diff($newmembers[$imageid], $imagegroups[$imageid]); if(count($adds[$id]) == 0) { unset($adds[$id]); } // removes are groupids that are in $imagegroups, but not in $newmembers $removes[$id] = array_diff($imagegroups[$imageid], $newmembers[$imageid]); if(count($removes[$id]) == 0) { unset($removes[$id]); } } foreach(array_keys($adds) as $imageid) { foreach($adds[$imageid] as $grpid) { $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) " . "VALUES ($imageid, $grpid)"; doQuery($query, 287); } } foreach(array_keys($removes) as $imageid) { foreach($removes[$imageid] as $grpid) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = $imageid AND " . "resourcegroupid = $grpid"; doQuery($query, 288); } } viewImageGrouping(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn submitImageMapping /// /// \brief updates image group to computer group mapping /// //////////////////////////////////////////////////////////////////////////////// function submitImageMapping() { $mapinput = processInputVar("mapping", ARG_MULTINUMERIC); # build an array of memberships currently in the db $tmp = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $imagegroups = $tmp["image"]; $tmp = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $compgroups = $tmp["computer"]; $imageinlist = implode(',', array_keys($imagegroups)); $compinlist = implode(',', array_keys($compgroups)); $mapping = getResourceMapping("image", "computer", $imageinlist, $compinlist); # build an array of posted in memberships $newmembers = array(); foreach(array_keys($mapinput) as $key) { list($imageid, $compid) = explode(':', $key); if(array_key_exists($imageid, $newmembers)) array_push($newmembers[$imageid], $compid); else $newmembers[$imageid] = array($compid); } $adds = array(); $removes = array(); foreach(array_keys($imagegroups) as $imageid) { // if $imageid is not in $newmembers and not in $mapping, do nothing if(! array_key_exists($imageid, $newmembers) && ! array_key_exists($imageid, $mapping)) { continue; } // check that $imageid is in $newmembers, if not, remove it from all groups // user has access to if(! array_key_exists($imageid, $newmembers)) { $removes[$imageid] = $mapping[$imageid]; continue; } // check that $imageid is in $mapping, if not, add all groups in // $newmembers if(! array_key_exists($imageid, $mapping)) { $adds[$imageid] = $newmembers[$imageid]; continue; } // adds are groupids that are in $newmembers, but not in $mapping $adds[$imageid] = array_diff($newmembers[$imageid], $mapping[$imageid]); if(count($adds[$imageid]) == 0) { unset($adds[$imageid]); } // removes are groupids that are in $mapping, but not in $newmembers $removes[$imageid] = array_diff($mapping[$imageid], $newmembers[$imageid]); if(count($removes[$imageid]) == 0) { unset($removes[$imageid]); } } foreach(array_keys($adds) as $imageid) { foreach($adds[$imageid] as $compid) { $query = "INSERT INTO resourcemap " . "(resourcegroupid1, " . "resourcetypeid1, " . "resourcegroupid2, " . "resourcetypeid2) " . "VALUES ($imageid, " . "13, " . "$compid, " . "12)"; doQuery($query, 101); } } foreach(array_keys($removes) as $imageid) { foreach($removes[$imageid] as $compid) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = $imageid AND " . "resourcetypeid1 = 13 AND " . "resourcegroupid2 = $compid AND " . "resourcetypeid2 = 12"; doQuery($query, 101); } } viewImageMapping(); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn processImageInput($checks) /// /// \param $checks - (optional) 1 to perform validation, 0 not to /// /// \return an array with the following indexes:\n /// imageid, name, prettyname, platformid, osid /// /// \brief validates input from the previous form; if anything was improperly /// submitted, sets submitErr and submitErrMsg /// //////////////////////////////////////////////////////////////////////////////// function processImageInput($checks=1) { global $submitErr, $submitErrMsg, $user; $return = array(); $mode = processInputVar("mode", ARG_STRING); $return["imageid"] = processInputVar("imageid" , ARG_NUMERIC, getContinuationVar('imageid')); $return['requestid'] = getContinuationVar('requestid'); #$return["name"] = processInputVar("name", ARG_STRING); $return["prettyname"] = processInputVar("prettyname", ARG_STRING); $return["owner"] = processInputVar("owner", ARG_STRING, "{$user["unityid"]}@{$user['affiliation']}"); #$return["platformid"] = processInputVar("platformid", ARG_NUMERIC); #$return["osid"] = processInputVar("osid", ARG_NUMERIC); $return["minram"] = processInputVar("minram", ARG_NUMERIC, 64); $return["minprocnumber"] = processInputVar("minprocnumber", ARG_NUMERIC); $return["minprocspeed"] = processInputVar("minprocspeed", ARG_NUMERIC, 500); $return["minnetwork"] = processInputVar("minnetwork", ARG_NUMERIC); $return["maxconcurrent"] = processInputVar("maxconcurrent", ARG_NUMERIC); $return["reloadtime"] = processInputVar("reloadtime", ARG_NUMERIC, 10); $return["forcheckout"] = processInputVar("forcheckout", ARG_NUMERIC, 1); $return["checkuser"] = processInputVar("checkuser", ARG_NUMERIC, 1); $return["rootaccess"] = processInputVar("rootaccess", ARG_NUMERIC, 1); $return["usergroupid"] = processInputVar("usergroupid", ARG_NUMERIC); $return["sysprep"] = processInputVar("sysprep", ARG_NUMERIC, 1); $return["description"] = processInputVar("description", ARG_STRING); $return["usage"] = processInputVar("usage", ARG_STRING); $return["comments"] = processInputVar("comments", ARG_STRING); $return['description'] = preg_replace("/[\n\s]*$/", '', $return['description']); $return['description'] = preg_replace("/\r/", '', $return['description']); $return['description'] = htmlspecialchars($return['description']); $return['description'] = preg_replace("/\n/", '
', $return['description']); $return['usage'] = preg_replace("/[\n\s]*$/", '', $return['usage']); $return['usage'] = preg_replace("/\r/", '', $return['usage']); $return['usage'] = htmlspecialchars($return['usage']); $return['usage'] = preg_replace("/\n/", '
', $return['usage']); $return['comments'] = preg_replace("/[\n\s]*$/", '', $return['comments']); $return['comments'] = preg_replace("/\r/", '', $return['comments']); $return['comments'] = htmlspecialchars($return['comments']); $return['comments'] = preg_replace("/\n/", '
', $return['comments']); if(! $checks) { return $return; } /*if($mode != "confirmAddImage" && (strlen($return["name"]) > 30 || strlen($return["name"]) < 2)) { $submitErr |= NAMEERR; $submitErrMsg[NAMEERR] = "Short Name must be from 2 to 30 characters"; } if(! ($submitErr & NAMEERR) && checkForImageName($return["name"], "short", $return["imageid"])) { $submitErr |= NAMEERR; $submitErrMsg[NAMEERR] = "An image already exists with this name."; }*/ if(preg_match('/-/', $return["prettyname"]) || strlen($return["prettyname"]) > 60 || strlen($return["prettyname"]) < 2) { $submitErr |= PRETTYNAMEERR; $submitErrMsg[PRETTYNAMEERR] = "Long Name must be from 2 to 60 characters " . "and cannot contain any dashes (-)."; } if(! ($submitErr & PRETTYNAMEERR) && checkForImageName($return["prettyname"], "long", $return["imageid"])) { $submitErr |= PRETTYNAMEERR; $submitErrMsg[PRETTYNAMEERR] = "An image already exists with this name."; } if($return["minram"] < 0 || $return["minram"] > 20480) { $submitErr |= MINRAMERR; $submitErrMsg[MINRAMERR] = "RAM must be between 0 and 20480 MB"; } if($return["minprocspeed"] < 0 || $return["minprocspeed"] > 20000) { $submitErr |= MINPROCSPEEDERR; $submitErrMsg[MINPROCSPEEDERR] = "Processor Speed must be between 0 and 20000"; } if((! is_numeric($return['maxconcurrent']) && ! empty($return['maxconcurrent'])) || (is_numeric($return['maxconcurrent']) && ($return["maxconcurrent"] < 1 || $return["maxconcurrent"] > 255))) { $submitErr |= MAXCONCURRENTERR; $submitErrMsg[MAXCONCURRENTERR] = "Max concurrent usage must be blank or between 1 and 255"; } if($return["reloadtime"] < 0 || $return["reloadtime"] > 120) { $submitErr |= RELOADTIMEERR; $submitErrMsg[RELOADTIMEERR] = "Estimated Reload Time must be between 0 and 120"; } if(! validateUserid($return["owner"])) { $submitErr |= IMGOWNERERR; $submitErrMsg[IMGOWNERERR] = "Submitted ID is not valid"; } if(empty($return['description'])) { $submitErr |= IMAGEDESCRIPTIONERR; $submitErrMsg[IMAGEDESCRIPTIONERR] = "You must include a description of the image
"; } return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForImageName($name, $longshort, $id) /// /// \param $name - the name of an image /// \param $longshort - "long" for long/pretty name, "short" for short/name /// \param $id - id of an image to ignore /// /// \return 1 if $name is already in the image table, 0 if not /// /// \brief checks for $name being in the image table except for $id /// //////////////////////////////////////////////////////////////////////////////// function checkForImageName($name, $longshort, $id) { if($longshort == "long") $field = "prettyname"; else $field = "name"; $query = "SELECT id FROM image " . "WHERE $field = '$name'"; if(! empty($id)) $query .= " AND id != $id"; $qh = doQuery($query, 101); if(mysql_num_rows($qh)) return 1; return 0; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn updateImage($data) /// /// \param $data - an array returned from processImageInput /// /// \return number of rows affected by the update\n /// \b NOTE: mysql reports that no rows were affected if none of the fields /// were actually changed even if the update matched a row /// /// \brief performs a query to update the image with data from $data /// //////////////////////////////////////////////////////////////////////////////// function updateImage($data) { $imgdata = getImages(0, $data["imageid"]); $imagenotes = getImageNotes($data['imageid']); $ownerid = getUserlistID($data["owner"]); if(empty($data['maxconcurrent']) || ! is_numeric($data['maxconcurrent'])) $data['maxconcurrent'] = 'NULL'; $query = "UPDATE image " . "SET prettyname = '{$data["prettyname"]}', " . "ownerid = $ownerid, " /*. "platformid = {$data["platformid"]}, " . "OSid = {$data["osid"]}, "*/ . "minram = {$data["minram"]}, " . "minprocnumber = {$data["minprocnumber"]}, " . "minprocspeed = {$data["minprocspeed"]}, " . "minnetwork = {$data["minnetwork"]}, " . "maxconcurrent = {$data["maxconcurrent"]}, " . "reloadtime = {$data["reloadtime"]}, " . "forcheckout = {$data["forcheckout"]}, " . "description = '{$data["description"]}', " . "`usage` = '{$data["usage"]}' " . "WHERE id = {$data["imageid"]}"; $qh = doQuery($query, 200); $return = mysql_affected_rows($GLOBALS["mysql_link_vcl"]); if(empty($imgdata[$data["imageid"]]["imagemetaid"]) && ($data["checkuser"] == 0 || $data["usergroupid"] != 0 || $data['rootaccess'] == 0)) { if($data["usergroupid"] == 0) $data["usergroupid"] = "NULL"; $query = "INSERT INTO imagemeta " . "(checkuser, " . "usergroupid, " . "rootaccess) " . "VALUES ({$data["checkuser"]}, " . "{$data["usergroupid"]}, " . "{$data["rootaccess"]})"; doQuery($query, 101); $qh = doQuery("SELECT LAST_INSERT_ID() FROM imagemeta", 101); if(! $row = mysql_fetch_row($qh)) abort(101); $imagemetaid = $row[0]; $query = "UPDATE image " . "SET imagemetaid = $imagemetaid " . "WHERE id = {$data["imageid"]}"; doQuery($query, 101); } elseif(! empty($imgdata[$data["imageid"]]["imagemetaid"])) { if($data["checkuser"] != $imgdata[$data["imageid"]]["checkuser"] || $data["rootaccess"] != $imgdata[$data["imageid"]]["rootaccess"] || $data["usergroupid"] != $imgdata[$data["imageid"]]["usergroupid"]) { if($data["usergroupid"] == 0) $data["usergroupid"] = "NULL"; $query = "UPDATE imagemeta " . "SET checkuser = {$data["checkuser"]}, " . "rootaccess = {$data["rootaccess"]}, " . "usergroupid = {$data["usergroupid"]} " . "WHERE id = {$imgdata[$data["imageid"]]["imagemetaid"]}"; doQuery($query, 101); } checkClearImageMeta($imgdata[$data['imageid']]['imagemetaid'], $data['imageid']); } return $return; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn addImage($data) /// /// \param $data - an array returned from processImageInput /// /// \return number of rows affected by the insert\n /// /// \brief performs a query to insert the image with data from $data /// //////////////////////////////////////////////////////////////////////////////// function addImage($data) { global $user; if(get_magic_quotes_gpc()) { $data['description'] = stripslashes($data['description']); $data['usage'] = stripslashes($data['usage']); } $data['description'] = mysql_real_escape_string($data['description']); $data['usage'] = mysql_real_escape_string($data['usage']); $ownerdata = getUserInfo($data['owner'], 1); $ownerid = $ownerdata['id']; if(empty($data['maxconcurrent']) || ! is_numeric($data['maxconcurrent'])) $data['maxconcurrent'] = 'NULL'; $query = "INSERT INTO image " . "(prettyname, " . "ownerid, " . "platformid, " . "OSid, " . "minram, " . "minprocnumber, " . "minprocspeed, " . "minnetwork, " . "maxconcurrent, " . "reloadtime, " . "deleted, " . "description, " . "`usage`, " . "basedoffrevisionid) " . "VALUES ('{$data["prettyname"]}', " . "$ownerid, " . "{$data["platformid"]}, " . "{$data["osid"]}, " . "{$data["minram"]}, " . "{$data["minprocnumber"]}, " . "{$data["minprocspeed"]}, " . "{$data["minnetwork"]}, " . "{$data["maxconcurrent"]}, " . "{$data["reloadtime"]}, " . "1, " . "'{$data['description']}', " . "'{$data['usage']}', " . "{$data['basedoffrevisionid']})"; doQuery($query, 205); // get last insert id $qh = doQuery("SELECT LAST_INSERT_ID() FROM image", 206); if(! $row = mysql_fetch_row($qh)) { abort(207); } $imageid = $row[0]; // possibly add entry to imagemeta table $imagemetaid = 0; if($data['checkuser'] != 0 && $data['checkuser'] != 1) $data['checkuser'] = 1; if($data['rootaccess'] != 0 && $data['rootaccess'] != 1) $data['rootaccess'] = 1; if(! is_numeric($data['usergroupid']) || $data['usergroupid'] <= 0) $data['usergroupid'] = "NULL"; if($data['sysprep'] != 0 && $data['sysprep'] != 1) $data['sysprep'] = 1; if($data['checkuser'] == 0 || $data['rootaccess'] == 0 || (is_numeric($data['usergroupid']) && $data['usergroupid'] > 0) || $data['sysprep'] == 0) { $query = "INSERT INTO imagemeta " . "(checkuser, " . "rootaccess, " . "usergroupid, " . "sysprep) " . "VALUES " . "({$data['checkuser']}, " . "{$data['rootaccess']}, " . "{$data['usergroupid']}, " . "{$data['sysprep']})"; doQuery($query, 101); // get last insert id $qh = doQuery("SELECT LAST_INSERT_ID() FROM imagemeta", 101); if(! $row = mysql_fetch_row($qh)) { abort(207); } $imagemetaid = $row[0]; } // create name from pretty name, os, and last insert id $OSs = getOSList(); $name = $OSs[$data["osid"]]["name"] . "-" . preg_replace('/\W/', '', $data["prettyname"]) . $imageid . "-v0"; if($imagemetaid) { $query = "UPDATE image " . "SET name = '$name', " . "imagemetaid = $imagemetaid " . "WHERE id = $imageid"; } else $query = "UPDATE image SET name = '$name' WHERE id = $imageid"; doQuery($query, 208); $query = "INSERT INTO imagerevision " . "(imageid, " . "userid, " . "datecreated, " . "production, " . "imagename, " . "comments) " . "VALUES ($imageid, " . "{$user['id']}, " . "NOW(), " . "1, " . "'$name', " . "'{$data['comments']}')"; doQuery($query, 101); // add entry in resource table $query = "INSERT INTO resource " . "(resourcetypeid, " . "subid) " . "VALUES (13, " . "$imageid)"; doQuery($query, 209); $qh = doQuery("SELECT LAST_INSERT_ID() FROM resource", 101); $row = mysql_fetch_row($qh); $resourceid = $row[0]; if(strncmp($OSs[$data['osid']]['name'], 'vmware', 6) == 0) $vmware = 1; else $vmware = 0; // create new node if it does not exist if($vmware) $nodename = 'newvmimages'; else $nodename = 'newimages'; $query = "SELECT id " . "FROM privnode " . "WHERE name = '$nodename' AND " . "parent = 3"; $qh = doQuery($query, 101); if(! $row = mysql_fetch_assoc($qh)) { $query2 = "INSERT INTO privnode " . "(parent, " . "name) " . "VALUES " . "(3, " . "'$nodename')"; doQuery($query2, 101); $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); } $parent = $row['id']; $query = "SELECT id " . "FROM privnode " . "WHERE name = '{$ownerdata['login']}-$ownerid' AND " . "parent = $parent"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) $newnode = $row['id']; else { $query = "INSERT INTO privnode " . "(parent, name) " . "VALUES ($parent, '{$ownerdata['login']}-$ownerid')"; doQuery($query, 101); $qh = doQuery("SELECT LAST_INSERT_ID() FROM privnode", 101); $row = mysql_fetch_row($qh); $newnode = $row[0]; } // give user imageCheckOut and imageAdmin at new node $newprivs = array('imageCheckOut', 'imageAdmin'); updateUserOrGroupPrivs($ownerid, $newnode, $newprivs, array(), 'user'); // create new image group if it does not exist $query = "SELECT id " . "FROM usergroup " . "WHERE name = 'manageNewImages'"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); $ownergroupid = $row['id']; if($vmware) $prefix = 'newvmimages'; else $prefix = 'newimages'; $query = "SELECT id " . "FROM resourcegroup " . "WHERE name = '$prefix-{$ownerdata['login']}-$ownerid' AND " . "ownerusergroupid = $ownergroupid AND " . "resourcetypeid = 13"; $qh = doQuery($query, 101); if($row = mysql_fetch_assoc($qh)) $resourcegroupid = $row['id']; else { $query = "INSERT INTO resourcegroup " . "(name, " . "ownerusergroupid, " . "resourcetypeid) " . "VALUES ('$prefix-{$ownerdata['login']}-$ownerid', " . "$ownergroupid, " . "13)"; doQuery($query, 305); $qh = doQuery("SELECT LAST_INSERT_ID() FROM resourcegroup", 101); $row = mysql_fetch_row($qh); $resourcegroupid = $row[0]; // map group to newimages/newvmimages comp group if($vmware) $rgroupname = 'newvmimages'; else $rgroupname = 'newimages'; $query = "SELECT id " . "FROM resourcegroup " . "WHERE name = '$rgroupname' AND " . "resourcetypeid = 12"; $qh = doQuery($query, 101); $row = mysql_fetch_assoc($qh); $compResGrpid = $row['id']; $query = "INSERT INTO resourcemap " . "(resourcegroupid1, " . "resourcetypeid1, " . "resourcegroupid2, " . "resourcetypeid2) " . "VALUES ($resourcegroupid, " . "13, " . "$compResGrpid, " . "12)"; doQuery($query, 101); } // make image group available at new node $adds = array('available', 'administer'); if($vmware) updateResourcePrivs("image/newvmimages-{$ownerdata['login']}-$ownerid", $newnode, $adds, array()); else updateResourcePrivs("image/newimages-{$ownerdata['login']}-$ownerid", $newnode, $adds, array()); // add image to image group $query = "INSERT INTO resourcegroupmembers " . "(resourceid, resourcegroupid) " . "VALUES ($resourceid, $resourcegroupid)"; doQuery($query, 101); return $imageid; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn checkForImageUsage($imageid) /// /// \param $imageid - id of an image /// /// \return 0 if image is not used on any computers, 1 if it is /// /// \brief checks for $imageid being the current imageid for any computers in /// the computer table or the imageid for any active reservations /// //////////////////////////////////////////////////////////////////////////////// function checkForImageUsage($imageid) { $query = "SELECT id " . "FROM computer " . "WHERE currentimageid = $imageid"; $qh = doQuery($query, 250); if(mysql_num_rows($qh)) return 1; $query = "SELECT rs.id " . "FROM reservation rs, " . "request rq " . "WHERE rs.requestid = rq.id " . "AND rs.imageid = $imageid " . "AND rq.end > NOW() " . "AND rq.stateid NOT IN (1, 5, 12)"; $qh = doQuery($query, 250); if(mysql_num_rows($qh)) return 1; return 0; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonImageGroupingImages() /// /// \brief accepts a groupid via form input and prints a json array with 3 /// arrays: an array of images that are in the group, an array of images /// not in it, and an array of all images user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonImageGroupingImages() { $groupid = processInputVar('groupid', ARG_NUMERIC); $groups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['image'])) { $arr = array('inimages' => array(), 'outimages' => array(), 'all' => array()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $resources = getUserResources(array('imageAdmin'), array('manageGroup')); uasort($resources['image'], 'sortKeepIndex'); $memberships = getResourceGroupMemberships('image'); $all = array(); $in = array(); $out = array(); foreach($resources['image'] as $id => $image) { if($image == 'No Image') continue; if(array_key_exists($id, $memberships['image']) && in_array($groupid, $memberships['image'][$id])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $image); $in[] = array('name' => $image, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $image); $out[] = array('name' => $image, 'id' => $id); } } $arr = array('inimages' => $in, 'outimages' => $out, 'all' => $all); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonImageGroupingGroups() /// /// \brief accepts an image id via form input and prints a json array with 3 /// arrays: an array of groups that the image is in, an array of groups it /// is not in and an array of all groups user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonImageGroupingGroups() { $imageid = processInputVar('imageid', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup")); if(! array_key_exists($imageid, $resources['image'])) { $arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groups = getUserResources(array('imageAdmin'), array('manageGroup'), 1); $memberships = getResourceGroupMemberships('image'); $in = array(); $out = array(); $all = array(); foreach($groups['image'] as $id => $group) { if(array_key_exists($imageid, $memberships['image']) && in_array($id, $memberships['image'][$imageid])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $group); $in[] = array('name' => $group, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $group); $out[] = array('name' => $group, 'id' => $id); } } $arr = array('ingroups' => $in, 'outgroups' => $out, 'all' => $all); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonImageMapCompGroups() /// /// \brief accepts a image groupid via form input and prints a json array with 3 /// arrays: an array of computer groups that are mapped to the group, an array /// of computer groups not mapped to it, and an array of all computer groups /// the user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonImageMapCompGroups() { $imagegrpid = processInputVar('imagegrpid', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($imagegrpid, $resources['image'])) { $arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $compgroups = getUserResources(array('computerAdmin'), array('manageGroup'), 1); $mapping = getResourceMapping('image', 'computer'); $in = array(); $out = array(); $all = array(); foreach($compgroups['computer'] as $id => $group) { if(array_key_exists($imagegrpid, $mapping) && in_array($id, $mapping[$imagegrpid])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $group); $in[] = array('name' => $group, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $group); $out[] = array('name' => $group, 'id' => $id); } } $arr = array('ingroups' => $in, 'outgroups' => $out, 'all' => $all); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn jsonImageMapImgGroups() /// /// \brief accepts a computer groupid via form input and prints a json array /// with 3 arrays: an array of image groups that are mapped to the group, an /// array of image groups not mapped to it, and an array of all image groups /// the user has access to /// //////////////////////////////////////////////////////////////////////////////// function jsonImageMapImgGroups() { $compgrpid = processInputVar('compgrpid', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($compgrpid, $resources['computer'])) { $arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array()); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imagegroups = getUserResources(array('imageAdmin'), array('manageGroup'), 1); $mapping = getResourceMapping('computer', 'image'); $in = array(); $out = array(); $all = array(); foreach($imagegroups['image'] as $id => $group) { if(array_key_exists($compgrpid, $mapping) && in_array($id, $mapping[$compgrpid])) { $all[] = array('inout' => 1, 'id' => $id, 'name' => $group); $in[] = array('name' => $group, 'id' => $id); } else { $all[] = array('inout' => 0, 'id' => $id, 'name' => $group); $out[] = array('name' => $group, 'id' => $id); } } $arr = array('ingroups' => $in, 'outgroups' => $out, 'all' => $all); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddImageToGroup() /// /// \brief accepts a groupid and a comma delimited list of image ids to be /// added to the group; adds them and returns an array of image ids that were /// added /// //////////////////////////////////////////////////////////////////////////////// function AJaddImageToGroup() { $groupid = processInputVar('id', ARG_NUMERIC); $groups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['image'])) { $arr = array('images' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $resources = getUserResources(array("imageAdmin"), array("manageGroup")); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $imageids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $resources['image'])) { $arr = array('images' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imageids[] = $id; } $allimages = getImages(); $adds = array(); foreach($imageids as $id) { $adds[] = "({$allimages[$id]['resourceid']}, $groupid)"; } $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) VALUES "; $query .= implode(',', $adds); doQuery($query, 287); $_SESSION['userresources'] = array(); $arr = array('images' => $imageids, 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremImageFromGroup() /// /// \brief accepts a groupid and a comma delimited list of image ids to be /// removed from the group; removes them and returns an array of image ids /// that were removed /// //////////////////////////////////////////////////////////////////////////////// function AJremImageFromGroup() { $groupid = processInputVar('id', ARG_NUMERIC); $groups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($groupid, $groups['image'])) { $arr = array('images' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $resources = getUserResources(array("imageAdmin"), array("manageGroup")); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $imageids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $resources['image'])) { $arr = array('images' => array(), 'addrem' => 0, 'id' => $id, 'extra' => $resources['image']); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imageids[] = $id; } $allimages = getImages(); foreach($imageids as $id) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$allimages[$id]['resourceid']} AND " . "resourcegroupid = $groupid"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('images' => $imageids, 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddGroupToImage() /// /// \brief accepts an image id and a comma delimited list of group ids that /// the image should be added to; adds it to them and returns an array of /// groups it was added to /// //////////////////////////////////////////////////////////////////////////////// function AJaddGroupToImage() { $imageid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup")); if(! array_key_exists($imageid, $resources['image'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $groups['image'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groupids[] = $id; } $img = getImages(0, $imageid); $adds = array(); foreach($groupids as $id) { $adds[] = "({$img[$imageid]['resourceid']}, $id)"; } $query = "INSERT IGNORE INTO resourcegroupmembers " . "(resourceid, resourcegroupid) VALUES "; $query .= implode(',', $adds); doQuery($query, 101); $_SESSION['userresources'] = array(); $arr = array('groups' => $groupids, 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremGroupFromImage() /// /// \brief accepts an image id and a comma delimited list of group ids that /// the image should be removed from; removes it from them and returns an /// array of groups it was removed from /// //////////////////////////////////////////////////////////////////////////////// function AJremGroupFromImage() { $imageid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup")); if(! array_key_exists($imageid, $resources['image'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $groupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $groups['image'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $groupids[] = $id; } $img = getImages(0, $imageid); foreach($groupids as $id) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$img[$imageid]['resourceid']} AND " . "resourcegroupid = $id"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('groups' => $groupids, 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddCompGrpToImgGrp() /// /// \brief accepts an image group id and a comma delimited list of computer /// group ids that the image group should be mapped to; maps it to them and /// returns an array of groups it was mapped to /// //////////////////////////////////////////////////////////////////////////////// function AJaddCompGrpToImgGrp() { $imagegrpid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($imagegrpid, $resources['image'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $compgroups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $compgroupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $compgroups['computer'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $compgroupids[] = $id; } $adds = array(); foreach($compgroupids as $id) { $adds[] = "($imagegrpid, 13, $id, 12)"; } $query = "INSERT IGNORE INTO resourcemap " . "(resourcegroupid1, resourcetypeid1, resourcegroupid2, resourcetypeid2) VALUES "; $query .= implode(',', $adds); doQuery($query, 101); $_SESSION['userresources'] = array(); $arr = array('groups' => $compgroupids, 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremCompGrpFromImgGrp() /// /// \brief accepts an image group id and a comma delimited list of computer /// group ids that the image group should be unmapped from; unmaps it from them /// and returns an array of computer groups it was unmapped from /// //////////////////////////////////////////////////////////////////////////////// function AJremCompGrpFromImgGrp() { $imagegrpid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("imageAdmin"), array("manageGroup"), 1); if(! array_key_exists($imagegrpid, $resources['image'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $compgroups = getUserResources(array("computerAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $compgroupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $compgroups['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $compgroupids[] = $id; } foreach($compgroupids as $id) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = $imagegrpid AND " . "resourcetypeid1 = 13 AND " . "resourcegroupid2 = $id AND " . "resourcetypeid2 = 12"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('groups' => $compgroupids, 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJaddImgGrpToCompGrp() /// /// \brief accepts a computer group id and a comma delimited list of image /// group ids that the computer group should be mapped to; maps it to them and /// returns an array of groups it was mapped to /// //////////////////////////////////////////////////////////////////////////////// function AJaddImgGrpToCompGrp() { $compgrpid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($compgrpid, $resources['computer'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imagegroups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $imagegroupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $imagegroups['image'])) { $arr = array('groups' => array(), 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imagegroupids[] = $id; } $adds = array(); foreach($imagegroupids as $id) { $adds[] = "($id, 13, $compgrpid, 12)"; } $query = "INSERT IGNORE INTO resourcemap " . "(resourcegroupid1, resourcetypeid1, resourcegroupid2, resourcetypeid2) VALUES "; $query .= implode(',', $adds); doQuery($query, 101); $_SESSION['userresources'] = array(); $arr = array('groups' => $imagegroupids, 'addrem' => 1); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJremImgGrpFromCompGrp() /// /// \brief accepts a computer group id and a comma delimited list of image group /// ids that the computer group should be unmapped from; unmaps it from them /// and returns an array of image groups it was unmapped from /// //////////////////////////////////////////////////////////////////////////////// function AJremImgGrpFromCompGrp() { $compgrpid = processInputVar('id', ARG_NUMERIC); $resources = getUserResources(array("computerAdmin"), array("manageGroup"), 1); if(! array_key_exists($compgrpid, $resources['computer'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imagegroups = getUserResources(array("imageAdmin"), array("manageGroup"), 1); $tmp = processInputVar('listids', ARG_STRING); $tmp = explode(',', $tmp); $imagegroupids = array(); foreach($tmp as $id) { if(! is_numeric($id)) continue; if(! array_key_exists($id, $imagegroups['image'])) { $arr = array('groups' => array(), 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; return; } $imagegroupids[] = $id; } foreach($imagegroupids as $id) { $query = "DELETE FROM resourcemap " . "WHERE resourcegroupid1 = $id AND " . "resourcetypeid1 = 13 AND " . "resourcegroupid2 = $compgrpid AND " . "resourcetypeid2 = 12"; doQuery($query, 288); } $_SESSION['userresources'] = array(); $arr = array('groups' => $imagegroupids, 'addrem' => 0); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJupdateRevisionProduction() /// /// \brief updates which revision is set as the one in production /// //////////////////////////////////////////////////////////////////////////////// function AJupdateRevisionProduction() { $imageid = getContinuationVar('imageid'); $revisionid = getContinuationVar('revisionid'); $query = "UPDATE imagerevision " . "SET production = 0 " . "WHERE imageid = $imageid"; doQuery($query, 101); $query = "UPDATE imagerevision " . "SET production = 1 " . "WHERE id = $revisionid"; doQuery($query, 101); } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJupdateRevisionComments() /// /// \brief updates the comments for a revision /// //////////////////////////////////////////////////////////////////////////////// function AJupdateRevisionComments() { $imageid = getContinuationVar('imageid'); $revisionid = getContinuationVar('revisionid'); $comments = processInputVar('comments', ARG_STRING); $comments = htmlspecialchars($comments); if(get_magic_quotes_gpc()) $comments = stripslashes($comments); $comments = mysql_real_escape_string($comments); $query = "UPDATE imagerevision " . "SET comments = '$comments' " . "WHERE id = $revisionid"; doQuery($query, 101); $arr = array('comments' => $comments, 'id' => $revisionid); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } //////////////////////////////////////////////////////////////////////////////// /// /// \fn AJdeleteRevisions() /// /// \brief sets deleted flag for submitted revisions /// //////////////////////////////////////////////////////////////////////////////// function AJdeleteRevisions() { $revids = getContinuationVar('revids'); $imageid = getContinuationVar('imageid'); $checkedids = processInputVar('checkedids', ARG_STRING); $ids = explode(',', $checkedids); foreach($ids as $id) { if(! is_numeric($id) || ! in_array($id, $revids)) { header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode(array()) . '}*/'; return; } } $query = "UPDATE imagerevision " . "SET deleted = 1 " . "WHERE id IN ($checkedids) " . "AND production != 1"; doQuery($query, 101); $html = getRevisionHTML($imageid); $arr = array('html' => $html); header('Content-Type: text/json-comment-filtered; charset=utf-8'); print '/*{"items":' . json_encode($arr) . '}*/'; } ?>