careers.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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($tool_name);
  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('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left','sortable'=>'false'),
  38. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  39. );
  40. //Autowidth
  41. $extra_params['autowidth'] = 'true';
  42. //height auto
  43. $extra_params['height'] = 'auto';
  44. //With this function we can add actions to the jgrid (edit, delete, etc)
  45. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  46. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  47. '&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>'.
  48. '&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>'.
  49. '\';
  50. }';
  51. ?>
  52. <script>
  53. $(function() {
  54. <?php
  55. // grid definition see the $career->display() function
  56. echo Display::grid_js('careers', $url,$columns,$column_model,$extra_params, array(), $action_links,true);
  57. ?>
  58. });
  59. </script>
  60. <?php
  61. $career = new Career();
  62. // Action handling: Add
  63. switch ($action) {
  64. case 'add':
  65. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  66. api_not_allowed();
  67. }
  68. $_SESSION['notebook_view'] = 'creation_date';
  69. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  70. $form = $career->return_form($url, 'add');
  71. // The validation or display
  72. if ($form->validate()) {
  73. if ($check) {
  74. $values = $form->exportValues();
  75. $res = $career->save($values);
  76. if ($res) {
  77. Display::display_confirmation_message(get_lang('ItemAdded'));
  78. }
  79. }
  80. $career->display();
  81. } else {
  82. echo '<div class="actions">';
  83. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  84. echo '</div>';
  85. $form->addElement('hidden', 'sec_token');
  86. $form->setConstants(array('sec_token' => $token));
  87. $form->display();
  88. }
  89. break;
  90. case 'edit':
  91. // Action handling: Editing
  92. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  93. $form = $career->return_form($url, 'edit');
  94. // The validation or display
  95. if ($form->validate()) {
  96. if ($check) {
  97. $values = $form->exportValues();
  98. $career->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  99. $res = $career->update($values);
  100. if ($values['status']) {
  101. Display::display_confirmation_message(sprintf(get_lang('CareerXUnarchived'), $values['name']), false);
  102. } else {
  103. Display::display_confirmation_message(sprintf(get_lang('CareerXArchived'), $values['name']), false);
  104. }
  105. }
  106. $career->display();
  107. } else {
  108. echo '<div class="actions">';
  109. echo '<a href="'.api_get_self().'">'.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 'delete':
  117. // Action handling: delete
  118. if ($check) {
  119. $res = $career->delete($_GET['id']);
  120. if ($res) {
  121. Display::display_confirmation_message(get_lang('ItemDeleted'));
  122. }
  123. }
  124. $career->display();
  125. break;
  126. case 'copy':
  127. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  128. api_not_allowed();
  129. }
  130. if ($check) {
  131. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  132. if ($res) {
  133. Display::display_confirmation_message(get_lang('ItemCopied'));
  134. }
  135. }
  136. $career->display();
  137. break;
  138. default:
  139. $career->display();
  140. break;
  141. }
  142. Display :: display_footer();