course_list.php 20 KB

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