user_portal.php 68 KB

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