user_portal.php 64 KB

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