careers.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. require_once api_get_path(LIBRARY_PATH).'career.lib.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. //Add the JS needed to use the jqgrid
  14. $htmlHeadXtra[] = api_get_jqgrid_js();
  15. // setting breadcrumbs
  16. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
  18. $action = isset($_GET['action']) ? $_GET['action'] : null;
  19. $check = Security::check_token('request');
  20. $token = Security::get_token();
  21. if ($action == 'add') {
  22. $interbreadcrumb[]=array('url' => 'careers.php','name' => get_lang('Careers'));
  23. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
  24. } elseif ($action == 'edit') {
  25. $interbreadcrumb[]=array('url' => 'careers.php','name' => get_lang('Careers'));
  26. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  27. } else {
  28. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Careers'));
  29. }
  30. // The header.
  31. Display::display_header($tool_name);
  32. //jqgrid will use this URL to do the selects
  33. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
  34. //The order is important you need to check the the $column variable in the model.ajax.php file
  35. $columns = array(get_lang('Name'), get_lang('Description'), get_lang('Actions'));
  36. //Column config
  37. $column_model = array(
  38. array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
  39. array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left','sortable'=>'false'),
  40. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  41. );
  42. //Autowidth
  43. $extra_params['autowidth'] = 'true';
  44. //height auto
  45. $extra_params['height'] = 'auto';
  46. //With this function we can add actions to the jgrid (edit, delete, etc)
  47. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  48. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  49. '&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>'.
  50. '&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>'.
  51. '\';
  52. }';
  53. ?>
  54. <script>
  55. $(function() {
  56. <?php
  57. // grid definition see the $career->display() function
  58. echo Display::grid_js('careers', $url,$columns,$column_model,$extra_params, array(), $action_links,true);
  59. ?>
  60. });
  61. </script>
  62. <?php
  63. $career = new Career();
  64. // Action handling: Add
  65. switch ($action) {
  66. case 'add':
  67. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  68. api_not_allowed();
  69. }
  70. $_SESSION['notebook_view'] = 'creation_date';
  71. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  72. $form = $career->return_form($url, 'add');
  73. // The validation or display
  74. if ($form->validate()) {
  75. if ($check) {
  76. $values = $form->exportValues();
  77. $res = $career->save($values);
  78. if ($res) {
  79. Display::display_confirmation_message(get_lang('ItemAdded'));
  80. }
  81. }
  82. $career->display();
  83. } else {
  84. echo '<div class="actions">';
  85. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  86. echo '</div>';
  87. $form->addElement('hidden', 'sec_token');
  88. $form->setConstants(array('sec_token' => $token));
  89. $form->display();
  90. }
  91. break;
  92. case 'edit':
  93. // Action handling: Editing
  94. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  95. $form = $career->return_form($url, 'edit');
  96. // The validation or display
  97. if ($form->validate()) {
  98. if ($check) {
  99. $values = $form->exportValues();
  100. $career->update_all_promotion_status_by_career_id($values['id'],$values['status']);
  101. $res = $career->update($values);
  102. if ($values['status']) {
  103. Display::display_confirmation_message(sprintf(get_lang('CareerXUnarchived'), $values['name']), false);
  104. } else {
  105. Display::display_confirmation_message(sprintf(get_lang('CareerXArchived'), $values['name']), false);
  106. }
  107. }
  108. $career->display();
  109. } else {
  110. echo '<div class="actions">';
  111. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  112. echo '</div>';
  113. $form->addElement('hidden', 'sec_token');
  114. $form->setConstants(array('sec_token' => $token));
  115. $form->display();
  116. }
  117. break;
  118. case 'delete':
  119. // Action handling: delete
  120. if ($check) {
  121. $res = $career->delete($_GET['id']);
  122. if ($res) {
  123. Display::display_confirmation_message(get_lang('ItemDeleted'));
  124. }
  125. }
  126. $career->display();
  127. break;
  128. case 'copy':
  129. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  130. api_not_allowed();
  131. }
  132. if ($check) {
  133. $res = $career->copy($_GET['id'], true); //copy career and promotions inside
  134. if ($res) {
  135. Display::display_confirmation_message(get_lang('ItemCopied'));
  136. }
  137. }
  138. $career->display();
  139. break;
  140. default:
  141. $career->display();
  142. break;
  143. }
  144. Display :: display_footer();