user_portal.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. <?php // $Id: user_portal.php,v 1.10 2006/08/19 09:33:14 yannoo Exp $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * This is the index file displayed when a user is logged in on Dokeos.
  23. *
  24. * It displays:
  25. * - personal course list
  26. * - menu bar
  27. *
  28. * Part of the what's new ideas were based on a rene haentjens hack
  29. *
  30. * Search for
  31. * CONFIGURATION parameters
  32. * to modify settings
  33. *
  34. * @todo rewrite code to separate display, logic, database code
  35. * @package dokeos.main
  36. ==============================================================================
  37. */
  38. /**
  39. * @todo shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  40. * if these are really configuration settings then we can add those to the dokeos config settings
  41. * @todo move get_personal_course_list and some other functions to a more appripriate place course.lib.php or user.lib.php
  42. * @todo use api_get_path instead of $rootAdminWeb
  43. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  44. * @todo display_digest, shouldn't this be removed and be made into an extension?
  45. */
  46. /*
  47. ==============================================================================
  48. INIT SECTION
  49. ==============================================================================
  50. */
  51. // Don't change these settings
  52. define('SCRIPTVAL_No', 0);
  53. define('SCRIPTVAL_InCourseList', 1);
  54. define('SCRIPTVAL_UnderCourseList', 2);
  55. define('SCRIPTVAL_Both', 3);
  56. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  57. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  58. define('SCRIPTVAL_NoTimeLimit', 6);
  59. // End 'don't change' section
  60. // name of the language file that needs to be included
  61. $language_file = array ('courses', 'index');
  62. $cidReset = true; /* Flag forcing the 'current course' reset,
  63. as we're not inside a course anymore */
  64. /*
  65. -----------------------------------------------------------
  66. Included libraries
  67. -----------------------------------------------------------
  68. */
  69. include_once ('./main/inc/global.inc.php');
  70. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  71. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  72. include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
  73. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  74. include_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  75. api_block_anonymous_users(); // only users who are logged in can proceed
  76. /*
  77. -----------------------------------------------------------
  78. Table definitions
  79. -----------------------------------------------------------
  80. */
  81. //Database table definitions
  82. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  83. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  84. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  85. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  86. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  87. /*
  88. -----------------------------------------------------------
  89. Constants and CONFIGURATION parameters
  90. -----------------------------------------------------------
  91. */
  92. // ---- Course list options ----
  93. define('CONFVAL_showCourseLangIfNotSameThatPlatform', TRUE);
  94. // Preview of course content
  95. // to disable all: set CONFVAL_maxTotalByCourse = 0
  96. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  97. // by default disabled since what's new icons are better (see function display_digest() )
  98. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  99. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  100. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  101. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  102. // Order to sort data
  103. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  104. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  105. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  106. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  107. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  108. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  109. // SCRIPTVAL_UnderCourseList // best choice
  110. // SCRIPTVAL_Both // probably only for debug
  111. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  112. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  113. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  114. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  115. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  116. /*if(api_is_allowed_to_create_course() && !isset($_GET['sessionview'])){
  117. $nosession = true;
  118. }
  119. else {
  120. $nosession = false;
  121. }*/
  122. $nosession=false;
  123. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  124. {
  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. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  395. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  396. $course_database = $my_course['db'];
  397. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  398. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  399. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  400. $user_id = api_get_user_id();
  401. $session_id = $my_course['id_session'];
  402. $course_system_code = $my_course['k'];
  403. $course_visual_code = $my_course['c'];
  404. $course_title = $my_course['i'];
  405. $course_directory = $my_course['d'];
  406. $course_teacher = $my_course['t'];
  407. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  408. $course_info = Database :: get_course_info($course_system_code);
  409. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  410. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  411. $course_visibility = $course_access_settings['visibility'];
  412. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  413. //function logic - act on the data
  414. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  415. if ($is_virtual_course)
  416. {
  417. // If the current user is also subscribed in the real course to which this
  418. // virtual course is linked, we don't need to display the virtual course entry in
  419. // the course list - it is combined with the real course entry.
  420. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  421. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  422. if ($is_subscribed_in_target_course)
  423. {
  424. return; //do not display this course entry
  425. }
  426. }
  427. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  428. if ($has_virtual_courses)
  429. {
  430. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  431. $course_display_title = $return_result['title'];
  432. $course_display_code = $return_result['code'];
  433. }
  434. else
  435. {
  436. $course_display_title = $course_title;
  437. $course_display_code = $course_visual_code;
  438. }
  439. $s_course_status=$my_course['s'];
  440. $s_htlm_status_icon="";
  441. if($s_course_status==1)
  442. {
  443. $s_htlm_status_icon=Display::return_icon('teachers.gif');
  444. }
  445. if($s_course_status==2)
  446. {
  447. $s_htlm_status_icon=Display::return_icon('coachs.gif');
  448. }
  449. if($s_course_status==5)
  450. {
  451. $s_htlm_status_icon=Display::return_icon('students.gif');
  452. }
  453. //display course entry
  454. $result.="\n\t";
  455. $result .= '<li class="courses"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  456. //show a hyperlink to the course, unless the course is closed and user is not course admin
  457. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)
  458. {
  459. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  460. {
  461. if(empty($my_course['id_session']))
  462. {
  463. $my_course['id_session'] = 0;
  464. }
  465. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00')
  466. {
  467. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  468. }
  469. }
  470. else
  471. {
  472. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  473. }
  474. }
  475. else
  476. {
  477. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  478. }
  479. // show the course_code and teacher if chosen to display this
  480. if (get_setting('display_coursecode_in_courselist') == 'true' OR get_setting('display_teacher_in_courselist') == 'true')
  481. {
  482. $result .= '<br />';
  483. }
  484. if (get_setting('display_coursecode_in_courselist') == 'true')
  485. {
  486. $result .= $course_display_code;
  487. }
  488. if (get_setting('display_coursecode_in_courselist') == 'true' AND get_setting('display_teacher_in_courselist') == 'true')
  489. {
  490. $result .= ' &ndash; ';
  491. }
  492. if (get_setting('display_teacher_in_courselist') == 'true')
  493. {
  494. $result .= $course_teacher;
  495. if(!empty($course_teacher_email))
  496. {
  497. $result .= ' ('.$course_teacher_email.')';
  498. }
  499. }
  500. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  501. // display the what's new icons
  502. $result .= show_notification($my_course);
  503. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0)
  504. {
  505. reset($digest);
  506. $result .= '
  507. <ul>';
  508. while (list ($key2) = each($digest[$thisCourseSysCode]))
  509. {
  510. $result .= '<li>';
  511. if ($orderKey[1] == 'keyTools')
  512. {
  513. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  514. $result .= "$toolsList[$key2][\"name\"]</a>";
  515. }
  516. else
  517. {
  518. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  519. }
  520. $result .= '</li>';
  521. $result .= '<ul>';
  522. reset($digest[$thisCourseSysCode][$key2]);
  523. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2]))
  524. {
  525. $result .= '<li>';
  526. if ($orderKey[2] == 'keyTools')
  527. {
  528. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  529. $result .= "$toolsList[$key3][\"name\"]</a>";
  530. }
  531. else
  532. {
  533. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  534. }
  535. $result .= '<ul compact="compact">';
  536. reset($digest[$thisCourseSysCode][$key2][$key3]);
  537. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3]))
  538. {
  539. $result .= '<li>';
  540. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  541. $result .= '</li>';
  542. }
  543. $result .= '</ul>';
  544. $result .= '</li>';
  545. }
  546. $result .= '</ul>';
  547. $result .= '</li>';
  548. }
  549. $result .= '</ul>';
  550. }
  551. $result .= '</li>';
  552. if(api_get_setting('use_session_mode')=='true' && !$nosession)
  553. {
  554. $session = '';
  555. $active = false;
  556. if(!empty($my_course['session_name']))
  557. {
  558. // Request for the name of the general coach
  559. $sql = 'SELECT lastname, firstname
  560. FROM '.$tbl_session.' ts
  561. LEFT JOIN '.$main_user_table .' tu
  562. ON ts.id_coach = tu.user_id
  563. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  564. $rs = api_sql_query($sql, __FILE__, __LINE__);
  565. $sessioncoach = api_store_result($rs);
  566. $sessioncoach = $sessioncoach[0];
  567. $session = array();
  568. $session['title'] = $my_course['session_name'];
  569. if ( $my_course['date_start']=='0000-00-00' ) {
  570. $session['dates'] = get_lang('WithoutTimeLimits');
  571. if ( api_get_setting('show_session_coach') === 'true' ) {
  572. $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname'];
  573. }
  574. $active = true;
  575. } else {
  576. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  577. if ( api_get_setting('show_session_coach') === 'true' ) {
  578. $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname'];
  579. }
  580. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  581. }
  582. }
  583. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active);
  584. }
  585. else
  586. {
  587. $output = array ($my_course['user_course_cat'], $result);
  588. }
  589. return $output;
  590. }
  591. /**
  592. * Returns the "what's new" icon notifications
  593. * @param array Course information array, containing at least elements 'db' and 'k'
  594. * @return string The HTML link to be shown next to the course
  595. * @version
  596. */
  597. function show_notification($my_course)
  598. {
  599. $statistic_database = Database :: get_statistic_database();
  600. $user_id = api_get_user_id();
  601. $course_database = $my_course['db'];
  602. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  603. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  604. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  605. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  606. // get the user's last access dates to all tools of this course
  607. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  608. USE INDEX (access_cours_code, access_user_id)
  609. WHERE access_cours_code = '".$my_course['k']."'
  610. AND access_user_id = '$user_id'";
  611. $resLastTrackInCourse = api_sql_query($sqlLastTrackInCourse, __FILE__, __LINE__);
  612. $oldestTrackDate = "3000-01-01 00:00:00";
  613. while ($lastTrackInCourse = mysql_fetch_array($resLastTrackInCourse))
  614. {
  615. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  616. if ($oldestTrackDate > $lastTrackInCourse['access_date'])
  617. $oldestTrackDate = $lastTrackInCourse['access_date'];
  618. }
  619. // get the last edits of all tools of this course
  620. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  621. tet.lastedit_type type, tet.to_group_id group_id,
  622. ctt.image image, ctt.link link
  623. FROM $tool_edit_table tet, $course_tool_table ctt
  624. WHERE tet.lastedit_date > '$oldestTrackDate'
  625. AND ctt.name = tet.tool
  626. AND ctt.visibility = '1'
  627. AND tet.lastedit_user_id != $user_id
  628. ORDER BY tet.lastedit_date";
  629. $res = api_sql_query($sql);
  630. //get the group_id's with user membership
  631. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  632. $groups_ids[] = 0; //add group 'everyone'
  633. //filter all selected items
  634. while ($res && ($item_property = mysql_fetch_array($res)))
  635. {
  636. 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'])))
  637. {
  638. $notifications[$item_property['tool']] = $item_property;
  639. }
  640. }
  641. //show all tool icons where there is something new
  642. $retvalue = '&nbsp;';
  643. if (isset ($notifications))
  644. {
  645. while (list ($key, $notification) = each($notifications))
  646. {
  647. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  648. $type = $notification['lastedit_type'];
  649. //$notification[image]=str_replace(".png","gif",$notification[image]);
  650. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  651. $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;';
  652. }
  653. }
  654. return $retvalue;
  655. }
  656. /**
  657. * retrieves the user defined course categories
  658. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  659. * @return array containing all the titles of the user defined courses with the id as key of the array
  660. */
  661. function get_user_course_categories()
  662. {
  663. global $_user;
  664. $output = array();
  665. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  666. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".$_user['user_id']."'";
  667. $result = api_sql_query($sql,__FILE__,__LINE__);
  668. while ($row = mysql_fetch_array($result))
  669. {
  670. $output[$row['id']] = $row['title'];
  671. }
  672. return $output;
  673. }
  674. /*
  675. ==============================================================================
  676. MAIN CODE
  677. ==============================================================================
  678. */
  679. /*
  680. ==============================================================================
  681. PERSONAL COURSE LIST
  682. ==============================================================================
  683. */
  684. if (!isset ($maxValvas))
  685. {
  686. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  687. }
  688. if (!isset ($maxAgenda))
  689. {
  690. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  691. }
  692. if (!isset ($maxCourse))
  693. {
  694. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  695. }
  696. $maxValvas = (int) $maxValvas;
  697. $maxAgenda = (int) $maxAgenda;
  698. $maxCourse = (int) $maxCourse; // 0 if invalid
  699. if ($maxCourse > 0)
  700. {
  701. unset ($allentries); // we shall collect all summary$key1 entries in here:
  702. $toolsList['agenda']['name'] = get_lang('Agenda');
  703. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  704. $toolsList['valvas']['name'] = get_lang('Valvas');
  705. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  706. }
  707. echo ' <div id="maincontent">'; // start of content for logged in users
  708. // Plugins for the my courses main area
  709. api_plugin('mycourses_main');
  710. /*
  711. -----------------------------------------------------------------------------
  712. System Announcements
  713. -----------------------------------------------------------------------------
  714. */
  715. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  716. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  717. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  718. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include']))
  719. {
  720. include ('./home/'.$_GET['include']);
  721. $pageIncluded = true;
  722. }
  723. else
  724. {
  725. /*--------------------------------------
  726. DISPLAY COURSES
  727. --------------------------------------*/
  728. $list = '';
  729. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  730. foreach ($personal_course_list as $my_course)
  731. {
  732. $thisCourseDbName = $my_course['db'];
  733. $thisCourseSysCode = $my_course['k'];
  734. $thisCoursePublicCode = $my_course['c'];
  735. $thisCoursePath = $my_course['d'];
  736. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  737. $dbname = $my_course['k'];
  738. $status[$dbname] = $my_course['s'];
  739. $nbDigestEntries = 0; // number of entries already collected
  740. if ($maxCourse < $maxValvas)
  741. $maxValvas = $maxCourse;
  742. if ($maxCourse > 0)
  743. {
  744. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  745. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  746. }
  747. /*
  748. -----------------------------------------------------------
  749. Announcements
  750. -----------------------------------------------------------
  751. */
  752. $course_database = $my_course['db'];
  753. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  754. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  755. $result = api_sql_query($query);
  756. // collect from announcements, but only if tool is visible for the course
  757. if ($result && $maxValvas > 0 && mysql_num_rows($result) > 0)
  758. {
  759. //Search announcements table
  760. //Take the entries listed at the top of advalvas/announcements tool
  761. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  762. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  763. FROM ".$course_announcement_table;
  764. switch (CONFVAL_limitPreviewTo)
  765. {
  766. case SCRIPTVAL_NewEntriesOfTheDay :
  767. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  768. break;
  769. case SCRIPTVAL_NoTimeLimit :
  770. break;
  771. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  772. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  773. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  774. }
  775. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC
  776. LIMIT ".$maxValvas;
  777. $resGetLastAnnouncements = api_sql_query($sqlGetLastAnnouncements, __FILE__, __LINE__);
  778. if ($resGetLastAnnouncements)
  779. {
  780. while ($annoncement = mysql_fetch_array($resGetLastAnnouncements))
  781. {
  782. $keyTools = "valvas";
  783. $keyTime = $annoncement['publicationDate'];
  784. $keyCourse = $thisCourseSysCode;
  785. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  786. $nbDigestEntries ++; // summary has same order as advalvas
  787. }
  788. }
  789. }
  790. /*
  791. -----------------------------------------------------------
  792. Agenda
  793. -----------------------------------------------------------
  794. */
  795. $course_database = $my_course['db'];
  796. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  797. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  798. $result = api_sql_query($query);
  799. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  800. if ($maxAgenda < $thisAgenda)
  801. $thisAgenda = $maxAgenda;
  802. // collect from agenda, but only if tool is visible for the course
  803. if ($result && $thisAgenda > 0 && mysql_num_rows($result) > 0)
  804. {
  805. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  806. $sqlGetNextAgendaEvent = "SELECT start_date , title content, start_time
  807. FROM $tableCal
  808. WHERE start_date >= CURDATE()
  809. ORDER BY start_date, start_time
  810. LIMIT $maxAgenda";
  811. $resGetNextAgendaEvent = api_sql_query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
  812. if ($resGetNextAgendaEvent)
  813. {
  814. while ($agendaEvent = mysql_fetch_array($resGetNextAgendaEvent))
  815. {
  816. $keyTools = 'agenda';
  817. $keyTime = $agendaEvent['start_date'];
  818. $keyCourse = $thisCourseSysCode;
  819. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  820. $nbDigestEntries ++; // summary has same order as advalvas
  821. }
  822. }
  823. }
  824. /*
  825. -----------------------------------------------------------
  826. Digest Display
  827. take collected data and display it
  828. -----------------------------------------------------------
  829. */
  830. $list[] = get_logged_user_course_html($my_course);
  831. } //end while mycourse...
  832. }
  833. if ( is_array($list) ) {
  834. //Courses whithout sessions
  835. $old_user_category = 0;
  836. foreach($list as $key=>$value) {
  837. if ( empty($value[2]) ) { //if out of any session
  838. $userdefined_categories = get_user_course_categories();
  839. echo '
  840. <ul class="courseslist">';
  841. if ($old_user_category<>$value[0])
  842. {
  843. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  844. {
  845. echo "\n</ul>";
  846. }
  847. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  848. if ($key<>0 OR $value[0]<>0) // there are courses in the previous category
  849. {
  850. echo "<ul class=\"courseslist\">";
  851. }
  852. $old_user_category=$value[0];
  853. }
  854. echo $value[1];
  855. echo "</ul>\n";
  856. }
  857. }
  858. $listActives = $listInactives = $listCourses = array();
  859. foreach ( $list as $key=>$value ) {
  860. if ( $value['active'] ) { //if the session is still active (as told by get_logged_user_course_html())
  861. $listActives[] = $value;
  862. } else if ( !empty($value[2]) ) { //if there is a session but it is not active
  863. $listInactives[] = $value;
  864. }
  865. }
  866. $old_user_category = 0;
  867. $userdefined_categories = get_user_course_categories();
  868. if(count($listActives)>0 && $display_actives){
  869. echo "<ul class=\"courseslist\">\n";
  870. foreach ($listActives as $key => $value)
  871. {
  872. if (!empty($value[2])) {
  873. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  874. $old_session = $value[2];
  875. if ($key != 0) {
  876. echo '</ul>';
  877. }
  878. echo '<ul class="session_box">' .
  879. '<li class="session_box_title">'.$value[3]['title'].' - '.$value[3]['dates'].'</li>';
  880. if ( !empty($value[3]['coach']) ) {
  881. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  882. }
  883. echo "</ul>\n";
  884. echo '<ul class="session_course_item">';
  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 class="sessions_list_inactive">';
  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 '</ul>';
  900. }
  901. echo '<ul class="session_box">' .
  902. '<li class="session_box_title">'.$value[3]['title'].' - '.$value[3]['dates'].'</li>';
  903. if ( !empty($value[3]['coach']) ) {
  904. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  905. }
  906. echo "</ul>\n";
  907. echo '<ul>';
  908. }
  909. }
  910. echo $value[1];
  911. }
  912. echo "\n</ul><br /><br />\n";
  913. }
  914. }
  915. echo '</div>'; // end of content section
  916. // Register whether full admin or null admin course
  917. // by course through an array dbname x user status
  918. api_session_register('status');
  919. /*
  920. ==============================================================================
  921. RIGHT MENU
  922. ==============================================================================
  923. */
  924. echo ' <div class="menu">';
  925. // tabs that are deactivated are added here
  926. if (!empty($menu_navigation))
  927. {
  928. echo '<div class="menusection">';
  929. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  930. echo '<ul class="menulist">';
  931. foreach($menu_navigation as $section => $navigation_info)
  932. {
  933. $current = ($section == $GLOBALS['this_section'] ? ' id="current"' : '');
  934. echo '<li'.$current.'>';
  935. echo '<a href="'.$navigation_info['url'].'" target="_top">'.$navigation_info['title'].'</a>';
  936. echo '</li>';
  937. echo "\n";
  938. }
  939. echo '</ul>';
  940. echo '</div>';
  941. }
  942. // api_display_language_form(); // moved to the profile page.
  943. echo '<div class="menusection">';
  944. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  945. echo '<ul class="menulist">';
  946. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION["studentview"] != "studentenview");
  947. if ($display_add_course_link)
  948. display_create_course_link();
  949. display_edit_course_list_links();
  950. if(isset($toolsList) and is_array($toolsList) and isset($digest))
  951. {
  952. display_digest($toolsList, $digest, $orderKey, $courses);
  953. }
  954. echo '</ul>';
  955. echo '</div>';
  956. // plugins for the my courses menu
  957. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])){
  958. echo '<div class="note">';
  959. api_plugin('mycourses_menu');
  960. echo '</div>';
  961. }
  962. echo '</div>'; // end of menu
  963. //footer
  964. Display :: display_footer();
  965. ?>