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