user_portal.php 49 KB

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