careers.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. use ChamiloSession as Session;
  5. /**
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  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' => Container::getRouter()->generate('administration'),
  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. Display::display_confirmation_message(get_lang('ItemAdded'));
  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. Display::display_confirmation_message(get_lang('CareerUpdated'));
  129. if ($values['status'] && !$old_status) {
  130. Display::display_confirmation_message(
  131. sprintf(get_lang('CareerXUnarchived'), $values['name']),
  132. false
  133. );
  134. } elseif (!$values['status'] && $old_status) {
  135. Display::display_confirmation_message(
  136. sprintf(get_lang('CareerXArchived'), $values['name']),
  137. false
  138. );
  139. }
  140. }
  141. }
  142. $career->display();
  143. } else {
  144. echo '<div class="actions">';
  145. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  146. echo '</div>';
  147. $form->addElement('hidden', 'sec_token');
  148. $form->setConstants(array('sec_token' => $token));
  149. $form->display();
  150. }
  151. break;
  152. case 'delete':
  153. // Action handling: delete
  154. if ($check) {
  155. $res = $career->delete($_GET['id']);
  156. if ($res) {
  157. Display::display_confirmation_message(get_lang('ItemDeleted'));
  158. }
  159. }
  160. $career->display();
  161. break;
  162. case 'copy':
  163. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  164. api_not_allowed();
  165. }
  166. if ($check) {
  167. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  168. if ($res) {
  169. Display::display_confirmation_message(get_lang('ItemCopied'));
  170. }
  171. }
  172. $career->display();
  173. break;
  174. default:
  175. $career->display();
  176. break;
  177. }
  178. Display :: display_footer();