';
//$htmlHeadXtra[] = '';
/* Table definitions */
// Database table definitions.
$main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
$main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
$main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
/* Constants and CONFIGURATION parameters */
// ---- 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
//define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatShort'));
define('CONFVAL_dateFormatForInfosFromCourses', get_lang('dateFormatLong'));
//define("CONFVAL_limitPreviewTo",SCRIPTVAL_NewEntriesOfTheDay);
//define("CONFVAL_limitPreviewTo",SCRIPTVAL_NoTimeLimit);
define("CONFVAL_limitPreviewTo", SCRIPTVAL_NewEntriesOfTheDayOfLastLogin);
// This is the main function to get the course list.
$personal_course_list = UserManager::get_personal_session_course_list($_user['user_id']);
// Check if a user is enrolled only in one course for going directly to the course after the login.
if (api_get_setting('go_to_course_after_login') == 'true') {
$my_session_list = array();
$count_of_courses_no_sessions = 0;
$count_of_courses_with_sessions = 0;
foreach($personal_course_list as $course) {
if (!empty($course['id_session'])) {
$my_session_list[$course['id_session']] = true;
$count_of_courses_with_sessions++;
} else {
$count_of_courses_no_sessions++;
}
}
$count_of_sessions = count($my_session_list);
//echo $count_of_sessions.' '.$count_of_courses_with_sessions.' '.$count_of_courses_no_sessions;
//!isset($_SESSION['coursesAlreadyVisited'])
if ($count_of_sessions == 1 && $count_of_courses_no_sessions == 0) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]];
$course_directory = $course_info['d'];
$id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
$url = api_get_path(WEB_CODE_PATH).'session/?session_id='.$id_session;
header('location:'.$url);
exit;
}
if (!isset($_SESSION['coursesAlreadyVisited']) && $count_of_sessions == 0 && $count_of_courses_no_sessions == 1) {
$key = array_keys($personal_course_list);
$course_info = $personal_course_list[$key[0]];
$course_directory = $course_info['d'];
$id_session = isset($course_info['id_session']) ? $course_info['id_session'] : 0;
$url = api_get_path(WEB_COURSE_PATH).$course_directory.'/?id_session='.$id_session;
header('location:'.$url);
exit;
}
/*
if (api_get_setting('hide_courses_in_sessions') == 'true') {
//Check sessions
$session_list = array();
$only_session_id = 0;
foreach($personal_course_list as $course_item) {
$session_list[$course_item['id_session']] = $course_item;
$only_session_id = $course_item['id_session'];
}
if (count($session_list) == 1 && !empty($only_session_id)) {
header('Location:'.api_get_path(WEB_CODE_PATH).'session/?session_id='.$session_list[$only_session_id]['id_session']);
}
}
*/
}
$nosession = false;
if (api_get_setting('use_session_mode') == 'true' && !$nosession) {
$display_actives = !isset($_GET['inactives']);
}
$nameTools = get_lang('MyCourses');
$this_section = SECTION_COURSES;
/* 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('
config error:'.__FILE__.'
set
'; // Start of content for logged in users.
// Plugins for the my courses main area.
echo '
';
api_plugin('mycourses_main');
echo '
';
/* System Announcements */
$announcement = isset($_GET['announcement']) ? $_GET['announcement'] : -1;
$visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
SystemAnnouncementManager :: display_announcements($visibility, $announcement);
if (!empty ($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/',$_GET['include'])) {
include ('./home/'.$_GET['include']);
$pageIncluded = true;
} else {
/* DISPLAY COURSES */
// Compose a structured array of session categories, sessions and courses
// for the current user.
if (isset($_GET['history']) && intval($_GET['history']) == 1) {
$courses_tree = UserManager::get_sessions_by_category($_user['user_id'], true, true);
} else {
$courses_tree = UserManager::get_sessions_by_category($_user['user_id'], true);
}
foreach ($courses_tree as $cat => $sessions) {
$courses_tree[$cat]['details'] = SessionManager::get_session_category($cat);
if ($cat == 0) {
$courses_tree[$cat]['courses'] = CourseManager::get_courses_list_by_user_id($_user['user_id'], false);
}
$courses_tree[$cat]['sessions'] = array_flip(array_flip($sessions));
if (count($courses_tree[$cat]['sessions']) > 0) {
foreach ($courses_tree[$cat]['sessions'] as $k => $s_id) {
$courses_tree[$cat]['sessions'][$k] = array('details' => SessionManager::fetch($s_id));
$courses_tree[$cat]['sessions'][$k]['courses'] = UserManager::get_courses_list_by_session($_user['user_id'], $s_id);
}
}
}
$list = '';
foreach ($personal_course_list as $my_course) {
$thisCourseDbName = $my_course['db'];
$thisCourseSysCode = $my_course['k'];
$thisCoursePublicCode = $my_course['c'];
$thisCoursePath = $my_course['d'];
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$dbname = $my_course['k'];
$status = array();
$status[$dbname] = $my_course['s'];
$nbDigestEntries = 0; // Number of entries already collected.
if ($maxCourse < $maxValvas) {
$maxValvas = $maxCourse;
}
if ($maxCourse > 0) {
$courses[$thisCourseSysCode]['coursePath'] = $thisCoursePath;
$courses[$thisCourseSysCode]['courseCode'] = $thisCoursePublicCode;
}
/* Announcements */
$course_database = $my_course['db'];
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database);
$query = "SELECT visibility FROM $course_tool_table WHERE link = 'announcements/announcements.php' AND visibility = 1";
$result = Database::query($query);
// Collect from announcements, but only if tool is visible for the course.
if ($result && $maxValvas > 0 && Database::num_rows($result) > 0) {
// Search announcements table.
// Take the entries listed at the top of advalvas/announcements tool.
$course_announcement_table = Database::get_course_table(TABLE_ANNOUNCEMENT);
$sqlGetLastAnnouncements = "SELECT end_date publicationDate, content
FROM ".$course_announcement_table;
switch (CONFVAL_limitPreviewTo) {
case SCRIPTVAL_NewEntriesOfTheDay :
$sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d')."'";
break;
case SCRIPTVAL_NoTimeLimit :
break;
case SCRIPTVAL_NewEntriesOfTheDayOfLastLogin :
// take care mysql -> DATE_FORMAT(time,format) php -> date(format,date)
$sqlGetLastAnnouncements .= "WHERE DATE_FORMAT(end_date,'%Y %m %d') >= '".date('Y m d', $_user['lastLogin'])."'";
}
$sqlGetLastAnnouncements .= "ORDER BY end_date DESC LIMIT ".$maxValvas;
$resGetLastAnnouncements = Database::query($sqlGetLastAnnouncements);
if ($resGetLastAnnouncements) {
while ($annoncement = Database::fetch_array($resGetLastAnnouncements)) {
$keyTools = 'valvas';
$keyTime = $annoncement['publicationDate'];
$keyCourse = $thisCourseSysCode;
$digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($annoncement['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
$nbDigestEntries ++; // summary has same order as advalvas
}
}
}
/* Agenda */
$course_database = $my_course['db'];
$course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database);
$query = "SELECT visibility FROM $course_tool_table WHERE link = 'calendar/agenda.php' AND visibility = 1";
$result = Database::query($query);
$thisAgenda = $maxCourse - $nbDigestEntries; // New max entries for agenda.
if ($maxAgenda < $thisAgenda) {
$thisAgenda = $maxAgenda;
}
// Collect from agenda, but only if tool is visible for the course.
if ($result && $thisAgenda > 0 && Database::num_rows($result) > 0) {
$tableCal = $courseTablePrefix.$thisCourseDbName.$_configuration['db_glue'].'calendar_event';
$sqlGetNextAgendaEvent = "SELECT start_date, title content, start_time
FROM $tableCal
WHERE start_date >= CURDATE()
ORDER BY start_date, start_time
LIMIT $maxAgenda";
$resGetNextAgendaEvent = Database::query($sqlGetNextAgendaEvent);
if ($resGetNextAgendaEvent) {
while ($agendaEvent = Database::fetch_array($resGetNextAgendaEvent)) {
$keyTools = 'agenda';
$keyTime = $agendaEvent['start_date'];
$keyCourse = $thisCourseSysCode;
$digest[$$orderKey[0]][$$orderKey[1]][$$orderKey[2]][] = @htmlspecialchars(api_substr(strip_tags($agendaEvent['content']), 0, CONFVAL_NB_CHAR_FROM_CONTENT), ENT_QUOTES, $charset);
$nbDigestEntries ++; // Summary has same order as advalvas.
}
}
}
/*
Digest Display
Take collected data and display it.
*/
} // End while mycourse...
}
if (isset($_GET['history']) && intval($_GET['history']) == 1) {
echo '
'.get_lang('HistoryTrainingSession').'
';
if (empty($courses_tree[0]['sessions'])){
echo get_lang('YouDoNotHaveAnySessionInItsHistory');
}
}
if (is_array($courses_tree)) {
foreach ($courses_tree as $key => $category) {
if ($key == 0) {
// Sessions and courses that are not in a session category.
if (!isset($_GET['history'])) { // Check if it's not history trainnign session list.
CourseManager :: display_special_courses(api_get_user_id());
CourseManager :: display_courses(api_get_user_id());
}
// Independent sessions.
foreach ($category['sessions'] as $session) {
// Don't show empty sessions.
if (count($session['courses']) < 1) { continue; }
// Courses inside the current session.
$date_session_start = $session['details']['date_start'];
$days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count_courses_session = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session['details']['id'], $course['code']);
if ($is_coach_course) {
$allowed_time = api_strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = api_strtotime($date_session_start);
}
if ($session_now > $allowed_time) { //read only and accesible
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',true);
//$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item',($session['details']['visibility']==3?false:true));
$html_courses_session .= $c[1];
}
$count_courses_session++;
}
}
if ($count_courses_session > 0) {
echo '
';
echo '- ';
echo Display::return_icon('window_list.png', get_lang('Expand').'/'.get_lang('Hide'), array('width' => '48px', 'align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
$s = Display :: get_session_title_box($session['details']['id']);
$extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
/*if ($session['details']['visibility'] == 3) {
$session_link = $s['title'];
} else {*/
$session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
//}
echo Display::tag('span',$session_link. ' '.$extra_info);
if (api_is_platform_admin()) {
echo '';
}
echo '
';
if (api_get_setting('hide_courses_in_sessions') == 'false') {
echo $html_courses_session;
}
echo '
';
}
}
} else {
// All sessions included in.
if (!empty($category['details'])) {
$count_courses_session = 0;
$html_sessions = '';
foreach ($category['sessions'] as $session) {
// Don't show empty sessions.
if (count($session['courses']) < 1) { continue; }
$date_session_start = $session['details']['date_start'];
$days_access_before_beginning = $session['details']['nb_days_access_before_beginning'] * 24 * 3600;
$session_now = time();
$html_courses_session = '';
$count = 0;
foreach ($session['courses'] as $course) {
$is_coach_course = api_is_coach($session['details']['id'], $course['code']);
if ($is_coach_course) {
$allowed_time = strtotime($date_session_start) - $days_access_before_beginning;
} else {
$allowed_time = strtotime($date_session_start);
}
if ($session_now > $allowed_time) {
$c = CourseManager :: get_logged_user_course_html($course, $session['details']['id'], 'session_course_item');
$html_courses_session .= $c[1];
$count_courses_session++;
$count++;
}
}
if ($count > 0) {
$s = Display :: get_session_title_box($session['details']['id']);
$html_sessions .= '
';
$html_sessions .= '- ';
//$html_sessions .= Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'session_img_'.$session['details']['id'])) . ' ';
$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'])) . ' ';
$session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
$html_sessions .= '' . $session_link. ' ';
$html_sessions .= '';
$html_sessions .= (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
$html_sessions .= '';
if (api_is_platform_admin()) {
$html_sessions .= '';
}
$html_sessions .= '
';
$html_sessions .= $html_courses_session;
$html_sessions .= '
';
}
}
if ($count_courses_session > 0) {
echo '
';
echo '
';
//echo Display::return_icon('div_hide.gif', get_lang('Expand').'/'.get_lang('Hide'), array('align' => 'absmiddle', 'id' => 'category_img_'.$category['details']['id']));
echo Display::return_icon('folder_blue.png', get_lang('SessionCategory'), array('width'=>'48px', 'align' => 'absmiddle'));
if (api_is_platform_admin()) {
echo'
';
}
echo '
';
echo $category['details']['name'];
echo '';
echo '
';
if ($category['details']['date_end'] != '0000-00-00') {
printf(get_lang('FromDateXToDateY'),$category['details']['date_start'],$category['details']['date_end']);
}
echo '';
echo $html_sessions;
echo '
';
}
}
}
}
}
echo '
'; // End of content main-section
// Register whether full admin or null admin course
// by course through an array dbname x user status.
api_session_register('status');
/* RIGHT MENU */
$show_menu = false;
$show_create_link = false;
$show_course_link = false;
$show_digest_link = false;
$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
if ($display_add_course_link) {
$show_menu = true;
$show_create_link = true;
}
if (api_is_platform_admin() || api_is_course_admin() || api_is_allowed_to_create_course()) {
$show_menu = true;
$show_course_link = true;
} else {
if (api_get_setting('allow_students_to_browse_courses') == 'true') {
$show_menu = true;
$show_course_link = true;
}
}
if (isset($toolsList) && is_array($toolsList) && isset($digest)) {
$show_digest_link = true;
$show_menu = true;
}
//Always show the user image
$img_array = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', true, true);
$no_image = false;
if ($img_array['file'] == 'unknown.jpg') {
$no_image = true;
}
$img_array = UserManager::get_picture_user(api_get_user_id(), $img_array['file'], 50, USER_IMAGE_SIZE_MEDIUM, ' width="90" height="90" ');
$profile_content .='