course_request_accepted.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A list containig the accepted 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. // Language files that need to be included.
  13. $language_file = array('admin', 'create_course');
  14. $cidReset = true;
  15. require '../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. // Including a configuration file.
  22. require api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
  23. // Include additional libraries
  24. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  25. // A check whether the course validation feature is enabled.
  26. $course_validation_feature = api_get_setting('course_validation') == 'true';
  27. // Filltering passed to this page parameters.
  28. $delete_course_request = intval($_GET['delete_course_request']);
  29. $message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
  30. $is_error_message = !empty($_GET['is_error_message']);
  31. if ($course_validation_feature) {
  32. /**
  33. * Deletion of a course request.
  34. */
  35. if (!empty($delete_course_request)) {
  36. $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
  37. $result = CourseRequestManager::delete_course_request($delete_course_request);
  38. if ($result) {
  39. $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
  40. $is_error_message = false;
  41. } else {
  42. $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
  43. $is_error_message = true;
  44. }
  45. }
  46. /**
  47. * Form actions: delete.
  48. */
  49. elseif (isset($_POST['action'])) {
  50. switch ($_POST['action']) {
  51. // Delete selected courses
  52. case 'delete_course_requests' :
  53. $course_requests = $_POST['course_request'];
  54. if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
  55. $success = true;
  56. foreach ($_POST['course_request'] as $index => $course_request_id) {
  57. $success &= CourseRequestManager::delete_course_request($course_request_id);
  58. }
  59. $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
  60. $is_error_message = !$success;
  61. }
  62. break;
  63. }
  64. }
  65. } else {
  66. $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
  67. $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
  68. $is_error_message = true;
  69. }
  70. /**
  71. * Get the number of courses which will be displayed.
  72. */
  73. function get_number_of_requests() {
  74. return CourseRequestManager::count_course_requests(COURSE_REQUEST_ACCEPTED);
  75. }
  76. /**
  77. * Get course data to display
  78. */
  79. function get_request_data($from, $number_of_items, $column, $direction)
  80. {
  81. $keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : null;
  82. $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
  83. $sql = "SELECT id AS col0,
  84. code AS col1,
  85. title AS col2,
  86. category_code AS col3,
  87. tutor_name AS col4,
  88. request_date AS col5,
  89. id AS col6
  90. FROM $course_request_table WHERE status = ".COURSE_REQUEST_ACCEPTED;
  91. if ($keyword != '') {
  92. $sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
  93. }
  94. $sql .= " ORDER BY col$column $direction ";
  95. $sql .= " LIMIT $from,$number_of_items";
  96. $res = Database :: query($sql);
  97. $course_requests = array();
  98. while ($course_request = Database :: fetch_row($res)) {
  99. $course_request[5] = api_get_local_time($course_request[5]);
  100. $course_requests[] = $course_request;
  101. }
  102. return $course_requests;
  103. }
  104. /**
  105. * Actions in the list: edit, accept, delete.
  106. */
  107. function modify_filter($id)
  108. {
  109. $code = CourseRequestManager::get_course_request_code($id);
  110. $result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
  111. '&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>';
  112. return $result;
  113. }
  114. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  115. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  116. $tool_name = get_lang('AcceptedCourseRequests');
  117. Display :: display_header($tool_name);
  118. // Display confirmation or error message.
  119. if (!empty($message)) {
  120. if ($is_error_message) {
  121. Display::display_error_message($message, false);
  122. } else {
  123. Display::display_normal_message($message, false);
  124. }
  125. }
  126. if (!$course_validation_feature) {
  127. Display :: display_footer();
  128. exit;
  129. }
  130. // Create a simple search-box.
  131. $form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
  132. $renderer = $form->defaultRenderer();
  133. $renderer->setElementTemplate('<span>{element}</span> ');
  134. $form->addElement('text', 'keyword', get_lang('keyword'));
  135. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
  136. // The action bar.
  137. echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
  138. //echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
  139. echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
  140. echo ' <a href="course_request_rejected.php">'.Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
  141. echo '</div>';
  142. echo '<div class="actions">';
  143. $form->display();
  144. echo '</div>';
  145. // Create a sortable table with the course data.
  146. $table = new SortableTable('course_requests_accepted', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
  147. //$table->set_additional_parameters($parameters);
  148. $table->set_header(0, '', false);
  149. $table->set_header(1, get_lang('Code'));
  150. $table->set_header(2, get_lang('Title'));
  151. $table->set_header(3, get_lang('Category'));
  152. $table->set_header(4, get_lang('Teacher'));
  153. $table->set_header(5, get_lang('CourseRequestDate'));
  154. $table->set_header(6, '', false);
  155. $table->set_column_filter(6, 'modify_filter');
  156. $table->set_form_actions(array('delete_course_requests' => get_lang('DeleteCourseRequests')), 'course_request');
  157. $table->display();
  158. /* FOOTER */
  159. Display :: display_footer();