. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * Item_Project Class * * Relation between Projects and Items * * @since 0.85 **/ class Item_Project extends CommonDBRelation{ // From CommonDBRelation static public $itemtype_1 = 'Project'; static public $items_id_1 = 'projects_id'; static public $itemtype_2 = 'itemtype'; static public $items_id_2 = 'items_id'; static public $checkItem_2_Rights = self::HAVE_VIEW_RIGHT_ON_ITEM; function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } function prepareInputForAdd($input) { // Avoid duplicate entry if (countElementsInTable($this->getTable(), ['projects_id' => $input['projects_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 project * * @param $project Project object * * @return void **/ static function showForProject(Project $project) { global $CFG_GLPI; $instID = $project->fields['id']; if (!$project->can($instID, READ)) { return false; } $canedit = $project->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')."
"; Dropdown::showSelectItemFromItemtypes(['itemtypes' => $CFG_GLPI["project_asset_types"], 'entity_restrict' => ($project->fields['is_recursive'] ?getSonsOf('glpi_entities', $project->fields['entities_id']) :$project->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; $totalnb = 0; while ($row = $types_iterator->next()) { $itemtype = $row['itemtype']; if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $iterator = self::getTypeItems($instID, $itemtype); $nb = count($iterator); $prem = true; while ($data = $iterator->next()) { $name = $data[$itemtype::getNameField()]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$itemtype::getNameField()])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = $item::getFormURLWithID($data['id']); $namelink = "".$name.""; echo ""; if ($canedit) { echo ""; } if ($prem) { $typename = $item->getTypeName($nb); echo ""; $prem = false; } echo ""; echo ""; echo ""; echo ""; echo ""; } $totalnb += $nb; } } if ($totalnb > 0) { echo ""; echo " "; } 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'), $typename, $nb) : $typename).""; echo Dropdown::getDropdownName("glpi_entities", $data['entity'])."".$namelink."".(isset($data["serial"])? "".$data["serial"]."" :"-"). "". (isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."
". (($totalnb > 0) ? sprintf(__('%1$s = %2$s'), __('Total'), $totalnb) :" "); echo " 
"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { $nb = 0; switch ($item->getType()) { case 'Project' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForMainItem($item); } return self::createTabEntry(_n('Item', 'Items', Session::getPluralNumber()), $nb); default : // Not used now if (Session::haveRight("project", Project::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) { $typeitem = new $type; foreach ($tab as $ID) { $typeitem->getFromDB($ID); $nb += self::countForItem($typeitem); } } } } return self::createTabEntry(Project::getTypeName(Session::getPluralNumber()), $nb); } } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'Project' : self::showForProject($item); break; default : // Not defined and used now // Project::showListForItem($item); } return true; } }