course_request_review.php 12 KB

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