user_portal.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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-2005 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. {
  125. if (isset($_GET['inactives'])){
  126. $display_actives = false;
  127. }
  128. else {
  129. $display_actives = true;
  130. }
  131. }
  132. $nameTools = get_lang('MyCourses');
  133. $this_section = SECTION_COURSES;
  134. /*
  135. -----------------------------------------------------------
  136. Check configuration parameters integrity
  137. -----------------------------------------------------------
  138. */
  139. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse")
  140. {
  141. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  142. if (DEBUG || api_is_platform_admin()) // Show bug if admin. Else force a new order
  143. die('
  144. <strong>config error:'.__FILE__.'</strong><br />
  145. set
  146. <ul>
  147. <li>
  148. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  149. (actually : '.CONFVAL_showExtractInfo.')
  150. </li>
  151. </ul>
  152. or
  153. <ul>
  154. <li>
  155. $orderKey[0] != "keyCourse"
  156. (actually : '.$orderKey[0].')
  157. </li>
  158. </ul>');
  159. else
  160. {
  161. $orderKey = array ('keyCourse', 'keyTools', 'keyTime');
  162. }
  163. }
  164. /*
  165. -----------------------------------------------------------
  166. Header
  167. include the HTTP, HTML headers plus the top banner
  168. -----------------------------------------------------------
  169. */
  170. Display :: display_header($nameTools);
  171. /*
  172. ==============================================================================
  173. FUNCTIONS
  174. display_admin_links()
  175. display_create_course_link()
  176. display_edit_course_list_links()
  177. display_digest($toolsList, $digest, $orderKey, $courses)
  178. show_notification($my_course)
  179. get_personal_course_list($user_id)
  180. get_logged_user_course_html($my_course)
  181. get_user_course_categories()
  182. ==============================================================================
  183. */
  184. /*
  185. -----------------------------------------------------------
  186. Database functions
  187. some of these can go to database layer.
  188. -----------------------------------------------------------
  189. */
  190. /**
  191. * Database function that gets the list of courses for a particular user.
  192. * @param $user_id, the id of the user
  193. * @return an array with courses
  194. */
  195. function get_personal_course_list($user_id)
  196. {
  197. // initialisation
  198. $personal_course_list = array();
  199. // table definitions
  200. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  201. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  202. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  203. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  204. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  205. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  206. $personal_course_list = array ();
  207. //Courses in which we suscribed out of any session
  208. $personal_course_list_sql = "SELECT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i,
  209. course.tutor_name t, course.course_language l, course_rel_user.status s, course_rel_user.sort sort,
  210. course_rel_user.user_course_cat user_course_cat
  211. FROM ".$main_course_table." course,".$main_course_user_table." course_rel_user
  212. WHERE course.code = course_rel_user.course_code"."
  213. AND course_rel_user.user_id = '".$user_id."'
  214. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC,i";
  215. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  216. while ($result_row = mysql_fetch_array($course_list_sql_result))
  217. {
  218. $personal_course_list[] = $result_row;
  219. }
  220. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  221. $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
  222. FROM $main_course_table as course, $tbl_session_course_user as srcru
  223. WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
  224. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  225. while ($result_row = mysql_fetch_array($course_list_sql_result))
  226. {
  227. $personal_course_list[] = $result_row;
  228. }
  229. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  230. $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
  231. FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
  232. WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
  233. $course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
  234. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  235. while ($result_row = mysql_fetch_array($course_list_sql_result))
  236. {
  237. $personal_course_list[] = $result_row;
  238. }
  239. return $personal_course_list;
  240. }
  241. /*
  242. -----------------------------------------------------------
  243. Display functions
  244. -----------------------------------------------------------
  245. */
  246. /**
  247. * Warning: this function defines a global.
  248. * @todo use the correct get_path function
  249. */
  250. function display_admin_links()
  251. {
  252. global $rootAdminWeb;
  253. echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
  254. }
  255. /**
  256. * Enter description here...
  257. *
  258. */
  259. function display_create_course_link()
  260. {
  261. echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
  262. }
  263. /**
  264. * Enter description here...
  265. *
  266. */
  267. function display_edit_course_list_links()
  268. {
  269. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  270. }
  271. /**
  272. * Displays a digest e.g. short summary of new agenda and announcements items.
  273. * This used to be displayed in the right hand menu, but is now
  274. * disabled by default (see config settings in this file) because most people like
  275. * the what's new icons better.
  276. *
  277. * @version 1.0
  278. */
  279. function display_digest($toolsList, $digest, $orderKey, $courses)
  280. {
  281. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both))
  282. {
  283. // // // LEVEL 1 // // //
  284. reset($digest);
  285. echo "<br /><br />\n";
  286. while (list ($key1) = each($digest))
  287. {
  288. if (is_array($digest[$key1]))
  289. {
  290. // // // Title of LEVEL 1 // // //
  291. echo "<b>\n";
  292. if ($orderKey[0] == 'keyTools')
  293. {
  294. $tools = $key1;
  295. echo $toolsList[$key1]['name'];
  296. }
  297. elseif ($orderKey[0] == 'keyCourse')
  298. {
  299. $courseSysCode = $key1;
  300. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  301. }
  302. elseif ($orderKey[0] == 'keyTime')
  303. {
  304. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($digest[$key1]));
  305. }
  306. echo "</b>\n";
  307. // // // End Of Title of LEVEL 1 // // //
  308. // // // LEVEL 2 // // //
  309. reset($digest[$key1]);
  310. while (list ($key2) = each($digest[$key1]))
  311. {
  312. // // // Title of LEVEL 2 // // //
  313. echo "<p>\n", "\n";
  314. if ($orderKey[1] == 'keyTools')
  315. {
  316. $tools = $key2;
  317. echo $toolsList[$key2][name];
  318. }
  319. elseif ($orderKey[1] == 'keyCourse')
  320. {
  321. $courseSysCode = $key2;
  322. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  323. }
  324. elseif ($orderKey[1] == 'keyTime')
  325. {
  326. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  327. }
  328. echo "\n";
  329. echo "</p>";
  330. // // // End Of Title of LEVEL 2 // // //
  331. // // // LEVEL 3 // // //
  332. reset($digest[$key1][$key2]);
  333. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2]))
  334. {
  335. // // // Title of LEVEL 3 // // //
  336. if ($orderKey[2] == 'keyTools')
  337. {
  338. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  339. }
  340. elseif ($orderKey[2] == 'keyCourse')
  341. {
  342. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  343. }
  344. elseif ($orderKey[2] == 'keyTime')
  345. {
  346. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3))."</a>";
  347. }
  348. // // // End Of Title of LEVEL 3 // // //
  349. // // // LEVEL 4 (data) // // //
  350. reset($digest[$key1][$key2][$key3]);
  351. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3]))
  352. {
  353. echo $level3title, ' &ndash; ', substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  354. //adding ... (three dots) if the texts are too large and they are shortened
  355. if (strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT)
  356. {
  357. echo '...';
  358. }
  359. }
  360. echo "<br />\n";
  361. }
  362. }
  363. }
  364. }
  365. }
  366. } // end function display_digest
  367. /**
  368. * Display code for one specific course a logged in user is subscribed to.
  369. * Shows a link to the course, what's new icons...
  370. *
  371. * $my_course['d'] - course directory
  372. * $my_course['i'] - course title
  373. * $my_course['c'] - visual course code
  374. * $my_course['k'] - system course code
  375. * $my_course['db'] - course database
  376. *
  377. * @version 1.0.3
  378. * @todo refactor into different functions for database calls | logic | display
  379. * @todo replace single-character $my_course['d'] indices
  380. * @todo move code for what's new icons to a separate function to clear things up
  381. * @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.
  382. */
  383. function get_logged_user_course_html($my_course)
  384. {
  385. global $nosession;
  386. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  387. {
  388. global $now, $date_start, $date_end;
  389. }
  390. //initialise
  391. $result = '';
  392. // Table definitions
  393. //$statistic_database = Database::get_statistic_database();
  394. $course_database = $my_course['db'];
  395. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  396. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  397. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  398. $user_id = api_get_user_id();
  399. $course_system_code = $my_course['k'];
  400. $course_visual_code = $my_course['c'];
  401. $course_title = $my_course['i'];
  402. $course_directory = $my_course['d'];
  403. $course_teacher = $my_course['t'];
  404. $course_teacher_email = $my_course['email'];
  405. $course_info = Database :: get_course_info($course_system_code);
  406. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  407. $course_id = $course_info['course_id'];
  408. $course_visibility = $course_access_settings['visibility'];
  409. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  410. //function logic - act on the data
  411. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  412. if ($is_virtual_course)
  413. {
  414. // If the current user is also subscribed in the real course to which this
  415. // virtual course is linked, we don't need to display the virtual course entry in
  416. // the course list - it is combined with the real course entry.
  417. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  418. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  419. if ($is_subscribed_in_target_course)
  420. {
  421. return; //do not display this course entry
  422. }
  423. }
  424. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  425. if ($has_virtual_courses)
  426. {
  427. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  428. $course_display_title = $return_result['title'];
  429. $course_display_code = $return_result['code'];
  430. }
  431. else
  432. {
  433. $course_display_title = $course_title;
  434. $course_display_code = $course_visual_code;
  435. }
  436. $s_course_status=$my_course['s'];
  437. $s_htlm_status_icon="";
  438. if($s_course_status==1)
  439. {
  440. $s_htlm_status_icon=Display::return_icon('teachers.gif');
  441. }
  442. if($s_course_status==2)
  443. {
  444. $s_htlm_status_icon=Display::return_icon('coachs.gif');
  445. }
  446. if($s_course_status==5)
  447. {
  448. $s_htlm_status_icon=Display::return_icon('students.gif');
  449. }
  450. //display course entry
  451. $result.="\n\t";
  452. $result .= '<li class="courses"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  453. //show a hyperlink to the course, unless the course is closed and user is not course admin
  454. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)
  455. {
  456. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  457. {
  458. if(empty($my_course['id_session']))
  459. {
  460. $my_course['id_session'] = 0;
  461. }
  462. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00')
  463. {
  464. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  465. }
  466. }
  467. else
  468. {
  469. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  470. }
  471. }
  472. else
  473. {
  474. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  475. }
  476. // show the course_code and teacher if chosen to display this
  477. if (get_setting('display_coursecode_in_courselist') == 'true' OR get_setting('display_teacher_in_courselist') == 'true')
  478. {
  479. $result .= '<br />';
  480. }
  481. if (get_setting('display_coursecode_in_courselist') == 'true')
  482. {
  483. $result .= $course_display_code;
  484. }
  485. if (get_setting('display_coursecode_in_courselist') == 'true' AND get_setting('display_teacher_in_courselist') == 'true')
  486. {
  487. $result .= ' &ndash; ';
  488. }
  489. if (get_setting('display_teacher_in_courselist') == 'true')
  490. {
  491. $result .= $course_teacher;
  492. if(!empty($course_teacher_email))
  493. {
  494. $result .= ' ('.$course_teacher_email.')';
  495. }
  496. }
  497. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  498. // display the what's new icons
  499. $result .= show_notification($my_course);
  500. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0)
  501. {
  502. reset($digest);
  503. $result .= '<ul>';
  504. while (list ($key2) = each($digest[$thisCourseSysCode]))
  505. {
  506. $result .= '<li>';
  507. if ($orderKey[1] == 'keyTools')
  508. {
  509. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  510. $result .= "$toolsList[$key2][\"name\"]</a>";
  511. }
  512. else
  513. {
  514. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  515. }
  516. $result .= '</li>';
  517. $result .= '<ul>';
  518. reset($digest[$thisCourseSysCode][$key2]);
  519. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2]))
  520. {
  521. $result .= '<li>';
  522. if ($orderKey[2] == 'keyTools')
  523. {
  524. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  525. $result .= "$toolsList[$key3][\"name\"]</a>";
  526. }
  527. else
  528. {
  529. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  530. }
  531. $result .= '<ul compact="compact">';
  532. reset($digest[$thisCourseSysCode][$key2][$key3]);
  533. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3]))
  534. {
  535. $result .= '<li>';
  536. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  537. $result .= '</li>';
  538. }
  539. $result .= '</ul>';
  540. $result .= '</li>';
  541. }
  542. $result .= '</ul>';
  543. $result .= '</li>';
  544. }
  545. $result .= '</ul>';
  546. }
  547. $result .= '</li>';
  548. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  549. {
  550. if(!empty($my_course['session_name']))
  551. {
  552. $session = $my_course['session_name'];
  553. if($my_course['date_start']=='0000-00-00')
  554. {
  555. $session .= ' - '.get_lang('WithoutTimeLimits');
  556. $active = true;
  557. }
  558. else
  559. {
  560. $session .= ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  561. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  562. }
  563. }
  564. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
  565. }
  566. else
  567. {
  568. $output = array ($my_course['user_course_cat'], $result);
  569. }
  570. return $output;
  571. }
  572. /**
  573. * Returns the "what's new" icon notifications
  574. * @version
  575. */
  576. function show_notification($my_course)
  577. {
  578. $statistic_database = Database :: get_statistic_database();
  579. $user_id = api_get_user_id();
  580. $course_database = $my_course['db'];
  581. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  582. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  583. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  584. // get the user's last access dates to all tools of this course
  585. $sqlLastTrackInCourse = "SELECT * FROM $statistic_database.track_e_lastaccess
  586. USE INDEX (access_cours_code, access_user_id)
  587. WHERE access_cours_code = '".$my_course['k']."'
  588. AND access_user_id = '$user_id'";
  589. $resLastTrackInCourse = api_sql_query($sqlLastTrackInCourse, __FILE__, __LINE__);
  590. $oldestTrackDate = "3000-01-01 00:00:00";
  591. while ($lastTrackInCourse = mysql_fetch_array($resLastTrackInCourse))
  592. {
  593. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  594. if ($oldestTrackDate > $lastTrackInCourse['access_date'])
  595. $oldestTrackDate = $lastTrackInCourse['access_date'];
  596. }
  597. // get the last edits of all tools of this course
  598. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  599. tet.lastedit_type type, tet.to_group_id group_id,
  600. ctt.image image, ctt.link link
  601. FROM $tool_edit_table tet, $course_tool_table ctt
  602. WHERE tet.lastedit_date > '$oldestTrackDate'
  603. AND ctt.name = tet.tool
  604. AND ctt.visibility = '1'
  605. AND tet.lastedit_user_id != $user_id
  606. ORDER BY tet.lastedit_date";
  607. $res = api_sql_query($sql);
  608. //get the group_id's with user membership
  609. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  610. $groups_ids[] = 0; //add group 'everyone'
  611. //filter all selected items
  612. while ($res && ($item_property = mysql_fetch_array($res)))
  613. {
  614. 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'])))
  615. {
  616. $notifications[$item_property['tool']] = $item_property;
  617. }
  618. }
  619. //show all tool icons where there is something new
  620. $retvalue = '&nbsp;';
  621. if (isset ($notifications))
  622. {
  623. while (list ($key, $notification) = each($notifications))
  624. {
  625. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  626. $type = $notification['lastedit_type'];
  627. //$notification[image]=str_replace(".png","gif",$notification[image]);
  628. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  629. $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;';
  630. }
  631. }
  632. return $retvalue;
  633. }
  634. /**
  635. * retrieves the user defined course categories
  636. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  637. * @return array containing all the titles of the user defined courses with the id as key of the array
  638. */
  639. function get_user_course_categories()
  640. {
  641. global $_user;
  642. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  643. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_user['user_id']."'";
  644. $result = api_sql_query($sql,__FILE__,__LINE__);
  645. while ($row = mysql_fetch_array($result))
  646. {
  647. $output[$row['id']] = $row['title'];
  648. }
  649. return $output;
  650. }
  651. /*
  652. ==============================================================================
  653. MAIN CODE
  654. ==============================================================================
  655. */
  656. /*
  657. ==============================================================================
  658. PERSONAL COURSE LIST
  659. ==============================================================================
  660. */
  661. if (!isset ($maxValvas))
  662. {
  663. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  664. }
  665. if (!isset ($maxAgenda))
  666. {
  667. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  668. }
  669. if (!isset ($maxCourse))
  670. {
  671. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  672. }
  673. $maxValvas = (int) $maxValvas;
  674. $maxAgenda = (int) $maxAgenda;
  675. $maxCourse = (int) $maxCourse; // 0 if invalid
  676. if ($maxCourse > 0)
  677. {
  678. unset ($allentries); // we shall collect all summary$key1 entries in here:
  679. $toolsList['agenda']['name'] = get_lang('Agenda');
  680. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  681. $toolsList['valvas']['name'] = get_lang('Valvas');
  682. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  683. }
  684. echo '<div class="maincontent">'; // start of content for logged in users
  685. // Plugins for the my courses main area
  686. api_plugin('mycourses_main');
  687. // link to see the session view or course view
  688. /*if(api_get_setting('use_session_mode')=='true' && api_is_allowed_to_create_course()) {
  689. if(isset($_GET['sessionview'])){
  690. echo '<a href="'.api_get_self().'">'.get_lang('CourseView').'</a>';
  691. }
  692. else {
  693. echo '<a href="'.api_get_self().'?sessionview=true">'.get_lang('SessionView').'</a>';
  694. }
  695. }*/
  696. /*
  697. -----------------------------------------------------------------------------
  698. System Announcements
  699. -----------------------------------------------------------------------------
  700. */
  701. $announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
  702. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  703. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  704. if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
  705. {
  706. include ('./home/'.$_GET['include']);
  707. $pageIncluded = true;
  708. }
  709. else
  710. {
  711. /*--------------------------------------
  712. DISPLAY COURSES
  713. --------------------------------------*/
  714. $list = '';
  715. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  716. /*if(api_get_setting('use_session_mode')=='true' && !$nosession)
  717. {
  718. echo "bouh";
  719. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  720. }
  721. else
  722. {
  723. $personal_course_list = get_personal_course_list($_user['user_id']);
  724. }*/
  725. foreach ($personal_course_list as $my_course)
  726. {
  727. $thisCourseDbName = $my_course['db'];
  728. $thisCourseSysCode = $my_course['k'];
  729. $thisCoursePublicCode = $my_course['c'];
  730. $thisCoursePath = $my_course['d'];
  731. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  732. /*
  733. currently disabled functionality, should return
  734. $thisCoursePath = $sys_course_path . $thisCoursePath;
  735. if(! file_exists($thisCoursePath))
  736. {
  737. echo "<li>".$my_course['i']."<br/>";
  738. echo "".get_lang("CourseDoesntExist")." (<a href=\"main/install/update_courses.php\">";
  739. echo "".get_lang("GetCourseFromOldPortal")."</a>)</li>";
  740. continue;
  741. }*/
  742. $dbname = $my_course['k'];
  743. $status[$dbname] = $my_course['s'];
  744. $nbDigestEntries = 0; // number of entries already collected
  745. if ($maxCourse < $maxValvas)
  746. $maxValvas = $maxCourse;
  747. if ($maxCourse > 0)
  748. {
  749. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  750. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  751. }
  752. /*
  753. -----------------------------------------------------------
  754. Announcements
  755. -----------------------------------------------------------
  756. */
  757. $course_database = $my_course['db'];
  758. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  759. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  760. $result = api_sql_query($query);
  761. // collect from announcements, but only if tool is visible for the course
  762. if ($result && $maxValvas > 0 && mysql_num_rows($result) > 0)
  763. {
  764. //Search announcements table
  765. //Take the entries listed at the top of advalvas/announcements tool
  766. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  767. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  768. FROM ".$course_announcement_table;
  769. switch (CONFVAL_limitPreviewTo)
  770. {
  771. case SCRIPTVAL_NewEntriesOfTheDay :
  772. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  773. break;
  774. case SCRIPTVAL_NoTimeLimit :
  775. break;
  776. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  777. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  778. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  779. }
  780. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC
  781. LIMIT ".$maxValvas;
  782. $resGetLastAnnouncements = api_sql_query($sqlGetLastAnnouncements, __FILE__, __LINE__);
  783. if ($resGetLastAnnouncements)
  784. {
  785. while ($annoncement = mysql_fetch_array($resGetLastAnnouncements))
  786. {
  787. $keyTools = "valvas";
  788. $keyTime = $annoncement['publicationDate'];
  789. $keyCourse = $thisCourseSysCode;
  790. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  791. $nbDigestEntries ++; // summary has same order as advalvas
  792. }
  793. }
  794. }
  795. /*
  796. -----------------------------------------------------------
  797. Agenda
  798. -----------------------------------------------------------
  799. */
  800. $course_database = $my_course['db'];
  801. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  802. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  803. $result = api_sql_query($query);
  804. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  805. if ($maxAgenda < $thisAgenda)
  806. $thisAgenda = $maxAgenda;
  807. // collect from agenda, but only if tool is visible for the course
  808. if ($result && $thisAgenda > 0 && mysql_num_rows($result) > 0)
  809. {
  810. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  811. $sqlGetNextAgendaEvent = "SELECT start_date , title content, start_time
  812. FROM $tableCal
  813. WHERE start_date >= CURDATE()
  814. ORDER BY start_date, start_time
  815. LIMIT $maxAgenda";
  816. $resGetNextAgendaEvent = api_sql_query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
  817. if ($resGetNextAgendaEvent)
  818. {
  819. while ($agendaEvent = mysql_fetch_array($resGetNextAgendaEvent))
  820. {
  821. $keyTools = 'agenda';
  822. $keyTime = $agendaEvent['start_date'];
  823. $keyCourse = $thisCourseSysCode;
  824. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  825. $nbDigestEntries ++; // summary has same order as advalvas
  826. }
  827. }
  828. }
  829. /*
  830. -----------------------------------------------------------
  831. Digest Display
  832. take collected data and display it
  833. -----------------------------------------------------------
  834. */
  835. $list[] = get_logged_user_course_html($my_course);
  836. } //end while mycourse...
  837. }
  838. if (is_array($list))
  839. {
  840. //Courses whithout sessions
  841. $old_user_category = 0;
  842. foreach($list as $key=>$value)
  843. {
  844. if($value[2]==0){
  845. $userdefined_categories = get_user_course_categories();
  846. echo "<ul>\n";
  847. if ($old_user_category<>$value[0])
  848. {
  849. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  850. {
  851. echo "\n</ul>";
  852. }
  853. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  854. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  855. {
  856. echo "<ul>";
  857. }
  858. $old_user_category=$value[0];
  859. }
  860. echo $value[1];
  861. echo "</ul>\n";
  862. }
  863. }
  864. $listActives = $listInactives = $listCourses = array();
  865. foreach($list as $key=>$value){
  866. if($value['active'])
  867. $listActives[] = $value;
  868. else if(!empty($value[2]))
  869. $listInactives[] = $value;
  870. }
  871. $old_user_category = 0;
  872. $userdefined_categories = get_user_course_categories();
  873. if(count($listActives)>0 && $display_actives){
  874. echo "<ul style=\"line-height: 20px; margin-top: 20px;\">\n";
  875. foreach ($listActives as $key => $value)
  876. {
  877. if(!empty($value[2])){
  878. if($old_session != $value[2]){
  879. $old_session = $value[2];
  880. if($key != 0){
  881. echo "\n</ul>";
  882. }
  883. echo "\n\n\t<ul class=\"user_course_category\" style=\"margin-bottom: 10px;\"><li>".$value[3]."</li></ul>\n";
  884. echo "<ul style=\"padding: 0px; margin: 0px;\">";
  885. }
  886. }
  887. echo $value[1];
  888. }
  889. echo "\n</ul><br /><br />\n";
  890. }
  891. if(count($listInactives)>0 && !$display_actives){
  892. echo "<ul style=\"line-height: 20px;\">";
  893. foreach ($listInactives as $key => $value)
  894. {
  895. if(!empty($value[2])){
  896. if($old_session != $value[2]){
  897. $old_session = $value[2];
  898. if($key != 0){
  899. echo "\n</ul>";
  900. }
  901. echo "\n\n\t<ul class=\"user_course_category\"><li>".$value[3]."</li></ul>\n";
  902. echo "<ul>";
  903. }
  904. }
  905. echo $value[1];
  906. }
  907. echo "\n</ul><br /><br />\n";
  908. }
  909. }
  910. echo "</div>"; // end of content section
  911. // Register whether full admin or null admin course
  912. // by course through an array dbname x user status
  913. api_session_register('status');
  914. /*
  915. ==============================================================================
  916. RIGHT MENU
  917. ==============================================================================
  918. */
  919. echo '<div class="menu">';
  920. // tabs that are deactivated are added here
  921. if (!empty($menu_navigation))
  922. {
  923. echo '<div class="menusection">';
  924. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  925. echo '<ul class="menulist">';
  926. foreach($menu_navigation as $section => $navigation_info)
  927. {
  928. $current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
  929. echo '<li'.$current.'>';
  930. echo '<a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a>';
  931. echo '</li>';
  932. echo "\n";
  933. }
  934. echo '</ul>';
  935. echo '</div>';
  936. }
  937. // api_display_language_form(); // moved to the profile page.
  938. echo '<div class="menusection">';
  939. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  940. echo '<ul class="menulist">';
  941. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
  942. if ($display_add_course_link)
  943. display_create_course_link();
  944. display_edit_course_list_links();
  945. display_digest($toolsList, $digest, $orderKey, $courses);
  946. echo '</ul>';
  947. echo '</div>';
  948. // plugins for the my courses menu
  949. if (is_array($_plugins['mycourses_menu'])){
  950. echo '<div class="note" style="background: none">';
  951. api_plugin('mycourses_menu');
  952. echo '</div>';
  953. }
  954. echo '</div>'; // end of menu
  955. /*
  956. ==============================================================================
  957. FOOTER
  958. ==============================================================================
  959. */
  960. Display :: display_footer();
  961. ?>