.
* ---------------------------------------------------------------------
*/
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 "";
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 .= "| ".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_top .= " | ";
$header_bottom .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_bottom .= " | ";
}
$header_end .= "".Supplier::getTypeName(1)." | ";
$header_end .= "".Entity::getTypeName(1)." | ";
$header_end .= "".SupplierType::getTypeName(1)." | ";
$header_end .= "". Phone::getTypeName(1)." | ";
$header_end .= "".__('Fax')." | ";
$header_end .= "".__('Website')." | ";
$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 "| ".Html::getMassiveActionCheckBox(__CLASS__, $assocID)." | ";
}
echo "";
echo "".
Dropdown::getDropdownName("glpi_suppliers", $data["id"])." | ";
echo "".Dropdown::getDropdownName("glpi_entities", $data["entity"]);
echo " | ";
echo "".Dropdown::getDropdownName("glpi_suppliertypes", $data["suppliertypes_id"]);
echo " | ";
echo "".$data["phonenumber"]." | ";
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
*
* @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 "";
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 .= "| ".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_top .= " | ";
$header_bottom .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_bottom .= " | ";
}
$header_end .= "".__('Name')." | ";
$header_end .= "".Entity::getTypeName(1)." | ";
$header_end .= "". Phone::getTypeName(1)." | ";
$header_end .= "". __('Phone 2')." | ";
$header_end .= "".__('Mobile phone')." | ";
$header_end .= "".__('Fax')." | ";
$header_end .= ""._n('Email', 'Emails', 1)." | ";
$header_end .= ""._n('Type', 'Types', 1)." | ";
$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 "| ".Html::getMassiveActionCheckBox(__CLASS__, $assocID)." | ";
}
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 "
";
}
}