PageRenderTime 50ms CodeModel.GetById 11ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/resource/element_resource.php

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