. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * DCRoom Class **/ class DCRoom extends CommonDBTM { use Glpi\Features\DCBreadcrumb; // From CommonDBTM public $dohistory = true; protected $usenotepad = true; static $rightname = 'datacenter'; static function getTypeName($nb = 0) { //TRANS: Test of comment for translation (mark : //TRANS) return _n('Server room', 'Server rooms', $nb); } function defineTabs($options = []) { $ong = []; $this ->addStandardTab('Rack', $ong, $options) ->addDefaultFormTab($ong) ->addImpactTab($ong, $options) ->addStandardTab('Infocom', $ong, $options) ->addStandardTab('Contract_Item', $ong, $options) ->addStandardTab('Document_Item', $ong, $options) ->addStandardTab('Link', $ong, $options) ->addStandardTab('Ticket', $ong, $options) ->addStandardTab('Item_Problem', $ong, $options) ->addStandardTab('Change_Item', $ong, $options) ->addStandardTab('Log', $ong, $options); return $ong; } function showForm($ID, $options = []) { global $DB, $CFG_GLPI; $rand = mt_rand(); $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo ""; echo ""; Html::autocompletionTextField($this, "name", ['rand' => $rand]); echo ""; echo ""; echo ""; Location::dropdown([ 'value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"], 'rand' => $rand ]); echo ""; echo ""; echo ""; echo ""; echo ""; $datacenters = $DB->request([ 'SELECT' => ['id', 'name'], 'FROM' => Datacenter::getTable() ]); $datacenters_list = []; while ($row = $datacenters->next()) { $datacenters_list[$row['id']] = $row['name']; } Dropdown::showFromArray( "datacenters_id", $datacenters_list, [ 'value' => $this->fields["datacenters_id"], 'rand' => $rand, 'display_emptychoice' => true ] ); Ajax::updateItemOnSelectEvent( "dropdown_datacenters_id$rand", "dropdown_locations_id$rand", $CFG_GLPI["root_doc"]."/ajax/dropdownLocation.php", [ 'items_id' => '__VALUE__', 'itemtype' => 'Datacenter' ] ); echo ""; echo ""; echo ""; echo ""; echo ""; Dropdown::showNumber( "vis_cols", [ 'value' => $this->fields["vis_cols"], 'min' => 1, 'max' => 100, 'step' => 1, 'rand' => $rand ] ); echo ""; echo ""; Dropdown::showNumber( "vis_rows", [ 'value' => $this->fields["vis_rows"], 'min' => 1, 'max' => 100, 'step' => 1, 'rand' => $rand ] ); echo ""; echo ""; echo ""; echo ""; if (!empty($this->fields['blueprint'])) { echo Html::image(Toolbox::getPictureUrl($this->fields['blueprint']), [ 'style' => 'max-width: 100px; max-height: 50px;', 'class' => 'picture_square' ]); echo " "; echo Html::getCheckbox([ 'title' => __('Clear'), 'name' => '_blank_blueprint' ]); echo " ".__('Clear'); } else { echo Html::file([ 'name' => 'blueprint', 'onlyimages' => true, ]); } echo ""; echo ""; echo ""; $this->showFormButtons($options); return true; } function prepareInputForAdd($input) { return $this->manageBlueprint($input); } function prepareInputForUpdate($input) { return $this->manageBlueprint($input); } function cleanDBonPurge() { Toolbox::deletePicture($this->fields['blueprint']); } /** * Add/remove blueprint picture * @param array $input the form input * @return array the altered input */ function manageBlueprint($input) { if (isset($input["_blank_blueprint"]) && $input["_blank_blueprint"]) { $input['blueprint'] = ''; if (array_key_exists('blueprint', $this->fields)) { Toolbox::deletePicture($this->fields['blueprint']); } } if (isset($input["_blueprint"])) { $blueprint = array_shift($input["_blueprint"]); if ($dest = Toolbox::savePicture(GLPI_TMP_DIR . '/' . $blueprint)) { $input['blueprint'] = $dest; } else { Session::addMessageAfterRedirect(__('Unable to save picture file.'), true, ERROR); } if (array_key_exists('blueprint', $this->fields)) { Toolbox::deletePicture($this->fields['blueprint']); } } return $input; } function rawSearchOptions() { $tab = []; $tab[] = [ 'id' => 'common', 'name' => __('Characteristics') ]; $tab[] = [ 'id' => '1', 'table' => $this->getTable(), 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', 'massiveaction' => false, // implicit key==1 'autocomplete' => true, ]; $tab[] = [ 'id' => '2', 'table' => $this->getTable(), 'field' => 'id', 'name' => __('ID'), 'massiveaction' => false, // implicit field is id 'datatype' => 'number' ]; $tab = array_merge($tab, Location::rawSearchOptionsToAdd()); $tab[] = [ 'id' => '4', 'table' => Datacenter::getTable(), 'field' => 'name', 'name' => Datacenter::getTypeName(1), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '5', 'table' => $this->getTable(), 'field' => 'vis_cols', 'name' => __('Number of columns'), 'datatype' => 'number' ]; $tab[] = [ 'id' => '6', 'table' => $this->getTable(), 'field' => 'vis_rows', 'name' => __('Number of rows'), 'datatype' => 'number' ]; $tab[] = [ 'id' => '19', 'table' => $this->getTable(), 'field' => 'date_mod', 'name' => __('Last update'), 'datatype' => 'datetime', 'massiveaction' => false ]; $tab[] = [ 'id' => '121', 'table' => $this->getTable(), 'field' => 'date_creation', 'name' => __('Creation date'), 'datatype' => 'datetime', 'massiveaction' => false ]; $tab[] = [ 'id' => '80', 'table' => 'glpi_entities', 'field' => 'completename', 'name' => Entity::getTypeName(1), 'datatype' => 'dropdown' ]; $tab = array_merge($tab, Notepad::rawSearchOptionsToAdd()); $tab = array_merge($tab, Datacenter::rawSearchOptionsToAdd(get_class($this))); return $tab; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch ($item->getType()) { case Datacenter::getType(): $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb =countElementsInTable( self::getTable(), [ 'datacenters_id' => $item->getID(), 'is_deleted' => 0 ] ); } return self::createTabEntry( self::getTypeName(Session::getPluralNumber()), $nb ); break; } } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showForDatacenter($item); } /** * Print datacenter's roms * * @param Datacenter $datacenter Datacenter object * * @return void **/ static function showForDatacenter(Datacenter $datacenter) { global $DB; $ID = $datacenter->getID(); $rand = mt_rand(); if (!$datacenter->getFromDB($ID) || !$datacenter->can($ID, READ)) { return false; } $canedit = $datacenter->canEdit($ID); $rooms = $DB->request([ 'FROM' => self::getTable(), 'WHERE' => [ 'datacenters_id' => $datacenter->getID() ] ]); echo "
"; Html::showSimpleForm(self::getFormURL(), '_add_fromitem', __('New room for this datacenter...'), ['datacenters_id' => $datacenter->getID()]); echo "
"; if ($canedit) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = [ 'num_displayed' => min($_SESSION['glpilist_limit'], count($rooms)), 'container' => 'mass'.__CLASS__.$rand ]; Html::showMassiveActions($massiveactionparams); } Session::initNavigateListItems( self::getType(), //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'), $datacenter->getTypeName(1), $datacenter->getName() ) ); if (!count($rooms)) { echo ""; echo "
".__('No server room found')."
"; } else { echo ""; $header = ""; if ($canedit) { $header .= ""; } $header .= ""; $header .= ""; $dcroom = new self(); echo $header; while ($room = $rooms->next()) { $dcroom->getFromResultSet($room); echo ""; if ($canedit) { echo ""; } echo ""; echo ""; } echo $header; echo "
"; $header .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header .= "".__('Name')."
"; Html::showMassiveActionCheckBox(__CLASS__, $room["id"]); echo "" . $dcroom->getLink() . "
"; } if ($canedit && count($rooms)) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } if ($canedit) { Html::closeForm(); } } /** * Get already filled places * * @param string $current Current position to exclude; defaults to null * * @return array [x => [pos_x], y => [pos_y]]] */ public function getFilled($current = null) { global $DB; $iterator = $DB->request([ 'FROM' => Rack::getTable(), 'WHERE' => [ 'dcrooms_id' => $this->getID(), 'is_deleted' => 0 ] ]); $filled = []; while ($rack = $iterator->next()) { if (preg_match('/(\d+),\s?(\d+)/', $rack['position'])) { $position = $rack['position']; if (empty($current) || $current != $position) { $filled[$position] = $position; } } } return $filled; } /** * Get all possible positions for current room * * @return array */ public function getAllPositions() { $positions = []; for ($x = 1; $x < (int)$this->fields['vis_cols'] + 1; ++$x) { for ($y = 1; $y < (int)$this->fields['vis_rows'] + 1; ++$y) { $positions["$x,$y"] = sprintf( __('col: %1$s, row: %2$s'), Toolbox::getBijectiveIndex($x), $y ); } } return $positions; } }