dolibarr  9.0.0
company.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2013 Christophe Battarel <contact@altairis.fr>
9  * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@zendsi.com>
10  * Copyright (C) 2015-2018 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 <http://www.gnu.org/licenses/>.
27  * or see http://www.gnu.org/
28  */
29 
42 function societe_prepare_head(Societe $object)
43 {
44  global $db, $langs, $conf, $user;
45  $h = 0;
46  $head = array();
47 
48  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
49  $head[$h][1] = $langs->trans("Card");
50  $head[$h][2] = 'card';
51  $h++;
52 
53  if (empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES))
54  {
55  if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
56  {
57  //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
58  $nbContact = 0; // TODO
59 
60  $sql = "SELECT COUNT(p.rowid) as nb";
61  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
62  $sql .= " WHERE p.fk_soc = ".$object->id;
63  $resql = $db->query($sql);
64  if ($resql)
65  {
66  $obj = $db->fetch_object($resql);
67  if ($obj) $nbContact = $obj->nb;
68  }
69 
70  $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
71  $head[$h][1] = $langs->trans('ContactsAddresses');
72  if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
73  $head[$h][2] = 'contact';
74  $h++;
75  }
76  }
77  else
78  {
79  $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
80  $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
81  $head[$h][1] = $langs->trans("ContactsAddresses");
82  if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
83  $head[$h][2] = 'contact';
84  $h++;
85  }
86 
87  if ($object->client==1 || $object->client==2 || $object->client==3)
88  {
89  $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
90  $head[$h][1] = '';
91  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && ($object->client==2 || $object->client==3)) $head[$h][1] .= $langs->trans("Prospect");
92  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && $object->client==3) $head[$h][1] .= ' | ';
93  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && ($object->client==1 || $object->client==3)) $head[$h][1] .= $langs->trans("Customer");
94  $head[$h][2] = 'customer';
95  $h++;
96 
97  if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
98  {
99  $langs->load("products");
100  // price
101  $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
102  $head[$h][1] = $langs->trans("CustomerPrices");
103  $head[$h][2] = 'price';
104  $h++;
105  }
106  }
107  if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire))
108  {
109  $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
110  $head[$h][1] = $langs->trans("Supplier");
111  $head[$h][2] = 'supplier';
112  $h++;
113  }
114 
115  if (! empty($conf->projet->enabled) && (!empty($user->rights->projet->lire) ))
116  {
117  $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
118  $head[$h][1] = $langs->trans("Projects");
119  $nbNote = 0;
120  $sql = "SELECT COUNT(n.rowid) as nb";
121  $sql.= " FROM ".MAIN_DB_PREFIX."projet as n";
122  $sql.= " WHERE fk_soc = ".$object->id;
123  $sql.= " AND entity IN (".getEntity('project').")";
124  $resql=$db->query($sql);
125  if ($resql)
126  {
127  $num = $db->num_rows($resql);
128  $i = 0;
129  while ($i < $num)
130  {
131  $obj = $db->fetch_object($resql);
132  $nbNote=$obj->nb;
133  $i++;
134  }
135  }
136  else {
137  dol_print_error($db);
138  }
139  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
140  $head[$h][2] = 'project';
141  $h++;
142  }
143 
144  // Tab to link resources
145  if (! empty($conf->resource->enabled) && ! empty($conf->global->RESOURCE_ON_THIRDPARTIES))
146  {
147  $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
148  $head[$h][1] = $langs->trans("Resources");
149  $head[$h][2] = 'resources';
150  $h++;
151  }
152 
153  if (! empty($conf->global->ACCOUNTING_ENABLE_LETTERING))
154  {
155  // Tab to accountancy
156  if (! empty($conf->accounting->enabled) && $object->client>0)
157  {
158  $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettering_customer.php?socid='.$object->id;
159  $head[$h][1] = $langs->trans("TabLetteringCustomer");
160  $head[$h][2] = 'lettering_customer';
161  $h++;
162  }
163 
164  // Tab to accountancy
165  if (! empty($conf->accounting->enabled) && $object->fournisseur>0)
166  {
167  $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettering_supplier.php?socid='.$object->id;
168  $head[$h][1] = $langs->trans("TabLetteringSupplier");
169  $head[$h][2] = 'lettering_supplier';
170  $h++;
171  }
172  }
173 
174  // Related items
175  if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->ficheinter->enabled) || ! empty($conf->fournisseur->enabled))
176  {
177  $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
178  $head[$h][1] = $langs->trans("Referers");
179  $head[$h][2] = 'consumption';
180  $h++;
181  }
182 
183  // Bank accounts
184  if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
185  {
186  $nbBankAccount=0;
187  $foundonexternalonlinesystem=0;
188  $langs->load("banks");
189 
190  $title = $langs->trans("BankAccounts");
191  if (! empty($conf->stripe->enabled))
192  {
193  $langs->load("stripe");
194  $title = $langs->trans("BankAccountsAndGateways");
195 
196  $servicestatus = 0;
197  if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha')) $servicestatus = 1;
198 
199  include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
200  $societeaccount = new SocieteAccount($db);
201  $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
202  if ($stripecu) $foundonexternalonlinesystem++;
203  }
204 
205  $sql = "SELECT COUNT(n.rowid) as nb";
206  $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
207  $sql.= " WHERE fk_soc = ".$object->id;
208  $resql=$db->query($sql);
209  if ($resql)
210  {
211  $num = $db->num_rows($resql);
212  $i = 0;
213  while ($i < $num)
214  {
215  $obj = $db->fetch_object($resql);
216  $nbBankAccount=$obj->nb;
217  $i++;
218  }
219  }
220  else {
221  dol_print_error($db);
222  }
223 
224  //if (! empty($conf->stripe->enabled) && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
225 
226  $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id;
227  $head[$h][1] = $title;
228  if ($foundonexternalonlinesystem) $head[$h][1].= ' <span class="badge">...</span>';
229  elseif ($nbBankAccount > 0) $head[$h][1].= ' <span class="badge">'.$nbBankAccount.'</span>';
230  $head[$h][2] = 'rib';
231  $h++;
232  }
233 
234  if (! empty($conf->website->enabled) && (! empty($conf->global->WEBSITE_USE_WEBSITE_ACCOUNTS)) && (!empty($user->rights->societe->lire)))
235  {
236  $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.$object->id;
237  $head[$h][1] = $langs->trans("WebSiteAccounts");
238  $nbNote = 0;
239  $sql = "SELECT COUNT(n.rowid) as nb";
240  $sql.= " FROM ".MAIN_DB_PREFIX."societe_account as n";
241  $sql.= " WHERE fk_soc = ".$object->id.' AND fk_website > 0';
242  $resql=$db->query($sql);
243  if ($resql)
244  {
245  $num = $db->num_rows($resql);
246  $i = 0;
247  while ($i < $num)
248  {
249  $obj = $db->fetch_object($resql);
250  $nbNote=$obj->nb;
251  $i++;
252  }
253  }
254  else {
255  dol_print_error($db);
256  }
257  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
258  $head[$h][2] = 'website';
259  $h++;
260  }
261 
262  // Show more tabs from modules
263  // Entries must be declared in modules descriptor with line
264  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
265  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
266  complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty');
267 
268  if ($user->societe_id == 0)
269  {
270  // Notifications
271  if (! empty($conf->notification->enabled))
272  {
273  $nbNote = 0;
274  $sql = "SELECT COUNT(n.rowid) as nb";
275  $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n";
276  $sql.= " WHERE fk_soc = ".$object->id;
277  $resql=$db->query($sql);
278  if ($resql)
279  {
280  $num = $db->num_rows($resql);
281  $i = 0;
282  while ($i < $num)
283  {
284  $obj = $db->fetch_object($resql);
285  $nbNote=$obj->nb;
286  $i++;
287  }
288  }
289  else {
290  dol_print_error($db);
291  }
292 
293  $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.$object->id;
294  $head[$h][1] = $langs->trans("Notifications");
295  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
296  $head[$h][2] = 'notify';
297  $h++;
298  }
299 
300  // Notes
301  $nbNote = 0;
302  if(!empty($object->note_private)) $nbNote++;
303  if(!empty($object->note_public)) $nbNote++;
304  $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.$object->id;
305  $head[$h][1] = $langs->trans("Notes");
306  if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
307  $head[$h][2] = 'note';
308  $h++;
309 
310  // Attached files
311  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
312  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
313  $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ;
314  $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
315  $nbLinks=Link::count($db, $object->element, $object->id);
316 
317  $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
318  $head[$h][1] = $langs->trans("Documents");
319  if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
320  $head[$h][2] = 'document';
321  $h++;
322  }
323 
324  $head[$h][0] = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id;
325  $head[$h][1].= $langs->trans("Events");
326  if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
327  {
328  $head[$h][1].= '/';
329  $head[$h][1].= $langs->trans("Agenda");
330  }
331  $head[$h][2] = 'agenda';
332  $h++;
333 
334  // Log
335  /*$head[$h][0] = DOL_URL_ROOT.'/societe/info.php?socid='.$object->id;
336  $head[$h][1] = $langs->trans("Info");
337  $head[$h][2] = 'info';
338  $h++;*/
339 
340  complete_head_from_modules($conf,$langs,$object,$head,$h,'thirdparty','remove');
341 
342  return $head;
343 }
344 
345 
352 function societe_prepare_head2($object)
353 {
354  global $langs, $conf, $user;
355  $h = 0;
356  $head = array();
357 
358  $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
359  $head[$h][1] = $langs->trans("Card");
360  $head[$h][2] = 'company';
361  $h++;
362 
363  $head[$h][0] = 'commerciaux.php?socid='.$object->id;
364  $head[$h][1] = $langs->trans("SalesRepresentative");
365  $head[$h][2] = 'salesrepresentative';
366  $h++;
367 
368  return $head;
369 }
370 
371 
372 
379 {
380  global $langs, $conf, $user;
381 
382  $h = 0;
383  $head = array();
384 
385  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
386  $head[$h][1] = $langs->trans("Miscellaneous");
387  $head[$h][2] = 'general';
388  $h++;
389 
390  // Show more tabs from modules
391  // Entries must be declared in modules descriptor with line
392  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
393  // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
394  complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin');
395 
396  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
397  $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
398  $head[$h][2] = 'attributes';
399  $h++;
400 
401  $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
402  $head[$h][1] = $langs->trans("ExtraFieldsContacts");
403  $head[$h][2] = 'attributes_contacts';
404  $h++;
405 
406  complete_head_from_modules($conf,$langs,null,$head,$h,'company_admin','remove');
407 
408  return $head;
409 }
410 
411 
412 
428 function getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
429 {
430  global $db,$langs;
431 
432  $result='';
433 
434  // Check parameters
435  if (empty($searchkey) && empty($searchlabel))
436  {
437  if ($withcode === 'all') return array('id'=>'','code'=>'','label'=>'');
438  else return '';
439  }
440  if (! is_object($dbtouse)) $dbtouse=$db;
441  if (! is_object($outputlangs)) $outputlangs=$langs;
442 
443  $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
444  if (is_numeric($searchkey)) $sql.= " WHERE rowid=".$searchkey;
445  elseif (! empty($searchkey)) $sql.= " WHERE code='".$db->escape($searchkey)."'";
446  else $sql.= " WHERE label='".$db->escape($searchlabel)."'";
447 
448  $resql=$dbtouse->query($sql);
449  if ($resql)
450  {
451  $obj = $dbtouse->fetch_object($resql);
452  if ($obj)
453  {
454  $label=((! empty($obj->label) && $obj->label!='-')?$obj->label:'');
455  if (is_object($outputlangs))
456  {
457  $outputlangs->load("dict");
458  if ($entconv) $label=($obj->code && ($outputlangs->trans("Country".$obj->code)!="Country".$obj->code))?$outputlangs->trans("Country".$obj->code):$label;
459  else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code)!="Country".$obj->code))?$outputlangs->transnoentitiesnoconv("Country".$obj->code):$label;
460  }
461  if ($withcode == 1) $result=$label?"$obj->code - $label":"$obj->code";
462  else if ($withcode == 2) $result=$obj->code;
463  else if ($withcode == 3) $result=$obj->rowid;
464  else if ($withcode === 'all') $result=array('id'=>$obj->rowid,'code'=>$obj->code,'label'=>$label);
465  else $result=$label;
466  }
467  else
468  {
469  $result='NotDefined';
470  }
471  $dbtouse->free($resql);
472  return $result;
473  }
474  else dol_print_error($dbtouse,'');
475  return 'Error';
476 }
477 
493 function getState($id,$withcode='',$dbtouse=0,$withregion=0,$outputlangs='',$entconv=1)
494 {
495  global $db,$langs;
496 
497  if (! is_object($dbtouse)) $dbtouse=$db;
498 
499  $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";
500  $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
501  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".$id;
502  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
503  $sql .= " ORDER BY c.code, d.code_departement";
504 
505  dol_syslog("Company.lib::getState", LOG_DEBUG);
506  $resql=$dbtouse->query($sql);
507  if ($resql)
508  {
509  $obj = $dbtouse->fetch_object($resql);
510  if ($obj)
511  {
512  $label=((! empty($obj->name) && $obj->name!='-')?$obj->name:'');
513  if (is_object($outputlangs))
514  {
515  $outputlangs->load("dict");
516  if ($entconv) $label=($obj->code && ($outputlangs->trans("State".$obj->code)!="State".$obj->code))?$outputlangs->trans("State".$obj->code):$label;
517  else $label=($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code)!="State".$obj->code))?$outputlangs->transnoentitiesnoconv("State".$obj->code):$label;
518  }
519 
520  if ($withcode == 1) {
521  if ($withregion == 1) {
522  return $label = $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
523  }
524  else {
525  return $label = $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
526  }
527  }
528  else if ($withcode == 2) {
529  if ($withregion == 1) {
530  return $label = $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
531  }
532  else {
533  return $label = ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
534  }
535  }
536  else if ($withcode === 'all') {
537  if ($withregion == 1) {
538  return array('id'=>$obj->id,'code'=>$obj->code,'label'=>$label,'region_code'=>$obj->region_code,'region'=>$obj->region_name);
539  }
540  else {
541  return array('id'=>$obj->id,'code'=>$obj->code,'label'=>$label);
542  }
543  }
544  else {
545  if ($withregion == 1) {
546  return $label = $obj->region_name . ' - ' . $label;
547  }
548  else {
549  return $label;
550  }
551  }
552  }
553  else
554  {
555  return $langs->transnoentitiesnoconv("NotDefined");
556  }
557  }
558  else dol_print_error($dbtouse,'');
559 }
560 
569 function currency_name($code_iso, $withcode='', $outputlangs=null)
570 {
571  global $langs,$db;
572 
573  if (empty($outputlangs)) $outputlangs=$langs;
574 
575  $outputlangs->load("dict");
576 
577  // If there is a translation, we can send immediatly the label
578  if ($outputlangs->trans("Currency".$code_iso)!="Currency".$code_iso)
579  {
580  return ($withcode?$code_iso.' - ':'').$outputlangs->trans("Currency".$code_iso);
581  }
582 
583  // If no translation, we read table to get label by default
584  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
585  $sql.= " WHERE code_iso='".$code_iso."'";
586 
587  $resql=$db->query($sql);
588  if ($resql)
589  {
590  $num = $db->num_rows($resql);
591 
592  if ($num)
593  {
594  $obj = $db->fetch_object($resql);
595  $label=($obj->label!='-'?$obj->label:'');
596  if ($withcode) return ($label==$code_iso)?"$code_iso":"$code_iso - $label";
597  else return $label;
598  }
599  else
600  {
601  return $code_iso;
602  }
603  }
604  return 'ErrorWhenReadingCurrencyLabel';
605 }
606 
613 function getFormeJuridiqueLabel($code)
614 {
615  global $db,$langs;
616 
617  if (! $code) return '';
618 
619  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."c_forme_juridique";
620  $sql.= " WHERE code='$code'";
621 
622  dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
623  $resql=$db->query($sql);
624  if ($resql)
625  {
626  $num = $db->num_rows($resql);
627 
628  if ($num)
629  {
630  $obj = $db->fetch_object($resql);
631  $label=($obj->libelle!='-' ? $obj->libelle : '');
632  return $label;
633  }
634  else
635  {
636  return $langs->trans("NotDefined");
637  }
638  }
639 }
640 
641 
649 {
650  // List of all country codes that are in europe for european vat rules
651  // List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9
652  $country_code_in_EEC=array(
653  'AT', // Austria
654  'BE', // Belgium
655  'BG', // Bulgaria
656  'CY', // Cyprus
657  'CZ', // Czech republic
658  'DE', // Germany
659  'DK', // Danemark
660  'EE', // Estonia
661  'ES', // Spain
662  'FI', // Finland
663  'FR', // France
664  'GB', // United Kingdom
665  'GR', // Greece
666  'HR', // Croatia
667  'NL', // Holland
668  'HU', // Hungary
669  'IE', // Ireland
670  'IM', // Isle of Man - Included in UK
671  'IT', // Italy
672  'LT', // Lithuania
673  'LU', // Luxembourg
674  'LV', // Latvia
675  'MC', // Monaco - Included in France
676  'MT', // Malta
677  //'NO', // Norway
678  'PL', // Poland
679  'PT', // Portugal
680  'RO', // Romania
681  'SE', // Sweden
682  'SK', // Slovakia
683  'SI', // Slovenia
684  'UK', // United Kingdom
685  //'CH', // Switzerland - No. Swizerland in not in EEC
686  );
687 
688  return $country_code_in_EEC;
689 }
690 
697 function isInEEC($object)
698 {
699  if (empty($object->country_code)) return false;
700 
701  $country_code_in_EEC = getCountriesInEEC();
702 
703  //print "dd".$this->country_code;
704  return in_array($object->country_code, $country_code_in_EEC);
705 }
706 
707 
720 function show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
721 {
722  global $user;
723 
724  $i = -1 ;
725 
726  if (! empty($conf->projet->enabled) && $user->rights->projet->lire)
727  {
728  $langs->load("projects");
729 
730  $newcardbutton='';
731  if (! empty($conf->projet->enabled) && $user->rights->projet->creer && empty($nocreatelink))
732  {
733  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'"><span class="valignmiddle">'.$langs->trans("AddProject").'</span>';
734  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
735  $newcardbutton.= '</a>';
736  }
737 
738  print "\n";
739  print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
740  print '<div class="div-table-responsive">';
741  print "\n".'<table class="noborder" width=100%>';
742 
743  $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";
744  $sql .= ", cls.code as opp_status_code";
745  $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
746  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
747  $sql .= " WHERE p.fk_soc = ".$object->id;
748  $sql .= " AND p.entity IN (".getEntity('project').")";
749  $sql .= " ORDER BY p.dateo DESC";
750 
751  $result=$db->query($sql);
752  if ($result)
753  {
754  $num = $db->num_rows($result);
755 
756  print '<tr class="liste_titre">';
757  print '<td>'.$langs->trans("Ref").'</td>';
758  print '<td>'.$langs->trans("Name").'</td>';
759  print '<td class="center">'.$langs->trans("DateStart").'</td>';
760  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
761  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
762  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
763  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
764  print '<td class="right">'.$langs->trans("Status").'</td>';
765  print '</tr>';
766 
767  if ($num > 0)
768  {
769  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
770 
771  $projecttmp = new Project($db);
772 
773  $i=0;
774 
775  while ($i < $num)
776  {
777  $obj = $db->fetch_object($result);
778  $projecttmp->fetch($obj->id);
779 
780  // To verify role of users
781  $userAccess = $projecttmp->restrictedProjectArea($user);
782 
783  if ($user->rights->projet->lire && $userAccess > 0)
784  {
785  print '<tr class="oddeven">';
786 
787  // Ref
788  print '<td><a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$projecttmp->id.'">'.img_object($langs->trans("ShowProject"),($obj->public?'projectpub':'project'))." ".$obj->ref.'</a></td>';
789  // Label
790  print '<td>'.$obj->title.'</td>';
791  // Date start
792  print '<td class="center">'.dol_print_date($db->jdate($obj->do),"day").'</td>';
793  // Date end
794  print '<td class="center">'.dol_print_date($db->jdate($obj->de),"day").'</td>';
795  // Opp amount
796  print '<td class="right">';
797  if ($obj->opp_status_code)
798  {
799  print price($obj->opp_amount, 1, '', 1, -1, -1, '');
800  }
801  print '</td>';
802  // Opp status
803  print '<td align="center">';
804  if ($obj->opp_status_code) print $langs->trans("OppStatus".$obj->opp_status_code);
805  print '</td>';
806  // Opp percent
807  print '<td align="right">';
808  if ($obj->opp_percent) print price($obj->opp_percent, 1, '', 1, 0).'%';
809  print '</td>';
810  // Status
811  print '<td align="right">'.$projecttmp->getLibStatut(5).'</td>';
812 
813  print '</tr>';
814  }
815  $i++;
816  }
817  }
818  else
819  {
820  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
821  }
822  $db->free($result);
823  }
824  else
825  {
826  dol_print_error($db);
827  }
828  print "</table>";
829  print '</div>';
830 
831  print "<br>\n";
832  }
833 
834  return $i;
835 }
836 
837 
848 function show_contacts($conf,$langs,$db,$object,$backtopage='')
849 {
850  global $user,$conf,$extrafields,$hookmanager;
851  global $contextpage;
852 
853  $form = new Form($db);
854 
855  $optioncss = GETPOST('optioncss', 'alpha');
856  $sortfield = GETPOST("sortfield",'alpha');
857  $sortorder = GETPOST("sortorder",'alpha');
858  $page = GETPOST('page','int');
859  $search_status = GETPOST("search_status",'int');
860  if ($search_status=='') $search_status=1; // always display activ customer first
861  $search_name = GETPOST("search_name",'alpha');
862  $search_addressphone = GETPOST("search_addressphone",'alpha');
863 
864  if (! $sortorder) $sortorder="ASC";
865  if (! $sortfield) $sortfield="t.lastname";
866 
867  if (! empty($conf->clicktodial->enabled))
868  {
869  $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
870  }
871 
872 
873  $contactstatic = new Contact($db);
874 
875  $extralabels=$extrafields->fetch_name_optionals_label($contactstatic->table_element);
876 
877  $contactstatic->fields=array(
878  'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
879  'poste' =>array('type'=>'varchar(128)', 'label'=>'PostOfFunction', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>20),
880  'address' =>array('type'=>'varchar(128)', 'label'=>'Address', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>30),
881  'statut' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'default'=>0, 'index'=>1, 'position'=>40, 'arrayofkeyval'=>array(0=>$contactstatic->LibStatut(0,1), 1=>$contactstatic->LibStatut(1,1))),
882  );
883 
884  // Definition of fields for list
885  $arrayfields=array(
886  't.rowid'=>array('label'=>"TechnicalID", 'checked'=>($conf->global->MAIN_SHOW_TECHNICAL_ID?1:0), 'enabled'=>($conf->global->MAIN_SHOW_TECHNICAL_ID?1:0), 'position'=>1),
887  't.name'=>array('label'=>"Name", 'checked'=>1, 'position'=>10),
888  't.poste'=>array('label'=>"PostOrFunction", 'checked'=>1, 'position'=>20),
889  '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),
890  't.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>40, 'align'=>'center'),
891  );
892  // Extra fields
893  if (is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label']))
894  {
895  foreach($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val)
896  {
897  if (! empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
898  $arrayfields["ef.".$key]=array(
899  'label'=>$extrafields->attributes[$contactstatic->table_element]['label'][$key],
900  'checked'=>(($extrafields->attributes[$contactstatic->table_element]['list'][$key]<0)?0:1),
901  'position'=>$extrafields->attributes[$contactstatic->table_element]['pos'][$key],
902  'enabled'=>(abs($extrafields->attributes[$contactstatic->table_element]['list'][$key])!=3 && $extrafields->attributes[$contactstatic->table_element]['perms'][$key]));
903  }
904  }
905  }
906 
907  // Initialize array of search criterias
908  $search=array();
909  foreach($contactstatic->fields as $key => $val)
910  {
911  if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
912  }
913  $search_array_options=$extrafields->getOptionalsFromPost($contactstatic->table_element,'','search_');
914 
915  // Purge search criteria
916  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
917  {
918  $search_status = '';
919  $search_name = '';
920  $search_addressphone = '';
921  $search_array_options=array();
922 
923  foreach($contactstatic->fields as $key => $val)
924  {
925  $search[$key]='';
926  }
927  $toselect='';
928  }
929 
930  $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
931  $arrayfields = dol_sort_array($arrayfields, 'position');
932 
933  $newcardbutton='';
934  if ($user->rights->societe->contact->creer)
935  {
936  $addcontact = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
937  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'"><span class="valignmiddle">'.$addcontact.'</span>';
938  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
939  $newcardbutton.= '</a>';
940  }
941 
942  print "\n";
943 
944  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
945  print load_fiche_titre($title, $newcardbutton,'');
946 
947  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
948  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
949  print '<input type="hidden" name="socid" value="'.$object->id.'">';
950  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
951  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
952  print '<input type="hidden" name="page" value="'.$page.'">';
953 
954  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
955  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
956  //if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
957 
958  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
959  print "\n".'<table class="tagtable liste">'."\n";
960 
961  $param="socid=".urlencode($object->id);
962  if ($search_status != '') $param.='&search_status='.urlencode($search_status);
963  if ($search_name != '') $param.='&search_name='.urlencode($search_name);
964  if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
965  // Add $param from extra fields
966  $extrafieldsobjectkey=$contactstatic->table_element;
967  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
968 
969  $sql = "SELECT t.rowid, 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.skype, t.statut, t.photo,";
970  $sql .= " t.civility as civility_id, t.address, t.zip, t.town";
971  $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
972  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
973  $sql .= " WHERE t.fk_soc = ".$object->id;
974  if ($search_status!='' && $search_status != '-1') $sql .= " AND t.statut = ".$db->escape($search_status);
975  if ($search_name) $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
976  // Add where from extra fields
977  $extrafieldsobjectkey=$contactstatic->table_element;
978  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
979  if ($sortfield == "t.name") $sql.=" ORDER BY t.lastname $sortorder, t.firstname $sortorder";
980  else $sql.= " ORDER BY $sortfield $sortorder";
981 
982  dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
983  $result = $db->query($sql);
984  if (! $result) dol_print_error($db);
985 
986  $num = $db->num_rows($result);
987 
988  // Fields title search
989  // --------------------------------------------------------------------
990  print '<tr class="liste_titre">';
991  foreach($contactstatic->fields as $key => $val)
992  {
993  $align='';
994  if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
995  if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
996  if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center';
997  if (! empty($arrayfields['t.'.$key]['checked']))
998  {
999  print '<td class="liste_titre'.($align?' '.$align:'').'">';
1000  if (in_array($key, array('lastname','name'))) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
1001  elseif (in_array($key, array('statut'))) print $form->selectarray('search_status', array('-1'=>'','0'=>$contactstatic->LibStatut(0,1),'1'=>$contactstatic->LibStatut(1,1)),$search_status);
1002  print '</td>';
1003  }
1004  }
1005  // Extra fields
1006  $extrafieldsobjectkey=$contactstatic->table_element;
1007  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1008 
1009  // Fields from hook
1010  $parameters=array('arrayfields'=>$arrayfields);
1011  $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1012  print $hookmanager->resPrint;
1013  // Action column
1014  print '<td class="liste_titre" align="right">';
1015  $searchpicto=$form->showFilterButtons();
1016  print $searchpicto;
1017  print '</td>';
1018  print '</tr>'."\n";
1019 
1020 
1021  // Fields title label
1022  // --------------------------------------------------------------------
1023  print '<tr class="liste_titre">';
1024  foreach($contactstatic->fields as $key => $val)
1025  {
1026  $align='';
1027  if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center';
1028  if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap';
1029  if ($key == 'status' || $key == 'statut') $align.=($align?' ':'').'center';
1030  if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n";
1031  }
1032  // Extra fields
1033  $extrafieldsobjectkey=$contactstatic->table_element;
1034  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1035  // Hook fields
1036  $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
1037  $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1038  print $hookmanager->resPrint;
1039  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],'','','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n";
1040  print '</tr>'."\n";
1041 
1042  $i = -1;
1043 
1044  if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x')))
1045  {
1046  $i = 0;
1047 
1048  while ($i < $num)
1049  {
1050  $obj = $db->fetch_object($result);
1051 
1052  $contactstatic->id = $obj->rowid;
1053  $contactstatic->ref = $obj->ref;
1054  $contactstatic->statut = $obj->statut;
1055  $contactstatic->lastname = $obj->lastname;
1056  $contactstatic->firstname = $obj->firstname;
1057  $contactstatic->civility_id = $obj->civility_id;
1058  $contactstatic->civility_code = $obj->civility_id;
1059  $contactstatic->poste = $obj->poste;
1060  $contactstatic->address = $obj->address;
1061  $contactstatic->zip = $obj->zip;
1062  $contactstatic->town = $obj->town;
1063  $contactstatic->phone_pro = $obj->phone_pro;
1064  $contactstatic->phone_mobile = $obj->phone_mobile;
1065  $contactstatic->phone_perso = $obj->phone_perso;
1066  $contactstatic->email = $obj->email;
1067  $contactstatic->web = $obj->web;
1068  $contactstatic->skype = $obj->skype;
1069  $contactstatic->photo = $obj->photo;
1070 
1071  $country_code = getCountry($obj->country_id, 2);
1072  $contactstatic->country_code = $country_code;
1073 
1074  $contactstatic->setGenderFromCivility();
1075  $contactstatic->fetch_optionals();
1076 
1077  if (is_array($contactstatic->array_options))
1078  {
1079  foreach($contactstatic->array_options as $key => $val)
1080  {
1081  $obj->$key = $val;
1082  }
1083  }
1084 
1085  print '<tr class="oddeven">';
1086 
1087  // ID
1088  if (! empty($arrayfields['t.rowid']['checked']))
1089  {
1090  print '<td>';
1091  print $contactstatic->id;
1092  print '</td>';
1093  }
1094 
1095  // Photo - Name
1096  if (! empty($arrayfields['t.name']['checked']))
1097  {
1098  print '<td>';
1099  print $form->showphoto('contact',$contactstatic,0,0,0,'photorefnoborder valignmiddle marginrightonly','small',1,0,1);
1100  print $contactstatic->getNomUrl(0,'',0,'&backtopage='.urlencode($backtopage));
1101  print '</td>';
1102  }
1103 
1104  // Job position
1105  if (! empty($arrayfields['t.poste']['checked']))
1106  {
1107  print '<td>';
1108  if ($obj->poste) print $obj->poste;
1109  print '</td>';
1110  }
1111 
1112  // Address - Phone - Email
1113  if (! empty($arrayfields['t.address']['checked']))
1114  {
1115  print '<td>';
1116  print $contactstatic->getBannerAddress('contact', $object);
1117  print '</td>';
1118  }
1119 
1120  // Status
1121  if (! empty($arrayfields['t.statut']['checked']))
1122  {
1123  print '<td align="center">'.$contactstatic->getLibStatut(5).'</td>';
1124  }
1125 
1126  // Extra fields
1127  $extrafieldsobjectkey=$contactstatic->table_element;
1128  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1129 
1130  // Actions
1131  print '<td align="right">';
1132 
1133  // Add to agenda
1134  if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create)
1135  {
1136  print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1137  print img_object($langs->trans("Event"),"action");
1138  print '</a> &nbsp; ';
1139  }
1140 
1141  // Edit
1142  if ($user->rights->societe->contact->creer)
1143  {
1144  print '<a href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1145  print img_edit();
1146  print '</a>';
1147  }
1148 
1149  print '</td>';
1150 
1151  print "</tr>\n";
1152  $i++;
1153  }
1154  }
1155  else
1156  {
1157  $colspan=1;
1158  foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
1159  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1160  }
1161  print "\n</table>\n";
1162  print '</div>';
1163 
1164  print '</form>'."\n";
1165 
1166  return $i;
1167 }
1168 
1179 function show_addresses($conf,$langs,$db,$object,$backtopage='')
1180 {
1181  global $user;
1182 
1183  require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
1184 
1185  $addressstatic = new Address($db);
1186  $num = $addressstatic->fetch_lines($object->id);
1187 
1188  $newcardbutton='';
1189  if ($user->rights->societe->creer)
1190  {
1191  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'"><span class="valignmiddle">'.$langs->trans("AddAddress").'</span>';
1192  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
1193  $newcardbutton.= '</a>';
1194  }
1195 
1196  print "\n";
1197  print load_fiche_titre($langs->trans("AddressesForCompany"),$newcardbutton,'');
1198 
1199  print "\n".'<table class="noborder" width="100%">'."\n";
1200 
1201  print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
1202  print '<td>'.$langs->trans("CompanyName").'</td>';
1203  print '<td>'.$langs->trans("Town").'</td>';
1204  print '<td>'.$langs->trans("Country").'</td>';
1205  print '<td>'.$langs->trans("Phone").'</td>';
1206  print '<td>'.$langs->trans("Fax").'</td>';
1207  print "<td>&nbsp;</td>";
1208  print "</tr>";
1209 
1210  if ($num > 0)
1211  {
1212  foreach ($addressstatic->lines as $address)
1213  {
1214  print '<tr class="oddeven">';
1215 
1216  print '<td>';
1217  $addressstatic->id = $address->id;
1218  $addressstatic->label = $address->label;
1219  print $addressstatic->getNomUrl(1);
1220  print '</td>';
1221 
1222  print '<td>'.$address->name.'</td>';
1223 
1224  print '<td>'.$address->town.'</td>';
1225 
1226  $img=picto_from_langcode($address->country_code);
1227  print '<td>'.($img?$img.' ':'').$address->country.'</td>';
1228 
1229  // Lien click to dial
1230  print '<td>';
1231  print dol_print_phone($address->phone,$address->country_code,$address->id,$object->id,'AC_TEL');
1232  print '</td>';
1233  print '<td>';
1234  print dol_print_phone($address->fax,$address->country_code,$address->id,$object->id,'AC_FAX');
1235  print '</td>';
1236 
1237  if ($user->rights->societe->creer)
1238  {
1239  print '<td align="right">';
1240  print '<a href="'.DOL_URL_ROOT.'/comm/address.php?action=edit&amp;id='.$address->id.'&amp;socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">';
1241  print img_edit();
1242  print '</a></td>';
1243  }
1244 
1245  print "</tr>\n";
1246  }
1247  }
1248  //else
1249  //{
1250  //print '<tr class="oddeven">';
1251  //print '<td>'.$langs->trans("NoAddressYetDefined").'</td>';
1252  //print "</tr>\n";
1253  //}
1254  print "\n</table>\n";
1255 
1256  print "<br>\n";
1257 
1258  return $num;
1259 }
1260 
1273 function show_actions_todo($conf,$langs,$db,$filterobj,$objcon='',$noprint=0,$actioncode='')
1274 {
1275  global $user,$conf;
1276 
1277  $out = show_actions_done($conf,$langs,$db,$filterobj,$objcon,1,$actioncode, 'todo');
1278 
1279  if ($noprint) return $out;
1280  else print $out;
1281 }
1282 
1300 function show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep,a.id', $sortorder='DESC')
1301 {
1302  global $user,$conf;
1303  global $form;
1304 
1305  global $param;
1306 
1307  dol_include_once('/comm/action/class/actioncomm.class.php');
1308 
1309  // Check parameters
1310  if (! is_object($filterobj) && ! is_object($objcon)) dol_print_error('','BadParameter');
1311 
1312  $out='';
1313  $histo=array();
1314  $numaction = 0 ;
1315  $now=dol_now('tzuser');
1316 
1317  if (! empty($conf->agenda->enabled))
1318  {
1319  // Recherche histo sur actioncomm
1320  if (is_object($objcon) && $objcon->id) {
1321  $sql = "SELECT DISTINCT a.id, a.label,";
1322  }
1323  else
1324  {
1325  $sql = "SELECT a.id, a.label,";
1326  }
1327  $sql.= " a.datep as dp,";
1328  $sql.= " a.datep2 as dp2,";
1329  $sql.= " a.note, a.percent,";
1330  $sql.= " a.fk_element, a.elementtype,";
1331  $sql.= " a.fk_user_author, a.fk_contact,";
1332  $sql.= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1333  $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";
1334  if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql.= ", sp.lastname, sp.firstname";
1335  elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql.= ", m.lastname, m.firstname";
1336  elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql.= ", o.ref";
1337  elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql.= ", o.ref";
1338  $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1339  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1340  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1341 
1342  if (is_object($objcon) && $objcon->id) {
1343  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1344  $sql.= " AND r.element_type = '" . $db->escape($objcon->table_element) . "' AND r.fk_element = " . $objcon->id;
1345  }
1346 
1347  if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1348  elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1349  $sql.= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1350  $sql.= " ON er.resource_type = 'dolresource'";
1351  $sql.= " AND er.element_id = a.id";
1352  $sql.= " AND er.resource_id = ".$filterobj->id;
1353  }
1354  elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql.= ", ".MAIN_DB_PREFIX."adherent as m";
1355  elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1356  elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql.= ", ".MAIN_DB_PREFIX."product as o";
1357 
1358  $sql.= " WHERE a.entity IN (".getEntity('agenda').")";
1359  if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) $sql.= " AND a.fk_soc = ".$filterobj->id;
1360  elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) $sql.= " AND a.fk_project = ".$filterobj->id;
1361  elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent')
1362  {
1363  $sql.= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1364  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1365  }
1366  elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur')
1367  {
1368  $sql.= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1369  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1370  }
1371  elseif (is_object($filterobj) && get_class($filterobj) == 'Product')
1372  {
1373  $sql.= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1374  if ($filterobj->id) $sql.= " AND a.fk_element = ".$filterobj->id;
1375  }
1376 
1377  // Condition on actioncode
1378  if (! empty($actioncode))
1379  {
1380  if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
1381  {
1382  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND c.type != 'systemauto'";
1383  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND c.type = 'systemauto'";
1384  else
1385  {
1386  if ($actioncode == 'AC_OTH') $sql.= " AND c.type != 'systemauto'";
1387  elseif ($actioncode == 'AC_OTH_AUTO') $sql.= " AND c.type = 'systemauto'";
1388  }
1389  }
1390  else
1391  {
1392  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND c.type != 'systemauto'";
1393  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND c.type = 'systemauto'";
1394  else $sql.= " AND c.code = '".$db->escape($actioncode)."'";
1395  }
1396  }
1397  if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1398  elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1399  if (is_array($filters) && $filters['search_agenda_label']) $sql.= natural_search('a.label', $filters['search_agenda_label']);
1400 
1401  //TODO Add limit for thirdparty in contexte very all result
1402  $sql.= $db->order($sortfield, $sortorder);
1403  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1404  $resql=$db->query($sql);
1405  if ($resql)
1406  {
1407  $i = 0 ;
1408  $num = $db->num_rows($resql);
1409 
1410  while ($i < $num)
1411  {
1412  $obj = $db->fetch_object($resql);
1413 
1414  $contactaction = new ActionComm($db);
1415  $contactaction->id=$obj->id;
1416  $result = $contactaction->fetchResources();
1417  if ($result<0) {
1418  dol_print_error($db);
1419  setEventMessage("company.lib::show_actions_done Error fetch ressource",'errors');
1420  }
1421 
1422  //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
1423  //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
1424  $tododone='';
1425  if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) $tododone='todo';
1426 
1427  $histo[$numaction]=array(
1428  'type'=>'action',
1429  'tododone'=>$tododone,
1430  'id'=>$obj->id,
1431  'datestart'=>$db->jdate($obj->dp),
1432  'dateend'=>$db->jdate($obj->dp2),
1433  'note'=>$obj->label,
1434  'percent'=>$obj->percent,
1435 
1436  'userid'=>$obj->user_id,
1437  'login'=>$obj->user_login,
1438  'userfirstname'=>$obj->user_firstname,
1439  'userlastname'=>$obj->user_lastname,
1440  'userphoto'=>$obj->user_photo,
1441 
1442  'contact_id'=>$obj->fk_contact,
1443  'socpeopleassigned' => $contactaction->socpeopleassigned,
1444  'lastname'=>$obj->lastname,
1445  'firstname'=>$obj->firstname,
1446  'fk_element'=>$obj->fk_element,
1447  'elementtype'=>$obj->elementtype,
1448  // Type of event
1449  'acode'=>$obj->acode,
1450  'alabel'=>$obj->alabel,
1451  'libelle'=>$obj->alabel, // deprecated
1452  'apicto'=>$obj->apicto
1453  );
1454 
1455  $numaction++;
1456  $i++;
1457  }
1458  }
1459  else
1460  {
1461  dol_print_error($db);
1462  }
1463  }
1464 
1465  // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
1466  if (! empty($conf->mailing->enabled) && ! empty($objcon->email))
1467  {
1468  $langs->load("mails");
1469 
1470  $sql = "SELECT m.rowid as id, mc.date_envoi as da, m.titre as note, '100' as percentage,";
1471  $sql.= " 'AC_EMAILING' as acode,";
1472  $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"; // User that valid action
1473  $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
1474  $sql.= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
1475  $sql.= " AND mc.statut = 1";
1476  $sql.= " AND u.rowid = m.fk_user_valid";
1477  $sql.= " AND mc.fk_mailing=m.rowid";
1478  $sql.= " ORDER BY mc.date_envoi DESC, m.rowid DESC";
1479 
1480  dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
1481  $resql=$db->query($sql);
1482  if ($resql)
1483  {
1484  $i = 0 ;
1485  $num = $db->num_rows($resql);
1486 
1487  while ($i < $num)
1488  {
1489  $obj = $db->fetch_object($resql);
1490  $histo[$numaction]=array(
1491  'type'=>'mailing',
1492  'tododone'=>'done',
1493  'id'=>$obj->id,
1494  'datestart'=>$db->jdate($obj->da),
1495  'dateend'=>$db->jdate($obj->da),
1496  'note'=>$obj->note,
1497  'percent'=>$obj->percentage,
1498  'acode'=>$obj->acode,
1499 
1500  'userid'=>$obj->user_id,
1501  'login'=>$obj->user_login,
1502  'userfirstname'=>$obj->user_firstname,
1503  'userlastname'=>$obj->user_lastname,
1504  'userphoto'=>$obj->user_photo
1505  );
1506  $numaction++;
1507  $i++;
1508  }
1509  $db->free($resql);
1510  }
1511  else
1512  {
1513  dol_print_error($db);
1514  }
1515  }
1516 
1517  if (! empty($conf->agenda->enabled) || (! empty($conf->mailing->enabled) && ! empty($objcon->email)))
1518  {
1519  $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
1520 
1521  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1522  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1523  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
1524  require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1525 
1526  $formactions=new FormActions($db);
1527 
1528  $actionstatic=new ActionComm($db);
1529  $userstatic=new User($db);
1530  $contactstatic = new Contact($db);
1531 
1532  $out.='<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
1533  if ($objcon && get_class($objcon) == 'Contact' &&
1534  (is_null($filterobj) || get_class($filterobj) == 'Societe'))
1535  {
1536  $out.='<input type="hidden" name="id" value="'.$objcon->id.'" />';
1537  }
1538  else
1539  {
1540  $out.='<input type="hidden" name="id" value="'.$filterobj->id.'" />';
1541  }
1542  if ($filterobj && get_class($filterobj) == 'Societe') $out.='<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
1543 
1544  $out.="\n";
1545 
1546  $out.='<div class="div-table-responsive-no-min">';
1547  $out.='<table class="noborder" width="100%">';
1548 
1549  $out.='<tr class="liste_titre">';
1550  if ($donetodo)
1551  {
1552  $out.='<td class="liste_titre"></td>';
1553  }
1554  $out.='<td class="liste_titre"></td>';
1555  $out.='<td class="liste_titre"></td>';
1556  $out.='<td class="liste_titre">';
1557  $out.=$formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:-1, 0, 0, 1);
1558  $out.='</td>';
1559  $out.='<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
1560  $out.='<td class="liste_titre"></td>';
1561  $out.='<td class="liste_titre"></td>';
1562  $out.='<td class="liste_titre"></td>';
1563  $out.='<td class="liste_titre"></td>';
1564  // Action column
1565  $out.='<td class="liste_titre" align="middle">';
1566  $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
1567  $out.=$searchpicto;
1568  $out.='</td>';
1569  $out.='</tr>';
1570 
1571  $out.='<tr class="liste_titre">';
1572  if ($donetodo)
1573  {
1574  $tmp='';
1575  if (get_class($filterobj) == 'Societe') $tmp.='<a href="'.DOL_URL_ROOT.'/comm/action/list.php?socid='.$filterobj->id.'&amp;status=done">';
1576  $tmp.=($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
1577  $tmp.=($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
1578  $tmp.=($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
1579  //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
1580  if (get_class($filterobj) == 'Societe') $tmp.='</a>';
1581  $out.=getTitleFieldOfList($tmp);
1582  }
1583  $out.=getTitleFieldOfList($langs->trans("Ref"), 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
1584  $out.=getTitleFieldOfList($langs->trans("Owner"));
1585  $out.=getTitleFieldOfList($langs->trans("Type"));
1586  $out.=getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1587  $out.=getTitleFieldOfList($langs->trans("Date"), 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, 'align="center"', $sortfield, $sortorder);
1588  $out.=getTitleFieldOfList('');
1589  $out.=getTitleFieldOfList($langs->trans("ActionOnContact"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
1590  $out.=getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, 'align="center"', $sortfield, $sortorder);
1591  $out.=getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
1592  $out.='</tr>';
1593 
1594  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
1595  $caction=new CActionComm($db);
1596  $arraylist=$caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0), '', 1);
1597 
1598  foreach ($histo as $key=>$value)
1599  {
1600  $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
1601 
1602  $actionstatic->type_picto=$histo[$key]['apicto'];
1603  $actionstatic->type_code=$histo[$key]['acode'];
1604 
1605  $out.='<tr class="oddeven">';
1606 
1607  // Done or todo
1608  if ($donetodo)
1609  {
1610  $out.='<td class="nowrap">';
1611  $out.='</td>';
1612  }
1613 
1614  // Ref
1615  $out.='<td class="nowrap">';
1616  $out.=$actionstatic->getNomUrl(1, -1);
1617  $out.='</td>';
1618 
1619  // Author of event
1620  $out.='<td class="tdoverflowmax100">';
1621  //$userstatic->id=$histo[$key]['userid'];
1622  //$userstatic->login=$histo[$key]['login'];
1623  //$out.=$userstatic->getLoginUrl(1);
1624  if ($histo[$key]['userid'] > 0)
1625  {
1626  $userstatic->fetch($histo[$key]['userid']);
1627  $out.=$userstatic->getNomUrl(-1);
1628  }
1629  $out.='</td>';
1630 
1631  // Type
1632  $out.='<td>';
1633  if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
1634  {
1635  if ($actionstatic->type_picto) print img_picto('', $actionstatic->type_picto);
1636  else {
1637  if ($actionstatic->type_code == 'AC_RDV') $out.= img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
1638  elseif ($actionstatic->type_code == 'AC_TEL') $out.= img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
1639  elseif ($actionstatic->type_code == 'AC_FAX') $out.= img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
1640  elseif ($actionstatic->type_code == 'AC_EMAIL') $out.= img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
1641  elseif ($actionstatic->type_code == 'AC_INT') $out.= img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
1642  elseif (! preg_match('/_AUTO/', $actionstatic->type_code)) $out.= img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
1643  }
1644  }
1645  $labeltype=$actionstatic->type_code;
1646  if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) $labeltype='AC_OTH';
1647  if (! empty($arraylist[$labeltype])) $labeltype=$arraylist[$labeltype];
1648  $out.= dol_trunc($labeltype,28);
1649  $out.='</td>';
1650 
1651  // Title
1652  $out.='<td>';
1653  if (isset($histo[$key]['type']) && $histo[$key]['type']=='action')
1654  {
1655  $transcode=$langs->trans("Action".$histo[$key]['acode']);
1656  $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:$histo[$key]['alabel']);
1657  //$actionstatic->libelle=$libelle;
1658  $libelle=$histo[$key]['note'];
1659  $actionstatic->id=$histo[$key]['id'];
1660  $out.=dol_trunc($libelle,120);
1661  }
1662  if (isset($histo[$key]['type']) && $histo[$key]['type']=='mailing')
1663  {
1664  $out.='<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"),"email").' ';
1665  $transcode=$langs->trans("Action".$histo[$key]['acode']);
1666  $libelle=($transcode!="Action".$histo[$key]['acode']?$transcode:'Send mass mailing');
1667  $out.=dol_trunc($libelle,120);
1668  }
1669  $out.='</td>';
1670 
1671  // Date
1672  $out.='<td class="center nowrap">';
1673  $out.=dol_print_date($histo[$key]['datestart'],'dayhour');
1674  if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart'])
1675  {
1676  $tmpa=dol_getdate($histo[$key]['datestart'],true);
1677  $tmpb=dol_getdate($histo[$key]['dateend'],true);
1678  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $out.='-'.dol_print_date($histo[$key]['dateend'],'hour');
1679  else $out.='-'.dol_print_date($histo[$key]['dateend'],'dayhour');
1680  }
1681  $late=0;
1682  if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1683  if ($histo[$key]['percent'] == 0 && ! $histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1684  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) $late=1;
1685  if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && ! $histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) $late=1;
1686  if ($late) $out.=img_warning($langs->trans("Late")).' ';
1687  $out.="</td>\n";
1688 
1689  // Title of event
1690  //$out.='<td>'.dol_trunc($histo[$key]['note'], 40).'</td>';
1691 
1692  // Objet lie
1693  $out.='<td>';
1694  if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element']))
1695  {
1696  $out.=dolGetElementUrl($histo[$key]['fk_element'],$histo[$key]['elementtype'],1);
1697  }
1698  else $out.='&nbsp;';
1699  $out.='</td>';
1700 
1701  // Contact pour cette action
1702  if (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0)
1703  {
1704  $contactstatic->lastname=$histo[$key]['lastname'];
1705  $contactstatic->firstname=$histo[$key]['firstname'];
1706  $contactstatic->id=$histo[$key]['contact_id'];
1707  $out.='<td width="120">'.$contactstatic->getNomUrl(1,'',10).'</td>';
1708  } elseif (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
1709  $out .= '<td>';
1710  foreach ( $histo[$key]['socpeopleassigned'] as $cid => $Tab ) {
1711  $contact = new Contact($db);
1712  $result = $contact->fetch($cid);
1713 
1714  if ($result < 0)
1715  dol_print_error($db, $contact->error);
1716 
1717  if ($result > 0) {
1718  $out .= $contact->getNomUrl(1);
1719  if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
1720  if (! empty($contact->phone_pro))
1721  $out .= '(' . dol_print_phone($contact->phone_pro) . ')';
1722  }
1723  $out .= '<div class="paddingright"></div>';
1724  }
1725  }
1726  $out .= '</td>';
1727  }
1728  else {
1729  $out.='<td>&nbsp;</td>';
1730  }
1731 
1732  // Status
1733  $out.='<td class="nowrap" align="center">'.$actionstatic->LibStatut($histo[$key]['percent'],3,0,$histo[$key]['datestart']).'</td>';
1734 
1735  // Actions
1736  $out.='<td></td>';
1737 
1738  $out.="</tr>\n";
1739  $i++;
1740  }
1741  $out.="</table>\n";
1742  $out.="</div>\n";
1743  }
1744 
1745  $out.='</form>';
1746 
1747  if ($noprint) return $out;
1748  else print $out;
1749 }
1750 
1760 function show_subsidiaries($conf,$langs,$db,$object)
1761 {
1762  global $user;
1763 
1764  $i=-1;
1765 
1766  $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";
1767  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
1768  $sql.= " WHERE s.parent = ".$object->id;
1769  $sql.= " AND s.entity IN (".getEntity('societe').")";
1770  $sql.= " ORDER BY s.nom";
1771 
1772  $result = $db->query($sql);
1773  $num = $db->num_rows($result);
1774 
1775  if ($num)
1776  {
1777  $socstatic = new Societe($db);
1778 
1779  print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
1780  print "\n".'<table class="noborder" width="100%">'."\n";
1781 
1782  print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
1783  print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
1784  print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
1785  print "<td>&nbsp;</td>";
1786  print "</tr>";
1787 
1788  $i=0;
1789 
1790  while ($i < $num)
1791  {
1792  $obj = $db->fetch_object($result);
1793 
1794  $socstatic->id = $obj->rowid;
1795  $socstatic->name = $obj->name;
1796  $socstatic->name_alias = $obj->name_alias;
1797  $socstatic->email = $obj->email;
1798  $socstatic->code_client = $obj->code_client;
1799  $socstatic->code_fournisseur = $obj->code_client;
1800  $socstatic->code_compta = $obj->code_compta;
1801  $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1802  $socstatic->email = $obj->email;
1803  $socstatic->canvas = $obj->canvas;
1804  $socstatic->client = $obj->client;
1805  $socstatic->fournisseur = $obj->fournisseur;
1806 
1807  print '<tr class="oddeven">';
1808 
1809  print '<td>';
1810  print $socstatic->getNomUrl(1);
1811  print '</td>';
1812 
1813  print '<td>'.$obj->address.'</td>';
1814  print '<td>'.$obj->zip.'</td>';
1815  print '<td>'.$obj->town.'</td>';
1816  print '<td>'.$obj->code_client.'</td>';
1817 
1818  print '<td align="center">';
1819  print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$obj->rowid.'&amp;action=edit">';
1820  print img_edit();
1821  print '</a></td>';
1822 
1823  print "</tr>\n";
1824  $i++;
1825  }
1826  print "\n</table>\n";
1827  }
1828 
1829  print "<br>\n";
1830 
1831  return $i;
1832 }
1833 
1834 
1835 
Class to manage different types of events.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage building of HTML components.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') else if($action=='specimen') else if($action=='setmodel') else if($action=='del') else if($action=='setdoc') $formactions
View.
picto_from_langcode($codelang, $moreatt='')
Return img flag of country for a language code or country code.
Class to manage agenda events (actions)
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...
Class to manage contact/addresses.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
show_addresses($conf, $langs, $db, $object, $backtopage='')
Show html area for list of addresses.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) TODO Add a field into ...
Class to manage Dolibarr users.
Definition: user.class.php:41
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='')
Show html area with actions to do.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class for SocieteAccount.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
Class to manage projects.
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='')
Get title line of an array.
societe_admin_prepare_head()
Return array head with list of tabs to view object informations.
show_contacts($conf, $langs, $db, $object, $backtopage='')
Show html area for list of contacts.
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...
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:59
liste_contact($statut=-1, $source='external', $list=0, $code='')
Get array of all contacts for an object.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_now($mode='gmt')
Return date for now.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
societe_prepare_head2($object)
Return array of tabs to used on page.
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
Class to manage addresses.
show_actions_done($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions (done or not, ignore the name of function)
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
currency_name($code_iso, $withcode='', $outputlangs=null)
Return label of currency or code+label.