promotions.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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).'promotion.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'career.lib.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. //Adds the JS needed to use the jqgrid
  15. $htmlHeadXtra[] = api_get_jquery_ui_js(true);
  16. // setting breadcrumbs
  17. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
  19. $action = $_GET['action'];
  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'=>'80', '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="?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="?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. // Action handling: Adding a note
  70. if (isset($_GET['action']) && $_GET['action'] == '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. $check = Security::check_token('post');
  88. if ($check) {
  89. $values = $form->exportValues();
  90. $res = $promotion->save($values);
  91. if ($res) {
  92. Display::display_confirmation_message(get_lang('ItemAdded'));
  93. }
  94. }
  95. Security::clear_token();
  96. $promotion->display();
  97. } else {
  98. echo '<div class="actions">';
  99. echo Display::url(Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM), api_get_self());
  100. echo '</div>';
  101. $token = Security::get_token();
  102. $form->addElement('hidden', 'sec_token');
  103. $form->setConstants(array('sec_token' => $token));
  104. $form->display();
  105. }
  106. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  107. //Editing
  108. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  109. $form = $promotion->return_form($url, 'edit');
  110. // The validation or display
  111. if ($form->validate()) {
  112. $check = Security::check_token('post');
  113. if ($check) {
  114. $values = $form->exportValues();
  115. $res = $promotion->update($values);
  116. $promotion->update_all_sessions_status_by_promotion_id($values['id'], $values['status']);
  117. if ($values['status']) {
  118. Display::display_confirmation_message(sprintf(get_lang('PromotionXUnarchived'), $values['name']), false);
  119. } else {
  120. Display::display_confirmation_message(sprintf(get_lang('PromotionXArchived'), $values['name']), false);
  121. }
  122. }
  123. Security::clear_token();
  124. $promotion->display();
  125. } else {
  126. echo '<div class="actions">';
  127. echo Display::url(Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM), api_get_self());
  128. echo '</div>';
  129. $token = Security::get_token();
  130. $form->addElement('hidden', 'sec_token');
  131. $form->setConstants(array('sec_token' => $token));
  132. $form->display();
  133. }
  134. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  135. // Action handling: deleting an obj
  136. $res = $promotion->delete($_GET['id']);
  137. if ($res) {
  138. Display::display_confirmation_message(get_lang('ItemDeleted'));
  139. }
  140. $promotion->display();
  141. } elseif (isset($_GET['action']) && $_GET['action'] == 'copy') {
  142. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  143. api_not_allowed();
  144. }
  145. $res = $promotion->copy($_GET['id'], null, true);
  146. if ($res) {
  147. Display::display_confirmation_message(get_lang('ItemCopied').' - '.get_lang('ExerciseAndLPsAreInvisibleInTheNewCourse'));
  148. }
  149. $promotion->display();
  150. } else {
  151. $promotion->display();
  152. }
  153. Display::display_footer();