course_list.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * This script shows a list of courses and allows searching for courses codes
  6. * and names
  7. * @package chamilo.admin
  8. */
  9. /* INIT SECTION */
  10. // Language files that need to be included.
  11. $language_file = array('admin', 'courses');
  12. $cidReset = true;
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. api_protect_admin_script();
  15. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
  16. /**
  17. * Get the number of courses which will be displayed
  18. */
  19. function get_number_of_courses()
  20. {
  21. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  22. $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table course";
  23. if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
  24. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  25. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (course.id = url_rel_course.c_id)";
  26. }
  27. if (isset ($_GET['keyword'])) {
  28. $keyword = Database::escape_string($_GET['keyword']);
  29. $sql .= " WHERE (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
  30. } elseif (isset ($_GET['keyword_code'])) {
  31. $keyword_code = Database::escape_string($_GET['keyword_code']);
  32. $keyword_title = Database::escape_string($_GET['keyword_title']);
  33. $keyword_category = Database::escape_string($_GET['keyword_category']);
  34. $keyword_language = Database::escape_string($_GET['keyword_language']);
  35. $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
  36. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  37. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  38. $sql .= " WHERE (code LIKE '%".$keyword_code."%' OR visual_code LIKE '%".$keyword_code."%') AND
  39. title LIKE '%".$keyword_title."%' AND
  40. category_code LIKE '%".$keyword_category."%' AND
  41. course_language LIKE '%".$keyword_language."%' AND
  42. visibility LIKE '%".$keyword_visibility."%' AND
  43. subscribe LIKE '".$keyword_subscribe."'AND
  44. unsubscribe LIKE '".$keyword_unsubscribe."'";
  45. }
  46. // adding the filter to see the user's only of the current access_url
  47. if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
  48. $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
  49. }
  50. $res = Database::query($sql);
  51. $obj = Database::fetch_object($res);
  52. return $obj->total_number_of_items;
  53. }
  54. /**
  55. * Get course data to display
  56. * @param int $from
  57. * @param int $number_of_items
  58. * @param int $column
  59. * @param string $direction
  60. * @return array
  61. */
  62. function get_course_data($from, $number_of_items, $column, $direction) {
  63. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  64. $sql = "SELECT code AS col0,
  65. title AS col1,
  66. code AS col2,
  67. course_language AS col3,
  68. category_code AS col4,
  69. subscribe AS col5,
  70. unsubscribe AS col6,
  71. code AS col7,
  72. visibility AS col8,
  73. directory as col9,
  74. visual_code
  75. FROM $course_table course";
  76. if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
  77. $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  78. $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (course.id = url_rel_course.c_id)";
  79. }
  80. if (isset ($_GET['keyword'])) {
  81. $keyword = Database::escape_string(trim($_GET['keyword']));
  82. $sql .= " WHERE (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%' ) ";
  83. } elseif (isset ($_GET['keyword_code'])) {
  84. $keyword_code = Database::escape_string($_GET['keyword_code']);
  85. $keyword_title = Database::escape_string($_GET['keyword_title']);
  86. $keyword_category = Database::escape_string($_GET['keyword_category']);
  87. $keyword_language = Database::escape_string($_GET['keyword_language']);
  88. $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
  89. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  90. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  91. $sql .= " WHERE (code LIKE '%".$keyword_code."%' OR visual_code LIKE '%".$keyword_code."%') AND title LIKE '%".$keyword_title."%' AND category_code LIKE '%".$keyword_category."%' AND course_language LIKE '%".$keyword_language."%' AND visibility LIKE '%".$keyword_visibility."%' AND subscribe LIKE '".$keyword_subscribe."'AND unsubscribe LIKE '".$keyword_unsubscribe."'";
  92. }
  93. // Adding the filter to see the user's only of the current access_url.
  94. if ((api_is_platform_admin() || api_is_session_admin()) && api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1) {
  95. $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
  96. }
  97. $sql .= " ORDER BY col$column $direction ";
  98. $sql .= " LIMIT $from,$number_of_items";
  99. $res = Database::query($sql);
  100. $courses = array ();
  101. while ($course = Database::fetch_array($res)) {
  102. // Place colour icons in front of courses.
  103. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
  104. $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
  105. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  106. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  107. $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
  108. $courses[] = $course_rem;
  109. }
  110. return $courses;
  111. }
  112. /**
  113. * Get course data to display filtered by session name
  114. * @param int $from
  115. * @param int $number_of_items
  116. * @param int $column
  117. * @param string $direction
  118. * @return array
  119. */
  120. function get_course_data_by_session($from, $number_of_items, $column, $direction)
  121. {
  122. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  123. $session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  124. $session = Database::get_main_table(TABLE_MAIN_SESSION);
  125. $sql = "SELECT c.code AS col0,
  126. c.title AS col1,
  127. c.code AS col2,
  128. c.course_language AS col3,
  129. c.category_code AS col4,
  130. c.subscribe AS col5,
  131. c.unsubscribe AS col6,
  132. c.code AS col7,
  133. c.visibility AS col8,
  134. c.directory as col9,
  135. c.visual_code
  136. FROM $course_table c
  137. INNER JOIN $session_rel_course r ON c.code = r.course_code
  138. INNER JOIN $session s ON r.id_session = s.id
  139. ";
  140. if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
  141. $sessionId = intval($_GET['session_id']);
  142. $sql.= " WHERE s.id = ".$sessionId;
  143. }
  144. $sql .= " ORDER BY col$column $direction ";
  145. $sql .= " LIMIT $from,$number_of_items";
  146. $res = Database::query($sql);
  147. $courses = array ();
  148. while ($course = Database::fetch_array($res)) {
  149. // Place colour icons in front of courses.
  150. $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
  151. $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
  152. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  153. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  154. $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
  155. $courses[] = $course_rem;
  156. }
  157. return $courses;
  158. }
  159. /**
  160. * Filter to display the edit-buttons
  161. */
  162. function modify_filter($code)
  163. {
  164. $icourse = api_get_course_info($code);
  165. return
  166. '<a href="course_information.php?code='.$code.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;'.
  167. //'<a href="../course_home/course_home.php?cidReq='.$code.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'. // This is not the preferable way to go to the homepage.
  168. '<a href="'.api_get_path(WEB_COURSE_PATH).$icourse['path'].'/index.php">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>&nbsp;'.
  169. '<a href="../tracking/courseLog.php?cidReq='.$code.'">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;'.
  170. '<a href="course_edit.php?course_code='.$code.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;'.
  171. '<a href="../coursecopy/backup.php?cidReq='.$code.'">'.Display::return_icon('backup.gif', get_lang('CreateBackup')).'</a>&nbsp;'.
  172. '<a href="course_list.php?delete_course='.$code.'" onclick="javascript: if (!confirm('."'".addslashes(get_lang('ConfirmYourChoice'))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  173. }
  174. /**
  175. * Return an icon representing the visibility of the course
  176. */
  177. function get_course_visibility_icon($v) {
  178. $style = 'margin-bottom:-5px;margin-right:5px;';
  179. switch($v) {
  180. case 0:
  181. return Display::return_icon('bullet_red.gif', get_lang('CourseVisibilityClosed'), array('style' => $style));
  182. break;
  183. case 1:
  184. return Display::return_icon('bullet_orange.gif', get_lang('Private'), array('style' => $style));
  185. break;
  186. case 2:
  187. return Display::return_icon('bullet_green.gif', get_lang('OpenToThePlatform'), array('style' => $style));
  188. break;
  189. case 3:
  190. return Display::return_icon('bullet_blue.gif', get_lang('OpenToTheWorld'), array('style' => $style));
  191. break;
  192. case 4:
  193. return Display::return_icon('bullet_grey.gif', get_lang('CourseVisibilityHidden'), array('style' => $style));
  194. break;
  195. default:
  196. return '';
  197. }
  198. }
  199. if (isset ($_POST['action'])) {
  200. switch ($_POST['action']) {
  201. // Delete selected courses
  202. case 'delete_courses':
  203. $course_codes = $_POST['course'];
  204. if (count($course_codes) > 0) {
  205. foreach ($course_codes as $course_code) {
  206. CourseManager::delete_course($course_code);
  207. $obj_cat = new Category();
  208. $obj_cat->update_category_delete($course_code);
  209. }
  210. }
  211. break;
  212. }
  213. }
  214. $content = '';
  215. $message = '';
  216. $actions = '';
  217. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  218. // Get all course categories
  219. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  220. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  221. $tool_name = get_lang('SearchACourse');
  222. //api_display_tool_title($tool_name);
  223. $form = new FormValidator('advanced_course_search', 'get');
  224. $form->addElement('header', $tool_name);
  225. $form->add_textfield('keyword_code', get_lang('CourseCode'), false);
  226. $form->add_textfield('keyword_title', get_lang('Title'), false);
  227. // Category code
  228. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
  229. $form->addElement(
  230. 'select_ajax',
  231. 'keyword_category',
  232. get_lang('CourseFaculty'),
  233. null,
  234. array(
  235. 'url' => $url
  236. )
  237. );
  238. $el = $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
  239. $el->addOption(get_lang('All'), '%');
  240. $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  241. $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  242. $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  243. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  244. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  245. $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
  246. $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  247. $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
  248. $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
  249. $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  250. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  251. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
  252. $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
  253. $defaults['keyword_language'] = '%';
  254. $defaults['keyword_visibility'] = '%';
  255. $defaults['keyword_subscribe'] = '%';
  256. $defaults['keyword_unsubscribe'] = '%';
  257. $form->setDefaults($defaults);
  258. $content .= $form->return_form();
  259. } else {
  260. $interbreadcrumb[] = array ('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
  261. $tool_name = get_lang('CourseList');
  262. if (isset($_GET['action'])) {
  263. switch ($_GET['action']) {
  264. case 'show_msg':
  265. if (!empty($_GET['warn'])) {
  266. $message = Display::return_message(urldecode($_GET['warn']), 'warning');
  267. }
  268. if (!empty($_GET['msg'])) {
  269. $message = Display::return_message(urldecode($_GET['msg']));
  270. }
  271. break;
  272. default:
  273. break;
  274. }
  275. }
  276. if (isset($_GET['delete_course'])) {
  277. CourseManager::delete_course($_GET['delete_course']);
  278. $obj_cat = new Category();
  279. $obj_cat->update_category_delete($_GET['delete_course']);
  280. }
  281. // Create a search-box
  282. $form = new FormValidator('search_simple', 'get', '', '', array('class'=>'form-inline'), false);
  283. $form->addElement('text', 'keyword', null);
  284. $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
  285. $form->addElement('static', 'search_advanced_link', null, '<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  286. // Create a filter by session
  287. $sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
  288. $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
  289. $sessionList = array();
  290. if (!empty($sessionId)) {
  291. $sessionList = array();
  292. $sessionInfo = SessionManager::fetch($sessionId);
  293. $sessionList[] = array('id' => $sessionInfo['id'], 'text' => $sessionInfo['name']);
  294. }
  295. $sessionFilter->addElement('select_ajax', 'session_name', get_lang('SearchCourseBySession'), null, array('url' => $url, 'defaults' => $sessionList));
  296. $courseListUrl = api_get_self();
  297. $actions = '
  298. <script>
  299. $(function() {
  300. $("#session_name").on("change", function() {
  301. var sessionId = $(this).val();
  302. window.location = "'.$courseListUrl.'?session_id="+sessionId;
  303. });
  304. });
  305. </script>';
  306. $actions .= '<div class="pull-right">';
  307. $actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
  308. if (api_get_setting('course.course_validation') == 'true') {
  309. $actions .= '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests'),'',ICON_SIZE_MEDIUM).'</a>';
  310. }
  311. $actions .= '</div>';
  312. $actions .= '<div class="pull-right">';
  313. $actions .= $sessionFilter->return_form();
  314. $actions .= '</div>';
  315. $actions .= $form->return_form();
  316. if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
  317. // Create a sortable table with the course data filtered by session
  318. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data_by_session', 2);
  319. } else {
  320. // Create a sortable table with the course data
  321. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
  322. }
  323. $parameters=array();
  324. if (isset ($_GET['keyword'])) {
  325. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  326. } elseif (isset ($_GET['keyword_code'])) {
  327. $parameters['keyword_code'] = Security::remove_XSS($_GET['keyword_code']);
  328. $parameters['keyword_title'] = Security::remove_XSS($_GET['keyword_title']);
  329. $parameters['keyword_category'] = Security::remove_XSS($_GET['keyword_category']);
  330. $parameters['keyword_language'] = Security::remove_XSS($_GET['keyword_language']);
  331. $parameters['keyword_visibility'] = Security::remove_XSS($_GET['keyword_visibility']);
  332. $parameters['keyword_subscribe'] = Security::remove_XSS($_GET['keyword_subscribe']);
  333. $parameters['keyword_unsubscribe'] = Security::remove_XSS($_GET['keyword_unsubscribe']);
  334. }
  335. $table->set_additional_parameters($parameters);
  336. $table->set_header(0, '', false, 'width="8px"');
  337. $table->set_header(1, get_lang('Title'), true, 'width="360px"');
  338. $table->set_header(2, get_lang('Code'));
  339. $table->set_header(3, get_lang('Language'), true, 'width="70px"');
  340. $table->set_header(4, get_lang('Category'));
  341. $table->set_header(5, get_lang('SubscriptionAllowed'), true, 'width="60px"');
  342. $table->set_header(6, get_lang('UnsubscriptionAllowed'), false, 'width="50px"');
  343. //$table->set_header(7, get_lang('Teacher'));
  344. $table->set_header(7, get_lang('Action'), false, 'width="160px"', array('class'=>'td_actions'));
  345. $table->set_column_filter(7, 'modify_filter');
  346. $table->set_form_actions(array('delete_courses' => get_lang('DeleteCourse')), 'course');
  347. $content .= $table->return_table();
  348. }
  349. echo $actions;
  350. echo $message;
  351. echo $content;