careers.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. api_protect_admin_script();
  11. //Add the JS needed to use the jqgrid
  12. $htmlHeadXtra[] = api_get_jqgrid_js();
  13. // setting breadcrumbs
  14. $interbreadcrumb[] = array(
  15. 'url' => 'index.php',
  16. 'name' => get_lang('PlatformAdmin'),
  17. );
  18. $interbreadcrumb[] = array(
  19. 'url' => 'career_dashboard.php',
  20. 'name' => get_lang('CareersAndPromotions'),
  21. );
  22. $action = isset($_GET['action']) ? $_GET['action'] : null;
  23. $check = Security::check_token('request');
  24. $token = Security::get_token();
  25. if ($action == 'add') {
  26. $interbreadcrumb[] = array('url' => 'careers.php', 'name' => get_lang('Careers'));
  27. $tool_name = get_lang('Add');
  28. } elseif ($action == 'edit') {
  29. $interbreadcrumb[] = array('url' => 'careers.php', 'name' => get_lang('Careers'));
  30. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  31. $tool_name = get_lang('Edit');
  32. } else {
  33. $tool_name = get_lang('Careers');
  34. }
  35. // The header.
  36. Display::display_header($tool_name);
  37. //jqgrid will use this URL to do the selects
  38. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
  39. //The order is important you need to check the the $column variable in the model.ajax.php file
  40. $columns = array(get_lang('Name'), get_lang('Description'), get_lang('Actions'));
  41. // Column config
  42. $column_model = array(
  43. array(
  44. 'name' => 'name',
  45. 'index' => 'name',
  46. 'width' => '200',
  47. 'align' => 'left',
  48. ),
  49. array(
  50. 'name' => 'description',
  51. 'index' => 'description',
  52. 'width' => '400',
  53. 'align' => 'left',
  54. 'sortable' => 'false',
  55. ),
  56. array(
  57. 'name' => 'actions',
  58. 'index' => 'actions',
  59. 'width' => '100',
  60. 'align' => 'left',
  61. 'formatter' => 'action_formatter',
  62. 'sortable' => 'false',
  63. ),
  64. );
  65. //Autowidth
  66. $extra_params['autowidth'] = 'true';
  67. //height auto
  68. $extra_params['height'] = 'auto';
  69. $diagramLink = '';
  70. $allow = api_get_configuration_value('allow_career_diagram');
  71. if ($allow) {
  72. $diagramLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/career_diagram.php?id=\'+options.rowId+\'">'.get_lang('Diagram').'</a>';
  73. }
  74. //With this function we can add actions to the jgrid (edit, delete, etc)
  75. $action_links = '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. ?>
  83. <script>
  84. $(function() {
  85. <?php
  86. // grid definition see the $career->display() function
  87. echo Display::grid_js(
  88. 'careers',
  89. $url,
  90. $columns,
  91. $column_model,
  92. $extra_params,
  93. array(),
  94. $action_links,
  95. true
  96. );
  97. ?>
  98. });
  99. </script>
  100. <?php
  101. $career = new Career();
  102. // Action handling: Add
  103. switch ($action) {
  104. case 'add':
  105. if (api_get_session_id() != 0 &&
  106. !api_is_allowed_to_session_edit(false, true)
  107. ) {
  108. api_not_allowed();
  109. }
  110. Session::write('notebook_view', 'creation_date');
  111. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  112. $form = $career->return_form($url, 'add');
  113. // The validation or display
  114. if ($form->validate()) {
  115. if ($check) {
  116. $values = $form->exportValues();
  117. $res = $career->save($values);
  118. if ($res) {
  119. echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
  120. }
  121. }
  122. $career->display();
  123. } else {
  124. echo '<div class="actions">';
  125. echo '<a href="'.api_get_self().'">'.
  126. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  127. echo '</div>';
  128. $form->addElement('hidden', 'sec_token');
  129. $form->setConstants(array('sec_token' => $token));
  130. $form->display();
  131. }
  132. break;
  133. case 'edit':
  134. // Action handling: Editing
  135. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  136. $form = $career->return_form($url, 'edit');
  137. // The validation or display
  138. if ($form->validate()) {
  139. if ($check) {
  140. $values = $form->exportValues();
  141. $career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
  142. $old_status = $career->get_status($values['id']);
  143. $res = $career->update($values);
  144. if ($res) {
  145. echo Display::return_message(get_lang('CareerUpdated'), 'confirmation');
  146. if ($values['status'] && !$old_status) {
  147. echo Display::return_message(
  148. sprintf(get_lang('CareerXUnarchived'), $values['name']),
  149. 'confirmation',
  150. false
  151. );
  152. } elseif (!$values['status'] && $old_status) {
  153. echo Display::return_message(
  154. sprintf(get_lang('CareerXArchived'), $values['name']),
  155. 'confirmation',
  156. false
  157. );
  158. }
  159. }
  160. }
  161. $career->display();
  162. } else {
  163. echo '<div class="actions">';
  164. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  165. echo '</div>';
  166. $form->addElement('hidden', 'sec_token');
  167. $form->setConstants(array('sec_token' => $token));
  168. $form->display();
  169. }
  170. break;
  171. case 'delete':
  172. // Action handling: delete
  173. if ($check) {
  174. $res = $career->delete($_GET['id']);
  175. if ($res) {
  176. echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
  177. }
  178. }
  179. $career->display();
  180. break;
  181. case 'copy':
  182. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  183. api_not_allowed();
  184. }
  185. if ($check) {
  186. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  187. if ($res) {
  188. echo Display::return_message(get_lang('ItemCopied'), 'confirmation');
  189. }
  190. }
  191. $career->display();
  192. break;
  193. default:
  194. $career->display();
  195. break;
  196. }
  197. Display :: display_footer();