user_portal.php 50 KB

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