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