. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } // Relation between Contracts and Suppliers class Contract_Supplier extends CommonDBRelation { // From CommonDBRelation static public $itemtype_1 = 'Contract'; static public $items_id_1 = 'contracts_id'; static public $itemtype_2 = 'Supplier'; static public $items_id_2 = 'suppliers_id'; function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { $nb = 0; switch ($item->getType()) { case 'Supplier' : if (Contract::canView()) { if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(Contract::getTypeName(Session::getPluralNumber()), $nb); } break; case 'Contract' : if (Session::haveRight("contact_enterprise", READ)) { if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(Supplier::getTypeName(Session::getPluralNumber()), $nb); } break; } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'Supplier' : self::showForSupplier($item); break; case 'Contract' : self::showForContract($item); break; } return true; } /** * Print an HTML array with contracts associated to the enterprise * * @since 0.84 * * @param Supplier $supplier * * @return void **/ static function showForSupplier(Supplier $supplier) { $ID = $supplier->fields['id']; if (!Contract::canView() || !$supplier->can($ID, READ)) { return; } $canedit = $supplier->can($ID, UPDATE); $rand = mt_rand(); $iterator = self::getListForItem($supplier); $number = count($iterator); $contracts = []; $used = []; while ($data = $iterator->next()) { $contracts[$data['linkid']] = $data; $used[$data['id']] = $data['id']; } if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
".__('Add a contract')."
"; Contract::dropdown(['used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->fields["is_recursive"], 'nochecklimit' => true]); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } echo "
"; if ($canedit && $number) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['container' => 'mass'.__CLASS__.$rand, 'num_displayed' => min($_SESSION['glpilist_limit'], $number)]; 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 .= ""; $header_end .= ""; $header_end .= ""; echo $header_begin.$header_top.$header_end; foreach ($contracts as $data) { $cID = $data["id"]; $assocID = $data["linkid"]; echo ""; if ($canedit) { echo ""; } $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } echo ""; 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 .= "".__('Name')."".Entity::getTypeName(1).""._x('phone', 'Number')."".ContractType::getTypeName(1)."".__('Start date')."".__('Initial contract period')."
"; Html::showMassiveActionCheckBox(__CLASS__, $assocID); echo " ".$name.""; echo "".Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "".$data["num"]."". Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"])."".Html::convDate($data["begin_date"]).""; sprintf(_n('%d month', '%d months', $data["duration"]), $data["duration"]); if (($data["begin_date"] != '') && !empty($data["begin_date"])) { echo " -> ".Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], 0, true); } echo "
"; if ($canedit && $number) { $massiveactionparams['ontop'] =false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } /** * Print the HTML array of suppliers for this contract * * @since 0.84 * * @param $contract Contract object * * @return void **/ static function showForContract(Contract $contract) { $instID = $contract->fields['id']; if (!$contract->can($instID, READ) || !Session::haveRight("contact_enterprise", READ)) { return; } $canedit = $contract->can($instID, UPDATE); $rand = mt_rand(); $iterator = self::getListForItem($contract); $number = count($iterator); $suppliers = []; $used = []; while ($data = $iterator->next()) { $suppliers[$data['linkid']] = $data; $used[$data['id']] = $data['id']; } if ($canedit) { echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
".__('Add a supplier')."
"; Supplier::dropdown(['used' => $used, 'entity' => $contract->fields["entities_id"], 'entity_sons' => $contract->fields["is_recursive"]]); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } echo "
"; if ($canedit && $number) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['num_displayed' => min($_SESSION['glpilist_limit'], $number), '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 .= ""; $header_end .= ""; echo $header_begin.$header_top.$header_end; foreach ($suppliers as $data) { $assocID = $data['linkid']; $website = $data['website']; if (!empty($website)) { if (!preg_match("?https*://?", $website)) { $website = "http://".$website; } $website = "".$data['website'].""; } $entID = $data['id']; $entity = $data['entity']; $entname = Dropdown::getDropdownName("glpi_suppliers", $entID); echo ""; if ($canedit) { echo ""; } echo ""; 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 .= "".Supplier::getTypeName(1)."".Entity::getTypeName(1)."".SupplierType::getTypeName(1)."".Phone::getTypeName(1)."".__('Website')."
"; Html::showMassiveActionCheckBox(__CLASS__, $assocID); echo ""; if ($_SESSION["glpiis_ids_visible"] || empty($entname)) { $entname = sprintf(__('%1$s (%2$s)'), $entname, $entID); } echo "".$entname; echo "".Dropdown::getDropdownName("glpi_entities", $entity).""; echo Dropdown::getDropdownName("glpi_suppliertypes", $data['suppliertypes_id'])."".$data['phonenumber']."".$website."
"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } }