dolibarr 24.0.3
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 {
186 }
187 dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
188 }
189 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/societe/project.php', ['socid' => $object->id]);
190 $head[$h][1] = $langs->trans("Projects");
191 if ($nbProject > 0) {
192 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbProject . '</span>';
193 }
194 $head[$h][2] = 'project';
195 $h++;
196 }
197
198 // Tab to link resources
199 if (isModEnabled('resource') && getDolGlobalString('RESOURCE_ON_THIRDPARTIES')) {
200 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/resource/element_resource.php', ['element' => 'societe', 'element_id' => $object->id]);
201 $head[$h][1] = $langs->trans("Resources");
202 $head[$h][2] = 'resources';
203 $h++;
204 }
205
206 // Related items
207 if ((isModEnabled('order') || isModEnabled('propal') || isModEnabled('invoice') || isModEnabled('intervention') || isModEnabled("supplier_proposal") || isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))
208 && !getDolGlobalString('THIRDPARTIES_DISABLE_RELATED_OBJECT_TAB')
209 ) {
210 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/societe/consumption.php', ['socid' => $object->id]);
211 $head[$h][1] = $langs->trans("Referers");
212 $head[$h][2] = 'consumption';
213 $h++;
214 }
215
216 // Bank accounts
217 if (!getDolGlobalInt('SOCIETE_DISABLE_BANKACCOUNT')) {
218 $nbBankAccount = 0;
219 $foundonexternalonlinesystem = 0;
220 $langs->load("bills");
221
222 $title = $langs->trans("PaymentModes");
223
224 $servicestatus = 0;
225 if (isModEnabled('stripe')) {
226 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha')*/) {
227 $servicestatus = 1;
228 }
229
230 include_once DOL_DOCUMENT_ROOT . '/societe/class/societeaccount.class.php';
231 $societeaccount = new SocieteAccount($db);
232 $stripecu = $societeaccount->getCustomerAccount($object->id, 'stripe', $servicestatus); // Get thirdparty cu_...
233 if ($stripecu) {
234 $foundonexternalonlinesystem++;
235 }
236 }
237
238 $sql = "SELECT COUNT(n.rowid) as nb";
239 $sql .= " FROM " . MAIN_DB_PREFIX . "societe_rib as n";
240 $sql .= " WHERE n.fk_soc = " . ((int) $object->id);
241 if (!isModEnabled('stripe')) {
242 $sql .= " AND (n.stripe_card_ref IS NULL OR n.stripe_card_ref ='')";
243 } else {
244 $sql .= " AND (n.stripe_card_ref IS NULL OR (n.stripe_card_ref IS NOT NULL AND n.status = " . ((int) $servicestatus) . "))";
245 }
246
247 $resql = $db->query($sql);
248 if ($resql) {
249 $obj = $db->fetch_object($resql);
250 $nbBankAccount = $obj->nb;
251 } else {
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 {
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 {
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 {
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 {
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 . '/societe/admin/societe_extrafields.php');
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 . '/societe/admin/contact_extrafields.php');
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 {
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 {
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 {
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("OpportunityAmountShort") . '</td>';
1190 print '<td class="center">' . $langs->trans("OpportunityStatusShort") . '</td>';
1191 print '<td class="right">' . $langs->trans("OpportunityProbabilityShort") . '</td>';
1192 print '<td class="right">' . $langs->trans("Status") . '</td>';
1193 print '</tr>';
1194
1195 if ($num > 0) {
1196 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
1197
1198 $projecttmp = new Project($db);
1199
1200 $i = 0;
1201
1202 while ($i < $num) {
1203 $obj = $db->fetch_object($result);
1204 $projecttmp->fetch($obj->id);
1205
1206 // To verify role of users
1207 $userAccess = $projecttmp->restrictedProjectArea($user);
1208
1209 if ($userAccess > 0) {
1210 print '<tr class="oddeven">';
1211
1212 // Ref
1213 print '<td class="nowraponall">';
1214 print $projecttmp->getNomUrl(1, '', 0, '', '-', 0, 1, '', 'project:' . $_SERVER["PHP_SELF"] . '?socid=__SOCID__');
1215 print '</td>';
1216
1217 // Label
1218 print '<td title="' . dol_escape_htmltag($obj->title) . '"><div class="twolinesmax-normallineheight minwidth200onall">' . dol_escape_htmltag($obj->title) . '</div></td>';
1219 // Date start
1220 print '<td class="center">' . dol_print_date($db->jdate($obj->do), "day") . '</td>';
1221 // Date end
1222 print '<td class="center">' . dol_print_date($db->jdate($obj->de), "day") . '</td>';
1223 // Opp amount
1224 print '<td class="right">';
1225 if ($obj->opp_status_code) {
1226 print '<span class="amount">' . price($obj->opp_amount, 1, '', 1, -1, -1, '') . '</span>';
1227 }
1228 print '</td>';
1229 // Opp status
1230 print '<td class="center">';
1231 if ($obj->opp_status_code) {
1232 print $langs->trans("OppStatus" . $obj->opp_status_code);
1233 }
1234 print '</td>';
1235 // Opp percent
1236 print '<td class="right">';
1237 if ($obj->opp_percent) {
1238 print price($obj->opp_percent, 1, '', 1, 0) . '%';
1239 }
1240 print '</td>';
1241 // Status
1242 print '<td class="right">' . $projecttmp->getLibStatut(5) . '</td>';
1243
1244 print '</tr>';
1245 }
1246 $i++;
1247 }
1248 } else {
1249 print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1250 }
1251 $db->free($result);
1252 } else {
1254 }
1255 }
1256
1257 $parameters = array('sql' => $sql, 'function' => 'show_projects');
1258 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1259 print $hookmanager->resPrint;
1260
1261 print "</table>";
1262 print '</div>';
1263
1264 print "<br>\n";
1265 }
1266
1267 return $i;
1268}
1269
1270
1282function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserlogin = 0)
1283{
1284 global $user, $extrafields, $hookmanager;
1285 global $contextpage;
1286
1287 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
1288 $formcompany = new FormCompany($db);
1289 $form = new Form($db);
1290
1291 $optioncss = GETPOST('optioncss', 'alpha');
1292 $sortfield = GETPOST('sortfield', 'aZ09comma');
1293 $sortorder = GETPOST('sortorder', 'aZ09comma');
1294 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
1295
1296 $search_status = GETPOST("search_status", "intcomma");
1297 if ($search_status == '') {
1298 $search_status = 1; // always display active customer first
1299 }
1300
1301 $search_rowid = GETPOST("search_rowid", "intcomma");
1302 $search_name = GETPOST("search_name", 'alpha');
1303 $search_address = GETPOST("search_address", 'alpha');
1304 $search_poste = GETPOST("search_poste", 'alpha');
1305 $search_note_private = GETPOST('search_note_private', 'alphanohtml');
1306 $search_roles = GETPOST("search_roles", 'array');
1307 $search_birthday_dtstart = GETPOST("search_birthday_dtstart", 'alpha');
1308 $search_birthday_dtend = GETPOST("search_birthday_dtend", 'alpha');
1309
1310 if ($search_birthday_dtstart != '' || $search_birthday_dtend != '') {
1311 $search_birthday_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_dtstartmonth'), GETPOSTINT('search_birthday_dtstartday'), GETPOSTINT('search_birthday_dtstartyear'));
1312 $search_birthday_dtend = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_dtendmonth'), GETPOSTINT('search_birthday_dtendday'), GETPOSTINT('search_birthday_dtendyear'));
1313 }
1314 $socialnetworks = getArrayOfSocialNetworks();
1315
1316 $searchAddressPhoneDBFields = array(
1317 //Address
1318 't.address',
1319 't.zip',
1320 't.town',
1321
1322 //Phone
1323 't.phone',
1324 't.phone_perso',
1325 't.phone_mobile',
1326
1327 //Fax
1328 't.fax',
1329
1330 //E-mail
1331 't.email',
1332 );
1333 //Social media
1334 // foreach ($socialnetworks as $key => $value) {
1335 // if ($value['active']) {
1336 // $searchAddressPhoneDBFields['t.'.$key] = "t.socialnetworks->'$.".$key."'";
1337 // }
1338 // }
1339
1340 if (!$sortorder) {
1341 $sortorder = "ASC";
1342 }
1343 if (!$sortfield) {
1344 $sortfield = "t.lastname";
1345 }
1346
1347 if (isModEnabled('clicktodial')) {
1348 $user->fetch_clicktodial(); // lecture des infos de clicktodial du user
1349 }
1350
1351
1352 $contactstatic = new Contact($db);
1353
1354 $extrafields->fetch_name_optionals_label($contactstatic->table_element);
1355
1356 $contactstatic->fields = array(
1357 'rowid' => array('type' => 'integer', 'label' => "TechnicalID", 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'visible' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? 1 : 0), 'position' => 1),
1358 'name' => array('type' => 'varchar(128)', 'label' => 'Name', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'searchall' => 1),
1359 'poste' => array('type' => 'varchar(128)', 'label' => 'PostOrFunction', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 2, 'index' => 1, 'position' => 20),
1360 'address' => array('type' => 'varchar(128)', 'label' => 'Address', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 3, 'index' => 1, 'position' => 30),
1361 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => (string) ((int) !getDolGlobalBool('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'visible' => 3, 'position' => 35),
1362 'role' => array('type' => 'checkbox', 'label' => 'Role', 'enabled' => '1', 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 4, 'index' => 1, 'position' => 40),
1363 'birthday' => array('type' => 'date', 'label' => 'Birthday', 'enabled' => '1', 'visible' => -1, 'notnull' => 0, 'position' => 45),
1364 '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))),
1365 );
1366
1367 // Definition of fields for list
1368 $arrayfields = array(
1369 't.rowid' => array('label' => "TechnicalID", 'checked' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'enabled' => (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') ? '1' : '0'), 'position' => 1),
1370 't.name' => array('label' => "Name", 'checked' => '1', 'position' => 10),
1371 't.poste' => array('label' => "PostOrFunction", 'checked' => '1', 'position' => 20),
1372 '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),
1373 't.note_private' => array('label' => 'NotePrivate', 'checked' => '0', 'position' => 35),
1374 'sc.role' => array('label' => "ContactByDefaultFor", 'checked' => '1', 'position' => 40),
1375 't.birthday' => array('label' => "Birthday", 'checked' => '0', 'position' => 45),
1376 't.statut' => array('label' => "Status", 'checked' => '1', 'position' => 50, 'class' => 'center'),
1377 'u.user' => array('label' => "DolibarrLogin", 'checked' => '1', 'position' => 50, 'class' => 'center'),
1378 );
1379 // Extra fields
1380 $extrafieldsobjectkey = $contactstatic->table_element;
1381 $extrafieldsobjectprefix = 'ef.';
1382 $extrafieldspositionoffset = 1000;
1383 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
1384
1385 // Initialize array of search criteria
1386 $search = array();
1387 foreach ($arrayfields as $key => $val) {
1388 $queryName = 'search_' . substr($key, 2);
1389 if (GETPOST($queryName, 'alpha')) {
1390 $search[substr($key, 2)] = GETPOST($queryName, 'alpha');
1391 }
1392 }
1393 $search_array_options = $extrafields->getOptionalsFromPost($contactstatic->table_element, '', 'search_');
1394
1395 // Purge search criteria
1396 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
1397 $search_rowid = '';
1398 $search_status = '';
1399 $search_name = '';
1400 $search_roles = array();
1401 $search_address = '';
1402 $search_poste = '';
1403 $search_note_private = '';
1404 $search_birthday_dtstart = '';
1405 $search_birthday_dtend = '';
1406 $search = array();
1407 $search_array_options = array();
1408
1409 foreach ($contactstatic->fields as $key => $val) {
1410 $search[$key] = '';
1411 }
1412 }
1413
1414 $contactstatic->fields = dol_sort_array($contactstatic->fields, 'position');
1415 $arrayfields = dol_sort_array($arrayfields, 'position');
1416
1417 $newcardbutton = '';
1418 $parameters = array('socid' => $object->id);
1419 $reshook = $hookmanager->executeHooks('printNewCardButton', $parameters, $object);
1420 if (empty($reshook)) {
1421 if ($user->hasRight('societe', 'contact', 'creer')) {
1422 $addcontact = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
1423 $newcardbutton .= dolGetButtonTitle($addcontact, '', 'fa fa-plus-circle', DOL_URL_ROOT . '/contact/card.php?socid=' . $object->id . '&action=create&backtopage=' . urlencode($backtopage));
1424 }
1425 } else {
1426 $newcardbutton = $hookmanager->resPrint;
1427 }
1428
1429 print "\n";
1430
1431 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ContactsForCompany") : $langs->trans("ContactsAddressesForCompany"));
1432 print load_fiche_titre($title, $newcardbutton, 'contact');
1433
1434 print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '" name="formfilter">';
1435 print '<input type="hidden" name="token" value="' . newToken() . '">';
1436 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1437 print '<input type="hidden" name="socid" value="' . $object->id . '">';
1438 print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
1439 print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
1440 print '<input type="hidden" name="page" value="' . $page . '">';
1441
1442 $arrayofmassactions = array();
1443 $mode = 'view';
1444
1445 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1446 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
1447 $showuserlogin = (!empty($showuserlogin) || !empty($arrayfields['u.user']['checked'])) ? 1 : 0;
1448 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1449 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1450
1451 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1452 print "\n" . '<table class="tagtable liste noborder">' . "\n";
1453
1454 $param = "socid=" . urlencode((string) ($object->id));
1455 if ($search_rowid != '') {
1456 $param .= '&search_rowid=' . urlencode((string) ($search_rowid));
1457 }
1458 if ($search_status != '') {
1459 $param .= '&search_status=' . urlencode((string) ($search_status));
1460 }
1461 if (count($search_roles) > 0) {
1462 $param .= implode('&search_roles[]=', $search_roles);
1463 }
1464 if ($search_name != '') {
1465 $param .= '&search_name=' . urlencode($search_name);
1466 }
1467 if ($search_poste != '') {
1468 $param .= '&search_poste=' . urlencode($search_poste);
1469 }
1470 if ($search_address != '') {
1471 $param .= '&search_address=' . urlencode($search_address);
1472 }
1473 if ($search_note_private != '') {
1474 $param .= '&search_note_private=' . urlencode($search_note_private);
1475 }
1476 if ($search_birthday_dtstart != '') {
1477 $param .= '&search_birthday_dtstart=' . urlencode((string) $search_birthday_dtstart);
1478 }
1479 if ($search_birthday_dtend != '') {
1480 $param .= '&search_birthday_dtend=' . urlencode((string) $search_birthday_dtend);
1481 }
1482 if ($optioncss != '') {
1483 $param .= '&optioncss=' . urlencode($optioncss);
1484 }
1485
1486 // Add $param from extra fields
1487 $extrafieldsobjectkey = $contactstatic->table_element;
1488 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
1489
1490 $sql = "SELECT t.rowid, t.entity, t.lastname, t.firstname, t.fk_pays as country_id, t.civility, t.poste,";
1491 $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,";
1492 $sql .= " t.civility as civility_id, t.address, t.zip, t.town, t.birthday,";
1493 $sql .= " t.note_private";
1494 $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as t";
1495 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople_extrafields as ef on (t.rowid = ef.fk_object)";
1496 $sql .= " WHERE t.fk_soc = " . ((int) $object->id);
1497 $sql .= " AND t.entity IN (" . getEntity('socpeople') . ")";
1498 $sql .= " AND ((t.fk_user_creat = " . ((int) $user->id) . " AND t.priv = 1) OR t.priv = 0)";
1499 if ($search_rowid) {
1500 $sql .= natural_search('t.rowid', $search_rowid);
1501 }
1502 if ($search_status != '' && $search_status != '-1') {
1503 $sql .= " AND t.statut = " . ((int) $search_status);
1504 }
1505 if ($search_name) {
1506 $sql .= natural_search(array('t.lastname', 't.firstname'), $search_name);
1507 }
1508 if ($search_poste) {
1509 $sql .= natural_search('t.poste', $search_poste);
1510 }
1511 if ($search_address) {
1512 $sql .= natural_search($searchAddressPhoneDBFields, $search_address);
1513 }
1514 if ($search_note_private) {
1515 $sql .= natural_search('t.note_private', $search_note_private);
1516 }
1517 if ($search_birthday_dtstart != '') {
1518 $sql .= " AND t.birthday >= '" . $db->idate($search_birthday_dtstart) . "'";
1519 }
1520 if ($search_birthday_dtend != '') {
1521 $sql .= " AND t.birthday <= '" . $db->idate($search_birthday_dtend) . "'";
1522 }
1523 if (count($search_roles) > 0) {
1524 $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)) . "))";
1525 }
1526 // Add where from extra fields
1527 $extrafieldsobjectkey = $contactstatic->table_element;
1528 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
1529 // Add where from hooks
1530 $parameters = array('socid' => $object->id);
1531 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
1532 $sql .= $hookmanager->resPrint;
1533 if ($sortfield == "t.name") {
1534 $sql .= " ORDER BY t.lastname $sortorder, t.firstname $sortorder";
1535 } else {
1536 $sql .= " ORDER BY $sortfield $sortorder";
1537 }
1538
1539 dol_syslog('core/lib/company.lib.php :: show_contacts', LOG_DEBUG);
1540 $result = $db->query($sql);
1541 if (!$result) {
1543 }
1544
1545 $num = $db->num_rows($result);
1546
1547 // Fields title search
1548 // --------------------------------------------------------------------
1549 print '<tr class="liste_titre">';
1550 // Action column
1551 if ($conf->main_checkbox_left_column) {
1552 print '<td class="liste_titre right">';
1553 print $form->showFilterButtons();
1554 print '</td>';
1555 }
1556 foreach ($contactstatic->fields as $key => $val) {
1557 $align = '';
1558 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1559 $align .= ($align ? ' ' : '') . 'center';
1560 }
1561 if (in_array($val['type'], array('timestamp'))) {
1562 $align .= ($align ? ' ' : '') . 'nowrap';
1563 }
1564 if ($key == 'status' || $key == 'statut') {
1565 $align .= ($align ? ' ' : '') . 'center';
1566 }
1567 if (!empty($arrayfields['t.' . $key]['checked']) || !empty($arrayfields['sc.' . $key]['checked'])) {
1568 print '<td class="liste_titre' . ($align ? ' ' . $align : '') . '">';
1569 if (in_array($key, array('statut'))) {
1570 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');
1571 } elseif (in_array($key, array('role'))) {
1572 print $formcompany->showRoles("search_roles", $contactstatic, 'edit', $search_roles, 'minwidth200 maxwidth300');
1573 } elseif (in_array($key, array('birthday'))) {
1574 print '<div class="nowrap">';
1575 print $form->selectDate($search_birthday_dtstart ? $search_birthday_dtstart : '', "search_birthday_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1576 print '</div>';
1577 print '<div class="nowrap">';
1578 print $form->selectDate($search_birthday_dtend ? $search_birthday_dtend : '', "search_birthday_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1579 print '</div>';
1580 } else {
1581 print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . (!empty($search[$key]) ? dol_escape_htmltag($search[$key]) : '') . '">';
1582 }
1583 print '</td>';
1584 }
1585 }
1586 if ($showuserlogin) {
1587 print '<td class="liste_titre"></td>';
1588 }
1589 // Extra fields
1590 $extrafieldsobjectkey = $contactstatic->table_element;
1591 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
1592
1593 // Fields from hook
1594 $parameters = array('arrayfields' => $arrayfields);
1595 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $contactstatic); // Note that $action and $object may have been modified by hook
1596 print $hookmanager->resPrint;
1597 // Action column
1598 if (!$conf->main_checkbox_left_column) {
1599 print '<td class="liste_titre right">';
1600 print $form->showFilterButtons();
1601 print '</td>';
1602 }
1603 print '</tr>' . "\n";
1604
1605
1606 // Fields title label
1607 // --------------------------------------------------------------------
1608 print '<tr class="liste_titre">';
1609 // Action column
1610 if ($conf->main_checkbox_left_column) {
1611 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1612 }
1613 foreach ($contactstatic->fields as $key => $val) {
1614 $align = '';
1615 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1616 $align .= ($align ? ' ' : '') . 'center';
1617 }
1618 if (in_array($val['type'], array('timestamp'))) {
1619 $align .= ($align ? ' ' : '') . 'nowrap';
1620 }
1621 if ($key == 'status' || $key == 'statut') {
1622 $align .= ($align ? ' ' : '') . 'center';
1623 }
1624 if (!empty($arrayfields['t.' . $key]['checked'])) {
1625 print getTitleFieldOfList($val['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1626 }
1627 if ($key == 'role') {
1628 $align .= ($align ? ' ' : '') . 'left';
1629 }
1630 if (!empty($arrayfields['sc.' . $key]['checked'])) {
1631 print getTitleFieldOfList($arrayfields['sc.' . $key]['label'], 0, $_SERVER['PHP_SELF'], '', '', $param, ($align ? 'class="' . $align . '"' : ''), $sortfield, $sortorder, $align . ' ') . "\n";
1632 }
1633 }
1634 if ($showuserlogin) {
1635 print '<th class="wrapcolumntitle liste_titre">' . $langs->trans("DolibarrLogin") . '</th>';
1636 }
1637 // Extra fields
1638 $extrafieldsobjectkey = $contactstatic->table_element;
1639 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
1640 // Hook fields
1641 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1642 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
1643 print $hookmanager->resPrint;
1644 // Action column
1645 if (!$conf->main_checkbox_left_column) {
1646 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ') . "\n";
1647 }
1648 print '</tr>' . "\n";
1649
1650 $i = -1;
1651
1652 if ($num || (GETPOST('button_search') || GETPOST('button_search.x') || GETPOST('button_search_x'))) {
1653 $i = 0;
1654
1655 while ($i < $num) {
1656 $obj = $db->fetch_object($result);
1657
1658 $contactstatic->id = $obj->rowid;
1659 $contactstatic->ref = $obj->rowid;
1660 $contactstatic->status = $obj->statut;
1661 $contactstatic->statut = $obj->statut;
1662 $contactstatic->lastname = $obj->lastname;
1663 $contactstatic->firstname = $obj->firstname;
1664 $contactstatic->civility_id = $obj->civility_id;
1665 $contactstatic->civility_code = $obj->civility_id;
1666 $contactstatic->poste = $obj->poste;
1667 $contactstatic->address = $obj->address;
1668 $contactstatic->zip = $obj->zip;
1669 $contactstatic->town = $obj->town;
1670 $contactstatic->phone_pro = $obj->phone_pro;
1671 $contactstatic->phone_mobile = $obj->phone_mobile;
1672 $contactstatic->phone_perso = $obj->phone_perso;
1673 $contactstatic->email = $obj->email;
1674 $contactstatic->socialnetworks = $obj->socialnetworks;
1675 $contactstatic->photo = $obj->photo;
1676 $contactstatic->fk_soc = $obj->fk_soc;
1677 $contactstatic->entity = $obj->entity;
1678
1679 $country_code = getCountry($obj->country_id, '2');
1680 $contactstatic->country_code = $country_code;
1681
1682 $contactstatic->setGenderFromCivility();
1683 $contactstatic->fetch_optionals();
1684
1685 $resultRole = $contactstatic->fetchRoles();
1686 if ($resultRole < 0) {
1687 setEventMessages(null, $contactstatic->errors, 'errors');
1688 }
1689
1690 if (is_array($contactstatic->array_options)) {
1691 foreach ($contactstatic->array_options as $key => $val) {
1692 $obj->$key = $val;
1693 }
1694 }
1695
1696 print '<tr class="oddeven">';
1697
1698 // Actions
1699 if ($conf->main_checkbox_left_column) {
1700 print '<td class="nowrap center">';
1701
1702 // Add to agenda
1703 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1704 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1705 print img_object($langs->trans("Event"), "action");
1706 print '</a> &nbsp; ';
1707 }
1708
1709 // Edit
1710 if ($user->hasRight('societe', 'contact', 'creer')) {
1711 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1712 print img_edit();
1713 print '</a>';
1714 }
1715
1716 // Delete
1717 if ($user->hasRight('societe', 'contact', 'delete')) {
1718 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) . '">';
1719 print img_delete();
1720 print '</a>';
1721 }
1722
1723 print '</td>';
1724 }
1725
1726 // ID
1727 if (!empty($arrayfields['t.rowid']['checked'])) {
1728 print '<td>';
1729 print $contactstatic->id;
1730 print '</td>';
1731 }
1732
1733 // Photo - Name
1734 if (!empty($arrayfields['t.name']['checked'])) {
1735 print '<td class="tdoverflowmax150">';
1736 print $form->showphoto('contact', $contactstatic, 0, 0, 0, 'photorefnoborder valignmiddle marginrightonly', 'small', 1, 0, 'user');
1737 print $contactstatic->getNomUrl(0, '', 0, '&backtopage=' . urlencode($backtopage));
1738 print '</td>';
1739 }
1740
1741 // Job position
1742 if (!empty($arrayfields['t.poste']['checked'])) {
1743 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->poste) . '">';
1744 if ($obj->poste) {
1745 print dol_escape_htmltag($obj->poste);
1746 }
1747 print '</td>';
1748 }
1749
1750 // Address - Phone - Email
1751 if (!empty($arrayfields['t.address']['checked'])) {
1752 $addresstoshow = $contactstatic->getBannerAddress('contact', $object);
1753 print '<td class="tdoverflowmax150 classfortooltip" title="'.dolPrintHTMLForAttribute($addresstoshow).'">';
1754 print $addresstoshow;
1755 print '</td>';
1756 }
1757
1758 // Note private
1759 if (!empty($arrayfields['t.note_private']['checked'])) {
1760 print '<td class="center">';
1761 print dolPrintHTML($obj->note_private);
1762 print '</td>';
1763 }
1764
1765 // Role
1766 if (!empty($arrayfields['sc.role']['checked'])) {
1767 print '<td class="tdoverflowmax150">';
1768 print $formcompany->showRoles("roles", $contactstatic, 'view');
1769 print '</td>';
1770 }
1771
1772 // Birthday
1773 if (!empty($arrayfields['t.birthday']['checked'])) {
1774 print '<td class="nowraponall">';
1775 print dol_print_date($db->jdate($obj->birthday));
1776 print '</td>';
1777 }
1778
1779 // Status
1780 if (!empty($arrayfields['t.statut']['checked'])) {
1781 print '<td class="center">' . $contactstatic->getLibStatut(5) . '</td>';
1782 }
1783
1784 if ($showuserlogin) {
1785 print '<td class="tdoverflowmax125">';
1786 $tmpuser = new User($db);
1787 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1788 $resfetch = $tmpuser->fetch(0, '', '', 0, -1, '', $contactstatic->id);
1789 if ($resfetch > 0) {
1790 print $tmpuser->getNomUrl(-1, '', 0, 0, 24, 1);
1791 }
1792 print '</td>';
1793 }
1794
1795 // Extra fields
1796 $extrafieldsobjectkey = $contactstatic->table_element;
1797 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
1798
1799 // Actions
1800 if (!$conf->main_checkbox_left_column) {
1801 print '<td class="nowrap center">';
1802
1803 // Add to agenda
1804 if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'create')) {
1805 print '<a href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&actioncode=&contactid=' . $obj->rowid . '&socid=' . $object->id . '&backtopage=' . urlencode($backtopage) . '">';
1806 print img_object($langs->trans("Event"), "action");
1807 print '</a> &nbsp; ';
1808 }
1809
1810 // Edit
1811 if ($user->hasRight('societe', 'contact', 'creer')) {
1812 print '<a class="editfielda paddingleft" href="' . DOL_URL_ROOT . '/contact/card.php?action=edit&token=' . newToken() . '&id=' . $obj->rowid . '&backtopage=' . urlencode($backtopage) . '">';
1813 print img_edit();
1814 print '</a>';
1815 }
1816
1817 // Delete
1818 if ($user->hasRight('societe', 'contact', 'delete')) {
1819 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) . '">';
1820 print img_delete();
1821 print '</a>';
1822 }
1823
1824 print '</td>';
1825 }
1826
1827 print "</tr>\n";
1828 $i++;
1829 }
1830
1831 if ($num == 0) {
1832 $colspan = 1 + ($showuserlogin ? 1 : 0);
1833 foreach ($arrayfields as $key => $val) {
1834 if (!empty($val['checked'])) {
1835 $colspan++;
1836 }
1837 }
1838 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
1839 }
1840 } else {
1841 $colspan = 1 + ($showuserlogin ? 1 : 0);
1842 foreach ($arrayfields as $key => $val) {
1843 if (!empty($val['checked'])) {
1844 $colspan++;
1845 }
1846 }
1847 print '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>';
1848 }
1849 print "\n</table>\n";
1850 print '</div>';
1851
1852 print '</form>' . "\n";
1853
1854 return $i;
1855}
1856
1857
1870function show_actions_todo($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '')
1871{
1872 $out = show_actions_done($conf, $langs, $db, $filterobj, $objcon, 1, $actioncode, 'todo');
1873
1874 if ($noprint) {
1875 return $out;
1876 } else {
1877 print $out;
1878 return null;
1879 }
1880}
1881
1900function show_actions_done($conf, $langs, $db, $filterobj, $objcon = null, $noprint = 0, $actioncode = '', $donetodo = 'done', $filters = array(), $sortfield = 'a.datep,a.id', $sortorder = 'DESC', $module = '')
1901{
1902 global $hookmanager, $user;
1903 global $form;
1904
1905 global $param, $massactionbutton;
1906
1907 $start_year = GETPOSTINT('dateevent_startyear');
1908 $start_month = GETPOSTINT('dateevent_startmonth');
1909 $start_day = GETPOSTINT('dateevent_startday');
1910 $end_year = GETPOSTINT('dateevent_endyear');
1911 $end_month = GETPOSTINT('dateevent_endmonth');
1912 $end_day = GETPOSTINT('dateevent_endday');
1913 $tms_start = '';
1914 $tms_end = '';
1915
1916 if (!empty($start_year) && !empty($start_month) && !empty($start_day)) {
1917 $tms_start = dol_mktime(0, 0, 0, $start_month, $start_day, $start_year, 'tzuserrel');
1918 }
1919 if (!empty($end_year) && !empty($end_month) && !empty($end_day)) {
1920 $tms_end = dol_mktime(23, 59, 59, $end_month, $end_day, $end_year, 'tzuserrel');
1921 }
1922 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
1923 $tms_start = '';
1924 $tms_end = '';
1925 }
1926 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
1927
1928 // Check parameters
1929 if (!is_object($filterobj) && !is_object($objcon)) {
1930 dol_print_error(null, 'BadParameter');
1931 }
1932
1933 $out = '';
1934 $histo = array();
1935 $numaction = 0;
1936 $now = dol_now('tzuser');
1937
1938 // Open DSI -- Fix order by -- Begin
1939 $sortfield_list = explode(',', $sortfield);
1940 $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent');
1941 $sortfield_new_list = array();
1942 foreach ($sortfield_list as $sortfield_value) {
1943 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
1944 }
1945 $sortfield_new = implode(',', $sortfield_new_list);
1946
1947 $complete = (string) (!empty($filters['search_complete']) ? $filters['search_complete'] : ''); // Can be 'na', '0', '50', '100'
1948 $percent = $complete !== '' ? $complete : -1;
1949 if ((string) $complete == '0') {
1950 $percent = '0';
1951 } elseif ((int) $complete == 100) {
1952 $percent = '100';
1953 }
1954
1955 $sql = '';
1956
1957 if (isModEnabled('agenda')) {
1958 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
1959 $hookmanager->initHooks(array('agendadao'));
1960
1961 $sql = "SELECT a.id, a.label as label,";
1962 $sql .= " a.datep as dp,";
1963 $sql .= " a.datep2 as dp2,";
1964 $sql .= " a.percent as percent, 'action' as type,";
1965 $sql .= " a.fk_element, a.elementtype,";
1966 $sql .= " a.fk_contact,";
1967 $sql .= " a.code, a.fulldayevent,";
1968 $sql .= " c.code as acode, c.libelle as alabel, c.picto as apicto,";
1969 $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";
1970 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
1971 $sql .= ", sp.lastname, sp.firstname";
1972 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
1973 /* Nothing */
1974 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
1975 /* Nothing */
1976 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
1977 $sql .= ", m.lastname, m.firstname";
1978 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
1979 $sql .= ", o.ref";
1980 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
1981 $sql .= ", o.ref";
1982 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
1983 $sql .= ", o.ref";
1984 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
1985 $sql .= ", o.ref";
1986 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
1987 $sql .= ", o.ref";
1988 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
1989 $sql .= ", s.ref";
1990 } elseif (is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid']) && $filterobj->table_element && $filterobj->element) {
1991 if (!empty($filterobj->fields['ref'])) {
1992 $sql .= ", o.ref";
1993 } elseif (!empty($filterobj->fields['label'])) {
1994 $sql .= ", o.label";
1995 }
1996 }
1997
1998 $canedit = 1;
1999 if (!$user->hasRight('agenda', 'myactions', 'read')) {
2000 $canedit = 0;
2001 }
2002 if (!$user->hasRight('agenda', 'allactions', 'read')) {
2003 $canedit = 0;
2004 }
2005 if (!$user->hasRight('agenda', 'allactions', 'read')) { // If no permission to see all, we show only affected to me
2006 $filters['search_filtert'] = (string) $user->id;
2007 }
2008
2009 // Fields from hook
2010 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
2011 $reshook = $hookmanager->executeHooks('showActionsDoneListSelect', $parameters); // Note that $action and $object may have been modified by hook
2012 if (!empty($hookmanager->resPrint)) {
2013 $sql .= $hookmanager->resPrint;
2014 }
2015
2016 $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
2017 // Link to the owner of action
2018 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_action";
2019 // Link to action types
2020 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_actioncomm as c ON a.fk_action = c.id";
2021
2022 // Set $force_filter_contact:
2023 // - true for a filter on a user or a contact, so a link on table llx_actioncomm_resources or llx_actioncomm.fk_user_action
2024 // - false for a link on table llx_element_resources
2025 $force_filter_contact = false;
2026 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
2027 $force_filter_contact = true;
2028 }
2029 if (is_object($objcon) && $objcon->id > 0) {
2030 $force_filter_contact = true;
2031 }
2032
2033 // Fields from hook
2034 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon);
2035 $reshook = $hookmanager->executeHooks('showActionsDoneListFrom', $parameters); // Note that $action and $object may have been modified by hook
2036 if (!empty($hookmanager->resPrint)) {
2037 $sql .= $hookmanager->resPrint;
2038 }
2039 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur'))) {
2040 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON a.fk_contact = sp.rowid";
2041 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
2042 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "element_resources as er";
2043 $sql .= " ON er.resource_type = 'dolresource'";
2044 $sql .= " AND er.element_type = 'action'";
2045 $sql .= " AND er.element_id = a.id";
2046 $sql .= " AND er.resource_id = " . ((int) $filterobj->id);
2047 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project') {
2048 /* Nothing */
2049 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2050 $sql .= ", " . MAIN_DB_PREFIX . "adherent as m";
2051 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2052 $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as o";
2053 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2054 $sql .= ", " . MAIN_DB_PREFIX . "product as o";
2055 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2056 $sql .= ", " . MAIN_DB_PREFIX . "ticket as o";
2057 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
2058 $sql .= ", " . MAIN_DB_PREFIX . "bom_bom as o";
2059 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
2060 $sql .= ", " . MAIN_DB_PREFIX . "contrat as o";
2061 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
2062 $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
2063 } elseif (is_object($filterobj) && get_class($filterobj) == 'Propal') {
2064 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "propal as o ON a.fk_element = o.rowid AND a.elementtype = 'propal'";
2065 } elseif (
2066 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2067 && ((!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
2068 && $filterobj->table_element && $filterobj->element
2069 ) {
2070 $sql .= ", " . MAIN_DB_PREFIX . $filterobj->table_element . " as o";
2071 }
2072
2073 $sql .= " WHERE a.entity IN (" . getEntity('agenda') . ")";
2074 if (!$force_filter_contact) {
2075 if (is_object($filterobj) && in_array(get_class($filterobj), array('Societe', 'Client', 'Fournisseur')) && $filterobj->id) {
2076 $sql .= " AND a.fk_soc = " . ((int) $filterobj->id);
2077 } elseif (is_object($filterobj) && get_class($filterobj) == 'Dolresource') {
2078 /* Nothing */
2079 } elseif (is_object($filterobj) && get_class($filterobj) == 'Project' && $filterobj->id) {
2080 $sql .= " AND a.fk_project = " . ((int) $filterobj->id);
2081 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2082 $sql .= " AND a.fk_element = m.rowid AND a.elementtype = 'member'";
2083 if ($filterobj->id) {
2084 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2085 }
2086 } elseif (is_object($filterobj) && get_class($filterobj) == 'Commande') {
2087 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order'";
2088 if ($filterobj->id) {
2089 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2090 }
2091 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2092 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
2093 if ($filterobj->id) {
2094 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2095 }
2096 } elseif (is_object($filterobj) && get_class($filterobj) == 'Facture') {
2097 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice'";
2098 if ($filterobj->id) {
2099 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2100 }
2101 } elseif (is_object($filterobj) && get_class($filterobj) == 'FactureFournisseur') {
2102 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'invoice_supplier'";
2103 if ($filterobj->id) {
2104 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2105 }
2106 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2107 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'product'";
2108 if ($filterobj->id) {
2109 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2110 }
2111 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2112 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
2113 if ($filterobj->id) {
2114 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2115 }
2116 } elseif (is_object($filterobj) && get_class($filterobj) == 'BOM') {
2117 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
2118 if ($filterobj->id) {
2119 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2120 }
2121 } elseif (is_object($filterobj) && get_class($filterobj) == 'Contrat') {
2122 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
2123 if ($filterobj->id) {
2124 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2125 }
2126 } elseif (is_object($filterobj) && get_class($filterobj) == 'Expedition') {
2127 $sql .= " AND a.fk_element = s.rowid AND a.elementtype = 'shipping'"; // shipping filter
2128 if ($filterobj->id) {
2129 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2130 }
2131 } elseif (
2132 is_object($filterobj) && is_array($filterobj->fields) && is_array($filterobj->fields['rowid'])
2133 && ((!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
2134 && $filterobj->table_element && $filterobj->element
2135 ) {
2136 // Generic case (if there is a $filterobj and a field rowid and (ref or label) exists.
2137 $sql .= " AND a.fk_element = o.rowid AND a.elementtype = '" . $db->escape($filterobj->element. ($module ? "@" . $module : "")) . "'";
2138 if ($filterobj->id) {
2139 $sql .= " AND a.fk_element = " . ((int) $filterobj->id);
2140 }
2141 } elseif (is_object($filterobj)) {
2142 return 'Bad value for $filterobj';
2143 }
2144 } else {
2145 if (is_object($filterobj) && $filterobj->id > 0 && get_class($filterobj) == 'User') {
2146 $sql .= " AND (u.rowid = " . ((int) $filterobj->id) . ' OR ';
2147 $sql .= " EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2148 $sql .= " AND r.element_type = '" . $db->escape($filterobj->table_element) . "' AND r.fk_element = " . ((int) $filterobj->id) . ')';
2149 $sql .= ")";
2150 }
2151 if (is_object($objcon) && $objcon->id > 0) {
2152 $sql .= " AND EXISTS (SELECT r.rowid FROM " . MAIN_DB_PREFIX . "actioncomm_resources as r WHERE a.id = r.fk_actioncomm";
2153 $sql .= " AND r.element_type = '" . $db->escape($objcon->table_element) . "' AND r.fk_element = " . ((int) $objcon->id) . ')';
2154 }
2155 }
2156
2157 if (!empty($tms_start) && !empty($tms_end)) {
2158 $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) . "'))";
2159 } elseif (empty($tms_start) && !empty($tms_end)) {
2160 $sql .= " AND ((a.datep <= '" . $db->idate($tms_end) . "') OR (a.datep2 <= '" . $db->idate($tms_end) . "'))";
2161 } elseif (!empty($tms_start) && empty($tms_end)) {
2162 $sql .= " AND ((a.datep >= '" . $db->idate($tms_start) . "') OR (a.datep2 >= '" . $db->idate($tms_start) . "'))";
2163 }
2164
2165 if (is_array($actioncode) && !empty($actioncode)) {
2166 $tmpsql = '';
2167
2168 foreach ($actioncode as $key => $code) {
2169 if ((string) $code === '-1' || (string) $code === '') {
2170 continue;
2171 }
2172 if ($key != 0) {
2173 $tmpsql .= " OR ";
2174 }
2175 if (!empty($code)) {
2176 addEventTypeSQL($tmpsql, $code, "");
2177 }
2178 }
2179 if ($tmpsql) {
2180 $sql .= ' AND (';
2181 $sql .= $tmpsql;
2182 $sql .= ')';
2183 }
2184 } elseif (!empty($actioncode) && $actioncode != '-1') {
2185 addEventTypeSQL($sql, $actioncode);
2186 }
2187
2188 addOtherFilterSQL($sql, $donetodo, $now, $filters);
2189
2190 // Fields from hook
2191 $parameters = array('sql' => &$sql, 'filterobj' => $filterobj, 'objcon' => $objcon, 'module' => $module);
2192 $reshook = $hookmanager->executeHooks('showActionsDoneListWhere', $parameters); // Note that $action and $object may have been modified by hook
2193 if (!empty($hookmanager->resPrint)) {
2194 $sql .= $hookmanager->resPrint;
2195 }
2196
2197 // Now add events of emailing module
2198 if (is_array($actioncode) && $objcon !== null) {
2199 foreach ($actioncode as $code) {
2200 $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj);
2201 if (!empty($sql2)) {
2202 if (!empty($sql)) {
2203 $sql = $sql . " UNION " . $sql2;
2204 } elseif (empty($sql)) {
2205 $sql = $sql2;
2206 }
2207 break;
2208 }
2209 }
2210 } elseif ($objcon !== null) {
2211 $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj);
2212 if (!empty($sql) && !empty($sql2)) {
2213 $sql = $sql . " UNION " . $sql2;
2214 } elseif (empty($sql) && !empty($sql2)) {
2215 $sql = $sql2;
2216 }
2217 }
2218 }
2219
2220 $MAXWITHOUTPAGINATION = getDolGlobalInt('AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
2221 $num = 0;
2222
2223 if ($sql) {
2224 // TODO Add navigation with this limits by replacing call of show_actions_done by the code found into comm/action/list.php...
2225 $offset = 0;
2226 $limit = $MAXWITHOUTPAGINATION;
2227
2228 // Complete request and execute it with limit
2229 $sql .= $db->order($sortfield_new, $sortorder); // @phan-suppress-current-line SqlInjection
2230 if ($limit) { // @phpstan-ignore-line
2231 $sql .= $db->plimit($limit + 1, $offset);
2232 }
2233
2234 dol_syslog("company.lib::show_actions_done", LOG_DEBUG);
2235
2236 $resql = $db->query($sql);
2237 if ($resql) {
2238 $i = 0;
2239 $num = $db->num_rows($resql);
2240
2241 $imaxinloop = ($limit ? min($num, $limit) : $num);
2242 while ($i < $imaxinloop) {
2243 $obj = $db->fetch_object($resql);
2244 if (empty($obj)) {
2245 break;
2246 }
2247
2248 if ($obj->type == 'action') {
2249 $contactaction = new ActionComm($db);
2250 $contactaction->id = $obj->id;
2251 $result = $contactaction->fetchResources();
2252 if ($result < 0) {
2254 setEventMessage("company.lib::show_actions_done Error fetch resource", 'errors');
2255 }
2256
2257 //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))";
2258 //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))";
2259 $tododone = '';
2260 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && (!empty($obj->datep) && $obj->datep > $now))) {
2261 $tododone = 'todo';
2262 }
2263
2264 $histo[$numaction] = array(
2265 'type' => $obj->type,
2266 'tododone' => $tododone,
2267 'id' => (int) $obj->id,
2268 'datestart' => $db->jdate($obj->dp),
2269 'dateend' => $db->jdate($obj->dp2),
2270 'fulldayevent' => (int) $obj->fulldayevent,
2271 'note' => $obj->label,
2272 'percent' => (int) $obj->percent,
2273
2274 'userid' => (int) $obj->user_id,
2275 'login' => $obj->user_login,
2276 'userfirstname' => $obj->user_firstname,
2277 'userlastname' => $obj->user_lastname,
2278 'userphoto' => $obj->user_photo,
2279
2280 'contact_id' => (int) $obj->fk_contact,
2281 'socpeopleassigned' => $contactaction->socpeopleassigned,
2282 'lastname' => empty($obj->lastname) ? '' : $obj->lastname,
2283 'firstname' => empty($obj->firstname) ? '' : $obj->firstname,
2284 'fk_element' => (int) $obj->fk_element,
2285 'elementtype' => $obj->elementtype,
2286
2287 'code' => $obj->code,
2288
2289 // Type of event
2290 'acode' => $obj->acode,
2291 'alabel' => $obj->alabel,
2292 'libelle' => $obj->alabel, // deprecated
2293 'apicto' => $obj->apicto
2294 );
2295 } else {
2296 $histo[$numaction] = array(
2297 'type' => $obj->type,
2298 'tododone' => 'done',
2299 'id' => (int) $obj->id,
2300 'datestart' => $db->jdate($obj->dp),
2301 'dateend' => $db->jdate($obj->dp2),
2302 'fulldayevent' => (int) $obj->fulldayevent,
2303 'note' => $obj->label,
2304 'percent' => (int) $obj->percent,
2305
2306 'code' => $obj->code,
2307
2308 // Type of event
2309 'acode' => $obj->acode,
2310
2311 'userid' => (int) $obj->user_id,
2312 'login' => $obj->user_login,
2313 'userfirstname' => $obj->user_firstname,
2314 'userlastname' => $obj->user_lastname,
2315 'userphoto' => $obj->user_photo
2316 );
2317 }
2318
2319 $numaction++;
2320 $i++;
2321 }
2322 } else {
2324 }
2325 }
2326
2327 '@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';
2328
2329 if (isModEnabled('agenda') || (isModEnabled('mailing') && !empty($objcon->email))) {
2330 $delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
2331
2332 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
2333 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
2334 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2335 require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2336
2337 $formactions = new FormActions($db);
2338
2339 $actionstatic = new ActionComm($db);
2340 $userstatic = new User($db);
2341 $userlinkcache = array();
2342 $contactstatic = new Contact($db);
2343 $elementlinkcache = array();
2344
2345 $out .= '<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
2346 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
2347 if (
2348 $objcon && get_class($objcon) == 'Contact' &&
2349 (is_null($filterobj) || get_class($filterobj) == 'Societe')
2350 ) {
2351 $out .= '<input type="hidden" name="id" value="' . $objcon->id . '" />';
2352 } else {
2353 $out .= '<input type="hidden" name="id" value="' . $filterobj->id . '" />';
2354 }
2355 if ($filterobj && get_class($filterobj) == 'Societe') {
2356 $out .= '<input type="hidden" name="socid" value="' . $filterobj->id . '" />';
2357 } else {
2358 $out .= '<input type="hidden" name="userid" value="' . $filterobj->id . '" />';
2359 }
2360
2361 $out .= "\n";
2362
2363 $out .= '<div class="div-table-responsive-no-min">';
2364 $out .= '<table class="noborder centpercent">';
2365
2366 $out .= '<tr class="liste_titre_filter">';
2367
2368 // Action column
2369 if ($conf->main_checkbox_left_column) {
2370 $out .= '<th class="liste_titre width50 middle">';
2371 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2372 $out .= $searchpicto;
2373 $out .= '</th>';
2374 }
2375
2376 if ($donetodo) {
2377 $out .= '<td class="liste_titre"></td>';
2378 }
2379
2380 // ID
2381 $out .= '<td class="liste_titre"><input type="text" class="width50" name="search_rowid" value="' . (isset($filters['search_rowid']) ? $filters['search_rowid'] : '') . '"></td>';
2382 // Date
2383 $out .= '<td class="liste_titre center">';
2384 $out .= $form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1);
2385 $out .= '</td>';
2386 // Owner
2387 $out .= '<td class="liste_titre">';
2388 $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');
2389 $out .= '</td>';
2390 // Type
2391 $out .= '<td class="liste_titre">';
2392 $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);
2393 $out .= '</td>';
2394 // Label - Title
2395 $out .= '<td class="liste_titre maxwidth100onsmartphone"><input type="text" class="maxwidth200" name="search_agenda_label" value="' . $filters['search_agenda_label'] . '"></td>';
2396 $out .= '<td class="liste_titre"></td>';
2397 $out .= '<td class="liste_titre"></td>';
2398 // Status ($percent can be 'na'or < 100 or 100)
2399 $out .= '<td class="liste_titre parentonrightofpage">';
2400 $out .= $formactions->form_select_status_action('formaction', $percent, 1, 'search_complete', 1, 2, 'search_status width100 onrightofpage', 1);
2401 $out .= '</td>';
2402 // Action column
2403 if (!$conf->main_checkbox_left_column) {
2404 $out .= '<td class="liste_titre" align="middle">';
2405 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
2406 $out .= $searchpicto;
2407 $out .= '</td>';
2408 }
2409 $out .= '</tr>';
2410
2411 $out .= '<tr class="liste_titre">';
2412 // Action column
2413 if ($conf->main_checkbox_left_column) {
2414 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2415 }
2416 if ($donetodo && $filterobj !== null) {
2417 $tmp = '';
2418 if (get_class($filterobj) == 'Societe') {
2419 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&socid=' . $filterobj->id . '&status=done">';
2420 }
2421 if (get_class($filterobj) == 'User') {
2422 $tmp .= '<a href="' . DOL_URL_ROOT . '/comm/action/list.php?mode=show_list&userid=' . $filterobj->id . '&status=done">';
2423 }
2424 $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
2425 $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
2426 $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
2427 //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
2428 if (get_class($filterobj) == 'Societe') {
2429 $tmp .= '</a>';
2430 }
2431 if (get_class($filterobj) == 'User') {
2432 $tmp .= '</a>';
2433 }
2434 $out .= getTitleFieldOfList($tmp);
2435 }
2436 $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder);
2437 $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center ');
2438 $out .= getTitleFieldOfList("Owner");
2439 $out .= getTitleFieldOfList("Type");
2440 $out .= getTitleFieldOfList("Title", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2441 $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0);
2442 $out .= getTitleFieldOfList("LinkedObject", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder);
2443 $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center ');
2444 // Action column
2445 if (!$conf->main_checkbox_left_column) {
2446 $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch ');
2447 }
2448 $out .= '</tr>';
2449
2450 require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php';
2451 $caction = new CActionComm($db);
2452 $arraylist = $caction->liste_array(1, 'code', '', (getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 0 : 1), '', 1);
2453
2454 foreach ($histo as $key => $value) {
2455 $actionstatic->fetch($histo[$key]['id']); // TODO Do we need this, we already have a lot of data of line into $histo
2456
2457 if (empty($actionstatic->code)) {
2458 $actionstatic->code = $histo[$key]['acode'];
2459 }
2460 $actionstatic->type_picto = $histo[$key]['apicto'] ?? '';
2461 $actionstatic->type_code = $histo[$key]['acode'];
2462
2463 $out .= '<tr class="oddeven">';
2464
2465 // Action column
2466 if ($conf->main_checkbox_left_column) {
2467 $out .= '<td></td>';
2468 }
2469
2470 // Done or todo
2471 if ($donetodo) {
2472 $out .= '<td class="nowrap">';
2473 $out .= '</td>';
2474 }
2475
2476 // Ref
2477 $out .= '<td class="nowraponall">';
2478 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2479 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '">' . img_object($langs->trans("ShowEMailing"), "email") . ' ';
2480 $out .= $histo[$key]['id'];
2481 $out .= '</a>';
2482 } else {
2483 $out .= $actionstatic->getNomUrl(1, -1);
2484 }
2485 $out .= '</td>';
2486
2487 // Date
2488 $out .= '<td class="center nowraponall nopaddingtopimp nopaddingbottomimp">';
2489
2490 $out .= dolOutputDates($histo[$key]['datestart'], $histo[$key]['dateend'], (int) $histo[$key]['fulldayevent'], 0, '', 'tzuserrel', 1);
2491
2492 // Add the late warning
2493 $late = 0;
2494 if ($histo[$key]['percent'] == 0 && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2495 $late = 1;
2496 }
2497 if ($histo[$key]['percent'] == 0 && !$histo[$key]['datestart'] && $histo[$key]['dateend'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2498 $late = 1;
2499 }
2500 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && $histo[$key]['dateend'] && $histo[$key]['dateend'] < ($now - $delay_warning)) {
2501 $late = 1;
2502 }
2503 if ($histo[$key]['percent'] > 0 && $histo[$key]['percent'] < 100 && !$histo[$key]['dateend'] && $histo[$key]['datestart'] && $histo[$key]['datestart'] < ($now - $delay_warning)) {
2504 $late = 1;
2505 }
2506 if ($late) {
2507 $out .= img_warning($langs->trans("Late")) . ' ';
2508 }
2509 $out .= '</td>';
2510
2511 // Author of event
2512 $out .= '<td class="tdoverflowmax125">';
2513 if ($histo[$key]['userid'] > 0) {
2514 if (isset($userlinkcache[$histo[$key]['userid']])) {
2515 $link = $userlinkcache[$histo[$key]['userid']];
2516 } else {
2517 $userstatic->fetch($histo[$key]['userid']);
2518 $link = $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', '');
2519 $userlinkcache[$histo[$key]['userid']] = $link;
2520 }
2521 $out .= $link;
2522 }
2523 $out .= '</td>';
2524
2525 // type_code // column "acode" in the sql = code in type of actioncomm, example: AC_OTH_AUTO, AC_EMAILING
2526 // code // columne code in the sql (not yet added), can be AC_CONTACT_SENTBYMAIL, ...
2527
2528 // Type
2529 $labelOfTypeToShow = $actionstatic->type_code;
2530 //$typelabel = $actionstatic->type_label;
2531 $code = $actionstatic->code;
2532 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labelOfTypeToShow])) {
2533 $labelOfTypeToShow = 'AC_OTH';
2534 }
2535 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
2536 $labelOfTypeToShow = $langs->trans("Message");
2537 } else {
2538 if (!empty($arraylist[$labelOfTypeToShow])) {
2539 $labelOfTypeToShow = $arraylist[$labelOfTypeToShow];
2540 } elseif ($actionstatic->type_code == 'AC_EMAILING') {
2541 $langs->load("mails");
2542 $labelOfTypeToShow = $langs->trans("Emailing");
2543 }
2544 if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labelOfTypeToShow && !empty($arraylist[$actionstatic->code])) {
2545 $labelOfTypeToShow .= ' - ' . $arraylist[$actionstatic->code]; // Show also detailed code
2546 }
2547 }
2548
2549 $labelOfTypeToShowLong = $labelOfTypeToShow;
2550 if ($actionstatic->type_code == 'AC_OTH_AUTO') {
2551 $labelOfTypeToShowLong .= ' (auto)';
2552 }
2553
2554 $out .= '<td class="tdoverflowmax125" title="' . $labelOfTypeToShowLong . '">';
2555 // Example $actionstatic->code = AC_COMPANY_MODIFY and $actionstatic->type_code = AC_OTH_AUTO
2556 $out .= $actionstatic->getTypePicto();
2557 $out .= $labelOfTypeToShow;
2558 if (preg_match('/PRIVATE/', $actionstatic->code)) {
2559 $out .= ' ' . img_picto($langs->trans("Private"), 'lock', 'class="valignmiddle"');
2560 }
2561 $out .= '</td>';
2562
2563 // Title/Label of event
2564 $out .= '<td class="tdoverflowmax300"';
2565 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'action') {
2566 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2567 //$libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']);
2568 $label = $histo[$key]['note'];
2569 $actionstatic->id = $histo[$key]['id'];
2570 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2571 $label = preg_replace('/^\[[^\[]*\]/', '[...]', $label);
2572 $out .= dol_trunc($label, 120);
2573 }
2574 if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') {
2575 $transcode = $langs->trans("Action" . $histo[$key]['acode']);
2576 $label = ($transcode != "Action" . $histo[$key]['acode'] ? $transcode : 'Send mass mailing');
2577 $label .= ' - ' . $histo[$key]['note'];
2578 $out .= '<a href="' . DOL_URL_ROOT . '/comm/mailing/card.php?id=' . $histo[$key]['id'] . '"';
2579 $out .= ' title="' . dol_escape_htmltag($label) . '">';
2580 $label = preg_replace('/^\[[^\[]*\]/', '[...]', $label);
2581 $out .= dol_trunc($label, 120);
2582 $out .= '</a>';
2583 }
2584 $out .= '</td>';
2585
2586 // Contact(s) for action
2587 if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) {
2588 $out .= '<td class="valignmiddle">';
2589 $contact = new Contact($db);
2590 foreach ($histo[$key]['socpeopleassigned'] as $cid => $cvalue) {
2591 $result = $contact->fetch($cid);
2592
2593 if ($result < 0) {
2594 dol_print_error($db, $contact->error);
2595 } elseif ($result > 0) {
2596 if (count($histo[$key]['socpeopleassigned']) > 1) {
2597 $out .= $contact->getNomUrl(-2, '', 0, '', -1, 0, 'paddingright');
2598 } else {
2599 $out .= $contact->getNomUrl(-3, '', 0, '', -1, 0, 'paddingright');
2600 if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') {
2601 if (!empty($contact->phone_pro)) {
2602 $out .= '(' . dol_print_phone($contact->phone_pro) . ')';
2603 }
2604 }
2605 }
2606 }
2607 }
2608 $out .= '</td>';
2609 } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) {
2610 $contactstatic->lastname = $histo[$key]['lastname'];
2611 $contactstatic->firstname = $histo[$key]['firstname'];
2612 $contactstatic->id = $histo[$key]['contact_id'];
2613 $contactstatic->photo = $histo[$key]['contact_photo'];
2614 $out .= '<td width="120">' . $contactstatic->getNomUrl(-1, '', 10) . '</td>';
2615 } else {
2616 $out .= '<td>&nbsp;</td>';
2617 }
2618
2619 // Linked object
2620 $out .= '<td class="tdoverflowmax200 nowraponall">';
2621 if (isset($histo[$key]['elementtype']) && !empty($histo[$key]['fk_element'])) {
2622 if (isset($elementlinkcache[$histo[$key]['elementtype']]) && isset($elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']])) {
2623 $link = $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']];
2624 } else {
2625 if (!isset($elementlinkcache[$histo[$key]['elementtype']])) {
2626 $elementlinkcache[$histo[$key]['elementtype']] = array();
2627 }
2628 $link = dolGetElementUrl((int) $histo[$key]['fk_element'], $histo[$key]['elementtype'], 1);
2629 $elementlinkcache[$histo[$key]['elementtype']][$histo[$key]['fk_element']] = $link;
2630 }
2631 $out .= $link;
2632 }
2633 $out .= '</td>';
2634
2635 // Status / Progression
2636 $out .= '<td class="nowrap center">';
2637 $out .= $actionstatic->LibStatut($histo[$key]['percent'], 2, 0, $histo[$key]['datestart']);
2638 $out .= '</td>';
2639
2640 // Action column
2641 if (!$conf->main_checkbox_left_column) {
2642 $out .= '<td></td>';
2643 }
2644
2645 $out .= "</tr>\n";
2646 }
2647 if (empty($histo)) {
2648 $colspan = 9;
2649 $out .= '<tr><td colspan="' . $colspan . '"><span class="opacitymedium">' . $langs->trans("NoRecordFound") . '</span></td></tr>';
2650 }
2651
2652 if ($num > $MAXWITHOUTPAGINATION) {
2653 $langs->load("errors");
2654 $colspan = 9;
2655 $out .= '<tr><td class="center" colspan="' . $colspan . '"><span class="opacitymedium">...' . $langs->trans("WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) . '...</span></td></tr>';
2656 }
2657
2658 $out .= "</table>\n";
2659 $out .= "</div>\n";
2660
2661 $out .= '</form>';
2662 }
2663
2664 if ($noprint) {
2665 return $out;
2666 } else {
2667 print $out;
2668 return null;
2669 }
2670}
2671
2682{
2683 $i = -1;
2684
2685 $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";
2686 $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
2687 $sql .= " WHERE s.parent = " . ((int) $object->id);
2688 $sql .= " AND s.entity IN (" . getEntity('societe') . ")";
2689 $sql .= " ORDER BY s.nom";
2690
2691 $result = $db->query($sql);
2692 $num = $db->num_rows($result);
2693
2694 if ($num) {
2695 $socstatic = new Societe($db);
2696
2697 print load_fiche_titre($langs->trans("Subsidiaries"), '', '');
2698
2699 print "\n" . '<div class="div-table-responsive-no-min">' . "\n";
2700 print '<table class="noborder centpercent">' . "\n";
2701
2702 print '<tr class="liste_titre"><td>' . $langs->trans("Company") . '</td>';
2703 print '<td>' . $langs->trans("Address") . '</td><td>' . $langs->trans("Zip") . '</td>';
2704 print '<td>' . $langs->trans("Town") . '</td><td>' . $langs->trans("CustomerCode") . '</td>';
2705 print "<td>&nbsp;</td>";
2706 print "</tr>";
2707
2708 $i = 0;
2709
2710 while ($i < $num) {
2711 $obj = $db->fetch_object($result);
2712
2713 $socstatic->id = $obj->rowid;
2714 $socstatic->name = $obj->name;
2715 $socstatic->name_alias = $obj->name_alias;
2716 $socstatic->email = $obj->email;
2717 $socstatic->code_client = $obj->code_client;
2718 $socstatic->code_fournisseur = $obj->code_fournisseur;
2719 $socstatic->code_compta = $obj->code_compta;
2720 $socstatic->code_compta_client = $obj->code_compta;
2721 $socstatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
2722 $socstatic->email = $obj->email;
2723 $socstatic->canvas = $obj->canvas;
2724 $socstatic->client = $obj->client;
2725 $socstatic->fournisseur = $obj->fournisseur;
2726 $socstatic->status = $obj->status;
2727
2728 print '<tr class="oddeven">';
2729
2730 print '<td class="tdoverflowmax150">';
2731 print $socstatic->getNomUrl(1);
2732 print '</td>';
2733
2734 print '<td class="tdoverflowmax400" title="' . dol_escape_htmltag($obj->address) . '">' . dol_escape_htmltag($obj->address) . '</td>';
2735 print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($obj->zip) . '">' . $obj->zip . '</td>';
2736 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->town) . '">' . $obj->town . '</td>';
2737 print '<td class="tdoverflowmax200" title="' . dol_escape_htmltag($obj->code_client) . '">' . $obj->code_client . '</td>';
2738
2739 print '<td class="center">';
2740 print '<a class="editfielda" href="' . DOL_URL_ROOT . '/societe/card.php?socid=' . ((int) $obj->rowid) . '&action=edit&token=' . newToken() . '">';
2741 print img_edit();
2742 print '</a></td>';
2743
2744 print "</tr>\n";
2745 $i++;
2746 }
2747 print "\n</table>\n";
2748 print '</div>' . "\n";
2749 }
2750
2751 print "<br>\n";
2752
2753 return $i;
2754}
2763function addEventTypeSQL(&$sql, $actioncode, $sqlANDOR = "AND")
2764{
2765 global $db;
2766
2767 // Condition on actioncode
2768
2769 if ((string) $actioncode == '-1') {
2770 return $sql;
2771 }
2772
2773 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
2774 if ($actioncode == 'AC_NON_AUTO') {
2775 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2776 } elseif ($actioncode == 'AC_ALL_AUTO') {
2777 $sql .= " $sqlANDOR c.type = 'systemauto'";
2778 } else {
2779 if ($actioncode == 'AC_OTH') {
2780 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2781 } elseif ($actioncode == 'AC_OTH_AUTO') {
2782 $sql .= " $sqlANDOR c.type = 'systemauto'";
2783 }
2784 }
2785 } else {
2786 if ($actioncode == 'AC_NON_AUTO') {
2787 $sql .= " $sqlANDOR c.type <> 'systemauto'";
2788 } elseif ($actioncode == 'AC_ALL_AUTO') {
2789 $sql .= " $sqlANDOR c.type = 'systemauto'";
2790 } else {
2791 $sql .= " $sqlANDOR c.code = '" . $db->escape($actioncode) . "'";
2792 }
2793 }
2794
2795 return $sql;
2796}
2797
2807function addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
2808{
2809 global $db;
2810
2811 if ($donetodo == 'todo') {
2812 $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" . $db->idate($now) . "'))";
2813 } elseif ($donetodo == 'done') {
2814 $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" . $db->idate($now) . "'))";
2815 }
2816 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'na') {
2817 $sql .= " AND a.percent = -1";
2818 }
2819 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '0') {
2820 $sql .= " AND a.percent = 0";
2821 }
2822 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '50') {
2823 $sql .= " AND a.percent > 0 AND a.percent < 100";
2824 }
2825 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === 'todo') {
2826 $sql .= " AND a.percent >= 0 AND a.percent < 100";
2827 }
2828 if (is_array($filters) && isset($filters['search_complete']) && $filters['search_complete'] === '100') {
2829 $sql .= " AND a.percent = 100";
2830 }
2831 if (is_array($filters) && !empty($filters['search_agenda_label'])) {
2832 $sql .= natural_search('a.label', $filters['search_agenda_label']);
2833 }
2834 if (is_array($filters) && !empty($filters['search_rowid'])) {
2835 $sql .= natural_search('a.id', $filters['search_rowid'], 1);
2836 }
2837 if (is_array($filters) && !empty($filters['search_filtert']) && ((int) $filters['search_filtert']) != -1) {
2838 $sql .= natural_search('a.fk_user_action', $filters['search_filtert'], 1);
2839 }
2840
2841 return $sql;
2842}
2843
2853function addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
2854{
2855 global $db;
2856
2857 // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing.
2858 if (isModEnabled('mailing') && !empty($objcon->email) && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) {
2859 $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";
2860 $sql2 .= ", null as fk_element, '' as elementtype, null as contact_id";
2861 $sql2 .= ", 'AC_EMAILING' as code, '0' as fulldayevent, 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
2862 $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
2863 if (is_object($filterobj) && get_class($filterobj) == 'Societe') {
2864 $sql2 .= ", '' as lastname, '' as firstname";
2865 } elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') {
2866 $sql2 .= ", '' as lastname, '' as firstname";
2867 } elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') {
2868 $sql2 .= ", '' as ref";
2869 } elseif (is_object($filterobj) && get_class($filterobj) == 'Product') {
2870 $sql2 .= ", '' as ref";
2871 } elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') {
2872 $sql2 .= ", '' as ref";
2873 }
2874 $sql2 .= " FROM " . MAIN_DB_PREFIX . "mailing as m, " . MAIN_DB_PREFIX . "mailing_cibles as mc, " . MAIN_DB_PREFIX . "user as u";
2875 $sql2 .= " WHERE mc.email = '" . $db->escape($objcon->email) . "'"; // Search is done on email.
2876 $sql2 .= " AND mc.statut = 1";
2877 $sql2 .= " AND u.rowid = m.fk_user_valid";
2878 $sql2 .= " AND mc.fk_mailing=m.rowid";
2879
2880 return $sql2;
2881 } else {
2882 return '';
2883 }
2884}
2885
2886
2899function htmlPrintOnlineHeader($mysoc, $langs, $showlogo = 1, $alttext = '', $subimageconst = '', $altlogo1 = '', $altlogo2 = '')
2900{
2902
2903 // Set logo of company by default
2904 $logosmall = $mysoc->logo_small;
2905 $logo = $mysoc->logo;
2906
2907 if ($altlogo1 && getDolGlobalString($altlogo1)) {
2908 $logosmall = getDolGlobalString($altlogo1);
2909 } elseif ($altlogo2 && getDolGlobalString($altlogo2)) {
2910 $logosmall = getDolGlobalString($altlogo2);
2911 }
2912
2913 // Define $urllogo and $urllogopublic
2914 //$urllogo = '';
2915 $urllogopublic = '';
2916 if ($showlogo) {
2917 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $logosmall)) {
2918 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$logosmall);
2919 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/thumbs/' . $logosmall);
2920 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $logo)) {
2921 //$urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$logo);
2922 $urllogopublic = $dolibarr_main_url_root . '/viewimage.php?modulepart=mycompany&entity=' . $conf->entity . '&file=' . urlencode('logos/' . $logo);
2923 } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.svg')) {
2924 //$urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
2925 $urllogopublic = $dolibarr_main_url_root . '/theme/dolibarr_logo.svg';
2926 }
2927 }
2928
2929 print '<header class="center">';
2930
2931 // Output html code for logo
2932 if ($urllogopublic || $alttext) {
2933 print '<div class="backgreypublicpayment">';
2934 print '<div class="logopublicpayment">';
2935 if ($urllogopublic) {
2936 if (!is_numeric($showlogo)) {
2937 print '<a href="' . $showlogo . '">';
2938 }
2939 print '<img id="dolpaymentlogo" src="' . $urllogopublic . '">';
2940 if (!is_numeric($showlogo)) {
2941 print '</a>';
2942 }
2943 }
2944 if ($alttext) {
2945 print '<div class="clearboth"></div><strong>' . $alttext . '</strong>';
2946 }
2947 print '</div>';
2948 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
2949 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>';
2950 }
2951 print '</div>';
2952 }
2953
2954 // Add an optional image under the ban with logo/title
2955 if (getDolGlobalString($subimageconst)) {
2956 print '<div class="backimagepublicsubimage">';
2957 print '<img id="id' . $subimageconst . '" src="' . getDolGlobalString($subimageconst) . '">';
2958 print '</div>';
2959 }
2960
2961 print '</header>';
2962}
2963
2964
2975function htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage = 0, $suffix = '', $object = null)
2976{
2977 $reg = array();
2978
2979 // Juridical status
2980 $line1 = "";
2981 if ($fromcompany->forme_juridique_code) {
2982 $line1 .= ($line1 ? " - " : "") . getFormeJuridiqueLabel((string) $fromcompany->forme_juridique_code);
2983 }
2984 // Capital
2985 if ($fromcompany->capital) {
2986 $line1 .= ($line1 ? " - " : "") . $langs->transnoentities("CapitalOf", (string) $fromcompany->capital) . " " . $langs->transnoentities("Currency" . getDolCurrency());
2987 }
2988 // Prof Id 1
2989 if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || !$fromcompany->idprof2)) {
2990 $field = $langs->transcountrynoentities("ProfId1", $fromcompany->country_code);
2991 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
2992 $field = $reg[1];
2993 }
2994 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof1;
2995 }
2996 // Prof Id 2
2997 if ($fromcompany->idprof2) {
2998 $field = $langs->transcountrynoentities("ProfId2", $fromcompany->country_code);
2999 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3000 $field = $reg[1];
3001 }
3002 $line1 .= ($line1 ? " - " : "") . $field . ": " . $fromcompany->idprof2;
3003 }
3004
3005 // Second line of company infos
3006 $line2 = "";
3007 // Prof Id 3
3008 if ($fromcompany->idprof3) {
3009 $field = $langs->transcountrynoentities("ProfId3", $fromcompany->country_code);
3010 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3011 $field = $reg[1];
3012 }
3013 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof3;
3014 }
3015 // Prof Id 4
3016 if ($fromcompany->idprof4) {
3017 $field = $langs->transcountrynoentities("ProfId4", $fromcompany->country_code);
3018 if (preg_match('/\‍((.*)\‍)/i', $field, $reg)) {
3019 $field = $reg[1];
3020 }
3021 $line2 .= ($line2 ? " - " : "") . $field . ": " . $fromcompany->idprof4;
3022 }
3023 // IntraCommunautary VAT
3024 if ($fromcompany->tva_intra != '') {
3025 $line2 .= ($line2 ? " - " : "") . $langs->transnoentities("VATIntraShort") . ": " . $fromcompany->tva_intra;
3026 }
3027
3028 print '<!-- htmlPrintOnlineFooter -->' . "\n";
3029
3030 // 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.
3031 print '<footer class="center centpercent opacitymedium paddingbottom">' . "\n";
3032 print '<br>';
3033 if ($addformmessage) {
3034 print '<!-- object = ' . (empty($object) ? 'undefined' : $object->element) . ' -->';
3035 print '<br>';
3036
3037 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORM_' . $suffix;
3038 if (getDolGlobalString($parammessageform) !== '') {
3039 print $langs->transnoentities(getDolGlobalString($parammessageform));
3040 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM') !== '') {
3041 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'));
3042 }
3043
3044 // Add other message if VAT exists
3045 if (!empty($object->total_vat) || !empty($object->total_tva)) {
3046 $parammessageform = 'ONLINE_PAYMENT_MESSAGE_FORMIFVAT_' . $suffix;
3047 if (getDolGlobalString($parammessageform) !== '') {
3048 print $langs->transnoentities(getDolGlobalString($parammessageform));
3049 } elseif (getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT') !== '') {
3050 print $langs->transnoentities(getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORMIFVAT'));
3051 }
3052 }
3053 }
3054
3055 print '<span style="font-size: 10px;"><br><hr>' . "\n";
3056 print $fromcompany->name . '<br>';
3057 print $line1;
3058 if (strlen($line1 . $line2) > 50) {
3059 print '<br>';
3060 } else {
3061 print ' - ';
3062 }
3063 print $line2;
3064 print '</span>';
3065 print '</footer>' . "\n";
3066}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
Class to manage agenda events (actions)
Class to manage different types of events.
Class for ConferenceOrBoothAttendee.
Class for ConferenceOrBooth.
Class to manage contact/addresses.
Class to manage building of HTML components.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class for SocieteAccount.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
addOtherFilterSQL(&$sql, $donetodo, $now, $filters)
Add more SQL filters for event list.
getCountriesInSEPA()
Return list of countries that are inside the SEPA zone (Single Euro Payment Area) Note: Try to keep t...
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
isInSEPA($object)
Return if a country of an object is inside the SEPA zone (Single Euro Payment Area)
addEventTypeSQL(&$sql, $actioncode, $sqlANDOR="AND")
Add Event Type SQL.
societe_admin_prepare_head()
Return array head with list of tabs to view object information.
getFormeJuridiqueLabel($code)
Return the name translated of juridical status.
show_actions_todo($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='')
Show html area with actions to do.
addMailingEventTypeSQL($actioncode, $objcon, $filterobj)
Add Mailing Event Type SQL.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dolOutputDates($datep, $datef=null, $fullday=0, $addseconds=0, $pictotoadd='', $tzoutput='tzuserrel', $reduceformat=0)
Print decorated date-hour.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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', ...)
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getArrayOfSocialNetworks()
Get array of social network dictionary.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.