course_request_review.php 13 KB

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