Add ip in stats table, format code fix PHP warnings BT#16541

pull/3090/head
Julio Montoya 6 years ago
parent 50bdbb1180
commit 6a3f709d1b
  1. 65
      main/inc/ajax/myspace.ajax.php
  2. 563
      main/inc/lib/myspace.lib.php
  3. 4
      main/inc/lib/pear/HTML/Table.php
  4. 7
      main/inc/lib/sortable_table.class.php
  5. 124
      main/inc/lib/statistics.lib.php
  6. 48
      main/mySpace/access_details.php

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -42,12 +43,14 @@ switch ($action) {
$sessionId
);
}
$foo_print = grapher($sql_result, $start_date, $end_date, $type);
$foo_print = MySpace::grapher($sql_result, $start_date, $end_date, $type);
echo $foo_print;
break;
case 'access_detail_by_date':
$db = ['is_empty' => true];
$export = isset($_REQUEST['export']) ? $_REQUEST['export'] : false;
$result = ['is_empty' => true];
$start_date = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : '';
$end_date = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : '';
$user_id = isset($_REQUEST['student']) ? $_REQUEST['student'] : '';
@ -56,45 +59,73 @@ switch ($action) {
$sessionId = isset($_REQUEST['session_id']) ? $_REQUEST['session_id'] : 0;
$courseInfo = api_get_course_info($course_code);
$sql_result = MySpace::get_connections_to_course_by_date(
$connections = MySpace::get_connections_to_course_by_date(
$user_id,
$courseInfo,
$sessionId,
$start_date,
$end_date
$end_date,
true
);
if (is_array($sql_result) && count($sql_result) > 0) {
$db['is_empty'] = false;
$db['result'] = convert_to_string($sql_result);
$rst = get_stats(
if (is_array($connections) && count($connections) > 0) {
$result['is_empty'] = false;
$tableData = [];
foreach ($connections as $data) {
$item = [
api_get_local_time($data['login']),
api_time_to_hms(api_strtotime($data['logout']) - api_strtotime($data['login'])),
$data['user_ip']
];
$tableData[] = $item;
}
$table = new SortableTableFromArray(
$tableData,
0,
500,
'stat_table',
null,
'stat_table'
);
$table->set_header(1, get_lang('LoginDate'), false);
$table->set_header(2, get_lang('Duration'), false);
$table->set_header(3, get_lang('IP'), false);
$result['result'] = $table->return_table();
if ($export) {
Export::arrayToXls($table->toArray());
exit;
}
$rst = MySpace::getStats(
$user_id,
$courseInfo,
$sessionId,
$start_date,
$end_date
);
$foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
$foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
$foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
$db['stats'] = $foo_stats;
$db['graph_result'] = grapher($sql_result, $start_date, $end_date, $type);
$stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
$stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
$stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
$result['stats'] = $stats;
$result['graph_result'] = MySpace::grapher($connections, $start_date, $end_date, $type);
} else {
$db['result'] = Display::return_message(
$result['result'] = Display::return_message(
get_lang('NoDataAvailable'),
'warning'
);
$db['graph_result'] = Display::return_message(
$result['graph_result'] = Display::return_message(
get_lang('NoDataAvailable'),
'warning'
);
$db['stats'] = Display::return_message(
$result['stats'] = Display::return_message(
get_lang('NoDataAvailable'),
'warning'
);
}
header('Cache-Control: no-cache');
echo json_encode($db);
echo json_encode($result);
break;
}
exit;

@ -8,8 +8,6 @@ use CpChart\Image as pImage;
/**
* Class MySpace.
*
* @package chamilo.reporting
*/
class MySpace
{
@ -2125,12 +2123,22 @@ class MySpace
'.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>
</center>';
$scoreInCourse = null;
if (null !== $avg_score_in_course) {
if (is_numeric($avg_score_in_course)) {
$scoreInCourse = $avg_score_in_course.'%';
} else {
$scoreInCourse = $avg_score_in_course;
}
}
$csv_content[] = [
api_html_entity_decode($row_course[1], ENT_QUOTES, $charset),
$nb_students_in_course,
$avg_time_spent_in_course,
is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course.'%' : $avg_score_in_course,
$scoreInCourse,
is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%',
$avg_messages_in_course,
$avg_assignments_in_course,
@ -2956,6 +2964,7 @@ class MySpace
* @param int $sessionId
* @param string $start_date
* @param string $end_date
* @param bool $addUserIp
*
* @author Jorge Frisancho Jibaja
* @author Julio Montoya <gugli100@gmail.com> fixing the function
@ -2969,14 +2978,15 @@ class MySpace
$course_info,
$sessionId,
$start_date,
$end_date
$end_date,
$addUserIp = false
) {
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$user_id = (int) $user_id;
$connections = [];
if (!empty($course_info)) {
$courseId = (int) $course_info['real_id'];
$end_date = add_day_to($end_date);
$end_date = self::add_day_to($end_date);
$start_date = Database::escape_string($start_date);
$end_date = Database::escape_string($end_date);
@ -2984,7 +2994,8 @@ class MySpace
$sql = "SELECT
login_course_date,
logout_course_date,
TIMESTAMPDIFF(SECOND, login_course_date, logout_course_date) duration
TIMESTAMPDIFF(SECOND, login_course_date, logout_course_date) duration,
user_ip
FROM $table
WHERE
user_id = $user_id AND
@ -2996,47 +3007,50 @@ class MySpace
$rs = Database::query($sql);
while ($row = Database::fetch_array($rs)) {
$connections[] = [
$item = [
'login' => $row['login_course_date'],
'logout' => $row['logout_course_date'],
'duration' => $row['duration'],
];
if ($addUserIp) {
$item['user_ip'] = $row['user_ip'];
}
$connections[] = $item;
}
}
return $connections;
}
}
/**
* @param $user_id
* @param array $course_info
* @param int $sessionId
* @param null $start_date
* @param null $end_date
*
* @return array
*/
function get_stats($user_id, $course_info, $sessionId, $start_date = null, $end_date = null)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$result = [];
if (!empty($course_info)) {
$stringStartDate = '';
$stringEndDate = '';
if ($start_date != null && $end_date != null) {
$end_date = add_day_to($end_date);
/**
* @param int $user_id
* @param array $course_info
* @param int $sessionId
* @param null $start_date
* @param null $end_date
*
* @return array
*/
public static function getStats($user_id, $course_info, $sessionId, $start_date = null, $end_date = null)
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$result = [];
if (!empty($course_info)) {
$stringStartDate = '';
$stringEndDate = '';
if ($start_date != null && $end_date != null) {
$end_date = self::add_day_to($end_date);
$start_date = Database::escape_string($start_date);
$end_date = Database::escape_string($end_date);
$start_date = Database::escape_string($start_date);
$end_date = Database::escape_string($end_date);
$stringStartDate = "AND login_course_date BETWEEN '$start_date' AND '$end_date'";
$stringEndDate = "AND logout_course_date BETWEEN '$start_date' AND '$end_date'";
}
$user_id = (int) $user_id;
$courseId = (int) $course_info['real_id'];
$sessionCondition = api_get_session_condition($sessionId);
$sql = "SELECT
$stringStartDate = "AND login_course_date BETWEEN '$start_date' AND '$end_date'";
$stringEndDate = "AND logout_course_date BETWEEN '$start_date' AND '$end_date'";
}
$user_id = (int) $user_id;
$courseId = (int) $course_info['real_id'];
$sessionCondition = api_get_session_condition($sessionId);
$sql = "SELECT
SEC_TO_TIME(AVG(time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
SEC_TO_TIME(SUM(time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
count(user_id) as times
@ -3047,284 +3061,253 @@ function get_stats($user_id, $course_info, $sessionId, $start_date = null, $end_
$sessionCondition
ORDER BY login_course_date ASC";
$rs = Database::query($sql);
if ($row = Database::fetch_array($rs)) {
$foo_avg = $row['avrg'];
$foo_total = $row['total'];
$foo_times = $row['times'];
$result = [
'avg' => $foo_avg,
'total' => $foo_total,
'times' => $foo_times,
];
$rs = Database::query($sql);
if ($row = Database::fetch_array($rs)) {
$foo_avg = $row['avrg'];
$foo_total = $row['total'];
$foo_times = $row['times'];
$result = [
'avg' => $foo_avg,
'total' => $foo_total,
'times' => $foo_times,
];
}
}
}
return $result;
}
function add_day_to($end_date)
{
$foo_date = strtotime($end_date);
$foo_date = strtotime(' +1 day', $foo_date);
$foo_date = date('Y-m-d', $foo_date);
return $foo_date;
}
/**
* Converte an array to a table in html.
*
* @param array $result
*
* @author Jorge Frisancho Jibaja
*
* @version OCT-22- 2010
*
* @return string
*/
function convert_to_string($result)
{
$html = '<table class="table">';
if (!empty($result)) {
foreach ($result as $key => $data) {
$html .= '<tr><td>';
$html .= api_get_local_time($data['login']);
$html .= '</td>';
$html .= '<td>';
$html .= api_time_to_hms(api_strtotime($data['logout']) - api_strtotime($data['login']));
$html .= '</tr></td>';
}
return $result;
}
$html .= '</table>';
return $html;
}
public static function add_day_to($end_date)
{
$foo_date = strtotime($end_date);
$foo_date = strtotime(' +1 day', $foo_date);
$foo_date = date('Y-m-d', $foo_date);
/**
* This function draw the graphic to be displayed on the user view as an image.
*
* @param array $sql_result
* @param string $start_date
* @param string $end_date
* @param string $type
*
* @author Jorge Frisancho Jibaja
*
* @version OCT-22- 2010
*
* @return string
*/
function grapher($sql_result, $start_date, $end_date, $type = '')
{
if (empty($start_date)) {
$start_date = '';
}
if (empty($end_date)) {
$end_date = '';
}
if ($type == '') {
$type = 'day';
return $foo_date;
}
$main_year = $main_month_year = $main_day = [];
$period = new DatePeriod(
new DateTime($start_date),
new DateInterval('P1D'),
new DateTime($end_date)
);
/**
* This function draw the graphic to be displayed on the user view as an image.
*
* @param array $sql_result
* @param string $start_date
* @param string $end_date
* @param string $type
*
* @author Jorge Frisancho Jibaja
*
* @version OCT-22- 2010
*
* @return string
*/
public static function grapher($sql_result, $start_date, $end_date, $type = '')
{
if (empty($start_date)) {
$start_date = '';
}
if (empty($end_date)) {
$end_date = '';
}
if ($type == '') {
$type = 'day';
}
$main_year = $main_month_year = $main_day = [];
foreach ($period as $date) {
$main_day[$date->format('d-m-Y')] = 0;
}
$period = new DatePeriod(
new DateTime($start_date),
new DateInterval('P1D'),
new DateTime($end_date)
);
$period = new DatePeriod(
new DateTime($start_date),
new DateInterval('P1M'),
new DateTime($end_date)
);
foreach ($period as $date) {
$main_day[$date->format('d-m-Y')] = 0;
}
foreach ($period as $date) {
$main_month_year[$date->format('m-Y')] = 0;
}
$period = new DatePeriod(
new DateTime($start_date),
new DateInterval('P1M'),
new DateTime($end_date)
);
$i = 0;
if (is_array($sql_result) && count($sql_result) > 0) {
foreach ($sql_result as $key => $data) {
$login = api_strtotime($data['login']);
$logout = api_strtotime($data['logout']);
//creating the main array
if (isset($main_month_year[date('m-Y', $login)])) {
$main_month_year[date('m-Y', $login)] += float_format(($logout - $login) / 60, 0);
foreach ($period as $date) {
$main_month_year[$date->format('m-Y')] = 0;
}
$i = 0;
if (is_array($sql_result) && count($sql_result) > 0) {
foreach ($sql_result as $key => $data) {
$login = api_strtotime($data['login']);
$logout = api_strtotime($data['logout']);
//creating the main array
if (isset($main_month_year[date('m-Y', $login)])) {
$main_month_year[date('m-Y', $login)] += float_format(($logout - $login) / 60, 0);
}
if (isset($main_day[date('d-m-Y', $login)])) {
$main_day[date('d-m-Y', $login)] += float_format(($logout - $login) / 60, 0);
}
if ($i > 500) {
break;
}
$i++;
}
if (isset($main_day[date('d-m-Y', $login)])) {
$main_day[date('d-m-Y', $login)] += float_format(($logout - $login) / 60, 0);
switch ($type) {
case 'day':
$main_date = $main_day;
break;
case 'month':
$main_date = $main_month_year;
break;
case 'year':
$main_date = $main_year;
break;
}
if ($i > 500) {
break;
$labels = array_keys($main_date);
if (count($main_date) == 1) {
$labels = $labels[0];
$main_date = $main_date[$labels];
}
$i++;
}
switch ($type) {
case 'day':
$main_date = $main_day;
break;
case 'month':
$main_date = $main_month_year;
break;
case 'year':
$main_date = $main_year;
break;
}
$labels = array_keys($main_date);
if (count($main_date) == 1) {
$labels = $labels[0];
$main_date = $main_date[$labels];
}
/* Create and populate the pData object */
$myData = new pData();
$myData->addPoints($main_date, 'Serie1');
if (count($main_date) != 1) {
$myData->addPoints($labels, 'Labels');
$myData->setSerieDescription('Labels', 'Months');
$myData->setAbscissa('Labels');
}
$myData->setSerieWeight('Serie1', 1);
$myData->setSerieDescription('Serie1', get_lang('MyResults'));
$myData->setAxisName(0, get_lang('Minutes'));
$myData->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true);
// Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH);
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]);
$chartHash = $myCache->getHash($myData);
if ($myCache->isInCache($chartHash)) {
//if we already created the img
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} else {
/* Define width, height and angle */
$mainWidth = 760;
$mainHeight = 230;
$angle = 50;
/* Create the pChart object */
$myPicture = new pImage($mainWidth, $mainHeight, $myData);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Draw the background */
$settings = ["R" => 255, "G" => 255, "B" => 255];
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings);
/* Add a border to the picture */
$myPicture->drawRectangle(
0,
0,
$mainWidth - 1,
$mainHeight - 1,
["R" => 0, "G" => 0, "B" => 0]
);
/* Create and populate the pData object */
$myData = new pData();
$myData->addPoints($main_date, 'Serie1');
if (count($main_date) != 1) {
$myData->addPoints($labels, 'Labels');
$myData->setSerieDescription('Labels', 'Months');
$myData->setAbscissa('Labels');
}
$myData->setSerieWeight('Serie1', 1);
$myData->setSerieDescription('Serie1', get_lang('MyResults'));
$myData->setAxisName(0, get_lang('Minutes'));
$myData->loadPalette(api_get_path(SYS_CODE_PATH).'palettes/pchart/default.color', true);
/* Set the default font */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 10, ]
);
/* Write the chart title */
$myPicture->drawText(
$mainWidth / 2,
30,
get_lang('TimeSpentInTheCourse'),
[
"FontSize" => 12,
"Align" => TEXT_ALIGN_BOTTOMMIDDLE,
]
);
// Cache definition
$cachePath = api_get_path(SYS_ARCHIVE_PATH);
$myCache = new pCache(['CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)]);
$chartHash = $myCache->getHash($myData);
/* Set the default font */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 8,
]
);
if ($myCache->isInCache($chartHash)) {
//if we already created the img
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
} else {
/* Define width, height and angle */
$mainWidth = 760;
$mainHeight = 230;
$angle = 50;
/* Create the pChart object */
$myPicture = new pImage($mainWidth, $mainHeight, $myData);
/* Turn of Antialiasing */
$myPicture->Antialias = false;
/* Draw the background */
$settings = ["R" => 255, "G" => 255, "B" => 255];
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings);
/* Add a border to the picture */
$myPicture->drawRectangle(
0,
0,
$mainWidth - 1,
$mainHeight - 1,
["R" => 0, "G" => 0, "B" => 0]
);
/* Define the chart area */
$myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80);
/* Draw the scale */
$scaleSettings = [
'XMargin' => 10,
'YMargin' => 10,
'Floating' => true,
'GridR' => 200,
'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'LabelRotation' => $angle,
'Mode' => SCALE_MODE_ADDALL_START0,
];
$myPicture->drawScale($scaleSettings);
/* Turn on Antialiasing */
$myPicture->Antialias = true;
/* Enable shadow computing */
$myPicture->setShadow(
true,
[
"X" => 1,
"Y" => 1,
"R" => 0,
"G" => 0,
"B" => 0,
"Alpha" => 10,
]
);
/* Set the default font */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 10, ]
);
/* Write the chart title */
$myPicture->drawText(
$mainWidth / 2,
30,
get_lang('TimeSpentInTheCourse'),
[
"FontSize" => 12,
"Align" => TEXT_ALIGN_BOTTOMMIDDLE,
]
);
/* Draw the line chart */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 10,
]
);
$myPicture->drawSplineChart();
$myPicture->drawPlotChart(
[
"DisplayValues" => true,
"PlotBorder" => true,
"BorderSize" => 1,
"Surrounding" => -60,
"BorderAlpha" => 80,
]
);
/* Set the default font */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 8,
]
);
/* Do NOT Write the chart legend */
/* Define the chart area */
$myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80);
/* Draw the scale */
$scaleSettings = [
'XMargin' => 10,
'YMargin' => 10,
'Floating' => true,
'GridR' => 200,
'GridG' => 200,
'GridB' => 200,
'DrawSubTicks' => true,
'CycleBackground' => true,
'LabelRotation' => $angle,
'Mode' => SCALE_MODE_ADDALL_START0,
];
$myPicture->drawScale($scaleSettings);
/* Turn on Antialiasing */
$myPicture->Antialias = true;
/* Enable shadow computing */
$myPicture->setShadow(
true,
[
"X" => 1,
"Y" => 1,
"R" => 0,
"G" => 0,
"B" => 0,
"Alpha" => 10,
]
);
/* Write and save into cache */
$myCache->writeToCache($chartHash, $myPicture);
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
}
/* Draw the line chart */
$myPicture->setFontProperties(
[
"FontName" => api_get_path(SYS_FONTS_PATH).'opensans/OpenSans-Regular.ttf',
"FontSize" => 10,
]
);
$myPicture->drawSplineChart();
$myPicture->drawPlotChart(
[
"DisplayValues" => true,
"PlotBorder" => true,
"BorderSize" => 1,
"Surrounding" => -60,
"BorderAlpha" => 80,
]
return '<img src="'.$imgPath.'">';
} else {
return api_convert_encoding(
'<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>',
'UTF-8'
);
/* Do NOT Write the chart legend */
/* Write and save into cache */
$myCache->writeToCache($chartHash, $myPicture);
$imgPath = api_get_path(SYS_ARCHIVE_PATH).$chartHash;
$myCache->saveFromCache($chartHash, $imgPath);
$imgPath = api_get_path(WEB_ARCHIVE_PATH).$chartHash;
}
$html = '<img src="'.$imgPath.'">';
return $html;
} else {
$foo_img = api_convert_encoding(
'<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>',
'UTF-8'
);
return $foo_img;
}
}

@ -923,7 +923,7 @@ class HTML_Table extends HTML_Common
* @access public
* @return string
*/
function toHtml()
public function toHtml()
{
$strHtml = '';
$tabs = $this->_getTabs();
@ -1024,5 +1024,3 @@ class HTML_Table extends HTML_Common
}
}
?>

@ -343,6 +343,13 @@ class SortableTable extends HTML_Table
echo $this->return_table();
}
public function toArray()
{
$headers = array_column($this->getHeaders(), 'label');
return array_merge([$headers], $this->get_table_data());
}
/**
* Displays the table, complete with navigation buttons to browse through
* the data-pages.

@ -230,9 +230,9 @@ class Statistics
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " AND (
user.username LIKE '%".$keyword."%' OR
default_event_type LIKE '%".$keyword."%' OR
default_value_type LIKE '%".$keyword."%' OR
user.username LIKE '%".$keyword."%' OR
default_event_type LIKE '%".$keyword."%' OR
default_value_type LIKE '%".$keyword."%' OR
default_value LIKE '%".$keyword."%') ";
}
@ -403,7 +403,7 @@ class Statistics
public static function getCourseCategories()
{
$categoryTable = Database::get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT code, name
$sql = "SELECT code, name
FROM $categoryTable
ORDER BY tree_pos";
$res = Database::query($sql);
@ -514,8 +514,8 @@ class Statistics
$period = get_lang('PeriodMonth');
$periodCollection = api_get_months_long();
$sql = "SELECT
DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date ,
$sql = "SELECT
DATE_FORMAT( login_date, '%Y-%m' ) AS stat_date ,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url
GROUP BY stat_date
@ -525,32 +525,32 @@ class Statistics
switch ($type) {
case 'hour':
$period = get_lang('PeriodHour');
$sql = "SELECT
DATE_FORMAT( login_date, '%H') AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url
GROUP BY stat_date
$sql = "SELECT
DATE_FORMAT( login_date, '%H') AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url
GROUP BY stat_date
ORDER BY stat_date ";
$sql_last_x = "SELECT
DATE_FORMAT( login_date, '%H' ) AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url ".sprintf($where_url_last, 'DAY')."
GROUP BY stat_date
$sql_last_x = "SELECT
DATE_FORMAT( login_date, '%H' ) AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url ".sprintf($where_url_last, 'DAY')."
GROUP BY stat_date
ORDER BY stat_date ";
break;
case 'day':
$periodCollection = api_get_week_days_long();
$period = get_lang('PeriodDay');
$sql = "SELECT DATE_FORMAT( login_date, '%w' ) AS stat_date ,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url
GROUP BY stat_date
$sql = "SELECT DATE_FORMAT( login_date, '%w' ) AS stat_date ,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url
GROUP BY stat_date
ORDER BY DATE_FORMAT( login_date, '%w' ) ";
$sql_last_x = "SELECT
DATE_FORMAT( login_date, '%w' ) AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url ".sprintf($where_url_last, 'WEEK')."
GROUP BY stat_date
$sql_last_x = "SELECT
DATE_FORMAT( login_date, '%w' ) AS stat_date,
count( login_id ) AS number_of_logins
FROM $table $table_url $where_url ".sprintf($where_url_last, 'WEEK')."
GROUP BY stat_date
ORDER BY DATE_FORMAT( login_date, '%w' ) ";
break;
}
@ -631,17 +631,17 @@ class Statistics
$label = get_lang('Today');
}
$label .= " <br /> $localDate - $localEndDate";
$sql = "SELECT count($field) AS number
FROM $table $table_url
WHERE
$sql = "SELECT count($field) AS number
FROM $table $table_url
WHERE
UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND
login_date BETWEEN '$startDate' AND '$endDate'
login_date BETWEEN '$startDate' AND '$endDate'
$where_url";
$sqlList[$label] = $sql;
}
$sql = "SELECT count($field) AS number
FROM $table $table_url
$sql = "SELECT count($field) AS number
FROM $table $table_url
WHERE UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration $where_url
";
$sqlList[get_lang('Total')] = $sql;
@ -675,10 +675,10 @@ class Statistics
$sql = "
SELECT count(logins) count FROM (
SELECT count(login_user_id) AS logins
FROM $table $table_url
WHERE
login_date BETWEEN '$startDate' AND '$endDate'
$where_url
FROM $table $table_url
WHERE
login_date BETWEEN '$startDate' AND '$endDate'
$where_url
GROUP BY login_user_id
) as t
";
@ -727,10 +727,10 @@ class Statistics
$sessionDuration = (int) $sessionDuration;
$sql = "SELECT count($field) AS number, date(login_date) as login_date
FROM $table $table_url
WHERE
FROM $table $table_url
WHERE
UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND
login_date >= '$newDate' $where_url
login_date >= '$newDate' $where_url
GROUP BY date(login_date)";
$res = Database::query($sql);
@ -1026,16 +1026,16 @@ class Statistics
}
if (api_is_multiple_url_enabled()) {
$sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message
FROM $access_url_rel_user_table as url, $message_table m
LEFT JOIN $user_table u ON m.$field = u.user_id
WHERE url.user_id = m.$field AND access_url_id='".$urlId."'
GROUP BY m.$field
$sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message
FROM $access_url_rel_user_table as url, $message_table m
LEFT JOIN $user_table u ON m.$field = u.user_id
WHERE url.user_id = m.$field AND access_url_id='".$urlId."'
GROUP BY m.$field
ORDER BY count_message DESC ";
} else {
$sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message
FROM $message_table m
LEFT JOIN $user_table u ON m.$field = u.user_id
$sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message
FROM $message_table m
LEFT JOIN $user_table u ON m.$field = u.user_id
GROUP BY m.$field ORDER BY count_message DESC ";
}
$res = Database::query($sql);
@ -1065,23 +1065,23 @@ class Statistics
$urlId = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend
FROM $access_url_rel_user_table as url, $user_friend_table uf
LEFT JOIN $user_table u
ON (uf.user_id = u.user_id)
WHERE
uf.relation_type <> '".USER_RELATION_TYPE_RRHH."' AND
uf.user_id = url.user_id AND
access_url_id = '".$urlId."'
GROUP BY uf.user_id
$sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend
FROM $access_url_rel_user_table as url, $user_friend_table uf
LEFT JOIN $user_table u
ON (uf.user_id = u.user_id)
WHERE
uf.relation_type <> '".USER_RELATION_TYPE_RRHH."' AND
uf.user_id = url.user_id AND
access_url_id = '".$urlId."'
GROUP BY uf.user_id
ORDER BY count_friend DESC ";
} else {
$sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend
FROM $user_friend_table uf
LEFT JOIN $user_table u
ON (uf.user_id = u.user_id)
WHERE uf.relation_type <> '".USER_RELATION_TYPE_RRHH."'
GROUP BY uf.user_id
$sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend
FROM $user_friend_table uf
LEFT JOIN $user_table u
ON (uf.user_id = u.user_id)
WHERE uf.relation_type <> '".USER_RELATION_TYPE_RRHH."'
GROUP BY uf.user_id
ORDER BY count_friend DESC ";
}
$res = Database::query($sql);
@ -1262,7 +1262,7 @@ class Statistics
if (!empty($result)) {
$actions = Display::url(
Display::return_icon('excel.png', get_lang('ExportToXls'), [], ICON_SIZE_MEDIUM),
Display::return_icon('excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM),
api_get_self().'?'.http_build_query(
[
'report' => 'logins_by_date',

@ -1,11 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This is the tracking library for Chamilo.
*
* @package chamilo.reporting
*
* Calculates the time spent on the course
*
* @param int $user_id the user id
@ -31,7 +30,7 @@ if (!$is_allowedToTrack) {
$this_section = SECTION_TRACKING;
$user_id = isset($_REQUEST['student']) ? (int) $_REQUEST['student'] : 0;
$session_id = (int) $_GET['id_session'];
$session_id = isset($_REQUEST['id_session']) ? (int) $_REQUEST['id_session'] : 0;
$type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : '';
$course_code = isset($_REQUEST['course']) ? Security::remove_XSS($_REQUEST['course']) : '';
$courseInfo = api_get_course_info($course_code);
@ -93,15 +92,26 @@ function loadGraph() {
var startDate = $('#date_from').val();
var endDate = $('#date_to').val();
var type = $('#type option:selected').val();
var url = '".$url."&startDate='+startDate+'&endDate='+endDate+'&type='+type;
$.ajax({
url: '".$url."&startDate='+startDate+'&endDate='+endDate+'&type='+type,
url: url,
dataType: 'json',
success: function(db) {
if (!db.is_empty) {
// Display confirmation message to the user
$('#messages').html(db.result).stop().css('opacity', 1).fadeIn(30);
console.log(url);
var exportLink = $('<a></a>').
attr(\"href\", url+'&export=excel')
.attr('class', 'btn btn-default')
.attr('target', '_blank')
.html('".addslashes(get_lang('ExportAsXLS'))."');
$('#messages').append(exportLink);
$('#cev_cont_stats').html(db.stats);
$('#graph' ).html(db.graph_result);
$('#graph').html(db.graph_result);
} else {
$('#messages').text('".get_lang('NoDataAvailable')."');
$('#messages').addClass('warning-message');
@ -118,24 +128,16 @@ $(function() {
changeMonth: true,
changeYear: true
});
$(\"#cev_button\").hide();
});
</script>";
$htmlHeadXtra[] = '<script>
$(function() {
$("#cev_button").hide();
$("#container-9").tabs({remote: true});
});
</script>';
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')];
Display::display_header('');
$userInfo = api_get_user_info($user_id);
$result_to_print = '';
$sql_result = MySpace::get_connections_to_course($user_id, $courseInfo);
$result_to_print = convert_to_string($sql_result);
echo Display::page_header(get_lang('DetailsStudentInCourse'));
echo Display::page_subheader(
@ -156,17 +158,17 @@ $form->display();
<?php echo get_lang('Statistics'); ?>
</div><br />
<div id="cev_cont_stats">
<?php
if ($result_to_print != '') {
$rst = get_stats($user_id, $courseInfo, $session_id);
$foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
$foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
$foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
echo $foo_stats;
<?php
$data = MySpace::getStats($user_id, $courseInfo, $session_id);
if (!empty($data)) {
$stats = '<strong>'.get_lang('Total').': </strong>'.$data['total'].'<br />';
$stats .= '<strong>'.get_lang('Average').': </strong>'.$data['avg'].'<br />';
$stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$data['times'].'<br />';
echo $stats;
} else {
echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
}
?>
?>
</div>
<br />
</div>

Loading…
Cancel
Save