dolibarr 21.0.0-alpha
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 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 * or see https://www.gnu.org/
29 */
30
44{
45 global $db, $langs, $conf, $user;
46 global $hookmanager;
47
48 $h = 0;
49 $head = array();
50
51 $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
52 $head[$h][1] = $langs->trans("ThirdParty");
53 $head[$h][2] = 'card';
54 $h++;
55
56
57 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB') && $user->hasRight('societe', 'contact', 'lire')) {
58 //$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
59 $nbContact = 0;
60 // Enable caching of thirdrparty count Contacts
61 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
62 $cachekey = 'count_contacts_thirdparty_'.$object->id;
63 $dataretrieved = dol_getcache($cachekey);
64
65 if (!is_null($dataretrieved)) {
66 $nbContact = $dataretrieved;
67 } else {
68 $sql = "SELECT COUNT(p.rowid) as nb";
69 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
70 // Add table from hooks
71 $parameters = array('contacttab' => true);
72 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
73 $sql .= $hookmanager->resPrint;
74 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
75 $sql .= " AND p.entity IN (".getEntity($object->element).")";
76 // Add where from hooks
77 $parameters = array('contacttab' => true);
78 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
79 $sql .= $hookmanager->resPrint;
80 $resql = $db->query($sql);
81 if ($resql) {
82 $obj = $db->fetch_object($resql);
83 $nbContact = $obj->nb;
84 }
85
86 dol_setcache($cachekey, $nbContact, 120); // If setting cache fails, this is not a problem, so we do not test result.
87 }
88
89 $head[$h][0] = DOL_URL_ROOT.'/societe/contact.php?socid='.$object->id;
90 $head[$h][1] = $langs->trans('ContactsAddresses');
91 if ($nbContact > 0) {
92 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
93 }
94 $head[$h][2] = 'contact';
95 $h++;
96 }
97 if (getDolGlobalString('MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES')) {
98 // Some features may be unstable with this option, like permissions rules, import contact, ...
99 $head[$h][0] = DOL_URL_ROOT.'/societe/societecontact.php?socid='.$object->id;
100 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
101 $head[$h][1] = $langs->trans("ContactsAddressesExt");
102 if ($nbContact > 0) {
103 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
104 }
105 $head[$h][2] = 'contactext';
106 $h++;
107 }
108
109 if ($object->client == 1 || $object->client == 2 || $object->client == 3) {
110 $head[$h][0] = DOL_URL_ROOT.'/comm/card.php?socid='.$object->id;
111 $head[$h][1] = '';
112 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && ($object->client == 2 || $object->client == 3)) {
113 $head[$h][1] .= $langs->trans("Prospect");
114 }
115 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && $object->client == 3) {
116 $head[$h][1] .= ' | ';
117 }
118 if (!getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && ($object->client == 1 || $object->client == 3)) {
119 $head[$h][1] .= $langs->trans("Customer");
120 }
121 $head[$h][2] = 'customer';
122 $h++;
123
124 if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
125 $langs->load("products");
126 // price
127 $head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
128 $head[$h][1] = $langs->trans("CustomerPrices");
129 $head[$h][2] = 'price';
130 $h++;
131 }
132 }
133 $supplier_module_enabled = 0;
134 if (isModEnabled('supplier_proposal') || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
135 $supplier_module_enabled = 1;
136 }
137 if ($supplier_module_enabled == 1 && $object->fournisseur && $user->hasRight('fournisseur', 'lire')) {
138 $head[$h][0] = DOL_URL_ROOT.'/fourn/card.php?socid='.$object->id;
139 $head[$h][1] = $langs->trans("Supplier");
140 $head[$h][2] = 'supplier';
141 $h++;
142 }
143
144 if (isModEnabled('project') && ($user->hasRight('projet', 'lire'))) {
145 $nbProject = 0;
146 // Enable caching of thirdrparty count projects
147 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
148 $cachekey = 'count_projects_thirdparty_'.$object->id;
149 $dataretrieved = dol_getcache($cachekey);
150
151 if (!is_null($dataretrieved)) {
152 $nbProject = $dataretrieved;
153 } else {
154 $sql = "SELECT COUNT(n.rowid) as nb";
155 $sql .= " FROM ".MAIN_DB_PREFIX."projet as n";
156 $sql .= " WHERE fk_soc = ".((int) $object->id);
157 $sql .= " AND entity IN (".getEntity('project').")";
158 $resql = $db->query($sql);
159 if ($resql) {
160 $obj = $db->fetch_object($resql);
161 $nbProject = $obj->nb;
162 } else {
163 dol_print_error($db);
164 }
165 dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
166 }
167 $head[$h][0] = DOL_URL_ROOT.'/societe/project.php?socid='.$object->id;
168 $head[$h][1] = $langs->trans("Projects");
169 if ($nbProject > 0) {
170 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
171 }
172 $head[$h][2] = 'project';
173 $h++;
174 }
175
176 // Tab to link resources
177 if (isModEnabled('resource') && getDolGlobalString('RESOURCE_ON_THIRDPARTIES')) {
178 $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=societe&element_id='.$object->id;
179 $head[$h][1] = $langs->trans("Resources");
180 $head[$h][2] = 'resources';
181 $h++;
182 }
183
184 // Related items
185 if ((isModEnabled('order') || isModEnabled('propal') || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
186 && !getDolGlobalString('THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB')) {
187 $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id;
188 $head[$h][1] = $langs->trans("Referers");
189 $head[$h][2] = 'consumption';
190 $h++;
191 }
192
193 // Bank accounts
194 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
195 $nbBankAccount = 0;
196 $foundonexternalonlinesystem = 0;
197 $langs->load("bills");
198
199 $title = $langs->trans("PaymentModes");
200
201 if (isModEnabled('stripe')) {
202 $servicestatus = 0;
203 if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
204 $servicestatus = 1;
205 }
206
207 include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
208 $societeaccount = new SocieteAccount($db);
209 $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
210 if ($stripecu) {
211 $foundonexternalonlinesystem++;
212 }
213 }
214
215 $sql = "SELECT COUNT(n.rowid) as nb";
216 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
217 $sql .= " WHERE n.fk_soc = ".((int) $object->id);
218 if (!isModEnabled('stripe')) {
219 $sql .= " AND n.stripe_card_ref IS NULL";
220 } else {
221 $sql .= " AND (n.stripe_card_ref IS NULL OR (n.stripe_card_ref IS NOT NULL AND n.status = ".((int) $servicestatus)."))";
222 }
223
224 $resql = $db->query($sql);
225 if ($resql) {
226 $obj = $db->fetch_object($resql);
227 $nbBankAccount = $obj->nb;
228 } else {
229 dol_print_error($db);
230 }
231
232 //if (isModEnabled('stripe') && $nbBankAccount > 0) $nbBankAccount = '...'; // No way to know exact number
233
234 $head[$h][0] = DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.urlencode((string) ($object->id));
235 $head[$h][1] = $title;
236 if ($foundonexternalonlinesystem) {
237 $head[$h][1] .= '<span class="badge marginleftonlyshort">...</span>';
238 } elseif ($nbBankAccount > 0) {
239 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbBankAccount.'</span>';
240 }
241 $head[$h][2] = 'rib';
242 $h++;
243 }
244
245 if ((isModEnabled('website') || isModEnabled('webportal')) && $user->hasRight('societe', 'lire')) {
246 $site_filter_list = array();
247 if (isModEnabled('website')) {
248 $site_filter_list[] = 'dolibarr_website';
249 }
250 if (isModEnabled('webportal')) {
251 $site_filter_list[] = 'dolibarr_portal';
252 }
253
254 $head[$h][0] = DOL_URL_ROOT.'/societe/website.php?id='.urlencode((string) ($object->id));
255 $head[$h][1] = $langs->trans("WebSiteAccounts");
256 $nbNote = 0;
257 $sql = "SELECT COUNT(n.rowid) as nb";
258 $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as n";
259 $sql .= " WHERE fk_soc = ".((int) $object->id);
260 $sql .= " AND entity IN (".getEntity('thirdpartyaccount').")";
261 if (!empty($site_filter_list)) {
262 $sql .= " AND n.site IN (".$db->sanitize("'".implode("','", $site_filter_list)."'", 1).")";
263 }
264 $resql = $db->query($sql);
265 if ($resql) {
266 $obj = $db->fetch_object($resql);
267 $nbNote = $obj->nb;
268 } else {
269 dol_print_error($db);
270 }
271 if ($nbNote > 0) {
272 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
273 }
274 $head[$h][2] = 'website';
275 $h++;
276 }
277
278 if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') {
279 if ($user->hasRight('partnership', 'read')) {
280 $langs->load("partnership");
281 $nbPartnership = is_array($object->partnerships) ? count($object->partnerships) : 0;
282 $head[$h][0] = DOL_URL_ROOT.'/partnership/partnership_list.php?socid='.$object->id;
283 $head[$h][1] = $langs->trans("Partnerships");
284 $nbNote = 0;
285 $sql = "SELECT COUNT(n.rowid) as nb";
286 $sql .= " FROM ".MAIN_DB_PREFIX."partnership as n";
287 $sql .= " WHERE fk_soc = ".((int) $object->id);
288 $sql .= " AND entity IN (".getEntity('partnership').")";
289 $resql = $db->query($sql);
290 if ($resql) {
291 $obj = $db->fetch_object($resql);
292 $nbNote = $obj->nb;
293 } else {
294 dol_print_error($db);
295 }
296 if ($nbNote > 0) {
297 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
298 }
299 $head[$h][2] = 'partnerships';
300 if ($nbPartnership > 0) {
301 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbPartnership.'</span>';
302 }
303 $h++;
304 }
305 }
306
307 // Notifications
308 if (isModEnabled('ticket') && $user->hasRight("ticket", "read")) {
309 //$langs->load('ticket');
310 $nbTicket = 0;
311 // Enable caching of thirdparty count notifications
312 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
313 $cachekey = 'count_ticket_thirdparty_'.$object->id;
314 $nbticketretreived = dol_getcache($cachekey);
315 if (!is_null($nbticketretreived)) {
316 $nbTicket = $nbticketretreived;
317 } else {
318 // List of notifications enabled for contacts of the third party
319 $sql = "SELECT COUNT(t.rowid) as nb";
320 $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
321 $sql .= " WHERE t.fk_soc = ".((int) $object->id);
322 $resql = $db->query($sql);
323 if ($resql) {
324 $obj = $db->fetch_object($resql);
325 $nbTicket = $obj->nb;
326 } else {
327 dol_print_error($db);
328 }
329 dol_setcache($cachekey, $nbTicket, 120); // If setting cache fails, this is not a problem, so we do not test result.
330 }
331
332 $head[$h][0] = DOL_URL_ROOT.'/ticket/list.php?socid='.urlencode((string) ($object->id));
333 $head[$h][1] = $langs->trans("Tickets");
334 if ($nbTicket > 0) {
335 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbTicket.'</span>';
336 }
337 $head[$h][2] = 'ticket';
338 $h++;
339 }
340
341
342 // Show more tabs from modules
343 // Entries must be declared in modules descriptor with line
344 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
345 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
346 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'core');
347
348 if ($user->socid == 0) {
349 // Notifications
350 if (isModEnabled('notification')) {
351 $langs->load('mails');
352 $nbNotif = 0;
353 // Enable caching of thirdparty count notifications
354 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
355 $cachekey = 'count_notifications_thirdparty_'.$object->id;
356 $dataretrieved = dol_getcache($cachekey);
357 if (!is_null($dataretrieved)) {
358 $nbNotif = $dataretrieved;
359 } else {
360 // List of notifications enabled for contacts of the third party
361 $sql = "SELECT COUNT(n.rowid) as nb";
362 $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
363 $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
364 $sql .= " ".MAIN_DB_PREFIX."socpeople as c";
365 $sql .= " WHERE a.rowid = n.fk_action";
366 $sql .= " AND c.rowid = n.fk_contact";
367 $sql .= " AND c.fk_soc = ".((int) $object->id);
368 $resql = $db->query($sql);
369 if ($resql) {
370 $obj = $db->fetch_object($resql);
371 $nbNotif = $obj->nb;
372 } else {
373 dol_print_error($db);
374 }
375 dol_setcache($cachekey, $nbNotif, 120); // If setting cache fails, this is not a problem, so we do not test result.
376 }
377
378 $head[$h][0] = DOL_URL_ROOT.'/societe/notify/card.php?socid='.urlencode((string) ($object->id));
379 $head[$h][1] = $langs->trans("Notifications");
380 if ($nbNotif > 0) {
381 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNotif.'</span>';
382 }
383 $head[$h][2] = 'notify';
384 $h++;
385 }
386
387 // Notes
388 $nbNote = 0;
389 if (!empty($object->note_private)) {
390 $nbNote++;
391 }
392 if (!empty($object->note_public)) {
393 $nbNote++;
394 }
395 $head[$h][0] = DOL_URL_ROOT.'/societe/note.php?id='.urlencode((string) ($object->id));
396 $head[$h][1] = $langs->trans("Notes");
397 if ($nbNote > 0) {
398 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
399 }
400 $head[$h][2] = 'note';
401 $h++;
402
403 // Attached files and Links
404 $totalAttached = 0;
405 // Enable caching of thirdrparty count attached files and links
406 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
407 $cachekey = 'count_attached_thirdparty_'.$object->id;
408 $dataretrieved = dol_getcache($cachekey);
409 if (!is_null($dataretrieved)) {
410 $totalAttached = $dataretrieved;
411 } else {
412 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
413 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
414 $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id;
415 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
416 $nbLinks = Link::count($db, $object->element, $object->id);
417 $totalAttached = $nbFiles + $nbLinks;
418 dol_setcache($cachekey, $totalAttached, 120); // If setting cache fails, this is not a problem, so we do not test result.
419 }
420
421 $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id;
422 $head[$h][1] = $langs->trans("Documents");
423 if (($totalAttached) > 0) {
424 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($totalAttached).'</span>';
425 }
426 $head[$h][2] = 'document';
427 $h++;
428 }
429
430 $head[$h][0] = DOL_URL_ROOT.'/societe/messaging.php?socid='.$object->id;
431 $head[$h][1] = $langs->trans("Events");
432 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
433 $nbEvent = 0;
434 // Enable caching of thirdparty count actioncomm
435 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
436 $cachekey = 'count_events_thirdparty_'.$object->id;
437 $dataretrieved = dol_getcache($cachekey);
438 if (!is_null($dataretrieved)) {
439 $nbEvent = $dataretrieved;
440 } else {
441 $sql = "SELECT COUNT(id) as nb";
442 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
443 $sql .= " WHERE fk_soc = ".((int) $object->id);
444 $sql .= " AND entity IN (".getEntity('agenda').")";
445 $resql = $db->query($sql);
446 if ($resql) {
447 $obj = $db->fetch_object($resql);
448 $nbEvent = $obj->nb;
449 } else {
450 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
451 }
452 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
453 }
454
455 $head[$h][1] .= '/';
456 $head[$h][1] .= $langs->trans("Agenda");
457 if ($nbEvent > 0) {
458 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
459 }
460 }
461 $head[$h][2] = 'agenda';
462 $h++;
463
464 // Show more tabs from modules
465 // Entries must be declared in modules descriptor with line
466 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
467 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
468 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'add', 'external');
469
470 complete_head_from_modules($conf, $langs, $object, $head, $h, 'thirdparty', 'remove');
471
472 return $head;
473}
474
475
483{
484 global $langs;
485 $h = 0;
486 $head = array();
487
488 $head[$h][0] = DOL_URL_ROOT.'/societe/card.php?socid='.$object->id;
489 $head[$h][1] = $langs->trans("ThirdParty");
490 $head[$h][2] = 'company';
491 $h++;
492
493 $head[$h][0] = 'commerciaux.php?socid='.$object->id;
494 $head[$h][1] = $langs->trans("SalesRepresentative");
495 $head[$h][2] = 'salesrepresentative';
496 $h++;
497
498 return $head;
499}
500
501
502
509{
510 global $langs, $conf, $db;
511
512 $extrafields = new ExtraFields($db);
513 $extrafields->fetch_name_optionals_label('societe');
514 $extrafields->fetch_name_optionals_label('socpeople');
515
516 $h = 0;
517 $head = array();
518
519 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe.php';
520 $head[$h][1] = $langs->trans("Miscellaneous");
521 $head[$h][2] = 'general';
522 $h++;
523
524 // Show more tabs from modules
525 // Entries must be declared in modules descriptor with line
526 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
527 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
528 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin');
529
530 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/societe_extrafields.php';
531 $head[$h][1] = $langs->trans("ExtraFieldsThirdParties");
532 $nbExtrafields = $extrafields->attributes['societe']['count'];
533 if ($nbExtrafields > 0) {
534 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
535 }
536 $head[$h][2] = 'attributes';
537 $h++;
538
539 $head[$h][0] = DOL_URL_ROOT.'/societe/admin/contact_extrafields.php';
540 $head[$h][1] = $langs->trans("ExtraFieldsContacts");
541 $nbExtrafields = $extrafields->attributes['socpeople']['count'];
542 if ($nbExtrafields > 0) {
543 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
544 }
545 $head[$h][2] = 'attributes_contacts';
546 $h++;
547
548 complete_head_from_modules($conf, $langs, null, $head, $h, 'company_admin', 'remove');
549
550 return $head;
551}
552
553
554
570function getCountry($searchkey, $withcode = '', $dbtouse = null, $outputlangs = null, $entconv = 1, $searchlabel = '')
571{
572 global $db, $langs;
573
574 $result = '';
575
576 // Check parameters
577 if (empty($searchkey) && empty($searchlabel)) {
578 if ($withcode === 'all') {
579 return array('id' => 0, 'code' => '', 'label' => '');
580 } else {
581 return '';
582 }
583 }
584 if (!is_object($dbtouse)) {
585 $dbtouse = $db;
586 }
587 if (!is_object($outputlangs)) {
588 $outputlangs = $langs;
589 }
590
591 $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_country";
592 if (is_numeric($searchkey)) {
593 $sql .= " WHERE rowid = ".((int) $searchkey);
594 } elseif (!empty($searchkey)) {
595 $sql .= " WHERE code = '".$db->escape($searchkey)."'";
596 } else {
597 $sql .= " WHERE label = '".$db->escape($searchlabel)."'";
598 }
599
600 $resql = $dbtouse->query($sql);
601 if ($resql) {
602 $obj = $dbtouse->fetch_object($resql);
603 if ($obj) {
604 $label = ((!empty($obj->label) && $obj->label != '-') ? $obj->label : '');
605 if (is_object($outputlangs)) {
606 $outputlangs->load("dict");
607 if ($entconv) {
608 $label = ($obj->code && ($outputlangs->trans("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->trans("Country".$obj->code) : $label;
609 } else {
610 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("Country".$obj->code) != "Country".$obj->code)) ? $outputlangs->transnoentitiesnoconv("Country".$obj->code) : $label;
611 }
612 }
613 if ($withcode == 1) {
614 $result = $label ? "$obj->code - $label" : "$obj->code";
615 } elseif ($withcode == 2) {
616 $result = $obj->code;
617 } elseif ($withcode == 3) {
618 $result = $obj->rowid;
619 } elseif ($withcode === 'all') {
620 $result = array('id' => $obj->rowid, 'code' => $obj->code, 'label' => $label);
621 } else {
622 $result = $label;
623 }
624 } else {
625 $result = 'NotDefined';
626 }
627 $dbtouse->free($resql);
628 return $result;
629 } else {
630 dol_print_error($dbtouse, '');
631 }
632 return 'Error';
633}
634
650function getState($id, $withcode = '0', $dbtouse = null, $withregion = 0, $outputlangs = null, $entconv = 1)
651{
652 global $db, $langs;
653
654 if (!is_object($dbtouse)) {
655 $dbtouse = $db;
656 }
657
658 $sql = "SELECT d.rowid as id, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.code_region as region_code, r.nom as region_name FROM";
659 $sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
660 $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and d.rowid=".((int) $id);
661 $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
662 $sql .= " ORDER BY c.code, d.code_departement";
663
664 dol_syslog("Company.lib::getState", LOG_DEBUG);
665 $resql = $dbtouse->query($sql);
666 if ($resql) {
667 $obj = $dbtouse->fetch_object($resql);
668 if ($obj) {
669 $label = ((!empty($obj->name) && $obj->name != '-') ? $obj->name : '');
670 if (is_object($outputlangs)) {
671 $outputlangs->load("dict");
672 if ($entconv) {
673 $label = ($obj->code && ($outputlangs->trans("State".$obj->code) != "State".$obj->code)) ? $outputlangs->trans("State".$obj->code) : $label;
674 } else {
675 $label = ($obj->code && ($outputlangs->transnoentitiesnoconv("State".$obj->code) != "State".$obj->code)) ? $outputlangs->transnoentitiesnoconv("State".$obj->code) : $label;
676 }
677 }
678
679 if ($withcode == 1) {
680 if ($withregion == 1) {
681 return $label = $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
682 } else {
683 return $label = $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
684 }
685 } elseif ($withcode == 2) {
686 if ($withregion == 1) {
687 return $label = $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
688 } else {
689 return $label = ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
690 }
691 } elseif ($withcode === 'all') {
692 if ($withregion == 1) {
693 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label, 'region_code' => $obj->region_code, 'region' => $obj->region_name);
694 } else {
695 return array('id' => $obj->id, 'code' => $obj->code, 'label' => $label);
696 }
697 } else {
698 if ($withregion == 1) {
699 return $label = $obj->region_name.' - '.$label;
700 } else {
701 return $label;
702 }
703 }
704 } else {
705 return $langs->transnoentitiesnoconv("NotDefined");
706 }
707 } else {
708 dol_print_error($dbtouse, '');
709 }
710
711 return '';
712}
713
722function currency_name($code_iso, $withcode = 0, $outputlangs = null)
723{
724 global $langs, $db;
725
726 if (empty($outputlangs)) {
727 $outputlangs = $langs;
728 }
729
730 $outputlangs->load("dict");
731
732 // If there is a translation, we can send immediately the label
733 if ($outputlangs->trans("Currency".$code_iso) != "Currency".$code_iso) {
734 return ($withcode ? $code_iso.' - ' : '').$outputlangs->trans("Currency".$code_iso);
735 }
736
737 // If no translation, we read table to get label by default
738 $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies";
739 $sql .= " WHERE code_iso='".$db->escape($code_iso)."'";
740
741 $resql = $db->query($sql);
742 if ($resql) {
743 $num = $db->num_rows($resql);
744
745 if ($num) {
746 $obj = $db->fetch_object($resql);
747 $label = ($obj->label != '-' ? $obj->label : '');
748 if ($withcode) {
749 return ($label == $code_iso) ? "$code_iso" : "$code_iso - $label";
750 } else {
751 return $label;
752 }
753 } else {
754 return $code_iso;
755 }
756 }
757 return 'ErrorWhenReadingCurrencyLabel';
758}
759
768{
769 global $conf, $db, $langs;
770
771 if (!$code) {
772 return '';
773 }
774
775 if (!empty($conf->cache["legalform_".$langs->defaultlang.'_'.$code])) {
776 return $conf->cache["legalform_".$langs->defaultlang.'_'.$code];
777 }
778
779 $sql = "SELECT libelle as label FROM ".MAIN_DB_PREFIX."c_forme_juridique";
780 $sql .= " WHERE code = '".$db->escape($code)."'";
781
782 dol_syslog("Company.lib::getFormeJuridiqueLabel", LOG_DEBUG);
783
784 $resql = $db->query($sql);
785 if ($resql) {
786 $num = $db->num_rows($resql);
787 if ($num) {
788 $obj = $db->fetch_object($resql);
789
790 $label = ($obj->label != '-' ? $obj->label : '');
791
792 $conf->cache["legalform_".$langs->defaultlang.'_'.$code] = $label;
793
794 return $langs->trans($label);
795 } else {
796 return $langs->trans("NotDefined");
797 }
798 } else {
799 return 'Error '.$db->lasterror();
800 }
801}
802
803
811{
812 // List of all country codes that are in europe for european vat rules
813 // List found on https://ec.europa.eu/taxation_customs/territorial-status-eu-countries-and-certain-territories_en
814 global $conf, $db;
815 $country_code_in_EEC = array();
816
817 if (!empty($conf->cache['country_code_in_EEC'])) {
818 // Use of cache to reduce number of database requests
819 $country_code_in_EEC = $conf->cache['country_code_in_EEC'];
820 } else {
821 $sql = "SELECT cc.code FROM ".MAIN_DB_PREFIX."c_country as cc";
822 $sql .= " WHERE cc.eec = 1";
823
824 $resql = $db->query($sql);
825 if ($resql) {
826 $num = $db->num_rows($resql);
827 $i = 0;
828 while ($i < $num) {
829 $objp = $db->fetch_object($resql);
830 $country_code_in_EEC[] = $objp->code;
831 $i++;
832 }
833 } else {
834 dol_print_error($db);
835 }
836 $conf->cache['country_code_in_EEC'] = $country_code_in_EEC;
837 }
838 return $country_code_in_EEC;
839}
840
848{
849 if (empty($object->country_code)) {
850 return false;
851 }
852
853 $country_code_in_EEC = getCountriesInEEC(); // This make a database call but there is a cache done into $conf->cache['country_code_in_EEC']
854
855 //print "dd".$object->country_code;
856 return in_array($object->country_code, $country_code_in_EEC);
857}
858
859
872function show_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
873{
874 global $user, $action, $hookmanager, $form, $massactionbutton, $massaction, $arrayofselected, $arrayofmassactions;
875
876 $i = -1;
877
878 if (isModEnabled('project') && $user->hasRight('projet', 'lire')) {
879 $langs->load("projects");
880
881 $newcardbutton = '';
882 if (isModEnabled('project') && $user->hasRight('projet', 'creer') && empty($nocreatelink)) {
883 $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
884 }
885
886 print "\n";
887 print load_fiche_titre($langs->trans("ProjectsDedicatedToThisThirdParty"), $newcardbutton.$morehtmlright, '');
888
889 print '<div class="div-table-responsive">'."\n";
890 print '<table class="noborder centpercent">';
891
892 $sql = "SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_modification, p.budget_amount";
893 $sql .= ", cls.code as opp_status_code";
894 $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
895 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid";
896 $sql .= " WHERE p.fk_soc = ".((int) $object->id);
897 $sql .= " AND p.entity IN (".getEntity('project').")";
898 $sql .= " ORDER BY p.dateo DESC";
899
900 $result = $db->query($sql);
901 if ($result) {
902 $num = $db->num_rows($result);
903
904 print '<tr class="liste_titre">';
905 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
906 print '<td class="center">';
907 $selectedfields = (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'";
1030 $sql .= " ORDER BY p.dateo DESC";
1031
1032 $result = $db->query($sql);
1033 if ($result) {
1034 $num = $db->num_rows($result);
1035
1036 print '<tr class="liste_titre">';
1037 print '<td>'.$langs->trans("Ref").'</td>';
1038 print '<td>'.$langs->trans("Name").'</td>';
1039 print '<td class="center">'.$langs->trans("DateStart").'</td>';
1040 print '<td class="center">'.$langs->trans("DateEnd").'</td>';
1041 print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
1042 print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
1043 print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
1044 print '<td class="right">'.$langs->trans("Status").'</td>';
1045 print '</tr>';
1046
1047 if ($num > 0) {
1048 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1049
1050 $projecttmp = new Project($db);
1051
1052 $i = 0;
1053
1054 while ($i < $num) {
1055 $obj = $db->fetch_object($result);
1056 $projecttmp->fetch($obj->id);
1057
1058 // To verify role of users
1059 $userAccess = $projecttmp->restrictedProjectArea($user);
1060
1061 if ($user->rights->projet->lire && $userAccess > 0) {
1062 print '<tr class="oddeven">';
1063
1064 // Ref
1065 print '<td class="nowraponall">';
1066 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:'.$_SERVER["PHP_SELF"].'?socid=__SOCID__');
1067 print '</td>';
1068
1069 // Label
1070 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->title).'">'.dol_escape_htmltag($obj->title).'</td>';
1071 // Date start
1072 print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
1073 // Date end
1074 print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
1075 // Opp amount
1076 print '<td class="right">';
1077 if ($obj->opp_status_code) {
1078 print '<span class="amount">'.price($obj->opp_amount, 1, '', 1, -1, -1, '').'</span>';
1079 }
1080 print '</td>';
1081 // Opp status
1082 print '<td class="center">';
1083 if ($obj->opp_status_code) {
1084 print $langs->trans("OppStatus".$obj->opp_status_code);
1085 }
1086 print '</td>';
1087 // Opp percent
1088 print '<td class="right">';
1089 if ($obj->opp_percent) {
1090 print price($obj->opp_percent, 1, '', 1, 0).'%';
1091 }
1092 print '</td>';
1093 // Status
1094 print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
1095
1096 print '</tr>';
1097 }
1098 $i++;
1099 }
1100 } else {
1101 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1102 }
1103 $db->free($result);
1104 } else {
1105 dol_print_error($db);
1106 }
1107 }
1108
1109 $parameters = array('sql' => $sql, 'function' => 'show_projects');
1110 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1111 print $hookmanager->resPrint;
1112
1113 print "</table>";
1114 print '</div>';
1115
1116 print "<br>\n";
1117 }
1118
1119 return $i;
1120}
1121
1122
1134function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
1135{
1136 global $user, $conf, $extrafields, $hookmanager;
1137 global $contextpage;
1138
1139 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
1140 $formcompany = new FormCompany($db);
1141 $form = new Form($db);
1142
1143 $optioncss = GETPOST('optioncss', 'alpha');
1144 $sortfield = GETPOST('sortfield', 'aZ09comma');
1145 $sortorder = GETPOST('sortorder', 'aZ09comma');
1146 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
1147
1148 $search_status = GETPOST("search_status", "intcomma");
1149 if ($search_status == '') {
1150 $search_status = 1; // always display active customer first
1151 }
1152
1153 $search_rowid = GETPOST("search_rowid", "intcomma");
1154 $search_name = GETPOST("search_name", 'alpha');
1155 $search_address = GETPOST("search_address", 'alpha');
1156 $search_poste = GETPOST("search_poste", 'alpha');
1157 $search_note_private = GETPOST('search_note_private', 'alphanohtml');
1158 $search_roles = GETPOST("search_roles", 'array');
1159 $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
1160 $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
1161
1162 if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
1163 $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_dtstartmonth'), GETPOSTINT('search_birthday_dtstartday'), GETPOSTINT('search_birthday_dtstartyear'));
1164 $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_dtendmonth'), GETPOSTINT('search_birthday_dtendday'), GETPOSTINT('search_birthday_dtendyear'));
1165 }
1166 $socialnetworks = getArrayOfSocialNetworks();
1167
1168 $searchAddressPhoneDBFields = array(
1169 //Address
1170 't.address',
1171 't.zip',
1172 't.town',
1173
1174 //Phone
1175 't.phone',
1176 't.phone_perso',
1177 't.phone_mobile',
1178
1179 //Fax
1180 't.fax',
1181
1182 //E-mail
1183 't.email',
1184 );
1185 //Social media
1186 // foreach ($socialnetworks as $key => $value) {
1187 // if ($value['active']) {
1188 // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
1189 // }
1190 // }
1191
1192 if (!$sortorder) {
1193 $sortorder = "ASC";
1194 }
1195 if (!$sortfield) {
1196 $sortfield = "t.lastname";
1197 }
1198
1199 if (isModEnabled('clicktodial')) {
1200 $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1201 }
1202
1203
1204 $contactstatic = new Contact($db);
1205
1206 $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1207
1208 $contactstatic->fields = array(
1209 'rowid' => array('type' => 'integer', 'label' => "TechnicalID", 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'visible' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1210 'name' => array('type' => 'varchar(128)', 'label' => 'Name', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1),
1211 'poste' => array('type' => 'varchar(128)', 'label' => 'PostOrFunction', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 2, 'index' => 1, 'position' => 20),
1212 'address' => array('type' => 'varchar(128)', 'label' => 'Address', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 3, 'index' => 1, 'position' => 30),
1213 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible' => 3, 'position' => 35),
1214 'role' => array('type' => 'checkbox', 'label' => 'Role', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 4, 'index' => 1, 'position' => 40),
1215 'birthday' => array('type' => 'date', 'label' => 'Birthday', 'enabled' => 1, 'visible' => -1, 'notnull' => 0, 'position' => 45),
1216 'statut' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => '0', 'index' => 1, 'position' => 50, 'arrayofkeyval' => array(0 => $contactstatic->LibStatut(0, 1), 1 => $contactstatic->LibStatut(1, 1))),
1217 );
1218
1219 // Definition of fields for list
1220 $arrayfields = array(
1221 't.rowid' => array('label' => "TechnicalID", 'checked' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1222 't.name' => array('label' => "Name", 'checked' => 1, 'position' => 10),
1223 't.poste' => array('label' => "PostOrFunction", 'checked' => 1, 'position' => 20),
1224 't.address' => array('label' => (empty($conf->dol_optimize_smallscreen) ? $langs->trans("Address").' / '.$langs->trans("Phone").' / '.$langs->trans("Email") : $langs->trans("Address")), 'checked' => 1, 'position' => 30),
1225 't.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'position' => 35),
1226 'sc.role' => array('label' => "ContactByDefaultFor", 'checked' => 1, 'position' => 40),
1227 't.birthday' => array('label' => "Birthday", 'checked' => 0, 'position' => 45),
1228 't.statut' => array('label' => "Status", 'checked' => 1, 'position' => 50, 'class' => 'center'),
1229 '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, '');
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">'."\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.'&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='.urlencode($obj->fk_soc).'">';
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 }
1733}
1734
1753function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1754{
1755 global $user, $conf, $hookmanager;
1756 global $form;
1757 global $param, $massactionbutton;
1758
1759 $start_year = GETPOSTINT('dateevent_startyear');
1760 $start_month = GETPOSTINT('dateevent_startmonth');
1761 $start_day = GETPOSTINT('dateevent_startday');
1762 $end_year = GETPOSTINT('dateevent_endyear');
1763 $end_month = GETPOSTINT('dateevent_endmonth');
1764 $end_day = GETPOSTINT('dateevent_endday');
1765 $tms_start = '';
1766 $tms_end = '';
1767
1768 if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1769 $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1770 }
1771 if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1772 $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1773 }
1774 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
1775 $tms_start = '';
1776 $tms_end = '';
1777 }
1778 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1779
1780 // Check parameters
1781 if (!is_object($filterobj) && !is_object($objcon)) {
1782 dol_print_error(null, 'BadParameter');
1783 }
1784
1785 $out = '';
1786 $histo = array();
1787 $numaction = 0;
1788 $now = dol_now('tzuser');
1789
1790 // Open DSI -- Fix order by -- Begin
1791 $sortfield_list = explode(',', $sortfield);
1792 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1793 $sortfield_new_list = array();
1794 foreach ($sortfield_list as $sortfield_value) {
1795 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1796 }
1797 $sortfield_new = implode(',', $sortfield_new_list);
1798
1799 $sql = '';
1800
1801 if (isModEnabled('agenda')) {
1802 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
1803 $hookmanager->initHooks(array('agendadao'));
1804
1805 // Recherche histo sur actioncomm
1806 if (is_object($objcon) && $objcon->id > 0) {
1807 $sql = "SELECT DISTINCT a.id, a.label as label,";
1808 } else {
1809 $sql = "SELECT a.id, a.label as label,";
1810 }
1811 $sql .= " a.datep as dp,";
1812 $sql .= " a.datep2 as dp2,";
1813 $sql .= " a.percent as percent, 'action' as type,";
1814 $sql .= " a.fk_element, a.elementtype,";
1815 $sql .= " a.fk_contact,";
1816 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1817 $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";
1818 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1819 $sql .= ", sp.lastname, sp.firstname";
1820 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1821 /* Nothing */
1822 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1823 /* Nothing */
1824 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1825 $sql .= ", m.lastname, m.firstname";
1826 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1827 $sql .= ", o.ref";
1828 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1829 $sql .= ", o.ref";
1830 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1831 $sql .= ", o.ref";
1832 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1833 $sql .= ", o.ref";
1834 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1835 $sql .= ", o.ref";
1836 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1837 if (!empty($filterobj->fields['ref'])) {
1838 $sql .= ", o.ref";
1839 } elseif (!empty($filterobj->fields['label'])) {
1840 $sql .= ", o.label";
1841 }
1842 }
1843
1844 // Fields from hook
1845 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1846 $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
1847 if (!empty($hookmanager->resPrint)) {
1848 $sql .= $hookmanager->resPrint;
1849 }
1850
1851 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1852 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_action";
1853 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action = c.id";
1854
1855 if (is_object($filterobj) && get_class($filterobj) !== 'User') {
1856 $force_filter_contact = false;
1857 } else {
1858 $force_filter_contact = true;
1859 }
1860 if (is_object($objcon) && $objcon->id > 0) {
1861 $force_filter_contact = true;
1862 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as r ON a.id = r.fk_actioncomm";
1863 $sql .= " AND r.element_type = '".$db->escape($objcon->table_element)."' AND r.fk_element = ".((int) $objcon->id);
1864 }
1865
1866 // Fields from hook
1867 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
1868 $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
1869 if (!empty($hookmanager->resPrint)) {
1870 $sql .= $hookmanager->resPrint;
1871 }
1872 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1873 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
1874 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1875 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as er";
1876 $sql .= " ON er.resource_type = 'dolresource'";
1877 $sql .= " AND er.element_id = a.id";
1878 $sql .= " AND er.resource_id = ".((int) $filterobj->id);
1879 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1880 /* Nothing */
1881 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1882 $sql .= ", ".MAIN_DB_PREFIX."adherent as m";
1883 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1884 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as o";
1885 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1886 $sql .= ", ".MAIN_DB_PREFIX."product as o";
1887 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1888 $sql .= ", ".MAIN_DB_PREFIX."ticket as o";
1889 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1890 $sql .= ", ".MAIN_DB_PREFIX."bom_bom as o";
1891 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1892 $sql .= ", ".MAIN_DB_PREFIX."contrat as o";
1893 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1894 && ((!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'])))
1895 && $filterobj->table_element && $filterobj->element) {
1896 $sql .= ", ".MAIN_DB_PREFIX.$filterobj->table_element." as o";
1897 }
1898
1899 $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1900 if ($force_filter_contact === false) {
1901 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
1902 $sql .= " AND a.fk_soc = ".((int) $filterobj->id);
1903 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1904 /* Nothing */
1905 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
1906 $sql .= " AND a.fk_project = ".((int) $filterobj->id);
1907 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1908 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
1909 if ($filterobj->id) {
1910 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1911 }
1912 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
1913 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
1914 if ($filterobj->id) {
1915 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1916 }
1917 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1918 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
1919 if ($filterobj->id) {
1920 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1921 }
1922 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
1923 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
1924 if ($filterobj->id) {
1925 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1926 }
1927 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1928 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
1929 if ($filterobj->id) {
1930 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1931 }
1932 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1933 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
1934 if ($filterobj->id) {
1935 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1936 }
1937 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1938 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
1939 if ($filterobj->id) {
1940 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1941 }
1942 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1943 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
1944 if ($filterobj->id) {
1945 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1946 }
1947 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
1948 && ((!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'])))
1949 && $filterobj->table_element && $filterobj->element) {
1950 // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
1951 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '".$db->escape($filterobj->element).($module ? "@".$module : "")."'";
1952 if ($filterobj->id) {
1953 $sql .= " AND a.fk_element = ".((int) $filterobj->id);
1954 }
1955 } elseif (is_object($filterobj)) {
1956 return 'Bad value for $filterobj';
1957 }
1958 } else {
1959 $sql .= " AND u.rowid = ". ((int) $filterobj->id);
1960 }
1961
1962 if (!empty($tms_start) && !empty($tms_end)) {
1963 $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)."'))";
1964 } elseif (empty($tms_start) && !empty($tms_end)) {
1965 $sql .= " AND ((a.datep <= '".$db->idate($tms_end)."') OR (a.datep2 <= '".$db->idate($tms_end)."'))";
1966 } elseif (!empty($tms_start) && empty($tms_end)) {
1967 $sql .= " AND ((a.datep >= '".$db->idate($tms_start)."') OR (a.datep2 >= '".$db->idate($tms_start)."'))";
1968 }
1969
1970 if (is_array($actioncode) && !empty($actioncode)) {
1971 $sql .= ' AND (';
1972 foreach ($actioncode as $key => $code) {
1973 if ($key != 0) {
1974 $sql .= " OR ";
1975 }
1976 if (!empty($code)) {
1977 addEventTypeSQL($sql, $code, "");
1978 }
1979 }
1980 $sql .= ')';
1981 } elseif (!empty($actioncode)) {
1982 addEventTypeSQL($sql, $actioncode);
1983 }
1984
1985 addOtherFilterSQL($sql, $donetodo, $now, $filters);
1986
1987 // Fields from hook
1988 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
1989 $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
1990 if (!empty($hookmanager->resPrint)) {
1991 $sql .= $hookmanager->resPrint;
1992 }
1993
1994 if (is_array($actioncode)) {
1995 foreach ($actioncode as $code) {
1996 $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
1997 if (!empty($sql2)) {
1998 if (!empty($sql)) {
1999 $sql = $sql." UNION ".$sql2;
2000 } elseif (empty($sql)) {
2001 $sql = $sql2;
2002 }
2003 break;
2004 }
2005 }
2006 } else {
2007 $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
2008 if (!empty($sql) && !empty($sql2)) {
2009 $sql = $sql." UNION ".$sql2;
2010 } elseif (empty($sql) && !empty($sql2)) {
2011 $sql = $sql2;
2012 }
2013 }
2014 }
2015
2016 if ($sql) {
2017 //TODO Add navigation with this limits...
2018 $offset = 0;
2019 $limit = 1000;
2020
2021 // Complete request and execute it with limit
2022 $sql .= $db->order($sortfield_new, $sortorder);
2023 if ($limit) {
2024 $sql .= $db->plimit($limit + 1, $offset);
2025 }
2026
2027 dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
2028
2029 $resql = $db->query($sql);
2030 if ($resql) {
2031 $i = 0;
2032 $num = $db->num_rows($resql);
2033
2034 $imaxinloop = ($limit ? min($num, $limit) : $num);
2035 while ($i < $imaxinloop) {
2036 $obj = $db->fetch_object($resql);
2037
2038 if ($obj->type == 'action') {
2039 $contactaction = new ActionComm($db);
2040 $contactaction->id = $obj->id;
2041 $result = $contactaction->fetchResources();
2042 if ($result < 0) {
2043 dol_print_error($db);
2044 setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2045 }
2046
2047 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2048 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2049 $tododone = '';
2050 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2051 $tododone = 'todo';
2052 }
2053
2054 $histo[$numaction] = array(
2055 'type' => $obj->type,
2056 'tododone' => $tododone,
2057 'id' => $obj->id,
2058 'datestart' => $db->jdate($obj->dp),
2059 'dateend' => $db->jdate($obj->dp2),
2060 'note' => $obj->label,
2061 'percent' => $obj->percent,
2062
2063 'userid' => $obj->user_id,
2064 'login' => $obj->user_login,
2065 'userfirstname' => $obj->user_firstname,
2066 'userlastname' => $obj->user_lastname,
2067 'userphoto' => $obj->user_photo,
2068
2069 'contact_id' => $obj->fk_contact,
2070 'socpeopleassigned' => $contactaction->socpeopleassigned,
2071 'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2072 'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2073 'fk_element' => $obj->fk_element,
2074 'elementtype' => $obj->elementtype,
2075 // Type of event
2076 'acode' => $obj->acode,
2077 'alabel' => $obj->alabel,
2078 'libelle' => $obj->alabel, // deprecated
2079 'apicto' => $obj->apicto
2080 );
2081 } else {
2082 $histo[$numaction] = array(
2083 'type' => $obj->type,
2084 'tododone' => 'done',
2085 'id' => $obj->id,
2086 'datestart' => $db->jdate($obj->dp),
2087 'dateend' => $db->jdate($obj->dp2),
2088 'note' => $obj->label,
2089 'percent' => $obj->percent,
2090 'acode' => $obj->acode,
2091
2092 'userid' => $obj->user_id,
2093 'login' => $obj->user_login,
2094 'userfirstname' => $obj->user_firstname,
2095 'userlastname' => $obj->user_lastname,
2096 'userphoto' => $obj->user_photo
2097 );
2098 }
2099
2100 $numaction++;
2101 $i++;
2102 }
2103 } else {
2104 dol_print_error($db);
2105 }
2106 }
2107
2108 '@phan-var-force array<int,array{userid:int,type:string,tododone:string,apicto:string,acode:string,alabel:string,note:string,id:int,percent:int<0,100>,datestart:int,dateend:int,fk_element:string,elementtype:string,contact_id:string,lastname:string,firstname:string,contact_photo:string,socpeaopleassigned:int[],login:string,userfirstname:string,userlastname:string,userphoto:string}> $histo';
2109
2110 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2111 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
2112
2113 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
2114 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2115 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2116 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2117
2118 $formactions = new FormActions($db);
2119
2120 $actionstatic = new ActionComm($db);
2121 $userstatic = new User($db);
2122 $userlinkcache = array();
2123 $contactstatic = new Contact($db);
2124 $elementlinkcache = array();
2125
2126 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
2127 $out .= '<input type="hidden" name="token" value="'.newToken().'">';
2128 if ($objcon && get_class($objcon) == 'Contact' &&
2129 (is_null($filterobj) || get_class($filterobj) == 'Societe')) {
2130 $out .= '<input type="hidden" name="id" value="'.$objcon->id.'" />';
2131 } else {
2132 $out .= '<input type="hidden" name="id" value="'.$filterobj->id.'" />';
2133 }
2134 if ($filterobj && get_class($filterobj) == 'Societe') {
2135 $out .= '<input type="hidden" name="socid" value="'.$filterobj->id.'" />';
2136 } else {
2137 $out .= '<input type="hidden" name="userid" value="'.$filterobj->id.'" />';
2138 }
2139
2140 $out .= "\n";
2141
2142 $out .= '<div class="div-table-responsive-no-min">';
2143 $out .= '<table class="noborder centpercent">';
2144
2145 $out .= '<tr class="liste_titre">';
2146
2147 // Action column
2148 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2149 $out .= '<th class="liste_titre width50 middle">';
2150 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2151 $out .= $searchpicto;
2152 $out .= '</th>';
2153 }
2154
2155 if ($donetodo) {
2156 $out .= '<td class="liste_titre"></td>';
2157 }
2158
2159 // ID
2160 $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="'.(isset($filters['search_rowid']) ? $filters['search_rowid'] : '').'"></td>';
2161 // Date
2162 $out .= '<td class="liste_titre center">';
2163 $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2164 $out .= '</td>';
2165 // Owner
2166 $out .= '<td class="liste_titre"></td>';
2167 // Type
2168 $out .= '<td class="liste_titre">';
2169 $out .= $formactions->select_type_actions($actioncode, "actioncode", '', getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, (getDolGlobalString('AGENDA_USE_MULTISELECT_TYPE') ? 1 : 0), 1, 'combolargeelem minwidth100 maxwidth150');
2170 $out .= '</td>';
2171 $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters['search_agenda_label'].'"></td>';
2172 $out .= '<td class="liste_titre"></td>';
2173 $out .= '<td class="liste_titre"></td>';
2174 $out .= '<td class="liste_titre"></td>';
2175 // Action column
2176 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2177 $out .= '<td class="liste_titre" align="middle">';
2178 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2179 $out .= $searchpicto;
2180 $out .= '</td>';
2181 }
2182 $out .= '</tr>';
2183
2184 $out .= '<tr class="liste_titre">';
2185 // Action column
2186 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2187 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2188 }
2189 if ($donetodo) {
2190 $tmp = '';
2191 if (get_class($filterobj) == 'Societe') {
2192 $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
2193 }
2194 if (get_class($filterobj) == 'User') {
2195 $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&userid='.$filterobj->id.'&status=done">';
2196 }
2197 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2198 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2199 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2200 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2201 if (get_class($filterobj) == 'Societe') {
2202 $tmp .= '</a>';
2203 }
2204 if (get_class($filterobj) == 'User') {
2205 $tmp .= '</a>';
2206 }
2207 $out .= getTitleFieldOfList($tmp);
2208 }
2209 $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2210 $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2211 $out .= getTitleFieldOfList("Owner");
2212 $out .= getTitleFieldOfList("Type");
2213 $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2214 $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2215 $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2216 $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2217 // Action column
2218 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2219 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2220 }
2221 $out .= '</tr>';
2222
2223 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
2224 $caction = new CActionComm($db);
2225 $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
2226
2227 foreach ($histo as $key => $value) {
2228 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2229
2230 $actionstatic->type_picto = $histo[$key]['apicto'];
2231 $actionstatic->type_code = $histo[$key]['acode'];
2232
2233 $out .= '<tr class="oddeven">';
2234
2235 // Action column
2236 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2237 $out .= '<td></td>';
2238 }
2239
2240 // Done or todo
2241 if ($donetodo) {
2242 $out .= '<td class="nowrap">';
2243 $out .= '</td>';
2244 }
2245
2246 // Ref
2247 $out .= '<td class="nowraponall">';
2248 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2249 $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2250 $out .= $histo[$key]['id'];
2251 $out .= '</a>';
2252 } else {
2253 $out .= $actionstatic->getNomUrl(1, -1);
2254 }
2255 $out .= '</td>';
2256
2257 // Date
2258 $out .= '<td class="center nowraponall">';
2259 $out .= dol_print_date($histo[$key]['datestart'], 'dayhour', 'tzuserrel');
2260 if ($histo[$key]['dateend'] && $histo[$key]['dateend'] != $histo[$key]['datestart']) {
2261 $tmpa = dol_getdate($histo[$key]['datestart'], true);
2262 $tmpb = dol_getdate($histo[$key]['dateend'], true);
2263 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2264 $out .= '-'.dol_print_date($histo[$key]['dateend'], 'hour', 'tzuserrel');
2265 } else {
2266 $out .= '-'.dol_print_date($histo[$key]['dateend'], 'dayhour', 'tzuserrel');
2267 }
2268 }
2269 $late = 0;
2270 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2271 $late = 1;
2272 }
2273 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2274 $late = 1;
2275 }
2276 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2277 $late = 1;
2278 }
2279 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2280 $late = 1;
2281 }
2282 if ($late) {
2283 $out .= img_warning($langs->trans("Late")).' ';
2284 }
2285 $out .= "</td>\n";
2286
2287 // Author of event
2288 $out .= '<td class="tdoverflowmax125">';
2289 if ($histo[$key]['userid'] > 0) {
2290 if (isset($userlinkcache[$histo[$key]['userid']])) {
2291 $link = $userlinkcache[$histo[$key]['userid']];
2292 } else {
2293 $userstatic->fetch($histo[$key]['userid']);
2294 $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2295 $userlinkcache[$histo[$key]['userid']] = $link;
2296 }
2297 $out .= $link;
2298 }
2299 $out .= '</td>';
2300
2301 // Type
2302 $labeltype = $actionstatic->type_code;
2303 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
2304 $labeltype = 'AC_OTH';
2305 }
2306 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2307 $labeltype = $langs->trans("Message");
2308 } else {
2309 if (!empty($arraylist[$labeltype])) {
2310 $labeltype = $arraylist[$labeltype];
2311 }
2312 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
2313 $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code
2314 }
2315 }
2316 $out .= '<td class="tdoverflowmax125" title="'.$labeltype.'">';
2317 $out .= $actionstatic->getTypePicto();
2318 //if (empty($conf->dol_optimize_smallscreen)) {
2319 $out .= $labeltype;
2320 //}
2321 $out .= '</td>';
2322
2323 // Title/Label of event
2324 $out .= '<td class="tdoverflowmax300"';
2325 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2326 $transcode = $langs->trans("Action".$histo[$key]['acode']);
2327 //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2328 $libelle = $histo[$key]['note'];
2329 $actionstatic->id = $histo[$key]['id'];
2330 $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2331 $out .= dol_trunc($libelle, 120);
2332 }
2333 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2334 $out .= '<a href="'.DOL_URL_ROOT.'/comm/mailing/card.php?id='.$histo[$key]['id'].'">'.img_object($langs->trans("ShowEMailing"), "email").' ';
2335 $transcode = $langs->trans("Action".$histo[$key]['acode']);
2336 $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2337 $out .= ' title="'.dol_escape_htmltag($libelle).'">';
2338 $out .= dol_trunc($libelle, 120);
2339 }
2340 $out .= '</td>';
2341
2342 // Linked object
2343 $out .= '<td class="tdoverflowmax200 nowraponall">';
2344 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2345 if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2346 $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2347 } else {
2348 if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2349 $elementlinkcache[$histo[$key]['elementtype']] = array();
2350 }
2351 $link = dolGetElementUrl($histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2352 $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2353 }
2354 $out .= $link;
2355 }
2356 $out .= '</td>';
2357
2358 // Contact(s) for action
2359 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2360 $out .= '<td class="valignmiddle">';
2361 $contact = new Contact($db);
2362 foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2363 $result = $contact->fetch($cid);
2364
2365 if ($result < 0) {
2366 dol_print_error($db, $contact->error);
2367 }
2368
2369 if ($result > 0) {
2370 $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright');
2371 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2372 if (!empty($contact->phone_pro)) {
2373 $out .= '('.dol_print_phone($contact->phone_pro).')';
2374 }
2375 }
2376 $out .= '<div class="paddingright"></div>';
2377 }
2378 }
2379 $out .= '</td>';
2380 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2381 $contactstatic->lastname = $histo[$key]['lastname'];
2382 $contactstatic->firstname = $histo[$key]['firstname'];
2383 $contactstatic->id = $histo[$key]['contact_id'];
2384 $contactstatic->photo = $histo[$key]['contact_photo'];
2385 $out .= '<td width="120">'.$contactstatic->getNomUrl(-1, '', 10).'</td>';
2386 } else {
2387 $out .= '<td>&nbsp;</td>';
2388 }
2389
2390 // Status
2391 $out .= '<td class="nowrap center">'.$actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']).'</td>';
2392
2393 // Action column
2394 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2395 $out .= '<td></td>';
2396 }
2397
2398 $out .= "</tr>\n";
2399 }
2400 if (empty($histo)) {
2401 $colspan = 9;
2402 $out .= '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2403 }
2404
2405 $out .= "</table>\n";
2406 $out .= "</div>\n";
2407
2408 $out .= '</form>';
2409 }
2410
2411 if ($noprint) {
2412 return $out;
2413 } else {
2414 print $out;
2415 }
2416}
2417
2427function show_subsidiaries($conf, $langs, $db, $object)
2428{
2429 global $user;
2430
2431 $i = -1;
2432
2433 $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";
2434 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
2435 $sql .= " WHERE s.parent = ".((int) $object->id);
2436 $sql .= " AND s.entity IN (".getEntity('societe').")";
2437 $sql .= " ORDER BY s.nom";
2438
2439 $result = $db->query($sql);
2440 $num = $db->num_rows($result);
2441
2442 if ($num) {
2443 $socstatic = new Societe($db);
2444
2445 print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2446
2447 print "\n".'<div class="div-table-responsive-no-min">'."\n";
2448 print '<table class="noborder centpercent">'."\n";
2449
2450 print '<tr class="liste_titre"><td>'.$langs->trans("Company").'</td>';
2451 print '<td>'.$langs->trans("Address").'</td><td>'.$langs->trans("Zip").'</td>';
2452 print '<td>'.$langs->trans("Town").'</td><td>'.$langs->trans("CustomerCode").'</td>';
2453 print "<td>&nbsp;</td>";
2454 print "</tr>";
2455
2456 $i = 0;
2457
2458 while ($i < $num) {
2459 $obj = $db->fetch_object($result);
2460
2461 $socstatic->id = $obj->rowid;
2462 $socstatic->name = $obj->name;
2463 $socstatic->name_alias = $obj->name_alias;
2464 $socstatic->email = $obj->email;
2465 $socstatic->code_client = $obj->code_client;
2466 $socstatic->code_fournisseur = $obj->code_fournisseur;
2467 $socstatic->code_compta = $obj->code_compta;
2468 $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2469 $socstatic->email = $obj->email;
2470 $socstatic->canvas = $obj->canvas;
2471 $socstatic->client = $obj->client;
2472 $socstatic->fournisseur = $obj->fournisseur;
2473
2474 print '<tr class="oddeven">';
2475
2476 print '<td class="tdoverflowmax150">';
2477 print $socstatic->getNomUrl(1);
2478 print '</td>';
2479
2480 print '<td class="tdoverflowmax400" title="'.dol_escape_htmltag($obj->address).'">'.dol_escape_htmltag($obj->address).'</td>';
2481 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">'.$obj->zip.'</td>';
2482 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->town).'">'.$obj->town.'</td>';
2483 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->code_client).'">'.$obj->code_client.'</td>';
2484
2485 print '<td class="center">';
2486 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $obj->rowid).'&action=edit&token='.newToken().'">';
2487 print img_edit();
2488 print '</a></td>';
2489
2490 print "</tr>\n";
2491 $i++;
2492 }
2493 print "\n</table>\n";
2494 print '</div>'."\n";
2495 }
2496
2497 print "<br>\n";
2498
2499 return $i;
2500}
2509function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2510{
2511 global $conf, $db;
2512 // Condition on actioncode
2513
2514 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2515 if ($actioncode == 'AC_NON_AUTO') {
2516 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2517 } elseif ($actioncode == 'AC_ALL_AUTO') {
2518 $sql .= " $sqlANDOR c.type = 'systemauto'";
2519 } else {
2520 if ($actioncode == 'AC_OTH') {
2521 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2522 } elseif ($actioncode == 'AC_OTH_AUTO') {
2523 $sql .= " $sqlANDOR c.type = 'systemauto'";
2524 }
2525 }
2526 } else {
2527 if ($actioncode == 'AC_NON_AUTO') {
2528 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2529 } elseif ($actioncode == 'AC_ALL_AUTO') {
2530 $sql .= " $sqlANDOR c.type = 'systemauto'";
2531 } else {
2532 $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'";
2533 }
2534 }
2535
2536 return $sql;
2537}
2538
2548function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2549{
2550 global $db;
2551
2552 if ($donetodo == 'todo') {
2553 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2554 } elseif ($donetodo == 'done') {
2555 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2556 }
2557 if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2558 $sql .= natural_search('a.label', $filters['search_agenda_label']);
2559 }
2560 if (is_array($filters) && !empty($filters['search_rowid'])) {
2561 $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2562 }
2563
2564 return $sql;
2565}
2566
2575function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2576{
2577 global $db;
2578
2579 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2580 if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2581 $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";
2582 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2583 $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2584 $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
2585 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2586 $sql2 .= ", '' as lastname, '' as firstname";
2587 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2588 $sql2 .= ", '' as lastname, '' as firstname";
2589 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2590 $sql2 .= ", '' as ref";
2591 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2592 $sql2 .= ", '' as ref";
2593 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2594 $sql2 .= ", '' as ref";
2595 }
2596 $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u";
2597 $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email.
2598 $sql2 .= " AND mc.statut = 1";
2599 $sql2 .= " AND u.rowid = m.fk_user_valid";
2600 $sql2 .= " AND mc.fk_mailing=m.rowid";
2601
2602 return $sql2;
2603 } else {
2604 return '';
2605 }
2606}
2607
2608
2609
2620function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2621{
2622 global $conf;
2623
2624 $reg = array();
2625
2626 // Juridical status
2627 $line1 = "";
2628 if ($fromcompany->forme_juridique_code) {
2629 $line1 .= ($line1 ? " - " : "").getFormeJuridiqueLabel($fromcompany->forme_juridique_code);
2630 }
2631 // Capital
2632 if ($fromcompany->capital) {
2633 $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency);
2634 }
2635 // Prof Id 1
2636 if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2637 $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2638 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2639 $field = $reg[1];
2640 }
2641 $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof1;
2642 }
2643 // Prof Id 2
2644 if ($fromcompany->idprof2) {
2645 $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2646 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2647 $field = $reg[1];
2648 }
2649 $line1 .= ($line1 ? " - " : "").$field.": ".$fromcompany->idprof2;
2650 }
2651
2652 // Second line of company infos
2653 $line2 = "";
2654 // Prof Id 3
2655 if ($fromcompany->idprof3) {
2656 $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
2657 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2658 $field = $reg[1];
2659 }
2660 $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof3;
2661 }
2662 // Prof Id 4
2663 if ($fromcompany->idprof4) {
2664 $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
2665 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2666 $field = $reg[1];
2667 }
2668 $line2 .= ($line2 ? " - " : "").$field.": ".$fromcompany->idprof4;
2669 }
2670 // IntraCommunautary VAT
2671 if ($fromcompany->tva_intra != '') {
2672 $line2 .= ($line2 ? " - " : "").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra;
2673 }
2674
2675 print '<!-- htmlPrintOnlineFooter -->'."\n";
2676
2677 // 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.
2678 print '<footer class="center centpercent opacitymedium">'."\n";
2679 print '<br>';
2680 if ($addformmessage) {
2681 print '<!-- object = '.(empty($object) ? 'undefined' : $object->element).' -->';
2682 print '<br>';
2683
2684 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_'.$suffix;
2685 if (getDolGlobalString($parammessageform) !== '') {
2686 print $langs->transnoentities(getDolGlobalString($parammessageform));
2687 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
2688 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
2689 }
2690
2691 // Add other message if VAT exists
2692 if (!empty($object->total_vat) || !empty($object->total_tva)) {
2693 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_'.$suffix;
2694 if (getDolGlobalString($parammessageform) !== '') {
2695 print $langs->transnoentities(getDolGlobalString($parammessageform));
2696 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
2697 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
2698 }
2699 }
2700 }
2701
2702 print '<span style="font-size: 10px;"><br><hr>'."\n";
2703 print $fromcompany->name.'<br>';
2704 print $line1;
2705 if (strlen($line1.$line2) > 50) {
2706 print '<br>';
2707 } else {
2708 print ' - ';
2709 }
2710 print $line2;
2711 print '</span>';
2712 print '</footer>'."\n";
2713}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage agenda events (actions)
Class to manage different types of events.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class for SocieteAccount.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
show_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
show_contacts($conf, $langs, $db, $object, $backtopage='', $showuserlogin=0)
Show html area for list of contacts.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML pages.
show_actions_done($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC', $module='')
Show html area with actions (done or not, ignore the name of function).
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
currency_name($code_iso, $withcode=0, $outputlangs=null)
Return label of currency or code+label.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
societe_prepare_head2($object)
Return array of tabs to used on page.
show_subsidiaries($conf, $langs, $db, $object)
Show html area for list of subsidiaries.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add Event Type SQL.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
societe_admin_prepare_head()
Return array head with list of tabs to view object information.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='')
Show html area with actions to do.
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.