. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } class Domain_Item extends CommonDBRelation { // From CommonDBRelation static public $itemtype_1 = "Domain"; static public $items_id_1 = 'domains_id'; static public $itemtype_2 = 'itemtype'; static public $items_id_2 = 'items_id'; static $rightname = 'domain'; static function cleanForItem(CommonDBTM $item) { $temp = new self(); $temp->deleteByCriteria( ['itemtype' => $item->getType(), 'items_id' => $item->getField('id')] ); } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { if ($item->getType() == 'Domain' && count(Domain::getTypes(false)) ) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(_n('Associated item', 'Associated items', Session::getPluralNumber()), self::countForDomain($item)); } return _n('Associated item', 'Associated items', Session::getPluralNumber()); } else if ($item->getType()== 'DomainRelation' || in_array($item->getType(), Domain::getTypes(true)) && Session::haveRight('domain', READ) ) { if ($_SESSION['glpishow_count_on_tabs']) { return self::createTabEntry(Domain::getTypeName(Session::getPluralNumber()), self::countForItem($item)); } return Domain::getTypeName(2); } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Domain') { self::showForDomain($item); } else if (in_array($item->getType(), Domain::getTypes(true)) || $item->getType() == DomainRelation::getType() ) { self::showForItem($item); } return true; } static function countForDomain(Domain $item) { $types = $item->getTypes(); if (count($types) == 0) { return 0; } return countElementsInTable( 'glpi_domains_items', [ "domains_id" => $item->getID(), "itemtype" => $types ] ); } static function countForItem(CommonDBTM $item) { $criteria = []; if ($item instanceof DomainRelation) { $criteria = ['domainrelations_id' => $item->fields['id']]; } else { $criteria = [ 'itemtype' => $item->getType(), 'items_id' => $item->fields['id'] ]; } return countElementsInTable( self::getTable(), $criteria ); } function getFromDBbyDomainsAndItem($domains_id, $items_id, $itemtype) { $criteria = ['domains_id' => $domains_id]; $item = new $itemtype; if ($item instanceof DomainRelation) { $criteria += ['domainrelations_id' => $items_id]; } else { $criteria += [ 'itemtype' => $itemtype, 'items_id' => $items_id ]; } return $this->getFromDBByCrit($criteria); } function addItem($values) { $this->add([ 'domains_id' => $values['domains_id'], 'items_id' => $values['items_id'], 'itemtype' => $values['itemtype'], 'domainrelations_id' => $values['domainrelations_id'] ]); } function deleteItemByDomainsAndItem($domains_id, $items_id, $itemtype) { if ($this->getFromDBbyDomainsAndItem($domains_id, $items_id, $itemtype)) { $this->delete(['id' => $this->fields["id"]]); } } /** * Show items linked to a domain * * @param Domain $domain Domain object * * @return void **/ public static function showForDomain(Domain $domain) { global $DB; $instID = $domain->fields['id']; if (!$domain->can($instID, READ)) { return false; } $canedit = $domain->can($instID, UPDATE); $rand = mt_rand(); $iterator = $DB->request([ 'SELECT' => 'itemtype', 'DISTINCT' => true, 'FROM' => self::getTable(), 'WHERE' => ['domains_id' => $instID], 'ORDER' => 'itemtype', 'LIMIT' => count(Domain::getTypes(true)) ]); $number = count($iterator); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit) { echo "
| " . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . " | "; } echo "" . _n('Type', 'Types', 1) . " | "; echo "" . __('Name') . " | "; if (Session::isMultiEntitiesMode()) { echo "" . Entity::getTypeName(1) . " | "; } echo "" . DomainRelation::getTypeName(1) . " | "; echo "" . __('Serial number') . " | "; echo "" . __('Inventory number') . " | "; echo "
|---|---|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]); echo " | "; } echo "" . $item->getTypeName(1) . " | "; echo "" . $name . " | "; if (Session::isMultiEntitiesMode()) { echo "" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . " | "; } echo "" . Dropdown::getDropdownName("glpi_domainrelations", $data['domainrelations_id']) . " | "; echo "" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . " | "; echo "" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . " | "; echo "
| " . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . " | "; } echo "" . __('Name') . " | "; if (Session::isMultiEntitiesMode()) { echo "" . Entity::getTypeName(1) . " | "; } echo "" . __('Group in charge') . " | "; echo "" . __('Technician in charge') . " | "; echo "" . _n('Type', 'Types', 1) . " | "; if (!$item instanceof DomainRelation) { echo "" . DomainRelation::getTypeName(1) . " | "; } echo "" . __('Creation date') . " | "; echo "" . __('Expiration date') . " | "; echo "||
|---|---|---|---|---|---|---|---|---|---|---|
| "; Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]); echo " | "; } echo "$link | "; if (Session::isMultiEntitiesMode()) { echo "" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . " | "; } echo "" . Dropdown::getDropdownName("glpi_groups", $data["groups_id_tech"]) . " | "; echo "" . getUserName($data["users_id_tech"]) . " | "; echo "" . Dropdown::getDropdownName("glpi_domaintypes", $data["domaintypes_id"]) . " | "; if (!$item instanceof DomainRelation) { echo "" . Dropdown::getDropdownName("glpi_domainrelations", $data["domainrelations_id"]) . " | "; } echo "" . Html::convDate($data["date_creation"]) . " | "; if ($data["date_expiration"] <= date('Y-m-d') && !empty($data["date_expiration"]) ) { echo "" . Html::convDate($data["date_expiration"]) . " | ";
} else if (empty($data["date_expiration"])) {
echo "" . __('Does not expire') . " | "; } else { echo "" . Html::convDate($data["date_expiration"]) . " | "; } echo "