userportal.lib.php 52 KB

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