user_portal.php 53 KB

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