promotions.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. //Adds the JS needed to use the jqgrid
  11. $htmlHeadXtra[] = api_get_jqgrid_js();
  12. // setting breadcrumbs
  13. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  14. $interbreadcrumb[] = ['url' => 'career_dashboard.php', 'name' => get_lang('CareersAndPromotions')];
  15. $action = isset($_GET['action']) ? $_GET['action'] : null;
  16. $check = Security::check_token('request');
  17. $token = Security::get_token();
  18. if ($action == 'add') {
  19. $interbreadcrumb[] = [
  20. 'url' => 'promotions.php',
  21. 'name' => get_lang('Promotions'),
  22. ];
  23. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
  24. } elseif ($action == 'edit') {
  25. $interbreadcrumb[] = [
  26. 'url' => 'promotions.php',
  27. 'name' => get_lang('Promotions'),
  28. ];
  29. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  30. } else {
  31. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Promotions')];
  32. }
  33. // The header.
  34. Display::display_header('');
  35. // Tool name
  36. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  37. $tool = 'Add';
  38. $interbreadcrumb[] = [
  39. 'url' => api_get_self(),
  40. 'name' => get_lang('Promotion'),
  41. ];
  42. }
  43. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  44. $tool = 'Modify';
  45. $interbreadcrumb[] = [
  46. 'url' => api_get_self(),
  47. 'name' => get_lang('Promotion'),
  48. ];
  49. }
  50. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_promotions';
  51. //The order is important you need to check the model.ajax.php the $column variable
  52. $columns = [
  53. get_lang('Name'),
  54. get_lang('Career'),
  55. get_lang('Description'),
  56. get_lang('Actions'),
  57. ];
  58. $column_model = [
  59. [
  60. 'name' => 'name',
  61. 'index' => 'name',
  62. 'width' => '180',
  63. 'align' => 'left',
  64. ],
  65. [
  66. 'name' => 'career',
  67. 'index' => 'career',
  68. 'width' => '100',
  69. 'align' => 'left',
  70. ],
  71. [
  72. 'name' => 'description',
  73. 'index' => 'description',
  74. 'width' => '500',
  75. 'align' => 'left',
  76. 'sortable' => 'false',
  77. ],
  78. [
  79. 'name' => 'actions',
  80. 'index' => 'actions',
  81. 'width' => '100',
  82. 'align' => 'left',
  83. 'formatter' => 'action_formatter',
  84. 'sortable' => 'false',
  85. ],
  86. ];
  87. $extra_params['autowidth'] = 'true'; //use the width of the parent
  88. //$extra_params['editurl'] = $url; //use the width of the parent
  89. $extra_params['height'] = 'auto'; //use the width of the parent
  90. //With this function we can add actions to the jgrid
  91. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  92. return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'">'.Display::return_icon('session_to_promotion.png', get_lang('SubscribeSessionsToPromotions'), '', ICON_SIZE_SMALL).'</a>'.
  93. '&nbsp;<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  94. '&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>'.
  95. '&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> \';
  96. }';
  97. ?>
  98. <script>
  99. $(function() {
  100. <?php
  101. echo Display::grid_js('promotions', $url, $columns, $column_model, $extra_params, [], $action_links, true);
  102. ?>
  103. });
  104. </script>
  105. <?php
  106. $promotion = new Promotion();
  107. $token = Security::get_token();
  108. switch ($action) {
  109. case 'add':
  110. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  111. api_not_allowed();
  112. }
  113. //First you need to create a Career
  114. $career = new Career();
  115. $careers = $career->get_all();
  116. if (empty($careers)) {
  117. $url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
  118. echo Display::return_message($url, 'normal', false);
  119. Display::display_footer();
  120. exit;
  121. }
  122. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  123. $form = $promotion->return_form($url, 'add');
  124. // The validation or display
  125. if ($form->validate()) {
  126. if ($check) {
  127. $values = $form->exportValues();
  128. $res = $promotion->save($values);
  129. if ($res) {
  130. echo Display::return_message(get_lang('ItemAdded'), 'confirm');
  131. }
  132. }
  133. $promotion->display();
  134. } else {
  135. echo '<div class="actions">';
  136. echo Display::url(Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM), api_get_self());
  137. echo '</div>';
  138. $form->addElement('hidden', 'sec_token');
  139. $form->setConstants(['sec_token' => $token]);
  140. $form->display();
  141. }
  142. break;
  143. case 'edit':
  144. //Editing
  145. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  146. $form = $promotion->return_form($url, 'edit');
  147. // The validation or display
  148. if ($form->validate()) {
  149. if ($check) {
  150. $values = $form->exportValues();
  151. $res = $promotion->update($values);
  152. $promotion->update_all_sessions_status_by_promotion_id($values['id'], $values['status']);
  153. if ($res) {
  154. echo Display::return_message(get_lang('PromotionUpdated').': '.$values['name'], 'confirm');
  155. }
  156. }
  157. $promotion->display();
  158. } else {
  159. echo '<div class="actions">';
  160. echo Display::url(
  161. Display::return_icon(
  162. 'back.png',
  163. get_lang('Back'),
  164. '',
  165. ICON_SIZE_MEDIUM
  166. ),
  167. api_get_self()
  168. );
  169. echo '</div>';
  170. $form->addElement('hidden', 'sec_token');
  171. $form->setConstants(['sec_token' => $token]);
  172. $form->display();
  173. }
  174. break;
  175. case 'delete':
  176. if ($check) {
  177. // Action handling: deleting an obj
  178. $res = $promotion->delete($_GET['id']);
  179. if ($res) {
  180. return Display::return_message(get_lang('ItemDeleted'), 'confirm');
  181. }
  182. }
  183. $promotion->display();
  184. break;
  185. case 'copy':
  186. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  187. api_not_allowed();
  188. }
  189. if ($check) {
  190. $res = $promotion->copy($_GET['id'], null, true);
  191. if ($res) {
  192. echo Display::return_message(
  193. get_lang('ItemCopied').' - '.get_lang(
  194. 'ExerciseAndLPsAreInvisibleInTheNewCourse'
  195. ),
  196. 'confirm'
  197. );
  198. }
  199. }
  200. $promotion->display();
  201. break;
  202. default:
  203. $promotion->display();
  204. break;
  205. }
  206. Display::display_footer();