dolibarr 22.0.5
contacts.tpl.php
1<?php
2/* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015-2016 Charlie BENKE <charlie@patas-monkey.com>
5 * Copyright (C) 2021-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Solution Libre SAS <contact@solution-libre.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 *
22 * This template needs:
23 * $object
24 * $withproject (if we are on task contact)
25 *
26 * $preselectedtypeofcontact may be defined or not
27 */
38'
39@phan-var-force ?CommonObject $object
40@phan-var-force ?CommonObject $objectsrc
41@phan-var-force ?string $permission
42';
43
44// Protection to avoid direct call of template
45if (empty($object) || !is_object($object)) {
46 print "Error, template page can't be called as URL";
47 exit(1);
48}
49
50
51if (empty($preselectedtypeofcontact)) {
52 $preselectedtypeofcontact = 0;
53}
54
55require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
56require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
57
58$module = $object->element;
59
60// Special cases
61if (isset($permissiontoadd) && !isset($permission)) {
62 $permission = $permissiontoadd;
63}
64// TODO Remove this section. We already got $permissiontoadd.
65if ($module == 'propal') {
66 $permission = $user->hasRight('propal', 'creer');
67} elseif ($module == 'fichinter') {
68 $permission = $user->hasRight('ficheinter', 'creer');
69} elseif ($module == 'order_supplier') {
70 if (!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
71 $permission = $user->hasRight('fournisseur', 'commande', 'creer');
72 } else {
73 $permission = $user->hasRight('supplier_order', 'creer');
74 }
75} elseif ($module == 'invoice_supplier' && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
76 if (!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) {
77 $permission = $user->hasRight('fournisseur', 'facture', 'creer');
78 } else {
79 $permission = $user->hasRight('supplier_invoice', 'creer');
80 }
81} elseif ($module == 'project') {
82 $permission = $user->hasRight('projet', 'creer');
83} elseif ($module == 'action') {
84 $permission = $user->hasRight('agenda', 'myactions', 'create');
85} elseif ($module == 'shipping') {
86 $permission = $user->hasRight('expedition', 'creer');
87} elseif ($module == 'reception') {
88 $permission = $user->hasRight('reception', 'creer');
89} elseif ($module == 'project_task') {
90 $permission = $user->hasRight('projet', 'creer');
91} elseif (!isset($permission) && $user->hasRight($module, 'creer')) {
92 $permission = $user->hasRight($module, 'creer');
93} elseif (!isset($permission) && $user->hasRight($module, 'write')) {
94 $permission = $user->hasRight($module, 'write');
95}
96
97$formcompany = new FormCompany($db);
98$companystatic = new Societe($db);
99$contactstatic = new Contact($db);
100$userstatic = new User($db);
101
102?>
103
104<!-- BEGIN PHP TEMPLATE CORE/TPL/CONTACTS.TPL.PHP -->
105<?php
106if ($permission) {
107 print '<div class="underbanner clearboth"></div>'."\n";
108
109 print '<div class="div-table-responsive-no-min">'."\n";
110 print '<div class="tagtable tableforcontact centpercent noborder nobordertop allwidth">'."\n"; ?>
111 <form class="tagtr liste_titre">
112 <div class="tagtd liste_titre"><?php echo img_object('', 'company', 'class="optiongrey paddingright"').$langs->trans("ThirdParty"); ?></div>
113 <div class="tagtd liste_titre"><?php echo img_picto($langs->trans("Users"), 'user', 'class="optiongrey paddingright"').$langs->trans("Users").' | '.img_picto($langs->trans("Contacts"), 'contact', 'class="optiongrey paddingright"').$langs->trans("Contacts"); ?></div>
114 <div class="tagtd liste_titre"><?php echo $langs->trans("ContactType"); ?></div>
115 <div class="tagtd liste_titre">&nbsp;</div>
116 <div class="tagtd liste_titre">&nbsp;</div>
117 </form>
118
119 <?php
120
121 if (empty($hideaddcontactforuser)) {
122 ?>
123 <form class="tagtr impair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
124 <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
125 <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
126 <input type="hidden" name="action" value="addcontact" />
127 <input type="hidden" name="source" value="internal" />
128 <?php if (!empty($withproject)) {
129 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
130 } ?>
131
132 <div class="tagtd"><span class="paddingleft"><?php echo getDolGlobalString('MAIN_INFO_SOCIETE_NOM'); ?></span></div>
133 <!-- <div class="nowrap tagtd"><?php echo img_object('', 'user').' '.$langs->trans("Users"); ?></div> -->
134 <div class="tagtd maxwidthonsmartphone">
135 <?php echo img_object('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($user->id, 'userid', 1, (!empty($userAlreadySelected) ? $userAlreadySelected : null), 0, '', '', '0', 56, 0, '', 0, '', 'minwidth100imp widthcentpercentminusxx maxwidth400 userselectcontact');
136 if (empty($hideaddcontactforgroups) && $module == 'project') {
137 print '<span class="opacitymedium"> '.$langs->trans("or").' </span>';
138 echo img_object('', 'group', 'class="pictofixedwidth"').$form->select_dolgroups(0, 'groupid', 1, '', 0, '', array(), '0', false, 'minwidth100imp widthcentpercentminusxx maxwidth400 groupselectcontact');
139 }
140 ?>
141 <script>
142 jQuery(document).ready(function(){
143 $(".userselectcontact").on("change", function(){
144 if ($(this).val() != -1) {
145 $(".groupselectcontact").val(-1).change();
146 }
147 });
148 $(".groupselectcontact").on("change", function(){
149 if ($(this).val() != -1) {
150 $(".userselectcontact").val(-1).change();
151 }
152 });
153 });
154 </script>
155 </div>
156 <div class="tagtd maxwidthonsmartphone">
157 <?php
158 $tmpobject = $object;
159 if (((!getDolGlobalInt('SHIPPING_USE_ITS_OWN_CONTACTS') && $object->element == 'shipping') || $object->element == 'reception') && is_object($objectsrc)) {
160 $tmpobject = $objectsrc;
161 }
162 $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal', 'position', 0, 'minwidth150imp widthcentpercentminusx maxwidth200'); ?></div>
163 <div class="tagtd">&nbsp;</div>
164 <div class="tagtd center"><input type="submit" class="button small" value="<?php echo $langs->trans("Add"); ?>"></div>
165 </form>
166 <?php
167 }
168
169 if (empty($hideaddcontactforthirdparty)) {
170 ?>
171
172 <form class="tagtr pair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
173 <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
174 <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
175 <input type="hidden" name="action" value="addcontact" />
176 <input type="hidden" name="source" value="external" />
177 <input type="hidden" name="page_y" value="" />
178 <?php if (!empty($withproject)) {
179 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
180 } ?>
181
182 <div class="tagtd nowrap noborderbottom">
183 <?php
184 $selectedCompany = GETPOSTISSET("newcompany") ? GETPOSTINT("newcompany") : (empty($object->socid) ? 0 : $object->socid);
185 $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', array(), 0, '', 'minwidth300imp maxwidth400 widthcentpercentminusx'); // This also print the select component?>
186 </div>
187 <div class="tagtd noborderbottom minwidth500imp">
188 <?php
189 print img_object('', 'contact', 'class="pictofixedwidth"');
190 //print $form->selectcontacts(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
191 print $form->select_contact(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp maxwidth400 widthcentpercentminusx', true);
192
193 $nbofcontacts = $form->num;
194
195 $newcardbutton = '';
196 if (!empty($object->socid) && $object->socid > 1 && $user->hasRight('societe', 'creer')) {
197 $newcardbutton .= '<a href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$selectedCompany.'&action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'" title="'.$langs->trans('NewContact').'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
198 }
199 print $newcardbutton; ?>
200 </div>
201 <div class="tagtd noborderbottom">
202 <?php
203 $tmpobject = $object;
204 if (((!getDolGlobalInt('SHIPPING_USE_ITS_OWN_CONTACTS') && $object->element == 'shipping') || $object->element == 'reception') && is_object($objectsrc)) {
205 '@phan-var-force Commande|Facture $objectsrc';
206 $tmpobject = $objectsrc;
207 }
208 $formcompany->selectTypeContact($tmpobject, $preselectedtypeofcontact, 'typecontact', 'external', 'position', 0, 'minwidth150imp widthcentpercentminusx maxwidth200'); ?>
209 </div>
210 <div class="tagtd noborderbottom">&nbsp;</div>
211 <div class="tagtd center noborderbottom">
212 <input type="submit" id="add-customer-contact" class="button small" value="<?php echo $langs->trans("Add"); ?>"<?php if (!$nbofcontacts) {
213 echo ' disabled';
214 } ?>>
215 </div>
216 </form>
217
218 <?php
219 }
220
221 print "</div>";
222 print "</div>";
223
224 print '<br>';
225}
226
227
228// Prepare list
229
230// TODO: replace this with 1 single direct SQL (for both internal and external string to use $db->sort($sortfield, $sortorder)
231$list = array();
232foreach (array('internal', 'external') as $source) {
233 if (((!getDolGlobalInt('SHIPPING_USE_ITS_OWN_CONTACTS') && $object->element == 'shipping') || $object->element == 'reception') && is_object($objectsrc)) {
234 '@phan-var-force Commande|Facture $objectsrc';
235 $contactlist = $objectsrc->liste_contact(-1, $source);
236 } else {
237 $contactlist = $object->liste_contact(-1, $source);
238 }
239
240 foreach ($contactlist as $contact) {
241 $entry = new stdClass();
242 $entry->id = $contact['rowid'];
243 $entry->type_id = $contact['fk_c_type_contact'];
244 $entry->type = $contact['libelle'];
245 $entry->nature = "";
246 $entry->nature_html = "";
247 $entry->thirdparty_id = 0;
248 $entry->thirdparty_html = "";
249 $entry->thirdparty_name = "";
250 $entry->contact_html = "";
251 $entry->contact_name = "";
252 $entry->status = 0;
253 $entry->status_html = "";
254
255 if ($contact['source'] == 'internal') {
256 $entry->nature = 'user';
257 $entry->nature_html = $langs->trans("User");
258 } elseif ($contact['source'] == 'external') {
259 $entry->nature = 'thirdparty';
260 $entry->nature_html = $langs->trans("ThirdPartyContact");
261 }
262
263 if ($contact['socid'] > 0) {
264 $companystatic->fetch($contact['socid']);
265 $entry->thirdparty_id = $companystatic->id;
266 $entry->thirdparty_html = $companystatic->getNomUrl(1);
267 $entry->thirdparty_name = strtolower($companystatic->getFullName($langs));
268 } elseif ($contact['socid'] < 0) {
269 $entry->thirdparty_html = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
270 $entry->thirdparty_name = strtolower($conf->global->MAIN_INFO_SOCIETE_NOM);
271 }
272
273 if ($contact['source'] == 'internal') {
274 $userstatic->fetch($contact['id']);
275 $entry->contact_id = $userstatic->id;
276 $entry->contact_html = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle');
277 $entry->contact_name = strtolower($userstatic->getFullName($langs));
278 $entry->contact_warning = 0;
279 } elseif ($contact['source'] == 'external') {
280 $contactstatic->fetch($contact['id']);
281 $entry->contact_id = $contactstatic->id;
282 $entry->contact_html = $contactstatic->getNomUrl(1, '', 0, '', 0, 0);
283 $entry->contact_name = strtolower($contactstatic->getFullName($langs));
284 $entry->contact_warning = $contactstatic->user_id; // Show warning to recommend to assign user_id as contact instead.
285 }
286
287 if ($contact['source'] == 'internal') {
288 $entry->status = $contact['statuscontact'];
289 $entry->status_html = $userstatic->LibStatut($contact['statuscontact'], 3);
290 } elseif ($contact['source'] == 'external') {
291 $entry->status = $contact['statuscontact'];
292 $entry->status_html = $contactstatic->LibStatut($contact['statuscontact'], 3);
293 }
294
295 $list[] = $entry;
296 }
297}
298
299
300$sortfield = GETPOST("sortfield", "aZ09comma");
301$sortorder = GETPOST("sortorder", 'aZ09comma');
302
303if (!$sortfield) {
304 $sortfield = "nature";
305}
306if (!$sortorder) {
307 $sortorder = "asc";
308}
309
310// Re-sort list
311$list = dol_sort_array($list, $sortfield, $sortorder, 1, 0, 1);
312
313$arrayfields = array(
314 'rowid' => array('label' => $langs->trans("Id"), 'checked' => 1),
315 'nature' => array('label' => $langs->trans("NatureOfContact"), 'checked' => 1),
316 'thirdparty' => array('label' => $langs->trans("ThirdParty"), 'checked' => 1),
317 'contact' => array('label' => $langs->trans("Users").' | '.$langs->trans("Contacts"), 'checked' => 1),
318 'type' => array('label' => $langs->trans("ContactType"), 'checked' => 1),
319 'status' => array('label' => $langs->trans("Status"), 'checked' => 1),
320 'link' => array('label' => $langs->trans("Link"), 'checked' => 1),
321);
322
323$param = 'id='.$object->id.'&mainmenu=home';
324
325
326// Show list of contact links
327
328print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
329print '<input type="hidden" name="token" value="'.newToken().'">';
330print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
331print '<input type="hidden" name="action" value="list">';
332print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
333print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
334
335print '<div class="div-table-responsive-no-min">'."\n";
336print '<table class="tagtable nobottomiftotal liste noborder">';
337
338print '<tr class="liste_titre">';
339print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty_name", "", $param, "", $sortfield, $sortorder);
340print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact_name", "", $param, "", $sortfield, $sortorder);
341print_liste_field_titre($arrayfields['nature']['label'], $_SERVER["PHP_SELF"], "nature", "", $param, "", $sortfield, $sortorder);
342print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder);
343print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder, 'center ');
344if ($permission) {
345 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder, 'center maxwidthsearch ');
346}
347print "</tr>";
348
349foreach ($list as $entry) {
350 print '<tr class="oddeven" data-rowid="' . $entry->id . '">';
351
352 print '<td class="tdoverflowmax200" data-thirdparty_id="' . ((int) $entry->thirdparty_id) . '" data-thirdparty_name="' . dol_escape_htmltag($entry->thirdparty_name) . '">'.$entry->thirdparty_html.'</td>';
353 print '<td class="tdoverflowmax200" data-contact_id="' . ((int) $entry->contact_id) . '">'.$entry->contact_html.'</td>';
354 print '<td class="nowrap" data-nature="' . dol_escape_htmltag($entry->nature) . '"><span class="opacitymedium">'.dol_escape_htmltag($entry->nature_html).'</span>';
355 if ($entry->contact_warning > 0) {
356 $tmpuser = new User($db);
357 $tmpuser->fetch($entry->contact_warning);
358 print ($tmpuser->id > 0 ? img_picto($langs->trans("ThisContactHasAUser", $tmpuser->getFullName($langs), $entry->contact_name), 'info') : '');
359 }
360 print '</td>';
361 print '<td class="tdoverflowmax200" data-type_id="' . ((int) $entry->type_id) . '" data-type="' . dol_escape_htmltag($entry->type) . '">'.dol_escape_htmltag($langs->trans($entry->type)).'</td>';
362 print '<td class="tdoverflowmax200 center" data-status_id="' . ((int) $entry->status) . '">'.$entry->status_html.'</td>';
363
364 if ($permission) {
365 $href = $_SERVER["PHP_SELF"];
366 $href .= '?id='.((int) $object->id);
367 $href .= '&action=deletecontact&token='.newToken();
368 $href .= '&lineid='.((int) $entry->id);
369
370 print '<td class="center">';
371 print '<a href="'.$href.'">';
372 print img_picto($langs->trans("Unlink"), "unlink");
373 print "</a>";
374 print "</td>";
375 }
376
377 print "</tr>";
378}
379if (empty($list)) {
380 $colspan = 5 + ($permission ? 1 : 0);
381 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">';
382 if (is_object($object) && !empty($object->thirdparty)) {
383 print $form->textwithpicto($langs->trans("NoSpecificContactAddress"), $langs->trans("NoSpecificContactAddressBis"));
384 } else {
385 print $langs->trans("NoSpecificContactAddress");
386 }
387 print '</span>';
388 print '</td></tr>';
389}
390print "</table>";
391print '</div>';
392
393print "</form>";
394
395print "<!-- TEMPLATE CONTACTS HOOK BEGIN HERE -->\n";
396if (is_object($hookmanager)) {
397 $hookmanager->initHooks(array('contacttpl'));
398 $parameters = array();
399 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
400 $reshook = $hookmanager->executeHooks('formContactTpl', $parameters, $object, $action);
401}
402print "<!-- END PHP TEMPLATE CONTACTS -->\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to manage contact/addresses.
Class to build HTML component for third parties management Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:158
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161