course_request_rejected.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A list containing the rejected course requests.
  5. *
  6. * @package chamilo.admin
  7. *
  8. * @author José Manuel Abuin Mosquera <chema@cesga.es>, 2010
  9. * @author Bruno Rubio Gayo <brubio@cesga.es>, 2010
  10. * Centro de Supercomputacion de Galicia (CESGA)
  11. * @author Ivan Tcholakov <ivantcholakov@gmail.com> (technical adaptation for Chamilo 1.8.8), 2010
  12. */
  13. $cidReset = true;
  14. require_once __DIR__.'/../inc/global.inc.php';
  15. $this_section = SECTION_PLATFORM_ADMIN;
  16. api_protect_admin_script();
  17. // A check whether the course validation feature is enabled.
  18. $course_validation_feature = api_get_setting('course_validation') == 'true';
  19. // Filltering passed to this page parameters.
  20. $accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
  21. $delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
  22. $request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
  23. $message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
  24. $is_error_message = !empty($_GET['is_error_message']);
  25. if ($course_validation_feature) {
  26. /**
  27. * Acceptance and creation of the requested course.
  28. */
  29. if (!empty($accept_course_request)) {
  30. $course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
  31. $course_id = CourseRequestManager::accept_course_request($accept_course_request);
  32. if ($course_id) {
  33. $course_code = CourseManager::get_course_code_from_course_id($course_id);
  34. $message = sprintf(get_lang('CourseRequestAccepted'), $course_request_code, $course_code);
  35. $is_error_message = false;
  36. } else {
  37. $message = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_code);
  38. $is_error_message = true;
  39. }
  40. } elseif (!empty($request_info)) {
  41. /**
  42. * Sending to the teacher a request for additional information about the proposed course.
  43. */
  44. $course_request_code = CourseRequestManager::get_course_request_code($request_info);
  45. $result = CourseRequestManager::ask_for_additional_info($request_info);
  46. if ($result) {
  47. $message = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_code);
  48. $is_error_message = false;
  49. } else {
  50. $message = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_code);
  51. $is_error_message = true;
  52. }
  53. } elseif (!empty($delete_course_request)) {
  54. /**
  55. * Deletion of a course request.
  56. */
  57. $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
  58. $result = CourseRequestManager::delete_course_request($delete_course_request);
  59. if ($result) {
  60. $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
  61. $is_error_message = false;
  62. } else {
  63. $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
  64. $is_error_message = true;
  65. }
  66. } elseif (isset($_POST['action'])) {
  67. /**
  68. * Form actions: delete.
  69. */
  70. switch ($_POST['action']) {
  71. // Delete selected courses
  72. case 'delete_course_requests':
  73. $course_requests = $_POST['course_request'];
  74. if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
  75. $success = true;
  76. foreach ($_POST['course_request'] as $index => $course_request_id) {
  77. $success &= CourseRequestManager::delete_course_request($course_request_id);
  78. }
  79. $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
  80. $is_error_message = !$success;
  81. }
  82. break;
  83. }
  84. }
  85. } else {
  86. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  87. $message = sprintf(
  88. get_lang('PleaseActivateCourseValidationFeature'),
  89. sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation'))
  90. );
  91. $is_error_message = true;
  92. }
  93. /**
  94. * Get the number of courses which will be displayed.
  95. */
  96. function get_number_of_requests()
  97. {
  98. return CourseRequestManager::count_course_requests(COURSE_REQUEST_REJECTED);
  99. }
  100. /**
  101. * Get course data to display.
  102. */
  103. function get_request_data($from, $number_of_items, $column, $direction)
  104. {
  105. $keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
  106. $course_request_table = Database::get_main_table(TABLE_MAIN_COURSE_REQUEST);
  107. $from = intval($from);
  108. $number_of_items = intval($number_of_items);
  109. $column = intval($column);
  110. $direction = !in_array(strtolower(trim($direction)), ['asc', 'desc']) ? 'asc' : $direction;
  111. $sql = "SELECT
  112. id AS col0,
  113. code AS col1,
  114. title AS col2,
  115. category_code AS col3,
  116. tutor_name AS col4,
  117. request_date AS col5,
  118. id AS col6
  119. FROM $course_request_table
  120. WHERE status = ".COURSE_REQUEST_REJECTED;
  121. if ($keyword != '') {
  122. $sql .= " AND (
  123. title LIKE '%".$keyword."%' OR
  124. code LIKE '%".$keyword."%' OR
  125. visual_code LIKE '%".$keyword."%'
  126. )";
  127. }
  128. $sql .= " ORDER BY col$column $direction ";
  129. $sql .= " LIMIT $from,$number_of_items";
  130. $res = Database :: query($sql);
  131. $course_requests = [];
  132. while ($course_request = Database :: fetch_row($res)) {
  133. $course_request[5] = api_get_local_time($course_request[5]);
  134. $course_requests[] = $course_request;
  135. }
  136. return $course_requests;
  137. }
  138. /**
  139. * Actions in the list: edit, accept, delete, request additional information.
  140. */
  141. function modify_filter($id)
  142. {
  143. $code = CourseRequestManager::get_course_request_code($id);
  144. $result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.
  145. Display::return_icon('edit.png', get_lang('Edit'), ['style' => 'vertical-align: middle;']).'</a>'.
  146. '&nbsp;<a href="?accept_course_request='.$id.'">'.
  147. Display::return_icon(
  148. 'accept.png',
  149. get_lang('AcceptThisCourseRequest'),
  150. [
  151. 'style' => 'vertical-align: middle;',
  152. 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;',
  153. ]
  154. ).
  155. '</a>';
  156. if (!CourseRequestManager::additional_info_asked($id)) {
  157. $result .= '&nbsp;<a href="?request_info='.$id.'">'.
  158. Display::return_icon(
  159. 'request_info.gif',
  160. get_lang('AskAdditionalInfo'),
  161. [
  162. 'style' => 'vertical-align: middle;',
  163. 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;',
  164. ]
  165. ).
  166. '</a>';
  167. }
  168. $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.
  169. Display::return_icon(
  170. 'delete.png',
  171. get_lang('DeleteThisCourseRequest'),
  172. [
  173. 'style' => 'vertical-align: middle;',
  174. 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;',
  175. ]
  176. ).
  177. '</a>';
  178. return $result;
  179. }
  180. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  181. $interbreadcrumb[] = ['url' => 'course_list.php', 'name' => get_lang('CourseList')];
  182. $tool_name = get_lang('RejectedCourseRequests');
  183. // Display confirmation or error message.
  184. if (!empty($message)) {
  185. if ($is_error_message) {
  186. Display::addFlash(Display::return_message($message, 'error', false));
  187. } else {
  188. Display::addFlash(Display::return_message($message, 'normal', false));
  189. }
  190. }
  191. Display::display_header($tool_name);
  192. if (!$course_validation_feature) {
  193. Display :: display_footer();
  194. exit;
  195. }
  196. // Create a simple search-box.
  197. $form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
  198. $renderer = $form->defaultRenderer();
  199. $renderer->setCustomElementTemplate('<span>{element}</span> ');
  200. $form->addElement('text', 'keyword', get_lang('Keyword'));
  201. $form->addButtonSearch(get_lang('Search'));
  202. // The action bar.
  203. echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
  204. echo ' <a href="course_request_review.php">'.
  205. Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').
  206. '</a>';
  207. echo ' <a href="course_request_accepted.php">'.
  208. Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').
  209. '</a>';
  210. echo '</div>';
  211. echo '<div class="actions">';
  212. $form->display();
  213. echo '</div>';
  214. // Create a sortable table with the course data.
  215. $table = new SortableTable('course_requests_rejected', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
  216. $table->set_header(0, '', false);
  217. $table->set_header(1, get_lang('Code'));
  218. $table->set_header(2, get_lang('Title'));
  219. $table->set_header(3, get_lang('Category'));
  220. $table->set_header(4, get_lang('Teacher'));
  221. $table->set_header(5, get_lang('CourseRequestDate'));
  222. $table->set_header(6, '', false);
  223. $table->set_column_filter(6, 'modify_filter');
  224. $table->set_form_actions(['delete_course_requests' => get_lang('DeleteCourseRequests')], 'course_request');
  225. $table->display();
  226. Display::display_footer();