grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Disk Class **/ class ComputerDisk extends CommonDBChild { // From CommonDBChild static public $itemtype = 'Computer'; static public $items_id = 'computers_id'; public $dohistory = true; static function getTypeName($nb=0) { return _n('Volume', 'Volumes', $nb); } function post_getEmpty() { $this->fields["totalsize"] = '0'; $this->fields["freesize"] = '0'; } /** * @see CommonGLPI::getTabNameForItem() **/ function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { // can exists for template if (($item->getType() == 'Computer') && Computer::canView()) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable('glpi_computerdisks', "computers_id = '".$item->getID()."' AND `is_deleted`='0'"); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return ''; } /** * @param $item CommonGLPI object * @param $tabnum (default 1) * @param $withtemplate (default 0) */ static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { self::showForComputer($item, $withtemplate); return true; } /** * @see CommonGLPI::defineTabs() * * @since version 0.85 **/ function defineTabs($options=array()) { $ong = array(); $this->addDefaultFormTab($ong); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * Duplicate all disks from a computer template to his clone * * @since version 0.84 * * @param $oldid * @param $newid **/ static function cloneComputer ($oldid, $newid) { global $DB; $query = "SELECT * FROM `glpi_computerdisks` WHERE `computers_id` = '$oldid'"; foreach ($DB->request($query) as $data) { $cd = new self(); unset($data['id']); $data['computers_id'] = $newid; $data = Toolbox::addslashes_deep($data); $cd->add($data); } } /** * Print the version form * * @param $ID integer ID of the item * @param $options array * - target for the Form * - computers_id ID of the computer for add process * * @return true if displayed false if item not found or not right to display **/ function showForm($ID, $options=array()) { global $CFG_GLPI; if (!Session::haveRight("computer", UPDATE)) { return false; } $comp = new Computer(); if ($ID > 0) { $this->check($ID, READ); $comp->getFromDB($this->fields['computers_id']); } else { $this->check(-1, CREATE, $options); $comp->getFromDB($options['computers_id']); } $this->showFormHeader($options); if ($this->isNewID($ID)) { echo ""; } echo ""; echo "".__('Computer').""; echo "".$comp->getLink().""; if (Plugin::haveImport()) { echo "".__('Automatic inventory').""; echo ""; if ($ID && $this->fields['is_dynamic']) { Plugin::doHook("autoinventory_information", $this); } else { _e('No'); } echo ""; } else { echo ""; } echo "\n"; echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name"); echo "".__('Partition').""; echo ""; Html::autocompletionTextField($this, "device"); echo ""; echo ""; echo "".__('Mount point').""; echo ""; Html::autocompletionTextField($this, "mountpoint"); echo "".__('File system').""; echo ""; FileSystem::dropdown(array('value' => $this->fields["filesystems_id"])); echo ""; echo ""; echo "".__('Global size').""; echo ""; Html::autocompletionTextField($this, "totalsize"); echo " ".__('Mio').""; echo "".__('Free size').""; echo ""; Html::autocompletionTextField($this, "freesize"); echo " ".__('Mio').""; $this->showFormButtons($options); return true; } /** * Print the computers disks * * @param $comp Computer object * @param $withtemplate boolean Template or basic item (default '') * * @return Nothing (call to classes members) **/ static function showForComputer(Computer $comp, $withtemplate='') { global $DB; $ID = $comp->fields['id']; if (!$comp->getFromDB($ID) || !$comp->can($ID, READ)) { return false; } $canedit = $comp->canEdit($ID); if ($canedit && !(!empty($withtemplate) && ($withtemplate == 2))) { echo "
". ""; _e('Add a volume'); echo "
\n"; } echo "
"; $query = "SELECT `glpi_filesystems`.`name` AS fsname, `glpi_computerdisks`.* FROM `glpi_computerdisks` LEFT JOIN `glpi_filesystems` ON (`glpi_computerdisks`.`filesystems_id` = `glpi_filesystems`.`id`) WHERE `computers_id` = '$ID' AND `is_deleted` = '0'"; if ($result = $DB->query($query)) { echo ""; $colspan = 7; if (Plugin::haveImport()) { $colspan++; } echo ""; if ($DB->numrows($result)) { $header = ""; if (Plugin::haveImport()) { $header .= ""; } $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; $header .= ""; echo $header; Session::initNavigateListItems(__CLASS__, //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Computer::getTypeName(1), $comp->getName())); $disk = new self(); while ($data = $DB->fetch_assoc($result)) { $disk->getFromDB($data['id']); echo ""; echo ""; if (Plugin::haveImport()) { echo ""; } echo ""; echo ""; echo ""; //TRANS: %s is a size $tmp = Toolbox::getSize($data['totalsize'] * 1024 * 1024); echo ""; $tmp = Toolbox::getSize($data['freesize'] * 1024 * 1024); echo ""; echo ""; echo ""; Session::addToNavigateListItems(__CLASS__, $data['id']); } echo $header; } else { echo ""; } echo "
".self::getTypeName($DB->numrows($result)). "
".__('Name')."".__('Automatic inventory')."".__('Partition')."".__('Mount point')."".__('File system')."".__('Global size')."".__('Free size')."".__('Free percentage')."
".$disk->getLink()."".Dropdown::getYesNo($data['is_dynamic'])."".$data['device']."".$data['mountpoint']."".$data['fsname']."$tmp$tmp"; $percent = 0; if ($data['totalsize'] > 0) { $percent = round(100*$data['freesize']/$data['totalsize']); } Html::displayProgressBar('100', $percent, array('simple' => true, 'forcepadding' => false)); echo "
".__('No item found')."
"; } echo "

"; } } ?>