index.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.main
  5. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Refactoring
  6. * @todo check the different @todos in this page and really do them
  7. * @todo check if the news management works as expected
  8. */
  9. // Only this script should have this constant defined. This is used to activate the javascript that
  10. // gives the login name automatic focus in header.inc.html.
  11. /** @todo Couldn't this be done using the $HtmlHeadXtra array? */
  12. define('CHAMILO_HOMEPAGE', true);
  13. $language_file = array('courses', 'index');
  14. /* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
  15. // Maybe we should change this into an api function? an example: Coursemanager::unset();
  16. $cidReset = true;
  17. /* Included libraries */
  18. /** @todo Make all the library files consistent, use filename.lib.php and not filename.lib.inc.php. */
  19. require_once 'main/inc/global.inc.php';
  20. require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
  21. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  22. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  23. require_once 'main/chat/chat_functions.lib.php';
  24. $loginFailed = isset($_GET['loginFailed']) ? true : isset($loginFailed);
  25. $setting_show_also_closed_courses = api_get_setting('show_closed_courses') == 'true';
  26. // The section (for the tabs).
  27. $this_section = SECTION_CAMPUS;
  28. unset($_SESSION['this_section']);//for hmtl editor repository
  29. /* Action Handling */
  30. /** @todo Wouldn't it make more sense if this would be done in local.inc.php so that local.inc.php become the only place where authentication is done?
  31. * by doing this you could logout from any page instead of only from index.php. From the moment there is a logout=true in the url you will be logged out
  32. * this can be usefull when you are on an open course and you need to log in to edit something and you immediately want to check how anonymous users
  33. * will see it.
  34. */
  35. $my_user_id = api_get_user_id();
  36. if (!empty($_GET['logout'])) {
  37. logout();
  38. }
  39. /* Table definitions */
  40. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  41. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  42. $track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  43. /* Constants and CONFIGURATION parameters */
  44. /** @todo these configuration settings should move to the Chamilo config settings. */
  45. /** Defines wether or not anonymous visitors can see a list of the courses on the Chamilo homepage that are open to the world. */
  46. $_setting['display_courses_to_anonymous_users'] = 'true';
  47. /** @todo Remove this piece of code because this is not used. */
  48. if (isset($_user['user_id'])) {
  49. $nameTools = api_get_setting('siteName');
  50. }
  51. /* LOGIN */
  52. /**
  53. * @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
  54. * @todo Consider removing this piece of code because does nothing.
  55. */
  56. if (isset($_GET['submitAuth']) && $_GET['submitAuth'] == 1) {
  57. // nice lie!!!
  58. echo 'Attempted breakin - sysadmins notified.';
  59. session_destroy();
  60. die();
  61. }
  62. // Delete session neccesary for legal terms
  63. if (api_get_setting('allow_terms_conditions') == 'true') {
  64. unset($_SESSION['update_term_and_condition']);
  65. unset($_SESSION['info_current_user']);
  66. }
  67. /**
  68. * @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
  69. * @todo Check if this code is used. I think this code is never executed because after clicking the submit button
  70. * the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
  71. * on api_get_setting('page_after_login').
  72. */
  73. if (!empty($_POST['submitAuth'])) {
  74. // The user has been already authenticated, we are now to find the last login of the user.
  75. if (isset ($_user['user_id'])) {
  76. $sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
  77. FROM $track_login_table
  78. WHERE login_user_id = '".$_user['user_id']."'
  79. ORDER BY login_date DESC LIMIT 1";
  80. $result_last_login = Database::query($sql_last_login);
  81. if (!$result_last_login) {
  82. if (Database::num_rows($result_last_login) > 0) {
  83. $user_last_login_datetime = Database::fetch_array($result_last_login);
  84. $user_last_login_datetime = $user_last_login_datetime[0];
  85. api_session_register('user_last_login_datetime');
  86. }
  87. }
  88. Database::free_result($result_last_login);
  89. //event_login();
  90. if (api_is_platform_admin()) {
  91. // decode all open event informations and fill the track_c_* tables
  92. include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
  93. decodeOpenInfos();
  94. }
  95. }
  96. // End login -- if ($_POST['submitAuth'])
  97. } else {
  98. // Only if login form was not sent because if the form is sent the user was already on the page.
  99. event_open();
  100. }
  101. // The header.
  102. /*$header_title = get_lang('Homepage');
  103. //$sitename = api_get_setting('siteName');
  104. if (!api_get_user_id()) {
  105. $header_title = null;
  106. }*/
  107. $header_title = null;
  108. if (!api_is_anonymous()) {
  109. $header_title = " ";
  110. }
  111. $htmlHeadXtra[] = api_get_jquery_libraries_js(array('bxslider'));
  112. $htmlHeadXtra[] ='
  113. <script type="text/javascript">
  114. $(document).ready(function(){
  115. $("#slider").bxSlider({
  116. infiniteLoop : true,
  117. auto : true,
  118. pager : true,
  119. autoHover : true,
  120. pause : 10000
  121. });
  122. });
  123. </script>';
  124. Display::display_header($header_title);
  125. /* MAIN CODE */
  126. echo '<div id="content" class="maincontent">';
  127. // Plugins for loginpage_main AND campushomepage_main.
  128. if (!api_get_user_id()) {
  129. api_plugin('loginpage_main');
  130. } else {
  131. api_plugin('campushomepage_main');
  132. }
  133. $home = 'home/';
  134. if (api_get_multiple_access_url()) {
  135. $access_url_id = api_get_current_access_url_id();
  136. $url_info = api_get_access_url($access_url_id);
  137. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  138. $clean_url = replace_dangerous_char($url);
  139. $clean_url = str_replace('/', '-', $clean_url);
  140. $clean_url .= '/';
  141. $home_old = 'home/';
  142. // if $clean_url == "localhost/" means that the multiple URL was not well configured we don't rename the $home variable
  143. if ($clean_url != 'localhost/')
  144. $home = 'home/'.$clean_url;
  145. }
  146. // Including the page for the news
  147. $page_included = false;
  148. if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) {
  149. $open = @(string)file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']);
  150. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  151. echo $open;
  152. $page_included = true;
  153. } else {
  154. if (!empty($_SESSION['user_language_choice'])) {
  155. $user_selected_language = $_SESSION['user_language_choice'];
  156. } elseif (!empty($_SESSION['_user']['language'])) {
  157. $user_selected_language = $_SESSION['_user']['language'];
  158. } else {
  159. $user_selected_language = api_get_setting('platformLanguage');
  160. }
  161. if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) {
  162. if (file_exists($home.'home_top.html')) {
  163. $home_top_temp = file($home.'home_top.html');
  164. } else {
  165. $home_top_temp = file($home_old.'home_top.html');
  166. }
  167. $home_top_temp = implode('', $home_top_temp);
  168. } else {
  169. if (file_exists($home.'home_top_'.$user_selected_language.'.html')) {
  170. $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html');
  171. } else {
  172. $home_top_temp = file_get_contents($home.'home_top.html');
  173. }
  174. }
  175. if (trim($home_top_temp) == '' && api_is_platform_admin()) {
  176. $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
  177. }
  178. $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
  179. $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
  180. echo $open;
  181. }
  182. // Display courses and category list.
  183. if (!$page_included) {
  184. // Display System announcements
  185. $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
  186. $announcement = intval($announcement);
  187. if (isset($_user['user_id'])) {
  188. $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
  189. SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
  190. } else {
  191. SystemAnnouncementManager :: display_announcements_slider(VISIBLE_GUEST, $announcement);
  192. }
  193. if (api_get_setting('display_categories_on_homepage') == 'true') {
  194. echo '<div class="home_cats">';
  195. display_anonymous_course_list();
  196. echo '</div>';
  197. }
  198. }
  199. echo '</div>';
  200. echo '<div id="menu-wrapper">';
  201. if (!api_is_anonymous()) {
  202. // @todo move all this in a class/function
  203. //Always show the user image
  204. $img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
  205. $no_image = false;
  206. if ($img_array['file'] == 'unknown.jpg') {
  207. $no_image = true;
  208. }
  209. $img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
  210. $profile_content ='<div id="social_widget">';
  211. $profile_content .= '<div id="social_widget_image">';
  212. if (api_get_setting('allow_social_tool') == 'true') {
  213. if (!$no_image) {
  214. $profile_content .='<a href="'.api_get_path(WEB_PATH).'main/social/home.php"><img src="'.$img_array['file'].'" '.$img_array['style'].' border="1"></a>';
  215. } else {
  216. $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>';
  217. }
  218. } else {
  219. $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>';
  220. }
  221. $profile_content .= ' </div></div>';
  222. if (api_get_setting('allow_message_tool') == 'true') {
  223. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  224. // New messages.
  225. $number_of_new_messages = MessageManager::get_new_messages();
  226. // New contact invitations.
  227. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  228. // New group invitations sent by a moderator.
  229. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  230. $group_pending_invitations = count($group_pending_invitations);
  231. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  232. $cant_msg = '';
  233. if ($number_of_new_messages > 0) {
  234. $cant_msg = ' ('.$number_of_new_messages.')';
  235. }
  236. $profile_content .= '<div class="clear"></div>';
  237. $profile_content .= '<div class="message-content"><ul class="menulist">';
  238. $link = '';
  239. if (api_get_setting('allow_social_tool') == 'true') {
  240. $link = '?f=social';
  241. }
  242. $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>';
  243. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php'.$link.'" class="message-body">'.get_lang('Compose').' </a></li>';
  244. if (api_get_setting('allow_social_tool') == 'true') {
  245. if ($total_invitations == 0) {
  246. $total_invitations = '';
  247. } else {
  248. $total_invitations = ' ('.$total_invitations.')';
  249. }
  250. $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php" class="message-body">'.get_lang('PendingInvitations').' '.$total_invitations.' </a></li>';
  251. }
  252. $profile_content .= '</ul>';
  253. $profile_content .= '</div>';
  254. }
  255. //Profile content
  256. echo show_right_block(get_lang('Profile'), $profile_content);
  257. }
  258. // Display right menu: language form, login section + useful weblinks.
  259. display_anonymous_right_menu();
  260. echo '</div>';
  261. /* Footer */
  262. Display :: display_footer();
  263. /* Functions */
  264. /**
  265. * This function handles the logout and is called whenever there is a $_GET['logout']
  266. *
  267. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  268. */
  269. function logout() {
  270. global $_configuration, $extAuthSource;
  271. // Variable initialisation.
  272. $query_string = '';
  273. if (!empty($_SESSION['user_language_choice'])) {
  274. $query_string = '?language='.$_SESSION['user_language_choice'];
  275. }
  276. // Database table definition.
  277. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  278. // Selecting the last login of the user.
  279. $uid = intval($_GET['uid']);
  280. $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";
  281. $q_last_connection = Database::query($sql_last_connection);
  282. if (Database::num_rows($q_last_connection) > 0) {
  283. $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
  284. }
  285. if (!isset($_SESSION['login_as'])) {
  286. $current_date = date('Y-m-d H:i:s', time());
  287. $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'";
  288. Database::query($s_sql_update_logout_date);
  289. }
  290. LoginDelete($uid); // From inc/lib/online.inc.php - removes the "online" status.
  291. // The following code enables the use of an external logout function.
  292. // Example: define a $extAuthSource['ldap']['logout'] = 'file.php' in configuration.php.
  293. // Then a function called ldap_logout() inside that file
  294. // (using *authent_name*_logout as the function name) and the following code
  295. // will find and execute it.
  296. $uinfo = api_get_user_info($uid);
  297. if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) {
  298. if (is_array($extAuthSource[$uinfo['auth_source']])) {
  299. $subarray = $extAuthSource[$uinfo['auth_source']];
  300. if (!empty($subarray['logout']) && file_exists($subarray['logout'])) {
  301. include_once ($subarray['logout']);
  302. $logout_function = $uinfo['auth_source'].'_logout';
  303. if (function_exists($logout_function)) {
  304. $logout_function($uinfo);
  305. }
  306. }
  307. }
  308. }
  309. exit_of_chat($uid);
  310. api_session_destroy();
  311. header("Location: index.php$query_string");
  312. exit();
  313. }
  314. /**
  315. * This function checks if there are courses that are open to the world in the platform course categories (=faculties)
  316. *
  317. * @param unknown_type $category
  318. * @return boolean
  319. */
  320. function category_has_open_courses($category) {
  321. global $setting_show_also_closed_courses;
  322. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  323. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  324. $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
  325. $sql_result = Database::query($sql_query);
  326. while ($course = Database::fetch_array($sql_result)) {
  327. if (!$setting_show_also_closed_courses) {
  328. if ((api_get_user_id() > 0
  329. && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  330. || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  331. return true; //at least one open course
  332. }
  333. } else {
  334. if (isset($course['visibility'])) {
  335. return true; // At least one course (it does not matter weither it's open or not because $setting_show_also_closed_courses = true).
  336. }
  337. }
  338. }
  339. return false;
  340. }
  341. /**
  342. * Display create course link
  343. */
  344. function display_create_course_link() {
  345. echo '<li><a href="main/create_course/add_course.php">'.
  346. (api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'</a></li>';
  347. }
  348. /**
  349. * Display edit course list links
  350. */
  351. function display_edit_course_list_links() {
  352. echo '<li><a href="main/auth/courses.php">'.get_lang('CourseManagement').'</a></li>';
  353. }
  354. /**
  355. * Display dashboard link
  356. */
  357. function display_dashboard_link() {
  358. echo '<li><a href="main/dashboard/index.php">'.get_lang('Dashboard').'</a></li>';
  359. }
  360. /**
  361. * Displays the right-hand menu for anonymous users:
  362. * login form, useful links, help section
  363. * Warning: function defines globals
  364. * @version 1.0.1
  365. * @todo does $_plugins need to be global?
  366. */
  367. function display_anonymous_right_menu() {
  368. global $loginFailed, $_plugins, $_user, $menu_navigation, $home, $home_old;
  369. $platformLanguage = api_get_setting('platformLanguage');
  370. $sys_path = api_get_path(SYS_PATH);
  371. $user_selected_language = api_get_interface_language();
  372. $display_add_course_link= api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
  373. $current_user_id = api_get_user_id();
  374. if (!empty($current_user_id)) {
  375. // tabs that are deactivated are added here
  376. $show_menu = false;
  377. $show_create_link = false;
  378. $show_course_link = false;
  379. if ($display_add_course_link) {
  380. //display_create_course_link();
  381. $show_menu = true;
  382. $show_create_link = true;
  383. }
  384. if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
  385. $show_menu = true;
  386. $show_course_link = true;
  387. } else {
  388. if (api_get_setting('allow_students_to_browse_courses') == 'true') {
  389. $show_menu = true;
  390. $show_course_link = true;
  391. }
  392. }
  393. if ($show_menu && ($show_create_link || $show_course_link )) {
  394. $show_menu = true;
  395. } else {
  396. $show_menu = false;
  397. }
  398. }
  399. if (!($current_user_id) || api_is_anonymous($current_user_id) || $show_menu) {
  400. echo '<div class="menu" id="menu">';
  401. }
  402. if (!($current_user_id) || api_is_anonymous($current_user_id) ) {
  403. // Only display if the user isn't logged in.
  404. api_display_language_form(true);
  405. echo '<br />';
  406. display_login_form();
  407. if ($loginFailed) {
  408. echo '<br />';
  409. handle_login_failed();
  410. }
  411. if (api_get_setting('allow_lostpassword') == 'true' || api_get_setting('allow_registration') == 'true') {
  412. echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
  413. if (api_get_setting('allow_registration') != 'false') {
  414. echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
  415. }
  416. if (api_get_setting('allow_lostpassword') == 'true') {
  417. display_lost_password_info();
  418. }
  419. echo '</ul></div>';
  420. }
  421. if (api_number_of_plugins('loginpage_menu') > 0) {
  422. echo '<div class="note" style="background: none">';
  423. api_plugin('loginpage_menu');
  424. echo '</div>';
  425. }
  426. }
  427. // My Account section.
  428. if ($show_menu) {
  429. echo '<div class="menusection">';
  430. echo '<span class="menusectioncaption">'.get_lang('MenuUser').'</span>';
  431. echo '<ul class="menulist">';
  432. if ($show_create_link) {
  433. display_create_course_link();
  434. }
  435. if ($show_course_link) {
  436. if (!api_is_drh() && !api_is_session_admin()) {
  437. display_edit_course_list_links();
  438. } else {
  439. display_dashboard_link();
  440. }
  441. }
  442. echo '</ul></div>';
  443. }
  444. if (!($current_user_id) || api_is_anonymous($current_user_id) || $show_menu) {
  445. echo '</div>';
  446. }
  447. // Notice
  448. $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html');
  449. if (empty($home_notice)) {
  450. $home_notice = @(string)file_get_contents($sys_path.$home.'home_notice.html');
  451. }
  452. if (!empty($home_notice)) {
  453. $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
  454. echo show_right_block('', $home_notice, 'note');
  455. }
  456. if (isset($_SESSION['_user']['user_id']) && $_SESSION['_user']['user_id'] != 0) {
  457. // Deleting the myprofile link.
  458. if (api_get_setting('allow_social_tool') == 'true') {
  459. unset($menu_navigation['myprofile']);
  460. }
  461. if (!empty($menu_navigation)) {
  462. $content = '<ul class="menulist">';
  463. foreach ($menu_navigation as $section => $navigation_info) {
  464. $current = $section == $GLOBALS['this_section'] ? ' id="current"' : '';
  465. $content .='<li'.$current.'><a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a></li>';
  466. }
  467. $content .= '</ul>';
  468. echo show_right_block(get_lang('MainNavigation'), $content);
  469. }
  470. }
  471. // Help section.
  472. /* Hide right menu "general" and other parts on anonymous right menu. */
  473. if (!isset($user_selected_language)) {
  474. $user_selected_language = $platformLanguage;
  475. }
  476. $home_menu = @(string)file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
  477. if (!empty($home_menu)) {
  478. $home_menu_content .= '<ul class="menulist">';
  479. $home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
  480. $home_menu_content .= '</ul>';
  481. echo show_right_block(get_lang('MenuGeneral'), $home_menu_content);
  482. }
  483. //Plugin
  484. if ($_user['user_id'] && api_number_of_plugins('campushomepage_menu') > 0) {
  485. ob_start();
  486. api_plugin('campushomepage_menu');
  487. $plugin_content = ob_get_contents();
  488. ob_end_clean();
  489. echo show_right_block('', $plugin_content);
  490. }
  491. }
  492. /**
  493. * Reacts on a failed login:
  494. * Displays an explanation with a link to the registration form.
  495. *
  496. * @version 1.0.1
  497. */
  498. function handle_login_failed() {
  499. if (!isset($_GET['error'])) {
  500. $message = get_lang('InvalidId');
  501. if (api_is_self_registration_allowed()) {
  502. $message = get_lang('InvalidForSelfRegistration');
  503. }
  504. } else {
  505. switch ($_GET['error']) {
  506. case '':
  507. $message = get_lang('InvalidId');
  508. if (api_is_self_registration_allowed()) {
  509. $message = get_lang('InvalidForSelfRegistration');
  510. }
  511. break;
  512. case 'account_expired':
  513. $message = get_lang('AccountExpired');
  514. break;
  515. case 'account_inactive':
  516. $message = get_lang('AccountInactive');
  517. break;
  518. case 'user_password_incorrect':
  519. $message = get_lang('InvalidId');
  520. break;
  521. case 'access_url_inactive':
  522. $message = get_lang('AccountURLInactive');
  523. break;
  524. }
  525. }
  526. echo '<div id="login_fail">'.$message.'</div>';
  527. }
  528. /**
  529. * Adds a form to let users login
  530. * @version 1.1
  531. */
  532. function display_login_form() {
  533. $form = new FormValidator('formLogin');
  534. $form->addElement('text', 'login', get_lang('UserName'), array('size' => 17));
  535. $form->addElement('password', 'password', get_lang('Pass'), array('size' => 17));
  536. $form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'login'));
  537. $renderer =& $form->defaultRenderer();
  538. $renderer->setElementTemplate('<div><label>{label}</label></div><div>{element}</div>');
  539. $form->display();
  540. if (api_get_setting('openid_authentication') == 'true') {
  541. include_once 'main/auth/openid/login.php';
  542. echo '<div>'.openid_form().'</div>';
  543. }
  544. }
  545. /**
  546. * Displays a link to the lost password section
  547. */
  548. function display_lost_password_info() {
  549. echo '<li><a href="main/auth/lostPassword.php">'.get_lang('LostPassword').'</a></li>';
  550. }
  551. /**
  552. * Display list of courses in a category.
  553. * (for anonymous users)
  554. *
  555. * @version 1.1
  556. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University - refactoring and code cleaning
  557. */
  558. function display_anonymous_course_list() {
  559. $ctok = $_SESSION['sec_token'];
  560. $stok = Security::get_token();
  561. // Initialization.
  562. $user_identified = (api_get_user_id() > 0 && !api_is_anonymous());
  563. $web_course_path = api_get_path(WEB_COURSE_PATH);
  564. $category = Database::escape_string($_GET['category']);
  565. global $setting_show_also_closed_courses;
  566. // Database table definitions.
  567. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  568. $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  569. $platformLanguage = api_get_setting('platformLanguage');
  570. // Get list of courses in category $category.
  571. $sql_get_course_list = "SELECT * FROM $main_course_table cours
  572. WHERE category_code = '".Database::escape_string($_GET['category'])."'
  573. ORDER BY title, UPPER(visual_code)";
  574. // Showing only the courses of the current access_url_id.
  575. global $_configuration;
  576. if ($_configuration['multiple_access_urls']) {
  577. $url_access_id = api_get_current_access_url_id();
  578. if ($url_access_id != -1) {
  579. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  580. $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course
  581. ON (url_rel_course.course_code=course.code)
  582. WHERE access_url_id = $url_access_id AND category_code = '".Database::escape_string($_GET['category'])."' ORDER BY title, UPPER(visual_code)";
  583. }
  584. }
  585. // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
  586. $sql_result_courses = Database::query($sql_get_course_list);
  587. while ($course_result = Database::fetch_array($sql_result_courses)) {
  588. $course_list[] = $course_result;
  589. }
  590. $platform_visible_courses = '';
  591. // $setting_show_also_closed_courses
  592. if ($user_identified) {
  593. if ($setting_show_also_closed_courses) {
  594. $platform_visible_courses = '';
  595. } else {
  596. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )";
  597. }
  598. } else {
  599. if ($setting_show_also_closed_courses) {
  600. $platform_visible_courses = '';
  601. } else {
  602. $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )";
  603. }
  604. }
  605. $sqlGetSubCatList = "
  606. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  607. FROM $main_category_table t1
  608. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  609. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  610. WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
  611. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  612. // Showing only the category of courses of the current access_url_id.
  613. global $_configuration;
  614. if ($_configuration['multiple_access_urls']) {
  615. $url_access_id = api_get_current_access_url_id();
  616. if ($url_access_id != -1) {
  617. $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  618. $sqlGetSubCatList = "
  619. SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
  620. FROM $main_category_table t1
  621. LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
  622. LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code $platform_visible_courses)
  623. INNER JOIN $tbl_url_rel_course as url_rel_course
  624. ON (url_rel_course.course_code=t3.code)
  625. WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? "IS NULL" : "='$category'")."
  626. GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name";
  627. }
  628. }
  629. $resCats = Database::query($sqlGetSubCatList);
  630. $thereIsSubCat = false;
  631. if (Database::num_rows($resCats) > 0) {
  632. $htmlListCat = '<h4 style="margin-top: 0px;">'.get_lang('CatList').'</h4><ul>';
  633. while ($catLine = Database::fetch_array($resCats)) {
  634. if ($catLine['code'] != $category) {
  635. $category_has_open_courses = category_has_open_courses($catLine['code']);
  636. if ($category_has_open_courses) {
  637. // The category contains courses accessible to anonymous visitors.
  638. $htmlListCat .= '<li>';
  639. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  640. if (api_get_setting('show_number_of_courses') == 'true') {
  641. $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')';
  642. }
  643. $htmlListCat .= "</li>\n";
  644. $thereIsSubCat = true;
  645. } elseif ($catLine['children_count'] > 0) {
  646. // The category has children, subcategories.
  647. $htmlListCat .= '<li>';
  648. $htmlListCat .= '<a href="'.api_get_self().'?category='.$catLine['code'].'">'.$catLine['name'].'</a>';
  649. $htmlListCat .= "</li>\n";
  650. $thereIsSubCat = true;
  651. }
  652. /* End changed code to eliminate the (0 courses) after empty categories. */
  653. elseif (api_get_setting('show_empty_course_categories') == 'true') {
  654. $htmlListCat .= '<li>';
  655. $htmlListCat .= $catLine['name'];
  656. $htmlListCat .= "</li>\n";
  657. $thereIsSubCat = true;
  658. } // Else don't set thereIsSubCat to true to avoid printing things if not requested.
  659. } else {
  660. $htmlTitre = '<p>';
  661. if (api_get_setting('show_back_link_on_top_of_tree') == 'true') {
  662. $htmlTitre .= '<a href="'.api_get_self().'">&lt;&lt; '.get_lang('BackToHomePage').'</a>';
  663. }
  664. if (!is_null($catLine['parent_id']) || (api_get_setting('show_back_link_on_top_of_tree') != 'true' && !is_null($catLine['code']))) {
  665. $htmlTitre .= '<a href="'.api_get_self().'?category='.$catLine['parent_id'].'">&lt;&lt; '.get_lang('Up').'</a>';
  666. }
  667. $htmlTitre .= "</p>\n";
  668. if ($category != "" && !is_null($catLine['code'])) {
  669. $htmlTitre .= '<h3>'.$catLine['name']."</h3>\n";
  670. } else {
  671. $htmlTitre .= '<h3>'.get_lang('Categories')."</h3>\n";
  672. }
  673. }
  674. }
  675. $htmlListCat .= "</ul>\n";
  676. }
  677. echo $htmlTitre;
  678. if ($thereIsSubCat) {
  679. echo $htmlListCat;
  680. }
  681. while ($categoryName = Database::fetch_array($resCats)) {
  682. echo '<h3>', $categoryName['name'], "</h3>\n";
  683. }
  684. $numrows = Database::num_rows($sql_result_courses);
  685. $courses_list_string = '';
  686. $courses_shown = 0;
  687. if ($numrows > 0) {
  688. if ($thereIsSubCat) {
  689. $courses_list_string .= "<hr size=\"1\" noshade=\"noshade\">\n";
  690. }
  691. $courses_list_string .= '<h4 style="margin-top: 0px;">'.get_lang('CourseList')."</h4>\n<ul>\n";
  692. if (api_get_user_id()) {
  693. $courses_of_user = get_courses_of_user(api_get_user_id());
  694. }
  695. foreach ($course_list as $course) {
  696. // $setting_show_also_closed_courses
  697. if (!$setting_show_also_closed_courses) {
  698. // If we do not show the closed courses
  699. // we only show the courses that are open to the world (to everybody)
  700. // and the courses that are open to the platform (if the current user is a registered user.
  701. if( ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM) || ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)) {
  702. $courses_shown++;
  703. $courses_list_string .= "<li>\n";
  704. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">'.$course['title'].'</a><br />';
  705. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  706. $courses_list_string .= $course['visual_code'];
  707. }
  708. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  709. $courses_list_string .= ' - ';
  710. }
  711. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  712. $courses_list_string .= $course['tutor_name'];
  713. }
  714. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  715. $courses_list_string .= ' - '.$course['course_language'];
  716. }
  717. $courses_list_string .= "</li>\n";
  718. }
  719. }
  720. // We DO show the closed courses.
  721. // The course is accessible if (link to the course homepage):
  722. // 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);
  723. // 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);
  724. // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED;
  725. // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting);
  726. // 5. the user is the platform admin api_is_platform_admin().
  727. //
  728. else {
  729. $courses_shown++;
  730. $courses_list_string .= "<li>\n";
  731. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  732. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  733. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  734. || $courses_of_user[$course['code']]['status'] == '1'
  735. || api_is_platform_admin()) {
  736. $courses_list_string .= '<a href="'.$web_course_path.$course['directory'].'/">';
  737. }
  738. $courses_list_string .= $course['title'];
  739. if ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD
  740. || ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM)
  741. || ($user_identified && key_exists($course['code'], $courses_of_user) && $course['visibility'] != COURSE_VISIBILITY_CLOSED)
  742. || $courses_of_user[$course['code']]['status'] == '1'
  743. || api_is_platform_admin()) {
  744. $courses_list_string .= '</a><br />';
  745. }
  746. if (api_get_setting('display_coursecode_in_courselist') == 'true') {
  747. $courses_list_string .= ' '.$course['visual_code'];
  748. }
  749. if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') {
  750. $courses_list_string .= ' - ';
  751. }
  752. if (api_get_setting('display_teacher_in_courselist') == 'true') {
  753. $courses_list_string .= $course['tutor_name'];
  754. }
  755. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  756. $courses_list_string .= ' - '.$course['course_language'];
  757. }
  758. if (api_get_setting('show_different_course_language') == 'true' && $course['course_language'] != api_get_setting('platformLanguage')) {
  759. $courses_list_string .= ' - '.$course['course_language'];
  760. }
  761. // We display a subscription link if:
  762. // 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
  763. // 2.
  764. if ($user_identified && !key_exists($course['code'], $courses_of_user)) {
  765. if ($course['subscribe'] == '1') {
  766. $courses_list_string .= '<form action="main/auth/courses.php?action=subscribe&category='.Security::remove_XSS($_GET['category']).'" method="post">';
  767. $courses_list_string .= '<input type="hidden" name="sec_token" value="'.$stok.'">';
  768. $courses_list_string .= '<input type="hidden" name="subscribe" value="'.$course['code'].'" />';
  769. $courses_list_string .= '<input type="image" name="unsub" src="main/img/enroll.gif" alt="'.get_lang('Subscribe').'" />'.get_lang('Subscribe').'</form>';
  770. } else {
  771. $courses_list_string .= '<br />'.get_lang('SubscribingNotAllowed');
  772. }
  773. }
  774. $courses_list_string .= "</li>\n";
  775. }
  776. }
  777. $courses_list_string .= "</ul>\n";
  778. } else {
  779. //echo '<blockquote>', get_lang('_No_course_publicly_available'), "</blockquote>\n";
  780. }
  781. if ($courses_shown > 0) { // Only display the list of courses and categories if there was more than
  782. // 0 courses visible to the world (we're in the anonymous list here).
  783. echo $courses_list_string;
  784. }
  785. if ($category != '') {
  786. echo '<p><a href="'.api_get_self().'"> ', Display :: return_icon('back.png', get_lang('BackToHomePage')), get_lang('BackToHomePage'), '</a></p>', "\n";
  787. }
  788. }
  789. /**
  790. * retrieves all the courses that the user has already subscribed to
  791. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  792. * @param int $user_id: the id of the user
  793. * @return array an array containing all the information of the courses of the given user
  794. */
  795. function get_courses_of_user($user_id) {
  796. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  797. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  798. // Secondly we select the courses that are in a category (user_course_cat <> 0) and sort these according to the sort of the category
  799. $user_id = intval($user_id);
  800. $sql_select_courses = "SELECT course.code k, course.visual_code vc, course.subscribe subscr, course.unsubscribe unsubscr,
  801. course.title i, course.tutor_name t, course.db_name db, course.directory dir, course_rel_user.status status,
  802. course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat
  803. FROM $table_course course,
  804. $table_course_user course_rel_user
  805. WHERE course.code = course_rel_user.course_code
  806. AND course_rel_user.user_id = '".$user_id."'
  807. AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  808. ORDER BY course_rel_user.sort ASC";
  809. $result = Database::query($sql_select_courses);
  810. $courses = array();
  811. while ($row = Database::fetch_array($result)) {
  812. // We only need the database name of the course.
  813. $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']);
  814. }
  815. return $courses;
  816. }
  817. function show_right_block($title, $content, $class = '') {
  818. $html = '';
  819. $html.= '<div id="menu" class="menu">';
  820. $html.= '<div class="menusection '.$class.' ">';
  821. if (!empty($title)) {
  822. $html.= '<span class="menusectioncaption">'.$title.'</span>';
  823. }
  824. $html.= $content;
  825. $html.= '</div>';
  826. $html.= '</div>';
  827. return $html;
  828. }