@ -1,76 +1,51 @@
<?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
==============================================================================
DOKEOS - elearning and course management software
For a full list of contributors, see documentation/credits.html
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 "documentation/licence.html" more details.
Contact:
Dokeos
Rue des Palais 44 Paleizenstraat
B-1030 Brussels - Belgium
Tel. +32 (2) 211 34 56
*/
/**
==============================================================================
* 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
==============================================================================
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University, Refactoring
* @version $Id: index.php 10548 2006-12-24 11:11:17Z pcool $
* @todo check the different @todos in this page and really do them
* @todo check if the news management works as expected
*/
/**
* @todo shouldn't the SCRIPTVAL_ and CONFVAL_ constant be moved to the config page? Has anybody any idea what the are used for?
* if these are really configuration settings then we can add those to the dokeos config settings
*/
/*
==============================================================================
INIT SECTION
==============================================================================
*/
// only this script should have this constant defined
// only this script should have this constant defined. This is used to activate the javascript that
// gives the login name automatic focus in header.inc.html.
/** @todo Couldn't this be done using the $HtmlHeadXtra array? */
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
// name of the language file that needs to be included
$language_file = array ('courses', 'index');
$cidReset = true; /* Flag forcing the 'current course' reset,
as we're not inside a course anymore */
// the language file
$langFile = array ('courses', 'index');
/* Flag forcing the 'current course' reset, as we're not inside a course anymore */
// maybe we should change this into an api function? an example: Coursemanager::unset();
$cidReset = true;
// the section (for the tabs)
$this_section = SECTION_CAMPUS;
/*
-----------------------------------------------------------
Included libraries
-----------------------------------------------------------
*/
/** @todo make all the library files consistent use filename.lib.php and not filename.lib.inc.php */
include_once ('./main/inc/global.inc.php');
include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
@ -79,42 +54,22 @@ 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');
// the section (for the tabs)
$this_section = SECTION_CAMPUS;
/*
-----------------------------------------------------------
Action Handling
-----------------------------------------------------------
*/
/** @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?
* 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
* 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
* will see it.
*/
if ($_GET['logout'])
{
$query_string='';
if(!empty($_SESSION['user_language_choice']))
{
$query_string='?language='.$_SESSION['user_language_choice'];
}
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_GET["uid"]."' ORDER BY login_date DESC LIMIT 0,1";
$q_last_connection=mysql_query($sql_last_connection);
$i_id_last_connection=mysql_result($q_last_connection,0,"login_id");
$s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
api_sql_query($s_sql_update_logout_date);
//LoginDelete(".$_user['user_id'].", $_configuration['statistics_database']);
LoginDelete($_GET["uid"], $_configuration['statistics_database']);
api_session_destroy();
header("Location: index.php$query_string");
exit();
echo 'test';
exit;
logout();
}
/*
@ -122,88 +77,44 @@ if ($_GET['logout'])
Table definitions
-----------------------------------------------------------
*/
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
$track_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$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
-----------------------------------------------------------
*/
// @todo shouldn't these be moved to the config page or made into dokeos config settings?
// ---- 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);
/** @todo these configuration settings should move to the dokeos config settings */
/** defines wether or not anonymous visitors can see a list of the courses on the Dokeos homepage that are open to the world */
$_setting['display_courses_to_anonymous_users'] = 'true';
/** defines weither empty course categories should appear in the list with the course categories */
$_setting['show_empty_course_categories'] = 'true';
/** defines weither the number of open courses has to appear after the course category (faculty) */
/** remark: actually count are only for direct children */
$_setting['show_number_of_courses'] = 'false';
/** Show the back link on top of the tree */
$_setting['show_back_link_on_top_of_tree'] = 'false';
/** Show the course language if it is not the same as the platform lanugage */
$_setting['show_different_course_language'] = 'true';
/** @todo remove this piece of code because this is not used */
if (isset ($_user['user_id']))
{
$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
==============================================================================
*/
/**
* @todo This piece of code should probably move to local.inc.php where the actual login / logout procedure is handled.
* @todo consider removing this piece of code because does nothing.
*/
if ($_GET["submitAuth"] == 1)
{
// nice lie!!!
@ -211,29 +122,32 @@ if ($_GET["submitAuth"] == 1)
session_destroy();
die();
}
/**
* @todo This piece of code should probably move to local.inc.php where the actual login procedure is handled.
* @todo check if this code is used. I think this code is never executed because after clicking the submit button
* the code does the stuff in local.inc.php and then redirects to index.php or user_portal.php depending
* on api_get_setting('page_after_login')
*/
if ($_POST["submitAuth"])
{
// To ensure legacy compatibility, we set the following variables.
// But they should be removed at last.
$lastname = $_user['lastName'];
$firstname = $_user['firstName'];
$email = $_user['mail'];
$status = $uData['status'];
// the user is already authenticated, we now find the last login of the user.
if (isset ($_user['user_id']))
{
$sqlLastL ogin = "SELECT UNIX_TIMESTAMP(login_date)
$sql_last_login = "SELECT UNIX_TIMESTAMP(login_date)
FROM $track_login_table
WHERE login_user_id = '".$_user['user_id']."'
ORDER BY login_date DESC LIMIT 1";
$resLastLogin = api_sql_query($sqlLastL ogin, __FILE__, __LINE__);
if (!$resLastL ogin)
if (mysql_num_rows($resLastL ogin) > 0)
$result_last_login = api_sql_query($sql_last_l ogin, __FILE__, __LINE__);
if (!$result_last_l ogin)
if (mysql_num_rows($result_last_l ogin) > 0)
{
$user_last_login_datetime = mysql_fetch_array($resLastL ogin);
$user_last_login_datetime = mysql_fetch_array($result_last_l ogin);
$user_last_login_datetime = $user_last_login_datetime[0];
api_session_register('user_last_login_datetime');
}
mysql_free_result($resLastLogin);
mysql_free_result($result_last_login);
//event_login();
if (api_is_platform_admin())
{
@ -242,43 +156,144 @@ if ($_POST["submitAuth"])
decodeOpenInfos();
}
}
} // end login -- if($submit)
} // end login -- if($_POST[" submitAuth"] )
else
{
// only if login form was not sent because if the form is sent the user was
// already on the page.
// only if login form was not sent because if the form is sent the user was already on the page.
event_open();
}
// the header
Display :: display_header('', 'dokeos');
/*
-----------------------------------------------------------
Header
include the HTTP, HTML headers plus the top banner
-----------------------------------------------------------
==============================================================================
MAIN CODE
==============================================================================
*/
echo '< div class = "maincontent" > ';
$help = "Clar";
// Plugins for loginpage_main AND campushomepage_main
if (!api_get_user_id())
{
api_plugin('loginpage_main');
}
else
{
api_plugin('campushomepage_main');
}
Display :: display_header('', $help);
// Including the page for the news
if (!empty ($_GET['include']) & & !strstr($_GET['include'], '/') & & strstr($_GET['include'], '.html'))
{
include ('./home/'.$_GET['include']);
$page_included = 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');
}
}
/*
==============================================================================
FUNCTIONS
// Display System announcements
$announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
display_anonymous_right_menu()
display_anonymous_course_list()
// Display courses and category list
if (!$page_included)
{
if (api_get_setting('display_courses_to_anonymous_users') == 'true')
{
echo '< div class = "home_cats" > ';
display_anonymous_course_list();
echo '< / div > ';
}
}
echo '< / div > ';
display_login_form()
handle_login_failed()
// display right menu: language form, login section + useful weblinks
echo '< div class = "menu" > ';
display_anonymous_right_menu();
echo '< / div > ';
display_lost_password_info()
/*
==============================================================================
FOOTER
==============================================================================
*/
Display :: display_footer();
/*
-----------------------------------------------------------
Display functions
-----------------------------------------------------------
*/
/**
* This function handles the logout and is called whenever there is a $_GET['logout']
*
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
*/
function logout()
{
// variable initialisation
$query_string='';
if(!empty($_SESSION['user_language_choice']))
{
$query_string='?language='.$_SESSION['user_language_choice'];
}
// Database table definition
$tbl_track_login = Database :: get_statistic_table(STATISTIC_TRACK_E_LOGIN_TABLE);
// selecting the last login of the user
$sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".$_GET["uid"]."' ORDER BY login_date DESC LIMIT 0,1";
$q_last_connection=mysql_query($sql_last_connection);
$i_id_last_connection=mysql_result($q_last_connection,0,"login_id");
$s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date=NOW() WHERE login_id='$i_id_last_connection'";
api_sql_query($s_sql_update_logout_date);
//LoginDelete(".$_user['user_id'].", $_configuration['statistics_database']);
LoginDelete($_GET["uid"], $_configuration['statistics_database']);
api_session_destroy();
header("Location: index.php$query_string");
exit();
}
/**
* This function checks if there are courses that are open to the world in the platform course categories (=faculties)
*
* @param unknown_type $category
* @return boolean
*/
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 ($course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD)
{
return true; //at least one open course
}
}
return false;
}
/**
* Displays the right-hand menu for anonymous users:
@ -423,21 +438,24 @@ function display_lost_password_info()
* Display list of courses in a category.
* (for anonymous users)
*
* Warning: this function defines globals.
* @version 1.0
* @version 1.1
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University - refactoring and code cleaning
*/
function display_anonymous_course_list()
{
//init
$web_course_path = api_get_path(WEB_COURSE_PATH);
$category = $_GET["category"];
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
// Database table definitions
$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."'
WHERE category_code = '".mysql_real_escape_string( $_GET[" 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__);
@ -454,7 +472,6 @@ function display_anonymous_course_list()
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)
@ -471,7 +488,7 @@ function display_anonymous_course_list()
{
//the category contains courses accessible to anonymous visitors
$htmlListCat .= "< a href = \"".$_SERVER['PHP_SELF']."?category=".$catLine['code']."\" > ".$catLine['name']."< / a > ";
if (CONFVAL_showNumberOfChild )
if (get_setting('show_number_of_courses') == 'true' )
{
$htmlListCat .= " (".$catLine['nbCourse']." ".get_lang("Courses").")";
}
@ -484,7 +501,7 @@ function display_anonymous_course_list()
/************************************************************************
end changed code to eliminate the (0 courses) after empty categories
************************************************************************/
elseif (CONFVAL_showNodeEmpty )
elseif (get_setting('show_empty_course_categories') == 'true' )
{
$htmlListCat .= $catLine['name'];
}
@ -494,11 +511,11 @@ function display_anonymous_course_list()
else
{
$htmlTitre = "< p > ";
if (CONFVAL_ShowLinkBackToTopOfTree )
if ($_setting['show_back_link_on_top_of_tree'] == 'true' )
{
$htmlTitre .= "< a href = \"".$_SERVER['PHP_SELF']."\" > "."< < ".get_lang("BackToHomePage")."< / a > ";
}
if (!is_null($catLine['parent_id']) || (!CONFVAL_ShowLinkBackToTopOfTree & & !is_null($catLine['code'])))
if (!is_null($catLine['parent_id']) || ($_setting['show_back_link_on_top_of_tree'] < > 'true' & & !is_null($catLine['code'])))
{
$htmlTitre .= "< a href = \"".$_SERVER['PHP_SELF']."?category=".$catLine['parent_id']."\" > "."< < ".get_lang("Up")."< / a > ";
}
@ -517,7 +534,9 @@ function display_anonymous_course_list()
}
echo $htmlTitre;
if ($thereIsSubCat)
{
echo $htmlListCat;
}
while ($categoryName = mysql_fetch_array($resCats))
{
echo "< h3 > ", $categoryName['name'], "< / h3 > \n";
@ -526,11 +545,20 @@ function display_anonymous_course_list()
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 "< li > \n";
echo "< a href = \"".$web_course_path.$course['directory'], " / \ " > ", $course['title'], "< / a > ";
echo "< br / > ", $course['visual_code'], " - ", $course['tutor_name'];
if ($_setting['show_different_course_language'] == 'true' & & $course['course_language'] < > api_get_setting('platformLanguage'))
{
echo ' - '.$course['course_language'];
}
echo "< / li > \n";
}
echo "< / ul > \n";
}
@ -543,113 +571,4 @@ function display_anonymous_course_list()
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(TABLE_MAIN_COURSE);
$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 (!api_get_user_id())
{
api_plugin('loginpage_main');
}
else
{
api_plugin('campushomepage_main');
}
// Including the page for the news
if (!empty ($_GET['include']) & & !strstr($_GET['include'], '/') & & strstr($_GET['include'], '.html'))
{
include ('./home/'.$_GET['include']);
$pageIncluded = true;
}
else
{
if(file_exists('home/home_top_'.$user_selected_language.'.html'))
{
include('home/home_top_'.$user_selected_language.'.html');
}
else
{
$platform_language=api_get_setting("platformLanguage");
if(file_exists('home/home_top_'.$platform_language.'.html')){
include('home/home_top_'.$platform_language.'.html');
}
else{
include ('home/home_top.html');
}
}
}
// Display System announcements
$announcement = $_GET['announcement'] ? $_GET['announcement'] : -1;
SystemAnnouncementManager :: display_announcements(VISIBLE_GUEST, $announcement);
echo "< br > < br > < br > ";
// 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" > ';
$user_selected_language = $_SESSION["_user"]["language"];
if(file_exists('home/home_news_'.$user_selected_language.'.html'))
{
include ('home/home_news_'.$user_selected_language.'.html');
}
else
{
$platform_language=api_get_setting("platformLanguage");
if(file_exists('home/home_news_'.$platform_language.'.html')){
include('home/home_news_'.$platform_language.'.html');
}
else{
include ('home/home_news.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();
?>