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