dolibarr 23.0.3
company.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4 * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2013 Christophe Battarel <contact@altairis.fr>
9 * Copyright (C) 2013-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2015-2025 Frédéric France <frederic.france@free.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-2024 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 * or see https://www.gnu.org/
29 */
30
44{
45 global $db, $langs, $conf, $user;
46 global $hookmanager;
47
48 $h = 0;
49 $head = array();
50
51 $head[$h][0] = DOL_URL_ROOT . '/societe/card.php?socid=' . $object->id;
52 $head[$h][1] = $langs->trans("ThirdParty");
53 $head[$h][2] = 'card';
54 $h++;
55
56
57 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $user->hasRight('societe', 'contact', 'lire')) {
58 //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
59 $nbContact = 0;
60 // Enable caching of thirdrparty count Contacts
61 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
62 $cachekey = 'count_contacts_thirdparty_' . $object->id;
63 $dataretrieved = dol_getcache($cachekey);
64
65 if (!is_null($dataretrieved)) {
66 $nbContact = $dataretrieved;
67 } else {
68 $sql = "SELECT COUNT(p.rowid) as nb";
69 $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as p";
70 // Add table from hooks
71 $parameters = array('contacttab' => true);
72 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
73 $sql .= $hookmanager->resPrint;
74 $sql .= " WHERE p.fk_soc = " . ((int) $object->id);
75 $sql .= " AND p.entity IN (" . getEntity($object->element) . ")";
76 // Add where from hooks
77 $parameters = array('contacttab' => true);
78 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
79 $sql .= $hookmanager->resPrint;
80 $resql = $db->query($sql);
81 if ($resql) {
82 $obj = $db->fetch_object($resql);
83 $nbContact = $obj->nb;
84 }
85
86 dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result.
87 }
88
89 $head[$h][0] = DOL_URL_ROOT . '/societe/contact.php?socid=' . $object->id;
90 $head[$h][1] = $langs->trans('ContactsAddresses');
91 if ($nbContact > 0) {
92 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>';
93 }
94 $head[$h][2] = 'contact';
95 $h++;
96 }
97 if (getDolGlobalString('MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES')) {
98 // Some features may be unstable with this option, like permissions rules, import contact, ...
99 $head[$h][0] = DOL_URL_ROOT . '/societe/societecontact.php?socid=' . $object->id;
100 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
101 $head[$h][1] = $langs->trans("ContactsAddressesExt");
102 if ($nbContact > 0) {
103 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>';
104 }
105 $head[$h][2] = 'contactext';
106 $h++;
107 }
108
109 if ($object->client == 1 || $object->client == 2 || $object->client == 3) {
110 $head[$h][0] = DOL_URL_ROOT . '/comm/card.php?socid=' . $object->id;
111 $head[$h][1] = '';
112 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && ($object->client == 2 || $object->client == 3)) {
113 $head[$h][1] .= $langs->trans("Prospect");
114 }
115 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && $object->client == 3) {
116 $head[$h][1] .= ' | ';
117 }
118 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && ($object->client == 1 || $object->client == 3)) {
119 $head[$h][1] .= $langs->trans("Customer");
120 }
121 $head[$h][2] = 'customer';
122 $h++;
123
124 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
125 $langs->load("products");
126 // price
127 $head[$h][0] = DOL_URL_ROOT . '/societe/price.php?socid=' . $object->id;
128 $head[$h][1] = $langs->trans("CustomerPrices");
129 $head[$h][2] = 'price';
130 $h++;
131 }
132 }
133 $supplier_module_enabled = 0;
134 if (isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
135 $supplier_module_enabled = 1;
136 }
137 if ($supplier_module_enabled == 1 && $object->fournisseur && $user->hasRight('fournisseur', 'lire')) {
138 $head[$h][0] = DOL_URL_ROOT . '/fourn/card.php?socid=' . $object->id;
139 $head[$h][1] = $langs->trans("Supplier");
140 $head[$h][2] = 'supplier';
141 $h++;
142 }
143
144 if (isModEnabled('accounting') && getDolGlobalString('ACCOUNTING_ENABLE_TABONTHIRDPARTY') && ($user->hasRight('accounting', 'mouvements', 'lire'))) {
145 // link to customer account by default
146 if (!empty($object->code_compta_client)) {
147 $subledger_start_account = $subledger_end_account = $object->code_compta_client;
148 $mode = 'customer';
149 } elseif (!empty($object->code_compta_fournisseur)) {
150 $subledger_start_account = $subledger_end_account = $object->code_compta_fournisseur;
151 $mode = 'supplier';
152 } else {
153 $subledger_start_account = $subledger_end_account = '';
154 $mode = 'customer';
155 }
156
157 $head[$h][0] = DOL_URL_ROOT . '/accountancy/bookkeeping/listbyaccount.php?socid=' . $object->id . '&mode=' . $mode . '&type=sub&search_accountancy_code_start=' . $subledger_start_account . '&search_accountancy_code_end=' . $subledger_end_account;
158 $head[$h][1] = $langs->trans("Accounting");
159 $head[$h][2] = 'accounting';
160 $h++;
161 }
162
163 if (isModEnabled('project') && ($user->hasRight('projet', 'lire'))) {
164 $nbProject = 0;
165 // Enable caching of thirdrparty count projects
166 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
167 $cachekey = 'count_projects_thirdparty_' . $object->id;
168 $dataretrieved = dol_getcache($cachekey);
169
170 if (!is_null($dataretrieved)) {
171 $nbProject = $dataretrieved;
172 } else {
173 $sql = "SELECT COUNT(n.rowid) as nb";
174 $sql .= " FROM " . MAIN_DB_PREFIX . "projet as n";
175 $sql .= " WHERE fk_soc = " . ((int) $object->id);
176 $sql .= " AND entity IN (" . getEntity('project') . ")";
177 $resql = $db->query($sql);
178 if ($resql) {
179 $obj = $db->fetch_object($resql);
180 $nbProject = $obj->nb;
181 } else {
182 dol_print_error($db);
183 }
184 dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
185 }
186 $head[$h][0] = DOL_URL_ROOT . '/societe/project.php?socid=' . $object->id;
187 $head[$h][1] = $langs->trans("Projects");
188 if ($nbProject > 0) {
189 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbProject . '</span>';
190 }
191 $head[$h][2] = 'project';
192 $h++;
193 }
194
195 // Tab to link resources
196 if (isModEnabled('resource') && getDolGlobalString('RESOURCE_ON_THIRDPARTIES')) {
197 $head[$h][0] = DOL_URL_ROOT . '/resource/element_resource.php?element=societe&element_id=' . $object->id;
198 $head[$h][1] = $langs->trans("Resources");
199 $head[$h][2] = 'resources';
200 $h++;
201 }
202
203 // Related items
204 if ((isModEnabled('order') || isModEnabled('propal') || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
205 && !getDolGlobalString('THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB')
206 ) {
207 $head[$h][0] = DOL_URL_ROOT . '/societe/consumption.php?socid=' . $object->id;
208 $head[$h][1] = $langs->trans("Referers");
209 $head[$h][2] = 'consumption';
210 $h++;
211 }
212
213 // Bank accounts
214 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
215 $nbBankAccount = 0;
216 $foundonexternalonlinesystem = 0;
217 $langs->load("bills");
218
219 $title = $langs->trans("PaymentModes");
220
221 $servicestatus = 0;
222 if (isModEnabled('stripe')) {
223 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha')*/) {
224 $servicestatus = 1;
225 }
226
227 include_once DOL_DOCUMENT_ROOT . '/societe/class/societeaccount.class.php';
228 $societeaccount = new SocieteAccount($db);
229 $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
230 if ($stripecu) {
231 $foundonexternalonlinesystem++;
232 }
233 }
234
235 $sql = "SELECT COUNT(n.rowid) as nb";
236 $sql .= " FROM " . MAIN_DB_PREFIX . "societe_rib as n";
237 $sql .= " WHERE n.fk_soc = " . ((int) $object->id);
238 if (!isModEnabled('stripe')) {
239 $sql .= " AND (n.stripe_card_ref IS NULL OR n.stripe_card_ref ='')";
240 } else {
241 $sql .= " AND (n.stripe_card_ref IS NULL OR (n.stripe_card_ref IS NOT NULL AND n.status = " . ((int) $servicestatus) . "))";
242 }
243
244 $resql = $db->query($sql);
245 if ($resql) {
246 $obj = $db->fetch_object($resql);
247 $nbBankAccount = $obj->nb;
248 } else {
249 dol_print_error($db);
250 }
251
252 //if (isModEnabled('stripe') && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
253
254 $head[$h][0] = DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . urlencode((string) ($object->id));
255 $head[$h][1] = $title;
256 if ($foundonexternalonlinesystem) {
257 $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
258 } elseif ($nbBankAccount > 0) {
259 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbBankAccount . '</span>';
260 }
261 $head[$h][2] = 'rib';
262 $h++;
263 }
264
265 if ((isModEnabled('website') || isModEnabled('webportal')) && $user->hasRight('societe', 'lire')) {
266 $site_filter_list = array();
267 if (isModEnabled('website')) {
268 $site_filter_list[] = 'dolibarr_website';
269 }
270 if (isModEnabled('webportal')) {
271 $site_filter_list[] = 'dolibarr_portal';
272 }
273
274 $head[$h][0] = DOL_URL_ROOT . '/societe/website.php?id=' . urlencode((string) ($object->id));
275 $head[$h][1] = $langs->trans("WebSiteAccounts");
276 $nbNote = 0;
277 $sql = "SELECT COUNT(n.rowid) as nb";
278 $sql .= " FROM " . MAIN_DB_PREFIX . "societe_account as n";
279 $sql .= " WHERE fk_soc = " . ((int) $object->id);
280 $sql .= " AND entity IN (" . getEntity('thirdpartyaccount') . ")";
281 if (!empty($site_filter_list)) {
282 $sql .= " AND n.site IN (" . $db->sanitize("'" . implode("','", $site_filter_list) . "'", 1) . ")";
283 }
284 $resql = $db->query($sql);
285 if ($resql) {
286 $obj = $db->fetch_object($resql);
287 $nbNote = $obj->nb;
288 } else {
289 dol_print_error($db);
290 }
291 if ($nbNote > 0) {
292 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
293 }
294 $head[$h][2] = 'website';
295 $h++;
296 }
297
298 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
299 if ($user->hasRight('partnership', 'read')) {
300 $langs->load("partnership");
301 $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
302 $head[$h][0] = DOL_URL_ROOT . '/partnership/partnership_list.php?socid=' . $object->id;
303 $head[$h][1] = $langs->trans("Partnerships");
304 $nbNote = 0;
305 $sql = "SELECT COUNT(n.rowid) as nb";
306 $sql .= " FROM " . MAIN_DB_PREFIX . "partnership as n";
307 $sql .= " WHERE fk_soc = " . ((int) $object->id);
308 $sql .= " AND entity IN (" . getEntity('partnership') . ")";
309 $resql = $db->query($sql);
310 if ($resql) {
311 $obj = $db->fetch_object($resql);
312 $nbNote = $obj->nb;
313 } else {
314 dol_print_error($db);
315 }
316 if ($nbNote > 0) {
317 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
318 }
319 $head[$h][2] = 'partnerships';
320 if ($nbPartnership > 0) {
321 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbPartnership . '</span>';
322 }
323 $h++;
324 }
325 }
326
327 // Notifications
328 if (isModEnabled('ticket') && $user->hasRight("ticket", "read")) {
329 //$langs->load('ticket');
330 $nbTicket = 0;
331 // Enable caching of thirdparty count notifications
332 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
333 $cachekey = 'count_ticket_thirdparty_' . $object->id;
334 $nbticketretreived = dol_getcache($cachekey);
335 if (!is_null($nbticketretreived)) {
336 $nbTicket = $nbticketretreived;
337 } else {
338 // List of notifications enabled for contacts of the third party
339 $sql = "SELECT COUNT(t.rowid) as nb";
340 $sql .= " FROM " . MAIN_DB_PREFIX . "ticket as t";
341 $sql .= " WHERE t.fk_soc = " . ((int) $object->id);
342 $resql = $db->query($sql);
343 if ($resql) {
344 $obj = $db->fetch_object($resql);
345 $nbTicket = $obj->nb;
346 } else {
347 dol_print_error($db);
348 }
349 dol_setcache($cachekey, $nbTicket, 120); // If setting cache fails, this is not a problem, so we do not test result.
350 }
351
352 $head[$h][0] = DOL_URL_ROOT . '/ticket/list.php?socid=' . urlencode((string) ($object->id));
353 $head[$h][1] = $langs->trans("Tickets");
354 if ($nbTicket > 0) {
355 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbTicket . '</span>';
356 }
357 $head[$h][2] = 'ticket';
358 $h++;
359 }
360
361
362 // Show more tabs from modules
363 // Entries must be declared in modules descriptor with line
364 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
365 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
366 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'core');
367
368 if ($user->socid == 0) {
369 // Notifications
370 if (isModEnabled('notification')) {
371 $langs->load('mails');
372 $nbNotif = 0;
373 // Enable caching of thirdparty count notifications
374 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
375 $cachekey = 'count_notifications_thirdparty_' . $object->id;
376 $dataretrieved = dol_getcache($cachekey);
377 if (!is_null($dataretrieved)) {
378 $nbNotif = $dataretrieved;
379 } else {
380 // List of notifications enabled for contacts of the third party
381 $sql = "SELECT COUNT(n.rowid) as nb";
382 $sql .= " FROM " . MAIN_DB_PREFIX . "c_action_trigger as a,";
383 $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
384 $sql .= " " . MAIN_DB_PREFIX . "socpeople as c";
385 $sql .= " WHERE a.rowid = n.fk_action";
386 $sql .= " AND c.rowid = n.fk_contact";
387 $sql .= " AND c.fk_soc = " . ((int) $object->id);
388 $resql = $db->query($sql);
389 if ($resql) {
390 $obj = $db->fetch_object($resql);
391 $nbNotif = $obj->nb;
392 } else {
393 dol_print_error($db);
394 }
395 dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
396 }
397
398 $head[$h][0] = DOL_URL_ROOT . '/societe/notify/card.php?socid=' . urlencode((string) ($object->id));
399 $head[$h][1] = $langs->trans("Notifications");
400 if ($nbNotif > 0) {
401 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNotif . '</span>';
402 }
403 $head[$h][2] = 'notify';
404 $h++;
405 }
406
407 // Notes
408 $nbNote = 0;
409 if (!empty($object->note_private)) {
410 $nbNote++;
411 }
412 if (!empty($object->note_public)) {
413 $nbNote++;
414 }
415 $head[$h][0] = DOL_URL_ROOT . '/societe/note.php?id=' . urlencode((string) ($object->id));
416 $head[$h][1] = $langs->trans("Notes");
417 if ($nbNote > 0) {
418 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
419 }
420 $head[$h][2] = 'note';
421 $h++;
422
423 // Attached files and Links
424 $totalAttached = 0;
425 // Enable caching of thirdrparty count attached files and links
426 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
427 $cachekey = 'count_attached_thirdparty_' . $object->id;
428 $dataretrieved = dol_getcache($cachekey);
429 if (!is_null($dataretrieved)) {
430 $totalAttached = $dataretrieved;
431 } else {
432 require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
433 require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
434 $upload_dir = $conf->societe->multidir_output[$object->entity ?? $conf->entity] . "/" . $object->id;
435 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
436 $nbLinks = Link::count($db, $object->element, $object->id);
437 $totalAttached = $nbFiles + $nbLinks;
438 dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
439 }
440
441 $head[$h][0] = DOL_URL_ROOT . '/societe/document.php?socid=' . $object->id;
442 $head[$h][1] = $langs->trans("Documents");
443 if (($totalAttached) > 0) {
444 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($totalAttached) . '</span>';
445 }
446 $head[$h][2] = 'document';
447 $h++;
448 }
449
450 $head[$h][0] = DOL_URL_ROOT . '/societe/messaging.php?socid=' . $object->id;
451 $head[$h][1] = $langs->trans("Events");
452 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
453 $nbEvent = 0;
454 // Enable caching of thirdparty count actioncomm
455 require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
456 $cachekey = 'count_events_thirdparty_' . $object->id;
457 $dataretrieved = dol_getcache($cachekey);
458 if (!is_null($dataretrieved)) {
459 $nbEvent = $dataretrieved;
460 } else {
461 $sql = "SELECT COUNT(id) as nb";
462 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm";
463 $sql .= " WHERE fk_soc = " . ((int) $object->id);
464 $sql .= " AND entity IN (" . getEntity('agenda') . ")";
465 $resql = $db->query($sql);
466 if ($resql) {
467 $obj = $db->fetch_object($resql);
468 $nbEvent = $obj->nb;
469 } else {
470 dol_syslog('Failed to count actioncomm ' . $db->lasterror(), LOG_ERR);
471 }
472 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
473 }
474
475 $head[$h][1] .= '/';
476 $head[$h][1] .= $langs->trans("Agenda");
477 if ($nbEvent > 0) {
478 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>';
479 }
480 }
481 $head[$h][2] = 'agenda';
482 $h++;
483
484 // Show more tabs from modules
485 // Entries must be declared in modules descriptor with line
486 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
487 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
488 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'external');
489
490 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
491
492 return $head;
493}
494
495
503{
504 global $langs;
505 $h = 0;
506 $head = array();
507
508 $head[$h][0] = DOL_URL_ROOT . '/societe/card.php?socid=' . $object->id;
509 $head[$h][1] = $langs->trans("ThirdParty");
510 $head[$h][2] = 'company';
511 $h++;
512
513 $head[$h][0] = 'commerciaux.php?socid=' . $object->id;
514 $head[$h][1] = $langs->trans("SalesRepresentative");
515 $head[$h][2] = 'salesrepresentative';
516 $h++;
517
518 return $head;
519}
520
521
522
529{
530 global $langs, $conf, $db;
531
532 $extrafields = new ExtraFields($db);
533 $extrafields->fetch_name_optionals_label('societe');
534 $extrafields->fetch_name_optionals_label('socpeople');
535
536 $h = 0;
537 $head = array();
538
539 $head[$h][0] = DOL_URL_ROOT . '/societe/admin/societe.php';
540 $head[$h][1] = $langs->trans("Miscellaneous");
541 $head[$h][2] = 'general';
542 $h++;
543
544 // Show more tabs from modules
545 // Entries must be declared in modules descriptor with line
546 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
547 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
548 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
549
550 $head[$h][0] = DOL_URL_ROOT . '/societe/admin/societe_extrafields.php';
551 $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
552 $nbExtrafields = $extrafields->attributes['societe']['count'];
553 if ($nbExtrafields > 0) {
554 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
555 }
556 $head[$h][2] = 'attributes';
557 $h++;
558
559 $head[$h][0] = DOL_URL_ROOT . '/societe/admin/contact_extrafields.php';
560 $head[$h][1] = $langs->trans("ExtraFieldsContacts");
561 $nbExtrafields = $extrafields->attributes['socpeople']['count'];
562 if ($nbExtrafields > 0) {
563 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
564 }
565 $head[$h][2] = 'attributes_contacts';
566 $h++;
567
568 if (getDolGlobalString('MAIN_FEATURES_LEVEL') >= 1) {
569 $head[$h][0] = DOL_URL_ROOT . '/societe/admin/public_interface.php';
570 $head[$h][1] = $langs->trans("PublicUrl");
571 $head[$h][2] = 'publicurl';
572 $h++;
573 }
574
575 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
576
577 return $head;
578}
579
580
581
597function getCountry($searchkey, $withcode = '', $dbtouse = null, $outputlangs = null, $entconv = 1, $searchlabel = '')
598{
599 global $db, $langs;
600
601 $result = '';
602
603 // Check parameters
604 if (empty($searchkey) && empty($searchlabel)) {
605 if ($withcode === 'all') {
606 return array('id' => 0, 'code' => '', 'label' => '');
607 } else {
608 return '';
609 }
610 }
611 if (!is_object($dbtouse)) {
612 $dbtouse = $db;
613 }
614 if (!is_object($outputlangs)) {
615 $outputlangs = $langs;
616 }
617
618 $sql = "SELECT rowid, code, label FROM " . MAIN_DB_PREFIX . "c_country";
619 if (is_numeric($searchkey)) {
620 $sql .= " WHERE rowid = " . ((int) $searchkey);
621 } elseif (!empty($searchkey)) {
622 $sql .= " WHERE code = '" . $db->escape($searchkey) . "'";
623 } else {
624 $sql .= " WHERE label = '" . $db->escape($searchlabel) . "'";
625 }
626
627 $resql = $dbtouse->query($sql);
628 if ($resql) {
629 $obj = $dbtouse->fetch_object($resql);
630 if ($obj) {
631 $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
632 if (is_object($outputlangs)) {
633 $outputlangs->load("dict");
634 if ($entconv) {
635 $label = ($obj->code && ($outputlangs->trans("Country" . $obj->code) != "Country" . $obj->code)) ? $outputlangs->trans("Country" . $obj->code) : $label;
636 } else {
637 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country" . $obj->code) != "Country" . $obj->code)) ? $outputlangs->transnoentitiesnoconv("Country" . $obj->code) : $label;
638 }
639 }
640 if ($withcode == '1') {
641 $result = $label ? "$obj->code - $label" : "$obj->code";
642 } elseif ($withcode == '2') {
643 $result = $obj->code;
644 } elseif ($withcode == '3') {
645 $result = $obj->rowid;
646 } elseif ($withcode === 'all') {
647 $result = array('id' => $obj->rowid, 'code' => $obj->code, 'label' => $label);
648 } else {
649 $result = $label;
650 }
651 } else {
652 $result = 'NotDefined';
653 }
654 $dbtouse->free($resql);
655 return $result;
656 } else {
657 dol_print_error($dbtouse, '');
658 }
659 return 'Error';
660}
661
677function getState($id, $withcode = '0', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1)
678{
679 global $db, $langs;
680
681 if (!is_object($dbtouse)) {
682 $dbtouse = $db;
683 }
684
685 $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";
686 $sql .= " " . MAIN_DB_PREFIX . "c_departements as d, " . MAIN_DB_PREFIX . "c_regions as r," . MAIN_DB_PREFIX . "c_country as c";
687 $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=" . ((int) $id);
688 $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
689 $sql .= " ORDER BY c.code, d.code_departement";
690
691 dol_syslog("Company.lib::getState", LOG_DEBUG);
692 $resql = $dbtouse->query($sql);
693 if ($resql) {
694 $obj = $dbtouse->fetch_object($resql);
695 if ($obj) {
696 $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
697 if (is_object($outputlangs)) {
698 $outputlangs->load("dict");
699 if ($entconv) {
700 $label = ($obj->code && ($outputlangs->trans("State" . $obj->code) != "State" . $obj->code)) ? $outputlangs->trans("State" . $obj->code) : $label;
701 } else {
702 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State" . $obj->code) != "State" . $obj->code)) ? $outputlangs->transnoentitiesnoconv("State" . $obj->code) : $label;
703 }
704 }
705
706 if ($withcode == 1) {
707 if ($withregion == 1) {
708 return $label = $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
709 } else {
710 return $label = $obj->code . ' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
711 }
712 } elseif ($withcode == 2) {
713 if ($withregion == 1) {
714 return $label = $obj->region_name . ' - ' . ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
715 } else {
716 return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
717 }
718 } elseif ($withcode === 'all') {
719 if ($withregion == 1) {
720 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label, 'region_code' => $obj->region_code, 'region' => $obj->region_name);
721 } else {
722 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label);
723 }
724 } else {
725 if ($withregion == 1) {
726 return $label = $obj->region_name . ' - ' . $label;
727 } else {
728 return $label;
729 }
730 }
731 } else {
732 return $langs->transnoentitiesnoconv("NotDefined");
733 }
734 } else {
735 dol_print_error($dbtouse, '');
736 }
737
738 return '';
739}
740
749function currency_name($code_iso, $withcode = 0, $outputlangs = null)
750{
751 global $langs, $db;
752
753 if (empty($outputlangs)) {
754 $outputlangs = $langs;
755 }
756
757 $outputlangs->load("dict");
758
759 // If there is a translation, we can send immediately the label
760 if ($outputlangs->trans("Currency" . $code_iso) != "Currency" . $code_iso) {
761 return ($withcode ? $code_iso . ' - ' : '') . $outputlangs->trans("Currency" . $code_iso);
762 }
763
764 // If no translation, we read table to get label by default
765 $sql = "SELECT label FROM " . MAIN_DB_PREFIX . "c_currencies";
766 $sql .= " WHERE code_iso='" . $db->escape($code_iso) . "'";
767
768 $resql = $db->query($sql);
769 if ($resql) {
770 $num = $db->num_rows($resql);
771
772 if ($num) {
773 $obj = $db->fetch_object($resql);
774 $label = ($obj->label != '-' ? $obj->label : '');
775 if ($withcode) {
776 return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
777 } else {
778 return $label;
779 }
780 } else {
781 return $code_iso;
782 }
783 }
784 return 'ErrorWhenReadingCurrencyLabel';
785}
786
795{
796 global $conf, $db, $langs;
797
798 if (!$code) {
799 return '';
800 }
801
802 if (!empty($conf->cache["legalform_" . $langs->defaultlang . '_' . $code])) {
803 return $conf->cache["legalform_" . $langs->defaultlang . '_' . $code];
804 }
805
806 $sql = "SELECT libelle as label FROM " . MAIN_DB_PREFIX . "c_forme_juridique";
807 $sql .= " WHERE code = '" . $db->escape($code) . "'";
808
809 dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
810
811 $resql = $db->query($sql);
812 if ($resql) {
813 $num = $db->num_rows($resql);
814 if ($num) {
815 $obj = $db->fetch_object($resql);
816
817 $label = ($obj->label != '-' ? $obj->label : '');
818
819 $conf->cache["legalform_" . $langs->defaultlang . '_' . $code] = $label;
820
821 return $langs->trans($label);
822 } else {
823 return $langs->trans("NotDefined");
824 }
825 } else {
826 return 'Error ' . $db->lasterror();
827 }
828}
829
830
838{
839 // List of all country codes that are in europe for european vat rules
840 // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
841 global $conf, $db;
842 $country_code_in_EEC = array();
843
844 if (!empty($conf->cache['country_code_in_EEC'])) {
845 // Use of cache to reduce number of database requests
846 $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
847 } else {
848 $sql = "SELECT cc.code FROM " . MAIN_DB_PREFIX . "c_country as cc";
849 $sql .= " WHERE cc.eec = 1";
850
851 $resql = $db->query($sql);
852 if ($resql) {
853 $num = $db->num_rows($resql);
854 $i = 0;
855 while ($i < $num) {
856 $objp = $db->fetch_object($resql);
857 $country_code_in_EEC[] = $objp->code;
858 $i++;
859 }
860 } else {
861 dol_print_error($db);
862 }
863 $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
864 }
865 return $country_code_in_EEC;
866}
867
875{
876 if (empty($object->country_code)) {
877 return false;
878 }
879
880 $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
881
882 //print "dd".$object->country_code;
883 return in_array($object->country_code, $country_code_in_EEC);
884}
885
893{
894 // List of all country codes that are in Europe agreement for bank transferts
895 // List found on https://www.ecb.europa.eu/paym/integration/retail/sepa/html/index.en.html
896 global $conf, $db;
897 $country_code_in_SEPA = array();
898
899 if (!empty($conf->cache['country_code_in_SEPA'])) {
900 // Use of cache to reduce number of database requests
901 $country_code_in_SEPA = $conf->cache['country_code_in_SEPA'];
902 } else {
903 $sql = "SELECT cc.code FROM " . MAIN_DB_PREFIX . "c_country as cc";
904 $sql .= " WHERE cc.sepa = 1";
905
906 $resql = $db->query($sql);
907 if ($resql) {
908 $num = $db->num_rows($resql);
909 $i = 0;
910 while ($i < $num) {
911 $objp = $db->fetch_object($resql);
912 $country_code_in_SEPA[] = $objp->code;
913 $i++;
914 }
915 } else {
916 dol_print_error($db);
917 }
918 $conf->cache['country_code_in_SEPA'] = $country_code_in_SEPA;
919 }
920 return $country_code_in_SEPA;
921}
922
930{
931 if (empty($object->country_code)) {
932 return false;
933 }
934
935 $country_code_in_SEPA = getCountriesInSEPA(); // This make a database call but there is a cache done into $conf->cache['country_code_in_SEPA']
936
937 //print "dd".$object->country_code;
938 return in_array($object->country_code, $country_code_in_SEPA);
939}
940
941
955function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '', $massactionbutton = '')
956{
957 global $user, $action, $hookmanager, $form;
958 global $massaction, $arrayofselected, $arrayofmassactions;
959
960 $i = -1;
961
962 if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
963 $langs->load("projects");
964
965 $newcardbutton = '';
966 if ($user->hasRight('projet', 'creer') && empty($nocreatelink)) {
967 $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/projet/card.php?socid=' . $object->id . '&action=create&backtopage=' . urlencode($backtopage));
968 }
969
970 print "\n";
971 print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton . $morehtmlright, '', 0, '', '', $massactionbutton);
972
973 print '<div class="div-table-responsive">' . "\n";
974 print '<table class="noborder centpercent">';
975
976 $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_modification, p.budget_amount";
977 $sql .= ", cls.code as opp_status_code";
978 $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
979 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_lead_status as cls on p.fk_opp_status = cls.rowid";
980 $sql .= " WHERE p.fk_soc = " . ((int) $object->id);
981 $sql .= " AND p.entity IN (" . getEntity('project') . ")";
982 $sql .= " ORDER BY p.dateo DESC";
983
984 $result = $db->query($sql);
985 if ($result) {
986 $num = $db->num_rows($result);
987
988 print '<tr class="liste_titre">';
989 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
990 print '<td class="center">';
991 $selectedfields = (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
992 print $selectedfields;
993 print '</td>';
994 }
995 print '<td>' . $langs->trans("Ref") . '</td>';
996 print '<td>' . $langs->trans("Name") . '</td>';
997 print '<td class="center">' . $langs->trans("DateStart") . '</td>';
998 print '<td class="center">' . $langs->trans("DateEnd") . '</td>';
999 print '<td class="right">' . $langs->trans("OpportunityAmountShort") . '</td>';
1000 print '<td class="center">' . $langs->trans("OpportunityStatusShort") . '</td>';
1001 print '<td class="right">' . $langs->trans("OpportunityProbabilityShort") . '</td>';
1002 print '<td class="right">' . $langs->trans("Status") . '</td>';
1003 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1004 print '<td class="center">';
1005 $selectedfields = (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1006 print $selectedfields;
1007 print '</td>';
1008 }
1009 print '</tr>';
1010
1011 if ($num > 0) {
1012 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
1013
1014 $projecttmp = new Project($db);
1015
1016 $i = 0;
1017
1018 while ($i < $num) {
1019 $obj = $db->fetch_object($result);
1020 $projecttmp->fetch($obj->id);
1021
1022 // To verify role of users
1023 $userAccess = $projecttmp->restrictedProjectArea($user);
1024
1025 if ($user->hasRight('projet', 'lire') && $userAccess > 0) {
1026 print '<tr class="oddeven">';
1027
1028 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1029 print '<td class="nowrap center actioncolumn">';
1030 if ($massactionbutton || $massaction) {
1031 $selected = 0;
1032 if (in_array($obj->id, $arrayofselected)) {
1033 $selected = 1;
1034 }
1035 print '<input id="cb' . $obj->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
1036 }
1037 print '</td>';
1038 }
1039 // Ref
1040 print '<td class="nowraponall">';
1041 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:' . $_SERVER["PHP_SELF"] . '?socid=__SOCID__');
1042 print '</td>';
1043
1044 // Label
1045 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->title) . '">' . dol_escape_htmltag($obj->title) . '</td>';
1046 // Date start
1047 print '<td class="center">' . dol_print_date($db->jdate($obj->do), "day") . '</td>';
1048 // Date end
1049 print '<td class="center">' . dol_print_date($db->jdate($obj->de), "day") . '</td>';
1050 // Opp amount
1051 print '<td class="right">';
1052 if ($obj->opp_status_code) {
1053 print '<span class="amount">' . price($obj->opp_amount, 1, '', 1, -1, -1, '') . '</span>';
1054 }
1055 print '</td>';
1056 // Opp status
1057 print '<td class="center">';
1058 if ($obj->opp_status_code) {
1059 print $langs->trans("OppStatus" . $obj->opp_status_code);
1060 }
1061 print '</td>';
1062 // Opp percent
1063 print '<td class="right">';
1064 if ($obj->opp_percent) {
1065 print price($obj->opp_percent, 1, '', 1, 0) . '%';
1066 }
1067 print '</td>';
1068 // Status
1069 print '<td class="right">' . $projecttmp->getLibStatut(5) . '</td>';
1070
1071 // Action column
1072 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1073 print '<td class="nowrap center actioncolumn">';
1074 if ($massactionbutton || $massaction) {
1075 $selected = 0;
1076 if (in_array($obj->id, $arrayofselected)) {
1077 $selected = 1;
1078 }
1079 print '<input id="cb' . $obj->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $obj->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
1080 }
1081 print '</td>';
1082 }
1083 print '</tr>';
1084 }
1085 $i++;
1086 }
1087 } else {
1088 print '<tr class="oddeven"><td colspan="9"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1089 }
1090 $db->free($result);
1091 } else {
1092 dol_print_error($db);
1093 }
1094
1095 //projects linked to that thirdpart because of a people of that company is linked to a project
1096 if (getDolGlobalString('PROJECT_DISPLAY_LINKED_BY_CONTACT')) {
1097 print "\n";
1098 print load_fiche_titre($langs->trans("ProjectsLinkedToThisThirdParty"), '', '');
1099
1100
1101 print '<div class="div-table-responsive">' . "\n";
1102 print '<table class="noborder centpercent">';
1103
1104 $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";
1105 $sql .= ", cls.code as opp_status_code";
1106 $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
1107 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_lead_status as cls on p.fk_opp_status = cls.rowid";
1108 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "element_contact as ec on p.rowid = ec.element_id";
1109 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sc on ec.fk_socpeople = sc.rowid";
1110 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc on ec.fk_c_type_contact = tc.rowid";
1111 $sql .= " WHERE sc.fk_soc = " . ((int) $object->id);
1112 $sql .= " AND p.entity IN (" . getEntity('project') . ")";
1113 $sql .= " AND tc.element = 'project' AND tc.source = 'external'";
1114 $sql .= " ORDER BY p.dateo DESC";
1115
1116 $result = $db->query($sql);
1117 if ($result) {
1118 $num = $db->num_rows($result);
1119
1120 print '<tr class="liste_titre">';
1121 print '<td>' . $langs->trans("Ref") . '</td>';
1122 print '<td>' . $langs->trans("Name") . '</td>';
1123 print '<td class="center">' . $langs->trans("DateStart") . '</td>';
1124 print '<td class="center">' . $langs->trans("DateEnd") . '</td>';
1125 print '<td class="right">' . $langs->trans("OpportunityAmountShort") . '</td>';
1126 print '<td class="center">' . $langs->trans("OpportunityStatusShort") . '</td>';
1127 print '<td class="right">' . $langs->trans("OpportunityProbabilityShort") . '</td>';
1128 print '<td class="right">' . $langs->trans("Status") . '</td>';
1129 print '</tr>';
1130
1131 if ($num > 0) {
1132 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
1133
1134 $projecttmp = new Project($db);
1135
1136 $i = 0;
1137
1138 while ($i < $num) {
1139 $obj = $db->fetch_object($result);
1140 $projecttmp->fetch($obj->id);
1141
1142 // To verify role of users
1143 $userAccess = $projecttmp->restrictedProjectArea($user);
1144
1145 if ($userAccess > 0) {
1146 print '<tr class="oddeven">';
1147
1148 // Ref
1149 print '<td class="nowraponall">';
1150 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:' . $_SERVER["PHP_SELF"] . '?socid=__SOCID__');
1151 print '</td>';
1152
1153 // Label
1154 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->title) . '">' . dol_escape_htmltag($obj->title) . '</td>';
1155 // Date start
1156 print '<td class="center">' . dol_print_date($db->jdate($obj->do), "day") . '</td>';
1157 // Date end
1158 print '<td class="center">' . dol_print_date($db->jdate($obj->de), "day") . '</td>';
1159 // Opp amount
1160 print '<td class="right">';
1161 if ($obj->opp_status_code) {
1162 print '<span class="amount">' . price($obj->opp_amount, 1, '', 1, -1, -1, '') . '</span>';
1163 }
1164 print '</td>';
1165 // Opp status
1166 print '<td class="center">';
1167 if ($obj->opp_status_code) {
1168 print $langs->trans("OppStatus" . $obj->opp_status_code);
1169 }
1170 print '</td>';
1171 // Opp percent
1172 print '<td class="right">';
1173 if ($obj->opp_percent) {
1174 print price($obj->opp_percent, 1, '', 1, 0) . '%';
1175 }
1176 print '</td>';
1177 // Status
1178 print '<td class="right">' . $projecttmp->getLibStatut(5) . '</td>';
1179
1180 print '</tr>';
1181 }
1182 $i++;
1183 }
1184 } else {
1185 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1186 }
1187 $db->free($result);
1188 } else {
1189 dol_print_error($db);
1190 }
1191 }
1192
1193 $parameters = array('sql' => $sql, 'function' => 'show_projects');
1194 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1195 print $hookmanager->resPrint;
1196
1197 print "</table>";
1198 print '</div>';
1199
1200 print "<br>\n";
1201 }
1202
1203 return $i;
1204}
1205
1206
1218function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
1219{
1220 global $user, $extrafields, $hookmanager;
1221 global $contextpage;
1222
1223 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
1224 $formcompany = new FormCompany($db);
1225 $form = new Form($db);
1226
1227 $optioncss = GETPOST('optioncss', 'alpha');
1228 $sortfield = GETPOST('sortfield', 'aZ09comma');
1229 $sortorder = GETPOST('sortorder', 'aZ09comma');
1230 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
1231
1232 $search_status = GETPOST("search_status", "intcomma");
1233 if ($search_status == '') {
1234 $search_status = 1; // always display active customer first
1235 }
1236
1237 $search_rowid = GETPOST("search_rowid", "intcomma");
1238 $search_name = GETPOST("search_name", 'alpha');
1239 $search_address = GETPOST("search_address", 'alpha');
1240 $search_poste = GETPOST("search_poste", 'alpha');
1241 $search_note_private = GETPOST('search_note_private', 'alphanohtml');
1242 $search_roles = GETPOST("search_roles", 'array');
1243 $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
1244 $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
1245
1246 if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
1247 $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_dtstartmonth'), GETPOSTINT('search_birthday_dtstartday'), GETPOSTINT('search_birthday_dtstartyear'));
1248 $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_dtendmonth'), GETPOSTINT('search_birthday_dtendday'), GETPOSTINT('search_birthday_dtendyear'));
1249 }
1250 $socialnetworks = getArrayOfSocialNetworks();
1251
1252 $searchAddressPhoneDBFields = array(
1253 //Address
1254 't.address',
1255 't.zip',
1256 't.town',
1257
1258 //Phone
1259 't.phone',
1260 't.phone_perso',
1261 't.phone_mobile',
1262
1263 //Fax
1264 't.fax',
1265
1266 //E-mail
1267 't.email',
1268 );
1269 //Social media
1270 // foreach ($socialnetworks as $key => $value) {
1271 // if ($value['active']) {
1272 // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
1273 // }
1274 // }
1275
1276 if (!$sortorder) {
1277 $sortorder = "ASC";
1278 }
1279 if (!$sortfield) {
1280 $sortfield = "t.lastname";
1281 }
1282
1283 if (isModEnabled('clicktodial')) {
1284 $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1285 }
1286
1287
1288 $contactstatic = new Contact($db);
1289
1290 $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1291
1292 $contactstatic->fields = array(
1293 'rowid' => array('type' => 'integer', 'label' => "TechnicalID", 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'visible' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1294 'name' => array('type' => 'varchar(128)', 'label' => 'Name', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1),
1295 'poste' => array('type' => 'varchar(128)', 'label' => 'PostOrFunction', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 2, 'index' => 1, 'position' => 20),
1296 'address' => array('type' => 'varchar(128)', 'label' => 'Address', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 3, 'index' => 1, 'position' => 30),
1297 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => (string) ((int) !getDolGlobalBool('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible' => 3, 'position' => 35),
1298 'role' => array('type' => 'checkbox', 'label' => 'Role', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 4, 'index' => 1, 'position' => 40),
1299 'birthday' => array('type' => 'date', 'label' => 'Birthday', 'enabled' => '1', 'visible' => -1, 'notnull' => 0, 'position' => 45),
1300 '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))),
1301 );
1302
1303 // Definition of fields for list
1304 $arrayfields = array(
1305 't.rowid' => array('label' => "TechnicalID", 'checked' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'position' => 1),
1306 't.name' => array('label' => "Name", 'checked' => '1', 'position' => 10),
1307 't.poste' => array('label' => "PostOrFunction", 'checked' => '1', 'position' => 20),
1308 '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),
1309 't.note_private' => array('label' => 'NotePrivate', 'checked' => '0', 'position' => 35),
1310 'sc.role' => array('label' => "ContactByDefaultFor", 'checked' => '1', 'position' => 40),
1311 't.birthday' => array('label' => "Birthday", 'checked' => '0', 'position' => 45),
1312 't.statut' => array('label' => "Status", 'checked' => '1', 'position' => 50, 'class' => 'center'),
1313 'u.user' => array('label' => "DolibarrLogin", 'checked' => '1', 'position' => 50, 'class' => 'center'),
1314 );
1315 // Extra fields
1316 $extrafieldsobjectkey = $contactstatic->table_element;
1317 $extrafieldsobjectprefix = 'ef.';
1318 $extrafieldspositionoffset = 1000;
1319 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
1320
1321 // Initialize array of search criteria
1322 $search = array();
1323 foreach ($arrayfields as $key => $val) {
1324 $queryName = 'search_' . substr($key, 2);
1325 if (GETPOST($queryName, 'alpha')) {
1326 $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1327 }
1328 }
1329 $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1330
1331 // Purge search criteria
1332 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
1333 $search_rowid = '';
1334 $search_status = '';
1335 $search_name = '';
1336 $search_roles = array();
1337 $search_address = '';
1338 $search_poste = '';
1339 $search_note_private = '';
1340 $search_birthday_dtstart = '';
1341 $search_birthday_dtend = '';
1342 $search = array();
1343 $search_array_options = array();
1344
1345 foreach ($contactstatic->fields as $key => $val) {
1346 $search[$key] = '';
1347 }
1348 }
1349
1350 $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1351 $arrayfields = dol_sort_array($arrayfields, 'position');
1352
1353 $newcardbutton = '';
1354 $parameters = array('socid' => $object->id);
1355 $reshook = $hookmanager->executeHooks('printNewCardButton', $parameters, $object);
1356 if (empty($reshook)) {
1357 if ($user->hasRight('societe', 'contact', 'creer')) {
1358 $addcontact = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1359 $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT . '/contact/card.php?socid=' . $object->id . '&action=create&backtopage=' . urlencode($backtopage));
1360 }
1361 } else {
1362 $newcardbutton = $hookmanager->resPrint;
1363 }
1364
1365 print "\n";
1366
1367 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1368 print load_fiche_titre($title, $newcardbutton, 'contact');
1369
1370 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '" name="formfilter">';
1371 print '<input type="hidden" name="token" value="' . newToken() . '">';
1372 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1373 print '<input type="hidden" name="socid" value="' . $object->id . '">';
1374 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
1375 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
1376 print '<input type="hidden" name="page" value="' . $page . '">';
1377
1378 $arrayofmassactions = array();
1379 $mode = 'view';
1380
1381 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1382 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1383 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1384 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1385
1386 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1387 print "\n" . '<table class="tagtable liste noborder">' . "\n";
1388
1389 $param = "socid=" . urlencode((string) ($object->id));
1390 if ($search_rowid != '') {
1391 $param .= '&search_rowid=' . urlencode((string) ($search_rowid));
1392 }
1393 if ($search_status != '') {
1394 $param .= '&search_status=' . urlencode((string) ($search_status));
1395 }
1396 if (count($search_roles) > 0) {
1397 $param .= implode('&search_roles[]=', $search_roles);
1398 }
1399 if ($search_name != '') {
1400 $param .= '&search_name=' . urlencode($search_name);
1401 }
1402 if ($search_poste != '') {
1403 $param .= '&search_poste=' . urlencode($search_poste);
1404 }
1405 if ($search_address != '') {
1406 $param .= '&search_address=' . urlencode($search_address);
1407 }
1408 if ($search_note_private != '') {
1409 $param .= '&search_note_private=' . urlencode($search_note_private);
1410 }
1411 if ($search_birthday_dtstart != '') {
1412 $param .= '&search_birthday_dtstart=' . urlencode((string) $search_birthday_dtstart);
1413 }
1414 if ($search_birthday_dtend != '') {
1415 $param .= '&search_birthday_dtend=' . urlencode((string) $search_birthday_dtend);
1416 }
1417 if ($optioncss != '') {
1418 $param .= '&optioncss=' . urlencode($optioncss);
1419 }
1420
1421 // Add $param from extra fields
1422 $extrafieldsobjectkey = $contactstatic->table_element;
1423 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
1424
1425 $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1426 $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,";
1427 $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1428 $sql .= " t.note_private";
1429 $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
1430 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1431 $sql .= " WHERE t.fk_soc = " . ((int) $object->id);
1432 $sql .= " AND t.entity IN (" . getEntity('socpeople') . ")";
1433 $sql .= " AND ((t.fk_user_creat = " . ((int) $user->id) . " AND t.priv = 1) OR t.priv = 0)";
1434 if ($search_rowid) {
1435 $sql .= natural_search('t.rowid', $search_rowid);
1436 }
1437 if ($search_status != '' && $search_status != '-1') {
1438 $sql .= " AND t.statut = " . ((int) $search_status);
1439 }
1440 if ($search_name) {
1441 $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1442 }
1443 if ($search_poste) {
1444 $sql .= natural_search('t.poste', $search_poste);
1445 }
1446 if ($search_address) {
1447 $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1448 }
1449 if ($search_note_private) {
1450 $sql .= natural_search('t.note_private', $search_note_private);
1451 }
1452 if ($search_birthday_dtstart != '') {
1453 $sql .= " AND t.birthday >= '" . $db->idate($search_birthday_dtstart) . "'";
1454 }
1455 if ($search_birthday_dtend != '') {
1456 $sql .= " AND t.birthday <= '" . $db->idate($search_birthday_dtend) . "'";
1457 }
1458 if (count($search_roles) > 0) {
1459 $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)) . "))";
1460 }
1461 // Add where from extra fields
1462 $extrafieldsobjectkey = $contactstatic->table_element;
1463 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
1464 // Add where from hooks
1465 $parameters = array('socid' => $object->id);
1466 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1467 $sql .= $hookmanager->resPrint;
1468 if ($sortfield == "t.name") {
1469 $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1470 } else {
1471 $sql .= " ORDER BY $sortfield $sortorder";
1472 }
1473
1474 dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1475 $result = $db->query($sql);
1476 if (!$result) {
1477 dol_print_error($db);
1478 }
1479
1480 $num = $db->num_rows($result);
1481
1482 // Fields title search
1483 // --------------------------------------------------------------------
1484 print '<tr class="liste_titre">';
1485 // Action column
1486 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1487 print '<td class="liste_titre right">';
1488 print $form->showFilterButtons();
1489 print '</td>';
1490 }
1491 foreach ($contactstatic->fields as $key => $val) {
1492 $align = '';
1493 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1494 $align .= ($align ? ' ' : '') . 'center';
1495 }
1496 if (in_array($val['type'], array('timestamp'))) {
1497 $align .= ($align ? ' ' : '') . 'nowrap';
1498 }
1499 if ($key == 'status' || $key == 'statut') {
1500 $align .= ($align ? ' ' : '') . 'center';
1501 }
1502 if (!empty($arrayfields['t.' . $key]['checked']) || !empty($arrayfields['sc.' . $key]['checked'])) {
1503 print '<td class="liste_titre' . ($align ? ' ' . $align : '') . '">';
1504 if (in_array($key, array('statut'))) {
1505 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');
1506 } elseif (in_array($key, array('role'))) {
1507 print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1508 } elseif (in_array($key, array('birthday'))) {
1509 print '<div class="nowrap">';
1510 print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1511 print '</div>';
1512 print '<div class="nowrap">';
1513 print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1514 print '</div>';
1515 } else {
1516 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . (!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '') . '">';
1517 }
1518 print '</td>';
1519 }
1520 }
1521 if ($showuserlogin) {
1522 print '<td class="liste_titre"></td>';
1523 }
1524 // Extra fields
1525 $extrafieldsobjectkey = $contactstatic->table_element;
1526 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
1527
1528 // Fields from hook
1529 $parameters = array('arrayfields' => $arrayfields);
1530 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1531 print $hookmanager->resPrint;
1532 // Action column
1533 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1534 print '<td class="liste_titre right">';
1535 print $form->showFilterButtons();
1536 print '</td>';
1537 }
1538 print '</tr>' . "\n";
1539
1540
1541 // Fields title label
1542 // --------------------------------------------------------------------
1543 print '<tr class="liste_titre">';
1544 // Action column
1545 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1546 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1547 }
1548 foreach ($contactstatic->fields as $key => $val) {
1549 $align = '';
1550 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1551 $align .= ($align ? ' ' : '') . 'center';
1552 }
1553 if (in_array($val['type'], array('timestamp'))) {
1554 $align .= ($align ? ' ' : '') . 'nowrap';
1555 }
1556 if ($key == 'status' || $key == 'statut') {
1557 $align .= ($align ? ' ' : '') . 'center';
1558 }
1559 if (!empty($arrayfields['t.' . $key]['checked'])) {
1560 print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1561 }
1562 if ($key == 'role') {
1563 $align .= ($align ? ' ' : '') . 'left';
1564 }
1565 if (!empty($arrayfields['sc.' . $key]['checked'])) {
1566 print getTitleFieldOfList($arrayfields['sc.' . $key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1567 }
1568 }
1569 if ($showuserlogin) {
1570 print '<th class="wrapcolumntitle liste_titre">' . $langs->trans("DolibarrLogin") . '</th>';
1571 }
1572 // Extra fields
1573 $extrafieldsobjectkey = $contactstatic->table_element;
1574 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
1575 // Hook fields
1576 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1577 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1578 print $hookmanager->resPrint;
1579 // Action column
1580 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1581 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1582 }
1583 print '</tr>' . "\n";
1584
1585 $i = -1;
1586
1587 if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1588 $i = 0;
1589
1590 while ($i < $num) {
1591 $obj = $db->fetch_object($result);
1592
1593 $contactstatic->id = $obj->rowid;
1594 $contactstatic->ref = $obj->rowid;
1595 $contactstatic->status = $obj->statut;
1596 $contactstatic->statut = $obj->statut;
1597 $contactstatic->lastname = $obj->lastname;
1598 $contactstatic->firstname = $obj->firstname;
1599 $contactstatic->civility_id = $obj->civility_id;
1600 $contactstatic->civility_code = $obj->civility_id;
1601 $contactstatic->poste = $obj->poste;
1602 $contactstatic->address = $obj->address;
1603 $contactstatic->zip = $obj->zip;
1604 $contactstatic->town = $obj->town;
1605 $contactstatic->phone_pro = $obj->phone_pro;
1606 $contactstatic->phone_mobile = $obj->phone_mobile;
1607 $contactstatic->phone_perso = $obj->phone_perso;
1608 $contactstatic->email = $obj->email;
1609 $contactstatic->socialnetworks = $obj->socialnetworks;
1610 $contactstatic->photo = $obj->photo;
1611 $contactstatic->fk_soc = $obj->fk_soc;
1612 $contactstatic->entity = $obj->entity;
1613
1614 $country_code = getCountry($obj->country_id, '2');
1615 $contactstatic->country_code = $country_code;
1616
1617 $contactstatic->setGenderFromCivility();
1618 $contactstatic->fetch_optionals();
1619
1620 $resultRole = $contactstatic->fetchRoles();
1621 if ($resultRole < 0) {
1622 setEventMessages(null, $contactstatic->errors, 'errors');
1623 }
1624
1625 if (is_array($contactstatic->array_options)) {
1626 foreach ($contactstatic->array_options as $key => $val) {
1627 $obj->$key = $val;
1628 }
1629 }
1630
1631 print '<tr class="oddeven">';
1632
1633 // Actions
1634 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1635 print '<td class="nowrap center">';
1636
1637 // Add to agenda
1638 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1639 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1640 print img_object($langs->trans("Event"), "action");
1641 print '</a> &nbsp; ';
1642 }
1643
1644 // Edit
1645 if ($user->hasRight('societe', 'contact', 'creer')) {
1646 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1647 print img_edit();
1648 print '</a>';
1649 }
1650
1651 // Delete
1652 if ($user->hasRight('societe', 'contact', 'delete')) {
1653 print '<a class="marginleftonly right" href="' . DOL_URL_ROOT . '/societe/contact.php?action=delete&token=' . newToken() . '&id=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1654 print img_delete();
1655 print '</a>';
1656 }
1657
1658 print '</td>';
1659 }
1660
1661 // ID
1662 if (!empty($arrayfields['t.rowid']['checked'])) {
1663 print '<td>';
1664 print $contactstatic->id;
1665 print '</td>';
1666 }
1667
1668 // Photo - Name
1669 if (!empty($arrayfields['t.name']['checked'])) {
1670 print '<td class="tdoverflowmax150">';
1671 print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 'user');
1672 print $contactstatic->getNomUrl(0, '', 0, '&backtopage=' . urlencode($backtopage));
1673 print '</td>';
1674 }
1675
1676 // Job position
1677 if (!empty($arrayfields['t.poste']['checked'])) {
1678 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->poste) . '">';
1679 if ($obj->poste) {
1680 print dol_escape_htmltag($obj->poste);
1681 }
1682 print '</td>';
1683 }
1684
1685 // Address - Phone - Email
1686 if (!empty($arrayfields['t.address']['checked'])) {
1687 $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1688 print '<td class="tdoverflowmax150 classfortooltip" title="'.dolPrintHTMLForAttribute($addresstoshow).'">';
1689 print $addresstoshow;
1690 print '</td>';
1691 }
1692
1693 // Note private
1694 if (!empty($arrayfields['t.note_private']['checked'])) {
1695 print '<td class="center">';
1696 print dolPrintHTML($obj->note_private);
1697 print '</td>';
1698 }
1699
1700 // Role
1701 if (!empty($arrayfields['sc.role']['checked'])) {
1702 print '<td class="tdoverflowmax150">';
1703 print $formcompany->showRoles("roles", $contactstatic, 'view');
1704 print '</td>';
1705 }
1706
1707 // Birthday
1708 if (!empty($arrayfields['t.birthday']['checked'])) {
1709 print '<td class="nowraponall">';
1710 print dol_print_date($db->jdate($obj->birthday));
1711 print '</td>';
1712 }
1713
1714 // Status
1715 if (!empty($arrayfields['t.statut']['checked'])) {
1716 print '<td class="center">' . $contactstatic->getLibStatut(5) . '</td>';
1717 }
1718
1719 if ($showuserlogin) {
1720 print '<td class="tdoverflowmax125">';
1721 $tmpuser = new User($db);
1722 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1723 $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1724 if ($resfetch > 0) {
1725 print $tmpuser->getNomUrl(-1, '', 0, 0, 24, 1);
1726 }
1727 print '</td>';
1728 }
1729
1730 // Extra fields
1731 $extrafieldsobjectkey = $contactstatic->table_element;
1732 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
1733
1734 // Actions
1735 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1736 print '<td class="nowrap center">';
1737
1738 // Add to agenda
1739 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1740 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1741 print img_object($langs->trans("Event"), "action");
1742 print '</a> &nbsp; ';
1743 }
1744
1745 // Edit
1746 if ($user->hasRight('societe', 'contact', 'creer')) {
1747 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1748 print img_edit();
1749 print '</a>';
1750 }
1751
1752 // Delete
1753 if ($user->hasRight('societe', 'contact', 'delete')) {
1754 print '<a class="marginleftonly right" href="' . DOL_URL_ROOT . '/societe/contact.php?action=delete&token=' . newToken() . '&id=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1755 print img_delete();
1756 print '</a>';
1757 }
1758
1759 print '</td>';
1760 }
1761
1762 print "</tr>\n";
1763 $i++;
1764 }
1765
1766 if ($num == 0) {
1767 $colspan = 1 + ($showuserlogin ? 1 : 0);
1768 foreach ($arrayfields as $key => $val) {
1769 if (!empty($val['checked'])) {
1770 $colspan++;
1771 }
1772 }
1773 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
1774 }
1775 } else {
1776 $colspan = 1 + ($showuserlogin ? 1 : 0);
1777 foreach ($arrayfields as $key => $val) {
1778 if (!empty($val['checked'])) {
1779 $colspan++;
1780 }
1781 }
1782 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1783 }
1784 print "\n</table>\n";
1785 print '</div>';
1786
1787 print '</form>' . "\n";
1788
1789 return $i;
1790}
1791
1792
1805function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '')
1806{
1807 $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1808
1809 if ($noprint) {
1810 return $out;
1811 } else {
1812 print $out;
1813 return null;
1814 }
1815}
1816
1835function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1836{
1837 global $hookmanager, $user;
1838 global $form;
1839
1840 global $param, $massactionbutton;
1841
1842 $start_year = GETPOSTINT('dateevent_startyear');
1843 $start_month = GETPOSTINT('dateevent_startmonth');
1844 $start_day = GETPOSTINT('dateevent_startday');
1845 $end_year = GETPOSTINT('dateevent_endyear');
1846 $end_month = GETPOSTINT('dateevent_endmonth');
1847 $end_day = GETPOSTINT('dateevent_endday');
1848 $tms_start = '';
1849 $tms_end = '';
1850
1851 if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1852 $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1853 }
1854 if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1855 $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1856 }
1857 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
1858 $tms_start = '';
1859 $tms_end = '';
1860 }
1861 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1862
1863 // Check parameters
1864 if (!is_object($filterobj) && !is_object($objcon)) {
1865 dol_print_error(null, 'BadParameter');
1866 }
1867
1868 $out = '';
1869 $histo = array();
1870 $numaction = 0;
1871 $now = dol_now('tzuser');
1872
1873 // Open DSI -- Fix order by -- Begin
1874 $sortfield_list = explode(',', $sortfield);
1875 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1876 $sortfield_new_list = array();
1877 foreach ($sortfield_list as $sortfield_value) {
1878 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1879 }
1880 $sortfield_new = implode(',', $sortfield_new_list);
1881
1882 $complete = (string) (!empty($filters['search_complete']) ? $filters['search_complete']: ''); // Can be 'na', '0', '50', '100'
1883 $percent = $complete !== '' ? $complete : -1;
1884 if ((string) $complete == '0') {
1885 $percent = '0';
1886 } elseif ((int) $complete == 100) {
1887 $percent = '100';
1888 }
1889
1890 $sql = '';
1891
1892 if (isModEnabled('agenda')) {
1893 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
1894 $hookmanager->initHooks(array('agendadao'));
1895
1896 $sql = "SELECT a.id, a.label as label,";
1897 $sql .= " a.datep as dp,";
1898 $sql .= " a.datep2 as dp2,";
1899 $sql .= " a.percent as percent, 'action' as type,";
1900 $sql .= " a.fk_element, a.elementtype,";
1901 $sql .= " a.fk_contact,";
1902 $sql .= " a.code,";
1903 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1904 $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";
1905 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1906 $sql .= ", sp.lastname, sp.firstname";
1907 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1908 /* Nothing */
1909 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1910 /* Nothing */
1911 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1912 $sql .= ", m.lastname, m.firstname";
1913 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1914 $sql .= ", o.ref";
1915 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1916 $sql .= ", o.ref";
1917 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1918 $sql .= ", o.ref";
1919 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1920 $sql .= ", o.ref";
1921 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1922 $sql .= ", o.ref";
1923 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
1924 $sql .= ", s.ref";
1925 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1926 if (!empty($filterobj->fields['ref'])) {
1927 $sql .= ", o.ref";
1928 } elseif (!empty($filterobj->fields['label'])) {
1929 $sql .= ", o.label";
1930 }
1931 }
1932
1933 $canedit = 1;
1934 if (!$user->hasRight('agenda', 'myactions', 'read')) {
1935 $canedit = 0;
1936 }
1937 if (!$user->hasRight('agenda', 'allactions', 'read')) {
1938 $canedit = 0;
1939 }
1940 if (!$user->hasRight('agenda', 'allactions', 'read')) { // If no permission to see all, we show only affected to me
1941 $filters['search_filtert'] = (string) $user->id;
1942 }
1943
1944 // Fields from hook
1945 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1946 $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1947 if (!empty($hookmanager->resPrint)) {
1948 $sql .= $hookmanager->resPrint;
1949 }
1950
1951 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
1952 // Link to the owner of action
1953 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_action";
1954 // Link to action types
1955 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_actioncomm as c ON a.fk_action = c.id";
1956
1957 // Set $force_filter_contact:
1958 // - true for a filter on a user or a contact, so a link on table llx_actioncomm_resources or llx_actioncomm.fk_user_action
1959 // - false for a link on table llx_element_resources
1960 $force_filter_contact = false;
1961 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
1962 $force_filter_contact = true;
1963 }
1964 if (is_object($objcon) && $objcon->id > 0) {
1965 $force_filter_contact = true;
1966 }
1967
1968 // Fields from hook
1969 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1970 $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1971 if (!empty($hookmanager->resPrint)) {
1972 $sql .= $hookmanager->resPrint;
1973 }
1974 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1975 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
1976 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1977 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "element_resources as er";
1978 $sql .= " ON er.resource_type = 'dolresource'";
1979 $sql .= " AND er.element_type = 'action'";
1980 $sql .= " AND er.element_id = a.id";
1981 $sql .= " AND er.resource_id = " . ((int) $filterobj->id);
1982 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1983 /* Nothing */
1984 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1985 $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
1986 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1987 $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as o";
1988 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1989 $sql .= ", " . MAIN_DB_PREFIX . "product as o";
1990 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1991 $sql .= ", " . MAIN_DB_PREFIX . "ticket as o";
1992 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1993 $sql .= ", " . MAIN_DB_PREFIX . "bom_bom as o";
1994 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1995 $sql .= ", " . MAIN_DB_PREFIX . "contrat as o";
1996 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
1997 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expedition as s ON a.fk_element = s.rowid AND a.elementtype = 'shipping'"; // Jointure sur la table des expéditions avec condition ON
1998 } elseif (is_object($filterobj) && get_class($filterobj) == 'Propal') {
1999 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "propal as o ON a.fk_element = o.rowid AND a.elementtype = 'propal'";
2000 } elseif (
2001 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2002 && ((!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref'])) || (!empty($filterobj->fields['label']) && is_array($filterobj->fields['label'])) || (!empty($filterobj->fields['titre']) && is_array($filterobj->fields['titre']))) // @phan-suppress-current-line PhanTypeInvalidDimOffset
2003 && $filterobj->table_element && $filterobj->element
2004 ) {
2005 $sql .= ", " . MAIN_DB_PREFIX . $filterobj->table_element . " as o";
2006 }
2007
2008 $sql .= " WHERE a.entity IN (" . getEntity('agenda') . ")";
2009 if (!$force_filter_contact) {
2010 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
2011 $sql .= " AND a.fk_soc = " . ((int) $filterobj->id);
2012 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
2013 /* Nothing */
2014 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
2015 $sql .= " AND a.fk_project = " . ((int) $filterobj->id);
2016 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2017 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
2018 if ($filterobj->id) {
2019 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2020 }
2021 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
2022 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
2023 if ($filterobj->id) {
2024 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2025 }
2026 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2027 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
2028 if ($filterobj->id) {
2029 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2030 }
2031 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
2032 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
2033 if ($filterobj->id) {
2034 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2035 }
2036 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
2037 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice_supplier'";
2038 if ($filterobj->id) {
2039 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2040 }
2041 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2042 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
2043 if ($filterobj->id) {
2044 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2045 }
2046 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2047 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
2048 if ($filterobj->id) {
2049 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2050 }
2051 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
2052 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
2053 if ($filterobj->id) {
2054 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2055 }
2056 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
2057 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
2058 if ($filterobj->id) {
2059 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2060 }
2061 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
2062 $sql .= " AND a.fk_element = s.rowid AND a.elementtype = 'shipping'"; //expedition filter
2063 if ($filterobj->id) {
2064 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2065 }
2066 } elseif (
2067 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2068 && ((!empty($filterobj->fields['ref']) && is_array($filterobj->fields['ref'])) || (!empty($filterobj->fields['label']) && is_array($filterobj->fields['label'])) || (!empty($filterobj->fields['titre']) && is_array($filterobj->fields['titre']))) // ref, titre, label do not exist on $fields - @phan-suppress-current-line PhanTypeInvalidDimOffset
2069 && $filterobj->table_element && $filterobj->element
2070 ) {
2071 // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
2072 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '" . $db->escape($filterobj->element) . ($module ? "@" . $module : "") . "'";
2073 if ($filterobj->id) {
2074 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2075 }
2076 } elseif (is_object($filterobj)) {
2077 return 'Bad value for $filterobj';
2078 }
2079 } else {
2080 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
2081 $sql .= " AND (u.rowid = " . ((int) $filterobj->id) . ' OR ';
2082 $sql .= " EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2083 $sql .= " AND r.element_type = '" . $db->escape($filterobj->table_element) . "' AND r.fk_element = " . ((int) $filterobj->id) . ')';
2084 $sql .= ")";
2085 }
2086 if (is_object($objcon) && $objcon->id > 0) {
2087 $sql .= " AND EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2088 $sql .= " AND r.element_type = '" . $db->escape($objcon->table_element) . "' AND r.fk_element = " . ((int) $objcon->id) . ')';
2089 }
2090 }
2091
2092 if (!empty($tms_start) && !empty($tms_end)) {
2093 $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) . "'))";
2094 } elseif (empty($tms_start) && !empty($tms_end)) {
2095 $sql .= " AND ((a.datep <= '" . $db->idate($tms_end) . "') OR (a.datep2 <= '" . $db->idate($tms_end) . "'))";
2096 } elseif (!empty($tms_start) && empty($tms_end)) {
2097 $sql .= " AND ((a.datep >= '" . $db->idate($tms_start) . "') OR (a.datep2 >= '" . $db->idate($tms_start) . "'))";
2098 }
2099
2100 if (is_array($actioncode) && !empty($actioncode)) {
2101 $tmpsql = '';
2102
2103 foreach ($actioncode as $key => $code) {
2104 if ((string) $code === '-1' || (string) $code === '') {
2105 continue;
2106 }
2107 if ($key != 0) {
2108 $tmpsql .= " OR ";
2109 }
2110 if (!empty($code)) {
2111 addEventTypeSQL($tmpsql, $code, "");
2112 }
2113 }
2114 if ($tmpsql) {
2115 $sql .= ' AND (';
2116 $sql .= $tmpsql;
2117 $sql .= ')';
2118 }
2119 } elseif (!empty($actioncode) && $actioncode != '-1') {
2120 addEventTypeSQL($sql, $actioncode);
2121 }
2122
2123 addOtherFilterSQL($sql, $donetodo, $now, $filters);
2124
2125 // Fields from hook
2126 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
2127 $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
2128 if (!empty($hookmanager->resPrint)) {
2129 $sql .= $hookmanager->resPrint;
2130 }
2131
2132 // Now add events of emailing module
2133 if (is_array($actioncode) && $objcon !== null) {
2134 foreach ($actioncode as $code) {
2135 $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
2136 if (!empty($sql2)) {
2137 if (!empty($sql)) {
2138 $sql = $sql . " UNION " . $sql2;
2139 } elseif (empty($sql)) {
2140 $sql = $sql2;
2141 }
2142 break;
2143 }
2144 }
2145 } else {
2146 $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
2147 if (!empty($sql) && !empty($sql2)) {
2148 $sql = $sql . " UNION " . $sql2;
2149 } elseif (empty($sql) && !empty($sql2)) {
2150 $sql = $sql2;
2151 }
2152 }
2153 }
2154
2155 $MAXWITHOUTPAGINATION = getDolGlobalInt('AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
2156 $num = 0;
2157
2158 if ($sql) {
2159 // TODO Add navigation with this limits by replacing call of show_actions_done by the code found into comm/action/list.php...
2160 $offset = 0;
2161 $limit = $MAXWITHOUTPAGINATION;
2162
2163 // Complete request and execute it with limit
2164 $sql .= $db->order($sortfield_new, $sortorder);
2165 if ($limit) { // @phpstan-ignore-line
2166 $sql .= $db->plimit($limit + 1, $offset);
2167 }
2168
2169 dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
2170
2171 $resql = $db->query($sql);
2172 if ($resql) {
2173 $i = 0;
2174 $num = $db->num_rows($resql);
2175
2176 $imaxinloop = ($limit ? min($num, $limit) : $num);
2177 while ($i < $imaxinloop) {
2178 $obj = $db->fetch_object($resql);
2179 if (empty($obj)) {
2180 break;
2181 }
2182
2183 if ($obj->type == 'action') {
2184 $contactaction = new ActionComm($db);
2185 $contactaction->id = $obj->id;
2186 $result = $contactaction->fetchResources();
2187 if ($result < 0) {
2188 dol_print_error($db);
2189 setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2190 }
2191
2192 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2193 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2194 $tododone = '';
2195 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2196 $tododone = 'todo';
2197 }
2198
2199 $histo[$numaction] = array(
2200 'type' => $obj->type,
2201 'tododone' => $tododone,
2202 'id' => (int) $obj->id,
2203 'datestart' => $db->jdate($obj->dp),
2204 'dateend' => $db->jdate($obj->dp2),
2205 'note' => $obj->label,
2206 'percent' => (int) $obj->percent,
2207
2208 'userid' => (int) $obj->user_id,
2209 'login' => $obj->user_login,
2210 'userfirstname' => $obj->user_firstname,
2211 'userlastname' => $obj->user_lastname,
2212 'userphoto' => $obj->user_photo,
2213
2214 'contact_id' => (int) $obj->fk_contact,
2215 'socpeopleassigned' => $contactaction->socpeopleassigned,
2216 'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2217 'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2218 'fk_element' => (int) $obj->fk_element,
2219 'elementtype' => $obj->elementtype,
2220
2221 'code' => $obj->code,
2222
2223 // Type of event
2224 'acode' => $obj->acode,
2225 'alabel' => $obj->alabel,
2226 'libelle' => $obj->alabel, // deprecated
2227 'apicto' => $obj->apicto
2228 );
2229 } else {
2230 $histo[$numaction] = array(
2231 'type' => $obj->type,
2232 'tododone' => 'done',
2233 'id' => (int) $obj->id,
2234 'datestart' => $db->jdate($obj->dp),
2235 'dateend' => $db->jdate($obj->dp2),
2236 'note' => $obj->label,
2237 'percent' => (int) $obj->percent,
2238
2239 'code' => $obj->code,
2240
2241 // Type of event
2242 'acode' => $obj->acode,
2243
2244 'userid' => (int) $obj->user_id,
2245 'login' => $obj->user_login,
2246 'userfirstname' => $obj->user_firstname,
2247 'userlastname' => $obj->user_lastname,
2248 'userphoto' => $obj->user_photo
2249 );
2250 }
2251
2252 $numaction++;
2253 $i++;
2254 }
2255 } else {
2256 dol_print_error($db);
2257 }
2258 }
2259
2260 '@phan-var-force array<int,array{userid:int,type:string,tododone:string,apicto:string,acode:string,alabel:string,note:string,id:int,percent:int<0,100>,datestart:int,dateend:int,fk_element:string,elementtype:string,contact_id:int,lastname:string,firstname:string,contact_photo:string,socpeopleassigned:int[],login:string,userfirstname:string,userlastname:string,userphoto:string}> $histo';
2261
2262 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2263 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
2264
2265 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
2266 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
2267 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2268 require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2269
2270 $formactions = new FormActions($db);
2271
2272 $actionstatic = new ActionComm($db);
2273 $userstatic = new User($db);
2274 $userlinkcache = array();
2275 $contactstatic = new Contact($db);
2276 $elementlinkcache = array();
2277
2278 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
2279 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
2280 if (
2281 $objcon && get_class($objcon) == 'Contact' &&
2282 (is_null($filterobj) || get_class($filterobj) == 'Societe')
2283 ) {
2284 $out .= '<input type="hidden" name="id" value="' . $objcon->id . '" />';
2285 } else {
2286 $out .= '<input type="hidden" name="id" value="' . $filterobj->id . '" />';
2287 }
2288 if ($filterobj && get_class($filterobj) == 'Societe') {
2289 $out .= '<input type="hidden" name="socid" value="' . $filterobj->id . '" />';
2290 } else {
2291 $out .= '<input type="hidden" name="userid" value="' . $filterobj->id . '" />';
2292 }
2293
2294 $out .= "\n";
2295
2296 $out .= '<div class="div-table-responsive-no-min">';
2297 $out .= '<table class="noborder centpercent">';
2298
2299 $out .= '<tr class="liste_titre_filter">';
2300
2301 // Action column
2302 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2303 $out .= '<th class="liste_titre width50 middle">';
2304 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2305 $out .= $searchpicto;
2306 $out .= '</th>';
2307 }
2308
2309 if ($donetodo) {
2310 $out .= '<td class="liste_titre"></td>';
2311 }
2312
2313 // ID
2314 $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="' . (isset($filters['search_rowid']) ? $filters['search_rowid'] : '') . '"></td>';
2315 // Date
2316 $out .= '<td class="liste_titre center">';
2317 $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2318 $out .= '</td>';
2319 // Owner
2320 $out .= '<td class="liste_titre">';
2321 $out .= $form->select_dolusers(($filters['search_filtert'] > 0 ? $filters['search_filtert'] : ''), 'search_filtert', 1, null, (int) !$canedit, '', '', '0', 0, 0, '', 2, '', 'minwidth100 maxwidth250 widthcentpercentminusx');
2322 $out .= '</td>';
2323 // Type
2324 $out .= '<td class="liste_titre">';
2325 $out .= $formactions->select_type_actions($actioncode, "actioncode", '', getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, (getDolGlobalString('AGENDA_USE_MULTISELECT_TYPE') ? 1 : 0), 1, 'selecttype combolargeelem minwidth100 maxwidth150', 1);
2326 $out .= '</td>';
2327 // Label - Title
2328 $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth125" name="search_agenda_label" value="' . $filters['search_agenda_label'] . '"></td>';
2329 $out .= '<td class="liste_titre"></td>';
2330 $out .= '<td class="liste_titre"></td>';
2331 // Status ($percent can be 'na'or < 100 or 100)
2332 $out .= '<td class="liste_titre parentonrightofpage">';
2333 $out .= $formactions->form_select_status_action('formaction', $percent, 1, 'search_complete', 1, 2, 'search_status width100 onrightofpage', 1);
2334 $out .= '</td>';
2335 // Action column
2336 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2337 $out .= '<td class="liste_titre" align="middle">';
2338 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2339 $out .= $searchpicto;
2340 $out .= '</td>';
2341 }
2342 $out .= '</tr>';
2343
2344 $out .= '<tr class="liste_titre">';
2345 // Action column
2346 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2347 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2348 }
2349 if ($donetodo && $filterobj !== null) {
2350 $tmp = '';
2351 if (get_class($filterobj) == 'Societe') {
2352 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&socid=' . $filterobj->id . '&status=done">';
2353 }
2354 if (get_class($filterobj) == 'User') {
2355 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&userid=' . $filterobj->id . '&status=done">';
2356 }
2357 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2358 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2359 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2360 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2361 if (get_class($filterobj) == 'Societe') {
2362 $tmp .= '</a>';
2363 }
2364 if (get_class($filterobj) == 'User') {
2365 $tmp .= '</a>';
2366 }
2367 $out .= getTitleFieldOfList($tmp);
2368 }
2369 $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2370 $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2371 $out .= getTitleFieldOfList("Owner");
2372 $out .= getTitleFieldOfList("Type");
2373 $out .= getTitleFieldOfList("Title", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2374 $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2375 $out .= getTitleFieldOfList("LinkedObject", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2376 $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2377 // Action column
2378 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2379 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2380 }
2381 $out .= '</tr>';
2382
2383 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
2384 $caction = new CActionComm($db);
2385 $arraylist = $caction->liste_array(1, 'code', '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 0 : 1), '', 1);
2386
2387 foreach ($histo as $key => $value) {
2388 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2389
2390 if (empty($actionstatic->code)) {
2391 $actionstatic->code = $histo[$key]['acode'];
2392 }
2393 $actionstatic->type_picto = $histo[$key]['apicto'] ?? '';
2394 $actionstatic->type_code = $histo[$key]['acode'];
2395
2396 $out .= '<tr class="oddeven">';
2397
2398 // Action column
2399 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2400 $out .= '<td></td>';
2401 }
2402
2403 // Done or todo
2404 if ($donetodo) {
2405 $out .= '<td class="nowrap">';
2406 $out .= '</td>';
2407 }
2408
2409 // Ref
2410 $out .= '<td class="nowraponall">';
2411 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2412 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
2413 $out .= $histo[$key]['id'];
2414 $out .= '</a>';
2415 } else {
2416 $out .= $actionstatic->getNomUrl(1, -1);
2417 }
2418 $out .= '</td>';
2419
2420 // Date
2421 $out .= '<td class="center nowraponall nopaddingtopimp nopaddingbottomimp">';
2422 $tmpa = dol_getdate($histo[$key]['datestart']);
2423 if (!empty($histo[$key]['dateend'])) {
2424 $tmpb = dol_getdate($histo[$key]['dateend']);
2425 } else {
2426 $tmpb = $tmpa;
2427 }
2428 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2429 // The same day
2430 if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) {
2431 $out .= '<div class="center inline-block lineheightsmall">';
2432 $out .= dol_print_date($histo[$key]['datestart'], 'dayreduceformat', 'tzuserrel');
2433 $out .= '<br><span class="opacitymedium hourspan">';
2434 $out .= dol_print_date($histo[$key]['datestart'], 'hourreduceformat', 'tzuserrel');
2435 $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hourreduceformat', 'tzuserrel');
2436 $out .= '</span>';
2437 $out .= '</div>';
2438 } else {
2439 $out .= '<div class="center inline-block lineheightsmall">';
2440 $out .= dol_print_date($histo[$key]['datestart'], 'dayreduceformat', 'tzuserrel');
2441 $out .= '<br><span class="opacitymedium hourspan">';
2442 $out .= dol_print_date($histo[$key]['datestart'], 'hourreduceformat', 'tzuserrel');
2443 $out .= '</span>';
2444 $out .= '</div>';
2445 }
2446 } else {
2447 // Not the same day
2448 $out .= '<div class="center inline-block lineheightsmall">';
2449 $out .= dol_print_date($histo[$key]['datestart'], 'dayreduceformat', 'tzuserrel');
2450 $out .= '<br><span class="opacitymedium hourspan">';
2451 $out .= dol_print_date($histo[$key]['datestart'], 'hourreduceformat', 'tzuserrel');
2452 $out .= '</span>';
2453 $out .= '</div>';
2454 $out .= ' - ';
2455 $out .= '<div class="center inline-block lineheightsmall">';
2456 $out .= dol_print_date($histo[$key]['dateend'], 'dayreduceformat', 'tzuserrel');
2457 $out .= '<br><span class="opacitymedium hourspan">';
2458 $out .= dol_print_date($histo[$key]['dateend'], 'hourreduceformat', 'tzuserrel');
2459 $out .= '</span>';
2460 $out .= '</div>';
2461 }
2462 // Add the late warning
2463 $late = 0;
2464 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2465 $late = 1;
2466 }
2467 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2468 $late = 1;
2469 }
2470 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2471 $late = 1;
2472 }
2473 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2474 $late = 1;
2475 }
2476 if ($late) {
2477 $out .= img_warning($langs->trans("Late")) . ' ';
2478 }
2479 $out .= '</td>';
2480
2481 // Author of event
2482 $out .= '<td class="tdoverflowmax125">';
2483 if ($histo[$key]['userid'] > 0) {
2484 if (isset($userlinkcache[$histo[$key]['userid']])) {
2485 $link = $userlinkcache[$histo[$key]['userid']];
2486 } else {
2487 $userstatic->fetch($histo[$key]['userid']);
2488 $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2489 $userlinkcache[$histo[$key]['userid']] = $link;
2490 }
2491 $out .= $link;
2492 }
2493 $out .= '</td>';
2494
2495 // type_code // column "acode" in the sql = code in type of actioncomm, example: AC_OTH_AUTO, AC_EMAILING
2496 // code // columne code in the sql (not yet added), can be AC_CONTACT_SENTBYMAIL, ...
2497
2498 // Type
2499 $labelOfTypeToShow = $actionstatic->type_code;
2500 //$typelabel = $actionstatic->type_label;
2501 $code = $actionstatic->code;
2502 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labelOfTypeToShow])) {
2503 $labelOfTypeToShow = 'AC_OTH';
2504 }
2505 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2506 $labelOfTypeToShow = $langs->trans("Message");
2507 } else {
2508 if (!empty($arraylist[$labelOfTypeToShow])) {
2509 $labelOfTypeToShow = $arraylist[$labelOfTypeToShow];
2510 } elseif ($actionstatic->type_code == 'AC_EMAILING') {
2511 $langs->load("mails");
2512 $labelOfTypeToShow = $langs->trans("Emailing");
2513 }
2514 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labelOfTypeToShow && !empty($arraylist[$actionstatic->code])) {
2515 $labelOfTypeToShow .= ' - ' . $arraylist[$actionstatic->code]; // Show also detailed code
2516 }
2517 }
2518
2519 $labelOfTypeToShowLong = $labelOfTypeToShow;
2520 if ($actionstatic->type_code == 'AC_OTH_AUTO') {
2521 $labelOfTypeToShowLong .= ' (auto)';
2522 }
2523
2524 $out .= '<td class="tdoverflowmax125" title="' . $labelOfTypeToShowLong . '">';
2525 // Example $actionstatic->code = AC_COMPANY_MODIFY and $actionstatic->type_code = AC_OTH_AUTO
2526 $out .= $actionstatic->getTypePicto();
2527 $out .= $labelOfTypeToShow;
2528 $out .= '</td>';
2529
2530 // Title/Label of event
2531 $out .= '<td class="tdoverflowmax300"';
2532 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2533 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2534 //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2535 $label = $histo[$key]['note'];
2536 $actionstatic->id = $histo[$key]['id'];
2537 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2538 $out .= dol_trunc($label, 120);
2539 }
2540 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2541 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2542 $label = ($transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2543 $label .= ' - ' . $histo[$key]['note'];
2544 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '"';
2545 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2546 //$out .= img_object($langs->trans("EMailing").'<br>'.$histo[$key]['note'], "email").' ';
2547 $out .= dol_trunc($label, 120);
2548 $out .= '</a>';
2549 }
2550 $out .= '</td>';
2551
2552 // Contact(s) for action
2553 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2554 $out .= '<td class="valignmiddle">';
2555 $contact = new Contact($db);
2556 foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2557 $result = $contact->fetch($cid);
2558
2559 if ($result < 0) {
2560 dol_print_error($db, $contact->error);
2561 } elseif ($result > 0) {
2562 if (count($histo[$key]['socpeopleassigned']) > 1) {
2563 $out .= $contact->getNomUrl(-2, '', 0, '', -1, 0, 'paddingright');
2564 } else {
2565 $out .= $contact->getNomUrl(-3, '', 0, '', -1, 0, 'paddingright');
2566 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2567 if (!empty($contact->phone_pro)) {
2568 $out .= '(' . dol_print_phone($contact->phone_pro) . ')';
2569 }
2570 }
2571 }
2572 }
2573 }
2574 $out .= '</td>';
2575 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2576 $contactstatic->lastname = $histo[$key]['lastname'];
2577 $contactstatic->firstname = $histo[$key]['firstname'];
2578 $contactstatic->id = $histo[$key]['contact_id'];
2579 $contactstatic->photo = $histo[$key]['contact_photo'];
2580 $out .= '<td width="120">' . $contactstatic->getNomUrl(-1, '', 10) . '</td>';
2581 } else {
2582 $out .= '<td>&nbsp;</td>';
2583 }
2584
2585 // Linked object
2586 $out .= '<td class="tdoverflowmax200 nowraponall">';
2587 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2588 if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2589 $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2590 } else {
2591 if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2592 $elementlinkcache[$histo[$key]['elementtype']] = array();
2593 }
2594 $link = dolGetElementUrl((int) $histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2595 $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2596 }
2597 $out .= $link;
2598 }
2599 $out .= '</td>';
2600
2601 // Status / Progression
2602 $out .= '<td class="nowrap center">';
2603 $out .= $actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']);
2604 $out .= '</td>';
2605
2606 // Action column
2607 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2608 $out .= '<td></td>';
2609 }
2610
2611 $out .= "</tr>\n";
2612 }
2613 if (empty($histo)) {
2614 $colspan = 9;
2615 $out .= '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
2616 }
2617
2618 if ($num > $MAXWITHOUTPAGINATION) {
2619 $langs->load("errors");
2620 $colspan = 9;
2621 $out .= '<tr><td class="center" colspan="' . $colspan . '"><span class="opacitymedium">...' . $langs->trans("WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) . '...</span></td></tr>';
2622 }
2623
2624 $out .= "</table>\n";
2625 $out .= "</div>\n";
2626
2627 $out .= '</form>';
2628 }
2629
2630 if ($noprint) {
2631 return $out;
2632 } else {
2633 print $out;
2634 return null;
2635 }
2636}
2637
2647function show_subsidiaries($conf, $langs, $db, $object)
2648{
2649 $i = -1;
2650
2651 $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, s.status";
2652 $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
2653 $sql .= " WHERE s.parent = " . ((int) $object->id);
2654 $sql .= " AND s.entity IN (" . getEntity('societe') . ")";
2655 $sql .= " ORDER BY s.nom";
2656
2657 $result = $db->query($sql);
2658 $num = $db->num_rows($result);
2659
2660 if ($num) {
2661 $socstatic = new Societe($db);
2662
2663 print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2664
2665 print "\n" . '<div class="div-table-responsive-no-min">' . "\n";
2666 print '<table class="noborder centpercent">' . "\n";
2667
2668 print '<tr class="liste_titre"><td>' . $langs->trans("Company") . '</td>';
2669 print '<td>' . $langs->trans("Address") . '</td><td>' . $langs->trans("Zip") . '</td>';
2670 print '<td>' . $langs->trans("Town") . '</td><td>' . $langs->trans("CustomerCode") . '</td>';
2671 print "<td>&nbsp;</td>";
2672 print "</tr>";
2673
2674 $i = 0;
2675
2676 while ($i < $num) {
2677 $obj = $db->fetch_object($result);
2678
2679 $socstatic->id = $obj->rowid;
2680 $socstatic->name = $obj->name;
2681 $socstatic->name_alias = $obj->name_alias;
2682 $socstatic->email = $obj->email;
2683 $socstatic->code_client = $obj->code_client;
2684 $socstatic->code_fournisseur = $obj->code_fournisseur;
2685 $socstatic->code_compta = $obj->code_compta;
2686 $socstatic->code_compta_client = $obj->code_compta;
2687 $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2688 $socstatic->email = $obj->email;
2689 $socstatic->canvas = $obj->canvas;
2690 $socstatic->client = $obj->client;
2691 $socstatic->fournisseur = $obj->fournisseur;
2692 $socstatic->status = $obj->status;
2693
2694 print '<tr class="oddeven">';
2695
2696 print '<td class="tdoverflowmax150">';
2697 print $socstatic->getNomUrl(1);
2698 print '</td>';
2699
2700 print '<td class="tdoverflowmax400" title="' . dol_escape_htmltag($obj->address) . '">' . dol_escape_htmltag($obj->address) . '</td>';
2701 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->zip) . '">' . $obj->zip . '</td>';
2702 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->town) . '">' . $obj->town . '</td>';
2703 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->code_client) . '">' . $obj->code_client . '</td>';
2704
2705 print '<td class="center">';
2706 print '<a class="editfielda" href="' . DOL_URL_ROOT . '/societe/card.php?socid=' . ((int) $obj->rowid) . '&action=edit&token=' . newToken() . '">';
2707 print img_edit();
2708 print '</a></td>';
2709
2710 print "</tr>\n";
2711 $i++;
2712 }
2713 print "\n</table>\n";
2714 print '</div>' . "\n";
2715 }
2716
2717 print "<br>\n";
2718
2719 return $i;
2720}
2729function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2730{
2731 global $db;
2732
2733 // Condition on actioncode
2734
2735 if ((string) $actioncode == '-1') {
2736 return $sql;
2737 }
2738
2739 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2740 if ($actioncode == 'AC_NON_AUTO') {
2741 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2742 } elseif ($actioncode == 'AC_ALL_AUTO') {
2743 $sql .= " $sqlANDOR c.type = 'systemauto'";
2744 } else {
2745 if ($actioncode == 'AC_OTH') {
2746 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2747 } elseif ($actioncode == 'AC_OTH_AUTO') {
2748 $sql .= " $sqlANDOR c.type = 'systemauto'";
2749 }
2750 }
2751 } else {
2752 if ($actioncode == 'AC_NON_AUTO') {
2753 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2754 } elseif ($actioncode == 'AC_ALL_AUTO') {
2755 $sql .= " $sqlANDOR c.type = 'systemauto'";
2756 } else {
2757 $sql .= " $sqlANDOR c.code = '" . $db->escape($actioncode) . "'";
2758 }
2759 }
2760
2761 return $sql;
2762}
2763
2773function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2774{
2775 global $db;
2776
2777 if ($donetodo == 'todo') {
2778 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) . "'))";
2779 } elseif ($donetodo == 'done') {
2780 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))";
2781 }
2782 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'na') {
2783 $sql .= " AND a.percent = -1";
2784 }
2785 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '0') {
2786 $sql .= " AND a.percent = 0";
2787 }
2788 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '50') {
2789 $sql .= " AND a.percent > 0 AND a.percent < 100";
2790 }
2791 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'todo') {
2792 $sql .= " AND a.percent >= 0 AND a.percent < 100";
2793 }
2794 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '100') {
2795 $sql .= " AND a.percent = 100";
2796 }
2797 if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2798 $sql .= natural_search('a.label', $filters['search_agenda_label']);
2799 }
2800 if (is_array($filters) && !empty($filters['search_rowid'])) {
2801 $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2802 }
2803 if (is_array($filters) && !empty($filters['search_filtert']) && ((int) $filters['search_filtert']) != -1) {
2804 $sql .= natural_search('a.fk_user_action', $filters['search_filtert'], 1);
2805 }
2806
2807 return $sql;
2808}
2809
2818function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2819{
2820 global $db;
2821
2822 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2823 if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2824 $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";
2825 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2826 $sql2 .= ", 'AC_EMAILING' as code, 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2827 $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
2828 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2829 $sql2 .= ", '' as lastname, '' as firstname";
2830 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2831 $sql2 .= ", '' as lastname, '' as firstname";
2832 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2833 $sql2 .= ", '' as ref";
2834 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2835 $sql2 .= ", '' as ref";
2836 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2837 $sql2 .= ", '' as ref";
2838 }
2839 $sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u";
2840 $sql2 .= " WHERE mc.email = '" . $db->escape($objcon->email) . "'"; // Search is done on email.
2841 $sql2 .= " AND mc.statut = 1";
2842 $sql2 .= " AND u.rowid = m.fk_user_valid";
2843 $sql2 .= " AND mc.fk_mailing=m.rowid";
2844
2845 return $sql2;
2846 } else {
2847 return '';
2848 }
2849}
2850
2851
2864function htmlPrintOnlineHeader($mysoc, $langs, $showlogo = 1, $alttext = '', $subimageconst = '', $altlogo1 = '', $altlogo2 = '')
2865{
2866 global $conf, $dolibarr_main_url_root;
2867
2868 // Set logo of company by default
2869 $logosmall = $mysoc->logo_small;
2870 $logo = $mysoc->logo;
2871
2872 if ($altlogo1 && getDolGlobalString($altlogo1)) {
2873 $logosmall = getDolGlobalString($altlogo1);
2874 } elseif ($altlogo2 && getDolGlobalString($altlogo2)) {
2875 $logosmall = getDolGlobalString($altlogo2);
2876 }
2877
2878 // Define $urllogo and $urllogopublic
2879 //$urllogo = '';
2880 $urllogopublic = '';
2881 if ($showlogo) {
2882 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $logosmall)) {
2883 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$logosmall);
2884 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/thumbs/' . $logosmall);
2885 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $logo)) {
2886 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$logo);
2887 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/' . $logo);
2888 } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) {
2889 //$urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
2890 $urllogopublic = $dolibarr_main_url_root . '/theme/dolibarr_logo.svg';
2891 }
2892 }
2893
2894 print '<header class="center">';
2895
2896 // Output html code for logo
2897 if ($urllogopublic || $alttext) {
2898 print '<div class="backgreypublicpayment">';
2899 print '<div class="logopublicpayment">';
2900 if ($urllogopublic) {
2901 if (!is_numeric($showlogo)) {
2902 print '<a href="' . $showlogo . '">';
2903 }
2904 print '<img id="dolpaymentlogo" src="' . $urllogopublic . '">';
2905 if (!is_numeric($showlogo)) {
2906 print '</a>';
2907 }
2908 }
2909 if ($alttext) {
2910 print '<div class="clearboth"></div><strong>' . $alttext . '</strong>';
2911 }
2912 print '</div>';
2913 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
2914 print '<div class="poweredbypublicpayment opacitymedium right hideonsmartphone"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">' . $langs->trans("PoweredBy") . '<br><img class="poweredbyimg" src="' . DOL_URL_ROOT . '/theme/dolibarr_logo.svg" width="80px"></a></div>';
2915 }
2916 print '</div>';
2917 }
2918
2919 // Add an optional image under the ban with logo/title
2920 if (getDolGlobalString($subimageconst)) {
2921 print '<div class="backimagepublicsubimage">';
2922 print '<img id="id' . $subimageconst . '" src="' . getDolGlobalString($subimageconst) . '">';
2923 print '</div>';
2924 }
2925
2926 print '</header>';
2927}
2928
2929
2940function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2941{
2942 global $conf;
2943
2944 $reg = array();
2945
2946 // Juridical status
2947 $line1 = "";
2948 if ($fromcompany->forme_juridique_code) {
2949 $line1 .= ($line1 ? " - " : "") . getFormeJuridiqueLabel((string) $fromcompany->forme_juridique_code);
2950 }
2951 // Capital
2952 if ($fromcompany->capital) {
2953 $line1 .= ($line1 ? " - " : "") . $langs->transnoentities("CapitalOf", (string) $fromcompany->capital) . " " . $langs->transnoentities("Currency" . getDolCurrency());
2954 }
2955 // Prof Id 1
2956 if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2957 $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2958 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2959 $field = $reg[1];
2960 }
2961 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof1;
2962 }
2963 // Prof Id 2
2964 if ($fromcompany->idprof2) {
2965 $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2966 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2967 $field = $reg[1];
2968 }
2969 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof2;
2970 }
2971
2972 // Second line of company infos
2973 $line2 = "";
2974 // Prof Id 3
2975 if ($fromcompany->idprof3) {
2976 $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2977 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2978 $field = $reg[1];
2979 }
2980 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof3;
2981 }
2982 // Prof Id 4
2983 if ($fromcompany->idprof4) {
2984 $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2985 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2986 $field = $reg[1];
2987 }
2988 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof4;
2989 }
2990 // IntraCommunautary VAT
2991 if ($fromcompany->tva_intra != '') {
2992 $line2 .= ($line2 ? " - " : "") . $langs->transnoentities("VATIntraShort") . ": " . $fromcompany->tva_intra;
2993 }
2994
2995 print '<!-- htmlPrintOnlineFooter -->' . "\n";
2996
2997 // 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.
2998 print '<footer class="center centpercent opacitymedium">' . "\n";
2999 print '<br>';
3000 if ($addformmessage) {
3001 print '<!-- object = ' . (empty($object) ? 'undefined' : $object->element) . ' -->';
3002 print '<br>';
3003
3004 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_' . $suffix;
3005 if (getDolGlobalString($parammessageform) !== '') {
3006 print $langs->transnoentities(getDolGlobalString($parammessageform));
3007 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
3008 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
3009 }
3010
3011 // Add other message if VAT exists
3012 if (!empty($object->total_vat) || !empty($object->total_tva)) {
3013 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_' . $suffix;
3014 if (getDolGlobalString($parammessageform) !== '') {
3015 print $langs->transnoentities(getDolGlobalString($parammessageform));
3016 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
3017 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
3018 }
3019 }
3020 }
3021
3022 print '<span style="font-size: 10px;"><br><hr>' . "\n";
3023 print $fromcompany->name . '<br>';
3024 print $line1;
3025 if (strlen($line1 . $line2) > 50) {
3026 print '<br>';
3027 } else {
3028 print ' - ';
3029 }
3030 print $line2;
3031 print '</span>';
3032 print '</footer>' . "\n";
3033}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
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.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
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 public pages.
show_actions_done($conf, $langs, $db, $filterobj, $objcon=null, $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=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
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.
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='', $massactionbutton='')
Show html area for list of projects.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add more SQL filters for event list.
getCountriesInSEPA()
Return list of countries that are inside the SEPA zone (Single Euro Payment Area) Note: Try to keep t...
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
isInSEPA($object)
Return if a country of an object is inside the SEPA zone (Single Euro Payment Area)
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
societe_admin_prepare_head()
Return array head with list of tabs to view object information.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='')
Show html area with actions to do.
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
global $mysoc
dol_dir_list($utf8_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:64
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
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=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.