dolibarr  17.0.3
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)) || 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('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || 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')&& (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->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 
665 function currency_name($code_iso, $withcode = '', $outputlangs = null)
666 {
667  global $langs, $db;
668 
669  if (empty($outputlangs)) {
670  $outputlangs = $langs;
671  }
672 
673  $outputlangs->load("dict");
674 
675  // If there is a translation, we can send immediatly the label
676  if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
677  return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
678  }
679 
680  // If no translation, we read table to get label by default
681  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
682  $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
683 
684  $resql = $db->query($sql);
685  if ($resql) {
686  $num = $db->num_rows($resql);
687 
688  if ($num) {
689  $obj = $db->fetch_object($resql);
690  $label = ($obj->label != '-' ? $obj->label : '');
691  if ($withcode) {
692  return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
693  } else {
694  return $label;
695  }
696  } else {
697  return $code_iso;
698  }
699  }
700  return 'ErrorWhenReadingCurrencyLabel';
701 }
702 
709 function getFormeJuridiqueLabel($code)
710 {
711  global $db, $langs;
712 
713  if (!$code) {
714  return '';
715  }
716 
717  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
718  $sql .= " WHERE code='".$db->escape($code)."'";
719 
720  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
721  $resql = $db->query($sql);
722  if ($resql) {
723  $num = $db->num_rows($resql);
724 
725  if ($num) {
726  $obj = $db->fetch_object($resql);
727  $label = ($obj->libelle != '-' ? $obj->libelle : '');
728  return $label;
729  } else {
730  return $langs->trans("NotDefined");
731  }
732  }
733 }
734 
735 
743 {
744  // List of all country codes that are in europe for european vat rules
745  // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
746  global $conf, $db;
747  $country_code_in_EEC = array();
748 
749  if (!empty($conf->cache['country_code_in_EEC'])) {
750  // Use of cache to reduce number of database requests
751  $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
752  } else {
753  $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
754  $sql .= " WHERE cc.eec = 1";
755 
756  $resql = $db->query($sql);
757  if ($resql) {
758  $num = $db->num_rows($resql);
759  $i = 0;
760  while ($i < $num) {
761  $objp = $db->fetch_object($resql);
762  $country_code_in_EEC[] = $objp->code;
763  $i++;
764  }
765  } else {
766  dol_print_error($db);
767  }
768  $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
769  }
770  return $country_code_in_EEC;
771 }
772 
779 function isInEEC($object)
780 {
781  if (empty($object->country_code)) {
782  return false;
783  }
784 
785  $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
786 
787  //print "dd".$object->country_code;
788  return in_array($object->country_code, $country_code_in_EEC);
789 }
790 
791 
804 function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
805 {
806  global $user, $action, $hookmanager;
807 
808  $i = -1;
809 
810  if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
811  $langs->load("projects");
812 
813  $newcardbutton = '';
814  if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
815  $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));
816  }
817 
818  print "\n";
819  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
820 
821  print '<div class="div-table-responsive">'."\n";
822  print '<table class="noborder centpercent">';
823 
824  $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";
825  $sql .= ", cls.code as opp_status_code";
826  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
827  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
828  $sql .= " WHERE p.fk_soc = ".((int) $object->id);
829  $sql .= " AND p.entity IN (".getEntity('project').")";
830  $sql .= " ORDER BY p.dateo DESC";
831 
832  $result = $db->query($sql);
833  if ($result) {
834  $num = $db->num_rows($result);
835 
836  print '<tr class="liste_titre">';
837  print '<td>'.$langs->trans("Ref").'</td>';
838  print '<td>'.$langs->trans("Name").'</td>';
839  print '<td class="center">'.$langs->trans("DateStart").'</td>';
840  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
841  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
842  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
843  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
844  print '<td class="right">'.$langs->trans("Status").'</td>';
845  print '</tr>';
846 
847  if ($num > 0) {
848  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
849 
850  $projecttmp = new Project($db);
851 
852  $i = 0;
853 
854  while ($i < $num) {
855  $obj = $db->fetch_object($result);
856  $projecttmp->fetch($obj->id);
857 
858  // To verify role of users
859  $userAccess = $projecttmp->restrictedProjectArea($user);
860 
861  if ($user->rights->projet->lire && $userAccess > 0) {
862  print '<tr class="oddeven">';
863 
864  // Ref
865  print '<td class="nowraponall">';
866  print $projecttmp->getNomUrl(1);
867  print '</td>';
868 
869  // Label
870  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
871  // Date start
872  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
873  // Date end
874  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
875  // Opp amount
876  print '<td class="right">';
877  if ($obj->opp_status_code) {
878  print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
879  }
880  print '</td>';
881  // Opp status
882  print '<td class="center">';
883  if ($obj->opp_status_code) {
884  print $langs->trans("OppStatus".$obj->opp_status_code);
885  }
886  print '</td>';
887  // Opp percent
888  print '<td class="right">';
889  if ($obj->opp_percent) {
890  print price($obj->opp_percent, 1, '', 1, 0).'%';
891  }
892  print '</td>';
893  // Status
894  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
895 
896  print '</tr>';
897  }
898  $i++;
899  }
900  } else {
901  print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
902  }
903  $db->free($result);
904  } else {
905  dol_print_error($db);
906  }
907 
908  $parameters = array('sql'=>$sql, 'function'=>'show_projects');
909  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
910  print $hookmanager->resPrint;
911 
912  print "</table>";
913  print '</div>';
914 
915  print "<br>\n";
916  }
917 
918  return $i;
919 }
920 
921 
933 function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
934 {
935  global $user, $conf, $extrafields, $hookmanager;
936  global $contextpage;
937 
938  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
939  $formcompany = new FormCompany($db);
940  $form = new Form($db);
941 
942  $optioncss = GETPOST('optioncss', 'alpha');
943  $sortfield = GETPOST('sortfield', 'aZ09comma');
944  $sortorder = GETPOST('sortorder', 'aZ09comma');
945  $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
946 
947  $search_status = GETPOST("search_status", 'int');
948  if ($search_status == '') {
949  $search_status = 1; // always display active customer first
950  }
951 
952  $search_rowid = GETPOST("search_rowid", 'int');
953  $search_name = GETPOST("search_name", 'alpha');
954  $search_address = GETPOST("search_address", 'alpha');
955  $search_poste = GETPOST("search_poste", 'alpha');
956  $search_note_private = GETPOST('search_note_private', 'alphanohtml');
957  $search_roles = GETPOST("search_roles", 'array');
958 
959  $socialnetworks = getArrayOfSocialNetworks();
960 
961  $searchAddressPhoneDBFields = array(
962  //Address
963  't.address',
964  't.zip',
965  't.town',
966 
967  //Phone
968  't.phone',
969  't.phone_perso',
970  't.phone_mobile',
971 
972  //Fax
973  't.fax',
974 
975  //E-mail
976  't.email',
977  );
978  //Social media
979  // foreach ($socialnetworks as $key => $value) {
980  // if ($value['active']) {
981  // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
982  // }
983  // }
984 
985  if (!$sortorder) {
986  $sortorder = "ASC";
987  }
988  if (!$sortfield) {
989  $sortfield = "t.lastname";
990  }
991 
992  if (isModEnabled('clicktodial')) {
993  $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
994  }
995 
996 
997  $contactstatic = new Contact($db);
998 
999  $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1000 
1001  $contactstatic->fields = array(
1002  '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),
1003  'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
1004  'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>2, 'index'=>1, 'position'=>20),
1005  'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>3, 'index'=>1, 'position'=>30),
1006  'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible'=>3, 'position'=>35),
1007  'role' =>array('type'=>'checkbox', 'label'=>'Role', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>4, 'index'=>1, 'position'=>40),
1008  '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))),
1009  );
1010 
1011  // Definition of fields for list
1012  $arrayfields = array(
1013  '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),
1014  't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10),
1015  't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20),
1016  '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),
1017  't.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'position'=>35),
1018  'sc.role'=>array('label'=>"ContactByDefaultFor", 'checked'=>1, 'position'=>40),
1019  't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>50, 'class'=>'center'),
1020  );
1021  // Extra fields
1022  if (!empty($extrafields->attributes[$contactstatic->table_element]['label']) && is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) {
1023  foreach ($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val) {
1024  if (!empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
1025  $arrayfields["ef.".$key] = array(
1026  'label'=>$extrafields->attributes[$contactstatic->table_element]['label'][$key],
1027  'checked'=>(($extrafields->attributes[$contactstatic->table_element]['list'][$key] < 0) ? 0 : 1),
1028  'position'=>1000 + $extrafields->attributes[$contactstatic->table_element]['pos'][$key],
1029  'enabled'=>(abs($extrafields->attributes[$contactstatic->table_element]['list'][$key]) != 3 && $extrafields->attributes[$contactstatic->table_element]['perms'][$key]));
1030  }
1031  }
1032  }
1033 
1034  // Initialize array of search criterias
1035  $search = array();
1036  foreach ($arrayfields as $key => $val) {
1037  $queryName = 'search_'.substr($key, 2);
1038  if (GETPOST($queryName, 'alpha')) {
1039  $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1040  }
1041  }
1042  $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1043 
1044  // Purge search criteria
1045  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
1046  $search_rowid = '';
1047  $search_status = '';
1048  $search_name = '';
1049  $search_roles = array();
1050  $search_address = '';
1051  $search_poste = '';
1052  $search_note_private = '';
1053  $search = array();
1054  $search_array_options = array();
1055 
1056  foreach ($contactstatic->fields as $key => $val) {
1057  $search[$key] = '';
1058  }
1059  }
1060 
1061  $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1062  $arrayfields = dol_sort_array($arrayfields, 'position');
1063 
1064  $newcardbutton = '';
1065  if ($user->hasRight('societe', 'contact', 'creer')) {
1066  $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1067  $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
1068  }
1069 
1070  print "\n";
1071 
1072  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1073  print load_fiche_titre($title, $newcardbutton, '');
1074 
1075  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
1076  print '<input type="hidden" name="token" value="'.newToken().'">';
1077  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1078  print '<input type="hidden" name="socid" value="'.$object->id.'">';
1079  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1080  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1081  print '<input type="hidden" name="page" value="'.$page.'">';
1082 
1083  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1084  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1085  //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
1086 
1087  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1088  print "\n".'<table class="tagtable liste">'."\n";
1089 
1090  $param = "socid=".urlencode($object->id);
1091  if ($search_rowid != '') {
1092  $param .= '&search_rowid='.urlencode($search_rowid);
1093  }
1094  if ($search_status != '') {
1095  $param .= '&search_status='.urlencode($search_status);
1096  }
1097  if (count($search_roles) > 0) {
1098  $param .= implode('&search_roles[]=', $search_roles);
1099  }
1100  if ($search_name != '') {
1101  $param .= '&search_name='.urlencode($search_name);
1102  }
1103  if ($search_poste != '') {
1104  $param .= '&search_poste='.urlencode($search_poste);
1105  }
1106  if ($search_address != '') {
1107  $param .= '&search_address='.urlencode($search_address);
1108  }
1109  if ($search_note_private != '') {
1110  $param .= '&search_note_private='.urlencode($search_note_private);
1111  }
1112  if ($optioncss != '') {
1113  $param .= '&optioncss='.urlencode($optioncss);
1114  }
1115 
1116  // Add $param from extra fields
1117  $extrafieldsobjectkey = $contactstatic->table_element;
1118  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1119 
1120  $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, t.fk_soc,";
1121  $sql .= " t.civility as civility_id, t.address, t.zip, t.town";
1122  $sql .= ", t.note_private";
1123  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
1124  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1125  $sql .= " WHERE t.fk_soc = ".((int) $object->id);
1126  $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";
1127  if ($search_rowid) {
1128  $sql .= natural_search('t.rowid', $search_rowid);
1129  }
1130  if ($search_status != '' && $search_status != '-1') {
1131  $sql .= " AND t.statut = ".((int) $search_status);
1132  }
1133  if ($search_name) {
1134  $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1135  }
1136  if ($search_poste) {
1137  $sql .= natural_search('t.poste', $search_poste);
1138  }
1139  if ($search_address) {
1140  $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1141  }
1142  if ($search_note_private) {
1143  $sql .= natural_search('t.note_private', $search_note_private);
1144  }
1145  if (count($search_roles) > 0) {
1146  $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))."))";
1147  }
1148  // Add where from extra fields
1149  $extrafieldsobjectkey = $contactstatic->table_element;
1150  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1151  // Add where from hooks
1152  $parameters = array('socid' => $object->id);
1153  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1154  $sql .= $hookmanager->resPrint;
1155  if ($sortfield == "t.name") {
1156  $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1157  } else {
1158  $sql .= " ORDER BY $sortfield $sortorder";
1159  }
1160 
1161  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1162  $result = $db->query($sql);
1163  if (!$result) {
1164  dol_print_error($db);
1165  }
1166 
1167  $num = $db->num_rows($result);
1168 
1169  // Fields title search
1170  // --------------------------------------------------------------------
1171  print '<tr class="liste_titre">';
1172  foreach ($contactstatic->fields as $key => $val) {
1173  $align = '';
1174  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1175  $align .= ($align ? ' ' : '').'center';
1176  }
1177  if (in_array($val['type'], array('timestamp'))) {
1178  $align .= ($align ? ' ' : '').'nowrap';
1179  }
1180  if ($key == 'status' || $key == 'statut') {
1181  $align .= ($align ? ' ' : '').'center';
1182  }
1183  if (!empty($arrayfields['t.'.$key]['checked']) || !empty($arrayfields['sc.'.$key]['checked'])) {
1184  print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
1185  if (in_array($key, array('statut'))) {
1186  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');
1187  } elseif (in_array($key, array('role'))) {
1188  print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1189  } else {
1190  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.(!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '').'">';
1191  }
1192  print '</td>';
1193  }
1194  }
1195  if ($showuserlogin) {
1196  print '<td class="liste_titre"></td>';
1197  }
1198  // Extra fields
1199  $extrafieldsobjectkey = $contactstatic->table_element;
1200  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1201 
1202  // Fields from hook
1203  $parameters = array('arrayfields'=>$arrayfields);
1204  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1205  print $hookmanager->resPrint;
1206  // Action column
1207  print '<td class="liste_titre" align="right">';
1208  print $form->showFilterButtons();
1209  print '</td>';
1210  print '</tr>'."\n";
1211 
1212 
1213  // Fields title label
1214  // --------------------------------------------------------------------
1215  print '<tr class="liste_titre">';
1216  foreach ($contactstatic->fields as $key => $val) {
1217  $align = '';
1218  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1219  $align .= ($align ? ' ' : '').'center';
1220  }
1221  if (in_array($val['type'], array('timestamp'))) {
1222  $align .= ($align ? ' ' : '').'nowrap';
1223  }
1224  if ($key == 'status' || $key == 'statut') {
1225  $align .= ($align ? ' ' : '').'center';
1226  }
1227  if (!empty($arrayfields['t.'.$key]['checked'])) {
1228  print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1229  }
1230  if ($key == 'role') {
1231  $align .= ($align ? ' ' : '').'left';
1232  }
1233  if (!empty($arrayfields['sc.'.$key]['checked'])) {
1234  print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1235  }
1236  }
1237  if ($showuserlogin) {
1238  print '<th class="wrapcolumntitle liste_titre">'.$langs->trans("DolibarrLogin").'</th>';
1239  }
1240  // Extra fields
1241  $extrafieldsobjectkey = $contactstatic->table_element;
1242  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1243  // Hook fields
1244  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1245  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1246  print $hookmanager->resPrint;
1247  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ')."\n";
1248  print '</tr>'."\n";
1249 
1250  $i = -1;
1251 
1252  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1253  $i = 0;
1254 
1255  while ($i < $num) {
1256  $obj = $db->fetch_object($result);
1257 
1258  $contactstatic->id = $obj->rowid;
1259  $contactstatic->ref = $obj->rowid;
1260  $contactstatic->statut = $obj->statut;
1261  $contactstatic->lastname = $obj->lastname;
1262  $contactstatic->firstname = $obj->firstname;
1263  $contactstatic->civility_id = $obj->civility_id;
1264  $contactstatic->civility_code = $obj->civility_id;
1265  $contactstatic->poste = $obj->poste;
1266  $contactstatic->address = $obj->address;
1267  $contactstatic->zip = $obj->zip;
1268  $contactstatic->town = $obj->town;
1269  $contactstatic->phone_pro = $obj->phone_pro;
1270  $contactstatic->phone_mobile = $obj->phone_mobile;
1271  $contactstatic->phone_perso = $obj->phone_perso;
1272  $contactstatic->email = $obj->email;
1273  $contactstatic->socialnetworks = $obj->socialnetworks;
1274  $contactstatic->photo = $obj->photo;
1275  $contactstatic->fk_soc = $obj->fk_soc;
1276  $contactstatic->entity = $obj->entity;
1277 
1278  $country_code = getCountry($obj->country_id, 2);
1279  $contactstatic->country_code = $country_code;
1280 
1281  $contactstatic->setGenderFromCivility();
1282  $contactstatic->fetch_optionals();
1283 
1284  $resultRole = $contactstatic->fetchRoles();
1285  if ($resultRole < 0) {
1286  setEventMessages(null, $contactstatic->errors, 'errors');
1287  }
1288 
1289  if (is_array($contactstatic->array_options)) {
1290  foreach ($contactstatic->array_options as $key => $val) {
1291  $obj->$key = $val;
1292  }
1293  }
1294 
1295  print '<tr class="oddeven">';
1296 
1297  // ID
1298  if (!empty($arrayfields['t.rowid']['checked'])) {
1299  print '<td>';
1300  print $contactstatic->id;
1301  print '</td>';
1302  }
1303 
1304  // Photo - Name
1305  if (!empty($arrayfields['t.name']['checked'])) {
1306  print '<td>';
1307  print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 1);
1308  print $contactstatic->getNomUrl(0, '', 0, '&backtopage='.urlencode($backtopage));
1309  print '</td>';
1310  }
1311 
1312  // Job position
1313  if (!empty($arrayfields['t.poste']['checked'])) {
1314  print '<td>';
1315  if ($obj->poste) {
1316  print $obj->poste;
1317  }
1318  print '</td>';
1319  }
1320 
1321  // Address - Phone - Email
1322  if (!empty($arrayfields['t.address']['checked'])) {
1323  print '<td>';
1324  print $contactstatic->getBannerAddress('contact', $object);
1325  print '</td>';
1326  }
1327 
1328  // Note private
1329  if (!empty($arrayfields['t.note_private']['checked'])) {
1330  print '<td>';
1331  if ($obj->note_private) {
1332  print dol_string_nohtmltag($obj->note_private);
1333  }
1334  print '</td>';
1335  }
1336 
1337  // Role
1338  if (!empty($arrayfields['sc.role']['checked'])) {
1339  print '<td>';
1340  print $formcompany->showRoles("roles", $contactstatic, 'view');
1341  print '</td>';
1342  }
1343 
1344  // Status
1345  if (!empty($arrayfields['t.statut']['checked'])) {
1346  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1347  }
1348 
1349  if ($showuserlogin) {
1350  print '<td>';
1351  $tmpuser= new User($db);
1352  $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1353  if ($resfetch > 0) {
1354  print $tmpuser->getNomUrl(1, '', 0, 0, 24, 1);
1355  }
1356  print '</td>';
1357  }
1358 
1359  // Extra fields
1360  $extrafieldsobjectkey = $contactstatic->table_element;
1361  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1362 
1363  // Actions
1364  print '<td align="right">';
1365 
1366  // Add to agenda
1367  if (isModEnabled('agenda')&& $user->hasRight('agenda', 'myactions', 'create')) {
1368  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1369  print img_object($langs->trans("Event"), "action");
1370  print '</a> &nbsp; ';
1371  }
1372 
1373  // Edit
1374  if ($user->hasRight('societe', 'contact', 'creer')) {
1375  print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1376  print img_edit();
1377  print '</a>';
1378  }
1379 
1380  print '</td>';
1381 
1382  print "</tr>\n";
1383  $i++;
1384  }
1385 
1386  if ($num == 0) {
1387  $colspan = 1 + ($showuserlogin ? 1 : 0);
1388  foreach ($arrayfields as $key => $val) {
1389  if (!empty($val['checked'])) {
1390  $colspan++;
1391  }
1392  }
1393  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1394  }
1395  } else {
1396  $colspan = 1 + ($showuserlogin ? 1 : 0);
1397  foreach ($arrayfields as $key => $val) {
1398  if (!empty($val['checked'])) {
1399  $colspan++;
1400  }
1401  }
1402  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1403  }
1404  print "\n</table>\n";
1405  print '</div>';
1406 
1407  print '</form>'."\n";
1408 
1409  return $i;
1410 }
1411 
1412 
1425 function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '')
1426 {
1427  global $user, $conf;
1428 
1429  $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1430 
1431  if ($noprint) {
1432  return $out;
1433  } else {
1434  print $out;
1435  }
1436 }
1437 
1456 function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1457 {
1458  global $user, $conf;
1459  global $form;
1460  global $param, $massactionbutton;
1461 
1462  $start_year = GETPOST('dateevent_startyear', 'int');
1463  $start_month = GETPOST('dateevent_startmonth', 'int');
1464  $start_day = GETPOST('dateevent_startday', 'int');
1465  $end_year = GETPOST('dateevent_endyear', 'int');
1466  $end_month = GETPOST('dateevent_endmonth', 'int');
1467  $end_day = GETPOST('dateevent_endday', 'int');
1468  $tms_start = '';
1469  $tms_end = '';
1470 
1471  if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1472  $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1473  }
1474  if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1475  $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1476  }
1477  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
1478  $tms_start = '';
1479  $tms_end = '';
1480  }
1481  dol_include_once('/comm/action/class/actioncomm.class.php');
1482 
1483  // Check parameters
1484  if (!is_object($filterobj) && !is_object($objcon)) {
1485  dol_print_error('', 'BadParameter');
1486  }
1487 
1488  $out = '';
1489  $histo = array();
1490  $numaction = 0;
1491  $now = dol_now('tzuser');
1492 
1493  // Open DSI -- Fix order by -- Begin
1494  $sortfield_list = explode(',', $sortfield);
1495  $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1496  $sortfield_new_list = array();
1497  foreach ($sortfield_list as $sortfield_value) {
1498  $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1499  }
1500  $sortfield_new = implode(',', $sortfield_new_list);
1501 
1502  $sql = '';
1503 
1504  if (isModEnabled('agenda')) {
1505  require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
1506  $hookmanager = new HookManager($db);
1507  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1508  $hookmanager->initHooks(array('agendadao'));
1509 
1510  // Recherche histo sur actioncomm
1511  if (is_object($objcon) && $objcon->id > 0) {
1512  $sql = "SELECT DISTINCT a.id, a.label as label,";
1513  } else {
1514  $sql = "SELECT a.id, a.label as label,";
1515  }
1516  $sql .= " a.datep as dp,";
1517  $sql .= " a.datep2 as dp2,";
1518  $sql .= " a.percent as percent, 'action' as type,";
1519  $sql .= " a.fk_element, a.elementtype,";
1520  $sql .= " a.fk_contact,";
1521  $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1522  $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";
1523  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1524  $sql .= ", sp.lastname, sp.firstname";
1525  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1526  /* Nothing */
1527  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1528  /* Nothing */
1529  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1530  $sql .= ", m.lastname, m.firstname";
1531  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1532  $sql .= ", o.ref";
1533  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1534  $sql .= ", o.ref";
1535  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1536  $sql .= ", o.ref";
1537  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1538  $sql .= ", o.ref";
1539  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1540  $sql .= ", o.ref";
1541  } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1542  if (!empty($filterobj->fields['ref'])) {
1543  $sql .= ", o.ref";
1544  } elseif (!empty($filterobj->fields['label'])) {
1545  $sql .= ", o.label";
1546  }
1547  }
1548 
1549  // Fields from hook
1550  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1551  $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1552  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1553 
1554  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1555  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1556  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1557 
1558  $force_filter_contact = false;
1559  if (is_object($objcon) && $objcon->id > 0) {
1560  $force_filter_contact = true;
1561  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1562  $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
1563  }
1564 
1565  // Fields from hook
1566  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1567  $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1568  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1569 
1570  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1571  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1572  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1573  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1574  $sql .= " ON er.resource_type = 'dolresource'";
1575  $sql .= " AND er.element_id = a.id";
1576  $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1577  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1578  /* Nothing */
1579  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1580  $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1581  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1582  $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1583  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1584  $sql .= ", ".MAIN_DB_PREFIX."product as o";
1585  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1586  $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1587  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1588  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1589  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1590  $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1591  } 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) {
1592  $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1593  }
1594 
1595  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1596  if ($force_filter_contact === false) {
1597  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1598  $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1599  } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1600  /* Nothing */
1601  } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1602  $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1603  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1604  $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1605  if ($filterobj->id) {
1606  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1607  }
1608  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1609  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1610  if ($filterobj->id) {
1611  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1612  }
1613  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1614  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1615  if ($filterobj->id) {
1616  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1617  }
1618  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1619  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1620  if ($filterobj->id) {
1621  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1622  }
1623  } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1624  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1625  if ($filterobj->id) {
1626  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1627  }
1628  } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1629  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1630  if ($filterobj->id) {
1631  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1632  }
1633  } 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) {
1634  // Generic case
1635  $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1636  if ($filterobj->id) {
1637  $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1638  }
1639  }
1640  }
1641 
1642  if (!empty($tms_start) && !empty($tms_end)) {
1643  $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)."'))";
1644  } elseif (empty($tms_start) && !empty($tms_end)) {
1645  $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1646  } elseif (!empty($tms_start) && empty($tms_end)) {
1647  $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1648  }
1649 
1650  if (is_array($actioncode) && !empty($actioncode)) {
1651  $sql .= ' AND (';
1652  foreach ($actioncode as $key => $code) {
1653  if ($key != 0) {
1654  $sql .= "OR (";
1655  }
1656  if (!empty($code)) {
1657  addEventTypeSQL($sql, $code);
1658  }
1659  if ($key != 0) {
1660  $sql .= ")";
1661  }
1662  }
1663  $sql .= ')';
1664  } elseif (!empty($actioncode)) {
1665  addEventTypeSQL($sql, $actioncode);
1666  }
1667 
1668  addOtherFilterSQL($sql, $donetodo, $now, $filters);
1669 
1670  // Fields from hook
1671  $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
1672  $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
1673  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1674 
1675  if (is_array($actioncode)) {
1676  foreach ($actioncode as $code) {
1677  $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1678  if (!empty($sql2)) {
1679  if (!empty($sql)) {
1680  $sql = $sql." UNION ".$sql2;
1681  } elseif (empty($sql)) {
1682  $sql = $sql2;
1683  }
1684  break;
1685  }
1686  }
1687  } else {
1688  $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
1689  if (!empty($sql) && !empty($sql2)) {
1690  $sql = $sql." UNION ".$sql2;
1691  } elseif (empty($sql) && !empty($sql2)) {
1692  $sql = $sql2;
1693  }
1694  }
1695  }
1696 
1697  //TODO Add limit in nb of results
1698  if ($sql) {
1699  $sql .= $db->order($sortfield_new, $sortorder);
1700 
1701  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1702 
1703  $resql = $db->query($sql);
1704  if ($resql) {
1705  $i = 0;
1706  $num = $db->num_rows($resql);
1707 
1708  while ($i < $num) {
1709  $obj = $db->fetch_object($resql);
1710 
1711  if ($obj->type == 'action') {
1712  $contactaction = new ActionComm($db);
1713  $contactaction->id = $obj->id;
1714  $result = $contactaction->fetchResources();
1715  if ($result < 0) {
1716  dol_print_error($db);
1717  setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors');
1718  }
1719 
1720  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1721  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1722  $tododone = '';
1723  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
1724  $tododone = 'todo';
1725  }
1726 
1727  $histo[$numaction] = array(
1728  'type'=>$obj->type,
1729  'tododone'=>$tododone,
1730  'id'=>$obj->id,
1731  'datestart'=>$db->jdate($obj->dp),
1732  'dateend'=>$db->jdate($obj->dp2),
1733  'note'=>$obj->label,
1734  'percent'=>$obj->percent,
1735 
1736  'userid'=>$obj->user_id,
1737  'login'=>$obj->user_login,
1738  'userfirstname'=>$obj->user_firstname,
1739  'userlastname'=>$obj->user_lastname,
1740  'userphoto'=>$obj->user_photo,
1741 
1742  'contact_id'=>$obj->fk_contact,
1743  'socpeopleassigned' => $contactaction->socpeopleassigned,
1744  'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
1745  'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
1746  'fk_element'=>$obj->fk_element,
1747  'elementtype'=>$obj->elementtype,
1748  // Type of event
1749  'acode'=>$obj->acode,
1750  'alabel'=>$obj->alabel,
1751  'libelle'=>$obj->alabel, // deprecated
1752  'apicto'=>$obj->apicto
1753  );
1754  } else {
1755  $histo[$numaction] = array(
1756  'type'=>$obj->type,
1757  'tododone'=>'done',
1758  'id'=>$obj->id,
1759  'datestart'=>$db->jdate($obj->dp),
1760  'dateend'=>$db->jdate($obj->dp2),
1761  'note'=>$obj->label,
1762  'percent'=>$obj->percent,
1763  'acode'=>$obj->acode,
1764 
1765  'userid'=>$obj->user_id,
1766  'login'=>$obj->user_login,
1767  'userfirstname'=>$obj->user_firstname,
1768  'userlastname'=>$obj->user_lastname,
1769  'userphoto'=>$obj->user_photo
1770  );
1771  }
1772 
1773  $numaction++;
1774  $i++;
1775  }
1776  } else {
1777  dol_print_error($db);
1778  }
1779  }
1780 
1781  if (isModEnabled('agenda')|| (isModEnabled('mailing') && !empty($objcon->email))) {
1782  $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
1783 
1784  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1785  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1786  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1787  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1788 
1789  $formactions = new FormActions($db);
1790 
1791  $actionstatic = new ActionComm($db);
1792  $userstatic = new User($db);
1793  $userlinkcache = array();
1794  $contactstatic = new Contact($db);
1795  $elementlinkcache = array();
1796 
1797  $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1798  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1799  if ($objcon && get_class($objcon) == 'Contact' &&
1800  (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
1801  $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
1802  } else {
1803  $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1804  }
1805  if ($filterobj && get_class($filterobj) == 'Societe') {
1806  $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1807  }
1808 
1809  $out .= "\n";
1810 
1811  $out .= '<div class="div-table-responsive-no-min">';
1812  $out .= '<table class="noborder centpercent">';
1813 
1814  $out .= '<tr class="liste_titre">';
1815  if ($donetodo) {
1816  $out .= '<td class="liste_titre"></td>';
1817  }
1818 
1819  $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
1820  $out .= '<td class="liste_titre"></td>';
1821  $out .= '<td class="liste_titre">';
1822  $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');
1823  $out .= '</td>';
1824  $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1825  $out .= '<td class="liste_titre center">';
1826  $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
1827  $out .= '</td>';
1828  $out .= '<td class="liste_titre"></td>';
1829  $out .= '<td class="liste_titre"></td>';
1830  $out .= '<td class="liste_titre"></td>';
1831  // Action column
1832  $out .= '<td class="liste_titre" align="middle">';
1833  $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
1834  $out .= $searchpicto;
1835  $out .= '</td>';
1836  $out .= '</tr>';
1837 
1838  $out .= '<tr class="liste_titre">';
1839  if ($donetodo) {
1840  $tmp = '';
1841  if (get_class($filterobj) == 'Societe') {
1842  $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
1843  }
1844  $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1845  $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1846  $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1847  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1848  if (get_class($filterobj) == 'Societe') {
1849  $tmp .= '</a>';
1850  }
1851  $out .= getTitleFieldOfList($tmp);
1852  }
1853  $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1854  $out .= getTitleFieldOfList("Owner");
1855  $out .= getTitleFieldOfList("Type");
1856  $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1857  $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
1858  $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1859  $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
1860  $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
1861  $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1862  $out .= '</tr>';
1863 
1864  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
1865  $caction = new CActionComm($db);
1866  $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
1867 
1868  foreach ($histo as $key => $value) {
1869  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1870 
1871  $actionstatic->type_picto = $histo[$key]['apicto'];
1872  $actionstatic->type_code = $histo[$key]['acode'];
1873 
1874  $out .= '<tr class="oddeven">';
1875 
1876  // Done or todo
1877  if ($donetodo) {
1878  $out .= '<td class="nowrap">';
1879  $out .= '</td>';
1880  }
1881 
1882  // Ref
1883  $out .= '<td class="nowraponall">';
1884  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
1885  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
1886  $out .= $histo[$key]['id'];
1887  $out .= '</a>';
1888  } else {
1889  $out .= $actionstatic->getNomUrl(1, -1);
1890  }
1891  $out .= '</td>';
1892 
1893  // Author of event
1894  $out .= '<td class="tdoverflowmax150">';
1895  //$userstatic->id=$histo[$key]['userid'];
1896  //$userstatic->login=$histo[$key]['login'];
1897  //$out.=$userstatic->getLoginUrl(1);
1898  if ($histo[$key]['userid'] > 0) {
1899  if (isset($userlinkcache[$histo[$key]['userid']])) {
1900  $link = $userlinkcache[$histo[$key]['userid']];
1901  } else {
1902  $userstatic->fetch($histo[$key]['userid']);
1903  $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
1904  $userlinkcache[$histo[$key]['userid']] = $link;
1905  }
1906  $out .= $link;
1907  }
1908  $out .= '</td>';
1909 
1910  // Type
1911  $labeltype = $actionstatic->type_code;
1912  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
1913  $labeltype = 'AC_OTH';
1914  }
1915  if (preg_match('/^TICKET_MSG/', $actionstatic->code)) {
1916  $labeltype = $langs->trans("Message");
1917  } else {
1918  if (!empty($arraylist[$labeltype])) {
1919  $labeltype = $arraylist[$labeltype];
1920  }
1921  if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
1922  $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
1923  }
1924  }
1925  $out .= '<td class="tdoverflowmax150" title="'.$labeltype.'">';
1926  $out .= $actionstatic->getTypePicto();
1927  $out .= $labeltype;
1928  $out .= '</td>';
1929 
1930  // Title/Label of event
1931  $out .= '<td class="tdoverflowmax300"';
1932  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
1933  $transcode = $langs->trans("Action".$histo[$key]['acode']);
1934  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
1935  //$actionstatic->libelle=$libelle;
1936  $libelle = $histo[$key]['note'];
1937  $actionstatic->id = $histo[$key]['id'];
1938  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
1939  $out .= dol_trunc($libelle, 120);
1940  }
1941  if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
1942  $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
1943  $transcode = $langs->trans("Action".$histo[$key]['acode']);
1944  $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
1945  $out .= ' title="'.dol_escape_htmltag($libelle).'">';
1946  $out .= dol_trunc($libelle, 120);
1947  }
1948  $out .= '</td>';
1949 
1950  // Date
1951  $out .= '<td class="center nowraponall">';
1952  $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
1953  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
1954  $tmpa = dol_getdate($histo[$key]['datestart'], true);
1955  $tmpb = dol_getdate($histo[$key]['dateend'], true);
1956  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1957  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
1958  } else {
1959  $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
1960  }
1961  }
1962  $late = 0;
1963  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1964  $late = 1;
1965  }
1966  if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1967  $late = 1;
1968  }
1969  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
1970  $late = 1;
1971  }
1972  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
1973  $late = 1;
1974  }
1975  if ($late) {
1976  $out .= img_warning($langs->trans("Late")).' ';
1977  }
1978  $out .= "</td>\n";
1979 
1980  // Title of event
1981  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
1982 
1983  // Linked object
1984  $out .= '<td class="nowraponall">';
1985  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
1986  if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
1987  $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
1988  } else {
1989  if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
1990  $elementlinkcache[$histo[$key]['elementtype']] = array();
1991  }
1992  $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
1993  $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
1994  }
1995  $out .= $link;
1996  } else {
1997  $out .= '&nbsp;';
1998  }
1999  $out .= '</td>';
2000 
2001  // Contact(s) for action
2002  if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2003  $out .= '<td class="valignmiddle">';
2004  $contact = new Contact($db);
2005  foreach ($histo[$key]['socpeopleassigned'] as $cid => $value) {
2006  $result = $contact->fetch($cid);
2007 
2008  if ($result < 0) {
2009  dol_print_error($db, $contact->error);
2010  }
2011 
2012  if ($result > 0) {
2013  $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2014  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2015  if (!empty($contact->phone_pro)) {
2016  $out .= '('.dol_print_phone($contact->phone_pro).')';
2017  }
2018  }
2019  $out .= '<div class="paddingright"></div>';
2020  }
2021  }
2022  $out .= '</td>';
2023  } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2024  $contactstatic->lastname = $histo[$key]['lastname'];
2025  $contactstatic->firstname = $histo[$key]['firstname'];
2026  $contactstatic->id = $histo[$key]['contact_id'];
2027  $contactstatic->photo = $histo[$key]['contact_photo'];
2028  $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2029  } else {
2030  $out .= '<td>&nbsp;</td>';
2031  }
2032 
2033  // Status
2034  $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2035 
2036  // Actions
2037  $out .= '<td></td>';
2038 
2039  $out .= "</tr>\n";
2040  $i++;
2041  }
2042  if (empty($histo)) {
2043  $colspan = 9;
2044  $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2045  }
2046 
2047  $out .= "</table>\n";
2048  $out .= "</div>\n";
2049 
2050  $out .= '</form>';
2051  }
2052 
2053  if ($noprint) {
2054  return $out;
2055  } else {
2056  print $out;
2057  }
2058 }
2059 
2069 function show_subsidiaries($conf, $langs, $db, $object)
2070 {
2071  global $user;
2072 
2073  $i = -1;
2074 
2075  $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";
2076  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2077  $sql .= " WHERE s.parent = ".((int) $object->id);
2078  $sql .= " AND s.entity IN (".getEntity('societe').")";
2079  $sql .= " ORDER BY s.nom";
2080 
2081  $result = $db->query($sql);
2082  $num = $db->num_rows($result);
2083 
2084  if ($num) {
2085  $socstatic = new Societe($db);
2086 
2087  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2088 
2089  print "\n".'<div class="div-table-responsive-no-min">'."\n";
2090  print '<table class="noborder centpercent">'."\n";
2091 
2092  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2093  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2094  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2095  print "<td>&nbsp;</td>";
2096  print "</tr>";
2097 
2098  $i = 0;
2099 
2100  while ($i < $num) {
2101  $obj = $db->fetch_object($result);
2102 
2103  $socstatic->id = $obj->rowid;
2104  $socstatic->name = $obj->name;
2105  $socstatic->name_alias = $obj->name_alias;
2106  $socstatic->email = $obj->email;
2107  $socstatic->code_client = $obj->code_client;
2108  $socstatic->code_fournisseur = $obj->code_client;
2109  $socstatic->code_compta = $obj->code_compta;
2110  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2111  $socstatic->email = $obj->email;
2112  $socstatic->canvas = $obj->canvas;
2113  $socstatic->client = $obj->client;
2114  $socstatic->fournisseur = $obj->fournisseur;
2115 
2116  print '<tr class="oddeven">';
2117 
2118  print '<td class="tdoverflowmax150">';
2119  print $socstatic->getNomUrl(1);
2120  print '</td>';
2121 
2122  print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2123  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2124  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2125  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2126 
2127  print '<td class="center">';
2128  print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2129  print img_edit();
2130  print '</a></td>';
2131 
2132  print "</tr>\n";
2133  $i++;
2134  }
2135  print "\n</table>\n";
2136  print '</div>'."\n";
2137  }
2138 
2139  print "<br>\n";
2140 
2141  return $i;
2142 }
2151 function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2152 {
2153  global $conf, $db;
2154  // Condition on actioncode
2155 
2156  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
2157  if ($actioncode == 'AC_NON_AUTO') {
2158  $sql .= " $sqlANDOR c.type != 'systemauto'";
2159  } elseif ($actioncode == 'AC_ALL_AUTO') {
2160  $sql .= " $sqlANDOR c.type = 'systemauto'";
2161  } else {
2162  if ($actioncode == 'AC_OTH') {
2163  $sql .= " $sqlANDOR c.type != 'systemauto'";
2164  } elseif ($actioncode == 'AC_OTH_AUTO') {
2165  $sql .= " $sqlANDOR c.type = 'systemauto'";
2166  }
2167  }
2168  } else {
2169  if ($actioncode == 'AC_NON_AUTO') {
2170  $sql .= " $sqlANDOR c.type != 'systemauto'";
2171  } elseif ($actioncode == 'AC_ALL_AUTO') {
2172  $sql .= " $sqlANDOR c.type = 'systemauto'";
2173  } else {
2174  $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2175  }
2176  }
2177 
2178  return $sql;
2179 }
2180 
2190 function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2191 {
2192  global $conf, $db;
2193  // Condition on actioncode
2194 
2195  if ($donetodo == 'todo') {
2196  $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2197  } elseif ($donetodo == 'done') {
2198  $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2199  }
2200  if (is_array($filters) && $filters['search_agenda_label']) {
2201  $sql .= natural_search('a.label', $filters['search_agenda_label']);
2202  }
2203  if (is_array($filters) && $filters['search_rowid']) {
2204  $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2205  }
2206 
2207  return $sql;
2208 }
2209 
2218 function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2219 {
2220  global $conf, $langs, $db;
2221  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2222  if (isModEnabled('mailing') && !empty($objcon->email)
2223  && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2224  $langs->load("mails");
2225 
2226  $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";
2227  $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2228  $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2229  $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
2230  if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2231  $sql2 .= ", '' as lastname, '' as firstname";
2232  } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2233  $sql2 .= ", '' as lastname, '' as firstname";
2234  } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2235  $sql2 .= ", '' as ref";
2236  } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2237  $sql2 .= ", '' as ref";
2238  } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2239  $sql2 .= ", '' as ref";
2240  }
2241  $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2242  $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2243  $sql2 .= " AND mc.statut = 1";
2244  $sql2 .= " AND u.rowid = m.fk_user_valid";
2245  $sql2 .= " AND mc.fk_mailing=m.rowid";
2246  return $sql2;
2247  }
2248 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2820
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:49
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:1493
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:3949
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: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:5201
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
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:520
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:4993
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:8713
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:1032
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:61
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4670
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:1425
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4538
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3132
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:2550
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:2069
addOtherFilterSQL
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
Definition: company.lib.php:2190
getCountriesInEEC
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
Definition: company.lib.php:742
$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:179
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:9390
currency_name
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.
Definition: company.lib.php:665
$resql
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:11017
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:1456
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:6880
show_contacts
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
Definition: company.lib.php:933
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
setEventMessage
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
Definition: functions.lib.php:8436
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:804
addMailingEventTypeSQL
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
Definition: company.lib.php:2218
getFormeJuridiqueLabel
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Definition: company.lib.php:709
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
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
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11290
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
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:421
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:9797
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:4360
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
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:5697
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
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:2863
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
addEventTypeSQL
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
Definition: company.lib.php:2151
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
isInEEC
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
Definition: company.lib.php:779