###############################################################################
# CP_AgentsReport.src                                                         #
###############################################################################
# UltraBoard 2000 by UltraScripts.com, Inc.                                   #
# Scripts written by Jacky Wing Wa Yung, WebMaster@UltraScripts.com           #
# Available from http://www.UltraBoard.org/                                   #
# =========================================================================== #
# COPYRIGHT NOTICE :                                                          #
#                                                                             #
# Copyright (c) 1999-2000 UltraScripts.com, Inc. All Rights Reserved.         #
#                                                                             #
# This program is being distributed as shareware. It may be used and modified #
# free for personal, government or non-profit. Any commercial use must be     #
# registered. However, modified versions cannot be sold or distributed. You   #
# cannot alter the copyright and "powered by" notices throughout the scripts. #
# These notices must be clearly visible to the end users.                     #
#                                                                             #
# WARRANTY DISCLAIMER:                                                        #
#                                                                             #
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT #
# ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR       #
# FITNESS FOR A PARTICULAR PURPOSE.                                           #
###############################################################################

package Source;

sub AgentsReport {
  my ($ERROR) = @_;

  my $epoch = time;
  my ($lHours, $lDays) = (localtime ($epoch))[2, 3];
  my ($gHours, $gDays) = (gmtime    ($epoch))[2, 3];

  $lHours += $lDays * 24;
  $gHours += $gDays * 24;

  my $tHours = $lHours - $gHours;

  my $TZ = "GMT";
  if ($tHours < 1) {
    $TZ = abs ($tHours)." hours before GMT";
  } elsif ($tHours > 1) {
    $TZ = $tHours." hours after GMT";
  } elsif ($tHours == -1) {
    $TZ = "1 hour before GMT";
  } elsif ($tHours ==  1) {
    $TZ = "1 hour after GMT";
  }

  &Standard::FileOpen(*TOTAL_HITS, "rw", "$SYSTEM::LOGS_PATH/total_hits.stats");
    my $TOTAL_HITS = <TOTAL_HITS> || 0;
  close (TOTAL_HITS);

  &Standard::PrintHTMLHeader();
  print &HTML::Header;
  print<<HTML;
<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr bgcolor="Gray">
    <td><font color="White"><b>
      <a href="$SYSTEM::CP_URL/Panel.$SYSTEM::EXT?action=body" target="UBBODY" class="address">Control Panel</a> / UltraBoard Statistics / Agents / Platforms report
    </b></font></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td>
            <table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolordark="White" bordercolorlight="Gray">
              <tr>
                <td>
                  <table width="100%" border="0" cellspacing="0" cellpadding="2">
                    <tr>
                      <td>
                      Local server time is $TZ. Total hits is $TOTAL_HITS.
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            &nbsp;<br>
            &nbsp;&nbsp;Browsers report
            <table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolordark="White" bordercolorlight="Gray">
              <tr height=24>
                <td nowrap>&nbsp;Browser&nbsp;</td>
                <td nowrap>&nbsp;Hits&nbsp;</td>
                <td nowrap>&nbsp;Percent&nbsp;</td>
                <td width="100%" nowrap>Graph</td>
              </tr>
HTML
  tie (my %BROWSERS, $AnyDBM_File::ISA[0], "$SYSTEM::LOGS_PATH/agents.stats", O_RDWR|O_CREAT, 0777);

  my $MaxHits = 1;
  my $TotalHits;
  foreach my $Hits (values %BROWSERS) {
    $MaxHits = $Hits if $Hits > $MaxHits;
    $TotalHits += $Hits;
  }
  $TotalHits ||= 1;

  foreach my $Browser (sort {$BROWSERS{$b} <=> $BROWSERS{$a}} keys %BROWSERS) {
    my $Hits = $BROWSERS{ $Browser } || 0;
    my $Percent = int ((($Hits / $MaxHits) * 100));
    my $PercentOfTotal = sprintf ("%.02f", (($Hits / $TotalHits) * 100));
    my $BrowserName = $Browser;
       $BrowserName =~s/\./ /g;
    print qq~<tr bgcolor="White">~;
    print qq~<td nowrap>&nbsp;$BrowserName&nbsp;</td>~;
    print qq~<td align="center" nowrap>&nbsp;$Hits&nbsp;</td>~;
    print qq~<td align="center" nowrap>&nbsp;$PercentOfTotal%&nbsp;</td>~;
    print qq~<td width="100%"><img src="$SYSTEM::IMAGE_URL/graph.gif" width="$Percent%" height="100%" border="1"></td>~;
    print qq~</tr>~;
  }

  untie (%BROWSERS);
print<<HTML;
            </table>
            &nbsp;<br>
            &nbsp;&nbsp;Platforms report
            <table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolordark="White" bordercolorlight="Gray">
              <tr height=24>
                <td nowrap>&nbsp;Platform&nbsp;</td>
                <td nowrap>&nbsp;Hits&nbsp;</td>
                <td nowrap>&nbsp;Percent&nbsp;</td>
                <td width="100%" nowrap>Graph</td>
              </tr>
HTML
  tie (my %PLATFORMS, $AnyDBM_File::ISA[0], "$SYSTEM::LOGS_PATH/platforms.stats", O_RDWR|O_CREAT, 0777);

  my $MaxHits = 1;
  my $TotalHits;
  foreach my $Hits (values %PLATFORMS) {
    $MaxHits = $Hits if $Hits > $MaxHits;
    $TotalHits += $Hits;
  }
  $TotalHits ||= 1;

  foreach my $Platform (sort {$PLATFORMS{$b} <=> $PLATFORMS{$a}} keys %PLATFORMS) {
    my $Hits = $PLATFORMS{ $Platform } || 0;
    my $Percent = int ((($Hits / $MaxHits) * 100));
    my $PercentOfTotal = sprintf ("%.02f", (($Hits / $TotalHits) * 100));
    print qq~<tr bgcolor="White">~;
    print qq~<td nowrap>&nbsp;$Platform&nbsp;</td>~;
    print qq~<td align="center" nowrap>&nbsp;$Hits&nbsp;</td>~;
    print qq~<td align="center" nowrap>&nbsp;$PercentOfTotal%&nbsp;</td>~;
    print qq~<td width="100%"><img src="$SYSTEM::IMAGE_URL/graph.gif" width="$Percent%" height="100%" border="1"></td>~;
    print qq~</tr>~;
  }

  untie (%PLATFORMS);
print<<HTML;
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
HTML
}

###############################################################################
1; # end of CP_AgentsReport.src file
###############################################################################