dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
7 * Copyright (C) 2024 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
43// Load translation files required by the page
44$langs->loadLangs(array('resource', 'other', 'interventions'));
45
46/*
47$sortorder = GETPOST('sortorder','alpha');
48$sortfield = GETPOST('sortfield','alpha');
49$page = GETPOST('page','int');
50*/
51
52$object = new Dolresource($db);
53
54$hookmanager->initHooks(array('element_resource'));
55$object->available_resources = array('dolresource');
56
57// Get parameters
58$id = GETPOSTINT('id'); // resource id
59$element_id = GETPOSTINT('element_id'); // element_id
60$element_ref = GETPOST('ref', 'alpha'); // element ref
61$element = GETPOST('element', 'alpha'); // element_type
62$action = GETPOST('action', 'alpha');
63$mode = GETPOST('mode', 'alpha');
64$lineid = GETPOSTINT('lineid');
65$resource_id = GETPOSTINT('fk_resource');
66$resource_type = GETPOST('resource_type', 'alpha');
67$busy = GETPOSTINT('busy');
68$mandatory = GETPOSTINT('mandatory');
69$cancel = GETPOST('cancel', 'alpha');
70$confirm = GETPOST('confirm', 'alpha');
71$socid = GETPOSTINT('socid');
72
73if (empty($mandatory)) {
74 $mandatory = 0;
75}
76if (empty($busy)) {
77 $busy = 0;
78}
79
80if ($socid > 0) { // Special for thirdparty
81 $element_id = $socid;
82 $element = 'societe';
83}
84
85if (!$user->hasRight('resource', 'read')) {
87}
88
89// Permission is not permission on resources. We just make link here on objects.
90if ($element == 'action') {
91 $result = restrictedArea($user, 'agenda', $element_id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
92}
93if ($element == 'fichinter') {
94 $result = restrictedArea($user, 'ficheinter', $element_id, 'fichinter');
95}
96if ($element == 'product' || $element == 'service') { // When RESOURCE_ON_PRODUCTS or RESOURCE_ON_SERVICES is set
97 $tmpobject = new Product($db);
98 $tmpobject->fetch($element_id);
99 $fieldtype = $tmpobject->type;
100 $result = restrictedArea($user, 'produit|service', $element_id, 'product&product', '', '', (string) $fieldtype);
101}
102
103
104/*
105 * Actions
106 */
107
108$parameters = array('resource_id' => $resource_id);
109$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110if ($reshook < 0) {
111 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112}
113
114if (empty($reshook)) {
115 $error = 0;
116 $objstat = null;
117
118 if ($action == 'add_element_resource' && !$cancel) {
119 $res = 0;
120 if (!($resource_id > 0)) {
121 $error++;
122 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors');
123 $action = '';
124 } else {
125 $objstat = fetchObjectByElement($element_id, $element, $element_ref);
126 $objstat->element = $element; // For externals module, we need to keep @xx
127
128 // TODO : add this check at update_linked_resource and when modifying event start or end date
129 // check if an event resource is already in use
130 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $objstat->element == 'action' && $resource_type == 'dolresource' && intval($busy) == 1) {
131 $eventDateStart = $objstat->datep;
132 $eventDateEnd = $objstat->datef;
133 $isFullDayEvent = $objstat->fulldayevent;
134 if (empty($eventDateEnd)) {
135 if ($isFullDayEvent) {
136 $eventDateStartArr = dol_getdate($eventDateStart);
137 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
138 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
139 }
140 }
141
142 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
143 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
144 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($resource_type)."'";
145 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($objstat->element)."'";
146 $sql .= " WHERE er.resource_id = ".((int) $resource_id);
147 $sql .= " AND er.busy = 1";
148 $sql .= " AND (";
149
150 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
151 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
152 // event date end between ac.datep and ac.datep2
153 if (!empty($eventDateEnd)) {
154 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
155 }
156 // event date start before ac.datep and event date end after ac.datep2
157 $sql .= " OR (";
158 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
159 if (!empty($eventDateEnd)) {
160 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
161 }
162 $sql .= ")";
163
164 $sql .= ")";
165 $resql = $db->query($sql);
166 if (!$resql) {
167 $error++;
168 $objstat->error = $db->lasterror();
169 $objstat->errors[] = $objstat->error;
170 } else {
171 if ($db->num_rows($resql) > 0) {
172 // Resource already in use
173 $error++;
174 $objstat->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
175 while ($obj = $db->fetch_object($resql)) {
176 $objstat->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
177 }
178 $objstat->errors[] = $objstat->error;
179 }
180 $db->free($resql);
181 }
182 }
183
184 if (!$error) {
185 $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
186 }
187 }
188
189 if (!$error && $res > 0 && is_object($objstat)) {
190 setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs');
191 header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$objstat->id);
192 exit;
193 } elseif ($objstat) {
194 setEventMessages($objstat->error, $objstat->errors, 'errors');
195 }
196 }
197
198 // Update resource
199 if ($action == 'update_linked_resource' && $user->hasRight('resource', 'write') && !GETPOST('cancel', 'alpha') && is_object($objstat)) {
200 $res = $object->fetchElementResource($lineid);
201 if ($res) {
202 $object->busy = $busy;
203 $object->mandatory = $mandatory;
204
205 if (getDolGlobalString('RESOURCE_USED_IN_EVENT_CHECK') && $object->element_type == 'action' && $object->resource_type == 'dolresource' && intval($object->busy) == 1) {
206 $eventDateStart = $object->objelement->datep; // @phan-suppress-current-line PhanUndeclaredProperty
207 $eventDateEnd = $object->objelement->datef; // @phan-suppress-current-line PhanUndeclaredProperty
208 $isFullDayEvent = $objstat->fulldayevent;
209 if (empty($eventDateEnd)) {
210 if ($isFullDayEvent) {
211 $eventDateStartArr = dol_getdate($eventDateStart);
212 $eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
213 $eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
214 }
215 }
216
217 $sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
218 $sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
219 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'";
220 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'";
221 $sql .= " WHERE er.resource_id = ".((int) $object->resource_id);
222 $sql .= " AND ac.id <> ".((int) $object->element_id);
223 $sql .= " AND er.busy = 1";
224 $sql .= " AND (";
225
226 // event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
227 $sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
228 // event date end between ac.datep and ac.datep2
229 if (!empty($eventDateEnd)) {
230 $sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
231 }
232 // event date start before ac.datep and event date end after ac.datep2
233 $sql .= " OR (";
234 $sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
235 if (!empty($eventDateEnd)) {
236 $sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
237 }
238 $sql .= ")";
239
240 $sql .= ")";
241 $resql = $db->query($sql);
242 if (!$resql) {
243 $error++;
244 $object->error = $db->lasterror();
245 $object->errors[] = $object->error;
246 } else {
247 if ($db->num_rows($resql) > 0) {
248 // Resource already in use
249 $error++;
250 $object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
251 while ($obj = $db->fetch_object($resql)) {
252 $object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
253 }
254 $object->errors[] = $objstat->error;
255 }
256 $db->free($resql);
257 }
258 }
259
260 if (!$error) {
261 $result = $object->updateElementResource($user);
262 if ($result < 0) {
263 $error++;
264 }
265 }
266
267 if ($error) {
268 setEventMessages($object->error, $object->errors, 'errors');
269 } else {
270 setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs');
271 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
272 exit;
273 }
274 }
275 }
276
277 // Delete a resource linked to an element
278 if ($action == 'confirm_delete_linked_resource' && $user->hasRight('resource', 'delete') && $confirm === 'yes') {
279 $result = $object->delete_resource($lineid, $element);
280
281 if ($result >= 0) {
282 setEventMessages($langs->trans('RessourceLineSuccessfullyDeleted'), null, 'mesgs');
283 header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id);
284 exit;
285 } else {
286 setEventMessages($object->error, $object->errors, 'errors');
287 }
288 }
289}
290
291$parameters = array('resource_id' => $resource_id);
292$reshook = $hookmanager->executeHooks('getElementResources', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
293if ($reshook < 0) {
294 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
295}
296
297
298
299/*
300 * View
301 */
302
303$form = new Form($db);
304
305$pagetitle = $langs->trans('ResourceElementPage');
306$help_url = '';
307llxHeader('', $pagetitle, $help_url, '', 0, 0, '', '', '', 'mod-resource page-element_resource');
308
309$now = dol_now();
310$delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
311
312// Load available resource, declared by modules
313$ret = count($object->available_resources);
314if ($ret == -1) {
315 dol_print_error($db, $object->error);
316 exit;
317}
318if (!$ret) {
319 print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
320} else {
321 // Confirmation suppression resource line
322 if ($action == 'delete_resource') {
323 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);
324 }
325
326
327 // Specific to agenda module
328 if (($element_id || $element_ref) && $element == 'action') {
329 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
330
331 // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
332 $hookmanager->initHooks(array('actioncard', 'globalcard'));
333
334 $act = fetchObjectByElement($element_id, $element, $element_ref);
335 if (is_object($act)) {
336 '@phan-var-force ActionComm $act';
337 $head = actions_prepare_head($act);
338
339 print dol_get_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action');
340
341 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1">';
342 $linkback .= img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="pictoactionview pictofixedwidth"');
343 $linkback .= '<span class="hideonsmartphone">'.$langs->trans("BackToList").'</span>';
344 $linkback .= '</a>';
345
346 // Link to other agenda views
347 $out = '';
348 $out .= '</li><li class="noborder litext">';
349 $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').'">';
350 $out .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictofixedwidth pictoactionview"');
351 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewCal").'</span>';
352 $out .= '</a>';
353 $out .= '</li><li class="noborder litext">';
354 $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').'">';
355 $out .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictofixedwidth pictoactionview"');
356 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewWeek").'</span>';
357 $out .= '</a>';
358 $out .= '</li><li class="noborder litext">';
359 $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').'">';
360 $out .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictofixedwidth pictoactionview"');
361 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewDay").'</span>';
362 $out .= '</a>';
363 $out .= '</li><li class="noborder litext">';
364 $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').'">';
365 $out .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictofixedwidth pictoactionview"');
366 $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewPerUser").'</span>';
367 $out .= '</a>';
368
369 // Add more views from hooks
370 $parameters = array();
371 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
372 if (empty($reshook)) {
373 $out .= $hookmanager->resPrint;
374 } elseif ($reshook > 1) {
375 $out = $hookmanager->resPrint;
376 }
377
378 $linkback .= $out;
379
380 $morehtmlref = '<div class="refidno">';
381 // Thirdparty
382 //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
383 // Project
384 $savobject = $object;
385 $object = $act;
386 if (isModEnabled('project')) {
387 $langs->load("projects");
388 //$morehtmlref .= '<br>';
389 if (0) {
390 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
391 if ($action != 'classify') {
392 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
393 }
394 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
395 } else {
396 if (!empty($object->fk_project)) {
397 $proj = new Project($db);
398 $proj->fetch($object->fk_project);
399 $morehtmlref .= $proj->getNomUrl(1);
400 if ($proj->title) {
401 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
402 }
403 }
404 }
405 }
406 $object = $savobject;
407 $morehtmlref .= '</div>';
408
409 dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
410
411 print '<div class="fichecenter">';
412
413 print '<div class="underbanner clearboth"></div>';
414
415 print '<table class="border tableforfield centpercent">';
416
417 // Type
418 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
419 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
420 print $act->getTypePicto();
421 print $langs->trans("Action".$act->type_code);
422 print '</td></tr>';
423 }
424
425 // Full day event
426 print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent ? 1 : 0, 3).'</td></tr>';
427
428 // Date start
429 print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
430 if (empty($act->fulldayevent)) {
431 print dol_print_date($act->datep, 'dayhour', 'tzuser');
432 } else {
433 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
434 print dol_print_date($act->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
435 }
436 if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) {
437 print img_warning($langs->trans("Late"));
438 }
439 print '</td>';
440 print '</tr>';
441
442 // Date end
443 print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
444 if (empty($act->fulldayevent)) {
445 print dol_print_date($act->datef, 'dayhour', 'tzuser');
446 } else {
447 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
448 print dol_print_date($act->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
449 }
450 if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) {
451 print img_warning($langs->trans("Late"));
452 }
453 print '</td></tr>';
454
455 // Location
456 if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
457 print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
458 }
459
460 // Assigned to
461 print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
462 $listofuserid = array();
463 if (empty($donotclearsession)) {
464 if ($act->userownerid > 0) {
465 $listofuserid[$act->userownerid] = array('id' => $act->userownerid, 'transparency' => $act->transparency); // Owner first
466 }
467 if (!empty($act->userassigned)) { // Now concat assigned users
468 // Restore array with key with same value than param 'id'
469 $tmplist1 = $act->userassigned;
470 $tmplist2 = array();
471 foreach ($tmplist1 as $key => $val) {
472 if ($val['id'] && $val['id'] != $act->userownerid) {
473 $listofuserid[$val['id']] = $val;
474 }
475 }
476 }
477 $_SESSION['assignedtouser'] = json_encode($listofuserid);
478 } else {
479 if (!empty($_SESSION['assignedtouser'])) {
480 $listofuserid = json_decode($_SESSION['assignedtouser'], true);
481 }
482 }
483 $listofcontactid = array(); // not used yet
484 $listofotherid = array(); // not used yet
485 print '<div class="assignedtouser">';
486 print $form->select_dolusers_forevent('view', 'assignedtouser', 1, array(), 0, '', array(), 0, 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
487 print '</div>';
488 /*if (in_array($user->id,array_keys($listofuserid)))
489 {
490 print '<div class="myavailability">';
491 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
492 print '</div>';
493 }*/
494 print ' </td></tr>';
495
496 print '</table>';
497
498 print '</div>';
499
500 print dol_get_fiche_end();
501 }
502 }
503
504 // Specific to thirdparty module
505 if (($element_id || $element_ref) && $element == 'societe') {
506 $socstatic = fetchObjectByElement($element_id, $element, $element_ref);
507 if (is_object($socstatic)) {
508 '@phan-var-force Societe $socstatic';
510 $savobject = $object;
511 $object = $socstatic;
512
513 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
514 $head = societe_prepare_head($socstatic);
515
516 print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
517
518 dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element);
519
520 print '<div class="fichecenter">';
521
522 print '<div class="underbanner clearboth"></div>';
523 print '<table class="border centpercent">';
524
525 // Alias name (commercial, trademark or alias name)
526 print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
527 print $socstatic->name_alias;
528 print "</td></tr>";
529
530 print '</table>';
531
532 print '</div>';
533
534 print dol_get_fiche_end();
535
536 $object = $savobject;
537 }
538 }
539
540 // Specific to fichinter module
541 if (($element_id || $element_ref) && $element == 'fichinter') {
542 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
543
544 $fichinter = new Fichinter($db);
545 $fichinter->fetch($element_id, $element_ref);
546 $fichinter->fetch_thirdparty();
547
548 $usercancreate = $user->hasRight('fichinter', 'creer');
549
550 if (is_object($fichinter)) {
551 $head = fichinter_prepare_head($fichinter);
552 print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
553
554 // Intervention card
555 $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
556
557
558 $morehtmlref = '<div class="refidno">';
559 // Ref customer
560 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', 0, 1);
561 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
562 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', 0, 1);
563 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', null, null, '', 1);
564 // Thirdparty
565 $morehtmlref .= '<br>'.$fichinter->thirdparty->getNomUrl(1, 'customer');
566 // Project
567 if (isModEnabled('project')) {
568 $langs->load("projects");
569 $morehtmlref .= '<br>';
570 if ($usercancreate && 0) {
571 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
572 if ($action != 'classify') {
573 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$fichinter->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
574 }
575 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
576 } else {
577 if (!empty($fichinter->fk_project)) {
578 $proj = new Project($db);
579 $proj->fetch($fichinter->fk_project);
580 $morehtmlref .= $proj->getNomUrl(1);
581 if ($proj->title) {
582 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
583 }
584 }
585 }
586 }
587 $morehtmlref .= '</div>';
588
589 dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
590
591 print dol_get_fiche_end();
592 }
593 }
594
595 // Specific to product/service module
596 if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) {
597 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
598
599 $product = new Product($db);
600 $product->fetch($element_id, $element_ref);
601
602 if (is_object($product)) {
603 $head = product_prepare_head($product);
604 $titre = $langs->trans("CardProduct".$product->type);
605 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
606
607 print dol_get_fiche_head($head, 'resources', $titre, -1, $picto);
608
609 $shownav = 1;
610 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
611 $shownav = 0;
612 }
613 dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
614
615 print dol_get_fiche_end();
616 }
617 }
618
619
620 // hook for other elements linked
621 $parameters = array('element' => $element, 'element_id' => $element_id, 'element_ref' => $element_ref);
622 $reshook = $hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
623 if ($reshook < 0) {
624 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
625 }
626
627
628 //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
629 print '<br>';
630
631 // Show list of resource links
632
633 foreach ($object->available_resources as $modresources => $resources) {
634 $resources = (array) $resources; // To be sure $resources is an array
635 foreach ($resources as $resource_obj) {
636 $element_prop = getElementProperties($resource_obj);
637
638 //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
639
640 $path = '';
641 if (strpos($resource_obj, '@')) {
642 $path .= '/'.$element_prop['module'];
643 }
644
645 $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
646
647 // Output template part (modules that overwrite templates must declare this into descriptor)
648 $defaulttpldir = '/core/tpl';
649 $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
650
651 foreach ($dirtpls as $module => $reldir) {
652 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) {
653 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
654 } else {
655 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
656 }
657 if (empty($conf->file->strict_mode)) {
658 $res = @include $tpl;
659 } else {
660 $res = include $tpl; // for debug
661 }
662 if ($res) {
663 break;
664 }
665 }
666
667 if ($mode != 'add' || $resource_obj != $resource_type) {
668 foreach ($dirtpls as $module => $reldir) {
669 if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) {
670 $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
671 } else {
672 $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
673 }
674 if (empty($conf->file->strict_mode)) {
675 $res = @include $tpl;
676 } else {
677 $res = include $tpl; // for debug
678 }
679 if ($res) {
680 break;
681 }
682 }
683 }
684 }
685 }
686}
687
688// End of page
689llxFooter();
690$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
actions_prepare_head($object)
Prepare array with list of tabs.
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:70
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.
llxFooter()
Footer empty.
Definition document.php:107
fichinter_prepare_head($object)
Prepare array with list of tabs.
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
fetchObjectByElement($element_id, $element_type, $element_ref='', $useCache=0, $maxCacheByType=10)
Fetch an object from its id and element_type Inclusion of classes is automatic.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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.