. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Change_Item Class * * Relation between Changes and Items **/ class Change_Item extends CommonDBRelation{ // From CommonDBRelation static public $itemtype_1 = 'Change'; static public $items_id_1 = 'changes_id'; static public $itemtype_2 = 'itemtype'; static public $items_id_2 = 'items_id'; static public $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS; function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } function prepareInputForAdd($input) { // Well, if I remember my PHP: empty(0) == true ... if (empty($input['changes_id']) || ($input['changes_id'] == 0)) { return false; } // Avoid duplicate entry if (countElementsInTable($this->getTable(), ['changes_id' => $input['changes_id'], 'itemtype' => $input['itemtype'], 'items_id' => $input['items_id']])>0) { return false; } return parent::prepareInputForAdd($input); } /** * Print the HTML array for Items linked to a change * * @param $change Change object * * @return boolean|void **/ static function showForChange(Change $change) { $instID = $change->fields['id']; if (!$change->can($instID, READ)) { return false; } $canedit = $change->canEdit($instID); $rand = mt_rand(); $types_iterator = self::getDistinctTypes($instID); $number = count($types_iterator); if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
".__('Add an item')."
"; $types = []; foreach (array_keys($change->getAllTypesForHelpdesk()) as $key) { $types[] = $key; } Dropdown::showSelectItemFromItemtypes(['itemtypes' => $types, 'entity_restrict' => ($change->fields['is_recursive'] ?getSonsOf('glpi_entities', $change->fields['entities_id']) :$change->fields['entities_id'])]); echo ""; echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } echo "
"; if ($canedit && $number) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['container' => 'mass'.__CLASS__.$rand]; Html::showMassiveActions($massiveactionparams); } echo ""; $header_begin = ""; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit && $number) { $header_top .= ""; $header_bottom .= ""; } $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; echo $header_begin.$header_top.$header_end; while ($type_row = $types_iterator->next()) { $itemtype = $type_row['itemtype']; if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $iterator = self::getTypeItems($instID, $itemtype); $nb = count($iterator); $prem = true; while ($data = $iterator->next()) { $link = $itemtype::getFormURLWithID($data['id']); $linkname = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $name = "".$linkname.""; echo ""; if ($canedit) { echo ""; } if ($prem) { $itemname = $item->getTypeName($nb); echo ""; $prem = false; } echo ""; echo ""; echo ""; echo ""; echo ""; } } } if ($number) { echo $header_begin.$header_bottom.$header_end; } echo "
".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_top .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand); $header_bottom .= ""._n('Type', 'Types', 1)."".Entity::getTypeName(1)."".__('Name')."".__('Serial number')."".__('Inventory number')."
"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]); echo "". ($nb>1 ? sprintf(__('%1$s: %2$s'), $itemname, $nb) : $itemname).""; echo Dropdown::getDropdownName("glpi_entities", $data['entity'])."".$name."". (isset($data["serial"])? "".$data["serial"]."" :"-")."". (isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."
"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { global $DB; if (!$withtemplate) { $nb = 0; switch ($item->getType()) { case 'Change' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForMainItem($item); } return self::createTabEntry(_n('Item', 'Items', Session::getPluralNumber()), $nb); case 'User' : case 'Group' : case 'Supplier' : if ($_SESSION['glpishow_count_on_tabs']) { $from = 'glpi_changes_' . strtolower($item->getType() . 's'); $result = $DB->request([ 'COUNT' => 'cpt', 'FROM' => $from, 'WHERE' => [ $item->getForeignKeyField() => $item->fields['id'] ] ])->next(); $nb = $result['cpt']; } return self::createTabEntry(Change::getTypeName(Session::getPluralNumber()), $nb); default : if (Session::haveRight("change", Change::READALL)) { if ($_SESSION['glpishow_count_on_tabs']) { // Direct one $nb = self::countForItem($item); // Linked items $linkeditems = $item->getLinkedItems(); if (count($linkeditems)) { foreach ($linkeditems as $type => $tab) { foreach ($tab as $ID) { $typeitem = new $type; $typeitem->getFromDB($ID); $nb += self::countForItem($typeitem); } } } } return self::createTabEntry(Change::getTypeName(Session::getPluralNumber()), $nb); } } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'Change' : self::showForChange($item); break; default : Change::showListForItem($item, $withtemplate); } return true; } }