dolibarr  18.0.0
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']) && (!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref']) || $filterobj->fields['label'] && is_array($filterobj->fields['label'])) && $filterobj->table_element && $filterobj->element) {
1676  $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1677  }
1678 
1679  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1680  if ($force_filter_contact === false) {
1681  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1682  $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1683  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1684  /* Nothing */
1685  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1686  $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1687  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1688  $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1689  if ($filterobj->id) {
1690  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1691  }
1692  } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
1693  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
1694  if ($filterobj->id) {
1695  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1696  }
1697  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1698  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1699  if ($filterobj->id) {
1700  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1701  }
1702  } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
1703  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
1704  if ($filterobj->id) {
1705  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1706  }
1707  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1708  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1709  if ($filterobj->id) {
1710  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1711  }
1712  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1713  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1714  if ($filterobj->id) {
1715  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1716  }
1717  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1718  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1719  if ($filterobj->id) {
1720  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1721  }
1722  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1723  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1724  if ($filterobj->id) {
1725  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1726  }
1727  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && (!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref']) || $filterobj->fields['label'] && is_array($filterobj->fields['label'])) && $filterobj->table_element && $filterobj->element) {
1728  // Generic case
1729  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1730  if ($filterobj->id) {
1731  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1732  }
1733  }
1734  }
1735 
1736  if (!empty($tms_start) && !empty($tms_end)) {
1737  $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)."'))";
1738  } elseif (empty($tms_start) && !empty($tms_end)) {
1739  $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1740  } elseif (!empty($tms_start) && empty($tms_end)) {
1741  $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1742  }
1743 
1744  if (is_array($actioncode) && !empty($actioncode)) {
1745  $sql .= ' AND (';
1746  foreach ($actioncode as $key => $code) {
1747  if ($key != 0) {
1748  $sql .= "OR (";
1749  }
1750  if (!empty($code)) {
1751  addEventTypeSQL($sql, $code);
1752  }
1753  if ($key != 0) {
1754  $sql .= ")";
1755  }
1756  }
1757  $sql .= ')';
1758  } elseif (!empty($actioncode)) {
1759  addEventTypeSQL($sql, $actioncode);
1760  }
1761 
1762  addOtherFilterSQL($sql, $donetodo, $now, $filters);
1763 
1764  // Fields from hook
1765  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
1766  $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
1767  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1768 
1769  if (is_array($actioncode)) {
1770  foreach ($actioncode as $code) {
1771  $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1772  if (!empty($sql2)) {
1773  if (!empty($sql)) {
1774  $sql = $sql." UNION ".$sql2;
1775  } elseif (empty($sql)) {
1776  $sql = $sql2;
1777  }
1778  break;
1779  }
1780  }
1781  } else {
1782  $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
1783  if (!empty($sql) && !empty($sql2)) {
1784  $sql = $sql." UNION ".$sql2;
1785  } elseif (empty($sql) && !empty($sql2)) {
1786  $sql = $sql2;
1787  }
1788  }
1789  }
1790 
1791  //TODO Add limit in nb of results
1792  if ($sql) {
1793  $sql .= $db->order($sortfield_new, $sortorder);
1794 
1795  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1796 
1797  $resql = $db->query($sql);
1798  if ($resql) {
1799  $i = 0;
1800  $num = $db->num_rows($resql);
1801 
1802  while ($i < $num) {
1803  $obj = $db->fetch_object($resql);
1804 
1805  if ($obj->type == 'action') {
1806  $contactaction = new ActionComm($db);
1807  $contactaction->id = $obj->id;
1808  $result = $contactaction->fetchResources();
1809  if ($result < 0) {
1810  dol_print_error($db);
1811  setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
1812  }
1813 
1814  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1815  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1816  $tododone = '';
1817  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
1818  $tododone = 'todo';
1819  }
1820 
1821  $histo[$numaction] = array(
1822  'type'=>$obj->type,
1823  'tododone'=>$tododone,
1824  'id'=>$obj->id,
1825  'datestart'=>$db->jdate($obj->dp),
1826  'dateend'=>$db->jdate($obj->dp2),
1827  'note'=>$obj->label,
1828  'percent'=>$obj->percent,
1829 
1830  'userid'=>$obj->user_id,
1831  'login'=>$obj->user_login,
1832  'userfirstname'=>$obj->user_firstname,
1833  'userlastname'=>$obj->user_lastname,
1834  'userphoto'=>$obj->user_photo,
1835 
1836  'contact_id'=>$obj->fk_contact,
1837  'socpeopleassigned' => $contactaction->socpeopleassigned,
1838  'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
1839  'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
1840  'fk_element'=>$obj->fk_element,
1841  'elementtype'=>$obj->elementtype,
1842  // Type of event
1843  'acode'=>$obj->acode,
1844  'alabel'=>$obj->alabel,
1845  'libelle'=>$obj->alabel, // deprecated
1846  'apicto'=>$obj->apicto
1847  );
1848  } else {
1849  $histo[$numaction] = array(
1850  'type'=>$obj->type,
1851  'tododone'=>'done',
1852  'id'=>$obj->id,
1853  'datestart'=>$db->jdate($obj->dp),
1854  'dateend'=>$db->jdate($obj->dp2),
1855  'note'=>$obj->label,
1856  'percent'=>$obj->percent,
1857  'acode'=>$obj->acode,
1858 
1859  'userid'=>$obj->user_id,
1860  'login'=>$obj->user_login,
1861  'userfirstname'=>$obj->user_firstname,
1862  'userlastname'=>$obj->user_lastname,
1863  'userphoto'=>$obj->user_photo
1864  );
1865  }
1866 
1867  $numaction++;
1868  $i++;
1869  }
1870  } else {
1871  dol_print_error($db);
1872  }
1873  }
1874 
1875  if (isModEnabled('agenda')|| (isModEnabled('mailing') && !empty($objcon->email))) {
1876  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
1877 
1878  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1879  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1880  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1881  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1882 
1883  $formactions = new FormActions($db);
1884 
1885  $actionstatic = new ActionComm($db);
1886  $userstatic = new User($db);
1887  $userlinkcache = array();
1888  $contactstatic = new Contact($db);
1889  $elementlinkcache = array();
1890 
1891  $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1892  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1893  if ($objcon && get_class($objcon) == 'Contact' &&
1894  (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
1895  $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
1896  } else {
1897  $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1898  }
1899  if ($filterobj && get_class($filterobj) == 'Societe') {
1900  $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1901  }
1902 
1903  $out .= "\n";
1904 
1905  $out .= '<div class="div-table-responsive-no-min">';
1906  $out .= '<table class="noborder centpercent">';
1907 
1908  $out .= '<tr class="liste_titre">';
1909 
1910  // Action column
1911  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1912  $out .= '<th class="liste_titre width50 middle">';
1913  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1914  $out .= $searchpicto;
1915  $out .= '</th>';
1916  }
1917 
1918  if ($donetodo) {
1919  $out .= '<td class="liste_titre"></td>';
1920  }
1921 
1922  $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
1923  $out .= '<td class="liste_titre"></td>';
1924  $out .= '<td class="liste_titre">';
1925  $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');
1926  $out .= '</td>';
1927  $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1928  $out .= '<td class="liste_titre center">';
1929  $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
1930  $out .= '</td>';
1931  $out .= '<td class="liste_titre"></td>';
1932  $out .= '<td class="liste_titre"></td>';
1933  $out .= '<td class="liste_titre"></td>';
1934  // Action column
1935  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1936  $out .= '<td class="liste_titre" align="middle">';
1937  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1938  $out .= $searchpicto;
1939  $out .= '</td>';
1940  }
1941  $out .= '</tr>';
1942 
1943  $out .= '<tr class="liste_titre">';
1944  // Action column
1945  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1946  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1947  }
1948  if ($donetodo) {
1949  $tmp = '';
1950  if (get_class($filterobj) == 'Societe') {
1951  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
1952  }
1953  $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1954  $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1955  $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1956  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1957  if (get_class($filterobj) == 'Societe') {
1958  $tmp .= '</a>';
1959  }
1960  $out .= getTitleFieldOfList($tmp);
1961  }
1962  $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1963  $out .= getTitleFieldOfList("Owner");
1964  $out .= getTitleFieldOfList("Type");
1965  $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1966  $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
1967  $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1968  $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
1969  $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
1970  // Action column
1971  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1972  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1973  }
1974  $out .= '</tr>';
1975 
1976  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
1977  $caction = new CActionComm($db);
1978  $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
1979 
1980  foreach ($histo as $key => $value) {
1981  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1982 
1983  $actionstatic->type_picto = $histo[$key]['apicto'];
1984  $actionstatic->type_code = $histo[$key]['acode'];
1985 
1986  $out .= '<tr class="oddeven">';
1987 
1988  // Action column
1989  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1990  $out .= '<td></td>';
1991  }
1992 
1993  // Done or todo
1994  if ($donetodo) {
1995  $out .= '<td class="nowrap">';
1996  $out .= '</td>';
1997  }
1998 
1999  // Ref
2000  $out .= '<td class="nowraponall">';
2001  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2002  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2003  $out .= $histo[$key]['id'];
2004  $out .= '</a>';
2005  } else {
2006  $out .= $actionstatic->getNomUrl(1, -1);
2007  }
2008  $out .= '</td>';
2009 
2010  // Author of event
2011  $out .= '<td class="tdoverflowmax150">';
2012  //$userstatic->id=$histo[$key]['userid'];
2013  //$userstatic->login=$histo[$key]['login'];
2014  //$out.=$userstatic->getLoginUrl(1);
2015  if ($histo[$key]['userid'] > 0) {
2016  if (isset($userlinkcache[$histo[$key]['userid']])) {
2017  $link = $userlinkcache[$histo[$key]['userid']];
2018  } else {
2019  $userstatic->fetch($histo[$key]['userid']);
2020  $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2021  $userlinkcache[$histo[$key]['userid']] = $link;
2022  }
2023  $out .= $link;
2024  }
2025  $out .= '</td>';
2026 
2027  // Type
2028  $labeltype = $actionstatic->type_code;
2029  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
2030  $labeltype = 'AC_OTH';
2031  }
2032  if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2033  $labeltype = $langs->trans("Message");
2034  } else {
2035  if (!empty($arraylist[$labeltype])) {
2036  $labeltype = $arraylist[$labeltype];
2037  }
2038  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
2039  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
2040  }
2041  }
2042  $out .= '<td class="tdoverflowmax150" title="'.$labeltype.'">';
2043  $out .= $actionstatic->getTypePicto();
2044  $out .= $labeltype;
2045  $out .= '</td>';
2046 
2047  // Title/Label of event
2048  $out .= '<td class="tdoverflowmax300"';
2049  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2050  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2051  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2052  //$actionstatic->libelle=$libelle;
2053  $libelle = $histo[$key]['note'];
2054  $actionstatic->id = $histo[$key]['id'];
2055  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2056  $out .= dol_trunc($libelle, 120);
2057  }
2058  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2059  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2060  $transcode = $langs->trans("Action".$histo[$key]['acode']);
2061  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2062  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2063  $out .= dol_trunc($libelle, 120);
2064  }
2065  $out .= '</td>';
2066 
2067  // Date
2068  $out .= '<td class="center nowraponall">';
2069  $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
2070  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
2071  $tmpa = dol_getdate($histo[$key]['datestart'], true);
2072  $tmpb = dol_getdate($histo[$key]['dateend'], true);
2073  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2074  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
2075  } else {
2076  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
2077  }
2078  }
2079  $late = 0;
2080  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2081  $late = 1;
2082  }
2083  if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2084  $late = 1;
2085  }
2086  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2087  $late = 1;
2088  }
2089  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2090  $late = 1;
2091  }
2092  if ($late) {
2093  $out .= img_warning($langs->trans("Late")).' ';
2094  }
2095  $out .= "</td>\n";
2096 
2097  // Title of event
2098  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
2099 
2100  // Linked object
2101  $out .= '<td class="nowraponall">';
2102  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2103  if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2104  $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2105  } else {
2106  if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2107  $elementlinkcache[$histo[$key]['elementtype']] = array();
2108  }
2109  $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2110  $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2111  }
2112  $out .= $link;
2113  } else {
2114  $out .= '&nbsp;';
2115  }
2116  $out .= '</td>';
2117 
2118  // Contact(s) for action
2119  if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2120  $out .= '<td class="valignmiddle">';
2121  $contact = new Contact($db);
2122  foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2123  $result = $contact->fetch($cid);
2124 
2125  if ($result < 0) {
2126  dol_print_error($db, $contact->error);
2127  }
2128 
2129  if ($result > 0) {
2130  $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2131  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2132  if (!empty($contact->phone_pro)) {
2133  $out .= '('.dol_print_phone($contact->phone_pro).')';
2134  }
2135  }
2136  $out .= '<div class="paddingright"></div>';
2137  }
2138  }
2139  $out .= '</td>';
2140  } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2141  $contactstatic->lastname = $histo[$key]['lastname'];
2142  $contactstatic->firstname = $histo[$key]['firstname'];
2143  $contactstatic->id = $histo[$key]['contact_id'];
2144  $contactstatic->photo = $histo[$key]['contact_photo'];
2145  $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2146  } else {
2147  $out .= '<td>&nbsp;</td>';
2148  }
2149 
2150  // Status
2151  $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2152 
2153  // Action column
2154  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2155  $out .= '<td></td>';
2156  }
2157 
2158  $out .= "</tr>\n";
2159  $i++;
2160  }
2161  if (empty($histo)) {
2162  $colspan = 9;
2163  $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2164  }
2165 
2166  $out .= "</table>\n";
2167  $out .= "</div>\n";
2168 
2169  $out .= '</form>';
2170  }
2171 
2172  if ($noprint) {
2173  return $out;
2174  } else {
2175  print $out;
2176  }
2177 }
2178 
2188 function show_subsidiaries($conf, $langs, $db, $object)
2189 {
2190  global $user;
2191 
2192  $i = -1;
2193 
2194  $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";
2195  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2196  $sql .= " WHERE s.parent = ".((int) $object->id);
2197  $sql .= " AND s.entity IN (".getEntity('societe').")";
2198  $sql .= " ORDER BY s.nom";
2199 
2200  $result = $db->query($sql);
2201  $num = $db->num_rows($result);
2202 
2203  if ($num) {
2204  $socstatic = new Societe($db);
2205 
2206  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2207 
2208  print "\n".'<div class="div-table-responsive-no-min">'."\n";
2209  print '<table class="noborder centpercent">'."\n";
2210 
2211  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2212  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2213  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2214  print "<td>&nbsp;</td>";
2215  print "</tr>";
2216 
2217  $i = 0;
2218 
2219  while ($i < $num) {
2220  $obj = $db->fetch_object($result);
2221 
2222  $socstatic->id = $obj->rowid;
2223  $socstatic->name = $obj->name;
2224  $socstatic->name_alias = $obj->name_alias;
2225  $socstatic->email = $obj->email;
2226  $socstatic->code_client = $obj->code_client;
2227  $socstatic->code_fournisseur = $obj->code_client;
2228  $socstatic->code_compta = $obj->code_compta;
2229  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2230  $socstatic->email = $obj->email;
2231  $socstatic->canvas = $obj->canvas;
2232  $socstatic->client = $obj->client;
2233  $socstatic->fournisseur = $obj->fournisseur;
2234 
2235  print '<tr class="oddeven">';
2236 
2237  print '<td class="tdoverflowmax150">';
2238  print $socstatic->getNomUrl(1);
2239  print '</td>';
2240 
2241  print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2242  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2243  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2244  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2245 
2246  print '<td class="center">';
2247  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2248  print img_edit();
2249  print '</a></td>';
2250 
2251  print "</tr>\n";
2252  $i++;
2253  }
2254  print "\n</table>\n";
2255  print '</div>'."\n";
2256  }
2257 
2258  print "<br>\n";
2259 
2260  return $i;
2261 }
2270 function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2271 {
2272  global $conf, $db;
2273  // Condition on actioncode
2274 
2275  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
2276  if ($actioncode == 'AC_NON_AUTO') {
2277  $sql .= " $sqlANDOR c.type != 'systemauto'";
2278  } elseif ($actioncode == 'AC_ALL_AUTO') {
2279  $sql .= " $sqlANDOR c.type = 'systemauto'";
2280  } else {
2281  if ($actioncode == 'AC_OTH') {
2282  $sql .= " $sqlANDOR c.type != 'systemauto'";
2283  } elseif ($actioncode == 'AC_OTH_AUTO') {
2284  $sql .= " $sqlANDOR c.type = 'systemauto'";
2285  }
2286  }
2287  } else {
2288  if ($actioncode == 'AC_NON_AUTO') {
2289  $sql .= " $sqlANDOR c.type != 'systemauto'";
2290  } elseif ($actioncode == 'AC_ALL_AUTO') {
2291  $sql .= " $sqlANDOR c.type = 'systemauto'";
2292  } else {
2293  $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2294  }
2295  }
2296 
2297  return $sql;
2298 }
2299 
2309 function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2310 {
2311  global $db;
2312 
2313  if ($donetodo == 'todo') {
2314  $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2315  } elseif ($donetodo == 'done') {
2316  $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2317  }
2318  if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2319  $sql .= natural_search('a.label', $filters['search_agenda_label']);
2320  }
2321  if (is_array($filters) && !empty($filters['search_rowid'])) {
2322  $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2323  }
2324 
2325  return $sql;
2326 }
2327 
2336 function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2337 {
2338  global $db;
2339 
2340  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2341  if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2342  $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";
2343  $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2344  $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2345  $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
2346  if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2347  $sql2 .= ", '' as lastname, '' as firstname";
2348  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2349  $sql2 .= ", '' as lastname, '' as firstname";
2350  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2351  $sql2 .= ", '' as ref";
2352  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2353  $sql2 .= ", '' as ref";
2354  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2355  $sql2 .= ", '' as ref";
2356  }
2357  $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2358  $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2359  $sql2 .= " AND mc.statut = 1";
2360  $sql2 .= " AND u.rowid = m.fk_user_valid";
2361  $sql2 .= " AND mc.fk_mailing=m.rowid";
2362 
2363  return $sql2;
2364  } else {
2365  return '';
2366  }
2367 }
2368 
2369 
2370 
2381 function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2382 {
2383  global $conf;
2384 
2385  $reg = array();
2386 
2387  // Juridical status
2388  $line1 = "";
2389  if ($fromcompany->forme_juridique_code) {
2390  $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
2391  }
2392  // Capital
2393  if ($fromcompany->capital) {
2394  $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
2395  }
2396  // Prof Id 1
2397  if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2398  $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2399  if (preg_match('/\((.*)\)/i', $field, $reg)) {
2400  $field = $reg[1];
2401  }
2402  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
2403  }
2404  // Prof Id 2
2405  if ($fromcompany->idprof2) {
2406  $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2407  if (preg_match('/\((.*)\)/i', $field, $reg)) {
2408  $field = $reg[1];
2409  }
2410  $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
2411  }
2412 
2413  // Second line of company infos
2414  $line2 = "";
2415  // Prof Id 3
2416  if ($fromcompany->idprof3) {
2417  $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2418  if (preg_match('/\((.*)\)/i', $field, $reg)) {
2419  $field = $reg[1];
2420  }
2421  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
2422  }
2423  // Prof Id 4
2424  if ($fromcompany->idprof4) {
2425  $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2426  if (preg_match('/\((.*)\)/i', $field, $reg)) {
2427  $field = $reg[1];
2428  }
2429  $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
2430  }
2431  // IntraCommunautary VAT
2432  if ($fromcompany->tva_intra != '') {
2433  $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
2434  }
2435 
2436  print '<!-- htmlPrintOnlineFooter -->'."\n";
2437 
2438  print '<footer class="center paddingleft paddingright opacitymedium centpercent">'."\n";
2439  print '<br>';
2440  if ($addformmessage) {
2441  print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
2442  print '<br>';
2443 
2444  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
2445  if (!empty($conf->global->$parammessageform)) {
2446  print $langs->transnoentities($conf->global->$parammessageform);
2447  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORM)) {
2448  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORM);
2449  }
2450 
2451  // Add other message if VAT exists
2452  if (!empty($object->total_vat) || !empty($object->total_tva)) {
2453  $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
2454  if (!empty($conf->global->$parammessageform)) {
2455  print $langs->transnoentities($conf->global->$parammessageform);
2456  } elseif (!empty($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT)) {
2457  print $langs->transnoentities($conf->global->ONLINE_PAYMENT_MESSAGE_FORMIFVAT);
2458  }
2459  }
2460  }
2461 
2462  print '<span style="font-size: 10px;"><br><hr>'."\n";
2463  print $fromcompany->name.'<br>';
2464  print $line1;
2465  if (strlen($line1.$line2) > 50) {
2466  print '<br>';
2467  } else {
2468  print ' - ';
2469  }
2470  print $line2;
2471  print '</span>';
2472  print '</footer>'."\n";
2473 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2925
dol_setcache
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
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:51
dolGetElementUrl
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
Definition: functions2.lib.php:2119
dol_trunc
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.
Definition: functions.lib.php:4059
Project
Class to manage projects.
Definition: project.class.php:36
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
dol_escape_htmltag
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...
Definition: functions.lib.php:1600
dol_getcache
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:140
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5318
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8922
SocieteAccount
Class for SocieteAccount.
Definition: societeaccount.class.php:35
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
htmlPrintOnlineFooter
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
Definition: company.lib.php:2381
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1129
dol_dir_list
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
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4784
show_actions_todo
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
Definition: company.lib.php:1511
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
setEventMessage
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
Definition: functions.lib.php:8637
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3243
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
getState
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
Definition: company.lib.php:595
show_subsidiaries
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
Definition: company.lib.php:2188
addOtherFilterSQL
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
Definition: company.lib.php:2309
getCountriesInEEC
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
Definition: company.lib.php:748
$formactions
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.
Definition: agenda_other.php:182
CActionComm
Class to manage different types of events.
Definition: cactioncomm.class.php:29
complete_head_from_modules
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).
Definition: functions.lib.php:9602
currency_name
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
Definition: company.lib.php:667
dolGetButtonTitle
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.
Definition: functions.lib.php:11263
show_actions_done
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).
Definition: company.lib.php:1542
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:7046
show_contacts
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
Definition: company.lib.php:939
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
Contact
Class to manage contact/addresses.
Definition: contact.class.php:42
show_projects
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
Definition: company.lib.php:810
addMailingEventTypeSQL
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
Definition: company.lib.php:2336
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
Definition: company.lib.php:711
societe_prepare_head2
societe_prepare_head2($object)
Return array of tabs to used on page.
Definition: company.lib.php:427
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
$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
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
getDolGlobalString
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:142
User
Class to manage Dolibarr users.
Definition: user.class.php:47
societe_admin_prepare_head
societe_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: company.lib.php:453
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:509
natural_search
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...
Definition: functions.lib.php:10024
dol_eval
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
Definition: functions.lib.php:9165
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4473
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
price
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.
Definition: functions.lib.php:5829
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:515
dol_mktime
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...
Definition: functions.lib.php:2968
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
addEventTypeSQL
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
Definition: company.lib.php:2270
isInEEC
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
Definition: company.lib.php:785