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