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