[svn r16523] display a message if datas from tracking are not calculable due to wrong old datas (FS#2741)

skala
Eric Marguin 17 years ago
parent 27466b26e3
commit 075cb6e097
  1. 8
      main/inc/lib/main_api.lib.php
  2. 26
      main/inc/lib/tracking.lib.php

@ -2263,7 +2263,13 @@ function api_parse_tex($textext)
*/ */
function api_time_to_hms($seconds) function api_time_to_hms($seconds)
{ {
//if seconds = -1, it means we have wrong datas in the db
if($seconds==-1)
{
return get_lang('Unknown').Display :: return_icon('info2.gif',get_lang('WrongDatasForTimeSpentOnThePlatform'));
}
//How many hours ? //How many hours ?
$hours = floor($seconds / 3600); $hours = floor($seconds / 3600);

@ -46,11 +46,13 @@ class Tracking {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . ' $sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . '
WHERE login_user_id = ' . intval($user_id).' AND logout_date IS NOT NULL'; WHERE login_user_id = ' . intval($user_id);;
$rs = api_sql_query($sql,__FILE__,__LINE__); $rs = api_sql_query($sql,__FILE__,__LINE__);
$nb_seconds = 0; $nb_seconds = 0;
$wrong_logout_dates = false;
while ($a_connections = Database::fetch_array($rs)) { while ($a_connections = Database::fetch_array($rs)) {
@ -59,12 +61,26 @@ class Tracking {
$i_timestamp_login_date = strtotime($s_login_date); $i_timestamp_login_date = strtotime($s_login_date);
$i_timestamp_logout_date = strtotime($s_logout_date); $i_timestamp_logout_date = strtotime($s_logout_date);
$nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date); if($i_timestamp_logout_date>0)
{
$nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date);
}
else
{ // there are wrong datas in db, then we can't give a wrong time
$wrong_logout_dates = true;
}
} }
return $nb_seconds; if($nb_seconds>0 || !$wrong_logout_dates)
{
return $nb_seconds;
}
else
{
return -1; //-1 means we have wrong datas in the db
}
} }
/** /**

Loading…
Cancel
Save