Remove unused userlogCSV.php file, format code.

Remove unused classes TrackingUserLogCSV, TrackingUserLog
classes move functions To Tracking.
pull/2487/head
jmontoyaa 8 years ago
parent 3a5312095b
commit a5f06b88a3
  1. 4
      main/admin/user_information.php
  2. 2
      main/inc/lib/exercise.lib.php
  3. 9
      main/inc/lib/myspace.lib.php
  4. 6
      main/inc/lib/statistics.lib.php
  5. 759
      main/inc/lib/tracking.lib.php
  6. 9
      main/mySpace/myStudents.php
  7. 2
      main/tracking/courseLog.php
  8. 338
      main/tracking/userlogCSV.php

@ -328,7 +328,7 @@ if (count($sessions) > 0) {
$csvContent[] = array_map('strip_tags', $row);
$data[] = $row;
$result = TrackingUserLogCSV::getToolInformation(
$result = Tracking::getToolInformation(
$userId,
$courseInfo,
$id_session
@ -435,7 +435,7 @@ if (Database::num_rows($res) > 0) {
$csvContent[] = array_map('strip_tags', $row);
$data[] = $row;
$result = TrackingUserLogCSV::getToolInformation(
$result = Tracking::getToolInformation(
$userId,
$courseInfo,
0

@ -2141,7 +2141,7 @@ HOTSPOT;
//Admin can always delete the attempt
if (($locked == false || api_is_platform_admin()) && !api_is_student_boss()) {
$ip = TrackingUserLog::get_ip_from_user_event(
$ip = Tracking::get_ip_from_user_event(
$results[$i]['exe_user_id'],
api_get_utc_datetime(),
false

@ -2689,8 +2689,12 @@ class MySpace
* @param $orderDirection
* @return array
*/
public static function getUserDataAccessTrackingOverview($from, $numberItems, $column, $orderDirection)
{
public static function getUserDataAccessTrackingOverview(
$from,
$numberItems,
$column,
$orderDirection
) {
$user = Database::get_main_table(TABLE_MAIN_USER);
$course = Database::get_main_table(TABLE_MAIN_COURSE);
$track_e_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
@ -2733,7 +2737,6 @@ class MySpace
$sql .= " LIMIT $from,$numberItems";
$result = Database::query($sql);
//$clicks = Tracking::get_total_clicks_by_session();
$data = array();
while ($user = Database::fetch_assoc($result)) {
$data[] = $user;

@ -333,7 +333,11 @@ class Statistics
array('title' => get_lang('UserInfo'))
);
$row[6] = TrackingUserLog::get_ip_from_user_event($row[6], $row[7], true);
$row[6] = Tracking::get_ip_from_user_event(
$row[6],
$row[7],
true
);
if (empty($row[6])) {
$row[6] = get_lang('Unknown');
}

@ -1595,8 +1595,11 @@ class Tracking
*
* @return int Time in seconds
*/
public static function get_time_spent_on_the_course($user_id, $courseId, $session_id = 0)
{
public static function get_time_spent_on_the_course(
$user_id,
$courseId,
$session_id = 0
) {
$courseId = intval($courseId);
$session_id = intval($session_id);
$tbl_track_course = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
@ -2638,7 +2641,9 @@ class Tracking
if (empty($session_id)) {
$sql = "SELECT DISTINCT(id), use_max_score
FROM $lp_table
WHERE c_id = $course_id AND (session_id = 0 OR session_id IS NULL ) $condition_lp ";
WHERE
c_id = $course_id AND
(session_id = 0 OR session_id IS NULL) $condition_lp ";
} else {
$sql = "SELECT DISTINCT(id), use_max_score
FROM $lp_table
@ -2726,16 +2731,20 @@ class Tracking
}
// Getting the most recent attempt
$sql = "SELECT lp_iv.id as lp_item_view_id,
lp_iv.score as score,
lp_i.max_score,
lp_iv.max_score as max_score_item_view,
lp_i.path,
lp_i.item_type,
lp_i.id as iid
$sql = "SELECT
lp_iv.id as lp_item_view_id,
lp_iv.score as score,
lp_i.max_score,
lp_iv.max_score as max_score_item_view,
lp_i.path,
lp_i.item_type,
lp_i.id as iid
FROM $lp_item_view_table as lp_iv
INNER JOIN $lp_item_table as lp_i
ON (lp_i.id = lp_iv.lp_item_id AND lp_iv.c_id = lp_i.c_id)
ON (
lp_i.id = lp_iv.lp_item_id AND
lp_iv.c_id = lp_i.c_id
)
WHERE
lp_iv.c_id = $course_id AND
lp_i.c_id = $course_id AND
@ -2771,16 +2780,12 @@ class Tracking
lp_view_id = $lp_view_id AND
(lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."')
";
if ($debug) var_dump($sql);
$res_max_score = Database::query($sql);
while ($row_max_score = Database::fetch_array($res_max_score, 'ASSOC')) {
$list[] = $row_max_score;
}
}
if ($debug) var_dump($list);
// Go through each scorable element of this view
$score_of_scorm_calculate = 0;
foreach ($list as $row_max_score) {
@ -2789,7 +2794,6 @@ class Tracking
// Came from the lp_item_view
$max_score_item_view = $row_max_score['max_score_item_view'];
$score = $row_max_score['score'];
if ($debug) echo '<h3>Item Type: '.$row_max_score['item_type'].'</h3>';
if ($row_max_score['item_type'] == 'sco') {
@ -2830,12 +2834,12 @@ class Tracking
$sql = "SELECT exe_id, exe_result
FROM $tbl_stats_exercices
WHERE
exe_exo_id = '$item_path' AND
exe_user_id = $user_id AND
orig_lp_item_id = $item_id AND
exe_exo_id = '$item_path' AND
exe_user_id = $user_id AND
orig_lp_item_id = $item_id AND
orig_lp_item_view_id = $lp_item_view_id AND
c_id = $course_id AND
session_id = $session_id AND
c_id = $course_id AND
session_id = $session_id AND
status = ''
ORDER BY $order
LIMIT 1";
@ -3170,14 +3174,12 @@ class Tracking
public static function get_student_followed_by_coach($coach_id)
{
$coach_id = intval($coach_id);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$students = [];
// At first, courses where $coach_id is coach of the course //
$sql = 'SELECT session_id, c_id
FROM ' . $tbl_session_course_user.'
@ -3407,11 +3409,11 @@ class Tracking
// Then, courses where $coach_id is coach of the session
$sql = 'SELECT DISTINCT course.code
FROM ' . $tbl_session_course.' as session_course
INNER JOIN ' . $tbl_session.' as session
FROM '.$tbl_session_course.' as session_course
INNER JOIN '.$tbl_session.' as session
ON session.id = session_course.session_id
AND session.id_coach = ' . $coach_id.'
INNER JOIN ' . $tbl_course.' as course
AND session.id_coach = '.$coach_id.'
INNER JOIN '.$tbl_course.' as course
ON course.id = session_course.c_id';
if (api_is_multiple_url_enabled()) {
@ -3419,13 +3421,13 @@ class Tracking
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = 'SELECT DISTINCT c.code
FROM ' . $tbl_session_course.' as session_course
FROM '.$tbl_session_course.' as session_course
INNER JOIN '.$tbl_course.' c
ON (c.id = session_course.c_id)
INNER JOIN ' . $tbl_session.' as session
INNER JOIN '.$tbl_session.' as session
ON session.id = session_course.session_id
AND session.id_coach = ' . $coach_id.'
INNER JOIN ' . $tbl_course.' as course
AND session.id_coach = '.$coach_id.'
INNER JOIN '.$tbl_course.' as course
ON course.id = session_course.c_id
INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url
ON (course_rel_url.c_id = c.id)';
@ -3612,8 +3614,11 @@ class Tracking
* return count of assignments including sessions, 0 = session is not filtered
* @return int Number of documents
*/
public static function count_student_uploaded_documents($student_id, $course_code, $session_id = null)
{
public static function count_student_uploaded_documents(
$student_id,
$course_code,
$session_id = null
) {
// get the information of the course
$a_course = api_get_course_info($course_code);
if (!empty($a_course)) {
@ -3664,8 +3669,11 @@ class Tracking
* if param $session_id is null(default) return count of assignments
* including sessions, 0 = session is not filtered
*/
public static function count_student_assignments($student_id, $course_code = null, $session_id = null)
{
public static function count_student_assignments(
$student_id,
$course_code = null,
$session_id = null
) {
if (empty($student_id)) {
return 0;
}
@ -4242,8 +4250,6 @@ class Tracking
return $a_students;
}
/**
* get count clicks about tools most used by course
* @param int $courseId
@ -4284,132 +4290,6 @@ class Tracking
return $data;
}
/**
* Get total clicks
* THIS FUNCTION IS NOT BEEN USED, IT WAS MEANT TO BE USE WITH track_e_course_access.date_from and track_e_course_access.date_to,
* BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES
* @param int User Id
* @param int Course Id
* @param int Session Id (optional), if param $session_id is 0 (default) it'll return results including sessions, 0 = session is not filtered
* @param string Date from
* @param string Date to
* @return array Data
* @author César Perales cesar.perales@beeznest.com 2014-01-16
*/
public static function get_total_clicks($userId, $courseId, $sessionId = 0, $date_from = '', $date_to = '')
{
$course = api_get_course_info_by_id($courseId);
$tables = array(
TABLE_STATISTIC_TRACK_E_LASTACCESS => array(
'course' => 'c_id',
'session' => 'access_session_id',
'user' => 'access_user_id',
'start_date'=> 'access_date',
),
TABLE_STATISTIC_TRACK_E_ACCESS => array(
'course' => 'c_id',
'session' => 'access_session_id',
'user' => 'access_user_id',
'start_date'=> 'access_date',
),
#TABLE_STATISTIC_TRACK_E_LOGIN, array(,, 'login_date', 'logout_date');
TABLE_STATISTIC_TRACK_E_DOWNLOADS => array(
'course' => 'c_id',
'session' => 'down_session_id',
'user' => 'down_user_id',
'start_date'=> 'down_date',
),
TABLE_STATISTIC_TRACK_E_LINKS => array(
'course' => 'c_id',
'session' => 'links_session_id',
'user' => 'links_user_id',
'start_date'=> 'links_date',
),
TABLE_STATISTIC_TRACK_E_ONLINE => array(
'course' => 'c_id',
'session' => 'session_id',
'user' => 'login_user_id',
'start_date'=> 'login_date',
),
#TABLE_STATISTIC_TRACK_E_HOTPOTATOES,
/*TABLE_STATISTIC_TRACK_E_COURSE_ACCESS => array(
'course' => 'c_id',
'session' => 'session_id',
'user' => 'user_id',
'start_date'=> 'login_course_date',
'end_date' => 'logout_course_date',
),*/
TABLE_STATISTIC_TRACK_E_EXERCISES => array(
'course' => 'c_id',
'session' => 'session_id',
'user' => 'exe_user_id',
'start_date'=> 'exe_date',
),
TABLE_STATISTIC_TRACK_E_ATTEMPT => array(
'course' => 'c_id',
'session' => 'session_id',
'user' => 'user_id',
'start_date'=> 'tms',
),
#TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING,
#TABLE_STATISTIC_TRACK_E_DEFAULT,
TABLE_STATISTIC_TRACK_E_UPLOADS => array(
'course' => 'c_id',
'session' => 'upload_session_id',
'user' => 'upload_user_id',
'start_date'=> 'upload_date',
),
);
foreach ($tables as $tableName => $fields) {
//If session is defined, add it to query
$where = '';
if (isset($sessionId) && !empty($sessionId)) {
$sessionField = $fields['session'];
$where .= " AND $sessionField = $sessionId";
}
//filter by date
if (!empty($date_from) && !empty($date_to)) {
$fieldStartDate = $fields['start_date'];
if (!isset($fields['end_date'])) {
$where .= sprintf(" AND ($fieldStartDate BETWEEN '%s' AND '%s' )", $date_from, $date_to);
} else {
$fieldEndDate = $fields['end_date'];
$where .= sprintf(" AND fieldStartDate >= '%s'
AND $fieldEndDate <= '%s'", $date_from, $date_to);
}
}
//query
$sql = "SELECT %s as user, count(*) as total
FROM %s
WHERE %s = '%s'
AND %s = %s
$where
GROUP BY %s";
$sql = sprintf($sql,
$fields['user'], //user field
$tableName, //FROM
$fields['course'], //course condition
$course['real_id'], //course condition
$fields['user'], //user condition
$userId, //user condition
$fields['user'] //GROUP BY
);
$rs = Database::query($sql);
//iterate query
if (Database::num_rows($rs) > 0) {
while ($row = Database::fetch_array($rs)) {
$data[$row['user']] = (isset($data[$row['user']])) ? $data[$row['user']] + $row[total] : $row['total'];
}
}
}
return $data;
}
/**
* get documents most downloaded by course
* @param string Course code
@ -4419,9 +4299,11 @@ class Tracking
* @param int Limit (optional, default = 0, 0 = without limit)
* @return array documents downloaded
*/
public static function get_documents_most_downloaded_by_course($course_code, $session_id = 0, $limit = 0)
{
//protect data
public static function get_documents_most_downloaded_by_course(
$course_code,
$session_id = 0,
$limit = 0
) {
$courseId = api_get_course_int_id($course_code);
$data = array();
@ -4648,7 +4530,6 @@ class Tracking
}
$html = '';
// Course list
if ($show_courses) {
if (!empty($courses)) {
@ -4751,8 +4632,7 @@ class Tracking
// Session list
if (!empty($course_in_session)) {
$main_session_graph = '';
//Load graphics only when calling to an specific session
$session_graph = array();
// Load graphics only when calling to an specific session
$all_exercise_graph_name_list = array();
$my_results = array();
$all_exercise_graph_list = array();
@ -6514,6 +6394,139 @@ class Tracking
return $html;
}
/**
* Gets the IP of a given user, using the last login before the given date
* @param int User ID
* @param string Datetime
* @param bool Whether to return the IP as a link or just as an IP
* @param string If defined and return_as_link if true, will be used as the text to be shown as the link
* @return string IP address (or false on error)
* @assert (0,0) === false
*/
public static function get_ip_from_user_event(
$user_id,
$event_date,
$return_as_link = false,
$body_replace = null
) {
if (empty($user_id) || empty($event_date)) {
return false;
}
$user_id = intval($user_id);
$event_date = Database::escape_string($event_date);
$table_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_ip = "SELECT login_date, user_ip
FROM $table_login
WHERE login_user_id = $user_id AND login_date < '$event_date'
ORDER BY login_date DESC LIMIT 1";
$ip = '';
$res_ip = Database::query($sql_ip);
if ($res_ip !== false && Database::num_rows($res_ip) > 0) {
$row_ip = Database::fetch_row($res_ip);
if ($return_as_link) {
$ip = Display::url(
(empty($body_replace) ? $row_ip[1] : $body_replace), 'http://www.whatsmyip.org/ip-geo-location/?ip='.$row_ip[1],
array('title' => get_lang('TraceIP'), 'target' => '_blank')
);
} else {
$ip = $row_ip[1];
}
}
return $ip;
}
/**
* @param int $userId
* @param array $courseInfo
* @param int $sessionId
* @return array
*/
public static function getToolInformation(
$userId,
$courseInfo,
$sessionId = 0
) {
$csvContent = array();
$courseToolInformation = '';
$headerTool = array(
array(get_lang('Title')),
array(get_lang('CreatedAt')),
array(get_lang('UpdatedAt')),
);
$headerListForCSV = array();
foreach ($headerTool as $item) {
$headerListForCSV[] = $item[0];
}
$courseForumInformationArray = getForumCreatedByUser(
$userId,
$courseInfo['real_id'],
$sessionId
);
if (!empty($courseForumInformationArray)) {
$csvContent[] = array();
$csvContent[] = [get_lang('Forums')];
$csvContent[] = $headerListForCSV;
foreach ($courseForumInformationArray as $row) {
$csvContent[] = $row;
}
$courseToolInformation .= Display::page_subheader2(
get_lang('Forums')
);
$courseToolInformation .= Display::return_sortable_table(
$headerTool,
$courseForumInformationArray
);
}
$courseWorkInformationArray = getWorkCreatedByUser(
$userId,
$courseInfo['real_id'],
$sessionId
);
if (!empty($courseWorkInformationArray)) {
$csvContent[] = null;
$csvContent[] = [get_lang('Works')];
$csvContent[] = $headerListForCSV;
foreach ($courseWorkInformationArray as $row) {
$csvContent[] = $row;
}
$csvContent[] = null;
$courseToolInformation .= Display::page_subheader2(
get_lang('Works')
);
$courseToolInformation .= Display::return_sortable_table(
$headerTool,
$courseWorkInformationArray
);
}
$courseToolInformationTotal = null;
if (!empty($courseToolInformation)) {
$sessionTitle = null;
if (!empty($sessionId)) {
$sessionTitle = ' ('.api_get_session_name($sessionId).')';
}
$courseToolInformationTotal .= Display::page_subheader(
$courseInfo['title'].$sessionTitle
);
$courseToolInformationTotal .= $courseToolInformation;
}
return array(
'array' => $csvContent,
'html' => $courseToolInformationTotal
);
}
}
/**
@ -6808,7 +6821,11 @@ class TrackingCourseLog
);
$row[3] = $row['col3'];
$ip = TrackingUserLog::get_ip_from_user_event($row['user_id'], $row['col5'], true);
$ip = Tracking::get_ip_from_user_event(
$row['user_id'],
$row['col5'],
true
);
if (empty($ip)) {
$ip = get_lang('Unknown');
}
@ -6952,7 +6969,7 @@ class TrackingCourseLog
* @since Nov 2009
* @version 1.8.6.2
*/
public static function get_addtional_profile_information_of_field_by_user($field_id, $users)
public static function getAdditionalProfileInformationOfFieldByUser($field_id, $users)
{
// Database table definition
$table_user = Database::get_main_table(TABLE_MAIN_USER);
@ -7024,12 +7041,18 @@ class TrackingCourseLog
public function sort_users($a, $b)
{
return strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
return strcmp(
trim(api_strtolower($a[$_SESSION['tracking_column']])),
trim(api_strtolower($b[$_SESSION['tracking_column']]))
);
}
public function sort_users_desc($a, $b)
{
return strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
return strcmp(
trim(api_strtolower($b[$_SESSION['tracking_column']])),
trim(api_strtolower($a[$_SESSION['tracking_column']]))
);
}
/**
@ -7051,8 +7074,13 @@ class TrackingCourseLog
* @param $includeInvitedUsers boolean Whether include the invited users
* @return array
*/
public static function get_user_data($from, $number_of_items, $column, $direction, $includeInvitedUsers = false)
{
public static function get_user_data(
$from,
$number_of_items,
$column,
$direction,
$includeInvitedUsers = false
) {
global $user_ids, $course_code, $export_csv, $is_western_name_order, $csv_content, $session_id;
$course_code = Database::escape_string($course_code);
@ -7088,7 +7116,6 @@ class TrackingCourseLog
}
$invitedUsersCondition = '';
if (!$includeInvitedUsers) {
$invitedUsersCondition = " AND user.status != ".INVITEE;
}
@ -7308,383 +7335,3 @@ class TrackingCourseLog
return $users;
}
}
/**
* @package chamilo.tracking
*/
class TrackingUserLog
{
/**
* Gets the IP of a given user, using the last login before the given date
* @param int User ID
* @param string Datetime
* @param bool Whether to return the IP as a link or just as an IP
* @param string If defined and return_as_link if true, will be used as the text to be shown as the link
* @return string IP address (or false on error)
* @assert (0,0) === false
*/
public static function get_ip_from_user_event(
$user_id,
$event_date,
$return_as_link = false,
$body_replace = null
) {
if (empty($user_id) || empty($event_date)) {
return false;
}
$user_id = intval($user_id);
$event_date = Database::escape_string($event_date);
$table_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql_ip = "SELECT login_date, user_ip
FROM $table_login
WHERE login_user_id = $user_id AND login_date < '$event_date'
ORDER BY login_date DESC LIMIT 1";
$ip = '';
$res_ip = Database::query($sql_ip);
if ($res_ip !== false && Database::num_rows($res_ip) > 0) {
$row_ip = Database::fetch_row($res_ip);
if ($return_as_link) {
$ip = Display::url(
(empty($body_replace) ? $row_ip[1] : $body_replace), 'http://www.whatsmyip.org/ip-geo-location/?ip='.$row_ip[1],
array('title' => get_lang('TraceIP'), 'target' => '_blank')
);
} else {
$ip = $row_ip[1];
}
}
return $ip;
}
}
/**
* @package chamilo.tracking
*/
class TrackingUserLogCSV
{
/**
* Displays the number of logins every month for a specific user in a specific course.
* @param $view
* @param int $user_id
* @param int $course_id
* @param int $session_id
* @return array
*/
public function display_login_tracking_info($view, $user_id, $course_id, $session_id = 0)
{
$MonthsLong = $GLOBALS['MonthsLong'];
$track_access_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
// protected data
$user_id = intval($user_id);
$session_id = intval($session_id);
$course_id = intval($course_id);
$tempView = $view;
if (substr($view, 0, 1) == '1') {
$new_view = substr_replace($view, '0', 0, 1);
$title[1] = get_lang('LoginsAndAccessTools').get_lang('LoginsDetails');
$sql = "SELECT UNIX_TIMESTAMP(access_date), count(access_date)
FROM $track_access_table
WHERE access_user_id = $user_id
AND c_id = $course_id
AND access_session_id = $session_id
GROUP BY YEAR(access_date),MONTH(access_date)
ORDER BY YEAR(access_date),MONTH(access_date) ASC";
//$results = getManyResults2Col($sql);
$results = getManyResults3Col($sql);
$title_line = get_lang('LoginsTitleMonthColumn').';'.get_lang('LoginsTitleCountColumn')."\n";
$line = '';
$total = 0;
if (is_array($results)) {
for ($j = 0; $j < count($results); $j++) {
$line .= $results[$j][0].';'.$results[$j][1]."\n";
$total = $total + $results[$j][1];
}
$line .= get_lang('Total').";".$total."\n";
} else {
$line = get_lang('NoResult')."</center></td>";
}
} else {
$new_view = substr_replace($view, '1', 0, 1);
}
return array($title_line, $line);
}
/**
* Displays the exercise results for a specific user in a specific course.
* @param string $view
* @param int $user_id User ID
* @param string $courseCode Course code
* @return array
* @todo remove globals
*/
public function display_exercise_tracking_info($view, $userId, $courseCode)
{
global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong;
$courseId = api_get_course_int_id($courseCode);
$userId = intval($userId);
if (substr($view, 1, 1) == '1') {
$new_view = substr_replace($view, '0', 1, 1);
$title[1] = get_lang('ExercicesDetails');
$line = '';
$sql = "SELECT ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
WHERE te.c_id = $courseId
AND te.exe_user_id = $userId
AND te.exe_exo_id = ce.id
ORDER BY ce.title ASC, te.exe_date ASC";
$hpsql = "SELECT te.exe_name, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date)
FROM $TABLETRACK_HOTPOTATOES AS te
WHERE te.exe_user_id = '$userId' AND te.c_id = $courseId
ORDER BY te.c_id ASC, te.exe_date ASC";
$hpresults = StatsUtils::getManyResultsXCol($hpsql, 4);
$NoTestRes = 0;
$NoHPTestRes = 0;
$results = StatsUtils::getManyResultsXCol($sql, 4);
$title_line = get_lang('ExercicesTitleExerciceColumn').";".get_lang('Date').';'.get_lang('ExercicesTitleScoreColumn')."\n";
if (is_array($results)) {
for ($i = 0; $i < sizeof($results); $i++) {
$display_date = api_convert_and_format_date($results[$i][3], null, date_default_timezone_get());
$line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n";
}
} else {
// istvan begin
$NoTestRes = 1;
}
// The Result of Tests
if (is_array($hpresults)) {
for ($i = 0; $i < sizeof($hpresults); $i++) {
$title = GetQuizName($hpresults[$i][0], '');
if ($title == '') {
$title = basename($hpresults[$i][0]);
}
$display_date = api_convert_and_format_date($hpresults[$i][3], null, date_default_timezone_get());
$line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n";
}
} else {
$NoHPTestRes = 1;
}
if ($NoTestRes == 1 && $NoHPTestRes == 1) {
$line = get_lang('NoResult');
}
} else {
$new_view = substr_replace($view, '1', 1, 1);
}
return array($title_line, $line);
}
/**
* Displays the student publications for a specific user in a specific course.
* @todo remove globals
*/
public function display_student_publications_tracking_info($view, $user_id, $course_id)
{
global $TABLETRACK_UPLOADS, $TABLECOURSE_WORK;
$_course = api_get_course_info();
$user_id = intval($user_id);
$course_id = intval($course_id);
if (substr($view, 2, 1) == '1') {
$sql = "SELECT u.upload_date, w.title, w.author, w.url
FROM $TABLETRACK_UPLOADS u , $TABLECOURSE_WORK w
WHERE
u.upload_work_id = w.id AND
u.upload_user_id = '$user_id' AND
u.c_id = '$course_id'
ORDER BY u.upload_date DESC";
$results = StatsUtils::getManyResultsXCol($sql, 4);
$title[1] = get_lang('WorksDetails');
$line = '';
$title_line = get_lang('WorkTitle').";".get_lang('WorkAuthors').";".get_lang('Date')."\n";
if (is_array($results)) {
for ($j = 0; $j < count($results); $j++) {
$pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3];
$beautifulDate = api_convert_and_format_date($results[$j][0], null, date_default_timezone_get());
$line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n";
}
} else {
$line = get_lang('NoResult');
}
}
return array($title_line, $line);
}
/**
* Displays the links followed for a specific user in a specific course.
* @todo remove globals
*/
public function display_links_tracking_info($view, $userId, $courseCode)
{
global $TABLETRACK_LINKS, $TABLECOURSE_LINKS;
$courseId = api_get_course_int_id($courseCode);
$userId = intval($userId);
$line = null;
if (substr($view, 3, 1) == '1') {
$new_view = substr_replace($view, '0', 3, 1);
$title[1] = get_lang('LinksDetails');
$sql = "SELECT cl.title, cl.url
FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
WHERE sl.links_link_id = cl.id
AND sl.c_id = $courseId
AND sl.links_user_id = $userId
GROUP BY cl.title, cl.url";
$results = StatsUtils::getManyResults2Col($sql);
$title_line = get_lang('LinksTitleLinkColumn')."\n";
if (is_array($results)) {
for ($j = 0; $j < count($results); $j++) {
$line .= $results[$j][0]."\n";
}
} else {
$line = get_lang('NoResult');
}
} else {
$new_view = substr_replace($view, '1', 3, 1);
}
return array($title_line, $line);
}
/**
* Displays the documents downloaded for a specific user in a specific course.
* @param string kind of view inside tracking info
* @param int User id
* @param string Course code
* @param int Session id (optional, default = 0)
* @return void
*/
public function display_document_tracking_info($view, $user_id, $courseCode, $session_id = 0)
{
// protect data
$user_id = intval($user_id);
$courseId = api_get_course_int_id($courseCode);
$session_id = intval($session_id);
$downloads_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
if (substr($view, 4, 1) == '1') {
$new_view = substr_replace($view, '0', 4, 1);
$title[1] = get_lang('DocumentsDetails');
$sql = "SELECT down_doc_path
FROM $downloads_table
WHERE c_id = $courseId
AND down_user_id = $user_id
AND down_session_id = $session_id
GROUP BY down_doc_path";
$results = StatsUtils::getManyResults1Col($sql);
$title_line = get_lang('DocumentsTitleDocumentColumn')."\n";
$line = null;
if (is_array($results)) {
for ($j = 0; $j < count($results); $j++) {
$line .= $results[$j]."\n";
}
} else {
$line = get_lang('NoResult');
}
} else {
$new_view = substr_replace($view, '1', 4, 1);
}
return array($title_line, $line);
}
/**
* @param int $userId
* @param array $courseInfo
* @param int $sessionId
* @return array
*/
public static function getToolInformation(
$userId,
$courseInfo,
$sessionId = 0
) {
$csvContent = array();
$courseToolInformation = '';
$headerTool = array(
array(get_lang('Title')),
array(get_lang('CreatedAt')),
array(get_lang('UpdatedAt')),
);
$headerListForCSV = array();
foreach ($headerTool as $item) {
$headerListForCSV[] = $item[0];
}
$courseForumInformationArray = getForumCreatedByUser(
$userId,
$courseInfo['real_id'],
$sessionId
);
if (!empty($courseForumInformationArray)) {
$csvContent[] = array();
$csvContent[] = [get_lang('Forums')];
$csvContent[] = $headerListForCSV;
foreach ($courseForumInformationArray as $row) {
$csvContent[] = $row;
}
$courseToolInformation .= Display::page_subheader2(
get_lang('Forums')
);
$courseToolInformation .= Display::return_sortable_table(
$headerTool,
$courseForumInformationArray
);
}
$courseWorkInformationArray = getWorkCreatedByUser(
$userId,
$courseInfo['real_id'],
$sessionId
);
if (!empty($courseWorkInformationArray)) {
$csvContent[] = null;
$csvContent[] = [get_lang('Works')];
$csvContent[] = $headerListForCSV;
foreach ($courseWorkInformationArray as $row) {
$csvContent[] = $row;
}
$csvContent[] = null;
$courseToolInformation .= Display::page_subheader2(
get_lang('Works')
);
$courseToolInformation .= Display::return_sortable_table(
$headerTool,
$courseWorkInformationArray
);
}
$courseToolInformationTotal = null;
if (!empty($courseToolInformation)) {
$sessionTitle = null;
if (!empty($sessionId)) {
$sessionTitle = ' ('.api_get_session_name($sessionId).')';
}
$courseToolInformationTotal .= Display::page_subheader(
$courseInfo['title'].$sessionTitle
);
$courseToolInformationTotal .= $courseToolInformation;
}
return array(
'array' => $csvContent,
'html' => $courseToolInformationTotal
);
}
}

@ -469,7 +469,7 @@ $avg_student_progress = round($avg_student_progress, 2);
$time_spent_on_the_course = 0;
if (!empty($courseInfo)) {
$time_spent_on_the_course = api_time_to_hms(
Tracking:: get_time_spent_on_the_course(
Tracking::get_time_spent_on_the_course(
$user_info['user_id'],
$courseInfo['real_id'],
$sessionId
@ -478,12 +478,15 @@ if (!empty($courseInfo)) {
}
// get information about connections on the platform by student
$first_connection_date = Tracking :: get_first_connection_date($user_info['user_id']);
$first_connection_date = Tracking::get_first_connection_date($user_info['user_id']);
if ($first_connection_date == '') {
$first_connection_date = get_lang('NoConnexion');
}
$last_connection_date = Tracking :: get_last_connection_date($user_info['user_id'], true);
$last_connection_date = Tracking::get_last_connection_date(
$user_info['user_id'],
true
);
if ($last_connection_date == '') {
$last_connection_date = get_lang('NoConnexion');
}

@ -194,7 +194,7 @@ if (isset($_GET['additional_profile_field'])) {
foreach ($_GET['additional_profile_field'] as $fieldId) {
// Fetching only the user that are loaded NOT ALL user in the portal.
$userProfileInfo[$fieldId] = TrackingCourseLog::get_addtional_profile_information_of_field_by_user(
$userProfileInfo[$fieldId] = TrackingCourseLog::getAdditionalProfileInformationOfFieldByUser(
$fieldId,
$user_array
);

@ -1,338 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
// TODO: Is this file deprecated?
/**
* @package chamilo.tracking
* @todo clean code - structure is unclear and difficult to modify
*/
$uInfo = $_REQUEST['uInfo'];
$view = $_REQUEST['view'];
require_once __DIR__.'/../inc/global.inc.php';
// Roles and rights system
$user_id = api_get_user_id();
$course_id = api_get_course_id();
$courseId = api_get_course_int_id();
//YW Hack security to quick fix RolesRights bug
$is_allowed = true;
require_once api_get_path(SYS_CODE_PATH).'exercise/hotpotatoes.lib.php';
/* Header */
/*
$interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
$interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
*/
if ($uInfo) {
$interbreadcrumb[] = array(
"url" => "../user/userInfo.php?uInfo=$uInfo",
"name" => get_lang('BredCrumpUsers')
);
}
$nameTools = get_lang('ToolName');
/* Constants and variables */
$is_allowedToTrack = $is_courseAdmin;
$is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course(
$user_id,
$courseId
);
// Database Table Definitions
$TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_course_user = Database::get_main_table(
TABLE_MAIN_SESSION_COURSE_USER
);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
$now = api_get_utc_datetime();
$sql = "SELECT 1
FROM $tbl_session_course_user AS session_course_user
INNER JOIN $tbl_session AS session
ON session_course_user.session_id = session.id
AND ((access_start_date <= '$now'
AND access_end_date >= '$now')
OR (access_start_date IS NULL AND access_end_date IS NULL))
WHERE session_id='".api_get_session_id()."' AND c_id = $courseId";
//echo $sql;
$result = Database::query($sql);
if (!Database::num_rows($result)) {
$disabled = true;
}
$tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
$tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
$tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
// The variables for the days and the months
$DaysShort = api_get_week_days_short();
$DaysLong = api_get_week_days_long();
$MonthsLong = api_get_months_long();
$MonthsShort = api_get_months_short();
//$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
//$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
//YW hack security to fix RolesRights bug
$is_allowedToTrack = true; // allowed to track only user of one group
$is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
/* MAIN SECTION */
$title[0] = '';
$title[1] = '';
$line = '';
$title_line = '';
// check if uid is tutor of this group
if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
if (!$uInfo && !isset($uInfo)) {
/*
* Display list of user of this group
*/
if ($is_allowedToTrackEverybodyInCourse) {
// if user can track everybody : list user of course
$sql = "SELECT count(user_id)
FROM $TABLECOURSUSER
WHERE c_id = '$courseId' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
} else {
// if user can only track one group : list users of this group
$sql = "SELECT count(user)
FROM $TABLECOURSE_GROUPSUSER
WHERE group_id = '$_gid'";
}
$userGroupNb = StatsUtils::getOneResult($sql);
$step = 25; // number of student per page
if ($userGroupNb > $step) {
if (!isset($offset)) {
$offset = 0;
}
$next = $offset + $step;
$previous = $offset - $step;
$navLink = "";
if ($previous >= 0) {
}
if ($next < $userGroupNb) {
}
} else {
$offset = 0;
}
echo $navLink;
if (!settype($offset, 'integer') || !settype($step, 'integer')) {
die('Offset or step variables are not integers.');
} //sanity check of integer vars
if ($is_allowedToTrackEverybodyInCourse) {
// list of users in this course
$sql = "SELECT u.user_id, u.firstname,u.lastname
FROM $TABLECOURSUSER cu , $TABLEUSER u
WHERE cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
AND cu.c_id = '$courseId'
LIMIT $offset,$step";
} else {
// list of users of this group
$sql = "SELECT u.user_id, u.firstname,u.lastname
FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
WHERE gu.user_id = u.user_id
AND gu.group_id = '$_gid'
LIMIT $offset,$step";
}
$list_users = getManyResults3Col($sql);
for ($i = 0; $i < sizeof($list_users); $i++) {
// just sum $i up
}
} else { // if uInfo is set
/*
* Informations about student uInfo
*/
// these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
// another course, or group
if ($is_allowedToTrackEverybodyInCourse) {
// check if user is in this course
$tracking_is_accepted = $is_course_member;
$tracked_user_info = api_get_user_info($uInfo);
$title[0] = $tracked_user_info[1].'_'.$tracked_user_info[2];
} else {
// check if user is in the group of this tutor
$sql = "SELECT u.firstname,u.lastname, u.email
FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
WHERE gu.user_id = u.user_id
AND gu.group_id = '$_gid'
AND u.user_id = '$uInfo'";
$query = Database::query($sql);
$tracked_user_info = @Database::fetch_assoc($query);
if (is_array($tracked_user_info)) {
$tracking_is_accepted = true;
}
$title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
}
if ($tracking_is_accepted) {
$tracked_user_info['email'] == '' ? $mail_link = get_lang(
'NoEmail'
) : $mail_link = Display::encrypted_mailto_link(
$tracked_user_info['email']
);
if (!isset($view)) {
$view = '0000000';
}
//Logins
list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info(
$view,
$uInfo,
$courseId
);
//Exercise results
list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info(
$view,
$uInfo,
$_cid
);
//Student publications uploaded
list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info(
$view,
$uInfo,
$courseId
);
//Links usage
list($title_line4, $line4) = TrackingUserLogCSV::display_links_tracking_info(
$view,
$uInfo,
$_cid
);
//Documents downloaded
list($title_line5, $line5) = TrackingUserLogCSV::display_document_tracking_info(
$view,
$uInfo,
$_cid
);
$title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
$line = $line1.$line2.$line3.$line4.$line5;
} else {
echo get_lang('ErrorUserNotInGroup');
}
/*
* Scorm contents and Learning Path
*/
//TODO: scorm tools is in work and the logs will change in few days...
/*if(substr($view,5,1) == '1')
{
$new_view = substr_replace($view,'0',5,1);
$title[1]=get_lang('ScormContentColumn');
$line ='';
$sql = "SELECT id, name FROM $tbl_learnpath_main";
$result=Database::query($sql);
$ar=Database::fetch_array($result);
if (is_array($ar))
{
while ($ar['id'] != '') {
$lp_title = stripslashes($ar['name']);
echo "<tr><td>";
echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
echo "</td></tr>";
if ($ar['id']==$scormcontopen) { //have to list the students here
$contentId=$ar['id'];
$sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
"FROM $tbl_learnpath_item i " .
"INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
"INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
"WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
$result3=Database::query($sql3);
$ar3=Database::fetch_array($result3);
if (is_array($ar3)) {
$title_line=get_lang('ScormTitleColumn').";".get_lang('ScormStatusColumn').";".get_lang('ScormScoreColumn').";".get_lang('ScormTimeColumn')."\n";
while ($ar3['status'] != '') {
require_once('../lp/learnpathItem.class.php');
$time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
$line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
$ar3=Database::fetch_array($result3);
}
} else {
$line .= get_lang('ScormNeverOpened');
}
}
$ar=Database::fetch_array($result);
}
} else {
$noscorm=true;
}
if ($noscorm) {
$line=get_lang('NoResult');
}
} else {
$new_view = substr_replace($view,'1',5,1);
}*/
}
/*
* Export to a CSV file
* force the browser to save the file instead of opening it
*/
$len = strlen($title_line.$line);
header('Content-type: application/octet-stream');
//header('Content-Type: application/force-download');
header('Content-length: '.$len);
$filename = html_entity_decode(
str_replace(
":",
"",
str_replace(" ", "_", $title[0].'_'.$title[1].'.csv')
)
);
$filename = api_replace_dangerous_char($filename);
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
header('Content-Disposition: filename= '.$filename);
} else {
header('Content-Disposition: attachment; filename= '.$filename);
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
header('Pragma: ');
header('Cache-Control: ');
header(
'Cache-Control: public'
); // IE cannot download from sessions without a cache
}
header('Content-Description: '.$filename);
header('Content-transfer-encoding: binary');
echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
echo api_html_entity_decode($line, ENT_QUOTES, $charset);
exit;
} else { // not allowed
api_not_allowed();
}
Loading…
Cancel
Save