dolibarr 25.0.0-alpha
element_resource.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2018 Jean-François Ferry <hello+jf@librethic.io>
3 * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
4 * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
5 * Copyright (C) 2021-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
35if (isModEnabled('project')) {
36 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
38}
39if (isModEnabled("product") || isModEnabled("service")) {
40 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41}
42
51// Load translation files required by the page
52$langs->loadLangs(array('resource', 'other', 'interventions'));
53
54/*
55$sortorder = GETPOST('sortorder','alpha');
56$sortfield = GETPOST('sortfield','alpha');
57$page = GETPOST('page','int');
58*/
59
60$object = new Dolresource($db);
61
62$hookmanager->initHooks(array('element_resource'));
63$object->available_resources = array('dolresource');
64
65// Get parameters
66$id = GETPOSTINT('id'); // resource id
67$element_id = GETPOSTINT('element_id'); // element_id
68$element_ref = GETPOST('ref', 'alpha'); // element ref
69$element = GETPOST('element', 'alpha'); // element_type
70$action = GETPOST('action', 'alpha');
71$mode = GETPOST('mode', 'alpha');
72$lineid = GETPOSTINT('lineid');
73$resource_id = GETPOSTINT('fk_resource');
74$resource_type = GETPOST('resource_type', 'alpha');
75$busy = GETPOSTINT('busy');
76$mandatory = GETPOSTINT('mandatory');
77$cancel = GETPOST('cancel', 'alpha');
78$confirm = GETPOST('confirm', 'alpha');
79$socid = GETPOSTINT('socid');
80
81if (empty($mandatory)) {
82 $mandatory = 0;
83}
84if (empty($busy)) {
85 $busy = 0;
86}
87
88if ($socid > 0) { // Special for thirdparty
89 $element_id = $socid;
90 $element = 'societe';
91}
92
93if (!$user->hasRight('resource', 'read')) {
95}
96
97// Permission is not permission on resources. We just make link here on objects.
98if ($element == 'action') {
99 $result = restrictedArea($user, 'agenda', $element_id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
100}
101if ($element == 'fichinter') {
102 $result = restrictedArea($user, 'ficheinter', $element_id, 'fichinter');
103}
104if ($element == 'product' || $element == 'service') { // When RESOURCE_ON_PRODUCTS or RESOURCE_ON_SERVICES is set
105 $tmpobject = new Product($db);
106 $tmpobject->fetch($element_id);
107 $fieldtype = $tmpobject->type;
108 $result = restrictedArea($user, 'produit|service', $element_id, 'product&product', '', '', (string) $fieldtype);
109}
110
111// TODO
112//$permissiontoadd should be set according to $element
113//$permissiontodelete should be set according to $element
114$permissiontoadd = $user->hasRight('resource', 'write');
115$permissiontodelete = $user->hasRight('resource', 'delete');
116
117
118/*
119 * Actions
120 */
121
122$parameters = array('resource_id' => $resource_id);
123$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
124if ($reshook < 0) {
125 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126}
127
128if (empty($reshook)) {
129 $error = 0;
130 $objstat = null;
131
132 if ($action == 'add_element_resource' && !$cancel && $permissiontoadd) { // Test on permission already done in header before actions
133 $res = 0;
134 if (!($resource_id > 0)) {
135 $error++;
136 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
137 $action = '';
138 } else {
139 $objstat = fetchObjectByElement($element_id, $element, $element_ref);
140 $objstat->element = $element; // For externals module, we need to keep @xx
141
142 // check if the resource is already busy on another event or intervention that overlaps
143 // (only for the element types whose module is actually enabled)
144 $elementsToCheck = array();
145 if (isModEnabled('agenda')) {
146 $elementsToCheck[] = 'action';
147 }
148 if (isModEnabled('intervention')) {
149 $elementsToCheck[] = 'fichinter';
150 }
151 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && in_array($objstat->element, $elementsToCheck) && $resource_type == 'dolresource' && intval($busy) == 1) {
152 $bookingDateStart = null;
153 $bookingDateEnd = null;
154
155 if ($objstat->element == 'action') {
157 '@phan-var-force ActionComm $objstat';
158 $bookingDateStart = $objstat->datep;
159 $bookingDateEnd = $objstat->datef;
160 if (empty($bookingDateEnd) && $objstat->fulldayevent) {
161 $eventDateStartArr = dol_getdate($bookingDateStart);
162 $bookingDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
163 $bookingDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
164 }
165 } elseif ($objstat->element == 'fichinter') {
166 // Fichinter has no usable header date range of its own: derive it from its lines.
168 '@phan-var-force Fichinter $objstat';
169 $sqlrange = "SELECT MIN(fd.date) as dmin, MAX(fd.date + INTERVAL fd.duree SECOND) as dmax";
170 $sqlrange .= " FROM ".MAIN_DB_PREFIX."fichinterdet as fd";
171 $sqlrange .= " WHERE fd.fk_fichinter = ".((int) $objstat->id);
172 $resqlrange = $db->query($sqlrange);
173 if ($resqlrange) {
174 $objrange = $db->fetch_object($resqlrange);
175 if ($objrange && $objrange->dmin) {
176 $bookingDateStart = $db->jdate($objrange->dmin);
177 $bookingDateEnd = $db->jdate($objrange->dmax);
178 }
179 $db->free($resqlrange);
180 }
181 }
182
183 if (!empty($bookingDateStart)) {
184 $resourcestatic = new Dolresource($db);
185 $resourcestatic->fetch($resource_id);
186 $conflicts = $resourcestatic->getBookingConflicts($resource_id, $resource_type, $bookingDateStart, ($bookingDateEnd ? $bookingDateEnd : $bookingDateStart), $objstat->element, $objstat->id);
187 if (!is_array($conflicts)) {
188 $error++;
189 $objstat->error = $resourcestatic->error;
190 $objstat->errors[] = $objstat->error;
191 } elseif (count($conflicts) > 0) {
192 // Resource already in use
193 $error++;
194 $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
195 foreach ($conflicts as $conflict) {
196 $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $resourcestatic->ref, $conflict['ref'].' ['.$conflict['element_id'].']');
197 }
198 $objstat->errors[] = $objstat->error;
199 }
200 }
201 }
202
203 if (!$error) {
204 $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
205 }
206 }
207
208 if (!$error && $res > 0 && is_object($objstat)) {
209 setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
210 header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
211 exit;
212 } elseif ($objstat) {
213 setEventMessages($objstat->error, $objstat->errors, 'errors');
214 }
215 }
216
217 // Actions on an existing link: it must be a link of the element of the page, on which access was checked
218 if (in_array($action, ['update_linked_resource', 'confirm_delete_linked_resource'])) {
219 $tmplink = new Dolresource($db);
220 if ($tmplink->fetchElementResource($lineid) <= 0 || (int) $tmplink->element_id !== (int) $element_id || $tmplink->element_type !== $element) {
221 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
222 $action = '';
223 }
224 }
225
226 // Update resource
227 if ($action == 'update_linked_resource' && $permissiontoadd && !$cancel) {
228 $res = $object->fetchElementResource($lineid);
229 if ($res) {
230 $object->busy = $busy;
231 $object->mandatory = $mandatory;
232
233 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $object->objelement instanceof ActionComm && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) {
234 $eventDateStart = $object->objelement->datep; // @phan-suppress-current-line PhanUndeclaredProperty
235 $eventDateEnd = $object->objelement->datef; // @phan-suppress-current-line PhanUndeclaredProperty
236 $isFullDayEvent = $object->objelement->fulldayevent; // @phan-suppress-current-line PhanUndeclaredProperty
237 if (empty($eventDateEnd)) {
238 if ($isFullDayEvent) {
239 $eventDateStartArr = dol_getdate($eventDateStart);
240 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
241 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
242 }
243 }
244
245 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
246 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
247 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'";
248 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'";
249 $sql .= " WHERE er.resource_id = ".((int) $object->resource_id);
250 $sql .= " AND ac.id <> ".((int) $object->element_id);
251 $sql .= " AND er.busy = 1";
252 $sql .= " AND (";
253
254 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
255 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
256 // event date end between ac.datep and ac.datep2
257 if (!empty($eventDateEnd)) {
258 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
259 }
260 // event date start before ac.datep and event date end after ac.datep2
261 $sql .= " OR (";
262 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
263 if (!empty($eventDateEnd)) {
264 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
265 }
266 $sql .= ")";
267
268 $sql .= ")";
269 $resql = $db->query($sql);
270 if (!$resql) {
271 $error++;
272 $object->error = $db->lasterror();
273 $object->errors[] = $object->error;
274 } else {
275 if ($db->num_rows($resql) > 0) {
276 // Resource already in use
277 $error++;
278 $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
279 while ($obj = $db->fetch_object($resql)) {
280 $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
281 }
282 $object->errors[] = $object->error;
283 }
284 $db->free($resql);
285 }
286 }
287
288 if (!$error) {
289 $result = $object->updateElementResource($user);
290 if ($result < 0) {
291 $error++;
292 }
293 }
294
295 if ($error) {
296 setEventMessages($object->error, $object->errors, 'errors');
297 } else {
298 setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
299 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
300 exit;
301 }
302 }
303 }
304
305 // Delete a resource linked to an element
306 if ($action == 'confirm_delete_linked_resource' && $permissiontodelete && $confirm === 'yes') {
307 $res = $object->fetchElementResource($lineid); // to have correct object deleting resource
308 if ($res) {
309 $result = $object->objelement->delete_resource($lineid, '');
310
311 if ($result >= 0) {
312 setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
313 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
314 exit;
315 } else {
316 setEventMessages($object->error, $object->errors, 'errors');
317 }
318 } else {
319 setEventMessages($object->error, $object->errors, 'errors');
320 }
321 }
322}
323
324$parameters = array('resource_id' => $resource_id);
325$reshook = $hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
326if ($reshook < 0) {
327 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
328}
329
330
331
332/*
333 * View
334 */
335
336$form = new Form($db);
337
338$pagetitle = $langs->trans('ResourceElementPage');
339$help_url = '';
340llxHeader('', $pagetitle, $help_url, '', 0, 0, '', '', '', 'mod-resource page-element_resource');
341
342$now = dol_now();
343$delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
344
345// Load available resource, declared by modules
346$ret = count($object->available_resources);
347if ($ret == -1) {
348 dol_print_error($db, $object->error);
349 exit;
350}
351if (!$ret) {
352 print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
353} else {
354 // Deletion confirmation resource line
355 if ($action == 'delete_resource') {
356 print $form->formconfirm("element_resource.php?element=".$element."&element_id=".$element_id."&id=".$id."&lineid=".$lineid, $langs->trans("DeleteResource"), $langs->trans("ConfirmDeleteResourceElement"), "confirm_delete_linked_resource", '', '', 1);
357 }
358
359
360 // Specific to agenda module
361 if (($element_id || $element_ref) && $element == 'action') {
362 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
363
364 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
365 $hookmanager->initHooks(array('actioncard', 'globalcard'));
366
367 $act = fetchObjectByElement($element_id, $element, $element_ref);
368 if (is_object($act)) {
369 '@phan-var-force ActionComm $act';
370 $head = actions_prepare_head($act);
371
372 print dol_get_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action');
373
374 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1">';
375 $linkback .= img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="pictoactionview pictofixedwidth"');
376 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("BackToList").'</span>';
377 $linkback .= '</a>';
378
379 // Link to other agenda views
380 $out = '';
381 $out .= '</li><li class="noborder litext">';
382 $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">';
383 $out .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictofixedwidth pictoactionview"');
384 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewCal").'</span>';
385 $out .= '</a>';
386 $out .= '</li><li class="noborder litext">';
387 $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">';
388 $out .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictofixedwidth pictoactionview"');
389 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewWeek").'</span>';
390 $out .= '</a>';
391 $out .= '</li><li class="noborder litext">';
392 $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">';
393 $out .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictofixedwidth pictoactionview"');
394 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewDay").'</span>';
395 $out .= '</a>';
396 $out .= '</li><li class="noborder litext">';
397 $out .= '<a href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($act->datep, '%Y').'&month='.dol_print_date($act->datep, '%m').'&day='.dol_print_date($act->datep, '%d').'">';
398 $out .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictofixedwidth pictoactionview"');
399 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewPerUser").'</span>';
400 $out .= '</a>';
401
402 // Add more views from hooks
403 $parameters = array();
404 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
405 if (empty($reshook)) {
406 $out .= $hookmanager->resPrint;
407 } elseif ($reshook > 1) {
408 $out = $hookmanager->resPrint;
409 }
410
411 $linkback .= $out;
412
413 $morehtmlref = '<div class="refidno">';
414 // Thirdparty
415 //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
416 // Project
417 $savobject = $object;
418 $object = $act;
419 if (isModEnabled('project')) {
420 $langs->load("projects");
421 //$morehtmlref .= '<br>';
422 if (0) { // @phpstan-ignore-line
423 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
424 if ($action != 'classify') {
425 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
426 }
427 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
428 } else {
429 if (!empty($object->fk_project)) {
430 $proj = new Project($db);
431 $proj->fetch($object->fk_project);
432 $morehtmlref .= $proj->getNomUrl(1);
433 if ($proj->title) {
434 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
435 }
436 }
437 }
438 }
439 $object = $savobject;
440 $morehtmlref .= '</div>';
441
442 dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
443
444 print '<div class="fichecenter">';
445
446 print '<div class="underbanner clearboth"></div>';
447
448 print '<table class="border tableforfield centpercent">';
449
450 // Type
451 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
452 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
453 print $act->getTypePicto();
454 print $langs->trans("Action".$act->type_code);
455 print '</td></tr>';
456 }
457
458 // Full day event
459 print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent ? 1 : 0, 3).'</td></tr>';
460
461 // Date start
462 print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
463 if (empty($act->fulldayevent)) {
464 print dol_print_date($act->datep, 'dayhour', 'tzuser');
465 } else {
466 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
467 print dol_print_date($act->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
468 }
469 if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) {
470 print img_warning($langs->trans("Late"));
471 }
472 print '</td>';
473 print '</tr>';
474
475 // Date end
476 print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
477 if (empty($act->fulldayevent)) {
478 print dol_print_date($act->datef, 'dayhour', 'tzuser');
479 } else {
480 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
481 print dol_print_date($act->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
482 }
483 if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) {
484 print img_warning($langs->trans("Late"));
485 }
486 print '</td></tr>';
487
488 // Location
489 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
490 print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
491 }
492
493 // Assigned to
494 print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
495 $listofuserid = array();
496 if (empty($donotclearsession)) {
497 if ($act->userownerid > 0) {
498 $listofuserid[$act->userownerid] = array('id' => $act->userownerid, 'transparency' => $act->transparency); // Owner first
499 }
500 if (!empty($act->userassigned)) { // Now concat assigned users
501 // Restore array with key with same value than param 'id'
502 $tmplist1 = $act->userassigned;
503 $tmplist2 = array();
504 foreach ($tmplist1 as $key => $val) {
505 if ($val['id'] && $val['id'] != $act->userownerid) {
506 $listofuserid[$val['id']] = $val;
507 }
508 }
509 }
510 $_SESSION['assignedtouser'] = json_encode($listofuserid);
511 } else {
512 if (!empty($_SESSION['assignedtouser'])) {
513 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
514 }
515 }
516 $listofcontactid = array(); // not used yet
517 $listofotherid = array(); // not used yet
518 print '<div class="assignedtouser">';
519 print $form->select_dolusers_forevent('view', 'assignedtouser', 1, array(), 0, '', array(), '0', 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
520 print '</div>';
521 /*if (in_array($user->id,array_keys($listofuserid)))
522 {
523 print '<div class="myavailability">';
524 print $langs->trans("MyAvailability").': '.(($act->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody
525 print '</div>';
526 }*/
527 print ' </td></tr>';
528
529 print '</table>';
530
531 print '</div>';
532
533 print dol_get_fiche_end();
534 }
535 }
536
537 // Specific to thirdparty module
538 if (($element_id || $element_ref) && $element == 'societe') {
539 $socstatic = fetchObjectByElement($element_id, $element, $element_ref);
540 if (is_object($socstatic)) {
541 '@phan-var-force Societe $socstatic';
543 $savobject = $object;
544 $object = $socstatic;
545
546 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
547 $head = societe_prepare_head($socstatic);
548
549 print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
550
551 dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element);
552
553 print '<div class="fichecenter">';
554
555 print '<div class="underbanner clearboth"></div>';
556 print '<table class="border centpercent">';
557
558 // Alias name (commercial, trademark or alias name)
559 print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
560 print $socstatic->name_alias;
561 print "</td></tr>";
562
563 print '</table>';
564
565 print '</div>';
566
567 print dol_get_fiche_end();
568
569 $object = $savobject;
570 }
571 }
572
573 // Specific to fichinter module
574 if (($element_id || $element_ref) && $element == 'fichinter') {
575 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
576
577 $fichinter = new Fichinter($db);
578 $fichinter->fetch($element_id, $element_ref);
579 $fichinter->fetch_thirdparty();
580
581 $usercancreate = $user->hasRight('fichinter', 'creer');
582
583 if (is_object($fichinter)) {
584 $head = fichinter_prepare_head($fichinter);
585 print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
586
587 // Intervention card
588 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
589
590
591 $morehtmlref = '<div class="refidno">';
592 // Ref customer
593 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', 0, 1);
594 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
595 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', 0, 1);
596 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', null, null, '', 1);
597 // Thirdparty
598 $morehtmlref .= '<br>'.$fichinter->thirdparty->getNomUrl(1, 'customer');
599 // Project
600 if (isModEnabled('project')) {
601 $langs->load("projects");
602 $morehtmlref .= '<br>';
603 if ($usercancreate && 0) {
604 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
605 if ($action != 'classify') {
606 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$fichinter->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
607 }
608 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, (string) $fichinter->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
609 } else {
610 if (!empty($fichinter->fk_project)) {
611 $proj = new Project($db);
612 $proj->fetch($fichinter->fk_project);
613 $morehtmlref .= $proj->getNomUrl(1);
614 if ($proj->title) {
615 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
616 }
617 }
618 }
619 }
620 $morehtmlref .= '</div>';
621
622 dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
623
624 print dol_get_fiche_end();
625 }
626 }
627
628 // Specific to product/service module
629 if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) {
630 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
631
632 $product = new Product($db);
633 $product->fetch($element_id, $element_ref);
634
635 if (is_object($product)) {
636 $head = product_prepare_head($product);
637 $titre = $langs->trans("CardProduct".$product->type);
638 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
639
640 print dol_get_fiche_head($head, 'resources', $titre, -1, $picto);
641
642 $shownav = 1;
643 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
644 $shownav = 0;
645 }
646 dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
647
648 print dol_get_fiche_end();
649 }
650 }
651
652
653 // hook for other elements linked
654 $parameters = array('element' => $element, 'element_id' => $element_id, 'element_ref' => $element_ref);
655 $reshook = $hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
656 if ($reshook < 0) {
657 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
658 }
659
660
661 //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
662 print '<br>';
663
664 // Show list of resource links
665
666 foreach ($object->available_resources as $modresources => $resources) {
667 $resources = (array) $resources; // To be sure $resources is an array
668 foreach ($resources as $resource_obj) {
669 $element_prop = getElementProperties($resource_obj);
670
671 //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
672
673 $path = '';
674 if (strpos($resource_obj, '@')) {
675 $path .= '/'.$element_prop['module'];
676 }
677
678 $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
679
680 // Output template part (modules that overwrite templates must declare this into descriptor)
681 $defaulttpldir = '/core/tpl';
682 $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
683
684 foreach ($dirtpls as $module => $reldir) {
685 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) {
686 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
687 } else {
688 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
689 }
690 if (empty($conf->file->strict_mode)) {
691 $res = @include $tpl;
692 } else {
693 $res = include $tpl; // for debug
694 }
695 if ($res) {
696 break;
697 }
698 }
699
700 if ($mode != 'add' || $resource_obj != $resource_type) {
701 foreach ($dirtpls as $module => $reldir) {
702 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) {
703 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
704 } else {
705 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
706 }
707 if (empty($conf->file->strict_mode)) {
708 $res = @include $tpl;
709 } else {
710 $res = include $tpl; // for debug
711 }
712 if ($res) {
713 break;
714 }
715 }
716 }
717 }
718 }
719}
720
721// End of page
722llxFooter();
723$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
actions_prepare_head($object)
Prepare array with list of tabs.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage agenda events (actions)
DAO Resource object.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
const TYPE_SERVICE
Service.
Class to manage projects.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
fichinter_prepare_head($object)
Prepare array with list of tabs.
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...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
product_prepare_head($object)
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.