userportal.lib.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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. /**
  329. * Reacts on a failed login:
  330. * Displays an explanation with a link to the registration form.
  331. *
  332. * @version 1.0.1
  333. */
  334. function handle_login_failed() {
  335. if (!isset($_GET['error'])) {
  336. $message = get_lang('InvalidId');
  337. if (api_is_self_registration_allowed()) {
  338. $message = get_lang('InvalidForSelfRegistration');
  339. }
  340. } else {
  341. switch ($_GET['error']) {
  342. case '':
  343. $message = get_lang('InvalidId');
  344. if (api_is_self_registration_allowed()) {
  345. $message = get_lang('InvalidForSelfRegistration');
  346. }
  347. break;
  348. case 'account_expired':
  349. $message = get_lang('AccountExpired');
  350. break;
  351. case 'account_inactive':
  352. $message = get_lang('AccountInactive');
  353. break;
  354. case 'user_password_incorrect':
  355. $message = get_lang('InvalidId');
  356. break;
  357. case 'access_url_inactive':
  358. $message = get_lang('AccountURLInactive');
  359. break;
  360. }
  361. }
  362. return '<div id="login_fail">'.$message.'</div>';
  363. }
  364. /**
  365. * Display list of courses in a category.
  366. * (for anonymous users)
  367. *
  368. * @version 1.1
  369. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  370. */
  371. function display_anonymous_course_list() {
  372. $ctok = $_SESSION['sec_token'];
  373. $stok = Security::get_token();
  374. // Initialization.
  375. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  376. $web_course_path = api_get_path(WEB_COURSE_PATH);
  377. $category = Database::escape_string($_GET['category']);
  378. global $setting_show_also_closed_courses;
  379. // Database table definitions.
  380. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  381. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  382. $platformLanguage = api_get_setting('platformLanguage');
  383. // Get list of courses in category $category.
  384. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  385. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  386. ORDER BY title, UPPER(visual_code)";
  387. // Showing only the courses of the current access_url_id.
  388. global $_configuration;
  389. if ($_configuration['multiple_access_urls']) {
  390. $url_access_id = api_get_current_access_url_id();
  391. if ($url_access_id != -1) {
  392. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  393. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  394. ON (url_rel_course.course_code=course.code)
  395. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  396. }
  397. }
  398. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  399. $sql_result_courses = Database::query($sql_get_course_list);
  400. while ($course_result = Database::fetch_array($sql_result_courses)) {
  401. $course_list[] = $course_result;
  402. }
  403. $platform_visible_courses = '';
  404. // $setting_show_also_closed_courses
  405. if ($user_identified) {
  406. if ($setting_show_also_closed_courses) {
  407. $platform_visible_courses = '';
  408. } else {
  409. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  410. }
  411. } else {
  412. if ($setting_show_also_closed_courses) {
  413. $platform_visible_courses = '';
  414. } else {
  415. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  416. }
  417. }
  418. $sqlGetSubCatList = "
  419. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  420. FROM $main_category_table t1
  421. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  422. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  423. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  424. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  425. // Showing only the category of courses of the current access_url_id.
  426. global $_configuration;
  427. if ($_configuration['multiple_access_urls']) {
  428. $url_access_id = api_get_current_access_url_id();
  429. if ($url_access_id != -1) {
  430. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  431. $sqlGetSubCatList = "
  432. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  433. FROM $main_category_table t1
  434. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  435. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  436. INNER JOIN $tbl_url_rel_course as url_rel_course
  437. ON (url_rel_course.course_code=t3.code)
  438. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  439. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  440. }
  441. }
  442. $resCats = Database::query($sqlGetSubCatList);
  443. $thereIsSubCat = false;
  444. if (Database::num_rows($resCats) > 0) {
  445. $htmlListCat = '<h4 style="margin-top: 0px;">'.get_lang('CatList').'</h4><ul>';
  446. while ($catLine = Database::fetch_array($resCats)) {
  447. if ($catLine['code'] != $category) {
  448. $category_has_open_courses = self::category_has_open_courses($catLine['code']);
  449. if ($category_has_open_courses) {
  450. // The category contains courses accessible to anonymous visitors.
  451. $htmlListCat .= '<li>';
  452. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  453. if (api_get_setting('show_number_of_courses') == 'true') {
  454. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  455. }
  456. $htmlListCat .= "</li>\n";
  457. $thereIsSubCat = true;
  458. } elseif ($catLine['children_count'] > 0) {
  459. // The category has children, subcategories.
  460. $htmlListCat .= '<li>';
  461. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  462. $htmlListCat .= "</li>\n";
  463. $thereIsSubCat = true;
  464. }
  465. /* End changed code to eliminate the (0 courses) after empty categories. */
  466. elseif (api_get_setting('show_empty_course_categories') == 'true') {
  467. $htmlListCat .= '<li>';
  468. $htmlListCat .= $catLine['name'];
  469. $htmlListCat .= "</li>\n";
  470. $thereIsSubCat = true;
  471. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  472. } else {
  473. $htmlTitre = '<p>';
  474. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  475. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  476. }
  477. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  478. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  479. }
  480. $htmlTitre .= "</p>\n";
  481. if ($category != "" && !is_null($catLine['code'])) {
  482. $htmlTitre .= '<h3>'.$catLine['name']."</h3>\n";
  483. } else {
  484. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>\n";
  485. }
  486. }
  487. }
  488. $htmlListCat .= "</ul>";
  489. }
  490. echo $htmlTitre;
  491. if ($thereIsSubCat) {
  492. echo $htmlListCat;
  493. }
  494. while ($categoryName = Database::fetch_array($resCats)) {
  495. echo '<h3>', $categoryName['name'], "</h3>\n";
  496. }
  497. $numrows = Database::num_rows($sql_result_courses);
  498. $courses_list_string = '';
  499. $courses_shown = 0;
  500. if ($numrows > 0) {
  501. if ($thereIsSubCat) {
  502. $courses_list_string .= "<hr size=\"1\" noshade=\"noshade\">\n";
  503. }
  504. $courses_list_string .= '<h4 style="margin-top: 0px;">'.get_lang('CourseList')."</h4>\n<ul>\n";
  505. if (api_get_user_id()) {
  506. $courses_of_user = self::get_courses_of_user(api_get_user_id());
  507. }
  508. foreach ($course_list as $course) {
  509. // $setting_show_also_closed_courses
  510. if (!$setting_show_also_closed_courses) {
  511. // If we do not show the closed courses
  512. // we only show the courses that are open to the world (to everybody)
  513. // and the courses that are open to the platform (if the current user is a registered user.
  514. if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  515. $courses_shown++;
  516. $courses_list_string .= "<li>\n";
  517. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  518. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  519. $courses_list_string .= $course['visual_code'];
  520. }
  521. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  522. $courses_list_string .= ' - ';
  523. }
  524. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  525. $courses_list_string .= $course['tutor_name'];
  526. }
  527. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  528. $courses_list_string .= ' - '.$course['course_language'];
  529. }
  530. $courses_list_string .= "</li>\n";
  531. }
  532. }
  533. // We DO show the closed courses.
  534. // The course is accessible if (link to the course homepage):
  535. // 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);
  536. // 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);
  537. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  538. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  539. // 5. the user is the platform admin api_is_platform_admin().
  540. //
  541. else {
  542. $courses_shown++;
  543. $courses_list_string .= "<li>\n";
  544. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  545. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  546. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  547. || $courses_of_user[$course['code']]['status'] == '1'
  548. || api_is_platform_admin()) {
  549. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  550. }
  551. $courses_list_string .= $course['title'];
  552. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  553. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  554. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  555. || $courses_of_user[$course['code']]['status'] == '1'
  556. || api_is_platform_admin()) {
  557. $courses_list_string .= '</a><br />';
  558. }
  559. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  560. $courses_list_string .= ' '.$course['visual_code'];
  561. }
  562. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  563. $courses_list_string .= ' - ';
  564. }
  565. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  566. $courses_list_string .= $course['tutor_name'];
  567. }
  568. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  569. $courses_list_string .= ' - '.$course['course_language'];
  570. }
  571. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  572. $courses_list_string .= ' - '.$course['course_language'];
  573. }
  574. // We display a subscription link if:
  575. // 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
  576. // 2.
  577. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  578. if ($course['subscribe'] == '1') {
  579. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  580. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  581. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  582. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  583. } else {
  584. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  585. }
  586. }
  587. $courses_list_string .= "</li>";
  588. }
  589. }
  590. $courses_list_string .= "</ul>";
  591. } else {
  592. //echo '<blockquote>', get_lang('_No_course_publicly_available'), "</blockquote>\n";
  593. }
  594. if ($courses_shown > 0) {
  595. // Only display the list of courses and categories if there was more than
  596. // 0 courses visible to the world (we're in the anonymous list here).
  597. echo $courses_list_string;
  598. }
  599. if ($category != '') {
  600. echo '<p><a href="'.api_get_self().'"> ', Display :: return_icon('back.png', get_lang('BackToHomePage')), get_lang('BackToHomePage'), '</a></p>';
  601. }
  602. }
  603. /**
  604. * retrieves all the courses that the user has already subscribed to
  605. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  606. * @param int $user_id: the id of the user
  607. * @return array an array containing all the information of the courses of the given user
  608. */
  609. function get_courses_of_user($user_id) {
  610. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  611. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  612. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  613. $user_id = intval($user_id);
  614. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  615. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  616. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  617. FROM $table_course course,
  618. $table_course_user course_rel_user
  619. WHERE course.code = course_rel_user.course_code
  620. AND course_rel_user.user_id = '".$user_id."'
  621. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  622. ORDER BY course_rel_user.sort ASC";
  623. $result = Database::query($sql_select_courses);
  624. $courses = array();
  625. while ($row = Database::fetch_array($result)) {
  626. // We only need the database name of the course.
  627. $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']);
  628. }
  629. return $courses;
  630. }
  631. function show_right_block($title, $content, $class = '') {
  632. $html = '';
  633. $html.= '<div id="menu" class="menu">';
  634. $html.= '<div class="menusection '.$class.' ">';
  635. if (!empty($title)) {
  636. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  637. }
  638. $html.= $content;
  639. $html.= '</div>';
  640. $html.= '</div>';
  641. return $html;
  642. }
  643. /**
  644. * Adds a form to let users login
  645. * @version 1.1
  646. */
  647. function display_login_form() {
  648. $form = new FormValidator('formLogin', 'POST', null, null, array('class'=>'form-stacked'));
  649. $form->addElement('text', 'login', get_lang('UserName'), array('size' => 17));
  650. $form->addElement('password', 'password', get_lang('Pass'), array('size' => 17));
  651. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'a_button gray'));
  652. $renderer =& $form->defaultRenderer();
  653. $renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>');
  654. $html = $form->return_form();
  655. if (api_get_setting('openid_authentication') == 'true') {
  656. include_once 'main/auth/openid/login.php';
  657. $html .= '<div>'.openid_form().'</div>';
  658. }
  659. return $html;
  660. }
  661. function return_search_block() {
  662. $html = '';
  663. if (api_get_setting('search_enabled') == 'true') {
  664. $html .= '<div class="searchbox">';
  665. $search_btn = get_lang('Search');
  666. $search_text_default = get_lang('YourTextHere');
  667. $search_content = '<br />
  668. <form action="main/search/" method="post">
  669. <input type="text" id="query" size="15" name="query" value="" />
  670. <button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
  671. </form></div>';
  672. $html .= self::show_right_block(get_lang('Search'), $search_content);
  673. }
  674. return $html;
  675. }
  676. function return_classes_block() {
  677. $html = '';
  678. if (api_get_setting('show_groups_to_users') == 'true') {
  679. require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
  680. $usergroup = new Usergroup();
  681. $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id());
  682. $classes = '';
  683. if (!empty($usergroup_list)) {
  684. foreach($usergroup_list as $group_id) {
  685. $data = $usergroup->get($group_id);
  686. $data['name'] = Display::url($data['name'], api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id']);
  687. $classes .= Display::tag('li', $data['name']);
  688. }
  689. }
  690. if (api_is_platform_admin()) {
  691. $classes .= Display::tag('li', Display::url(get_lang('AddClasses') ,api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add'));
  692. }
  693. if (!empty($classes)) {
  694. $classes = Display::tag('ul', $classes, array('class'=>'menulist'));
  695. $html .= self::show_right_block(get_lang('Classes'), $classes);
  696. }
  697. }
  698. return $html;
  699. }
  700. function return_reservation_block() {
  701. $html = '';
  702. if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
  703. $booking_content .='<ul class="menulist">';
  704. $booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
  705. $booking_content .='</ul>';
  706. $html .= self::show_right_block(get_lang('Booking'), $booking_content);
  707. }
  708. return $html;
  709. }
  710. function return_plugin_courses_block() {
  711. global $_plugins;
  712. // Plugins for the my courses menu.
  713. if (isset($_plugins['mycourses_menu']) && is_array($_plugins['mycourses_menu'])) {
  714. ob_start();
  715. api_plugin('mycourses_menu');
  716. $plugin_content = ob_get_contents();
  717. ob_end_clean();
  718. echo self::show_right_block('', $plugin_content);
  719. }
  720. }
  721. function return_profile_block() {
  722. $html = '';
  723. $user_id = api_get_user_id();
  724. if (empty($user_id)) {
  725. return;
  726. }
  727. //Always show the user image
  728. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  729. $no_image = false;
  730. if ($img_array['file'] == 'unknown.jpg') {
  731. $no_image = true;
  732. }
  733. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  734. $profile_content = '<div id="social_widget">';
  735. $profile_content .= '<div id="social_widget_image">';
  736. if (api_get_setting('allow_social_tool') == 'true') {
  737. if (!$no_image) {
  738. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  739. } else {
  740. $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>';
  741. }
  742. } else {
  743. $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>';
  744. }
  745. $profile_content .= ' </div></div>';
  746. // @todo Add a platform setting to add the user image.
  747. if (api_get_setting('allow_message_tool') == 'true') {
  748. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  749. // New messages.
  750. $number_of_new_messages = MessageManager::get_new_messages();
  751. // New contact invitations.
  752. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  753. // New group invitations sent by a moderator.
  754. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  755. $group_pending_invitations = count($group_pending_invitations);
  756. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  757. $cant_msg = '';
  758. if ($number_of_new_messages > 0) {
  759. $cant_msg = ' ('.$number_of_new_messages.')';
  760. }
  761. $profile_content .= '<div class="clear"></div>';
  762. $profile_content .= '<div class="message-content"><ul class="menulist">';
  763. $link = '';
  764. if (api_get_setting('allow_social_tool') == 'true') {
  765. $link = '?f=social';
  766. }
  767. $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>';
  768. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  769. if (api_get_setting('allow_social_tool') == 'true') {
  770. if ($total_invitations == 0) {
  771. $total_invitations = '';
  772. } else {
  773. $total_invitations = ' ('.$total_invitations.')';
  774. }
  775. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  776. }
  777. $profile_content .= '</ul>';
  778. $profile_content .= '</div>';
  779. }
  780. $html = self::show_right_block(get_lang('Profile'), $profile_content);
  781. return $html;
  782. }
  783. function return_navigation_course_links($menu_navigation) {
  784. $html = '';
  785. // Deleting the myprofile link.
  786. if (api_get_setting('allow_social_tool') == 'true') {
  787. unset($menu_navigation['myprofile']);
  788. }
  789. // Main navigation section.
  790. // Tabs that are deactivated are added here.
  791. if (!empty($menu_navigation)) {
  792. $main_navigation_content .= '<ul class="menulist">';
  793. foreach ($menu_navigation as $section => $navigation_info) {
  794. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  795. $main_navigation_content .= '<li'.$current.'>';
  796. $main_navigation_content .= '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
  797. $main_navigation_content .= '</li>';
  798. }
  799. $main_navigation_content .= '</ul>';
  800. $html = self::show_right_block(get_lang('MainNavigation'), $main_navigation_content);
  801. }
  802. return $html;
  803. }
  804. function return_account_block() {
  805. $html = '';
  806. $show_menu = false;
  807. $show_create_link = false;
  808. $show_course_link = false;
  809. $show_digest_link = false;
  810. $display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  811. if ($display_add_course_link) {
  812. $show_menu = true;
  813. $show_create_link = true;
  814. }
  815. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  816. $show_menu = true;
  817. $show_course_link = true;
  818. } else {
  819. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  820. $show_menu = true;
  821. $show_course_link = true;
  822. }
  823. }
  824. if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
  825. $show_digest_link = true;
  826. $show_menu = true;
  827. }
  828. // My account section.
  829. if ($show_menu) {
  830. $my_account_content = '<ul class="menulist">';
  831. if ($show_create_link) {
  832. $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>';
  833. }
  834. if ($show_course_link) {
  835. if (!api_is_drh()) {
  836. $my_account_content .= '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  837. $url = api_get_path(WEB_CODE_PATH).'auth/courses.php?action=sortmycourses';
  838. $my_account_content .= Display::url(get_lang('SortMyCourses'), $url);
  839. if (api_get_setting('use_session_mode') == 'true') {
  840. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  841. $my_account_content .= '<li><a href="user_portal.php">'.get_lang('DisplayTrainingList').'</a></li>';
  842. } else {
  843. $my_account_content .= '<li><a href="user_portal.php?history=1">'.get_lang('HistoryTrainingSessions').'</a></li>';
  844. }
  845. }
  846. } else {
  847. $my_account_content .= '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  848. }
  849. }
  850. if ($show_digest_link) {
  851. //digest never used?
  852. //$my_account_content .= Display :: display_digest($toolsList, $digest, $orderKey, $courses);
  853. }
  854. $my_account_content .= '</ul>';
  855. }
  856. if (!empty($my_account_content)) {
  857. $html = self::show_right_block(get_lang('MenuUser'), $my_account_content);
  858. }
  859. return $html;
  860. }
  861. function return_courses_main_plugin() {
  862. ob_start();
  863. echo '<div id="plugin-mycourses_main">';
  864. api_plugin('mycourses_main');
  865. echo '</div>';
  866. $plugin_content = ob_get_contents();
  867. ob_end_clean();
  868. return $plugin_content;
  869. }
  870. /**
  871. * The most important function here, prints the session and course list
  872. *
  873. * */
  874. function return_courses_and_sessions($personal_course_list) {
  875. // Don't change these settings
  876. define('SCRIPTVAL_No', 0);
  877. define('SCRIPTVAL_InCourseList', 1);
  878. define('SCRIPTVAL_UnderCourseList', 2);
  879. define('SCRIPTVAL_Both', 3);
  880. define('SCRIPTVAL_NewEntriesOfTheDay', 4);
  881. define('SCRIPTVAL_NewEntriesOfTheDayOfLastLogin', 5);
  882. define('SCRIPTVAL_NoTimeLimit', 6);
  883. // End 'don't change' section
  884. // ---- Course list options ----
  885. define('CONFVAL_showCourseLangIfNotSameThatPlatform', true);
  886. // Preview of course content
  887. // to disable all: set CONFVAL_maxTotalByCourse = 0
  888. // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
  889. // by default disabled since what's new icons are better (see function display_digest() )
  890. define('CONFVAL_maxValvasByCourse', 2); // Maximum number of entries
  891. define('CONFVAL_maxAgendaByCourse', 2); // collected from each course
  892. define('CONFVAL_maxTotalByCourse', 0); // and displayed in summary.
  893. define('CONFVAL_NB_CHAR_FROM_CONTENT', 80);
  894. // Order to sort data
  895. $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
  896. //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
  897. //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
  898. //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
  899. define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
  900. // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
  901. // SCRIPTVAL_UnderCourseList // best choice
  902. // SCRIPTVAL_Both // probably only for debug
  903. //define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
  904. define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
  905. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
  906. //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
  907. define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
  908. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  909. echo Display::tag('h2', get_lang('HistoryTrainingSession'));
  910. //if (empty($courses_tree[0]['sessions'])){
  911. if (empty($courses_tree)) {
  912. echo get_lang('YouDoNotHaveAnySessionInItsHistory');
  913. }
  914. }
  915. /* PERSONAL COURSE LIST */
  916. if (!isset ($maxValvas)) {
  917. $maxValvas = CONFVAL_maxValvasByCourse; // Maximum number of entries
  918. }
  919. if (!isset ($maxAgenda)) {
  920. $maxAgenda = CONFVAL_maxAgendaByCourse; // collected from each course
  921. }
  922. if (!isset ($maxCourse)) {
  923. $maxCourse = CONFVAL_maxTotalByCourse; // and displayed in summary.
  924. }
  925. $maxValvas = (int) $maxValvas;
  926. $maxAgenda = (int) $maxAgenda;
  927. $maxCourse = (int) $maxCourse; // 0 if invalid.
  928. /* DISPLAY COURSES */
  929. // Compose a structured array of session categories, sessions and courses
  930. // for the current user.
  931. if (isset($_GET['history']) && intval($_GET['history']) == 1) {
  932. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, true, true);
  933. if (empty($courses_tree[0]) && count($courses_tree) == 1) {
  934. $courses_tree = null;
  935. }
  936. } else {
  937. $courses_tree = UserManager::get_sessions_by_category(api_get_user_id(), true, false, true);
  938. }
  939. if (!empty($courses_tree)) {
  940. foreach ($courses_tree as $cat => $sessions) {
  941. $courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
  942. if ($cat == 0) {
  943. $courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id(api_get_user_id(), false);
  944. }
  945. $courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
  946. if (count($courses_tree[$cat]['sessions']) > 0) {
  947. foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
  948. $courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
  949. $courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session(api_get_user_id(), $s_id);
  950. }
  951. }
  952. }
  953. }
  954. $list = '';
  955. foreach ($personal_course_list as $my_course) {
  956. $thisCourseDbName = $my_course['db'];
  957. $thisCourseSysCode = $my_course['k'];
  958. $thisCoursePublicCode = $my_course['c'];
  959. $thisCoursePath = $my_course['d'];
  960. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  961. $dbname = $my_course['k'];
  962. $status = array();
  963. $status[$dbname] = $my_course['s'];
  964. $nbDigestEntries = 0; // Number of entries already collected.
  965. if ($maxCourse < $maxValvas) {
  966. $maxValvas = $maxCourse;
  967. }
  968. if ($maxCourse > 0) {
  969. $courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
  970. $courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
  971. }
  972. /* Announcements */
  973. $course_database = $my_course['db'];
  974. $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
  975. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
  976. $result = Database::query($query);
  977. // Collect from announcements, but only if tool is visible for the course.
  978. if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
  979. // Search announcements table.
  980. // Take the entries listed at the top of advalvas/announcements tool.
  981. $course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
  982. $sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
  983. FROM ".$course_announcement_table;
  984. switch (CONFVAL_limitPreviewTo) {
  985. case SCRIPTVAL_NewEntriesOfTheDay :
  986. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d')."'";
  987. break;
  988. case SCRIPTVAL_NoTimeLimit :
  989. break;
  990. case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
  991. // take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
  992. $sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d', $_user['lastLogin'])."'";
  993. }
  994. $sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
  995. $resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
  996. if ($resGetLastAnnouncements) {
  997. while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
  998. $keyTools = 'valvas';
  999. $keyTime = $annoncement['publicationDate'];
  1000. $keyCourse = $thisCourseSysCode;
  1001. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($annoncement['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1002. $nbDigestEntries ++; // summary has same order as advalvas
  1003. }
  1004. }
  1005. }
  1006. /* Agenda */
  1007. $course_database = $my_course['db'];
  1008. $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
  1009. $query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
  1010. $result = Database::query($query);
  1011. $thisAgenda = $maxCourse - $nbDigestEntries; // New max entries for agenda.
  1012. if ($maxAgenda < $thisAgenda) {
  1013. $thisAgenda = $maxAgenda;
  1014. }
  1015. // Collect from agenda, but only if tool is visible for the course.
  1016. if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
  1017. $tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue'].'calendar_event';
  1018. $sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
  1019. FROM $tableCal
  1020. WHERE start_date >= CURDATE()
  1021. ORDER BY start_date, start_time
  1022. LIMIT $maxAgenda";
  1023. $resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
  1024. if ($resGetNextAgendaEvent) {
  1025. while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
  1026. $keyTools = 'agenda';
  1027. $keyTime = $agendaEvent['start_date'];
  1028. $keyCourse = $thisCourseSysCode;
  1029. $digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($agendaEvent['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
  1030. $nbDigestEntries ++; // Summary has same order as advalvas.
  1031. }
  1032. }
  1033. }
  1034. } // End while mycourse...
  1035. if (is_array($courses_tree)) {
  1036. foreach ($courses_tree as $key => $category) {
  1037. if ($key == 0) {
  1038. // Sessions and courses that are not in a session category.
  1039. if (!isset($_GET['history'])) {
  1040. // If we're not in the history view...
  1041. CourseManager :: display_special_courses(api_get_user_id(), $this->load_directories_preview);
  1042. CourseManager :: display_courses(api_get_user_id(), $this->load_directories_preview);
  1043. }
  1044. // Independent sessions.
  1045. foreach ($category['sessions'] as $session) {
  1046. // Don't show empty sessions.
  1047. if (count($session['courses']) < 1) {
  1048. continue;
  1049. }
  1050. // Courses inside the current session.
  1051. $date_session_start = $session['details']['date_start'];
  1052. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  1053. $session_now = time();
  1054. $html_courses_session = '';
  1055. $count_courses_session = 0;
  1056. foreach ($session['courses'] as $course) {
  1057. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  1058. $allowed_time = 0;
  1059. if ($date_session_start != '0000-00-00') {
  1060. if ($is_coach_course) {
  1061. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  1062. } else {
  1063. $allowed_time = api_strtotime($date_session_start);
  1064. }
  1065. }
  1066. if ($session_now > $allowed_time) {
  1067. //read only and accesible
  1068. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1069. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item', true, $this->load_directories_preview);
  1070. //$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true));
  1071. $html_courses_session .= $c[1];
  1072. }
  1073. $count_courses_session++;
  1074. }
  1075. }
  1076. if ($count_courses_session > 0) {
  1077. echo '<div class="userportal-session-item"><ul class="session_box">';
  1078. echo '<li class="session_box_title" id="session_'.$session['details']['id'].'" >';
  1079. echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1080. $s = Display :: get_session_title_box($session['details']['id']);
  1081. $extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  1082. /*if ($session['details']['visibility'] == 3) {
  1083. $session_link = $s['title'];
  1084. } else {*/
  1085. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  1086. //}
  1087. echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
  1088. if (api_is_platform_admin()) {
  1089. echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.
  1090. Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a></div>';
  1091. }
  1092. echo '</li>';
  1093. if (api_get_setting('hide_courses_in_sessions') == 'false') {
  1094. echo $html_courses_session;
  1095. }
  1096. echo '</ul></div>';
  1097. }
  1098. }
  1099. } else {
  1100. // All sessions included in.
  1101. if (!empty($category['details'])) {
  1102. $count_courses_session = 0;
  1103. $html_sessions = '';
  1104. foreach ($category['sessions'] as $session) {
  1105. // Don't show empty sessions.
  1106. if (count($session['courses']) < 1) {
  1107. continue;
  1108. }
  1109. $date_session_start = $session['details']['date_start'];
  1110. $days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
  1111. $session_now = time();
  1112. $html_courses_session = '';
  1113. $count = 0;
  1114. foreach ($session['courses'] as $course) {
  1115. $is_coach_course = api_is_coach($session['details']['id'], $course['code']);
  1116. if ($is_coach_course) {
  1117. $allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
  1118. } else {
  1119. $allowed_time = api_strtotime($date_session_start);
  1120. }
  1121. if ($session_now > $allowed_time) {
  1122. $c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
  1123. $html_courses_session .= $c[1];
  1124. $count_courses_session++;
  1125. $count++;
  1126. }
  1127. }
  1128. if ($count > 0) {
  1129. $s = Display :: get_session_title_box($session['details']['id']);
  1130. $html_sessions .= '<ul class="sub_session_box" id="session_'.$session['details']['id'].'">';
  1131. $html_sessions .= '<li class="sub_session_box_title" id="session_'.$session['details']['id'].'">';
  1132. //$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
  1133. $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'])) . ' ';
  1134. $session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
  1135. $html_sessions .= '<span>' . $session_link. ' </span> ';
  1136. $html_sessions .= '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  1137. $html_sessions .= (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
  1138. $html_sessions .= '</span>';
  1139. if (api_is_platform_admin()) {
  1140. $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>';
  1141. }
  1142. $html_sessions .= '</li>';
  1143. $html_sessions .= $html_courses_session;
  1144. $html_sessions .= '</ul>';
  1145. }
  1146. }
  1147. if ($count_courses_session > 0) {
  1148. echo '<div class="userportal-session-category-item" id="session_category_'.$category['details']['id'].'">';
  1149. echo '<div class="session_category_title_box" id="session_category_title_box_'.$category['details']['id'].'" style="color: #555555;">';
  1150. echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
  1151. if (api_is_platform_admin()) {
  1152. 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>';
  1153. }
  1154. echo '<span id="session_category_title">';
  1155. echo $category['details']['name'];
  1156. echo '</span>';
  1157. echo '<span style="padding-left: 10px; font-size: 90%; font-weight: normal;">';
  1158. if ($category['details']['date_end'] != '0000-00-00') {
  1159. printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
  1160. }
  1161. echo '</span></div>';
  1162. echo $html_sessions;
  1163. echo '</div>';
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. }