user_portal.php 83 KB

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