user_portal.php 39 KB

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