position_agenda.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 htdocs/hrm/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' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  49. }
  50. $search_rowid = GETPOST('search_rowid');
  51. $search_agenda_label = GETPOST('search_agenda_label');
  52. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  53. $sortfield = GETPOST('sortfield', 'aZ09comma');
  54. $sortorder = GETPOST('sortorder', 'aZ09comma');
  55. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  56. if (empty($page) || $page == -1) {
  57. $page = 0;
  58. } // If $page is not defined, or '' or -1
  59. $offset = $limit * $page;
  60. $pageprev = $page - 1;
  61. $pagenext = $page + 1;
  62. if (!$sortfield) {
  63. $sortfield = 'a.datep,a.id';
  64. }
  65. if (!$sortorder) {
  66. $sortorder = 'DESC,DESC';
  67. }
  68. // Initialize technical objects
  69. $object = new Position($db);
  70. $extrafields = new ExtraFields($db);
  71. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  72. $hookmanager->initHooks(array('positionagenda', 'globalcard')); // Note that conf->hooks_modules contains array
  73. // Fetch optionals attributes and labels
  74. $extrafields->fetch_name_optionals_label($object->table_element);
  75. // Load object
  76. 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
  77. if ($id > 0 || !empty($ref)) {
  78. $upload_dir = $conf->hrm->multidir_output[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
  79. }
  80. // Permissions
  81. $permissiontoread = $user->rights->hrm->all->read;
  82. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
  83. // Security check (enable the most restrictive one)
  84. //if ($user->socid > 0) accessforbidden();
  85. //if ($user->socid > 0) $socid = $user->socid;
  86. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  87. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  88. if (empty($conf->hrm->enabled)) accessforbidden();
  89. if (!$permissiontoread) accessforbidden();
  90. /*
  91. * Actions
  92. */
  93. $parameters = array('id'=>$id);
  94. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  95. if ($reshook < 0) {
  96. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  97. }
  98. if (empty($reshook)) {
  99. // Cancel
  100. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  101. header("Location: ".$backtopage);
  102. exit;
  103. }
  104. // Purge search criteria
  105. 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
  106. $actioncode = '';
  107. $search_agenda_label = '';
  108. }
  109. }
  110. /*
  111. * View
  112. */
  113. $form = new Form($db);
  114. if ($object->id > 0) {
  115. $title = $langs->trans("Agenda");
  116. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  117. $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
  118. llxHeader('', $title, $help_url);
  119. if (isModEnabled('notification')) {
  120. $langs->load("mails");
  121. }
  122. $head = positionCardPrepareHead($object);
  123. print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
  124. // Object card
  125. // ------------------------------------------------------------
  126. $linkback = '<a href="'.dol_buildpath('/hrm/position_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  127. $morehtmlref = '<div class="refidno">';
  128. $u_position = new User(($db));
  129. $u_position->fetch($object->fk_user);
  130. $morehtmlref .= ($u_position->id > 0 ? $u_position->getNomUrl(1) : $langs->trans('Employee').' : ');
  131. $job = new Job($db);
  132. $job->fetch($object->fk_job);
  133. $morehtmlref .= '<br>'.$langs->trans('JobProfile').' : '.$job->getNomUrl(1);
  134. $morehtmlref .= '</div>';
  135. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  136. print '<div class="fichecenter">';
  137. print '<div class="underbanner clearboth"></div>';
  138. $object->info($object->id);
  139. dol_print_object_info($object, 1);
  140. print '</div>';
  141. print dol_get_fiche_end();
  142. // Actions buttons
  143. $objthirdparty = $object;
  144. $objcon = new stdClass();
  145. $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
  146. $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  147. $out .= '&backtopage='.urlencode($urlbacktopage);
  148. $permok = $user->hasRight('agenda', 'myactions', 'create');
  149. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  150. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  151. if (get_class($objthirdparty) == 'Societe') {
  152. $out .= '&socid='.urlencode($objthirdparty->id);
  153. }
  154. $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '');
  155. //$out.=$langs->trans("AddAnAction").' ';
  156. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  157. //$out.="</a>";
  158. }
  159. print '<div class="tabsAction">';
  160. if (isModEnabled('agenda')) {
  161. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  162. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out.'">'.$langs->trans("AddAction").'</a>';
  163. } else {
  164. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("AddAction").'</a>';
  165. }
  166. }
  167. print '</div>';
  168. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  169. $param = '&id='.$object->id.'&socid='.(!empty($socid) ? '&socid='.$socid : '');
  170. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  171. $param .= '&contextpage='.urlencode($contextpage);
  172. }
  173. if ($limit > 0 && $limit != $conf->liste_limit) {
  174. $param .= '&limit='.((int) $limit);
  175. }
  176. //print load_fiche_titre($langs->trans("ActionsOnPosition"), '', '');
  177. // List of all actions
  178. $filters = array();
  179. $filters['search_agenda_label'] = $search_agenda_label;
  180. $filters['search_rowid'] = $search_rowid;
  181. $object->fields['label']=array(); // Usefull to get only agenda events linked to position (this object doesn't need label of ref field, but show_actions_done() needs it to work correctly)
  182. // TODO Replace this with same code than into list.php
  183. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
  184. }
  185. }
  186. // End of page
  187. llxFooter();
  188. $db->close();