user_portal.php 39 KB

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