grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
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;
}
/**
* Get search function for the class
*
* @return array of search option
**/
function getSearchOptions() {
return parent::getSearchOptions();
}
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::countForSupplier($item);
}
return self::createTabEntry(Contact::getTypeName(Session::getPluralNumber()), $nb);
case 'Contact' :
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = self::countForContact($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;
}
/**
* @param $item string Supplier object
**/
static function countForSupplier(Supplier $item) {
$restrict = "`glpi_contacts_suppliers`.`suppliers_id` = '".$item->getField('id') ."'
AND `glpi_contacts_suppliers`.`contacts_id` = `glpi_contacts`.`id` ".
getEntitiesRestrictRequest(" AND ", "glpi_contacts", '',
$_SESSION['glpiactiveentities'], true);
return countElementsInTable(array('glpi_contacts_suppliers', 'glpi_contacts'), $restrict);
}
/**
* @param $item string Contact object
**/
static function countForContact(Contact $item) {
$restrict = "`glpi_contacts_suppliers`.`contacts_id` = '".$item->getField('id') ."'
AND `glpi_contacts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id` ".
getEntitiesRestrictRequest(" AND ", "glpi_suppliers", '',
$_SESSION['glpiactiveentities'], true);
return countElementsInTable(array('glpi_contacts_suppliers', 'glpi_suppliers'), $restrict);
}
/**
* Print the HTML array for entreprises on the current contact
*
*@return Nothing (display)
**/
static function showForContact(Contact $contact) {
global $DB,$CFG_GLPI;
$instID = $contact->fields['id'];
if (!$contact->can($instID, READ)) {
return false;
}
$canedit = $contact->can($instID, UPDATE);
$rand = mt_rand();
$query = "SELECT `glpi_contacts_suppliers`.`id`,
`glpi_suppliers`.`id` AS entID,
`glpi_suppliers`.`name` AS name,
`glpi_suppliers`.`website` AS website,
`glpi_suppliers`.`fax` AS fax,
`glpi_suppliers`.`phonenumber` AS phone,
`glpi_suppliers`.`suppliertypes_id` AS type,
`glpi_suppliers`.`is_deleted`,
`glpi_entities`.`id` AS entity
FROM `glpi_contacts_suppliers`, `glpi_suppliers`
LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_suppliers`.`entities_id`)
WHERE `glpi_contacts_suppliers`.`contacts_id` = '$instID'
AND `glpi_contacts_suppliers`.`suppliers_id` = `glpi_suppliers`.`id`".
getEntitiesRestrictRequest(" AND","glpi_suppliers",'','',true) ."
ORDER BY `glpi_entities`.`completename`, `name`";
$result = $DB->query($query);
$suppliers = array();
$used = array();
if ($number = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$suppliers[$data['id']] = $data;
$used[$data['entID']] = $data['entID'];
}
}
if ($canedit) {
echo "
";
}
echo "";
if ($canedit && $number) {
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = array('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 .= "| ".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_top .= " | ";
$header_bottom .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_bottom .= " | ";
}
$header_end .= "".__('Supplier')." | ";
$header_end .= "".__('Entity')." | ";
$header_end .= "".__('Third party type')." | ";
$header_end .= "". __('Phone')." | ";
$header_end .= "".__('Fax')." | ";
$header_end .= "".__('Website')." | ";
$header_end .= "
";
echo $header_begin.$header_top.$header_end;
$used = array();
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) {
$ID = $data["id"];
Session::addToNavigateListItems('Supplier', $data["entID"]);
$used[$data["entID"]] = $data["entID"];
$website = $data["website"];
if (!empty($website)) {
$website = $data["website"];
if (!preg_match("?https*://?",$website)) {
$website = "http://".$website;
}
$website = "".$data["website"]."";
}
echo "";
if ($canedit) {
echo "| ".Html::getMassiveActionCheckBox(__CLASS__, $data["id"])." | ";
}
echo "";
echo "".
Dropdown::getDropdownName("glpi_suppliers", $data["entID"])." | ";
echo "".Dropdown::getDropdownName("glpi_entities", $data["entity"]);
echo " | ";
echo "".Dropdown::getDropdownName("glpi_suppliertypes", $data["type"]);
echo " | ";
echo "".$data["phone"]." | ";
echo "".$data["fax"]." | ";
echo "".$website." | ";
echo "
";
}
echo $header_begin.$header_bottom.$header_end;
}
echo "
";
if ($canedit && $number) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "
";
}
/**
* Show contacts asociated to an enterprise
**/
static function showForSupplier(Supplier $supplier) {
global $DB,$CFG_GLPI;
$instID = $supplier->fields['id'];
if (!$supplier->can($instID, READ)) {
return false;
}
$canedit = $supplier->can($instID, UPDATE);
$rand = mt_rand();
$query = "SELECT `glpi_contacts`.*,
`glpi_contacts_suppliers`.`id` AS ID_ent,
`glpi_entities`.`id` AS entity
FROM `glpi_contacts_suppliers`, `glpi_contacts`
LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contacts`.`entities_id`)
WHERE `glpi_contacts_suppliers`.`contacts_id`=`glpi_contacts`.`id`
AND `glpi_contacts_suppliers`.`suppliers_id` = '$instID'" .
getEntitiesRestrictRequest(" AND", "glpi_contacts", '', '', true) ."
ORDER BY `glpi_entities`.`completename`, `glpi_contacts`.`name`";
$result = $DB->query($query);
$contacts = array();
$used = array();
if ($number = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$contacts[$data['ID_ent']] = $data;
$used[$data['id']] = $data['id'];
}
}
if ($canedit) {
echo "";
}
echo "";
if ($canedit && $number) {
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = array('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 .= "| ".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_top .= " | ";
$header_bottom .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_bottom .= " | ";
}
$header_end .= "".__('Name')." | ";
$header_end .= "".__('Entity')." | ";
$header_end .= "". __('Phone')." | ";
$header_end .= "". __('Phone 2')." | ";
$header_end .= "".__('Mobile phone')." | ";
$header_end .= "".__('Fax')." | ";
$header_end .= ""._n('Email', 'Emails', 1)." | ";
$header_end .= "".__('Type')." | ";
$header_end .= "
";
echo $header_begin.$header_top.$header_end;
$used = array();
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) {
$ID = $data["ID_ent"];
$used[$data["id"]] = $data["id"];
Session::addToNavigateListItems('Contact',$data["id"]);
echo "";
if ($canedit) {
echo "| ".Html::getMassiveActionCheckBox(__CLASS__, $data["ID_ent"])." | ";
}
echo "";
echo "".
sprintf(__('%1$s %2$s'), $data["name"], $data["firstname"])." | ";
echo "".Dropdown::getDropdownName("glpi_entities",
$data["entity"]);
echo " | ";
echo "".$data["phone"]." | ";
echo "".$data["phone2"]." | ";
echo "".$data["mobile"]." | ";
echo "".$data["fax"]." | ";
echo "";
echo "".$data["email"]." | ";
echo "".Dropdown::getDropdownName("glpi_contacttypes",
$data["contacttypes_id"])." | ";
echo "
";
}
echo $header_begin.$header_bottom.$header_end;
}
echo "
";
if ($canedit && $number) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "
";
}
}
?>