course_list.php 19 KB

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