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