element_resource.php 26 KB

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