user_portal.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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 = isset($my_course['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 = isset($course_info['course_id'])?$course_info['course_id']:null;
  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. * @param array Course information array, containing at least elements 'db' and 'k'
  575. * @return string The HTML link to be shown next to the course
  576. * @version
  577. */
  578. function show_notification($my_course)
  579. {
  580. $statistic_database = Database :: get_statistic_database();
  581. $user_id = api_get_user_id();
  582. $course_database = $my_course['db'];
  583. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  584. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  585. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  586. // get the user's last access dates to all tools of this course
  587. $sqlLastTrackInCourse = "SELECT * FROM $statistic_database.track_e_lastaccess
  588. USE INDEX (access_cours_code, access_user_id)
  589. WHERE access_cours_code = '".$my_course['k']."'
  590. AND access_user_id = '$user_id'";
  591. $resLastTrackInCourse = api_sql_query($sqlLastTrackInCourse, __FILE__, __LINE__);
  592. $oldestTrackDate = "3000-01-01 00:00:00";
  593. while ($lastTrackInCourse = mysql_fetch_array($resLastTrackInCourse))
  594. {
  595. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  596. if ($oldestTrackDate > $lastTrackInCourse['access_date'])
  597. $oldestTrackDate = $lastTrackInCourse['access_date'];
  598. }
  599. // get the last edits of all tools of this course
  600. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  601. tet.lastedit_type type, tet.to_group_id group_id,
  602. ctt.image image, ctt.link link
  603. FROM $tool_edit_table tet, $course_tool_table ctt
  604. WHERE tet.lastedit_date > '$oldestTrackDate'
  605. AND ctt.name = tet.tool
  606. AND ctt.visibility = '1'
  607. AND tet.lastedit_user_id != $user_id
  608. ORDER BY tet.lastedit_date";
  609. $res = api_sql_query($sql);
  610. //get the group_id's with user membership
  611. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  612. $groups_ids[] = 0; //add group 'everyone'
  613. //filter all selected items
  614. while ($res && ($item_property = mysql_fetch_array($res)))
  615. {
  616. 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'])))
  617. {
  618. $notifications[$item_property['tool']] = $item_property;
  619. }
  620. }
  621. //show all tool icons where there is something new
  622. $retvalue = '&nbsp;';
  623. if (isset ($notifications))
  624. {
  625. while (list ($key, $notification) = each($notifications))
  626. {
  627. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  628. $type = $notification['lastedit_type'];
  629. //$notification[image]=str_replace(".png","gif",$notification[image]);
  630. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  631. $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;';
  632. }
  633. }
  634. return $retvalue;
  635. }
  636. /**
  637. * retrieves the user defined course categories
  638. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  639. * @return array containing all the titles of the user defined courses with the id as key of the array
  640. */
  641. function get_user_course_categories()
  642. {
  643. global $_user;
  644. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  645. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_user['user_id']."'";
  646. $result = api_sql_query($sql,__FILE__,__LINE__);
  647. while ($row = mysql_fetch_array($result))
  648. {
  649. $output[$row['id']] = $row['title'];
  650. }
  651. return $output;
  652. }
  653. /*
  654. ==============================================================================
  655. MAIN CODE
  656. ==============================================================================
  657. */
  658. /*
  659. ==============================================================================
  660. PERSONAL COURSE LIST
  661. ==============================================================================
  662. */
  663. if (!isset ($maxValvas))
  664. {
  665. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  666. }
  667. if (!isset ($maxAgenda))
  668. {
  669. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  670. }
  671. if (!isset ($maxCourse))
  672. {
  673. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  674. }
  675. $maxValvas = (int) $maxValvas;
  676. $maxAgenda = (int) $maxAgenda;
  677. $maxCourse = (int) $maxCourse; // 0 if invalid
  678. if ($maxCourse > 0)
  679. {
  680. unset ($allentries); // we shall collect all summary$key1 entries in here:
  681. $toolsList['agenda']['name'] = get_lang('Agenda');
  682. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  683. $toolsList['valvas']['name'] = get_lang('Valvas');
  684. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  685. }
  686. echo '<div class="maincontent">'; // start of content for logged in users
  687. // Plugins for the my courses main area
  688. api_plugin('mycourses_main');
  689. /*
  690. -----------------------------------------------------------------------------
  691. System Announcements
  692. -----------------------------------------------------------------------------
  693. */
  694. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  695. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  696. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  697. if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
  698. {
  699. include ('./home/'.$_GET['include']);
  700. $pageIncluded = true;
  701. }
  702. else
  703. {
  704. /*--------------------------------------
  705. DISPLAY COURSES
  706. --------------------------------------*/
  707. $list = '';
  708. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  709. foreach ($personal_course_list as $my_course)
  710. {
  711. $thisCourseDbName = $my_course['db'];
  712. $thisCourseSysCode = $my_course['k'];
  713. $thisCoursePublicCode = $my_course['c'];
  714. $thisCoursePath = $my_course['d'];
  715. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  716. $dbname = $my_course['k'];
  717. $status[$dbname] = $my_course['s'];
  718. $nbDigestEntries = 0; // number of entries already collected
  719. if ($maxCourse < $maxValvas)
  720. $maxValvas = $maxCourse;
  721. if ($maxCourse > 0)
  722. {
  723. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  724. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  725. }
  726. /*
  727. -----------------------------------------------------------
  728. Announcements
  729. -----------------------------------------------------------
  730. */
  731. $course_database = $my_course['db'];
  732. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  733. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  734. $result = api_sql_query($query);
  735. // collect from announcements, but only if tool is visible for the course
  736. if ($result && $maxValvas > 0 && mysql_num_rows($result) > 0)
  737. {
  738. //Search announcements table
  739. //Take the entries listed at the top of advalvas/announcements tool
  740. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  741. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  742. FROM ".$course_announcement_table;
  743. switch (CONFVAL_limitPreviewTo)
  744. {
  745. case SCRIPTVAL_NewEntriesOfTheDay :
  746. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  747. break;
  748. case SCRIPTVAL_NoTimeLimit :
  749. break;
  750. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  751. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  752. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  753. }
  754. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC
  755. LIMIT ".$maxValvas;
  756. $resGetLastAnnouncements = api_sql_query($sqlGetLastAnnouncements, __FILE__, __LINE__);
  757. if ($resGetLastAnnouncements)
  758. {
  759. while ($annoncement = mysql_fetch_array($resGetLastAnnouncements))
  760. {
  761. $keyTools = "valvas";
  762. $keyTime = $annoncement['publicationDate'];
  763. $keyCourse = $thisCourseSysCode;
  764. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  765. $nbDigestEntries ++; // summary has same order as advalvas
  766. }
  767. }
  768. }
  769. /*
  770. -----------------------------------------------------------
  771. Agenda
  772. -----------------------------------------------------------
  773. */
  774. $course_database = $my_course['db'];
  775. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  776. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  777. $result = api_sql_query($query);
  778. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  779. if ($maxAgenda < $thisAgenda)
  780. $thisAgenda = $maxAgenda;
  781. // collect from agenda, but only if tool is visible for the course
  782. if ($result && $thisAgenda > 0 && mysql_num_rows($result) > 0)
  783. {
  784. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  785. $sqlGetNextAgendaEvent = "SELECT start_date , title content, start_time
  786. FROM $tableCal
  787. WHERE start_date >= CURDATE()
  788. ORDER BY start_date, start_time
  789. LIMIT $maxAgenda";
  790. $resGetNextAgendaEvent = api_sql_query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
  791. if ($resGetNextAgendaEvent)
  792. {
  793. while ($agendaEvent = mysql_fetch_array($resGetNextAgendaEvent))
  794. {
  795. $keyTools = 'agenda';
  796. $keyTime = $agendaEvent['start_date'];
  797. $keyCourse = $thisCourseSysCode;
  798. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  799. $nbDigestEntries ++; // summary has same order as advalvas
  800. }
  801. }
  802. }
  803. /*
  804. -----------------------------------------------------------
  805. Digest Display
  806. take collected data and display it
  807. -----------------------------------------------------------
  808. */
  809. $list[] = get_logged_user_course_html($my_course);
  810. } //end while mycourse...
  811. }
  812. if (is_array($list))
  813. {
  814. //Courses whithout sessions
  815. $old_user_category = 0;
  816. foreach($list as $key=>$value)
  817. {
  818. if($value[2]==0){
  819. $userdefined_categories = get_user_course_categories();
  820. echo "<ul>\n";
  821. if ($old_user_category<>$value[0])
  822. {
  823. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  824. {
  825. echo "\n</ul>";
  826. }
  827. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  828. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  829. {
  830. echo "<ul>";
  831. }
  832. $old_user_category=$value[0];
  833. }
  834. echo $value[1];
  835. echo "</ul>\n";
  836. }
  837. }
  838. $listActives = $listInactives = $listCourses = array();
  839. foreach($list as $key=>$value){
  840. if($value['active'])
  841. $listActives[] = $value;
  842. else if(!empty($value[2]))
  843. $listInactives[] = $value;
  844. }
  845. $old_user_category = 0;
  846. $userdefined_categories = get_user_course_categories();
  847. if(count($listActives)>0 && $display_actives){
  848. echo "<ul style=\"line-height: 20px; margin-top: 20px;\">\n";
  849. foreach ($listActives as $key => $value)
  850. {
  851. if(!empty($value[2])){
  852. if($old_session != $value[2]){
  853. $old_session = $value[2];
  854. if($key != 0){
  855. echo "\n</ul>";
  856. }
  857. echo "\n\n\t<ul class=\"user_course_category\" style=\"margin-bottom: 10px;\"><li>".$value[3]."</li></ul>\n";
  858. echo "<ul style=\"padding: 0px; margin: 0px;\">";
  859. }
  860. }
  861. echo $value[1];
  862. }
  863. echo "\n</ul><br /><br />\n";
  864. }
  865. if(count($listInactives)>0 && !$display_actives){
  866. echo "<ul style=\"line-height: 20px;\">";
  867. foreach ($listInactives as $key => $value)
  868. {
  869. if(!empty($value[2])){
  870. if($old_session != $value[2]){
  871. $old_session = $value[2];
  872. if($key != 0){
  873. echo "\n</ul>";
  874. }
  875. echo "\n\n\t<ul class=\"user_course_category\"><li>".$value[3]."</li></ul>\n";
  876. echo "<ul>";
  877. }
  878. }
  879. echo $value[1];
  880. }
  881. echo "\n</ul><br /><br />\n";
  882. }
  883. }
  884. echo "</div>"; // end of content section
  885. // Register whether full admin or null admin course
  886. // by course through an array dbname x user status
  887. api_session_register('status');
  888. /*
  889. ==============================================================================
  890. RIGHT MENU
  891. ==============================================================================
  892. */
  893. echo '<div class="menu">';
  894. // tabs that are deactivated are added here
  895. if (!empty($menu_navigation))
  896. {
  897. echo '<div class="menusection">';
  898. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  899. echo '<ul class="menulist">';
  900. foreach($menu_navigation as $section => $navigation_info)
  901. {
  902. $current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
  903. echo '<li'.$current.'>';
  904. echo '<a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a>';
  905. echo '</li>';
  906. echo "\n";
  907. }
  908. echo '</ul>';
  909. echo '</div>';
  910. }
  911. // api_display_language_form(); // moved to the profile page.
  912. echo '<div class="menusection">';
  913. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  914. echo '<ul class="menulist">';
  915. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
  916. if ($display_add_course_link)
  917. display_create_course_link();
  918. display_edit_course_list_links();
  919. if(isset($toolsList) and is_array($toolsList) and isset($digest))
  920. {
  921. display_digest($toolsList, $digest, $orderKey, $courses);
  922. }
  923. echo '</ul>';
  924. echo '</div>';
  925. // plugins for the my courses menu
  926. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])){
  927. echo '<div class="note" style="background: none">';
  928. api_plugin('mycourses_menu');
  929. echo '</div>';
  930. }
  931. echo '</div>'; // end of menu
  932. /*
  933. ==============================================================================
  934. FOOTER
  935. ==============================================================================
  936. */
  937. Display :: display_footer();
  938. ?>