diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index c528c39fe2..5b0fe91b48 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -450,7 +450,7 @@ class CourseManager { $table_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); $sql_course = "SELECT course_code FROM $table_field cf INNER JOIN $t_cfv cfv ON cfv.field_id=cf.id WHERE field_variable='$original_course_id_name' AND field_value='$original_course_id_value'"; $res = Database::query($sql_course); - $row = Database::fetch_object($res_course); + $row = Database::fetch_object($res); if ($row) { return $row->course_code; } else { @@ -2491,4 +2491,553 @@ class CourseManager { return self::course_code_exists($wanted_course_code); } + /** + * Display special courses (and only these) as several HTML divs of class userportal-course-item + * + * Special courses are courses that stick on top of the list and are "auto-registerable" + * in the sense that any user clicking them is registered as a student + * @param int User id + * @return void + */ + function display_special_courses ($user_id) { + + $user_id = intval($user_id); + $user_info = api_get_user_info($user_id); + $special_course_list = array(); + + $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); + $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $tbl_course_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); + $tbl_course_field_value = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); + $tbl_user_course_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + + // get course list auto-register + $sql = "SELECT course_code FROM $tbl_course_field_value tcfv INNER JOIN $tbl_course_field tcf ON " . + " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; + + $special_course_result = Database::query($sql); + if (Database::num_rows($special_course_result) > 0) { + $special_course_list = array(); + while ($result_row = Database::fetch_array($special_course_result)) { + $special_course_list[] = '"'.$result_row['course_code'].'"'; + } + } + $with_special_courses = $without_special_courses = ''; + if (!empty($special_course_list)) { + $with_special_courses = ' course.code IN ('.implode(',',$special_course_list).')'; + } + + if (!empty($with_special_courses)) { + $sql = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr, + course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status, + course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course_rel_user.user_id, course.visibility + FROM $TABLECOURS course + LEFT JOIN $TABLECOURSUSER course_rel_user ON course.code = course_rel_user.course_code AND course_rel_user.user_id = '$user_id' + WHERE $with_special_courses group by course.code"; + + $rs_special_course = Database::query($sql); + $number_of_courses = Database::num_rows($rs_special_course); + $key = 0; + $status_icon = ''; + if ($number_of_courses > 0) { + while ($course = Database::fetch_array($rs_special_course)) { + + // Get notifications. + $my_course = array(); + $my_course['db'] = $course['db_name']; + $my_course['k'] = $course['code']; + $my_course['id_session'] = null; + $my_course['s'] = $course['status']; + $show_notification = show_notification($my_course); + + if (empty($course['user_id'])) { + $course['status'] = $user_info['status']; + } + + $status_icon = Display::return_icon('blackboard.png', get_lang('Course'), array('width'=>'48px')); + /* + if ($course['status'] == 1) { + $status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style' => 'width: 11px; height: 11px;')); + } + if (($course['status'] == 5 && !api_is_coach()) || empty($course['status'])) { + $status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'), array('style' => 'width: 11px; height: 11px;')); + }*/ + + echo '
'; + + if (api_is_platform_admin()) { + echo '
'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).''; + if ($course['status'] == COURSEMANAGER) { + //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'),array('style'=>'width:11px; height:11px;')); + } + echo '
'; + } + $course_visibility = $course['visibility']; + if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) { + $course_title = ''.$course['title'].''; + } else { + $course_title = $course['title']." ".get_lang('CourseClosed'); + } + + echo '
'.$status_icon.'
'.$course_title.'
'; + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + echo $course['visual_code']; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') { + echo ' - '; + } + + if (api_get_setting('display_teacher_in_courselist') == 'true') { + echo $course['tutor']; + } + echo ' '; + echo Display::return_icon('klipper.png', get_lang('CourseAutoRegister')); + + // Show notifications. + echo $show_notification; + echo '
'; + $key++; + } + } + } + } + /** + * Display courses (without special courses) as several HTML divs + * of course categories, as class userportal-catalog-item. + * @uses display_courses_in_category() to display the courses themselves + * @param int user id + * @return void + */ + function display_courses($user_id) { + + global $_user, $_configuration; + + // Building an array that contains all the id's of the user defined course categories. + // Initially this was inside the display_courses_in_category function but when we do it here we have fewer + // sql executions = performance increase. + $all_user_categories = self :: get_user_course_categories(); + + // Step 0: We display the course without a user category. + self :: display_courses_in_category(0, 'true'); + + // Step 1: We get all the categories of the user. + $tucc = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $sql = "SELECT id, title FROM $tucc WHERE user_id='".$_user['user_id']."' ORDER BY sort ASC"; + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + // We simply display the title of the category. + echo '
'; + echo ''; + echo '
'; + } + } + /** + * Display courses inside a category (without special courses) as HTML dics of + * class userportal-course-item. + * @param int User category id + * @return void + */ + function display_courses_in_category($user_category_id) { + + global $_user, $_configuration; + // Table definitions + $TABLECOURS = Database :: get_main_table(TABLE_MAIN_COURSE); + $TABLECOURSUSER = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $TABLE_COURSE_FIELD = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD); + $TABLE_COURSE_FIELD_VALUE = Database :: get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES); + $TABLE_ACCESS_URL_REL_COURSE = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $TABLE_USER_COURSE_CATEGORY = Database :: get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $current_url_id = api_get_current_access_url_id(); + + // Get course list auto-register + $sql = "SELECT course_code FROM $TABLE_COURSE_FIELD_VALUE tcfv INNER JOIN $TABLE_COURSE_FIELD tcf ON " . + " tcfv.field_id = tcf.id WHERE tcf.field_variable = 'special_course' AND tcfv.field_value = 1 "; + + $special_course_result = Database::query($sql); + if (Database::num_rows($special_course_result) > 0) { + $special_course_list = array(); + while ($result_row = Database::fetch_array($special_course_result)) { + $special_course_list[] = '"'.$result_row['course_code'].'"'; + } + } + $without_special_courses = ''; + if (!empty($special_course_list)) { + $without_special_courses = ' AND course.code NOT IN ('.implode(',',$special_course_list).')'; + } + + $sql_select_courses = "SELECT course.code, course.visual_code, course.subscribe subscr, course.unsubscribe unsubscr, + course.title title, course.tutor_name tutor, course.db_name, course.directory, course_rel_user.status status, + course_rel_user.sort sort, course_rel_user.user_course_cat user_course_cat, course.visibility + FROM $TABLECOURS course, + $TABLECOURSUSER course_rel_user, ".$TABLE_ACCESS_URL_REL_COURSE." url + WHERE course.code = course_rel_user.course_code AND url.course_code = course.code + AND course_rel_user.user_id = '".$_user['user_id']."' + AND course_rel_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." + AND course_rel_user.user_course_cat='".$user_category_id."' $without_special_courses "; + // If multiple URL access mode is enabled, only fetch courses + // corresponding to the current URL. + if ($_configuration['multiple_access_urls'] && $current_url_id != -1){ + $sql_select_courses .= " AND url.course_code=course.code AND access_url_id='".$current_url_id."'"; + } + // Use user's classification for courses (if any). + $sql_select_courses .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC"; + $result = Database::query($sql_select_courses); + $number_of_courses = Database::num_rows($result); + $key = 0; + $status_icon = ''; + + // Browse through all courses. + while ($course = Database::fetch_array($result)) { + // Get notifications. + $my_course = array(); + $my_course['db'] = $course['db_name']; + $my_course['k'] = $course['code']; + $my_course['id_session'] = null; + $my_course['s'] = $course['status']; + // For each course, get if there is any notification icon to show + // (something that would have changed since the user's last visit). + $show_notification = Display :: show_notification($my_course); + // New code displaying the user's status in respect to this course. + $status_icon = Display::return_icon('blackboard.png', get_lang('Course'), array('width' => '48px')); + + echo '
'; + + if (api_is_platform_admin()) { + echo '
'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).''; + if ($course['status'] == COURSEMANAGER) { + //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;')); + } + echo '
'; + } + + // Function logic - act on the data (check if the course is virtual, if yes change the link). + $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course['code']); + if ($is_virtual_course) { + // If the current user is also subscribed in the real course to which this + // virtual course is linked, we don't need to display the virtual course entry in + // the course list - it is combined with the real course entry. + $target_course_code = CourseManager :: get_target_of_linked_course($course['code']); + $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); + if ($is_subscribed_in_target_course) { + return; // Do not display this course entry. + } + } + // Check if the course has virtual courses attached. If yes change the course title and display code. + $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course['code'], api_get_user_id()); + if ($has_virtual_courses) { + $course_info = api_get_course_info($course['code']); + $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); + $course_title = $return_result['title']; + $course_display_code = $return_result['code']; + } else { + $course_title = $course['title']; + $course_display_code = $course['visual_code']; + } + + // Show a hyperlink to the course, unless the course is closed and user is not course admin. + $course_visibility = $course['visibility']; + if ($course_visibility != COURSE_VISIBILITY_CLOSED || $course['status'] == COURSEMANAGER) { + $course_title = ''.$course['title'].''; + } else { + $course_title = $course['title']." ".get_lang('CourseClosed'); + } + // Start displaying the course block itself. + echo '
'.$status_icon.'
'.$course_title.'
'; + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + echo $course_display_code; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') { + echo ' - '; + } + if (api_get_setting('display_teacher_in_courselist') == 'true') { + if (!empty($course['tutor'])) + echo $course['tutor']; + } + // Show notifications. + echo $show_notification; + echo '
'; + $key++; + } + } + /** + * Retrieves the user defined course categories + * @author Patrick Cool , Ghent University + * @return array containing all the titles of the user defined courses with the id as key of the array + */ + function get_user_course_categories() { + global $_user; + $output = array(); + $table_category = Database::get_user_personal_table(TABLE_USER_COURSE_CATEGORY); + $sql = "SELECT * FROM ".$table_category." WHERE user_id='".Database::escape_string($_user['user_id'])."'"; + $result = Database::query($sql); + while ($row = Database::fetch_array($result)) { + $output[$row['id']] = $row['title']; + } + return $output; + } + /** + * Display code for one specific course a logged in user is subscribed to. + * Shows a link to the course, what's new icons... + * + * $my_course['d'] - course directory + * $my_course['i'] - course title + * $my_course['c'] - visual course code + * $my_course['k'] - system course code + * $my_course['db'] - course database + * + * @version 1.0.3 + * @todo refactor into different functions for database calls | logic | display + * @todo replace single-character $my_course['d'] indices + * @todo move code for what's new icons to a separate function to clear things up + * @todo add a parameter user_id so that it is possible to show the courselist of other users (=generalisation). This will prevent having to write a new function for this. + */ + function get_logged_user_course_html($course, $session_id = 0, $class = 'courses') { + global $nosession, $nbDigestEntries, $digest, $thisCourseSysCode, $orderKey; + $charset = api_get_system_encoding(); + + $current_uid = api_get_user_id(); + $info = api_get_course_info($course['code']); + $status_course = CourseManager::get_user_in_course_status($current_uid, $course['code']); + + if (!is_array($course['code'])) { + $my_course = api_get_course_info($course['code']); + $my_course['k'] = $my_course['id']; + $my_course['db'] = $my_course['dbName']; + $my_course['c'] = $my_course['official_code']; + $my_course['i'] = $my_course['name']; + $my_course['d'] = $my_course['path']; + $my_course['t'] = $my_course['titular']; + $my_course['id_session'] = $session_id; + $my_course['status'] = empty($session_id) ? $status_course : 5; + } + + if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + global $now, $date_start, $date_end; + } + + // Initialise. + $result = ''; + + // Table definitions + //$statistic_database = Database::get_statistic_database(); + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); + $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY); + $course_database = $my_course['db']; + $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database); + $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database); + + $user_id = api_get_user_id(); + $course_system_code = $my_course['k']; + $course_visual_code = $my_course['c']; + $course_title = $my_course['i']; + $course_directory = $my_course['d']; + $course_teacher = $my_course['t']; + $course_teacher_email = isset($my_course['email']) ? $my_course['email'] : ''; + $course_info = Database :: get_course_info($course_system_code); + $course_access_settings = CourseManager :: get_access_settings($course_system_code); + $course_id = isset($course_info['course_id']) ? $course_info['course_id'] : null; + $course_visibility = $course_access_settings['visibility']; + + $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code); + + // Function logic - act on the data. + $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']); + if ($is_virtual_course) { + // If the current user is also subscribed in the real course to which this + // virtual course is linked, we don't need to display the virtual course entry in + // the course list - it is combined with the real course entry. + $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code); + $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); + if ($is_subscribed_in_target_course) { + return; //do not display this course entry + } + } + $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id()); + if ($has_virtual_courses) { + $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); + $course_display_title = $return_result['title']; + $course_display_code = $return_result['code']; + } else { + $course_display_title = $course_title; + $course_display_code = $course_visual_code; + } + + $s_course_status = $my_course['status']; + $is_coach = api_is_coach($my_course['id_session'],$course['code']); + + $s_htlm_status_icon = ''; + + $s_htlm_status_icon =Display::return_icon('blackboard_blue.png', get_lang('Course'), array('width' => '48px')); + /* + if ($s_course_status == 1) { + $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style' => 'width: 11px; height: 11px;')); + } + if ($s_course_status == 2 || ($is_coach && $s_course_status != 1)) { + $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('coachs.gif', get_lang('Status').': '.get_lang('GeneralCoach'), array('style' => 'width: 11px; height: 11px;')); + } + if (($s_course_status == 5 && !$is_coach) || empty($s_course_status)) { + $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course')).' '.Display::return_icon('students.gif', get_lang('Status').': '.get_lang('Student'), array('style' => 'width: 11px; height: 11px;')); + } + */ + // Display course entry. + $result.="\n\t"; + $result .= '
  • '.$s_htlm_status_icon.'
    '; + // Show a hyperlink to the course, unless the course is closed and user is not course admin. + if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { + if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + if (empty($my_course['id_session'])) { + $my_course['id_session'] = 0; + } + if ($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start == '0000-00-00') { + $result .= ''.$course_display_title.''; + } + } else { + $result .= ''.$course_display_title.''; + } + } else { + $result .= $course_display_title.' '.get_lang('CourseClosed'); + } + + // Show the course_code and teacher if chosen to display this. + if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= '
    '; + } + + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + $result .= $course_display_code; + } + + if (api_get_setting('display_teacher_in_courselist') == 'true') { + if (api_get_setting('use_session_mode')=='true' && !$nosession) { + $coachs_course = api_get_coachs_from_course($my_course['id_session'], $course['code']); + $course_coachs = array(); + if (is_array($coachs_course)) { + foreach ($coachs_course as $coach_course) { + $course_coachs[] = api_get_person_name($coach_course['firstname'], $coach_course['lastname']); + } + } + + if ($s_course_status == 1 || ($s_course_status == 5 && empty($my_course['id_session'])) || empty($s_course_status)) { + $result .= $course_teacher; + } + + if (($s_course_status == 5 && !empty($my_course['id_session'])) || ($is_coach && $s_course_status != 1)) { + if (is_array($course_coachs) && count($course_coachs)> 0 ) { + if (api_get_setting('display_coursecode_in_courselist') == 'true' && api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= ' – '; + } + $result .= get_lang('Coachs').': '.implode(', ',$course_coachs); + } + } + + } else { + $result .= $course_teacher; + } + + if(!empty($course_teacher_email)) { + $result .= ' ('.$course_teacher_email.')'; + } + } + + $result .= isset($course['special_course']) ? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : ''; + + $current_course_settings = CourseManager :: get_access_settings($my_course['k']); + + // Display the "what's new" icons. + $result .= Display :: show_notification($my_course); + + if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) { + + reset($digest); + $result .= ' + '; + } + $result .= '
  • '; + + if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + $session = ''; + $active = false; + if (!empty($my_course['session_name'])) { + + // Request for the name of the general coach + $sql = 'SELECT lastname, firstname,sc.name + FROM '.$tbl_session.' ts + LEFT JOIN '.$main_user_table .' tu + ON ts.id_coach = tu.user_id + INNER JOIN '.$tbl_session_category.' sc ON ts.session_category_id = sc.id + WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1'; + + $rs = Database::query($sql); + $sessioncoach = Database::store_result($rs); + $sessioncoach = $sessioncoach[0]; + + $session = array(); + $session['title'] = $my_course['session_name']; + $session_category_id = CourseManager::get_session_category_id_by_session_id($my_course['id_session']); + $session['category'] = $sessioncoach['name']; + if ($my_course['date_start'] == '0000-00-00') { + $session['dates'] = get_lang('WithoutTimeLimits'); + if (api_get_setting('show_session_coach') === 'true') { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = true; + } else { + $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end']; + if (api_get_setting('show_session_coach') === 'true') { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = ($date_start <= $now && $date_end >= $now); + } + } + $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active' => $active, 'session_category_id' => $session_category_id); + } else { + $output = array ($my_course['user_course_cat'], $result); + } + + return $output; + } } //end class CourseManager diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 4b26f1e691..5502b8cb07 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -935,5 +935,256 @@ class Display { } }); */ } + /** + * Display create course link + * + */ + function display_create_course_link() { + echo '
  • '.(api_get_setting('course_validation') == 'true' ? get_lang('CreateCourseRequest') : get_lang('CourseCreate')).'
  • '; + } + + + /** + * Display dashboard link + * + */ + function display_dashboard_link() { + echo '
  • '.get_lang('Dashboard').'
  • '; + } + + /** + * Display edit course list links + * + */ + function display_edit_course_list_links() { + echo '
  • '.get_lang('CourseManagement').'
  • '; + } + + /** + * Show history sessions + * + */ + function display_history_course_session() { + if (api_get_setting('use_session_mode') == 'true') { + if (isset($_GET['history']) && intval($_GET['history']) == 1) { + echo '
  • '.get_lang('DisplayTrainingList').'
  • '; + } else { + echo '
  • '.get_lang('HistoryTrainingSessions').'
  • '; + } + } + } + /** + * Returns the "what's new" icon notifications + * + * The general logic of this function is to track the last time the user + * entered the course and compare to what has changed inside this course + * since then, based on the item_property table inside this course. Note that, + * if the user never entered the course before, he will not see notification + * icons. This function takes session ID into account (if any) and only shows + * the corresponding notifications. + * @param array Course information array, containing at least elements 'db' and 'k' + * @return string The HTML link to be shown next to the course + */ + function show_notification($my_course) { + + $statistic_database = Database :: get_statistic_database(); + $user_id = api_get_user_id(); + $course_database = $my_course['db']; + $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_database); + $course_group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_database); + $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); + // Get the user's last access dates to all tools of this course + $sqlLastTrackInCourse = "SELECT * FROM $t_track_e_access + USE INDEX (access_cours_code, access_user_id) + WHERE access_cours_code = '".$my_course['k']."' + AND access_user_id = '$user_id' AND access_session_id ='".$my_course['id_session']."'"; + $resLastTrackInCourse = Database::query($sqlLastTrackInCourse); + + $oldestTrackDate = '3000-01-01 00:00:00'; + while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) { + $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date']; + if ($oldestTrackDate > $lastTrackInCourse['access_date']) { + $oldestTrackDate = $lastTrackInCourse['access_date']; + } + } + + // Get the last edits of all tools of this course. + $sql = "SELECT tet.*, tet.lastedit_date last_date, tet.tool tool, tet.ref ref, + tet.lastedit_type type, tet.to_group_id group_id, + ctt.image image, ctt.link link + FROM $tool_edit_table tet, $course_tool_table ctt + WHERE tet.lastedit_date > '$oldestTrackDate' + AND ctt.name = tet.tool + AND ctt.visibility = '1' + AND tet.lastedit_user_id != $user_id AND tet.id_session = '".$my_course['id_session']."' + ORDER BY tet.lastedit_date"; + $res = Database::query($sql); + // Get the group_id's with user membership. + $group_ids = GroupManager :: get_group_ids($course_database, $user_id); + $group_ids[] = 0; //add group 'everyone' + // Filter all selected items. + while ($res && ($item_property = Database::fetch_array($res))) { + // First thing to check is if the user never entered the tool + // or if his last visit was earlier than the last modification. + if ((!isset ($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) + // Drop the tool elements that are part of a group that the + // user is not part of. + && ((in_array($item_property['to_group_id'], $group_ids) + // Drop the dropbox, notebook and chat tools because we don't care. + && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT))) + // Take only what's visible or invisible but where the user is a teacher or where the visibility is unset. + && ($item_property['visibility'] == '1' || ($my_course['s'] == '1' && $item_property['visibility'] == '0') || !isset($item_property['visibility']))) { + + // Also drop announcements and events that are not for the user or his group. + if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && (($item_property['to_user_id'] != $user_id ) && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) continue; + // If it's a survey, make sure the user's invited. Otherwise drop it. + if ($item_property['tool'] == TOOL_SURVEY) { + $survey_info = survey_manager::get_survey($item_property['ref'], 0, $my_course['k']); + $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_database); + if (!in_array($user_id, $invited_users['course_users'])) continue; + } + $notifications[$item_property['tool']] = $item_property; + } + } + // Show all tool icons where there is something new. + $retvalue = ' '; + if (isset($notifications)) { + while (list($key, $notification) = each($notifications)) { + $lastDate = date('d/m/Y H:i', convert_mysql_date($notification['lastedit_date'])); + $type = $notification['lastedit_type']; + //$notification[image] = str_replace('.png', 'gif', $notification[image]); + //$notification[image] = str_replace('.gif', '_s.gif', $notification[image]); + if (empty($my_course['id_session'])) { + $my_course['id_session'] = 0; + } + $retvalue .= ''.' '; + } + } + return $retvalue; + } + /** + * Displays a digest e.g. short summary of new agenda and announcements items. + * This used to be displayed in the right hand menu, but is now + * disabled by default (see config settings in this file) because most people like + * the what's new icons better. + * + * @version 1.0 + */ + function display_digest($toolsList, $digest, $orderKey, $courses) { + if (is_array($digest) && (CONFVAL_showExtractInfo == SCRIPTVAL_UnderCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both)) { + // // // LEVEL 1 // // // + reset($digest); + echo "

    \n"; + while (list($key1) = each($digest)) { + if (is_array($digest[$key1])) { + // // // Title of LEVEL 1 // // // + echo "\n"; + if ($orderKey[0] == 'keyTools') { + $tools = $key1; + echo $toolsList[$key1]['name']; + } elseif ($orderKey[0] == 'keyCourse') { + $courseSysCode = $key1; + echo "", $courses[$key1]['courseCode'], "\n"; + } elseif ($orderKey[0] == 'keyTime') { + echo api_convert_and_format_date($digest[$key1], DATE_FORMAT_LONG, date_default_timezone_get()); + } + echo "\n"; + // // // End Of Title of LEVEL 1 // // // + // // // LEVEL 2 // // // + reset($digest[$key1]); + while (list ($key2) = each($digest[$key1])) { + // // // Title of LEVEL 2 // // // + echo "

    \n", "\n"; + if ($orderKey[1] == 'keyTools') { + $tools = $key2; + echo $toolsList[$key2][name]; + } elseif ($orderKey[1] == 'keyCourse') { + $courseSysCode = $key2; + echo "", $courses[$key2]['courseCode'], "\n"; + } elseif ($orderKey[1] == 'keyTime') { + echo api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get()); + } + echo "\n"; + echo "

    "; + // // // End Of Title of LEVEL 2 // // // + // // // LEVEL 3 // // // + reset($digest[$key1][$key2]); + while (list ($key3, $dataFromCourse) = each($digest[$key1][$key2])) { + // // // Title of LEVEL 3 // // // + if ($orderKey[2] == 'keyTools') { + $level3title = "".$toolsList[$key3]['name'].""; + } elseif ($orderKey[2] == 'keyCourse') { + $level3title = "• ".$courses[$key3]['courseCode']."\n"; + } elseif ($orderKey[2] == 'keyTime') { + $level3title = "• ".api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get()).""; + } + // // // End Of Title of LEVEL 3 // // // + // // // LEVEL 4 (data) // // // + reset($digest[$key1][$key2][$key3]); + while (list ($key4, $dataFromCourse) = each($digest[$key1][$key2][$key3])) { + echo $level3title, ' – ', api_substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT); + //adding ... (three dots) if the texts are too large and they are shortened + if (api_strlen($dataFromCourse) >= CONFVAL_NB_CHAR_FROM_CONTENT) { + echo '...'; + } + } + echo "
    \n"; + } + } + } + } + } + } // End function display_digest + /** + * Get the session box details as an array + * @param int Session ID + * @return array Empty array or session array ['title'=>'...','category'=>'','dates'=>'...','coach'=>'...','active'=>true/false,'session_category_id'=>int] + */ + function get_session_title_box($session_id) { + global $nosession; + + if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + global $now, $date_start, $date_end; + } + + $output = array(); + if (api_get_setting('use_session_mode') == 'true' && !$nosession) { + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); + $tbl_session_category = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY); + $active = false; + // Request for the name of the general coach + $sql ='SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id + FROM '.$tbl_session.' ts + LEFT JOIN '.$main_user_table .' tu + ON ts.id_coach = tu.user_id + WHERE ts.id='.intval($session_id); + $rs = Database::query($sql); + $session_info = Database::store_result($rs); + $session_info = $session_info[0]; + $session = array(); + $session['title'] = $session_info[2]; + $session['coach'] = ''; + + if ($session_info[3] == '0000-00-00') { + $session['dates'] = get_lang('WithoutTimeLimits'); + if (api_get_setting('show_session_coach') === 'true') { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]); + } + $active = true; + } else { + $session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4]; + if ( api_get_setting('show_session_coach') === 'true' ) { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]); + } + $active = ($date_start <= $now && $date_end >= $now); + } + $session['active'] = $active; + $session['session_category_id'] = $session_info[5]; + $output = $session; + } + return $output; + } } //end class Display \ No newline at end of file diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 4761d1238a..99e5fc508f 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -367,7 +367,7 @@ class SocialManager extends UserManager { * Helper functions definition */ public static function get_logged_user_course_html($my_course, $count) { - global $nosession; + global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode; if (api_get_setting('use_session_mode')=='true' && !$nosession) { global $now, $date_start, $date_end; } @@ -431,51 +431,17 @@ class SocialManager extends UserManager { //display course entry $result .= '
    '; - //$result .= ''; $result .= '

    '; $result .= $s_htlm_status_icon; //show a hyperlink to the course, unless the course is closed and user is not course admin if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { $result .= ' '.$course_title.'

    '; - /* - if(api_get_setting('use_session_mode')=='true' && !$nosession) { - if(empty($my_course['id_session'])) { - $my_course['id_session'] = 0; - } - if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') { - //$result .= ''.$course_display_title.''; - $result .= ''.$course_display_title.''; - } - } else { - //$result .= ''.$course_display_title.''; - $result .= ''.$course_display_title.''; - }*/ } else { $result .= $course_display_title." "." ".get_lang('CourseClosed').""; } - // show the course_code and teacher if chosen to display this - // we dont need this! - /* - if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= '
    '; - } - if (api_get_setting('display_coursecode_in_courselist') == 'true') { - $result .= $course_display_code; - } - if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= ' – '; - } - if (api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= $course_teacher; - if(!empty($course_teacher_email)) { - $result .= ' ('.$course_teacher_email.')'; - } - } - */ $current_course_settings = CourseManager :: get_access_settings($my_course['k']); // display the what's new icons - // $result .= show_notification($my_course); if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) { reset($digest); $result .= '
    '; // End of content section. // Register whether full admin or null admin course // by course through an array dbname x user status. @@ -1565,9 +464,7 @@ api_session_register('status'); /* RIGHT MENU */ echo '