course_request_rejected.php 9.3 KB

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