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