userportal.lib.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
  4. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  5. require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php';
  6. class IndexManager {
  7. var $tpl = false; //An instance of the template engine
  8. var $name = '';
  9. var $home = '';
  10. var $default_home = 'home/';
  11. function __construct($title, $load_template = true) {
  12. if ($load_template) {
  13. $this->tpl = new Template($title);
  14. }
  15. $this->home = api_get_home_path();
  16. $this->user_id = api_get_user_id();
  17. $this->load_directories_preview = false;
  18. if (api_get_setting('show_documents_preview') == 'true') {
  19. $this->load_directories_preview = true;
  20. }
  21. }
  22. function set_login_form() {
  23. global $loginFailed;
  24. $login_form = '';
  25. if (!($this->user_id) || api_is_anonymous($this->user_id)) {
  26. // Only display if the user isn't logged in.
  27. $this->tpl->assign('login_language_form', api_display_language_form(true));
  28. $this->tpl->assign('login_form', self::display_login_form());
  29. if ($loginFailed) {
  30. $this->tpl->assign('login_failed', self::handle_login_failed());
  31. }
  32. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  33. $login_form .= '<ul class="menulist">';
  34. if (api_get_setting('allow_registration') != 'false') {
  35. $login_form .= '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  36. }
  37. if (api_get_setting('allow_lostpassword') == 'true') {
  38. $login_form .= '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  39. }
  40. $login_form .= '</ul>';
  41. }
  42. $this->tpl->assign('login_options', $login_form);
  43. if (api_number_of_plugins('loginpage_menu') > 0) {
  44. $login_form = '<div class="note" style="background: none">';
  45. ob_start();
  46. api_plugin('loginpage_menu');
  47. $plugin_login = ob_get_contents();
  48. $login_form .= $plugin_login;
  49. $login_form .= '</div>';
  50. $this->tpl->assign('login_plugin_menu', $login_form);
  51. }
  52. }
  53. }
  54. function return_exercise_block($personal_course_list) {
  55. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  56. $exercise_list = array();
  57. if (!empty($personal_course_list)) {
  58. foreach($personal_course_list as $course_item) {
  59. $course_code = $course_item['c'];
  60. $session_id = $course_item['id_session'];
  61. $exercises = get_exercises_to_be_taken($course_code, $session_id);
  62. foreach($exercises as $exercise_item) {
  63. $exercise_item['course_code'] = $course_code;
  64. $exercise_item['session_id'] = $session_id;
  65. $exercise_item['tms'] = api_strtotime($exercise_item['end_time']);
  66. $exercise_list[] = $exercise_item;
  67. }
  68. }
  69. if (!empty($exercise_list)) {
  70. $exercise_list = msort($exercise_list, 'tms');
  71. $my_exercise = $exercise_list[0];
  72. $url = Display::url($my_exercise['title'], api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id']);
  73. $this->tpl->assign('exercise_url', $url);
  74. $this->tpl->assign('exercise_end_date', api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT));
  75. }
  76. }
  77. }
  78. function return_announcements($show_slide = true) {
  79. // Display System announcements
  80. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  81. $announcement = intval($announcement);
  82. if (isset($_user['user_id'])) {
  83. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  84. if ($show_slide) {
  85. $announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  86. } else {
  87. $announcements = SystemAnnouncementManager :: display_all_announcements($visibility, $announcement);
  88. }
  89. } else {
  90. if ($show_slide) {
  91. $announcements = SystemAnnouncementManager :: display_announcements_slider(VISIBLE_GUEST, $announcement);
  92. } else {
  93. $announcements = SystemAnnouncementManager :: display_all_announcements(VISIBLE_GUEST, $announcement);
  94. }
  95. }
  96. return $announcements;
  97. }
  98. /**
  99. * This function handles the logout and is called whenever there is a $_GET['logout']
  100. *
  101. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  102. */
  103. function logout() {
  104. global $_configuration, $extAuthSource;
  105. // Variable initialisation.
  106. $query_string = '';
  107. if (!empty($_SESSION['user_language_choice'])) {
  108. $query_string = '?language='.$_SESSION['user_language_choice'];
  109. }
  110. // Database table definition.
  111. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  112. // Selecting the last login of the user.
  113. $uid = $this->user_id;
  114. $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1";
  115. $q_last_connection = Database::query($sql_last_connection);
  116. if (Database::num_rows($q_last_connection) > 0) {
  117. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  118. }
  119. if (!isset($_SESSION['login_as'])) {
  120. $current_date = date('Y-m-d H:i:s', time());
  121. $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'";
  122. Database::query($s_sql_update_logout_date);
  123. }
  124. LoginDelete($uid); // From inc/lib/online.inc.php - removes the "online" status.
  125. // The following code enables the use of an external logout function.
  126. // Example: define a $extAuthSource['ldap']['logout'] = 'file.php' in configuration.php.
  127. // Then a function called ldap_logout() inside that file
  128. // (using *authent_name*_logout as the function name) and the following code
  129. // will find and execute it.
  130. $uinfo = api_get_user_info($uid);
  131. if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) {
  132. if (is_array($extAuthSource[$uinfo['auth_source']])) {
  133. $subarray = $extAuthSource[$uinfo['auth_source']];
  134. if (!empty($subarray['logout']) && file_exists($subarray['logout'])) {
  135. include_once ($subarray['logout']);
  136. $logout_function = $uinfo['auth_source'].'_logout';
  137. if (function_exists($logout_function)) {
  138. $logout_function($uinfo);
  139. }
  140. }
  141. }
  142. }
  143. exit_of_chat($uid);
  144. api_session_destroy();
  145. header("Location: index.php$query_string");
  146. exit();
  147. }
  148. /**
  149. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  150. *
  151. * @param unknown_type $category
  152. * @return boolean
  153. */
  154. function category_has_open_courses($category) {
  155. global $setting_show_also_closed_courses;
  156. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  157. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  158. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  159. $sql_result = Database::query($sql_query);
  160. while ($course = Database::fetch_array($sql_result)) {
  161. if (!$setting_show_also_closed_courses) {
  162. if ((api_get_user_id() > 0
  163. && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  164. || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  165. return true; //at least one open course
  166. }
  167. } else {
  168. if (isset($course['visibility'])) {
  169. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  170. }
  171. }
  172. }
  173. return false;
  174. }
  175. /**
  176. * Displays the right-hand menu for anonymous users:
  177. * login form, useful links, help section
  178. * Warning: function defines globals
  179. * @version 1.0.1
  180. * @todo does $_plugins need to be global?
  181. */
  182. function display_anonymous_right_menu() {
  183. global $loginFailed, $_plugins, $_user, $menu_navigation;
  184. $platformLanguage = api_get_setting('platformLanguage');
  185. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  186. $current_user_id = api_get_user_id();
  187. echo self::set_login_form(false);
  188. echo self::return_teacher_link();
  189. echo self::return_notice();
  190. //Plugin
  191. echo self::return_plugin_campushomepage();
  192. }
  193. function return_teacher_link() {
  194. $html = '';
  195. if (!empty($this->user_id)) {
  196. // tabs that are deactivated are added here
  197. $show_menu = false;
  198. $show_create_link = false;
  199. $show_course_link = false;
  200. if ($display_add_course_link) {
  201. $show_menu = true;
  202. $show_create_link = true;
  203. }
  204. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  205. $show_menu = true;
  206. $show_course_link = true;
  207. } else {
  208. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  209. $show_menu = true;
  210. $show_course_link = true;
  211. }
  212. }
  213. if ($show_menu && ($show_create_link || $show_course_link )) {
  214. $show_menu = true;
  215. } else {
  216. $show_menu = false;
  217. }
  218. }
  219. // My Account section
  220. if ($show_menu) {
  221. $html .= '<ul class="menulist">';
  222. if ($show_create_link) {
  223. $html .= '<li><a href="main/create_course/add_course.php">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  224. }
  225. if ($show_course_link) {
  226. if (!api_is_drh() && !api_is_session_admin()) {
  227. $html .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  228. } else {
  229. $html .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  230. }
  231. }
  232. $html .= '</ul>';
  233. }
  234. if (!empty($html)) {
  235. $html = self::show_right_block(get_lang('MenuUser'), $html);
  236. }
  237. return $html;
  238. }
  239. function return_home_page() {
  240. // Including the page for the news
  241. $html = '';
  242. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  243. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$this->home.$_GET['include']);
  244. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  245. } else {
  246. if (!empty($_SESSION['user_language_choice'])) {
  247. $user_selected_language = $_SESSION['user_language_choice'];
  248. } elseif (!empty($_SESSION['_user']['language'])) {
  249. $user_selected_language = $_SESSION['_user']['language'];
  250. } else {
  251. $user_selected_language = api_get_setting('platformLanguage');
  252. }
  253. if (!file_exists($this->home.'home_news_'.$user_selected_language.'.html')) {
  254. if (file_exists($this->home.'home_top.html')) {
  255. $home_top_temp = file($this->home.'home_top.html');
  256. } else {
  257. $home_top_temp = file($this->default_home.'home_top.html');
  258. }
  259. $home_top_temp = implode('', $home_top_temp);
  260. } else {
  261. if (file_exists($this->home.'home_top_'.$user_selected_language.'.html')) {
  262. $home_top_temp = file_get_contents($this->home.'home_top_'.$user_selected_language.'.html');
  263. } else {
  264. $home_top_temp = file_get_contents($this->home.'home_top.html');
  265. }
  266. }
  267. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  268. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  269. }
  270. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  271. $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  272. }
  273. return $html;
  274. }
  275. function return_notice() {
  276. $sys_path = api_get_path(SYS_PATH);
  277. $user_selected_language = api_get_interface_language();
  278. $html = '';
  279. // Notice
  280. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice_'.$user_selected_language.'.html');
  281. if (empty($home_notice)) {
  282. $home_notice = @(string)file_get_contents($sys_path.$this->home.'home_notice.html');
  283. }
  284. if (!empty($home_notice)) {
  285. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  286. echo self::show_right_block('', $home_notice, 'note');
  287. }
  288. if (isset($_SESSION['_user']['user_id']) && $_SESSION['_user']['user_id'] != 0) {
  289. // Deleting the myprofile link.
  290. if (api_get_setting('allow_social_tool') == 'true') {
  291. unset($menu_navigation['myprofile']);
  292. }
  293. if (!empty($menu_navigation)) {
  294. $content = '<ul class="menulist">';
  295. foreach ($menu_navigation as $section => $navigation_info) {
  296. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  297. $content .='<li'.$current.'><a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a></li>';
  298. }
  299. $content .= '</ul>';
  300. $html .= self::show_right_block(get_lang('MainNavigation'), $content);
  301. }
  302. }
  303. // Help section.
  304. /* Hide right menu "general" and other parts on anonymous right menu. */
  305. if (!isset($user_selected_language)) {
  306. $user_selected_language = $platformLanguage;
  307. }
  308. $home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
  309. if (!empty($home_menu)) {
  310. $home_menu_content .= '<ul class="menulist">';
  311. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  312. $home_menu_content .= '</ul>';
  313. $html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content);
  314. }
  315. return $html;
  316. }
  317. function return_plugin_campushomepage() {
  318. $html = '';
  319. if (api_get_user_id() && api_number_of_plugins('campushomepage_menu') > 0) {
  320. ob_start();
  321. api_plugin('campushomepage_menu');
  322. $plugin_content = ob_get_contents();
  323. ob_end_clean();
  324. $html = self::show_right_block('', $plugin_content);
  325. }
  326. return $html;
  327. }
  328. function return_skills_links() {
  329. $content = '<ul class="menulist">';
  330. $content .= Display::tag('li', Display::url(get_lang('MySkills'), api_get_path(WEB_CODE_PATH).'social/skills_tree.php'));
  331. $content .= '</ul>';
  332. $html = self::show_right_block(get_lang("Skills"), $content);
  333. return $html;
  334. }
  335. /**
  336. * Reacts on a failed login:
  337. * Displays an explanation with a link to the registration form.
  338. *
  339. * @version 1.0.1
  340. */
  341. function handle_login_failed() {
  342. if (!isset($_GET['error'])) {
  343. $message = get_lang('InvalidId');
  344. if (api_is_self_registration_allowed()) {
  345. $message = get_lang('InvalidForSelfRegistration');
  346. }
  347. } else {
  348. switch ($_GET['error']) {
  349. case '':
  350. $message = get_lang('InvalidId');
  351. if (api_is_self_registration_allowed()) {
  352. $message = get_lang('InvalidForSelfRegistration');
  353. }
  354. break;
  355. case 'account_expired':
  356. $message = get_lang('AccountExpired');
  357. break;
  358. case 'account_inactive':
  359. $message = get_lang('AccountInactive');
  360. break;
  361. case 'user_password_incorrect':
  362. $message = get_lang('InvalidId');
  363. break;
  364. case 'access_url_inactive':
  365. $message = get_lang('AccountURLInactive');
  366. break;
  367. }
  368. }
  369. return '<div id="login_fail">'.$message.'</div>';
  370. }
  371. /**
  372. * Display list of courses in a category.
  373. * (for anonymous users)
  374. *
  375. * @version 1.1
  376. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  377. */
  378. function display_anonymous_course_list() {
  379. $ctok = $_SESSION['sec_token'];
  380. $stok = Security::get_token();
  381. // Initialization.
  382. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  383. $web_course_path = api_get_path(WEB_COURSE_PATH);
  384. $category = Database::escape_string($_GET['category']);
  385. global $setting_show_also_closed_courses;
  386. // Database table definitions.
  387. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  388. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  389. $platformLanguage = api_get_setting('platformLanguage');
  390. // Get list of courses in category $category.
  391. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  392. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  393. ORDER BY title, UPPER(visual_code)";
  394. // Showing only the courses of the current access_url_id.
  395. global $_configuration;
  396. if ($_configuration['multiple_access_urls']) {
  397. $url_access_id = api_get_current_access_url_id();
  398. if ($url_access_id != -1) {
  399. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  400. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  401. ON (url_rel_course.course_code=course.code)
  402. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  403. }
  404. }
  405. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  406. $sql_result_courses = Database::query($sql_get_course_list);
  407. while ($course_result = Database::fetch_array($sql_result_courses)) {
  408. $course_list[] = $course_result;
  409. }
  410. $platform_visible_courses = '';
  411. // $setting_show_also_closed_courses
  412. if ($user_identified) {
  413. if ($setting_show_also_closed_courses) {
  414. $platform_visible_courses = '';
  415. } else {
  416. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  417. }
  418. } else {
  419. if ($setting_show_also_closed_courses) {
  420. $platform_visible_courses = '';
  421. } else {
  422. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  423. }
  424. }
  425. $sqlGetSubCatList = "
  426. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  427. FROM $main_category_table t1
  428. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  429. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  430. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  431. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  432. // Showing only the category of courses of the current access_url_id.
  433. global $_configuration;
  434. if ($_configuration['multiple_access_urls']) {
  435. $url_access_id = api_get_current_access_url_id();
  436. if ($url_access_id != -1) {
  437. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  438. $sqlGetSubCatList = "
  439. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  440. FROM $main_category_table t1
  441. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  442. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  443. INNER JOIN $tbl_url_rel_course as url_rel_course
  444. ON (url_rel_course.course_code=t3.code)
  445. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  446. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  447. }
  448. }
  449. $resCats = Database::query($sqlGetSubCatList);
  450. $thereIsSubCat = false;
  451. if (Database::num_rows($resCats) > 0) {
  452. $htmlListCat = '<h4 style="margin-top: 0px;">'.get_lang('CatList').'</h4><ul>';
  453. while ($catLine = Database::fetch_array($resCats)) {
  454. if ($catLine['code'] != $category) {
  455. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  456. if ($category_has_open_courses) {
  457. // The category contains courses accessible to anonymous visitors.
  458. $htmlListCat .= '<li>';
  459. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  460. if (api_get_setting('show_number_of_courses') == 'true') {
  461. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  462. }
  463. $htmlListCat .= "</li>\n";
  464. $thereIsSubCat = true;
  465. } elseif ($catLine['children_count'] > 0) {
  466. // The category has children, subcategories.
  467. $htmlListCat .= '<li>';
  468. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  469. $htmlListCat .= "</li>\n";
  470. $thereIsSubCat = true;
  471. }
  472. /* End changed code to eliminate the (0 courses) after empty categories. */
  473. elseif (api_get_setting('show_empty_course_categories') == 'true') {
  474. $htmlListCat .= '<li>';
  475. $htmlListCat .= $catLine['name'];
  476. $htmlListCat .= "</li>\n";
  477. $thereIsSubCat = true;
  478. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  479. } else {
  480. $htmlTitre = '<p>';
  481. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  482. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  483. }
  484. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  485. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  486. }
  487. $htmlTitre .= "</p>\n";
  488. if ($category != "" && !is_null($catLine['code'])) {
  489. $htmlTitre .= '<h3>'.$catLine['name']."</h3>\n";
  490. } else {
  491. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>\n";
  492. }
  493. }
  494. }
  495. $htmlListCat .= "</ul>";
  496. }
  497. echo $htmlTitre;
  498. if ($thereIsSubCat) {
  499. echo $htmlListCat;
  500. }
  501. while ($categoryName = Database::fetch_array($resCats)) {
  502. echo '<h3>', $categoryName['name'], "</h3>\n";
  503. }
  504. $numrows = Database::num_rows($sql_result_courses);
  505. $courses_list_string = '';
  506. $courses_shown = 0;
  507. if ($numrows > 0) {
  508. if ($thereIsSubCat) {
  509. $courses_list_string .= "<hr size=\"1\" noshade=\"noshade\">\n";
  510. }
  511. $courses_list_string .= '<h4 style="margin-top: 0px;">'.get_lang('CourseList')."</h4>\n<ul>\n";
  512. if (api_get_user_id()) {
  513. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  514. }
  515. foreach ($course_list as $course) {
  516. // $setting_show_also_closed_courses
  517. if (!$setting_show_also_closed_courses) {
  518. // If we do not show the closed courses
  519. // we only show the courses that are open to the world (to everybody)
  520. // and the courses that are open to the platform (if the current user is a registered user.
  521. if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  522. $courses_shown++;
  523. $courses_list_string .= "<li>\n";
  524. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  525. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  526. $courses_list_string .= $course['visual_code'];
  527. }
  528. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  529. $courses_list_string .= ' - ';
  530. }
  531. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  532. $courses_list_string .= $course['tutor_name'];
  533. }
  534. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  535. $courses_list_string .= ' - '.$course['course_language'];
  536. }
  537. $courses_list_string .= "</li>\n";
  538. }
  539. }
  540. // We DO show the closed courses.
  541. // The course is accessible if (link to the course homepage):
  542. // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD);
  543. // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM);
  544. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  545. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  546. // 5. the user is the platform admin api_is_platform_admin().
  547. //
  548. else {
  549. $courses_shown++;
  550. $courses_list_string .= "<li>\n";
  551. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  552. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  553. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  554. || $courses_of_user[$course['code']]['status'] == '1'
  555. || api_is_platform_admin()) {
  556. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  557. }
  558. $courses_list_string .= $course['title'];
  559. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  560. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  561. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  562. || $courses_of_user[$course['code']]['status'] == '1'
  563. || api_is_platform_admin()) {
  564. $courses_list_string .= '</a><br />';
  565. }
  566. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  567. $courses_list_string .= ' '.$course['visual_code'];
  568. }
  569. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  570. $courses_list_string .= ' - ';
  571. }
  572. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  573. $courses_list_string .= $course['tutor_name'];
  574. }
  575. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  576. $courses_list_string .= ' - '.$course['course_language'];
  577. }
  578. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  579. $courses_list_string .= ' - '.$course['course_language'];
  580. }
  581. // We display a subscription link if:
  582. // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied
  583. // 2.
  584. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  585. if ($course['subscribe'] == '1') {
  586. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  587. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  588. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  589. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  590. } else {
  591. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  592. }
  593. }
  594. $courses_list_string .= "</li>";
  595. }
  596. }
  597. $courses_list_string .= "</ul>";
  598. } else {
  599. //echo '<blockquote>', get_lang('_No_course_publicly_available'), "</blockquote>\n";
  600. }
  601. if ($courses_shown > 0) {
  602. // Only display the list of courses and categories if there was more than
  603. // 0 courses visible to the world (we're in the anonymous list here).
  604. echo $courses_list_string;
  605. }
  606. if ($category != '') {
  607. echo '<p><a href="'.api_get_self().'"> ', Display :: return_icon('back.png', get_lang('BackToHomePage')), get_lang('BackToHomePage'), '</a></p>';
  608. }
  609. }
  610. /**
  611. * retrieves all the courses that the user has already subscribed to
  612. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  613. * @param int $user_id: the id of the user
  614. * @return array an array containing all the information of the courses of the given user
  615. */
  616. function get_courses_of_user($user_id) {
  617. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  618. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  619. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  620. $user_id = intval($user_id);
  621. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  622. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  623. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  624. FROM $table_course course,
  625. $table_course_user course_rel_user
  626. WHERE course.code = course_rel_user.course_code
  627. AND course_rel_user.user_id = '".$user_id."'
  628. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  629. ORDER BY course_rel_user.sort ASC";
  630. $result = Database::query($sql_select_courses);
  631. $courses = array();
  632. while ($row = Database::fetch_array($result)) {
  633. // We only need the database name of the course.
  634. $courses[$row['k']] = array('db' => $row['db'], 'code' => $row['k'], 'visual_code' => $row['vc'], 'title' => $row['i'], 'directory' => $row['dir'], 'status' => $row['status'], 'tutor' => $row['t'], 'subscribe' => $row['subscr'], 'unsubscribe' => $row['unsubscr'], 'sort' => $row['sort'], 'user_course_category' => $row['user_course_cat']);
  635. }
  636. return $courses;
  637. }
  638. function show_right_block($title, $content, $class = '') {
  639. $html = '';
  640. $html.= '<div id="menu" class="menu">';
  641. $html.= '<div class="menusection '.$class.' ">';
  642. if (!empty($title)) {
  643. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  644. }
  645. $html.= $content;
  646. $html.= '</div>';
  647. $html.= '</div>';
  648. return $html;
  649. }
  650. /**
  651. * Adds a form to let users login
  652. * @version 1.1
  653. */
  654. function display_login_form() {
  655. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-stacked'));
  656. $form->addElement('text', 'login', get_lang('UserName'), array('size' => 17));
  657. $form->addElement('password', 'password', get_lang('Pass'), array('size' => 17));
  658. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'a_button gray'));
  659. $renderer =& $form->defaultRenderer();
  660. $renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>');
  661. $html = $form->return_form();
  662. if (api_get_setting('openid_authentication') == 'true') {
  663. include_once 'main/auth/openid/login.php';
  664. $html .= '<div>'.openid_form().'</div>';
  665. }
  666. return $html;
  667. }
  668. function return_search_block() {
  669. $html = '';
  670. if (api_get_setting('search_enabled') == 'true') {
  671. $html .= '<div class="searchbox">';
  672. $search_btn = get_lang('Search');
  673. $search_text_default = get_lang('YourTextHere');
  674. $search_content = '<br />
  675. <form action="main/search/" method="post">
  676. <input type="text" id="query" size="15" name="query" value="" />
  677. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  678. </form></div>';
  679. $html .= self::show_right_block(get_lang('Search'), $search_content);
  680. }
  681. return $html;
  682. }
  683. function return_classes_block() {
  684. $html = '';
  685. if (api_get_setting('show_groups_to_users') == 'true') {
  686. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  687. $usergroup = new Usergroup();
  688. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  689. $classes = '';
  690. if (!empty($usergroup_list)) {
  691. foreach($usergroup_list as $group_id) {
  692. $data = $usergroup->get($group_id);
  693. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  694. $classes .= Display::tag('li', $data['name']);
  695. }
  696. }
  697. if (api_is_platform_admin()) {
  698. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  699. }
  700. if (!empty($classes)) {
  701. $classes = Display::tag('ul', $classes, array('class'=>'menulist'));
  702. $html .= self::show_right_block(get_lang('Classes'), $classes);
  703. }
  704. }
  705. return $html;
  706. }
  707. function return_reservation_block() {
  708. $html = '';
  709. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  710. $booking_content .='<ul class="menulist">';
  711. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  712. $booking_content .='</ul>';
  713. $html .= self::show_right_block(get_lang('Booking'), $booking_content);
  714. }
  715. return $html;
  716. }
  717. function return_plugin_courses_block() {
  718. global $_plugins;
  719. // Plugins for the my courses menu.
  720. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  721. ob_start();
  722. api_plugin('mycourses_menu');
  723. $plugin_content = ob_get_contents();
  724. ob_end_clean();
  725. echo self::show_right_block('', $plugin_content);
  726. }
  727. }
  728. function return_profile_block() {
  729. $html = '';
  730. $user_id = api_get_user_id();
  731. if (empty($user_id)) {
  732. return;
  733. }
  734. //Always show the user image
  735. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  736. $no_image = false;
  737. if ($img_array['file'] == 'unknown.jpg') {
  738. $no_image = true;
  739. }
  740. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  741. $profile_content = '<div id="social_widget">';
  742. $profile_content .= '<div id="social_widget_image">';
  743. if (api_get_setting('allow_social_tool') == 'true') {
  744. if (!$no_image) {
  745. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  746. } else {
  747. $profile_content .='<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>';
  748. }
  749. } else {
  750. $profile_content .='<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>';
  751. }
  752. $profile_content .= ' </div></div>';
  753. // @todo Add a platform setting to add the user image.
  754. if (api_get_setting('allow_message_tool') == 'true') {
  755. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  756. // New messages.
  757. $number_of_new_messages = MessageManager::get_new_messages();
  758. // New contact invitations.
  759. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  760. // New group invitations sent by a moderator.
  761. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  762. $group_pending_invitations = count($group_pending_invitations);
  763. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  764. $cant_msg = '';
  765. if ($number_of_new_messages > 0) {
  766. $cant_msg = ' ('.$number_of_new_messages.')';
  767. }
  768. $profile_content .= '<div class="clear"></div>';
  769. $profile_content .= '<ul class="menulist">';
  770. $link = '';
  771. if (api_get_setting('allow_social_tool') == 'true') {
  772. $link = '?f=social';
  773. }
  774. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php'.$link.'" class="message-body">'.get_lang('Inbox').$cant_msg.' </a></li>';
  775. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  776. if (api_get_setting('allow_social_tool') == 'true') {
  777. if ($total_invitations == 0) {
  778. $total_invitations = '';
  779. } else {
  780. $total_invitations = ' ('.$total_invitations.')';
  781. }
  782. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  783. }
  784. $profile_content .= '</ul>';
  785. }
  786. $html = self::show_right_block(get_lang('Profile'), $profile_content);
  787. return $html;
  788. }
  789. function return_navigation_course_links($menu_navigation) {
  790. $html = '';
  791. // Deleting the myprofile link.
  792. if (api_get_setting('allow_social_tool') == 'true') {
  793. unset($menu_navigation['myprofile']);
  794. }
  795. // Main navigation section.
  796. // Tabs that are deactivated are added here.
  797. if (!empty($menu_navigation)) {
  798. $main_navigation_content .= '<ul class="menulist">';
  799. foreach ($menu_navigation as $section => $navigation_info) {
  800. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  801. $main_navigation_content .= '<li'.$current.'>';
  802. $main_navigation_content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  803. $main_navigation_content .= '</li>';
  804. }
  805. $main_navigation_content .= '</ul>';
  806. $html = self::show_right_block(get_lang('MainNavigation'), $main_navigation_content);
  807. }
  808. return $html;
  809. }
  810. function return_account_block() {
  811. $html = '';
  812. $show_menu = false;
  813. $show_create_link = false;
  814. $show_course_link = false;
  815. $show_digest_link = false;
  816. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  817. if ($display_add_course_link) {
  818. $show_menu = true;
  819. $show_create_link = true;
  820. }
  821. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  822. $show_menu = true;
  823. $show_course_link = true;
  824. } else {
  825. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  826. $show_menu = true;
  827. $show_course_link = true;
  828. }
  829. }
  830. if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
  831. $show_digest_link = true;
  832. $show_menu = true;
  833. }
  834. // My account section
  835. $my_account_content = '<ul class="menulist">';
  836. if ($show_create_link) {
  837. $my_account_content .= '<li><a href="main/create_course/add_course.php">'.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  838. }
  839. //Sort courses
  840. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  841. $my_account_content .= Display::url(get_lang('SortMyCourses'), $url);
  842. //Course management
  843. if ($show_course_link) {
  844. if (!api_is_drh()) {
  845. $my_account_content .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  846. if (api_get_setting('use_session_mode') == 'true') {
  847. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  848. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  849. } else {
  850. $my_account_content .= '<li><a href="user_portal.php?history=1">'.get_lang('HistoryTrainingSessions').'</a></li>';
  851. }
  852. }
  853. } else {
  854. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  855. }
  856. }
  857. $my_account_content .= '</ul>';
  858. if (!empty($my_account_content)) {
  859. $html = self::show_right_block(get_lang('MenuUser'), $my_account_content);
  860. }
  861. return $html;
  862. }
  863. function return_courses_main_plugin() {
  864. ob_start();
  865. echo '<div id="plugin-mycourses_main">';
  866. api_plugin('mycourses_main');
  867. echo '</div>';
  868. $plugin_content = ob_get_contents();
  869. ob_end_clean();
  870. return $plugin_content;
  871. }
  872. /**
  873. * The most important function here, prints the session and course list
  874. *
  875. * */
  876. function return_courses_and_sessions($personal_course_list) {
  877. // Don't change these settings
  878. define('SCRIPTVAL_No', 0);
  879. define('SCRIPTVAL_InCourseList', 1);
  880. define('SCRIPTVAL_UnderCourseList', 2);
  881. define('SCRIPTVAL_Both', 3);
  882. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  883. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  884. define('SCRIPTVAL_NoTimeLimit', 6);
  885. // End 'don't change' section
  886. // ---- Course list options ----
  887. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  888. // Preview of course content
  889. // to disable all: set CONFVAL_maxTotalByCourse = 0
  890. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  891. // by default disabled since what's new icons are better (see function display_digest() )
  892. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  893. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  894. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  895. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  896. // Order to sort data
  897. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  898. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  899. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  900. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  901. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  902. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  903. // SCRIPTVAL_UnderCourseList // best choice
  904. // SCRIPTVAL_Both // probably only for debug
  905. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  906. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  907. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  908. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  909. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  910. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  911. echo Display::tag('h2', get_lang('HistoryTrainingSession'));
  912. //if (empty($courses_tree[0]['sessions'])){
  913. if (empty($courses_tree)) {
  914. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  915. }
  916. }
  917. /* PERSONAL COURSE LIST */
  918. if (!isset ($maxValvas)) {
  919. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  920. }
  921. if (!isset ($maxAgenda)) {
  922. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  923. }
  924. if (!isset ($maxCourse)) {
  925. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  926. }
  927. $maxValvas = (int) $maxValvas;
  928. $maxAgenda = (int) $maxAgenda;
  929. $maxCourse = (int) $maxCourse; // 0 if invalid.
  930. /* DISPLAY COURSES */
  931. // Compose a structured array of session categories, sessions and courses
  932. // for the current user.
  933. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  934. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, true, true);
  935. if (empty($courses_tree[0]) && count($courses_tree) == 1) {
  936. $courses_tree = null;
  937. }
  938. } else {
  939. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, false, true);
  940. }
  941. if (!empty($courses_tree)) {
  942. foreach ($courses_tree as $cat => $sessions) {
  943. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  944. if ($cat == 0) {
  945. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id(api_get_user_id(), false);
  946. }
  947. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  948. if (count($courses_tree[$cat]['sessions']) > 0) {
  949. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  950. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  951. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session(api_get_user_id(), $s_id);
  952. }
  953. }
  954. }
  955. }
  956. $list = '';
  957. foreach ($personal_course_list as $my_course) {
  958. $thisCourseDbName = $my_course['db'];
  959. $thisCourseSysCode = $my_course['k'];
  960. $thisCoursePublicCode = $my_course['c'];
  961. $thisCoursePath = $my_course['d'];
  962. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  963. $dbname = $my_course['k'];
  964. $status = array();
  965. $status[$dbname] = $my_course['s'];
  966. $nbDigestEntries = 0; // Number of entries already collected.
  967. if ($maxCourse < $maxValvas) {
  968. $maxValvas = $maxCourse;
  969. }
  970. if ($maxCourse > 0) {
  971. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  972. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  973. }
  974. /* Announcements */
  975. $course_id = $my_course['course_id'];
  976. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
  977. $query = "SELECT visibility FROM $course_tool_table WHERE c_id = $course_id AND link = 'announcements/announcements.php' AND visibility = 1";
  978. $result = Database::query($query);
  979. // Collect from announcements, but only if tool is visible for the course.
  980. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  981. // Search announcements table.
  982. // Take the entries listed at the top of advalvas/announcements tool.
  983. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  984. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  985. FROM ".$course_announcement_table." WHERE c_id = $course_id ";
  986. switch (CONFVAL_limitPreviewTo) {
  987. case SCRIPTVAL_NewEntriesOfTheDay :
  988. $sqlGetLastAnnouncements .= " AND DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d')."'";
  989. break;
  990. case SCRIPTVAL_NoTimeLimit :
  991. break;
  992. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  993. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  994. $sqlGetLastAnnouncements .= " AND DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d', $_user['lastLogin'])."'";
  995. }
  996. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  997. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  998. if ($resGetLastAnnouncements) {
  999. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  1000. $keyTools = 'valvas';
  1001. $keyTime = $annoncement['publicationDate'];
  1002. $keyCourse = $thisCourseSysCode;
  1003. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($annoncement['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1004. $nbDigestEntries ++; // summary has same order as advalvas
  1005. }
  1006. }
  1007. }
  1008. /* Agenda */
  1009. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST);
  1010. $query = "SELECT visibility FROM $course_tool_table WHERE c_id = $course_id AND link = 'calendar/agenda.php' AND visibility = 1";
  1011. $result = Database::query($query);
  1012. $thisAgenda = $maxCourse - $nbDigestEntries; // New max entries for agenda.
  1013. if ($maxAgenda < $thisAgenda) {
  1014. $thisAgenda = $maxAgenda;
  1015. }
  1016. // Collect from agenda, but only if tool is visible for the course.
  1017. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  1018. //$tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue'].'calendar_event';
  1019. $course_table_agenda = Database::get_course_table(TABLE_AGENDA);
  1020. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  1021. FROM $course_table_agenda
  1022. WHERE c_id = $course_id AND start_date >= CURDATE()
  1023. ORDER BY start_date, start_time
  1024. LIMIT $maxAgenda";
  1025. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  1026. if ($resGetNextAgendaEvent) {
  1027. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  1028. $keyTools = 'agenda';
  1029. $keyTime = $agendaEvent['start_date'];
  1030. $keyCourse = $thisCourseSysCode;
  1031. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($agendaEvent['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1032. $nbDigestEntries ++; // Summary has same order as advalvas.
  1033. }
  1034. }
  1035. }
  1036. } // End while mycourse...
  1037. if (is_array($courses_tree)) {
  1038. foreach ($courses_tree as $key => $category) {
  1039. if ($key == 0) {
  1040. // Sessions and courses that are not in a session category.
  1041. if (!isset($_GET['history'])) {
  1042. // If we're not in the history view...
  1043. CourseManager :: display_special_courses(api_get_user_id(), $this->load_directories_preview);
  1044. CourseManager :: display_courses(api_get_user_id(), $this->load_directories_preview);
  1045. }
  1046. // Independent sessions.
  1047. foreach ($category['sessions'] as $session) {
  1048. // Don't show empty sessions.
  1049. if (count($session['courses']) < 1) {
  1050. continue;
  1051. }
  1052. // Courses inside the current session.
  1053. $date_session_start = $session['details']['date_start'];
  1054. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  1055. $session_now = time();
  1056. $html_courses_session = '';
  1057. $count_courses_session = 0;
  1058. foreach ($session['courses'] as $course) {
  1059. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  1060. $allowed_time = 0;
  1061. if ($date_session_start != '0000-00-00') {
  1062. if ($is_coach_course) {
  1063. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  1064. } else {
  1065. $allowed_time = api_strtotime($date_session_start);
  1066. }
  1067. }
  1068. if ($session_now > $allowed_time) {
  1069. //read only and accesible
  1070. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1071. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item', true, $this->load_directories_preview);
  1072. //$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true));
  1073. $html_courses_session .= $c[1];
  1074. }
  1075. $count_courses_session++;
  1076. }
  1077. }
  1078. if ($count_courses_session > 0) {
  1079. echo '<div class="userportal-session-item"><ul class="session_box">';
  1080. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  1081. echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1082. $s = Display :: get_session_title_box($session['details']['id']);
  1083. $extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  1084. /*if ($session['details']['visibility'] == 3) {
  1085. $session_link = $s['title'];
  1086. } else {*/
  1087. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  1088. //}
  1089. echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
  1090. if (api_is_platform_admin()) {
  1091. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.
  1092. Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
  1093. }
  1094. echo '</li>';
  1095. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1096. echo $html_courses_session;
  1097. }
  1098. echo '</ul></div>';
  1099. }
  1100. }
  1101. } else {
  1102. // All sessions included in.
  1103. if (!empty($category['details'])) {
  1104. $count_courses_session = 0;
  1105. $html_sessions = '';
  1106. foreach ($category['sessions'] as $session) {
  1107. // Don't show empty sessions.
  1108. if (count($session['courses']) < 1) {
  1109. continue;
  1110. }
  1111. $date_session_start = $session['details']['date_start'];
  1112. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  1113. $session_now = time();
  1114. $html_courses_session = '';
  1115. $count = 0;
  1116. foreach ($session['courses'] as $course) {
  1117. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  1118. if ($is_coach_course) {
  1119. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  1120. } else {
  1121. $allowed_time = api_strtotime($date_session_start);
  1122. }
  1123. if ($session_now > $allowed_time) {
  1124. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1125. $html_courses_session .= $c[1];
  1126. $count_courses_session++;
  1127. $count++;
  1128. }
  1129. }
  1130. if ($count > 0) {
  1131. $s = Display :: get_session_title_box($session['details']['id']);
  1132. $html_sessions .= '<ul class="sub_session_box" id="session_'.$session['details']['id'].'">';
  1133. $html_sessions .= '<li class="sub_session_box_title" id="session_'.$session['details']['id'].'">';
  1134. //$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1135. $html_sessions .= Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1136. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  1137. $html_sessions .= '<span>' . $session_link. ' </span> ';
  1138. $html_sessions .= '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  1139. $html_sessions .= (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  1140. $html_sessions .= '</span>';
  1141. if (api_is_platform_admin()) {
  1142. $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.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
  1143. }
  1144. $html_sessions .= '</li>';
  1145. $html_sessions .= $html_courses_session;
  1146. $html_sessions .= '</ul>';
  1147. }
  1148. }
  1149. if ($count_courses_session > 0) {
  1150. echo '<div class="userportal-session-category-item" id="session_category_'.$category['details']['id'].'">';
  1151. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  1152. echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  1153. if (api_is_platform_admin()) {
  1154. echo'<div style="float: right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$category['details']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(),22).'</a></div>';
  1155. }
  1156. echo '<span id="session_category_title">';
  1157. echo $category['details']['name'];
  1158. echo '</span>';
  1159. echo '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  1160. if ($category['details']['date_end'] != '0000-00-00') {
  1161. printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
  1162. }
  1163. echo '</span></div>';
  1164. echo $html_sessions;
  1165. echo '</div>';
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. function return_hot_courses() {
  1173. return CourseManager::return_hot_courses();
  1174. }
  1175. }