user_portal.php 53 KB

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