\n";
print "
$title
\n";
print "$question
\n";
print "
\n";
/*print " \n";
print " Short Name: | \n";
print " " . $images[$imageid]["name"] . " | \n";
print "
\n";*/
print " \n";
print " Long Name: | \n";
print " " . $images[$imageid]["prettyname"] . " | \n";
print "
\n";
print " \n";
print " Owner: | \n";
print " " . $images[$imageid]["owner"] . " | \n";
print "
\n";
print " \n";
print " Platform: | \n";
print " " . $platforms[$images[$imageid]["platformid"]] . " | \n";
print "
\n";
print " \n";
print " OS: | \n";
print " " . $oslist[$images[$imageid]["osid"]]["prettyname"] . " | \n";
print "
\n";
print " \n";
print " Minimum RAM (MB): | \n";
print " " . $images[$imageid]["minram"] . " | \n";
print "
\n";
print " \n";
print " Minimum Num of Processors: | \n";
print " " . $images[$imageid]["minprocnumber"] . " | \n";
print "
\n";
print " \n";
print " Minimum Processor Speed (MHz): | \n";
print " " . $images[$imageid]["minprocspeed"] . " | \n";
print "
\n";
print " \n";
print " Minimum Network Speed (Mbps): | \n";
print " " . $images[$imageid]["minnetwork"] . " | \n";
print "
\n";
print " \n";
print " Estimated Reload Time (min): | \n";
print " " . $images[$imageid]["reloadtime"] . " | \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 " Short Name: | \n";
print " " . $images[$imageid]["name"] . " | \n";
print "
\n";*/
print " \n";
print " Long Name: | \n";
print " " . $images[$imageid]["prettyname"] . " | \n";
print "
\n";
print " \n";
print " Owner: | \n";
print " " . $images[$imageid]["owner"] . " | \n";
print "
\n";
print " \n";
print " Platform: | \n";
print " " . $platforms[$images[$imageid]["platformid"]] . " | \n";
print "
\n";
print " \n";
print " OS: | \n";
print " " . $oslist[$images[$imageid]["osid"]]["prettyname"] . " | \n";
print "
\n";
print " \n";
print " Minimum RAM (MB): | \n";
print " " . $images[$imageid]["minram"] . " | \n";
print "
\n";
print " \n";
print " Minimum Num of Processors: | \n";
print " " . $images[$imageid]["minprocnumber"] . " | \n";
print "
\n";
print " \n";
print " Minimum Processor Speed (MHz): | \n";
print " " . $images[$imageid]["minprocspeed"] . " | \n";
print "
\n";
print " \n";
print " Minimum Network Speed (Mbps): | \n";
print " " . $images[$imageid]["minnetwork"] . " | \n";
print "
\n";
print " \n";
print " Maximum Concurrent Usage: | \n";
if($images[$imageid]['maxconcurrent'] == '')
print " N/A | \n";
else
print " " . $images[$imageid]["maxconcurrent"] . " | \n";
print "
\n";
print " \n";
print " Estimated Reload Time (min): | \n";
print " " . $images[$imageid]["reloadtime"] . " | \n";
print "
\n";
print " \n";
print " Available for checkout: | \n";
if($images[$imageid]["forcheckout"])
print " yes | \n";
else
print " no | \n";
print "
\n";
print " \n";
print " Check for logged in user: | \n";
if(array_key_exists("checkuser", $images[$imageid]) &&
$images[$imageid]["checkuser"] == 0)
print " no | \n";
else
print " yes | \n";
print "
\n";
print " \n";
print " Users have administrative access: | \n";
if(array_key_exists("rootaccess", $images[$imageid]) &&
$images[$imageid]["rootaccess"] == 0)
print " no | \n";
else
print " yes | \n";
print "
\n";
if($oslist[$images[$imageid]["osid"]]["type"] == 'windows') {
print " \n";
print " Use sysprep: | \n";
if(array_key_exists("sysprep", $images[$imageid]) &&
$images[$imageid]["sysprep"] == 0)
print " no | \n";
else
print " yes | \n";
print "
\n";
}
if(array_key_exists("subimages", $images[$imageid]) &&
count($images[$imageid]["subimages"])) {
print " \n";
print " ";
print "Subimages: | \n";
print " \n";
foreach($images[$imageid]["subimages"] as $imgid) {
print "{$images[$imgid]["prettyname"]} \n";
}
print " | \n";
print "
\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("manageMapping"), 1);
$imagegroups = $tmp["image"];
$tmp = getUserResources(array("computerAdmin"),
array("manageMapping"), 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["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['rootaccess'] == 0)) {
$query = "INSERT INTO imagemeta "
. "(checkuser, "
. "rootaccess) "
. "VALUES ({$data["checkuser"]}, "
. "{$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"]) {
$query = "UPDATE imagemeta "
. "SET checkuser = {$data["checkuser"]}, "
. "rootaccess = {$data["rootaccess"]} "
. "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']);
# get architecture of base image
$query = "SELECT i.architecture "
. "FROM image i, "
. "imagerevision ir "
. "WHERE ir.imageid = i.id AND "
. "ir.id = {$data['basedoffrevisionid']}";
$qh = doQuery($query, 101);
$row = mysql_fetch_assoc($qh);
$arch = $row['architecture'];
$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, "
. "architecture, "
. "description, "
. "`usage`, "
. "basedoffrevisionid) "
. "VALUES ('{$data["prettyname"]}', "
. "$ownerid, "
. "{$data["platformid"]}, "
. "{$data["osid"]}, "
. "{$data["minram"]}, "
. "{$data["minprocnumber"]}, "
. "{$data["minprocspeed"]}, "
. "{$data["minnetwork"]}, "
. "{$data["maxconcurrent"]}, "
. "{$data["reloadtime"]}, "
. "1, "
. "'$arch', "
. "'{$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($data['sysprep'] != 0 && $data['sysprep'] != 1)
$data['sysprep'] = 1;
if($data['checkuser'] == 0 ||
$data['rootaccess'] == 0 ||
$data['sysprep'] == 0) {
$query = "INSERT INTO imagemeta "
. "(checkuser, "
. "rootaccess, "
. "sysprep) "
. "VALUES "
. "({$data['checkuser']}, "
. "{$data['rootaccess']}, "
. "{$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());
sendJSON($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);
sendJSON($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());
sendJSON($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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($imagegrpid, $resources['image'])) {
$arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array());
sendJSON($arr);
return;
}
$compgroups = getUserResources(array('computerAdmin'), array('manageMapping'), 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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($compgrpid, $resources['computer'])) {
$arr = array('ingroups' => array(), 'outgroups' => array(), 'all' => array());
sendJSON($arr);
return;
}
$imagegroups = getUserResources(array('imageAdmin'), array('manageMapping'), 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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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']);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($imagegrpid, $resources['image'])) {
$arr = array('groups' => array(), 'addrem' => 1);
sendJSON($arr);
return;
}
$compgroups = getUserResources(array("computerAdmin"), array("manageMapping"), 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);
sendJSON($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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($imagegrpid, $resources['image'])) {
$arr = array('groups' => array(), 'addrem' => 0);
sendJSON($arr);
return;
}
$compgroups = getUserResources(array("computerAdmin"), array("manageMapping"), 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);
sendJSON($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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($compgrpid, $resources['computer'])) {
$arr = array('groups' => array(), 'addrem' => 1);
sendJSON($arr);
return;
}
$imagegroups = getUserResources(array("imageAdmin"), array("manageMapping"), 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);
sendJSON($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);
sendJSON($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("manageMapping"), 1);
if(! array_key_exists($compgrpid, $resources['computer'])) {
$arr = array('groups' => array(), 'addrem' => 0);
sendJSON($arr);
return;
}
$imagegroups = getUserResources(array("imageAdmin"), array("manageMapping"), 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);
sendJSON($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);
sendJSON($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);
sendJSON($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)) {
sendJSON(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);
sendJSON($arr);
}
?>