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