restype = 'image';
$this->restypename = 'Image';
$this->namefield = 'prettyname';
$this->hasmapping = 1;
$this->maptype = 'computer';
$this->maptypename = 'Computer';
$this->defaultGetDataArgs = array('includedeleted' => 0,
'rscid' => 0);
$this->basecdata['obj'] = $this;
$this->addable = 0;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn getData($args)
///
/// \param $args - array of arguments that determine what data gets returned;
/// must include:\n
/// \b includedeleted - 0 or 1; include deleted images\n
/// \b rscid - only return data for resource with this id; pass 0 for all
/// (from image table)
///
/// \return array of data as returned from getImages
///
/// \brief wrapper for calling getImages
///
/////////////////////////////////////////////////////////////////////////////
function getData($args) {
$data = getImages($args['includedeleted'], $args['rscid']);
$noimageid = getImageId('noimage');
if($noimageid)
unset($data[$noimageid]);
return $data;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn fieldWidth($field)
///
/// \param $field - name of a resource field
///
/// \return string for setting width of field (includes width= part)
///
/// \brief generates the required width for the field; can return an empty
/// string if field should default to auto width
///
/////////////////////////////////////////////////////////////////////////////
function fieldWidth($field) {
switch($field) {
case 'owner':
$w = 12;
break;
case 'os':
$w = 8;
break;
case 'addomain':
$w = 10;
break;
case 'baseOU':
$w = 12;
break;
case 'adauthenabled':
$w = 9;
break;
default:
return '';
}
if(preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT']) ||
preg_match('/Trident/i', $_SERVER['HTTP_USER_AGENT']) ||
preg_match('/Edge/i', $_SERVER['HTTP_USER_AGENT']))
$w = round($w * 11.5) . 'px';
else
$w = "{$w}em";
return "width=\"$w\"";
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn fieldDisplayName($field)
///
/// \param $field - name of a resource field
///
/// \return display value for $field
///
/// \brief generates the display value for $field
///
/////////////////////////////////////////////////////////////////////////////
function fieldDisplayName($field) {
switch($field) {
case 'os':
return i("OS");
case 'installtype':
return i("Install Type");
case 'ostype':
return i("OS Type");
case 'minram':
return i("Required RAM");
case 'minprocnumber':
return i("Required Cores");
case 'minprocspeed':
return i("Processor Speed");
case 'minnetwork':
return i("Min. Network Speed");
case 'maxconcurrent':
return i("Max Concurrent Usage");
case 'reloadtime':
return i("Est. Reload Time");
case 'lastupdate':
return i("Last Updated");
case 'forcheckout':
return i("Available for Checkout");
case 'maxinitialtime':
return i("Max Initial Time");
case 'checkuser':
return i("Check Logged in User");
case 'rootaccess':
return i("Admin. Access");
case 'sethostname':
return i("Set Hostname");
case 'adauthenabled':
return i("Use AD Authentication");
case 'addomain':
return i("AD Domain");
case 'baseOU':
return i("Base OU");
}
return i(ucfirst($field));
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn checkResourceInUse($rscid)
///
/// \return empty string if not being used; string of where resource is
/// being used if being used
///
/// \brief checks to see if an image is being used
///
/////////////////////////////////////////////////////////////////////////////
function checkResourceInUse($rscid) {
$msgs = array();
# check reservations
$query = "SELECT rq.end "
. "FROM request rq, "
. "reservation rs "
. "WHERE rs.requestid = rq.id AND "
. "rs.imageid = $rscid AND "
. "rq.stateid NOT IN (1, 12) AND "
. "rq.end > NOW() "
. "ORDER BY rq.end DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh))
$msgs[] = sprintf(i("There is at least one reservation for this image. The latest end time is %s."), prettyDatetime($row['end'], 1));;
# check blockComputers
$query = "SELECT br.name, "
. "bt.end "
. "FROM blockRequest br, "
. "blockTimes bt, "
. "blockComputers bc "
. "WHERE bc.imageid = $rscid AND "
. "bc.blockTimeid = bt.id AND "
. "bt.blockRequestid = br.id AND "
. "bt.end > NOW() AND "
. "bt.skip = 0 AND "
. "br.status = 'accepted' "
. "ORDER BY bt.end DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh))
$msgs[] = sprintf(i("There is at least one Block Allocation with computers currently allocated with this image. Block Allocation %s has the latest end time which is %s."), $row['name'], prettyDatetime($row['end'], 1));
# check blockRequest
$query = "SELECT br.name, "
. "bt.end "
. "FROM blockRequest br, "
. "blockTimes bt "
. "WHERE br.imageid = $rscid AND "
. "bt.blockRequestid = br.id AND "
. "bt.end > NOW() AND "
. "bt.skip = 0 AND "
. "br.status = 'accepted' "
. "ORDER BY bt.end DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh))
$msgs[] = sprintf(i("There is at least one Block Allocation configured to use this image. Block Allocation %s has the latest end time which is %s."), $row['name'], prettyDatetime($row['end'], 1));
# check serverprofile
$query = "SELECT name "
. "FROM serverprofile "
. "WHERE imageid = $rscid";
$qh = doQuery($query);
$profiles = array();
while($row = mysql_fetch_assoc($qh))
$profiles[] = $row['name'];
if(count($profiles))
$msgs[] = i("The following Server Profiles are configured to use this image:") . "
\n" . implode("
\n", $profiles);
# check subimages
$query = "SELECT DISTINCT i.prettyname "
. "FROM image i, "
. "imagemeta im, "
. "subimages s "
. "WHERE i.imagemetaid = im.id AND "
. "im.subimages = 1 AND "
. "s.imagemetaid = im.id AND "
. "s.imageid = $rscid";
$images = array();
while($row = mysql_fetch_assoc($qh))
$images[] = $row['prettyname'];
if(count($images))
$msgs[] = i("The following images have the selected image assigned as a subimage:") . "
\n" . implode("
\n", $images);
# check vmprofile
$query = "SELECT profilename "
. "FROM vmprofile "
. "WHERE imageid = $rscid";
$profiles = array();
while($row = mysql_fetch_assoc($qh))
$profiles[] = $row['profilename'];
if(count($profiles))
$msgs[] = i("The following VM Host Profiles have the this image selected:") . "
\n" . implode("
\n", $profiles);
if(empty($msgs))
return '';
$msg = i("The selected image is currently being used in the following ways and cannot be deleted at this time.") . "
\n";
$msg .= implode("
\n", $msgs) . "
\n";
return $msg;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn submitToggleDeleteResourceExtra($rscid, $deleted)
///
/// \param $rscid - id of a resource (from image table)
/// \param $deleted - (optional, default=0) 1 if resource was previously
/// deleted; 0 if not
///
/// \brief handles deleted flag for cooresponding entries in imagerevision
/// table
///
/////////////////////////////////////////////////////////////////////////////
function submitToggleDeleteResourceExtra($rscid, $deleted=0) {
if($deleted) {
$query = "UPDATE imagerevision i1, "
. "imagerevision i2 "
. "SET i1.deleted = 0, "
. "i1.datedeleted = NULL "
. "WHERE i1.imageid = $rscid AND "
. "i2.imageid = $rscid AND "
. "i2.production = 1 AND "
. "i1.datedeleted = i2.datedeleted";
}
else {
$query = "UPDATE imagerevision "
. "SET deleted = 1, "
. "datedeleted = NOW() "
. "WHERE imageid = $rscid AND "
. "deleted = 0";
}
doQuery($query);
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn extraSelectAdminOptions()
///
/// \return html
///
/// \brief generates HTML for option to create/update an image
///
/////////////////////////////////////////////////////////////////////////////
function extraSelectAdminOptions() {
$h = '';
$cdata = array('imaging' => 1);
$cont = addContinuationsEntry("viewRequests", $cdata);
$h .= "
\n";
return $h;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn addEditDialogHTML($add)
///
/// \param $add (optional, defaul=0) - 0 for edit, 1 for add
///
/// \brief generates HTML for dialog used to edit resource
///
/////////////////////////////////////////////////////////////////////////////
function addEditDialogHTML($add=0) {
global $user;
# dialog for on page editing
$h = '';
$h .= "