promotions.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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).'promotion.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'career.lib.php';
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. api_protect_admin_script();
  15. //Adds the JS needed to use the jqgrid
  16. $htmlHeadXtra[] = api_get_jquery_ui_js(true);
  17. // setting breadcrumbs
  18. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  19. $interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
  20. $action = $_GET['action'];
  21. if ($action == 'add') {
  22. $interbreadcrumb[]=array('url' => 'promotions.php','name' => get_lang('Promotions'));
  23. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
  24. } elseif ($action == 'edit') {
  25. $interbreadcrumb[]=array('url' => 'promotions.php','name' => get_lang('Promotions'));
  26. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
  27. } else {
  28. $interbreadcrumb[]=array('url' => '#','name' => get_lang('Promotions'));
  29. }
  30. // The header.
  31. Display::display_header($tool_name);
  32. // Tool name
  33. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  34. $tool = 'Add';
  35. $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Promotion'));
  36. }
  37. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  38. $tool = 'Modify';
  39. $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Promotion'));
  40. }
  41. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_promotions';
  42. //The order is important you need to check the model.ajax.php the $column variable
  43. $columns = array(get_lang('Name'),get_lang('Career'),get_lang('Description'),get_lang('Actions'));
  44. $column_model = array(
  45. array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
  46. array('name'=>'career', 'index'=>'career', 'width'=>'100', 'align'=>'left'),
  47. array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left','sortable'=>'false'),
  48. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false'),
  49. );
  50. $extra_params['autowidth'] = 'true'; //use the width of the parent
  51. //$extra_params['editurl'] = $url; //use the width of the parent
  52. $extra_params['height'] = 'auto'; //use the width of the parent
  53. //With this function we can add actions to the jgrid
  54. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  55. return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'">'.Display::return_icon('session_to_promotion.png',get_lang('SubscribeSessionsToPromotions'),'',22).'</a>'.
  56. '&nbsp;<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>'.
  57. '&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>'.
  58. '&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> \';
  59. }';
  60. ?>
  61. <script>
  62. $(function() {
  63. <?php
  64. echo Display::grid_js('promotions', $url,$columns,$column_model,$extra_params,array(), $action_links, true);
  65. ?>
  66. });
  67. </script>
  68. <?php
  69. // Tool introduction
  70. Display::display_introduction_section(get_lang('Promotions'));
  71. $promotion = new Promotion();
  72. // Action handling: Adding a note
  73. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  74. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  75. api_not_allowed();
  76. }
  77. //First you need to create a Career
  78. $career = new Career();
  79. $careers = $career->get_all();
  80. if (empty($careers)) {
  81. $url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
  82. Display::display_normal_message($url, false);
  83. Display::display_footer();
  84. exit;
  85. }
  86. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  87. $form = $promotion->return_form($url, 'add');
  88. // The validation or display
  89. if ($form->validate()) {
  90. $check = Security::check_token('post');
  91. if ($check) {
  92. $values = $form->exportValues();
  93. $res = $promotion->save($values);
  94. if ($res) {
  95. Display::display_confirmation_message(get_lang('ItemAdded'));
  96. }
  97. }
  98. Security::clear_token();
  99. $promotion->display();
  100. } else {
  101. echo '<div class="actions">';
  102. echo Display::url(Display::return_icon('back.png',get_lang('Back'),'','32'), api_get_self());
  103. echo '</div>';
  104. $token = Security::get_token();
  105. $form->addElement('hidden', 'sec_token');
  106. $form->setConstants(array('sec_token' => $token));
  107. $form->display();
  108. }
  109. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  110. //Editing
  111. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  112. $form = $promotion->return_form($url, 'edit');
  113. // The validation or display
  114. if ($form->validate()) {
  115. $check = Security::check_token('post');
  116. if ($check) {
  117. $values = $form->exportValues();
  118. $res = $promotion->update($values);
  119. $promotion->update_all_sessions_status_by_promotion_id($values['id'], $values['status']);
  120. if ($values['status']) {
  121. Display::display_confirmation_message(sprintf(get_lang('PromotionXUnarchived'), $values['name']), false);
  122. } else {
  123. Display::display_confirmation_message(sprintf(get_lang('PromotionXArchived'), $values['name']), false);
  124. }
  125. }
  126. Security::clear_token();
  127. $promotion->display();
  128. } else {
  129. echo '<div class="actions">';
  130. echo Display::url(Display::return_icon('back.png',get_lang('Back'),'','32'), api_get_self());
  131. echo '</div>';
  132. $token = Security::get_token();
  133. $form->addElement('hidden', 'sec_token');
  134. $form->setConstants(array('sec_token' => $token));
  135. $form->display();
  136. }
  137. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  138. // Action handling: deleting an obj
  139. $res = $promotion->delete($_GET['id']);
  140. if ($res) {
  141. Display::display_confirmation_message(get_lang('ItemDeleted'));
  142. }
  143. $promotion->display();
  144. } elseif (isset($_GET['action']) && $_GET['action'] == 'copy') {
  145. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  146. api_not_allowed();
  147. }
  148. $res = $promotion->copy($_GET['id'], null, true);
  149. if ($res) {
  150. Display::display_confirmation_message(get_lang('ItemCopied').' - '.get_lang('ExerciseAndLPsAreInvisibleInTheNewCourse'));
  151. }
  152. $promotion->display();
  153. } else {
  154. $promotion->display();
  155. }
  156. Display::display_footer();