dolibarr  20.0.0-alpha
company.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2013 Christophe Battarel <contact@altairis.fr>
9  * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
11  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
12  * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
13  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  * or see https://www.gnu.org/
29  */
30 
44 {
45  global $db, $langs, $conf, $user;
46  global $hookmanager;
47 
48  $h = 0;
49  $head = array();
50 
51  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
52  $head[$h][1] = $langs->trans("ThirdParty");
53  $head[$h][2] = 'card';
54  $h++;
55 
56 
57  if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $user->hasRight('societe', 'contact', 'lire')) {
58  //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
59  $nbContact = 0;
60  // Enable caching of thirdrparty count Contacts
61  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
62  $cachekey = 'count_contacts_thirdparty_'.$object->id;
63  $dataretrieved = dol_getcache($cachekey);
64 
65  if (!is_null($dataretrieved)) {
66  $nbContact = $dataretrieved;
67  } else {
68  $sql = "SELECT COUNT(p.rowid) as nb";
69  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
70  // Add table from hooks
71  $parameters = array('contacttab' => true);
72  $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
73  $sql .= $hookmanager->resPrint;
74  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
75  $sql .= " AND p.entity IN (".getEntity($object->element).")";
76  // Add where from hooks
77  $parameters = array('contacttab' => true); // @phan-suppress-current-line PhanPluginRedundantAssignment
78  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
79  $sql .= $hookmanager->resPrint;
80  $resql = $db->query($sql);
81  if ($resql) {
82  $obj = $db->fetch_object($resql);
83  $nbContact = $obj->nb;
84  }
85 
86  dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result.
87  }
88 
89  $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
90  $head[$h][1] = $langs->trans('ContactsAddresses');
91  if ($nbContact > 0) {
92  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
93  }
94  $head[$h][2] = 'contact';
95  $h++;
96  }
97  if (getDolGlobalString('MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES')) {
98  // Some features may be unstable with this option, like permissions rules, import contact, ...
99  $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
100  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
101  $head[$h][1] = $langs->trans("ContactsAddressesExt");
102  if ($nbContact > 0) {
103  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
104  }
105  $head[$h][2] = 'contactext';
106  $h++;
107  }
108 
109  if ($object->client == 1 || $object->client == 2 || $object->client == 3) {
110  $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
111  $head[$h][1] = '';
112  if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && ($object->client == 2 || $object->client == 3)) {
113  $head[$h][1] .= $langs->trans("Prospect");
114  }
115  if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && $object->client == 3) {
116  $head[$h][1] .= ' | ';
117  }
118  if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && ($object->client == 1 || $object->client == 3)) {
119  $head[$h][1] .= $langs->trans("Customer");
120  }
121  $head[$h][2] = 'customer';
122  $h++;
123 
124  if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
125  $langs->load("products");
126  // price
127  $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
128  $head[$h][1] = $langs->trans("CustomerPrices");
129  $head[$h][2] = 'price';
130  $h++;
131  }
132  }
133  $supplier_module_enabled = 0;
134  if (isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
135  $supplier_module_enabled = 1;
136  }
137  if ($supplier_module_enabled == 1 && $object->fournisseur && $user->hasRight('fournisseur', 'lire')) {
138  $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
139  $head[$h][1] = $langs->trans("Supplier");
140  $head[$h][2] = 'supplier';
141  $h++;
142  }
143 
144  if (isModEnabled('project') && ($user->hasRight('projet', 'lire'))) {
145  $nbProject = 0;
146  // Enable caching of thirdrparty count projects
147  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
148  $cachekey = 'count_projects_thirdparty_'.$object->id;
149  $dataretrieved = dol_getcache($cachekey);
150 
151  if (!is_null($dataretrieved)) {
152  $nbProject = $dataretrieved;
153  } else {
154  $sql = "SELECT COUNT(n.rowid) as nb";
155  $sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
156  $sql .= " WHERE fk_soc = ".((int) $object->id);
157  $sql .= " AND entity IN (".getEntity('project').")";
158  $resql = $db->query($sql);
159  if ($resql) {
160  $obj = $db->fetch_object($resql);
161  $nbProject = $obj->nb;
162  } else {
163  dol_print_error($db);
164  }
165  dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
166  }
167  $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
168  $head[$h][1] = $langs->trans("Projects");
169  if ($nbProject > 0) {
170  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
171  }
172  $head[$h][2] = 'project';
173  $h++;
174  }
175 
176  // Tab to link resources
177  if (isModEnabled('resource') && getDolGlobalString('RESOURCE_ON_THIRDPARTIES')) {
178  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
179  $head[$h][1] = $langs->trans("Resources");
180  $head[$h][2] = 'resources';
181  $h++;
182  }
183 
184  // Related items
185  if ((isModEnabled('order') || isModEnabled('propal') || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
186  && !getDolGlobalString('THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB')) {
187  $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
188  $head[$h][1] = $langs->trans("Referers");
189  $head[$h][2] = 'consumption';
190  $h++;
191  }
192 
193  // Bank accounts
194  if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
195  $nbBankAccount = 0;
196  $foundonexternalonlinesystem = 0;
197  $langs->load("bills");
198 
199  $title = $langs->trans("PaymentModes");
200 
201  if (isModEnabled('stripe')) {
202  $servicestatus = 0;
203  if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
204  $servicestatus = 1;
205  }
206 
207  include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
208  $societeaccount = new SocieteAccount($db);
209  $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
210  if ($stripecu) {
211  $foundonexternalonlinesystem++;
212  }
213  }
214 
215  $sql = "SELECT COUNT(n.rowid) as nb";
216  $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
217  $sql .= " WHERE n.fk_soc = ".((int) $object->id);
218  if (!isModEnabled('stripe')) {
219  $sql .= " AND n.stripe_card_ref IS NULL";
220  } else {
221  $sql .= " AND (n.stripe_card_ref IS NULL OR (n.stripe_card_ref IS NOT NULL AND n.status = ".((int) $servicestatus)."))";
222  }
223 
224  $resql = $db->query($sql);
225  if ($resql) {
226  $obj = $db->fetch_object($resql);
227  $nbBankAccount = $obj->nb;
228  } else {
229  dol_print_error($db);
230  }
231 
232  //if (isModEnabled('stripe') && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
233 
234  $head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.urlencode((string) ($object->id));
235  $head[$h][1] = $title;
236  if ($foundonexternalonlinesystem) {
237  $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
238  } elseif ($nbBankAccount > 0) {
239  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbBankAccount.'</span>';
240  }
241  $head[$h][2] = 'rib';
242  $h++;
243  }
244 
245  if ((isModEnabled('website') || isModEnabled('webportal')) && $user->hasRight('societe', 'lire')) {
246  $site_filter_list = array();
247  if (isModEnabled('website')) {
248  $site_filter_list[] = 'dolibarr_website';
249  }
250  if (isModEnabled('webportal')) {
251  $site_filter_list[] = 'dolibarr_portal';
252  }
253 
254  $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.urlencode((string) ($object->id));
255  $head[$h][1] = $langs->trans("WebSiteAccounts");
256  $nbNote = 0;
257  $sql = "SELECT COUNT(n.rowid) as nb";
258  $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as n";
259  $sql .= " WHERE fk_soc = ".((int) $object->id);
260  $sql .= " AND entity IN (".getEntity('thirdpartyaccount').")";
261  if (!empty($site_filter_list)) {
262  $sql .= " AND n.site IN (".$db->sanitize("'".implode("','", $site_filter_list)."'", 1).")";
263  }
264  $resql = $db->query($sql);
265  if ($resql) {
266  $obj = $db->fetch_object($resql);
267  $nbNote = $obj->nb;
268  } else {
269  dol_print_error($db);
270  }
271  if ($nbNote > 0) {
272  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
273  }
274  $head[$h][2] = 'website';
275  $h++;
276  }
277 
278  if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
279  if ($user->hasRight('partnership', 'read')) {
280  $langs->load("partnership");
281  $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
282  $head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?socid='.$object->id;
283  $head[$h][1] = $langs->trans("Partnerships");
284  $nbNote = 0;
285  $sql = "SELECT COUNT(n.rowid) as nb";
286  $sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
287  $sql .= " WHERE fk_soc = ".((int) $object->id);
288  $sql .= " AND entity IN (".getEntity('partnership').")";
289  $resql = $db->query($sql);
290  if ($resql) {
291  $obj = $db->fetch_object($resql);
292  $nbNote = $obj->nb;
293  } else {
294  dol_print_error($db);
295  }
296  if ($nbNote > 0) {
297  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
298  }
299  $head[$h][2] = 'partnerships';
300  if ($nbPartnership > 0) {
301  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
302  }
303  $h++;
304  }
305  }
306 
307  // Show more tabs from modules
308  // Entries must be declared in modules descriptor with line
309  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
310  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
311  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'core');
312 
313  if ($user->socid == 0) {
314  // Notifications
315  if (isModEnabled('notification')) {
316  $langs->load('mails');
317  $nbNotif = 0;
318  // Enable caching of thirdparty count notifications
319  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
320  $cachekey = 'count_notifications_thirdparty_'.$object->id;
321  $dataretrieved = dol_getcache($cachekey);
322  if (!is_null($dataretrieved)) {
323  $nbNotif = $dataretrieved;
324  } else {
325  // List of notifications enabled for contacts of the third party
326  $sql = "SELECT COUNT(n.rowid) as nb";
327  $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
328  $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
329  $sql .= " ".MAIN_DB_PREFIX."socpeople as c";
330  $sql .= " WHERE a.rowid = n.fk_action";
331  $sql .= " AND c.rowid = n.fk_contact";
332  $sql .= " AND c.fk_soc = ".((int) $object->id);
333  $resql = $db->query($sql);
334  if ($resql) {
335  $obj = $db->fetch_object($resql);
336  $nbNotif = $obj->nb;
337  } else {
338  dol_print_error($db);
339  }
340  dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
341  }
342 
343  $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.urlencode((string) ($object->id));
344  $head[$h][1] = $langs->trans("Notifications");
345  if ($nbNotif > 0) {
346  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
347  }
348  $head[$h][2] = 'notify';
349  $h++;
350  }
351 
352  // Notes
353  $nbNote = 0;
354  if (!empty($object->note_private)) {
355  $nbNote++;
356  }
357  if (!empty($object->note_public)) {
358  $nbNote++;
359  }
360  $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.urlencode((string) ($object->id));
361  $head[$h][1] = $langs->trans("Notes");
362  if ($nbNote > 0) {
363  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
364  }
365  $head[$h][2] = 'note';
366  $h++;
367 
368  // Attached files and Links
369  $totalAttached = 0;
370  // Enable caching of thirdrparty count attached files and links
371  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
372  $cachekey = 'count_attached_thirdparty_'.$object->id;
373  $dataretrieved = dol_getcache($cachekey);
374  if (!is_null($dataretrieved)) {
375  $totalAttached = $dataretrieved;
376  } else {
377  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
378  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
379  $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
380  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
381  $nbLinks = Link::count($db, $object->element, $object->id);
382  $totalAttached = $nbFiles + $nbLinks;
383  dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
384  }
385 
386  $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
387  $head[$h][1] = $langs->trans("Documents");
388  if (($totalAttached) > 0) {
389  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
390  }
391  $head[$h][2] = 'document';
392  $h++;
393  }
394 
395  $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
396  $head[$h][1] = $langs->trans("Events");
397  if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
398  $nbEvent = 0;
399  // Enable caching of thirdparty count actioncomm
400  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
401  $cachekey = 'count_events_thirdparty_'.$object->id;
402  $dataretrieved = dol_getcache($cachekey);
403  if (!is_null($dataretrieved)) {
404  $nbEvent = $dataretrieved;
405  } else {
406  $sql = "SELECT COUNT(id) as nb";
407  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
408  $sql .= " WHERE fk_soc = ".((int) $object->id);
409  $sql .= " AND entity IN (".getEntity('agenda').")";
410  $resql = $db->query($sql);
411  if ($resql) {
412  $obj = $db->fetch_object($resql);
413  $nbEvent = $obj->nb;
414  } else {
415  dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
416  }
417  dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
418  }
419 
420  $head[$h][1] .= '/';
421  $head[$h][1] .= $langs->trans("Agenda");
422  if ($nbEvent > 0) {
423  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
424  }
425  }
426  $head[$h][2] = 'agenda';
427  $h++;
428 
429  // Show more tabs from modules
430  // Entries must be declared in modules descriptor with line
431  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
432  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
433  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'external');
434 
435  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
436 
437  return $head;
438 }
439 
440 
448 {
449  global $langs;
450  $h = 0;
451  $head = array();
452 
453  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
454  $head[$h][1] = $langs->trans("ThirdParty");
455  $head[$h][2] = 'company';
456  $h++;
457 
458  $head[$h][0] = 'commerciaux.php?socid='.$object->id;
459  $head[$h][1] = $langs->trans("SalesRepresentative");
460  $head[$h][2] = 'salesrepresentative';
461  $h++;
462 
463  return $head;
464 }
465 
466 
467 
474 {
475  global $langs, $conf, $db;
476 
477  $extrafields = new ExtraFields($db);
478  $extrafields->fetch_name_optionals_label('societe');
479  $extrafields->fetch_name_optionals_label('socpeople');
480 
481  $h = 0;
482  $head = array();
483 
484  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
485  $head[$h][1] = $langs->trans("Miscellaneous");
486  $head[$h][2] = 'general';
487  $h++;
488 
489  // Show more tabs from modules
490  // Entries must be declared in modules descriptor with line
491  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
492  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
493  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
494 
495  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
496  $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
497  $nbExtrafields = $extrafields->attributes['societe']['count'];
498  if ($nbExtrafields > 0) {
499  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
500  }
501  $head[$h][2] = 'attributes';
502  $h++;
503 
504  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
505  $head[$h][1] = $langs->trans("ExtraFieldsContacts");
506  $nbExtrafields = $extrafields->attributes['socpeople']['count'];
507  if ($nbExtrafields > 0) {
508  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
509  }
510  $head[$h][2] = 'attributes_contacts';
511  $h++;
512 
513  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
514 
515  return $head;
516 }
517 
518 
519 
535 function getCountry($searchkey, $withcode = '', $dbtouse = null, $outputlangs = null, $entconv = 1, $searchlabel = '')
536 {
537  global $db, $langs;
538 
539  $result = '';
540 
541  // Check parameters
542  if (empty($searchkey) && empty($searchlabel)) {
543  if ($withcode === 'all') {
544  return array('id' => 0, 'code' => '', 'label' => '');
545  } else {
546  return '';
547  }
548  }
549  if (!is_object($dbtouse)) {
550  $dbtouse = $db;
551  }
552  if (!is_object($outputlangs)) {
553  $outputlangs = $langs;
554  }
555 
556  $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
557  if (is_numeric($searchkey)) {
558  $sql .= " WHERE rowid = ".((int) $searchkey);
559  } elseif (!empty($searchkey)) {
560  $sql .= " WHERE code = '".$db->escape($searchkey)."'";
561  } else {
562  $sql .= " WHERE label = '".$db->escape($searchlabel)."'";
563  }
564 
565  $resql = $dbtouse->query($sql);
566  if ($resql) {
567  $obj = $dbtouse->fetch_object($resql);
568  if ($obj) {
569  $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
570  if (is_object($outputlangs)) {
571  $outputlangs->load("dict");
572  if ($entconv) {
573  $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label;
574  } else {
575  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label;
576  }
577  }
578  if ($withcode == 1) {
579  $result = $label ? "$obj->code - $label" : "$obj->code";
580  } elseif ($withcode == 2) {
581  $result = $obj->code;
582  } elseif ($withcode == 3) {
583  $result = $obj->rowid;
584  } elseif ($withcode === 'all') {
585  $result = array('id' => $obj->rowid, 'code' => $obj->code, 'label' => $label);
586  } else {
587  $result = $label;
588  }
589  } else {
590  $result = 'NotDefined';
591  }
592  $dbtouse->free($resql);
593  return $result;
594  } else {
595  dol_print_error($dbtouse, '');
596  }
597  return 'Error';
598 }
599 
615 function getState($id, $withcode = '', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1)
616 {
617  global $db, $langs;
618 
619  if (!is_object($dbtouse)) {
620  $dbtouse = $db;
621  }
622 
623  $sql = "SELECT d.rowid as id, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.code_region as region_code, r.nom as region_name FROM";
624  $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
625  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".((int) $id);
626  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
627  $sql .= " ORDER BY c.code, d.code_departement";
628 
629  dol_syslog("Company.lib::getState", LOG_DEBUG);
630  $resql = $dbtouse->query($sql);
631  if ($resql) {
632  $obj = $dbtouse->fetch_object($resql);
633  if ($obj) {
634  $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
635  if (is_object($outputlangs)) {
636  $outputlangs->load("dict");
637  if ($entconv) {
638  $label = ($obj->code && ($outputlangs->trans("State".$obj->code) != "State".$obj->code)) ? $outputlangs->trans("State".$obj->code) : $label;
639  } else {
640  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code) != "State".$obj->code)) ? $outputlangs->transnoentitiesnoconv("State".$obj->code) : $label;
641  }
642  }
643 
644  if ($withcode == 1) {
645  if ($withregion == 1) {
646  return $label = $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
647  } else {
648  return $label = $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
649  }
650  } elseif ($withcode == 2) {
651  if ($withregion == 1) {
652  return $label = $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
653  } else {
654  return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
655  }
656  } elseif ($withcode === 'all') {
657  if ($withregion == 1) {
658  return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label, 'region_code' => $obj->region_code, 'region' => $obj->region_name);
659  } else {
660  return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label);
661  }
662  } else {
663  if ($withregion == 1) {
664  return $label = $obj->region_name.' - '.$label;
665  } else {
666  return $label;
667  }
668  }
669  } else {
670  return $langs->transnoentitiesnoconv("NotDefined");
671  }
672  } else {
673  dol_print_error($dbtouse, '');
674  }
675 
676  return '';
677 }
678 
687 function currency_name($code_iso, $withcode = 0, $outputlangs = null)
688 {
689  global $langs, $db;
690 
691  if (empty($outputlangs)) {
692  $outputlangs = $langs;
693  }
694 
695  $outputlangs->load("dict");
696 
697  // If there is a translation, we can send immediately the label
698  if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
699  return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
700  }
701 
702  // If no translation, we read table to get label by default
703  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
704  $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
705 
706  $resql = $db->query($sql);
707  if ($resql) {
708  $num = $db->num_rows($resql);
709 
710  if ($num) {
711  $obj = $db->fetch_object($resql);
712  $label = ($obj->label != '-' ? $obj->label : '');
713  if ($withcode) {
714  return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
715  } else {
716  return $label;
717  }
718  } else {
719  return $code_iso;
720  }
721  }
722  return 'ErrorWhenReadingCurrencyLabel';
723 }
724 
731 function getFormeJuridiqueLabel($code)
732 {
733  global $db, $langs;
734 
735  if (!$code) {
736  return '';
737  }
738 
739  $sql = "SELECT libelle as label FROM ".MAIN_DB_PREFIX."c_forme_juridique";
740  $sql .= " WHERE code = '".$db->escape($code)."'";
741 
742  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
743 
744  $resql = $db->query($sql);
745  if ($resql) {
746  $num = $db->num_rows($resql);
747  if ($num) {
748  $obj = $db->fetch_object($resql);
749 
750  $label = ($obj->label != '-' ? $obj->label : '');
751 
752  return $langs->trans($label);
753  } else {
754  return $langs->trans("NotDefined");
755  }
756  } else {
757  return 'Error '.$db->lasterror();
758  }
759 }
760 
761 
769 {
770  // List of all country codes that are in europe for european vat rules
771  // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
772  global $conf, $db;
773  $country_code_in_EEC = array();
774 
775  if (!empty($conf->cache['country_code_in_EEC'])) {
776  // Use of cache to reduce number of database requests
777  $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
778  } else {
779  $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
780  $sql .= " WHERE cc.eec = 1";
781 
782  $resql = $db->query($sql);
783  if ($resql) {
784  $num = $db->num_rows($resql);
785  $i = 0;
786  while ($i < $num) {
787  $objp = $db->fetch_object($resql);
788  $country_code_in_EEC[] = $objp->code;
789  $i++;
790  }
791  } else {
792  dol_print_error($db);
793  }
794  $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
795  }
796  return $country_code_in_EEC;
797 }
798 
805 function isInEEC($object)
806 {
807  if (empty($object->country_code)) {
808  return false;
809  }
810 
811  $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
812 
813  //print "dd".$object->country_code;
814  return in_array($object->country_code, $country_code_in_EEC);
815 }
816 
817 
830 function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
831 {
832  global $user, $action, $hookmanager, $form, $massactionbutton, $massaction, $arrayofselected, $arrayofmassactions;
833 
834  $i = -1;
835 
836  if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
837  $langs->load("projects");
838 
839  $newcardbutton = '';
840  if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
841  $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
842  }
843 
844  print "\n";
845  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
846 
847  print '<div class="div-table-responsive">'."\n";
848  print '<table class="noborder centpercent">';
849 
850  $sql = "SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_modification, p.budget_amount";
851  $sql .= ", cls.code as opp_status_code";
852  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
853  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
854  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
855  $sql .= " AND p.entity IN (".getEntity('project').")";
856  $sql .= " ORDER BY p.dateo DESC";
857 
858  $result = $db->query($sql);
859  if ($result) {
860  $num = $db->num_rows($result);
861 
862  print '<tr class="liste_titre">';
863  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
864  print '<td class="center">';
865  $selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
866  print $selectedfields;
867  print '</td>';
868  }
869  print '<td>'.$langs->trans("Ref").'</td>';
870  print '<td>'.$langs->trans("Name").'</td>';
871  print '<td class="center">'.$langs->trans("DateStart").'</td>';
872  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
873  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
874  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
875  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
876  print '<td class="right">'.$langs->trans("Status").'</td>';
877  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
878  print '<td class="center">';
879  $selectedfields = (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
880  print $selectedfields;
881  print '</td>';
882  }
883  print '</tr>';
884 
885  if ($num > 0) {
886  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
887 
888  $projecttmp = new Project($db);
889 
890  $i = 0;
891 
892  while ($i < $num) {
893  $obj = $db->fetch_object($result);
894  $projecttmp->fetch($obj->id);
895 
896  // To verify role of users
897  $userAccess = $projecttmp->restrictedProjectArea($user);
898 
899  if ($user->hasRight('projet', 'lire') && $userAccess > 0) {
900  print '<tr class="oddeven">';
901 
902  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
903  print '<td class="nowrap center actioncolumn">';
904  if ($massactionbutton || $massaction) {
905  $selected = 0;
906  if (in_array($obj->id, $arrayofselected)) {
907  $selected = 1;
908  }
909  print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
910  }
911  print '</td>';
912  }
913  // Ref
914  print '<td class="nowraponall">';
915  print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__');
916  print '</td>';
917 
918  // Label
919  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
920  // Date start
921  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
922  // Date end
923  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
924  // Opp amount
925  print '<td class="right">';
926  if ($obj->opp_status_code) {
927  print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
928  }
929  print '</td>';
930  // Opp status
931  print '<td class="center">';
932  if ($obj->opp_status_code) {
933  print $langs->trans("OppStatus".$obj->opp_status_code);
934  }
935  print '</td>';
936  // Opp percent
937  print '<td class="right">';
938  if ($obj->opp_percent) {
939  print price($obj->opp_percent, 1, '', 1, 0).'%';
940  }
941  print '</td>';
942  // Status
943  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
944 
945  // Action column
946  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
947  print '<td class="nowrap center actioncolumn">';
948  if ($massactionbutton || $massaction) {
949  $selected = 0;
950  if (in_array($obj->id, $arrayofselected)) {
951  $selected = 1;
952  }
953  print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
954  }
955  print '</td>';
956  }
957  print '</tr>';
958  }
959  $i++;
960  }
961  } else {
962  print '<tr class="oddeven"><td colspan="9"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
963  }
964  $db->free($result);
965  } else {
966  dol_print_error($db);
967  }
968 
969  //projects linked to that thirdpart because of a people of that company is linked to a project
970  if (getDolGlobalString('PROJECT_DISPLAY_LINKED_BY_CONTACT')) {
971  print "\n";
972  print load_fiche_titre($langs->trans("ProjectsLinkedToThisThirdParty"), '', '');
973 
974 
975  print '<div class="div-table-responsive">'."\n";
976  print '<table class="noborder centpercent">';
977 
978  $sql = "SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount";
979  $sql .= ", cls.code as opp_status_code";
980  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
981  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
982  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec on p.rowid = ec.element_id";
983  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sc on ec.fk_socpeople = sc.rowid";
984  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_contact as tc on ec.fk_c_type_contact = tc.rowid";
985  $sql .= " WHERE sc.fk_soc = ".((int) $object->id);
986  $sql .= " AND p.entity IN (".getEntity('project').")";
987  $sql .= " AND tc.element = 'project'";
988  $sql .= " ORDER BY p.dateo DESC";
989 
990  $result = $db->query($sql);
991  if ($result) {
992  $num = $db->num_rows($result);
993 
994  print '<tr class="liste_titre">';
995  print '<td>'.$langs->trans("Ref").'</td>';
996  print '<td>'.$langs->trans("Name").'</td>';
997  print '<td class="center">'.$langs->trans("DateStart").'</td>';
998  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
999  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
1000  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
1001  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
1002  print '<td class="right">'.$langs->trans("Status").'</td>';
1003  print '</tr>';
1004 
1005  if ($num > 0) {
1006  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1007 
1008  $projecttmp = new Project($db);
1009 
1010  $i = 0;
1011 
1012  while ($i < $num) {
1013  $obj = $db->fetch_object($result);
1014  $projecttmp->fetch($obj->id);
1015 
1016  // To verify role of users
1017  $userAccess = $projecttmp->restrictedProjectArea($user);
1018 
1019  if ($user->rights->projet->lire && $userAccess > 0) {
1020  print '<tr class="oddeven">';
1021 
1022  // Ref
1023  print '<td class="nowraponall">';
1024  print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__');
1025  print '</td>';
1026 
1027  // Label
1028  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
1029  // Date start
1030  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
1031  // Date end
1032  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
1033  // Opp amount
1034  print '<td class="right">';
1035  if ($obj->opp_status_code) {
1036  print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
1037  }
1038  print '</td>';
1039  // Opp status
1040  print '<td class="center">';
1041  if ($obj->opp_status_code) {
1042  print $langs->trans("OppStatus".$obj->opp_status_code);
1043  }
1044  print '</td>';
1045  // Opp percent
1046  print '<td class="right">';
1047  if ($obj->opp_percent) {
1048  print price($obj->opp_percent, 1, '', 1, 0).'%';
1049  }
1050  print '</td>';
1051  // Status
1052  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
1053 
1054  print '</tr>';
1055  }
1056  $i++;
1057  }
1058  } else {
1059  print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1060  }
1061  $db->free($result);
1062  } else {
1063  dol_print_error($db);
1064  }
1065  }
1066 
1067  $parameters = array('sql' => $sql, 'function' => 'show_projects');
1068  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1069  print $hookmanager->resPrint;
1070 
1071  print "</table>";
1072  print '</div>';
1073 
1074  print "<br>\n";
1075  }
1076 
1077  return $i;
1078 }
1079 
1080 
1092 function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
1093 {
1094  global $user, $conf, $extrafields, $hookmanager;
1095  global $contextpage;
1096 
1097  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
1098  $formcompany = new FormCompany($db);
1099  $form = new Form($db);
1100 
1101  $optioncss = GETPOST('optioncss', 'alpha');
1102  $sortfield = GETPOST('sortfield', 'aZ09comma');
1103  $sortorder = GETPOST('sortorder', 'aZ09comma');
1104  $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
1105 
1106  $search_status = GETPOST("search_status", "intcomma");
1107  if ($search_status == '') {
1108  $search_status = 1; // always display active customer first
1109  }
1110 
1111  $search_rowid = GETPOST("search_rowid", "intcomma");
1112  $search_name = GETPOST("search_name", 'alpha');
1113  $search_address = GETPOST("search_address", 'alpha');
1114  $search_poste = GETPOST("search_poste", 'alpha');
1115  $search_note_private = GETPOST('search_note_private', 'alphanohtml');
1116  $search_roles = GETPOST("search_roles", 'array');
1117  $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
1118  $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
1119 
1120  if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
1121  $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_dtstartmonth'), GETPOSTINT('search_birthday_dtstartday'), GETPOSTINT('search_birthday_dtstartyear'));
1122  $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_dtendmonth'), GETPOSTINT('search_birthday_dtendday'), GETPOSTINT('search_birthday_dtendyear'));
1123  }
1124  $socialnetworks = getArrayOfSocialNetworks();
1125 
1126  $searchAddressPhoneDBFields = array(
1127  //Address
1128  't.address',
1129  't.zip',
1130  't.town',
1131 
1132  //Phone
1133  't.phone',
1134  't.phone_perso',
1135  't.phone_mobile',
1136 
1137  //Fax
1138  't.fax',
1139 
1140  //E-mail
1141  't.email',
1142  );
1143  //Social media
1144  // foreach ($socialnetworks as $key => $value) {
1145  // if ($value['active']) {
1146  // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
1147  // }
1148  // }
1149 
1150  if (!$sortorder) {
1151  $sortorder = "ASC";
1152  }
1153  if (!$sortfield) {
1154  $sortfield = "t.lastname";
1155  }
1156 
1157  if (isModEnabled('clicktodial')) {
1158  $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1159  }
1160 
1161 
1162  $contactstatic = new Contact($db);
1163 
1164  $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1165 
1166  $contactstatic->fields = array(
1167  'rowid' => array('type' => 'integer', 'label' => "TechnicalID", 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'visible' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1168  'name' => array('type' => 'varchar(128)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1),
1169  'poste' => array('type' => 'varchar(128)', 'label' => 'PostOrFunction', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 2, 'index' => 1, 'position' => 20),
1170  'address' => array('type' => 'varchar(128)', 'label' => 'Address', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 3, 'index' => 1, 'position' => 30),
1171  'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible' => 3, 'position' => 35),
1172  'role' => array('type' => 'checkbox', 'label' => 'Role', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 4, 'index' => 1, 'position' => 40),
1173  'birthday' => array('type' => 'date', 'label' => 'Birthday', 'enabled' => 1, 'visible' => -1, 'notnull' => 0, 'position' => 45),
1174  'statut' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => '0', 'index' => 1, 'position' => 50, 'arrayofkeyval' => array(0 => $contactstatic->LibStatut(0, 1), 1 => $contactstatic->LibStatut(1, 1))),
1175  );
1176 
1177  // Definition of fields for list
1178  $arrayfields = array(
1179  't.rowid' => array('label' => "TechnicalID", 'checked' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1180  't.name' => array('label' => "Name", 'checked' => 1, 'position' => 10),
1181  't.poste' => array('label' => "PostOrFunction", 'checked' => 1, 'position' => 20),
1182  't.address' => array('label' => (empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked' => 1, 'position' => 30),
1183  't.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'position' => 35),
1184  'sc.role' => array('label' => "ContactByDefaultFor", 'checked' => 1, 'position' => 40),
1185  't.birthday' => array('label' => "Birthday", 'checked' => 0, 'position' => 45),
1186  't.statut' => array('label' => "Status", 'checked' => 1, 'position' => 50, 'class' => 'center'),
1187  );
1188  // Extra fields
1189  if (!empty($extrafields->attributes[$contactstatic->table_element]['label']) && is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) {
1190  foreach ($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val) {
1191  if (!empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
1192  $arrayfields["ef.".$key] = array(
1193  'label' => $extrafields->attributes[$contactstatic->table_element]['label'][$key],
1194  'checked' => (((int) dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1, 1, '1') < 0) ? 0 : 1),
1195  'position' => 1000 + $extrafields->attributes[$contactstatic->table_element]['pos'][$key],
1196  'enabled' => (abs((int) dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1)) != 3 && (int) dol_eval($extrafields->attributes[$contactstatic->table_element]['perms'][$key], 1, 1, '1'))
1197  );
1198  }
1199  }
1200  }
1201 
1202  // Initialize array of search criteria
1203  $search = array();
1204  foreach ($arrayfields as $key => $val) {
1205  $queryName = 'search_'.substr($key, 2);
1206  if (GETPOST($queryName, 'alpha')) {
1207  $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1208  }
1209  }
1210  $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1211 
1212  // Purge search criteria
1213  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
1214  $search_rowid = '';
1215  $search_status = '';
1216  $search_name = '';
1217  $search_roles = array();
1218  $search_address = '';
1219  $search_poste = '';
1220  $search_note_private = '';
1221  $search_birthday_dtstart = '';
1222  $search_birthday_dtend = '';
1223  $search = array();
1224  $search_array_options = array();
1225 
1226  foreach ($contactstatic->fields as $key => $val) {
1227  $search[$key] = '';
1228  }
1229  }
1230 
1231  $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1232  $arrayfields = dol_sort_array($arrayfields, 'position');
1233 
1234  $newcardbutton = '';
1235  if ($user->hasRight('societe', 'contact', 'creer')) {
1236  $addcontact = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1237  $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
1238  }
1239 
1240  print "\n";
1241 
1242  $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1243  print load_fiche_titre($title, $newcardbutton, '');
1244 
1245  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
1246  print '<input type="hidden" name="token" value="'.newToken().'">';
1247  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1248  print '<input type="hidden" name="socid" value="'.$object->id.'">';
1249  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1250  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1251  print '<input type="hidden" name="page" value="'.$page.'">';
1252 
1253  $arrayofmassactions = array();
1254  $mode = 'view';
1255 
1256  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1257  $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1258  $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1259  $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1260 
1261  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1262  print "\n".'<table class="tagtable liste">'."\n";
1263 
1264  $param = "socid=".urlencode((string) ($object->id));
1265  if ($search_rowid != '') {
1266  $param .= '&search_rowid='.urlencode((string) ($search_rowid));
1267  }
1268  if ($search_status != '') {
1269  $param .= '&search_status='.urlencode((string) ($search_status));
1270  }
1271  if (count($search_roles) > 0) {
1272  $param .= implode('&search_roles[]=', $search_roles);
1273  }
1274  if ($search_name != '') {
1275  $param .= '&search_name='.urlencode($search_name);
1276  }
1277  if ($search_poste != '') {
1278  $param .= '&search_poste='.urlencode($search_poste);
1279  }
1280  if ($search_address != '') {
1281  $param .= '&search_address='.urlencode($search_address);
1282  }
1283  if ($search_note_private != '') {
1284  $param .= '&search_note_private='.urlencode($search_note_private);
1285  }
1286  if ($search_birthday_dtstart != '') {
1287  $param .= '&search_birthday_dtstart='.urlencode($search_birthday_dtstart);
1288  }
1289  if ($search_birthday_dtend != '') {
1290  $param .= '&search_birthday_dtend='.urlencode($search_birthday_dtend);
1291  }
1292  if ($optioncss != '') {
1293  $param .= '&optioncss='.urlencode($optioncss);
1294  }
1295 
1296  // Add $param from extra fields
1297  $extrafieldsobjectkey = $contactstatic->table_element;
1298  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1299 
1300  $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1301  $sql .= " t.phone as phone_pro, t.phone_mobile, t.phone_perso, t.fax, t.email, t.socialnetworks, t.statut, t.photo, t.fk_soc,";
1302  $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1303  $sql .= " t.note_private";
1304  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
1305  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1306  $sql .= " WHERE t.fk_soc = ".((int) $object->id);
1307  $sql .= " AND t.entity IN (" .getEntity('socpeople') .")";
1308  $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";
1309  if ($search_rowid) {
1310  $sql .= natural_search('t.rowid', $search_rowid);
1311  }
1312  if ($search_status != '' && $search_status != '-1') {
1313  $sql .= " AND t.statut = ".((int) $search_status);
1314  }
1315  if ($search_name) {
1316  $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1317  }
1318  if ($search_poste) {
1319  $sql .= natural_search('t.poste', $search_poste);
1320  }
1321  if ($search_address) {
1322  $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1323  }
1324  if ($search_note_private) {
1325  $sql .= natural_search('t.note_private', $search_note_private);
1326  }
1327  if ($search_birthday_dtstart != '') {
1328  $sql .= " AND t.birthday >= '".$db->idate($search_birthday_dtstart)."'";
1329  }
1330  if ($search_birthday_dtend != '') {
1331  $sql .= " AND t.birthday <= '".$db->idate($search_birthday_dtend)."'";
1332  }
1333  if (count($search_roles) > 0) {
1334  $sql .= " AND t.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".$db->sanitize(implode(',', $search_roles))."))";
1335  }
1336  // Add where from extra fields
1337  $extrafieldsobjectkey = $contactstatic->table_element;
1338  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1339  // Add where from hooks
1340  $parameters = array('socid' => $object->id);
1341  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1342  $sql .= $hookmanager->resPrint;
1343  if ($sortfield == "t.name") {
1344  $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1345  } else {
1346  $sql .= " ORDER BY $sortfield $sortorder";
1347  }
1348 
1349  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1350  $result = $db->query($sql);
1351  if (!$result) {
1352  dol_print_error($db);
1353  }
1354 
1355  $num = $db->num_rows($result);
1356 
1357  // Fields title search
1358  // --------------------------------------------------------------------
1359  print '<tr class="liste_titre">';
1360  // Action column
1361  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1362  print '<td class="liste_titre" align="right">';
1363  print $form->showFilterButtons();
1364  print '</td>';
1365  }
1366  foreach ($contactstatic->fields as $key => $val) {
1367  $align = '';
1368  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1369  $align .= ($align ? ' ' : '').'center';
1370  }
1371  if (in_array($val['type'], array('timestamp'))) {
1372  $align .= ($align ? ' ' : '').'nowrap';
1373  }
1374  if ($key == 'status' || $key == 'statut') {
1375  $align .= ($align ? ' ' : '').'center';
1376  }
1377  if (!empty($arrayfields['t.'.$key]['checked']) || !empty($arrayfields['sc.'.$key]['checked'])) {
1378  print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
1379  if (in_array($key, array('statut'))) {
1380  print $form->selectarray('search_status', array('-1' => '', '0' => $contactstatic->LibStatut(0, 1), '1' => $contactstatic->LibStatut(1, 1)), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'onrightofpage');
1381  } elseif (in_array($key, array('role'))) {
1382  print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1383  } elseif (in_array($key, array('birthday'))) {
1384  print '<div class="nowrap">';
1385  print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1386  print '</div>';
1387  print '<div class="nowrap">';
1388  print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1389  print '</div>';
1390  } else {
1391  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.(!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '').'">';
1392  }
1393  print '</td>';
1394  }
1395  }
1396  if ($showuserlogin) {
1397  print '<td class="liste_titre"></td>';
1398  }
1399  // Extra fields
1400  $extrafieldsobjectkey = $contactstatic->table_element;
1401  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1402 
1403  // Fields from hook
1404  $parameters = array('arrayfields' => $arrayfields);
1405  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1406  print $hookmanager->resPrint;
1407  // Action column
1408  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1409  print '<td class="liste_titre" align="right">';
1410  print $form->showFilterButtons();
1411  print '</td>';
1412  }
1413  print '</tr>'."\n";
1414 
1415 
1416  // Fields title label
1417  // --------------------------------------------------------------------
1418  print '<tr class="liste_titre">';
1419  // Action column
1420  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1421  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1422  }
1423  foreach ($contactstatic->fields as $key => $val) {
1424  $align = '';
1425  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1426  $align .= ($align ? ' ' : '').'center';
1427  }
1428  if (in_array($val['type'], array('timestamp'))) {
1429  $align .= ($align ? ' ' : '').'nowrap';
1430  }
1431  if ($key == 'status' || $key == 'statut') {
1432  $align .= ($align ? ' ' : '').'center';
1433  }
1434  if (!empty($arrayfields['t.'.$key]['checked'])) {
1435  print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1436  }
1437  if ($key == 'role') {
1438  $align .= ($align ? ' ' : '').'left';
1439  }
1440  if (!empty($arrayfields['sc.'.$key]['checked'])) {
1441  print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1442  }
1443  }
1444  if ($showuserlogin) {
1445  print '<th class="wrapcolumntitle liste_titre">'.$langs->trans("DolibarrLogin").'</th>';
1446  }
1447  // Extra fields
1448  $extrafieldsobjectkey = $contactstatic->table_element;
1449  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1450  // Hook fields
1451  $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1452  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1453  print $hookmanager->resPrint;
1454  // Action column
1455  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1456  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1457  }
1458  print '</tr>'."\n";
1459 
1460  $i = -1;
1461 
1462  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1463  $i = 0;
1464 
1465  while ($i < $num) {
1466  $obj = $db->fetch_object($result);
1467 
1468  $contactstatic->id = $obj->rowid;
1469  $contactstatic->ref = $obj->rowid;
1470  $contactstatic->statut = $obj->statut;
1471  $contactstatic->lastname = $obj->lastname;
1472  $contactstatic->firstname = $obj->firstname;
1473  $contactstatic->civility_id = $obj->civility_id;
1474  $contactstatic->civility_code = $obj->civility_id;
1475  $contactstatic->poste = $obj->poste;
1476  $contactstatic->address = $obj->address;
1477  $contactstatic->zip = $obj->zip;
1478  $contactstatic->town = $obj->town;
1479  $contactstatic->phone_pro = $obj->phone_pro;
1480  $contactstatic->phone_mobile = $obj->phone_mobile;
1481  $contactstatic->phone_perso = $obj->phone_perso;
1482  $contactstatic->email = $obj->email;
1483  $contactstatic->socialnetworks = $obj->socialnetworks;
1484  $contactstatic->photo = $obj->photo;
1485  $contactstatic->fk_soc = $obj->fk_soc;
1486  $contactstatic->entity = $obj->entity;
1487 
1488  $country_code = getCountry($obj->country_id, 2);
1489  $contactstatic->country_code = $country_code;
1490 
1491  $contactstatic->setGenderFromCivility();
1492  $contactstatic->fetch_optionals();
1493 
1494  $resultRole = $contactstatic->fetchRoles();
1495  if ($resultRole < 0) {
1496  setEventMessages(null, $contactstatic->errors, 'errors');
1497  }
1498 
1499  if (is_array($contactstatic->array_options)) {
1500  foreach ($contactstatic->array_options as $key => $val) {
1501  $obj->$key = $val;
1502  }
1503  }
1504 
1505  print '<tr class="oddeven">';
1506 
1507  // Actions
1508  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1509  print '<td class="nowrap center">';
1510 
1511  // Add to agenda
1512  if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1513  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1514  print img_object($langs->trans("Event"), "action");
1515  print '</a> &nbsp; ';
1516  }
1517 
1518  // Edit
1519  if ($user->hasRight('societe', 'contact', 'creer')) {
1520  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1521  print img_edit();
1522  print '</a>';
1523  }
1524 
1525  // Delete
1526  if ($user->hasRight('societe', 'contact', 'delete')) {
1527  print '<a class="marginleftonly right" href="'.DOL_URL_ROOT.'/societe/contact.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1528  print img_delete();
1529  print '</a>';
1530  }
1531 
1532  print '</td>';
1533  }
1534 
1535  // ID
1536  if (!empty($arrayfields['t.rowid']['checked'])) {
1537  print '<td>';
1538  print $contactstatic->id;
1539  print '</td>';
1540  }
1541 
1542  // Photo - Name
1543  if (!empty($arrayfields['t.name']['checked'])) {
1544  print '<td class="tdoverflowmax150">';
1545  print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 1);
1546  print $contactstatic->getNomUrl(0, '', 0, '&backtopage='.urlencode($backtopage));
1547  print '</td>';
1548  }
1549 
1550  // Job position
1551  if (!empty($arrayfields['t.poste']['checked'])) {
1552  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->poste).'">';
1553  if ($obj->poste) {
1554  print dol_escape_htmltag($obj->poste);
1555  }
1556  print '</td>';
1557  }
1558 
1559  // Address - Phone - Email
1560  if (!empty($arrayfields['t.address']['checked'])) {
1561  $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1562  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($addresstoshow)).'">';
1563  print $addresstoshow;
1564  print '</td>';
1565  }
1566 
1567  // Note private
1568  if (!empty($arrayfields['t.note_private']['checked'])) {
1569  print '<td>';
1570  if ($obj->note_private) {
1571  print dol_string_nohtmltag($obj->note_private);
1572  }
1573  print '</td>';
1574  }
1575 
1576  // Role
1577  if (!empty($arrayfields['sc.role']['checked'])) {
1578  print '<td class="tdoverflowmax150">';
1579  print $formcompany->showRoles("roles", $contactstatic, 'view');
1580  print '</td>';
1581  }
1582 
1583  // Birthday
1584  if (!empty($arrayfields['t.birthday']['checked'])) {
1585  print '<td class="nowraponall">';
1586  print dol_print_date($db->jdate($obj->birthday));
1587  print '</td>';
1588  }
1589 
1590  // Status
1591  if (!empty($arrayfields['t.statut']['checked'])) {
1592  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1593  }
1594 
1595  if ($showuserlogin) {
1596  print '<td class="tdoverflowmax125">';
1597  $tmpuser = new User($db);
1598  // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1599  $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1600  if ($resfetch > 0) {
1601  print $tmpuser->getNomUrl(1, '', 0, 0, 24, 1);
1602  }
1603  print '</td>';
1604  }
1605 
1606  // Extra fields
1607  $extrafieldsobjectkey = $contactstatic->table_element;
1608  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1609 
1610  // Actions
1611  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1612  print '<td class="nowrap center">';
1613 
1614  // Add to agenda
1615  if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1616  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1617  print img_object($langs->trans("Event"), "action");
1618  print '</a> &nbsp; ';
1619  }
1620 
1621  // Edit
1622  if ($user->hasRight('societe', 'contact', 'creer')) {
1623  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1624  print img_edit();
1625  print '</a>';
1626  }
1627 
1628  // Delete
1629  if ($user->hasRight('societe', 'contact', 'delete')) {
1630  print '<a class="marginleftonly right" href="'.DOL_URL_ROOT.'/societe/contact.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&socid='.urlencode($obj->fk_soc).'">';
1631  print img_delete();
1632  print '</a>';
1633  }
1634 
1635  print '</td>';
1636  }
1637 
1638  print "</tr>\n";
1639  $i++;
1640  }
1641 
1642  if ($num == 0) {
1643  $colspan = 1 + ($showuserlogin ? 1 : 0);
1644  foreach ($arrayfields as $key => $val) {
1645  if (!empty($val['checked'])) {
1646  $colspan++;
1647  }
1648  }
1649  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1650  }
1651  } else {
1652  $colspan = 1 + ($showuserlogin ? 1 : 0);
1653  foreach ($arrayfields as $key => $val) {
1654  if (!empty($val['checked'])) {
1655  $colspan++;
1656  }
1657  }
1658  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1659  }
1660  print "\n</table>\n";
1661  print '</div>';
1662 
1663  print '</form>'."\n";
1664 
1665  return $i;
1666 }
1667 
1668 
1681 function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '')
1682 {
1683  global $user, $conf;
1684 
1685  $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1686 
1687  if ($noprint) {
1688  return $out;
1689  } else {
1690  print $out;
1691  }
1692 }
1693 
1712 function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1713 {
1714  global $user, $conf, $hookmanager;
1715  global $form;
1716  global $param, $massactionbutton;
1717 
1718  $start_year = GETPOSTINT('dateevent_startyear');
1719  $start_month = GETPOSTINT('dateevent_startmonth');
1720  $start_day = GETPOSTINT('dateevent_startday');
1721  $end_year = GETPOSTINT('dateevent_endyear');
1722  $end_month = GETPOSTINT('dateevent_endmonth');
1723  $end_day = GETPOSTINT('dateevent_endday');
1724  $tms_start = '';
1725  $tms_end = '';
1726 
1727  if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1728  $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1729  }
1730  if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1731  $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1732  }
1733  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
1734  $tms_start = '';
1735  $tms_end = '';
1736  }
1737  require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1738 
1739  // Check parameters
1740  if (!is_object($filterobj) && !is_object($objcon)) {
1741  dol_print_error(null, 'BadParameter');
1742  }
1743 
1744  $out = '';
1745  $histo = array();
1746  $numaction = 0;
1747  $now = dol_now('tzuser');
1748 
1749  // Open DSI -- Fix order by -- Begin
1750  $sortfield_list = explode(',', $sortfield);
1751  $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1752  $sortfield_new_list = array();
1753  foreach ($sortfield_list as $sortfield_value) {
1754  $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1755  }
1756  $sortfield_new = implode(',', $sortfield_new_list);
1757 
1758  $sql = '';
1759 
1760  if (isModEnabled('agenda')) {
1761  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1762  $hookmanager->initHooks(array('agendadao'));
1763 
1764  // Recherche histo sur actioncomm
1765  if (is_object($objcon) && $objcon->id > 0) {
1766  $sql = "SELECT DISTINCT a.id, a.label as label,";
1767  } else {
1768  $sql = "SELECT a.id, a.label as label,";
1769  }
1770  $sql .= " a.datep as dp,";
1771  $sql .= " a.datep2 as dp2,";
1772  $sql .= " a.percent as percent, 'action' as type,";
1773  $sql .= " a.fk_element, a.elementtype,";
1774  $sql .= " a.fk_contact,";
1775  $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1776  $sql .= " u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname";
1777  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1778  $sql .= ", sp.lastname, sp.firstname";
1779  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1780  /* Nothing */
1781  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1782  /* Nothing */
1783  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1784  $sql .= ", m.lastname, m.firstname";
1785  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1786  $sql .= ", o.ref";
1787  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1788  $sql .= ", o.ref";
1789  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1790  $sql .= ", o.ref";
1791  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1792  $sql .= ", o.ref";
1793  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1794  $sql .= ", o.ref";
1795  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1796  if (!empty($filterobj->fields['ref'])) {
1797  $sql .= ", o.ref";
1798  } elseif (!empty($filterobj->fields['label'])) {
1799  $sql .= ", o.label";
1800  }
1801  }
1802 
1803  // Fields from hook
1804  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1805  $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1806  if (!empty($hookmanager->resPrint)) {
1807  $sql .= $hookmanager->resPrint;
1808  }
1809 
1810  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1811  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1812  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1813 
1814  if (is_object($filterobj) && get_class($filterobj) !== 'User') {
1815  $force_filter_contact = false;
1816  } else {
1817  $force_filter_contact = true;
1818  }
1819  if (is_object($objcon) && $objcon->id > 0) {
1820  $force_filter_contact = true;
1821  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1822  $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
1823  }
1824 
1825  // Fields from hook
1826  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1827  $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1828  if (!empty($hookmanager->resPrint)) {
1829  $sql .= $hookmanager->resPrint;
1830  }
1831  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1832  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1833  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1834  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1835  $sql .= " ON er.resource_type = 'dolresource'";
1836  $sql .= " AND er.element_id = a.id";
1837  $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1838  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1839  /* Nothing */
1840  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1841  $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1842  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1843  $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1844  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1845  $sql .= ", ".MAIN_DB_PREFIX."product as o";
1846  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1847  $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1848  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1849  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1850  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1851  $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1852  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1853  && ((!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref'])) || (!empty($filterobj->fields['label']) && is_array($filterobj->fields['label'])) || (!empty($filterobj->fields['titre']) && is_array($filterobj->fields['titre'])))
1854  && $filterobj->table_element && $filterobj->element) {
1855  $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1856  }
1857 
1858  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1859  if ($force_filter_contact === false) {
1860  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1861  $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1862  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1863  /* Nothing */
1864  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1865  $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1866  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1867  $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1868  if ($filterobj->id) {
1869  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1870  }
1871  } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
1872  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
1873  if ($filterobj->id) {
1874  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1875  }
1876  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1877  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1878  if ($filterobj->id) {
1879  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1880  }
1881  } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
1882  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
1883  if ($filterobj->id) {
1884  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1885  }
1886  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1887  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1888  if ($filterobj->id) {
1889  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1890  }
1891  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1892  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1893  if ($filterobj->id) {
1894  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1895  }
1896  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1897  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1898  if ($filterobj->id) {
1899  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1900  }
1901  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1902  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1903  if ($filterobj->id) {
1904  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1905  }
1906  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1907  && ((!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref'])) || (!empty($filterobj->fields['label']) && is_array($filterobj->fields['label'])) || (!empty($filterobj->fields['titre']) && is_array($filterobj->fields['titre'])))
1908  && $filterobj->table_element && $filterobj->element) {
1909  // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
1910  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1911  if ($filterobj->id) {
1912  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1913  }
1914  } elseif (is_object($filterobj)) {
1915  return 'Bad value for $filterobj';
1916  }
1917  } else {
1918  $sql .= " AND u.rowid = ". ((int) $filterobj->id);
1919  }
1920 
1921  if (!empty($tms_start) && !empty($tms_end)) {
1922  $sql .= " AND ((a.datep BETWEEN '".$db->idate($tms_start)."' AND '".$db->idate($tms_end)."') OR (a.datep2 BETWEEN '".$db->idate($tms_start)."' AND '".$db->idate($tms_end)."'))";
1923  } elseif (empty($tms_start) && !empty($tms_end)) {
1924  $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1925  } elseif (!empty($tms_start) && empty($tms_end)) {
1926  $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1927  }
1928 
1929  if (is_array($actioncode) && !empty($actioncode)) {
1930  $sql .= ' AND (';
1931  foreach ($actioncode as $key => $code) {
1932  if ($key != 0) {
1933  $sql .= " OR ";
1934  }
1935  if (!empty($code)) {
1936  addEventTypeSQL($sql, $code, "");
1937  }
1938  }
1939  $sql .= ')';
1940  } elseif (!empty($actioncode)) {
1941  addEventTypeSQL($sql, $actioncode);
1942  }
1943 
1944  addOtherFilterSQL($sql, $donetodo, $now, $filters);
1945 
1946  // Fields from hook
1947  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
1948  $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
1949  if (!empty($hookmanager->resPrint)) {
1950  $sql .= $hookmanager->resPrint;
1951  }
1952 
1953  if (is_array($actioncode)) {
1954  foreach ($actioncode as $code) {
1955  $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1956  if (!empty($sql2)) {
1957  if (!empty($sql)) {
1958  $sql = $sql." UNION ".$sql2;
1959  } elseif (empty($sql)) {
1960  $sql = $sql2;
1961  }
1962  break;
1963  }
1964  }
1965  } else {
1966  $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
1967  if (!empty($sql) && !empty($sql2)) {
1968  $sql = $sql." UNION ".$sql2;
1969  } elseif (empty($sql) && !empty($sql2)) {
1970  $sql = $sql2;
1971  }
1972  }
1973  }
1974 
1975  if ($sql) {
1976  //TODO Add navigation with this limits...
1977  $offset = 0;
1978  $limit = 1000;
1979 
1980  // Complete request and execute it with limit
1981  $sql .= $db->order($sortfield_new, $sortorder);
1982  if ($limit) {
1983  $sql .= $db->plimit($limit + 1, $offset);
1984  }
1985 
1986  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1987 
1988  $resql = $db->query($sql);
1989  if ($resql) {
1990  $i = 0;
1991  $num = $db->num_rows($resql);
1992 
1993  $imaxinloop = ($limit ? min($num, $limit) : $num);
1994  while ($i < $imaxinloop) {
1995  $obj = $db->fetch_object($resql);
1996 
1997  if ($obj->type == 'action') {
1998  $contactaction = new ActionComm($db);
1999  $contactaction->id = $obj->id;
2000  $result = $contactaction->fetchResources();
2001  if ($result < 0) {
2002  dol_print_error($db);
2003  setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2004  }
2005 
2006  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2007  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2008  $tododone = '';
2009  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2010  $tododone = 'todo';
2011  }
2012 
2013  $histo[$numaction] = array(
2014  'type' => $obj->type,
2015  'tododone' => $tododone,
2016  'id' => $obj->id,
2017  'datestart' => $db->jdate($obj->dp),
2018  'dateend' => $db->jdate($obj->dp2),
2019  'note' => $obj->label,
2020  'percent' => $obj->percent,
2021 
2022  'userid' => $obj->user_id,
2023  'login' => $obj->user_login,
2024  'userfirstname' => $obj->user_firstname,
2025  'userlastname' => $obj->user_lastname,
2026  'userphoto' => $obj->user_photo,
2027 
2028  'contact_id' => $obj->fk_contact,
2029  'socpeopleassigned' => $contactaction->socpeopleassigned,
2030  'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2031  'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2032  'fk_element' => $obj->fk_element,
2033  'elementtype' => $obj->elementtype,
2034  // Type of event
2035  'acode' => $obj->acode,
2036  'alabel' => $obj->alabel,
2037  'libelle' => $obj->alabel, // deprecated
2038  'apicto' => $obj->apicto
2039  );
2040  } else {
2041  $histo[$numaction] = array(
2042  'type' => $obj->type,
2043  'tododone' => 'done',
2044  'id' => $obj->id,
2045  'datestart' => $db->jdate($obj->dp),
2046  'dateend' => $db->jdate($obj->dp2),
2047  'note' => $obj->label,
2048  'percent' => $obj->percent,
2049  'acode' => $obj->acode,
2050 
2051  'userid' => $obj->user_id,
2052  'login' => $obj->user_login,
2053  'userfirstname' => $obj->user_firstname,
2054  'userlastname' => $obj->user_lastname,
2055  'userphoto' => $obj->user_photo
2056  );
2057  }
2058 
2059  $numaction++;
2060  $i++;
2061  }
2062  } else {
2063  dol_print_error($db);
2064  }
2065  }
2066 
2067  '@phan-var-force array<int,array{userid:int,type:string,tododone:string,apicto:string,acode:string,alabel:string,note:string,id:int,percent:int<0,100>,datestart:int,dateend:int,fk_element:string,elementtype:string,contact_id:string,lastname:string,firstname:string,contact_photo:string,socpeaopleassigned:int[],login:string,userfirstname:string,userlastname:string,userphoto:string}> $histo';
2068 
2069  if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2070  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
2071 
2072  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
2073  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2074  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2075  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2076 
2077  $formactions = new FormActions($db);
2078 
2079  $actionstatic = new ActionComm($db);
2080  $userstatic = new User($db);
2081  $userlinkcache = array();
2082  $contactstatic = new Contact($db);
2083  $elementlinkcache = array();
2084 
2085  $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2086  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
2087  if ($objcon && get_class($objcon) == 'Contact' &&
2088  (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
2089  $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
2090  } else {
2091  $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
2092  }
2093  if ($filterobj && get_class($filterobj) == 'Societe') {
2094  $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
2095  } else {
2096  $out .= '<input type="hidden" name="userid" value="'.$filterobj->id.'" />';
2097  }
2098 
2099  $out .= "\n";
2100 
2101  $out .= '<div class="div-table-responsive-no-min">';
2102  $out .= '<table class="noborder centpercent">';
2103 
2104  $out .= '<tr class="liste_titre">';
2105 
2106  // Action column
2107  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2108  $out .= '<th class="liste_titre width50 middle">';
2109  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2110  $out .= $searchpicto;
2111  $out .= '</th>';
2112  }
2113 
2114  if ($donetodo) {
2115  $out .= '<td class="liste_titre"></td>';
2116  }
2117 
2118  $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
2119  $out .= '<td class="liste_titre"></td>';
2120  $out .= '<td class="liste_titre">';
2121  $out .= $formactions->select_type_actions($actioncode, "actioncode", '', getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, (getDolGlobalString('AGENDA_USE_MULTISELECT_TYPE') ? 1 : 0), 1, 'combolargeelem minwidth100 maxwidth150');
2122  $out .= '</td>';
2123  $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
2124  $out .= '<td class="liste_titre center">';
2125  $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2126  $out .= '</td>';
2127  $out .= '<td class="liste_titre"></td>';
2128  $out .= '<td class="liste_titre"></td>';
2129  $out .= '<td class="liste_titre"></td>';
2130  // Action column
2131  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2132  $out .= '<td class="liste_titre" align="middle">';
2133  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2134  $out .= $searchpicto;
2135  $out .= '</td>';
2136  }
2137  $out .= '</tr>';
2138 
2139  $out .= '<tr class="liste_titre">';
2140  // Action column
2141  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2142  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2143  }
2144  if ($donetodo) {
2145  $tmp = '';
2146  if (get_class($filterobj) == 'Societe') {
2147  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
2148  }
2149  if (get_class($filterobj) == 'User') {
2150  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&userid='.$filterobj->id.'&status=done">';
2151  }
2152  $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2153  $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2154  $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2155  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2156  if (get_class($filterobj) == 'Societe') {
2157  $tmp .= '</a>';
2158  }
2159  if (get_class($filterobj) == 'User') {
2160  $tmp .= '</a>';
2161  }
2162  $out .= getTitleFieldOfList($tmp);
2163  }
2164  $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2165  $out .= getTitleFieldOfList("Owner");
2166  $out .= getTitleFieldOfList("Type");
2167  $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2168  $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2169  $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2170  $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2171  $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2172  // Action column
2173  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2174  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2175  }
2176  $out .= '</tr>';
2177 
2178  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
2179  $caction = new CActionComm($db);
2180  $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
2181 
2182  foreach ($histo as $key => $value) {
2183  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2184 
2185  $actionstatic->type_picto = $histo[$key]['apicto'];
2186  $actionstatic->type_code = $histo[$key]['acode'];
2187 
2188  $out .= '<tr class="oddeven">';
2189 
2190  // Action column
2191  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2192  $out .= '<td></td>';
2193  }
2194 
2195  // Done or todo
2196  if ($donetodo) {
2197  $out .= '<td class="nowrap">';
2198  $out .= '</td>';
2199  }
2200 
2201  // Ref
2202  $out .= '<td class="nowraponall">';
2203  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2204  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2205  $out .= $histo[$key]['id'];
2206  $out .= '</a>';
2207  } else {
2208  $out .= $actionstatic->getNomUrl(1, -1);
2209  }
2210  $out .= '</td>';
2211 
2212  // Author of event
2213  $out .= '<td class="tdoverflowmax125">';
2214  if ($histo[$key]['userid'] > 0) {
2215  if (isset($userlinkcache[$histo[$key]['userid']])) {
2216  $link = $userlinkcache[$histo[$key]['userid']];
2217  } else {
2218  $userstatic->fetch($histo[$key]['userid']);
2219  $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2220  $userlinkcache[$histo[$key]['userid']] = $link;
2221  }
2222  $out .= $link;
2223  }
2224  $out .= '</td>';
2225 
2226  // Type
2227  $labeltype = $actionstatic->type_code;
2228  if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
2229  $labeltype = 'AC_OTH';
2230  }
2231  if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2232  $labeltype = $langs->trans("Message");
2233  } else {
2234  if (!empty($arraylist[$labeltype])) {
2235  $labeltype = $arraylist[$labeltype];
2236  }
2237  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
2238  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
2239  }
2240  }
2241  $out .= '<td class="tdoverflowmax125" title="'.$labeltype.'">';
2242  $out .= $actionstatic->getTypePicto();
2243  //if (empty($conf->dol_optimize_smallscreen)) {
2244  $out .= $labeltype;
2245  //}
2246  $out .= '</td>';
2247 
2248  // Title/Label of event
2249  $out .= '<td class="tdoverflowmax300"';
2250  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2251  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2252  //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2253  $libelle = $histo[$key]['note'];
2254  $actionstatic->id = $histo[$key]['id'];
2255  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2256  $out .= dol_trunc($libelle, 120);
2257  }
2258  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2259  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2260  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2261  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2262  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2263  $out .= dol_trunc($libelle, 120);
2264  }
2265  $out .= '</td>';
2266 
2267  // Date
2268  $out .= '<td class="center nowraponall">';
2269  $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
2270  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
2271  $tmpa = dol_getdate($histo[$key]['datestart'], true);
2272  $tmpb = dol_getdate($histo[$key]['dateend'], true);
2273  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2274  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
2275  } else {
2276  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
2277  }
2278  }
2279  $late = 0;
2280  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2281  $late = 1;
2282  }
2283  if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2284  $late = 1;
2285  }
2286  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2287  $late = 1;
2288  }
2289  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2290  $late = 1;
2291  }
2292  if ($late) {
2293  $out .= img_warning($langs->trans("Late")).' ';
2294  }
2295  $out .= "</td>\n";
2296 
2297  // Linked object
2298  $out .= '<td class="nowraponall">';
2299  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2300  if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2301  $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2302  } else {
2303  if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2304  $elementlinkcache[$histo[$key]['elementtype']] = array();
2305  }
2306  $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2307  $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2308  }
2309  $out .= $link;
2310  }
2311  $out .= '</td>';
2312 
2313  // Contact(s) for action
2314  if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2315  $out .= '<td class="valignmiddle">';
2316  $contact = new Contact($db);
2317  foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2318  $result = $contact->fetch($cid);
2319 
2320  if ($result < 0) {
2321  dol_print_error($db, $contact->error);
2322  }
2323 
2324  if ($result > 0) {
2325  $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2326  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2327  if (!empty($contact->phone_pro)) {
2328  $out .= '('.dol_print_phone($contact->phone_pro).')';
2329  }
2330  }
2331  $out .= '<div class="paddingright"></div>';
2332  }
2333  }
2334  $out .= '</td>';
2335  } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2336  $contactstatic->lastname = $histo[$key]['lastname'];
2337  $contactstatic->firstname = $histo[$key]['firstname'];
2338  $contactstatic->id = $histo[$key]['contact_id'];
2339  $contactstatic->photo = $histo[$key]['contact_photo'];
2340  $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2341  } else {
2342  $out .= '<td>&nbsp;</td>';
2343  }
2344 
2345  // Status
2346  $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2347 
2348  // Action column
2349  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2350  $out .= '<td></td>';
2351  }
2352 
2353  $out .= "</tr>\n";
2354  }
2355  if (empty($histo)) {
2356  $colspan = 9;
2357  $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2358  }
2359 
2360  $out .= "</table>\n";
2361  $out .= "</div>\n";
2362 
2363  $out .= '</form>';
2364  }
2365 
2366  if ($noprint) {
2367  return $out;
2368  } else {
2369  print $out;
2370  }
2371 }
2372 
2382 function show_subsidiaries($conf, $langs, $db, $object)
2383 {
2384  global $user;
2385 
2386  $i = -1;
2387 
2388  $sql = "SELECT s.rowid, s.client, s.fournisseur, s.nom as name, s.name_alias, s.email, s.address, s.zip, s.town, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.canvas";
2389  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2390  $sql .= " WHERE s.parent = ".((int) $object->id);
2391  $sql .= " AND s.entity IN (".getEntity('societe').")";
2392  $sql .= " ORDER BY s.nom";
2393 
2394  $result = $db->query($sql);
2395  $num = $db->num_rows($result);
2396 
2397  if ($num) {
2398  $socstatic = new Societe($db);
2399 
2400  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2401 
2402  print "\n".'<div class="div-table-responsive-no-min">'."\n";
2403  print '<table class="noborder centpercent">'."\n";
2404 
2405  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2406  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2407  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2408  print "<td>&nbsp;</td>";
2409  print "</tr>";
2410 
2411  $i = 0;
2412 
2413  while ($i < $num) {
2414  $obj = $db->fetch_object($result);
2415 
2416  $socstatic->id = $obj->rowid;
2417  $socstatic->name = $obj->name;
2418  $socstatic->name_alias = $obj->name_alias;
2419  $socstatic->email = $obj->email;
2420  $socstatic->code_client = $obj->code_client;
2421  $socstatic->code_fournisseur = $obj->code_fournisseur;
2422  $socstatic->code_compta = $obj->code_compta;
2423  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2424  $socstatic->email = $obj->email;
2425  $socstatic->canvas = $obj->canvas;
2426  $socstatic->client = $obj->client;
2427  $socstatic->fournisseur = $obj->fournisseur;
2428 
2429  print '<tr class="oddeven">';
2430 
2431  print '<td class="tdoverflowmax150">';
2432  print $socstatic->getNomUrl(1);
2433  print '</td>';
2434 
2435  print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2436  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2437  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2438  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2439 
2440  print '<td class="center">';
2441  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2442  print img_edit();
2443  print '</a></td>';
2444 
2445  print "</tr>\n";
2446  $i++;
2447  }
2448  print "\n</table>\n";
2449  print '</div>'."\n";
2450  }
2451 
2452  print "<br>\n";
2453 
2454  return $i;
2455 }
2464 function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2465 {
2466  global $conf, $db;
2467  // Condition on actioncode
2468 
2469  if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2470  if ($actioncode == 'AC_NON_AUTO') {
2471  $sql .= " $sqlANDOR c.type <> 'systemauto'";
2472  } elseif ($actioncode == 'AC_ALL_AUTO') {
2473  $sql .= " $sqlANDOR c.type = 'systemauto'";
2474  } else {
2475  if ($actioncode == 'AC_OTH') {
2476  $sql .= " $sqlANDOR c.type <> 'systemauto'";
2477  } elseif ($actioncode == 'AC_OTH_AUTO') {
2478  $sql .= " $sqlANDOR c.type = 'systemauto'";
2479  }
2480  }
2481  } else {
2482  if ($actioncode == 'AC_NON_AUTO') {
2483  $sql .= " $sqlANDOR c.type <> 'systemauto'";
2484  } elseif ($actioncode == 'AC_ALL_AUTO') {
2485  $sql .= " $sqlANDOR c.type = 'systemauto'";
2486  } else {
2487  $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2488  }
2489  }
2490 
2491  return $sql;
2492 }
2493 
2503 function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2504 {
2505  global $db;
2506 
2507  if ($donetodo == 'todo') {
2508  $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2509  } elseif ($donetodo == 'done') {
2510  $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2511  }
2512  if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2513  $sql .= natural_search('a.label', $filters['search_agenda_label']);
2514  }
2515  if (is_array($filters) && !empty($filters['search_rowid'])) {
2516  $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2517  }
2518 
2519  return $sql;
2520 }
2521 
2530 function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2531 {
2532  global $db;
2533 
2534  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2535  if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2536  $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type";
2537  $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2538  $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2539  $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action
2540  if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2541  $sql2 .= ", '' as lastname, '' as firstname";
2542  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2543  $sql2 .= ", '' as lastname, '' as firstname";
2544  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2545  $sql2 .= ", '' as ref";
2546  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2547  $sql2 .= ", '' as ref";
2548  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2549  $sql2 .= ", '' as ref";
2550  }
2551  $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2552  $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2553  $sql2 .= " AND mc.statut = 1";
2554  $sql2 .= " AND u.rowid = m.fk_user_valid";
2555  $sql2 .= " AND mc.fk_mailing=m.rowid";
2556 
2557  return $sql2;
2558  } else {
2559  return '';
2560  }
2561 }
2562 
2563 
2564 
2575 function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2576 {
2577  global $conf;
2578 
2579  $reg = array();
2580 
2581  // Juridical status
2582  $line1 = "";
2583  if ($fromcompany->forme_juridique_code) {
2584  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
2585  }
2586  // Capital
2587  if ($fromcompany->capital) {
2588  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
2589  }
2590  // Prof Id 1
2591  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2592  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2593  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2594  $field = $reg[1];
2595  }
2596  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
2597  }
2598  // Prof Id 2
2599  if ($fromcompany->idprof2) {
2600  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2601  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2602  $field = $reg[1];
2603  }
2604  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
2605  }
2606 
2607  // Second line of company infos
2608  $line2 = "";
2609  // Prof Id 3
2610  if ($fromcompany->idprof3) {
2611  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2612  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2613  $field = $reg[1];
2614  }
2615  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
2616  }
2617  // Prof Id 4
2618  if ($fromcompany->idprof4) {
2619  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2620  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2621  $field = $reg[1];
2622  }
2623  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
2624  }
2625  // IntraCommunautary VAT
2626  if ($fromcompany->tva_intra != '') {
2627  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
2628  }
2629 
2630  print '<!-- htmlPrintOnlineFooter -->'."\n";
2631 
2632  // css centpercent has been removed from class="..." because not compatible with paddingleft/right and there is an horizontal scroll appearring on payment page for example.
2633  print '<footer class="center paddingleft paddingright opacitymedium">'."\n";
2634  print '<br>';
2635  if ($addformmessage) {
2636  print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
2637  print '<br>';
2638 
2639  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
2640  if (getDolGlobalString($parammessageform) !== '') {
2641  print $langs->transnoentities(getDolGlobalString($parammessageform));
2642  } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
2643  print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
2644  }
2645 
2646  // Add other message if VAT exists
2647  if (!empty($object->total_vat) || !empty($object->total_tva)) {
2648  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
2649  if (getDolGlobalString($parammessageform) !== '') {
2650  print $langs->transnoentities(getDolGlobalString($parammessageform));
2651  } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
2652  print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
2653  }
2654  }
2655  }
2656 
2657  print '<span style="font-size: 10px;"><br><hr>'."\n";
2658  print $fromcompany->name.'<br>';
2659  print $line1;
2660  if (strlen($line1.$line2) > 50) {
2661  print '<br>';
2662  } else {
2663  print ' - ';
2664  }
2665  print $line2;
2666  print '</span>';
2667  print '</footer>'."\n";
2668 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class for SocieteAccount.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:50
getState($id, $withcode='', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
show_actions_done($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
societe_prepare_head2($object)
Return array of tabs to used on page.
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:43
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
societe_admin_prepare_head()
Return array head with list of tabs to view object information.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='')
Show html area with actions to do.
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:63
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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...
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:69
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:141