dolibarr  16.0.5
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->rights->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('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_proposal->enabled) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
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 (!empty($conf->project->enabled) && (!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('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))
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)) && (!empty($user->rights->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.'/societe/partnership.php?socid='.$object->id;
271  $head[$h][1] = $langs->trans("Partnership");
272  $head[$h][2] = 'partnership';
273  if ($nbPartnership > 0) {
274  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
275  }
276  $h++;
277  }
278  }
279 
280  // Show more tabs from modules
281  // Entries must be declared in modules descriptor with line
282  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
283  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
284  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty');
285 
286  if ($user->socid == 0) {
287  // Notifications
288  if (isModEnabled('notification')) {
289  $nbNotif = 0;
290  // Enable caching of thirdparty count notifications
291  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
292  $cachekey = 'count_notifications_thirdparty_'.$object->id;
293  $dataretrieved = dol_getcache($cachekey);
294  if (!is_null($dataretrieved)) {
295  $nbNotif = $dataretrieved;
296  } else {
297  $sql = "SELECT COUNT(n.rowid) as nb";
298  $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n";
299  $sql .= " WHERE fk_soc = ".((int) $object->id);
300  $resql = $db->query($sql);
301  if ($resql) {
302  $obj = $db->fetch_object($resql);
303  $nbNotif = $obj->nb;
304  } else {
305  dol_print_error($db);
306  }
307  dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
308  }
309 
310  $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.urlencode($object->id);
311  $head[$h][1] = $langs->trans("Notifications");
312  if ($nbNotif > 0) {
313  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
314  }
315  $head[$h][2] = 'notify';
316  $h++;
317  }
318 
319  // Notes
320  $nbNote = 0;
321  if (!empty($object->note_private)) {
322  $nbNote++;
323  }
324  if (!empty($object->note_public)) {
325  $nbNote++;
326  }
327  $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.urlencode($object->id);
328  $head[$h][1] = $langs->trans("Notes");
329  if ($nbNote > 0) {
330  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
331  }
332  $head[$h][2] = 'note';
333  $h++;
334 
335  // Attached files and Links
336  $totalAttached = 0;
337  // Enable caching of thirdrparty count attached files and links
338  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
339  $cachekey = 'count_attached_thirdparty_'.$object->id;
340  $dataretrieved = dol_getcache($cachekey);
341  if (!is_null($dataretrieved)) {
342  $totalAttached = $dataretrieved;
343  } else {
344  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
345  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
346  $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
347  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
348  $nbLinks = Link::count($db, $object->element, $object->id);
349  $totalAttached = $nbFiles + $nbLinks;
350  dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
351  }
352 
353  $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
354  $head[$h][1] = $langs->trans("Documents");
355  if (($totalAttached) > 0) {
356  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
357  }
358  $head[$h][2] = 'document';
359  $h++;
360  }
361 
362  $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
363  $head[$h][1] = $langs->trans("Events");
364  if (isModEnabled('agenda')&& (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
365  $nbEvent = 0;
366  // Enable caching of thirdrparty count actioncomm
367  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
368  $cachekey = 'count_events_thirdparty_'.$object->id;
369  $dataretrieved = dol_getcache($cachekey);
370  if (!is_null($dataretrieved)) {
371  $nbEvent = $dataretrieved;
372  } else {
373  $sql = "SELECT COUNT(id) as nb";
374  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
375  $sql .= " WHERE fk_soc = ".((int) $object->id);
376  $resql = $db->query($sql);
377  if ($resql) {
378  $obj = $db->fetch_object($resql);
379  $nbEvent = $obj->nb;
380  } else {
381  dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
382  }
383  dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
384  }
385 
386  $head[$h][1] .= '/';
387  $head[$h][1] .= $langs->trans("Agenda");
388  if ($nbEvent > 0) {
389  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
390  }
391  }
392  $head[$h][2] = 'agenda';
393  $h++;
394 
395  // Log
396  /*$head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id;
397  $head[$h][1] = $langs->trans("Info");
398  $head[$h][2] = 'info';
399  $h++;*/
400 
401  complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
402 
403  return $head;
404 }
405 
406 
413 function societe_prepare_head2($object)
414 {
415  global $langs, $conf, $user;
416  $h = 0;
417  $head = array();
418 
419  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
420  $head[$h][1] = $langs->trans("ThirdParty");
421  $head[$h][2] = 'company';
422  $h++;
423 
424  $head[$h][0] = 'commerciaux.php?socid='.$object->id;
425  $head[$h][1] = $langs->trans("SalesRepresentative");
426  $head[$h][2] = 'salesrepresentative';
427  $h++;
428 
429  return $head;
430 }
431 
432 
433 
440 {
441  global $langs, $conf, $user;
442 
443  $h = 0;
444  $head = array();
445 
446  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
447  $head[$h][1] = $langs->trans("Miscellaneous");
448  $head[$h][2] = 'general';
449  $h++;
450 
451  // Show more tabs from modules
452  // Entries must be declared in modules descriptor with line
453  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
454  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
455  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
456 
457  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
458  $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
459  $head[$h][2] = 'attributes';
460  $h++;
461 
462  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
463  $head[$h][1] = $langs->trans("ExtraFieldsContacts");
464  $head[$h][2] = 'attributes_contacts';
465  $h++;
466 
467  complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
468 
469  return $head;
470 }
471 
472 
473 
489 function getCountry($searchkey, $withcode = '', $dbtouse = 0, $outputlangs = '', $entconv = 1, $searchlabel = '')
490 {
491  global $db, $langs;
492 
493  $result = '';
494 
495  // Check parameters
496  if (empty($searchkey) && empty($searchlabel)) {
497  if ($withcode === 'all') {
498  return array('id'=>'', 'code'=>'', 'label'=>'');
499  } else {
500  return '';
501  }
502  }
503  if (!is_object($dbtouse)) {
504  $dbtouse = $db;
505  }
506  if (!is_object($outputlangs)) {
507  $outputlangs = $langs;
508  }
509 
510  $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
511  if (is_numeric($searchkey)) {
512  $sql .= " WHERE rowid = ".((int) $searchkey);
513  } elseif (!empty($searchkey)) {
514  $sql .= " WHERE code = '".$db->escape($searchkey)."'";
515  } else {
516  $sql .= " WHERE label = '".$db->escape($searchlabel)."'";
517  }
518 
519  $resql = $dbtouse->query($sql);
520  if ($resql) {
521  $obj = $dbtouse->fetch_object($resql);
522  if ($obj) {
523  $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
524  if (is_object($outputlangs)) {
525  $outputlangs->load("dict");
526  if ($entconv) {
527  $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label;
528  } else {
529  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label;
530  }
531  }
532  if ($withcode == 1) {
533  $result = $label ? "$obj->code - $label" : "$obj->code";
534  } elseif ($withcode == 2) {
535  $result = $obj->code;
536  } elseif ($withcode == 3) {
537  $result = $obj->rowid;
538  } elseif ($withcode === 'all') {
539  $result = array('id'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$label);
540  } else {
541  $result = $label;
542  }
543  } else {
544  $result = 'NotDefined';
545  }
546  $dbtouse->free($resql);
547  return $result;
548  } else {
549  dol_print_error($dbtouse, '');
550  }
551  return 'Error';
552 }
553 
569 function getState($id, $withcode = '', $dbtouse = 0, $withregion = 0, $outputlangs = '', $entconv = 1)
570 {
571  global $db, $langs;
572 
573  if (!is_object($dbtouse)) {
574  $dbtouse = $db;
575  }
576 
577  $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";
578  $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
579  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".((int) $id);
580  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
581  $sql .= " ORDER BY c.code, d.code_departement";
582 
583  dol_syslog("Company.lib::getState", LOG_DEBUG);
584  $resql = $dbtouse->query($sql);
585  if ($resql) {
586  $obj = $dbtouse->fetch_object($resql);
587  if ($obj) {
588  $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
589  if (is_object($outputlangs)) {
590  $outputlangs->load("dict");
591  if ($entconv) {
592  $label = ($obj->code && ($outputlangs->trans("State".$obj->code) != "State".$obj->code)) ? $outputlangs->trans("State".$obj->code) : $label;
593  } else {
594  $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code) != "State".$obj->code)) ? $outputlangs->transnoentitiesnoconv("State".$obj->code) : $label;
595  }
596  }
597 
598  if ($withcode == 1) {
599  if ($withregion == 1) {
600  return $label = $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
601  } else {
602  return $label = $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
603  }
604  } elseif ($withcode == 2) {
605  if ($withregion == 1) {
606  return $label = $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
607  } else {
608  return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
609  }
610  } elseif ($withcode === 'all') {
611  if ($withregion == 1) {
612  return array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$label, 'region_code'=>$obj->region_code, 'region'=>$obj->region_name);
613  } else {
614  return array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$label);
615  }
616  } else {
617  if ($withregion == 1) {
618  return $label = $obj->region_name.' - '.$label;
619  } else {
620  return $label;
621  }
622  }
623  } else {
624  return $langs->transnoentitiesnoconv("NotDefined");
625  }
626  } else {
627  dol_print_error($dbtouse, '');
628  }
629 }
630 
639 function currency_name($code_iso, $withcode = '', $outputlangs = null)
640 {
641  global $langs, $db;
642 
643  if (empty($outputlangs)) {
644  $outputlangs = $langs;
645  }
646 
647  $outputlangs->load("dict");
648 
649  // If there is a translation, we can send immediatly the label
650  if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
651  return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
652  }
653 
654  // If no translation, we read table to get label by default
655  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
656  $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
657 
658  $resql = $db->query($sql);
659  if ($resql) {
660  $num = $db->num_rows($resql);
661 
662  if ($num) {
663  $obj = $db->fetch_object($resql);
664  $label = ($obj->label != '-' ? $obj->label : '');
665  if ($withcode) {
666  return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
667  } else {
668  return $label;
669  }
670  } else {
671  return $code_iso;
672  }
673  }
674  return 'ErrorWhenReadingCurrencyLabel';
675 }
676 
683 function getFormeJuridiqueLabel($code)
684 {
685  global $db, $langs;
686 
687  if (!$code) {
688  return '';
689  }
690 
691  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
692  $sql .= " WHERE code='".$db->escape($code)."'";
693 
694  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
695  $resql = $db->query($sql);
696  if ($resql) {
697  $num = $db->num_rows($resql);
698 
699  if ($num) {
700  $obj = $db->fetch_object($resql);
701  $label = ($obj->libelle != '-' ? $obj->libelle : '');
702  return $label;
703  } else {
704  return $langs->trans("NotDefined");
705  }
706  }
707 }
708 
709 
717 {
718  // List of all country codes that are in europe for european vat rules
719  // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
720  global $conf, $db;
721  $country_code_in_EEC = array();
722 
723  if (!empty($conf->cache['country_code_in_EEC'])) {
724  // Use of cache to reduce number of database requests
725  $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
726  } else {
727  $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
728  $sql .= " WHERE cc.eec = 1";
729 
730  $resql = $db->query($sql);
731  if ($resql) {
732  $num = $db->num_rows($resql);
733  $i = 0;
734  while ($i < $num) {
735  $objp = $db->fetch_object($resql);
736  $country_code_in_EEC[] = $objp->code;
737  $i++;
738  }
739  } else {
740  dol_print_error($db);
741  }
742  $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
743  }
744  return $country_code_in_EEC;
745 }
746 
753 function isInEEC($object)
754 {
755  if (empty($object->country_code)) {
756  return false;
757  }
758 
759  $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
760 
761  //print "dd".$object->country_code;
762  return in_array($object->country_code, $country_code_in_EEC);
763 }
764 
765 
778 function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
779 {
780  global $user, $action, $hookmanager;
781 
782  $i = -1;
783 
784  if (!empty($conf->project->enabled) && $user->rights->projet->lire) {
785  $langs->load("projects");
786 
787  $newcardbutton = '';
788  if (!empty($conf->project->enabled) && $user->rights->projet->creer && empty($nocreatelink)) {
789  $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));
790  }
791 
792  print "\n";
793  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
794 
795  print '<div class="div-table-responsive">'."\n";
796  print '<table class="noborder centpercent">';
797 
798  $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";
799  $sql .= ", cls.code as opp_status_code";
800  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
801  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
802  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
803  $sql .= " AND p.entity IN (".getEntity('project').")";
804  $sql .= " ORDER BY p.dateo DESC";
805 
806  $result = $db->query($sql);
807  if ($result) {
808  $num = $db->num_rows($result);
809 
810  print '<tr class="liste_titre">';
811  print '<td>'.$langs->trans("Ref").'</td>';
812  print '<td>'.$langs->trans("Name").'</td>';
813  print '<td class="center">'.$langs->trans("DateStart").'</td>';
814  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
815  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
816  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
817  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
818  print '<td class="right">'.$langs->trans("Status").'</td>';
819  print '</tr>';
820 
821  if ($num > 0) {
822  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
823 
824  $projecttmp = new Project($db);
825 
826  $i = 0;
827 
828  while ($i < $num) {
829  $obj = $db->fetch_object($result);
830  $projecttmp->fetch($obj->id);
831 
832  // To verify role of users
833  $userAccess = $projecttmp->restrictedProjectArea($user);
834 
835  if ($user->rights->projet->lire && $userAccess > 0) {
836  print '<tr class="oddeven">';
837 
838  // Ref
839  print '<td class="nowraponall">';
840  print $projecttmp->getNomUrl(1);
841  print '</td>';
842 
843  // Label
844  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
845  // Date start
846  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
847  // Date end
848  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
849  // Opp amount
850  print '<td class="right">';
851  if ($obj->opp_status_code) {
852  print price($obj->opp_amount, 1, '', 1, -1, -1, '');
853  }
854  print '</td>';
855  // Opp status
856  print '<td class="center">';
857  if ($obj->opp_status_code) {
858  print $langs->trans("OppStatus".$obj->opp_status_code);
859  }
860  print '</td>';
861  // Opp percent
862  print '<td class="right">';
863  if ($obj->opp_percent) {
864  print price($obj->opp_percent, 1, '', 1, 0).'%';
865  }
866  print '</td>';
867  // Status
868  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
869 
870  print '</tr>';
871  }
872  $i++;
873  }
874  } else {
875  print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
876  }
877  $db->free($result);
878  } else {
879  dol_print_error($db);
880  }
881 
882  $parameters = array('sql'=>$sql, 'function'=>'show_projects');
883  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
884  print $hookmanager->resPrint;
885 
886  print "</table>";
887  print '</div>';
888 
889  print "<br>\n";
890  }
891 
892  return $i;
893 }
894 
895 
907 function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
908 {
909  global $user, $conf, $extrafields, $hookmanager;
910  global $contextpage;
911 
912  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
913  $formcompany = new FormCompany($db);
914  $form = new Form($db);
915 
916  $optioncss = GETPOST('optioncss', 'alpha');
917  $sortfield = GETPOST('sortfield', 'aZ09comma');
918  $sortorder = GETPOST('sortorder', 'aZ09comma');
919  $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
920 
921  $search_status = GETPOST("search_status", 'int');
922  if ($search_status == '') {
923  $search_status = 1; // always display active customer first
924  }
925 
926  $search_name = GETPOST("search_name", 'alpha');
927  $search_address = GETPOST("search_address", 'alpha');
928  $search_poste = GETPOST("search_poste", 'alpha');
929  $search_roles = GETPOST("search_roles", 'array');
930 
931  $socialnetworks = getArrayOfSocialNetworks();
932 
933  $searchAddressPhoneDBFields = array(
934  //Address
935  't.address',
936  't.zip',
937  't.town',
938 
939  //Phone
940  't.phone',
941  't.phone_perso',
942  't.phone_mobile',
943 
944  //Fax
945  't.fax',
946 
947  //E-mail
948  't.email',
949  );
950  //Social media
951  // foreach ($socialnetworks as $key => $value) {
952  // if ($value['active']) {
953  // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
954  // }
955  // }
956 
957  if (!$sortorder) {
958  $sortorder = "ASC";
959  }
960  if (!$sortfield) {
961  $sortfield = "t.lastname";
962  }
963 
964  if (!empty($conf->clicktodial->enabled)) {
965  $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
966  }
967 
968 
969  $contactstatic = new Contact($db);
970 
971  $extrafields->fetch_name_optionals_label($contactstatic->table_element);
972 
973  $contactstatic->fields = array(
974  'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
975  'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>2, 'index'=>1, 'position'=>20),
976  'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>3, 'index'=>1, 'position'=>30),
977  'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>4, 'index'=>1, 'position'=>40),
978  '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))),
979  );
980 
981  // Definition of fields for list
982  $arrayfields = array(
983  '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),
984  't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10),
985  't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20),
986  '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),
987  'sc.role'=>array('label'=>"ContactByDefaultFor", 'checked'=>1, 'position'=>40),
988  't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'),
989  );
990  // Extra fields
991  if (!empty($extrafields->attributes[$contactstatic->table_element]['label']) && is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) {
992  foreach ($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val) {
993  if (!empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
994  $arrayfields["ef.".$key] = array(
995  'label'=>$extrafields->attributes[$contactstatic->table_element]['label'][$key],
996  'checked'=>(($extrafields->attributes[$contactstatic->table_element]['list'][$key] < 0) ? 0 : 1),
997  'position'=>1000 + $extrafields->attributes[$contactstatic->table_element]['pos'][$key],
998  'enabled'=>(abs($extrafields->attributes[$contactstatic->table_element]['list'][$key]) != 3 && $extrafields->attributes[$contactstatic->table_element]['perms'][$key]));
999  }
1000  }
1001  }
1002 
1003  // Initialize array of search criterias
1004  $search = array();
1005  foreach ($arrayfields as $key => $val) {
1006  $queryName = 'search_'.substr($key, 2);
1007  if (GETPOST($queryName, 'alpha')) {
1008  $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1009  }
1010  }
1011  $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1012 
1013  // Purge search criteria
1014  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
1015  $search_status = '';
1016  $search_name = '';
1017  $search_roles = array();
1018  $search_address = '';
1019  $search_poste = '';
1020  $search = array();
1021  $search_array_options = array();
1022 
1023  foreach ($contactstatic->fields as $key => $val) {
1024  $search[$key] = '';
1025  }
1026  }
1027 
1028  $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1029  $arrayfields = dol_sort_array($arrayfields, 'position');
1030 
1031  $newcardbutton = '';
1032  if ($user->rights->societe->contact->creer) {
1033  $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1034  $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
1035  }
1036 
1037  print "\n";
1038 
1039  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1040  print load_fiche_titre($title, $newcardbutton, '');
1041 
1042  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
1043  print '<input type="hidden" name="token" value="'.newToken().'">';
1044  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1045  print '<input type="hidden" name="socid" value="'.$object->id.'">';
1046  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1047  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1048  print '<input type="hidden" name="page" value="'.$page.'">';
1049 
1050  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1051  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1052  //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
1053 
1054  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1055  print "\n".'<table class="tagtable liste">'."\n";
1056 
1057  $param = "socid=".urlencode($object->id);
1058  if ($search_status != '') {
1059  $param .= '&search_status='.urlencode($search_status);
1060  }
1061  if (count($search_roles) > 0) {
1062  $param .= implode('&search_roles[]=', $search_roles);
1063  }
1064  if ($search_name != '') {
1065  $param .= '&search_name='.urlencode($search_name);
1066  }
1067  if ($search_poste != '') {
1068  $param .= '&search_poste='.urlencode($search_poste);
1069  }
1070  if ($search_address != '') {
1071  $param .= '&search_address='.urlencode($search_address);
1072  }
1073  if ($optioncss != '') {
1074  $param .= '&optioncss='.urlencode($optioncss);
1075  }
1076 
1077  // Add $param from extra fields
1078  $extrafieldsobjectkey = $contactstatic->table_element;
1079  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1080 
1081  $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste, t.phone as phone_pro, t.phone_mobile, t.phone_perso, t.fax, t.email, t.socialnetworks, t.statut, t.photo,";
1082  $sql .= " t.civility as civility_id, t.address, t.zip, t.town";
1083  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
1084  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1085  $sql .= " WHERE t.fk_soc = ".((int) $object->id);
1086  if ($search_status != '' && $search_status != '-1') {
1087  $sql .= " AND t.statut = ".((int) $search_status);
1088  }
1089  if ($search_name) {
1090  $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1091  }
1092  if ($search_poste) {
1093  $sql .= natural_search('t.poste', $search_poste);
1094  }
1095  if ($search_address) {
1096  $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1097  }
1098  if (count($search_roles) > 0) {
1099  $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))."))";
1100  }
1101  // Add where from extra fields
1102  $extrafieldsobjectkey = $contactstatic->table_element;
1103  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1104  // Add where from hooks
1105  $parameters = array('socid' => $object->id);
1106  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1107  $sql .= $hookmanager->resPrint;
1108  if ($sortfield == "t.name") {
1109  $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1110  } else {
1111  $sql .= " ORDER BY $sortfield $sortorder";
1112  }
1113 
1114  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1115  $result = $db->query($sql);
1116  if (!$result) {
1117  dol_print_error($db);
1118  }
1119 
1120  $num = $db->num_rows($result);
1121 
1122  // Fields title search
1123  // --------------------------------------------------------------------
1124  print '<tr class="liste_titre">';
1125  foreach ($contactstatic->fields as $key => $val) {
1126  $align = '';
1127  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1128  $align .= ($align ? ' ' : '').'center';
1129  }
1130  if (in_array($val['type'], array('timestamp'))) {
1131  $align .= ($align ? ' ' : '').'nowrap';
1132  }
1133  if ($key == 'status' || $key == 'statut') {
1134  $align .= ($align ? ' ' : '').'center';
1135  }
1136  if (!empty($arrayfields['t.'.$key]['checked']) || !empty($arrayfields['sc.'.$key]['checked'])) {
1137  print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
1138  if (in_array($key, array('statut'))) {
1139  print $form->selectarray('search_status', array('-1'=>'', '0'=>$contactstatic->LibStatut(0, 1), '1'=>$contactstatic->LibStatut(1, 1)), $search_status);
1140  } elseif (in_array($key, array('role'))) {
1141  print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1142  } else {
1143  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.(!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '').'">';
1144  }
1145  print '</td>';
1146  }
1147  }
1148  if ($showuserlogin) {
1149  print '<td></td>';
1150  }
1151  // Extra fields
1152  $extrafieldsobjectkey = $contactstatic->table_element;
1153  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1154 
1155  // Fields from hook
1156  $parameters = array('arrayfields'=>$arrayfields);
1157  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1158  print $hookmanager->resPrint;
1159  // Action column
1160  print '<td class="liste_titre" align="right">';
1161  print $form->showFilterButtons();
1162  print '</td>';
1163  print '</tr>'."\n";
1164 
1165 
1166  // Fields title label
1167  // --------------------------------------------------------------------
1168  print '<tr class="liste_titre">';
1169  foreach ($contactstatic->fields as $key => $val) {
1170  $align = '';
1171  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1172  $align .= ($align ? ' ' : '').'center';
1173  }
1174  if (in_array($val['type'], array('timestamp'))) {
1175  $align .= ($align ? ' ' : '').'nowrap';
1176  }
1177  if ($key == 'status' || $key == 'statut') {
1178  $align .= ($align ? ' ' : '').'center';
1179  }
1180  if (!empty($arrayfields['t.'.$key]['checked'])) {
1181  print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1182  }
1183  if ($key == 'role') {
1184  $align .= ($align ? ' ' : '').'left';
1185  }
1186  if (!empty($arrayfields['sc.'.$key]['checked'])) {
1187  print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1188  }
1189  }
1190  if ($showuserlogin) {
1191  print '<td>'.$langs->trans("DolibarrLogin").'</td>';
1192  }
1193  // Extra fields
1194  $extrafieldsobjectkey = $contactstatic->table_element;
1195  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1196  // Hook fields
1197  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1198  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1199  print $hookmanager->resPrint;
1200  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n";
1201  print '</tr>'."\n";
1202 
1203  $i = -1;
1204 
1205  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1206  $i = 0;
1207 
1208  while ($i < $num) {
1209  $obj = $db->fetch_object($result);
1210 
1211  $contactstatic->id = $obj->rowid;
1212  $contactstatic->ref = $obj->rowid;
1213  $contactstatic->statut = $obj->statut;
1214  $contactstatic->lastname = $obj->lastname;
1215  $contactstatic->firstname = $obj->firstname;
1216  $contactstatic->civility_id = $obj->civility_id;
1217  $contactstatic->civility_code = $obj->civility_id;
1218  $contactstatic->poste = $obj->poste;
1219  $contactstatic->address = $obj->address;
1220  $contactstatic->zip = $obj->zip;
1221  $contactstatic->town = $obj->town;
1222  $contactstatic->phone_pro = $obj->phone_pro;
1223  $contactstatic->phone_mobile = $obj->phone_mobile;
1224  $contactstatic->phone_perso = $obj->phone_perso;
1225  $contactstatic->email = $obj->email;
1226  $contactstatic->socialnetworks = $obj->socialnetworks;
1227  $contactstatic->photo = $obj->photo;
1228  $contactstatic->entity = $obj->entity;
1229 
1230  $country_code = getCountry($obj->country_id, 2);
1231  $contactstatic->country_code = $country_code;
1232 
1233  $contactstatic->setGenderFromCivility();
1234  $contactstatic->fetch_optionals();
1235 
1236  $resultRole = $contactstatic->fetchRoles();
1237  if ($resultRole < 0) {
1238  setEventMessages(null, $contactstatic->errors, 'errors');
1239  }
1240 
1241  if (is_array($contactstatic->array_options)) {
1242  foreach ($contactstatic->array_options as $key => $val) {
1243  $obj->$key = $val;
1244  }
1245  }
1246 
1247  print '<tr class="oddeven">';
1248 
1249  // ID
1250  if (!empty($arrayfields['t.rowid']['checked'])) {
1251  print '<td>';
1252  print $contactstatic->id;
1253  print '</td>';
1254  }
1255 
1256  // Photo - Name
1257  if (!empty($arrayfields['t.name']['checked'])) {
1258  print '<td>';
1259  print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 1);
1260  print $contactstatic->getNomUrl(0, '', 0, '&backtopage='.urlencode($backtopage));
1261  print '</td>';
1262  }
1263 
1264  // Job position
1265  if (!empty($arrayfields['t.poste']['checked'])) {
1266  print '<td>';
1267  if ($obj->poste) {
1268  print $obj->poste;
1269  }
1270  print '</td>';
1271  }
1272 
1273  // Address - Phone - Email
1274  if (!empty($arrayfields['t.address']['checked'])) {
1275  print '<td>';
1276  print $contactstatic->getBannerAddress('contact', $object);
1277  print '</td>';
1278  }
1279 
1280  // Role
1281  if (!empty($arrayfields['sc.role']['checked'])) {
1282  print '<td>';
1283  print $formcompany->showRoles("roles", $contactstatic, 'view');
1284  print '</td>';
1285  }
1286 
1287  // Status
1288  if (!empty($arrayfields['t.statut']['checked'])) {
1289  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1290  }
1291 
1292  if ($showuserlogin) {
1293  print '<td>';
1294  $tmpuser= new User($db);
1295  $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1296  if ($resfetch > 0) {
1297  print $tmpuser->getNomUrl(1, '', 0, 0, 24, 1);
1298  }
1299  print '</td>';
1300  }
1301 
1302  // Extra fields
1303  $extrafieldsobjectkey = $contactstatic->table_element;
1304  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1305 
1306  // Actions
1307  print '<td align="right">';
1308 
1309  // Add to agenda
1310  if (isModEnabled('agenda')&& $user->rights->agenda->myactions->create) {
1311  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1312  print img_object($langs->trans("Event"), "action");
1313  print '</a> &nbsp; ';
1314  }
1315 
1316  // Edit
1317  if ($user->rights->societe->contact->creer) {
1318  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1319  print img_edit();
1320  print '</a>';
1321  }
1322 
1323  print '</td>';
1324 
1325  print "</tr>\n";
1326  $i++;
1327  }
1328  } else {
1329  $colspan = 1;
1330  foreach ($arrayfields as $key => $val) {
1331  if (!empty($val['checked'])) {
1332  $colspan++;
1333  }
1334  }
1335  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1336  }
1337  print "\n</table>\n";
1338  print '</div>';
1339 
1340  print '</form>'."\n";
1341 
1342  return $i;
1343 }
1344 
1345 
1358 function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '')
1359 {
1360  global $user, $conf;
1361 
1362  $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1363 
1364  if ($noprint) {
1365  return $out;
1366  } else {
1367  print $out;
1368  }
1369 }
1370 
1389 function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1390 {
1391  global $user, $conf;
1392  global $form;
1393  global $param, $massactionbutton;
1394 
1395  $start_year = GETPOST('dateevent_startyear', 'int');
1396  $start_month = GETPOST('dateevent_startmonth', 'int');
1397  $start_day = GETPOST('dateevent_startday', 'int');
1398  $end_year = GETPOST('dateevent_endyear', 'int');
1399  $end_month = GETPOST('dateevent_endmonth', 'int');
1400  $end_day = GETPOST('dateevent_endday', 'int');
1401  $tms_start = '';
1402  $tms_end = '';
1403 
1404  if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1405  $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1406  }
1407  if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1408  $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1409  }
1410  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
1411  $tms_start = '';
1412  $tms_end = '';
1413  }
1414  dol_include_once('/comm/action/class/actioncomm.class.php');
1415 
1416  // Check parameters
1417  if (!is_object($filterobj) && !is_object($objcon)) {
1418  dol_print_error('', 'BadParameter');
1419  }
1420 
1421  $out = '';
1422  $histo = array();
1423  $numaction = 0;
1424  $now = dol_now('tzuser');
1425 
1426  // Open DSI -- Fix order by -- Begin
1427  $sortfield_list = explode(',', $sortfield);
1428  $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1429  $sortfield_new_list = array();
1430  foreach ($sortfield_list as $sortfield_value) {
1431  $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1432  }
1433  $sortfield_new = implode(',', $sortfield_new_list);
1434 
1435  $sql = '';
1436 
1437  if (isModEnabled('agenda')) {
1438  // Recherche histo sur actioncomm
1439  if (is_object($objcon) && $objcon->id > 0) {
1440  $sql = "SELECT DISTINCT a.id, a.label as label,";
1441  } else {
1442  $sql = "SELECT a.id, a.label as label,";
1443  }
1444  $sql .= " a.datep as dp,";
1445  $sql .= " a.datep2 as dp2,";
1446  $sql .= " a.percent as percent, 'action' as type,";
1447  $sql .= " a.fk_element, a.elementtype,";
1448  $sql .= " a.fk_contact,";
1449  $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1450  $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";
1451  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1452  $sql .= ", sp.lastname, sp.firstname";
1453  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1454  /* Nothing */
1455  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1456  /* Nothing */
1457  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1458  $sql .= ", m.lastname, m.firstname";
1459  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1460  $sql .= ", o.ref";
1461  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1462  $sql .= ", o.ref";
1463  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1464  $sql .= ", o.ref";
1465  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1466  $sql .= ", o.ref";
1467  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1468  $sql .= ", o.ref";
1469  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1470  if (!empty($filterobj->fields['ref'])) {
1471  $sql .= ", o.ref";
1472  } elseif (!empty($filterobj->fields['label'])) {
1473  $sql .= ", o.label";
1474  }
1475  }
1476 
1477  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1478  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1479  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1480 
1481  $force_filter_contact = false;
1482  if (is_object($objcon) && $objcon->id > 0) {
1483  $force_filter_contact = true;
1484  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1485  $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
1486  }
1487 
1488  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1489  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1490  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1491  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1492  $sql .= " ON er.resource_type = 'dolresource'";
1493  $sql .= " AND er.element_id = a.id";
1494  $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1495  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1496  /* Nothing */
1497  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1498  $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1499  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1500  $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1501  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1502  $sql .= ", ".MAIN_DB_PREFIX."product as o";
1503  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1504  $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1505  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1506  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1507  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1508  $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1509  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && (is_array($filterobj->fields['ref']) || is_array($filterobj->fields['label'])) && $filterobj->table_element && $filterobj->element) {
1510  $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1511  }
1512 
1513  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1514  if ($force_filter_contact === false) {
1515  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1516  $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1517  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1518  /* Nothing */
1519  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1520  $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1521  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1522  $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1523  if ($filterobj->id) {
1524  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1525  }
1526  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1527  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1528  if ($filterobj->id) {
1529  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1530  }
1531  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1532  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1533  if ($filterobj->id) {
1534  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1535  }
1536  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1537  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1538  if ($filterobj->id) {
1539  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1540  }
1541  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1542  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1543  if ($filterobj->id) {
1544  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1545  }
1546  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1547  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1548  if ($filterobj->id) {
1549  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1550  }
1551  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && (is_array($filterobj->fields['ref']) || is_array($filterobj->fields['label'])) && $filterobj->table_element && $filterobj->element) {
1552  // Generic case
1553  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1554  if ($filterobj->id) {
1555  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1556  }
1557  }
1558  }
1559 
1560  if (!empty($tms_start) && !empty($tms_end)) {
1561  $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)."'))";
1562  } elseif (empty($tms_start) && !empty($tms_end)) {
1563  $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1564  } elseif (!empty($tms_start) && empty($tms_end)) {
1565  $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1566  }
1567 
1568  if (is_array($actioncode) && !empty($actioncode)) {
1569  $sql .= ' AND (';
1570  foreach ($actioncode as $key => $code) {
1571  if ($key != 0) {
1572  $sql .= "OR (";
1573  }
1574  if (!empty($code)) {
1575  addEventTypeSQL($sql, $code);
1576  }
1577  if ($key != 0) {
1578  $sql .= ")";
1579  }
1580  }
1581  $sql .= ')';
1582  } elseif (!empty($actioncode)) {
1583  addEventTypeSQL($sql, $actioncode);
1584  }
1585 
1586  addOtherFilterSQL($sql, $donetodo, $now, $filters);
1587 
1588  if (is_array($actioncode)) {
1589  foreach ($actioncode as $code) {
1590  $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1591  if (!empty($sql2)) {
1592  if (!empty($sql)) {
1593  $sql = $sql." UNION ".$sql2;
1594  } elseif (empty($sql)) {
1595  $sql = $sql2;
1596  }
1597  break;
1598  }
1599  }
1600  } else {
1601  $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
1602  if (!empty($sql) && !empty($sql2)) {
1603  $sql = $sql." UNION ".$sql2;
1604  } elseif (empty($sql) && !empty($sql2)) {
1605  $sql = $sql2;
1606  }
1607  }
1608  }
1609 
1610  //TODO Add limit in nb of results
1611  if ($sql) {
1612  $sql .= $db->order($sortfield_new, $sortorder);
1613  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1614  $resql = $db->query($sql);
1615  if ($resql) {
1616  $i = 0;
1617  $num = $db->num_rows($resql);
1618 
1619  while ($i < $num) {
1620  $obj = $db->fetch_object($resql);
1621 
1622  if ($obj->type == 'action') {
1623  $contactaction = new ActionComm($db);
1624  $contactaction->id = $obj->id;
1625  $result = $contactaction->fetchResources();
1626  if ($result < 0) {
1627  dol_print_error($db);
1628  setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
1629  }
1630 
1631  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1632  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1633  $tododone = '';
1634  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
1635  $tododone = 'todo';
1636  }
1637 
1638  $histo[$numaction] = array(
1639  'type'=>$obj->type,
1640  'tododone'=>$tododone,
1641  'id'=>$obj->id,
1642  'datestart'=>$db->jdate($obj->dp),
1643  'dateend'=>$db->jdate($obj->dp2),
1644  'note'=>$obj->label,
1645  'percent'=>$obj->percent,
1646 
1647  'userid'=>$obj->user_id,
1648  'login'=>$obj->user_login,
1649  'userfirstname'=>$obj->user_firstname,
1650  'userlastname'=>$obj->user_lastname,
1651  'userphoto'=>$obj->user_photo,
1652 
1653  'contact_id'=>$obj->fk_contact,
1654  'socpeopleassigned' => $contactaction->socpeopleassigned,
1655  'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
1656  'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
1657  'fk_element'=>$obj->fk_element,
1658  'elementtype'=>$obj->elementtype,
1659  // Type of event
1660  'acode'=>$obj->acode,
1661  'alabel'=>$obj->alabel,
1662  'libelle'=>$obj->alabel, // deprecated
1663  'apicto'=>$obj->apicto
1664  );
1665  } else {
1666  $histo[$numaction] = array(
1667  'type'=>$obj->type,
1668  'tododone'=>'done',
1669  'id'=>$obj->id,
1670  'datestart'=>$db->jdate($obj->dp),
1671  'dateend'=>$db->jdate($obj->dp2),
1672  'note'=>$obj->label,
1673  'percent'=>$obj->percent,
1674  'acode'=>$obj->acode,
1675 
1676  'userid'=>$obj->user_id,
1677  'login'=>$obj->user_login,
1678  'userfirstname'=>$obj->user_firstname,
1679  'userlastname'=>$obj->user_lastname,
1680  'userphoto'=>$obj->user_photo
1681  );
1682  }
1683 
1684  $numaction++;
1685  $i++;
1686  }
1687  } else {
1688  dol_print_error($db);
1689  }
1690  }
1691 
1692  if (isModEnabled('agenda')|| (isModEnabled('mailing') && !empty($objcon->email))) {
1693  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
1694 
1695  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1696  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1697  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1698  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1699 
1700  $formactions = new FormActions($db);
1701 
1702  $actionstatic = new ActionComm($db);
1703  $userstatic = new User($db);
1704  $userlinkcache = array();
1705  $contactstatic = new Contact($db);
1706  $elementlinkcache = array();
1707 
1708  $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1709  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1710  if ($objcon && get_class($objcon) == 'Contact' &&
1711  (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
1712  $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
1713  } else {
1714  $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1715  }
1716  if ($filterobj && get_class($filterobj) == 'Societe') {
1717  $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1718  }
1719 
1720  $out .= "\n";
1721 
1722  $out .= '<div class="div-table-responsive-no-min">';
1723  $out .= '<table class="noborder centpercent">';
1724 
1725  $out .= '<tr class="liste_titre">';
1726  if ($donetodo) {
1727  $out .= '<td class="liste_titre"></td>';
1728  }
1729  $out .= '<td class="liste_titre"></td>';
1730  $out .= '<td class="liste_titre"></td>';
1731  $out .= '<td class="liste_titre">';
1732  $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, 'minwidth200');
1733  $out .= '</td>';
1734  $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1735  $out .= '<td class="liste_titre center">';
1736  $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
1737  $out .= '</td>';
1738  $out .= '<td class="liste_titre"></td>';
1739  $out .= '<td class="liste_titre"></td>';
1740  $out .= '<td class="liste_titre"></td>';
1741  // Action column
1742  $out .= '<td class="liste_titre" align="middle">';
1743  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1744  $out .= $searchpicto;
1745  $out .= '</td>';
1746  $out .= '</tr>';
1747 
1748  $out .= '<tr class="liste_titre">';
1749  if ($donetodo) {
1750  $tmp = '';
1751  if (get_class($filterobj) == 'Societe') {
1752  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
1753  }
1754  $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1755  $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1756  $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1757  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1758  if (get_class($filterobj) == 'Societe') {
1759  $tmp .= '</a>';
1760  }
1761  $out .= getTitleFieldOfList($tmp);
1762  }
1763  $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1764  $out .= getTitleFieldOfList("Owner");
1765  $out .= getTitleFieldOfList("Type");
1766  $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1767  $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
1768  $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1769  $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
1770  $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
1771  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1772  $out .= '</tr>';
1773 
1774  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
1775  $caction = new CActionComm($db);
1776  $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
1777 
1778  foreach ($histo as $key => $value) {
1779  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1780 
1781  $actionstatic->type_picto = $histo[$key]['apicto'];
1782  $actionstatic->type_code = $histo[$key]['acode'];
1783 
1784  $out .= '<tr class="oddeven">';
1785 
1786  // Done or todo
1787  if ($donetodo) {
1788  $out .= '<td class="nowrap">';
1789  $out .= '</td>';
1790  }
1791 
1792  // Ref
1793  $out .= '<td class="nowraponall">';
1794  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
1795  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
1796  $out .= $histo[$key]['id'];
1797  $out .= '</a>';
1798  } else {
1799  $out .= $actionstatic->getNomUrl(1, -1);
1800  }
1801  $out .= '</td>';
1802 
1803  // Author of event
1804  $out .= '<td class="tdoverflowmax150">';
1805  //$userstatic->id=$histo[$key]['userid'];
1806  //$userstatic->login=$histo[$key]['login'];
1807  //$out.=$userstatic->getLoginUrl(1);
1808  if ($histo[$key]['userid'] > 0) {
1809  if (isset($userlinkcache[$histo[$key]['userid']])) {
1810  $link = $userlinkcache[$histo[$key]['userid']];
1811  } else {
1812  $userstatic->fetch($histo[$key]['userid']);
1813  $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
1814  $userlinkcache[$histo[$key]['userid']] = $link;
1815  }
1816  $out .= $link;
1817  }
1818  $out .= '</td>';
1819 
1820  // Type
1821  $labeltype = $actionstatic->type_code;
1822  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
1823  $labeltype = 'AC_OTH';
1824  }
1825  if ($actionstatic->type_code == 'AC_OTH' && $actionstatic->code == 'TICKET_MSG') {
1826  $labeltype = $langs->trans("Message");
1827  } else {
1828  if (!empty($arraylist[$labeltype])) {
1829  $labeltype = $arraylist[$labeltype];
1830  }
1831  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
1832  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
1833  }
1834  }
1835  $out .= '<td class="tdoverflowmax150" title="'.$labeltype.'">';
1836  $out .= $actionstatic->getTypePicto();
1837  $out .= $labeltype;
1838  $out .= '</td>';
1839 
1840  // Title/Label of event
1841  $out .= '<td class="tdoverflowmax300"';
1842  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
1843  $transcode = $langs->trans("Action".$histo[$key]['acode']);
1844  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
1845  //$actionstatic->libelle=$libelle;
1846  $libelle = $histo[$key]['note'];
1847  $actionstatic->id = $histo[$key]['id'];
1848  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
1849  $out .= dol_trunc($libelle, 120);
1850  }
1851  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
1852  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
1853  $transcode = $langs->trans("Action".$histo[$key]['acode']);
1854  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
1855  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
1856  $out .= dol_trunc($libelle, 120);
1857  }
1858  $out .= '</td>';
1859 
1860  // Date
1861  $out .= '<td class="center nowrap">';
1862  $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
1863  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
1864  $tmpa = dol_getdate($histo[$key]['datestart'], true);
1865  $tmpb = dol_getdate($histo[$key]['dateend'], true);
1866  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1867  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
1868  } else {
1869  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
1870  }
1871  }
1872  $late = 0;
1873  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1874  $late = 1;
1875  }
1876  if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1877  $late = 1;
1878  }
1879  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
1880  $late = 1;
1881  }
1882  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1883  $late = 1;
1884  }
1885  if ($late) {
1886  $out .= img_warning($langs->trans("Late")).' ';
1887  }
1888  $out .= "</td>\n";
1889 
1890  // Title of event
1891  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
1892 
1893  // Linked object
1894  $out .= '<td class="nowraponall">';
1895  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
1896  if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
1897  $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
1898  } else {
1899  if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
1900  $elementlinkcache[$histo[$key]['elementtype']] = array();
1901  }
1902  $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
1903  $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
1904  }
1905  $out .= $link;
1906  } else {
1907  $out .= '&nbsp;';
1908  }
1909  $out .= '</td>';
1910 
1911  // Contact(s) for action
1912  if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
1913  $out .= '<td class="valignmiddle">';
1914  $contact = new Contact($db);
1915  foreach ($histo[$key]['socpeopleassigned'] as $cid => $value) {
1916  $result = $contact->fetch($cid);
1917 
1918  if ($result < 0) {
1919  dol_print_error($db, $contact->error);
1920  }
1921 
1922  if ($result > 0) {
1923  $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
1924  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
1925  if (!empty($contact->phone_pro)) {
1926  $out .= '('.dol_print_phone($contact->phone_pro).')';
1927  }
1928  }
1929  $out .= '<div class="paddingright"></div>';
1930  }
1931  }
1932  $out .= '</td>';
1933  } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
1934  $contactstatic->lastname = $histo[$key]['lastname'];
1935  $contactstatic->firstname = $histo[$key]['firstname'];
1936  $contactstatic->id = $histo[$key]['contact_id'];
1937  $contactstatic->photo = $histo[$key]['contact_photo'];
1938  $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
1939  } else {
1940  $out .= '<td>&nbsp;</td>';
1941  }
1942 
1943  // Status
1944  $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
1945 
1946  // Actions
1947  $out .= '<td></td>';
1948 
1949  $out .= "</tr>\n";
1950  $i++;
1951  }
1952  $out .= "</table>\n";
1953  $out .= "</div>\n";
1954 
1955  $out .= '</form>';
1956  }
1957 
1958  if ($noprint) {
1959  return $out;
1960  } else {
1961  print $out;
1962  }
1963 }
1964 
1974 function show_subsidiaries($conf, $langs, $db, $object)
1975 {
1976  global $user;
1977 
1978  $i = -1;
1979 
1980  $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";
1981  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
1982  $sql .= " WHERE s.parent = ".((int) $object->id);
1983  $sql .= " AND s.entity IN (".getEntity('societe').")";
1984  $sql .= " ORDER BY s.nom";
1985 
1986  $result = $db->query($sql);
1987  $num = $db->num_rows($result);
1988 
1989  if ($num) {
1990  $socstatic = new Societe($db);
1991 
1992  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
1993 
1994  print "\n".'<div class="div-table-responsive-no-min">'."\n";
1995  print '<table class="noborder centpercent">'."\n";
1996 
1997  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
1998  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
1999  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2000  print "<td>&nbsp;</td>";
2001  print "</tr>";
2002 
2003  $i = 0;
2004 
2005  while ($i < $num) {
2006  $obj = $db->fetch_object($result);
2007 
2008  $socstatic->id = $obj->rowid;
2009  $socstatic->name = $obj->name;
2010  $socstatic->name_alias = $obj->name_alias;
2011  $socstatic->email = $obj->email;
2012  $socstatic->code_client = $obj->code_client;
2013  $socstatic->code_fournisseur = $obj->code_client;
2014  $socstatic->code_compta = $obj->code_compta;
2015  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2016  $socstatic->email = $obj->email;
2017  $socstatic->canvas = $obj->canvas;
2018  $socstatic->client = $obj->client;
2019  $socstatic->fournisseur = $obj->fournisseur;
2020 
2021  print '<tr class="oddeven">';
2022 
2023  print '<td class="tdoverflowmax150">';
2024  print $socstatic->getNomUrl(1);
2025  print '</td>';
2026 
2027  print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2028  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2029  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2030  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2031 
2032  print '<td class="center">';
2033  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2034  print img_edit();
2035  print '</a></td>';
2036 
2037  print "</tr>\n";
2038  $i++;
2039  }
2040  print "\n</table>\n";
2041  print '</div>'."\n";
2042  }
2043 
2044  print "<br>\n";
2045 
2046  return $i;
2047 }
2056 function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2057 {
2058  global $conf, $db;
2059  // Condition on actioncode
2060 
2061  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
2062  if ($actioncode == 'AC_NON_AUTO') {
2063  $sql .= " $sqlANDOR c.type != 'systemauto'";
2064  } elseif ($actioncode == 'AC_ALL_AUTO') {
2065  $sql .= " $sqlANDOR c.type = 'systemauto'";
2066  } else {
2067  if ($actioncode == 'AC_OTH') {
2068  $sql .= " $sqlANDOR c.type != 'systemauto'";
2069  } elseif ($actioncode == 'AC_OTH_AUTO') {
2070  $sql .= " $sqlANDOR c.type = 'systemauto'";
2071  }
2072  }
2073  } else {
2074  if ($actioncode == 'AC_NON_AUTO') {
2075  $sql .= " $sqlANDOR c.type != 'systemauto'";
2076  } elseif ($actioncode == 'AC_ALL_AUTO') {
2077  $sql .= " $sqlANDOR c.type = 'systemauto'";
2078  } else {
2079  $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2080  }
2081  }
2082 
2083  return $sql;
2084 }
2085 
2095 function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2096 {
2097  global $conf, $db;
2098  // Condition on actioncode
2099 
2100  if ($donetodo == 'todo') {
2101  $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2102  } elseif ($donetodo == 'done') {
2103  $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2104  }
2105  if (is_array($filters) && $filters['search_agenda_label']) {
2106  $sql .= natural_search('a.label', $filters['search_agenda_label']);
2107  }
2108 
2109  return $sql;
2110 }
2111 
2120 function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2121 {
2122  global $conf, $langs, $db;
2123  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2124  if (isModEnabled('mailing') && !empty($objcon->email)
2125  && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2126  $langs->load("mails");
2127 
2128  $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";
2129  $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2130  $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2131  $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
2132  if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2133  $sql2 .= ", '' as lastname, '' as firstname";
2134  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2135  $sql2 .= ", '' as lastname, '' as firstname";
2136  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2137  $sql2 .= ", '' as ref";
2138  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2139  $sql2 .= ", '' as ref";
2140  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2141  $sql2 .= ", '' as ref";
2142  }
2143  $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2144  $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2145  $sql2 .= " AND mc.statut = 1";
2146  $sql2 .= " AND u.rowid = m.fk_user_valid";
2147  $sql2 .= " AND mc.fk_mailing=m.rowid";
2148  return $sql2;
2149  }
2150 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
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:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
dolGetElementUrl
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
Definition: functions2.lib.php:2113
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:3805
Project
Class to manage projects.
Definition: project.class.php:35
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
dol_getcache
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:135
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:5049
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_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:4844
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
SocieteAccount
Class for SocieteAccount.
Definition: societeaccount.class.php:35
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
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:1033
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
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:1358
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3026
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:2514
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:569
show_subsidiaries
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
Definition: company.lib.php:1974
addOtherFilterSQL
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
Definition: company.lib.php:2095
getCountriesInEEC
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
Definition: company.lib.php:716
$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:178
CActionComm
Class to manage different types of events.
Definition: cactioncomm.class.php:29
currency_name
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
Definition: company.lib.php:639
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:10605
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:1389
show_contacts
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
Definition: company.lib.php:907
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8108
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
show_projects
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
Definition: company.lib.php:778
addMailingEventTypeSQL
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
Definition: company.lib.php:2120
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:683
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
societe_prepare_head2
societe_prepare_head2($object)
Return array of tabs to used on page.
Definition: company.lib.php:413
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
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
User
Class to manage Dolibarr users.
Definition: user.class.php:44
societe_admin_prepare_head
societe_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: company.lib.php:439
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
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:9420
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
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:5541
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:489
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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:2757
addEventTypeSQL
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
Definition: company.lib.php:2056
isInEEC
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
Definition: company.lib.php:753