user_portal.php 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the index file displayed when a user is logged in on Dokeos.
  5. *
  6. * It displays:
  7. * - personal course list
  8. * - menu bar
  9. *
  10. * Part of the what's new ideas were based on a rene haentjens hack
  11. *
  12. * Search for
  13. * CONFIGURATION parameters
  14. * to modify settings
  15. *
  16. * @todo rewrite code to separate display, logic, database code
  17. * @package chamilo.main
  18. */
  19. /**
  20. * @todo shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
  21. * if these are really configuration settings then we can add those to the dokeos config settings
  22. * @todo move get_personal_course_list and some other functions to a more appripriate place course.lib.php or user.lib.php
  23. * @todo use api_get_path instead of $rootAdminWeb
  24. * @todo check for duplication of functions with index.php (user_portal.php is orginally a copy of index.php)
  25. * @todo display_digest, shouldn't this be removed and be made into an extension?
  26. */
  27. /* INIT SECTION */
  28. // Don't change these settings
  29. define('SCRIPTVAL_No', 0);
  30. define('SCRIPTVAL_InCourseList', 1);
  31. define('SCRIPTVAL_UnderCourseList', 2);
  32. define('SCRIPTVAL_Both', 3);
  33. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  34. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  35. define('SCRIPTVAL_NoTimeLimit', 6);
  36. // End 'don't change' section
  37. // Language files that should be included
  38. $language_file = array ('courses', 'index');
  39. $cidReset = true; /* Flag forcing the 'current course' reset,
  40. as we're not inside a course anymore */
  41. /*
  42. Included libraries
  43. */
  44. require_once './main/inc/global.inc.php';
  45. $libpath = api_get_path(LIBRARY_PATH);
  46. require_once $libpath.'course.lib.php';
  47. require_once $libpath.'debug.lib.inc.php';
  48. require_once $libpath.'system_announcements.lib.php';
  49. require_once $libpath.'groupmanager.lib.php';
  50. require_once $libpath.'usermanager.lib.php';
  51. require_once 'main/survey/survey.lib.php';
  52. require_once $libpath.'sessionmanager.lib.php';
  53. api_block_anonymous_users(); // only users who are logged in can proceed
  54. //$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  55. //$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.toggle.js" type="text/javascript" language="javascript"></script>';
  56. /*
  57. Table definitions
  58. */
  59. //Database table definitions
  60. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  61. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  62. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  63. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  64. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  65. /*
  66. Constants and CONFIGURATION parameters
  67. */
  68. // ---- Course list options ----
  69. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  70. // Preview of course content
  71. // to disable all: set CONFVAL_maxTotalByCourse = 0
  72. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  73. // by default disabled since what's new icons are better (see function display_digest() )
  74. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  75. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  76. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  77. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  78. // Order to sort data
  79. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  80. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  81. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  82. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  83. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  84. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  85. // SCRIPTVAL_UnderCourseList // best choice
  86. // SCRIPTVAL_Both // probably only for debug
  87. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  88. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  89. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  90. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  91. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  92. // this is the main function to get the course list
  93. $personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
  94. // check if a user is enrolled only in one course for going directly to the course after the login
  95. if (api_get_setting('go_to_course_after_login') == 'true') {
  96. if (!isset($_SESSION['coursesAlreadyVisited']) && is_array($personal_course_list) && count($personal_course_list) == 1) {
  97. $key = array_keys($personal_course_list);
  98. $course_info = $personal_course_list[$key[0]];
  99. $course_directory = $course_info['d'];
  100. $id_session = isset($course_info['id_session'])?$course_info['id_session']:0;
  101. header('location:'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session);
  102. exit;
  103. }
  104. }
  105. $nosession = false;
  106. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  107. $display_actives = !isset($_GET['inactives']);
  108. }
  109. $nameTools = get_lang('MyCourses');
  110. $this_section = SECTION_COURSES;
  111. /*
  112. Check configuration parameters integrity
  113. */
  114. if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse") {
  115. // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
  116. if (DEBUG || api_is_platform_admin()){ // Show bug if admin. Else force a new order
  117. die('
  118. <strong>config error:'.__FILE__.'</strong><br />
  119. set
  120. <ul>
  121. <li>
  122. CONFVAL_showExtractInfo = SCRIPTVAL_UnderCourseList
  123. (actually : '.CONFVAL_showExtractInfo.')
  124. </li>
  125. </ul>
  126. or
  127. <ul>
  128. <li>
  129. $orderKey[0] != "keyCourse"
  130. (actually : '.$orderKey[0].')
  131. </li>
  132. </ul>');
  133. }else {
  134. $orderKey = array ('keyCourse', 'keyTools', 'keyTime');
  135. }
  136. }
  137. /*
  138. -----------------------------------------------------------
  139. Header
  140. include the HTTP, HTML headers plus the top banner
  141. -----------------------------------------------------------
  142. */
  143. Display :: display_header($nameTools);
  144. /*
  145. FUNCTIONS
  146. display_admin_links()
  147. display_create_course_link()
  148. display_edit_course_list_links()
  149. display_digest($toolsList, $digest, $orderKey, $courses)
  150. show_notification($my_course)
  151. get_personal_course_list($user_id)
  152. get_logged_user_course_html($my_course)
  153. get_user_course_categories()
  154. */
  155. /*
  156. Database functions
  157. some of these can go to database layer.
  158. */
  159. /**
  160. * Database function that gets the list of courses for a particular user.
  161. * @param $user_id, the id of the user
  162. * @return an array with courses
  163. */
  164. function get_personal_course_list($user_id) {
  165. // initialisation
  166. $personal_course_list = array();
  167. // table definitions
  168. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  169. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  170. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  171. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  172. $tbl_session_course_user= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  173. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  174. $user_id = Database::escape_string($user_id);
  175. $personal_course_list = array ();
  176. //Courses in which we suscribed out of any session
  177. $personal_course_list_sql = "SELECT course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i,
  178. course.tutor_name t, course.course_language l, course_rel_user.status s, course_rel_user.sort sort,
  179. course_rel_user.user_course_cat user_course_cat
  180. FROM ".$main_course_table." course,".$main_course_user_table." course_rel_user
  181. WHERE course.code = course_rel_user.course_code"."
  182. AND course_rel_user.user_id = '".$user_id."'
  183. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  184. ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC,i";
  185. $course_list_sql_result = Database::query($personal_course_list_sql);
  186. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  187. $personal_course_list[] = $result_row;
  188. }
  189. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  190. $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
  191. FROM $main_course_table as course, $tbl_session_course_user as srcru
  192. WHERE srcru.course_code=course.code AND srcru.id_user='$user_id'";
  193. $course_list_sql_result = Database::query($personal_course_list_sql);
  194. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  195. $personal_course_list[] = $result_row;
  196. }
  197. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  198. $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
  199. FROM $main_course_table as course, $tbl_session_course as src, $tbl_session as session
  200. WHERE session.id_coach='$user_id' AND session.id=src.id_session AND src.course_code=course.code";
  201. $course_list_sql_result = Database::query($personal_course_list_sql);
  202. //$personal_course_list = array_merge($personal_course_list, $course_list_sql_result);
  203. while ($result_row = Database::fetch_array($course_list_sql_result)) {
  204. $personal_course_list[] = $result_row;
  205. }
  206. return $personal_course_list;
  207. }
  208. /**
  209. * display special courses
  210. * @param int User id
  211. * @return void
  212. */
  213. function display_special_courses ($user_id) {
  214. $user_id = intval($user_id);
  215. $user_info = api_get_user_info($user_id);
  216. $special_course_list = array();
  217. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  218. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  219. $tbl_course_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
  220. $tbl_course_field_value = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
  221. $tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  222. // get course list auto-register
  223. $sql = "SELECT course_code FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf ON " .
  224. " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 ";
  225. $special_course_result = Database::query($sql);
  226. if(Database::num_rows($special_course_result)>0) {
  227. $special_course_list = array();
  228. while ($result_row = Database::fetch_array($special_course_result)) {
  229. $special_course_list[] = '"'.$result_row['course_code'].'"';
  230. }
  231. }
  232. $with_special_courses = $without_special_courses = '';
  233. if (!empty($special_course_list)) {
  234. $with_special_courses = ' course.code IN ('.implode(',',$special_course_list).')';
  235. }
  236. if (!empty($with_special_courses)) {
  237. $sql = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  238. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  239. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course_rel_user.user_id, course.visibility
  240. FROM $TABLECOURS course
  241. LEFT JOIN $TABLECOURSUSER course_rel_user ON course.code = course_rel_user.course_code AND course_rel_user.user_id = '$user_id'
  242. WHERE $with_special_courses";
  243. $rs_special_course = api_sql_query($sql);
  244. $number_of_courses = Database::num_rows($rs_special_course);
  245. $key = 0;
  246. $status_icon = '';
  247. if ($number_of_courses > 0) {
  248. while ($course = Database::fetch_array($rs_special_course)) {
  249. // get notifications
  250. $my_course = array();
  251. $my_course['db'] = $course['db_name'];
  252. $my_course['k'] = $course['code'];
  253. $my_course['id_session'] = null;
  254. $my_course['s'] = $course['status'];
  255. $show_notification = show_notification($my_course);
  256. if (empty($course['user_id'])) {
  257. $course['status'] = $user_info['status'];
  258. }
  259. $status_icon = Display::return_icon('blackboard.png', get_lang('Course'), array('width'=>'48px'));
  260. /*
  261. if ($course['status'] == 1) {
  262. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  263. }
  264. if (($course['status'] == 5 && !api_is_coach()) || empty($course['status'])) {
  265. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  266. }*/
  267. echo '<div class="userportal-course-item">';
  268. if (api_is_platform_admin()) {
  269. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a>';
  270. if ($course['status'] == COURSEMANAGER) {
  271. //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  272. }
  273. echo '</div>';
  274. }
  275. /*
  276. if (api_is_allowed_to_edit(null, true)) {
  277. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course['db_name']).'</a>';
  278. } else {
  279. $progress_thematic_icon = get_thematic_progress_icon($course['db_name']);
  280. }
  281. */
  282. //echo "\t<tr>\n";
  283. //echo "\t\t<td>\n";
  284. //show a hyperlink to the course, unless the course is closed and user is not course admin
  285. //$course_access_settings = CourseManager :: get_access_settings($course['code']);
  286. $course_visibility = $course['visibility'];
  287. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) {
  288. $course_title = '<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'/?id_session=0&amp;autoreg=1">'.$course['title'].'</a>';
  289. } else {
  290. $course_title = $course['title']." ".get_lang('CourseClosed');
  291. }
  292. echo "<div style=\"float:left;margin-right:10px;\">".$status_icon."</div><span style=\"font-size:135%;\">".$course_title."</span><br />";
  293. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  294. echo $course['visual_code'];
  295. }
  296. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  297. echo " - ";
  298. }
  299. if ($course['status'] == COURSEMANAGER) {
  300. //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width:16px; height:16px; padding-right:5px;'));
  301. }
  302. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  303. echo $course['tutor'];
  304. }
  305. echo '&nbsp;';
  306. echo Display::return_icon('klipper.png', get_lang('CourseAutoRegister'));
  307. // show notifications
  308. echo $show_notification;
  309. echo '</div>';
  310. $key++;
  311. }
  312. }
  313. }
  314. }
  315. /**
  316. * Display courses without special courses
  317. * @param int user id
  318. * @return void
  319. */
  320. function display_courses($user_id) {
  321. global $_user, $_configuration;
  322. // building an array that contains all the id's of the user defined course categories
  323. // initially this was inside the display_courses_in_category function but when we do it here we have fewer
  324. // sql executions = performance increase.
  325. $all_user_categories = get_user_course_categories();
  326. // step 0: we display the course without a user category
  327. display_courses_in_category(0, 'true');
  328. // Step 1: We get all the categories of the user.
  329. $tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  330. $sql = "SELECT id, title FROM $tucc WHERE user_id='".$_user['user_id']."' ORDER BY sort ASC";
  331. $result = Database::query($sql);
  332. while ($row = Database::fetch_array($result)) {
  333. // We simply display the title of the category.
  334. echo '<div class="userportal-catalog-item">';
  335. echo '<ul class="catalog_box">';
  336. echo '<li>';
  337. echo Display::return_icon('folder_yellow.png', '', array('width'=>'48px', 'align' => 'absmiddle'));
  338. echo '<span>';
  339. echo '<a name="category'.$row['id'].'"></a>'; // display an internal anchor.
  340. echo $row['title'];
  341. echo '</span>';
  342. echo '</li>';
  343. display_courses_in_category($row['id']);
  344. echo '</ul>';
  345. echo '</div>';
  346. }
  347. }
  348. /**
  349. * display courses in category without special courses
  350. * @param int User category id
  351. * @return void
  352. */
  353. function display_courses_in_category($user_category_id) {
  354. global $_user, $_configuration;
  355. // table definitions
  356. $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE);
  357. $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  358. $TABLE_USER_COURSE_CATEGORY = Database :: get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  359. $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD);
  360. $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
  361. $TABLE_ACCESS_URL_REL_COURSE = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  362. $current_url_id = api_get_current_access_url_id();
  363. // get course list auto-register
  364. $sql = "SELECT course_code FROM $TABLE_COURSE_FIELD_VALUE tcfv INNER JOIN $TABLE_COURSE_FIELD tcf ON " .
  365. " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 ";
  366. $special_course_result = Database::query($sql);
  367. if(Database::num_rows($special_course_result)>0) {
  368. $special_course_list = array();
  369. while ($result_row = Database::fetch_array($special_course_result)) {
  370. $special_course_list[] = '"'.$result_row['course_code'].'"';
  371. }
  372. }
  373. $without_special_courses = '';
  374. if (!empty($special_course_list)) {
  375. $without_special_courses = ' AND course.code NOT IN ('.implode(',',$special_course_list).')';
  376. }
  377. $sql_select_courses = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr,
  378. course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status,
  379. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course.visibility
  380. FROM $TABLECOURS course,
  381. $TABLECOURSUSER course_rel_user, ".$TABLE_ACCESS_URL_REL_COURSE." url
  382. WHERE course.code = course_rel_user.course_code AND url.course_code = course.code
  383. AND course_rel_user.user_id = '".$_user['user_id']."'
  384. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  385. AND course_rel_user.user_course_cat='".$user_category_id."' $without_special_courses ";
  386. if ($_configuration['multiple_access_urls'] == true && $current_url_id!=-1){
  387. $sql_select_courses .= " AND url.course_code=course.code AND access_url_id='".$current_url_id."'";
  388. }
  389. $sql_select_courses .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
  390. $result = Database::query($sql_select_courses);
  391. $number_of_courses = Database::num_rows($result);
  392. $key = 0;
  393. $status_icon = '';
  394. while ($course = Database::fetch_array($result)) {
  395. // get notifications
  396. $my_course = array();
  397. $my_course['db'] = $course['db_name'];
  398. $my_course['k'] = $course['code'];
  399. $my_course['id_session'] = null;
  400. $my_course['s'] = $course['status'];
  401. $show_notification = show_notification($my_course);
  402. $status_icon = Display::return_icon('blackboard.png', get_lang('Course'), array('width'=>'48px'));
  403. /*
  404. // course list
  405. if ($course['status'] == COURSEMANAGER) {
  406. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  407. }
  408. if (($course['status'] == STUDENT && !api_is_coach()) || empty($course['status'])) {
  409. $status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  410. }*/
  411. /*
  412. if (api_is_allowed_to_edit(null,true)) {
  413. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course['db_name']).'</a>';
  414. } else {
  415. $progress_thematic_icon = get_thematic_progress_icon($course['db_name']);
  416. }
  417. */
  418. echo '<div class="userportal-course-item">';
  419. if (api_is_platform_admin()) {
  420. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a>';
  421. if ($course['status'] == COURSEMANAGER) {
  422. //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;'));
  423. }
  424. echo '</div>';
  425. }
  426. //function logic - act on the data
  427. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course['code']);
  428. if ($is_virtual_course) {
  429. // If the current user is also subscribed in the real course to which this
  430. // virtual course is linked, we don't need to display the virtual course entry in
  431. // the course list - it is combined with the real course entry.
  432. $target_course_code = CourseManager :: get_target_of_linked_course($course['code']);
  433. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  434. if ($is_subscribed_in_target_course) {
  435. return; //do not display this course entry
  436. }
  437. }
  438. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course['code'], api_get_user_id());
  439. if ($has_virtual_courses) {
  440. $course_info = api_get_course_info($course['code']);
  441. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  442. $course_title = $return_result['title'];
  443. $course_display_code = $return_result['code'];
  444. } else {
  445. $course_title = $course['title'];
  446. $course_display_code = $course['visual_code'];
  447. }
  448. //show a hyperlink to the course, unless the course is closed and user is not course admin
  449. $course_visibility = $course['visibility'];
  450. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) {
  451. $course_title = '<a href="'.api_get_path(WEB_COURSE_PATH).$course['directory'].'/?id_session=0">'.$course['title'].'</a>';
  452. } else {
  453. $course_title = $course['title']." ".get_lang('CourseClosed');
  454. }
  455. echo '<div style="float:left;margin-right:10px;">'.$status_icon.'</div><span style="font-size:135%;">'.$course_title.'</span><br />';
  456. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  457. echo $course_display_code;
  458. }
  459. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  460. echo ' - ';
  461. }
  462. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  463. if (!empty($course['tutor']))
  464. echo $course['tutor'];
  465. }
  466. // show notifications
  467. echo $show_notification;
  468. echo '</div>';
  469. $key++;
  470. }
  471. }
  472. /*
  473. Display functions
  474. */
  475. /**
  476. * get icon showing thematic progress for a course
  477. * @param string Course database name
  478. * @param int Session id (optional)
  479. * @return string img html
  480. */
  481. function get_thematic_progress_icon($course_dbname,$session_id = 0) {
  482. $tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION,$course_dbname);
  483. $session_id = intval($session_id);
  484. $sql = "SELECT progress FROM $tbl_course_description WHERE description_type = 8 AND session_id = '$session_id' ";
  485. $rs = Database::query($sql);
  486. $img = '';
  487. $title = '0%';
  488. $image = 'level_0.png';
  489. if (Database::num_rows($rs) > 0) {
  490. $row = Database::fetch_array($rs);
  491. $progress = $row['progress'];
  492. $image = 'level_'.$progress.'.png';
  493. $title = $row['progress'].'%';
  494. $img = Display::return_icon($image,get_lang('ThematicAdvance'),array('style'=>'vertical-align:middle')).'&nbsp;<span>'.$title.'</span>';
  495. }
  496. return $img;
  497. }
  498. /**
  499. * Warning: this function defines a global.
  500. * @todo use the correct get_path function
  501. */
  502. function display_admin_links() {
  503. global $rootAdminWeb;
  504. echo "<li><a href=\"".$rootAdminWeb."\">".get_lang('PlatformAdmin')."</a></li>";
  505. }
  506. /**
  507. * Display create course link
  508. *
  509. */
  510. function display_create_course_link() {
  511. echo "<li><a href=\"main/create_course/add_course.php\">".get_lang('CourseCreate')."</a></li>";
  512. }
  513. /**
  514. * Display dashboard link
  515. *
  516. */
  517. function display_dashboard_link() {
  518. echo "<li><a href=\"main/dashboard/index.php\">".get_lang('Dashboard')."</a></li>";
  519. }
  520. /**
  521. * Display edit course list links
  522. *
  523. */
  524. function display_edit_course_list_links() {
  525. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  526. }
  527. /**
  528. * Show history sessions
  529. *
  530. */
  531. function display_history_course_session() {
  532. if (api_get_setting('use_session_mode')=='true') {
  533. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  534. echo "<li><a href=\"user_portal.php\">".get_lang('DisplayTrainingList')."</a></li>";
  535. } else {
  536. echo "<li><a href=\"user_portal.php?history=1\">".get_lang('HistoryTrainingSessions')."</a></li>";
  537. }
  538. }
  539. }
  540. /**
  541. * Displays a digest e.g. short summary of new agenda and announcements items.
  542. * This used to be displayed in the right hand menu, but is now
  543. * disabled by default (see config settings in this file) because most people like
  544. * the what's new icons better.
  545. *
  546. * @version 1.0
  547. */
  548. function display_digest($toolsList, $digest, $orderKey, $courses) {
  549. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  550. // // // LEVEL 1 // // //
  551. reset($digest);
  552. echo "<br /><br />\n";
  553. while (list($key1) = each($digest)) {
  554. if (is_array($digest[$key1])) {
  555. // // // Title of LEVEL 1 // // //
  556. echo "<strong>\n";
  557. if ($orderKey[0] == 'keyTools') {
  558. $tools = $key1;
  559. echo $toolsList[$key1]['name'];
  560. } elseif ($orderKey[0] == 'keyCourse') {
  561. $courseSysCode = $key1;
  562. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  563. } elseif ($orderKey[0] == 'keyTime') {
  564. echo api_convert_and_format_date($digest[$key1], DATE_FORMAT_LONG, date_default_timezone_get());
  565. }
  566. echo "</strong>\n";
  567. // // // End Of Title of LEVEL 1 // // //
  568. // // // LEVEL 2 // // //
  569. reset($digest[$key1]);
  570. while (list ($key2) = each($digest[$key1])) {
  571. // // // Title of LEVEL 2 // // //
  572. echo "<p>\n", "\n";
  573. if ($orderKey[1] == 'keyTools') {
  574. $tools = $key2;
  575. echo $toolsList[$key2][name];
  576. } elseif ($orderKey[1] == 'keyCourse') {
  577. $courseSysCode = $key2;
  578. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  579. } elseif ($orderKey[1] == 'keyTime') {
  580. echo api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  581. }
  582. echo "\n";
  583. echo "</p>";
  584. // // // End Of Title of LEVEL 2 // // //
  585. // // // LEVEL 3 // // //
  586. reset($digest[$key1][$key2]);
  587. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  588. // // // Title of LEVEL 3 // // //
  589. if ($orderKey[2] == 'keyTools') {
  590. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  591. } elseif ($orderKey[2] == 'keyCourse') {
  592. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  593. } elseif ($orderKey[2] == 'keyTime') {
  594. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get())."</a>";
  595. }
  596. // // // End Of Title of LEVEL 3 // // //
  597. // // // LEVEL 4 (data) // // //
  598. reset($digest[$key1][$key2][$key3]);
  599. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  600. echo $level3title, ' &ndash; ', api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  601. //adding ... (three dots) if the texts are too large and they are shortened
  602. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  603. echo '...';
  604. }
  605. }
  606. echo "<br />\n";
  607. }
  608. }
  609. }
  610. }
  611. }
  612. } // end function display_digest
  613. /**
  614. * Display code for one specific course a logged in user is subscribed to.
  615. * Shows a link to the course, what's new icons...
  616. *
  617. * $my_course['d'] - course directory
  618. * $my_course['i'] - course title
  619. * $my_course['c'] - visual course code
  620. * $my_course['k'] - system course code
  621. * $my_course['db'] - course database
  622. *
  623. * @version 1.0.3
  624. * @todo refactor into different functions for database calls | logic | display
  625. * @todo replace single-character $my_course['d'] indices
  626. * @todo move code for what's new icons to a separate function to clear things up
  627. * @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.
  628. */
  629. function get_logged_user_course_html($course, $session_id = 0, $class='courses') {
  630. global $charset;
  631. global $nosession;
  632. $current_uid = api_get_user_id();
  633. $info = api_get_course_info($course['code']);
  634. $status_course = CourseManager::get_user_in_course_status($current_uid, $course['code']);
  635. if (!is_array($course['code'])) {
  636. $my_course = api_get_course_info($course['code']);
  637. $my_course['k'] = $my_course['id'];
  638. $my_course['db'] = $my_course['dbName'];
  639. $my_course['c'] = $my_course['official_code'];
  640. $my_course['i'] = $my_course['name'];
  641. $my_course['d'] = $my_course['path'];
  642. $my_course['t'] = $my_course['titular'];
  643. $my_course['id_session'] = $session_id;
  644. $my_course['status'] = ((empty($session_id))?$status_course:5);
  645. }
  646. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  647. global $now, $date_start, $date_end;
  648. }
  649. //initialise
  650. $result = '';
  651. // Table definitions
  652. //$statistic_database = Database::get_statistic_database();
  653. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  654. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  655. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  656. $course_database = $my_course['db'];
  657. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  658. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  659. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  660. $user_id = api_get_user_id();
  661. $course_system_code = $my_course['k'];
  662. $course_visual_code = $my_course['c'];
  663. $course_title = $my_course['i'];
  664. $course_directory = $my_course['d'];
  665. $course_teacher = $my_course['t'];
  666. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  667. $course_info = Database :: get_course_info($course_system_code);
  668. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  669. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  670. $course_visibility = $course_access_settings['visibility'];
  671. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  672. //function logic - act on the data
  673. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  674. if ($is_virtual_course) {
  675. // If the current user is also subscribed in the real course to which this
  676. // virtual course is linked, we don't need to display the virtual course entry in
  677. // the course list - it is combined with the real course entry.
  678. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  679. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  680. if ($is_subscribed_in_target_course) {
  681. return; //do not display this course entry
  682. }
  683. }
  684. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  685. if ($has_virtual_courses) {
  686. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  687. $course_display_title = $return_result['title'];
  688. $course_display_code = $return_result['code'];
  689. } else {
  690. $course_display_title = $course_title;
  691. $course_display_code = $course_visual_code;
  692. }
  693. $s_course_status = $my_course['status'];
  694. $is_coach = api_is_coach($my_course['id_session'],$course['code']);
  695. $s_htlm_status_icon = "";
  696. $s_htlm_status_icon=Display::return_icon('blackboard_blue.png', get_lang('Course'), array('width'=>'48px'));
  697. /*
  698. if ($s_course_status == 1) {
  699. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px'));
  700. }
  701. if ($s_course_status == 2 || ($is_coach && $s_course_status != 1)) {
  702. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('coachs.gif', get_lang('Status').': '.get_lang('GeneralCoach'),array('style'=>'width:11px; height:11px'));
  703. }
  704. if (($s_course_status == 5 && !$is_coach) || empty($s_course_status)) {
  705. $s_htlm_status_icon=Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'),array('style'=>'width:11px; height:11px'));
  706. }
  707. */
  708. //display course entry
  709. $result.="\n\t";
  710. $result .= '<li class="'.$class.'"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  711. //show a hyperlink to the course, unless the course is closed and user is not course admin
  712. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  713. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  714. if(empty($my_course['id_session'])) {
  715. $my_course['id_session'] = 0;
  716. }
  717. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  718. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  719. }
  720. } else {
  721. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  722. }
  723. } else {
  724. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  725. }
  726. /*
  727. if (api_is_allowed_to_edit(null, true)) {
  728. $progress_thematic_icon = '<a href="'.api_get_path(WEB_CODE_PATH).'course_description/index.php?action=edit&cidReq='.$course['code'].'&description_type=8'.'">'.get_thematic_progress_icon($course_database, $session_id).'</a>';
  729. } else {
  730. $progress_thematic_icon = get_thematic_progress_icon($course_database, $session_id);
  731. }
  732. */
  733. //$result .= '&nbsp;&nbsp;<span>'.$progress_thematic_icon.'</span>';
  734. // show the course_code and teacher if chosen to display this
  735. if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
  736. $result .= '<br />';
  737. }
  738. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  739. $result .= $course_display_code;
  740. }
  741. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  742. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  743. $coachs_course = api_get_coachs_from_course($my_course['id_session'],$course['code']);
  744. $course_coachs = array();
  745. if (is_array($coachs_course)) {
  746. foreach ($coachs_course as $coach_course) {
  747. $course_coachs[] = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
  748. }
  749. }
  750. if ($s_course_status == 1 || ($s_course_status == 5 && empty($my_course['id_session'])) || empty($s_course_status)) {
  751. $result .= $course_teacher;
  752. }
  753. if (($s_course_status == 5 && !empty($my_course['id_session'])) || ($is_coach && $s_course_status != 1)) {
  754. if (is_array($course_coachs) && count($course_coachs)> 0 ) {
  755. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  756. $result .= ' &ndash; ';
  757. }
  758. $result .= get_lang('Coachs').': '.implode(', ',$course_coachs);
  759. }
  760. }
  761. } else {
  762. $result .= $course_teacher;
  763. }
  764. if(!empty($course_teacher_email)) {
  765. $result .= ' ('.$course_teacher_email.')';
  766. }
  767. }
  768. $result .= (isset($course['special_course']))? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
  769. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  770. // display the what's new icons
  771. $result .= show_notification($my_course);
  772. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  773. reset($digest);
  774. $result .= '
  775. <ul>';
  776. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  777. $result .= '<li>';
  778. if ($orderKey[1] == 'keyTools') {
  779. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  780. $result .= "$toolsList[$key2][\"name\"]</a>";
  781. } else {
  782. $result .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  783. }
  784. $result .= '</li>';
  785. $result .= '<ul>';
  786. reset ($digest[$thisCourseSysCode][$key2]);
  787. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  788. $result .= '<li>';
  789. if ($orderKey[2] == 'keyTools') {
  790. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  791. $result .= "$toolsList[$key3][\"name\"]</a>";
  792. } else {
  793. $result .= api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get());
  794. }
  795. $result .= '<ul compact="compact">';
  796. reset($digest[$thisCourseSysCode][$key2][$key3]);
  797. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  798. $result .= '<li>';
  799. $result .= htmlspecialchars(api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  800. $result .= '</li>';
  801. }
  802. $result .= '</ul>';
  803. $result .= '</li>';
  804. }
  805. $result .= '</ul>';
  806. $result .= '</li>';
  807. }
  808. $result .= '</ul>';
  809. }
  810. $result .= '</li>';
  811. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  812. $session = '';
  813. $active = false;
  814. if (!empty($my_course['session_name'])) {
  815. // Request for the name of the general coach
  816. $sql = 'SELECT lastname, firstname,sc.name
  817. FROM '.$tbl_session.' ts
  818. LEFT JOIN '.$main_user_table .' tu
  819. ON ts.id_coach = tu.user_id
  820. INNER JOIN '.$tbl_session_category.' sc ON ts.session_category_id = sc.id
  821. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  822. $rs = Database::query($sql);
  823. $sessioncoach = Database::store_result($rs);
  824. $sessioncoach = $sessioncoach[0];
  825. $session = array();
  826. $session['title'] = $my_course['session_name'];
  827. $session_category_id = CourseManager::get_session_category_id_by_session_id($my_course['id_session']);
  828. $session['category'] = $sessioncoach['name'];
  829. if ( $my_course['date_start']=='0000-00-00' ) {
  830. $session['dates'] = get_lang('WithoutTimeLimits');
  831. if (api_get_setting('show_session_coach') === 'true') {
  832. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  833. }
  834. $active = true;
  835. } else {
  836. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  837. if (api_get_setting('show_session_coach') === 'true') {
  838. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  839. }
  840. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  841. }
  842. }
  843. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active,'session_category_id'=>$session_category_id);
  844. } else {
  845. $output = array ($my_course['user_course_cat'], $result);
  846. }
  847. return $output;
  848. }
  849. /**
  850. * Get the session box details as an array
  851. * @param int Session ID
  852. * @return array Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  853. */
  854. function get_session_title_box($session_id) {
  855. global $nosession;
  856. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  857. global $now, $date_start, $date_end;
  858. }
  859. $output = array();
  860. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  861. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  862. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  863. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  864. $active = false;
  865. // Request for the name of the general coach
  866. $sql ='SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
  867. FROM '.$tbl_session.' ts
  868. LEFT JOIN '.$main_user_table .' tu
  869. ON ts.id_coach = tu.user_id
  870. WHERE ts.id='.intval($session_id);
  871. $rs = Database::query($sql);
  872. $session_info = Database::store_result($rs);
  873. $session_info = $session_info[0];
  874. $session = array();
  875. $session['title'] = $session_info[2];
  876. $session['coach'] = '';
  877. if ( $session_info[3]=='0000-00-00' ) {
  878. $session['dates'] = get_lang('WithoutTimeLimits');
  879. if ( api_get_setting('show_session_coach') === 'true' ) {
  880. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  881. }
  882. $active = true;
  883. } else {
  884. $session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4];
  885. if ( api_get_setting('show_session_coach') === 'true' ) {
  886. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  887. }
  888. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  889. }
  890. $session['active'] = $active;
  891. $session['session_category_id'] = $session_info[5];
  892. $output = $session;
  893. }
  894. return $output;
  895. }
  896. /**
  897. * Display code for one specific course a logged in user is subscribed to.
  898. * Shows a link to the course, what's new icons...
  899. *
  900. * $my_course['d'] - course directory
  901. * $my_course['i'] - course title
  902. * $my_course['c'] - visual course code
  903. * $my_course['k'] - system course code
  904. * $my_course['db'] - course database
  905. *
  906. * @version 1.0.3
  907. * @todo refactor into different functions for database calls | logic | display
  908. * @todo replace single-character $my_course['d'] indices
  909. * @todo move code for what's new icons to a separate function to clear things up
  910. * @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.
  911. */
  912. function get_global_courses_list($user_id) {
  913. //1. get list of sessions the user is subscribed to
  914. //2. build an ordered list of session categories and sessions
  915. //3. fill this ordered list with course details
  916. global $charset;
  917. global $nosession;
  918. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  919. global $now, $date_start, $date_end;
  920. }
  921. $output = array();
  922. return $output;
  923. }
  924. /**
  925. * Returns the "what's new" icon notifications
  926. * @param array Course information array, containing at least elements 'db' and 'k'
  927. * @return string The HTML link to be shown next to the course
  928. * @version
  929. */
  930. function show_notification($my_course) {
  931. $statistic_database = Database :: get_statistic_database();
  932. $user_id = api_get_user_id();
  933. $course_database = $my_course['db'];
  934. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  935. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  936. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  937. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  938. // get the user's last access dates to all tools of this course
  939. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  940. USE INDEX (access_cours_code, access_user_id)
  941. WHERE access_cours_code = '".$my_course['k']."'
  942. AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
  943. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
  944. $oldestTrackDate = "3000-01-01 00:00:00";
  945. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  946. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  947. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  948. $oldestTrackDate = $lastTrackInCourse['access_date'];
  949. }
  950. }
  951. // get the last edits of all tools of this course
  952. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  953. tet.lastedit_type type, tet.to_group_id group_id,
  954. ctt.image image, ctt.link link
  955. FROM $tool_edit_table tet, $course_tool_table ctt
  956. WHERE tet.lastedit_date > '$oldestTrackDate'
  957. AND ctt.name = tet.tool
  958. AND ctt.visibility = '1'
  959. AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
  960. ORDER BY tet.lastedit_date";
  961. $res = Database::query($sql);
  962. //get the group_id's with user membership
  963. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  964. $group_ids[] = 0; //add group 'everyone'
  965. //filter all selected items
  966. while ($res && ($item_property = Database::fetch_array($res))) {
  967. if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  968. && ((in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
  969. && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset ($item_property['visibility']))) {
  970. if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'],$group_ids)) )) continue;
  971. if ($item_property['tool'] == TOOL_SURVEY) {
  972. $survey_info = survey_manager::get_survey($item_property['ref'],0,$my_course['k']);
  973. $invited_users = SurveyUtil::get_invited_users($survey_info['code'],$course_database);
  974. if (!in_array($user_id,$invited_users['course_users'])) continue;
  975. }
  976. $notifications[$item_property['tool']] = $item_property;
  977. }
  978. }
  979. //show all tool icons where there is something new
  980. $retvalue = '&nbsp;';
  981. if (isset ($notifications)) {
  982. while (list ($key, $notification) = each($notifications)) {
  983. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  984. $type = $notification['lastedit_type'];
  985. //$notification[image]=str_replace(".png","gif",$notification[image]);
  986. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  987. if(empty($my_course['id_session'])) {
  988. $my_course['id_session'] = 0;
  989. }
  990. $retvalue .= '<a href="'.api_get_path(WEB_CODE_PATH).$notification['link'].'?cidReq='.$my_course['k'].'&amp;ref='.$notification['ref'].'&amp;gidReq='.$notification['to_group_id'].'&amp;id_session='.$my_course['id_session'].'">'.'<img title="-- '.get_lang(ucfirst($notification['tool'])).' -- '.get_lang('_title_notification').": ".get_lang($type)." ($lastDate).\"".' src="'.api_get_path(WEB_CODE_PATH).'img/'.$notification['image'].'" border="0" align="absbottom" /></a>&nbsp;';
  991. }
  992. }
  993. return $retvalue;
  994. }
  995. /**
  996. * retrieves the user defined course categories
  997. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  998. * @return array containing all the titles of the user defined courses with the id as key of the array
  999. */
  1000. function get_user_course_categories() {
  1001. global $_user;
  1002. $output = array();
  1003. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  1004. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'";
  1005. $result = Database::query($sql);
  1006. while ($row = Database::fetch_array($result)) {
  1007. $output[$row['id']] = $row['title'];
  1008. }
  1009. return $output;
  1010. }
  1011. /*
  1012. MAIN CODE
  1013. */
  1014. /*
  1015. PERSONAL COURSE LIST
  1016. */
  1017. if (!isset ($maxValvas)) {
  1018. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  1019. }
  1020. if (!isset ($maxAgenda)) {
  1021. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  1022. }
  1023. if (!isset ($maxCourse)) {
  1024. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  1025. }
  1026. $maxValvas = (int) $maxValvas;
  1027. $maxAgenda = (int) $maxAgenda;
  1028. $maxCourse = (int) $maxCourse; // 0 if invalid
  1029. if ($maxCourse > 0) {
  1030. unset ($allentries); // we shall collect all summary$key1 entries in here:
  1031. $toolsList['agenda']['name'] = get_lang('Agenda');
  1032. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  1033. $toolsList['valvas']['name'] = get_lang('Valvas');
  1034. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  1035. }
  1036. echo ' <div class="maincontent" id="maincontent">'; // start of content for logged in users
  1037. // Plugins for the my courses main area
  1038. echo '<div id="plugin-mycourses_main">';
  1039. api_plugin('mycourses_main');
  1040. echo '</div>';
  1041. /*
  1042. -----------------------------------------------------------------------------
  1043. System Announcements
  1044. -----------------------------------------------------------------------------
  1045. */
  1046. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  1047. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  1048. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  1049. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  1050. include ('./home/'.$_GET['include']);
  1051. $pageIncluded = true;
  1052. } else {
  1053. /*--------------------------------------
  1054. DISPLAY COURSES
  1055. --------------------------------------*/
  1056. // compose a structured array of session categories, sessions and courses
  1057. // for the current user
  1058. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1059. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true,true);
  1060. } else {
  1061. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true);
  1062. }
  1063. foreach ($courses_tree as $cat => $sessions) {
  1064. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  1065. if ($cat == 0) {
  1066. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($_user['user_id'],false);
  1067. }
  1068. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  1069. if (count($courses_tree[$cat]['sessions'])>0) {
  1070. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  1071. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  1072. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($_user['user_id'],$s_id);
  1073. }
  1074. }
  1075. }
  1076. $list = '';
  1077. foreach ($personal_course_list as $my_course) {
  1078. $thisCourseDbName = $my_course['db'];
  1079. $thisCourseSysCode = $my_course['k'];
  1080. $thisCoursePublicCode = $my_course['c'];
  1081. $thisCoursePath = $my_course['d'];
  1082. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  1083. $dbname = $my_course['k'];
  1084. $status[$dbname] = $my_course['s'];
  1085. $nbDigestEntries = 0; // number of entries already collected
  1086. if ($maxCourse < $maxValvas) {
  1087. $maxValvas = $maxCourse;
  1088. }
  1089. if ($maxCourse > 0) {
  1090. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  1091. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  1092. }
  1093. /*
  1094. -----------------------------------------------------------
  1095. Announcements
  1096. -----------------------------------------------------------
  1097. */
  1098. $course_database = $my_course['db'];
  1099. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  1100. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  1101. $result = Database::query($query);
  1102. // collect from announcements, but only if tool is visible for the course
  1103. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  1104. //Search announcements table
  1105. //Take the entries listed at the top of advalvas/announcements tool
  1106. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1107. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  1108. FROM ".$course_announcement_table;
  1109. switch (CONFVAL_limitPreviewTo) {
  1110. case SCRIPTVAL_NewEntriesOfTheDay :
  1111. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  1112. break;
  1113. case SCRIPTVAL_NoTimeLimit :
  1114. break;
  1115. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  1116. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  1117. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  1118. }
  1119. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  1120. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  1121. if ($resGetLastAnnouncements) {
  1122. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  1123. $keyTools = 'valvas';
  1124. $keyTime = $annoncement['publicationDate'];
  1125. $keyCourse = $thisCourseSysCode;
  1126. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1127. $nbDigestEntries ++; // summary has same order as advalvas
  1128. }
  1129. }
  1130. }
  1131. /*
  1132. -----------------------------------------------------------
  1133. Agenda
  1134. -----------------------------------------------------------
  1135. */
  1136. $course_database = $my_course['db'];
  1137. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  1138. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  1139. $result = Database::query($query);
  1140. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  1141. if ($maxAgenda < $thisAgenda) {
  1142. $thisAgenda = $maxAgenda;
  1143. }
  1144. // collect from agenda, but only if tool is visible for the course
  1145. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  1146. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  1147. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  1148. FROM $tableCal
  1149. WHERE start_date >= CURDATE()
  1150. ORDER BY start_date, start_time
  1151. LIMIT $maxAgenda";
  1152. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  1153. if ($resGetNextAgendaEvent) {
  1154. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  1155. $keyTools = 'agenda';
  1156. $keyTime = $agendaEvent['start_date'];
  1157. $keyCourse = $thisCourseSysCode;
  1158. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1159. $nbDigestEntries ++; // summary has same order as advalvas
  1160. }
  1161. }
  1162. }
  1163. /*
  1164. -----------------------------------------------------------
  1165. Digest Display
  1166. take collected data and display it
  1167. -----------------------------------------------------------
  1168. */
  1169. //$list[] = get_logged_user_course_html($my_course);
  1170. } //end while mycourse...
  1171. }
  1172. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1173. echo '<h3>'.get_lang('HistoryTrainingSession').'</h3>';
  1174. if (empty($courses_tree[0]['sessions'])){
  1175. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  1176. }
  1177. }
  1178. if ( is_array($courses_tree) ) {
  1179. foreach ($courses_tree as $key => $category) {
  1180. if ($key == 0) {
  1181. // sessions and courses that are not in a session category
  1182. if (!isset($_GET['history'])) { // check if it's not history trainnign session list
  1183. display_special_courses(api_get_user_id());
  1184. display_courses(api_get_user_id());
  1185. }
  1186. //independent sessions
  1187. foreach ($category['sessions'] as $session) {
  1188. //don't show empty sessions
  1189. if (count($session['courses'])<1) { continue; }
  1190. //courses inside the current session
  1191. $date_session_start = $session['details']['date_start'];
  1192. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1193. $session_now = time();
  1194. $html_courses_session = '';
  1195. $count_courses_session = 0;
  1196. foreach ($session['courses'] as $course) {
  1197. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1198. if ($is_coach_course) {
  1199. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1200. } else {
  1201. $allowed_time = strtotime($date_session_start);
  1202. }
  1203. if ($session_now > $allowed_time) {
  1204. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1205. $html_courses_session .= $c[1];
  1206. $count_courses_session++;
  1207. }
  1208. }
  1209. if ($count_courses_session > 0) {
  1210. //echo '<div class="clear"></div>';
  1211. echo '<div class="userportal-session-item"><ul class="session_box">';
  1212. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  1213. //echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1214. echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width'=>'48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1215. $s = get_session_title_box($session['details']['id']);
  1216. $extra_info = (!empty($s['coach'])?$s['coach'].' | ':'').$s['dates'];
  1217. //var_dump($s);
  1218. //echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  1219. echo '<span>' . $s['title']. ' </span> <span style="padding-left:10px; font-size: 90%; font-weight: normal;">'.$extra_info.'</span>';
  1220. if (api_is_platform_admin()) {
  1221. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
  1222. }
  1223. echo '</li>';
  1224. echo $html_courses_session;
  1225. echo '</ul></div>';
  1226. }
  1227. }
  1228. } else {
  1229. // all sessions included in
  1230. if (!empty($category['details'])) {
  1231. $count_courses_session = 0;
  1232. $html_sessions = '';
  1233. foreach ($category['sessions'] as $session) {
  1234. //don't show empty sessions
  1235. if (count($session['courses'])<1) { continue; }
  1236. $date_session_start = $session['details']['date_start'];
  1237. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1238. $session_now = time();
  1239. $html_courses_session = '';
  1240. $count = 0;
  1241. foreach ($session['courses'] as $course) {
  1242. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1243. if ($is_coach_course) {
  1244. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1245. } else {
  1246. $allowed_time = strtotime($date_session_start);
  1247. }
  1248. if ($session_now > $allowed_time) {
  1249. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1250. $html_courses_session .= $c[1];
  1251. $count_courses_session++;
  1252. $count++;
  1253. }
  1254. }
  1255. if ($count > 0) {
  1256. $s = get_session_title_box($session['details']['id']);
  1257. $html_sessions .= '<ul class="sub_session_box" id="session_'.$session['details']['id'].'">';
  1258. $html_sessions .= '<li class="sub_session_box_title" id="session_'.$session['details']['id'].'">';
  1259. //$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1260. $html_sessions .= Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width'=>'48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1261. $html_sessions .= '<span>' . $s['title']. ' </span> ';
  1262. $html_sessions .= '<span style="padding-left:10px; font-size: 90%; font-weight: normal;">';
  1263. $html_sessions .= (!empty($s['coach'])?$s['coach'].' | ':'').$s['dates'];
  1264. $html_sessions .= '</span>';
  1265. if (api_is_platform_admin()) {
  1266. $html_sessions .= '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
  1267. }
  1268. $html_sessions .= '</li>';
  1269. $html_sessions .= $html_courses_session;
  1270. $html_sessions .= '</ul>';
  1271. }
  1272. }
  1273. if ($count_courses_session > 0) {
  1274. echo '<div class="userportal-session-category-item" id="session_category_'.$category['details']['id'].'">';
  1275. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  1276. //echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id']));
  1277. echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  1278. if (api_is_platform_admin()) {
  1279. echo'<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$category['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
  1280. }
  1281. echo '<span id="session_category_title">';
  1282. echo $category['details']['name'];
  1283. echo '</span>';
  1284. echo '<span style="padding-left:10px; font-size: 90%; font-weight: normal;">';
  1285. echo get_lang('From').' '.$category['details']['date_start'].' '.get_lang('Until').' '.$category['details']['date_end'].'</div>';
  1286. echo '</span>';
  1287. echo $html_sessions;
  1288. echo '</div>';
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. /*
  1295. $userdefined_categories = get_user_course_categories();
  1296. if ( is_array($list) ) {
  1297. //Courses whithout sessions
  1298. $old_user_category = 0;
  1299. foreach ($list as $key => $value) {
  1300. if (empty($value[2])) { //if out of any session
  1301. $userdefined_categories = get_user_course_categories();
  1302. echo '<ul class="courseslist">';
  1303. if ($old_user_category<>$value[0]) {
  1304. if ($key <> 0 || $value[0] <> 0) {// there are courses in the previous category
  1305. echo "\n</ul>";
  1306. }
  1307. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  1308. if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
  1309. echo "<ul class=\"courseslist\">";
  1310. }
  1311. $old_user_category = $value[0];
  1312. }
  1313. echo $value[1];
  1314. echo "</ul>\n";
  1315. }
  1316. }
  1317. $listActives = $listInactives = $listCourses = array();
  1318. foreach ($list as $key => $value) {
  1319. if ($value['active']) { //if the session is still active (as told by get_logged_user_course_html())
  1320. $listActives[] = $value;
  1321. } else if (!empty($value[2])) { //if there is a session but it is not active
  1322. $listInactives[] = $value;
  1323. }
  1324. }
  1325. $old_user_category = 0;
  1326. $userdefined_categories = get_user_course_categories();
  1327. if (count($listActives) > 0 && $display_actives) {
  1328. echo "<ul class=\"courseslist\">\n";
  1329. $name_category = array();
  1330. $i = 0;
  1331. $j=0;
  1332. foreach ($listActives as $key => $value) {
  1333. $session_category_id=$value['session_category_id'];
  1334. if (!empty($value[3]['category'])) {
  1335. if (!in_array($value[3]['category'], $name_category)) {
  1336. if ($key != 0) {
  1337. echo '</ul>';
  1338. }
  1339. //Category
  1340. $name_category['name'] = $value[3]['category'];
  1341. echo '<ul class="category_box" id="category_box_'.$session_category_id.'">' .
  1342. '<li class="category_box_title" id="category_box_title_'.$session_category_id.'">'.$name_category['name'].'</li>';
  1343. echo "</ul>\n";
  1344. }
  1345. }
  1346. if (!empty($value[2])) {
  1347. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  1348. $old_session = $value[2];
  1349. if ($key != 0) {
  1350. echo '</ul>';
  1351. }
  1352. //Session
  1353. echo '<ul style="display:none" class="session_box_'.$session_category_id.'" >' .
  1354. '<li class="session_box_title" >'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1355. if ( !empty($value[3]['coach']) ) {
  1356. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1357. }
  1358. echo "</ul>\n";
  1359. echo '<ul class="session_course_item" id="session_course_item_'.$i.'">';
  1360. }
  1361. }
  1362. //Courses
  1363. echo $value[1];
  1364. $i++;
  1365. }
  1366. echo "\n</ul><br /><br />\n";
  1367. }
  1368. if (count($listInactives) > 0 && !$display_actives) {
  1369. echo '<ul class="sessions_list_inactive">';
  1370. foreach ($listInactives as $key => $value) {
  1371. if (!empty($value[2])) {
  1372. if ($old_session != $value[2]) {
  1373. $old_session = $value[2];
  1374. if ($key != 0) {
  1375. echo '</ul>';
  1376. }
  1377. echo '<ul class="session_box">' .
  1378. '<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1379. if (!empty($value[3]['coach'])) {
  1380. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1381. }
  1382. echo "</ul>\n";
  1383. echo '<ul>';
  1384. }
  1385. }
  1386. echo $value[1];
  1387. }
  1388. echo "\n</ul><br /><br />\n";
  1389. }
  1390. }
  1391. */
  1392. echo '</div>'; // end of content section
  1393. // Register whether full admin or null admin course
  1394. // by course through an array dbname x user status
  1395. api_session_register('status');
  1396. /*
  1397. RIGHT MENU
  1398. */
  1399. echo ' <div id="menu-wrapper">';
  1400. echo ' <div id="menu" class="menu">';
  1401. // api_display_language_form(); // moved to the profile page.
  1402. $show_menu = false;
  1403. $show_create_link = false;
  1404. $show_course_link = false;
  1405. $show_digest_link = false;
  1406. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  1407. if ($display_add_course_link) {
  1408. $show_menu = true;
  1409. $show_create_link = true;
  1410. }
  1411. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  1412. $show_menu = true;
  1413. $show_course_link = true;
  1414. } else {
  1415. if (api_get_setting('allow_students_to_browse_courses')=='true') {
  1416. $show_menu = true;
  1417. $show_course_link = true;
  1418. }
  1419. }
  1420. if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
  1421. $show_digest_link = true;
  1422. $show_menu = true;
  1423. }
  1424. echo '<div class="menusection">';
  1425. echo '<span class="menusectioncaption">'.get_lang('Profile').'</span>';
  1426. //Always show the user image
  1427. $img_array= UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',true,true);
  1428. $no_image =false;
  1429. if ($img_array['file'] == 'unknown.jpg') {
  1430. $no_image =true;
  1431. }
  1432. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  1433. echo '<div class="clear"></div>';
  1434. echo '<div id="social_widget">';
  1435. echo ' <div id="social_widget_image">';
  1436. if (api_get_setting('allow_social_tool')=='true') {
  1437. if ($no_image == false) {
  1438. echo '<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1439. } else {
  1440. echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1441. }
  1442. } else {
  1443. echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1444. }
  1445. echo '</div>';
  1446. // @todo add a platform setting to add the user image
  1447. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  1448. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  1449. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  1450. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  1451. // New messages
  1452. $number_of_new_messages = MessageManager::get_new_messages();
  1453. // New contact invitations
  1454. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  1455. // New group invitations sent by a moderator
  1456. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  1457. $group_pending_invitations = count($group_pending_invitations);
  1458. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  1459. $cant_msg = '';
  1460. if ($number_of_new_messages > 0) {
  1461. $cant_msg = ' ('.$number_of_new_messages.')';
  1462. }
  1463. //<h2 class="message-title">'.get_lang('Messages').'</h2>
  1464. echo '<div class="clear"></div>';
  1465. echo '<div class="message-content"><ul class="menulist">';
  1466. $link = '';
  1467. if (api_get_setting('show_tabs', 'social') == 'true') {
  1468. $link = '?f=social';
  1469. }
  1470. echo '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a></li>';
  1471. echo '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  1472. //echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php" class="message-body">'.get_lang('EditMyProfile').' </a><br />';
  1473. //if ($total_invitations > 0) {
  1474. echo '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' ('.$total_invitations.') </a></li>';
  1475. //}
  1476. echo '</ul>';
  1477. echo '</div>';
  1478. }
  1479. echo '</div>'; //end
  1480. echo '</div>';
  1481. echo '</div>'; // end of menu
  1482. echo ' <div id="menu" class="menu">';
  1483. echo '<div class="menusection">';
  1484. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  1485. // My account section
  1486. if ($show_menu) {
  1487. echo '<ul class="menulist">';
  1488. if ($show_create_link) {
  1489. display_create_course_link();
  1490. }
  1491. if ($show_course_link) {
  1492. if (!api_is_drh()) {
  1493. display_edit_course_list_links();
  1494. display_history_course_session();
  1495. } else {
  1496. display_dashboard_link();
  1497. }
  1498. }
  1499. if ($show_digest_link) {
  1500. display_digest($toolsList, $digest, $orderKey, $courses);
  1501. }
  1502. echo '</ul>';
  1503. }
  1504. echo '</div>'; //close menusection
  1505. //deleting the myprofile link
  1506. if (api_get_setting('allow_social_tool') == true) {
  1507. unset($menu_navigation['myprofile']);
  1508. }
  1509. // Main navigation section
  1510. // tabs that are deactivated are added here
  1511. if (!empty($menu_navigation)) {
  1512. echo '<div class="menusection">';
  1513. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  1514. echo '<ul class="menulist">';
  1515. foreach ($menu_navigation as $section => $navigation_info) {
  1516. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  1517. echo '<li'.$current.'>';
  1518. echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  1519. echo '</li>';
  1520. }
  1521. echo '</ul>';
  1522. echo '</div>';
  1523. }
  1524. // plugins for the my courses menu
  1525. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  1526. echo '<div class="note">';
  1527. echo '<div id="plugin-mycourses_menu">';
  1528. api_plugin('mycourses_menu');
  1529. echo '</div>';
  1530. }
  1531. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course() ){
  1532. echo '<div class="menusection">';
  1533. echo '<span class="menusectioncaption">'.get_lang('Booking').'</span>';
  1534. echo '<ul class="menulist">';
  1535. echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  1536. echo '</ul>';
  1537. echo '</div>';
  1538. }
  1539. //Deleting the session_id
  1540. api_session_unregister('session_id');
  1541. // search textbox
  1542. if (api_get_setting('search_enabled') == 'true') {
  1543. echo '<div class="searchbox">';
  1544. $search_btn = get_lang('Search');
  1545. $search_text_default = get_lang('YourTextHere');
  1546. echo <<<EOD
  1547. <br />
  1548. <form action="main/search/" method="post">
  1549. &nbsp;&nbsp;<input type="text" id="query" size="15" name="query" value="" />
  1550. &nbsp;&nbsp;<button class="save" type="submit" name="submit" value="$search_btn"/>$search_btn </button>
  1551. </form>
  1552. EOD;
  1553. echo '</div>';
  1554. }
  1555. echo '<div class="clear"></div>';
  1556. echo '</div>'; // end of menu
  1557. echo '</div>'; // end of menu wrapper
  1558. //footer
  1559. Display :: display_footer();