. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } class Contact_Supplier extends CommonDBRelation{ // From CommonDBRelation static public $itemtype_1 = 'Contact'; static public $items_id_1 = 'contacts_id'; static public $itemtype_2 = 'Supplier'; static public $items_id_2 = 'suppliers_id'; static function getTypeName($nb = 0) { return _n('Link Contact/Supplier', 'Links Contact/Supplier', $nb); } function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate && Session::haveRight("contact_enterprise", READ)) { $nb = 0; switch ($item->getType()) { case 'Supplier' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(Contact::getTypeName(Session::getPluralNumber()), $nb); case 'Contact' : if ($_SESSION['glpishow_count_on_tabs']) { $nb = self::countForItem($item); } return self::createTabEntry(Supplier::getTypeName(Session::getPluralNumber()), $nb); } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'Supplier' : self::showForSupplier($item); break; case 'Contact' : self::showForContact($item); break; } return true; } /** * Print the HTML array for entreprises on the current contact * * @return void */ static function showForContact(Contact $contact) { $instID = $contact->fields['id']; if (!$contact->can($instID, READ)) { return; } $canedit = $contact->can($instID, UPDATE); $rand = mt_rand(); $iterator = self::getListForItem($contact); $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 "
".__('Add a supplier')."
"; echo ""; Supplier::dropdown(['used' => $used, 'entity' => $contact->fields["entities_id"], 'entity_sons' => $contact->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 .= ""; $header_end .= ""; echo $header_begin.$header_top.$header_end; if ($number > 0) { Session::initNavigateListItems('Supplier', //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Contact::getTypeName(1), $contact->getName())); foreach ($suppliers as $data) { $assocID = $data["linkid"]; Session::addToNavigateListItems('Supplier', $data["id"]); $website = $data["website"]; if (!empty($website)) { $website = $data["website"]; if (!preg_match("?https*://?", $website)) { $website = "http://".$website; } $website = "".$data["website"].""; } echo ""; if ($canedit) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } 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)."".__('Fax')."".__('Website')."
".Html::getMassiveActionCheckBox(__CLASS__, $assocID).""; echo "". Dropdown::getDropdownName("glpi_suppliers", $data["id"])."".Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "".Dropdown::getDropdownName("glpi_suppliertypes", $data["suppliertypes_id"]); echo "".$data["phonenumber"]."".$data["fax"]."".$website."
"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } /** * Show contacts asociated to an enterprise * * @return void **/ static function showForSupplier(Supplier $supplier) { $instID = $supplier->fields['id']; if (!$supplier->can($instID, READ)) { return; } $canedit = $supplier->can($instID, UPDATE); $rand = mt_rand(); $iterator = self::getListForItem($supplier); $number = count($iterator); $contacts = []; $used = []; while ($data = $iterator->next()) { $contacts[$data['linkid']] = $data; $used[$data['id']] = $data['id']; } if ($canedit) { echo "
"; echo ""; echo ""; echo ""; echo ""; echo "
".__('Add a contact')."
"; echo ""; Contact::dropdown(['used' => $used, 'entity' => $supplier->fields["entities_id"], 'entity_sons' => $supplier->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 .= ""; $header_end .= ""; $header_end .= ""; $header_end .= ""; echo $header_begin.$header_top.$header_end; if ($number) { Session::initNavigateListItems('Contact', //TRANS : %1$s is the itemtype name, %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), Supplier::getTypeName(1), $supplier->getName())); foreach ($contacts as $data) { $assocID = $data["linkid"]; Session::addToNavigateListItems('Contact', $data["id"]); echo ""; if ($canedit) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } 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)."". Phone::getTypeName(1)."". __('Phone 2')."".__('Mobile phone')."".__('Fax').""._n('Email', 'Emails', 1).""._n('Type', 'Types', 1)."
".Html::getMassiveActionCheckBox(__CLASS__, $assocID).""; echo "". sprintf(__('%1$s %2$s'), $data["name"], $data["firstname"])."".Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "".$data["phone"]."".$data["phone2"]."".$data["mobile"]."".$data["fax"].""; echo "".$data["email"]."".Dropdown::getDropdownName("glpi_contacttypes", $data["contacttypes_id"])."
"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } }