user_portal.php 36 KB

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