. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } class DomainRecord extends CommonDBChild { const DEFAULT_TTL = 3600; static $rightname = 'domain'; // From CommonDBChild static public $itemtype = 'Domain'; static public $items_id = 'domains_id'; public $dohistory = true; static function getTypeName($nb = 0) { return _n('Domain record', 'Domains records', $nb); } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { if ($item->getType() == 'Domain') { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(_n('Record', 'Records', Session::getPluralNumber()), self::countForDomain($item)); } return _n('Record', 'Records', Session::getPluralNumber()); } } return ''; } static function countForDomain(Domain $item) { return countElementsInTable( self::getTable(), [ "domains_id" => $item->getID(), ] ); } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Domain') { self::showForDomain($item); } return true; } function rawSearchOptions() { $tab = []; $tab = array_merge($tab, parent::rawSearchOptions()); $tab[] = [ 'id' => '2', 'table' => 'glpi_domains', 'field' => 'name', 'name' => Domain::getTypeName(1), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '3', 'table' => DomainRecordType::getTable(), 'field' => 'name', 'name' => DomainRecordType::getTypeName(1), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '4', 'table' => $this->getTable(), 'field' => 'ttl', 'name' => __('TTL'), 'datatype' => 'number' ]; $tab[] = [ 'id' => '11', 'table' => $this->getTable(), 'field' => 'data', 'name' => __('Data'), ]; $tab[] = [ 'id' => '6', 'table' => 'glpi_users', 'field' => 'name', 'linkfield' => 'users_id_tech', 'name' => __('Technician in charge'), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '7', 'table' => $this->getTable(), 'field' => 'date_creation', 'name' => __('Creation date'), 'datatype' => 'date' ]; $tab[] = [ 'id' => '8', 'table' => $this->getTable(), 'field' => 'comment', 'name' => __('Comments'), 'datatype' => 'text' ]; $tab[] = [ 'id' => '9', 'table' => 'glpi_groups', 'field' => 'name', 'linkfield' => 'groups_id_tech', 'name' => __('Group in charge'), 'datatype' => 'dropdown' ]; $tab[] = [ 'id' => '10', 'table' => $this->getTable(), 'field' => 'date_mod', 'massiveaction' => false, 'name' => __('Last update'), 'datatype' => 'datetime' ]; $tab[] = [ 'id' => '80', 'table' => 'glpi_entities', 'field' => 'completename', 'name' => Entity::getTypeName(1), 'datatype' => 'dropdown' ]; return $tab; } static function canCreate() { if (count($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'])) { return true; } return parent::canCreate(); } static function canUpdate() { if (count($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'])) { return true; } return parent::canUpdate(); } static function canDelete() { if (count($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'])) { return true; } return parent::canDelete(); } static function canPurge() { if (count($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'])) { return true; } return parent::canPurge(); } public function canCreateItem() { return count($_SESSION['glpiactiveprofile']['managed_domainrecordtypes']); } public function canUpdateItem() { return parent::canUpdateItem() && ($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'] == [-1] || in_array($this->fields['domainrecordtypes_id'], $_SESSION['glpiactiveprofile']['managed_domainrecordtypes']) ); } function canDeleteItem() { return parent::canDeleteItem() && ($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'] == [-1] || in_array($this->fields['domainrecordtypes_id'], $_SESSION['glpiactiveprofile']['managed_domainrecordtypes']) ); } function canPurgeItem() { return parent::canPurgeItem() && ($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'] == [-1] || in_array($this->fields['domainrecordtypes_id'], $_SESSION['glpiactiveprofile']['managed_domainrecordtypes']) ); } function defineTabs($options = []) { $ong = []; $this->addDefaultFormTab($ong); $this->addStandardTab('Ticket', $ong, $options); $this->addStandardTab('Item_Problem', $ong, $options); $this->addStandardTab('Document_Item', $ong, $options); $this->addStandardTab('Link', $ong, $options); $this->addStandardTab('Notepad', $ong, $options); $this->addStandardTab('Log', $ong, $options); return $ong; } /** * Prepare input for add and update * * @param array $input Input values * @param boolean $add True when we're adding a record * * @return aray|false */ private function prepareInput($input, $add = false) { if ($add) { if (isset($input['date_creation']) && empty($input['date_creation'])) { $input['date_creation'] = 'NULL'; } if (!isset($input['ttl']) || empty($input['ttl'])) { $input['ttl'] = self::DEFAULT_TTL; } } //search entity if ($add && !isset($input['entities_id'])) { $input['entities_id'] = $_SESSION['glpiactive_entity'] ?? 0; $input['is_recursive'] = $_SESSION['glpiactive_entity_recursive'] ?? 0; $domain = new Domain(); if (isset($input['domains_id']) && $domain->getFromDB($input['domains_id'])) { $input['entities_id'] = $domain->fields['entities_id']; $input['is_recursive'] = $domain->fields['is_recursive']; } } if (!Session::isCron() && (isset($input['domainrecordtypes_id']) || isset($this->fields['domainrecordtypes_id']))) { if (!($_SESSION['glpiactiveprofile']['managed_domainrecordtypes'] == [-1])) { if (isset($input['domainrecordtypes_id']) && !(in_array($input['domainrecordtypes_id'], $_SESSION['glpiactiveprofile']['managed_domainrecordtypes']))) { //no right to use selected type Session::addMessageAfterRedirect( __('You are not allowed to use this type of records'), true, ERROR ); return false; } if ($add === false && !(in_array($this->fields['domainrecordtypes_id'], $_SESSION['glpiactiveprofile']['managed_domainrecordtypes']))) { //no right to change existing type Session::addMessageAfterRedirect( __('You are not allowed to edit this type of records'), true, ERROR ); return false; } } } return $input; } function prepareInputForAdd($input) { return $this->prepareInput($input, true); } function prepareInputForUpdate($input) { return $this->prepareInput($input); } function showForm($ID, $options = []) { $this->initForm($ID, $options); $this->showFormHeader($options); echo "
| " . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . " | "; } echo "" . _n('Type', 'Types', 1) . " | "; echo "" . __('Name') . " | "; echo "" . __('TTL') . " | "; echo "" . _n('Target', 'Targets', 1) . " | "; echo "
|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["id"]); echo " | "; } echo "" . Dropdown::getDropdownName(DomainRecordType::getTable(), $data['domainrecordtypes_id']) . " | "; echo "" . $name . " | "; echo "" . $data['ttl'] . " | "; echo "" . $data['data'] . " | "; echo "