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