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