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("ReferringItems");
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 $showuserlogin = (!empty($showuserlogin) || !empty($arrayfields['u.user']['checked'])) ? 1 : 0;
1455 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1456 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1457
1458 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1459 print "\n" . '<table class="tagtable liste noborder">' . "\n";
1460
1461 $param = "socid=" . urlencode((string) ($object->id));
1462 if ($search_rowid != '') {
1463 $param .= '&search_rowid=' . urlencode((string) ($search_rowid));
1464 }
1465 if ($search_status != '') {
1466 $param .= '&search_status=' . urlencode((string) ($search_status));
1467 }
1468 if (count($search_roles) > 0) {
1469 $param .= implode('&search_roles[]=', $search_roles);
1470 }
1471 if ($search_name != '') {
1472 $param .= '&search_name=' . urlencode($search_name);
1473 }
1474 if ($search_poste != '') {
1475 $param .= '&search_poste=' . urlencode($search_poste);
1476 }
1477 if ($search_address != '') {
1478 $param .= '&search_address=' . urlencode($search_address);
1479 }
1480 if ($search_note_private != '') {
1481 $param .= '&search_note_private=' . urlencode($search_note_private);
1482 }
1483 if ($search_birthday_dtstart != '') {
1484 $param .= '&search_birthday_dtstart=' . urlencode((string) $search_birthday_dtstart);
1485 }
1486 if ($search_birthday_dtend != '') {
1487 $param .= '&search_birthday_dtend=' . urlencode((string) $search_birthday_dtend);
1488 }
1489 if ($optioncss != '') {
1490 $param .= '&optioncss=' . urlencode($optioncss);
1491 }
1492
1493 // Add $param from extra fields
1494 $extrafieldsobjectkey = $contactstatic->table_element;
1495 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
1496
1497 $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1498 $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,";
1499 $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1500 $sql .= " t.note_private";
1501 $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
1502 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1503 $sql .= " WHERE t.fk_soc = " . ((int) $object->id);
1504 $sql .= " AND t.entity IN (" . getEntity('socpeople') . ")";
1505 $sql .= " AND ((t.fk_user_creat = " . ((int) $user->id) . " AND t.priv = 1) OR t.priv = 0)";
1506 if ($search_rowid) {
1507 $sql .= natural_search('t.rowid', $search_rowid);
1508 }
1509 if ($search_status != '' && $search_status != '-1') {
1510 $sql .= " AND t.statut = " . ((int) $search_status);
1511 }
1512 if ($search_name) {
1513 $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1514 }
1515 if ($search_poste) {
1516 $sql .= natural_search('t.poste', $search_poste);
1517 }
1518 if ($search_address) {
1519 $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1520 }
1521 if ($search_note_private) {
1522 $sql .= natural_search('t.note_private', $search_note_private);
1523 }
1524 if ($search_birthday_dtstart != '') {
1525 $sql .= " AND t.birthday >= '" . $db->idate($search_birthday_dtstart) . "'";
1526 }
1527 if ($search_birthday_dtend != '') {
1528 $sql .= " AND t.birthday <= '" . $db->idate($search_birthday_dtend) . "'";
1529 }
1530 if (count($search_roles) > 0) {
1531 $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)) . "))";
1532 }
1533 // Add where from extra fields
1534 $extrafieldsobjectkey = $contactstatic->table_element;
1535 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
1536 // Add where from hooks
1537 $parameters = array('socid' => $object->id);
1538 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1539 $sql .= $hookmanager->resPrint;
1540 if ($sortfield == "t.name") {
1541 $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1542 } else {
1543 $sql .= " ORDER BY $sortfield $sortorder";
1544 }
1545
1546 dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1547 $result = $db->query($sql);
1548 if (!$result) {
1549 dol_print_error($db);
1550 }
1551
1552 $num = $db->num_rows($result);
1553
1554 // Fields title search
1555 // --------------------------------------------------------------------
1556 print '<tr class="liste_titre">';
1557 // Action column
1558 if ($conf->main_checkbox_left_column) {
1559 print '<td class="liste_titre right">';
1560 print $form->showFilterButtons();
1561 print '</td>';
1562 }
1563 foreach ($contactstatic->fields as $key => $val) {
1564 $align = '';
1565 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1566 $align .= ($align ? ' ' : '') . 'center';
1567 }
1568 if (in_array($val['type'], array('timestamp'))) {
1569 $align .= ($align ? ' ' : '') . 'nowrap';
1570 }
1571 if ($key == 'status' || $key == 'statut') {
1572 $align .= ($align ? ' ' : '') . 'center';
1573 }
1574 if (!empty($arrayfields['t.' . $key]['checked']) || !empty($arrayfields['sc.' . $key]['checked'])) {
1575 print '<td class="liste_titre' . ($align ? ' ' . $align : '') . '">';
1576 if (in_array($key, array('statut'))) {
1577 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');
1578 } elseif (in_array($key, array('role'))) {
1579 print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1580 } elseif (in_array($key, array('birthday'))) {
1581 print '<div class="nowrap">';
1582 print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1583 print '</div>';
1584 print '<div class="nowrap">';
1585 print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1586 print '</div>';
1587 } else {
1588 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . (!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '') . '">';
1589 }
1590 print '</td>';
1591 }
1592 }
1593 if ($showuserlogin) {
1594 print '<td class="liste_titre"></td>';
1595 }
1596 // Extra fields
1597 $extrafieldsobjectkey = $contactstatic->table_element;
1598 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
1599
1600 // Fields from hook
1601 $parameters = array('arrayfields' => $arrayfields);
1602 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1603 print $hookmanager->resPrint;
1604 // Action column
1605 if (!$conf->main_checkbox_left_column) {
1606 print '<td class="liste_titre right">';
1607 print $form->showFilterButtons();
1608 print '</td>';
1609 }
1610 print '</tr>' . "\n";
1611
1612
1613 // Fields title label
1614 // --------------------------------------------------------------------
1615 print '<tr class="liste_titre">';
1616 // Action column
1617 if ($conf->main_checkbox_left_column) {
1618 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1619 }
1620 foreach ($contactstatic->fields as $key => $val) {
1621 $align = '';
1622 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1623 $align .= ($align ? ' ' : '') . 'center';
1624 }
1625 if (in_array($val['type'], array('timestamp'))) {
1626 $align .= ($align ? ' ' : '') . 'nowrap';
1627 }
1628 if ($key == 'status' || $key == 'statut') {
1629 $align .= ($align ? ' ' : '') . 'center';
1630 }
1631 if (!empty($arrayfields['t.' . $key]['checked'])) {
1632 print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1633 }
1634 if ($key == 'role') {
1635 $align .= ($align ? ' ' : '') . 'left';
1636 }
1637 if (!empty($arrayfields['sc.' . $key]['checked'])) {
1638 print getTitleFieldOfList($arrayfields['sc.' . $key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1639 }
1640 }
1641 if ($showuserlogin) {
1642 print '<th class="wrapcolumntitle liste_titre">' . $langs->trans("DolibarrLogin") . '</th>';
1643 }
1644 // Extra fields
1645 $extrafieldsobjectkey = $contactstatic->table_element;
1646 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
1647 // Hook fields
1648 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1649 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1650 print $hookmanager->resPrint;
1651 // Action column
1652 if (!$conf->main_checkbox_left_column) {
1653 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1654 }
1655 print '</tr>' . "\n";
1656
1657 $i = -1;
1658
1659 if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1660 $i = 0;
1661
1662 while ($i < $num) {
1663 $obj = $db->fetch_object($result);
1664
1665 $contactstatic->id = $obj->rowid;
1666 $contactstatic->ref = $obj->rowid;
1667 $contactstatic->status = $obj->statut;
1668 $contactstatic->statut = $obj->statut;
1669 $contactstatic->lastname = $obj->lastname;
1670 $contactstatic->firstname = $obj->firstname;
1671 $contactstatic->civility_id = $obj->civility_id;
1672 $contactstatic->civility_code = $obj->civility_id;
1673 $contactstatic->poste = $obj->poste;
1674 $contactstatic->address = $obj->address;
1675 $contactstatic->zip = $obj->zip;
1676 $contactstatic->town = $obj->town;
1677 $contactstatic->phone_pro = $obj->phone_pro;
1678 $contactstatic->phone_mobile = $obj->phone_mobile;
1679 $contactstatic->phone_perso = $obj->phone_perso;
1680 $contactstatic->email = $obj->email;
1681 $contactstatic->socialnetworks = $obj->socialnetworks;
1682 $contactstatic->photo = $obj->photo;
1683 $contactstatic->fk_soc = $obj->fk_soc;
1684 $contactstatic->entity = $obj->entity;
1685
1686 $country_code = getCountry($obj->country_id, '2');
1687 $contactstatic->country_code = $country_code;
1688
1689 $contactstatic->setGenderFromCivility();
1690 $contactstatic->fetch_optionals();
1691
1692 $resultRole = $contactstatic->fetchRoles();
1693 if ($resultRole < 0) {
1694 setEventMessages(null, $contactstatic->errors, 'errors');
1695 }
1696
1697 if (is_array($contactstatic->array_options)) {
1698 foreach ($contactstatic->array_options as $key => $val) {
1699 $obj->$key = $val;
1700 }
1701 }
1702
1703 print '<tr class="oddeven">';
1704
1705 // Actions
1706 if ($conf->main_checkbox_left_column) {
1707 print '<td class="nowrap center">';
1708
1709 // Add to agenda
1710 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1711 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1712 print img_object($langs->trans("Event"), "action");
1713 print '</a> &nbsp; ';
1714 }
1715
1716 // Edit
1717 if ($user->hasRight('societe', 'contact', 'creer')) {
1718 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1719 print img_edit();
1720 print '</a>';
1721 }
1722
1723 // Delete
1724 if ($user->hasRight('societe', 'contact', 'delete')) {
1725 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) . '">';
1726 print img_delete();
1727 print '</a>';
1728 }
1729
1730 print '</td>';
1731 }
1732
1733 // ID
1734 if (!empty($arrayfields['t.rowid']['checked'])) {
1735 print '<td>';
1736 print $contactstatic->id;
1737 print '</td>';
1738 }
1739
1740 // Photo - Name
1741 if (!empty($arrayfields['t.name']['checked'])) {
1742 print '<td class="tdoverflowmax150">';
1743 print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 'user');
1744 print $contactstatic->getNomUrl(0, '', 0, '&backtopage=' . urlencode($backtopage));
1745 print '</td>';
1746 }
1747
1748 // Job position
1749 if (!empty($arrayfields['t.poste']['checked'])) {
1750 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->poste) . '">';
1751 if ($obj->poste) {
1752 print dol_escape_htmltag($obj->poste);
1753 }
1754 print '</td>';
1755 }
1756
1757 // Address - Phone - Email
1758 if (!empty($arrayfields['t.address']['checked'])) {
1759 $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1760 print '<td class="tdoverflowmax150 classfortooltip" title="'.dolPrintHTMLForAttribute($addresstoshow).'">';
1761 print $addresstoshow;
1762 print '</td>';
1763 }
1764
1765 // Note private
1766 if (!empty($arrayfields['t.note_private']['checked'])) {
1767 print '<td class="center">';
1768 print dolPrintHTML($obj->note_private);
1769 print '</td>';
1770 }
1771
1772 // Role
1773 if (!empty($arrayfields['sc.role']['checked'])) {
1774 print '<td class="tdoverflowmax150">';
1775 print $formcompany->showRoles("roles", $contactstatic, 'view');
1776 print '</td>';
1777 }
1778
1779 // Birthday
1780 if (!empty($arrayfields['t.birthday']['checked'])) {
1781 print '<td class="nowraponall">';
1782 print dol_print_date($db->jdate($obj->birthday));
1783 print '</td>';
1784 }
1785
1786 // Status
1787 if (!empty($arrayfields['t.statut']['checked'])) {
1788 print '<td class="center">' . $contactstatic->getLibStatut(5) . '</td>';
1789 }
1790
1791 if ($showuserlogin) {
1792 print '<td class="tdoverflowmax125">';
1793 $tmpuser = new User($db);
1794 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1795 $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1796 if ($resfetch > 0) {
1797 print $tmpuser->getNomUrl(-1, '', 0, 0, 24, 1);
1798 }
1799 print '</td>';
1800 }
1801
1802 // Extra fields
1803 $extrafieldsobjectkey = $contactstatic->table_element;
1804 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
1805
1806 // Actions
1807 if (!$conf->main_checkbox_left_column) {
1808 print '<td class="nowrap center">';
1809
1810 // Add to agenda
1811 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1812 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1813 print img_object($langs->trans("Event"), "action");
1814 print '</a> &nbsp; ';
1815 }
1816
1817 // Edit
1818 if ($user->hasRight('societe', 'contact', 'creer')) {
1819 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1820 print img_edit();
1821 print '</a>';
1822 }
1823
1824 // Delete
1825 if ($user->hasRight('societe', 'contact', 'delete')) {
1826 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) . '">';
1827 print img_delete();
1828 print '</a>';
1829 }
1830
1831 print '</td>';
1832 }
1833
1834 print "</tr>\n";
1835 $i++;
1836 }
1837
1838 if ($num == 0) {
1839 $colspan = 1 + ($showuserlogin ? 1 : 0);
1840 foreach ($arrayfields as $key => $val) {
1841 if (!empty($val['checked'])) {
1842 $colspan++;
1843 }
1844 }
1845 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
1846 }
1847 } else {
1848 $colspan = 1 + ($showuserlogin ? 1 : 0);
1849 foreach ($arrayfields as $key => $val) {
1850 if (!empty($val['checked'])) {
1851 $colspan++;
1852 }
1853 }
1854 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1855 }
1856 print "\n</table>\n";
1857 print '</div>';
1858
1859 print '</form>' . "\n";
1860
1861 return $i;
1862}
1863
1864
1877function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '')
1878{
1879 $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1880
1881 if ($noprint) {
1882 return $out;
1883 } else {
1884 print $out;
1885 return null;
1886 }
1887}
1888
1907function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1908{
1909 global $hookmanager, $user;
1910 global $form;
1911
1912 global $param, $massactionbutton;
1913
1914 $start_year = GETPOSTINT('dateevent_startyear');
1915 $start_month = GETPOSTINT('dateevent_startmonth');
1916 $start_day = GETPOSTINT('dateevent_startday');
1917 $end_year = GETPOSTINT('dateevent_endyear');
1918 $end_month = GETPOSTINT('dateevent_endmonth');
1919 $end_day = GETPOSTINT('dateevent_endday');
1920 $tms_start = '';
1921 $tms_end = '';
1922
1923 if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1924 $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1925 }
1926 if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1927 $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1928 }
1929 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
1930 $tms_start = '';
1931 $tms_end = '';
1932 }
1933 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1934
1935 // Check parameters
1936 if (!is_object($filterobj) && !is_object($objcon)) {
1937 dol_print_error(null, 'BadParameter');
1938 }
1939
1940 $out = '';
1941 $histo = array();
1942 $numaction = 0;
1943 $now = dol_now('tzuser');
1944
1945 // Open DSI -- Fix order by -- Begin
1946 $sortfield_list = explode(',', $sortfield);
1947 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1948 $sortfield_new_list = array();
1949 foreach ($sortfield_list as $sortfield_value) {
1950 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1951 }
1952 $sortfield_new = implode(',', $sortfield_new_list);
1953
1954 $complete = (string) (!empty($filters['search_complete']) ? $filters['search_complete'] : ''); // Can be 'na', '0', '50', '100'
1955 $percent = $complete !== '' ? $complete : -1;
1956 if ((string) $complete == '0') {
1957 $percent = '0';
1958 } elseif ((int) $complete == 100) {
1959 $percent = '100';
1960 }
1961
1962 $sql = '';
1963
1964 if (isModEnabled('agenda')) {
1965 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
1966 $hookmanager->initHooks(array('agendadao'));
1967
1968 $sql = "SELECT a.id, a.label as label,";
1969 $sql .= " a.datep as dp,";
1970 $sql .= " a.datep2 as dp2,";
1971 $sql .= " a.percent as percent, 'action' as type,";
1972 $sql .= " a.fk_element, a.elementtype,";
1973 $sql .= " a.fk_contact,";
1974 $sql .= " a.code, a.fulldayevent,";
1975 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1976 $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";
1977 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1978 $sql .= ", sp.lastname, sp.firstname";
1979 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1980 /* Nothing */
1981 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1982 /* Nothing */
1983 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1984 $sql .= ", m.lastname, m.firstname";
1985 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1986 $sql .= ", o.ref";
1987 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1988 $sql .= ", o.ref";
1989 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1990 $sql .= ", o.ref";
1991 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1992 $sql .= ", o.ref";
1993 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1994 $sql .= ", o.ref";
1995 } elseif (is_object($filterobj) && get_class($filterobj) == 'Holiday') {
1996 $sql .= ", o.ref";
1997 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
1998 $sql .= ", s.ref";
1999 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
2000 if (!empty($filterobj->fields['ref'])) {
2001 $sql .= ", o.ref";
2002 } elseif (!empty($filterobj->fields['label'])) {
2003 $sql .= ", o.label";
2004 }
2005 }
2006
2007 $canedit = 1;
2008 if (!$user->hasRight('agenda', 'myactions', 'read')) {
2009 $canedit = 0;
2010 }
2011 if (!$user->hasRight('agenda', 'allactions', 'read')) {
2012 $canedit = 0;
2013 }
2014 if (!$user->hasRight('agenda', 'allactions', 'read')) { // If no permission to see all, we show only affected to me
2015 $filters['search_filtert'] = (string) $user->id;
2016 }
2017
2018 // Fields from hook
2019 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
2020 $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
2021 if (!empty($hookmanager->resPrint)) {
2022 $sql .= $hookmanager->resPrint;
2023 }
2024
2025 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
2026 // Link to the owner of action
2027 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_action";
2028 // Link to action types
2029 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_actioncomm as c ON a.fk_action = c.id";
2030
2031 // Set $force_filter_contact:
2032 // - true for a filter on a user or a contact, so a link on table llx_actioncomm_resources or llx_actioncomm.fk_user_action
2033 // - false for a link on table llx_element_resources
2034 $force_filter_contact = false;
2035 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
2036 $force_filter_contact = true;
2037 }
2038 if (is_object($objcon) && $objcon->id > 0) {
2039 $force_filter_contact = true;
2040 }
2041
2042 // Fields from hook
2043 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
2044 $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
2045 if (!empty($hookmanager->resPrint)) {
2046 $sql .= $hookmanager->resPrint;
2047 }
2048 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
2049 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
2050 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
2051 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "element_resources as er";
2052 $sql .= " ON er.resource_type = 'dolresource'";
2053 $sql .= " AND er.element_type = 'action'";
2054 $sql .= " AND er.element_id = a.id";
2055 $sql .= " AND er.resource_id = " . ((int) $filterobj->id);
2056 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
2057 /* Nothing */
2058 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2059 $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
2060 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2061 $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as o";
2062 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2063 $sql .= ", " . MAIN_DB_PREFIX . "product as o";
2064 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2065 $sql .= ", " . MAIN_DB_PREFIX . "ticket as o";
2066 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
2067 $sql .= ", " . MAIN_DB_PREFIX . "bom_bom as o";
2068 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
2069 $sql .= ", " . MAIN_DB_PREFIX . "contrat as o";
2070 } elseif (is_object($filterobj) && get_class($filterobj) == 'Holiday') {
2071 $sql .= ", " . MAIN_DB_PREFIX . "holiday as o";
2072 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
2073 $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
2074 } elseif (is_object($filterobj) && get_class($filterobj) == 'Propal') {
2075 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "propal as o ON a.fk_element = o.rowid AND a.elementtype = 'propal'";
2076 } elseif (
2077 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2078 && ((!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
2079 && $filterobj->table_element && $filterobj->element
2080 ) {
2081 $sql .= ", " . MAIN_DB_PREFIX . $filterobj->table_element . " as o";
2082 }
2083
2084 $sql .= " WHERE a.entity IN (" . getEntity('agenda') . ")";
2085 if (!$force_filter_contact) {
2086 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
2087 $sql .= " AND a.fk_soc = " . ((int) $filterobj->id);
2088 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
2089 /* Nothing */
2090 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
2091 $sql .= " AND a.fk_project = " . ((int) $filterobj->id);
2092 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2093 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
2094 if ($filterobj->id) {
2095 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2096 }
2097 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
2098 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
2099 if ($filterobj->id) {
2100 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2101 }
2102 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2103 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
2104 if ($filterobj->id) {
2105 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2106 }
2107 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
2108 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
2109 if ($filterobj->id) {
2110 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2111 }
2112 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
2113 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice_supplier'";
2114 if ($filterobj->id) {
2115 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2116 }
2117 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2118 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
2119 if ($filterobj->id) {
2120 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2121 }
2122 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2123 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
2124 if ($filterobj->id) {
2125 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2126 }
2127 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
2128 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
2129 if ($filterobj->id) {
2130 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2131 }
2132 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
2133 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
2134 if ($filterobj->id) {
2135 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2136 }
2137 } elseif (is_object($filterobj) && get_class($filterobj) == 'Holiday') {
2138 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'holiday'";
2139 if ($filterobj->id) {
2140 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2141 }
2142 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
2143 $sql .= " AND a.fk_element = s.rowid AND a.elementtype = 'shipping'"; // shipping filter
2144 if ($filterobj->id) {
2145 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2146 }
2147 } elseif (
2148 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2149 && ((!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
2150 && $filterobj->table_element && $filterobj->element
2151 ) {
2152 // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
2153 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '" . $db->escape($filterobj->element. ($module ? "@" . $module : "")) . "'";
2154 if ($filterobj->id) {
2155 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2156 }
2157 } elseif (is_object($filterobj)) {
2158 return 'Bad value for $filterobj';
2159 }
2160 } else {
2161 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
2162 $sql .= " AND (u.rowid = " . ((int) $filterobj->id) . ' OR ';
2163 $sql .= " EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2164 $sql .= " AND r.element_type = '" . $db->escape($filterobj->table_element) . "' AND r.fk_element = " . ((int) $filterobj->id) . ')';
2165 $sql .= ")";
2166 }
2167 if (is_object($objcon) && $objcon->id > 0) {
2168 $sql .= " AND EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2169 $sql .= " AND r.element_type = '" . $db->escape($objcon->table_element) . "' AND r.fk_element = " . ((int) $objcon->id) . ')';
2170 }
2171 }
2172
2173 if (!empty($tms_start) && !empty($tms_end)) {
2174 $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) . "'))";
2175 } elseif (empty($tms_start) && !empty($tms_end)) {
2176 $sql .= " AND ((a.datep <= '" . $db->idate($tms_end) . "') OR (a.datep2 <= '" . $db->idate($tms_end) . "'))";
2177 } elseif (!empty($tms_start) && empty($tms_end)) {
2178 $sql .= " AND ((a.datep >= '" . $db->idate($tms_start) . "') OR (a.datep2 >= '" . $db->idate($tms_start) . "'))";
2179 }
2180
2181 if (is_array($actioncode) && !empty($actioncode)) {
2182 $tmpsql = '';
2183
2184 foreach ($actioncode as $key => $code) {
2185 if ((string) $code === '-1' || (string) $code === '') {
2186 continue;
2187 }
2188 if ($key != 0) {
2189 $tmpsql .= " OR ";
2190 }
2191 if (!empty($code)) {
2192 addEventTypeSQL($tmpsql, $code, "");
2193 }
2194 }
2195 if ($tmpsql) {
2196 $sql .= ' AND (';
2197 $sql .= $tmpsql;
2198 $sql .= ')';
2199 }
2200 } elseif (!empty($actioncode) && $actioncode != '-1') {
2201 addEventTypeSQL($sql, $actioncode);
2202 }
2203
2204 addOtherFilterSQL($sql, $donetodo, $now, $filters);
2205
2206 // Fields from hook
2207 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
2208 $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
2209 if (!empty($hookmanager->resPrint)) {
2210 $sql .= $hookmanager->resPrint;
2211 }
2212
2213 // Now add events of emailing module
2214 if (is_array($actioncode) && $objcon !== null) {
2215 foreach ($actioncode as $code) {
2216 $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
2217 if (!empty($sql2)) {
2218 if (!empty($sql)) {
2219 $sql = $sql . " UNION " . $sql2;
2220 } elseif (empty($sql)) {
2221 $sql = $sql2;
2222 }
2223 break;
2224 }
2225 }
2226 } elseif ($objcon !== null) {
2227 $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
2228 if (!empty($sql) && !empty($sql2)) {
2229 $sql = $sql . " UNION " . $sql2;
2230 } elseif (empty($sql) && !empty($sql2)) {
2231 $sql = $sql2;
2232 }
2233 }
2234 }
2235
2236 $MAXWITHOUTPAGINATION = getDolGlobalInt('AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
2237 $num = 0;
2238
2239 if ($sql) {
2240 // TODO Add navigation with this limits by replacing call of show_actions_done by the code found into comm/action/list.php...
2241 $offset = 0;
2242 $limit = $MAXWITHOUTPAGINATION;
2243
2244 // Complete request and execute it with limit
2245 $sql .= $db->order($sortfield_new, $sortorder); // @phan-suppress-current-line SqlInjection
2246 if ($limit) { // @phpstan-ignore-line
2247 $sql .= $db->plimit($limit + 1, $offset);
2248 }
2249
2250 dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
2251
2252 $resql = $db->query($sql);
2253 if ($resql) {
2254 $i = 0;
2255 $num = $db->num_rows($resql);
2256
2257 $imaxinloop = ($limit ? min($num, $limit) : $num);
2258 while ($i < $imaxinloop) {
2259 $obj = $db->fetch_object($resql);
2260 if (empty($obj)) {
2261 break;
2262 }
2263
2264 if ($obj->type == 'action') {
2265 $contactaction = new ActionComm($db);
2266 $contactaction->id = $obj->id;
2267 $result = $contactaction->fetchResources();
2268 if ($result < 0) {
2269 dol_print_error($db);
2270 setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2271 }
2272
2273 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2274 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2275 $tododone = '';
2276 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2277 $tododone = 'todo';
2278 }
2279
2280 $histo[$numaction] = array(
2281 'type' => $obj->type,
2282 'tododone' => $tododone,
2283 'id' => (int) $obj->id,
2284 'datestart' => $db->jdate($obj->dp),
2285 'dateend' => $db->jdate($obj->dp2),
2286 'fulldayevent' => (int) $obj->fulldayevent,
2287 'note' => $obj->label,
2288 'percent' => (int) $obj->percent,
2289
2290 'userid' => (int) $obj->user_id,
2291 'login' => $obj->user_login,
2292 'userfirstname' => $obj->user_firstname,
2293 'userlastname' => $obj->user_lastname,
2294 'userphoto' => $obj->user_photo,
2295
2296 'contact_id' => (int) $obj->fk_contact,
2297 'socpeopleassigned' => $contactaction->socpeopleassigned,
2298 'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2299 'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2300 'fk_element' => (int) $obj->fk_element,
2301 'elementtype' => $obj->elementtype,
2302
2303 'code' => $obj->code,
2304
2305 // Type of event
2306 'acode' => $obj->acode,
2307 'alabel' => $obj->alabel,
2308 'libelle' => $obj->alabel, // deprecated
2309 'apicto' => $obj->apicto
2310 );
2311 } else {
2312 $histo[$numaction] = array(
2313 'type' => $obj->type,
2314 'tododone' => 'done',
2315 'id' => (int) $obj->id,
2316 'datestart' => $db->jdate($obj->dp),
2317 'dateend' => $db->jdate($obj->dp2),
2318 'fulldayevent' => (int) $obj->fulldayevent,
2319 'note' => $obj->label,
2320 'percent' => (int) $obj->percent,
2321
2322 'code' => $obj->code,
2323
2324 // Type of event
2325 'acode' => $obj->acode,
2326
2327 'userid' => (int) $obj->user_id,
2328 'login' => $obj->user_login,
2329 'userfirstname' => $obj->user_firstname,
2330 'userlastname' => $obj->user_lastname,
2331 'userphoto' => $obj->user_photo
2332 );
2333 }
2334
2335 $numaction++;
2336 $i++;
2337 }
2338 } else {
2339 dol_print_error($db);
2340 }
2341 }
2342
2343 '@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';
2344
2345 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2346 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
2347
2348 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
2349 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
2350 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2351 require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2352
2353 $formactions = new FormActions($db);
2354
2355 $actionstatic = new ActionComm($db);
2356 $userstatic = new User($db);
2357 $userlinkcache = array();
2358 $contactstatic = new Contact($db);
2359 $elementlinkcache = array();
2360
2361 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST" spellcheck="false">';
2362 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
2363 if (
2364 $objcon && get_class($objcon) == 'Contact' &&
2365 (is_null($filterobj) || get_class($filterobj) == 'Societe')
2366 ) {
2367 $out .= '<input type="hidden" name="id" value="' . $objcon->id . '" />';
2368 } else {
2369 $out .= '<input type="hidden" name="id" value="' . $filterobj->id . '" />';
2370 }
2371 if ($filterobj && get_class($filterobj) == 'Societe') {
2372 $out .= '<input type="hidden" name="socid" value="' . $filterobj->id . '" />';
2373 } else {
2374 $out .= '<input type="hidden" name="userid" value="' . $filterobj->id . '" />';
2375 }
2376
2377 $out .= "\n";
2378
2379 $out .= '<div class="div-table-responsive-no-min">';
2380 $out .= '<table class="noborder centpercent">';
2381
2382 $out .= '<tr class="liste_titre_filter">';
2383
2384 // Action column
2385 if ($conf->main_checkbox_left_column) {
2386 $out .= '<th class="liste_titre width50 middle">';
2387 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2388 $out .= $searchpicto;
2389 $out .= '</th>';
2390 }
2391
2392 if ($donetodo) {
2393 $out .= '<td class="liste_titre"></td>';
2394 }
2395
2396 // ID
2397 $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="' . (isset($filters['search_rowid']) ? $filters['search_rowid'] : '') . '"></td>';
2398 // Date
2399 $out .= '<td class="liste_titre center">';
2400 $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2401 $out .= '</td>';
2402 // Owner
2403 $out .= '<td class="liste_titre">';
2404 $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');
2405 $out .= '</td>';
2406 // Type
2407 $out .= '<td class="liste_titre">';
2408 $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);
2409 $out .= '</td>';
2410 // Label - Title
2411 $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth200" name="search_agenda_label" value="' . $filters['search_agenda_label'] . '"></td>';
2412 $out .= '<td class="liste_titre"></td>';
2413 $out .= '<td class="liste_titre"></td>';
2414 // Status ($percent can be 'na'or < 100 or 100)
2415 $out .= '<td class="liste_titre parentonrightofpage">';
2416 $out .= $formactions->form_select_status_action('formaction', $percent, 1, 'search_complete', 1, 2, 'search_status width100 onrightofpage', 1);
2417 $out .= '</td>';
2418 // Action column
2419 if (!$conf->main_checkbox_left_column) {
2420 $out .= '<td class="liste_titre" align="middle">';
2421 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2422 $out .= $searchpicto;
2423 $out .= '</td>';
2424 }
2425 $out .= '</tr>';
2426
2427 $out .= '<tr class="liste_titre">';
2428 // Action column
2429 if ($conf->main_checkbox_left_column) {
2430 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2431 }
2432 if ($donetodo && $filterobj !== null) {
2433 $tmp = '';
2434 if (get_class($filterobj) == 'Societe') {
2435 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&socid=' . $filterobj->id . '&status=done">';
2436 }
2437 if (get_class($filterobj) == 'User') {
2438 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&userid=' . $filterobj->id . '&status=done">';
2439 }
2440 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2441 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2442 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2443 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2444 if (get_class($filterobj) == 'Societe') {
2445 $tmp .= '</a>';
2446 }
2447 if (get_class($filterobj) == 'User') {
2448 $tmp .= '</a>';
2449 }
2450 $out .= getTitleFieldOfList($tmp);
2451 }
2452 $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2453 $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2454 $out .= getTitleFieldOfList("Owner");
2455 $out .= getTitleFieldOfList("Type");
2456 $out .= getTitleFieldOfList("Title", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2457 $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2458 $out .= getTitleFieldOfList("LinkedObject", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2459 $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2460 // Action column
2461 if (!$conf->main_checkbox_left_column) {
2462 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2463 }
2464 $out .= '</tr>';
2465
2466 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
2467 $caction = new CActionComm($db);
2468 $arraylist = $caction->liste_array(1, 'code', '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 0 : 1), '', 1);
2469
2470 foreach ($histo as $key => $value) {
2471 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2472
2473 if (empty($actionstatic->code)) {
2474 $actionstatic->code = $histo[$key]['acode'];
2475 }
2476 $actionstatic->type_picto = $histo[$key]['apicto'] ?? '';
2477 $actionstatic->type_code = $histo[$key]['acode'];
2478
2479 $out .= '<tr class="oddeven">';
2480
2481 // Action column
2482 if ($conf->main_checkbox_left_column) {
2483 $out .= '<td></td>';
2484 }
2485
2486 // Done or todo
2487 if ($donetodo) {
2488 $out .= '<td class="nowrap">';
2489 $out .= '</td>';
2490 }
2491
2492 // Ref
2493 $out .= '<td class="nowraponall">';
2494 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2495 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
2496 $out .= $histo[$key]['id'];
2497 $out .= '</a>';
2498 } else {
2499 $out .= $actionstatic->getNomUrl(1, -1);
2500 }
2501 $out .= '</td>';
2502
2503 // Date
2504 $out .= '<td class="center nowraponall nopaddingtopimp nopaddingbottomimp">';
2505
2506 $out .= dolOutputDates($histo[$key]['datestart'], $histo[$key]['dateend'], (int) $histo[$key]['fulldayevent'], 0, '', 'tzuserrel', 1);
2507
2508 // Add the late warning
2509 $late = 0;
2510 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2511 $late = 1;
2512 }
2513 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2514 $late = 1;
2515 }
2516 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2517 $late = 1;
2518 }
2519 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2520 $late = 1;
2521 }
2522 if ($late) {
2523 $out .= img_warning($langs->trans("Late")) . ' ';
2524 }
2525 $out .= '</td>';
2526
2527 // Author of event
2528 $out .= '<td class="tdoverflowmax125">';
2529 if ($histo[$key]['userid'] > 0) {
2530 if (isset($userlinkcache[$histo[$key]['userid']])) {
2531 $link = $userlinkcache[$histo[$key]['userid']];
2532 } else {
2533 $userstatic->fetch($histo[$key]['userid']);
2534 $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2535 $userlinkcache[$histo[$key]['userid']] = $link;
2536 }
2537 $out .= $link;
2538 }
2539 $out .= '</td>';
2540
2541 // type_code // column "acode" in the sql = code in type of actioncomm, example: AC_OTH_AUTO, AC_EMAILING
2542 // code // columne code in the sql (not yet added), can be AC_CONTACT_SENTBYMAIL, ...
2543
2544 // Type
2545 $labelOfTypeToShow = $actionstatic->type_code;
2546 //$typelabel = $actionstatic->type_label;
2547 $code = $actionstatic->code;
2548 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labelOfTypeToShow])) {
2549 $labelOfTypeToShow = 'AC_OTH';
2550 }
2551 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2552 $labelOfTypeToShow = $langs->trans("Message");
2553 } else {
2554 if (!empty($arraylist[$labelOfTypeToShow])) {
2555 $labelOfTypeToShow = $arraylist[$labelOfTypeToShow];
2556 } elseif ($actionstatic->type_code == 'AC_EMAILING') {
2557 $langs->load("mails");
2558 $labelOfTypeToShow = $langs->trans("Emailing");
2559 }
2560 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labelOfTypeToShow && !empty($arraylist[$actionstatic->code])) {
2561 $labelOfTypeToShow .= ' - ' . $arraylist[$actionstatic->code]; // Show also detailed code
2562 }
2563 }
2564
2565 $labelOfTypeToShowLong = $labelOfTypeToShow;
2566 if ($actionstatic->type_code == 'AC_OTH_AUTO') {
2567 $labelOfTypeToShowLong .= ' (auto)';
2568 }
2569
2570 $out .= '<td class="tdoverflowmax125" title="' . $labelOfTypeToShowLong . '">';
2571 // Example $actionstatic->code = AC_COMPANY_MODIFY and $actionstatic->type_code = AC_OTH_AUTO
2572 $out .= $actionstatic->getTypePicto();
2573 $out .= $labelOfTypeToShow;
2574 if (preg_match('/PRIVATE/', $actionstatic->code)) {
2575 $out .= ' ' . img_picto($langs->trans("Private"), 'lock', 'class="valignmiddle"');
2576 }
2577 $out .= '</td>';
2578
2579 // Title/Label of event
2580 $out .= '<td class="tdoverflowmax300"';
2581 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2582 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2583 //$label_trans = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2584 $label = $histo[$key]['note'];
2585 $actionstatic->id = $histo[$key]['id'];
2586 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2587 $label = preg_replace('/^\[[^\[]*\]/', '[...]', $label);
2588 $out .= dol_trunc($label, 120);
2589 }
2590 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2591 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2592 $label = ($transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2593 $label .= ' - ' . $histo[$key]['note'];
2594 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '"';
2595 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2596 $label = preg_replace('/^\[[^\[]*\]/', '[...]', $label);
2597 $out .= dol_trunc($label, 120);
2598 $out .= '</a>';
2599 }
2600 $out .= '</td>';
2601
2602 // Contact(s) for action
2603 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2604 $out .= '<td class="valignmiddle">';
2605 $contact = new Contact($db);
2606 foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2607 $result = $contact->fetch($cid);
2608
2609 if ($result < 0) {
2610 dol_print_error($db, $contact->error);
2611 } elseif ($result > 0) {
2612 if (count($histo[$key]['socpeopleassigned']) > 1) {
2613 $out .= $contact->getNomUrl(-2, '', 0, '', -1, 0, 'paddingright');
2614 } else {
2615 $out .= $contact->getNomUrl(-3, '', 0, '', -1, 0, 'paddingright');
2616 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2617 if (!empty($contact->phone_pro)) {
2618 $out .= '(' . dol_print_phone($contact->phone_pro) . ')';
2619 }
2620 }
2621 }
2622 }
2623 }
2624 $out .= '</td>';
2625 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2626 $contactstatic->lastname = $histo[$key]['lastname'];
2627 $contactstatic->firstname = $histo[$key]['firstname'];
2628 $contactstatic->id = $histo[$key]['contact_id'];
2629 $contactstatic->photo = $histo[$key]['contact_photo'];
2630 $out .= '<td width="120">' . $contactstatic->getNomUrl(-1, '', 10) . '</td>';
2631 } else {
2632 $out .= '<td>&nbsp;</td>';
2633 }
2634
2635 // Linked object
2636 $out .= '<td class="tdoverflowmax200 nowraponall">';
2637 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2638 if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2639 $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2640 } else {
2641 if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2642 $elementlinkcache[$histo[$key]['elementtype']] = array();
2643 }
2644 $link = dolGetElementUrl((int) $histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2645 $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2646 }
2647 $out .= $link;
2648 }
2649 $out .= '</td>';
2650
2651 // Status / Progression
2652 $out .= '<td class="nowrap center">';
2653 $out .= $actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']);
2654 $out .= '</td>';
2655
2656 // Action column
2657 if (!$conf->main_checkbox_left_column) {
2658 $out .= '<td></td>';
2659 }
2660
2661 $out .= "</tr>\n";
2662 }
2663 if (empty($histo)) {
2664 $colspan = 9;
2665 $out .= '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
2666 }
2667
2668 if ($num > $MAXWITHOUTPAGINATION) {
2669 $langs->load("errors");
2670 $colspan = 9;
2671 $out .= '<tr><td class="center" colspan="' . $colspan . '"><span class="opacitymedium">...' . $langs->trans("WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) . '...</span></td></tr>';
2672 }
2673
2674 $out .= "</table>\n";
2675 $out .= "</div>\n";
2676
2677 $out .= '</form>';
2678 }
2679
2680 if ($noprint) {
2681 return $out;
2682 } else {
2683 print $out;
2684 return null;
2685 }
2686}
2687
2697function show_subsidiaries($conf, $langs, $db, $object)
2698{
2699 $i = -1;
2700
2701 $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";
2702 $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
2703 $sql .= " WHERE s.parent = " . ((int) $object->id);
2704 $sql .= " AND s.entity IN (" . getEntity('societe') . ")";
2705 $sql .= " ORDER BY s.nom";
2706
2707 $result = $db->query($sql);
2708 $num = $db->num_rows($result);
2709
2710 if ($num) {
2711 $socstatic = new Societe($db);
2712
2713 print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2714
2715 print "\n" . '<div class="div-table-responsive-no-min">' . "\n";
2716 print '<table class="noborder centpercent">' . "\n";
2717
2718 print '<tr class="liste_titre"><td>' . $langs->trans("Company") . '</td>';
2719 print '<td>' . $langs->trans("Address") . '</td><td>' . $langs->trans("Zip") . '</td>';
2720 print '<td>' . $langs->trans("Town") . '</td><td>' . $langs->trans("CustomerCode") . '</td>';
2721 print "<td>&nbsp;</td>";
2722 print "</tr>";
2723
2724 $i = 0;
2725
2726 while ($i < $num) {
2727 $obj = $db->fetch_object($result);
2728
2729 $socstatic->id = $obj->rowid;
2730 $socstatic->name = $obj->name;
2731 $socstatic->name_alias = $obj->name_alias;
2732 $socstatic->email = $obj->email;
2733 $socstatic->code_client = $obj->code_client;
2734 $socstatic->code_fournisseur = $obj->code_fournisseur;
2735 $socstatic->code_compta = $obj->code_compta;
2736 $socstatic->code_compta_client = $obj->code_compta;
2737 $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2738 $socstatic->email = $obj->email;
2739 $socstatic->canvas = $obj->canvas;
2740 $socstatic->client = $obj->client;
2741 $socstatic->fournisseur = $obj->fournisseur;
2742 $socstatic->status = $obj->status;
2743
2744 print '<tr class="oddeven">';
2745
2746 print '<td class="tdoverflowmax150">';
2747 print $socstatic->getNomUrl(1);
2748 print '</td>';
2749
2750 print '<td class="tdoverflowmax400" title="' . dol_escape_htmltag($obj->address) . '">' . dol_escape_htmltag($obj->address) . '</td>';
2751 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->zip) . '">' . $obj->zip . '</td>';
2752 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->town) . '">' . $obj->town . '</td>';
2753 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->code_client) . '">' . $obj->code_client . '</td>';
2754
2755 print '<td class="center">';
2756 print '<a class="editfielda" href="' . DOL_URL_ROOT . '/societe/card.php?socid=' . ((int) $obj->rowid) . '&action=edit&token=' . newToken() . '">';
2757 print img_edit();
2758 print '</a></td>';
2759
2760 print "</tr>\n";
2761 $i++;
2762 }
2763 print "\n</table>\n";
2764 print '</div>' . "\n";
2765 }
2766
2767 print "<br>\n";
2768
2769 return $i;
2770}
2771
2788function getSalesRepresentativeSqlFilter($socidfield, $userids = 0, $not = 0, $allownull = 0)
2789{
2790 global $db;
2791
2792 if (!is_array($userids)) {
2793 $userids = ($userids === '' || $userids === null) ? array() : explode(',', (string) $userids);
2794 }
2795 $userids = array_values(array_filter(array_map('intval', $userids), static function (int $v): bool {
2796 return $v > 0;
2797 }));
2798
2799 $sql = "";
2800 if ($allownull) {
2801 $sql .= "(t.fk_soc IS NULL OR ";
2802 }
2803 $sql .= ($not ? 'NOT EXISTS' : 'EXISTS');
2804 // $socidfield is a column expression of the outer query (e.g. 's.rowid'); it is compared to sc.fk_soc
2805 $sql .= ' (SELECT sc.fk_soc FROM '.$db->prefix().'societe_commerciaux as sc WHERE '.$db->sanitize($socidfield).' = sc.fk_soc';
2806 if (!empty($userids)) {
2807 $sql .= ' AND sc.fk_user IN ('.$db->sanitize(implode(',', $userids)).')';
2808 }
2809 if ($allownull) {
2810 $sql .= ')';
2811 }
2812
2813 return $sql;
2814}
2815
2824function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2825{
2826 global $db;
2827
2828 // Condition on actioncode
2829
2830 if ((string) $actioncode == '-1') {
2831 return $sql;
2832 }
2833
2834 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2835 if ($actioncode == 'AC_NON_AUTO') {
2836 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2837 } elseif ($actioncode == 'AC_ALL_AUTO') {
2838 $sql .= " $sqlANDOR c.type = 'systemauto'";
2839 } else {
2840 if ($actioncode == 'AC_OTH') {
2841 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2842 } elseif ($actioncode == 'AC_OTH_AUTO') {
2843 $sql .= " $sqlANDOR c.type = 'systemauto'";
2844 }
2845 }
2846 } else {
2847 if ($actioncode == 'AC_NON_AUTO') {
2848 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2849 } elseif ($actioncode == 'AC_ALL_AUTO') {
2850 $sql .= " $sqlANDOR c.type = 'systemauto'";
2851 } else {
2852 $sql .= " $sqlANDOR c.code = '" . $db->escape($actioncode) . "'";
2853 }
2854 }
2855
2856 return $sql;
2857}
2858
2868function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2869{
2870 global $db;
2871
2872 if ($donetodo == 'todo') {
2873 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) . "'))";
2874 } elseif ($donetodo == 'done') {
2875 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))";
2876 }
2877 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'na') {
2878 $sql .= " AND a.percent = -1";
2879 }
2880 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '0') {
2881 $sql .= " AND a.percent = 0";
2882 }
2883 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '50') {
2884 $sql .= " AND a.percent > 0 AND a.percent < 100";
2885 }
2886 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'todo') {
2887 $sql .= " AND a.percent >= 0 AND a.percent < 100";
2888 }
2889 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '100') {
2890 $sql .= " AND a.percent = 100";
2891 }
2892 if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2893 $sql .= natural_search('a.label', $filters['search_agenda_label']);
2894 }
2895 if (is_array($filters) && !empty($filters['search_rowid'])) {
2896 $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2897 }
2898 if (is_array($filters) && !empty($filters['search_filtert']) && ((int) $filters['search_filtert']) != -1) {
2899 $sql .= natural_search('a.fk_user_action', $filters['search_filtert'], 1);
2900 }
2901
2902 return $sql;
2903}
2904
2914function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2915{
2916 global $db;
2917
2918 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2919 if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2920 $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";
2921 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2922 $sql2 .= ", 'AC_EMAILING' as code, '0' as fulldayevent, 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2923 $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
2924 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2925 $sql2 .= ", '' as lastname, '' as firstname";
2926 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2927 $sql2 .= ", '' as lastname, '' as firstname";
2928 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2929 $sql2 .= ", '' as ref";
2930 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2931 $sql2 .= ", '' as ref";
2932 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2933 $sql2 .= ", '' as ref";
2934 }
2935 $sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u";
2936 $sql2 .= " WHERE mc.email = '" . $db->escape((string) $objcon->email) . "'"; // Search is done on email.
2937 $sql2 .= " AND mc.statut = 1";
2938 $sql2 .= " AND u.rowid = m.fk_user_valid";
2939 $sql2 .= " AND mc.fk_mailing=m.rowid";
2940
2941 return $sql2;
2942 } else {
2943 return '';
2944 }
2945}
2946
2947
2960function htmlPrintOnlineHeader($mysoc, $langs, $showlogo = 1, $alttext = '', $subimageconst = '', $altlogo1 = '', $altlogo2 = '')
2961{
2963
2964 // Set logo of company by default
2965 $logosmall = $mysoc->logo_small;
2966 $logo = $mysoc->logo;
2967
2968 if ($altlogo1 && getDolGlobalString($altlogo1)) {
2969 $logosmall = getDolGlobalString($altlogo1);
2970 } elseif ($altlogo2 && getDolGlobalString($altlogo2)) {
2971 $logosmall = getDolGlobalString($altlogo2);
2972 }
2973
2974 // Define $urllogo and $urllogopublic
2975 //$urllogo = '';
2976 $urllogopublic = '';
2977 if ($showlogo) {
2978 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $logosmall)) {
2979 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$logosmall);
2980 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/thumbs/' . $logosmall);
2981 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $logo)) {
2982 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$logo);
2983 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/' . $logo);
2984 } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) {
2985 //$urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
2986 $urllogopublic = $dolibarr_main_url_root . '/theme/dolibarr_logo.svg';
2987 }
2988 }
2989
2990 print '<header class="center">';
2991
2992 // Output html code for logo
2993 if ($urllogopublic || $alttext) {
2994 print '<div class="backgreypublicpayment">';
2995 print '<div class="logopublicpayment">';
2996 if ($urllogopublic) {
2997 if (!is_numeric($showlogo)) {
2998 print '<a href="' . $showlogo . '">';
2999 }
3000 print '<img id="dolpaymentlogo" src="' . $urllogopublic . '">';
3001 if (!is_numeric($showlogo)) {
3002 print '</a>';
3003 }
3004 }
3005 if ($alttext) {
3006 print '<div class="clearboth"></div><strong>' . $alttext . '</strong>';
3007 }
3008 print '</div>';
3009 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
3010 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>';
3011 }
3012 print '</div>';
3013 }
3014
3015 // Add an optional image under the ban with logo/title
3016 if (getDolGlobalString($subimageconst)) {
3017 print '<div class="backimagepublicsubimage">';
3018 print '<img id="id' . $subimageconst . '" src="' . getDolGlobalString($subimageconst) . '">';
3019 print '</div>';
3020 }
3021
3022 print '</header>';
3023}
3024
3025
3036function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
3037{
3038 $reg = array();
3039
3040 // Juridical status
3041 $line1 = "";
3042 if ($fromcompany->forme_juridique_code) {
3043 $line1 .= ($line1 ? " - " : "") . getFormeJuridiqueLabel((string) $fromcompany->forme_juridique_code);
3044 }
3045 // Capital
3046 if ($fromcompany->capital) {
3047 $line1 .= ($line1 ? " - " : "") . $langs->transnoentities("CapitalOf", (string) $fromcompany->capital) . " " . $langs->transnoentities("Currency" . getDolCurrency());
3048 }
3049 // Prof Id 1
3050 if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
3051 $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
3052 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3053 $field = $reg[1];
3054 }
3055 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof1;
3056 }
3057 // Prof Id 2
3058 if ($fromcompany->idprof2) {
3059 $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
3060 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3061 $field = $reg[1];
3062 }
3063 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof2;
3064 }
3065
3066 // Second line of company infos
3067 $line2 = "";
3068 // Prof Id 3
3069 if ($fromcompany->idprof3) {
3070 $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
3071 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3072 $field = $reg[1];
3073 }
3074 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof3;
3075 }
3076 // Prof Id 4
3077 if ($fromcompany->idprof4) {
3078 $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
3079 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3080 $field = $reg[1];
3081 }
3082 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof4;
3083 }
3084 // IntraCommunautary VAT
3085 if ($fromcompany->tva_intra != '') {
3086 $line2 .= ($line2 ? " - " : "") . $langs->transnoentities("VATIntraShort") . ": " . $fromcompany->tva_intra;
3087 }
3088
3089 print '<!-- htmlPrintOnlineFooter -->' . "\n";
3090
3091 // 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.
3092 print '<footer class="center centpercent opacitymedium paddingbottom">' . "\n";
3093 print '<br>';
3094 if ($addformmessage) {
3095 print '<!-- object = ' . (empty($object) ? 'undefined' : $object->element) . ' -->';
3096 print '<br>';
3097
3098 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_' . $suffix;
3099 if (getDolGlobalString($parammessageform) !== '') {
3100 print $langs->transnoentities(getDolGlobalString($parammessageform));
3101 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
3102 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
3103 }
3104
3105 // Add other message if VAT exists
3106 if (!empty($object->total_vat) || !empty($object->total_tva)) {
3107 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_' . $suffix;
3108 if (getDolGlobalString($parammessageform) !== '') {
3109 print $langs->transnoentities(getDolGlobalString($parammessageform));
3110 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
3111 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
3112 }
3113 }
3114 }
3115
3116 print '<span style="font-size: 10px;"><br><hr>' . "\n";
3117 print $fromcompany->name . '<br>';
3118 print $line1;
3119 if (strlen($line1 . $line2) > 50) {
3120 print '<br>';
3121 } else {
3122 print ' - ';
3123 }
3124 print $line2;
3125 print '</span>';
3126 print '</footer>' . "\n";
3127}
$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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
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:66
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:183
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.