careers.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. $allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
  11. api_protect_admin_script($allowCareer);
  12. // Add the JS needed to use the jqgrid
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. // setting breadcrumbs
  15. $interbreadcrumb[] = [
  16. 'url' => 'index.php',
  17. 'name' => get_lang('Administration'),
  18. ];
  19. $interbreadcrumb[] = [
  20. 'url' => 'career_dashboard.php',
  21. 'name' => get_lang('Careers and promotions'),
  22. ];
  23. $action = isset($_GET['action']) ? $_GET['action'] : null;
  24. $check = Security::check_token('request');
  25. $token = Security::get_token();
  26. if ($action == 'add') {
  27. $interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
  28. $tool_name = get_lang('Add');
  29. } elseif ($action == 'edit') {
  30. $interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
  31. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  32. $tool_name = get_lang('Edit');
  33. } else {
  34. $tool_name = get_lang('Careers');
  35. }
  36. //jqgrid will use this URL to do the selects
  37. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
  38. //The order is important you need to check the the $column variable in the model.ajax.php file
  39. $columns = [get_lang('Name'), get_lang('Description'), get_lang('Detail')];
  40. // Column config
  41. $column_model = [
  42. [
  43. 'name' => 'name',
  44. 'index' => 'name',
  45. 'width' => '200',
  46. 'align' => 'left',
  47. ],
  48. [
  49. 'name' => 'description',
  50. 'index' => 'description',
  51. 'width' => '400',
  52. 'align' => 'left',
  53. 'sortable' => 'false',
  54. ],
  55. [
  56. 'name' => 'actions',
  57. 'index' => 'actions',
  58. 'width' => '100',
  59. 'align' => 'left',
  60. 'formatter' => 'action_formatter',
  61. 'sortable' => 'false',
  62. ],
  63. ];
  64. $extra_params['autowidth'] = 'true';
  65. $extra_params['height'] = 'auto';
  66. $diagramLink = '';
  67. $allow = api_get_configuration_value('allow_career_diagram');
  68. if ($allow) {
  69. $diagramLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/career_diagram.php?id=\'+options.rowId+\'">'.get_lang('Diagram').'</a>';
  70. }
  71. // With this function we can add actions to the jgrid (edit, delete, etc)
  72. if (api_is_platform_admin()) {
  73. $actionLinks = 'function action_formatter(cellvalue, options, rowObject) {
  74. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  75. $diagramLink.
  76. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("Please confirm your choice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
  77. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("Please confirm your choice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
  78. '\';
  79. }';
  80. } else {
  81. $actionLinks = "function action_formatter(cellvalue, options, rowObject) {
  82. return '".$diagramLink."';
  83. }";
  84. }
  85. $career = new Career();
  86. $content = '';
  87. $listUrl = api_get_self();
  88. // Action handling: Add
  89. switch ($action) {
  90. case 'add':
  91. api_protect_admin_script();
  92. if (api_get_session_id() != 0 &&
  93. !api_is_allowed_to_session_edit(false, true)
  94. ) {
  95. api_not_allowed();
  96. }
  97. Session::write('notebook_view', 'creation_date');
  98. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  99. $form = $career->return_form($url, 'add');
  100. // The validation or display
  101. if ($form->validate()) {
  102. if ($check) {
  103. $values = $form->exportValues();
  104. $res = $career->save($values);
  105. if ($res) {
  106. Display::addFlash(
  107. Display::return_message(get_lang('Item added'), 'confirmation')
  108. );
  109. }
  110. }
  111. header('Location: '.$listUrl);
  112. exit;
  113. } else {
  114. $content .= '<div class="actions">';
  115. $content .= '<a href="'.api_get_self().'">'.
  116. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  117. $content .= '</div>';
  118. $form->addElement('hidden', 'sec_token');
  119. $form->setConstants(['sec_token' => $token]);
  120. $content .= $form->returnForm();
  121. }
  122. break;
  123. case 'edit':
  124. api_protect_admin_script();
  125. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  126. $careerInfo = $career->get($id);
  127. if (empty($careerInfo)) {
  128. api_not_allowed(true);
  129. }
  130. // Action handling: Editing
  131. $url = api_get_self().'?action=edit&id='.$id;
  132. $form = $career->return_form($url, 'edit');
  133. // The validation or display
  134. if ($form->validate()) {
  135. if ($check) {
  136. $values = $form->exportValues();
  137. $career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
  138. $old_status = $career->get_status($values['id']);
  139. $res = $career->update($values);
  140. $values['item_id'] = $values['id'];
  141. $sessionFieldValue = new ExtraFieldValue('career');
  142. $sessionFieldValue->saveFieldValues($values);
  143. if ($res) {
  144. Display::addFlash(
  145. Display::return_message(get_lang('Career updated successfully'), 'confirmation')
  146. );
  147. if ($values['status'] && !$old_status) {
  148. Display::addFlash(
  149. Display::return_message(
  150. sprintf(get_lang('The <i>%s</i> career has been unarchived. This action has the consequence of making visible the career, its promotions and all the sessions registered into this promotion. You can undo this by archiving the career.'), $values['name']),
  151. 'confirmation',
  152. false
  153. )
  154. );
  155. } elseif (!$values['status'] && $old_status) {
  156. Display::addFlash(
  157. Display::return_message(
  158. sprintf(get_lang('The <i>%s</i> career has been archived. This action has the consequence of making invisible the career, its promotions and all the sessions registered into this promotion. You can undo this by unarchiving the career.'), $values['name']),
  159. 'confirmation',
  160. false
  161. )
  162. );
  163. }
  164. }
  165. }
  166. header('Location: '.$listUrl);
  167. exit;
  168. } else {
  169. $content .= '<div class="actions">';
  170. $content .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  171. $content .= '</div>';
  172. $form->addElement('hidden', 'sec_token');
  173. $form->setConstants(['sec_token' => $token]);
  174. $content .= $form->returnForm();
  175. }
  176. break;
  177. case 'delete':
  178. api_protect_admin_script();
  179. // Action handling: delete
  180. if ($check) {
  181. $res = $career->delete($_GET['id']);
  182. if ($res) {
  183. Display::addFlash(
  184. Display::return_message(get_lang('Item deleted'), 'confirmation')
  185. );
  186. }
  187. }
  188. header('Location: '.$listUrl);
  189. exit;
  190. break;
  191. case 'copy':
  192. api_protect_admin_script();
  193. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  194. api_not_allowed(true);
  195. }
  196. if ($check) {
  197. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  198. if ($res) {
  199. Display::addFlash(
  200. Display::return_message(get_lang('Item copied'), 'confirmation')
  201. );
  202. }
  203. }
  204. header('Location: '.$listUrl);
  205. exit;
  206. break;
  207. default:
  208. $content = $career->display();
  209. break;
  210. }
  211. Display::display_header($tool_name);
  212. ?>
  213. <script>
  214. $(function() {
  215. <?php
  216. // grid definition see the $career->display() function
  217. echo Display::grid_js(
  218. 'careers',
  219. $url,
  220. $columns,
  221. $column_model,
  222. $extra_params,
  223. [],
  224. $actionLinks,
  225. true
  226. );
  227. ?>
  228. });
  229. </script>
  230. <?php
  231. echo $content;
  232. Display::display_footer();