123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 |
- <?php
- /*
- ==============================================================================
- Dokeos - elearning and course management software
- Copyright (c) 2004-2005 Dokeos S.A.
- Copyright (c) 2003 Ghent University (UGent)
- Copyright (c) 2001 Universite catholique de Louvain (UCL)
- Copyright (c) various contributors
- For a full list of contributors, see "credits.txt".
- The full license can be read in "license.txt".
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- See the GNU General Public License for more details.
- Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
- Mail: info@dokeos.com
- ==============================================================================
- */
- /**
- ==============================================================================
- * This is the index file displayed when a user arrives at Dokeos.
- *
- * It dispalys:
- * - tree of courses and categories
- * - login form
- * - public menu
- *
- * Search for
- * CONFIGURATION parameters
- * to modify settings
- *
- * @todo rewrite code to separate display, logic, database code
- * @package dokeos.main
- ==============================================================================
- */
- /*
- ==============================================================================
- INIT SECTION
- ==============================================================================
- */
- // only this script should have this constant defined
- define('DOKEOS_HOMEPAGE', true);
- // Don't change these settings
- define("SCRIPTVAL_No", 0);
- define("SCRIPTVAL_InCourseList", 1);
- define("SCRIPTVAL_UnderCourseList", 2);
- define("SCRIPTVAL_Both", 3);
- define("SCRIPTVAL_NewEntriesOfTheDay", 4);
- define("SCRIPTVAL_NewEntriesOfTheDayOfLastLogin", 5);
- define("SCRIPTVAL_NoTimeLimit", 6);
- // End 'don't change' section
- $langFile = array ('courses', 'index');
- $cidReset = true; /* Flag forcing the 'current course' reset,
- as we're not inside a course anymore */
- /*
- -----------------------------------------------------------
- Included libraries
- -----------------------------------------------------------
- */
- //this includes main_api too:
- include_once ('./main/inc/global.inc.php');
- $this_section = SECTION_CAMPUS;
- include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
- include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
- include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
- include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
- include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
- include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
- if ($_GET['logout'])
- {
- $query_string='';
- if(!empty($_SESSION['user_language_choice']))
- {
- $query_string='?language='.$_SESSION['user_language_choice'];
- }
-
-
- //LoginDelete($_uid, $statsDbName);
- LoginDelete($_GET["uid"], $statsDbName);
- api_session_destroy();
- header("Location: index.php$query_string");
- exit();
- }
- /*
- -----------------------------------------------------------
- Table definitions
- -----------------------------------------------------------
- */
- //new table definitions, using database library
- //these already have backticks around them!
- $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
- $main_category_table = Database :: get_main_table(MAIN_CATEGORY_TABLE);
- $track_login_table = Database :: get_statistic_table(STATISTIC_TRACK_E_LOGIN_TABLE);
- /*
- -----------------------------------------------------------
- Constants and CONFIGURATION parameters
- -----------------------------------------------------------
- */
- // ---- Category list options ----
- /** defines wether or not anonymous visitors can see a list of the courses on
- the Dokeos homepage that are open to the world */
- define('DISPLAY_COURSES_TO_ANONYMOUS_USERS', true);
- define('CONFVAL_showNodeEmpty', true);
- define('CONFVAL_showNumberOfChild', false); // actually count are only for direct children
- define('CONFVAL_ShowLinkBackToTopOfTree', false);
- // ---- Course list options ----
- define("CONFVAL_showCourseLangIfNotSameThatPlatform", TRUE);
- // Preview of course content
- // to disable all: set CONFVAL_maxTotalByCourse = 0
- // to enable all: set e.g. CONFVAL_maxTotalByCourse = 5
- // by default disabled since what's new icons are better (see function display_digest() )
- define("CONFVAL_maxValvasByCourse", 2); // Maximum number of entries
- define("CONFVAL_maxAgendaByCourse", 2); // collected from each course
- define("CONFVAL_maxTotalByCourse", 0); // and displayed in summary.
- define("CONFVAL_NB_CHAR_FROM_CONTENT", 80);
- // Order to sort data
- $orderKey = array('keyTools', 'keyTime', 'keyCourse'); // default "best" Choice
- //$orderKey = array('keyTools', 'keyCourse', 'keyTime');
- //$orderKey = array('keyCourse', 'keyTime', 'keyTools');
- //$orderKey = array('keyCourse', 'keyTools', 'keyTime');
- define('CONFVAL_showExtractInfo', SCRIPTVAL_UnderCourseList);
- // SCRIPTVAL_InCourseList // best choice if $orderKey[0] == 'keyCourse'
- // SCRIPTVAL_UnderCourseList // best choice
- // SCRIPTVAL_Both // probably only for debug
- //$dateFormatForInfosFromCourses = $dateFormatShort;
- $dateFormatForInfosFromCourses = $dateFormatLong;
- //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
- //define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
- define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
- if (isset ($_uid))
- {
- $nameTools = api_get_setting('siteName');
- }
- /*
- -----------------------------------------------------------
- Check configuration parameters integrity
- -----------------------------------------------------------
- */
- if (CONFVAL_showExtractInfo != SCRIPTVAL_UnderCourseList and $orderKey[0] != "keyCourse")
- {
- // CONFVAL_showExtractInfo must be SCRIPTVAL_UnderCourseList to accept $orderKey[0] !="keyCourse"
- if (DEBUG || api_is_platform_admin()) // Show bug if admin. Else force a new order
- die("
- <strong>
- config error:".__FILE__."</strong>
- <br/>
- set
- <ul>
- <li>
- CONFVAL_showExtractInfo=SCRIPTVAL_UnderCourseList
- (actually : ".CONFVAL_showExtractInfo.")
- </li>
- </ul>
- or
- <ul>
- <li>
- \$orderKey[0] !=\"keyCourse\"
- (actually : ".$orderKey[0].")
- </li>
- </ul>");
- else
- {
- $orderKey = array ("keyCourse", "keyTools", "keyTime");
- }
- }
- /*
- ==============================================================================
- LOGIN
- ==============================================================================
- */
- if ($_GET["submitAuth"] == 1)
- {
- echo "Attempted breakin - sysadmins notified.";
- session_destroy();
- die();
- }
- if ($_POST["submitAuth"])
- {
- // To ensure legacy compatibility, we set the following variables.
- // But they should be removed at last.
- $uid = $_uid;
- $lastname = $_user['lastName'];
- $firstname = $_user['firstName'];
- $email = $_user['mail'];
- $status = $uData['status'];
- if (isset ($_uid))
- {
- $sqlLastLogin = "SELECT UNIX_TIMESTAMP(login_date)
- FROM $track_login_table
- WHERE login_user_id = '$_uid'
- ORDER BY login_date DESC LIMIT 1";
- $resLastLogin = api_sql_query($sqlLastLogin, __FILE__, __LINE__);
- if (!$resLastLogin)
- if (mysql_num_rows($resLastLogin) > 0)
- {
- $user_last_login_datetime = mysql_fetch_array($resLastLogin);
- $user_last_login_datetime = $user_last_login_datetime[0];
- api_session_register('user_last_login_datetime');
- }
- mysql_free_result($resLastLogin);
- event_login();
- if (api_is_platform_admin())
- {
- // decode all open event informations and fill the track_c_* tables
- include (api_get_path(LIBRARY_PATH)."stats.lib.inc.php");
- decodeOpenInfos();
- }
- }
- } // end login -- if($submit)
- else
- {
- // only if login form was not sent because if the form is sent the user was
- // already on the page.
- event_open();
- }
- /*
- -----------------------------------------------------------
- Header
- include the HTTP, HTML headers plus the top banner
- -----------------------------------------------------------
- */
- $help = "Clar";
- Display :: display_header('', $help);
- /*
- ==============================================================================
- FUNCTIONS
- display_anonymous_right_menu()
- display_anonymous_course_list()
- display_login_form()
- handle_login_failed()
- display_lost_password_info()
- ==============================================================================
- */
- /*
- -----------------------------------------------------------
- Display functions
- -----------------------------------------------------------
- */
- /**
- * Displays the right-hand menu for anonymous users:
- * login form, useful links, help section
- * Warning: function defines globals
- * @version 1.0.1
- */
- function display_anonymous_right_menu()
- {
- global $loginFailed, $_plugins;
- $platformLanguage = api_get_setting('platformLanguage');
- $_uid = api_get_user_id();
- if ( !(isset($_uid) && $_uid) ) // only display if the user isn't logged in
- {
- api_display_language_form();
- display_login_form();
-
- if ($loginFailed)
- handle_login_failed();
- if (api_get_setting('allow_lostpassword') == 'true' OR api_get_setting('allow_registration') == 'true')
- {
- echo '<div class="menusection"><span class="menusectioncaption">'.get_lang('MenuUser').'</span><ul class="menulist">';
- if (get_setting('allow_registration') <> 'false')
- {
- echo '<li><a href="main/auth/inscription.php">'.get_lang('Reg').'</a></li>';
- }
- if (get_setting('allow_lostpassword') == 'true')
- {
- display_lost_password_info();
- }
- echo '</ul></div>';
- }
- api_plugin('loginpage_menu');
- }
-
- /*** hide right menu "general" and other parts on anonymous right menu *****/
- echo "<div class=\"menusection\">", "<span class=\"menusectioncaption\">".get_lang("MenuGeneral")."</span>";
- echo "<ul class=\"menulist\">";
- $user_selected_language = $_SESSION["user_language_choice"];
- if (!isset ($user_selected_language))
- $user_selected_language = $platformLanguage;
- if(!file_exists('home/home_menu_'.$user_selected_language.'.html'))
- {
- include ('home/home_menu.html');
- }
- else
- {
- include('home/home_menu_'.$user_selected_language.'.html');
- }
- echo '</ul>';
- echo '</div>';
-
- if ($_uid)
- {
- api_plugin('campushomepage_menu');
- }
- /**** use this comment to hide notice file section from right menu ****
- echo '<div class="note">';
- // includes for any files to be displayed below anonymous right menu
- if(!file_exists('home/home_notice_'.$user_selected_language.'.html'))
- {
- include ('home/home_notice.html');
- }
- else
- {
- include('home/home_notice_'.$user_selected_language.'.html');
- }
- echo '</div>';
- **** end of hide various right menu items on anonymous right menu ****/
- }
- /**
- * Reacts on a failed login:
- * displays an explanation with
- * a link to the registration form.
- *
- * @version 1.0.1
- */
- function handle_login_failed()
- {
- switch ($_GET['error'])
- {
- case '':
- $message = get_lang("InvalidId");
- if (api_is_self_registration_allowed())
- {
- $message = get_lang("InvalidForSelfRegistration");
- }
- break;
- case 'account_expired':
- $message=get_lang('AccountExpired');
- break;
- case 'account_inactive':
- $message=get_lang('AccountInactive');
- break;
- case 'user_password_incorrect':
- $message=get_lang('InvalidId');
- break;
- }
- echo "<div id=\"login_fail\">".$message."</div>";
- }
- /**
- * Adds a form to let users login
- * @version 1.1
- */
- function display_login_form()
- {
- $form = new FormValidator('formLogin');
- $form->addElement('static',null,null,get_lang('UserName'));
- $form->addElement('text','login','',array('size'=>15));
- $form->addElement('static',null,null,get_lang('Pass'));
- $form->addElement('password','password','',array('size'=>15));
- $form->addElement('submit','submitAuth',get_lang('Ok'));
- $form->display();
- }
- /**
- * Displays a link to the lost password section
- */
- function display_lost_password_info()
- {
- echo "<li><a href=\"main/auth/lostPassword.php\">".get_lang("LostPassword")."</a></li>";
- }
- /**
- * Display list of courses in a category.
- * (for anonymous users)
- *
- * Warning: this function defines globals.
- * @version 1.0
- */
- function display_anonymous_course_list()
- {
- //init
- global $coursesRepositoryWeb;
- $web_course_path = api_get_path(WEB_COURSE_PATH);
- $category = $_GET["category"];
- $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
- $main_category_table = Database :: get_main_table(MAIN_CATEGORY_TABLE);
- $platformLanguage = api_get_setting('platformLanguage');
- //get list of courses in category $category
- $sql_get_course_list = "SELECT * FROM $main_course_table cours
- WHERE category_code = '".$category."'
- ORDER BY UPPER(visual_code)";
- //removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."'
- $sql_result_courses = api_sql_query($sql_get_course_list, __FILE__, __LINE__);
-
- while ($course_result = mysql_fetch_array($sql_result_courses))
- {
- $course_list[] = $course_result;
- }
-
- $sqlGetSubCatList = "
- SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse
- FROM $main_category_table t1
- LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id
- LEFT JOIN $main_course_table t3 ON (t3.category_code=t1.code AND t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."')
- WHERE t1.parent_id ". (empty ($category) ? "IS NULL" : "='$category'")."
- GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos";
-
- $resCats = api_sql_query($sqlGetSubCatList, __FILE__, __LINE__);
- $thereIsSubCat = FALSE;
- if (mysql_num_rows($resCats) > 0)
- {
- $htmlListCat = "<h4 style=\"margin-top: 0px;\">".get_lang("CatList")."</h4>"."<ul>";
- while ($catLine = mysql_fetch_array($resCats))
- {
- if ($catLine['code'] != $category)
- {
- $htmlListCat .= "<li>";
-
- $category_has_open_courses = category_has_open_courses($catLine['code']);
- if ($category_has_open_courses)
- {
- //the category contains courses accessible to anonymous visitors
- $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
- if (CONFVAL_showNumberOfChild)
- {
- $htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
- }
- }
- elseif ($catLine['children_count'] > 0)
- {
- //the category has children, subcategories
- $htmlListCat .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\">".$catLine['name']."</a>";
- }
- /************************************************************************
- end changed code to eliminate the (0 courses) after empty categories
- ************************************************************************/
- elseif (CONFVAL_showNodeEmpty)
- {
- $htmlListCat .= $catLine['name'];
- }
- $htmlListCat .= "</li>\n";
- $thereIsSubCat = true;
- }
- else
- {
- $htmlTitre = "<p>";
- if (CONFVAL_ShowLinkBackToTopOfTree)
- {
- $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."\">"."<< ".get_lang("BackToHomePage")."</a>";
- }
- if (!is_null($catLine['parent_id']) || (!CONFVAL_ShowLinkBackToTopOfTree && !is_null($catLine['code'])))
- {
- $htmlTitre .= "<a href=\"".$_SERVER['PHP_SELF']."?category=".$catLine['parent_id']."\">"."<< ".get_lang("Up")."</a>";
- }
- $htmlTitre .= "</p>\n";
- if ($category != "" && !is_null($catLine['code']))
- {
- $htmlTitre .= "<h3>".$catLine['name']."</h3>\n";
- }
- else
- {
- $htmlTitre .= "<h3>".get_lang("Categories")."</h3>\n";
- }
- }
- }
- $htmlListCat .= "</ul>\n";
- }
- echo $htmlTitre;
- if ($thereIsSubCat)
- echo $htmlListCat;
- while ($categoryName = mysql_fetch_array($resCats))
- {
- echo "<h3>", $categoryName['name'], "</h3>\n";
- }
- $numrows = mysql_num_rows($sql_result_courses);
- if ($numrows > 0)
- {
- if ($thereIsSubCat)
- echo "<hr size=\"1\" noshade=\"noshade\">\n";
- echo "<h4 style=\"margin-top: 0px;\">", get_lang("CourseList"), "</h4>\n", "<ul>\n";
- while ($course = mysql_fetch_array($sql_result_courses))
- {
- echo "<li>\n", "<a href=\"".$web_course_path.$course['directory'], "/\">", $course['title'], "</a>", "<br/>", $course['visual_code'], " - ", $course['tutor_name'], ((CONFVAL_showCourseLangIfNotSameThatPlatform && $course['course_language'] != $platformLanguage) ? " - ".$course['course_language'] : ""), "\n", "</li>\n";
- }
- echo "</ul>\n";
- }
- else
- {
- // echo "<blockquote>",get_lang('_No_course_publicly_available'),"</blockquote>\n";
- }
- if ($category != "")
- {
- echo "<p>", "<a href=\"".$_SERVER['PHP_SELF']."\"><b><<</b> ", get_lang("BackToHomePage"), "</a>", "</p>\n";
- }
- }
- function category_has_open_courses($category)
- {
- $main_course_table = Database :: get_main_table(MAIN_COURSE_TABLE);
- $sql_query = "SELECT * FROM $main_course_table WHERE category_code='$category'";
- $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
- while ($course = mysql_fetch_array($sql_result))
- {
- if ($is_allowed_anonymous_access)
- return true; //at least one open course
- }
-
- return false;
- }
- /*
- ==============================================================================
- MAIN CODE
- ==============================================================================
- */
- echo '<div class="maincontent">';
- /*
- -----------------------------------------------------------------------------
- Plugins for loginpage_main AND campushomepage_main
- -----------------------------------------------------------------------------
- */
- if (!$_uid)
- {
- api_plugin('loginpage_main');
- }
- else
- {
- api_plugin('campushomepage_main');
- }
- if (!empty ($_GET['include']) && !strstr($_GET['include'], '/') && strstr($_GET['include'], '.html'))
- {
- include ('./home/'.$_GET['include']);
- $pageIncluded = true;
- }
- else
- {
- if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
- {
- include ('home/home_top.html');
- }
- else
- {
- include('home/home_top_'.$user_selected_language.'.html');
- }
- }
- // Display System announcements
- $announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
- SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
- // Display courses and category list
- if (!$pageIncluded)
- {
- // echo '<div class="clear"> </div>';
- echo '<div class="home_cats">';
- if (DISPLAY_COURSES_TO_ANONYMOUS_USERS)
- {
- display_anonymous_course_list();
- }
- echo '</div>';
- /*
- echo '<div class="home_news">';
- if(!file_exists('home/home_news_'.$user_selected_language.'.html'))
- {
- include ('home/home_news.html');
- }
- else
- {
- include('home/home_news_'.$user_selected_language.'.html');
- }
- echo '</div>';
- */
- }
- echo '</div>';
- // Right Menu
- // language form, login section + useful weblinks
- echo '<div class="menu">';
- display_anonymous_right_menu();
- echo '</div>';
- /*
- ==============================================================================
- FOOTER
- ==============================================================================
- */
- Display :: display_footer();
- ?>
|