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