careers.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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' => '80',
  47. 'align' => 'left',
  48. ),
  49. array(
  50. 'name' => 'description',
  51. 'index' => 'description',
  52. 'width' => '500',
  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. //With this function we can add actions to the jgrid (edit, delete, etc)
  70. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  71. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  72. '&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>'.
  73. '&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>'.
  74. '\';
  75. }';
  76. ?>
  77. <script>
  78. $(function() {
  79. <?php
  80. // grid definition see the $career->display() function
  81. echo Display::grid_js('careers', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  82. ?>
  83. });
  84. </script>
  85. <?php
  86. $career = new Career();
  87. // Action handling: Add
  88. switch ($action) {
  89. case 'add':
  90. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  91. api_not_allowed();
  92. }
  93. Session::write('notebook_view', 'creation_date');
  94. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  95. $form = $career->return_form($url, 'add');
  96. // The validation or display
  97. if ($form->validate()) {
  98. if ($check) {
  99. $values = $form->exportValues();
  100. $res = $career->save($values);
  101. if ($res) {
  102. echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
  103. }
  104. }
  105. $career->display();
  106. } else {
  107. echo '<div class="actions">';
  108. echo '<a href="'.api_get_self().'">'.
  109. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  110. echo '</div>';
  111. $form->addElement('hidden', 'sec_token');
  112. $form->setConstants(array('sec_token' => $token));
  113. $form->display();
  114. }
  115. break;
  116. case 'edit':
  117. // Action handling: Editing
  118. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  119. $form = $career->return_form($url, 'edit');
  120. // The validation or display
  121. if ($form->validate()) {
  122. if ($check) {
  123. $values = $form->exportValues();
  124. $career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
  125. $old_status = $career->get_status($values['id']);
  126. $res = $career->update($values);
  127. if ($res) {
  128. echo Display::return_message(get_lang('CareerUpdated'), 'confirmation');
  129. if ($values['status'] && !$old_status) {
  130. echo Display::return_message(
  131. sprintf(get_lang('CareerXUnarchived'), $values['name']),
  132. 'confirmation',
  133. false
  134. );
  135. } elseif (!$values['status'] && $old_status) {
  136. echo Display::return_message(
  137. sprintf(get_lang('CareerXArchived'), $values['name']),
  138. 'confirmation',
  139. false
  140. );
  141. }
  142. }
  143. }
  144. $career->display();
  145. } else {
  146. echo '<div class="actions">';
  147. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  148. echo '</div>';
  149. $form->addElement('hidden', 'sec_token');
  150. $form->setConstants(array('sec_token' => $token));
  151. $form->display();
  152. }
  153. break;
  154. case 'delete':
  155. // Action handling: delete
  156. if ($check) {
  157. $res = $career->delete($_GET['id']);
  158. if ($res) {
  159. echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
  160. }
  161. }
  162. $career->display();
  163. break;
  164. case 'copy':
  165. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  166. api_not_allowed();
  167. }
  168. if ($check) {
  169. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  170. if ($res) {
  171. echo Display::return_message(get_lang('ItemCopied'), 'confirmation');
  172. }
  173. }
  174. $career->display();
  175. break;
  176. default:
  177. $career->display();
  178. break;
  179. }
  180. Display :: display_footer();