dolibarr  20.0.0-beta
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
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
34 if (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 }
38 if (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 
72 if (empty($mandatory)) {
73  $mandatory = 0;
74 }
75 if (empty($busy)) {
76  $busy = 0;
77 }
78 
79 if ($socid > 0) { // Special for thirdparty
80  $element_id = $socid;
81  $element = 'societe';
82 }
83 
84 if (!$user->hasRight('resource', 'read')) {
86 }
87 
88 // Permission is not permission on resources. We just make link here on objects.
89 if ($element == 'action') {
90  $result = restrictedArea($user, 'agenda', $element_id, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
91 }
92 if ($element == 'fichinter') {
93  $result = restrictedArea($user, 'ficheinter', $element_id, 'fichinter');
94 }
95 if ($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
109 if ($reshook < 0) {
110  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111 }
112 
113 if (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
291 if ($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 llxHeader('', $pagetitle, '');
305 
306 $now = dol_now();
307 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
308 
309 // Load available resource, declared by modules
310 $ret = count($object->available_resources);
311 if ($ret == -1) {
312  dol_print_error($db, $object->error);
313  exit;
314 }
315 if (!$ret) {
316  print '<div class="warning">'.$langs->trans('NoResourceInDatabase').'</div>';
317 } else {
318  // Confirmation suppression resource line
319  if ($action == 'delete_resource') {
320  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);
321  }
322 
323 
324  // Specific to agenda module
325  if (($element_id || $element_ref) && $element == 'action') {
326  require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
327 
328  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
329  $hookmanager->initHooks(array('actioncard', 'globalcard'));
330 
331  $act = fetchObjectByElement($element_id, $element, $element_ref);
332  if (is_object($act)) {
333  $head = actions_prepare_head($act);
334 
335  print dol_get_fiche_head($head, 'resources', $langs->trans("Action"), -1, 'action');
336 
337  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1">';
338  $linkback .= img_picto($langs->trans("BackToList"), 'object_calendarlist', 'class="pictoactionview pictofixedwidth"');
339  $linkback .= '<span class="hideonsmartphone">'.$langs->trans("BackToList").'</span>';
340  $linkback .= '</a>';
341 
342  // Link to other agenda views
343  $out = '';
344  $out .= '</li><li class="noborder litext">';
345  $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').'">';
346  $out .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictofixedwidth pictoactionview"');
347  $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewCal").'</span>';
348  $out .= '</a>';
349  $out .= '</li><li class="noborder litext">';
350  $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').'">';
351  $out .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictofixedwidth pictoactionview"');
352  $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewWeek").'</span>';
353  $out .= '</a>';
354  $out .= '</li><li class="noborder litext">';
355  $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').'">';
356  $out .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictofixedwidth pictoactionview"');
357  $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewDay").'</span>';
358  $out .= '</a>';
359  $out .= '</li><li class="noborder litext">';
360  $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').'">';
361  $out .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictofixedwidth pictoactionview"');
362  $out .= '<span class="hideonsmartphone">'.$langs->trans("ViewPerUser").'</span>';
363  $out .= '</a>';
364 
365  // Add more views from hooks
366  $parameters = array();
367  $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
368  if (empty($reshook)) {
369  $out .= $hookmanager->resPrint;
370  } elseif ($reshook > 1) {
371  $out = $hookmanager->resPrint;
372  }
373 
374  $linkback .= $out;
375 
376  $morehtmlref = '<div class="refidno">';
377  // Thirdparty
378  //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
379  // Project
380  $savobject = $object;
381  $object = $act;
382  if (isModEnabled('project')) {
383  $langs->load("projects");
384  //$morehtmlref .= '<br>';
385  if (0) {
386  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
387  if ($action != 'classify') {
388  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
389  }
390  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
391  } else {
392  if (!empty($object->fk_project)) {
393  $proj = new Project($db);
394  $proj->fetch($object->fk_project);
395  $morehtmlref .= $proj->getNomUrl(1);
396  if ($proj->title) {
397  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
398  }
399  }
400  }
401  }
402  $object = $savobject;
403  $morehtmlref .= '</div>';
404 
405  dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
406 
407  print '<div class="fichecenter">';
408 
409  print '<div class="underbanner clearboth"></div>';
410 
411  print '<table class="border tableforfield centpercent">';
412 
413  // Type
414  if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
415  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
416  print $act->getTypePicto();
417  print $langs->trans("Action".$act->type_code);
418  print '</td></tr>';
419  }
420 
421  // Full day event
422  print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent ? 1 : 0, 3).'</td></tr>';
423 
424  // Date start
425  print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
426  if (empty($act->fulldayevent)) {
427  print dol_print_date($act->datep, 'dayhour', 'tzuser');
428  } else {
429  $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
430  print dol_print_date($act->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
431  }
432  if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) {
433  print img_warning($langs->trans("Late"));
434  }
435  print '</td>';
436  print '</tr>';
437 
438  // Date end
439  print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
440  if (empty($act->fulldayevent)) {
441  print dol_print_date($act->datef, 'dayhour', 'tzuser');
442  } else {
443  $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
444  print dol_print_date($act->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
445  }
446  if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) {
447  print img_warning($langs->trans("Late"));
448  }
449  print '</td></tr>';
450 
451  // Location
452  if (!getDolGlobalString('AGENDA_DISABLE_LOCATION')) {
453  print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
454  }
455 
456  // Assigned to
457  print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
458  $listofuserid = array();
459  if (empty($donotclearsession)) {
460  if ($act->userownerid > 0) {
461  $listofuserid[$act->userownerid] = array('id'=>$act->userownerid, 'transparency'=>$act->transparency); // Owner first
462  }
463  if (!empty($act->userassigned)) { // Now concat assigned users
464  // Restore array with key with same value than param 'id'
465  $tmplist1 = $act->userassigned;
466  $tmplist2 = array();
467  foreach ($tmplist1 as $key => $val) {
468  if ($val['id'] && $val['id'] != $act->userownerid) {
469  $listofuserid[$val['id']] = $val;
470  }
471  }
472  }
473  $_SESSION['assignedtouser'] = json_encode($listofuserid);
474  } else {
475  if (!empty($_SESSION['assignedtouser'])) {
476  $listofuserid = json_decode($_SESSION['assignedtouser'], true);
477  }
478  }
479  $listofcontactid = array(); // not used yet
480  $listofotherid = array(); // not used yet
481  print '<div class="assignedtouser">';
482  print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
483  print '</div>';
484  /*if (in_array($user->id,array_keys($listofuserid)))
485  {
486  print '<div class="myavailability">';
487  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
488  print '</div>';
489  }*/
490  print ' </td></tr>';
491 
492  print '</table>';
493 
494  print '</div>';
495 
496  print dol_get_fiche_end();
497  }
498  }
499 
500  // Specific to thirdparty module
501  if (($element_id || $element_ref) && $element == 'societe') {
502  $socstatic = fetchObjectByElement($element_id, $element, $element_ref);
503  if (is_object($socstatic)) {
504  $savobject = $object;
505  $object = $socstatic;
506 
507  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
508  $head = societe_prepare_head($socstatic);
509 
510  print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
511 
512  dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element);
513 
514  print '<div class="fichecenter">';
515 
516  print '<div class="underbanner clearboth"></div>';
517  print '<table class="border centpercent">';
518 
519  // Alias name (commercial, trademark or alias name)
520  print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
521  print $socstatic->name_alias;
522  print "</td></tr>";
523 
524  print '</table>';
525 
526  print '</div>';
527 
528  print dol_get_fiche_end();
529 
530  $object = $savobject;
531  }
532  }
533 
534  // Specific to fichinter module
535  if (($element_id || $element_ref) && $element == 'fichinter') {
536  require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
537 
538  $fichinter = new Fichinter($db);
539  $fichinter->fetch($element_id, $element_ref);
540  $fichinter->fetch_thirdparty();
541 
542  $usercancreate = $user->hasRight('fichinter', 'creer');
543 
544  if (is_object($fichinter)) {
545  $head = fichinter_prepare_head($fichinter);
546  print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
547 
548  // Intervention card
549  $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
550 
551 
552  $morehtmlref = '<div class="refidno">';
553  // Ref customer
554  //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', 0, 1);
555  //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
556  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', 0, 1);
557  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', null, null, '', 1);
558  // Thirdparty
559  $morehtmlref .= '<br>'.$fichinter->thirdparty->getNomUrl(1, 'customer');
560  // Project
561  if (isModEnabled('project')) {
562  $langs->load("projects");
563  $morehtmlref .= '<br>';
564  if ($usercancreate && 0) {
565  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
566  if ($action != 'classify') {
567  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$fichinter->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
568  }
569  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
570  } else {
571  if (!empty($fichinter->fk_project)) {
572  $proj = new Project($db);
573  $proj->fetch($fichinter->fk_project);
574  $morehtmlref .= $proj->getNomUrl(1);
575  if ($proj->title) {
576  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
577  }
578  }
579  }
580  }
581  $morehtmlref .= '</div>';
582 
583  dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
584 
585  print dol_get_fiche_end();
586  }
587  }
588 
589  // Specific to product/service module
590  if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) {
591  require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
592 
593  $product = new Product($db);
594  $product->fetch($element_id, $element_ref);
595 
596  if (is_object($product)) {
597  $head = product_prepare_head($product);
598  $titre = $langs->trans("CardProduct".$product->type);
599  $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
600 
601  print dol_get_fiche_head($head, 'resources', $titre, -1, $picto);
602 
603  $shownav = 1;
604  if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
605  $shownav = 0;
606  }
607  dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
608 
609  print dol_get_fiche_end();
610  }
611  }
612 
613 
614  // hook for other elements linked
615  $parameters = array('element'=>$element, 'element_id'=>$element_id, 'element_ref'=>$element_ref);
616  $reshook = $hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
617  if ($reshook < 0) {
618  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
619  }
620 
621 
622  //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
623  print '<br>';
624 
625  // Show list of resource links
626 
627  foreach ($object->available_resources as $modresources => $resources) {
628  $resources = (array) $resources; // To be sure $resources is an array
629  foreach ($resources as $resource_obj) {
630  $element_prop = getElementProperties($resource_obj);
631 
632  //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
633 
634  $path = '';
635  if (strpos($resource_obj, '@')) {
636  $path .= '/'.$element_prop['module'];
637  }
638 
639  $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
640 
641  // Output template part (modules that overwrite templates must declare this into descriptor)
642  $defaulttpldir = '/core/tpl';
643  $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
644 
645  foreach ($dirtpls as $module => $reldir) {
646  if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) {
647  $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
648  } else {
649  $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
650  }
651  if (empty($conf->file->strict_mode)) {
652  $res = @include $tpl;
653  } else {
654  $res = include $tpl; // for debug
655  }
656  if ($res) {
657  break;
658  }
659  }
660 
661  if ($mode != 'add' || $resource_obj != $resource_type) {
662  foreach ($dirtpls as $module => $reldir) {
663  if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) {
664  $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
665  } else {
666  $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
667  }
668  if (empty($conf->file->strict_mode)) {
669  $res = @include $tpl;
670  } else {
671  $res = include $tpl; // for debug
672  }
673  if ($res) {
674  break;
675  }
676  }
677  }
678  }
679  }
680 }
681 
682 // End of page
683 llxFooter();
684 $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.
Definition: agenda.lib.php:453
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.
Definition: company.lib.php:43
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
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.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:37
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.