# -- # Kernel/Modules/SystemStatsGeneric.pm - generic pure SQL stats module # Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/ # -- # $Id: SystemStatsGeneric.pm,v 1.10 2007/02/07 11:37:26 tr Exp $ # -- # This software comes with ABSOLUTELY NO WARRANTY. For details, see # the enclosed file COPYING for license information (GPL). If you # did not receive this file, see http://www.gnu.org/licenses/gpl.txt. # -- # # Description: copy this file into Kernel/Modules/ and change the # config options ($Title, $DetailText, $SQL, ...) below. # # Add a html link to your OTRS agent frontend, e. g. # Your Stats # and you will get your printable pure SQL stats. # # If you want a CSV file add the param CSV=1 to your html link e. g. # Your CVS Stats File # # -- package Kernel::Modules::SystemStatsGeneric; use strict; use vars qw($VERSION); $VERSION = '$Revision: 1.10 $'; $VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/; sub new { my $Type = shift; my %Param = @_; # allocate new hash for object my $Self = {}; bless ($Self, $Type); # get common opjects foreach (keys %Param) { $Self->{$_} = $Param{$_}; } # check all needed objects foreach (qw(ParamObject DBObject QueueObject LayoutObject ConfigObject LogObject TimeObject)) { die "Got no $_" if (!$Self->{$_}); } $Self->{CSV} = $Self->{ParamObject}->GetParam(Param => 'CSV') || 0; return $Self; } sub Run { my $Self = shift; my %Param = @_; # ------------------------------------------------------------------------------ # # Config options! # ------------------------------------------------------------------------------ # my $Title = 'Name of Stats'; my $DetailText = 'Some text about the content! $Data{"Records"} database records - ($Text{"Stand"}: $Env{"Time"})'; my $CSVFile = 'csv-file'; my $SQLLimit = 5000; my $SQL = qq|SELECT * FROM system_user|; my $Group = 'stats'; # ------------------------------------------------------------------------------ # # permission check (user need to be rw in group stats) if (!$Self->{"UserIsGroup[$Group]"} || $Self->{"UserIsGroup[$Group]"} ne 'Yes') { return $Self->{LayoutObject}->NoPermission( Message => "You have to be in the $Group group!" ); } # starting with page ... my $CSVBody = ''; my $OutputBody = ''; my $Records = 0; my @HeadData = (); my @GlobalData = (); # get table columns names my $sth = $Self->{DBObject}->{dbh}->prepare($SQL); $sth->execute; my $names = $sth->{NAME}; @HeadData = @{$names}; # get table columns data $Self->{DBObject}->Prepare(SQL => $SQL, Limit => $SQLLimit); while (my @Row = $Self->{DBObject}->FetchrowArray()) { push (@GlobalData, \@Row); } # fillup colomn names if (!$Self->{CSV}) { $OutputBody .= '
$col | \n"; } } if ($Self->{CSV}) { $CSVBody .= "\n"; } else { $OutputBody .= "
---|
$_ | \n"; } } if ($Self->{CSV}) { $CSVBody .= "\n"; } else { $OutputBody .= "
$Data{"Title"} |
$Data{"DetailText"}
'); # return html $Output .= $OutputBody.$Self->{LayoutObject}->Output(Template => '