user_portal.php 68 KB

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