position_agenda.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) 2021 Greg Rastklan <greg.rastklan@atm-consulting.fr>
  5. * Copyright (C) 2021 Jean-Pascal BOUDET <jean-pascal.boudet@atm-consulting.fr>
  6. * Copyright (C) 2021 Grégory BLEMAND <gregory.blemand@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file position_agenda.php
  23. * \ingroup hrm
  24. * \brief Tab of events on Position
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/hrm/class/position.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/hrm/lib/hrm_position.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/hrm/class/job.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("hrm", "other"));
  36. // Get parameters
  37. $id = GETPOST('id', 'int');
  38. $ref = GETPOST('ref', 'alpha');
  39. $action = GETPOST('action', 'aZ09');
  40. $cancel = GETPOST('cancel', 'aZ09');
  41. $backtopage = GETPOST('backtopage', 'alpha');
  42. if (GETPOST('actioncode', 'array')) {
  43. $actioncode = GETPOST('actioncode', 'array', 3);
  44. if (!count($actioncode)) {
  45. $actioncode = '0';
  46. }
  47. } else {
  48. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT));
  49. }
  50. $search_agenda_label = GETPOST('search_agenda_label');
  51. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page == -1) {
  56. $page = 0;
  57. } // If $page is not defined, or '' or -1
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (!$sortfield) {
  62. $sortfield = 'a.datep,a.id';
  63. }
  64. if (!$sortorder) {
  65. $sortorder = 'DESC,DESC';
  66. }
  67. // Initialize technical objects
  68. $object = new Position($db);
  69. $extrafields = new ExtraFields($db);
  70. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  71. $hookmanager->initHooks(array('positionagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  72. // Fetch optionals attributes and labels
  73. $extrafields->fetch_name_optionals_label($object->table_element);
  74. // Load object
  75. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  76. if ($id > 0 || !empty($ref)) {
  77. $upload_dir = $conf->hrm->multidir_output[$object->entity]."/".$object->id;
  78. }
  79. $permissiontoread = $user->rights->hrm->all->read;
  80. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
  81. // Security check (enable the most restrictive one)
  82. //if ($user->socid > 0) accessforbidden();
  83. //if ($user->socid > 0) $socid = $user->socid;
  84. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  85. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  86. if (empty($conf->hrm->enabled)) accessforbidden();
  87. if (!$permissiontoread) accessforbidden();
  88. /*
  89. * Actions
  90. */
  91. $parameters = array('id'=>$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. // Cancel
  98. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  99. header("Location: ".$backtopage);
  100. exit;
  101. }
  102. // Purge search criteria
  103. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  104. $actioncode = '';
  105. $search_agenda_label = '';
  106. }
  107. }
  108. /*
  109. * View
  110. */
  111. $form = new Form($db);
  112. if ($object->id > 0) {
  113. $title = $langs->trans("Agenda");
  114. //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  115. $help_url = 'EN:Module_Agenda_En';
  116. llxHeader('', $title, $help_url);
  117. if (!empty($conf->notification->enabled)) {
  118. $langs->load("mails");
  119. }
  120. $head = PositionCardPrepareHead($object);
  121. print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
  122. // Object card
  123. // ------------------------------------------------------------
  124. $linkback = '<a href="'.dol_buildpath('/hrm/position_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  125. $morehtmlref = '<div class="refidno">';
  126. $u_position = new User(($db));
  127. $u_position->fetch($object->fk_user);
  128. $morehtmlref .= $langs->trans('Employee').' : '.$u_position->getNomUrl(1);
  129. $job = new Job($db);
  130. $job->fetch($object->fk_job);
  131. $morehtmlref .= '<br>'.$langs->trans('Job').' : '.$job->getNomUrl(1);
  132. $morehtmlref .= '</div>';
  133. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  134. print '<div class="fichecenter">';
  135. print '<div class="underbanner clearboth"></div>';
  136. $object->info($object->id);
  137. dol_print_object_info($object, 1);
  138. print '</div>';
  139. print dol_get_fiche_end();
  140. // Actions buttons
  141. $objthirdparty = $object;
  142. $objcon = new stdClass();
  143. $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
  144. $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  145. $out .= '&backtopage='.urlencode($urlbacktopage);
  146. $permok = $user->rights->agenda->myactions->create;
  147. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  148. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  149. if (get_class($objthirdparty) == 'Societe') {
  150. $out .= '&socid='.urlencode($objthirdparty->id);
  151. }
  152. $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '').'&percentage=-1';
  153. //$out.=$langs->trans("AddAnAction").' ';
  154. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  155. //$out.="</a>";
  156. }
  157. print '<div class="tabsAction">';
  158. if (!empty($conf->agenda->enabled)) {
  159. if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) {
  160. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  161. } else {
  162. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  163. }
  164. }
  165. print '</div>';
  166. if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  167. $param = '&id='.$object->id.'&socid='.$socid;
  168. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  169. $param .= '&contextpage='.urlencode($contextpage);
  170. }
  171. if ($limit > 0 && $limit != $conf->liste_limit) {
  172. $param .= '&limit='.urlencode($limit);
  173. }
  174. //print load_fiche_titre($langs->trans("ActionsOnPosition"), '', '');
  175. // List of all actions
  176. $filters = array();
  177. $filters['search_agenda_label'] = $search_agenda_label;
  178. $object->fields['label']=array(); // Usefull to get only get agenda events linked to position (this object doesn't need label of ref field, but show_actions_done() needs it to work correctly)
  179. // TODO Replace this with same code than into list.php
  180. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
  181. }
  182. }
  183. // End of page
  184. llxFooter();
  185. $db->close();