Skip to content

Commit f637ffc

Browse files
committed
Fix dates - Use api_get_local_time, and api_strtotime see BT#13000
1 parent 6fe2641 commit f637ffc

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

main/inc/lib/myspace.lib.php

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,15 @@ public function export_csv($header, $data, $file_name = 'export.csv')
128128
*/
129129
public static function get_connections_to_course($userId, $courseId, $sessionId = 0)
130130
{
131-
// Database table definitions
132-
$tbl_track_course = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
131+
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
133132

134133
// protect data
135134
$userId = (int) $userId;
136135
$courseId = (int) $courseId;
137136
$sessionId = (int) $sessionId;
138137

139138
$sql = 'SELECT login_course_date, logout_course_date
140-
FROM ' . $tbl_track_course.'
139+
FROM ' . $table.'
141140
WHERE
142141
user_id = '.$userId.' AND
143142
c_id = '.$courseId.' AND
@@ -147,11 +146,9 @@ public static function get_connections_to_course($userId, $courseId, $sessionId
147146
$connections = array();
148147

149148
while ($row = Database::fetch_array($rs)) {
150-
$timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
151-
$timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
152149
$connections[] = array(
153-
'login' => $timestamp_login_date,
154-
'logout' => $timestamp_logout_date
150+
'login' => api_strtotime($row['login_course_date'], 'UTC'),
151+
'logout' => api_strtotime($row['logout_course_date'], 'UTC')
155152
);
156153
}
157154

@@ -2648,7 +2645,6 @@ public static function getUserDataAccessTrackingOverview($from, $numberItems, $c
26482645
//TODO: Dont use numeric index
26492646
foreach ($data as $key => $info) {
26502647
$start_date = $info['col0'];
2651-
26522648
$end_date = $info['logout_course_date'];
26532649

26542650
$return[$info['user_id']] = array(
@@ -2682,17 +2678,16 @@ public static function getUserDataAccessTrackingOverview($from, $numberItems, $c
26822678
/**
26832679
* Gets the connections to a course as an array of login and logout time
26842680
*
2685-
* @param int $user_id
2686-
* @param int $courseId
2681+
* @param int $user_id
2682+
* @param int $courseId
26872683
* @author Jorge Frisancho Jibaja
26882684
* @author Julio Montoya <gugli100@gmail.com> fixing the function
26892685
* @version OCT-22- 2010
26902686
* @return array
26912687
*/
26922688
public static function get_connections_to_course_by_date($user_id, $courseId, $start_date, $end_date)
26932689
{
2694-
// Database table definitions
2695-
$tbl_track_course = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
2690+
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
26962691
$course_info = api_get_course_info_by_id($courseId);
26972692
$user_id = intval($user_id);
26982693
$courseId = intval($courseId);
@@ -2701,23 +2696,19 @@ public static function get_connections_to_course_by_date($user_id, $courseId, $s
27012696
if (!empty($course_info)) {
27022697
$end_date = add_day_to($end_date);
27032698
$sql = "SELECT login_course_date, logout_course_date
2704-
FROM $tbl_track_course
2705-
WHERE
2706-
user_id = $user_id AND
2707-
c_id = $courseId AND
2708-
login_course_date BETWEEN '$start_date' AND '$end_date' AND
2709-
logout_course_date BETWEEN '$start_date' AND '$end_date'
2710-
ORDER BY login_course_date ASC";
2699+
FROM $table
2700+
WHERE
2701+
user_id = $user_id AND
2702+
c_id = $courseId AND
2703+
login_course_date BETWEEN '$start_date' AND '$end_date' AND
2704+
logout_course_date BETWEEN '$start_date' AND '$end_date'
2705+
ORDER BY login_course_date ASC";
27112706
$rs = Database::query($sql);
27122707

27132708
while ($row = Database::fetch_array($rs)) {
2714-
$login_date = $row['login_course_date'];
2715-
$logout_date = $row['logout_course_date'];
2716-
$timestamp_login_date = strtotime($login_date);
2717-
$timestamp_logout_date = strtotime($logout_date);
27182709
$connections[] = array(
2719-
'login' => $timestamp_login_date,
2720-
'logout' => $timestamp_logout_date
2710+
'login' => api_strtotime($row['login_course_date'], 'UTC'),
2711+
'logout' => api_strtotime($row['logout_course_date'], 'UTC')
27212712
);
27222713
}
27232714
}
@@ -2734,8 +2725,7 @@ public static function get_connections_to_course_by_date($user_id, $courseId, $s
27342725
*/
27352726
function get_stats($user_id, $courseId, $start_date = null, $end_date = null)
27362727
{
2737-
// Database table definitions
2738-
$tbl_track_course = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
2728+
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
27392729

27402730
$course_info = api_get_course_info_by_id($courseId);
27412731
if (!empty($course_info)) {
@@ -2749,18 +2739,17 @@ function get_stats($user_id, $courseId, $start_date = null, $end_date = null)
27492739
$user_id = intval($user_id);
27502740
$courseId = intval($courseId);
27512741
$sql = "SELECT
2752-
SEC_TO_TIME(avg(time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
2753-
SEC_TO_TIME(sum(time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
2742+
SEC_TO_TIME(AVG(time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
2743+
SEC_TO_TIME(SUM(time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
27542744
count(user_id) as times
2755-
FROM $tbl_track_course
2745+
FROM $table
27562746
WHERE
27572747
user_id = $user_id AND
27582748
c_id = $courseId $stringStartDate $stringEndDate
27592749
ORDER BY login_course_date ASC";
27602750

27612751
$rs = Database::query($sql);
27622752
$result = array();
2763-
27642753
if ($row = Database::fetch_array($rs)) {
27652754
$foo_avg = $row['avrg'];
27662755
$foo_total = $row['total'];
@@ -2805,21 +2794,26 @@ function convert_to_array($sql_result)
28052794
/**
28062795
* Converte an array to a table in html
28072796
*
2808-
* @param array $sql_result
2797+
* @param array $result
28092798
* @author Jorge Frisancho Jibaja
28102799
* @version OCT-22- 2010
28112800
* @return string
28122801
*/
2813-
function convert_to_string($sql_result)
2802+
function convert_to_string($result)
28142803
{
2815-
$result_to_print = '<table>';
2816-
if (!empty($sql_result)) {
2817-
foreach ($sql_result as $key => $data) {
2818-
$result_to_print .= '<tr><td>'.date('d-m-Y (H:i:s)', $data['login']).'</td><td>'.api_time_to_hms($data['logout'] - $data['login']).'</tr></td>'."\n";
2804+
$html = '<table class="table">';
2805+
if (!empty($result)) {
2806+
foreach ($result as $key => $data) {
2807+
$html .= '<tr><td>';
2808+
$html .= api_get_local_time($data['login']);
2809+
$html .= '</td>';
2810+
$html .= '<td>';
2811+
$html .= api_time_to_hms($data['logout'] - $data['login']);
2812+
$html .= '</tr></td>';
28192813
}
28202814
}
2821-
$result_to_print .= '</table>';
2822-
return $result_to_print;
2815+
$html .= '</table>';
2816+
return $html;
28232817
}
28242818

28252819

@@ -2836,9 +2830,15 @@ function convert_to_string($sql_result)
28362830
*/
28372831
function grapher($sql_result, $start_date, $end_date, $type = "")
28382832
{
2839-
if (empty($start_date)) { $start_date = ""; }
2840-
if (empty($end_date)) { $end_date = ""; }
2841-
if ($type == "") { $type = 'day'; }
2833+
if (empty($start_date)) {
2834+
$start_date = '';
2835+
}
2836+
if (empty($end_date)) {
2837+
$end_date = '';
2838+
}
2839+
if ($type == '') {
2840+
$type = 'day';
2841+
}
28422842
$main_year = $main_month_year = $main_day = [];
28432843

28442844
$period = new DatePeriod(
@@ -2888,7 +2888,6 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
28882888
break;
28892889
}
28902890

2891-
// the nice graphics :D
28922891
$labels = array_keys($main_date);
28932892
if (count($main_date) == 1) {
28942893
$labels = $labels[0];
@@ -2929,7 +2928,6 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
29292928

29302929
/* Turn of Antialiasing */
29312930
$myPicture->Antialias = false;
2932-
29332931
/* Draw the background */
29342932
$settings = array("R" => 255, "G" => 255, "B" => 255);
29352933
$myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings);
@@ -3032,7 +3030,10 @@ function grapher($sql_result, $start_date, $end_date, $type = "")
30323030

30333031
return $html;
30343032
} else {
3035-
$foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>', 'UTF-8');
3033+
$foo_img = api_convert_encoding(
3034+
'<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>',
3035+
'UTF-8'
3036+
);
30363037

30373038
return $foo_img;
30383039
}

main/mySpace/access_details.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
$course_code = isset($_REQUEST['course']) ? Security::remove_XSS($_REQUEST['course']) : '';
2929
$courseInfo = api_get_course_info($course_code);
3030
$courseId = (!empty($courseInfo['real_id']) ? $courseInfo['real_id'] : null);
31-
$connections = MySpace::get_connections_to_course($user_id, $courseId, $session_id);
3231
$quote_simple = "'";
3332

3433
$form = new FormValidator(

0 commit comments

Comments
 (0)