user_portal.php 39 KB

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