dolibarr 21.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-2024 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 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('project') && ($user->hasRight('projet', 'lire'))) {
145 $nbProject = 0;
146 // Enable caching of thirdrparty count projects
147 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
148 $cachekey = 'count_projects_thirdparty_'.$object->id;
149 $dataretrieved = dol_getcache($cachekey);
150
151 if (!is_null($dataretrieved)) {
152 $nbProject = $dataretrieved;
153 } else {
154 $sql = "SELECT COUNT(n.rowid) as nb";
155 $sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
156 $sql .= " WHERE fk_soc = ".((int) $object->id);
157 $sql .= " AND entity IN (".getEntity('project').")";
158 $resql = $db->query($sql);
159 if ($resql) {
160 $obj = $db->fetch_object($resql);
161 $nbProject = $obj->nb;
162 } else {
163 dol_print_error($db);
164 }
165 dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
166 }
167 $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
168 $head[$h][1] = $langs->trans("Projects");
169 if ($nbProject > 0) {
170 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
171 }
172 $head[$h][2] = 'project';
173 $h++;
174 }
175
176 // Tab to link resources
177 if (isModEnabled('resource') && getDolGlobalString('RESOURCE_ON_THIRDPARTIES')) {
178 $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
179 $head[$h][1] = $langs->trans("Resources");
180 $head[$h][2] = 'resources';
181 $h++;
182 }
183
184 // Related items
185 if ((isModEnabled('order') || isModEnabled('propal') || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
186 && !getDolGlobalString('THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB')) {
187 $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
188 $head[$h][1] = $langs->trans("Referers");
189 $head[$h][2] = 'consumption';
190 $h++;
191 }
192
193 // Bank accounts
194 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
195 $nbBankAccount = 0;
196 $foundonexternalonlinesystem = 0;
197 $langs->load("bills");
198
199 $title = $langs->trans("PaymentModes");
200
201 $servicestatus = 0;
202 if (isModEnabled('stripe')) {
203 if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
204 $servicestatus = 1;
205 }
206
207 include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
208 $societeaccount = new SocieteAccount($db);
209 $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
210 if ($stripecu) {
211 $foundonexternalonlinesystem++;
212 }
213 }
214
215 $sql = "SELECT COUNT(n.rowid) as nb";
216 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
217 $sql .= " WHERE n.fk_soc = ".((int) $object->id);
218 if (!isModEnabled('stripe')) {
219 $sql .= " AND n.stripe_card_ref IS NULL";
220 } else {
221 $sql .= " AND (n.stripe_card_ref IS NULL OR (n.stripe_card_ref IS NOT NULL AND n.status = ".((int) $servicestatus)."))";
222 }
223
224 $resql = $db->query($sql);
225 if ($resql) {
226 $obj = $db->fetch_object($resql);
227 $nbBankAccount = $obj->nb;
228 } else {
229 dol_print_error($db);
230 }
231
232 //if (isModEnabled('stripe') && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
233
234 $head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.urlencode((string) ($object->id));
235 $head[$h][1] = $title;
236 if ($foundonexternalonlinesystem) {
237 $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
238 } elseif ($nbBankAccount > 0) {
239 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbBankAccount.'</span>';
240 }
241 $head[$h][2] = 'rib';
242 $h++;
243 }
244
245 if ((isModEnabled('website') || isModEnabled('webportal')) && $user->hasRight('societe', 'lire')) {
246 $site_filter_list = array();
247 if (isModEnabled('website')) {
248 $site_filter_list[] = 'dolibarr_website';
249 }
250 if (isModEnabled('webportal')) {
251 $site_filter_list[] = 'dolibarr_portal';
252 }
253
254 $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.urlencode((string) ($object->id));
255 $head[$h][1] = $langs->trans("WebSiteAccounts");
256 $nbNote = 0;
257 $sql = "SELECT COUNT(n.rowid) as nb";
258 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as n";
259 $sql .= " WHERE fk_soc = ".((int) $object->id);
260 $sql .= " AND entity IN (".getEntity('thirdpartyaccount').")";
261 if (!empty($site_filter_list)) {
262 $sql .= " AND n.site IN (".$db->sanitize("'".implode("','", $site_filter_list)."'", 1).")";
263 }
264 $resql = $db->query($sql);
265 if ($resql) {
266 $obj = $db->fetch_object($resql);
267 $nbNote = $obj->nb;
268 } else {
269 dol_print_error($db);
270 }
271 if ($nbNote > 0) {
272 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
273 }
274 $head[$h][2] = 'website';
275 $h++;
276 }
277
278 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
279 if ($user->hasRight('partnership', 'read')) {
280 $langs->load("partnership");
281 $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
282 $head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?socid='.$object->id;
283 $head[$h][1] = $langs->trans("Partnerships");
284 $nbNote = 0;
285 $sql = "SELECT COUNT(n.rowid) as nb";
286 $sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
287 $sql .= " WHERE fk_soc = ".((int) $object->id);
288 $sql .= " AND entity IN (".getEntity('partnership').")";
289 $resql = $db->query($sql);
290 if ($resql) {
291 $obj = $db->fetch_object($resql);
292 $nbNote = $obj->nb;
293 } else {
294 dol_print_error($db);
295 }
296 if ($nbNote > 0) {
297 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
298 }
299 $head[$h][2] = 'partnerships';
300 if ($nbPartnership > 0) {
301 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
302 }
303 $h++;
304 }
305 }
306
307 // Notifications
308 if (isModEnabled('ticket') && $user->hasRight("ticket", "read")) {
309 //$langs->load('ticket');
310 $nbTicket = 0;
311 // Enable caching of thirdparty count notifications
312 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
313 $cachekey = 'count_ticket_thirdparty_'.$object->id;
314 $nbticketretreived = dol_getcache($cachekey);
315 if (!is_null($nbticketretreived)) {
316 $nbTicket = $nbticketretreived;
317 } else {
318 // List of notifications enabled for contacts of the third party
319 $sql = "SELECT COUNT(t.rowid) as nb";
320 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
321 $sql .= " WHERE t.fk_soc = ".((int) $object->id);
322 $resql = $db->query($sql);
323 if ($resql) {
324 $obj = $db->fetch_object($resql);
325 $nbTicket = $obj->nb;
326 } else {
327 dol_print_error($db);
328 }
329 dol_setcache($cachekey, $nbTicket, 120); // If setting cache fails, this is not a problem, so we do not test result.
330 }
331
332 $head[$h][0] = DOL_URL_ROOT.'/ticket/list.php?socid='.urlencode((string) ($object->id));
333 $head[$h][1] = $langs->trans("Tickets");
334 if ($nbTicket > 0) {
335 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbTicket.'</span>';
336 }
337 $head[$h][2] = 'ticket';
338 $h++;
339 }
340
341
342 // Show more tabs from modules
343 // Entries must be declared in modules descriptor with line
344 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
345 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
346 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'core');
347
348 if ($user->socid == 0) {
349 // Notifications
350 if (isModEnabled('notification')) {
351 $langs->load('mails');
352 $nbNotif = 0;
353 // Enable caching of thirdparty count notifications
354 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
355 $cachekey = 'count_notifications_thirdparty_'.$object->id;
356 $dataretrieved = dol_getcache($cachekey);
357 if (!is_null($dataretrieved)) {
358 $nbNotif = $dataretrieved;
359 } else {
360 // List of notifications enabled for contacts of the third party
361 $sql = "SELECT COUNT(n.rowid) as nb";
362 $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
363 $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
364 $sql .= " ".MAIN_DB_PREFIX."socpeople as c";
365 $sql .= " WHERE a.rowid = n.fk_action";
366 $sql .= " AND c.rowid = n.fk_contact";
367 $sql .= " AND c.fk_soc = ".((int) $object->id);
368 $resql = $db->query($sql);
369 if ($resql) {
370 $obj = $db->fetch_object($resql);
371 $nbNotif = $obj->nb;
372 } else {
373 dol_print_error($db);
374 }
375 dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
376 }
377
378 $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.urlencode((string) ($object->id));
379 $head[$h][1] = $langs->trans("Notifications");
380 if ($nbNotif > 0) {
381 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
382 }
383 $head[$h][2] = 'notify';
384 $h++;
385 }
386
387 // Notes
388 $nbNote = 0;
389 if (!empty($object->note_private)) {
390 $nbNote++;
391 }
392 if (!empty($object->note_public)) {
393 $nbNote++;
394 }
395 $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.urlencode((string) ($object->id));
396 $head[$h][1] = $langs->trans("Notes");
397 if ($nbNote > 0) {
398 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
399 }
400 $head[$h][2] = 'note';
401 $h++;
402
403 // Attached files and Links
404 $totalAttached = 0;
405 // Enable caching of thirdrparty count attached files and links
406 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
407 $cachekey = 'count_attached_thirdparty_'.$object->id;
408 $dataretrieved = dol_getcache($cachekey);
409 if (!is_null($dataretrieved)) {
410 $totalAttached = $dataretrieved;
411 } else {
412 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
413 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
414 $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
415 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
416 $nbLinks = Link::count($db, $object->element, $object->id);
417 $totalAttached = $nbFiles + $nbLinks;
418 dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
419 }
420
421 $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
422 $head[$h][1] = $langs->trans("Documents");
423 if (($totalAttached) > 0) {
424 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
425 }
426 $head[$h][2] = 'document';
427 $h++;
428 }
429
430 $head[$h][0] = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
431 $head[$h][1] = $langs->trans("Events");
432 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
433 $nbEvent = 0;
434 // Enable caching of thirdparty count actioncomm
435 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
436 $cachekey = 'count_events_thirdparty_'.$object->id;
437 $dataretrieved = dol_getcache($cachekey);
438 if (!is_null($dataretrieved)) {
439 $nbEvent = $dataretrieved;
440 } else {
441 $sql = "SELECT COUNT(id) as nb";
442 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
443 $sql .= " WHERE fk_soc = ".((int) $object->id);
444 $sql .= " AND entity IN (".getEntity('agenda').")";
445 $resql = $db->query($sql);
446 if ($resql) {
447 $obj = $db->fetch_object($resql);
448 $nbEvent = $obj->nb;
449 } else {
450 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
451 }
452 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
453 }
454
455 $head[$h][1] .= '/';
456 $head[$h][1] .= $langs->trans("Agenda");
457 if ($nbEvent > 0) {
458 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
459 }
460 }
461 $head[$h][2] = 'agenda';
462 $h++;
463
464 // Show more tabs from modules
465 // Entries must be declared in modules descriptor with line
466 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
467 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
468 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'external');
469
470 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
471
472 return $head;
473}
474
475
483{
484 global $langs;
485 $h = 0;
486 $head = array();
487
488 $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
489 $head[$h][1] = $langs->trans("ThirdParty");
490 $head[$h][2] = 'company';
491 $h++;
492
493 $head[$h][0] = 'commerciaux.php?socid='.$object->id;
494 $head[$h][1] = $langs->trans("SalesRepresentative");
495 $head[$h][2] = 'salesrepresentative';
496 $h++;
497
498 return $head;
499}
500
501
502
509{
510 global $langs, $conf, $db;
511
512 $extrafields = new ExtraFields($db);
513 $extrafields->fetch_name_optionals_label('societe');
514 $extrafields->fetch_name_optionals_label('socpeople');
515
516 $h = 0;
517 $head = array();
518
519 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
520 $head[$h][1] = $langs->trans("Miscellaneous");
521 $head[$h][2] = 'general';
522 $h++;
523
524 // Show more tabs from modules
525 // Entries must be declared in modules descriptor with line
526 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
527 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
528 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
529
530 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
531 $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
532 $nbExtrafields = $extrafields->attributes['societe']['count'];
533 if ($nbExtrafields > 0) {
534 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
535 }
536 $head[$h][2] = 'attributes';
537 $h++;
538
539 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
540 $head[$h][1] = $langs->trans("ExtraFieldsContacts");
541 $nbExtrafields = $extrafields->attributes['socpeople']['count'];
542 if ($nbExtrafields > 0) {
543 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
544 }
545 $head[$h][2] = 'attributes_contacts';
546 $h++;
547
548 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
549
550 return $head;
551}
552
553
554
570function getCountry($searchkey, $withcode = '', $dbtouse = null, $outputlangs = null, $entconv = 1, $searchlabel = '')
571{
572 global $db, $langs;
573
574 $result = '';
575
576 // Check parameters
577 if (empty($searchkey) && empty($searchlabel)) {
578 if ($withcode === 'all') {
579 return array('id' => 0, 'code' => '', 'label' => '');
580 } else {
581 return '';
582 }
583 }
584 if (!is_object($dbtouse)) {
585 $dbtouse = $db;
586 }
587 if (!is_object($outputlangs)) {
588 $outputlangs = $langs;
589 }
590
591 $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
592 if (is_numeric($searchkey)) {
593 $sql .= " WHERE rowid = ".((int) $searchkey);
594 } elseif (!empty($searchkey)) {
595 $sql .= " WHERE code = '".$db->escape($searchkey)."'";
596 } else {
597 $sql .= " WHERE label = '".$db->escape($searchlabel)."'";
598 }
599
600 $resql = $dbtouse->query($sql);
601 if ($resql) {
602 $obj = $dbtouse->fetch_object($resql);
603 if ($obj) {
604 $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
605 if (is_object($outputlangs)) {
606 $outputlangs->load("dict");
607 if ($entconv) {
608 $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label;
609 } else {
610 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label;
611 }
612 }
613 if ($withcode == '1') {
614 $result = $label ? "$obj->code - $label" : "$obj->code";
615 } elseif ($withcode == '2') {
616 $result = $obj->code;
617 } elseif ($withcode == '3') {
618 $result = $obj->rowid;
619 } elseif ($withcode === 'all') {
620 $result = array('id' => $obj->rowid, 'code' => $obj->code, 'label' => $label);
621 } else {
622 $result = $label;
623 }
624 } else {
625 $result = 'NotDefined';
626 }
627 $dbtouse->free($resql);
628 return $result;
629 } else {
630 dol_print_error($dbtouse, '');
631 }
632 return 'Error';
633}
634
650function getState($id, $withcode = '0', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1)
651{
652 global $db, $langs;
653
654 if (!is_object($dbtouse)) {
655 $dbtouse = $db;
656 }
657
658 $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";
659 $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
660 $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".((int) $id);
661 $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
662 $sql .= " ORDER BY c.code, d.code_departement";
663
664 dol_syslog("Company.lib::getState", LOG_DEBUG);
665 $resql = $dbtouse->query($sql);
666 if ($resql) {
667 $obj = $dbtouse->fetch_object($resql);
668 if ($obj) {
669 $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
670 if (is_object($outputlangs)) {
671 $outputlangs->load("dict");
672 if ($entconv) {
673 $label = ($obj->code && ($outputlangs->trans("State".$obj->code) != "State".$obj->code)) ? $outputlangs->trans("State".$obj->code) : $label;
674 } else {
675 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code) != "State".$obj->code)) ? $outputlangs->transnoentitiesnoconv("State".$obj->code) : $label;
676 }
677 }
678
679 if ($withcode == 1) {
680 if ($withregion == 1) {
681 return $label = $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
682 } else {
683 return $label = $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
684 }
685 } elseif ($withcode == 2) {
686 if ($withregion == 1) {
687 return $label = $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
688 } else {
689 return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
690 }
691 } elseif ($withcode === 'all') {
692 if ($withregion == 1) {
693 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label, 'region_code' => $obj->region_code, 'region' => $obj->region_name);
694 } else {
695 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label);
696 }
697 } else {
698 if ($withregion == 1) {
699 return $label = $obj->region_name.' - '.$label;
700 } else {
701 return $label;
702 }
703 }
704 } else {
705 return $langs->transnoentitiesnoconv("NotDefined");
706 }
707 } else {
708 dol_print_error($dbtouse, '');
709 }
710
711 return '';
712}
713
722function currency_name($code_iso, $withcode = 0, $outputlangs = null)
723{
724 global $langs, $db;
725
726 if (empty($outputlangs)) {
727 $outputlangs = $langs;
728 }
729
730 $outputlangs->load("dict");
731
732 // If there is a translation, we can send immediately the label
733 if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
734 return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
735 }
736
737 // If no translation, we read table to get label by default
738 $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
739 $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
740
741 $resql = $db->query($sql);
742 if ($resql) {
743 $num = $db->num_rows($resql);
744
745 if ($num) {
746 $obj = $db->fetch_object($resql);
747 $label = ($obj->label != '-' ? $obj->label : '');
748 if ($withcode) {
749 return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
750 } else {
751 return $label;
752 }
753 } else {
754 return $code_iso;
755 }
756 }
757 return 'ErrorWhenReadingCurrencyLabel';
758}
759
768{
769 global $conf, $db, $langs;
770
771 if (!$code) {
772 return '';
773 }
774
775 if (!empty($conf->cache["legalform_".$langs->defaultlang.'_'.$code])) {
776 return $conf->cache["legalform_".$langs->defaultlang.'_'.$code];
777 }
778
779 $sql = "SELECT libelle as label FROM ".MAIN_DB_PREFIX."c_forme_juridique";
780 $sql .= " WHERE code = '".$db->escape($code)."'";
781
782 dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
783
784 $resql = $db->query($sql);
785 if ($resql) {
786 $num = $db->num_rows($resql);
787 if ($num) {
788 $obj = $db->fetch_object($resql);
789
790 $label = ($obj->label != '-' ? $obj->label : '');
791
792 $conf->cache["legalform_".$langs->defaultlang.'_'.$code] = $label;
793
794 return $langs->trans($label);
795 } else {
796 return $langs->trans("NotDefined");
797 }
798 } else {
799 return 'Error '.$db->lasterror();
800 }
801}
802
803
811{
812 // List of all country codes that are in europe for european vat rules
813 // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
814 global $conf, $db;
815 $country_code_in_EEC = array();
816
817 if (!empty($conf->cache['country_code_in_EEC'])) {
818 // Use of cache to reduce number of database requests
819 $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
820 } else {
821 $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
822 $sql .= " WHERE cc.eec = 1";
823
824 $resql = $db->query($sql);
825 if ($resql) {
826 $num = $db->num_rows($resql);
827 $i = 0;
828 while ($i < $num) {
829 $objp = $db->fetch_object($resql);
830 $country_code_in_EEC[] = $objp->code;
831 $i++;
832 }
833 } else {
834 dol_print_error($db);
835 }
836 $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
837 }
838 return $country_code_in_EEC;
839}
840
848{
849 if (empty($object->country_code)) {
850 return false;
851 }
852
853 $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
854
855 //print "dd".$object->country_code;
856 return in_array($object->country_code, $country_code_in_EEC);
857}
858
859
872function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
873{
874 global $user, $action, $hookmanager, $form, $massactionbutton, $massaction, $arrayofselected, $arrayofmassactions;
875
876 $i = -1;
877
878 if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
879 $langs->load("projects");
880
881 $newcardbutton = '';
882 if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
883 $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&action=create&backtopage='.urlencode($backtopage));
884 }
885
886 print "\n";
887 print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
888
889 print '<div class="div-table-responsive">'."\n";
890 print '<table class="noborder centpercent">';
891
892 $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";
893 $sql .= ", cls.code as opp_status_code";
894 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
895 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
896 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
897 $sql .= " AND p.entity IN (".getEntity('project').")";
898 $sql .= " ORDER BY p.dateo DESC";
899
900 $result = $db->query($sql);
901 if ($result) {
902 $num = $db->num_rows($result);
903
904 print '<tr class="liste_titre">';
905 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
906 print '<td class="center">';
907 $selectedfields = (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
908 print $selectedfields;
909 print '</td>';
910 }
911 print '<td>'.$langs->trans("Ref").'</td>';
912 print '<td>'.$langs->trans("Name").'</td>';
913 print '<td class="center">'.$langs->trans("DateStart").'</td>';
914 print '<td class="center">'.$langs->trans("DateEnd").'</td>';
915 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
916 print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
917 print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
918 print '<td class="right">'.$langs->trans("Status").'</td>';
919 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
920 print '<td class="center">';
921 $selectedfields = (is_array($arrayofmassactions) && count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
922 print $selectedfields;
923 print '</td>';
924 }
925 print '</tr>';
926
927 if ($num > 0) {
928 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
929
930 $projecttmp = new Project($db);
931
932 $i = 0;
933
934 while ($i < $num) {
935 $obj = $db->fetch_object($result);
936 $projecttmp->fetch($obj->id);
937
938 // To verify role of users
939 $userAccess = $projecttmp->restrictedProjectArea($user);
940
941 if ($user->hasRight('projet', 'lire') && $userAccess > 0) {
942 print '<tr class="oddeven">';
943
944 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
945 print '<td class="nowrap center actioncolumn">';
946 if ($massactionbutton || $massaction) {
947 $selected = 0;
948 if (in_array($obj->id, $arrayofselected)) {
949 $selected = 1;
950 }
951 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
952 }
953 print '</td>';
954 }
955 // Ref
956 print '<td class="nowraponall">';
957 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__');
958 print '</td>';
959
960 // Label
961 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
962 // Date start
963 print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
964 // Date end
965 print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
966 // Opp amount
967 print '<td class="right">';
968 if ($obj->opp_status_code) {
969 print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
970 }
971 print '</td>';
972 // Opp status
973 print '<td class="center">';
974 if ($obj->opp_status_code) {
975 print $langs->trans("OppStatus".$obj->opp_status_code);
976 }
977 print '</td>';
978 // Opp percent
979 print '<td class="right">';
980 if ($obj->opp_percent) {
981 print price($obj->opp_percent, 1, '', 1, 0).'%';
982 }
983 print '</td>';
984 // Status
985 print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
986
987 // Action column
988 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
989 print '<td class="nowrap center actioncolumn">';
990 if ($massactionbutton || $massaction) {
991 $selected = 0;
992 if (in_array($obj->id, $arrayofselected)) {
993 $selected = 1;
994 }
995 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
996 }
997 print '</td>';
998 }
999 print '</tr>';
1000 }
1001 $i++;
1002 }
1003 } else {
1004 print '<tr class="oddeven"><td colspan="9"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1005 }
1006 $db->free($result);
1007 } else {
1008 dol_print_error($db);
1009 }
1010
1011 //projects linked to that thirdpart because of a people of that company is linked to a project
1012 if (getDolGlobalString('PROJECT_DISPLAY_LINKED_BY_CONTACT')) {
1013 print "\n";
1014 print load_fiche_titre($langs->trans("ProjectsLinkedToThisThirdParty"), '', '');
1015
1016
1017 print '<div class="div-table-responsive">'."\n";
1018 print '<table class="noborder centpercent">';
1019
1020 $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";
1021 $sql .= ", cls.code as opp_status_code";
1022 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
1023 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
1024 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact as ec on p.rowid = ec.element_id";
1025 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sc on ec.fk_socpeople = sc.rowid";
1026 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_contact as tc on ec.fk_c_type_contact = tc.rowid";
1027 $sql .= " WHERE sc.fk_soc = ".((int) $object->id);
1028 $sql .= " AND p.entity IN (".getEntity('project').")";
1029 $sql .= " AND tc.element = 'project' AND tc.source = 'external'";
1030 $sql .= " ORDER BY p.dateo DESC";
1031
1032 $result = $db->query($sql);
1033 if ($result) {
1034 $num = $db->num_rows($result);
1035
1036 print '<tr class="liste_titre">';
1037 print '<td>'.$langs->trans("Ref").'</td>';
1038 print '<td>'.$langs->trans("Name").'</td>';
1039 print '<td class="center">'.$langs->trans("DateStart").'</td>';
1040 print '<td class="center">'.$langs->trans("DateEnd").'</td>';
1041 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
1042 print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
1043 print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
1044 print '<td class="right">'.$langs->trans("Status").'</td>';
1045 print '</tr>';
1046
1047 if ($num > 0) {
1048 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1049
1050 $projecttmp = new Project($db);
1051
1052 $i = 0;
1053
1054 while ($i < $num) {
1055 $obj = $db->fetch_object($result);
1056 $projecttmp->fetch($obj->id);
1057
1058 // To verify role of users
1059 $userAccess = $projecttmp->restrictedProjectArea($user);
1060
1061 if ($user->rights->projet->lire && $userAccess > 0) {
1062 print '<tr class="oddeven">';
1063
1064 // Ref
1065 print '<td class="nowraponall">';
1066 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__');
1067 print '</td>';
1068
1069 // Label
1070 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
1071 // Date start
1072 print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
1073 // Date end
1074 print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
1075 // Opp amount
1076 print '<td class="right">';
1077 if ($obj->opp_status_code) {
1078 print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
1079 }
1080 print '</td>';
1081 // Opp status
1082 print '<td class="center">';
1083 if ($obj->opp_status_code) {
1084 print $langs->trans("OppStatus".$obj->opp_status_code);
1085 }
1086 print '</td>';
1087 // Opp percent
1088 print '<td class="right">';
1089 if ($obj->opp_percent) {
1090 print price($obj->opp_percent, 1, '', 1, 0).'%';
1091 }
1092 print '</td>';
1093 // Status
1094 print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
1095
1096 print '</tr>';
1097 }
1098 $i++;
1099 }
1100 } else {
1101 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1102 }
1103 $db->free($result);
1104 } else {
1105 dol_print_error($db);
1106 }
1107 }
1108
1109 $parameters = array('sql' => $sql, 'function' => 'show_projects');
1110 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1111 print $hookmanager->resPrint;
1112
1113 print "</table>";
1114 print '</div>';
1115
1116 print "<br>\n";
1117 }
1118
1119 return $i;
1120}
1121
1122
1134function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
1135{
1136 global $user, $conf, $extrafields, $hookmanager;
1137 global $contextpage;
1138
1139 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
1140 $formcompany = new FormCompany($db);
1141 $form = new Form($db);
1142
1143 $optioncss = GETPOST('optioncss', 'alpha');
1144 $sortfield = GETPOST('sortfield', 'aZ09comma');
1145 $sortorder = GETPOST('sortorder', 'aZ09comma');
1146 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
1147
1148 $search_status = GETPOST("search_status", "intcomma");
1149 if ($search_status == '') {
1150 $search_status = 1; // always display active customer first
1151 }
1152
1153 $search_rowid = GETPOST("search_rowid", "intcomma");
1154 $search_name = GETPOST("search_name", 'alpha');
1155 $search_address = GETPOST("search_address", 'alpha');
1156 $search_poste = GETPOST("search_poste", 'alpha');
1157 $search_note_private = GETPOST('search_note_private', 'alphanohtml');
1158 $search_roles = GETPOST("search_roles", 'array');
1159 $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
1160 $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
1161
1162 if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
1163 $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_dtstartmonth'), GETPOSTINT('search_birthday_dtstartday'), GETPOSTINT('search_birthday_dtstartyear'));
1164 $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_dtendmonth'), GETPOSTINT('search_birthday_dtendday'), GETPOSTINT('search_birthday_dtendyear'));
1165 }
1166 $socialnetworks = getArrayOfSocialNetworks();
1167
1168 $searchAddressPhoneDBFields = array(
1169 //Address
1170 't.address',
1171 't.zip',
1172 't.town',
1173
1174 //Phone
1175 't.phone',
1176 't.phone_perso',
1177 't.phone_mobile',
1178
1179 //Fax
1180 't.fax',
1181
1182 //E-mail
1183 't.email',
1184 );
1185 //Social media
1186 // foreach ($socialnetworks as $key => $value) {
1187 // if ($value['active']) {
1188 // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
1189 // }
1190 // }
1191
1192 if (!$sortorder) {
1193 $sortorder = "ASC";
1194 }
1195 if (!$sortfield) {
1196 $sortfield = "t.lastname";
1197 }
1198
1199 if (isModEnabled('clicktodial')) {
1200 $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1201 }
1202
1203
1204 $contactstatic = new Contact($db);
1205
1206 $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1207
1208 $contactstatic->fields = array(
1209 'rowid' => array('type' => 'integer', 'label' => "TechnicalID", 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'visible' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1210 'name' => array('type' => 'varchar(128)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1),
1211 'poste' => array('type' => 'varchar(128)', 'label' => 'PostOrFunction', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 2, 'index' => 1, 'position' => 20),
1212 'address' => array('type' => 'varchar(128)', 'label' => 'Address', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 3, 'index' => 1, 'position' => 30),
1213 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => ((int) !getDolGlobalBool('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible' => 3, 'position' => 35),
1214 'role' => array('type' => 'checkbox', 'label' => 'Role', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 4, 'index' => 1, 'position' => 40),
1215 'birthday' => array('type' => 'date', 'label' => 'Birthday', 'enabled' => 1, 'visible' => -1, 'notnull' => 0, 'position' => 45),
1216 '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))),
1217 );
1218
1219 // Definition of fields for list
1220 $arrayfields = array(
1221 't.rowid' => array('label' => "TechnicalID", 'checked' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1222 't.name' => array('label' => "Name", 'checked' => 1, 'position' => 10),
1223 't.poste' => array('label' => "PostOrFunction", 'checked' => 1, 'position' => 20),
1224 '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),
1225 't.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'position' => 35),
1226 'sc.role' => array('label' => "ContactByDefaultFor", 'checked' => 1, 'position' => 40),
1227 't.birthday' => array('label' => "Birthday", 'checked' => 0, 'position' => 45),
1228 't.statut' => array('label' => "Status", 'checked' => 1, 'position' => 50, 'class' => 'center'),
1229 'u.user' => array('label' => "DolibarrLogin", 'checked' => 1, 'position' => 50, 'class' => 'center'),
1230 );
1231 // Extra fields
1232 if (!empty($extrafields->attributes[$contactstatic->table_element]['label']) && is_array($extrafields->attributes[$contactstatic->table_element]['label']) && count($extrafields->attributes[$contactstatic->table_element]['label'])) {
1233 foreach ($extrafields->attributes[$contactstatic->table_element]['label'] as $key => $val) {
1234 if (!empty($extrafields->attributes[$contactstatic->table_element]['list'][$key])) {
1235 $arrayfields["ef.".$key] = array(
1236 'label' => $extrafields->attributes[$contactstatic->table_element]['label'][$key],
1237 'checked' => (((int) dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1, 1, '1') < 0) ? 0 : 1),
1238 'position' => 1000 + $extrafields->attributes[$contactstatic->table_element]['pos'][$key],
1239 'enabled' => (abs((int) dol_eval($extrafields->attributes[$contactstatic->table_element]['list'][$key], 1)) != 3 && (int) dol_eval($extrafields->attributes[$contactstatic->table_element]['perms'][$key], 1, 1, '1'))
1240 );
1241 }
1242 }
1243 }
1244
1245 // Initialize array of search criteria
1246 $search = array();
1247 foreach ($arrayfields as $key => $val) {
1248 $queryName = 'search_'.substr($key, 2);
1249 if (GETPOST($queryName, 'alpha')) {
1250 $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1251 }
1252 }
1253 $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1254
1255 // Purge search criteria
1256 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
1257 $search_rowid = '';
1258 $search_status = '';
1259 $search_name = '';
1260 $search_roles = array();
1261 $search_address = '';
1262 $search_poste = '';
1263 $search_note_private = '';
1264 $search_birthday_dtstart = '';
1265 $search_birthday_dtend = '';
1266 $search = array();
1267 $search_array_options = array();
1268
1269 foreach ($contactstatic->fields as $key => $val) {
1270 $search[$key] = '';
1271 }
1272 }
1273
1274 $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1275 $arrayfields = dol_sort_array($arrayfields, 'position');
1276
1277 $newcardbutton = '';
1278 if ($user->hasRight('societe', 'contact', 'creer')) {
1279 $addcontact = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1280 $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?socid='.$object->id.'&action=create&backtopage='.urlencode($backtopage));
1281 }
1282
1283 print "\n";
1284
1285 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1286 print load_fiche_titre($title, $newcardbutton, 'contact');
1287
1288 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
1289 print '<input type="hidden" name="token" value="'.newToken().'">';
1290 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1291 print '<input type="hidden" name="socid" value="'.$object->id.'">';
1292 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1293 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1294 print '<input type="hidden" name="page" value="'.$page.'">';
1295
1296 $arrayofmassactions = array();
1297 $mode = 'view';
1298
1299 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1300 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1301 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1302 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1303
1304 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1305 print "\n".'<table class="tagtable liste noborder">'."\n";
1306
1307 $param = "socid=".urlencode((string) ($object->id));
1308 if ($search_rowid != '') {
1309 $param .= '&search_rowid='.urlencode((string) ($search_rowid));
1310 }
1311 if ($search_status != '') {
1312 $param .= '&search_status='.urlencode((string) ($search_status));
1313 }
1314 if (count($search_roles) > 0) {
1315 $param .= implode('&search_roles[]=', $search_roles);
1316 }
1317 if ($search_name != '') {
1318 $param .= '&search_name='.urlencode($search_name);
1319 }
1320 if ($search_poste != '') {
1321 $param .= '&search_poste='.urlencode($search_poste);
1322 }
1323 if ($search_address != '') {
1324 $param .= '&search_address='.urlencode($search_address);
1325 }
1326 if ($search_note_private != '') {
1327 $param .= '&search_note_private='.urlencode($search_note_private);
1328 }
1329 if ($search_birthday_dtstart != '') {
1330 $param .= '&search_birthday_dtstart='.urlencode($search_birthday_dtstart);
1331 }
1332 if ($search_birthday_dtend != '') {
1333 $param .= '&search_birthday_dtend='.urlencode($search_birthday_dtend);
1334 }
1335 if ($optioncss != '') {
1336 $param .= '&optioncss='.urlencode($optioncss);
1337 }
1338
1339 // Add $param from extra fields
1340 $extrafieldsobjectkey = $contactstatic->table_element;
1341 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1342
1343 $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1344 $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,";
1345 $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1346 $sql .= " t.note_private";
1347 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
1348 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1349 $sql .= " WHERE t.fk_soc = ".((int) $object->id);
1350 $sql .= " AND t.entity IN (" .getEntity('socpeople') .")";
1351 $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)";
1352 if ($search_rowid) {
1353 $sql .= natural_search('t.rowid', $search_rowid);
1354 }
1355 if ($search_status != '' && $search_status != '-1') {
1356 $sql .= " AND t.statut = ".((int) $search_status);
1357 }
1358 if ($search_name) {
1359 $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1360 }
1361 if ($search_poste) {
1362 $sql .= natural_search('t.poste', $search_poste);
1363 }
1364 if ($search_address) {
1365 $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1366 }
1367 if ($search_note_private) {
1368 $sql .= natural_search('t.note_private', $search_note_private);
1369 }
1370 if ($search_birthday_dtstart != '') {
1371 $sql .= " AND t.birthday >= '".$db->idate($search_birthday_dtstart)."'";
1372 }
1373 if ($search_birthday_dtend != '') {
1374 $sql .= " AND t.birthday <= '".$db->idate($search_birthday_dtend)."'";
1375 }
1376 if (count($search_roles) > 0) {
1377 $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))."))";
1378 }
1379 // Add where from extra fields
1380 $extrafieldsobjectkey = $contactstatic->table_element;
1381 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1382 // Add where from hooks
1383 $parameters = array('socid' => $object->id);
1384 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1385 $sql .= $hookmanager->resPrint;
1386 if ($sortfield == "t.name") {
1387 $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1388 } else {
1389 $sql .= " ORDER BY $sortfield $sortorder";
1390 }
1391
1392 dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1393 $result = $db->query($sql);
1394 if (!$result) {
1395 dol_print_error($db);
1396 }
1397
1398 $num = $db->num_rows($result);
1399
1400 // Fields title search
1401 // --------------------------------------------------------------------
1402 print '<tr class="liste_titre">';
1403 // Action column
1404 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1405 print '<td class="liste_titre" align="right">';
1406 print $form->showFilterButtons();
1407 print '</td>';
1408 }
1409 foreach ($contactstatic->fields as $key => $val) {
1410 $align = '';
1411 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1412 $align .= ($align ? ' ' : '').'center';
1413 }
1414 if (in_array($val['type'], array('timestamp'))) {
1415 $align .= ($align ? ' ' : '').'nowrap';
1416 }
1417 if ($key == 'status' || $key == 'statut') {
1418 $align .= ($align ? ' ' : '').'center';
1419 }
1420 if (!empty($arrayfields['t.'.$key]['checked']) || !empty($arrayfields['sc.'.$key]['checked'])) {
1421 print '<td class="liste_titre'.($align ? ' '.$align : '').'">';
1422 if (in_array($key, array('statut'))) {
1423 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');
1424 } elseif (in_array($key, array('role'))) {
1425 print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1426 } elseif (in_array($key, array('birthday'))) {
1427 print '<div class="nowrap">';
1428 print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1429 print '</div>';
1430 print '<div class="nowrap">';
1431 print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1432 print '</div>';
1433 } else {
1434 print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.(!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '').'">';
1435 }
1436 print '</td>';
1437 }
1438 }
1439 if ($showuserlogin) {
1440 print '<td class="liste_titre"></td>';
1441 }
1442 // Extra fields
1443 $extrafieldsobjectkey = $contactstatic->table_element;
1444 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1445
1446 // Fields from hook
1447 $parameters = array('arrayfields' => $arrayfields);
1448 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1449 print $hookmanager->resPrint;
1450 // Action column
1451 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1452 print '<td class="liste_titre" align="right">';
1453 print $form->showFilterButtons();
1454 print '</td>';
1455 }
1456 print '</tr>'."\n";
1457
1458
1459 // Fields title label
1460 // --------------------------------------------------------------------
1461 print '<tr class="liste_titre">';
1462 // Action column
1463 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1464 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1465 }
1466 foreach ($contactstatic->fields as $key => $val) {
1467 $align = '';
1468 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1469 $align .= ($align ? ' ' : '').'center';
1470 }
1471 if (in_array($val['type'], array('timestamp'))) {
1472 $align .= ($align ? ' ' : '').'nowrap';
1473 }
1474 if ($key == 'status' || $key == 'statut') {
1475 $align .= ($align ? ' ' : '').'center';
1476 }
1477 if (!empty($arrayfields['t.'.$key]['checked'])) {
1478 print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1479 }
1480 if ($key == 'role') {
1481 $align .= ($align ? ' ' : '').'left';
1482 }
1483 if (!empty($arrayfields['sc.'.$key]['checked'])) {
1484 print getTitleFieldOfList($arrayfields['sc.'.$key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="'.$align.'"' : ''), $sortfield, $sortorder, $align.' ')."\n";
1485 }
1486 }
1487 if ($showuserlogin) {
1488 print '<th class="wrapcolumntitle liste_titre">'.$langs->trans("DolibarrLogin").'</th>';
1489 }
1490 // Extra fields
1491 $extrafieldsobjectkey = $contactstatic->table_element;
1492 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1493 // Hook fields
1494 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1495 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1496 print $hookmanager->resPrint;
1497 // Action column
1498 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1499 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
1500 }
1501 print '</tr>'."\n";
1502
1503 $i = -1;
1504
1505 if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1506 $i = 0;
1507
1508 while ($i < $num) {
1509 $obj = $db->fetch_object($result);
1510
1511 $contactstatic->id = $obj->rowid;
1512 $contactstatic->ref = $obj->rowid;
1513 $contactstatic->statut = $obj->statut;
1514 $contactstatic->lastname = $obj->lastname;
1515 $contactstatic->firstname = $obj->firstname;
1516 $contactstatic->civility_id = $obj->civility_id;
1517 $contactstatic->civility_code = $obj->civility_id;
1518 $contactstatic->poste = $obj->poste;
1519 $contactstatic->address = $obj->address;
1520 $contactstatic->zip = $obj->zip;
1521 $contactstatic->town = $obj->town;
1522 $contactstatic->phone_pro = $obj->phone_pro;
1523 $contactstatic->phone_mobile = $obj->phone_mobile;
1524 $contactstatic->phone_perso = $obj->phone_perso;
1525 $contactstatic->email = $obj->email;
1526 $contactstatic->socialnetworks = $obj->socialnetworks;
1527 $contactstatic->photo = $obj->photo;
1528 $contactstatic->fk_soc = $obj->fk_soc;
1529 $contactstatic->entity = $obj->entity;
1530
1531 $country_code = getCountry($obj->country_id, '2');
1532 $contactstatic->country_code = $country_code;
1533
1534 $contactstatic->setGenderFromCivility();
1535 $contactstatic->fetch_optionals();
1536
1537 $resultRole = $contactstatic->fetchRoles();
1538 if ($resultRole < 0) {
1539 setEventMessages(null, $contactstatic->errors, 'errors');
1540 }
1541
1542 if (is_array($contactstatic->array_options)) {
1543 foreach ($contactstatic->array_options as $key => $val) {
1544 $obj->$key = $val;
1545 }
1546 }
1547
1548 print '<tr class="oddeven">';
1549
1550 // Actions
1551 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1552 print '<td class="nowrap center">';
1553
1554 // Add to agenda
1555 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1556 print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1557 print img_object($langs->trans("Event"), "action");
1558 print '</a> &nbsp; ';
1559 }
1560
1561 // Edit
1562 if ($user->hasRight('societe', 'contact', 'creer')) {
1563 print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1564 print img_edit();
1565 print '</a>';
1566 }
1567
1568 // Delete
1569 if ($user->hasRight('societe', 'contact', 'delete')) {
1570 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).'">';
1571 print img_delete();
1572 print '</a>';
1573 }
1574
1575 print '</td>';
1576 }
1577
1578 // ID
1579 if (!empty($arrayfields['t.rowid']['checked'])) {
1580 print '<td>';
1581 print $contactstatic->id;
1582 print '</td>';
1583 }
1584
1585 // Photo - Name
1586 if (!empty($arrayfields['t.name']['checked'])) {
1587 print '<td class="tdoverflowmax150">';
1588 print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 1);
1589 print $contactstatic->getNomUrl(0, '', 0, '&backtopage='.urlencode($backtopage));
1590 print '</td>';
1591 }
1592
1593 // Job position
1594 if (!empty($arrayfields['t.poste']['checked'])) {
1595 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->poste).'">';
1596 if ($obj->poste) {
1597 print dol_escape_htmltag($obj->poste);
1598 }
1599 print '</td>';
1600 }
1601
1602 // Address - Phone - Email
1603 if (!empty($arrayfields['t.address']['checked'])) {
1604 $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1605 print '<td class="tdoverflowmax150" title="'.dolPrintHTMLForAttribute($addresstoshow).'">';
1606 print $addresstoshow;
1607 print '</td>';
1608 }
1609
1610 // Note private
1611 if (!empty($arrayfields['t.note_private']['checked'])) {
1612 print '<td class="center">';
1613 print dolPrintHTML($obj->note_private);
1614 print '</td>';
1615 }
1616
1617 // Role
1618 if (!empty($arrayfields['sc.role']['checked'])) {
1619 print '<td class="tdoverflowmax150">';
1620 print $formcompany->showRoles("roles", $contactstatic, 'view');
1621 print '</td>';
1622 }
1623
1624 // Birthday
1625 if (!empty($arrayfields['t.birthday']['checked'])) {
1626 print '<td class="nowraponall">';
1627 print dol_print_date($db->jdate($obj->birthday));
1628 print '</td>';
1629 }
1630
1631 // Status
1632 if (!empty($arrayfields['t.statut']['checked'])) {
1633 print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1634 }
1635
1636 if ($showuserlogin) {
1637 print '<td class="tdoverflowmax125">';
1638 $tmpuser = new User($db);
1639 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1640 $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1641 if ($resfetch > 0) {
1642 print $tmpuser->getNomUrl(-1, '', 0, 0, 24, 1);
1643 }
1644 print '</td>';
1645 }
1646
1647 // Extra fields
1648 $extrafieldsobjectkey = $contactstatic->table_element;
1649 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1650
1651 // Actions
1652 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1653 print '<td class="nowrap center">';
1654
1655 // Add to agenda
1656 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1657 print '<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&actioncode=&contactid='.$obj->rowid.'&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">';
1658 print img_object($langs->trans("Event"), "action");
1659 print '</a> &nbsp; ';
1660 }
1661
1662 // Edit
1663 if ($user->hasRight('societe', 'contact', 'creer')) {
1664 print '<a class="editfielda paddingleft" href="'.DOL_URL_ROOT.'/contact/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($backtopage).'">';
1665 print img_edit();
1666 print '</a>';
1667 }
1668
1669 // Delete
1670 if ($user->hasRight('societe', 'contact', 'delete')) {
1671 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).'">';
1672 print img_delete();
1673 print '</a>';
1674 }
1675
1676 print '</td>';
1677 }
1678
1679 print "</tr>\n";
1680 $i++;
1681 }
1682
1683 if ($num == 0) {
1684 $colspan = 1 + ($showuserlogin ? 1 : 0);
1685 foreach ($arrayfields as $key => $val) {
1686 if (!empty($val['checked'])) {
1687 $colspan++;
1688 }
1689 }
1690 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1691 }
1692 } else {
1693 $colspan = 1 + ($showuserlogin ? 1 : 0);
1694 foreach ($arrayfields as $key => $val) {
1695 if (!empty($val['checked'])) {
1696 $colspan++;
1697 }
1698 }
1699 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1700 }
1701 print "\n</table>\n";
1702 print '</div>';
1703
1704 print '</form>'."\n";
1705
1706 return $i;
1707}
1708
1709
1722function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '')
1723{
1724 global $user, $conf;
1725
1726 $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1727
1728 if ($noprint) {
1729 return $out;
1730 } else {
1731 print $out;
1732 return null;
1733 }
1734}
1735
1754function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1755{
1756 global $user, $conf, $hookmanager;
1757 global $form;
1758 global $param, $massactionbutton;
1759
1760 $start_year = GETPOSTINT('dateevent_startyear');
1761 $start_month = GETPOSTINT('dateevent_startmonth');
1762 $start_day = GETPOSTINT('dateevent_startday');
1763 $end_year = GETPOSTINT('dateevent_endyear');
1764 $end_month = GETPOSTINT('dateevent_endmonth');
1765 $end_day = GETPOSTINT('dateevent_endday');
1766 $tms_start = '';
1767 $tms_end = '';
1768
1769 if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1770 $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1771 }
1772 if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1773 $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1774 }
1775 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
1776 $tms_start = '';
1777 $tms_end = '';
1778 }
1779 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1780
1781 // Check parameters
1782 if (!is_object($filterobj) && !is_object($objcon)) {
1783 dol_print_error(null, 'BadParameter');
1784 }
1785
1786 $out = '';
1787 $histo = array();
1788 $numaction = 0;
1789 $now = dol_now('tzuser');
1790
1791 // Open DSI -- Fix order by -- Begin
1792 $sortfield_list = explode(',', $sortfield);
1793 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1794 $sortfield_new_list = array();
1795 foreach ($sortfield_list as $sortfield_value) {
1796 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1797 }
1798 $sortfield_new = implode(',', $sortfield_new_list);
1799
1800 $sql = '';
1801
1802 if (isModEnabled('agenda')) {
1803 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
1804 $hookmanager->initHooks(array('agendadao'));
1805
1806 $sql = "SELECT a.id, a.label as label,";
1807 $sql .= " a.datep as dp,";
1808 $sql .= " a.datep2 as dp2,";
1809 $sql .= " a.percent as percent, 'action' as type,";
1810 $sql .= " a.fk_element, a.elementtype,";
1811 $sql .= " a.fk_contact,";
1812 $sql .= " a.code,";
1813 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1814 $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";
1815 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1816 $sql .= ", sp.lastname, sp.firstname";
1817 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1818 /* Nothing */
1819 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1820 /* Nothing */
1821 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1822 $sql .= ", m.lastname, m.firstname";
1823 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1824 $sql .= ", o.ref";
1825 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1826 $sql .= ", o.ref";
1827 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1828 $sql .= ", o.ref";
1829 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1830 $sql .= ", o.ref";
1831 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1832 $sql .= ", o.ref";
1833 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1834 if (!empty($filterobj->fields['ref'])) {
1835 $sql .= ", o.ref";
1836 } elseif (!empty($filterobj->fields['label'])) {
1837 $sql .= ", o.label";
1838 }
1839 }
1840
1841 // Fields from hook
1842 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1843 $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1844 if (!empty($hookmanager->resPrint)) {
1845 $sql .= $hookmanager->resPrint;
1846 }
1847
1848 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1849 // Link to the owner of action
1850 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1851 // Link to action types
1852 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1853
1854 // Set $force_filter_contact:
1855 // - true for a filter on a user or a contact, so a link on table llx_actioncomm_resources or llx_actioncomm.fk_user_action
1856 // - false for a link on table llx_element_resources
1857 $force_filter_contact = false;
1858 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
1859 $force_filter_contact = true;
1860 }
1861 if (is_object($objcon) && $objcon->id > 0) {
1862 $force_filter_contact = true;
1863 }
1864
1865 // Fields from hook
1866 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1867 $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1868 if (!empty($hookmanager->resPrint)) {
1869 $sql .= $hookmanager->resPrint;
1870 }
1871 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1872 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1873 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1874 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1875 $sql .= " ON er.resource_type = 'dolresource'";
1876 $sql .= " AND er.element_id = a.id";
1877 $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1878 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1879 /* Nothing */
1880 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1881 $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1882 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1883 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1884 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1885 $sql .= ", ".MAIN_DB_PREFIX."product as o";
1886 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1887 $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1888 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1889 $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1890 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1891 $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1892 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1893 && ((!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-curren-line PhanTypeInvalidDimOffset
1894 && $filterobj->table_element && $filterobj->element) {
1895 $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1896 }
1897
1898 $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1899 if (!$force_filter_contact) {
1900 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1901 $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1902 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1903 /* Nothing */
1904 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1905 $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1906 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1907 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1908 if ($filterobj->id) {
1909 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1910 }
1911 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
1912 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
1913 if ($filterobj->id) {
1914 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1915 }
1916 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1917 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1918 if ($filterobj->id) {
1919 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1920 }
1921 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
1922 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
1923 if ($filterobj->id) {
1924 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1925 }
1926 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
1927 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice_supplier'";
1928 if ($filterobj->id) {
1929 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1930 }
1931 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1932 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1933 if ($filterobj->id) {
1934 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1935 }
1936 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1937 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1938 if ($filterobj->id) {
1939 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1940 }
1941 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1942 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1943 if ($filterobj->id) {
1944 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1945 }
1946 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1947 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1948 if ($filterobj->id) {
1949 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1950 }
1951 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1952 && ((!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
1953 && $filterobj->table_element && $filterobj->element) {
1954 // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
1955 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1956 if ($filterobj->id) {
1957 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1958 }
1959 } elseif (is_object($filterobj)) {
1960 return 'Bad value for $filterobj';
1961 }
1962 } else {
1963 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
1964 $sql .= " AND (u.rowid = ". ((int) $filterobj->id).' OR ';
1965 $sql .= " EXISTS (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
1966 $sql .= " AND r.element_type = '".$db->escape($filterobj->table_element)."' AND r.fk_element = ".((int) $filterobj->id).')';
1967 $sql .= ")";
1968 }
1969 if (is_object($objcon) && $objcon->id > 0) {
1970 $sql .= " AND EXISTS (SELECT r.rowid FROM ".MAIN_DB_PREFIX."actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
1971 $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id).')';
1972 }
1973 }
1974
1975 if (!empty($tms_start) && !empty($tms_end)) {
1976 $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)."'))";
1977 } elseif (empty($tms_start) && !empty($tms_end)) {
1978 $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1979 } elseif (!empty($tms_start) && empty($tms_end)) {
1980 $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1981 }
1982
1983 if (is_array($actioncode) && !empty($actioncode)) {
1984 $sql .= ' AND (';
1985 foreach ($actioncode as $key => $code) {
1986 if ((string) $code == '-1') {
1987 continue;
1988 }
1989 if ($key != 0) {
1990 $sql .= " OR ";
1991 }
1992 if (!empty($code)) {
1993 addEventTypeSQL($sql, $code, "");
1994 }
1995 }
1996 $sql .= ')';
1997 } elseif (!empty($actioncode) && $actioncode != '-1') {
1998 addEventTypeSQL($sql, $actioncode);
1999 }
2000
2001 addOtherFilterSQL($sql, $donetodo, $now, $filters);
2002
2003 // Fields from hook
2004 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
2005 $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
2006 if (!empty($hookmanager->resPrint)) {
2007 $sql .= $hookmanager->resPrint;
2008 }
2009
2010 // Now add events of emailing module
2011 if (is_array($actioncode)) {
2012 foreach ($actioncode as $code) {
2013 $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
2014 if (!empty($sql2)) {
2015 if (!empty($sql)) {
2016 $sql = $sql." UNION ".$sql2;
2017 } elseif (empty($sql)) {
2018 $sql = $sql2;
2019 }
2020 break;
2021 }
2022 }
2023 } else {
2024 $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
2025 if (!empty($sql) && !empty($sql2)) {
2026 $sql = $sql." UNION ".$sql2;
2027 } elseif (empty($sql) && !empty($sql2)) {
2028 $sql = $sql2;
2029 }
2030 }
2031 }
2032
2033 if ($sql) {
2034 //TODO Add navigation with this limits...
2035 $offset = 0;
2036 $limit = 1000;
2037
2038 // Complete request and execute it with limit
2039 $sql .= $db->order($sortfield_new, $sortorder);
2040 if ($limit) { // @phpstan-ignore-line
2041 $sql .= $db->plimit($limit + 1, $offset);
2042 }
2043
2044 dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
2045
2046 $resql = $db->query($sql);
2047 if ($resql) {
2048 $i = 0;
2049 $num = $db->num_rows($resql);
2050
2051 $imaxinloop = ($limit ? min($num, $limit) : $num);
2052 while ($i < $imaxinloop) {
2053 $obj = $db->fetch_object($resql);
2054
2055 if ($obj->type == 'action') {
2056 $contactaction = new ActionComm($db);
2057 $contactaction->id = $obj->id;
2058 $result = $contactaction->fetchResources();
2059 if ($result < 0) {
2060 dol_print_error($db);
2061 setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2062 }
2063
2064 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2065 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2066 $tododone = '';
2067 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2068 $tododone = 'todo';
2069 }
2070
2071 $histo[$numaction] = array(
2072 'type' => $obj->type,
2073 'tododone' => $tododone,
2074 'id' => (int) $obj->id,
2075 'datestart' => $db->jdate($obj->dp),
2076 'dateend' => $db->jdate($obj->dp2),
2077 'note' => $obj->label,
2078 'percent' => (int) $obj->percent,
2079
2080 'userid' => (int) $obj->user_id,
2081 'login' => $obj->user_login,
2082 'userfirstname' => $obj->user_firstname,
2083 'userlastname' => $obj->user_lastname,
2084 'userphoto' => $obj->user_photo,
2085
2086 'contact_id' => (int) $obj->fk_contact,
2087 'socpeopleassigned' => $contactaction->socpeopleassigned,
2088 'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2089 'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2090 'fk_element' => (int) $obj->fk_element,
2091 'elementtype' => $obj->elementtype,
2092
2093 'code' => $obj->code,
2094
2095 // Type of event
2096 'acode' => $obj->acode,
2097 'alabel' => $obj->alabel,
2098 'libelle' => $obj->alabel, // deprecated
2099 'apicto' => $obj->apicto
2100 );
2101 } else {
2102 $histo[$numaction] = array(
2103 'type' => $obj->type,
2104 'tododone' => 'done',
2105 'id' => (int) $obj->id,
2106 'datestart' => $db->jdate($obj->dp),
2107 'dateend' => $db->jdate($obj->dp2),
2108 'note' => $obj->label,
2109 'percent' => (int) $obj->percent,
2110
2111 'code' => $obj->code,
2112
2113 // Type of event
2114 'acode' => $obj->acode,
2115
2116 'userid' => (int) $obj->user_id,
2117 'login' => $obj->user_login,
2118 'userfirstname' => $obj->user_firstname,
2119 'userlastname' => $obj->user_lastname,
2120 'userphoto' => $obj->user_photo
2121 );
2122 }
2123
2124 $numaction++;
2125 $i++;
2126 }
2127 } else {
2128 dol_print_error($db);
2129 }
2130 }
2131
2132 '@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';
2133
2134 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2135 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
2136
2137 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
2138 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2139 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2140 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2141
2142 $formactions = new FormActions($db);
2143
2144 $actionstatic = new ActionComm($db);
2145 $userstatic = new User($db);
2146 $userlinkcache = array();
2147 $contactstatic = new Contact($db);
2148 $elementlinkcache = array();
2149
2150 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2151 $out .= '<input type="hidden" name="token" value="'.newToken().'">';
2152 if ($objcon && get_class($objcon) == 'Contact' &&
2153 (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
2154 $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
2155 } else {
2156 $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
2157 }
2158 if ($filterobj && get_class($filterobj) == 'Societe') {
2159 $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
2160 } else {
2161 $out .= '<input type="hidden" name="userid" value="'.$filterobj->id.'" />';
2162 }
2163
2164 $out .= "\n";
2165
2166 $out .= '<div class="div-table-responsive-no-min">';
2167 $out .= '<table class="noborder centpercent">';
2168
2169 $out .= '<tr class="liste_titre">';
2170
2171 // Action column
2172 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2173 $out .= '<th class="liste_titre width50 middle">';
2174 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2175 $out .= $searchpicto;
2176 $out .= '</th>';
2177 }
2178
2179 if ($donetodo) {
2180 $out .= '<td class="liste_titre"></td>';
2181 }
2182
2183 // ID
2184 $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
2185 // Date
2186 $out .= '<td class="liste_titre center">';
2187 $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2188 $out .= '</td>';
2189 // Owner
2190 $out .= '<td class="liste_titre"></td>';
2191 // Type
2192 $out .= '<td class="liste_titre">';
2193 $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);
2194 $out .= '</td>';
2195 // Label
2196 $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
2197 $out .= '<td class="liste_titre"></td>';
2198 $out .= '<td class="liste_titre"></td>';
2199 $out .= '<td class="liste_titre"></td>';
2200 // Action column
2201 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2202 $out .= '<td class="liste_titre" align="middle">';
2203 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2204 $out .= $searchpicto;
2205 $out .= '</td>';
2206 }
2207 $out .= '</tr>';
2208
2209 $out .= '<tr class="liste_titre">';
2210 // Action column
2211 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2212 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2213 }
2214 if ($donetodo && $filterobj !== null) {
2215 $tmp = '';
2216 if (get_class($filterobj) == 'Societe') {
2217 $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
2218 }
2219 if (get_class($filterobj) == 'User') {
2220 $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&userid='.$filterobj->id.'&status=done">';
2221 }
2222 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2223 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2224 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2225 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2226 if (get_class($filterobj) == 'Societe') {
2227 $tmp .= '</a>';
2228 }
2229 if (get_class($filterobj) == 'User') {
2230 $tmp .= '</a>';
2231 }
2232 $out .= getTitleFieldOfList($tmp);
2233 }
2234 $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2235 $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2236 $out .= getTitleFieldOfList("Owner");
2237 $out .= getTitleFieldOfList("Type");
2238 $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2239 $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2240 $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2241 $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2242 // Action column
2243 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2244 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2245 }
2246 $out .= '</tr>';
2247
2248 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
2249 $caction = new CActionComm($db);
2250 $arraylist = $caction->liste_array(1, 'code', '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 0 : 1), '', 1);
2251
2252 foreach ($histo as $key => $value) {
2253 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2254
2255 if (empty($actionstatic->code)) {
2256 $actionstatic->code = $histo[$key]['acode'];
2257 }
2258 $actionstatic->type_picto = $histo[$key]['apicto'] ?? '';
2259 $actionstatic->type_code = $histo[$key]['acode'];
2260
2261 $out .= '<tr class="oddeven">';
2262
2263 // Action column
2264 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2265 $out .= '<td></td>';
2266 }
2267
2268 // Done or todo
2269 if ($donetodo) {
2270 $out .= '<td class="nowrap">';
2271 $out .= '</td>';
2272 }
2273
2274 // Ref
2275 $out .= '<td class="nowraponall">';
2276 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2277 $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2278 $out .= $histo[$key]['id'];
2279 $out .= '</a>';
2280 } else {
2281 $out .= $actionstatic->getNomUrl(1, -1);
2282 }
2283 $out .= '</td>';
2284
2285 // Date
2286 $out .= '<td class="center nowraponall">';
2287 $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
2288 if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
2289 $tmpa = dol_getdate($histo[$key]['datestart'], true);
2290 $tmpb = dol_getdate($histo[$key]['dateend'], true);
2291 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2292 $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
2293 } else {
2294 $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
2295 }
2296 }
2297 $late = 0;
2298 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2299 $late = 1;
2300 }
2301 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2302 $late = 1;
2303 }
2304 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2305 $late = 1;
2306 }
2307 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2308 $late = 1;
2309 }
2310 if ($late) {
2311 $out .= img_warning($langs->trans("Late")).' ';
2312 }
2313 $out .= "</td>\n";
2314
2315 // Author of event
2316 $out .= '<td class="tdoverflowmax125">';
2317 if ($histo[$key]['userid'] > 0) {
2318 if (isset($userlinkcache[$histo[$key]['userid']])) {
2319 $link = $userlinkcache[$histo[$key]['userid']];
2320 } else {
2321 $userstatic->fetch($histo[$key]['userid']);
2322 $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2323 $userlinkcache[$histo[$key]['userid']] = $link;
2324 }
2325 $out .= $link;
2326 }
2327 $out .= '</td>';
2328
2329 // type_code // column "acode" in the sql = code in type of actioncomm, example: AC_OTH_AUTO, AC_EMAILING
2330 // code // columne code in the sql (not yet added), can be AC_CONTACT_SENTBYMAIL, ...
2331
2332 // Type
2333 $labelOfTypeToShow = $actionstatic->type_code;
2334 //$typelabel = $actionstatic->type_label;
2335 $code = $actionstatic->code;
2336 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labelOfTypeToShow])) {
2337 $labelOfTypeToShow = 'AC_OTH';
2338 }
2339 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2340 $labelOfTypeToShow = $langs->trans("Message");
2341 } else {
2342 if (!empty($arraylist[$labelOfTypeToShow])) {
2343 $labelOfTypeToShow = $arraylist[$labelOfTypeToShow];
2344 } elseif ($actionstatic->type_code == 'AC_EMAILING') {
2345 $langs->load("mails");
2346 $labelOfTypeToShow = $langs->trans("Emailing");
2347 }
2348 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labelOfTypeToShow && !empty($arraylist[$actionstatic->code])) {
2349 $labelOfTypeToShow .= ' - '.$arraylist[$actionstatic->code]; // Show also detailed code
2350 }
2351 }
2352
2353 $labelOfTypeToShowLong = $labelOfTypeToShow;
2354 if ($actionstatic->type_code == 'AC_OTH_AUTO') {
2355 $labelOfTypeToShowLong .= ' (auto)';
2356 }
2357
2358 $out .= '<td class="tdoverflowmax125" title="'.$labelOfTypeToShowLong.'">';
2359 $out .= $actionstatic->getTypePicto();
2360 //if (empty($conf->dol_optimize_smallscreen)) {
2361 $out .= $labelOfTypeToShow;
2362 //}
2363 $out .= '</td>';
2364
2365 // Title/Label of event
2366 $out .= '<td class="tdoverflowmax300"';
2367 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2368 $transcode = $langs->trans("Action".$histo[$key]['acode']);
2369 //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2370 $label = $histo[$key]['note'];
2371 $actionstatic->id = $histo[$key]['id'];
2372 $out .= ' title="'.dol_escape_htmltag($label).'">';
2373 $out .= dol_trunc($label, 120);
2374 }
2375 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2376 $transcode = $langs->trans("Action".$histo[$key]['acode']);
2377 $label = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2378 $label .= ' - '.$histo[$key]['note'];
2379 $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'"';
2380 $out .= ' title="'.dol_escape_htmltag($label).'">';
2381 //$out .= img_object($langs->trans("EMailing").'<br>'.$histo[$key]['note'], "email").' ';
2382 $out .= dol_trunc($label, 120);
2383 $out .= '</a>';
2384 }
2385 $out .= '</td>';
2386
2387 // Linked object
2388 $out .= '<td class="tdoverflowmax200 nowraponall">';
2389 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2390 if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2391 $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2392 } else {
2393 if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2394 $elementlinkcache[$histo[$key]['elementtype']] = array();
2395 }
2396 $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2397 $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2398 }
2399 $out .= $link;
2400 }
2401 $out .= '</td>';
2402
2403 // Contact(s) for action
2404 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2405 $out .= '<td class="valignmiddle">';
2406 $contact = new Contact($db);
2407 foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2408 $result = $contact->fetch($cid);
2409
2410 if ($result < 0) {
2411 dol_print_error($db, $contact->error);
2412 }
2413
2414 if ($result > 0) {
2415 $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2416 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2417 if (!empty($contact->phone_pro)) {
2418 $out .= '('.dol_print_phone($contact->phone_pro).')';
2419 }
2420 }
2421 $out .= '<div class="paddingright"></div>';
2422 }
2423 }
2424 $out .= '</td>';
2425 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2426 $contactstatic->lastname = $histo[$key]['lastname'];
2427 $contactstatic->firstname = $histo[$key]['firstname'];
2428 $contactstatic->id = $histo[$key]['contact_id'];
2429 $contactstatic->photo = $histo[$key]['contact_photo'];
2430 $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2431 } else {
2432 $out .= '<td>&nbsp;</td>';
2433 }
2434
2435 // Status
2436 $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2437
2438 // Action column
2439 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2440 $out .= '<td></td>';
2441 }
2442
2443 $out .= "</tr>\n";
2444 }
2445 if (empty($histo)) {
2446 $colspan = 9;
2447 $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2448 }
2449
2450 $out .= "</table>\n";
2451 $out .= "</div>\n";
2452
2453 $out .= '</form>';
2454 }
2455
2456 if ($noprint) {
2457 return $out;
2458 } else {
2459 print $out;
2460 return null;
2461 }
2462}
2463
2473function show_subsidiaries($conf, $langs, $db, $object)
2474{
2475 global $user;
2476
2477 $i = -1;
2478
2479 $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";
2480 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2481 $sql .= " WHERE s.parent = ".((int) $object->id);
2482 $sql .= " AND s.entity IN (".getEntity('societe').")";
2483 $sql .= " ORDER BY s.nom";
2484
2485 $result = $db->query($sql);
2486 $num = $db->num_rows($result);
2487
2488 if ($num) {
2489 $socstatic = new Societe($db);
2490
2491 print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2492
2493 print "\n".'<div class="div-table-responsive-no-min">'."\n";
2494 print '<table class="noborder centpercent">'."\n";
2495
2496 print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2497 print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2498 print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2499 print "<td>&nbsp;</td>";
2500 print "</tr>";
2501
2502 $i = 0;
2503
2504 while ($i < $num) {
2505 $obj = $db->fetch_object($result);
2506
2507 $socstatic->id = $obj->rowid;
2508 $socstatic->name = $obj->name;
2509 $socstatic->name_alias = $obj->name_alias;
2510 $socstatic->email = $obj->email;
2511 $socstatic->code_client = $obj->code_client;
2512 $socstatic->code_fournisseur = $obj->code_fournisseur;
2513 $socstatic->code_compta = $obj->code_compta;
2514 $socstatic->code_compta_client = $obj->code_compta;
2515 $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2516 $socstatic->email = $obj->email;
2517 $socstatic->canvas = $obj->canvas;
2518 $socstatic->client = $obj->client;
2519 $socstatic->fournisseur = $obj->fournisseur;
2520 $socstatic->status = $obj->status;
2521
2522 print '<tr class="oddeven">';
2523
2524 print '<td class="tdoverflowmax150">';
2525 print $socstatic->getNomUrl(1);
2526 print '</td>';
2527
2528 print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2529 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2530 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2531 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2532
2533 print '<td class="center">';
2534 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2535 print img_edit();
2536 print '</a></td>';
2537
2538 print "</tr>\n";
2539 $i++;
2540 }
2541 print "\n</table>\n";
2542 print '</div>'."\n";
2543 }
2544
2545 print "<br>\n";
2546
2547 return $i;
2548}
2557function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2558{
2559 global $db;
2560
2561 // Condition on actioncode
2562
2563 if ((string) $actioncode == '-1') {
2564 return $sql;
2565 }
2566
2567 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2568 if ($actioncode == 'AC_NON_AUTO') {
2569 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2570 } elseif ($actioncode == 'AC_ALL_AUTO') {
2571 $sql .= " $sqlANDOR c.type = 'systemauto'";
2572 } else {
2573 if ($actioncode == 'AC_OTH') {
2574 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2575 } elseif ($actioncode == 'AC_OTH_AUTO') {
2576 $sql .= " $sqlANDOR c.type = 'systemauto'";
2577 }
2578 }
2579 } else {
2580 if ($actioncode == 'AC_NON_AUTO') {
2581 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2582 } elseif ($actioncode == 'AC_ALL_AUTO') {
2583 $sql .= " $sqlANDOR c.type = 'systemauto'";
2584 } else {
2585 $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2586 }
2587 }
2588
2589 return $sql;
2590}
2591
2601function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2602{
2603 global $db;
2604
2605 if ($donetodo == 'todo') {
2606 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2607 } elseif ($donetodo == 'done') {
2608 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2609 }
2610 if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2611 $sql .= natural_search('a.label', $filters['search_agenda_label']);
2612 }
2613 if (is_array($filters) && !empty($filters['search_rowid'])) {
2614 $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2615 }
2616
2617 return $sql;
2618}
2619
2628function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2629{
2630 global $db;
2631
2632 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2633 if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2634 $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";
2635 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2636 $sql2 .= ", 'AC_EMAILING' as code, 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2637 $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
2638 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2639 $sql2 .= ", '' as lastname, '' as firstname";
2640 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2641 $sql2 .= ", '' as lastname, '' as firstname";
2642 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2643 $sql2 .= ", '' as ref";
2644 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2645 $sql2 .= ", '' as ref";
2646 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2647 $sql2 .= ", '' as ref";
2648 }
2649 $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2650 $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2651 $sql2 .= " AND mc.statut = 1";
2652 $sql2 .= " AND u.rowid = m.fk_user_valid";
2653 $sql2 .= " AND mc.fk_mailing=m.rowid";
2654
2655 return $sql2;
2656 } else {
2657 return '';
2658 }
2659}
2660
2661
2670function htmlPrintOnlineHeader($mysoc, $langs, $suffix = '')
2671{
2672 global $conf;
2673
2674 // Define urllogo
2675 $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
2676 $suffix = GETPOST("suffix", 'aZ09');
2677
2678 $customLogoWithSuffix = getDolGlobalString('ONLINE_SIGN_LOGO_'.$suffix);
2679 $customLogo = getDolGlobalString('ONLINE_SIGN_LOGO');
2680
2681 if (!empty($customLogoWithSuffix) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$customLogoWithSuffix)) {
2682 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$customLogoWithSuffix);
2683 } elseif (!empty($customLogo) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$customLogo)) {
2684 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$customLogo);
2685 } elseif (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
2686 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
2687 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
2688 $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
2689 } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
2690 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
2691 }
2692
2693 print '<header class="center">';
2694
2695 // Output html code for logo
2696 print '<div class="backgreypublicpayment">';
2697 print '<div class="logopublicpayment">';
2698 print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
2699 print '</div>';
2700 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
2701 print '<div class="poweredbypublicpayment opacitymedium right"><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>';
2702 }
2703 print '</div>';
2704
2705 if (getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION')) {
2706 print '<div class="backimagepublicregistration">';
2707 print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('MEMBER_IMAGE_PUBLIC_REGISTRATION').'">';
2708 print '</div>';
2709 }
2710
2711 print '</header>';
2712}
2713
2714
2725function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2726{
2727 global $conf;
2728
2729 $reg = array();
2730
2731 // Juridical status
2732 $line1 = "";
2733 if ($fromcompany->forme_juridique_code) {
2734 $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel((string) $fromcompany->forme_juridique_code);
2735 }
2736 // Capital
2737 if ($fromcompany->capital) {
2738 $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
2739 }
2740 // Prof Id 1
2741 if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2742 $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2743 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2744 $field = $reg[1];
2745 }
2746 $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
2747 }
2748 // Prof Id 2
2749 if ($fromcompany->idprof2) {
2750 $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2751 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2752 $field = $reg[1];
2753 }
2754 $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
2755 }
2756
2757 // Second line of company infos
2758 $line2 = "";
2759 // Prof Id 3
2760 if ($fromcompany->idprof3) {
2761 $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2762 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2763 $field = $reg[1];
2764 }
2765 $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
2766 }
2767 // Prof Id 4
2768 if ($fromcompany->idprof4) {
2769 $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2770 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2771 $field = $reg[1];
2772 }
2773 $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
2774 }
2775 // IntraCommunautary VAT
2776 if ($fromcompany->tva_intra != '') {
2777 $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
2778 }
2779
2780 print '<!-- htmlPrintOnlineFooter -->'."\n";
2781
2782 // 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.
2783 print '<footer class="center centpercent opacitymedium">'."\n";
2784 print '<br>';
2785 if ($addformmessage) {
2786 print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
2787 print '<br>';
2788
2789 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
2790 if (getDolGlobalString($parammessageform) !== '') {
2791 print $langs->transnoentities(getDolGlobalString($parammessageform));
2792 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
2793 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
2794 }
2795
2796 // Add other message if VAT exists
2797 if (!empty($object->total_vat) || !empty($object->total_tva)) {
2798 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
2799 if (getDolGlobalString($parammessageform) !== '') {
2800 print $langs->transnoentities(getDolGlobalString($parammessageform));
2801 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
2802 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
2803 }
2804 }
2805 }
2806
2807 print '<span style="font-size: 10px;"><br><hr>'."\n";
2808 print $fromcompany->name.'<br>';
2809 print $line1;
2810 if (strlen($line1.$line2) > 50) {
2811 print '<br>';
2812 } else {
2813 print ' - ';
2814 }
2815 print $line2;
2816 print '</span>';
2817 print '</footer>'."\n";
2818}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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, $suffix='')
Show header of company in HTML public pages.
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML 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.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
societe_admin_prepare_head()
Return array head with list of tabs to view object 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.
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:63
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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'.
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.
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...
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.
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
dol_setcache($memoryid, $data, $expire=0, $filecache=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.