user_portal.php 71 KB

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