PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/resource/element_resource.php

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