PageRenderTime 72ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

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