element_resource.php 27 KB

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