careers.php 6.6 KB

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