user_portal.php 39 KB

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