course_list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. // $Id: course_list.php 15245 2008-05-08 16:53:52Z juliomontoya $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2008 Dokeos SPRL
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  19. Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22. /**
  23. ==============================================================================
  24. * @package dokeos.admin
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. INIT SECTION
  30. ==============================================================================
  31. */
  32. // name of the language file that needs to be included
  33. $language_file = 'admin';
  34. $cidReset = true;
  35. require ('../inc/global.inc.php');
  36. $this_section = SECTION_PLATFORM_ADMIN;
  37. api_protect_admin_script();
  38. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  39. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  40. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  41. /**
  42. * Get the number of courses which will be displayed
  43. */
  44. function get_number_of_courses()
  45. {
  46. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  47. $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table";
  48. if (isset ($_GET['keyword']))
  49. {
  50. $keyword = Database::escape_string($_GET['keyword']);
  51. $sql .= " WHERE title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%'";
  52. }
  53. elseif (isset ($_GET['keyword_code']))
  54. {
  55. $keyword_code = Database::escape_string($_GET['keyword_code']);
  56. $keyword_title = Database::escape_string($_GET['keyword_title']);
  57. $keyword_category = Database::escape_string($_GET['keyword_category']);
  58. $keyword_language = Database::escape_string($_GET['keyword_language']);
  59. $keyword_visibility = Database::escape_string($_GET['keyword_visibility']);
  60. $keyword_subscribe = Database::escape_string($_GET['keyword_subscribe']);
  61. $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
  62. $sql .= " WHERE 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."'";
  63. }
  64. $res = api_sql_query($sql, __FILE__, __LINE__);
  65. $obj = Database::fetch_object($res);
  66. return $obj->total_number_of_items;
  67. }
  68. /**
  69. * Get course data to display
  70. */
  71. function get_course_data($from, $number_of_items, $column, $direction)
  72. {
  73. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  74. $users_table = Database :: get_main_table(TABLE_MAIN_USER);
  75. $course_users_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  76. $sql = "SELECT code AS col0, visual_code AS col1, title AS col2, course_language AS col3, category_code AS col4, subscribe AS col5, unsubscribe AS col6, code AS col7, tutor_name as col8, code AS col9, visibility AS col10 FROM $course_table";
  77. if (isset ($_GET['keyword']))
  78. {
  79. $keyword = Database::escape_string($_GET['keyword']);
  80. $sql .= " WHERE title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%'";
  81. }
  82. elseif (isset ($_GET['keyword_code']))
  83. {
  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."%' 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. $sql .= " ORDER BY col$column $direction ";
  94. $sql .= " LIMIT $from,$number_of_items";
  95. $res = api_sql_query($sql, __FILE__, __LINE__);
  96. $courses = array ();
  97. while ($course = Database::fetch_row($res))
  98. {
  99. //place colour icons in front of courses
  100. $course[1] = get_course_visibility_icon($course[10]).$course[1];
  101. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  102. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  103. $course[7] = CourseManager :: is_virtual_course_from_system_code($course[7]) ? get_lang('Yes') : get_lang('No');
  104. $course_rem = array($course[0],$course[1],$course[2],$course[3],$course[4],$course[5],$course[6],$course[7],$course[8],$course[9]);
  105. $courses[] = $course_rem;
  106. }
  107. return $courses;
  108. }
  109. /**
  110. * Filter to display the edit-buttons
  111. */
  112. function modify_filter($code)
  113. {
  114. global $charset;
  115. return
  116. '<a href="course_information.php?code='.$code.'"><img src="../img/synthese_view.gif" border="0" style="vertical-align: middle" title="'.get_lang('Info').'" alt="'.get_lang('Info').'"/></a>&nbsp;'.
  117. '<a href="../course_home/course_home.php?cidReq='.$code.'"><img src="../img/course_home.gif" border="0" style="vertical-align: middle" title="'.get_lang('CourseHomepage').'" alt="'.get_lang('CourseHomepage').'"/></a>&nbsp;'.
  118. '<a href="../tracking/courseLog.php?cidReq='.$code.'"><img src="../img/statistics.gif" border="0" style="vertical-align: middle" title="'.get_lang('Tracking').'" alt="'.get_lang('Tracking').'"/></a>&nbsp;'.
  119. '<a href="course_edit.php?course_code='.$code.'"><img src="../img/edit.gif" border="0" style="vertical-align: middle" title="'.get_lang('Edit').'" alt="'.get_lang('Edit').'"/></a>&nbsp;'.
  120. '<a href="course_list.php?delete_course='.$code.'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;"><img src="../img/delete.gif" border="0" style="vertical-align: middle" title="'.get_lang('Delete').'" alt="'.get_lang('Delete').'"/></a>';
  121. }
  122. /**
  123. * Return an icon representing the visibility of the course
  124. */
  125. function get_course_visibility_icon($v)
  126. {
  127. $path = api_get_path(REL_CODE_PATH);
  128. $style = 'style="margin-bottom:-5px;margin-right:5px;"';
  129. switch($v)
  130. {
  131. case 0:
  132. return '<img src="'.$path.'img/bullet_red.gif" title="'.get_lang('CourseVisibilityClosed').'" '.$style.' />';
  133. break;
  134. case 1:
  135. return '<img src="'.$path.'img/bullet_orange.gif" title="'.get_lang('Private').'" '.$style.' />';
  136. break;
  137. case 2:
  138. return '<img src="'.$path.'img/bullet_green.gif" title="'.get_lang('OpenToThePlatform').'" '.$style.' />';
  139. break;
  140. case 3:
  141. return '<img src="'.$path.'img/bullet_blue.gif" title="'.get_lang('OpenToTheWorld').'" '.$style.' />';
  142. break;
  143. default:
  144. return '';
  145. }
  146. }
  147. if (isset ($_POST['action']))
  148. {
  149. switch ($_POST['action'])
  150. {
  151. // Delete selected courses
  152. case 'delete_courses' :
  153. $course_codes = $_POST['course'];
  154. if (count($course_codes) > 0)
  155. {
  156. foreach ($course_codes as $index => $course_code)
  157. {
  158. CourseManager :: delete_course($course_code);
  159. }
  160. }
  161. break;
  162. }
  163. }
  164. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  165. {
  166. // Get all course categories
  167. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  168. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  169. $res = api_sql_query($sql, __FILE__, __LINE__);
  170. $categories['%'] = get_lang('All');
  171. while ($cat = Database::fetch_array($res))
  172. {
  173. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  174. }
  175. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  176. $interbreadcrumb[] = array ("url" => 'course_list.php', "name" => get_lang('CourseList'));
  177. $tool_name = get_lang('SearchACourse');
  178. Display :: display_header($tool_name);
  179. //api_display_tool_title($tool_name);
  180. $form = new FormValidator('advanced_course_search', 'get');
  181. $form->add_textfield('keyword_code', get_lang('CourseCode'), false);
  182. $form->add_textfield('keyword_title', get_lang('Title'), false);
  183. $form->addElement('select', 'keyword_category', get_lang('CourseFaculty'), $categories);
  184. $el = & $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
  185. $el->addOption(get_lang('All'), '%');
  186. $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  187. $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  188. $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  189. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  190. $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
  191. $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  192. $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
  193. $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
  194. $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  195. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  196. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
  197. $form->addElement('submit', 'submit', get_lang('Ok'));
  198. $defaults['keyword_language'] = '%';
  199. $defaults['keyword_visibility'] = '%';
  200. $defaults['keyword_subscribe'] = '%';
  201. $defaults['keyword_unsubscribe'] = '%';
  202. $form->setDefaults($defaults);
  203. $form->display();
  204. }
  205. else
  206. {
  207. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  208. $tool_name = get_lang('CourseList');
  209. Display :: display_header($tool_name);
  210. //api_display_tool_title($tool_name);
  211. if (isset ($_GET['delete_course']))
  212. {
  213. CourseManager :: delete_course($_GET['delete_course']);
  214. }
  215. // Create a search-box
  216. $form = new FormValidator('search_simple','get','','',null,false);
  217. $renderer =& $form->defaultRenderer();
  218. $renderer->setElementTemplate('<span>{element}</span> ');
  219. $form->addElement('text','keyword',get_lang('keyword'));
  220. $form->addElement('submit','submit',get_lang('Search'));
  221. $form->addElement('static','search_advanced_link',null,'<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  222. $form->display();
  223. // Create a sortable table with the course data
  224. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data',2);
  225. $parameters=array();
  226. $table->set_additional_parameters($parameters);
  227. $table->set_header(0, '', false);
  228. $table->set_header(1, get_lang('Code'));
  229. $table->set_header(2, get_lang('Title'));
  230. $table->set_header(3, get_lang('Language'));
  231. $table->set_header(4, get_lang('Category'));
  232. $table->set_header(5, get_lang('SubscriptionAllowed'));
  233. $table->set_header(6, get_lang('UnsubscriptionAllowed'));
  234. $table->set_header(7, get_lang('IsVirtualCourse'));
  235. $table->set_header(8, get_lang('Teacher'));
  236. $table->set_header(9, get_lang('Modify'), false,'width="120px"');
  237. $table->set_column_filter(9,'modify_filter');
  238. $table->set_form_actions(array ('delete_courses' => get_lang('DeleteCourse')),'course');
  239. $table->display();
  240. }
  241. /*
  242. ==============================================================================
  243. FOOTER
  244. ==============================================================================
  245. */
  246. Display :: display_footer();
  247. ?>