promotions.php 7.0 KB

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