Index: lib/WebGUI/Auth.pm =================================================================== --- lib/WebGUI/Auth.pm (revision 3895) +++ lib/WebGUI/Auth.pm (working copy) @@ -93,16 +93,38 @@ #------------------------------------------------------------------- sub _logLogin { my $self = shift; - $self->session->db->write("insert into userLoginLog values (?,?,?,?,?)", + $self->timeRecordSession; + $self->session->db->write("insert into userLoginLog values (?,?,?,?,?,?,?)", [ $_[0], $_[1], $self->session->datetime->time(), $self->session->env->getIp, - $self->session->env->get("HTTP_USER_AGENT") ] + $self->session->env->get("HTTP_USER_AGENT"), + $self->session->getId, + $self->session->datetime->time()] ); } +#------------------------------------------------------------------- +sub timeRecordSession { + my $self = shift; + my ($nonTimeRecordedRows) = $self->session->db->quickArray("select count(*) from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$self->session->getId] ); + if ($nonTimeRecordedRows eq "1") { + # We would normally expect to only find one entry + $self->session->db->write("update userLoginLog set lastPageViewed = (select lastPageView from userSession where sessionId = ?) where lastPageViewed = timeStamp and sessionId = ? ", + [ $self->session->getId, + $self->session->getId]); + } elsif ($nonTimeRecordedRows eq "0") { + # Do nothing + } else { + # If something strange happened and we ended up with > 1 matching rows, cut our losses and remove offending userLoginLog rows (otherwise we + # could end up with ridiculously long user recorded times) + $self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows"); + $self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$self->session->getId] ); + } +} + #------------------------------------------------------------------- =head2 authenticate ( ) Index: lib/WebGUI/Operation/LoginHistory.pm =================================================================== --- lib/WebGUI/Operation/LoginHistory.pm (revision 3895) +++ lib/WebGUI/Operation/LoginHistory.pm (working copy) @@ -46,7 +46,21 @@ $row[$i] .= ''.$data{status}.''; $row[$i] .= ''.$session->datetime->epochToHuman($data{timeStamp},"%H:%n%p %M/%D/%y").''; $row[$i] .= ''.$data{ipAddress}.''; - $row[$i] .= ''.$data{userAgent}.''; + $row[$i] .= ''.$data{userAgent}.''; + $row[$i] .= ''.$data{sessionId}.''; + if ($data{lastPageViewed}) { + if ($data{lastPageViewed} == $data{timeStamp}) { + $row[$i] .= "Active"; + $row[$i] .= "Active"; + } else { + $row[$i] .= ''.$session->datetime->epochToHuman($data{lastPageViewed},"%H:%n%p %M/%D/%y").''; + my ($interval, $units) = $session->datetime->secondsToInterval($data{lastPageViewed} - $data{timeStamp}); + $row[$i] .= "$interval $units"; + } + } else { + $row[$i] .= ""; + $row[$i] .= ""; + } $i++; } $sth->finish; @@ -57,7 +71,10 @@ $output .= ''.$i18n->get(434).''; $output .= ''.$i18n->get(429).''; $output .= ''.$i18n->get(431).''; - $output .= ''.$i18n->get(433).''; + $output .= ''.$i18n->get(433).''; + $output .= 'Session ID'; + $output .= 'Last Page Viewed'; + $output .= 'Session Length'; $output .= $p->getPage($session->form->process("pn")); $output .= ''; $output .= $p->getBar($session->form->process("pn")); Index: lib/WebGUI/Operation/User.pm =================================================================== --- lib/WebGUI/Operation/User.pm (revision 3895) +++ lib/WebGUI/Operation/User.pm (working copy) @@ -579,6 +579,8 @@ '.$i18n->get(454).' '.$i18n->get(429).' '.$i18n->get(434).' + '.$i18n->echo("Last Page View").' + '.$i18n->echo("Time Recorded (excludes active sessions)").' '; my $p = doUserSearch($session,"listUsers",1); foreach my $data (@{$p->getPageData}) { @@ -589,8 +591,10 @@ $output .= ''.$data->{email}.''; $output .= ''.$session->datetime->epochToHuman($data->{dateCreated},"%z").''; $output .= ''.$session->datetime->epochToHuman($data->{lastUpdated},"%z").''; - my ($lastLoginStatus, $lastLogin) = $session->db->quickArray("select status,timeStamp from userLoginLog where - userId=".$session->db->quote($data->{userId})." order by timeStamp DESC"); + # Total Time Recorded is computed from userLoginLog table + my ($totalTimeRecorded)= $session->db->quickArray("select sum(lastPageViewed-timeStamp) from userLoginLog where userId = ?", [$data->{userId}]); + my ($lastLoginStatus, $lastLogin, $lastPageView) = $session->db->quickArray("select ull.status,ull.timeStamp,us.lastPageView from userLoginLog ull, userSession us where ull.sessionId = us.sessionId and ull.lastPageViewed != ull.timeStamp and + ull.userId=".$session->db->quote($data->{userId})." order by ull.timeStamp DESC"); if ($lastLogin) { $output .= ''.$session->datetime->epochToHuman($lastLogin).''; } else { @@ -601,6 +605,14 @@ } else { $output .= ' - '; } + if ($lastPageView) { + $output .= ' '.$session->datetime->epochToHuman($lastPageView).''; + my ($interval, $units) = $session->datetime->secondsToInterval($totalTimeRecorded); + $output .= "$interval $units"; + } else { + $output .= " - "; + $output .= " - "; + } $output .= ''; } $output .= ''; Index: lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm =================================================================== --- lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm (revision 3895) +++ lib/WebGUI/Workflow/Activity/DeleteExpiredSessions.pm (working copy) @@ -68,9 +68,24 @@ sub execute { my $self = shift; - my $sth = $self->session->db->read("select sessionId from userSession where expiressession->db->read("select sessionId, lastPageView from userSession where expiresarray) { + + while (my ($sessionId, $lastPageView) = $sth->array) { + # timeRecordSessions + my ($nonTimeRecordedRows) = $self->session->db->quickArray("select count(*) from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] ); + if ($nonTimeRecordedRows eq "1") { + # We would normally expect to only find one entry + $self->session->db->write("update userLoginLog set lastPageViewed = ? where lastPageViewed = timeStamp and sessionId = ? ", + [ $lastPageView, $sessionId ]); + } elsif ($nonTimeRecordedRows eq "0") { + # Do nothing + } else { + # If something strange happened and we ended up with > 1 matching rows, cut our losses and remove offending userLoginLog rows (otherwise we + # could end up with ridiculously long user recorded times) + $self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows"); + $self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] ); + } my $session = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename, undef, undef, $sessionId, 1); if (defined $session) { $session->var->end;