careers.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. //Add the JS needed to use the jqgrid
  11. $htmlHeadXtra[] = api_get_jqgrid_js();
  12. // setting breadcrumbs
  13. $interbreadcrumb[] = array(
  14. 'url' => 'index.php',
  15. 'name' => get_lang('PlatformAdmin'),
  16. );
  17. $interbreadcrumb[] = array(
  18. 'url' => 'career_dashboard.php',
  19. 'name' => get_lang('CareersAndPromotions'),
  20. );
  21. $action = isset($_GET['action']) ? $_GET['action'] : null;
  22. $check = Security::check_token('request');
  23. $token = Security::get_token();
  24. if ($action == 'add') {
  25. $interbreadcrumb[]=array('url' => 'careers.php','name' => get_lang('Careers'));
  26. $tool_name = get_lang('Add');
  27. } elseif ($action == 'edit') {
  28. $interbreadcrumb[]=array('url' => 'careers.php','name' => get_lang('Careers'));
  29. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  30. $tool_name = get_lang('Edit');
  31. } else {
  32. $tool_name = get_lang('Careers');
  33. }
  34. // The header.
  35. Display::display_header($tool_name);
  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 = array(get_lang('Name'), get_lang('Description'), get_lang('Actions'));
  40. // Column config
  41. $column_model = array(
  42. array(
  43. 'name' => 'name',
  44. 'index' => 'name',
  45. 'width' => '80',
  46. 'align' => 'left',
  47. ),
  48. array(
  49. 'name' => 'description',
  50. 'index' => 'description',
  51. 'width' => '500',
  52. 'align' => 'left',
  53. 'sortable' => 'false',
  54. ),
  55. array(
  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. //With this function we can add actions to the jgrid (edit, delete, etc)
  69. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  70. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  71. '&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>'.
  72. '&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>'.
  73. '\';
  74. }';
  75. ?>
  76. <script>
  77. $(function() {
  78. <?php
  79. // grid definition see the $career->display() function
  80. echo Display::grid_js('careers', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  81. ?>
  82. });
  83. </script>
  84. <?php
  85. $career = new Career();
  86. // Action handling: Add
  87. switch ($action) {
  88. case 'add':
  89. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  90. api_not_allowed();
  91. }
  92. $_SESSION['notebook_view'] = 'creation_date';
  93. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  94. $form = $career->return_form($url, 'add');
  95. // The validation or display
  96. if ($form->validate()) {
  97. if ($check) {
  98. $values = $form->exportValues();
  99. $res = $career->save($values);
  100. if ($res) {
  101. Display::display_confirmation_message(get_lang('ItemAdded'));
  102. }
  103. }
  104. $career->display();
  105. } else {
  106. echo '<div class="actions">';
  107. echo '<a href="'.api_get_self().'">'.
  108. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  109. echo '</div>';
  110. $form->addElement('hidden', 'sec_token');
  111. $form->setConstants(array('sec_token' => $token));
  112. $form->display();
  113. }
  114. break;
  115. case 'edit':
  116. // Action handling: Editing
  117. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  118. $form = $career->return_form($url, 'edit');
  119. // The validation or display
  120. if ($form->validate()) {
  121. if ($check) {
  122. $values = $form->exportValues();
  123. $career->update_all_promotion_status_by_career_id($values['id'], $values['status']);
  124. $old_status = $career->get_status($values['id']);
  125. $res = $career->update($values);
  126. if ($res) {
  127. Display::display_confirmation_message(get_lang('CareerUpdated'));
  128. if ($values['status'] && !$old_status) {
  129. Display::display_confirmation_message(sprintf(get_lang('CareerXUnarchived'), $values['name']), false);
  130. } elseif (!$values['status'] && $old_status) {
  131. Display::display_confirmation_message(sprintf(get_lang('CareerXArchived'), $values['name']), false);
  132. }
  133. }
  134. }
  135. $career->display();
  136. } else {
  137. echo '<div class="actions">';
  138. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  139. echo '</div>';
  140. $form->addElement('hidden', 'sec_token');
  141. $form->setConstants(array('sec_token' => $token));
  142. $form->display();
  143. }
  144. break;
  145. case 'delete':
  146. // Action handling: delete
  147. if ($check) {
  148. $res = $career->delete($_GET['id']);
  149. if ($res) {
  150. Display::display_confirmation_message(get_lang('ItemDeleted'));
  151. }
  152. }
  153. $career->display();
  154. break;
  155. case 'copy':
  156. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  157. api_not_allowed();
  158. }
  159. if ($check) {
  160. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  161. if ($res) {
  162. Display::display_confirmation_message(get_lang('ItemCopied'));
  163. }
  164. }
  165. $career->display();
  166. break;
  167. default:
  168. $career->display();
  169. break;
  170. }
  171. Display :: display_footer();