element_resource.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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->rights->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 (!empty($conf->global->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->rights->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 (!empty($conf->global->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->rights->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 = img_picto($langs->trans("BackToList"), 'object_list', 'class="hideonsmartphone pictoactionview"');
  291. $linkback .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list">'.$langs->trans("BackToList").'</a>';
  292. // Link to other agenda views
  293. $out = '';
  294. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="hideonsmartphone pictoactionview"');
  295. $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>';
  296. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="hideonsmartphone pictoactionview"');
  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').'">'.$langs->trans("ViewCal").'</a>';
  298. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="hideonsmartphone pictoactionview"');
  299. $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>';
  300. $out .= '</li><li class="noborder litext">'.img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="hideonsmartphone pictoactionview"');
  301. $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>';
  302. // Add more views from hooks
  303. $parameters = array();
  304. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  305. if (empty($reshook)) {
  306. $out .= $hookmanager->resPrint;
  307. } elseif ($reshook > 1) {
  308. $out = $hookmanager->resPrint;
  309. }
  310. $linkback .= $out;
  311. $morehtmlref = '<div class="refidno">';
  312. // Thirdparty
  313. //$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
  314. // Project
  315. $savobject = $object;
  316. $object = $act;
  317. if (isModEnabled('project')) {
  318. $langs->load("projects");
  319. //$morehtmlref .= '<br>';
  320. if (0) {
  321. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  322. if ($action != 'classify') {
  323. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  324. }
  325. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  326. } else {
  327. if (!empty($object->fk_project)) {
  328. $proj = new Project($db);
  329. $proj->fetch($object->fk_project);
  330. $morehtmlref .= $proj->getNomUrl(1);
  331. if ($proj->title) {
  332. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  333. }
  334. }
  335. }
  336. }
  337. $object = $savobject;
  338. $morehtmlref .= '</div>';
  339. dol_banner_tab($act, 'element_id', $linkback, ($user->socid ? 0 : 1), 'id', 'ref', $morehtmlref, '&element='.$element, 0, '', '');
  340. print '<div class="fichecenter">';
  341. print '<div class="underbanner clearboth"></div>';
  342. print '<table class="border tableforfield centpercent">';
  343. // Type
  344. if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  345. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
  346. print $act->getTypePicto();
  347. print $langs->trans("Action".$act->type_code);
  348. print '</td></tr>';
  349. }
  350. // Full day event
  351. print '<tr><td class="titlefield">'.$langs->trans("EventOnFullDay").'</td><td colspan="3">'.yn($act->fulldayevent ? 1 : 0, 3).'</td></tr>';
  352. // Date start
  353. print '<tr><td>'.$langs->trans("DateActionStart").'</td><td colspan="3">';
  354. if (empty($act->fulldayevent)) {
  355. print dol_print_date($act->datep, 'dayhour', 'tzuser');
  356. } else {
  357. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  358. print dol_print_date($act->datep, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  359. }
  360. if ($act->percentage == 0 && $act->datep && $act->datep < ($now - $delay_warning)) {
  361. print img_warning($langs->trans("Late"));
  362. }
  363. print '</td>';
  364. print '</tr>';
  365. // Date end
  366. print '<tr><td>'.$langs->trans("DateActionEnd").'</td><td colspan="3">';
  367. if (empty($act->fulldayevent)) {
  368. print dol_print_date($act->datef, 'dayhour', 'tzuser');
  369. } else {
  370. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  371. print dol_print_date($act->datef, 'day', ($tzforfullday ? $tzforfullday : 'tzuser'));
  372. }
  373. if ($act->percentage > 0 && $act->percentage < 100 && $act->datef && $act->datef < ($now - $delay_warning)) {
  374. print img_warning($langs->trans("Late"));
  375. }
  376. print '</td></tr>';
  377. // Location
  378. if (empty($conf->global->AGENDA_DISABLE_LOCATION)) {
  379. print '<tr><td>'.$langs->trans("Location").'</td><td colspan="3">'.$act->location.'</td></tr>';
  380. }
  381. // Assigned to
  382. print '<tr><td class="nowrap">'.$langs->trans("ActionAffectedTo").'</td><td colspan="3">';
  383. $listofuserid = array();
  384. if (empty($donotclearsession)) {
  385. if ($act->userownerid > 0) {
  386. $listofuserid[$act->userownerid] = array('id'=>$act->userownerid, 'transparency'=>$act->transparency); // Owner first
  387. }
  388. if (!empty($act->userassigned)) { // Now concat assigned users
  389. // Restore array with key with same value than param 'id'
  390. $tmplist1 = $act->userassigned; $tmplist2 = array();
  391. foreach ($tmplist1 as $key => $val) {
  392. if ($val['id'] && $val['id'] != $act->userownerid) {
  393. $listofuserid[$val['id']] = $val;
  394. }
  395. }
  396. }
  397. $_SESSION['assignedtouser'] = json_encode($listofuserid);
  398. } else {
  399. if (!empty($_SESSION['assignedtouser'])) {
  400. $listofuserid = json_decode($_SESSION['assignedtouser'], true);
  401. }
  402. }
  403. $listofcontactid = array(); // not used yet
  404. $listofotherid = array(); // not used yet
  405. print '<div class="assignedtouser">';
  406. print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', ($act->datep != $act->datef) ? 1 : 0, $listofuserid, $listofcontactid, $listofotherid);
  407. print '</div>';
  408. /*if (in_array($user->id,array_keys($listofuserid)))
  409. {
  410. print '<div class="myavailability">';
  411. 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
  412. print '</div>';
  413. }*/
  414. print ' </td></tr>';
  415. print '</table>';
  416. print '</div>';
  417. print dol_get_fiche_end();
  418. }
  419. }
  420. // Specific to thirdparty module
  421. if (($element_id || $element_ref) && $element == 'societe') {
  422. $socstatic = fetchObjectByElement($element_id, $element, $element_ref);
  423. if (is_object($socstatic)) {
  424. $savobject = $object;
  425. $object = $socstatic;
  426. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  427. $head = societe_prepare_head($socstatic);
  428. print dol_get_fiche_head($head, 'resources', $langs->trans("ThirdParty"), -1, 'company');
  429. dol_banner_tab($socstatic, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom', '', '&element='.$element);
  430. print '<div class="fichecenter">';
  431. print '<div class="underbanner clearboth"></div>';
  432. print '<table class="border centpercent">';
  433. // Alias name (commercial, trademark or alias name)
  434. print '<tr><td class="titlefield">'.$langs->trans('AliasNames').'</td><td colspan="3">';
  435. print $socstatic->name_alias;
  436. print "</td></tr>";
  437. print '</table>';
  438. print '</div>';
  439. print dol_get_fiche_end();
  440. $object = $savobject;
  441. }
  442. }
  443. // Specific to fichinter module
  444. if (($element_id || $element_ref) && $element == 'fichinter') {
  445. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  446. $fichinter = new Fichinter($db);
  447. $fichinter->fetch($element_id, $element_ref);
  448. $fichinter->fetch_thirdparty();
  449. $usercancreate = $user->hasRight('fichinter', 'creer');
  450. if (is_object($fichinter)) {
  451. $head = fichinter_prepare_head($fichinter);
  452. print dol_get_fiche_head($head, 'resource', $langs->trans("InterventionCard"), -1, 'intervention');
  453. // Intervention card
  454. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  455. $morehtmlref = '<div class="refidno">';
  456. // Ref customer
  457. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', 0, 1);
  458. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, $user->rights->ficheinter->creer, 'string', '', null, null, '', 1);
  459. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', 0, 1);
  460. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $fichinter->ref_client, $fichinter, 0, 'string', '', null, null, '', 1);
  461. // Thirdparty
  462. $morehtmlref .= '<br>'.$fichinter->thirdparty->getNomUrl(1, 'customer');
  463. // Project
  464. if (isModEnabled('project')) {
  465. $langs->load("projects");
  466. $morehtmlref .= '<br>';
  467. if ($usercancreate && 0) {
  468. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  469. if ($action != 'classify') {
  470. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$fichinter->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  471. }
  472. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  473. } else {
  474. if (!empty($fichinter->fk_project)) {
  475. $proj = new Project($db);
  476. $proj->fetch($fichinter->fk_project);
  477. $morehtmlref .= $proj->getNomUrl(1);
  478. if ($proj->title) {
  479. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  480. }
  481. }
  482. }
  483. }
  484. $morehtmlref .= '</div>';
  485. dol_banner_tab($fichinter, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '&element='.$element, 0, '', '', 1);
  486. print dol_get_fiche_end();
  487. }
  488. }
  489. // Specific to product/service module
  490. if (($element_id || $element_ref) && ($element == 'product' || $element == 'service')) {
  491. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  492. $product = new Product($db);
  493. $product->fetch($element_id, $element_ref);
  494. if (is_object($product)) {
  495. $head = product_prepare_head($product);
  496. $titre = $langs->trans("CardProduct".$product->type);
  497. $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
  498. print dol_get_fiche_head($head, 'resources', $titre, -1, $picto);
  499. $shownav = 1;
  500. if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
  501. $shownav = 0;
  502. }
  503. dol_banner_tab($product, 'ref', '', $shownav, 'ref', 'ref', '', '&element='.$element);
  504. print dol_get_fiche_end();
  505. }
  506. }
  507. // hook for other elements linked
  508. $parameters = array('element'=>$element, 'element_id'=>$element_id, 'element_ref'=>$element_ref);
  509. $reshook = $hookmanager->executeHooks('printElementTab', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  510. if ($reshook < 0) {
  511. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  512. }
  513. //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'','');
  514. print '<br>';
  515. // Show list of resource links
  516. foreach ($object->available_resources as $modresources => $resources) {
  517. $resources = (array) $resources; // To be sure $resources is an array
  518. foreach ($resources as $resource_obj) {
  519. $element_prop = getElementProperties($resource_obj);
  520. //print '/'.$modresources.'/class/'.$resource_obj.'.class.php<br>';
  521. $path = '';
  522. if (strpos($resource_obj, '@')) {
  523. $path .= '/'.$element_prop['module'];
  524. }
  525. $linked_resources = $object->getElementResources($element, $element_id, $resource_obj);
  526. // Output template part (modules that overwrite templates must declare this into descriptor)
  527. $defaulttpldir = '/core/tpl';
  528. $dirtpls = array_merge($conf->modules_parts['tpl'], array($defaulttpldir), array($path.$defaulttpldir));
  529. foreach ($dirtpls as $module => $reldir) {
  530. if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php'))) {
  531. $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_add.tpl.php');
  532. } else {
  533. $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_add.tpl.php';
  534. }
  535. if (empty($conf->file->strict_mode)) {
  536. $res = @include $tpl;
  537. } else {
  538. $res = include $tpl; // for debug
  539. }
  540. if ($res) {
  541. break;
  542. }
  543. }
  544. if ($mode != 'add' || $resource_obj != $resource_type) {
  545. foreach ($dirtpls as $module => $reldir) {
  546. if (file_exists(dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php'))) {
  547. $tpl = dol_buildpath($reldir.'/resource_'.$element_prop['element'].'_view.tpl.php');
  548. } else {
  549. $tpl = DOL_DOCUMENT_ROOT.$reldir.'/resource_view.tpl.php';
  550. }
  551. if (empty($conf->file->strict_mode)) {
  552. $res = @include $tpl;
  553. } else {
  554. $res = include $tpl; // for debug
  555. }
  556. if ($res) {
  557. break;
  558. }
  559. }
  560. }
  561. }
  562. }
  563. }
  564. // End of page
  565. llxFooter();
  566. $db->close();