* Copyright (C) 2013-2015 Laurent Destailleur * Copyright (C) 2015-2016 Charlie BENKE * Copyright (C) 2021-2025 Frédéric France * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * This template needs: * $object * $withproject (if we are on task contact) * * $preselectedtypeofcontact may be defined or not */ /** * @var ?CommonObject $object * @var ?CommonObject $objectsrc * @var DoliDB $db * @var Form $form * @var HookManager $hookmanager * @var Translate $langs * @var User $user * @var ?string $permission */ ' @phan-var-force ?CommonObject $object @phan-var-force ?CommonObject $objectsrc @phan-var-force ?string $permission '; // Protection to avoid direct call of template if (empty($object) || !is_object($object)) { print "Error, template page can't be called as URL"; exit(1); } if (empty($preselectedtypeofcontact)) { $preselectedtypeofcontact = 0; } require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; $module = $object->element; // Special cases if (isset($permissiontoadd) && !isset($permission)) { $permission = $permissiontoadd; } // TODO Remove this section. We already got $permissiontoadd. if ($module == 'propal') { $permission = $user->hasRight('propal', 'creer'); } elseif ($module == 'fichinter') { $permission = $user->hasRight('ficheinter', 'creer'); } elseif ($module == 'order_supplier') { if (!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) { $permission = $user->hasRight('fournisseur', 'commande', 'creer'); } else { $permission = $user->hasRight('supplier_order', 'creer'); } } elseif ($module == 'invoice_supplier' && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) { if (!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) { $permission = $user->hasRight('fournisseur', 'facture', 'creer'); } else { $permission = $user->hasRight('supplier_invoice', 'creer'); } } elseif ($module == 'project') { $permission = $user->hasRight('projet', 'creer'); } elseif ($module == 'action') { $permission = $user->hasRight('agenda', 'myactions', 'create'); } elseif ($module == 'shipping') { $permission = $user->hasRight('expedition', 'creer'); } elseif ($module == 'reception') { $permission = $user->hasRight('reception', 'creer'); } elseif ($module == 'project_task') { $permission = $user->hasRight('projet', 'creer'); } elseif (!isset($permission) && $user->hasRight($module, 'creer')) { $permission = $user->hasRight($module, 'creer'); } elseif (!isset($permission) && $user->hasRight($module, 'write')) { $permission = $user->hasRight($module, 'write'); } $formcompany = new FormCompany($db); $companystatic = new Societe($db); $contactstatic = new Contact($db); $userstatic = new User($db); ?> '."\n"; print '
'."\n"; print '
'."\n"; ?>
trans("ThirdParty"); ?>
trans("Users"), 'user', 'class="optiongrey paddingright"').$langs->trans("Users").' | '.img_picto($langs->trans("Contacts"), 'contact', 'class="optiongrey paddingright"').$langs->trans("Contacts"); ?>
trans("ContactType"); ?>
 
 
'; } ?>
select_dolusers($user->id, 'userid', 1, (!empty($userAlreadySelected) ? $userAlreadySelected : null), 0, '', '', '0', 56, 0, '', 0, '', 'minwidth100imp widthcentpercentminusxx maxwidth400 userselectcontact'); if (empty($hideaddcontactforgroups) && $module == 'project') { print ' '.$langs->trans("or").' '; echo img_object('', 'group', 'class="pictofixedwidth"').$form->select_dolgroups(0, 'groupid', 1, '', 0, '', array(), '0', false, 'minwidth100imp widthcentpercentminusxx maxwidth400 groupselectcontact'); } ?>
element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) { $tmpobject = $objectsrc; } $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal', 'position', 0, 'minwidth150imp widthcentpercentminusx maxwidth200'); ?>
 
">
'; } ?>
socid) ? 0 : $object->socid); $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', array(), 0, '', 'minwidth300imp maxwidth400 widthcentpercentminusx'); // This also print the select component?>
selectcontacts(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400'); print $form->select_contact(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp maxwidth400 widthcentpercentminusx', true); $nbofcontacts = $form->num; $newcardbutton = ''; if (!empty($object->socid) && $object->socid > 1 && $user->hasRight('societe', 'creer')) { $newcardbutton .= ''; } print $newcardbutton; ?>
element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) { '@phan-var-force Commande|Facture $objectsrc'; $tmpobject = $objectsrc; } $formcompany->selectTypeContact($tmpobject, $preselectedtypeofcontact, 'typecontact', 'external', 'position', 0, 'minwidth150imp widthcentpercentminusx maxwidth200'); ?>
 
">
"; print "
"; print '
'; } // Prepare list // TODO: replace this with 1 single direct SQL (for both internal and external string to use $db->sort($sortfield, $sortorder) $list = array(); foreach (array('internal', 'external') as $source) { if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) { '@phan-var-force Commande|Facture $objectsrc'; $contactlist = $objectsrc->liste_contact(-1, $source); } else { $contactlist = $object->liste_contact(-1, $source); } foreach ($contactlist as $contact) { $entry = new stdClass(); $entry->id = $contact['rowid']; $entry->type_id = $contact['fk_c_type_contact']; $entry->type = $contact['libelle']; $entry->nature = ""; $entry->nature_html = ""; $entry->thirdparty_id = 0; $entry->thirdparty_html = ""; $entry->thirdparty_name = ""; $entry->contact_html = ""; $entry->contact_name = ""; $entry->status = 0; $entry->status_html = ""; if ($contact['source'] == 'internal') { $entry->nature = 'user'; $entry->nature_html = $langs->trans("User"); } elseif ($contact['source'] == 'external') { $entry->nature = 'thirdparty'; $entry->nature_html = $langs->trans("ThirdPartyContact"); } if ($contact['socid'] > 0) { $companystatic->fetch($contact['socid']); $entry->thirdparty_id = $companystatic->id; $entry->thirdparty_html = $companystatic->getNomUrl(1); $entry->thirdparty_name = strtolower($companystatic->getFullName($langs)); } elseif ($contact['socid'] < 0) { $entry->thirdparty_html = getDolGlobalString('MAIN_INFO_SOCIETE_NOM'); $entry->thirdparty_name = strtolower($conf->global->MAIN_INFO_SOCIETE_NOM); } if ($contact['source'] == 'internal') { $userstatic->fetch($contact['id']); $entry->contact_id = $userstatic->id; $entry->contact_html = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle'); $entry->contact_name = strtolower($userstatic->getFullName($langs)); } elseif ($contact['source'] == 'external') { $contactstatic->fetch($contact['id']); $entry->contact_id = $contactstatic->id; $entry->contact_html = $contactstatic->getNomUrl(1, '', 0, '', 0, 0); $entry->contact_name = strtolower($contactstatic->getFullName($langs)); } if ($contact['source'] == 'internal') { $entry->status = $contact['statuscontact']; $entry->status_html = $userstatic->LibStatut($contact['statuscontact'], 3); } elseif ($contact['source'] == 'external') { $entry->status = $contact['statuscontact']; $entry->status_html = $contactstatic->LibStatut($contact['statuscontact'], 3); } $list[] = $entry; } } $sortfield = GETPOST("sortfield", "aZ09comma"); $sortorder = GETPOST("sortorder", 'aZ09comma'); if (!$sortfield) { $sortfield = "nature"; } if (!$sortorder) { $sortorder = "asc"; } // Re-sort list $list = dol_sort_array($list, $sortfield, $sortorder, 1, 0, 1); $arrayfields = array( 'rowid' => array('label' => $langs->trans("Id"), 'checked' => 1), 'nature' => array('label' => $langs->trans("NatureOfContact"), 'checked' => 1), 'thirdparty' => array('label' => $langs->trans("ThirdParty"), 'checked' => 1), 'contact' => array('label' => $langs->trans("Users").' | '.$langs->trans("Contacts"), 'checked' => 1), 'type' => array('label' => $langs->trans("ContactType"), 'checked' => 1), 'status' => array('label' => $langs->trans("Status"), 'checked' => 1), 'link' => array('label' => $langs->trans("Link"), 'checked' => 1), ); $param = 'id='.$object->id.'&mainmenu=home'; // Show list of contact links print '
'; print ''; print ''; print ''; print ''; print ''; print '
'."\n"; print ''; print ''; print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty_name", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact_name", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['nature']['label'], $_SERVER["PHP_SELF"], "nature", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder, 'center '); if ($permission) { print_liste_field_titre('', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder, 'center maxwidthsearch '); } print ""; foreach ($list as $entry) { print ''; print ''; print ''; print ''; print ''; print ''; if ($permission) { $href = $_SERVER["PHP_SELF"]; $href .= '?id='.((int) $object->id); $href .= '&action=deletecontact&token='.newToken(); $href .= '&lineid='.((int) $entry->id); print '"; } print ""; } if (empty($list)) { $colspan = 5 + ($permission ? 1 : 0); print ''; } print "
'.$entry->thirdparty_html.''.$entry->contact_html.''.dol_escape_htmltag($entry->nature_html).''.dol_escape_htmltag($entry->type).''.$entry->status_html.''; print ''; print img_picto($langs->trans("Unlink"), "unlink"); print ""; print "
'; if (is_object($object) && !empty($object->thirdparty)) { print $form->textwithpicto($langs->trans("NoSpecificContactAddress"), $langs->trans("NoSpecificContactAddressBis")); } else { print $langs->trans("NoSpecificContactAddress"); } print ''; print '
"; print '
'; print "
"; print "\n"; if (is_object($hookmanager)) { $hookmanager->initHooks(array('contacttpl')); $parameters = array(); // @phan-suppress-next-line PhanTypeMismatchArgumentNullable $reshook = $hookmanager->executeHooks('formContactTpl', $parameters, $object, $action); } print "\n";