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