user_portal.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. <?php // $Id: user_portal.php,v 1.10 2006/08/19 09:33:14 yannoo Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This is the index file displayed when a user is logged in on Dokeos.
  23. *
  24. * It displays:
  25. * - personal course list
  26. * - menu bar
  27. *
  28. * Part of the what's new ideas were based on a rene haentjens hack
  29. *
  30. * Search for
  31. * CONFIGURATION parameters
  32. * to modify settings
  33. *
  34. * @todo rewrite code to separate display, logic, database code
  35. * @package dokeos.main
  36. ==============================================================================
  37. */
  38. /**
  39. * @todo shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  40. * if these are really configuration settings then we can add those to the dokeos config settings
  41. * @todo move get_personal_course_list and some other functions to a more appripriate place course.lib.php or user.lib.php
  42. * @todo use api_get_path instead of $rootAdminWeb
  43. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  44. * @todo display_digest, shouldn't this be removed and be made into an extension?
  45. */
  46. /*
  47. ==============================================================================
  48. INIT SECTION
  49. ==============================================================================
  50. */
  51. // Don't change these settings
  52. define('SCRIPTVAL_No', 0);
  53. define('SCRIPTVAL_InCourseList', 1);
  54. define('SCRIPTVAL_UnderCourseList', 2);
  55. define('SCRIPTVAL_Both', 3);
  56. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  57. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  58. define('SCRIPTVAL_NoTimeLimit', 6);
  59. // End 'don't change' section
  60. // name of the language file that needs to be included
  61. $language_file = array ('courses', 'index');
  62. $cidReset = true; /* Flag forcing the 'current course' reset,
  63. as we're not inside a course anymore */
  64. /*
  65. -----------------------------------------------------------
  66. Included libraries
  67. -----------------------------------------------------------
  68. */
  69. include_once ('./main/inc/global.inc.php');
  70. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  71. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  72. include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
  73. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  74. include_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  75. api_block_anonymous_users(); // only users who are logged in can proceed
  76. /*
  77. -----------------------------------------------------------
  78. Table definitions
  79. -----------------------------------------------------------
  80. */
  81. //Database table definitions
  82. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  83. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  84. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  85. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  86. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  87. /*
  88. -----------------------------------------------------------
  89. Constants and CONFIGURATION parameters
  90. -----------------------------------------------------------
  91. */
  92. // ---- Course list options ----
  93. define('CONFVAL_showCourseLangIfNotSameThatPlatform', TRUE);
  94. // Preview of course content
  95. // to disable all: set CONFVAL_maxTotalByCourse = 0
  96. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  97. // by default disabled since what's new icons are better (see function display_digest() )
  98. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  99. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  100. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  101. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  102. // Order to sort data
  103. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  104. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  105. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  106. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  107. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  108. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  109. // SCRIPTVAL_UnderCourseList // best choice
  110. // SCRIPTVAL_Both // probably only for debug
  111. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  112. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  113. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  114. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  115. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  116. /*if(api_is_allowed_to_create_course() && !isset($_GET['sessionview'])){
  117. $nosession = true;
  118. }
  119. else {
  120. $nosession = false;
  121. }*/
  122. $nosession=false;
  123. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  124. if (isset($_GET['inactives'])){
  125. $display_actives = false;
  126. } else {
  127. $display_actives = true;
  128. }
  129. }
  130. $nameTools = get_lang('MyCourses');
  131. $this_section = SECTION_COURSES;
  132. /*
  133. -----------------------------------------------------------
  134. Check configuration parameters integrity
  135. -----------------------------------------------------------
  136. */
  137. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse") {
  138. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  139. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order
  140. die('
  141. <strong>config error:'.__FILE__.'</strong><br />
  142. set
  143. <ul>
  144. <li>
  145. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  146. (actually : '.CONFVAL_showExtractInfo.')
  147. </li>
  148. </ul>
  149. or
  150. <ul>
  151. <li>
  152. $orderKey[0] != "keyCourse"
  153. (actually : '.$orderKey[0].')
  154. </li>
  155. </ul>');
  156. }else {
  157. $orderKey = array ('keyCourse', 'keyTools', 'keyTime');
  158. }
  159. }
  160. /*
  161. -----------------------------------------------------------
  162. Header
  163. include the HTTP, HTML headers plus the top banner
  164. -----------------------------------------------------------
  165. */
  166. Display :: display_header($nameTools);
  167. /*
  168. ==============================================================================
  169. FUNCTIONS
  170. display_admin_links()
  171. display_create_course_link()
  172. display_edit_course_list_links()
  173. display_digest($toolsList, $digest, $orderKey, $courses)
  174. show_notification($my_course)
  175. get_personal_course_list($user_id)
  176. get_logged_user_course_html($my_course)
  177. get_user_course_categories()
  178. ==============================================================================
  179. */
  180. /*
  181. -----------------------------------------------------------
  182. Database functions
  183. some of these can go to database layer.
  184. -----------------------------------------------------------
  185. */
  186. /**
  187. * Database function that gets the list of courses for a particular user.
  188. * @param $user_id, the id of the user
  189. * @return an array with courses
  190. */
  191. function get_personal_course_list($user_id) {
  192. // initialisation
  193. $personal_course_list = array();
  194. // table definitions
  195. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  196. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  197. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  198. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  199. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  200. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  201. $personal_course_list = array ();
  202. //Courses in which we suscribed out of any session
  203. $personal_course_list_sql = "SELECT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i,
  204. course.tutor_name t, course.course_language l, course_rel_user.status s, course_rel_user.sort sort,
  205. course_rel_user.user_course_cat user_course_cat
  206. FROM ".$main_course_table." course,".$main_course_user_table." course_rel_user
  207. WHERE course.code = course_rel_user.course_code"."
  208. AND course_rel_user.user_id = '".$user_id."'
  209. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC,i";
  210. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  211. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  212. $personal_course_list[] = $result_row;
  213. }
  214. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  215. $personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 5 as s
  216. FROM $main_course_table as course, $tbl_session_course_user as srcru
  217. WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
  218. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  219. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  220. $personal_course_list[] = $result_row;
  221. }
  222. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  223. $personal_course_list_sql = "SELECT DISTINCT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, course.tutor_name t, course.course_language l, 2 as s
  224. FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
  225. WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
  226. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  227. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  228. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  229. $personal_course_list[] = $result_row;
  230. }
  231. return $personal_course_list;
  232. }
  233. /*
  234. -----------------------------------------------------------
  235. Display functions
  236. -----------------------------------------------------------
  237. */
  238. /**
  239. * Warning: this function defines a global.
  240. * @todo use the correct get_path function
  241. */
  242. function display_admin_links() {
  243. global $rootAdminWeb;
  244. echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
  245. }
  246. /**
  247. * Enter description here...
  248. *
  249. */
  250. function display_create_course_link() {
  251. echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
  252. }
  253. /**
  254. * Enter description here...
  255. *
  256. */
  257. function display_edit_course_list_links() {
  258. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  259. }
  260. /**
  261. * Displays a digest e.g. short summary of new agenda and announcements items.
  262. * This used to be displayed in the right hand menu, but is now
  263. * disabled by default (see config settings in this file) because most people like
  264. * the what's new icons better.
  265. *
  266. * @version 1.0
  267. */
  268. function display_digest($toolsList, $digest, $orderKey, $courses) {
  269. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  270. // // // LEVEL 1 // // //
  271. reset($digest);
  272. echo "<br /><br />\n";
  273. while (list ($key1) = each($digest)) {
  274. if (is_array($digest[$key1])) {
  275. // // // Title of LEVEL 1 // // //
  276. echo "<b>\n";
  277. if ($orderKey[0] == 'keyTools') {
  278. $tools = $key1;
  279. echo $toolsList[$key1]['name'];
  280. } elseif ($orderKey[0] == 'keyCourse') {
  281. $courseSysCode = $key1;
  282. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  283. } elseif ($orderKey[0] == 'keyTime') {
  284. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($digest[$key1]));
  285. }
  286. echo "</b>\n";
  287. // // // End Of Title of LEVEL 1 // // //
  288. // // // LEVEL 2 // // //
  289. reset($digest[$key1]);
  290. while (list ($key2) = each($digest[$key1])) {
  291. // // // Title of LEVEL 2 // // //
  292. echo "<p>\n", "\n";
  293. if ($orderKey[1] == 'keyTools') {
  294. $tools = $key2;
  295. echo $toolsList[$key2][name];
  296. } elseif ($orderKey[1] == 'keyCourse') {
  297. $courseSysCode = $key2;
  298. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  299. } elseif ($orderKey[1] == 'keyTime') {
  300. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  301. }
  302. echo "\n";
  303. echo "</p>";
  304. // // // End Of Title of LEVEL 2 // // //
  305. // // // LEVEL 3 // // //
  306. reset($digest[$key1][$key2]);
  307. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  308. // // // Title of LEVEL 3 // // //
  309. if ($orderKey[2] == 'keyTools') {
  310. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  311. } elseif ($orderKey[2] == 'keyCourse') {
  312. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  313. } elseif ($orderKey[2] == 'keyTime') {
  314. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3))."</a>";
  315. }
  316. // // // End Of Title of LEVEL 3 // // //
  317. // // // LEVEL 4 (data) // // //
  318. reset($digest[$key1][$key2][$key3]);
  319. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  320. echo $level3title, ' &ndash; ', substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  321. //adding ... (three dots) if the texts are too large and they are shortened
  322. if (strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  323. echo '...';
  324. }
  325. }
  326. echo "<br />\n";
  327. }
  328. }
  329. }
  330. }
  331. }
  332. } // end function display_digest
  333. /**
  334. * Display code for one specific course a logged in user is subscribed to.
  335. * Shows a link to the course, what's new icons...
  336. *
  337. * $my_course['d'] - course directory
  338. * $my_course['i'] - course title
  339. * $my_course['c'] - visual course code
  340. * $my_course['k'] - system course code
  341. * $my_course['db'] - course database
  342. *
  343. * @version 1.0.3
  344. * @todo refactor into different functions for database calls | logic | display
  345. * @todo replace single-character $my_course['d'] indices
  346. * @todo move code for what's new icons to a separate function to clear things up
  347. * @todo add a parameter user_id so that it is possible to show the courselist of other users (=generalisation). This will prevent having to write a new function for this.
  348. */
  349. function get_logged_user_course_html($my_course) {
  350. global $nosession;
  351. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  352. global $now, $date_start, $date_end;
  353. }
  354. //initialise
  355. $result = '';
  356. // Table definitions
  357. //$statistic_database = Database::get_statistic_database();
  358. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  359. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  360. $course_database = $my_course['db'];
  361. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  362. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  363. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  364. $user_id = api_get_user_id();
  365. $session_id = $my_course['id_session'];
  366. $course_system_code = $my_course['k'];
  367. $course_visual_code = $my_course['c'];
  368. $course_title = $my_course['i'];
  369. $course_directory = $my_course['d'];
  370. $course_teacher = $my_course['t'];
  371. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  372. $course_info = Database :: get_course_info($course_system_code);
  373. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  374. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  375. $course_visibility = $course_access_settings['visibility'];
  376. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  377. //function logic - act on the data
  378. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  379. if ($is_virtual_course) {
  380. // If the current user is also subscribed in the real course to which this
  381. // virtual course is linked, we don't need to display the virtual course entry in
  382. // the course list - it is combined with the real course entry.
  383. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  384. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  385. if ($is_subscribed_in_target_course) {
  386. return; //do not display this course entry
  387. }
  388. }
  389. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  390. if ($has_virtual_courses) {
  391. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  392. $course_display_title = $return_result['title'];
  393. $course_display_code = $return_result['code'];
  394. } else {
  395. $course_display_title = $course_title;
  396. $course_display_code = $course_visual_code;
  397. }
  398. $s_course_status=$my_course['s'];
  399. $s_htlm_status_icon="";
  400. if ($s_course_status==1) {
  401. $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher'));
  402. }
  403. if ($s_course_status==2) {
  404. $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach'));
  405. }
  406. if ($s_course_status==5) {
  407. $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student'));
  408. }
  409. //display course entry
  410. $result.="\n\t";
  411. $result .= '<li class="courses"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  412. //show a hyperlink to the course, unless the course is closed and user is not course admin
  413. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  414. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  415. if(empty($my_course['id_session'])) {
  416. $my_course['id_session'] = 0;
  417. }
  418. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  419. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  420. }
  421. } else {
  422. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  423. }
  424. } else {
  425. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  426. }
  427. // show the course_code and teacher if chosen to display this
  428. if (get_setting('display_coursecode_in_courselist') == 'true' OR get_setting('display_teacher_in_courselist') == 'true') {
  429. $result .= '<br />';
  430. }
  431. if (get_setting('display_coursecode_in_courselist') == 'true') {
  432. $result .= $course_display_code;
  433. }
  434. if (get_setting('display_coursecode_in_courselist') == 'true' AND get_setting('display_teacher_in_courselist') == 'true') {
  435. $result .= ' &ndash; ';
  436. }
  437. if (get_setting('display_teacher_in_courselist') == 'true') {
  438. $result .= $course_teacher;
  439. if(!empty($course_teacher_email)) {
  440. $result .= ' ('.$course_teacher_email.')';
  441. }
  442. }
  443. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  444. // display the what's new icons
  445. $result .= show_notification($my_course);
  446. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  447. reset($digest);
  448. $result .= '
  449. <ul>';
  450. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  451. $result .= '<li>';
  452. if ($orderKey[1] == 'keyTools') {
  453. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  454. $result .= "$toolsList[$key2][\"name\"]</a>";
  455. } else {
  456. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  457. }
  458. $result .= '</li>';
  459. $result .= '<ul>';
  460. reset($digest[$thisCourseSysCode][$key2]);
  461. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  462. $result .= '<li>';
  463. if ($orderKey[2] == 'keyTools') {
  464. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  465. $result .= "$toolsList[$key3][\"name\"]</a>";
  466. } else {
  467. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  468. }
  469. $result .= '<ul compact="compact">';
  470. reset($digest[$thisCourseSysCode][$key2][$key3]);
  471. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  472. $result .= '<li>';
  473. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  474. $result .= '</li>';
  475. }
  476. $result .= '</ul>';
  477. $result .= '</li>';
  478. }
  479. $result .= '</ul>';
  480. $result .= '</li>';
  481. }
  482. $result .= '</ul>';
  483. }
  484. $result .= '</li>';
  485. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  486. $session = '';
  487. $active = false;
  488. if (!empty($my_course['session_name'])) {
  489. // Request for the name of the general coach
  490. $sql = 'SELECT lastname, firstname
  491. FROM '.$tbl_session.' ts
  492. LEFT JOIN '.$main_user_table .' tu
  493. ON ts.id_coach = tu.user_id
  494. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  495. $rs = api_sql_query($sql, __FILE__, __LINE__);
  496. $sessioncoach = api_store_result($rs);
  497. $sessioncoach = $sessioncoach[0];
  498. $session = array();
  499. $session['title'] = $my_course['session_name'];
  500. if ( $my_course['date_start']=='0000-00-00' ) {
  501. $session['dates'] = get_lang('WithoutTimeLimits');
  502. if ( api_get_setting('show_session_coach') === 'true' ) {
  503. $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname'];
  504. }
  505. $active = true;
  506. } else {
  507. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  508. if ( api_get_setting('show_session_coach') === 'true' ) {
  509. $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname'];
  510. }
  511. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  512. }
  513. }
  514. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
  515. } else {
  516. $output = array ($my_course['user_course_cat'], $result);
  517. }
  518. return $output;
  519. }
  520. /**
  521. * Returns the "what's new" icon notifications
  522. * @param array Course information array, containing at least elements 'db' and 'k'
  523. * @return string The HTML link to be shown next to the course
  524. * @version
  525. */
  526. function show_notification($my_course) {
  527. $statistic_database = Database :: get_statistic_database();
  528. $user_id = api_get_user_id();
  529. $course_database = $my_course['db'];
  530. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  531. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  532. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  533. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  534. // get the user's last access dates to all tools of this course
  535. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  536. USE INDEX (access_cours_code, access_user_id)
  537. WHERE access_cours_code = '".$my_course['k']."'
  538. AND access_user_id = '$user_id'";
  539. $resLastTrackInCourse = api_sql_query($sqlLastTrackInCourse, __FILE__, __LINE__);
  540. $oldestTrackDate = "3000-01-01 00:00:00";
  541. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  542. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  543. if ($oldestTrackDate > $lastTrackInCourse['access_date'])
  544. $oldestTrackDate = $lastTrackInCourse['access_date'];
  545. }
  546. // get the last edits of all tools of this course
  547. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  548. tet.lastedit_type type, tet.to_group_id group_id,
  549. ctt.image image, ctt.link link
  550. FROM $tool_edit_table tet, $course_tool_table ctt
  551. WHERE tet.lastedit_date > '$oldestTrackDate'
  552. AND ctt.name = tet.tool
  553. AND ctt.visibility = '1'
  554. AND tet.lastedit_user_id != $user_id
  555. ORDER BY tet.lastedit_date";
  556. $res = api_sql_query($sql);
  557. //get the group_id's with user membership
  558. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  559. $groups_ids[] = 0; //add group 'everyone'
  560. //filter all selected items
  561. while ($res && ($item_property = Database::fetch_array($res))) {
  562. if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) && (in_array($item_property['to_group_id'], $groups_ids) || $item_property['to_user_id'] == $user_id) && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset ($item_property['visibility']))) {
  563. $notifications[$item_property['tool']] = $item_property;
  564. }
  565. }
  566. //show all tool icons where there is something new
  567. $retvalue = '&nbsp;';
  568. if (isset ($notifications)) {
  569. while (list ($key, $notification) = each($notifications)) {
  570. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  571. $type = $notification['lastedit_type'];
  572. //$notification[image]=str_replace(".png","gif",$notification[image]);
  573. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  574. $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'">'.'<img title="-- '.get_lang(ucfirst($notification['tool'])).' -- '.get_lang('_title_notification').": ".get_lang($type)." ($lastDate).\"".' src="'.api_get_path(WEB_CODE_PATH).'img/'.$notification['image'].'" border="0" align="absbottom" /></a>&nbsp;';
  575. }
  576. }
  577. return $retvalue;
  578. }
  579. /**
  580. * retrieves the user defined course categories
  581. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  582. * @return array containing all the titles of the user defined courses with the id as key of the array
  583. */
  584. function get_user_course_categories() {
  585. global $_user;
  586. $output = array();
  587. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  588. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_user['user_id']."'";
  589. $result = api_sql_query($sql,__FILE__,__LINE__);
  590. while ($row = Database::fetch_array($result)) {
  591. $output[$row['id']] = $row['title'];
  592. }
  593. return $output;
  594. }
  595. /*
  596. ==============================================================================
  597. MAIN CODE
  598. ==============================================================================
  599. */
  600. /*
  601. ==============================================================================
  602. PERSONAL COURSE LIST
  603. ==============================================================================
  604. */
  605. if (!isset ($maxValvas)) {
  606. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  607. }
  608. if (!isset ($maxAgenda)) {
  609. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  610. }
  611. if (!isset ($maxCourse)) {
  612. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  613. }
  614. $maxValvas = (int) $maxValvas;
  615. $maxAgenda = (int) $maxAgenda;
  616. $maxCourse = (int) $maxCourse; // 0 if invalid
  617. if ($maxCourse > 0) {
  618. unset ($allentries); // we shall collect all summary$key1 entries in here:
  619. $toolsList['agenda']['name'] = get_lang('Agenda');
  620. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  621. $toolsList['valvas']['name'] = get_lang('Valvas');
  622. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  623. }
  624. echo ' <div class="maincontent" id="maincontent">'; // start of content for logged in users
  625. // Plugins for the my courses main area
  626. api_plugin('mycourses_main');
  627. /*
  628. -----------------------------------------------------------------------------
  629. System Announcements
  630. -----------------------------------------------------------------------------
  631. */
  632. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  633. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  634. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  635. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  636. include ('./home/'.$_GET['include']);
  637. $pageIncluded = true;
  638. } else {
  639. /*--------------------------------------
  640. DISPLAY COURSES
  641. --------------------------------------*/
  642. $list = '';
  643. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  644. foreach ($personal_course_list as $my_course) {
  645. $thisCourseDbName = $my_course['db'];
  646. $thisCourseSysCode = $my_course['k'];
  647. $thisCoursePublicCode = $my_course['c'];
  648. $thisCoursePath = $my_course['d'];
  649. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  650. $dbname = $my_course['k'];
  651. $status[$dbname] = $my_course['s'];
  652. $nbDigestEntries = 0; // number of entries already collected
  653. if ($maxCourse < $maxValvas) {
  654. $maxValvas = $maxCourse;
  655. }
  656. if ($maxCourse > 0) {
  657. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  658. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  659. }
  660. /*
  661. -----------------------------------------------------------
  662. Announcements
  663. -----------------------------------------------------------
  664. */
  665. $course_database = $my_course['db'];
  666. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  667. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  668. $result = api_sql_query($query);
  669. // collect from announcements, but only if tool is visible for the course
  670. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  671. //Search announcements table
  672. //Take the entries listed at the top of advalvas/announcements tool
  673. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  674. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  675. FROM ".$course_announcement_table;
  676. switch (CONFVAL_limitPreviewTo) {
  677. case SCRIPTVAL_NewEntriesOfTheDay :
  678. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  679. break;
  680. case SCRIPTVAL_NoTimeLimit :
  681. break;
  682. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  683. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  684. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  685. }
  686. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC
  687. LIMIT ".$maxValvas;
  688. $resGetLastAnnouncements = api_sql_query($sqlGetLastAnnouncements, __FILE__, __LINE__);
  689. if ($resGetLastAnnouncements) {
  690. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  691. $keyTools = "valvas";
  692. $keyTime = $annoncement['publicationDate'];
  693. $keyCourse = $thisCourseSysCode;
  694. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  695. $nbDigestEntries ++; // summary has same order as advalvas
  696. }
  697. }
  698. }
  699. /*
  700. -----------------------------------------------------------
  701. Agenda
  702. -----------------------------------------------------------
  703. */
  704. $course_database = $my_course['db'];
  705. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  706. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  707. $result = api_sql_query($query);
  708. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  709. if ($maxAgenda < $thisAgenda) {
  710. $thisAgenda = $maxAgenda;
  711. }
  712. // collect from agenda, but only if tool is visible for the course
  713. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  714. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  715. $sqlGetNextAgendaEvent = "SELECT start_date , title content, start_time
  716. FROM $tableCal
  717. WHERE start_date >= CURDATE()
  718. ORDER BY start_date, start_time
  719. LIMIT $maxAgenda";
  720. $resGetNextAgendaEvent = api_sql_query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
  721. if ($resGetNextAgendaEvent) {
  722. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  723. $keyTools = 'agenda';
  724. $keyTime = $agendaEvent['start_date'];
  725. $keyCourse = $thisCourseSysCode;
  726. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  727. $nbDigestEntries ++; // summary has same order as advalvas
  728. }
  729. }
  730. }
  731. /*
  732. -----------------------------------------------------------
  733. Digest Display
  734. take collected data and display it
  735. -----------------------------------------------------------
  736. */
  737. $list[] = get_logged_user_course_html($my_course);
  738. } //end while mycourse...
  739. }
  740. if ( is_array($list) ) {
  741. //Courses whithout sessions
  742. $old_user_category = 0;
  743. foreach($list as $key=>$value) {
  744. if ( empty($value[2]) ) { //if out of any session
  745. $userdefined_categories = get_user_course_categories();
  746. echo '
  747. <ul class="courseslist">';
  748. if ($old_user_category<>$value[0]) {
  749. if ($key<>0 OR $value[0]<>0) {// there are courses in the previous category
  750. echo "\n</ul>";
  751. }
  752. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  753. if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
  754. echo "<ul class=\"courseslist\">";
  755. }
  756. $old_user_category=$value[0];
  757. }
  758. echo $value[1];
  759. echo "</ul>\n";
  760. }
  761. }
  762. $listActives = $listInactives = $listCourses = array();
  763. foreach ( $list as $key=>$value ) {
  764. if ( $value['active'] ) { //if the session is still active (as told by get_logged_user_course_html())
  765. $listActives[] = $value;
  766. } else if ( !empty($value[2]) ) { //if there is a session but it is not active
  767. $listInactives[] = $value;
  768. }
  769. }
  770. $old_user_category = 0;
  771. $userdefined_categories = get_user_course_categories();
  772. if(count($listActives)>0 && $display_actives){
  773. echo "<ul class=\"courseslist\">\n";
  774. foreach ($listActives as $key => $value) {
  775. if (!empty($value[2])) {
  776. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  777. $old_session = $value[2];
  778. if ($key != 0) {
  779. echo '</ul>';
  780. }
  781. echo '<ul class="session_box">' .
  782. '<li class="session_box_title">'.$value[3]['title'].' - '.$value[3]['dates'].'</li>';
  783. if ( !empty($value[3]['coach']) ) {
  784. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  785. }
  786. echo "</ul>\n";
  787. echo '<ul class="session_course_item">';
  788. }
  789. }
  790. echo $value[1];
  791. }
  792. echo "\n</ul><br /><br />\n";
  793. }
  794. if (count($listInactives)>0 && !$display_actives) {
  795. echo '<ul class="sessions_list_inactive">';
  796. foreach ($listInactives as $key => $value) {
  797. if (!empty($value[2])) {
  798. if ($old_session != $value[2]) {
  799. $old_session = $value[2];
  800. if ($key != 0) {
  801. echo '</ul>';
  802. }
  803. echo '<ul class="session_box">' .
  804. '<li class="session_box_title">'.$value[3]['title'].' - '.$value[3]['dates'].'</li>';
  805. if ( !empty($value[3]['coach']) ) {
  806. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  807. }
  808. echo "</ul>\n";
  809. echo '<ul>';
  810. }
  811. }
  812. echo $value[1];
  813. }
  814. echo "\n</ul><br /><br />\n";
  815. }
  816. }
  817. echo '</div>'; // end of content section
  818. // Register whether full admin or null admin course
  819. // by course through an array dbname x user status
  820. api_session_register('status');
  821. /*
  822. ==============================================================================
  823. RIGHT MENU
  824. ==============================================================================
  825. */
  826. echo ' <div class="menu">';
  827. // tabs that are deactivated are added here
  828. if (!empty($menu_navigation)) {
  829. echo '<div class="menusection">';
  830. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  831. echo '<ul class="menulist">';
  832. foreach ($menu_navigation as $section => $navigation_info) {
  833. $current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
  834. echo '<li'.$current.'>';
  835. echo '<a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a>';
  836. echo '</li>';
  837. echo "\n";
  838. }
  839. echo '</ul>';
  840. echo '</div>';
  841. }
  842. // api_display_language_form(); // moved to the profile page.
  843. echo '<div class="menusection">';
  844. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  845. echo '<ul class="menulist">';
  846. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
  847. if ($display_add_course_link) {
  848. if ( api_get_setting('allow_users_to_create_courses')=='false' && !api_is_platform_admin()) {
  849. //echo get_lang('NotHavePermissionToCreateCourses');
  850. } else {
  851. display_create_course_link();
  852. }
  853. }
  854. display_edit_course_list_links();
  855. if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
  856. display_digest($toolsList, $digest, $orderKey, $courses);
  857. }
  858. echo '</ul>';
  859. echo '</div>';
  860. // plugins for the my courses menu
  861. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  862. echo '<div class="note">';
  863. api_plugin('mycourses_menu');
  864. echo '</div>';
  865. }
  866. echo '</div>'; // end of menu
  867. //footer
  868. Display :: display_footer();