user_portal.php 51 KB

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