user_portal.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. <?php // $Id: user_portal.php 22375 2009-07-26 18:54:59Z herodoto $
  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. // Language files that should 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. require_once './main/inc/global.inc.php';
  53. $libpath = api_get_path(LIBRARY_PATH);
  54. require_once $libpath.'course.lib.php';
  55. require_once $libpath.'debug.lib.inc.php';
  56. require_once $libpath.'system_announcements.lib.php';
  57. require_once $libpath.'groupmanager.lib.php';
  58. require_once $libpath.'usermanager.lib.php';
  59. require_once 'main/survey/survey.lib.php';
  60. require_once $libpath.'sessionmanager.lib.php';
  61. api_block_anonymous_users(); // only users who are logged in can proceed
  62. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  63. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.toggle.js" type="text/javascript" language="javascript"></script>';
  64. /*
  65. -----------------------------------------------------------
  66. Table definitions
  67. -----------------------------------------------------------
  68. */
  69. //Database table definitions
  70. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  71. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  72. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  73. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  74. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  75. /*
  76. -----------------------------------------------------------
  77. Constants and CONFIGURATION parameters
  78. -----------------------------------------------------------
  79. */
  80. // ---- Course list options ----
  81. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  82. // Preview of course content
  83. // to disable all: set CONFVAL_maxTotalByCourse = 0
  84. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  85. // by default disabled since what's new icons are better (see function display_digest() )
  86. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  87. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  88. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  89. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  90. // Order to sort data
  91. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  92. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  93. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  94. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  95. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  96. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  97. // SCRIPTVAL_UnderCourseList // best choice
  98. // SCRIPTVAL_Both // probably only for debug
  99. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  100. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  101. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  102. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  103. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  104. // this is the main function to get the course list
  105. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  106. // check if a user is enrolled only in one course for going directly to the course after the login
  107. if (api_get_setting('go_to_course_after_login') == 'true') {
  108. if (!isset($_SESSION['coursesAlreadyVisited']) && is_array($personal_course_list) && count($personal_course_list) == 1) {
  109. $key = array_keys($personal_course_list);
  110. $course_info = $personal_course_list[$key[0]];
  111. $course_directory = $course_info['d'];
  112. $id_session = isset($course_info['id_session'])?$course_info['id_session']:0;
  113. header('location:'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session);
  114. exit;
  115. }
  116. }
  117. $nosession = false;
  118. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  119. $display_actives = !isset($_GET['inactives']);
  120. }
  121. $nameTools = get_lang('MyCourses');
  122. $this_section = SECTION_COURSES;
  123. /*
  124. -----------------------------------------------------------
  125. Check configuration parameters integrity
  126. -----------------------------------------------------------
  127. */
  128. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse") {
  129. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  130. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order
  131. die('
  132. <strong>config error:'.__FILE__.'</strong><br />
  133. set
  134. <ul>
  135. <li>
  136. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  137. (actually : '.CONFVAL_showExtractInfo.')
  138. </li>
  139. </ul>
  140. or
  141. <ul>
  142. <li>
  143. $orderKey[0] != "keyCourse"
  144. (actually : '.$orderKey[0].')
  145. </li>
  146. </ul>');
  147. }else {
  148. $orderKey = array ('keyCourse', 'keyTools', 'keyTime');
  149. }
  150. }
  151. /*
  152. -----------------------------------------------------------
  153. Header
  154. include the HTTP, HTML headers plus the top banner
  155. -----------------------------------------------------------
  156. */
  157. Display :: display_header($nameTools);
  158. /*
  159. ==============================================================================
  160. FUNCTIONS
  161. display_admin_links()
  162. display_create_course_link()
  163. display_edit_course_list_links()
  164. display_digest($toolsList, $digest, $orderKey, $courses)
  165. show_notification($my_course)
  166. get_personal_course_list($user_id)
  167. get_logged_user_course_html($my_course)
  168. get_user_course_categories()
  169. ==============================================================================
  170. */
  171. /*
  172. -----------------------------------------------------------
  173. Database functions
  174. some of these can go to database layer.
  175. -----------------------------------------------------------
  176. */
  177. /**
  178. * Database function that gets the list of courses for a particular user.
  179. * @param $user_id, the id of the user
  180. * @return an array with courses
  181. */
  182. function get_personal_course_list($user_id) {
  183. // initialisation
  184. $personal_course_list = array();
  185. // table definitions
  186. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  187. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  188. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  189. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  190. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  191. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  192. $user_id = Database::escape_string($user_id);
  193. $personal_course_list = array ();
  194. //Courses in which we suscribed out of any session
  195. $personal_course_list_sql = "SELECT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i,
  196. course.tutor_name t, course.course_language l, course_rel_user.status s, course_rel_user.sort sort,
  197. course_rel_user.user_course_cat user_course_cat
  198. FROM ".$main_course_table." course,".$main_course_user_table." course_rel_user
  199. WHERE course.code = course_rel_user.course_code"."
  200. AND course_rel_user.user_id = '".$user_id."'
  201. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC,i";
  202. $course_list_sql_result = Database::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, 5 as s
  208. FROM $main_course_table as course, $tbl_session_course_user as srcru
  209. WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
  210. $course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
  211. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  212. $personal_course_list[] = $result_row;
  213. }
  214. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  215. $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
  216. FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
  217. WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
  218. $course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
  219. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  220. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  221. $personal_course_list[] = $result_row;
  222. }
  223. return $personal_course_list;
  224. }
  225. /*
  226. -----------------------------------------------------------
  227. Display functions
  228. -----------------------------------------------------------
  229. */
  230. /**
  231. * Warning: this function defines a global.
  232. * @todo use the correct get_path function
  233. */
  234. function display_admin_links() {
  235. global $rootAdminWeb;
  236. echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
  237. }
  238. /**
  239. * Enter description here...
  240. *
  241. */
  242. function display_create_course_link() {
  243. echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
  244. }
  245. /**
  246. * Enter description here...
  247. *
  248. */
  249. function display_edit_course_list_links() {
  250. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  251. }
  252. /**
  253. * Show history sessions
  254. *
  255. */
  256. function display_history_course_session() {
  257. if (api_get_setting('use_session_mode')=='true') {
  258. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  259. echo "<li><a href=\"user_portal.php\">".get_lang('DisplayTrainingList')."</a></li>";
  260. } else {
  261. echo "<li><a href=\"user_portal.php?history=1\">".get_lang('HistoryTrainingSessions')."</a></li>";
  262. }
  263. }
  264. }
  265. /**
  266. * Displays a digest e.g. short summary of new agenda and announcements items.
  267. * This used to be displayed in the right hand menu, but is now
  268. * disabled by default (see config settings in this file) because most people like
  269. * the what's new icons better.
  270. *
  271. * @version 1.0
  272. */
  273. function display_digest($toolsList, $digest, $orderKey, $courses) {
  274. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  275. // // // LEVEL 1 // // //
  276. reset($digest);
  277. echo "<br /><br />\n";
  278. while (list($key1) = each($digest)) {
  279. if (is_array($digest[$key1])) {
  280. // // // Title of LEVEL 1 // // //
  281. echo "<strong>\n";
  282. if ($orderKey[0] == 'keyTools') {
  283. $tools = $key1;
  284. echo $toolsList[$key1]['name'];
  285. } elseif ($orderKey[0] == 'keyCourse') {
  286. $courseSysCode = $key1;
  287. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  288. } elseif ($orderKey[0] == 'keyTime') {
  289. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($digest[$key1]));
  290. }
  291. echo "</strong>\n";
  292. // // // End Of Title of LEVEL 1 // // //
  293. // // // LEVEL 2 // // //
  294. reset($digest[$key1]);
  295. while (list ($key2) = each($digest[$key1])) {
  296. // // // Title of LEVEL 2 // // //
  297. echo "<p>\n", "\n";
  298. if ($orderKey[1] == 'keyTools') {
  299. $tools = $key2;
  300. echo $toolsList[$key2][name];
  301. } elseif ($orderKey[1] == 'keyCourse') {
  302. $courseSysCode = $key2;
  303. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  304. } elseif ($orderKey[1] == 'keyTime') {
  305. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  306. }
  307. echo "\n";
  308. echo "</p>";
  309. // // // End Of Title of LEVEL 2 // // //
  310. // // // LEVEL 3 // // //
  311. reset($digest[$key1][$key2]);
  312. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  313. // // // Title of LEVEL 3 // // //
  314. if ($orderKey[2] == 'keyTools') {
  315. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  316. } elseif ($orderKey[2] == 'keyCourse') {
  317. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  318. } elseif ($orderKey[2] == 'keyTime') {
  319. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3))."</a>";
  320. }
  321. // // // End Of Title of LEVEL 3 // // //
  322. // // // LEVEL 4 (data) // // //
  323. reset($digest[$key1][$key2][$key3]);
  324. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  325. echo $level3title, ' &ndash; ', api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  326. //adding ... (three dots) if the texts are too large and they are shortened
  327. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  328. echo '...';
  329. }
  330. }
  331. echo "<br />\n";
  332. }
  333. }
  334. }
  335. }
  336. }
  337. } // end function display_digest
  338. /**
  339. * Display code for one specific course a logged in user is subscribed to.
  340. * Shows a link to the course, what's new icons...
  341. *
  342. * $my_course['d'] - course directory
  343. * $my_course['i'] - course title
  344. * $my_course['c'] - visual course code
  345. * $my_course['k'] - system course code
  346. * $my_course['db'] - course database
  347. *
  348. * @version 1.0.3
  349. * @todo refactor into different functions for database calls | logic | display
  350. * @todo replace single-character $my_course['d'] indices
  351. * @todo move code for what's new icons to a separate function to clear things up
  352. * @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.
  353. */
  354. function get_logged_user_course_html($course, $session_id = 0, $class='courses') {
  355. global $charset;
  356. global $nosession;
  357. $current_uid = api_get_user_id();
  358. $info = api_get_course_info($course['code']);
  359. $status_course = CourseManager::get_user_in_course_status($current_uid, $course['code']);
  360. if (!is_array($course['code'])) {
  361. $my_course = api_get_course_info($course['code']);
  362. $my_course['k'] = $my_course['id'];
  363. $my_course['db'] = $my_course['dbName'];
  364. $my_course['c'] = $my_course['official_code'];
  365. $my_course['i'] = $my_course['name'];
  366. $my_course['d'] = $my_course['path'];
  367. $my_course['t'] = $my_course['titular'];
  368. $my_course['id_session'] = $session_id;
  369. $my_course['status'] = ((empty($session_id))?$status_course:5);
  370. }
  371. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  372. global $now, $date_start, $date_end;
  373. }
  374. //initialise
  375. $result = '';
  376. // Table definitions
  377. //$statistic_database = Database::get_statistic_database();
  378. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  379. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  380. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  381. $course_database = $my_course['db'];
  382. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  383. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  384. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  385. $user_id = api_get_user_id();
  386. $course_system_code = $my_course['k'];
  387. $course_visual_code = $my_course['c'];
  388. $course_title = $my_course['i'];
  389. $course_directory = $my_course['d'];
  390. $course_teacher = $my_course['t'];
  391. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  392. $course_info = Database :: get_course_info($course_system_code);
  393. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  394. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  395. $course_visibility = $course_access_settings['visibility'];
  396. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  397. //function logic - act on the data
  398. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  399. if ($is_virtual_course) {
  400. // If the current user is also subscribed in the real course to which this
  401. // virtual course is linked, we don't need to display the virtual course entry in
  402. // the course list - it is combined with the real course entry.
  403. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  404. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  405. if ($is_subscribed_in_target_course) {
  406. return; //do not display this course entry
  407. }
  408. }
  409. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  410. if ($has_virtual_courses) {
  411. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  412. $course_display_title = $return_result['title'];
  413. $course_display_code = $return_result['code'];
  414. } else {
  415. $course_display_title = $course_title;
  416. $course_display_code = $course_visual_code;
  417. }
  418. $s_course_status = $my_course['status'];
  419. $is_coach = api_is_coach($my_course['id_session'],$course['code']);
  420. $s_htlm_status_icon = "";
  421. if ($s_course_status == 1) {
  422. $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher'));
  423. }
  424. if ($s_course_status == 2 || ($is_coach && $s_course_status != 1)) {
  425. $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach'));
  426. }
  427. if (($s_course_status == 5 && !$is_coach) || empty($s_course_status)) {
  428. $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student'));
  429. }
  430. //display course entry
  431. $result.="\n\t";
  432. $result .= '<li class="'.$class.'"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  433. //show a hyperlink to the course, unless the course is closed and user is not course admin
  434. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  435. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  436. if(empty($my_course['id_session'])) {
  437. $my_course['id_session'] = 0;
  438. }
  439. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  440. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  441. }
  442. } else {
  443. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  444. }
  445. } else {
  446. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  447. }
  448. // show the course_code and teacher if chosen to display this
  449. if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
  450. $result .= '<br />';
  451. }
  452. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  453. $result .= $course_display_code;
  454. }
  455. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  456. $result .= ' &ndash; ';
  457. }
  458. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  459. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  460. $coachs_course = api_get_coachs_from_course($my_course['id_session'],$course['code']);
  461. $course_coachs = array();
  462. if (is_array($coachs_course)) {
  463. foreach ($coachs_course as $coach_course) {
  464. $course_coachs[] = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
  465. }
  466. }
  467. if ($s_course_status == 1 || ($s_course_status == 5 && empty($my_course['id_session'])) || empty($s_course_status)) {
  468. $result .= $course_teacher;
  469. }
  470. if (($s_course_status == 5 && !empty($my_course['id_session'])) || ($is_coach && $s_course_status != 1)) {
  471. $result .= get_lang('Coachs').': '.implode(', ',$course_coachs);
  472. }
  473. } else {
  474. $result .= $course_teacher;
  475. }
  476. if(!empty($course_teacher_email)) {
  477. $result .= ' ('.$course_teacher_email.')';
  478. }
  479. }
  480. $result .= (isset($course['special_course']))? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
  481. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  482. // display the what's new icons
  483. $result .= show_notification($my_course);
  484. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  485. reset($digest);
  486. $result .= '
  487. <ul>';
  488. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  489. $result .= '<li>';
  490. if ($orderKey[1] == 'keyTools') {
  491. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  492. $result .= "$toolsList[$key2][\"name\"]</a>";
  493. } else {
  494. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  495. }
  496. $result .= '</li>';
  497. $result .= '<ul>';
  498. reset ($digest[$thisCourseSysCode][$key2]);
  499. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  500. $result .= '<li>';
  501. if ($orderKey[2] == 'keyTools') {
  502. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  503. $result .= "$toolsList[$key3][\"name\"]</a>";
  504. } else {
  505. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  506. }
  507. $result .= '<ul compact="compact">';
  508. reset($digest[$thisCourseSysCode][$key2][$key3]);
  509. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  510. $result .= '<li>';
  511. $result .= htmlspecialchars(api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  512. $result .= '</li>';
  513. }
  514. $result .= '</ul>';
  515. $result .= '</li>';
  516. }
  517. $result .= '</ul>';
  518. $result .= '</li>';
  519. }
  520. $result .= '</ul>';
  521. }
  522. $result .= '</li>';
  523. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  524. $session = '';
  525. $active = false;
  526. if (!empty($my_course['session_name'])) {
  527. // Request for the name of the general coach
  528. $sql = 'SELECT lastname, firstname,sc.name
  529. FROM '.$tbl_session.' ts
  530. LEFT JOIN '.$main_user_table .' tu
  531. ON ts.id_coach = tu.user_id
  532. INNER JOIN '.$tbl_session_category.' sc ON ts.session_category_id = sc.id
  533. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  534. $rs = Database::query($sql, __FILE__, __LINE__);
  535. $sessioncoach = Database::store_result($rs);
  536. $sessioncoach = $sessioncoach[0];
  537. $session = array();
  538. $session['title'] = $my_course['session_name'];
  539. $session_category_id = CourseManager::get_session_category_id_by_session_id($my_course['id_session']);
  540. $session['category'] = $sessioncoach['name'];
  541. if ( $my_course['date_start']=='0000-00-00' ) {
  542. $session['dates'] = get_lang('WithoutTimeLimits');
  543. if (api_get_setting('show_session_coach') === 'true') {
  544. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  545. }
  546. $active = true;
  547. } else {
  548. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  549. if (api_get_setting('show_session_coach') === 'true') {
  550. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  551. }
  552. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  553. }
  554. }
  555. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active,'session_category_id'=>$session_category_id);
  556. } else {
  557. $output = array ($my_course['user_course_cat'], $result);
  558. }
  559. return $output;
  560. }
  561. /**
  562. * Get the session box details as an array
  563. * @param int Session ID
  564. * @return array Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  565. */
  566. function get_session_title_box($session_id) {
  567. global $nosession;
  568. $output = array();
  569. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  570. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  571. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  572. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  573. $active = false;
  574. // Request for the name of the general coach
  575. $sql =
  576. 'SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
  577. FROM '.$tbl_session.' ts
  578. LEFT JOIN '.$main_user_table .' tu
  579. ON ts.id_coach = tu.user_id
  580. WHERE ts.id='.intval($session_id);
  581. $rs = Database::query($sql, __FILE__, __LINE__);
  582. $session_info = Database::store_result($rs);
  583. $session_info = $session_info[0];
  584. $session = array();
  585. $session['title'] = $session_info[2];
  586. $session['coach'] = '';
  587. if ( $session_info[3]=='0000-00-00' ) {
  588. $session['dates'] = get_lang('WithoutTimeLimits');
  589. if ( api_get_setting('show_session_coach') === 'true' ) {
  590. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  591. }
  592. $active = true;
  593. } else {
  594. $session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4];
  595. if ( api_get_setting('show_session_coach') === 'true' ) {
  596. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  597. }
  598. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  599. }
  600. $session['active'] = $active;
  601. $session['session_category_id'] = $session_info[5];
  602. $output = $session;
  603. }
  604. return $output;
  605. }
  606. /**
  607. * Display code for one specific course a logged in user is subscribed to.
  608. * Shows a link to the course, what's new icons...
  609. *
  610. * $my_course['d'] - course directory
  611. * $my_course['i'] - course title
  612. * $my_course['c'] - visual course code
  613. * $my_course['k'] - system course code
  614. * $my_course['db'] - course database
  615. *
  616. * @version 1.0.3
  617. * @todo refactor into different functions for database calls | logic | display
  618. * @todo replace single-character $my_course['d'] indices
  619. * @todo move code for what's new icons to a separate function to clear things up
  620. * @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.
  621. */
  622. function get_global_courses_list($user_id) {
  623. //1. get list of sessions the user is subscribed to
  624. //2. build an ordered list of session categories and sessions
  625. //3. fill this ordered list with course details
  626. global $charset;
  627. global $nosession;
  628. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  629. global $now, $date_start, $date_end;
  630. }
  631. $output = array();
  632. return $output;
  633. }
  634. /**
  635. * Returns the "what's new" icon notifications
  636. * @param array Course information array, containing at least elements 'db' and 'k'
  637. * @return string The HTML link to be shown next to the course
  638. * @version
  639. */
  640. function show_notification($my_course) {
  641. $statistic_database = Database :: get_statistic_database();
  642. $user_id = api_get_user_id();
  643. $course_database = $my_course['db'];
  644. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  645. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  646. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  647. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  648. // get the user's last access dates to all tools of this course
  649. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  650. USE INDEX (access_cours_code, access_user_id)
  651. WHERE access_cours_code = '".$my_course['k']."'
  652. AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
  653. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse, __FILE__, __LINE__);
  654. $oldestTrackDate = "3000-01-01 00:00:00";
  655. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  656. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  657. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  658. $oldestTrackDate = $lastTrackInCourse['access_date'];
  659. }
  660. }
  661. // get the last edits of all tools of this course
  662. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  663. tet.lastedit_type type, tet.to_group_id group_id,
  664. ctt.image image, ctt.link link
  665. FROM $tool_edit_table tet, $course_tool_table ctt
  666. WHERE tet.lastedit_date > '$oldestTrackDate'
  667. AND ctt.name = tet.tool
  668. AND ctt.visibility = '1'
  669. AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
  670. ORDER BY tet.lastedit_date";
  671. $res = Database::query($sql);
  672. //get the group_id's with user membership
  673. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  674. $group_ids[] = 0; //add group 'everyone'
  675. //filter all selected items
  676. while ($res && ($item_property = Database::fetch_array($res))) {
  677. if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  678. && ((in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
  679. && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset ($item_property['visibility']))) {
  680. if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'],$group_ids)) )) continue;
  681. if ($item_property['tool'] == TOOL_SURVEY) {
  682. $survey_info = survey_manager::get_survey($item_property['ref'],0,$my_course['k']);
  683. $invited_users = SurveyUtil::get_invited_users($survey_info['code'],$course_database);
  684. if (!in_array($user_id,$invited_users['course_users'])) continue;
  685. }
  686. $notifications[$item_property['tool']] = $item_property;
  687. }
  688. }
  689. //show all tool icons where there is something new
  690. $retvalue = '&nbsp;';
  691. if (isset ($notifications)) {
  692. while (list ($key, $notification) = each($notifications)) {
  693. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  694. $type = $notification['lastedit_type'];
  695. //$notification[image]=str_replace(".png","gif",$notification[image]);
  696. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  697. if(empty($my_course['id_session'])) {
  698. $my_course['id_session'] = 0;
  699. }
  700. $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.'<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;';
  701. }
  702. }
  703. return $retvalue;
  704. }
  705. /**
  706. * retrieves the user defined course categories
  707. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  708. * @return array containing all the titles of the user defined courses with the id as key of the array
  709. */
  710. function get_user_course_categories() {
  711. global $_user;
  712. $output = array();
  713. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  714. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'";
  715. $result = Database::query($sql,__FILE__,__LINE__);
  716. while ($row = Database::fetch_array($result)) {
  717. $output[$row['id']] = $row['title'];
  718. }
  719. return $output;
  720. }
  721. /*
  722. ==============================================================================
  723. MAIN CODE
  724. ==============================================================================
  725. */
  726. /*
  727. ==============================================================================
  728. PERSONAL COURSE LIST
  729. ==============================================================================
  730. */
  731. if (!isset ($maxValvas)) {
  732. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  733. }
  734. if (!isset ($maxAgenda)) {
  735. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  736. }
  737. if (!isset ($maxCourse)) {
  738. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  739. }
  740. $maxValvas = (int) $maxValvas;
  741. $maxAgenda = (int) $maxAgenda;
  742. $maxCourse = (int) $maxCourse; // 0 if invalid
  743. if ($maxCourse > 0) {
  744. unset ($allentries); // we shall collect all summary$key1 entries in here:
  745. $toolsList['agenda']['name'] = get_lang('Agenda');
  746. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  747. $toolsList['valvas']['name'] = get_lang('Valvas');
  748. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  749. }
  750. echo ' <div class="maincontent" id="maincontent">'; // start of content for logged in users
  751. // Plugins for the my courses main area
  752. api_plugin('mycourses_main');
  753. /*
  754. -----------------------------------------------------------------------------
  755. System Announcements
  756. -----------------------------------------------------------------------------
  757. */
  758. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  759. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  760. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  761. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  762. include ('./home/'.$_GET['include']);
  763. $pageIncluded = true;
  764. } else {
  765. /*--------------------------------------
  766. DISPLAY COURSES
  767. --------------------------------------*/
  768. // compose a structured array of session categories, sessions and courses
  769. // for the current user
  770. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  771. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true,true);
  772. } else {
  773. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true);
  774. }
  775. foreach ($courses_tree as $cat => $sessions) {
  776. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  777. if ($cat == 0) {
  778. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($_user['user_id'],false);
  779. }
  780. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  781. if (count($courses_tree[$cat]['sessions'])>0) {
  782. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  783. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  784. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($_user['user_id'],$s_id);
  785. }
  786. }
  787. }
  788. $list = '';
  789. foreach ($personal_course_list as $my_course) {
  790. $thisCourseDbName = $my_course['db'];
  791. $thisCourseSysCode = $my_course['k'];
  792. $thisCoursePublicCode = $my_course['c'];
  793. $thisCoursePath = $my_course['d'];
  794. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  795. $dbname = $my_course['k'];
  796. $status[$dbname] = $my_course['s'];
  797. $nbDigestEntries = 0; // number of entries already collected
  798. if ($maxCourse < $maxValvas) {
  799. $maxValvas = $maxCourse;
  800. }
  801. if ($maxCourse > 0) {
  802. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  803. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  804. }
  805. /*
  806. -----------------------------------------------------------
  807. Announcements
  808. -----------------------------------------------------------
  809. */
  810. $course_database = $my_course['db'];
  811. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  812. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  813. $result = Database::query($query);
  814. // collect from announcements, but only if tool is visible for the course
  815. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  816. //Search announcements table
  817. //Take the entries listed at the top of advalvas/announcements tool
  818. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  819. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  820. FROM ".$course_announcement_table;
  821. switch (CONFVAL_limitPreviewTo) {
  822. case SCRIPTVAL_NewEntriesOfTheDay :
  823. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  824. break;
  825. case SCRIPTVAL_NoTimeLimit :
  826. break;
  827. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  828. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  829. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  830. }
  831. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  832. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements, __FILE__, __LINE__);
  833. if ($resGetLastAnnouncements) {
  834. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  835. $keyTools = 'valvas';
  836. $keyTime = $annoncement['publicationDate'];
  837. $keyCourse = $thisCourseSysCode;
  838. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  839. $nbDigestEntries ++; // summary has same order as advalvas
  840. }
  841. }
  842. }
  843. /*
  844. -----------------------------------------------------------
  845. Agenda
  846. -----------------------------------------------------------
  847. */
  848. $course_database = $my_course['db'];
  849. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  850. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  851. $result = Database::query($query);
  852. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  853. if ($maxAgenda < $thisAgenda) {
  854. $thisAgenda = $maxAgenda;
  855. }
  856. // collect from agenda, but only if tool is visible for the course
  857. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  858. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  859. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  860. FROM $tableCal
  861. WHERE start_date >= CURDATE()
  862. ORDER BY start_date, start_time
  863. LIMIT $maxAgenda";
  864. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent, __FILE__, __LINE__);
  865. if ($resGetNextAgendaEvent) {
  866. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  867. $keyTools = 'agenda';
  868. $keyTime = $agendaEvent['start_date'];
  869. $keyCourse = $thisCourseSysCode;
  870. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  871. $nbDigestEntries ++; // summary has same order as advalvas
  872. }
  873. }
  874. }
  875. /*
  876. -----------------------------------------------------------
  877. Digest Display
  878. take collected data and display it
  879. -----------------------------------------------------------
  880. */
  881. //$list[] = get_logged_user_course_html($my_course);
  882. } //end while mycourse...
  883. }
  884. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  885. echo '<h3>'.get_lang('HistoryTrainingSession').'</h3>';
  886. if (empty($courses_tree[0]['sessions'])){
  887. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  888. }
  889. }
  890. if ( is_array($courses_tree) ) {
  891. foreach ($courses_tree as $key => $category) {
  892. if ($key == 0) {
  893. // sessions and courses that are not in a session category
  894. if (!isset($_GET['history'])) { // check if it's not history trainnign session list
  895. // independent courses
  896. if(count($category['courses']) > 0) {
  897. echo '<ul class="courseslist" style="list-style-type:none;">';
  898. }
  899. foreach ($category['courses'] as $course) {
  900. $c = get_logged_user_course_html($course, 0, 'independent_course_item');
  901. echo $c[1];
  902. }
  903. if(count($category['courses']) > 0) {
  904. echo '</ul>';
  905. }
  906. }
  907. //independent sessions
  908. foreach ($category['sessions'] as $session) {
  909. //don't show empty sessions
  910. if (count($session['courses'])<1) { continue; }
  911. //courses inside the current session
  912. $date_session_start = $session['details']['date_start'];
  913. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  914. $session_now = time();
  915. $html_courses_session = '';
  916. $count_courses_session = 0;
  917. foreach ($session['courses'] as $course) {
  918. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  919. if ($is_coach_course) {
  920. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  921. } else {
  922. $allowed_time = strtotime($date_session_start);
  923. }
  924. if ($session_now > $allowed_time) {
  925. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  926. $html_courses_session .= $c[1];
  927. $count_courses_session++;
  928. }
  929. }
  930. if ($count_courses_session > 0) {
  931. echo '<ul class="session_box">';
  932. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  933. echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  934. $s = get_session_title_box($session['details']['id']);
  935. echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  936. echo '</li>';
  937. echo $html_courses_session;
  938. echo '</ul>';
  939. }
  940. }
  941. } else {
  942. // all sessions included in
  943. if (!empty($category['details'])) {
  944. $count_courses_session = 0;
  945. $html_sessions = '';
  946. foreach ($category['sessions'] as $session) {
  947. //don't show empty sessions
  948. if (count($session['courses'])<1) { continue; }
  949. $date_session_start = $session['details']['date_start'];
  950. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  951. $session_now = time();
  952. $html_courses_session = '';
  953. $count = 0;
  954. foreach ($session['courses'] as $course) {
  955. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  956. if ($is_coach_course) {
  957. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  958. } else {
  959. $allowed_time = strtotime($date_session_start);
  960. }
  961. if ($session_now > $allowed_time) {
  962. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  963. $html_courses_session .= $c[1];
  964. $count_courses_session++;
  965. $count++;
  966. }
  967. }
  968. if ($count > 0) {
  969. $s = get_session_title_box($session['details']['id']);
  970. $html_sessions .= '<ul class="session_box" id="session_'.$session['details']['id'].'">';
  971. $html_sessions .= '<li class="session_box_title" id="session_'.$session['details']['id'].'">';
  972. $html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  973. $html_sessions .= get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  974. $html_sessions .= '</li>';
  975. $html_sessions .= $html_courses_session;
  976. $html_sessions .= '</ul>';
  977. }
  978. }
  979. if ($count_courses_session > 0) {
  980. echo '<div class="session_category" id="session_category_'.$category['details']['id'].'" style="background-color:#fbfbfb; border:1px solid #dddddd; padding:5px; margin-top: 10px;">';
  981. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="font-size:larger; color: #555555;">'. Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id'])) . ' ' . get_lang('SessionCategory') . ': ' . $category['details']['name'].' - '.get_lang('From').' '.$category['details']['date_start'].' '.get_lang('Until').' '.$category['details']['date_end'].'</div>';
  982. echo $html_sessions;
  983. echo '</div>';
  984. }
  985. }
  986. }
  987. }
  988. }
  989. /*
  990. if ( is_array($list) ) {
  991. //Courses whithout sessions
  992. $old_user_category = 0;
  993. foreach ($list as $key => $value) {
  994. if (empty($value[2])) { //if out of any session
  995. $userdefined_categories = get_user_course_categories();
  996. echo '<ul class="courseslist">';
  997. if ($old_user_category<>$value[0]) {
  998. if ($key <> 0 || $value[0] <> 0) {// there are courses in the previous category
  999. echo "\n</ul>";
  1000. }
  1001. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  1002. if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
  1003. echo "<ul class=\"courseslist\">";
  1004. }
  1005. $old_user_category = $value[0];
  1006. }
  1007. echo $value[1];
  1008. echo "</ul>\n";
  1009. }
  1010. }
  1011. $listActives = $listInactives = $listCourses = array();
  1012. foreach ($list as $key => $value) {
  1013. if ($value['active']) { //if the session is still active (as told by get_logged_user_course_html())
  1014. $listActives[] = $value;
  1015. } else if (!empty($value[2])) { //if there is a session but it is not active
  1016. $listInactives[] = $value;
  1017. }
  1018. }
  1019. $old_user_category = 0;
  1020. $userdefined_categories = get_user_course_categories();
  1021. if (count($listActives) > 0 && $display_actives) {
  1022. echo "<ul class=\"courseslist\">\n";
  1023. $name_category = array();
  1024. $i = 0;
  1025. $j=0;
  1026. foreach ($listActives as $key => $value) {
  1027. $session_category_id=$value['session_category_id'];
  1028. if (!empty($value[3]['category'])) {
  1029. if (!in_array($value[3]['category'], $name_category)) {
  1030. if ($key != 0) {
  1031. echo '</ul>';
  1032. }
  1033. //Category
  1034. $name_category['name'] = $value[3]['category'];
  1035. echo '<ul class="category_box" id="category_box_'.$session_category_id.'">' .
  1036. '<li class="category_box_title" id="category_box_title_'.$session_category_id.'">'.$name_category['name'].'</li>';
  1037. echo "</ul>\n";
  1038. }
  1039. }
  1040. if (!empty($value[2])) {
  1041. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  1042. $old_session = $value[2];
  1043. if ($key != 0) {
  1044. echo '</ul>';
  1045. }
  1046. //Session
  1047. echo '<ul style="display:none" class="session_box_'.$session_category_id.'" >' .
  1048. '<li class="session_box_title" >'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1049. if ( !empty($value[3]['coach']) ) {
  1050. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1051. }
  1052. echo "</ul>\n";
  1053. echo '<ul class="session_course_item" id="session_course_item_'.$i.'">';
  1054. }
  1055. }
  1056. //Courses
  1057. echo $value[1];
  1058. $i++;
  1059. }
  1060. echo "\n</ul><br /><br />\n";
  1061. }
  1062. if (count($listInactives) > 0 && !$display_actives) {
  1063. echo '<ul class="sessions_list_inactive">';
  1064. foreach ($listInactives as $key => $value) {
  1065. if (!empty($value[2])) {
  1066. if ($old_session != $value[2]) {
  1067. $old_session = $value[2];
  1068. if ($key != 0) {
  1069. echo '</ul>';
  1070. }
  1071. echo '<ul class="session_box">' .
  1072. '<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1073. if (!empty($value[3]['coach'])) {
  1074. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1075. }
  1076. echo "</ul>\n";
  1077. echo '<ul>';
  1078. }
  1079. }
  1080. echo $value[1];
  1081. }
  1082. echo "\n</ul><br /><br />\n";
  1083. }
  1084. } */
  1085. echo '</div>'; // end of content section
  1086. // Register whether full admin or null admin course
  1087. // by course through an array dbname x user status
  1088. api_session_register('status');
  1089. /*
  1090. ==============================================================================
  1091. RIGHT MENU
  1092. ==============================================================================
  1093. */
  1094. echo ' <div id="menu" class="menu">';
  1095. // api_display_language_form(); // moved to the profile page.
  1096. $show_menu = false;
  1097. $show_create_link = false;
  1098. $show_course_link = false;
  1099. $show_digest_link = false;
  1100. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  1101. if ($display_add_course_link) {
  1102. $show_menu = true;
  1103. $show_create_link = true;
  1104. }
  1105. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  1106. $show_menu = true;
  1107. $show_course_link = true;
  1108. } else {
  1109. if (api_get_setting('allow_students_to_browse_courses')=='true') {
  1110. $show_menu = true;
  1111. $show_course_link = true;
  1112. }
  1113. }
  1114. if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
  1115. $show_digest_link = true;
  1116. $show_menu = true;
  1117. }
  1118. // My account section
  1119. if ($show_menu) {
  1120. echo '<div class="menusection">';
  1121. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  1122. //user image
  1123. // @todo add a platform setting to add the user image
  1124. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  1125. $img_array= UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',true,true);
  1126. $no_image =false;
  1127. if ($img_array['file'] == 'unknown.jpg') {
  1128. $no_image =true;
  1129. }
  1130. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  1131. echo '<div class="clear"></div>';
  1132. echo '<div id="social_widget" >';
  1133. echo '<div id="social_widget_image">';
  1134. if ($no_image == false)
  1135. echo '<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1136. else
  1137. echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1138. echo '</div>';
  1139. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  1140. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  1141. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  1142. // New messages
  1143. $number_of_new_messages = MessageManager::get_new_messages();
  1144. // New contact invitations
  1145. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  1146. // New group invitations sent by a moderator
  1147. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  1148. $group_pending_invitations = count($group_pending_invitations);
  1149. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  1150. $cant_msg = '';
  1151. if ($number_of_new_messages > 0)
  1152. $cant_msg = ' ('.$number_of_new_messages.')';
  1153. //<h2 class="message-title">'.get_lang('Messages').'</h2>
  1154. echo '<div class="clear"></div>';
  1155. echo '<div class="message-content">
  1156. <p>';
  1157. $link = '';
  1158. if (api_get_setting('show_tabs', 'social') == 'true') {
  1159. $link = '?f=social';
  1160. }
  1161. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a><br />';
  1162. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a><br />';
  1163. //echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php" class="message-body">'.get_lang('EditMyProfile').' </a><br />';
  1164. if ($total_invitations > 0) {
  1165. echo '<a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' ('.$total_invitations.') </a><br />';
  1166. }
  1167. echo '</p>';
  1168. echo '</div>';
  1169. echo '</div><div class="clear"></div>';
  1170. }
  1171. echo '<ul class="menulist">';
  1172. if ($show_create_link) {
  1173. display_create_course_link();
  1174. }
  1175. if ($show_course_link) {
  1176. display_edit_course_list_links();
  1177. display_history_course_session();
  1178. }
  1179. if ($show_digest_link) {
  1180. display_digest($toolsList, $digest, $orderKey, $courses);
  1181. }
  1182. echo '</ul>';
  1183. echo '</div>';
  1184. }
  1185. //deleting the myprofile link
  1186. if (api_get_setting('allow_social_tool') == true) {
  1187. unset($menu_navigation['myprofile']);
  1188. }
  1189. // Main navigation section
  1190. // tabs that are deactivated are added here
  1191. if (!empty($menu_navigation)) {
  1192. echo '<div class="menusection">';
  1193. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  1194. echo '<ul class="menulist">';
  1195. foreach ($menu_navigation as $section => $navigation_info) {
  1196. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  1197. echo '<li'.$current.'>';
  1198. echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  1199. echo '</li>';
  1200. echo "\n";
  1201. }
  1202. echo '</ul>';
  1203. echo '</div>';
  1204. }
  1205. // plugins for the my courses menu
  1206. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  1207. echo '<div class="note">';
  1208. api_plugin('mycourses_menu');
  1209. echo '</div>';
  1210. }
  1211. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course() ){
  1212. echo '<div class="menusection">';
  1213. echo '<span class="menusectioncaption">'.get_lang('Booking').'</span>';
  1214. echo '<ul class="menulist">';
  1215. echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  1216. echo '</ul>';
  1217. echo '</div>';
  1218. }
  1219. // search textbox
  1220. if (api_get_setting('search_enabled') == 'true') {
  1221. echo '<div class="searchbox">';
  1222. $search_btn = get_lang('Search');
  1223. $search_text_default = get_lang('YourTextHere');
  1224. echo <<<EOD
  1225. <br />
  1226. <form action="main/search/" method="post">
  1227. &nbsp;&nbsp;<input type="text" id="query" size="15" name="query" value="" />
  1228. &nbsp;&nbsp;<button class="save" type="submit" name="submit" value="$search_btn"/>$search_btn </button>
  1229. </form>
  1230. EOD;
  1231. echo '</div>';
  1232. }
  1233. echo '</div>'; // end of menu
  1234. //footer
  1235. Display :: display_footer();