user_portal.php 73 KB

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