#!/usr/bin/perl -w
###################################################################################
#                                                                                 #
#                   PerlDesk - Customer Help Desk Software                        #
#                                                                                 #
###################################################################################
#                                                                                 #
#     Author: John Bennett	                                                  #
#      Email: j.bennett@perldesk.com                                              #
#        Web: http://www.perldesk.com                                             #
#   Filename: ssi_time.cgi                                                        #
#    Details: You can include this in your site to display avg. response times    #                                                 #
#    Release: 1.5.5                                                               #
#                                                                                 #
###################################################################################
# Please direct bug reports,suggestions or feedback to the perldesk forums.       #
# www.perldesk.com/board                                                          #
#                                                                                 #
# PerlDesk is free for both commercial and non-commercial use providing that the  #
# copyright headers remain intact and the links remain on the html pages.         #
# Re-distribution of this script without prior consent is strictly prohibited.    # 
#                                                                                 #
###################################################################################
# Please see the README/INSTALL files if you have any problems with this software #                                                            
###################################################################################
use CGI qw(:standard);
use DBI();

 require "conf.pl";




print "Content-type: text/html\n\n";


$dbh = DBI->connect("DBI:mysql:$DBNAME:$DBHOST","$DBUSER","$DBPASS");

 $statemente = 'SELECT value FROM settings WHERE setting = "ssi_closed"'; 
 $sth = $dbh->prepare($statemente) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
 $sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
   while(my $ref = $sth->fetchrow_hashref())  {
		$closed = $ref->{'value'};
   }
 $sth->finish;


 $statement = 'SELECT value FROM settings WHERE setting = "avgtime"'; 
 $sth = $dbh->prepare($statement) or die print "Couldn't prepare statement: $DBI::errstr; stopped";
 $sth->execute() or die print "Couldn't execute statement: $DBI::errstr; stopped";
   while(my $ref = $sth->fetchrow_hashref()) {	
        $tsec = $ref->{'value'};
   }
$sth->finish;


 if ($closed > 0) {

   $sec      =  ($tsec/$closed);
   $days     =  int($sec/(24*60*60));
   $hours    =  ($sec/(60*60))%24;
   $mins     =  ($sec/60)%60;
   $secs     =  $sec%60;
   $restime  =  "$hours hr(s) $mins min(s) $secs seconds";

 } else {
            $restime = "No calls closed";
        }

print "$restime";
