careers.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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('PlatformAdmin'),
  18. ];
  19. $interbreadcrumb[] = [
  20. 'url' => 'career_dashboard.php',
  21. 'name' => get_lang('CareersAndPromotions'),
  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('Actions')];
  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. //Autowidth
  65. $extra_params['autowidth'] = 'true';
  66. //height auto
  67. $extra_params['height'] = 'auto';
  68. $diagramLink = '';
  69. $allow = api_get_configuration_value('allow_career_diagram');
  70. if ($allow) {
  71. $diagramLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/career_diagram.php?id=\'+options.rowId+\'">'.get_lang('Diagram').'</a>';
  72. }
  73. // With this function we can add actions to the jgrid (edit, delete, etc)
  74. if (api_is_platform_admin()) {
  75. $actionLinks = 'function action_formatter(cellvalue, options, rowObject) {
  76. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  77. $diagramLink.
  78. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), 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>'.
  79. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), 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>'.
  80. '\';
  81. }';
  82. } else {
  83. $actionLinks = "function action_formatter(cellvalue, options, rowObject) {
  84. return '".$diagramLink."';
  85. }";
  86. }
  87. $career = new Career();
  88. $content = '';
  89. $listUrl = api_get_self();
  90. // Action handling: Add
  91. switch ($action) {
  92. case 'add':
  93. api_protect_admin_script();
  94. if (api_get_session_id() != 0 &&
  95. !api_is_allowed_to_session_edit(false, true)
  96. ) {
  97. api_not_allowed();
  98. }
  99. Session::write('notebook_view', 'creation_date');
  100. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  101. $form = $career->return_form($url, 'add');
  102. // The validation or display
  103. if ($form->validate()) {
  104. if ($check) {
  105. $values = $form->exportValues();
  106. $res = $career->save($values);
  107. if ($res) {
  108. Display::addFlash(
  109. Display::return_message(get_lang('ItemAdded'), 'confirmation')
  110. );
  111. }
  112. }
  113. header('Location: '.$listUrl);
  114. exit;
  115. } else {
  116. $content .= '<div class="actions">';
  117. $content .= '<a href="'.api_get_self().'">'.
  118. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  119. $content .= '</div>';
  120. $form->addElement('hidden', 'sec_token');
  121. $form->setConstants(['sec_token' => $token]);
  122. $content .= $form->returnForm();
  123. }
  124. break;
  125. case 'edit':
  126. api_protect_admin_script();
  127. // Action handling: Editing
  128. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  129. $form = $career->return_form($url, 'edit');
  130. // The validation or display
  131. if ($form->validate()) {
  132. if ($check) {
  133. $values = $form->exportValues();
  134. $career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
  135. $old_status = $career->get_status($values['id']);
  136. $res = $career->update($values);
  137. if ($res) {
  138. Display::addFlash(
  139. Display::return_message(get_lang('CareerUpdated'), 'confirmation')
  140. );
  141. if ($values['status'] && !$old_status) {
  142. Display::addFlash(
  143. Display::return_message(
  144. sprintf(get_lang('CareerXUnarchived'), $values['name']),
  145. 'confirmation',
  146. false
  147. )
  148. );
  149. } elseif (!$values['status'] && $old_status) {
  150. Display::addFlash(
  151. Display::return_message(
  152. sprintf(get_lang('CareerXArchived'), $values['name']),
  153. 'confirmation',
  154. false
  155. )
  156. );
  157. }
  158. }
  159. }
  160. header('Location: '.$listUrl);
  161. exit;
  162. } else {
  163. $content .= '<div class="actions">';
  164. $content .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  165. $content .= '</div>';
  166. $form->addElement('hidden', 'sec_token');
  167. $form->setConstants(['sec_token' => $token]);
  168. $content .= $form->returnForm();
  169. }
  170. break;
  171. case 'delete':
  172. api_protect_admin_script();
  173. // Action handling: delete
  174. if ($check) {
  175. $res = $career->delete($_GET['id']);
  176. if ($res) {
  177. Display::addFlash(
  178. Display::return_message(get_lang('ItemDeleted'), 'confirmation')
  179. );
  180. }
  181. }
  182. header('Location: '.$listUrl);
  183. exit;
  184. break;
  185. case 'copy':
  186. api_protect_admin_script();
  187. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  188. api_not_allowed(true);
  189. }
  190. if ($check) {
  191. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  192. if ($res) {
  193. Display::addFlash(
  194. Display::return_message(get_lang('ItemCopied'), 'confirmation')
  195. );
  196. }
  197. }
  198. header('Location: '.$listUrl);
  199. exit;
  200. break;
  201. default:
  202. $content = $career->display();
  203. break;
  204. }
  205. // The header.
  206. Display::display_header($tool_name);
  207. ?>
  208. <script>
  209. $(function() {
  210. <?php
  211. // grid definition see the $career->display() function
  212. echo Display::grid_js(
  213. 'careers',
  214. $url,
  215. $columns,
  216. $column_model,
  217. $extra_params,
  218. [],
  219. $actionLinks,
  220. true
  221. );
  222. ?>
  223. });
  224. </script>
  225. <?php
  226. echo $content;
  227. Display::display_footer();