diff --git a/main/admin/user_information.php b/main/admin/user_information.php index 7ad0e7bd5d..5c3dbb7615 100755 --- a/main/admin/user_information.php +++ b/main/admin/user_information.php @@ -7,36 +7,24 @@ */ // name of the language file that needs to be included -$language_file = 'admin'; +$language_file = array('registration', 'index', 'tracking', 'exercice', 'admin', 'gradebook'); $cidReset = true; require_once '../inc/global.inc.php'; -$this_section=SECTION_PLATFORM_ADMIN; +$this_section = SECTION_PLATFORM_ADMIN; +require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php'; api_protect_admin_script(); -$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin')); -$interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList')); +$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList')); if (!isset($_GET['user_id'])) { api_not_allowed(); } -$user = api_get_user_info($_GET['user_id']); +$user = api_get_user_info($_GET['user_id'], true); $tool_name = $user['complete_name'].(empty($user['official_code'])?'':' ('.$user['official_code'].')'); -Display::display_header($tool_name); - $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); -if (isset($_GET['action'])) { - switch ($_GET['action']) { - case 'unsubscribe': - if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) { - CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code']); - Display::display_normal_message(get_lang('UserUnsubscribed')); - } else { - Display::display_error_message(get_lang('CannotUnsubscribeUserFromCourse')); - } - break; - } -} + // only allow platform admins to login_as, or session admins only for students (not teachers nor other admins) $login_as_icon = null; $editUser = null; @@ -45,24 +33,24 @@ if (api_is_platform_admin()) { '' - .Display::return_icon('login_as.gif', get_lang('LoginAs')).''; + .Display::return_icon('login_as.png', get_lang('LoginAs'), + array(), ICON_SIZE_MEDIUM).''; $editUser = Display::url( Display::return_icon( 'edit.png', get_lang('Edit'), - array() + array(), + ICON_SIZE_MEDIUM ), api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user['user_id'] ); -} -echo '
- '.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).' - - '.$login_as_icon.' - '.$editUser.' -
'; -echo Display::page_header($tool_name); + $exportLink = Display::url( + Display::return_icon( + 'export_csv.png', get_lang('ExportAsCSV'),'', ICON_SIZE_MEDIUM), + api_get_self().'?user_id='.$user['user_id'].'&action=export' + ); +} // Getting the user image $sysdir_array = UserManager::get_user_picture_path_by_id($user['user_id'], 'system', false, true); @@ -81,55 +69,104 @@ $onclick = $window_name."=window.open('".$fullurl."','".$window_name ."location=no,directories=no,status=no,menubar=no,scrollbars=no," ."resizable=no,width=".$width.",height=".$height.",left=200,top=20');" ." return false;"; -echo '' - .'
'; -echo '

'.($user['status'] == 1 ? get_lang('Teacher') : get_lang('Student')) - .'

'; -echo '

'.Display :: encrypted_mailto_link($user['mail'], $user['mail']).'

'; + // Show info about who created this user and when $creatorId = $user['creator_id']; $creatorInfo = api_get_user_info($creatorId); $registrationDate = $user['registration_date']; -echo '

'.sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id='.$creatorId, $creatorInfo['username'], api_get_utc_datetime($registrationDate)).'

'; -/** - * Show the sessions and the courses in which this user is subscribed - */ +$csvContent = array(); -echo Display::page_subheader(get_lang('SessionList')); +$table = new HTML_Table(array('class' => 'data_table')); +$table->setHeaderContents(0, 0, get_lang('Information')); +$csvContent[] = get_lang('Information'); +$data = array( + get_lang('Name') => $user['complete_name'], + get_lang('Email') => $user['email'], + get_lang('Phone') => $user['phone'], + get_lang('OfficialCode') => $user['official_code'], + get_lang('Online') => $user['user_is_online'] ? + Display::return_icon('online.png') : Display::return_icon('offline.png'), + get_lang('Status') => $user['status'] == 1 ? get_lang('Teacher') : get_lang('Student'), + null => sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id=' + .$creatorId, $creatorInfo['username'], api_get_utc_datetime($registrationDate)) +); -$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); -$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); -$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); -$tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); -$tbl_user = Database :: get_main_table(TABLE_MAIN_USER); +$row = 1; +foreach ($data as $label => $item) { + if (!empty($label)) { + $label = $label.': '; + } + $table->setCellContents($row, 0, $label.$item); + $csvContent[] = array($label, strip_tags($item)); + $row++; +} +$userInformation = $table->toHtml(); -$user_id = $user['user_id']; +$table = new HTML_Table(array('class' => 'data_table')); +$table->setHeaderContents(0, 0, get_lang('Tracking')); +$csvContent[] = get_lang('Tracking'); +$data = array( + get_lang('FirstLogin') => Tracking :: get_first_connection_date($user['user_id']), + get_lang('LatestLogin') => Tracking :: get_last_connection_date($user['user_id'], true) +); +$row = 1; +foreach ($data as $label => $item) { + if (!empty($label)) { + $label = $label.': '; + } + $table->setCellContents($row, 0, $label.$item); + $csvContent[] = array($label, strip_tags($item)); + $row++; +} +$trackingInformation = $table->toHtml(); +$tbl_session_course = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE); +$tbl_session_course_user = Database:: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); +$tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION); +$tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE); +$tbl_user = Database:: get_main_table(TABLE_MAIN_USER); +$user_id = $user['user_id']; $sessions = SessionManager::get_sessions_by_user($user_id, true); $personal_course_list = array(); if (count($sessions) > 0) { - $header[] = array (get_lang('Code'), true); - $header[] = array (get_lang('Title'), true); - $header[] = array (get_lang('Status'), true); - $header[] = array ('', false); + $sessionInformation = null; + $header = array( + array(get_lang('Code'), true), + array(get_lang('Title'), true), + array(get_lang('Status'), true), + array(get_lang('TimeSpentInTheCourse'), true), + array(get_lang('TotalPostsInAllForums'), true), + array('', false) + ); - foreach ($sessions as $session_item) { + $headerList = array(); + foreach ($header as $item) { + $headerList[] = $item[0]; + } + + $csvContent[] = array(); + $csvContent[] = array(get_lang('Sessions')); - $data = array (); + foreach ($sessions as $session_item) { + $data = array(); $personal_course_list = array(); $id_session = $session_item['session_id']; + $csvContent[] = array($session_item['session_name']); + $csvContent[] = $headerList; + foreach ($session_item['courses'] as $my_course) { $course_info = api_get_course_info($my_course['code']); - $row = array(); - $row[] = $my_course['code']; - $row[] = $course_info['title']; - $sessionStatus = SessionManager::get_user_status_in_session($user['user_id'], $my_course['code'], $id_session); + $sessionStatus = SessionManager::get_user_status_in_session( + $user['user_id'], + $my_course['code'], + $id_session + ); $status = null; - - switch($sessionStatus) { + switch ($sessionStatus) { + case 0: case STUDENT: $status = get_lang('Student'); break; @@ -137,21 +174,46 @@ if (count($sessions) > 0) { $status = get_lang('CourseCoach'); break; } - - $row[] = $status; - $tools = ''. - Display::return_icon('synthese_view.gif', get_lang('Overview')).''. - ''. - Display::return_icon('course_home.gif', get_lang('CourseHomepage')).''; + Display::return_icon('synthese_view.gif', get_lang('Overview')).''. + ''. + Display::return_icon('course_home.gif', get_lang('CourseHomepage')).''; if ($my_course['status'] == STUDENT) { $tools .= ''. - Display::return_icon('delete.png', get_lang('Delete')).''; + Display::return_icon('delete.png', get_lang('Delete')).''; } - $row[] = $tools; + + $timeSpent = api_time_to_hms( + Tracking :: get_time_spent_on_the_course( + $user['user_id'], + $course_info['code'], + $id_session + ) + ); + + $totalForumMessages = CourseManager::getCountPostInForumPerUser( + $user['user_id'], + $course_info['real_id'], + $id_session + ); + + $row = array( + Display::url( + $my_course['code'], + $course_info['course_public_url'].'?id_session='.$id_session + ), + $course_info['title'], + $status, + $timeSpent, + $totalForumMessages, + $tools + ); + + $csvContent[] = array_map('strip_tags', $row); $data[] = $row; } + if ($session_item['date_start'] == '0000-00-00') { $session_item['date_start'] = null; } @@ -163,13 +225,14 @@ if (count($sessions) > 0) { $dates = array_filter( array($session_item['date_start'], $session_item['date_end']) ); - echo Display::page_subheader( + + $sessionInformation .= Display::page_subheader( ''. $session_item['session_name'].'', ' '.implode(' - ', $dates) ); - Display :: display_sortable_table( + $sessionInformation .= Display::return_sortable_table( $header, $data, array(), @@ -178,10 +241,9 @@ if (count($sessions) > 0) { ); } } else { - echo '

'.get_lang('NoSessionsForThisUser').'

'; + $sessionInformation = '

'.get_lang('NoSessionsForThisUser').'

'; } - /** * Show the courses in which this user is subscribed */ @@ -190,53 +252,94 @@ $sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c'. ' AND cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' '; $res = Database::query($sql); if (Database::num_rows($res) > 0) { - $header = array(); - $header[] = array(get_lang('Code'), true); - $header[] = array(get_lang('Title'), true); - $header[] = array(get_lang('Status'), true); - $header[] = array('', false); - $data = array (); + $header = array( + array(get_lang('Code'), true), + array(get_lang('Title'), true), + array(get_lang('Status'), true), + array(get_lang('TimeSpentInTheCourse'), true), + array(get_lang('TotalPostsInAllForums'), true), + array('', false) + ); + + + $headerList = array(); + foreach ($header as $item) { + $headerList[] = $item[0]; + } + $csvContent[] = array(); + $csvContent[] = array(get_lang('Courses')); + $csvContent[] = $headerList; + + $data = array(); while ($course = Database::fetch_object($res)) { - $row = array (); - $row[] = $course->code; - $row[] = $course->title; - $row[] = $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'); + $tools = ''.Display::return_icon('synthese_view.gif', get_lang('Overview')).''. - ''.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'' . - ''.Display::return_icon('edit.gif', get_lang('Edit')).''; + ''.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'' . + ''.Display::return_icon('edit.gif', get_lang('Edit')).''; if ($course->status == STUDENT) { $tools .= ''.Display::return_icon('delete.png', get_lang('Delete')).''; } - $row[] = $tools; + + $timeSpent = api_time_to_hms( + Tracking :: get_time_spent_on_the_course( + $user['user_id'], + $course->code, + 0 + ) + ); + + $totalForumMessages = CourseManager::getCountPostInForumPerUser( + $user['user_id'], + $course->id, + 0 + ); + $courseInfo = api_get_course_info($course->code); + $row = array ( + Display::url($course->code, $courseInfo['course_public_url']), + $course->title, + $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'), + $timeSpent, + $totalForumMessages, + $tools, + ); + + $csvContent[] = array_map('strip_tags', $row); $data[] = $row; } - echo Display::page_subheader(get_lang('Courses')); - Display :: display_sortable_table( + $courseInformation = Display::page_subheader(get_lang('Courses')); + $courseInformation .= Display::return_sortable_table( $header, $data, - array (), - array (), - array ('user_id' => intval($_GET['user_id'])) + array(), + array(), + array('user_id' => intval($_GET['user_id'])) ); } else { - echo '

'.get_lang('NoCoursesForThisUser').'

'; + $courseInformation = '

'.get_lang('NoCoursesForThisUser').'

'; } + /** * Show the URL in which this user is subscribed */ +$urlInformation = null; if (api_is_multiple_url_enabled()) { $url_list= UrlManager::get_access_url_from_user($user['user_id']); if (count($url_list) > 0) { $header = array(); $header[] = array('URL', true); - $data = array (); + $data = array(); + + $csvContent[] = array(); + $csvContent[] = array('Url'); foreach ($url_list as $url) { $row = array(); $row[] = Display::url($url['url'], $url['url']); + $csvContent[] = array_map('strip_tags', $row); $data[] = $row; } - echo '

'.get_lang('URLList').'

'; - Display :: display_sortable_table( + + $urlInformation = Display::page_subheader(get_lang('URLList')); + $urlInformation .= Display::return_sortable_table( $header, $data, array(), @@ -244,8 +347,64 @@ if (api_is_multiple_url_enabled()) { array('user_id' => intval($_GET['user_id'])) ); } else { - echo '

'.get_lang('NoUrlForThisUser').'

'; + $urlInformation = '

'.get_lang('NoUrlForThisUser').'

'; + } +} + +$message = null; + +if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'unsubscribe': + if (CourseManager::get_user_in_course_status($_GET['user_id'], $_GET['course_code']) == STUDENT) { + CourseManager::unsubscribe_user($_GET['user_id'], $_GET['course_code']); + $message = Display::return_message(get_lang('UserUnsubscribed')); + } else { + $message = Display::return_message( + get_lang('CannotUnsubscribeUserFromCourse'), + 'error' + ); + } + break; + case 'export': + Export :: export_table_csv_utf8($csvContent, 'user_information_'.$user); + exit; + break; } } +Display::display_header($tool_name); + +echo '
+ '.Display::return_icon('statistics.png', get_lang('Reporting'), '', ICON_SIZE_MEDIUM).' + + '.$login_as_icon.' + '.$editUser.' + '.$exportLink.' +
'; + +echo Display::page_header($tool_name); + +echo '
'; +echo '
'; +echo '' + .'
'; +echo '
'; + +echo $message; + +echo '
'; +echo $userInformation; +echo '
'; + +echo '
'; +echo $trackingInformation; +echo '
'; +echo '
'; + +echo Display::page_subheader(get_lang('SessionList')); +echo $sessionInformation; +echo $courseInformation; +echo $urlInformation; + Display::display_footer(); diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index fc650979d3..feb6ef3fff 100755 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -2442,7 +2442,7 @@ class CourseManager ); //@api_mail($recipient_name, $emailto, $emailsubject, $emailbody, $sender_name,$email_admin); - api_mail_html($recipient_name, $emailto, $emailsubject, $emailbody, + api_mail_html($recipient_name, $emailto, $emailsubject, $emailbody, $sender_name, $email_admin, null, null, null, $additional_parameters); } } @@ -4736,4 +4736,95 @@ class CourseManager return $courseAccess; } + /** + * @param int $courseId + * @param int $sessionId + * @param bool $getAllSessions + * @return mixed + */ + public static function getCountForum( + $courseId, + $sessionId = 0, + $getAllSessions = false + ) { + $forum = Database::get_course_table(TABLE_FORUM); + if ($getAllSessions) { + $sql = "SELECT count(*) as count + FROM $forum f + where f.c_id = %s"; + } else { + $sql = "SELECT count(*) as count + FROM $forum f + where f.c_id = %s and f.session_id = %s"; + } + $sql_query = sprintf($sql, $courseId, $sessionId); + $result = Database::query($sql_query); + $row = Database::fetch_array($result); + return $row['count']; + } + + /** + * @param int $userId + * @param int $courseId + * @param int $sessionId + * @return mixed + */ + public static function getCountPostInForumPerUser( + $userId, + $courseId, + $sessionId = 0 + ) { + $forum = Database::get_course_table(TABLE_FORUM); + $forum_post = Database::get_course_table(TABLE_FORUM_POST); + + $sql = "SELECT count(distinct post_id) as count + FROM $forum_post p + INNER JOIN $forum f + ON f.forum_id = p.forum_id AND f.c_id = p.c_id + WHERE p.poster_id = %s and f.session_id = %s and p.c_id = %s"; + + $sql = sprintf( + $sql, + intval($userId), + intval($sessionId), + intval($courseId) + ); + + $result = Database::query($sql); + $row = Database::fetch_array($result); + return $row['count']; + } + + /** + * @param int $userId + * @param int $courseId + * @param int $sessionId + * @return mixed + */ + public static function getCountForumPerUser( + $userId, + $courseId, + $sessionId = 0 + ) { + $forum = Database::get_course_table(TABLE_FORUM); + $forum_post = Database::get_course_table(TABLE_FORUM_POST); + + $sql = "SELECT count(distinct f.forum_id) as count + FROM $forum_post p + INNER JOIN $forum f + ON f.forum_id = p.forum_id AND f.c_id = p.c_id + WHERE p.poster_id = %s and f.session_id = %s and p.c_id = %s"; + + $sql = sprintf( + $sql, + intval($userId), + intval($sessionId), + intval($courseId) + ); + + $result = Database::query($sql); + $row = Database::fetch_array($result); + return $row['count']; + } + } diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 48796c808e..ca8bca1d79 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -235,6 +235,30 @@ class Display } } + public static function return_sortable_table( + $header, + $content, + $sorting_options = array(), + $paging_options = array(), + $query_vars = null, + $form_actions = array(), + $style = 'table' + ) { + ob_start(); + self::display_sortable_table( + $header, + $content, + $sorting_options, + $paging_options, + $query_vars, + $form_actions, + $style + ); + $content = ob_get_contents(); + ob_end_clean(); + return $content; + } + /** * Shows a nice grid * @param string grid name (important to create css) diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 63a1fcff85..88f92fa4d0 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -942,23 +942,15 @@ class SessionManager isset($survey_user_list[$user_id]) ? $survey_user_list[$user_id] ++ : $survey_user_list[$user_id] = 1; } } + /** * Forums */ - //total - if ($getAllSessions) { - $sql = "SELECT count(*) as count - FROM $forum f - where f.c_id = %s"; - } else { - $sql = "SELECT count(*) as count - FROM $forum f - where f.c_id = %s and f.session_id = %s"; - } - $sql_query = sprintf($sql, $course['real_id'], $sessionId); - $result = Database::query($sql_query); - $row = Database::fetch_array($result); - $forums_total = $row['count']; + $forums_total = CourseManager::getCountForum( + $course['real_id'], + $sessionId, + $getAllSessions + ); //process table info foreach ($users as $user) { @@ -1042,16 +1034,11 @@ class SessionManager } //Forums - #$forums_done = Tracking::count_student_messages($user['user_id'], $course_code, $session_id); - $sql = "SELECT count(distinct f.forum_id) as count FROM $forum_post p - INNER JOIN $forum f ON f.forum_id = p.forum_id - WHERE p.poster_id = %s and f.session_id = %s and p.c_id = %s"; - $sql_query = sprintf($sql, $user['user_id'], $user['id_session'], $course['real_id']); - - $result = Database::query($sql_query); - $row = Database::fetch_array($result); - - $forums_done = $row['count']; + $forums_done = CourseManager::getCountForumPerUser( + $user['user_id'], + $course['real_id'], + $user['id_session'] + ); $forums_left = $forums_total - $forums_done; if (!empty($forums_total)) { $forums_progress = round((( $forums_done * 100 ) / $forums_total), 2);