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