promotions.php 7.5 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[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  14. $interbreadcrumb[] = array('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[] = array(
  20. 'url' => 'promotions.php',
  21. 'name' => get_lang('Promotions'),
  22. );
  23. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Add'));
  24. } elseif ($action == 'edit') {
  25. $interbreadcrumb[] = array(
  26. 'url' => 'promotions.php',
  27. 'name' => get_lang('Promotions'),
  28. );
  29. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  30. } else {
  31. $interbreadcrumb[] = array('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[] = array(
  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[] = array(
  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 = array(
  53. get_lang('Name'),
  54. get_lang('Career'),
  55. get_lang('Description'),
  56. get_lang('Actions'),
  57. );
  58. $column_model = array(
  59. array(
  60. 'name' => 'name',
  61. 'index' => 'name',
  62. 'width' => '180',
  63. 'align' => 'left',
  64. ),
  65. array(
  66. 'name' => 'career',
  67. 'index' => 'career',
  68. 'width' => '100',
  69. 'align' => 'left',
  70. ),
  71. array(
  72. 'name' => 'description',
  73. 'index' => 'description',
  74. 'width' => '500',
  75. 'align' => 'left',
  76. 'sortable' => 'false',
  77. ),
  78. array(
  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, array(), $action_links, true);
  102. ?>
  103. });
  104. </script>
  105. <?php
  106. $promotion = new Promotion();
  107. switch ($action) {
  108. case 'add':
  109. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  110. api_not_allowed();
  111. }
  112. //First you need to create a Career
  113. $career = new Career();
  114. $careers = $career->get_all();
  115. if (empty($careers)) {
  116. $url = Display::url(get_lang('YouNeedToCreateACareerFirst'), 'careers.php?action=add');
  117. echo Display::return_message($url, 'normal', false);
  118. Display::display_footer();
  119. exit;
  120. }
  121. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  122. $form = $promotion->return_form($url, 'add');
  123. // The validation or display
  124. if ($form->validate()) {
  125. if ($check) {
  126. $values = $form->exportValues();
  127. $res = $promotion->save($values);
  128. if ($res) {
  129. echo Display::return_message(get_lang('ItemAdded'), 'confirm');
  130. }
  131. }
  132. $promotion->display();
  133. } else {
  134. echo '<div class="actions">';
  135. echo Display::url(Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM), api_get_self());
  136. echo '</div>';
  137. $form->addElement('hidden', 'sec_token');
  138. $form->setConstants(array('sec_token' => $token));
  139. $form->display();
  140. }
  141. break;
  142. case 'edit':
  143. //Editing
  144. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  145. $form = $promotion->return_form($url, 'edit');
  146. // The validation or display
  147. if ($form->validate()) {
  148. if ($check) {
  149. $values = $form->exportValues();
  150. $res = $promotion->update($values);
  151. $promotion->update_all_sessions_status_by_promotion_id($values['id'], $values['status']);
  152. if ($res) {
  153. echo Display::return_message(get_lang('PromotionUpdated').': '.$values['name'], 'confirm');
  154. }
  155. }
  156. $promotion->display();
  157. } else {
  158. echo '<div class="actions">';
  159. echo Display::url(
  160. Display::return_icon(
  161. 'back.png',
  162. get_lang('Back'),
  163. '',
  164. ICON_SIZE_MEDIUM
  165. ),
  166. api_get_self()
  167. );
  168. echo '</div>';
  169. $form->addElement('hidden', 'sec_token');
  170. $form->setConstants(array('sec_token' => $token));
  171. $form->display();
  172. }
  173. break;
  174. case 'delete':
  175. if ($check) {
  176. // Action handling: deleting an obj
  177. $res = $promotion->delete($_GET['id']);
  178. if ($res) {
  179. return Display::return_message(get_lang('ItemDeleted'), 'confirm');
  180. }
  181. }
  182. $promotion->display();
  183. break;
  184. case 'copy':
  185. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  186. api_not_allowed();
  187. }
  188. if ($check) {
  189. $res = $promotion->copy($_GET['id'], null, true);
  190. if ($res) {
  191. echo Display::return_message(
  192. get_lang('ItemCopied').' - '.get_lang(
  193. 'ExerciseAndLPsAreInvisibleInTheNewCourse'
  194. ),
  195. 'confirm'
  196. );
  197. }
  198. }
  199. $promotion->display();
  200. break;
  201. default:
  202. $promotion->display();
  203. break;
  204. }
  205. Display::display_footer();