course_request_review.php 12 KB

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