user_portal.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682
  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. 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. * Enter description here...
  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. * Enter description here...
  504. *
  505. */
  506. function display_edit_course_list_links() {
  507. echo "<li><a href=\"main/auth/courses.php\">".get_lang('CourseManagement')."</a></li>";
  508. }
  509. /**
  510. * Show history sessions
  511. *
  512. */
  513. function display_history_course_session() {
  514. if (api_get_setting('use_session_mode')=='true') {
  515. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  516. echo "<li><a href=\"user_portal.php\">".get_lang('DisplayTrainingList')."</a></li>";
  517. } else {
  518. echo "<li><a href=\"user_portal.php?history=1\">".get_lang('HistoryTrainingSessions')."</a></li>";
  519. }
  520. }
  521. }
  522. /**
  523. * Displays a digest e.g. short summary of new agenda and announcements items.
  524. * This used to be displayed in the right hand menu, but is now
  525. * disabled by default (see config settings in this file) because most people like
  526. * the what's new icons better.
  527. *
  528. * @version 1.0
  529. */
  530. function display_digest($toolsList, $digest, $orderKey, $courses) {
  531. if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) {
  532. // // // LEVEL 1 // // //
  533. reset($digest);
  534. echo "<br /><br />\n";
  535. while (list($key1) = each($digest)) {
  536. if (is_array($digest[$key1])) {
  537. // // // Title of LEVEL 1 // // //
  538. echo "<strong>\n";
  539. if ($orderKey[0] == 'keyTools') {
  540. $tools = $key1;
  541. echo $toolsList[$key1]['name'];
  542. } elseif ($orderKey[0] == 'keyCourse') {
  543. $courseSysCode = $key1;
  544. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key1]['coursePath'], "\">", $courses[$key1]['courseCode'], "</a>\n";
  545. } elseif ($orderKey[0] == 'keyTime') {
  546. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($digest[$key1]));
  547. }
  548. echo "</strong>\n";
  549. // // // End Of Title of LEVEL 1 // // //
  550. // // // LEVEL 2 // // //
  551. reset($digest[$key1]);
  552. while (list ($key2) = each($digest[$key1])) {
  553. // // // Title of LEVEL 2 // // //
  554. echo "<p>\n", "\n";
  555. if ($orderKey[1] == 'keyTools') {
  556. $tools = $key2;
  557. echo $toolsList[$key2][name];
  558. } elseif ($orderKey[1] == 'keyCourse') {
  559. $courseSysCode = $key2;
  560. echo "<a href=\"", api_get_path(WEB_COURSE_PATH), $courses[$key2]['coursePath'], "\">", $courses[$key2]['courseCode'], "</a>\n";
  561. } elseif ($orderKey[1] == 'keyTime') {
  562. echo format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  563. }
  564. echo "\n";
  565. echo "</p>";
  566. // // // End Of Title of LEVEL 2 // // //
  567. // // // LEVEL 3 // // //
  568. reset($digest[$key1][$key2]);
  569. while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) {
  570. // // // Title of LEVEL 3 // // //
  571. if ($orderKey[2] == 'keyTools') {
  572. $level3title = "<a href=\"".$toolsList[$key3]["path"].$courseSysCode."\">".$toolsList[$key3]['name']."</a>";
  573. } elseif ($orderKey[2] == 'keyCourse') {
  574. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$key3."\">".$courses[$key3]['courseCode']."</a>\n";
  575. } elseif ($orderKey[2] == 'keyTime') {
  576. $level3title = "&#8226; <a href=\"".$toolsList[$tools]["path"].$courseSysCode."\">".format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3))."</a>";
  577. }
  578. // // // End Of Title of LEVEL 3 // // //
  579. // // // LEVEL 4 (data) // // //
  580. reset($digest[$key1][$key2][$key3]);
  581. while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) {
  582. echo $level3title, ' &ndash; ', api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT);
  583. //adding ... (three dots) if the texts are too large and they are shortened
  584. if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) {
  585. echo '...';
  586. }
  587. }
  588. echo "<br />\n";
  589. }
  590. }
  591. }
  592. }
  593. }
  594. } // end function display_digest
  595. /**
  596. * Display code for one specific course a logged in user is subscribed to.
  597. * Shows a link to the course, what's new icons...
  598. *
  599. * $my_course['d'] - course directory
  600. * $my_course['i'] - course title
  601. * $my_course['c'] - visual course code
  602. * $my_course['k'] - system course code
  603. * $my_course['db'] - course database
  604. *
  605. * @version 1.0.3
  606. * @todo refactor into different functions for database calls | logic | display
  607. * @todo replace single-character $my_course['d'] indices
  608. * @todo move code for what's new icons to a separate function to clear things up
  609. * @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.
  610. */
  611. function get_logged_user_course_html($course, $session_id = 0, $class='courses') {
  612. global $charset;
  613. global $nosession;
  614. $current_uid = api_get_user_id();
  615. $info = api_get_course_info($course['code']);
  616. $status_course = CourseManager::get_user_in_course_status($current_uid, $course['code']);
  617. if (!is_array($course['code'])) {
  618. $my_course = api_get_course_info($course['code']);
  619. $my_course['k'] = $my_course['id'];
  620. $my_course['db'] = $my_course['dbName'];
  621. $my_course['c'] = $my_course['official_code'];
  622. $my_course['i'] = $my_course['name'];
  623. $my_course['d'] = $my_course['path'];
  624. $my_course['t'] = $my_course['titular'];
  625. $my_course['id_session'] = $session_id;
  626. $my_course['status'] = ((empty($session_id))?$status_course:5);
  627. }
  628. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  629. global $now, $date_start, $date_end;
  630. }
  631. //initialise
  632. $result = '';
  633. // Table definitions
  634. //$statistic_database = Database::get_statistic_database();
  635. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  636. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  637. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  638. $course_database = $my_course['db'];
  639. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  640. $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  641. $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database);
  642. $user_id = api_get_user_id();
  643. $course_system_code = $my_course['k'];
  644. $course_visual_code = $my_course['c'];
  645. $course_title = $my_course['i'];
  646. $course_directory = $my_course['d'];
  647. $course_teacher = $my_course['t'];
  648. $course_teacher_email = isset($my_course['email'])?$my_course['email']:'';
  649. $course_info = Database :: get_course_info($course_system_code);
  650. $course_access_settings = CourseManager :: get_access_settings($course_system_code);
  651. $course_id = isset($course_info['course_id'])?$course_info['course_id']:null;
  652. $course_visibility = $course_access_settings['visibility'];
  653. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code);
  654. //function logic - act on the data
  655. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']);
  656. if ($is_virtual_course) {
  657. // If the current user is also subscribed in the real course to which this
  658. // virtual course is linked, we don't need to display the virtual course entry in
  659. // the course list - it is combined with the real course entry.
  660. $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code);
  661. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  662. if ($is_subscribed_in_target_course) {
  663. return; //do not display this course entry
  664. }
  665. }
  666. $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id());
  667. if ($has_virtual_courses) {
  668. $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info);
  669. $course_display_title = $return_result['title'];
  670. $course_display_code = $return_result['code'];
  671. } else {
  672. $course_display_title = $course_title;
  673. $course_display_code = $course_visual_code;
  674. }
  675. $s_course_status = $my_course['status'];
  676. $is_coach = api_is_coach($my_course['id_session'],$course['code']);
  677. $s_htlm_status_icon = "";
  678. if ($s_course_status == 1) {
  679. $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'));
  680. }
  681. if ($s_course_status == 2 || ($is_coach && $s_course_status != 1)) {
  682. $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'));
  683. }
  684. if (($s_course_status == 5 && !$is_coach) || empty($s_course_status)) {
  685. $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'));
  686. }
  687. //display course entry
  688. $result.="\n\t";
  689. $result .= '<li class="'.$class.'"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
  690. //show a hyperlink to the course, unless the course is closed and user is not course admin
  691. if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
  692. if(api_get_setting('use_session_mode')=='true' && !$nosession) {
  693. if(empty($my_course['id_session'])) {
  694. $my_course['id_session'] = 0;
  695. }
  696. if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') {
  697. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$my_course['id_session'].'">'.$course_display_title.'</a>';
  698. }
  699. } else {
  700. $result .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_directory.'/">'.$course_display_title.'</a>';
  701. }
  702. } else {
  703. $result .= $course_display_title." "." ".get_lang('CourseClosed')."";
  704. }
  705. if (api_is_allowed_to_edit(null, true)) {
  706. $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>';
  707. } else {
  708. $progress_thematic_icon = get_thematic_progress_icon($course_database, $session_id);
  709. }
  710. $result .= '&nbsp;&nbsp;<span>'.$progress_thematic_icon.'</span>';
  711. // show the course_code and teacher if chosen to display this
  712. if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
  713. $result .= '<br />';
  714. }
  715. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  716. $result .= $course_display_code;
  717. }
  718. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  719. $result .= ' &ndash; ';
  720. }
  721. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  722. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  723. $coachs_course = api_get_coachs_from_course($my_course['id_session'],$course['code']);
  724. $course_coachs = array();
  725. if (is_array($coachs_course)) {
  726. foreach ($coachs_course as $coach_course) {
  727. $course_coachs[] = api_get_person_name($coach_course['firstname'], $coach_course['lastname']);
  728. }
  729. }
  730. if ($s_course_status == 1 || ($s_course_status == 5 && empty($my_course['id_session'])) || empty($s_course_status)) {
  731. $result .= $course_teacher;
  732. }
  733. if (($s_course_status == 5 && !empty($my_course['id_session'])) || ($is_coach && $s_course_status != 1)) {
  734. $result .= get_lang('Coachs').': '.implode(', ',$course_coachs);
  735. }
  736. } else {
  737. $result .= $course_teacher;
  738. }
  739. if(!empty($course_teacher_email)) {
  740. $result .= ' ('.$course_teacher_email.')';
  741. }
  742. }
  743. $result .= (isset($course['special_course']))? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
  744. $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  745. // display the what's new icons
  746. $result .= show_notification($my_course);
  747. if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) {
  748. reset($digest);
  749. $result .= '
  750. <ul>';
  751. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  752. $result .= '<li>';
  753. if ($orderKey[1] == 'keyTools') {
  754. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  755. $result .= "$toolsList[$key2][\"name\"]</a>";
  756. } else {
  757. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2));
  758. }
  759. $result .= '</li>';
  760. $result .= '<ul>';
  761. reset ($digest[$thisCourseSysCode][$key2]);
  762. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  763. $result .= '<li>';
  764. if ($orderKey[2] == 'keyTools') {
  765. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  766. $result .= "$toolsList[$key3][\"name\"]</a>";
  767. } else {
  768. $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3));
  769. }
  770. $result .= '<ul compact="compact">';
  771. reset($digest[$thisCourseSysCode][$key2][$key3]);
  772. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  773. $result .= '<li>';
  774. $result .= htmlspecialchars(api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  775. $result .= '</li>';
  776. }
  777. $result .= '</ul>';
  778. $result .= '</li>';
  779. }
  780. $result .= '</ul>';
  781. $result .= '</li>';
  782. }
  783. $result .= '</ul>';
  784. }
  785. $result .= '</li>';
  786. if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
  787. $session = '';
  788. $active = false;
  789. if (!empty($my_course['session_name'])) {
  790. // Request for the name of the general coach
  791. $sql = 'SELECT lastname, firstname,sc.name
  792. FROM '.$tbl_session.' ts
  793. LEFT JOIN '.$main_user_table .' tu
  794. ON ts.id_coach = tu.user_id
  795. INNER JOIN '.$tbl_session_category.' sc ON ts.session_category_id = sc.id
  796. WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1';
  797. $rs = Database::query($sql);
  798. $sessioncoach = Database::store_result($rs);
  799. $sessioncoach = $sessioncoach[0];
  800. $session = array();
  801. $session['title'] = $my_course['session_name'];
  802. $session_category_id = CourseManager::get_session_category_id_by_session_id($my_course['id_session']);
  803. $session['category'] = $sessioncoach['name'];
  804. if ( $my_course['date_start']=='0000-00-00' ) {
  805. $session['dates'] = get_lang('WithoutTimeLimits');
  806. if (api_get_setting('show_session_coach') === 'true') {
  807. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  808. }
  809. $active = true;
  810. } else {
  811. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  812. if (api_get_setting('show_session_coach') === 'true') {
  813. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  814. }
  815. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  816. }
  817. }
  818. $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active,'session_category_id'=>$session_category_id);
  819. } else {
  820. $output = array ($my_course['user_course_cat'], $result);
  821. }
  822. return $output;
  823. }
  824. /**
  825. * Get the session box details as an array
  826. * @param int Session ID
  827. * @return array Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int]
  828. */
  829. function get_session_title_box($session_id) {
  830. global $nosession;
  831. $output = array();
  832. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  833. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  834. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  835. $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  836. $active = false;
  837. // Request for the name of the general coach
  838. $sql =
  839. 'SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
  840. FROM '.$tbl_session.' ts
  841. LEFT JOIN '.$main_user_table .' tu
  842. ON ts.id_coach = tu.user_id
  843. WHERE ts.id='.intval($session_id);
  844. $rs = Database::query($sql);
  845. $session_info = Database::store_result($rs);
  846. $session_info = $session_info[0];
  847. $session = array();
  848. $session['title'] = $session_info[2];
  849. $session['coach'] = '';
  850. if ( $session_info[3]=='0000-00-00' ) {
  851. $session['dates'] = get_lang('WithoutTimeLimits');
  852. if ( api_get_setting('show_session_coach') === 'true' ) {
  853. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  854. }
  855. $active = true;
  856. } else {
  857. $session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4];
  858. if ( api_get_setting('show_session_coach') === 'true' ) {
  859. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
  860. }
  861. $active = ($date_start <= $now && $date_end >= $now)?true:false;
  862. }
  863. $session['active'] = $active;
  864. $session['session_category_id'] = $session_info[5];
  865. $output = $session;
  866. }
  867. return $output;
  868. }
  869. /**
  870. * Display code for one specific course a logged in user is subscribed to.
  871. * Shows a link to the course, what's new icons...
  872. *
  873. * $my_course['d'] - course directory
  874. * $my_course['i'] - course title
  875. * $my_course['c'] - visual course code
  876. * $my_course['k'] - system course code
  877. * $my_course['db'] - course database
  878. *
  879. * @version 1.0.3
  880. * @todo refactor into different functions for database calls | logic | display
  881. * @todo replace single-character $my_course['d'] indices
  882. * @todo move code for what's new icons to a separate function to clear things up
  883. * @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.
  884. */
  885. function get_global_courses_list($user_id) {
  886. //1. get list of sessions the user is subscribed to
  887. //2. build an ordered list of session categories and sessions
  888. //3. fill this ordered list with course details
  889. global $charset;
  890. global $nosession;
  891. if (api_get_setting('use_session_mode')=='true' && !$nosession) {
  892. global $now, $date_start, $date_end;
  893. }
  894. $output = array();
  895. return $output;
  896. }
  897. /**
  898. * Returns the "what's new" icon notifications
  899. * @param array Course information array, containing at least elements 'db' and 'k'
  900. * @return string The HTML link to be shown next to the course
  901. * @version
  902. */
  903. function show_notification($my_course) {
  904. $statistic_database = Database :: get_statistic_database();
  905. $user_id = api_get_user_id();
  906. $course_database = $my_course['db'];
  907. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  908. $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database);
  909. $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database);
  910. $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  911. // get the user's last access dates to all tools of this course
  912. $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access
  913. USE INDEX (access_cours_code, access_user_id)
  914. WHERE access_cours_code = '".$my_course['k']."'
  915. AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'";
  916. $resLastTrackInCourse = Database::query($sqlLastTrackInCourse);
  917. $oldestTrackDate = "3000-01-01 00:00:00";
  918. while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) {
  919. $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date'];
  920. if ($oldestTrackDate > $lastTrackInCourse['access_date']) {
  921. $oldestTrackDate = $lastTrackInCourse['access_date'];
  922. }
  923. }
  924. // get the last edits of all tools of this course
  925. $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref,
  926. tet.lastedit_type type, tet.to_group_id group_id,
  927. ctt.image image, ctt.link link
  928. FROM $tool_edit_table tet, $course_tool_table ctt
  929. WHERE tet.lastedit_date > '$oldestTrackDate'
  930. AND ctt.name = tet.tool
  931. AND ctt.visibility = '1'
  932. AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."'
  933. ORDER BY tet.lastedit_date";
  934. $res = Database::query($sql);
  935. //get the group_id's with user membership
  936. $group_ids = GroupManager :: get_group_ids($course_database, $user_id);
  937. $group_ids[] = 0; //add group 'everyone'
  938. //filter all selected items
  939. while ($res && ($item_property = Database::fetch_array($res))) {
  940. if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date'])
  941. && ((in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)))
  942. && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset ($item_property['visibility']))) {
  943. 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;
  944. if ($item_property['tool'] == TOOL_SURVEY) {
  945. $survey_info = survey_manager::get_survey($item_property['ref'],0,$my_course['k']);
  946. $invited_users = SurveyUtil::get_invited_users($survey_info['code'],$course_database);
  947. if (!in_array($user_id,$invited_users['course_users'])) continue;
  948. }
  949. $notifications[$item_property['tool']] = $item_property;
  950. }
  951. }
  952. //show all tool icons where there is something new
  953. $retvalue = '&nbsp;';
  954. if (isset ($notifications)) {
  955. while (list ($key, $notification) = each($notifications)) {
  956. $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date']));
  957. $type = $notification['lastedit_type'];
  958. //$notification[image]=str_replace(".png","gif",$notification[image]);
  959. //$notification[image]=str_replace(".gif","_s.gif",$notification[image]);
  960. if(empty($my_course['id_session'])) {
  961. $my_course['id_session'] = 0;
  962. }
  963. $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;';
  964. }
  965. }
  966. return $retvalue;
  967. }
  968. /**
  969. * retrieves the user defined course categories
  970. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  971. * @return array containing all the titles of the user defined courses with the id as key of the array
  972. */
  973. function get_user_course_categories() {
  974. global $_user;
  975. $output = array();
  976. $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY);
  977. $sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'";
  978. $result = Database::query($sql);
  979. while ($row = Database::fetch_array($result)) {
  980. $output[$row['id']] = $row['title'];
  981. }
  982. return $output;
  983. }
  984. /*
  985. ==============================================================================
  986. MAIN CODE
  987. ==============================================================================
  988. */
  989. /*
  990. ==============================================================================
  991. PERSONAL COURSE LIST
  992. ==============================================================================
  993. */
  994. if (!isset ($maxValvas)) {
  995. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  996. }
  997. if (!isset ($maxAgenda)) {
  998. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  999. }
  1000. if (!isset ($maxCourse)) {
  1001. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  1002. }
  1003. $maxValvas = (int) $maxValvas;
  1004. $maxAgenda = (int) $maxAgenda;
  1005. $maxCourse = (int) $maxCourse; // 0 if invalid
  1006. if ($maxCourse > 0) {
  1007. unset ($allentries); // we shall collect all summary$key1 entries in here:
  1008. $toolsList['agenda']['name'] = get_lang('Agenda');
  1009. $toolsList['agenda']['path'] = api_get_path(WEB_CODE_PATH)."calendar/agenda.php?cidReq=";
  1010. $toolsList['valvas']['name'] = get_lang('Valvas');
  1011. $toolsList['valvas']['path'] = api_get_path(WEB_CODE_PATH)."announcements/announcements.php?cidReq=";
  1012. }
  1013. echo ' <div class="maincontent" id="maincontent">'; // start of content for logged in users
  1014. // Plugins for the my courses main area
  1015. api_plugin('mycourses_main');
  1016. /*
  1017. -----------------------------------------------------------------------------
  1018. System Announcements
  1019. -----------------------------------------------------------------------------
  1020. */
  1021. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  1022. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  1023. SystemAnnouncementManager :: display_announcements($visibility, $announcement);
  1024. if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
  1025. include ('./home/'.$_GET['include']);
  1026. $pageIncluded = true;
  1027. } else {
  1028. /*--------------------------------------
  1029. DISPLAY COURSES
  1030. --------------------------------------*/
  1031. // compose a structured array of session categories, sessions and courses
  1032. // for the current user
  1033. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1034. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true,true);
  1035. } else {
  1036. $courses_tree = UserManager::get_sessions_by_category($_user['user_id'],true);
  1037. }
  1038. foreach ($courses_tree as $cat => $sessions) {
  1039. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  1040. if ($cat == 0) {
  1041. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($_user['user_id'],false);
  1042. }
  1043. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  1044. if (count($courses_tree[$cat]['sessions'])>0) {
  1045. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  1046. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  1047. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($_user['user_id'],$s_id);
  1048. }
  1049. }
  1050. }
  1051. $list = '';
  1052. foreach ($personal_course_list as $my_course) {
  1053. $thisCourseDbName = $my_course['db'];
  1054. $thisCourseSysCode = $my_course['k'];
  1055. $thisCoursePublicCode = $my_course['c'];
  1056. $thisCoursePath = $my_course['d'];
  1057. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  1058. $dbname = $my_course['k'];
  1059. $status[$dbname] = $my_course['s'];
  1060. $nbDigestEntries = 0; // number of entries already collected
  1061. if ($maxCourse < $maxValvas) {
  1062. $maxValvas = $maxCourse;
  1063. }
  1064. if ($maxCourse > 0) {
  1065. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  1066. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  1067. }
  1068. /*
  1069. -----------------------------------------------------------
  1070. Announcements
  1071. -----------------------------------------------------------
  1072. */
  1073. $course_database = $my_course['db'];
  1074. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  1075. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  1076. $result = Database::query($query);
  1077. // collect from announcements, but only if tool is visible for the course
  1078. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  1079. //Search announcements table
  1080. //Take the entries listed at the top of advalvas/announcements tool
  1081. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  1082. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  1083. FROM ".$course_announcement_table;
  1084. switch (CONFVAL_limitPreviewTo) {
  1085. case SCRIPTVAL_NewEntriesOfTheDay :
  1086. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d")."'";
  1087. break;
  1088. case SCRIPTVAL_NoTimeLimit :
  1089. break;
  1090. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  1091. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  1092. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date("Y m d", $_user["lastLogin"])."'";
  1093. }
  1094. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  1095. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  1096. if ($resGetLastAnnouncements) {
  1097. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  1098. $keyTools = 'valvas';
  1099. $keyTime = $annoncement['publicationDate'];
  1100. $keyCourse = $thisCourseSysCode;
  1101. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($annoncement["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1102. $nbDigestEntries ++; // summary has same order as advalvas
  1103. }
  1104. }
  1105. }
  1106. /*
  1107. -----------------------------------------------------------
  1108. Agenda
  1109. -----------------------------------------------------------
  1110. */
  1111. $course_database = $my_course['db'];
  1112. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST,$course_database);
  1113. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  1114. $result = Database::query($query);
  1115. $thisAgenda = $maxCourse - $nbDigestEntries; // new max entries for agenda
  1116. if ($maxAgenda < $thisAgenda) {
  1117. $thisAgenda = $maxAgenda;
  1118. }
  1119. // collect from agenda, but only if tool is visible for the course
  1120. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  1121. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue']."calendar_event";
  1122. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  1123. FROM $tableCal
  1124. WHERE start_date >= CURDATE()
  1125. ORDER BY start_date, start_time
  1126. LIMIT $maxAgenda";
  1127. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  1128. if ($resGetNextAgendaEvent) {
  1129. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  1130. $keyTools = 'agenda';
  1131. $keyTime = $agendaEvent['start_date'];
  1132. $keyCourse = $thisCourseSysCode;
  1133. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = htmlspecialchars(api_substr(strip_tags($agendaEvent["content"]), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1134. $nbDigestEntries ++; // summary has same order as advalvas
  1135. }
  1136. }
  1137. }
  1138. /*
  1139. -----------------------------------------------------------
  1140. Digest Display
  1141. take collected data and display it
  1142. -----------------------------------------------------------
  1143. */
  1144. //$list[] = get_logged_user_course_html($my_course);
  1145. } //end while mycourse...
  1146. }
  1147. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  1148. echo '<h3>'.get_lang('HistoryTrainingSession').'</h3>';
  1149. if (empty($courses_tree[0]['sessions'])){
  1150. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  1151. }
  1152. }
  1153. if ( is_array($courses_tree) ) {
  1154. foreach ($courses_tree as $key => $category) {
  1155. if ($key == 0) {
  1156. // sessions and courses that are not in a session category
  1157. if (!isset($_GET['history'])) { // check if it's not history trainnign session list
  1158. display_special_courses(api_get_user_id());
  1159. display_courses(api_get_user_id());
  1160. }
  1161. //independent sessions
  1162. foreach ($category['sessions'] as $session) {
  1163. //don't show empty sessions
  1164. if (count($session['courses'])<1) { continue; }
  1165. //courses inside the current session
  1166. $date_session_start = $session['details']['date_start'];
  1167. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1168. $session_now = time();
  1169. $html_courses_session = '';
  1170. $count_courses_session = 0;
  1171. foreach ($session['courses'] as $course) {
  1172. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1173. if ($is_coach_course) {
  1174. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1175. } else {
  1176. $allowed_time = strtotime($date_session_start);
  1177. }
  1178. if ($session_now > $allowed_time) {
  1179. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1180. $html_courses_session .= $c[1];
  1181. $count_courses_session++;
  1182. }
  1183. }
  1184. if ($count_courses_session > 0) {
  1185. echo '<ul class="session_box">';
  1186. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  1187. echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1188. $s = get_session_title_box($session['details']['id']);
  1189. echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  1190. echo '</li>';
  1191. echo $html_courses_session;
  1192. echo '</ul>';
  1193. }
  1194. }
  1195. } else {
  1196. // all sessions included in
  1197. if (!empty($category['details'])) {
  1198. $count_courses_session = 0;
  1199. $html_sessions = '';
  1200. foreach ($category['sessions'] as $session) {
  1201. //don't show empty sessions
  1202. if (count($session['courses'])<1) { continue; }
  1203. $date_session_start = $session['details']['date_start'];
  1204. $days_access_before_beginning = ($session['details']['nb_days_access_before_beginning'])*24*3600;
  1205. $session_now = time();
  1206. $html_courses_session = '';
  1207. $count = 0;
  1208. foreach ($session['courses'] as $course) {
  1209. $is_coach_course = api_is_coach($session['details']['id'],$course['code']);
  1210. if ($is_coach_course) {
  1211. $allowed_time = (strtotime($date_session_start)-$days_access_before_beginning);
  1212. } else {
  1213. $allowed_time = strtotime($date_session_start);
  1214. }
  1215. if ($session_now > $allowed_time) {
  1216. $c = get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1217. $html_courses_session .= $c[1];
  1218. $count_courses_session++;
  1219. $count++;
  1220. }
  1221. }
  1222. if ($count > 0) {
  1223. $s = get_session_title_box($session['details']['id']);
  1224. $html_sessions .= '<ul class="session_box" id="session_'.$session['details']['id'].'">';
  1225. $html_sessions .= '<li class="session_box_title" id="session_'.$session['details']['id'].'">';
  1226. $html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1227. $html_sessions .= get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach'])?$s['coach'].' - ':'').$s['dates'];
  1228. $html_sessions .= '</li>';
  1229. $html_sessions .= $html_courses_session;
  1230. $html_sessions .= '</ul>';
  1231. }
  1232. }
  1233. if ($count_courses_session > 0) {
  1234. echo '<div class="session_category" id="session_category_'.$category['details']['id'].'" style="background-color:#fbfbfb; border:1px solid #dddddd; padding:5px; margin-top: 10px;">';
  1235. 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>';
  1236. echo $html_sessions;
  1237. echo '</div>';
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. /*
  1244. $userdefined_categories = get_user_course_categories();
  1245. if ( is_array($list) ) {
  1246. //Courses whithout sessions
  1247. $old_user_category = 0;
  1248. foreach ($list as $key => $value) {
  1249. if (empty($value[2])) { //if out of any session
  1250. $userdefined_categories = get_user_course_categories();
  1251. echo '<ul class="courseslist">';
  1252. if ($old_user_category<>$value[0]) {
  1253. if ($key <> 0 || $value[0] <> 0) {// there are courses in the previous category
  1254. echo "\n</ul>";
  1255. }
  1256. echo "\n\n\t<ul class=\"user_course_category\"><li>".$userdefined_categories[$value[0]]."</li></ul>\n";
  1257. if ($key<>0 OR $value[0]<>0){ // there are courses in the previous category
  1258. echo "<ul class=\"courseslist\">";
  1259. }
  1260. $old_user_category = $value[0];
  1261. }
  1262. echo $value[1];
  1263. echo "</ul>\n";
  1264. }
  1265. }
  1266. $listActives = $listInactives = $listCourses = array();
  1267. foreach ($list as $key => $value) {
  1268. if ($value['active']) { //if the session is still active (as told by get_logged_user_course_html())
  1269. $listActives[] = $value;
  1270. } else if (!empty($value[2])) { //if there is a session but it is not active
  1271. $listInactives[] = $value;
  1272. }
  1273. }
  1274. $old_user_category = 0;
  1275. $userdefined_categories = get_user_course_categories();
  1276. if (count($listActives) > 0 && $display_actives) {
  1277. echo "<ul class=\"courseslist\">\n";
  1278. $name_category = array();
  1279. $i = 0;
  1280. $j=0;
  1281. foreach ($listActives as $key => $value) {
  1282. $session_category_id=$value['session_category_id'];
  1283. if (!empty($value[3]['category'])) {
  1284. if (!in_array($value[3]['category'], $name_category)) {
  1285. if ($key != 0) {
  1286. echo '</ul>';
  1287. }
  1288. //Category
  1289. $name_category['name'] = $value[3]['category'];
  1290. echo '<ul class="category_box" id="category_box_'.$session_category_id.'">' .
  1291. '<li class="category_box_title" id="category_box_title_'.$session_category_id.'">'.$name_category['name'].'</li>';
  1292. echo "</ul>\n";
  1293. }
  1294. }
  1295. if (!empty($value[2])) {
  1296. if ((isset($old_session) && $old_session != $value[2]) or ((!isset($old_session)) && isset($value[2]))) {
  1297. $old_session = $value[2];
  1298. if ($key != 0) {
  1299. echo '</ul>';
  1300. }
  1301. //Session
  1302. echo '<ul style="display:none" class="session_box_'.$session_category_id.'" >' .
  1303. '<li class="session_box_title" >'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1304. if ( !empty($value[3]['coach']) ) {
  1305. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1306. }
  1307. echo "</ul>\n";
  1308. echo '<ul class="session_course_item" id="session_course_item_'.$i.'">';
  1309. }
  1310. }
  1311. //Courses
  1312. echo $value[1];
  1313. $i++;
  1314. }
  1315. echo "\n</ul><br /><br />\n";
  1316. }
  1317. if (count($listInactives) > 0 && !$display_actives) {
  1318. echo '<ul class="sessions_list_inactive">';
  1319. foreach ($listInactives as $key => $value) {
  1320. if (!empty($value[2])) {
  1321. if ($old_session != $value[2]) {
  1322. $old_session = $value[2];
  1323. if ($key != 0) {
  1324. echo '</ul>';
  1325. }
  1326. echo '<ul class="session_box">' .
  1327. '<li class="session_box_title">'.$value[3]['title'].' '.$value[3]['dates'].'</li>';
  1328. if (!empty($value[3]['coach'])) {
  1329. echo '<li class="session_box_coach">'.$value[3]['coach'].'</li>';
  1330. }
  1331. echo "</ul>\n";
  1332. echo '<ul>';
  1333. }
  1334. }
  1335. echo $value[1];
  1336. }
  1337. echo "\n</ul><br /><br />\n";
  1338. }
  1339. }
  1340. */
  1341. echo '</div>'; // end of content section
  1342. // Register whether full admin or null admin course
  1343. // by course through an array dbname x user status
  1344. api_session_register('status');
  1345. /*
  1346. ==============================================================================
  1347. RIGHT MENU
  1348. ==============================================================================
  1349. */
  1350. echo ' <div id="menu" class="menu">';
  1351. // api_display_language_form(); // moved to the profile page.
  1352. $show_menu = false;
  1353. $show_create_link = false;
  1354. $show_course_link = false;
  1355. $show_digest_link = false;
  1356. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  1357. if ($display_add_course_link) {
  1358. $show_menu = true;
  1359. $show_create_link = true;
  1360. }
  1361. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  1362. $show_menu = true;
  1363. $show_course_link = true;
  1364. } else {
  1365. if (api_get_setting('allow_students_to_browse_courses')=='true') {
  1366. $show_menu = true;
  1367. $show_course_link = true;
  1368. }
  1369. }
  1370. if (isset($toolsList) and is_array($toolsList) and isset($digest)) {
  1371. $show_digest_link = true;
  1372. $show_menu = true;
  1373. }
  1374. echo '<div class="menusection">';
  1375. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  1376. //user image
  1377. // @todo add a platform setting to add the user image
  1378. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool') == 'true') {
  1379. $img_array= UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',true,true);
  1380. $no_image =false;
  1381. if ($img_array['file'] == 'unknown.jpg') {
  1382. $no_image =true;
  1383. }
  1384. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  1385. echo '<div class="clear"></div>';
  1386. echo '<div id="social_widget" >';
  1387. echo ' <div id="social_widget_image">';
  1388. if ($no_image == false) {
  1389. echo '<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  1390. } else {
  1391. 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>';
  1392. }
  1393. echo '</div>';
  1394. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  1395. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  1396. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  1397. // New messages
  1398. $number_of_new_messages = MessageManager::get_new_messages();
  1399. // New contact invitations
  1400. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  1401. // New group invitations sent by a moderator
  1402. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION,false);
  1403. $group_pending_invitations = count($group_pending_invitations);
  1404. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  1405. $cant_msg = '';
  1406. if ($number_of_new_messages > 0) {
  1407. $cant_msg = ' ('.$number_of_new_messages.')';
  1408. }
  1409. //<h2 class="message-title">'.get_lang('Messages').'</h2>
  1410. echo '<div class="clear"></div>';
  1411. echo '<div class="message-content"> <p>';
  1412. $link = '';
  1413. if (api_get_setting('show_tabs', 'social') == 'true') {
  1414. $link = '?f=social';
  1415. }
  1416. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a><br />';
  1417. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a><br />';
  1418. //echo '<a href="'.api_get_path(WEB_PATH).'main/auth/profile.php" class="message-body">'.get_lang('EditMyProfile').' </a><br />';
  1419. if ($total_invitations > 0) {
  1420. echo '<a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' ('.$total_invitations.') </a><br />';
  1421. }
  1422. echo '</p>';
  1423. echo '</div>';
  1424. echo '</div><div class="clear"></div>';
  1425. }
  1426. // My account section
  1427. if ($show_menu) {
  1428. echo '<ul class="menulist">';
  1429. if ($show_create_link) {
  1430. display_create_course_link();
  1431. }
  1432. if ($show_course_link) {
  1433. display_edit_course_list_links();
  1434. display_history_course_session();
  1435. }
  1436. if ($show_digest_link) {
  1437. display_digest($toolsList, $digest, $orderKey, $courses);
  1438. }
  1439. echo '</ul>';
  1440. }
  1441. echo '</div>'; //close menusection
  1442. //deleting the myprofile link
  1443. if (api_get_setting('allow_social_tool') == true) {
  1444. unset($menu_navigation['myprofile']);
  1445. }
  1446. // Main navigation section
  1447. // tabs that are deactivated are added here
  1448. if (!empty($menu_navigation)) {
  1449. echo '<div class="menusection">';
  1450. echo '<span class="menusectioncaption">'.get_lang('MainNavigation').'</span>';
  1451. echo '<ul class="menulist">';
  1452. foreach ($menu_navigation as $section => $navigation_info) {
  1453. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  1454. echo '<li'.$current.'>';
  1455. echo '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  1456. echo '</li>';
  1457. echo "\n";
  1458. }
  1459. echo '</ul>';
  1460. echo '</div>';
  1461. }
  1462. // plugins for the my courses menu
  1463. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  1464. echo '<div class="note">';
  1465. api_plugin('mycourses_menu');
  1466. echo '</div>';
  1467. }
  1468. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course() ){
  1469. echo '<div class="menusection">';
  1470. echo '<span class="menusectioncaption">'.get_lang('Booking').'</span>';
  1471. echo '<ul class="menulist">';
  1472. echo '<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  1473. echo '</ul>';
  1474. echo '</div>';
  1475. }
  1476. // search textbox
  1477. if (api_get_setting('search_enabled') == 'true') {
  1478. echo '<div class="searchbox">';
  1479. $search_btn = get_lang('Search');
  1480. $search_text_default = get_lang('YourTextHere');
  1481. echo <<<EOD
  1482. <br />
  1483. <form action="main/search/" method="post">
  1484. &nbsp;&nbsp;<input type="text" id="query" size="15" name="query" value="" />
  1485. &nbsp;&nbsp;<button class="save" type="submit" name="submit" value="$search_btn"/>$search_btn </button>
  1486. </form>
  1487. EOD;
  1488. echo '</div>';
  1489. }
  1490. echo '</div>'; // end of menu
  1491. //footer
  1492. Display :: display_footer();