dolibarr  16.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 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
28 if (empty($object) || !is_object($object)) {
29  print "Error, template page can't be called as URL";
30  exit;
31 }
32 
33 if (empty($preselectedtypeofcontact)) {
34  $preselectedtypeofcontact = 0;
35 }
36 
37 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39 
40 $module = $object->element;
41 
42 // Special cases
43 if ($module == 'propal') {
44  $permission = $user->rights->propale->creer;
45 } elseif ($module == 'fichinter') {
46  $permission = $user->rights->ficheinter->creer;
47 } elseif ($module == 'order_supplier') {
48  if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
49  $permission = $user->rights->fournisseur->commande->creer;
50  } else {
51  $permission = $user->rights->supplier_order->creer;
52  }
53 } elseif ($module == 'invoice_supplier' && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
54  if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
55  $permission = $user->rights->fournisseur->facture->creer;
56  } else {
57  $permission = $user->rights->supplier_invoice->creer;
58  }
59 } elseif ($module == 'project') {
60  $permission = $user->rights->projet->creer;
61 } elseif ($module == 'action') {
62  $permission = $user->rights->agenda->myactions->create;
63 } elseif ($module == 'shipping') {
64  $permission = $user->rights->expedition->creer;
65 } elseif ($module == 'reception') {
66  $permission = $user->rights->reception->creer;
67 } elseif ($module == 'project_task') {
68  $permission = $user->rights->projet->creer;
69 } elseif (!isset($permission) && isset($user->rights->$module->creer)) {
70  $permission = $user->rights->$module->creer;
71 } elseif (!isset($permission) && isset($user->rights->$module->write)) {
72  $permission = $user->rights->$module->write;
73 }
74 
75 $formcompany = new FormCompany($db);
76 $companystatic = new Societe($db);
77 $contactstatic = new Contact($db);
78 $userstatic = new User($db);
79 
80 ?>
81 
82 <!-- BEGIN PHP TEMPLATE CONTACTS -->
83 <?php
84 if ($permission) {
85  print '<div class="underbanner clearboth"></div>'."\n";
86 
87  print '<div class="div-table-responsive-no-min">'."\n";
88  print '<div class="tagtable tableforcontact centpercent noborder nobordertop allwidth">'."\n";
89 
90  ?>
91  <form class="tagtr liste_titre">
92  <div class="tagtd liste_titre"><?php echo img_object('', 'company', 'class="optiongrey paddingright"').$langs->trans("ThirdParty"); ?></div>
93  <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>
94  <div class="tagtd liste_titre"><?php echo $langs->trans("ContactType"); ?></div>
95  <div class="tagtd liste_titre">&nbsp;</div>
96  <div class="tagtd liste_titre">&nbsp;</div>
97  </form>
98 
99  <?php
100 
101  if (empty($hideaddcontactforuser)) {
102  ?>
103  <form class="tagtr impair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
104  <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
105  <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
106  <input type="hidden" name="action" value="addcontact" />
107  <input type="hidden" name="source" value="internal" />
108  <?php if (!empty($withproject)) {
109  print '<input type="hidden" name="withproject" value="'.$withproject.'">';
110  } ?>
111 
112  <div class="tagtd"><?php echo $conf->global->MAIN_INFO_SOCIETE_NOM; ?></div>
113  <!-- <div class="nowrap tagtd"><?php echo img_object('', 'user').' '.$langs->trans("Users"); ?></div> -->
114  <div class="tagtd maxwidthonsmartphone"><?php echo img_object('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($user->id, 'userid', 0, (!empty($userAlreadySelected) ? $userAlreadySelected : null), 0, null, null, 0, 56, 0, '', 0, '', 'minwidth100imp widthcentpercentminusxx maxwidth400'); ?></div>
115  <div class="tagtd maxwidthonsmartphone">
116  <?php
117  $tmpobject = $object;
118  if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
119  $tmpobject = $objectsrc;
120  }
121  $formcompany->selectTypeContact($tmpobject, '', 'type', 'internal', 'position', 0, 'minwidth125imp widthcentpercentminusx maxwidth400');
122  ?></div>
123  <div class="tagtd">&nbsp;</div>
124  <div class="tagtd center"><input type="submit" class="button small" value="<?php echo $langs->trans("Add"); ?>"></div>
125  </form>
126 
127  <?php
128  }
129 
130  if (empty($hideaddcontactforthirdparty)) {
131  ?>
132 
133  <form class="tagtr pair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
134  <input type="hidden" name="token" value="<?php echo newToken(); ?>" />
135  <input type="hidden" name="id" value="<?php echo $object->id; ?>" />
136  <input type="hidden" name="action" value="addcontact" />
137  <input type="hidden" name="source" value="external" />
138  <input type="hidden" name="page_y" value="" />
139  <?php if (!empty($withproject)) {
140  print '<input type="hidden" name="withproject" value="'.$withproject.'">';
141  } ?>
142 
143  <div class="tagtd nowrap noborderbottom">
144  <?php
145  $selectedCompany = GETPOSTISSET("newcompany") ? GETPOST("newcompany", 'int') : (empty($object->socid) ? 0 : $object->socid);
146  $selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany', '', 0, '', 'minwidth300imp'); ?>
147  </div>
148  <div class="tagtd noborderbottom minwidth500imp">
149  <?php
150  print img_object('', 'contact', 'class="pictofixedwidth"').$form->selectcontacts(($selectedCompany > 0 ? $selectedCompany : -1), '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
151  $nbofcontacts = $form->num;
152 
153  $newcardbutton = '';
154  if (!empty($object->socid) && $object->socid > 1 && $user->rights->societe->creer) {
155  $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>';
156  }
157  print $newcardbutton;
158  ?>
159  </div>
160  <div class="tagtd noborderbottom">
161  <?php
162  $tmpobject = $object;
163  if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
164  $tmpobject = $objectsrc;
165  }
166  $formcompany->selectTypeContact($tmpobject, $preselectedtypeofcontact, 'typecontact', 'external', 'position', 0, 'minwidth125imp widthcentpercentminusx maxwidth400');
167  ?>
168  </div>
169  <div class="tagtd noborderbottom">&nbsp;</div>
170  <div class="tagtd center noborderbottom">
171  <input type="submit" id="add-customer-contact" class="button small" value="<?php echo $langs->trans("Add"); ?>"<?php if (!$nbofcontacts) {
172  echo ' disabled';
173  } ?>>
174  </div>
175  </form>
176 
177  <?php
178  }
179 
180  print "</div>";
181  print "</div>";
182 
183  print '<br>';
184 }
185 
186 
187 // Prepare list
188 
189 // TODO: replace this with direct SQL string to use $db->sort($sortfield, $sortorder)
190 $list = array();
191 foreach (array('internal', 'external') as $source) {
192  if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
193  $contactlist = $objectsrc->liste_contact(-1, $source);
194  } else {
195  $contactlist = $object->liste_contact(-1, $source);
196  }
197 
198  foreach ($contactlist as $contact) {
199  $entry = new stdClass();
200  $entry->id = $contact['rowid'];
201  $entry->type = $contact['libelle'];
202  $entry->nature = "";
203  $entry->thirdparty_html = "";
204  $entry->thirdparty_name = "";
205  $entry->contact_html = "";
206  $entry->contact_name = "";
207  $entry->status = "";
208 
209  if ($contact['source'] == 'internal') {
210  $entry->nature = $langs->trans("User");
211  } elseif ($contact['source'] == 'external') {
212  $entry->nature = $langs->trans("ThirdPartyContact");
213  }
214 
215  if ($contact['socid'] > 0) {
216  $companystatic->fetch($contact['socid']);
217  $entry->thirdparty_html = $companystatic->getNomUrl(1);
218  $entry->thirdparty_name = strtolower($companystatic->getFullName($langs));
219  } elseif ($contact['socid'] < 0) {
220  $entry->thirdparty_html = $conf->global->MAIN_INFO_SOCIETE_NOM;
221  $entry->thirdparty_name = strtolower($conf->global->MAIN_INFO_SOCIETE_NOM);
222  }
223 
224  if ($contact['source'] == 'internal') {
225  $userstatic->fetch($contact['id']);
226  $entry->contact_html = $userstatic->getNomUrl(-1, '', 0, 0, 0, 0, '', 'valignmiddle');
227  $entry->contact_name = strtolower($userstatic->getFullName($langs));
228  } elseif ($contact['source'] == 'external') {
229  $contactstatic->fetch($contact['id']);
230  $entry->contact_html = $contactstatic->getNomUrl(1, '', 0, '', 0, 0);
231  $entry->contact_name = strtolower($contactstatic->getFullName($langs));
232  }
233 
234  if ($contact['source'] == 'internal') {
235  $entry->status = $userstatic->LibStatut($contact['statuscontact'], 3);
236  } elseif ($contact['source'] == 'external') {
237  $entry->status = $contactstatic->LibStatut($contact['statuscontact'], 3);
238  }
239 
240  $list[] = $entry;
241  }
242 }
243 
244 
245 $sortfield = GETPOST("sortfield", "aZ09comma");
246 $sortorder = GETPOST("sortorder", 'aZ09comma');
247 
248 if (!$sortfield) {
249  $sortfield = "nature";
250 }
251 if (!$sortorder) {
252  $sortorder = "asc";
253 }
254 
255 // Re-sort list
256 $list = dol_sort_array($list, $sortfield, $sortorder, 1, 0, 1);
257 
258 $arrayfields = array(
259  'rowid' => array('label'=>$langs->trans("Id"), 'checked'=>1),
260  'nature' => array('label'=>$langs->trans("NatureOfContact"), 'checked'=>1),
261  'thirdparty' => array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
262  'contact' => array('label'=>$langs->trans("Users").' | '.$langs->trans("Contacts"), 'checked'=>1),
263  'type' => array('label'=>$langs->trans("ContactType"), 'checked'=>1),
264  'status' => array('label'=>$langs->trans("Status"), 'checked'=>1),
265  'link' => array('label'=>$langs->trans("Link"), 'checked'=>1),
266 );
267 
268 $param = 'id='.$object->id.'&mainmenu=home';
269 
273 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
274 print '<input type="hidden" name="token" value="'.newToken().'">';
275 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
276 print '<input type="hidden" name="action" value="list">';
277 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
278 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
279 
280 print '<div class="div-table-responsive-no-min">'."\n";
281 print '<table class="tagtable nobottomiftotal liste">';
282 
283 //print '<tr class="liste_titre_filter">';
284 //print '</tr>';
285 
286 print '<tr class="liste_titre">';
287 print_liste_field_titre($arrayfields['thirdparty']['label'], $_SERVER["PHP_SELF"], "thirdparty_name", "", $param, "", $sortfield, $sortorder);
288 print_liste_field_titre($arrayfields['contact']['label'], $_SERVER["PHP_SELF"], "contact_name", "", $param, "", $sortfield, $sortorder);
289 print_liste_field_titre($arrayfields['nature']['label'], $_SERVER["PHP_SELF"], "nature", "", $param, "", $sortfield, $sortorder);
290 print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, "", $sortfield, $sortorder);
291 print_liste_field_titre($arrayfields['status']['label'], $_SERVER["PHP_SELF"], "statut", "", $param, "", $sortfield, $sortorder, 'center ');
292 print_liste_field_titre('', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder, 'center maxwidthsearch ');
293 print "</tr>";
294 
295 foreach ($list as $entry) {
296  print '<tr class="oddeven">';
297 
298  print '<td class="tdoverflowmax200">'.$entry->thirdparty_html.'</td>';
299  print '<td class="tdoverflowmax200">'.$entry->contact_html.'</td>';
300  print '<td class="nowrap"><span class="opacitymedium">'.$entry->nature.'</span></td>';
301  print '<td class="tdoverflowmax200">'.$entry->type.'</td>';
302  print '<td class="tdoverflowmax200 center">'.$entry->status.'</td>';
303 
304  if ($permission) {
305  $href = $_SERVER["PHP_SELF"];
306  $href .= '?id='.((int) $object->id);
307  $href .= '&action=deletecontact&token='.newToken();
308  $href .= '&lineid='.((int) $entry->id);
309 
310  print '<td class="center">';
311  print '<a href="'.$href.'">';
312  print img_picto($langs->trans("Unlink"), "unlink");
313  print "</a>";
314  print "</td>";
315  }
316 
317  print "</tr>";
318 }
319 
320 print "</table>";
321 print '</div>';
322 
323 print "</form>";
324 
325 print "<!-- TEMPLATE CONTACTS HOOK BEGIN HERE -->\n";
326 if (is_object($hookmanager)) {
327  $hookmanager->initHooks(array('contacttpl'));
328  $parameters = array();
329  $reshook = $hookmanager->executeHooks('formContactTpl', $parameters, $object, $action);
330 }
331 print "<!-- END PHP TEMPLATE CONTACTS -->\n";
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
name
$conf db name
Definition: repair.php:122
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119