dolibarr 23.0.4
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-2025 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 // TODO : add this check at update_linked_resource and when modifying event start or end date
143 // check if an event resource is already in use
144 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $objstat->element == 'action' && $resource_type == 'dolresource' && intval($busy) == 1) {
146 '@phan-var-force ActionComm $objstat';
147 $eventDateStart = $objstat->datep;
148 $eventDateEnd = $objstat->datef;
149 $isFullDayEvent = $objstat->fulldayevent;
150 if (empty($eventDateEnd)) {
151 if ($isFullDayEvent) {
152 $eventDateStartArr = dol_getdate($eventDateStart);
153 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
154 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
155 }
156 }
157
158 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
159 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
160 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($resource_type)."'";
161 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($objstat->element)."'";
162 $sql .= " WHERE er.resource_id = ".((int) $resource_id);
163 $sql .= " AND er.busy = 1";
164 $sql .= " AND (";
165
166 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
167 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
168 // event date end between ac.datep and ac.datep2
169 if (!empty($eventDateEnd)) {
170 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
171 }
172 // event date start before ac.datep and event date end after ac.datep2
173 $sql .= " OR (";
174 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
175 if (!empty($eventDateEnd)) {
176 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
177 }
178 $sql .= ")";
179
180 $sql .= ")";
181 $resql = $db->query($sql);
182 if (!$resql) {
183 $error++;
184 $objstat->error = $db->lasterror();
185 $objstat->errors[] = $objstat->error;
186 } else {
187 if ($db->num_rows($resql) > 0) {
188 // Resource already in use
189 $error++;
190 $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
191 while ($obj = $db->fetch_object($resql)) {
192 $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
193 }
194 $objstat->errors[] = $objstat->error;
195 }
196 $db->free($resql);
197 }
198 }
199
200 if (!$error) {
201 $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
202 }
203 }
204
205 if (!$error && $res > 0 && is_object($objstat)) {
206 setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
207 header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
208 exit;
209 } elseif ($objstat) {
210 setEventMessages($objstat->error, $objstat->errors, 'errors');
211 }
212 }
213
214 // Actions on an existing link: it must be a link of the element of the page, on which access was checked
215 if (in_array($action, ['update_linked_resource', 'confirm_delete_linked_resource'])) {
216 $tmplink = new Dolresource($db);
217 if ($tmplink->fetchElementResource($lineid) <= 0 || (int) $tmplink->element_id !== (int) $element_id || $tmplink->element_type !== $element) {
218 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
219 $action = '';
220 }
221 }
222
223 // Update resource
224 if ($action == 'update_linked_resource' && $permissiontoadd && !$cancel) {
225 $res = $object->fetchElementResource($lineid);
226 if ($res) {
227 $object->busy = $busy;
228 $object->mandatory = $mandatory;
229
230 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $object->objelement instanceof ActionComm && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) {
231 $eventDateStart = $object->objelement->datep; // @phan-suppress-current-line PhanUndeclaredProperty
232 $eventDateEnd = $object->objelement->datef; // @phan-suppress-current-line PhanUndeclaredProperty
233 $isFullDayEvent = $object->objelement->fulldayevent; // @phan-suppress-current-line PhanUndeclaredProperty
234 if (empty($eventDateEnd)) {
235 if ($isFullDayEvent) {
236 $eventDateStartArr = dol_getdate($eventDateStart);
237 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
238 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
239 }
240 }
241
242 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
243 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
244 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'";
245 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'";
246 $sql .= " WHERE er.resource_id = ".((int) $object->resource_id);
247 $sql .= " AND ac.id <> ".((int) $object->element_id);
248 $sql .= " AND er.busy = 1";
249 $sql .= " AND (";
250
251 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
252 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
253 // event date end between ac.datep and ac.datep2
254 if (!empty($eventDateEnd)) {
255 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
256 }
257 // event date start before ac.datep and event date end after ac.datep2
258 $sql .= " OR (";
259 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
260 if (!empty($eventDateEnd)) {
261 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
262 }
263 $sql .= ")";
264
265 $sql .= ")";
266 $resql = $db->query($sql);
267 if (!$resql) {
268 $error++;
269 $object->error = $db->lasterror();
270 $object->errors[] = $object->error;
271 } else {
272 if ($db->num_rows($resql) > 0) {
273 // Resource already in use
274 $error++;
275 $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
276 while ($obj = $db->fetch_object($resql)) {
277 $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
278 }
279 $object->errors[] = $object->error;
280 }
281 $db->free($resql);
282 }
283 }
284
285 if (!$error) {
286 $result = $object->updateElementResource($user);
287 if ($result < 0) {
288 $error++;
289 }
290 }
291
292 if ($error) {
293 setEventMessages($object->error, $object->errors, 'errors');
294 } else {
295 setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
296 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
297 exit;
298 }
299 }
300 }
301
302 // Delete a resource linked to an element
303 if ($action == 'confirm_delete_linked_resource' && $permissiontodelete && $confirm === 'yes') {
304 $res = $object->fetchElementResource($lineid); // to have correct object deleting resource
305 if ($res) {
306 $result = $object->objelement->delete_resource($lineid, '');
307
308 if ($result >= 0) {
309 setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
310 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
311 exit;
312 } else {
313 setEventMessages($object->error, $object->errors, 'errors');
314 }
315 } else {
316 setEventMessages($object->error, $object->errors, 'errors');
317 }
318 }
319}
320
321$parameters = array('resource_id' => $resource_id);
322$reshook = $hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
323if ($reshook < 0) {
324 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
325}
326
327
328
329/*
330 * View
331 */
332
333$form = new Form($db);
334
335$pagetitle = $langs->trans('ResourceElementPage');
336$help_url = '';
337llxHeader('', $pagetitle, $help_url, '', 0, 0, '', '', '', 'mod-resource page-element_resource');
338
339$now = dol_now();
340$delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
341
342// Load available resource, declared by modules
343$ret = count($object->available_resources);
344if ($ret == -1) {
345 dol_print_error($db, $object->error);
346 exit;
347}
348if (!$ret) {
349 print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
350} else {
351 // Confirmation suppression resource line
352 if ($action == 'delete_resource') {
353 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);
354 }
355
356
357 // Specific to agenda module
358 if (($element_id || $element_ref) && $element == 'action') {
359 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
360
361 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
362 $hookmanager->initHooks(array('actioncard', 'globalcard'));
363
364 $act = fetchObjectByElement($element_id, $element, $element_ref);
365 if (is_object($act)) {
366 '@phan-var-force ActionComm $act';
367 $head = actions_prepare_head($act);
368
369 print dol_get_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action');
370
371 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1">';
372 $linkback .= img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="pictoactionview pictofixedwidth"');
373 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("BackToList").'</span>';
374 $linkback .= '</a>';
375
376 // Link to other agenda views
377 $out = '';
378 $out .= '</li><li class="noborder litext">';
379 $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').'">';
380 $out .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictofixedwidth pictoactionview"');
381 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewCal").'</span>';
382 $out .= '</a>';
383 $out .= '</li><li class="noborder litext">';
384 $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').'">';
385 $out .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictofixedwidth pictoactionview"');
386 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewWeek").'</span>';
387 $out .= '</a>';
388 $out .= '</li><li class="noborder litext">';
389 $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').'">';
390 $out .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictofixedwidth pictoactionview"');
391 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewDay").'</span>';
392 $out .= '</a>';
393 $out .= '</li><li class="noborder litext">';
394 $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').'">';
395 $out .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictofixedwidth pictoactionview"');
396 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewPerUser").'</span>';
397 $out .= '</a>';
398
399 // Add more views from hooks
400 $parameters = array();
401 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
402 if (empty($reshook)) {
403 $out .= $hookmanager->resPrint;
404 } elseif ($reshook > 1) {
405 $out = $hookmanager->resPrint;
406 }
407
408 $linkback .= $out;
409
410 $morehtmlref = '<div class="refidno">';
411 // Thirdparty
412 //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
413 // Project
414 $savobject = $object;
415 $object = $act;
416 if (isModEnabled('project')) {
417 $langs->load("projects");
418 //$morehtmlref .= '<br>';
419 if (0) { // @phpstan-ignore-line
420 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
421 if ($action != 'classify') {
422 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
423 }
424 $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');
425 } else {
426 if (!empty($object->fk_project)) {
427 $proj = new Project($db);
428 $proj->fetch($object->fk_project);
429 $morehtmlref .= $proj->getNomUrl(1);
430 if ($proj->title) {
431 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
432 }
433 }
434 }
435 }
436 $object = $savobject;
437 $morehtmlref .= '</div>';
438
439 dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
440
441 print '<div class="fichecenter">';
442
443 print '<div class="underbanner clearboth"></div>';
444
445 print '<table class="border tableforfield centpercent">';
446
447 // Type
448 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
449 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
450 print $act->getTypePicto();
451 print $langs->trans("Action".$act->type_code);
452 print '</td></tr>';
453 }
454
455 // Full day event
456 print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent ? 1 : 0, 3).'</td></tr>';
457
458 // Date start
459 print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
460 if (empty($act->fulldayevent)) {
461 print dol_print_date($act->datep, 'dayhour', 'tzuser');
462 } else {
463 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
464 print dol_print_date($act->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
465 }
466 if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) {
467 print img_warning($langs->trans("Late"));
468 }
469 print '</td>';
470 print '</tr>';
471
472 // Date end
473 print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
474 if (empty($act->fulldayevent)) {
475 print dol_print_date($act->datef, 'dayhour', 'tzuser');
476 } else {
477 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
478 print dol_print_date($act->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
479 }
480 if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) {
481 print img_warning($langs->trans("Late"));
482 }
483 print '</td></tr>';
484
485 // Location
486 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
487 print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
488 }
489
490 // Assigned to
491 print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
492 $listofuserid = array();
493 if (empty($donotclearsession)) {
494 if ($act->userownerid > 0) {
495 $listofuserid[$act->userownerid] = array('id' => $act->userownerid, 'transparency' => $act->transparency); // Owner first
496 }
497 if (!empty($act->userassigned)) { // Now concat assigned users
498 // Restore array with key with same value than param 'id'
499 $tmplist1 = $act->userassigned;
500 $tmplist2 = array();
501 foreach ($tmplist1 as $key => $val) {
502 if ($val['id'] && $val['id'] != $act->userownerid) {
503 $listofuserid[$val['id']] = $val;
504 }
505 }
506 }
507 $_SESSION['assignedtouser'] = json_encode($listofuserid);
508 } else {
509 if (!empty($_SESSION['assignedtouser'])) {
510 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
511 }
512 }
513 $listofcontactid = array(); // not used yet
514 $listofotherid = array(); // not used yet
515 print '<div class="assignedtouser">';
516 print $form->select_dolusers_forevent('view', 'assignedtouser', 1, array(), 0, '', array(), '0', 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
517 print '</div>';
518 /*if (in_array($user->id,array_keys($listofuserid)))
519 {
520 print '<div class="myavailability">';
521 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
522 print '</div>';
523 }*/
524 print ' </td></tr>';
525
526 print '</table>';
527
528 print '</div>';
529
530 print dol_get_fiche_end();
531 }
532 }
533
534 // Specific to thirdparty module
535 if (($element_id || $element_ref) && $element == 'societe') {
536 $socstatic = fetchObjectByElement($element_id, $element, $element_ref);
537 if (is_object($socstatic)) {
538 '@phan-var-force Societe $socstatic';
540 $savobject = $object;
541 $object = $socstatic;
542
543 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
544 $head = societe_prepare_head($socstatic);
545
546 print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
547
548 dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element);
549
550 print '<div class="fichecenter">';
551
552 print '<div class="underbanner clearboth"></div>';
553 print '<table class="border centpercent">';
554
555 // Alias name (commercial, trademark or alias name)
556 print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
557 print $socstatic->name_alias;
558 print "</td></tr>";
559
560 print '</table>';
561
562 print '</div>';
563
564 print dol_get_fiche_end();
565
566 $object = $savobject;
567 }
568 }
569
570 // Specific to fichinter module
571 if (($element_id || $element_ref) && $element == 'fichinter') {
572 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
573
574 $fichinter = new Fichinter($db);
575 $fichinter->fetch($element_id, $element_ref);
576 $fichinter->fetch_thirdparty();
577
578 $usercancreate = $user->hasRight('fichinter', 'creer');
579
580 if (is_object($fichinter)) {
581 $head = fichinter_prepare_head($fichinter);
582 print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
583
584 // Intervention card
585 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
586
587
588 $morehtmlref = '<div class="refidno">';
589 // Ref customer
590 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', 0, 1);
591 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
592 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', 0, 1);
593 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', null, null, '', 1);
594 // Thirdparty
595 $morehtmlref .= '<br>'.$fichinter->thirdparty->getNomUrl(1, 'customer');
596 // Project
597 if (isModEnabled('project')) {
598 $langs->load("projects");
599 $morehtmlref .= '<br>';
600 if ($usercancreate && 0) {
601 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
602 if ($action != 'classify') {
603 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$fichinter->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
604 }
605 $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');
606 } else {
607 if (!empty($fichinter->fk_project)) {
608 $proj = new Project($db);
609 $proj->fetch($fichinter->fk_project);
610 $morehtmlref .= $proj->getNomUrl(1);
611 if ($proj->title) {
612 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
613 }
614 }
615 }
616 }
617 $morehtmlref .= '</div>';
618
619 dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
620
621 print dol_get_fiche_end();
622 }
623 }
624
625 // Specific to product/service module
626 if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) {
627 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
628
629 $product = new Product($db);
630 $product->fetch($element_id, $element_ref);
631
632 if (is_object($product)) {
633 $head = product_prepare_head($product);
634 $titre = $langs->trans("CardProduct".$product->type);
635 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
636
637 print dol_get_fiche_head($head, 'resources', $titre, -1, $picto);
638
639 $shownav = 1;
640 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
641 $shownav = 0;
642 }
643 dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
644
645 print dol_get_fiche_end();
646 }
647 }
648
649
650 // hook for other elements linked
651 $parameters = array('element' => $element, 'element_id' => $element_id, 'element_ref' => $element_ref);
652 $reshook = $hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
653 if ($reshook < 0) {
654 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
655 }
656
657
658 //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
659 print '<br>';
660
661 // Show list of resource links
662
663 foreach ($object->available_resources as $modresources => $resources) {
664 $resources = (array) $resources; // To be sure $resources is an array
665 foreach ($resources as $resource_obj) {
666 $element_prop = getElementProperties($resource_obj);
667
668 //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
669
670 $path = '';
671 if (strpos($resource_obj, '@')) {
672 $path .= '/'.$element_prop['module'];
673 }
674
675 $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
676
677 // Output template part (modules that overwrite templates must declare this into descriptor)
678 $defaulttpldir = '/core/tpl';
679 $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
680
681 foreach ($dirtpls as $module => $reldir) {
682 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) {
683 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
684 } else {
685 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
686 }
687 if (empty($conf->file->strict_mode)) {
688 $res = @include $tpl;
689 } else {
690 $res = include $tpl; // for debug
691 }
692 if ($res) {
693 break;
694 }
695 }
696
697 if ($mode != 'add' || $resource_obj != $resource_type) {
698 foreach ($dirtpls as $module => $reldir) {
699 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) {
700 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
701 } else {
702 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
703 }
704 if (empty($conf->file->strict_mode)) {
705 $res = @include $tpl;
706 } else {
707 $res = include $tpl; // for debug
708 }
709 if ($res) {
710 break;
711 }
712 }
713 }
714 }
715 }
716}
717
718// End of page
719llxFooter();
720$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.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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, $mode=0)
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.