user_portal.php 73 KB

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