dolibarr  19.0.0-dev
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-2021 Frédéric France <frederic.france@netlogic.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  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  * or see https://www.gnu.org/
28  */
29 
42 function societe_prepare_head(Societe $object)
43 {
44  global $db, $langs, $conf, $user;
45  global $hookmanager;
46 
47  $h = 0;
48  $head = array();
49 
50  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
51  $head[$h][1] = $langs->trans("ThirdParty");
52  $head[$h][2] = 'card';
53  $h++;
54 
55  if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) {
56  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->hasRight('societe', 'contact', 'lire')) {
57  //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
58  $nbContact = 0;
59  // Enable caching of thirdrparty count Contacts
60  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
61  $cachekey = 'count_contacts_thirdparty_'.$object->id;
62  $dataretrieved = dol_getcache($cachekey);
63 
64  if (!is_null($dataretrieved)) {
65  $nbContact = $dataretrieved;
66  } else {
67  $sql = "SELECT COUNT(p.rowid) as nb";
68  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
69  // Add table from hooks
70  $parameters = array('contacttab' => true);
71  $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
72  $sql .= $hookmanager->resPrint;
73  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
74  // Add where from hooks
75  $parameters = array('contacttab' => true);
76  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
77  $sql .= $hookmanager->resPrint;
78  $resql = $db->query($sql);
79  if ($resql) {
80  $obj = $db->fetch_object($resql);
81  $nbContact = $obj->nb;
82  }
83 
84  dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result.
85  }
86 
87  $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
88  $head[$h][1] = $langs->trans('ContactsAddresses');
89  if ($nbContact > 0) {
90  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
91  }
92  $head[$h][2] = 'contact';
93  $h++;
94  }
95  } else {
96  $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
97  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
98  $head[$h][1] = $langs->trans("ContactsAddresses");
99  if ($nbContact > 0) {
100  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
101  }
102  $head[$h][2] = 'contact';
103  $h++;
104  }
105 
106  if ($object->client == 1 || $object->client == 2 || $object->client == 3) {
107  $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
108  $head[$h][1] = '';
109  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client == 2 || $object->client == 3)) {
110  $head[$h][1] .= $langs->trans("Prospect");
111  }
112  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client == 3) {
113  $head[$h][1] .= ' | ';
114  }
115  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client == 1 || $object->client == 3)) {
116  $head[$h][1] .= $langs->trans("Customer");
117  }
118  $head[$h][2] = 'customer';
119  $h++;
120 
121  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
122  $langs->load("products");
123  // price
124  $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
125  $head[$h][1] = $langs->trans("CustomerPrices");
126  $head[$h][2] = 'price';
127  $h++;
128  }
129  }
130  $supplier_module_enabled = 0;
131  if (isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
132  $supplier_module_enabled = 1;
133  }
134  if ($supplier_module_enabled == 1 && $object->fournisseur && !empty($user->rights->fournisseur->lire)) {
135  $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
136  $head[$h][1] = $langs->trans("Supplier");
137  $head[$h][2] = 'supplier';
138  $h++;
139  }
140 
141  if (isModEnabled('project') && (!empty($user->rights->projet->lire))) {
142  $nbProject = 0;
143  // Enable caching of thirdrparty count projects
144  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
145  $cachekey = 'count_projects_thirdparty_'.$object->id;
146  $dataretrieved = dol_getcache($cachekey);
147 
148  if (!is_null($dataretrieved)) {
149  $nbProject = $dataretrieved;
150  } else {
151  $sql = "SELECT COUNT(n.rowid) as nb";
152  $sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
153  $sql .= " WHERE fk_soc = ".((int) $object->id);
154  $sql .= " AND entity IN (".getEntity('project').")";
155  $resql = $db->query($sql);
156  if ($resql) {
157  $obj = $db->fetch_object($resql);
158  $nbProject = $obj->nb;
159  } else {
160  dol_print_error($db);
161  }
162  dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
163  }
164  $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
165  $head[$h][1] = $langs->trans("Projects");
166  if ($nbProject > 0) {
167  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
168  }
169  $head[$h][2] = 'project';
170  $h++;
171  }
172 
173  // Tab to link resources
174  if (isModEnabled('resource') && !empty($conf->global->RESOURCE_ON_THIRDPARTIES)) {
175  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
176  $head[$h][1] = $langs->trans("Resources");
177  $head[$h][2] = 'resources';
178  $h++;
179  }
180 
181  // Related items
182  if ((isModEnabled('commande') || isModEnabled('propal') || isModEnabled('facture') || isModEnabled('ficheinter') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
183  && empty($conf->global->THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB)) {
184  $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
185  $head[$h][1] = $langs->trans("Referers");
186  $head[$h][2] = 'consumption';
187  $h++;
188  }
189 
190  // Bank accounts
191  if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT)) {
192  $nbBankAccount = 0;
193  $foundonexternalonlinesystem = 0;
194  $langs->load("bills");
195 
196  $title = $langs->trans("PaymentModes");
197 
198  if (isModEnabled('stripe')) {
199  //$langs->load("stripe");
200  //$title = $langs->trans("BankAccountsAndGateways");
201 
202  $servicestatus = 0;
203  if (!empty($conf->global->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($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') && (!empty($conf->global->WEBSITE_USE_WEBSITE_ACCOUNTS)) && ($user->hasRight('societe', 'lire'))) {
246  $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.urlencode($object->id);
247  $head[$h][1] = $langs->trans("WebSiteAccounts");
248  $nbNote = 0;
249  $sql = "SELECT COUNT(n.rowid) as nb";
250  $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as n";
251  $sql .= " WHERE fk_soc = ".((int) $object->id).' AND fk_website > 0';
252  $resql = $db->query($sql);
253  if ($resql) {
254  $obj = $db->fetch_object($resql);
255  $nbNote = $obj->nb;
256  } else {
257  dol_print_error($db);
258  }
259  if ($nbNote > 0) {
260  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
261  }
262  $head[$h][2] = 'website';
263  $h++;
264  }
265 
266  if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
267  if (!empty($user->rights->partnership->read)) {
268  $langs->load("partnership");
269  $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
270  $head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?socid='.$object->id;
271  $head[$h][1] = $langs->trans("Partnerships");
272  $nbNote = 0;
273  $sql = "SELECT COUNT(n.rowid) as nb";
274  $sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
275  $sql .= " WHERE fk_soc = ".((int) $object->id);
276  $resql = $db->query($sql);
277  if ($resql) {
278  $obj = $db->fetch_object($resql);
279  $nbNote = $obj->nb;
280  } else {
281  dol_print_error($db);
282  }
283  if ($nbNote > 0) {
284  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
285  }
286  $head[$h][2] = 'partnerships';
287  if ($nbPartnership > 0) {
288  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
289  }
290  $h++;
291  }
292  }
293 
294  // Show more tabs from modules
295  // Entries must be declared in modules descriptor with line
296  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
297  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
298  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'core');
299 
300  if ($user->socid == 0) {
301  // Notifications
302  if (isModEnabled('notification')) {
303  $nbNotif = 0;
304  // Enable caching of thirdparty count notifications
305  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
306  $cachekey = 'count_notifications_thirdparty_'.$object->id;
307  $dataretrieved = dol_getcache($cachekey);
308  if (!is_null($dataretrieved)) {
309  $nbNotif = $dataretrieved;
310  } else {
311  $sql = "SELECT COUNT(n.rowid) as nb";
312  $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n";
313  $sql .= " WHERE fk_soc = ".((int) $object->id);
314  $resql = $db->query($sql);
315  if ($resql) {
316  $obj = $db->fetch_object($resql);
317  $nbNotif = $obj->nb;
318  } else {
319  dol_print_error($db);
320  }
321  dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
322  }
323 
324  $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.urlencode($object->id);
325  $head[$h][1] = $langs->trans("Notifications");
326  if ($nbNotif > 0) {
327  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
328  }
329  $head[$h][2] = 'notify';
330  $h++;
331  }
332 
333  // Notes
334  $nbNote = 0;
335  if (!empty($object->note_private)) {
336  $nbNote++;
337  }
338  if (!empty($object->note_public)) {
339  $nbNote++;
340  }
341  $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.urlencode($object->id);
342  $head[$h][1] = $langs->trans("Notes");
343  if ($nbNote > 0) {
344  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
345  }
346  $head[$h][2] = 'note';
347  $h++;
348 
349  // Attached files and Links
350  $totalAttached = 0;
351  // Enable caching of thirdrparty count attached files and links
352  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
353  $cachekey = 'count_attached_thirdparty_'.$object->id;
354  $dataretrieved = dol_getcache($cachekey);
355  if (!is_null($dataretrieved)) {
356  $totalAttached = $dataretrieved;
357  } else {
358  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
359  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
360  $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
361  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
362  $nbLinks = Link::count($db, $object->element, $object->id);
363  $totalAttached = $nbFiles + $nbLinks;
364  dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
365  }
366 
367  $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
368  $head[$h][1] = $langs->trans("Documents");
369  if (($totalAttached) > 0) {
370  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
371  }
372  $head[$h][2] = 'document';
373  $h++;
374  }
375 
376  $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
377  $head[$h][1] = $langs->trans("Events");
378  if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
379  $nbEvent = 0;
380  // Enable caching of thirdparty count actioncomm
381  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
382  $cachekey = 'count_events_thirdparty_'.$object->id;
383  $dataretrieved = dol_getcache($cachekey);
384  if (!is_null($dataretrieved)) {
385  $nbEvent = $dataretrieved;
386  } else {
387  $sql = "SELECT COUNT(id) as nb";
388  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
389  $sql .= " WHERE fk_soc = ".((int) $object->id);
390  $resql = $db->query($sql);
391  if ($resql) {
392  $obj = $db->fetch_object($resql);
393  $nbEvent = $obj->nb;
394  } else {
395  dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
396  }
397  dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
398  }
399 
400  $head[$h][1] .= '/';
401  $head[$h][1] .= $langs->trans("Agenda");
402  if ($nbEvent > 0) {
403  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
404  }
405  }
406  $head[$h][2] = 'agenda';
407  $h++;
408 
409  // Show more tabs from modules
410  // Entries must be declared in modules descriptor with line
411  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
412  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
413  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'external');
414 
415  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
416 
417  return $head;
418 }
419 
420 
427 function societe_prepare_head2($object)
428 {
429  global $langs, $conf, $user;
430  $h = 0;
431  $head = array();
432 
433  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
434  $head[$h][1] = $langs->trans("ThirdParty");
435  $head[$h][2] = 'company';
436  $h++;
437 
438  $head[$h][0] = 'commerciaux.php?socid='.$object->id;
439  $head[$h][1] = $langs->trans("SalesRepresentative");
440  $head[$h][2] = 'salesrepresentative';
441  $h++;
442 
443  return $head;
444 }
445 
446 
447 
454 {
455  global $langs, $conf, $user, $db;
456 
457  $extrafields = new ExtraFields($db);
458  $extrafields->fetch_name_optionals_label('societe');
459  $extrafields->fetch_name_optionals_label('socpeople');
460 
461  $h = 0;
462  $head = array();
463 
464  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
465  $head[$h][1] = $langs->trans("Miscellaneous");
466  $head[$h][2] = 'general';
467  $h++;
468 
469  // Show more tabs from modules
470  // Entries must be declared in modules descriptor with line
471  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
472  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
473  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
474 
475  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
476  $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
477  $nbExtrafields = $extrafields->attributes['societe']['count'];
478  if ($nbExtrafields > 0) {
479  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
480  }
481  $head[$h][2] = 'attributes';
482  $h++;
483 
484  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
485  $head[$h][1] = $langs->trans("ExtraFieldsContacts");
486  $nbExtrafields = $extrafields->attributes['socpeople']['count'];
487  if ($nbExtrafields > 0) {
488  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
489  }
490  $head[$h][2] = 'attributes_contacts';
491  $h++;
492 
493  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
494 
495  return $head;
496 }
497 
498 
499 
515 function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '', $entconv = 1, $searchlabel = '')
516 {
517  global $db, $langs;
518 
519  $result = '';
520 
521  // Check parameters
522  if (empty($searchkey) && empty($searchlabel)) {
523  if ($withcode === 'all') {
524  return array('id'=>'', 'code'=>'', 'label'=>'');
525  } else {
526  return '';
527  }
528  }
529  if (!is_object($dbtouse)) {
530  $dbtouse = $db;
531  }
532  if (!is_object($outputlangs)) {
533  $outputlangs = $langs;
534  }
535 
536  $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
537  if (is_numeric($searchkey)) {
538  $sql .= " WHERE rowid = ".((int) $searchkey);
539  } elseif (!empty($searchkey)) {
540  $sql .= " WHERE code = '".$db->escape($searchkey)."'";
541  } else {
542  $sql .= " WHERE label = '".$db->escape($searchlabel)."'";
543  }
544 
545  $resql = $dbtouse->query($sql);
546  if ($resql) {
547  $obj = $dbtouse->fetch_object($resql);
548  if ($obj) {
549  $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
550  if (is_object($outputlangs)) {
551  $outputlangs->load("dict");
552  if ($entconv) {
553  $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label;
554  } else {
555  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label;
556  }
557  }
558  if ($withcode == 1) {
559  $result = $label ? "$obj->code - $label" : "$obj->code";
560  } elseif ($withcode == 2) {
561  $result = $obj->code;
562  } elseif ($withcode == 3) {
563  $result = $obj->rowid;
564  } elseif ($withcode === 'all') {
565  $result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label);
566  } else {
567  $result = $label;
568  }
569  } else {
570  $result = 'NotDefined';
571  }
572  $dbtouse->free($resql);
573  return $result;
574  } else {
575  dol_print_error($dbtouse, '');
576  }
577  return 'Error';
578 }
579 
595 function getState($id, $withcode = '', $dbtouse = 0, $withregion = 0, $outputlangs = '', $entconv = 1)
596 {
597  global $db, $langs;
598 
599  if (!is_object($dbtouse)) {
600  $dbtouse = $db;
601  }
602 
603  $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";
604  $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
605  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".((int) $id);
606  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
607  $sql .= " ORDER BY c.code, d.code_departement";
608 
609  dol_syslog("Company.lib::getState", LOG_DEBUG);
610  $resql = $dbtouse->query($sql);
611  if ($resql) {
612  $obj = $dbtouse->fetch_object($resql);
613  if ($obj) {
614  $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
615  if (is_object($outputlangs)) {
616  $outputlangs->load("dict");
617  if ($entconv) {
618  $label = ($obj->code && ($outputlangs->trans("State".$obj->code) != "State".$obj->code)) ? $outputlangs->trans("State".$obj->code) : $label;
619  } else {
620  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code) != "State".$obj->code)) ? $outputlangs->transnoentitiesnoconv("State".$obj->code) : $label;
621  }
622  }
623 
624  if ($withcode == 1) {
625  if ($withregion == 1) {
626  return $label = $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
627  } else {
628  return $label = $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
629  }
630  } elseif ($withcode == 2) {
631  if ($withregion == 1) {
632  return $label = $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
633  } else {
634  return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
635  }
636  } elseif ($withcode === 'all') {
637  if ($withregion == 1) {
638  return array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$label, 'region_code'=>$obj->region_code, 'region'=>$obj->region_name);
639  } else {
640  return array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$label);
641  }
642  } else {
643  if ($withregion == 1) {
644  return $label = $obj->region_name.' - '.$label;
645  } else {
646  return $label;
647  }
648  }
649  } else {
650  return $langs->transnoentitiesnoconv("NotDefined");
651  }
652  } else {
653  dol_print_error($dbtouse, '');
654  }
655 
656  return '';
657 }
658 
667 function currency_name($code_iso, $withcode = '', $outputlangs = null)
668 {
669  global $langs, $db;
670 
671  if (empty($outputlangs)) {
672  $outputlangs = $langs;
673  }
674 
675  $outputlangs->load("dict");
676 
677  // If there is a translation, we can send immediatly the label
678  if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
679  return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
680  }
681 
682  // If no translation, we read table to get label by default
683  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
684  $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
685 
686  $resql = $db->query($sql);
687  if ($resql) {
688  $num = $db->num_rows($resql);
689 
690  if ($num) {
691  $obj = $db->fetch_object($resql);
692  $label = ($obj->label != '-' ? $obj->label : '');
693  if ($withcode) {
694  return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
695  } else {
696  return $label;
697  }
698  } else {
699  return $code_iso;
700  }
701  }
702  return 'ErrorWhenReadingCurrencyLabel';
703 }
704 
711 function getFormeJuridiqueLabel($code)
712 {
713  global $db, $langs;
714 
715  if (!$code) {
716  return '';
717  }
718 
719  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
720  $sql .= " WHERE code = '".$db->escape($code)."'";
721 
722  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
723 
724  $resql = $db->query($sql);
725  if ($resql) {
726  $num = $db->num_rows($resql);
727  if ($num) {
728  $obj = $db->fetch_object($resql);
729 
730  $label = ($obj->libelle != '-' ? $obj->libelle : '');
731 
732  return $langs->trans($label);
733  } else {
734  return $langs->trans("NotDefined");
735  }
736  } else {
737  return 'Error '.$db->lasterror();
738  }
739 }
740 
741 
749 {
750  // List of all country codes that are in europe for european vat rules
751  // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
752  global $conf, $db;
753  $country_code_in_EEC = array();
754 
755  if (!empty($conf->cache['country_code_in_EEC'])) {
756  // Use of cache to reduce number of database requests
757  $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
758  } else {
759  $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
760  $sql .= " WHERE cc.eec = 1";
761 
762  $resql = $db->query($sql);
763  if ($resql) {
764  $num = $db->num_rows($resql);
765  $i = 0;
766  while ($i < $num) {
767  $objp = $db->fetch_object($resql);
768  $country_code_in_EEC[] = $objp->code;
769  $i++;
770  }
771  } else {
772  dol_print_error($db);
773  }
774  $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
775  }
776  return $country_code_in_EEC;
777 }
778 
785 function isInEEC($object)
786 {
787  if (empty($object->country_code)) {
788  return false;
789  }
790 
791  $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
792 
793  //print "dd".$object->country_code;
794  return in_array($object->country_code, $country_code_in_EEC);
795 }
796 
797 
810 function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
811 {
812  global $user, $action, $hookmanager;
813 
814  $i = -1;
815 
816  if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
817  $langs->load("projects");
818 
819  $newcardbutton = '';
820  if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
821  $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));
822  }
823 
824  print "\n";
825  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
826 
827  print '<div class="div-table-responsive">'."\n";
828  print '<table class="noborder centpercent">';
829 
830  $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";
831  $sql .= ", cls.code as opp_status_code";
832  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
833  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
834  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
835  $sql .= " AND p.entity IN (".getEntity('project').")";
836  $sql .= " ORDER BY p.dateo DESC";
837 
838  $result = $db->query($sql);
839  if ($result) {
840  $num = $db->num_rows($result);
841 
842  print '<tr class="liste_titre">';
843  print '<td>'.$langs->trans("Ref").'</td>';
844  print '<td>'.$langs->trans("Name").'</td>';
845  print '<td class="center">'.$langs->trans("DateStart").'</td>';
846  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
847  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
848  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
849  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
850  print '<td class="right">'.$langs->trans("Status").'</td>';
851  print '</tr>';
852 
853  if ($num > 0) {
854  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
855 
856  $projecttmp = new Project($db);
857 
858  $i = 0;
859 
860  while ($i < $num) {
861  $obj = $db->fetch_object($result);
862  $projecttmp->fetch($obj->id);
863 
864  // To verify role of users
865  $userAccess = $projecttmp->restrictedProjectArea($user);
866 
867  if ($user->rights->projet->lire && $userAccess > 0) {
868  print '<tr class="oddeven">';
869 
870  // Ref
871  print '<td class="nowraponall">';
872  print $projecttmp->getNomUrl(1);
873  print '</td>';
874 
875  // Label
876  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
877  // Date start
878  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
879  // Date end
880  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
881  // Opp amount
882  print '<td class="right">';
883  if ($obj->opp_status_code) {
884  print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
885  }
886  print '</td>';
887  // Opp status
888  print '<td class="center">';
889  if ($obj->opp_status_code) {
890  print $langs->trans("OppStatus".$obj->opp_status_code);
891  }
892  print '</td>';
893  // Opp percent
894  print '<td class="right">';
895  if ($obj->opp_percent) {
896  print price($obj->opp_percent, 1, '', 1, 0).'%';
897  }
898  print '</td>';
899  // Status
900  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
901 
902  print '</tr>';
903  }
904  $i++;
905  }
906  } else {
907  print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
908  }
909  $db->free($result);
910  } else {
911  dol_print_error($db);
912  }
913 
914  $parameters = array('sql'=>$sql, 'function'=>'show_projects');
915  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
916  print $hookmanager->resPrint;
917 
918  print "</table>";
919  print '</div>';
920 
921  print "<br>\n";
922  }
923 
924  return $i;
925 }
926 
927 
939 function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
940 {
941  global $user, $conf, $extrafields, $hookmanager;
942  global $contextpage;
943 
944  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
945  $formcompany = new FormCompany($db);
946  $form = new Form($db);
947 
948  $optioncss = GETPOST('optioncss', 'alpha');
949  $sortfield = GETPOST('sortfield', 'aZ09comma');
950  $sortorder = GETPOST('sortorder', 'aZ09comma');
951  $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
952 
953  $search_status = GETPOST("search_status", 'int');
954  if ($search_status == '') {
955  $search_status = 1; // always display active customer first
956  }
957 
958  $search_rowid = GETPOST("search_rowid", 'int');
959  $search_name = GETPOST("search_name", 'alpha');
960  $search_address = GETPOST("search_address", 'alpha');
961  $search_poste = GETPOST("search_poste", 'alpha');
962  $search_note_private = GETPOST('search_note_private', 'alphanohtml');
963  $search_roles = GETPOST("search_roles", 'array');
964  $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
965  $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
966 
967  if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
968  $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOST('search_birthday_dtstartmonth', 'int'), GETPOST('search_birthday_dtstartday', 'int'), GETPOST('search_birthday_dtstartyear', 'int'));
969  $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOST('search_birthday_dtendmonth', 'int'), GETPOST('search_birthday_dtendday', 'int'), GETPOST('search_birthday_dtendyear', 'int'));
970  }
971  $socialnetworks = getArrayOfSocialNetworks();
972 
973  $searchAddressPhoneDBFields = array(
974  //Address
975  't.address',
976  't.zip',
977  't.town',
978 
979  //Phone
980  't.phone',
981  't.phone_perso',
982  't.phone_mobile',
983 
984  //Fax
985  't.fax',
986 
987  //E-mail
988  't.email',
989  );
990  //Social media
991  // foreach ($socialnetworks as $key => $value) {
992  // if ($value['active']) {
993  // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
994  // }
995  // }
996 
997  if (!$sortorder) {
998  $sortorder = "ASC";
999  }
1000  if (!$sortfield) {
1001  $sortfield = "t.lastname";
1002  }
1003 
1004  if (isModEnabled('clicktodial')) {
1005  $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1006  }
1007 
1008 
1009  $contactstatic = new Contact($db);
1010 
1011  $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1012 
1013  $contactstatic->fields = array(
1014  'rowid' =>array('type'=>'integer', 'label'=>"TechnicalID", 'enabled'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) ? 1 : 0), 'visible'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) ? 1 : 0), 'position'=>1),
1015  'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
1016  'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>2, 'index'=>1, 'position'=>20),
1017  'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>3, 'index'=>1, 'position'=>30),
1018  'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible'=>3, 'position'=>35),
1019  'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>4, 'index'=>1, 'position'=>40),
1020  'birthday' =>array('type'=>'date', 'label'=>'Birthday', 'enabled'=>1, 'visible'=>-1, 'notnull'=> 0, 'position'=>45),
1021  '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))),
1022  );
1023 
1024  // Definition of fields for list
1025  $arrayfields = array(
1026  't.rowid'=>array('label'=>"TechnicalID", 'checked'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) ? 1 : 0), 'enabled'=>(!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) ? 1 : 0), 'position'=>1),
1027  't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10),
1028  't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20),
1029  '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),
1030  't.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'position'=>35),
1031  'sc.role'=>array('label'=>"ContactByDefaultFor", 'checked'=>1, 'position'=>40),
1032  't.birthday'=>array('label'=>"Birthday", 'checked'=>0, 'position'=>45),
1033  't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'),
1034  );
1035  // Extra fields
1036  if (!empty($extrafields->attributes[$contactstatic->table_element]['label']) && is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) {
1037  foreach ($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val) {
1038  if (!empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
1039  $arrayfields["ef.".$key] = array(
1040  'label'=>$extrafields->attributes[$contactstatic->table_element]['label'][$key],
1041  'checked'=>((dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1, 1, '1') < 0) ? 0 : 1),
1042  'position'=>1000 + $extrafields->attributes[$contactstatic->table_element]['pos'][$key],
1043  'enabled' => (abs((int) dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1)) != 3 && dol_eval($extrafields->attributes[$contactstatic->table_element]['perms'][$key], 1, 1, '1'))
1044  );
1045  }
1046  }
1047  }
1048 
1049  // Initialize array of search criterias
1050  $search = array();
1051  foreach ($arrayfields as $key => $val) {
1052  $queryName = 'search_'.substr($key, 2);
1053  if (GETPOST($queryName, 'alpha')) {
1054  $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1055  }
1056  }
1057  $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1058 
1059  // Purge search criteria
1060  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
1061  $search_rowid = '';
1062  $search_status = '';
1063  $search_name = '';
1064  $search_roles = array();
1065  $search_address = '';
1066  $search_poste = '';
1067  $search_note_private = '';
1068  $search_birthday_dtstart = '';
1069  $search_birthday_dtend = '';
1070  $search = array();
1071  $search_array_options = array();
1072 
1073  foreach ($contactstatic->fields as $key => $val) {
1074  $search[$key] = '';
1075  }
1076  }
1077 
1078  $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1079  $arrayfields = dol_sort_array($arrayfields, 'position');
1080 
1081  $newcardbutton = '';
1082  if ($user->hasRight('societe', 'contact', 'creer')) {
1083  $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1084  $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
1085  }
1086 
1087  print "\n";
1088 
1089  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1090  print load_fiche_titre($title, $newcardbutton, '');
1091 
1092  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
1093  print '<input type="hidden" name="token" value="'.newToken().'">';
1094  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1095  print '<input type="hidden" name="socid" value="'.$object->id.'">';
1096  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1097  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1098  print '<input type="hidden" name="page" value="'.$page.'">';
1099 
1100  $arrayofmassactions = array();
1101  $mode = 'view';
1102 
1103  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1104  $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
1105  $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1106 
1107  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1108  print "\n".'<table class="tagtable liste">'."\n";
1109 
1110  $param = "socid=".urlencode($object->id);
1111  if ($search_rowid != '') {
1112  $param .= '&search_rowid='.urlencode($search_rowid);
1113  }
1114  if ($search_status != '') {
1115  $param .= '&search_status='.urlencode($search_status);
1116  }
1117  if (count($search_roles) > 0) {
1118  $param .= implode('&search_roles[]=', $search_roles);
1119  }
1120  if ($search_name != '') {
1121  $param .= '&search_name='.urlencode($search_name);
1122  }
1123  if ($search_poste != '') {
1124  $param .= '&search_poste='.urlencode($search_poste);
1125  }
1126  if ($search_address != '') {
1127  $param .= '&search_address='.urlencode($search_address);
1128  }
1129  if ($search_note_private != '') {
1130  $param .= '&search_note_private='.urlencode($search_note_private);
1131  }
1132  if ($search_birthday_dtstart != '') {
1133  $param .= '&search_birthday_dtstart='.urlencode($search_birthday_dtstart);
1134  }
1135  if ($search_birthday_dtend != '') {
1136  $param .= '&search_birthday_dtend='.urlencode($search_birthday_dtend);
1137  }
1138  if ($optioncss != '') {
1139  $param .= '&optioncss='.urlencode($optioncss);
1140  }
1141 
1142  // Add $param from extra fields
1143  $extrafieldsobjectkey = $contactstatic->table_element;
1144  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1145 
1146  $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1147  $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,";
1148  $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1149  $sql .= " t.note_private";
1150  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
1151  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1152  $sql .= " WHERE t.fk_soc = ".((int) $object->id);
1153  $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";
1154  if ($search_rowid) {
1155  $sql .= natural_search('t.rowid', $search_rowid);
1156  }
1157  if ($search_status != '' && $search_status != '-1') {
1158  $sql .= " AND t.statut = ".((int) $search_status);
1159  }
1160  if ($search_name) {
1161  $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1162  }
1163  if ($search_poste) {
1164  $sql .= natural_search('t.poste', $search_poste);
1165  }
1166  if ($search_address) {
1167  $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1168  }
1169  if ($search_note_private) {
1170  $sql .= natural_search('t.note_private', $search_note_private);
1171  }
1172  if ($search_birthday_dtstart != '') {
1173  $sql .= " AND t.birthday >= '".$db->idate($search_birthday_dtstart)."'";
1174  }
1175  if ($search_birthday_dtend != '') {
1176  $sql .= " AND t.birthday <= '".$db->idate($search_birthday_dtend)."'";
1177  }
1178  if (count($search_roles) > 0) {
1179  $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))."))";
1180  }
1181  // Add where from extra fields
1182  $extrafieldsobjectkey = $contactstatic->table_element;
1183  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1184  // Add where from hooks
1185  $parameters = array('socid' => $object->id);
1186  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1187  $sql .= $hookmanager->resPrint;
1188  if ($sortfield == "t.name") {
1189  $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1190  } else {
1191  $sql .= " ORDER BY $sortfield $sortorder";
1192  }
1193 
1194  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1195  $result = $db->query($sql);
1196  if (!$result) {
1197  dol_print_error($db);
1198  }
1199 
1200  $num = $db->num_rows($result);
1201 
1202  // Fields title search
1203  // --------------------------------------------------------------------
1204  print '<tr class="liste_titre">';
1205  // Action column
1206  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1207  print '<td class="liste_titre" align="right">';
1208  print $form->showFilterButtons();
1209  print '</td>';
1210  }
1211  foreach ($contactstatic->fields as $key => $val) {
1212  $align = '';
1213  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1214  $align .= ($align ? ' ' : '').'center';
1215  }
1216  if (in_array($val['type'], array('timestamp'))) {
1217  $align .= ($align ? ' ' : '').'nowrap';
1218  }
1219  if ($key == 'status' || $key == 'statut') {
1220  $align .= ($align ? ' ' : '').'center';
1221  }
1222  if (!empty($arrayfields['t.'.$key]['checked']) || !empty($arrayfields['sc.'.$key]['checked'])) {
1223  print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
1224  if (in_array($key, array('statut'))) {
1225  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');
1226  } elseif (in_array($key, array('role'))) {
1227  print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1228  } elseif (in_array($key, array('birthday'))) {
1229  print '<div class="nowrap">';
1230  print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1231  print '</div>';
1232  print '<div class="nowrap">';
1233  print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1234  print '</div>';
1235  } else {
1236  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.(!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '').'">';
1237  }
1238  print '</td>';
1239  }
1240  }
1241  if ($showuserlogin) {
1242  print '<td class="liste_titre"></td>';
1243  }
1244  // Extra fields
1245  $extrafieldsobjectkey = $contactstatic->table_element;
1246  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1247 
1248  // Fields from hook
1249  $parameters = array('arrayfields'=>$arrayfields);
1250  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1251  print $hookmanager->resPrint;
1252  // Action column
1253  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1254  print '<td class="liste_titre" align="right">';
1255  print $form->showFilterButtons();
1256  print '</td>';
1257  }
1258  print '</tr>'."\n";
1259 
1260 
1261  // Fields title label
1262  // --------------------------------------------------------------------
1263  print '<tr class="liste_titre">';
1264  // Action column
1265  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1266  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1267  }
1268  foreach ($contactstatic->fields as $key => $val) {
1269  $align = '';
1270  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1271  $align .= ($align ? ' ' : '').'center';
1272  }
1273  if (in_array($val['type'], array('timestamp'))) {
1274  $align .= ($align ? ' ' : '').'nowrap';
1275  }
1276  if ($key == 'status' || $key == 'statut') {
1277  $align .= ($align ? ' ' : '').'center';
1278  }
1279  if (!empty($arrayfields['t.'.$key]['checked'])) {
1280  print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1281  }
1282  if ($key == 'role') {
1283  $align .= ($align ? ' ' : '').'left';
1284  }
1285  if (!empty($arrayfields['sc.'.$key]['checked'])) {
1286  print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1287  }
1288  }
1289  if ($showuserlogin) {
1290  print '<th class="wrapcolumntitle liste_titre">'.$langs->trans("DolibarrLogin").'</th>';
1291  }
1292  // Extra fields
1293  $extrafieldsobjectkey = $contactstatic->table_element;
1294  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1295  // Hook fields
1296  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1297  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1298  print $hookmanager->resPrint;
1299  // Action column
1300  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1301  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1302  }
1303  print '</tr>'."\n";
1304 
1305  $i = -1;
1306 
1307  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1308  $i = 0;
1309 
1310  while ($i < $num) {
1311  $obj = $db->fetch_object($result);
1312 
1313  $contactstatic->id = $obj->rowid;
1314  $contactstatic->ref = $obj->rowid;
1315  $contactstatic->statut = $obj->statut;
1316  $contactstatic->lastname = $obj->lastname;
1317  $contactstatic->firstname = $obj->firstname;
1318  $contactstatic->civility_id = $obj->civility_id;
1319  $contactstatic->civility_code = $obj->civility_id;
1320  $contactstatic->poste = $obj->poste;
1321  $contactstatic->address = $obj->address;
1322  $contactstatic->zip = $obj->zip;
1323  $contactstatic->town = $obj->town;
1324  $contactstatic->phone_pro = $obj->phone_pro;
1325  $contactstatic->phone_mobile = $obj->phone_mobile;
1326  $contactstatic->phone_perso = $obj->phone_perso;
1327  $contactstatic->email = $obj->email;
1328  $contactstatic->socialnetworks = $obj->socialnetworks;
1329  $contactstatic->photo = $obj->photo;
1330  $contactstatic->fk_soc = $obj->fk_soc;
1331  $contactstatic->entity = $obj->entity;
1332 
1333  $country_code = getCountry($obj->country_id, 2);
1334  $contactstatic->country_code = $country_code;
1335 
1336  $contactstatic->setGenderFromCivility();
1337  $contactstatic->fetch_optionals();
1338 
1339  $resultRole = $contactstatic->fetchRoles();
1340  if ($resultRole < 0) {
1341  setEventMessages(null, $contactstatic->errors, 'errors');
1342  }
1343 
1344  if (is_array($contactstatic->array_options)) {
1345  foreach ($contactstatic->array_options as $key => $val) {
1346  $obj->$key = $val;
1347  }
1348  }
1349 
1350  print '<tr class="oddeven">';
1351 
1352  // Actions
1353  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1354  print '<td class="nowrap center">';
1355 
1356  // Add to agenda
1357  if (isModEnabled('agenda')&& $user->hasRight('agenda', 'myactions', 'create')) {
1358  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1359  print img_object($langs->trans("Event"), "action");
1360  print '</a> &nbsp; ';
1361  }
1362 
1363  // Edit
1364  if ($user->hasRight('societe', 'contact', 'creer')) {
1365  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1366  print img_edit();
1367  print '</a>';
1368  }
1369 
1370  print '</td>';
1371  }
1372 
1373  // ID
1374  if (!empty($arrayfields['t.rowid']['checked'])) {
1375  print '<td>';
1376  print $contactstatic->id;
1377  print '</td>';
1378  }
1379 
1380  // Photo - Name
1381  if (!empty($arrayfields['t.name']['checked'])) {
1382  print '<td class="tdoverflowmax150">';
1383  print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 1);
1384  print $contactstatic->getNomUrl(0, '', 0, '&backtopage='.urlencode($backtopage));
1385  print '</td>';
1386  }
1387 
1388  // Job position
1389  if (!empty($arrayfields['t.poste']['checked'])) {
1390  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->poste).'">';
1391  if ($obj->poste) {
1392  print dol_escape_htmltag($obj->poste);
1393  }
1394  print '</td>';
1395  }
1396 
1397  // Address - Phone - Email
1398  if (!empty($arrayfields['t.address']['checked'])) {
1399  $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1400  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag(dol_string_nohtmltag($addresstoshow)).'">';
1401  print $addresstoshow;
1402  print '</td>';
1403  }
1404 
1405  // Note private
1406  if (!empty($arrayfields['t.note_private']['checked'])) {
1407  print '<td>';
1408  if ($obj->note_private) {
1409  print dol_string_nohtmltag($obj->note_private);
1410  }
1411  print '</td>';
1412  }
1413 
1414  // Role
1415  if (!empty($arrayfields['sc.role']['checked'])) {
1416  print '<td>';
1417  print $formcompany->showRoles("roles", $contactstatic, 'view');
1418  print '</td>';
1419  }
1420 
1421  // Birthday
1422  if (!empty($arrayfields['t.birthday']['checked'])) {
1423  print '<td class="nowraponall">';
1424  print dol_print_date($db->jdate($obj->birthday));
1425  print '</td>';
1426  }
1427 
1428  // Status
1429  if (!empty($arrayfields['t.statut']['checked'])) {
1430  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1431  }
1432 
1433  if ($showuserlogin) {
1434  print '<td class="tdoverflowmax125">';
1435  $tmpuser= new User($db);
1436  $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1437  if ($resfetch > 0) {
1438  print $tmpuser->getNomUrl(1, '', 0, 0, 24, 1);
1439  }
1440  print '</td>';
1441  }
1442 
1443  // Extra fields
1444  $extrafieldsobjectkey = $contactstatic->table_element;
1445  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1446 
1447  // Actions
1448  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1449  print '<td class="nowrap center">';
1450 
1451  // Add to agenda
1452  if (isModEnabled('agenda')&& $user->hasRight('agenda', 'myactions', 'create')) {
1453  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1454  print img_object($langs->trans("Event"), "action");
1455  print '</a> &nbsp; ';
1456  }
1457 
1458  // Edit
1459  if ($user->hasRight('societe', 'contact', 'creer')) {
1460  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1461  print img_edit();
1462  print '</a>';
1463  }
1464 
1465  print '</td>';
1466  }
1467 
1468  print "</tr>\n";
1469  $i++;
1470  }
1471 
1472  if ($num == 0) {
1473  $colspan = 1 + ($showuserlogin ? 1 : 0);
1474  foreach ($arrayfields as $key => $val) {
1475  if (!empty($val['checked'])) {
1476  $colspan++;
1477  }
1478  }
1479  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1480  }
1481  } else {
1482  $colspan = 1 + ($showuserlogin ? 1 : 0);
1483  foreach ($arrayfields as $key => $val) {
1484  if (!empty($val['checked'])) {
1485  $colspan++;
1486  }
1487  }
1488  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1489  }
1490  print "\n</table>\n";
1491  print '</div>';
1492 
1493  print '</form>'."\n";
1494 
1495  return $i;
1496 }
1497 
1498 
1511 function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '')
1512 {
1513  global $user, $conf;
1514 
1515  $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1516 
1517  if ($noprint) {
1518  return $out;
1519  } else {
1520  print $out;
1521  }
1522 }
1523 
1542 function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1543 {
1544  global $user, $conf, $hookmanager;
1545  global $form;
1546  global $param, $massactionbutton;
1547 
1548  $start_year = GETPOST('dateevent_startyear', 'int');
1549  $start_month = GETPOST('dateevent_startmonth', 'int');
1550  $start_day = GETPOST('dateevent_startday', 'int');
1551  $end_year = GETPOST('dateevent_endyear', 'int');
1552  $end_month = GETPOST('dateevent_endmonth', 'int');
1553  $end_day = GETPOST('dateevent_endday', 'int');
1554  $tms_start = '';
1555  $tms_end = '';
1556 
1557  if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1558  $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1559  }
1560  if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1561  $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1562  }
1563  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
1564  $tms_start = '';
1565  $tms_end = '';
1566  }
1567  dol_include_once('/comm/action/class/actioncomm.class.php');
1568 
1569  // Check parameters
1570  if (!is_object($filterobj) && !is_object($objcon)) {
1571  dol_print_error('', 'BadParameter');
1572  }
1573 
1574  $out = '';
1575  $histo = array();
1576  $numaction = 0;
1577  $now = dol_now('tzuser');
1578 
1579  // Open DSI -- Fix order by -- Begin
1580  $sortfield_list = explode(',', $sortfield);
1581  $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1582  $sortfield_new_list = array();
1583  foreach ($sortfield_list as $sortfield_value) {
1584  $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1585  }
1586  $sortfield_new = implode(',', $sortfield_new_list);
1587 
1588  $sql = '';
1589 
1590  if (isModEnabled('agenda')) {
1591  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1592  $hookmanager->initHooks(array('agendadao'));
1593 
1594  // Recherche histo sur actioncomm
1595  if (is_object($objcon) && $objcon->id > 0) {
1596  $sql = "SELECT DISTINCT a.id, a.label as label,";
1597  } else {
1598  $sql = "SELECT a.id, a.label as label,";
1599  }
1600  $sql .= " a.datep as dp,";
1601  $sql .= " a.datep2 as dp2,";
1602  $sql .= " a.percent as percent, 'action' as type,";
1603  $sql .= " a.fk_element, a.elementtype,";
1604  $sql .= " a.fk_contact,";
1605  $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1606  $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";
1607  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1608  $sql .= ", sp.lastname, sp.firstname";
1609  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1610  /* Nothing */
1611  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1612  /* Nothing */
1613  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1614  $sql .= ", m.lastname, m.firstname";
1615  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1616  $sql .= ", o.ref";
1617  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1618  $sql .= ", o.ref";
1619  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1620  $sql .= ", o.ref";
1621  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1622  $sql .= ", o.ref";
1623  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1624  $sql .= ", o.ref";
1625  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1626  if (!empty($filterobj->fields['ref'])) {
1627  $sql .= ", o.ref";
1628  } elseif (!empty($filterobj->fields['label'])) {
1629  $sql .= ", o.label";
1630  }
1631  }
1632 
1633  // Fields from hook
1634  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1635  $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1636  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1637 
1638  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1639  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1640  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1641 
1642  $force_filter_contact = false;
1643  if (is_object($objcon) && $objcon->id > 0) {
1644  $force_filter_contact = true;
1645  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1646  $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
1647  }
1648 
1649  // Fields from hook
1650  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1651  $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1652  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1653 
1654  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1655  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1656  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1657  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1658  $sql .= " ON er.resource_type = 'dolresource'";
1659  $sql .= " AND er.element_id = a.id";
1660  $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1661  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1662  /* Nothing */
1663  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1664  $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1665  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1666  $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1667  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1668  $sql .= ", ".MAIN_DB_PREFIX."product as o";
1669  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1670  $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1671  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1672  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1673  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1674  $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1675  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1676  && ((!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'])))
1677  && $filterobj->table_element && $filterobj->element) {
1678  $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1679  } elseif (is_object($filterobj)) {
1680  return 'Bad value for $filterobj';
1681  }
1682 
1683  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1684  if ($force_filter_contact === false) {
1685  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1686  $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1687  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1688  /* Nothing */
1689  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1690  $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1691  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1692  $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1693  if ($filterobj->id) {
1694  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1695  }
1696  } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
1697  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
1698  if ($filterobj->id) {
1699  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1700  }
1701  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1702  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1703  if ($filterobj->id) {
1704  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1705  }
1706  } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
1707  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
1708  if ($filterobj->id) {
1709  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1710  }
1711  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1712  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1713  if ($filterobj->id) {
1714  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1715  }
1716  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1717  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1718  if ($filterobj->id) {
1719  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1720  }
1721  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1722  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1723  if ($filterobj->id) {
1724  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1725  }
1726  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1727  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1728  if ($filterobj->id) {
1729  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1730  }
1731  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1732  && ((!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'])))
1733  && $filterobj->table_element && $filterobj->element) {
1734  // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
1735  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1736  if ($filterobj->id) {
1737  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1738  }
1739  } elseif (is_object($filterobj)) {
1740  return 'Bad value for $filterobj';
1741  }
1742  }
1743 
1744  if (!empty($tms_start) && !empty($tms_end)) {
1745  $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)."'))";
1746  } elseif (empty($tms_start) && !empty($tms_end)) {
1747  $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1748  } elseif (!empty($tms_start) && empty($tms_end)) {
1749  $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1750  }
1751 
1752  if (is_array($actioncode) && !empty($actioncode)) {
1753  $sql .= ' AND (';
1754  foreach ($actioncode as $key => $code) {
1755  if ($key != 0) {
1756  $sql .= "OR (";
1757  }
1758  if (!empty($code)) {
1759  addEventTypeSQL($sql, $code);
1760  }
1761  if ($key != 0) {
1762  $sql .= ")";
1763  }
1764  }
1765  $sql .= ')';
1766  } elseif (!empty($actioncode)) {
1767  addEventTypeSQL($sql, $actioncode);
1768  }
1769 
1770  addOtherFilterSQL($sql, $donetodo, $now, $filters);
1771 
1772  // Fields from hook
1773  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
1774  $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
1775  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1776 
1777  if (is_array($actioncode)) {
1778  foreach ($actioncode as $code) {
1779  $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1780  if (!empty($sql2)) {
1781  if (!empty($sql)) {
1782  $sql = $sql." UNION ".$sql2;
1783  } elseif (empty($sql)) {
1784  $sql = $sql2;
1785  }
1786  break;
1787  }
1788  }
1789  } else {
1790  $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
1791  if (!empty($sql) && !empty($sql2)) {
1792  $sql = $sql." UNION ".$sql2;
1793  } elseif (empty($sql) && !empty($sql2)) {
1794  $sql = $sql2;
1795  }
1796  }
1797  }
1798 
1799  //TODO Add limit in nb of results
1800  if ($sql) {
1801  $sql .= $db->order($sortfield_new, $sortorder);
1802 
1803  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1804 
1805  $resql = $db->query($sql);
1806  if ($resql) {
1807  $i = 0;
1808  $num = $db->num_rows($resql);
1809 
1810  while ($i < $num) {
1811  $obj = $db->fetch_object($resql);
1812 
1813  if ($obj->type == 'action') {
1814  $contactaction = new ActionComm($db);
1815  $contactaction->id = $obj->id;
1816  $result = $contactaction->fetchResources();
1817  if ($result < 0) {
1818  dol_print_error($db);
1819  setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
1820  }
1821 
1822  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1823  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1824  $tododone = '';
1825  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
1826  $tododone = 'todo';
1827  }
1828 
1829  $histo[$numaction] = array(
1830  'type'=>$obj->type,
1831  'tododone'=>$tododone,
1832  'id'=>$obj->id,
1833  'datestart'=>$db->jdate($obj->dp),
1834  'dateend'=>$db->jdate($obj->dp2),
1835  'note'=>$obj->label,
1836  'percent'=>$obj->percent,
1837 
1838  'userid'=>$obj->user_id,
1839  'login'=>$obj->user_login,
1840  'userfirstname'=>$obj->user_firstname,
1841  'userlastname'=>$obj->user_lastname,
1842  'userphoto'=>$obj->user_photo,
1843 
1844  'contact_id'=>$obj->fk_contact,
1845  'socpeopleassigned' => $contactaction->socpeopleassigned,
1846  'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
1847  'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
1848  'fk_element'=>$obj->fk_element,
1849  'elementtype'=>$obj->elementtype,
1850  // Type of event
1851  'acode'=>$obj->acode,
1852  'alabel'=>$obj->alabel,
1853  'libelle'=>$obj->alabel, // deprecated
1854  'apicto'=>$obj->apicto
1855  );
1856  } else {
1857  $histo[$numaction] = array(
1858  'type'=>$obj->type,
1859  'tododone'=>'done',
1860  'id'=>$obj->id,
1861  'datestart'=>$db->jdate($obj->dp),
1862  'dateend'=>$db->jdate($obj->dp2),
1863  'note'=>$obj->label,
1864  'percent'=>$obj->percent,
1865  'acode'=>$obj->acode,
1866 
1867  'userid'=>$obj->user_id,
1868  'login'=>$obj->user_login,
1869  'userfirstname'=>$obj->user_firstname,
1870  'userlastname'=>$obj->user_lastname,
1871  'userphoto'=>$obj->user_photo
1872  );
1873  }
1874 
1875  $numaction++;
1876  $i++;
1877  }
1878  } else {
1879  dol_print_error($db);
1880  }
1881  }
1882 
1883  if (isModEnabled('agenda')|| (isModEnabled('mailing') && !empty($objcon->email))) {
1884  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
1885 
1886  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1887  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1888  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1889  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1890 
1891  $formactions = new FormActions($db);
1892 
1893  $actionstatic = new ActionComm($db);
1894  $userstatic = new User($db);
1895  $userlinkcache = array();
1896  $contactstatic = new Contact($db);
1897  $elementlinkcache = array();
1898 
1899  $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1900  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1901  if ($objcon && get_class($objcon) == 'Contact' &&
1902  (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
1903  $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
1904  } else {
1905  $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1906  }
1907  if ($filterobj && get_class($filterobj) == 'Societe') {
1908  $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1909  }
1910 
1911  $out .= "\n";
1912 
1913  $out .= '<div class="div-table-responsive-no-min">';
1914  $out .= '<table class="noborder centpercent">';
1915 
1916  $out .= '<tr class="liste_titre">';
1917 
1918  // Action column
1919  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1920  $out .= '<th class="liste_titre width50 middle">';
1921  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1922  $out .= $searchpicto;
1923  $out .= '</th>';
1924  }
1925 
1926  if ($donetodo) {
1927  $out .= '<td class="liste_titre"></td>';
1928  }
1929 
1930  $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
1931  $out .= '<td class="liste_titre"></td>';
1932  $out .= '<td class="liste_titre">';
1933  $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, (empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 0 : 1), 1, 'minwidth100 maxwidth150');
1934  $out .= '</td>';
1935  $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1936  $out .= '<td class="liste_titre center">';
1937  $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
1938  $out .= '</td>';
1939  $out .= '<td class="liste_titre"></td>';
1940  $out .= '<td class="liste_titre"></td>';
1941  $out .= '<td class="liste_titre"></td>';
1942  // Action column
1943  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1944  $out .= '<td class="liste_titre" align="middle">';
1945  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1946  $out .= $searchpicto;
1947  $out .= '</td>';
1948  }
1949  $out .= '</tr>';
1950 
1951  $out .= '<tr class="liste_titre">';
1952  // Action column
1953  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1954  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1955  }
1956  if ($donetodo) {
1957  $tmp = '';
1958  if (get_class($filterobj) == 'Societe') {
1959  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
1960  }
1961  $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1962  $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1963  $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1964  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1965  if (get_class($filterobj) == 'Societe') {
1966  $tmp .= '</a>';
1967  }
1968  $out .= getTitleFieldOfList($tmp);
1969  }
1970  $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1971  $out .= getTitleFieldOfList("Owner");
1972  $out .= getTitleFieldOfList("Type");
1973  $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1974  $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
1975  $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1976  $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
1977  $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
1978  // Action column
1979  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1980  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1981  }
1982  $out .= '</tr>';
1983 
1984  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
1985  $caction = new CActionComm($db);
1986  $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
1987 
1988  foreach ($histo as $key => $value) {
1989  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1990 
1991  $actionstatic->type_picto = $histo[$key]['apicto'];
1992  $actionstatic->type_code = $histo[$key]['acode'];
1993 
1994  $out .= '<tr class="oddeven">';
1995 
1996  // Action column
1997  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1998  $out .= '<td></td>';
1999  }
2000 
2001  // Done or todo
2002  if ($donetodo) {
2003  $out .= '<td class="nowrap">';
2004  $out .= '</td>';
2005  }
2006 
2007  // Ref
2008  $out .= '<td class="nowraponall">';
2009  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2010  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2011  $out .= $histo[$key]['id'];
2012  $out .= '</a>';
2013  } else {
2014  $out .= $actionstatic->getNomUrl(1, -1);
2015  }
2016  $out .= '</td>';
2017 
2018  // Author of event
2019  $out .= '<td class="tdoverflowmax150">';
2020  //$userstatic->id=$histo[$key]['userid'];
2021  //$userstatic->login=$histo[$key]['login'];
2022  //$out.=$userstatic->getLoginUrl(1);
2023  if ($histo[$key]['userid'] > 0) {
2024  if (isset($userlinkcache[$histo[$key]['userid']])) {
2025  $link = $userlinkcache[$histo[$key]['userid']];
2026  } else {
2027  $userstatic->fetch($histo[$key]['userid']);
2028  $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2029  $userlinkcache[$histo[$key]['userid']] = $link;
2030  }
2031  $out .= $link;
2032  }
2033  $out .= '</td>';
2034 
2035  // Type
2036  $labeltype = $actionstatic->type_code;
2037  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
2038  $labeltype = 'AC_OTH';
2039  }
2040  if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2041  $labeltype = $langs->trans("Message");
2042  } else {
2043  if (!empty($arraylist[$labeltype])) {
2044  $labeltype = $arraylist[$labeltype];
2045  }
2046  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
2047  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
2048  }
2049  }
2050  $out .= '<td class="tdoverflowmax150" title="'.$labeltype.'">';
2051  $out .= $actionstatic->getTypePicto();
2052  $out .= $labeltype;
2053  $out .= '</td>';
2054 
2055  // Title/Label of event
2056  $out .= '<td class="tdoverflowmax300"';
2057  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2058  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2059  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2060  //$actionstatic->libelle=$libelle;
2061  $libelle = $histo[$key]['note'];
2062  $actionstatic->id = $histo[$key]['id'];
2063  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2064  $out .= dol_trunc($libelle, 120);
2065  }
2066  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2067  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2068  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2069  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2070  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2071  $out .= dol_trunc($libelle, 120);
2072  }
2073  $out .= '</td>';
2074 
2075  // Date
2076  $out .= '<td class="center nowraponall">';
2077  $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
2078  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
2079  $tmpa = dol_getdate($histo[$key]['datestart'], true);
2080  $tmpb = dol_getdate($histo[$key]['dateend'], true);
2081  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2082  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
2083  } else {
2084  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
2085  }
2086  }
2087  $late = 0;
2088  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2089  $late = 1;
2090  }
2091  if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2092  $late = 1;
2093  }
2094  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2095  $late = 1;
2096  }
2097  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2098  $late = 1;
2099  }
2100  if ($late) {
2101  $out .= img_warning($langs->trans("Late")).' ';
2102  }
2103  $out .= "</td>\n";
2104 
2105  // Title of event
2106  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
2107 
2108  // Linked object
2109  $out .= '<td class="nowraponall">';
2110  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2111  if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2112  $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2113  } else {
2114  if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2115  $elementlinkcache[$histo[$key]['elementtype']] = array();
2116  }
2117  $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2118  $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2119  }
2120  $out .= $link;
2121  } else {
2122  $out .= '&nbsp;';
2123  }
2124  $out .= '</td>';
2125 
2126  // Contact(s) for action
2127  if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2128  $out .= '<td class="valignmiddle">';
2129  $contact = new Contact($db);
2130  foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2131  $result = $contact->fetch($cid);
2132 
2133  if ($result < 0) {
2134  dol_print_error($db, $contact->error);
2135  }
2136 
2137  if ($result > 0) {
2138  $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2139  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2140  if (!empty($contact->phone_pro)) {
2141  $out .= '('.dol_print_phone($contact->phone_pro).')';
2142  }
2143  }
2144  $out .= '<div class="paddingright"></div>';
2145  }
2146  }
2147  $out .= '</td>';
2148  } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2149  $contactstatic->lastname = $histo[$key]['lastname'];
2150  $contactstatic->firstname = $histo[$key]['firstname'];
2151  $contactstatic->id = $histo[$key]['contact_id'];
2152  $contactstatic->photo = $histo[$key]['contact_photo'];
2153  $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2154  } else {
2155  $out .= '<td>&nbsp;</td>';
2156  }
2157 
2158  // Status
2159  $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2160 
2161  // Action column
2162  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2163  $out .= '<td></td>';
2164  }
2165 
2166  $out .= "</tr>\n";
2167  $i++;
2168  }
2169  if (empty($histo)) {
2170  $colspan = 9;
2171  $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2172  }
2173 
2174  $out .= "</table>\n";
2175  $out .= "</div>\n";
2176 
2177  $out .= '</form>';
2178  }
2179 
2180  if ($noprint) {
2181  return $out;
2182  } else {
2183  print $out;
2184  }
2185 }
2186 
2196 function show_subsidiaries($conf, $langs, $db, $object)
2197 {
2198  global $user;
2199 
2200  $i = -1;
2201 
2202  $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";
2203  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2204  $sql .= " WHERE s.parent = ".((int) $object->id);
2205  $sql .= " AND s.entity IN (".getEntity('societe').")";
2206  $sql .= " ORDER BY s.nom";
2207 
2208  $result = $db->query($sql);
2209  $num = $db->num_rows($result);
2210 
2211  if ($num) {
2212  $socstatic = new Societe($db);
2213 
2214  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2215 
2216  print "\n".'<div class="div-table-responsive-no-min">'."\n";
2217  print '<table class="noborder centpercent">'."\n";
2218 
2219  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2220  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2221  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2222  print "<td>&nbsp;</td>";
2223  print "</tr>";
2224 
2225  $i = 0;
2226 
2227  while ($i < $num) {
2228  $obj = $db->fetch_object($result);
2229 
2230  $socstatic->id = $obj->rowid;
2231  $socstatic->name = $obj->name;
2232  $socstatic->name_alias = $obj->name_alias;
2233  $socstatic->email = $obj->email;
2234  $socstatic->code_client = $obj->code_client;
2235  $socstatic->code_fournisseur = $obj->code_client;
2236  $socstatic->code_compta = $obj->code_compta;
2237  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2238  $socstatic->email = $obj->email;
2239  $socstatic->canvas = $obj->canvas;
2240  $socstatic->client = $obj->client;
2241  $socstatic->fournisseur = $obj->fournisseur;
2242 
2243  print '<tr class="oddeven">';
2244 
2245  print '<td class="tdoverflowmax150">';
2246  print $socstatic->getNomUrl(1);
2247  print '</td>';
2248 
2249  print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2250  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2251  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2252  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2253 
2254  print '<td class="center">';
2255  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2256  print img_edit();
2257  print '</a></td>';
2258 
2259  print "</tr>\n";
2260  $i++;
2261  }
2262  print "\n</table>\n";
2263  print '</div>'."\n";
2264  }
2265 
2266  print "<br>\n";
2267 
2268  return $i;
2269 }
2278 function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2279 {
2280  global $conf, $db;
2281  // Condition on actioncode
2282 
2283  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
2284  if ($actioncode == 'AC_NON_AUTO') {
2285  $sql .= " $sqlANDOR c.type != 'systemauto'";
2286  } elseif ($actioncode == 'AC_ALL_AUTO') {
2287  $sql .= " $sqlANDOR c.type = 'systemauto'";
2288  } else {
2289  if ($actioncode == 'AC_OTH') {
2290  $sql .= " $sqlANDOR c.type != 'systemauto'";
2291  } elseif ($actioncode == 'AC_OTH_AUTO') {
2292  $sql .= " $sqlANDOR c.type = 'systemauto'";
2293  }
2294  }
2295  } else {
2296  if ($actioncode == 'AC_NON_AUTO') {
2297  $sql .= " $sqlANDOR c.type != 'systemauto'";
2298  } elseif ($actioncode == 'AC_ALL_AUTO') {
2299  $sql .= " $sqlANDOR c.type = 'systemauto'";
2300  } else {
2301  $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2302  }
2303  }
2304 
2305  return $sql;
2306 }
2307 
2317 function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2318 {
2319  global $db;
2320 
2321  if ($donetodo == 'todo') {
2322  $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2323  } elseif ($donetodo == 'done') {
2324  $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2325  }
2326  if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2327  $sql .= natural_search('a.label', $filters['search_agenda_label']);
2328  }
2329  if (is_array($filters) && !empty($filters['search_rowid'])) {
2330  $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2331  }
2332 
2333  return $sql;
2334 }
2335 
2344 function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2345 {
2346  global $db;
2347 
2348  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2349  if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2350  $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";
2351  $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2352  $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2353  $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
2354  if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2355  $sql2 .= ", '' as lastname, '' as firstname";
2356  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2357  $sql2 .= ", '' as lastname, '' as firstname";
2358  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2359  $sql2 .= ", '' as ref";
2360  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2361  $sql2 .= ", '' as ref";
2362  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2363  $sql2 .= ", '' as ref";
2364  }
2365  $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2366  $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2367  $sql2 .= " AND mc.statut = 1";
2368  $sql2 .= " AND u.rowid = m.fk_user_valid";
2369  $sql2 .= " AND mc.fk_mailing=m.rowid";
2370 
2371  return $sql2;
2372  } else {
2373  return '';
2374  }
2375 }
2376 
2377 
2378 
2389 function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2390 {
2391  global $conf;
2392 
2393  $reg = array();
2394 
2395  // Juridical status
2396  $line1 = "";
2397  if ($fromcompany->forme_juridique_code) {
2398  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
2399  }
2400  // Capital
2401  if ($fromcompany->capital) {
2402  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
2403  }
2404  // Prof Id 1
2405  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2406  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2407  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2408  $field = $reg[1];
2409  }
2410  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
2411  }
2412  // Prof Id 2
2413  if ($fromcompany->idprof2) {
2414  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2415  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2416  $field = $reg[1];
2417  }
2418  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
2419  }
2420 
2421  // Second line of company infos
2422  $line2 = "";
2423  // Prof Id 3
2424  if ($fromcompany->idprof3) {
2425  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2426  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2427  $field = $reg[1];
2428  }
2429  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
2430  }
2431  // Prof Id 4
2432  if ($fromcompany->idprof4) {
2433  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2434  if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2435  $field = $reg[1];
2436  }
2437  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
2438  }
2439  // IntraCommunautary VAT
2440  if ($fromcompany->tva_intra != '') {
2441  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
2442  }
2443 
2444  print '<!-- htmlPrintOnlineFooter -->'."\n";
2445 
2446  print '<footer class="center paddingleft paddingright opacitymedium centpercent">'."\n";
2447  print '<br>';
2448  if ($addformmessage) {
2449  print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
2450  print '<br>';
2451 
2452  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
2453  if (!empty($conf->global->$parammessageform)) {
2454  print $langs->transnoentities($conf->global->$parammessageform);
2455  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
2456  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
2457  }
2458 
2459  // Add other message if VAT exists
2460  if (!empty($object->total_vat) || !empty($object->total_tva)) {
2461  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
2462  if (!empty($conf->global->$parammessageform)) {
2463  print $langs->transnoentities($conf->global->$parammessageform);
2464  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
2465  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
2466  }
2467  }
2468  }
2469 
2470  print '<span style="font-size: 10px;"><br><hr>'."\n";
2471  print $fromcompany->name.'<br>';
2472  print $line1;
2473  if (strlen($line1.$line2) > 50) {
2474  print '<br>';
2475  } else {
2476  print ' - ';
2477  }
2478  print $line2;
2479  print '</span>';
2480  print '</footer>'."\n";
2481 }
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:48
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.
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $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=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or 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:42
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
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 informations.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->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') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_dir_list($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:62
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 informations (by default a local PHP server timestamp) Re...
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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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_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 editer/modifier 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:68
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:140