package WebGUI::Operation::Statistics; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2003 Plain Black LLC. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use Exporter; use strict; use WebGUI::Cache; use WebGUI::DateTime; use WebGUI::Icon; use WebGUI::International; use WebGUI::Operation::Shared; use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; our @ISA = qw(Exporter); our @EXPORT = qw(&www_viewPageReport &www_viewStatistics &www_viewTrafficReport &www_killSession &www_viewLoginHistory &www_viewActiveSessions); #------------------------------------------------------------------- sub _submenu { my (%menu); tie %menu, 'Tie::IxHash'; $menu{WebGUI::URL::page("op=viewActiveSessions")} = WebGUI::International::get(423); $menu{WebGUI::URL::page("op=viewLoginHistory")} = WebGUI::International::get(424); $menu{WebGUI::URL::page("op=viewPageReport")} = WebGUI::International::get(796); # $menu{WebGUI::URL::page("op=viewTrafficReport")} = WebGUI::International::get(797); $menu{WebGUI::URL::page('op=viewStatistics')} = WebGUI::International::get(144); return menuWrapper($_[0],\%menu); } #------------------------------------------------------------------- sub www_killSession { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); WebGUI::Session::end($session{form}{sid}); return www_viewActiveSessions(); } #------------------------------------------------------------------- sub www_viewActiveSessions { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); my ($output, $p, @row, $i, $sth, %data); tie %data, 'Tie::CPHash'; $output = '

'.WebGUI::International::get(425).'

'; $sth = WebGUI::SQL->read("select users.username,users.userId,userSession.sessionId,userSession.expires, userSession.lastPageView,userSession.lastIP from users,userSession where users.userId=userSession.userId and users.userId<>1 order by users.username,userSession.lastPageView desc"); while (%data = $sth->hash) { $row[$i] = ''.$data{username}.' ('.$data{userId}.')'; $row[$i] .= ''.$data{sessionId}.''; $row[$i] .= ''.epochToHuman($data{expires}).''; $row[$i] .= ''.epochToHuman($data{lastPageView}).''; $row[$i] .= ''.$data{lastIP}.''; $row[$i] .= ''.deleteIcon("op=killSession&sid=$data{sessionId}").''; $i++; } $sth->finish; $p = WebGUI::Paginator->new(WebGUI::URL::page('op=viewActiveSessions'),\@row); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= $p->getPage($session{form}{pn}); $output .= '
'.WebGUI::International::get(428).''.WebGUI::International::get(435).''.WebGUI::International::get(432).''.WebGUI::International::get(430).''.WebGUI::International::get(431).''.WebGUI::International::get(436).'
'; $output .= $p->getBarTraditional($session{form}{pn}); return _submenu($output); } #------------------------------------------------------------------- sub www_viewLoginHistory { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); my ($output, $p, @row, $i, $sth, %data); tie %data, 'Tie::CPHash'; $output = '

'.WebGUI::International::get(426).'

'; $sth = WebGUI::SQL->read("select * from users,userLoginLog where users.userId=userLoginLog.userId order by userLoginLog.timeStamp desc"); while (%data = $sth->hash) { $data{username} = 'unknown user' if ($data{userId} == 0); $row[$i] = ''.$data{username}.' ('.$data{userId}.')'; $row[$i] .= ''.$data{status}.''; $row[$i] .= ''.epochToHuman($data{timeStamp},"%H:%n%p %M/%D/%y").''; $row[$i] .= ''.$data{ipAddress}.''; $row[$i] .= ''.$data{userAgent}.''; $i++; } $sth->finish; $p = WebGUI::Paginator->new(WebGUI::URL::page('op=viewLoginHistory'),\@row); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= $p->getPage($session{form}{pn}); $output .= '
'.WebGUI::International::get(428).''.WebGUI::International::get(434).''.WebGUI::International::get(429).''.WebGUI::International::get(431).''.WebGUI::International::get(433).'
'; $output .= $p->getBar($session{form}{pn}); return _submenu($output); } #------------------------------------------------------------------- sub www_viewPageReport { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); my ($output, $count, $user, $data, $sth, $page, $pageId); $output = '

Page Statistics

'; unless ($session{setting}{trackPageStatistics}) { $output .= WebGUI::International::get(802); } else { $sth = WebGUI::SQL->read("select pageTitle,pageId,userId,ipAddress,wobjectId from pageStatistics order by pageTitle,userId,ipAddress"); while ($data = $sth->hashRef) { if ($data->{userId} == 1) { $user = $data->{ipAddress}; } else { $user = $data->{userId}; } $page->{$data->{pageId}}{pageTitle} = $data->{pageTitle}; $page->{$data->{pageId}}{users}{$user}++; $page->{$data->{pageId}}{views}++; $page->{$data->{pageId}}{interact}++ if ($data->{wobjectId}); } $sth->finish; $output .= ''; foreach $pageId (keys %{$page}) { $output .= ''; $output .= ''; $count = 0; foreach (keys %{$page->{$pageId}{users}}) { $count++; } $output .= ''; $output .= ''; } $output .= '
'.WebGUI::International::get(798).' '.WebGUI::International::get(799).' '.WebGUI::International::get(800).' '.WebGUI::International::get(801).'
'.$page->{$pageId}{pageTitle}.''.$page->{$pageId}{views}.''.$count.''.$page->{$pageId}{interact}.'
'; } return _submenu($output); } #------------------------------------------------------------------- sub www_viewStatistics { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); my ($output, $data); my $url = "http://www.plainblack.com/downloads/latest-version.txt"; my $cache = WebGUI::Cache->new($url,"URL"); my $version = $cache->get; if (not defined $version) { $version = $cache->setByHTTP($url,43200); } chomp $version; $output .= helpIcon(12); $output .= '

'.WebGUI::International::get(437).'

'; $output .= ''; $output .= ''; $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from page where parentId>1000 and parentId<>3"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from page where parentId>1000 and parentId=0"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from page where parentId=5"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from wobject where wobjectId > 0 and pageId<>3"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from style where styleId>1000"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from template where templateId>1000"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from collateral where collateralId>1000"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from userSession"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from users where userId>25"); $output .= ''; ($data) = WebGUI::SQL->quickArray("select count(*) from groups where groupId>25"); $output .= ''; $output .= '
'.WebGUI::International::get(145).':'.$WebGUI::VERSION.'
'.WebGUI::International::get(349).':'.$version.'
'.WebGUI::International::get(147).':'.$data.'
'.WebGUI::International::get(795).':'.$data.'
'.WebGUI::International::get(794).':'.$data.'
'.WebGUI::International::get(148).':'.$data.'
'.WebGUI::International::get(427).':'.$data.'
'.WebGUI::International::get(792).':'.$data.'
'.WebGUI::International::get(793).':'.$data.'
'.WebGUI::International::get(146).':'.$data.'
'.WebGUI::International::get(149).':'.$data.'
'.WebGUI::International::get(89).':'.$data.'
'; return _submenu($output); } #------------------------------------------------------------------- sub www_viewTrafficReport { return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3)); my ($output, $data); $output = '

Pages

'; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-2592000)); $output .= "Last 30 days: ".$data."
"; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-604800)); $output .= "Last 7 days: ".$data."
"; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-86400)); $output .= "Last 24 hours: ".$data."
"; $output .= '

Visitors

'; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-2592000) ." group by ipAddress,userId"); $output .= "Last 30 days: ".$data."
"; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-604800) ." group by ipAddress,userId"); $output .= "Last 7 days: ".$data."
"; ($data) = WebGUI::SQL->quickArray("select count(*) from pageStatistics where dateStamp>=".(time()-86400) ." group by ipAddress,userId"); $output .= "Last 24 hours: ".$data."
"; return _submenu($output); } 1;