job_agenda.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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/job_agenda.php
  23. * \ingroup hrm
  24. * \brief Tab of events on Job
  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/job.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/hrm/lib/hrm_job.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('hrm', 'other'));
  35. // Get parameters
  36. $id = GETPOST('id', 'int');
  37. $ref = GETPOST('ref', 'alpha');
  38. $action = GETPOST('action', 'aZ09');
  39. $cancel = GETPOST('cancel', 'aZ09');
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. if (GETPOST('actioncode', 'array')) {
  42. $actioncode = GETPOST('actioncode', 'array', 3);
  43. if (!count($actioncode)) {
  44. $actioncode = '0';
  45. }
  46. } else {
  47. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  48. }
  49. $search_rowid = GETPOST('search_rowid');
  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 Job($db);
  69. $extrafields = new ExtraFields($db);
  70. $diroutputmassaction = $conf->hrm->dir_output.'/temp/massgeneration/'.$user->id;
  71. $hookmanager->initHooks(array('jobagenda', '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[!empty($object->entity) ? $object->entity : $conf->entity]."/".$object->id;
  78. }
  79. // Permissions
  80. $permissiontoread = $user->rights->hrm->all->read;
  81. $permissiontoadd = $user->rights->hrm->all->write; // Used by the include of actions_addupdatedelete.inc.php
  82. // Security check (enable the most restrictive one)
  83. //if ($user->socid > 0) accessforbidden();
  84. //if ($user->socid > 0) $socid = $user->socid;
  85. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  86. //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  87. if (empty($conf->hrm->enabled)) accessforbidden();
  88. if (!$permissiontoread) accessforbidden();
  89. /*
  90. * Actions
  91. */
  92. $parameters = array('id'=>$id);
  93. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  94. if ($reshook < 0) {
  95. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  96. }
  97. if (empty($reshook)) {
  98. // Cancel
  99. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  100. header("Location: ".$backtopage);
  101. exit;
  102. }
  103. // Purge search criteria
  104. 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
  105. $actioncode = '';
  106. $search_agenda_label = '';
  107. }
  108. }
  109. /*
  110. * View
  111. */
  112. $form = new Form($db);
  113. if ($object->id > 0) {
  114. $title = $langs->trans("Agenda");
  115. //if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
  116. $help_url = 'EN:Module_Agenda_En|DE:Modul_Terminplanung';
  117. llxHeader('', $title, $help_url);
  118. if (isModEnabled('notification')) {
  119. $langs->load("mails");
  120. }
  121. $head = jobPrepareHead($object);
  122. print dol_get_fiche_head($head, 'agenda', $langs->trans("Agenda"), -1, $object->picto);
  123. // Object card
  124. // ------------------------------------------------------------
  125. $linkback = '<a href="'.dol_buildpath('/hrm/job_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  126. $morehtmlref = '<div class="refid">';
  127. $morehtmlref.= $object->label;
  128. $morehtmlref .= '</div>';
  129. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
  130. print '<div class="fichecenter">';
  131. print '<div class="underbanner clearboth"></div>';
  132. $object->info($object->id);
  133. dol_print_object_info($object, 1);
  134. print '</div>';
  135. print dol_get_fiche_end();
  136. // Actions buttons
  137. $objthirdparty = $object;
  138. $objcon = new stdClass();
  139. $out = '&origin='.urlencode($object->element.'@'.$object->module).'&originid='.urlencode($object->id);
  140. $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id;
  141. $out .= '&backtopage='.urlencode($urlbacktopage);
  142. $permok = $user->rights->agenda->myactions->create;
  143. if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok) {
  144. //$out.='<a href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create';
  145. if (get_class($objthirdparty) == 'Societe') {
  146. $out .= '&socid='.urlencode($objthirdparty->id);
  147. }
  148. $out .= (!empty($objcon->id) ? '&contactid='.urlencode($objcon->id) : '');
  149. //$out.=$langs->trans("AddAnAction").' ';
  150. //$out.=img_picto($langs->trans("AddAnAction"),'filenew');
  151. //$out.="</a>";
  152. }
  153. if (isModEnabled('agenda')) {
  154. if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
  155. $newcardbutton = '';
  156. $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out);
  157. }
  158. }
  159. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  160. $param = '&id='.$object->id.'&socid='.(!empty($socid) ? '&socid='.$socid : '');
  161. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  162. $param .= '&contextpage='.urlencode($contextpage);
  163. }
  164. if ($limit > 0 && $limit != $conf->liste_limit) {
  165. $param .= '&limit='.((int) $limit);
  166. }
  167. print load_fiche_titre($langs->trans("ActionsOnJob"), $newcardbutton, '');
  168. // List of all actions
  169. $filters = array();
  170. $filters['search_agenda_label'] = $search_agenda_label;
  171. $filters['search_rowid'] = $search_rowid;
  172. // TODO Replace this with same code than into list.php
  173. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, $object->module);
  174. }
  175. }
  176. // End of page
  177. llxFooter();
  178. $db->close();