careers.php 6.9 KB

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