course_list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. // $Id: course_list.php 14573 2008-03-11 22:54:59Z yannoo $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  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: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * @package dokeos.admin
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. // name of the language file that needs to be included
  32. $language_file = 'admin';
  33. $cidReset = true;
  34. require ('../inc/global.inc.php');
  35. $this_section = SECTION_PLATFORM_ADMIN;
  36. api_protect_admin_script();
  37. require_once (api_get_path(LIBRARY_PATH)."course.lib.php");
  38. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  39. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  40. /**
  41. * Get the number of courses which will be displayed
  42. */
  43. function get_number_of_courses()
  44. {
  45. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  46. $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table";
  47. if (isset ($_GET['keyword']))
  48. {
  49. $keyword = mysql_real_escape_string($_GET['keyword']);
  50. $sql .= " WHERE title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%'";
  51. }
  52. elseif (isset ($_GET['keyword_code']))
  53. {
  54. $keyword_code = mysql_real_escape_string($_GET['keyword_code']);
  55. $keyword_title = mysql_real_escape_string($_GET['keyword_title']);
  56. $keyword_category = mysql_real_escape_string($_GET['keyword_category']);
  57. $keyword_language = mysql_real_escape_string($_GET['keyword_language']);
  58. $keyword_visibility = mysql_real_escape_string($_GET['keyword_visibility']);
  59. $keyword_subscribe = mysql_real_escape_string($_GET['keyword_subscribe']);
  60. $keyword_unsubscribe = mysql_real_escape_string($_GET['keyword_unsubscribe']);
  61. $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."'";
  62. }
  63. $res = api_sql_query($sql, __FILE__, __LINE__);
  64. $obj = mysql_fetch_object($res);
  65. return $obj->total_number_of_items;
  66. }
  67. /**
  68. * Get course data to display
  69. */
  70. function get_course_data($from, $number_of_items, $column, $direction)
  71. {
  72. $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  73. $users_table = Database :: get_main_table(TABLE_MAIN_USER);
  74. $course_users_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  75. $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";
  76. if (isset ($_GET['keyword']))
  77. {
  78. $keyword = mysql_real_escape_string($_GET['keyword']);
  79. $sql .= " WHERE title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%'";
  80. }
  81. elseif (isset ($_GET['keyword_code']))
  82. {
  83. $keyword_code = mysql_real_escape_string($_GET['keyword_code']);
  84. $keyword_title = mysql_real_escape_string($_GET['keyword_title']);
  85. $keyword_category = mysql_real_escape_string($_GET['keyword_category']);
  86. $keyword_language = mysql_real_escape_string($_GET['keyword_language']);
  87. $keyword_visibility = mysql_real_escape_string($_GET['keyword_visibility']);
  88. $keyword_subscribe = mysql_real_escape_string($_GET['keyword_subscribe']);
  89. $keyword_unsubscribe = mysql_real_escape_string($_GET['keyword_unsubscribe']);
  90. $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."'";
  91. }
  92. $sql .= " ORDER BY col$column $direction ";
  93. $sql .= " LIMIT $from,$number_of_items";
  94. $res = api_sql_query($sql, __FILE__, __LINE__);
  95. $courses = array ();
  96. while ($course = mysql_fetch_row($res))
  97. {
  98. //place colour icons in front of courses
  99. $course[1] = get_course_visibility_icon($course[10]).$course[1];
  100. $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  101. $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
  102. $course[7] = CourseManager :: is_virtual_course_from_system_code($course[7]) ? get_lang('Yes') : get_lang('No');
  103. $course_rem = array($course[0],$course[1],$course[2],$course[3],$course[4],$course[5],$course[6],$course[7],$course[8],$course[9]);
  104. $courses[] = $course_rem;
  105. }
  106. return $courses;
  107. }
  108. /**
  109. * Filter to display the edit-buttons
  110. */
  111. function modify_filter($code)
  112. {
  113. global $charset;
  114. return
  115. '<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;'.
  116. '<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;'.
  117. '<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;'.
  118. '<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;'.
  119. '<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>';
  120. }
  121. /**
  122. * Return an icon representing the visibility of the course
  123. */
  124. function get_course_visibility_icon($v)
  125. {
  126. $path = api_get_path(REL_CODE_PATH);
  127. $style = 'style="margin-bottom:-5px;margin-right:5px;"';
  128. switch($v)
  129. {
  130. case 0:
  131. return '<img src="'.$path.'img/bullet_red.gif" title="'.get_lang('CourseVisibilityClosed').'" '.$style.' />';
  132. break;
  133. case 1:
  134. return '<img src="'.$path.'img/bullet_orange.gif" title="'.get_lang('Private').'" '.$style.' />';
  135. break;
  136. case 2:
  137. return '<img src="'.$path.'img/bullet_green.gif" title="'.get_lang('OpenToThePlatform').'" '.$style.' />';
  138. break;
  139. case 3:
  140. return '<img src="'.$path.'img/bullet_blue.gif" title="'.get_lang('OpenToTheWorld').'" '.$style.' />';
  141. break;
  142. default:
  143. return '';
  144. }
  145. }
  146. if (isset ($_POST['action']))
  147. {
  148. switch ($_POST['action'])
  149. {
  150. // Delete selected courses
  151. case 'delete_courses' :
  152. $course_codes = $_POST['course'];
  153. if (count($course_codes) > 0)
  154. {
  155. foreach ($course_codes as $index => $course_code)
  156. {
  157. CourseManager :: delete_course($course_code);
  158. }
  159. }
  160. break;
  161. }
  162. }
  163. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  164. {
  165. // Get all course categories
  166. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  167. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  168. $res = api_sql_query($sql, __FILE__, __LINE__);
  169. $categories['%'] = get_lang('All');
  170. while ($cat = mysql_fetch_array($res))
  171. {
  172. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  173. }
  174. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  175. $interbreadcrumb[] = array ("url" => 'course_list.php', "name" => get_lang('CourseList'));
  176. $tool_name = get_lang('SearchACourse');
  177. Display :: display_header($tool_name);
  178. //api_display_tool_title($tool_name);
  179. $form = new FormValidator('advanced_course_search', 'get');
  180. $form->add_textfield('keyword_code', get_lang('CourseCode'), false);
  181. $form->add_textfield('keyword_title', get_lang('Title'), false);
  182. $form->addElement('select', 'keyword_category', get_lang('CourseFaculty'), $categories);
  183. $el = & $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
  184. $el->addOption(get_lang('All'), '%');
  185. $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  186. $form->addElement('radio', 'keyword_visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  187. $form->addElement('radio', 'keyword_visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  188. $form->addElement('radio', 'keyword_visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  189. $form->addElement('radio', 'keyword_visibility', null, get_lang('All'), '%');
  190. $form->addElement('radio', 'keyword_subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  191. $form->addElement('radio', 'keyword_subscribe', null, get_lang('Denied'), 0);
  192. $form->addElement('radio', 'keyword_subscribe', null, get_lang('All'), '%');
  193. $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  194. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  195. $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
  196. $form->addElement('submit', 'submit', get_lang('Ok'));
  197. $defaults['keyword_language'] = '%';
  198. $defaults['keyword_visibility'] = '%';
  199. $defaults['keyword_subscribe'] = '%';
  200. $defaults['keyword_unsubscribe'] = '%';
  201. $form->setDefaults($defaults);
  202. $form->display();
  203. }
  204. else
  205. {
  206. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  207. $tool_name = get_lang('CourseList');
  208. Display :: display_header($tool_name);
  209. //api_display_tool_title($tool_name);
  210. if (isset ($_GET['delete_course']))
  211. {
  212. CourseManager :: delete_course($_GET['delete_course']);
  213. }
  214. // Create a search-box
  215. $form = new FormValidator('search_simple','get','','',null,false);
  216. $renderer =& $form->defaultRenderer();
  217. $renderer->setElementTemplate('<span>{element}</span> ');
  218. $form->addElement('text','keyword',get_lang('keyword'));
  219. $form->addElement('submit','submit',get_lang('Search'));
  220. $form->addElement('static','search_advanced_link',null,'<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  221. $form->display();
  222. // Create a sortable table with the course data
  223. $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data',2);
  224. $table->set_additional_parameters($parameters);
  225. $table->set_header(0, '', false);
  226. $table->set_header(1, get_lang('Code'));
  227. $table->set_header(2, get_lang('Title'));
  228. $table->set_header(3, get_lang('Language'));
  229. $table->set_header(4, get_lang('Category'));
  230. $table->set_header(5, get_lang('SubscriptionAllowed'));
  231. $table->set_header(6, get_lang('UnsubscriptionAllowed'));
  232. $table->set_header(7, get_lang('IsVirtualCourse'));
  233. $table->set_header(8, get_lang('Teacher'));
  234. $table->set_header(9, '', false);
  235. $table->set_column_filter(9,'modify_filter');
  236. $table->set_form_actions(array ('delete_courses' => get_lang('DeleteCourse')),'course');
  237. $table->display();
  238. }
  239. /*
  240. ==============================================================================
  241. FOOTER
  242. ==============================================================================
  243. */
  244. Display :: display_footer();
  245. ?>