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