]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Added precious patch from Chris Larsen
authoreldy <>
Sat, 10 Apr 2010 13:27:11 +0000 (13:27 +0000)
committereldy <>
Sat, 10 Apr 2010 13:27:11 +0000 (13:27 +0000)
wwwroot/cgi-bin/awstats.pl
wwwroot/cgi-bin/plugins/graphgooglechartapi.pm

index a8c55e8f764184bd1355dbc555f2d59fb95232fd..7a5d8ff5be413861293b7a7c24787273e0c674a1 100644 (file)
@@ -64,8 +64,9 @@ use vars qw/
   $lowerval
   $PluginMode
   $MetaRobot
+  $AverageVisits $AveragePages $AverageHits $AverageBytes
   $TotalUnique $TotalVisits $TotalHostsKnown $TotalHostsUnknown
-  $TotalPages $TotalHits $TotalBytes
+  $TotalPages $TotalHits $TotalBytes $TotalHitsErrors
   $TotalNotViewedPages $TotalNotViewedHits $TotalNotViewedBytes
   $TotalEntries $TotalExits $TotalBytesPages $TotalDifferentPages
   $TotalKeyphrases $TotalKeywords $TotalDifferentKeyphrases $TotalDifferentKeywords
@@ -85,8 +86,9 @@ $LastUpdate          = 0;
 $lowerval            = 0;
 $PluginMode          = '';
 $MetaRobot           = 0;
+$AverageVisits = $AveragePages = $AverageHits = $AverageBytes = 0; 
 $TotalUnique         = $TotalVisits = $TotalHostsKnown = $TotalHostsUnknown = 0;
-$TotalPages          = $TotalHits = $TotalBytes = 0;
+$TotalPages          = $TotalHits = $TotalBytes = $TotalHitsErrors = 0;
 $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
 $TotalEntries = $TotalExits = $TotalBytesPages = $TotalDifferentPages = 0;
 $TotalKeyphrases = $TotalKeywords = $TotalDifferentKeyphrases = 0;
@@ -996,9 +998,6 @@ EOF
                        # Call to plugins' function AddHTMLStyles
                        foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLStyles'} } )
                        {
-
-                               # my $function="AddHTMLStyles_$pluginname()";
-                               # eval("$function");
                                my $function = "AddHTMLStyles_$pluginname";
                                &$function();
                        }
@@ -1019,6 +1018,13 @@ EOF
 #      print "<script type=\"text\/javascript\" src=\"/js/fabtabulous.js\"><\/script>";
 #      print "<script type=\"text\/javascript\" src=\"/js/mytablekit.js\"><\/script>";
 
+               # Call to plugins' function AddHTMLHeader
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLHeader'} } )
+               {
+                       my $function = "AddHTMLHeader_$pluginname";
+                       &$function();
+               }
+                       
                print "</head>\n\n";
                if ( $FrameName ne 'index' ) {
                        print "<body style=\"margin-top: 0px\"";
@@ -8333,7 +8339,7 @@ sub Convert_IP_To_Decimal {
 }
 
 #------------------------------------------------------------------------------
-# Function:     Test there is at least on value in list not null
+# Function:     Test there is at least one value in list not null
 # Parameters:   List of values
 # Input:        None
 # Output:       None
@@ -8349,6 +8355,171 @@ sub AtLeastOneNotNull {
        return 0;
 }
 
+#------------------------------------------------------------------------------
+# Function:     Prints the command line interface help information
+# Parameters:   None
+# Input:        None
+# Output:       None
+# Return:       None
+#------------------------------------------------------------------------------
+sub PrintCLIHelp{
+       &Read_Ref_Data(
+               'browsers',       'domains', 'operating_systems', 'robots',
+               'search_engines', 'worms'
+       );
+       print "----- $PROG $VERSION (c) 2000-2010 Laurent Destailleur -----\n";
+       print
+"AWStats is a free web server logfile analyzer to show you advanced web\n";
+       print "statistics.\n";
+       print
+"AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
+       print "with a GNU General Public License (See LICENSE file for details).\n";
+       print "\n";
+       print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
+       print "\n";
+       print
+"  This runs $PROG in command line to update statistics (-update option) of a\n";
+       print
+"   web site, from the log file defined in AWStats config file, or build a HTML\n";
+       print "   report (-output option).\n";
+       print
+"  First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
+       print "  If not found, $PROG tries to read $PROG.conf, and finally the full path passed to -config=\n";
+       print
+"  Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
+       print
+"   in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
+       print "   awstats.pl script file.\n";
+       print
+"  Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
+       print
+"   use it as the \"config\" value, whatever is the value on command line or URL.\n";
+       print "   See AWStats documentation for all setup instrutions.\n";
+       print "\n";
+       print "Options to update statistics:\n";
+       print "  -update        to update statistics (default)\n";
+       print
+"  -showsteps     to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
+       print
+"  -showcorrupted to add output for each corrupted lines found, with reason\n";
+       print
+"  -showdropped   to add output for each dropped lines found, with reason\n";
+       print "  -showunknownorigin  to output referer when it can't be parsed\n";
+       print
+"  -showdirectorigin   to output log line when origin is a direct access\n";
+       print "  -updatefor=n   to stop the update process after parsing n lines\n";
+       print
+"  -LogFile=x     to change log to analyze whatever is 'LogFile' in config file\n";
+       print
+"  Be care to process log files in chronological order when updating statistics.\n";
+       print "\n";
+       print "Options to show statistics:\n";
+       print
+"  -output      to output main HTML report (no update made except with -update)\n";
+       print "  -output=x    to output other report pages where x is:\n";
+       print
+"               alldomains       to build page of all domains/countries\n";
+       print "               allhosts         to build page of all hosts\n";
+       print
+         "               lasthosts        to build page of last hits for hosts\n";
+       print
+         "               unknownip        to build page of all unresolved IP\n";
+       print
+"               allemails        to build page of all email senders (maillog)\n";
+       print
+"               lastemails       to build page of last email senders (maillog)\n";
+       print
+"               allemailr        to build page of all email receivers (maillog)\n";
+       print
+"               lastemailr       to build page of last email receivers (maillog)\n";
+       print "               alllogins        to build page of all logins used\n";
+       print
+         "               lastlogins       to build page of last hits for logins\n";
+       print
+"               allrobots        to build page of all robots/spider visits\n";
+       print
+         "               lastrobots       to build page of last hits for robots\n";
+       print "               urldetail        to list most often viewed pages \n";
+       print
+"               urldetail:filter to list most often viewed pages matching filter\n";
+       print "               urlentry         to list entry pages\n";
+       print
+         "               urlentry:filter  to list entry pages matching filter\n";
+       print "               urlexit          to list exit pages\n";
+       print
+         "               urlexit:filter   to list exit pages matching filter\n";
+       print
+"               osdetail         to build page with os detailed versions\n";
+       print
+"               browserdetail    to build page with browsers detailed versions\n";
+       print
+"               unknownbrowser   to list 'User Agents' with unknown browser\n";
+       print
+         "               unknownos        to list 'User Agents' with unknown OS\n";
+       print
+"               refererse        to build page of all refering search engines\n";
+       print
+         "               refererpages     to build page of all refering pages\n";
+
+ #print "               referersites     to build page of all refering sites\n";
+       print
+"               keyphrases       to list all keyphrases used on search engines\n";
+       print
+"               keywords         to list all keywords used on search engines\n";
+       print "               errors404        to list 'Referers' for 404 errors\n";
+       print
+"               allextraX        to build page of all values for ExtraSection X\n";
+       print "  -staticlinks           to have static links in HTML report page\n";
+       print "  -staticlinksext=xxx    to have static links with .xxx extension instead of .html\n";
+       print
+"  -lang=LL     to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
+       print "  -month=MM    to output a HTML report for an old month MM\n";
+       print "  -year=YYYY   to output a HTML report for an old year YYYY\n";
+       print
+"  The 'date' options doesn't allow you to process old log file. They only\n";
+       print
+"  allow you to see a past report for a chosen month/year period instead of\n";
+       print "  current month/year.\n";
+       print "\n";
+       print "Other options:\n";
+       print
+"  -debug=X     to add debug informations lesser than level X (speed reduced)\n";
+       print "\n";
+       print "Now supports/detects:\n";
+       print
+"  Web/Ftp/Mail/streaming server log analyzis (and load balanced log files)\n";
+       print "  Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
+       print "  Number of visits, number of unique visitors\n";
+       print "  Visits duration and list of last visits\n";
+       print "  Authenticated users\n";
+       print "  Days of week and rush hours\n";
+       print "  Hosts list and unresolved IP addresses list\n";
+       print "  Most viewed, entry and exit pages\n";
+       print "  Files type and Web compression (mod_gzip, mod_deflate stats)\n";
+       print "  Screen size\n";
+       print "  Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
+       print "                        Quicktime reader, WMA reader, PDF reader\n";
+       print "  Configurable personalized reports\n";
+       print "  " . ( scalar keys %DomainsHashIDLib ) . " domains/countries\n";
+       print "  " . ( scalar keys %RobotsHashIDLib ) . " robots\n";
+       print "  " . ( scalar keys %WormsHashLib ) . " worm's families\n";
+       print "  " . ( scalar keys %OSHashLib ) . " operating systems\n";
+       print "  " . ( scalar keys %BrowsersHashIDLib ) . " browsers";
+       &Read_Ref_Data('browsers_phone');
+       print " ("
+         . ( scalar keys %BrowsersHashIDLib )
+         . " with phone browsers database)\n";
+       print "  "
+         . ( scalar keys %SearchEnginesHashLib )
+         . " search engines (and keyphrases/keywords used from them)\n";
+       print "  All HTTP errors with last referrer\n";
+       print "  Report by day/month/year\n";
+       print "  Dynamic or static HTML or XHTML reports, static PDF reports\n";
+       print "  Indexed text or XML monthly database\n";
+       print "  And a lot of other advanced features and options...\n";
+       print "New versions and FAQ at http://awstats.sourceforge.net\n";
+}
+
 #------------------------------------------------------------------------------
 # Function:     Return the string to add in html tag to include popup javascript code
 # Parameters:   tooltip number
@@ -8372,7 +8543,7 @@ sub Tooltip {
 # Output:       HTML Form
 # Return:       None
 #------------------------------------------------------------------------------
-sub ShowFormFilter {
+sub HTMLShowFormFilter {
        my $fieldfiltername    = shift;
        my $fieldfilterinvalue = shift;
        my $fieldfilterexvalue = shift;
@@ -8444,7 +8615,7 @@ sub ShowFormFilter {
 # Output:       URL link
 # Return:       None
 #------------------------------------------------------------------------------
-sub ShowUserInfo {
+sub HTMLShowUserInfo {
        my $user = shift;
 
        # Call to plugins' function ShowInfoUser
@@ -8464,7 +8635,7 @@ sub ShowUserInfo {
 # Output:       Cluster info
 # Return:       None
 #------------------------------------------------------------------------------
-sub ShowClusterInfo {
+sub HTMLShowClusterInfo {
        my $user = shift;
 
        # Call to plugins' function ShowInfoCluster
@@ -8485,7 +8656,7 @@ sub ShowClusterInfo {
 # Output:       None
 # Return:       None
 #------------------------------------------------------------------------------
-sub ShowHostInfo {
+sub HTMLShowHostInfo {
        my $host = shift;
 
        # Call to plugins' function ShowInfoHost
@@ -8505,7 +8676,7 @@ sub ShowHostInfo {
 # Output:       URL link
 # Return:       None
 #------------------------------------------------------------------------------
-sub ShowURLInfo {
+sub HTMLShowURLInfo {
        my $url     = shift;
        my $nompage = CleanXSS($url);
 
@@ -9050,7 +9221,15 @@ sub DefinePerlParsingFormat {
        if ($Debug) { debug(" PerlParsingFormat is $PerlParsingFormat"); }
 }
 
-sub ShowMenuCateg {
+#------------------------------------------------------------------------------
+# Function:     Prints a menu category for the frame or static header
+# Parameters:   -
+# Input:        $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
+#                              $NewLinkParams, $NewLinkTarget
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowMenuCateg {
        my ( $categ, $categtext, $categicon, $frame, $targetpage, $linkanchor,
                $NewLinkParams, $NewLinkTarget )
          = ( shift, shift, shift, shift, shift, shift, shift, shift );
@@ -9105,7 +9284,14 @@ sub ShowMenuCateg {
        print( $frame? "" : "</td></tr>\n" );
 }
 
-sub ShowEmailSendersChart {
+#------------------------------------------------------------------------------
+# Function:     Prints HTML to display an email senders chart
+# Parameters:   -
+# Input:        $NewLinkParams, NewLinkTarget
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowEmailSendersChart {
        my $NewLinkParams         = shift;
        my $NewLinkTarget         = shift;
        my $MaxLengthOfShownEMail = 48;
@@ -9265,7 +9451,14 @@ sub ShowEmailSendersChart {
        &tab_end();
 }
 
-sub ShowEmailReceiversChart {
+#------------------------------------------------------------------------------
+# Function:     Prints HTML to display an email receivers chart
+# Parameters:   -
+# Input:        $NewLinkParams, NewLinkTarget
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowEmailReceiversChart {
        my $NewLinkParams         = shift;
        my $NewLinkTarget         = shift;
        my $MaxLengthOfShownEMail = 48;
@@ -9429,10155 +9622,10745 @@ sub ShowEmailReceiversChart {
 }
 
 #------------------------------------------------------------------------------
-# MAIN
+# Function:     Prints the top banner of the inner frame or static page
+# Parameters:   $WIDTHMENU1
+# Input:        _
+# Output:       HTML
+# Return:       -
 #------------------------------------------------------------------------------
-( $DIR  = $0 ) =~ s/([^\/\\]+)$//;
-( $PROG = $1 ) =~ s/\.([^\.]*)$//;
-$Extension = $1;
-$DIR ||= '.';
-$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
+sub HTMLTopBanner{
+       my $WIDTHMENU1 = shift;
+       my $frame = ( $FrameName eq 'mainleft' );
 
-$starttime = time();
+       if ($Debug) { debug( "ShowTopBan", 2 ); }
+       print "$Center<a name=\"menu\">&nbsp;</a>\n";
 
-# Get current time (time when AWStats was started)
-( $nowsec, $nowmin, $nowhour, $nowday, $nowmonth, $nowyear, $nowwday, $nowyday )
-  = localtime($starttime);
-$nowweekofmonth = int( $nowday / 7 );
-$nowweekofyear  =
-  int( ( $nowyday - 1 + 6 - ( $nowwday == 0 ? 6 : $nowwday - 1 ) ) / 7 ) + 1;
-if ( $nowweekofyear > 52 ) { $nowweekofyear = 1; }
-$nowdaymod = $nowday % 7;
-$nowwday++;
-$nowns = Time::Local::timegm( 0, 0, 0, $nowday, $nowmonth, $nowyear );
+       if ( $FrameName ne 'mainleft' ) {
+               my $NewLinkParams = ${QueryString};
+               $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
+               $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
+               $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
+               $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
+               $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+               $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+               $NewLinkParams =~ s/^&amp;//;
+               $NewLinkParams =~ s/&amp;$//;
+               my $NewLinkTarget = '';
 
-if ( $nowdaymod <= $nowwday ) {
-       if ( ( $nowwday != 7 ) || ( $nowdaymod != 0 ) ) {
-               $nowweekofmonth = $nowweekofmonth + 1;
+               if ( $FrameName eq 'mainright' ) {
+                       $NewLinkTarget = " target=\"_parent\"";
+               }
+               print "<form name=\"FormDateFilter\" action=\""
+                 . XMLEncode("$AWScript?${NewLinkParams}")
+                 . "\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\"$NewLinkTarget>\n";
        }
-}
-if ( $nowdaymod > $nowwday ) { $nowweekofmonth = $nowweekofmonth + 2; }
 
-# Change format of time variables
-$nowweekofmonth = "0$nowweekofmonth";
-if ( $nowweekofyear < 10 ) { $nowweekofyear = "0$nowweekofyear"; }
-if ( $nowyear < 100 ) { $nowyear += 2000; }
-else { $nowyear += 1900; }
-$nowsmallyear = $nowyear;
-$nowsmallyear =~ s/^..//;
-if ( ++$nowmonth < 10 ) { $nowmonth = "0$nowmonth"; }
-if ( $nowday < 10 )     { $nowday   = "0$nowday"; }
-if ( $nowhour < 10 )    { $nowhour  = "0$nowhour"; }
-if ( $nowmin < 10 )     { $nowmin   = "0$nowmin"; }
-if ( $nowsec < 10 )     { $nowsec   = "0$nowsec"; }
-$nowtime = int( $nowyear . $nowmonth . $nowday . $nowhour . $nowmin . $nowsec );
+       if ( $QueryString !~ /buildpdf/i ) {
+               print
+"<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
+               print "<tr><td>\n";
+               print
+"<table class=\"aws_data sortable\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
+       }
+       else {
+               print "<table width=\"100%\">\n";
+       }
 
-# Get tomorrow time (will be used to discard some record with corrupted date (future date))
-my (
-       $tomorrowsec, $tomorrowmin,   $tomorrowhour,
-       $tomorrowday, $tomorrowmonth, $tomorrowyear
-  )
-  = localtime( $starttime + 86400 );
-if ( $tomorrowyear < 100 ) { $tomorrowyear += 2000; }
-else { $tomorrowyear += 1900; }
-if ( ++$tomorrowmonth < 10 ) { $tomorrowmonth = "0$tomorrowmonth"; }
-if ( $tomorrowday < 10 )     { $tomorrowday   = "0$tomorrowday"; }
-if ( $tomorrowhour < 10 )    { $tomorrowhour  = "0$tomorrowhour"; }
-if ( $tomorrowmin < 10 )     { $tomorrowmin   = "0$tomorrowmin"; }
-if ( $tomorrowsec < 10 )     { $tomorrowsec   = "0$tomorrowsec"; }
-$tomorrowtime =
-  int(  $tomorrowyear
-         . $tomorrowmonth
-         . $tomorrowday
-         . $tomorrowhour
-         . $tomorrowmin
-         . $tomorrowsec );
+       if ( $FrameName ne 'mainright' ) {
 
-# Allowed option
-my @AllowedCLIArgs = (
-       'migrate',            'config',
-       'logfile',            'output',
-       'runascli',           'update',
-       'staticlinks',        'staticlinksext',
-       'noloadplugin',       'loadplugin',
-       'hostfilter',         'urlfilter',
-       'refererpagesfilter', 'lang',
-       'month',              'year',
-       'framename',          'debug',
-       'showsteps',          'showdropped',
-       'showcorrupted',      'showunknownorigin',
-       'showdirectorigin',   'limitflush',
-       'confdir',            'updatefor',
-       'hostfilter',         'hostfilterex',
-       'urlfilter',          'urlfilterex',
-       'refererpagesfilter', 'refererpagesfilterex',
-       'pluginmode',         'filterrawlog'
-);
-
-# Parse input parameters and sanitize them for security reasons
-$QueryString = '';
-
-# AWStats use GATEWAY_INTERFACE to known if ran as CLI or CGI. AWSTATS_DEL_GATEWAY_INTERFACE can
-# be set to force AWStats to be ran as CLI even from a web page.
-if ( $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'} ) { $ENV{'GATEWAY_INTERFACE'} = ''; }
-if ( $ENV{'GATEWAY_INTERFACE'} ) {    # Run from a browser as CGI
-       $DebugMessages = 0;
-
-       # Prepare QueryString
-       if ( $ENV{'CONTENT_LENGTH'} ) {
-               binmode STDIN;
-               read( STDIN, $QueryString, $ENV{'CONTENT_LENGTH'} );
-       }
-       if ( $ENV{'QUERY_STRING'} ) {
-               $QueryString = $ENV{'QUERY_STRING'};
-
-               # Set & and &amp; to &amp;
-               $QueryString =~ s/&amp;/&/g;
-               $QueryString =~ s/&/&amp;/g;
-       }
-
-       # Remove all XSS vulnerabilities coming from AWStats parameters
-       $QueryString = CleanXSS( &DecodeEncodedString($QueryString) );
-
-       # Security test
-       if ( $QueryString =~ /LogFile=([^&]+)/i ) {
-               error(
-"Logfile parameter can't be overwritten when AWStats is used from a CGI"
-               );
-       }
-
-       # No update but report by default when run from a browser
-       $UpdateStats = ( $QueryString =~ /update=1/i ? 1 : 0 );
+               # Print Statistics Of
+               if ( $FrameName eq 'mainleft' ) {
+                       my $shortSiteDomain = $SiteDomain;
+                       if ( length($SiteDomain) > 30 ) {
+                               $shortSiteDomain =
+                                   substr( $SiteDomain, 0, 20 ) . "..."
+                                 . substr( $SiteDomain, length($SiteDomain) - 5, 5 );
+                       }
+                       print
+"<tr><td class=\"awsm\"><b>$Message[7]:</b></td></tr><tr><td class=\"aws\"><span style=\"font-size: 12px;\">$shortSiteDomain</span></td>";
+               }
+               else {
+                       print
+"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[7]:</b>&nbsp;</td><td class=\"aws\" valign=\"middle\"><span style=\"font-size: 14px;\">$SiteDomain</span></td>";
+               }
 
-       if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
-       if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
-       if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
-               $PluginMode = &Sanitize( "$1", 1 );
-       }
-       if ( $QueryString =~ /configdir=([^&]+)/i ) {
-               $DirConfig = &Sanitize("$1");
+               # Logo and flags
+               if ( $FrameName ne 'mainleft' ) {
+                       if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
+                               print "<td align=\"right\" rowspan=\"3\"><a href=\""
+                                 . XMLEncode($LogoLink)
+                                 . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
+                                 . AltTitle( ucfirst($PROG) . " Web Site" )
+                                 . " /></a>";
+                       }
+                       else {
+                               print "<td align=\"right\" rowspan=\"3\"><a href=\""
+                                 . XMLEncode($LogoLink)
+                                 . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>";
+                       }
+                       if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
+                       print "</td>";
+               }
+               print "</tr>\n";
        }
+       if ( $FrameName ne 'mainleft' ) {
 
-       # All filters
-       if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       }    # Filter on host list can also be defined with hostfilter=filter
-       if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
-               $FilterEx{'host'} = "$1";
-       }    #
-       if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
-               $FilterIn{'url'} = "$1";
-       }    # Filter on URL list can also be defined with urlfilter=filter
-       if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
-       if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
-               $FilterIn{'refererpages'} = "$1";
-       } # Filter on referer list can also be defined with refererpagesfilter=filter
-       if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
-               $FilterEx{'refererpages'} = "$1";
-       }    #
-            # All output
-       if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
-               $FilterIn{'url'} = "$1";
-       } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
-               $FilterIn{'refererpages'} = "$1";
-       } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
+               # Print Last Update
+               print
+"<tr valign=\"middle\"><td class=\"aws\" valign=\"middle\" width=\"$WIDTHMENU1\"><b>$Message[35]:</b>&nbsp;</td>";
+               print
+"<td class=\"aws\" valign=\"middle\"><span style=\"font-size: 12px;\">";
+               if ($LastUpdate) { print Format_Date( $LastUpdate, 0 ); }
+               else {
 
-       # If migrate
-       if ( $QueryString =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
-               $MigrateStats = &Sanitize("$2");
-               $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
-               $SiteConfig = $5 ? $5 : 'xxx';
-               $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
-       }
-}
-else {                             # Run from command line
-       $DebugMessages = 1;
+                       # Here NbOfOldLines = 0 (because LastUpdate is not defined)
+                       if ( !$UpdateStats ) {
+                               print "<span style=\"color: #880000\">$Message[24]</span>";
+                       }
+                       else {
+                               print
+"<span style=\"color: #880000\">No qualified records found in log ($NbOfLinesCorrupted corrupted, $NbOfLinesDropped dropped)</span>";
+                       }
 
-       # Prepare QueryString
-       for ( 0 .. @ARGV - 1 ) {
+               }
+               print "</span>";
 
-               # If migrate
-               if ( $ARGV[$_] =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
-                       $MigrateStats = "$2";
-                       $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
-                       $SiteConfig = $5 ? $5 : 'xxx';
-                       $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
-                       next;
+               # Print Update Now link
+               if ( $AllowToUpdateStatsFromBrowser && !$StaticLinks ) {
+                       my $NewLinkParams = ${QueryString};
+                       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
+                       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
+                       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+                       if ( $FrameName eq 'mainright' ) {
+                               $NewLinkParams .= "&amp;framename=mainright";
+                       }
+                       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+                       $NewLinkParams =~ s/^&amp;//;
+                       $NewLinkParams =~ s/&amp;$//;
+                       if ($NewLinkParams) {
+                               $NewLinkParams = "${NewLinkParams}&amp;";
+                       }
+                       print "&nbsp; &nbsp; &nbsp; &nbsp;";
+                       print "<a href=\""
+                         . XMLEncode("$AWScript?${NewLinkParams}update=1")
+                         . "\">$Message[74]</a>";
                }
+               print "</td>";
 
-               # TODO Check if ARGV is in @AllowedArg
-               if ($QueryString) { $QueryString .= '&amp;'; }
-               my $NewLinkParams = $ARGV[$_];
-               $NewLinkParams =~ s/^-+//;
-               $QueryString .= "$NewLinkParams";
-       }
+               # Logo and flags
+               if ( $FrameName eq 'mainright' ) {
+                       if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
+                               print "<td align=\"right\" rowspan=\"2\"><a href=\""
+                                 . XMLEncode($LogoLink)
+                                 . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
+                                 . AltTitle( ucfirst($PROG) . " Web Site" )
+                                 . " /></a>\n";
+                       }
+                       else {
+                               print "<td align=\"right\" rowspan=\"2\"><a href=\""
+                                 . XMLEncode($LogoLink)
+                                 . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>\n";
+                       }
+                       if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
+                       print "</td>";
+               }
 
-       # Remove all XSS vulnerabilities coming from AWStats parameters
-       $QueryString = CleanXSS($QueryString);
+               print "</tr>\n";
 
-       # Security test
-       if (   $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'}
-               && $QueryString =~ /LogFile=([^&]+)/i )
-       {
-               error(
-"Logfile parameter can't be overwritten when AWStats is used from a CGI"
-               );
+               # Print selected period of analysis (month and year required)
+               print
+"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[133]:</b></td>";
+               print "<td class=\"aws\" valign=\"middle\">";
+               if ( $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks ) {
+                       print "<select class=\"aws_formfield\" name=\"month\">\n";
+                       foreach ( 1 .. 12 ) {
+                               my $monthix = sprintf( "%02s", $_ );
+                               print "<option"
+                                 . (
+                                         "$MonthRequired" eq "$monthix"
+                                       ? " selected=\"true\""
+                                       : ""
+                                 )
+                                 . " value=\"$monthix\">$MonthNumLib{$monthix}</option>\n";
+                       }
+                       if ( $AllowFullYearView >= 2 ) {
+                               print "<option"
+                                 . ( $MonthRequired eq 'all' ? " selected=\"true\"" : "" )
+                                 . " value=\"all\">- $Message[6] -</option>\n";
+                       }
+                       print "</select>\n";
+                       print "<select class=\"aws_formfield\" name=\"year\">\n";
+
+                       # Add YearRequired in list if not in ListOfYears
+                       $ListOfYears{$YearRequired} ||= $MonthRequired;
+                       foreach ( sort keys %ListOfYears ) {
+                               print "<option"
+                                 . ( $YearRequired eq "$_" ? " selected=\"true\"" : "" )
+                                 . " value=\"$_\">$_</option>\n";
+                       }
+                       print "</select>\n";
+                       print "<input type=\"hidden\" name=\"output\" value=\""
+                         . join( ',', keys %HTMLOutput )
+                         . "\" />\n";
+                       if ($SiteConfig) {
+                               print
+"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
+                       }
+                       if ($DirConfig) {
+                               print
+"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
+                       }
+                       if ( $QueryString =~ /lang=(\w+)/i ) {
+                               print
+                                 "<input type=\"hidden\" name=\"lang\" value=\"$1\" />\n";
+                       }
+                       if ( $QueryString =~ /debug=(\d+)/i ) {
+                               print
+                                 "<input type=\"hidden\" name=\"debug\" value=\"$1\" />\n";
+                       }
+                       if ( $FrameName eq 'mainright' ) {
+                               print
+"<input type=\"hidden\" name=\"framename\" value=\"index\" />\n";
+                       }
+                       print
+"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" />";
+               }
+               else {
+                       print "<span style=\"font-size: 14px;\">";
+                       if ($DayRequired) { print "$Message[4] $DayRequired - "; }
+                       if ( $MonthRequired eq 'all' ) {
+                               print "$Message[6] $YearRequired";
+                       }
+                       else {
+                               print
+                                 "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired";
+                       }
+                       print "</span>";
+               }
+               print "</td></tr>\n";
        }
-
-       # Update with no report by default when run from command line
-       $UpdateStats = 1;
-
-       if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
-       if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
-       if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
-               $PluginMode = &Sanitize( "$1", 1 );
+       if ( $QueryString !~ /buildpdf/i ) {
+               print "</table>\n";
+               print "</td></tr></table>\n";
        }
-       if ( $QueryString =~ /configdir=([^&]+)/i ) {
-               $DirConfig = &Sanitize("$1");
+       else {
+               print "</table>\n";
        }
 
-       # All filters
-       if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       }    # Filter on host list can also be defined with hostfilter=filter
-       if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
-               $FilterEx{'host'} = "$1";
-       }    #
-       if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
-               $FilterIn{'url'} = "$1";
-       }    # Filter on URL list can also be defined with urlfilter=filter
-       if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
-       if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
-               $FilterIn{'refererpages'} = "$1";
-       } # Filter on referer list can also be defined with refererpagesfilter=filter
-       if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
-               $FilterEx{'refererpages'} = "$1";
-       }    #
-            # All output
-       if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
-               $FilterIn{'host'} = "$1";
-       } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
-               $FilterIn{'url'} = "$1";
-       } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
-       if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
-               $FilterIn{'refererpages'} = "$1";
-       } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
-         # Config parameters
-       if ( $QueryString =~ /LogFile=([^&]+)/i ) { $LogFile = "$1"; }
+       if ( $FrameName ne 'mainleft' ) { print "</form>\n"; }
+       else { print "<br />\n"; }
+       print "\n";
+}
 
-       # If show options
-       if ( $QueryString =~ /showsteps/i ) {
-               $ShowSteps = 1;
-               $QueryString =~ s/showsteps[^&]*//i;
-       }
-       if ( $QueryString =~ /showcorrupted/i ) {
-               $ShowCorrupted = 1;
-               $QueryString =~ s/showcorrupted[^&]*//i;
-       }
-       if ( $QueryString =~ /showdropped/i ) {
-               $ShowDropped = 1;
-               $QueryString =~ s/showdropped[^&]*//i;
-       }
-       if ( $QueryString =~ /showunknownorigin/i ) {
-               $ShowUnknownOrigin = 1;
-               $QueryString =~ s/showunknownorigin[^&]*//i;
-       }
-       if ( $QueryString =~ /showdirectorigin/i ) {
-               $ShowDirectOrigin = 1;
-               $QueryString =~ s/showdirectorigin[^&]*//i;
-       }
-}
-if ( $QueryString =~ /(^|&|&amp;)staticlinks/i ) {
-       $StaticLinks = "$PROG.$SiteConfig";
-}
-if ( $QueryString =~ /(^|&|&amp;)staticlinks=([^&]+)/i ) {
-       $StaticLinks = "$2";
-}    # When ran from awstatsbuildstaticpages.pl
-if ( $QueryString =~ /(^|&|&amp;)staticlinksext=([^&]+)/i ) {
-       $StaticExt = "$2";
-}
-if ( $QueryString =~ /(^|&|&amp;)framename=([^&]+)/i ) { $FrameName = "$2"; }
-if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i )       { $Debug     = $2; }
-if ( $QueryString =~ /(^|&|&amp;)databasebreak=(\w+)/i ) {
-       $DatabaseBreak = $2;
-}
-if ( $QueryString =~ /(^|&|&amp;)updatefor=(\d+)/i ) { $UpdateFor = $2; }
+#------------------------------------------------------------------------------
+# Function:     Prints the menu in a frame or below the top banner
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMenu{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       my $frame = ( $FrameName eq 'mainleft' );
+
+       if ($Debug) { debug( "ShowMenu", 2 ); }
+
+       # Print menu links
+       if ( ( $HTMLOutput{'main'} && $FrameName ne 'mainright' )
+               || $FrameName eq 'mainleft' )
+       {    # If main page asked
+                   # Define link anchor
+               my $linkanchor =
+                 ( $FrameName eq 'mainleft' ? "$AWScript?${NewLinkParams}" : "" );
+               if ( $linkanchor && ( $linkanchor !~ /framename=mainright/ ) ) {
+                       $linkanchor .= "framename=mainright";
+               }
+               $linkanchor =~ s/(&|&amp;)$//;
+               $linkanchor = XMLEncode("$linkanchor");
+
+               # Define target
+               my $targetpage =
+                 ( $FrameName eq 'mainleft' ? " target=\"mainright\"" : "" );
+
+               # Print Menu
+               my $linetitle;    # TODO a virer
+               if ( !$PluginsLoaded{'ShowMenu'}{'menuapplet'} ) {
+                       my $menuicon = 0;    # TODO a virer
+                                            # Menu HTML
+                       print "<table"
+                         . (
+                               $frame
+                               ? " cellspacing=\"0\" cellpadding=\"0\" border=\"0\""
+                               : ""
+                         )
+                         . ">\n";
+                       if ( $FrameName eq 'mainleft' && $ShowMonthStats ) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#top\"$targetpage>$Message[128]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       my %menu     = ();
+                       my %menulink = ();
+                       my %menutext = ();
+
+                       # When
+                       %menu = (
+                               'month'       => $ShowMonthStats       ? 1 : 0,
+                               'daysofmonth' => $ShowDaysOfMonthStats ? 2 : 0,
+                               'daysofweek'  => $ShowDaysOfWeekStats  ? 3 : 0,
+                               'hours'       => $ShowHoursStats       ? 4 : 0
+                       );
+                       %menulink = (
+                               'month'       => 1,
+                               'daysofmonth' => 1,
+                               'daysofweek'  => 1,
+                               'hours'       => 1
+                       );
+                       %menutext = (
+                               'month'       => $Message[162],
+                               'daysofmonth' => $Message[138],
+                               'daysofweek'  => $Message[91],
+                               'hours'       => $Message[20]
+                       );
+                       HTMLShowMenuCateg(
+                               'when',         $Message[93],
+                               'menu4.png',    $frame,
+                               $targetpage,    $linkanchor,
+                               $NewLinkParams, $NewLinkTarget,
+                               \%menu,         \%menulink,
+                               \%menutext
+                       );
 
-if ( $QueryString =~ /(^|&|&amp;)noloadplugin=([^&]+)/i ) {
-       foreach ( split( /,/, $2 ) ) { $NoLoadPlugin{ &Sanitize( "$_", 1 ) } = 1; }
-}
-if ( $QueryString =~ /(^|&|&amp;)limitflush=(\d+)/i ) { $LIMITFLUSH = $2; }
+                       # Who
+                       %menu = (
+                               'countries'  => $ShowDomainsStats ? 1 : 0,
+                               'alldomains' => $ShowDomainsStats ? 2 : 0,
+                               'visitors'   => $ShowHostsStats   ? 3 : 0,
+                               'allhosts'   => $ShowHostsStats   ? 4 : 0,
+                               'lasthosts' => ( $ShowHostsStats =~ /L/i ) ? 5 : 0,
+                               'unknownip' => $ShowHostsStats         ? 6 : 0,
+                               'logins'    => $ShowAuthenticatedUsers ? 7 : 0,
+                               'alllogins' => $ShowAuthenticatedUsers ? 8 : 0,
+                               'lastlogins' => ( $ShowAuthenticatedUsers =~ /L/i ) ? 9 : 0,
+                               'emailsenders' => $ShowEMailSenders ? 10 : 0,
+                               'allemails'    => $ShowEMailSenders ? 11 : 0,
+                               'lastemails' => ( $ShowEMailSenders =~ /L/i ) ? 12 : 0,
+                               'emailreceivers' => $ShowEMailReceivers ? 13 : 0,
+                               'allemailr'      => $ShowEMailReceivers ? 14 : 0,
+                               'lastemailr' => ( $ShowEMailReceivers =~ /L/i ) ? 15 : 0,
+                               'robots'    => $ShowRobotsStats ? 16 : 0,
+                               'allrobots' => $ShowRobotsStats ? 17 : 0,
+                               'lastrobots' => ( $ShowRobotsStats =~ /L/i ) ? 18 : 0,
+                               'worms' => $ShowWormsStats ? 19 : 0
+                       );
+                       %menulink = (
+                               'countries'      => 1,
+                               'alldomains'     => 2,
+                               'visitors'       => 1,
+                               'allhosts'       => 2,
+                               'lasthosts'      => 2,
+                               'unknownip'      => 2,
+                               'logins'         => 1,
+                               'alllogins'      => 2,
+                               'lastlogins'     => 2,
+                               'emailsenders'   => 1,
+                               'allemails'      => 2,
+                               'lastemails'     => 2,
+                               'emailreceivers' => 1,
+                               'allemailr'      => 2,
+                               'lastemailr'     => 2,
+                               'robots'         => 1,
+                               'allrobots'      => 2,
+                               'lastrobots'     => 2,
+                               'worms'          => 1
+                       );
+                       %menutext = (
+                               'countries'      => $Message[148],
+                               'alldomains'     => $Message[80],
+                               'visitors'       => $Message[81],
+                               'allhosts'       => $Message[80],
+                               'lasthosts'      => $Message[9],
+                               'unknownip'      => $Message[45],
+                               'logins'         => $Message[94],
+                               'alllogins'      => $Message[80],
+                               'lastlogins'     => $Message[9],
+                               'emailsenders'   => $Message[131],
+                               'allemails'      => $Message[80],
+                               'lastemails'     => $Message[9],
+                               'emailreceivers' => $Message[132],
+                               'allemailr'      => $Message[80],
+                               'lastemailr'     => $Message[9],
+                               'robots'         => $Message[53],
+                               'allrobots'      => $Message[80],
+                               'lastrobots'     => $Message[9],
+                               'worms'          => $Message[136]
+                       );
+                       HTMLShowMenuCateg(
+                               'who',          $Message[92],
+                               'menu5.png',    $frame,
+                               $targetpage,    $linkanchor,
+                               $NewLinkParams, $NewLinkTarget,
+                               \%menu,         \%menulink,
+                               \%menutext
+                       );
 
-# Get/Define output
-if ( $QueryString =~
-       /(^|&|&amp;)output(=[^&]*|)(.*)(&|&amp;)output(=[^&]*|)(&|$)/i )
-{
-       error( "Only 1 output option is allowed", "", "", 1 );
-}
-if ( $QueryString =~ /(^|&|&amp;)output(=[^&]*|)(&|$)/i ) {
+                       # Navigation
+                       $linetitle = &AtLeastOneNotNull(
+                               $ShowSessionsStats,  $ShowPagesStats,
+                               $ShowFileTypesStats, $ShowFileSizesStats,
+                               $ShowOSStats,        $ShowBrowsersStats,
+                               $ShowScreenSizeStats
+                       );
+                       if ($linetitle) {
+                               print "<tr><td class=\"awsm\""
+                                 . ( $frame ? "" : " valign=\"top\"" ) . ">"
+                                 . (
+                                       $menuicon
+                                       ? "<img src=\"$DirIcons/other/menu2.png\" />&nbsp;"
+                                       : ""
+                                 )
+                                 . "<b>$Message[72]:</b></td>\n";
+                       }
+                       if ($linetitle) {
+                               print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
+                       }
+                       if ($ShowSessionsStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#sessions\"$targetpage>$Message[117]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowFileTypesStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#filetypes\"$targetpage>$Message[73]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowPagesStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#urls\"$targetpage>$Message[29]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowPagesStats) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=urldetail")
+                                       : "$StaticLinks.urldetail.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[80]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ( $ShowPagesStats =~ /E/i ) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=urlentry")
+                                       : "$StaticLinks.urlentry.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[104]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ( $ShowPagesStats =~ /X/i ) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'}
+                                         || !$StaticLinks
+                                       ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
+                                       : "$StaticLinks.urlexit.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[116]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowOSStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+                                 "<a href=\"$linkanchor#os\"$targetpage>$Message[59]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowOSStats) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=osdetail")
+                                       : "$StaticLinks.osdetail.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[58]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowOSStats) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=unknownos")
+                                       : "$StaticLinks.unknownos.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[0]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowBrowsersStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#browsers\"$targetpage>$Message[21]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowBrowsersStats) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=browserdetail")
+                                       : "$StaticLinks.browserdetail.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[58]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowBrowsersStats) {
+                               print( $frame
+                                       ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
+                                       : ""
+                               );
+                               print "<a href=\""
+                                 . (
+                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                                       ? XMLEncode(
+                                               "$AWScript?${NewLinkParams}output=unknownbrowser")
+                                       : "$StaticLinks.unknownbrowser.$StaticExt"
+                                 )
+                                 . "\"$NewLinkTarget>$Message[0]</a>\n";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($ShowScreenSizeStats) {
+                               print( $frame? "<tr><td class=\"awsm\">" : "" );
+                               print
+"<a href=\"$linkanchor#screensizes\"$targetpage>$Message[135]</a>";
+                               print( $frame? "</td></tr>\n" : " &nbsp; " );
+                       }
+                       if ($linetitle) { print( $frame? "" : "</td></tr>\n" ); }
+
+                       # Referers
+                       %menu = (
+                               'referer'      => $ShowOriginStats ? 1 : 0,
+                               'refererse'    => $ShowOriginStats ? 2 : 0,
+                               'refererpages' => $ShowOriginStats ? 3 : 0,
+                               'keys' => ( $ShowKeyphrasesStats || $ShowKeywordsStats )
+                               ? 4
+                               : 0,
+                               'keyphrases' => $ShowKeyphrasesStats ? 5 : 0,
+                               'keywords'   => $ShowKeywordsStats   ? 6 : 0
+                       );
+                       %menulink = (
+                               'referer'      => 1,
+                               'refererse'    => 2,
+                               'refererpages' => 2,
+                               'keys'         => 1,
+                               'keyphrases'   => 2,
+                               'keywords'     => 2
+                       );
+                       %menutext = (
+                               'referer'      => $Message[37],
+                               'refererse'    => $Message[126],
+                               'refererpages' => $Message[127],
+                               'keys'         => $Message[14],
+                               'keyphrases'   => $Message[120],
+                               'keywords'     => $Message[121]
+                       );
+                       HTMLShowMenuCateg(
+                               'referers',     $Message[23],
+                               'menu7.png',    $frame,
+                               $targetpage,    $linkanchor,
+                               $NewLinkParams, $NewLinkTarget,
+                               \%menu,         \%menulink,
+                               \%menutext
+                       );
 
-       # At least one output expected. We define %HTMLOutput
-       my $outputlist = "$2";
-       if ($outputlist) {
-               $outputlist =~ s/^=//;
-               foreach my $outputparam ( split( /,/, $outputlist ) ) {
-                       $outputparam =~ s/:(.*)$//;
-                       if ($outputparam) { $HTMLOutput{ lc($outputparam) } = "$1" || 1; }
+                       # Others
+                       %menu = (
+                               'filetypes' => ( $ShowFileTypesStats =~ /C/i ) ? 1 : 0,
+                               'misc' => $ShowMiscStats ? 2 : 0,
+                               'errors' => ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats )
+                               ? 3
+                               : 0,
+                               'clusters' => $ShowClusterStats ? 5 : 0
+                       );
+                       %menulink = (
+                               'filetypes' => 1,
+                               'misc'      => 1,
+                               'errors'    => 1,
+                               'clusters'  => 1
+                       );
+                       %menutext = (
+                               'filetypes' => $Message[98],
+                               'misc'      => $Message[139],
+                               'errors'    =>
+                                 ( $ShowSMTPErrorsStats ? $Message[147] : $Message[32] ),
+                               'clusters' => $Message[155]
+                       );
+                       foreach ( keys %TrapInfosForHTTPErrorCodes ) {
+                               $menu{"errors$_"}     = $ShowHTTPErrorsStats ? 4 : 0;
+                               $menulink{"errors$_"} = 2;
+                               $menutext{"errors$_"} = $Message[31];
+                       }
+                       HTMLShowMenuCateg(
+                               'others',       $Message[2],
+                               'menu8.png',    $frame,
+                               $targetpage,    $linkanchor,
+                               $NewLinkParams, $NewLinkTarget,
+                               \%menu,         \%menulink,
+                               \%menutext
+                       );
+
+                       # Extra/Marketing
+                       %menu     = ();
+                       %menulink = ();
+                       %menutext = ();
+                       my $i = 1;
+                       foreach ( 1 .. @ExtraName - 1 ) {
+                               $menu{"extra$_"}        = $i++;
+                               $menulink{"extra$_"}    = 1;
+                               $menutext{"extra$_"}    = $ExtraName[$_];
+                               $menu{"allextra$_"}     = $i++;
+                               $menulink{"allextra$_"} = 2;
+                               $menutext{"allextra$_"} = $Message[80];
+                       }
+                       HTMLShowMenuCateg(
+                               'extra',        $Message[134],
+                               '',             $frame,
+                               $targetpage,    $linkanchor,
+                               $NewLinkParams, $NewLinkTarget,
+                               \%menu,         \%menulink,
+                               \%menutext
+                       );
+                       print "</table>\n";
                }
-       }
+               else {
 
-       # If on command line and no update
-       if ( !$ENV{'GATEWAY_INTERFACE'} && $QueryString !~ /update/i ) {
-               $UpdateStats = 0;
+                       # Menu Applet
+                       if ($frame) { }
+                       else { }
+               }
+
+               #print ($frame?"":"<br />\n");
+               print "<br />\n";
        }
 
-       # If no output defined, used default value
-       if ( !scalar keys %HTMLOutput ) { $HTMLOutput{'main'} = 1; }
-}
-if ( $ENV{'GATEWAY_INTERFACE'} && !scalar keys %HTMLOutput ) {
-       $HTMLOutput{'main'} = 1;
+       # Print Back link
+       elsif ( !$HTMLOutput{'main'} ) {
+               print "<table>\n";
+               $NewLinkParams =~ s/(^|&|&amp;)hostfilter=[^&]*//i;
+               $NewLinkParams =~ s/(^|&|&amp;)urlfilter=[^&]*//i;
+               $NewLinkParams =~ s/(^|&|&amp;)refererpagesfilter=[^&]*//i;
+               $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+               $NewLinkParams =~ s/^&amp;//;
+               $NewLinkParams =~ s/&amp;$//;
+               if (   !$DetailedReportsOnNewWindows
+                       || $FrameName eq 'mainright'
+                       || $QueryString =~ /buildpdf/i )
+               {
+                       print "<tr><td class=\"aws\"><a href=\""
+                         . (
+                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                               ? XMLEncode(
+                                       "$AWScript"
+                                         . ( ${NewLinkParams} ? "?${NewLinkParams}" : "" )
+                                 )
+                               : "$StaticLinks.$StaticExt"
+                         )
+                         . "\">$Message[76]</a></td></tr>\n";
+               }
+               else {
+                       print
+"<tr><td class=\"aws\"><a href=\"javascript:parent.window.close();\">$Message[118]</a></td></tr>\n";
+               }
+               print "</table>\n";
+               print "\n";
+       }
 }
 
-# Remove -output option with no = from QueryString
-$QueryString =~ s/(^|&|&amp;)output(&|$)/$1$2/i;
-$QueryString =~ s/&+$//;
+#------------------------------------------------------------------------------
+# Function:     Prints the File Type table
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainFileType{
+       if ($Debug) { debug( "ShowFileTypesStatsCompressionStats", 2 ); }
+       print "$Center<a name=\"filetypes\">&nbsp;</a><br />\n";
+       my $Totalh = 0;
+       foreach ( keys %_filetypes_h ) { $Totalh += $_filetypes_h{$_}; }
+       my $Totalk = 0;
+       foreach ( keys %_filetypes_k ) { $Totalk += $_filetypes_k{$_}; }
+       my $title = "$Message[73]";
+       if ( $ShowFileTypesStats =~ /C/i ) { $title .= " - $Message[98]"; }
+       
+       # build keylist at top
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_filetypes_h,
+               \%_filetypes_h );
+               
+       &tab_head( "$title", 19, 0, 'filetypes' );
+               
+       # Graph the top five in a pie chart
+       if (scalar @keylist > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
+                               push @blocklabel, "$key";
+                               $cnt++;
+                               if ($cnt > 4) { last; }
+                       }
+                       print "<tr><td colspan=\"7\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "$title",              "filetypes",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[73]</th>";
 
-# Check year, month, day, hour parameters
-if ( $QueryString =~ /(^|&|&amp;)month=(year)/i ) {
-       error("month=year is a deprecated option. Use month=all instead.");
-}
-if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
-       $YearRequired = sprintf( "%04d", $2 );
-}
-else { $YearRequired = "$nowyear"; }
-if ( $QueryString =~ /(^|&|&amp;)month=(\d{1,2})/i ) {
-       $MonthRequired = sprintf( "%02d", $2 );
-}
-elsif ( $QueryString =~ /(^|&|&amp;)month=(all)/i ) { $MonthRequired = 'all'; }
-else { $MonthRequired = "$nowmonth"; }
-if ( $QueryString =~ /(^|&|&amp;)day=(\d{1,2})/i ) {
-       $DayRequired = sprintf( "%02d", $2 );
-} # day is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
-else { $DayRequired = ''; }
-if ( $QueryString =~ /(^|&|&amp;)hour=(\d{1,2})/i ) {
-       $HourRequired = sprintf( "%02d", $2 );
-} # hour is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
-else { $HourRequired = ''; }
+       if ( $ShowFileTypesStats =~ /H/i ) {
+               print "<th bgcolor=\"#$color_h\" width=\"80\""
+                 . Tooltip(4)
+                 . ">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       }
+       if ( $ShowFileTypesStats =~ /B/i ) {
+               print "<th bgcolor=\"#$color_k\" width=\"80\""
+                 . Tooltip(5)
+                 . ">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
+       }
+       if ( $ShowFileTypesStats =~ /C/i ) {
+               print
+"<th bgcolor=\"#$color_k\" width=\"100\">$Message[100]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[101]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[99]</th>";
+       }
+       print "</tr>\n";
+       my $total_con = 0;
+       my $total_cre = 0;
+       my $count     = 0;
+       foreach my $key (@keylist) {
+               my $p_h = '&nbsp;';
+               my $p_k = '&nbsp;';
+               if ($Totalh) {
+                       $p_h = int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
+                       $p_h = "$p_h %";
+               }
+               if ($Totalk) {
+                       $p_k = int( $_filetypes_k{$key} / $Totalk * 1000 ) / 10;
+                       $p_k = "$p_k %";
+               }
+               if ( $key eq 'Unknown' ) {
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/mime\/unknown.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\" colspan=\"2\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
+               }
+               else {
+                       my $nameicon = $MimeHashIcon{$key} || "notavailable";
+                       my $nametype =
+                         $MimeHashLib{ $MimeHashFamily{$key} || "" } || "&nbsp;";
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\">$key</td>";
+                       print "<td class=\"aws\">$nametype</td>";
+               }
+               if ( $ShowFileTypesStats =~ /H/i ) {
+                       print "<td>".Format_Number($_filetypes_h{$key})."</td><td>$p_h</td>";
+               }
+               if ( $ShowFileTypesStats =~ /B/i ) {
+                       print '<td nowrap="nowrap">'
+                         . Format_Bytes( $_filetypes_k{$key} )
+                         . "</td><td>$p_k</td>";
+               }
+               if ( $ShowFileTypesStats =~ /C/i ) {
+                       if ( $_filetypes_gz_in{$key} ) {
+                               my $percent = int(
+                                       100 * (
+                                               1 - $_filetypes_gz_out{$key} /
+                                                 $_filetypes_gz_in{$key}
+                                       )
+                               );
+                               printf(
+                                       "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
+                                       Format_Bytes( $_filetypes_gz_in{$key} ),
+                                       Format_Bytes( $_filetypes_gz_out{$key} ),
+                                       Format_Bytes(
+                                               $_filetypes_gz_in{$key} -
+                                                 $_filetypes_gz_out{$key}
+                                       ),
+                                       $percent
+                               );
+                               $total_con += $_filetypes_gz_in{$key};
+                               $total_cre += $_filetypes_gz_out{$key};
+                       }
+                       else {
+                               print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
+                       }
+               }
+               print "</tr>\n";
+               $count++;
+       }
 
-# Check parameter validity
-# TODO
+       # Add total (only usefull if compression is enabled)
+       if ( $ShowFileTypesStats =~ /C/i ) {
+               my $colspan = 3;
+               if ( $ShowFileTypesStats =~ /H/i ) { $colspan += 2; }
+               if ( $ShowFileTypesStats =~ /B/i ) { $colspan += 2; }
+               print "<tr>";
+               print
+"<td class=\"aws\" colspan=\"$colspan\"><b>$Message[98]</b></td>";
+               if ( $ShowFileTypesStats =~ /C/i ) {
+                       if ($total_con) {
+                               my $percent =
+                                 int( 100 * ( 1 - $total_cre / $total_con ) );
+                               printf(
+                                       "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
+                                       Format_Bytes($total_con),
+                                       Format_Bytes($total_cre),
+                                       Format_Bytes( $total_con - $total_cre ),
+                                       $percent
+                               );
+                       }
+                       else {
+                               print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
+                       }
+               }
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-# Print AWStats and Perl version
-if ($Debug) {
-       debug( ucfirst($PROG) . " - $VERSION - Perl $^X $]", 1 );
-       debug( "DIR=$DIR PROG=$PROG Extension=$Extension",   2 );
-       debug( "QUERY_STRING=$QueryString",                  2 );
-       debug( "HTMLOutput=" . join( ',', keys %HTMLOutput ), 1 );
-       debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
-       debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
-       debug( "UpdateFor=$UpdateFor",                                     2 );
-       debug( "PluginMode=$PluginMode",                                   2 );
-       debug( "DirConfig=$DirConfig",                                     2 );
+#------------------------------------------------------------------------------
+# Function:     Prints the Browser Detail frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowBrowserDetail{
+       # Show browsers versions
+       print "$Center<a name=\"browsersversions\">&nbsp;</a><br />";
+       my $title = "$Message[21]";
+       &tab_head( "$title", 19, 0, 'browsersversions' );
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
+       print
+"<th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       print "<th>&nbsp;</th>";
+       print "</tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       &BuildKeyList( MinimumButNoZero( scalar keys %_browser_h, 500 ),
+               1, \%_browser_h, \%_browser_h );
+       my %keysinkeylist = ();
+       my $max_h = 1;
+
+       # Count total by family
+       my %totalfamily_h = ();
+       my $TotalFamily   = 0;
+  BROWSERLOOP: foreach my $key (@keylist) {
+               $total_h += $_browser_h{$key};
+               if ( $_browser_h{$key} > $max_h ) {
+                       $max_h = $_browser_h{$key};
+               }
+               foreach my $family ( keys %BrowsersFamily ) {
+                       if ( $key =~ /^$family/i ) {
+                               $totalfamily_h{$family} += $_browser_h{$key};
+                               $TotalFamily            += $_browser_h{$key};
+                               next BROWSERLOOP;
+                       }
+               }
+       }
+
+       # Write records grouped in a browser family
+       foreach my $family (
+               sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} }
+               keys %BrowsersFamily
+         )
+       {
+               my $p = '&nbsp;';
+               if ($total_h) {
+                       $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               my $familyheadershown = 0;
+
+               #foreach my $key ( reverse sort keys %_browser_h ) {
+               foreach my $key ( reverse sort SortBrowsers keys %_browser_h ) {
+                       if ( $key =~ /^$family(.*)/i ) {
+                               if ( !$familyheadershown ) {
+                                       print
+"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>"
+                                 . uc($family)
+                                 . "</b></td>";
+                               print "<td>&nbsp;</td><td><b>"
+                                 . Format_Number(int( $totalfamily_h{$family} ))
+                                 . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
+                               print "</tr>\n";
+                               $familyheadershown = 1;
+                       }
+                       $keysinkeylist{$key} = 1;
+                       my $ver = $1;
+                       my $p   = '&nbsp;';
+                       if ($total_h) {
+                               $p =
+                                 int( $_browser_h{$key} / $total_h * 1000 ) / 10;
+                               $p = "$p %";
+                       }
+                       print "<tr>";
+                       print "<td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/$family.png\""
+                         . AltTitle("")
+                         . " /></td>";
+                       print "<td class=\"aws\">"
+                         . ucfirst($family) . " "
+                         . ( $ver ? "$ver" : "?" ) . "</td>";
+                       print "<td>"
+                         . (
+                               $BrowsersHereAreGrabbers{$family}
+                               ? "<b>$Message[112]</b>"
+                               : "$Message[113]"
+                         )
+                         . "</td>";
+                       my $bredde_h = 0;
+                       if ( $max_h > 0 ) {
+                               $bredde_h =
+                                 int( $BarWidth * ( $_browser_h{$key} || 0 ) /
+                                         $max_h ) + 1;
+                       }
+                       if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
+                               $bredde_h = 2;
+                       }
+                       print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
+                       print "<td class=\"aws\">";
+
+                       # alt and title are not provided to reduce page size
+                       if ($ShowBrowsersStats) {
+                               print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+                               }
+                               print "</td>";
+                               print "</tr>\n";
+                               $count++;
+                       }
+               }
+       }
+
+       # Write other records
+       my $familyheadershown = 0;
+       foreach my $key (@keylist) {
+               if ( $keysinkeylist{$key} ) { next; }
+               if ( !$familyheadershown )  {
+                       my $p = '&nbsp;';
+                       if ($total_h) {
+                               $p =
+                                 int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
+                                 10;
+                               $p = "$p %";
+                       }
+                       print
+"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
+                       print "<td>&nbsp;</td><td><b>"
+                         . Format_Number(( $total_h - $TotalFamily ))
+                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
+                       print "</tr>\n";
+                       $familyheadershown = 1;
+               }
+               my $p = '&nbsp;';
+               if ($total_h) {
+                       $p = int( $_browser_h{$key} / $total_h * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               print "<tr>";
+               if ( $key eq 'Unknown' ) {
+                       print "<td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td>";
+               }
+               else {
+                       my $keywithoutcumul = $key;
+                       $keywithoutcumul =~ s/cumul$//i;
+                       my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
+                         || $keywithoutcumul;
+                       my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
+                         || "notavailable";
+                       print "<td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\">$libbrowser</td><td>"
+                         . (
+                               $BrowsersHereAreGrabbers{$key}
+                               ? "<b>$Message[112]</b>"
+                               : "$Message[113]"
+                         )
+                         . "</td>";
+               }
+               my $bredde_h = 0;
+               if ( $max_h > 0 ) {
+                       $bredde_h =
+                         int( $BarWidth * ( $_browser_h{$key} || 0 ) / $max_h ) +
+                         1;
+               }
+               if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
+                       $bredde_h = 2;
+               }
+               print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
+               print "<td class=\"aws\">";
+
+               # alt and title are not provided to reduce page size
+               if ($ShowBrowsersStats) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+               }
+               print "</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
 }
 
-# Force SiteConfig if AWSTATS_FORCE_CONFIG is defined
-if ( $ENV{'AWSTATS_CONFIG'} ) {
-       $ENV{'AWSTATS_FORCE_CONFIG'} = $ENV{'AWSTATS_CONFIG'};
-}    # For backward compatibility
-if ( $ENV{'AWSTATS_FORCE_CONFIG'} ) {
-       if ($Debug) {
-               debug(  "AWSTATS_FORCE_CONFIG parameter is defined to '"
-                         . $ENV{'AWSTATS_FORCE_CONFIG'}
-                         . "'. $PROG will use this as config value." );
+#------------------------------------------------------------------------------
+# Function:     Prints the Unknown Browser Detail frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowBrowserUnknown{
+       print "$Center<a name=\"unknownbrowser\">&nbsp;</a><br />\n";
+       my $title = "$Message[50]";
+       &tab_head( "$title", 19, 0, 'unknownbrowser' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
+         . ( scalar keys %_unknownrefererbrowser_l )
+         . ")</th><th>$Message[9]</th></tr>\n";
+       my $total_l = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownrefererbrowser_l,
+               \%_unknownrefererbrowser_l );
+       foreach my $key (@keylist) {
+               my $useragent = XMLEncode( CleanXSS($key) );
+               print
+                 "<tr><td class=\"aws\">$useragent</td><td nowrap=\"nowrap\">"
+                 . Format_Date( $_unknownrefererbrowser_l{$key}, 1 )
+                 . "</td></tr>\n";
+               $total_l += 1;
+               $count++;
        }
-       $SiteConfig = &Sanitize( $ENV{'AWSTATS_FORCE_CONFIG'} );
+       my $rest_l = ( scalar keys %_unknownrefererbrowser_l ) - $total_l;
+       if ( $rest_l > 0 ) {
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td>-</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
 }
 
-if ( ( !$ENV{'GATEWAY_INTERFACE'} ) && ( !$SiteConfig ) ) {
-       &Read_Ref_Data(
-               'browsers',       'domains', 'operating_systems', 'robots',
-               'search_engines', 'worms'
-       );
-       print "----- $PROG $VERSION (c) 2000-2010 Laurent Destailleur -----\n";
-       print
-"AWStats is a free web server logfile analyzer to show you advanced web\n";
-       print "statistics.\n";
+#------------------------------------------------------------------------------
+# Function:     Prints the OS Detail frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowOSDetail{
+       # Show os versions
+       print "$Center<a name=\"osversions\">&nbsp;</a><br />";
+       my $title = "$Message[59]";
+       &tab_head( "$title", 19, 0, 'osversions' );
        print
-"AWStats comes with ABSOLUTELY NO WARRANTY. It's a free software distributed\n";
-       print "with a GNU General Public License (See LICENSE file for details).\n";
-       print "\n";
-       print "Syntax: $PROG.$Extension -config=virtualhostname [options]\n";
-       print "\n";
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
        print
-"  This runs $PROG in command line to update statistics (-update option) of a\n";
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       print "<th>&nbsp;</th>";
+       print "</tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       &BuildKeyList( MinimumButNoZero( scalar keys %_os_h, 500 ),
+               1, \%_os_h, \%_os_h );
+       my %keysinkeylist = ();
+       my $max_h = 1;
+
+       # Count total by family
+       my %totalfamily_h = ();
+       my $TotalFamily   = 0;
+  OSLOOP: foreach my $key (@keylist) {
+               $total_h += $_os_h{$key};
+               if ( $_os_h{$key} > $max_h ) { $max_h = $_os_h{$key}; }
+               foreach my $family ( keys %OSFamily ) {
+                       if ( $key =~ /^$family/i ) {
+                               $totalfamily_h{$family} += $_os_h{$key};
+                               $TotalFamily            += $_os_h{$key};
+                               next OSLOOP;
+                       }
+               }
+       }
+
+       # Write records grouped in a browser family
+       foreach my $family ( keys %OSFamily ) {
+               my $p = '&nbsp;';
+               if ($total_h) {
+                       $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               my $familyheadershown = 0;
+               foreach my $key ( reverse sort keys %_os_h ) {
+                       if ( $key =~ /^$family(.*)/i ) {
+                               if ( !$familyheadershown ) {
+                                       my $family_name = '';
+                                       if ( $OSFamily{$family} ) {
+                                               $family_name = $OSFamily{$family};
+                                       }
+                                       print
+"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$family_name</b></td>";
+                                       print "<td><b>"
+                                         . Format_Number(int( $totalfamily_h{$family} ))
+                                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
+                                       print "</tr>\n";
+                                       $familyheadershown = 1;
+                               }
+                               $keysinkeylist{$key} = 1;
+                               my $ver = $1;
+                               my $p   = '&nbsp;';
+                               if ($total_h) {
+                                       $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
+                                       $p = "$p %";
+                               }
+                               print "<tr>";
+                               print "<td"
+                                 . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                                 . "><img src=\"$DirIcons\/os\/$key.png\""
+                                 . AltTitle("")
+                                 . " /></td>";
+
+                               print "<td class=\"aws\">$OSHashLib{$key}</td>";
+                               my $bredde_h = 0;
+                               if ( $max_h > 0 ) {
+                                       $bredde_h =
+                                         int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h )
+                                         + 1;
+                               }
+                               if ( ( $bredde_h == 1 ) && $_os_h{$key} ) {
+                                       $bredde_h = 2;
+                               }
+                               print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
+                               print "<td class=\"aws\">";
+
+                               # alt and title are not provided to reduce page size
+                               if ($ShowOSStats) {
+                                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+                               }
+                               print "</td>";
+                               print "</tr>\n";
+                               $count++;
+                       }
+               }
+       }
+
+       # Write other records
+       my $familyheadershown = 0;
+       foreach my $key (@keylist) {
+               if ( $keysinkeylist{$key} ) { next; }
+               if ( !$familyheadershown )  {
+                       my $p = '&nbsp;';
+                       if ($total_h) {
+                               $p =
+                                 int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
+                                 10;
+                               $p = "$p %";
+                       }
+                       print
+"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
+                       print "<td><b>"
+                         . Format_Number(( $total_h - $TotalFamily ))
+                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
+                       print "</tr>\n";
+                       $familyheadershown = 1;
+               }
+               my $p = '&nbsp;';
+               if ($total_h) {
+                       $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               print "<tr>";
+               if ( $key eq 'Unknown' ) {
+                       print "<td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
+               }
+               else {
+                       my $keywithoutcumul = $key;
+                       $keywithoutcumul =~ s/cumul$//i;
+                       my $libos = $OSHashLib{$keywithoutcumul}
+                         || $keywithoutcumul;
+                       my $nameicon = $keywithoutcumul;
+                       $nameicon =~ s/[^\w]//g;
+                       print "<td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/os\/$nameicon.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\">$libos</td>";
+               }
+               my $bredde_h = 0;
+               if ( $max_h > 0 ) {
+                       $bredde_h =
+                         int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h ) + 1;
+               }
+               if ( ( $bredde_h == 1 ) && $_os_h{$key} ) { $bredde_h = 2; }
+               print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
+               print "<td class=\"aws\">";
+
+               # alt and title are not provided to reduce page size
+               if ($ShowOSStats) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+               }
+               print "</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
+}
+
+#------------------------------------------------------------------------------
+# Function:     Prints the Unkown OS Detail frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowOSUnknown{
+       print "$Center<a name=\"unknownos\">&nbsp;</a><br />\n";
+       my $title = "$Message[46]";
+       &tab_head( "$title", 19, 0, 'unknownos' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
+         . ( scalar keys %_unknownreferer_l )
+         . ")</th><th>$Message[9]</th></tr>\n";
+       my $total_l = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownreferer_l,
+               \%_unknownreferer_l );
+       foreach my $key (@keylist) {
+               my $useragent = XMLEncode( CleanXSS($key) );
+               print "<tr><td class=\"aws\">$useragent</td>";
+               print "<td nowrap=\"nowrap\">"
+                 . Format_Date( $_unknownreferer_l{$key}, 1 ) . "</td>";
+               print "</tr>\n";
+               $total_l += 1;
+               $count++;
+       }
+       my $rest_l = ( scalar keys %_unknownreferer_l ) - $total_l;
+       if ( $rest_l > 0 ) {
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td>-</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
+}
+
+#------------------------------------------------------------------------------
+# Function:     Prints the Referers frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowReferers{
+       print "$Center<a name=\"refererse\">&nbsp;</a><br />\n";
+       my $title = "$Message[40]";
+       &tab_head( "$title", 19, 0, 'refererse' );
        print
-"   web site, from the log file defined in AWStats config file, or build a HTML\n";
-       print "   report (-output option).\n";
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentSearchEngines)." $Message[122]</th>";
        print
-"  First, $PROG tries to read $PROG.virtualhostname.conf as the config file.\n";
-       print "  If not found, $PROG tries to read $PROG.conf, and finally the full path passed to -config=\n";
+"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
        print
-"  Note 1: Config files ($PROG.virtualhostname.conf or $PROG.conf) must be\n";
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       print "</tr>\n";
+       my $total_s = 0;
+       my $total_p = 0;
+       my $total_h = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $count = 0;
+       &BuildKeyList(
+               $MaxRowsInHTMLOutput,
+               $MinHit{'Refer'},
+               \%_se_referrals_h,
+               (
+                       ( scalar keys %_se_referrals_p )
+                       ? \%_se_referrals_p
+                       : \%_se_referrals_h
+               )
+       );    # before 5.4 only hits were recorded
+
+       foreach my $key (@keylist) {
+               my $newreferer = $SearchEnginesHashLib{$key} || CleanXSS($key);
+               my $p_p;
+               my $p_h;
+               if ($TotalSearchEnginesPages) {
+                       $p_p =
+                         int( $_se_referrals_p{$key} / $TotalSearchEnginesPages *
+                                 1000 ) / 10;
+               }
+               if ($TotalSearchEnginesHits) {
+                       $p_h =
+                         int( $_se_referrals_h{$key} / $TotalSearchEnginesHits *
+                                 1000 ) / 10;
+               }
+               print "<tr><td class=\"aws\">$newreferer</td>";
+               print "<td>"
+                 . (
+                       $_se_referrals_p{$key} ? $_se_referrals_p{$key} : '&nbsp;' )
+                 . "</td>";
+               print "<td>"
+                 . ( $_se_referrals_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
+               print "<td>".Format_Number($_se_referrals_h{$key})."</td>";
+               print "<td>$p_h %</td>";
+               print "</tr>\n";
+               $total_p += $_se_referrals_p{$key};
+               $total_h += $_se_referrals_h{$key};
+               $count++;
+       }
+       if ($Debug) {
+               debug(
+"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
+                       2
+               );
+       }
+       $rest_p = $TotalSearchEnginesPages - $total_p;
+       $rest_h = $TotalSearchEnginesHits - $total_h;
+       if ( $rest_p > 0 || $rest_h > 0 ) {
+               my $p_p;
+               my $p_h;
+               if ($TotalSearchEnginesPages) {
+                       $p_p =
+                         int( $rest_p / $TotalSearchEnginesPages * 1000 ) / 10;
+               }
+               if ($TotalSearchEnginesHits) {
+                       $p_h = int( $rest_h / $TotalSearchEnginesHits * 1000 ) / 10;
+               }
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
+               print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
+               print "<td>".Format_Number($rest_h)."</td>";
+               print "<td>$p_h %</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
+}
+
+#------------------------------------------------------------------------------
+# Function:     Prints the Referer Pages frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowRefererPages{
+       print "$Center<a name=\"refererpages\">&nbsp;</a><br />\n";
+       my $total_p = 0;
+       my $total_h = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+
+       # Show filter form
+       &HTMLShowFormFilter(
+               "refererpagesfilter",
+               $FilterIn{'refererpages'},
+               $FilterEx{'refererpages'}
+       );
+       my $title = "$Message[41]";
+       my $cpt   = 0;
+       $cpt = ( scalar keys %_pagesrefs_h );
+       &tab_head( "$title", 19, 0, 'refererpages' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
+       if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
+
+               if ( $FilterIn{'refererpages'} ) {
+                       print "$Message[79] <b>$FilterIn{'refererpages'}</b>";
+               }
+               if ( $FilterIn{'refererpages'} && $FilterEx{'refererpages'} ) {
+                       print " - ";
+               }
+               if ( $FilterEx{'refererpages'} ) {
+                       print
+                         "Exclude $Message[79] <b>$FilterEx{'refererpages'}</b>";
+               }
+               if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
+                       print ": ";
+               }
+               print "$cpt $Message[28]";
+
+               #if ($MonthRequired ne 'all') {
+               #       if ($HTMLOutput{'refererpages'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
+               #}
+       }
+       else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
+       print "</th>";
        print
-"   in /etc/awstats, /usr/local/etc/awstats, /etc or same directory than\n";
-       print "   awstats.pl script file.\n";
+"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
        print
-"  Note 2: If AWSTATS_FORCE_CONFIG environment variable is defined, AWStats will\n";
-       print
-"   use it as the \"config\" value, whatever is the value on command line or URL.\n";
-       print "   See AWStats documentation for all setup instrutions.\n";
-       print "\n";
-       print "Options to update statistics:\n";
-       print "  -update        to update statistics (default)\n";
-       print
-"  -showsteps     to add benchmark information every $NBOFLINESFORBENCHMARK lines processed\n";
-       print
-"  -showcorrupted to add output for each corrupted lines found, with reason\n";
-       print
-"  -showdropped   to add output for each dropped lines found, with reason\n";
-       print "  -showunknownorigin  to output referer when it can't be parsed\n";
-       print
-"  -showdirectorigin   to output log line when origin is a direct access\n";
-       print "  -updatefor=n   to stop the update process after parsing n lines\n";
-       print
-"  -LogFile=x     to change log to analyze whatever is 'LogFile' in config file\n";
-       print
-"  Be care to process log files in chronological order when updating statistics.\n";
-       print "\n";
-       print "Options to show statistics:\n";
-       print
-"  -output      to output main HTML report (no update made except with -update)\n";
-       print "  -output=x    to output other report pages where x is:\n";
-       print
-"               alldomains       to build page of all domains/countries\n";
-       print "               allhosts         to build page of all hosts\n";
-       print
-         "               lasthosts        to build page of last hits for hosts\n";
-       print
-         "               unknownip        to build page of all unresolved IP\n";
-       print
-"               allemails        to build page of all email senders (maillog)\n";
-       print
-"               lastemails       to build page of last email senders (maillog)\n";
-       print
-"               allemailr        to build page of all email receivers (maillog)\n";
-       print
-"               lastemailr       to build page of last email receivers (maillog)\n";
-       print "               alllogins        to build page of all logins used\n";
-       print
-         "               lastlogins       to build page of last hits for logins\n";
-       print
-"               allrobots        to build page of all robots/spider visits\n";
-       print
-         "               lastrobots       to build page of last hits for robots\n";
-       print "               urldetail        to list most often viewed pages \n";
-       print
-"               urldetail:filter to list most often viewed pages matching filter\n";
-       print "               urlentry         to list entry pages\n";
-       print
-         "               urlentry:filter  to list entry pages matching filter\n";
-       print "               urlexit          to list exit pages\n";
-       print
-         "               urlexit:filter   to list exit pages matching filter\n";
-       print
-"               osdetail         to build page with os detailed versions\n";
-       print
-"               browserdetail    to build page with browsers detailed versions\n";
-       print
-"               unknownbrowser   to list 'User Agents' with unknown browser\n";
-       print
-         "               unknownos        to list 'User Agents' with unknown OS\n";
-       print
-"               refererse        to build page of all refering search engines\n";
-       print
-         "               refererpages     to build page of all refering pages\n";
-
- #print "               referersites     to build page of all refering sites\n";
-       print
-"               keyphrases       to list all keyphrases used on search engines\n";
-       print
-"               keywords         to list all keywords used on search engines\n";
-       print "               errors404        to list 'Referers' for 404 errors\n";
-       print
-"               allextraX        to build page of all values for ExtraSection X\n";
-       print "  -staticlinks           to have static links in HTML report page\n";
-       print "  -staticlinksext=xxx    to have static links with .xxx extension instead of .html\n";
-       print
-"  -lang=LL     to output a HTML report in language LL (en,de,es,fr,it,nl,...)\n";
-       print "  -month=MM    to output a HTML report for an old month MM\n";
-       print "  -year=YYYY   to output a HTML report for an old year YYYY\n";
-       print
-"  The 'date' options doesn't allow you to process old log file. They only\n";
-       print
-"  allow you to see a past report for a chosen month/year period instead of\n";
-       print "  current month/year.\n";
-       print "\n";
-       print "Other options:\n";
-       print
-"  -debug=X     to add debug informations lesser than level X (speed reduced)\n";
-       print "\n";
-       print "Now supports/detects:\n";
-       print
-"  Web/Ftp/Mail/streaming server log analyzis (and load balanced log files)\n";
-       print "  Reverse DNS lookup (IPv4 and IPv6) and GeoIP lookup\n";
-       print "  Number of visits, number of unique visitors\n";
-       print "  Visits duration and list of last visits\n";
-       print "  Authenticated users\n";
-       print "  Days of week and rush hours\n";
-       print "  Hosts list and unresolved IP addresses list\n";
-       print "  Most viewed, entry and exit pages\n";
-       print "  Files type and Web compression (mod_gzip, mod_deflate stats)\n";
-       print "  Screen size\n";
-       print "  Ratio of Browsers with support of: Java, Flash, RealG2 reader,\n";
-       print "                        Quicktime reader, WMA reader, PDF reader\n";
-       print "  Configurable personalized reports\n";
-       print "  " . ( scalar keys %DomainsHashIDLib ) . " domains/countries\n";
-       print "  " . ( scalar keys %RobotsHashIDLib ) . " robots\n";
-       print "  " . ( scalar keys %WormsHashLib ) . " worm's families\n";
-       print "  " . ( scalar keys %OSHashLib ) . " operating systems\n";
-       print "  " . ( scalar keys %BrowsersHashIDLib ) . " browsers";
-       &Read_Ref_Data('browsers_phone');
-       print " ("
-         . ( scalar keys %BrowsersHashIDLib )
-         . " with phone browsers database)\n";
-       print "  "
-         . ( scalar keys %SearchEnginesHashLib )
-         . " search engines (and keyphrases/keywords used from them)\n";
-       print "  All HTTP errors with last referrer\n";
-       print "  Report by day/month/year\n";
-       print "  Dynamic or static HTML or XHTML reports, static PDF reports\n";
-       print "  Indexed text or XML monthly database\n";
-       print "  And a lot of other advanced features and options...\n";
-       print "New versions and FAQ at http://awstats.sourceforge.net\n";
-       exit 2;
-}
-$SiteConfig ||= &Sanitize( $ENV{'SERVER_NAME'} );
-
-#$ENV{'SERVER_NAME'}||=$SiteConfig;    # For thoose who use __SERVER_NAME__ in conf file and use CLI.
-$ENV{'AWSTATS_CURRENT_CONFIG'} = $SiteConfig;
-
-# Read config file (SiteConfig must be defined)
-&Read_Config($DirConfig);
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       print "</tr>\n";
+       my $total_s = 0;
+       my $count = 0;
+       &BuildKeyList(
+               $MaxRowsInHTMLOutput,
+               $MinHit{'Refer'},
+               \%_pagesrefs_h,
+               (
+                       ( scalar keys %_pagesrefs_p )
+                       ? \%_pagesrefs_p
+                       : \%_pagesrefs_h
+               )
+       );
 
-# Check language
-if ( $QueryString =~ /(^|&|&amp;)lang=([^&]+)/i ) { $Lang = "$2"; }
-if ( !$Lang || $Lang eq 'auto' ) {    # If lang not defined or forced to auto
-       my $langlist = $ENV{'HTTP_ACCEPT_LANGUAGE'} || '';
-       $langlist =~ s/;[^,]*//g;
+       foreach my $key (@keylist) {
+               my $nompage = CleanXSS($key);
+               if ( length($nompage) > $MaxLengthOfShownURL ) {
+                       $nompage =
+                         substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
+               }
+               my $p_p;
+               my $p_h;
+               if ($TotalRefererPages) {
+                       $p_p =
+                         int( $_pagesrefs_p{$key} / $TotalRefererPages * 1000 ) /
+                         10;
+               }
+               if ($TotalRefererHits) {
+                       $p_h =
+                         int( $_pagesrefs_h{$key} / $TotalRefererHits * 1000 ) /
+                         10;
+               }
+               print "<tr><td class=\"aws\">";
+               &HTMLShowURLInfo($key);
+               print "</td>";
+               print "<td>"
+                 . ( $_pagesrefs_p{$key} ? Format_Number($_pagesrefs_p{$key}) : '&nbsp;' )
+                 . "</td><td>"
+                 . ( $_pagesrefs_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
+               print "<td>"
+                 . ( $_pagesrefs_h{$key} ? Format_Number($_pagesrefs_h{$key}) : '&nbsp;' )
+                 . "</td><td>"
+                 . ( $_pagesrefs_h{$key} ? "$p_h %" : '&nbsp;' ) . "</td>";
+               print "</tr>\n";
+               $total_p += $_pagesrefs_p{$key};
+               $total_h += $_pagesrefs_h{$key};
+               $count++;
+       }
        if ($Debug) {
                debug(
-                       "Search an available language among HTTP_ACCEPT_LANGUAGE=$langlist",
-                       1
+"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
+                       2
                );
        }
-       foreach my $code ( split( /,/, $langlist ) )
-       {                                 # Search for a valid lang in priority
-               if ( $LangBrowserToLangAwstats{$code} ) {
-                       $Lang = $LangBrowserToLangAwstats{$code};
-                       if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
-                       last;
+       $rest_p = $TotalRefererPages - $total_p;
+       $rest_h = $TotalRefererHits - $total_h;
+       if ( $rest_p > 0 || $rest_h > 0 ) {
+               my $p_p;
+               my $p_h;
+               if ($TotalRefererPages) {
+                       $p_p = int( $rest_p / $TotalRefererPages * 1000 ) / 10;
                }
-               $code =~ s/-.*$//;
-               if ( $LangBrowserToLangAwstats{$code} ) {
-                       $Lang = $LangBrowserToLangAwstats{$code};
-                       if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
-                       last;
+               if ($TotalRefererHits) {
+                       $p_h = int( $rest_h / $TotalRefererHits * 1000 ) / 10;
                }
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
+               print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
+               print "<td>".Format_Number($rest_h)."</td>";
+               print "<td>$p_h %</td>";
+               print "</tr>\n";
        }
+       &tab_end();
+       &html_end(1);
 }
-if ( !$Lang || $Lang eq 'auto' ) {
+
+#------------------------------------------------------------------------------
+# Function:     Prints the Key Phrases frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowKeyPhrases{
+       print "$Center<a name=\"keyphrases\">&nbsp;</a><br />\n";
+       &tab_head( $Message[43], 19, 0, 'keyphrases' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+         . Tooltip(15)
+         . "><th>".Format_Number($TotalDifferentKeyphrases)." $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
+       my $total_s = 0;
+       my $count = 0;
+       &BuildKeyList(
+               $MaxRowsInHTMLOutput, $MinHit{'Keyphrase'},
+               \%_keyphrases,        \%_keyphrases
+       );
+       foreach my $key (@keylist) {
+               my $mot;
+               # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
+               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
+                       $mot = CleanXSS(
+                               DecodeKey_decodeutfkeys(
+                                       $key, $PageCode || 'iso-8859-1'
+                               )
+                       );
+               }
+               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
+               my $p;
+               if ($TotalKeyphrases) {
+                       $p =
+                         int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
+               }
+               print "<tr><td class=\"aws\">"
+                 . XMLEncode($mot)
+                 . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
+               $total_s += $_keyphrases{$key};
+               $count++;
+       }
        if ($Debug) {
-               debug( " No language defined or available. Will use Lang=en", 1 );
+               debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
        }
-       $Lang = 'en';
+       my $rest_s = $TotalKeyphrases - $total_s;
+       if ( $rest_s > 0 ) {
+               my $p;
+               if ($TotalKeyphrases) {
+                       $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
+               }
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>".Format_Number($rest_s)."</td>";
+                               print "<td>$p %</td></tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
 }
 
-# Check and correct bad parameters
-&Check_Config();
-
-# Now SiteDomain is defined
-
-if ( $Debug && !$DebugMessages ) {
-       error(
-"Debug has not been allowed. Change DebugMessages parameter in config file to allow debug."
-       );
+#------------------------------------------------------------------------------
+# Function:     Prints the Keywords frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowKeywords{
+       print "$Center<a name=\"keywords\">&nbsp;</a><br />\n";
+       &tab_head( $Message[44], 19, 0, 'keywords' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+         . Tooltip(15)
+         . "><th>".Format_Number($TotalDifferentKeywords)." $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
+       my $total_s = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Keyword'},
+               \%_keywords, \%_keywords );
+       foreach my $key (@keylist) {
+               my $mot;
+               # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
+               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
+                       $mot = CleanXSS(
+                               DecodeKey_decodeutfkeys(
+                                       $key, $PageCode || 'iso-8859-1'
+                               )
+                       );
+               }
+               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
+               my $p;
+               if ($TotalKeywords) {
+                       $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
+               }
+               print "<tr><td class=\"aws\">"
+                 . XMLEncode($mot)
+                 . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
+               $total_s += $_keywords{$key};
+               $count++;
+       }
+       if ($Debug) {
+               debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
+       }
+       my $rest_s = $TotalKeywords - $total_s;
+       if ( $rest_s > 0 ) {
+               my $p;
+               if ($TotalKeywords) {
+                       $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
+               }
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>".Format_Number($rest_s)."</td>";
+               print "<td>$p %</td></tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
 }
 
-# Define frame name and correct variable for frames
-if ( !$FrameName ) {
-       if (   $ENV{'GATEWAY_INTERFACE'}
-               && $UseFramesWhenCGI
-               && $HTMLOutput{'main'}
-               && !$PluginMode )
-       {
-               $FrameName = 'index';
+#------------------------------------------------------------------------------
+# Function:     Prints the HTTP Error code frame or static page
+# Parameters:   $code - the error code we're printing
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowErrorCodes{
+       my $code = shift;
+       print "$Center<a name=\"errors$code\">&nbsp;</a><br />\n";
+       &tab_head( $Message[47], 19, 0, "errors$code" );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>URL ("
+         . Format_Number(( scalar keys %_sider404_h ))
+         . ")</th><th bgcolor=\"#$color_h\">$Message[49]</th><th>$Message[23]</th></tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_sider404_h,
+               \%_sider404_h );
+       foreach my $key (@keylist) {
+               my $nompage = XMLEncode( CleanXSS($key) );
+
+               #if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
+               my $referer = XMLEncode( CleanXSS( $_referer404_h{$key} ) );
+               print "<tr><td class=\"aws\">$nompage</td>";
+               print "<td>".Format_Number($_sider404_h{$key})."</td>";
+               print "<td class=\"aws\">"
+                 . ( $referer ? "$referer" : "&nbsp;" ) . "</td>";
+               print "</tr>\n";
+               my $total_s += $_sider404_h{$key};
+               $count++;
        }
-       else { $FrameName = 'main'; }
+
+# TODO Build TotalErrorHits
+#                      if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
+#                      $rest_h=$TotalErrorHits-$total_h;
+#                      if ($rest_h > 0) {
+#                              my $p;
+#                              if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
+#                              print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td>";
+#                              print "<td>$rest_h</td>";
+#                              print "<td>...</td>";
+#                              print "</tr>\n";
+#                      }
+       &tab_end();
+       &html_end(1);
 }
 
-# Load Message files, Reference data files and Plugins
-if ($Debug) { debug( "FrameName=$FrameName", 1 ); }
-if ( $FrameName ne 'index' ) {
-       &Read_Language_Data($Lang);
-       if ( $FrameName ne 'mainleft' ) {
-               my %datatoload = ();
-               my (
-                       $filedomains, $filemime, $filerobots, $fileworms,
-                       $filebrowser, $fileos,   $filese
-                 )
-                 = (
-                       'domains',  'mime',
-                       'robots',   'worms',
-                       'browsers', 'operating_systems',
-                       'search_engines'
-                 );
-               my ( $filestatushttp, $filestatussmtp ) =
-                 ( 'status_http', 'status_smtp' );
-               if ( $LevelForBrowsersDetection eq 'allphones' ) {
-                       $filebrowser = 'browsers_phone';
-               }
-               if ($UpdateStats) {    # If update
-                       if ( $LevelForFileTypesDetection < 2 ) {
-                               $datatoload{$filemime} = 1;
-                       }                  # Only if need to filter on known extensions
-                       if ($LevelForRobotsDetection) {
-                               $datatoload{$filerobots} = 1;
-                       }                  # ua
-                       if ($LevelForWormsDetection) {
-                               $datatoload{$fileworms} = 1;
-                       }                  # url
-                       if ($LevelForBrowsersDetection) {
-                               $datatoload{$filebrowser} = 1;
-                       }                  # ua
-                       if ($LevelForOSDetection) {
-                               $datatoload{$fileos} = 1;
-                       }                  # ua
-                       if ($LevelForRefererAnalyze) {
-                               $datatoload{$filese} = 1;
-                       }                  # referer
-                                          # if (...) { $datatoload{'referer_spam'}=1; }
-               }
-               if ( scalar keys %HTMLOutput ) {    # If output
-                       if ( $ShowDomainsStats || $ShowHostsStats ) {
-                               $datatoload{$filedomains} = 1;
-                       } # TODO Replace by test if ($ShowDomainsStats) when plugins geoip can force load of domains datafile.
-                       if ($ShowFileTypesStats)  { $datatoload{$filemime}       = 1; }
-                       if ($ShowRobotsStats)     { $datatoload{$filerobots}     = 1; }
-                       if ($ShowWormsStats)      { $datatoload{$fileworms}      = 1; }
-                       if ($ShowBrowsersStats)   { $datatoload{$filebrowser}    = 1; }
-                       if ($ShowOSStats)         { $datatoload{$fileos}         = 1; }
-                       if ($ShowOriginStats)     { $datatoload{$filese}         = 1; }
-                       if ($ShowHTTPErrorsStats) { $datatoload{$filestatushttp} = 1; }
-                       if ($ShowSMTPErrorsStats) { $datatoload{$filestatussmtp} = 1; }
-               }
-               &Read_Ref_Data( keys %datatoload );
-       }
-       &Read_Plugins();
-}
+#------------------------------------------------------------------------------
+# Function:     Loops through any defined extra sections and dumps the info to HTML
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowExtraSections{
+       foreach my $extranum ( 1 .. @ExtraName - 1 ) {
+               my $total_p = 0;
+               my $total_h = 0;
+               my $total_k = 0;
+               
+               if ( $HTMLOutput{"allextra$extranum"} ) {
+                       if ($Debug) { debug( "ExtraName$extranum", 2 ); }
+                       print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
+                       my $title = $ExtraName[$extranum];
+                       &tab_head( "$title", 19, 0, "extra$extranum" );
+                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+                       print "<th>" . $ExtraFirstColumnTitle[$extranum] . "</th>";
 
-# Here charset is defined, so we can send the http header (Need BuildReportFormat,PageCode)
-if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
-       http_head();
-}    # Run from a browser as CGI
+                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                               print
+"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
+                       }
+                       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                               print
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+                       }
+                       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+                       }
+                       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                               print "<th width=\"120\">$Message[9]</th>";
+                       }
+                       print "</tr>\n";
+                       $total_p = $total_h = $total_k = 0;
 
-# Init other parameters
-$NBOFLINESFORBENCHMARK--;
-if ( $ENV{'GATEWAY_INTERFACE'} ) { $DirCgi = ''; }
-if ( $DirCgi && !( $DirCgi =~ /\/$/ ) && !( $DirCgi =~ /\\$/ ) ) {
-       $DirCgi .= '/';
-}
-if ( !$DirData || $DirData =~ /^\./ ) {
-       if ( !$DirData || $DirData eq '.' ) {
-               $DirData = "$DIR";
-       }    # If not defined or chosen to '.' value then DirData is current dir
-       elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
-}
-$DirData ||= '.';    # If current dir not defined then we put it to '.'
-$DirData =~ s/[\\\/]+$//;
+ #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
+ #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
+                       my $count = 0;
+                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                               &BuildKeyList(
+                                       $MaxRowsInHTMLOutput,
+                                       $MinHitExtra[$extranum],
+                                       \%{ '_section_' . $extranum . '_h' },
+                                       \%{ '_section_' . $extranum . '_p' }
+                               );
+                       }
+                       else {
+                               &BuildKeyList(
+                                       $MaxRowsInHTMLOutput,
+                                       $MinHitExtra[$extranum],
+                                       \%{ '_section_' . $extranum . '_h' },
+                                       \%{ '_section_' . $extranum . '_h' }
+                               );
+                       }
+                       my %keysinkeylist = ();
+                       foreach my $key (@keylist) {
+                               $keysinkeylist{$key} = 1;
+                               my $firstcol = CleanXSS( DecodeEncodedString($key) );
+                               $total_p += ${ '_section_' . $extranum . '_p' }{$key};
+                               $total_h += ${ '_section_' . $extranum . '_h' }{$key};
+                               $total_k += ${ '_section_' . $extranum . '_k' }{$key};
+                               print "<tr>";
+                               printf(
+"<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
+                                       $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
+                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                                       print "<td>"
+                                         . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                                       print "<td>"
+                                         . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                                       print "<td>"
+                                         . Format_Bytes(
+                                               ${ '_section_' . $extranum . '_k' }{$key} )
+                                         . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                                       print "<td>"
+                                         . (
+                                               ${ '_section_' . $extranum . '_l' }{$key}
+                                               ? Format_Date(
+                                                       ${ '_section_' . $extranum . '_l' }{$key}, 1 )
+                                               : '-'
+                                         )
+                                         . "</td>";
+                               }
+                               print "</tr>\n";
+                               $count++;
+                       }
 
-if ( $FirstDayOfWeek == 1 ) { @DOWIndex = ( 1, 2, 3, 4, 5, 6, 0 ); }
-else { @DOWIndex = ( 0, 1, 2, 3, 4, 5, 6 ); }
+                       # If we ask average or sum, we loop on all other records
+                       if (   $ExtraAddAverageRow[$extranum]
+                               || $ExtraAddSumRow[$extranum] )
+                       {
+                               foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
+                                       if ( $keysinkeylist{$_} ) { next; }
+                                       $total_p += ${ '_section_' . $extranum . '_p' }{$_};
+                                       $total_h += ${ '_section_' . $extranum . '_h' }{$_};
+                                       $total_k += ${ '_section_' . $extranum . '_k' }{$_};
+                                       $count++;
+                               }
+                       }
 
-# Should we link to ourselves or to a wrapper script
-$AWScript = ( $WrapperScript ? "$WrapperScript" : "$DirCgi$PROG.$Extension" );
+                       # Add average row
+                       if ( $ExtraAddAverageRow[$extranum] ) {
+                               print "<tr>";
+                               print "<td class=\"aws\"><b>$Message[96]</b></td>";
+                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                                       print "<td>"
+                                         . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" )
+                                         . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                                       print "<td>"
+                                         . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" )
+                                         . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                                       print "<td>"
+                                         . (
+                                               $count
+                                               ? Format_Bytes( $total_k / $count )
+                                               : "&nbsp;"
+                                         )
+                                         . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                                       print "<td>&nbsp;</td>";
+                               }
+                               print "</tr>\n";
+                       }
 
-# Print html header (Need HTMLOutput,Expires,Lang,StyleSheet,HTMLHeadSectionExpires defined by Read_Config, PageCode defined by Read_Language_Data)
-if ( !$HeaderHTMLSent ) { &html_head; }
+                       # Add sum row
+                       if ( $ExtraAddSumRow[$extranum] ) {
+                               print "<tr>";
+                               print "<td class=\"aws\"><b>$Message[102]</b></td>";
+                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                                       print "<td>" . ($total_p) . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                                       print "<td>" . ($total_h) . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                                       print "<td>" . Format_Bytes($total_k) . "</td>";
+                               }
+                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                                       print "<td>&nbsp;</td>";
+                               }
+                               print "</tr>\n";
+                       }
+                       &tab_end();
+                       &html_end(1);
+               }
+       }
+}
 
-# AWStats output is replaced by a plugin output
-if ($PluginMode) {
+#------------------------------------------------------------------------------
+# Function:     Prints the Robot details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowRobots{
+       my $total_p = 0;
+       my $total_h = 0;
+       my $total_k = 0;
+       my $total_r = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $rest_k = 0;
+       my $rest_r = 0;
+       
+       print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
+       my $title = '';
+       if ( $HTMLOutput{'allrobots'} )  { $title .= "$Message[53]"; }
+       if ( $HTMLOutput{'lastrobots'} ) { $title .= "$Message[9]"; }
+       &tab_head( "$title", 19, 0, 'robots' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
+         . Format_Number(( scalar keys %_robot_h ))
+         . " $Message[51]</th>";
+       if ( $ShowRobotsStats =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+       }
+       if ( $ShowRobotsStats =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ShowRobotsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       $total_p = $total_h = $total_k = $total_r = 0;
+       my $count = 0;
+       if ( $HTMLOutput{'allrobots'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
+                       \%_robot_h, \%_robot_h );
+       }
+       if ( $HTMLOutput{'lastrobots'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
+                       \%_robot_h, \%_robot_l );
+       }
+       foreach my $key (@keylist) {
+               print "<tr><td class=\"aws\">"
+                 . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
+                 . "</td>";
+               if ( $ShowRobotsStats =~ /H/i ) {
+                       print "<td>"
+                         . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
+                         . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_robot_l{$key}
+                               ? Format_Date( $_robot_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
 
-       #       my $function="BuildFullHTMLOutput_$PluginMode()";
-       #       eval("$function");
-       my $function = "BuildFullHTMLOutput_$PluginMode";
-       &$function();
-       if ( $? || $@ ) { error("$@"); }
-       &html_end(0);
-       exit 0;
-}
+               #$total_p += $_robot_p{$key}||0;
+               $total_h += $_robot_h{$key};
+               $total_k += $_robot_k{$key} || 0;
+               $total_r += $_robot_r{$key} || 0;
+               $count++;
+       }
 
-# Security check
-if ( $AllowAccessFromWebToAuthenticatedUsersOnly && $ENV{'GATEWAY_INTERFACE'} )
-{
-       if ($Debug) { debug( "REMOTE_USER=" . $ENV{"REMOTE_USER"} ); }
-       if ( !$ENV{"REMOTE_USER"} ) {
-               error(
-"Access to statistics is only allowed from an authenticated session to authenticated users."
+       # For bots we need to count Totals
+       my $TotalPagesRobots =
+         0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
+       my $TotalHitsRobots = 0;
+       foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
+       my $TotalBytesRobots = 0;
+       foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
+       my $TotalRRobots = 0;
+       foreach ( values %_robot_r ) { $TotalRRobots += $_; }
+       $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
+       $rest_h = $TotalHitsRobots - $total_h;
+       $rest_k = $TotalBytesRobots - $total_k;
+       $rest_r = $TotalRRobots - $total_r;
+
+       if ($Debug) {
+               debug(
+"Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",
+                       2
                );
        }
-       if (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
-               my $userisinlist = 0;
-               my $remoteuser   = quotemeta( $ENV{"REMOTE_USER"} );
-               $remoteuser =~ s/\s/%20/g
-                 ; # Allow authenticated user with space in name to be compared to allowed user list
-               my $currentuser = qr/^$remoteuser$/i;    # Set precompiled regex
-               foreach (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
-                       if (/$currentuser/o) { $userisinlist = 1; last; }
-               }
-               if ( !$userisinlist ) {
-                       error(  "User '"
-                                 . $ENV{"REMOTE_USER"}
-                                 . "' is not allowed to access statistics of this domain/config."
-                       );
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
+       {               # All other robots
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowRobotsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
+               if ( $ShowRobotsStats =~ /B/i ) {
+                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
                }
+               if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
        }
+       &tab_end(
+               "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
+       &html_end(1);
 }
-if ( $AllowAccessFromWebToFollowingIPAddresses && $ENV{'GATEWAY_INTERFACE'} ) {
-       my $IPAddress     = $ENV{"REMOTE_ADDR"};                  # IPv4 or IPv6
-       my $useripaddress = &Convert_IP_To_Decimal($IPAddress);
-       my @allowaccessfromipaddresses =
-         split( /[\s,]+/, $AllowAccessFromWebToFollowingIPAddresses );
-       my $allowaccess = 0;
-       foreach my $ipaddressrange (@allowaccessfromipaddresses) {
-               if ( $ipaddressrange !~
-                       /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/
-                       && $ipaddressrange !~
-                       /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
-               {
-                       error(
-"AllowAccessFromWebToFollowingIPAddresses is defined to '$AllowAccessFromWebToFollowingIPAddresses' but part of value does not match the correct syntax: IPv4AddressMin[-IPv4AddressMax] or IPv6Address[\/prefix] in \"$ipaddressrange\""
-                       );
-               }
 
-               # Test ip v4
-               if ( $ipaddressrange =~
-                       /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/ )
-               {
-                       my $ipmin = &Convert_IP_To_Decimal($1);
-                       my $ipmax = $2 ? &Convert_IP_To_Decimal($2) : $ipmin;
+#------------------------------------------------------------------------------
+# Function:     Prints the URL, Entry or Exit details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowURLDetail{
+       my $total_p = 0;
+       my $total_e = 0;
+       my $total_k = 0;
+       my $total_x = 0;
+       # Call to plugins' function ShowPagesFilter
+       foreach
+         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
+       {
+               my $function = "ShowPagesFilter_$pluginname";
+               &$function();
+       }
+       print "$Center<a name=\"urls\">&nbsp;</a><br />\n";
 
-                       # Is it an authorized ip ?
-                       if ( ( $useripaddress >= $ipmin ) && ( $useripaddress <= $ipmax ) )
-                       {
-                               $allowaccess = 1;
-                               last;
+       # Show filter form
+       &HTMLShowFormFilter( "urlfilter", $FilterIn{'url'}, $FilterEx{'url'} );
+
+       # Show URL list
+       my $title = '';
+       my $cpt   = 0;
+       if ( $HTMLOutput{'urldetail'} ) {
+               $title = $Message[19];
+               $cpt   = ( scalar keys %_url_p );
+       }
+       if ( $HTMLOutput{'urlentry'} ) {
+               $title = $Message[104];
+               $cpt   = ( scalar keys %_url_e );
+       }
+       if ( $HTMLOutput{'urlexit'} ) {
+               $title = $Message[116];
+               $cpt   = ( scalar keys %_url_x );
+       }
+       &tab_head( "$title", 19, 0, 'urls' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
+       if ( $FilterIn{'url'} || $FilterEx{'url'} ) {
+               if ( $FilterIn{'url'} ) {
+                       print "$Message[79] <b>$FilterIn{'url'}</b>";
+               }
+               if ( $FilterIn{'url'} && $FilterEx{'url'} ) { print " - "; }
+               if ( $FilterEx{'url'} ) {
+                       print "Exclude $Message[79] <b>$FilterEx{'url'}</b>";
+               }
+               if ( $FilterIn{'url'} || $FilterEx{'url'} ) { print ": "; }
+               print Format_Number($cpt)." $Message[28]";
+               if ( $MonthRequired ne 'all' ) {
+                       if ( $HTMLOutput{'urldetail'} ) {
+                               print
+"<br />$Message[102]: ".Format_Number($TotalDifferentPages)." $Message[28]";
                        }
                }
+       }
+       else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
+       print "</th>";
+       if ( $ShowPagesStats =~ /P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
+       }
+       if ( $ShowPagesStats =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
+       }
+       if ( $ShowPagesStats =~ /E/i ) {
+               print
+                 "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
+       }
+       if ( $ShowPagesStats =~ /X/i ) {
+               print
+                 "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
+       }
 
-               # Test ip v6
-               if ( $ipaddressrange =~
-                       /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
-               {
-                       if ( $ipaddressrange =~ /::\// ) {
-                               my @IPv6split = split( /::/, $ipaddressrange );
-                               if ( $IPAddress =~ /^$IPv6split[0]/ ) {
-                                       $allowaccess = 1;
-                                       last;
-                               }
-                       }
-                       elsif ( $ipaddressrange == $IPAddress ) {
-                               $allowaccess = 1;
-                               last;
-                       }
+       # Call to plugins' function ShowPagesAddField
+       foreach
+         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+       {
+
+               #                       my $function="ShowPagesAddField_$pluginname('title')";
+               #                       eval("$function");
+               my $function = "ShowPagesAddField_$pluginname";
+               &$function('title');
+       }
+       print "<th>&nbsp;</th></tr>\n";
+       $total_p = $total_k = $total_e = $total_x = 0;
+       my $count = 0;
+       if ( $HTMLOutput{'urlentry'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_e,
+                       \%_url_e );
+       }
+       elsif ( $HTMLOutput{'urlexit'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_x,
+                       \%_url_x );
+       }
+       else {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_p,
+                       \%_url_p );
+       }
+       my $max_p = 1;
+       my $max_k = 1;
+       foreach my $key (@keylist) {
+               if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
+               if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
+                       $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
                }
        }
-       if ( !$allowaccess ) {
-               error( "Access to statistics is not allowed from your IP Address "
-                         . $ENV{"REMOTE_ADDR"} );
+       foreach my $key (@keylist) {
+               print "<tr><td class=\"aws\">";
+               &HTMLShowURLInfo($key);
+               print "</td>";
+               my $bredde_p = 0;
+               my $bredde_e = 0;
+               my $bredde_x = 0;
+               my $bredde_k = 0;
+               if ( $max_p > 0 ) {
+                       $bredde_p =
+                         int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
+               if ( $max_p > 0 ) {
+                       $bredde_e =
+                         int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
+               if ( $max_p > 0 ) {
+                       $bredde_x =
+                         int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
+               if ( $max_k > 0 ) {
+                       $bredde_k =
+                         int( $BarWidth *
+                                 ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
+                                 $max_k ) + 1;
+               }
+               if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
+               if ( $ShowPagesStats =~ /P/i ) {
+                       print "<td>".Format_Number($_url_p{$key})."</td>";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print "<td>"
+                         . (
+                               $_url_k{$key}
+                               ? Format_Bytes(
+                                       $_url_k{$key} / ( $_url_p{$key} || 1 )
+                                 )
+                               : "&nbsp;"
+                         )
+                         . "</td>";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print "<td>"
+                         . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print "<td>"
+                         . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
+               }
+
+               # Call to plugins' function ShowPagesAddField
+               foreach my $pluginname (
+                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+               {
+
+                 #                             my $function="ShowPagesAddField_$pluginname('$key')";
+                 #                             eval("$function");
+                       my $function = "ShowPagesAddField_$pluginname";
+                       &$function($key);
+               }
+               print "<td class=\"aws\">";
+
+               # alt and title are not provided to reduce page size
+               if ( $ShowPagesStats =~ /P/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\" /><br />";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\" />";
+               }
+               print "</td></tr>\n";
+               $total_p += $_url_p{$key};
+               $total_e += $_url_e{$key};
+               $total_x += $_url_x{$key};
+               $total_k += $_url_k{$key};
+               $count++;
        }
-}
-if (   ( $UpdateStats || $MigrateStats )
-       && ( !$AllowToUpdateStatsFromBrowser )
-       && $ENV{'GATEWAY_INTERFACE'} )
-{
-       error(  ""
-                 . ( $UpdateStats ? "Update" : "Migrate" )
-                 . " of statistics has not been allowed from a browser (AllowToUpdateStatsFromBrowser should be set to 1)."
-       );
-}
-if ( scalar keys %HTMLOutput && $MonthRequired eq 'all' ) {
-       if ( !$AllowFullYearView ) {
-               error(
-"Full year view has not been allowed (AllowFullYearView is set to 0)."
+       if ($Debug) {
+               debug(
+"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
+                       2
                );
        }
-       if ( $AllowFullYearView < 3 && $ENV{'GATEWAY_INTERFACE'} ) {
-               error(
-"Full year view has not been allowed from a browser (AllowFullYearView should be set to 3)."
-               );
+       my $rest_p = $TotalPages - $total_p;
+       my $rest_k = $TotalBytesPages - $total_k;
+       my $rest_e = $TotalEntries - $total_e;
+       my $rest_x = $TotalExits - $total_x;
+       if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowPagesStats =~ /P/i ) {
+                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print "<td>"
+                         . (
+                               $rest_k
+                               ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
+                               : "&nbsp;"
+                         )
+                         . "</td>";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
+               }
+
+               # Call to plugins' function ShowPagesAddField
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+               {
+                       my $function = "ShowPagesAddField_$pluginname";
+                       &$function('');
+               }
+               print "<td>&nbsp;</td></tr>\n";
        }
+       &tab_end();
+       &html_end(1);
 }
 
-#------------------------------------------
-# MIGRATE PROCESS (Must be after reading config cause we need MaxNbOf... and Min...)
-#------------------------------------------
-if ($MigrateStats) {
-       if ($Debug) { debug( "MigrateStats is $MigrateStats", 2 ); }
-       if ( $MigrateStats !~
-               /^(.*)$PROG(\d\d)(\d\d\d\d)(\d{0,2})(\d{0,2})(.*)\.txt$/ )
-       {
-               error(
-"AWStats history file name must match following syntax: ${PROG}MMYYYY[.config].txt",
-                       "", "", 1
-               );
+#------------------------------------------------------------------------------
+# Function:     Prints the Login details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowLogins{
+       my $total_p = 0;
+       my $total_h = 0;
+       my $total_k = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $rest_k = 0;
+       print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
+       my $title = '';
+       if ( $HTMLOutput{'alllogins'} )  { $title .= "$Message[94]"; }
+       if ( $HTMLOutput{'lastlogins'} ) { $title .= "$Message[9]"; }
+       &tab_head( "$title", 19, 0, 'logins' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
+         . Format_Number(( scalar keys %_login_h )) . "</th>";
+       &HTMLShowUserInfo('__title__');
+       if ( $ShowAuthenticatedUsers =~ /P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
        }
-       $DirData       = "$1";
-       $MonthRequired = "$2";
-       $YearRequired  = "$3";
-       $DayRequired   = "$4";
-       $HourRequired  = "$5";
-       $FileSuffix    = "$6";
-
-       # Correct DirData
-       if ( !$DirData || $DirData =~ /^\./ ) {
-               if ( !$DirData || $DirData eq '.' ) {
-                       $DirData = "$DIR";
-               }    # If not defined or chosen to '.' value then DirData is current dir
-               elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
+       if ( $ShowAuthenticatedUsers =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
        }
-       $DirData ||= '.';    # If current dir not defined then we put it to '.'
-       $DirData =~ s/[\\\/]+$//;
-       print "Start migration for file '$MigrateStats'.";
-       print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
-       if ($EnableLockForUpdate) { &Lock_Update(1); }
-       my $newhistory =
-         &Read_History_With_TmpUpdate( $YearRequired, $MonthRequired, $DayRequired,
-               $HourRequired, 1, 0, 'all' );
-       if ( rename( "$newhistory", "$MigrateStats" ) == 0 ) {
-               unlink "$newhistory";
-               error(
-"Failed to rename \"$newhistory\" into \"$MigrateStats\".\nWrite permissions on \"$MigrateStats\" might be wrong"
+       if ( $ShowAuthenticatedUsers =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ShowAuthenticatedUsers =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       $total_p = $total_h = $total_k = 0;
+       my $count = 0;
+       if ( $HTMLOutput{'alllogins'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
+                       \%_login_h, \%_login_p );
+       }
+       if ( $HTMLOutput{'lastlogins'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
+                       \%_login_h, \%_login_l );
+       }
+       foreach my $key (@keylist) {
+               print "<tr><td class=\"aws\">$key</td>";
+               &HTMLShowUserInfo($key);
+               if ( $ShowAuthenticatedUsers =~ /P/i ) {
+                       print "<td>"
+                         . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
+                         . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /H/i ) {
+                       print "<td>".Format_Number($_login_h{$key})."</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /L/i ) {
+                       print "<td>"
                          . (
-                               $ENV{'GATEWAY_INTERFACE'} ? " for a 'migration from web'" : ""
+                               $_login_l{$key}
+                               ? Format_Date( $_login_l{$key}, 1 )
+                               : '-'
                          )
-                         . " or file might be opened."
+                         . "</td>";
+               }
+               print "</tr>\n";
+               $total_p += $_login_p{$key} || 0;
+               $total_h += $_login_h{$key};
+               $total_k += $_login_k{$key} || 0;
+               $count++;
+       }
+       if ($Debug) {
+               debug(
+"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
+                       2
                );
        }
-       if ($EnableLockForUpdate) { &Lock_Update(0); }
-       print "Migration for file '$MigrateStats' successful.";
-       print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
+       $rest_p = $TotalPages - $total_p;
+       $rest_h = $TotalHits - $total_h;
+       $rest_k = $TotalBytes - $total_k;
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
+       {    # All other logins and/or anonymous
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[125]</span></td>";
+               &HTMLShowUserInfo('');
+               if ( $ShowAuthenticatedUsers =~ /P/i ) {
+                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /H/i ) {
+                       print "<td>".Format_Number($rest_h)."</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /L/i ) {
+                       print "<td>&nbsp;</td>";
+               }
+               print "</tr>\n";
+       }
+       &tab_end();
        &html_end(1);
-       exit 0;
 }
 
-# Output main frame page and exit. This must be after the security check.
-if ( $FrameName eq 'index' ) {
-
-       # Define the NewLinkParams for main chart
-       my $NewLinkParams = ${QueryString};
-       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-       $NewLinkParams =~ s/^&amp;//;
-       $NewLinkParams =~ s/&amp;$//;
-       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
-
-       # Exit if main frame
-       print "<frameset cols=\"$FRAMEWIDTH,*\">\n";
-       print "<frame name=\"mainleft\" src=\""
-         . XMLEncode("$AWScript?${NewLinkParams}framename=mainleft")
-         . "\" noresize=\"noresize\" frameborder=\"0\" />\n";
-       print "<frame name=\"mainright\" src=\""
-         . XMLEncode("$AWScript?${NewLinkParams}framename=mainright")
-         . "\" noresize=\"noresize\" scrolling=\"yes\" frameborder=\"0\" />\n";
-       print "<noframes><body>";
-       print "Your browser does not support frames.<br />\n";
-       print "You must set AWStats UseFramesWhenCGI parameter to 0\n";
-       print "to see your reports.<br />\n";
-       print "</body></noframes>\n";
-       print "</frameset>\n";
-       &html_end(0);
-       exit 0;
-}
-
-%MonthNumLib = (
-       "01", "$Message[60]", "02", "$Message[61]", "03", "$Message[62]",
-       "04", "$Message[63]", "05", "$Message[64]", "06", "$Message[65]",
-       "07", "$Message[66]", "08", "$Message[67]", "09", "$Message[68]",
-       "10", "$Message[69]", "11", "$Message[70]", "12", "$Message[71]"
-);
-
-# Build ListOfYears list with all existing years
-(
-       $lastyearbeforeupdate, $lastmonthbeforeupdate, $lastdaybeforeupdate,
-       $lasthourbeforeupdate, $lastdatebeforeupdate
-  )
-  = ( 0, 0, 0, 0, 0 );
-my $datemask = '';
-if    ( $DatabaseBreak eq 'month' ) { $datemask = '(\d\d)(\d\d\d\d)'; }
-elsif ( $DatabaseBreak eq 'year' )  { $datemask = '(\d\d\d\d)'; }
-elsif ( $DatabaseBreak eq 'day' )   { $datemask = '(\d\d)(\d\d\d\d)(\d\d)'; }
-elsif ( $DatabaseBreak eq 'hour' )  {
-       $datemask = '(\d\d)(\d\d\d\d)(\d\d)(\d\d)';
-}
-
-if ($Debug) {
-       debug(
-"Scan for last history files into DirData='$DirData' with mask='$datemask'"
-       );
-}
-opendir( DIR, "$DirData" );
-my $regfilesuffix = quotemeta($FileSuffix);
-foreach ( grep /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i,
-       file_filt sort readdir DIR )
-{
-       /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i;
-       if ( !$ListOfYears{"$2"} || "$1" gt $ListOfYears{"$2"} ) {
-
-               # ListOfYears contains max month found
-               $ListOfYears{"$2"} = "$1";
-       }
-       my $rangestring = ( $2 || "" ) . ( $1 || "" ) . ( $3 || "" ) . ( $4 || "" );
-       if ( $rangestring gt $lastdatebeforeupdate ) {
-
-               # We are on a new max for mask
-               $lastyearbeforeupdate  = ( $2 || "" );
-               $lastmonthbeforeupdate = ( $1 || "" );
-               $lastdaybeforeupdate   = ( $3 || "" );
-               $lasthourbeforeupdate  = ( $4 || "" );
-               $lastdatebeforeupdate = $rangestring;
+#------------------------------------------------------------------------------
+# Function:     Prints the Unknown IP/Host details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowHostsUnknown{
+       my $total_p = 0;
+       my $total_h = 0;
+       my $total_k = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $rest_k = 0;
+       print "$Center<a name=\"unknownip\">&nbsp;</a><br />\n";
+       &tab_head( "$Message[45]", 19, 0, 'unknownwip' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
+         . Format_Number(( scalar keys %_host_h ))
+         . " $Message[1]</th>";
+       &HTMLShowHostInfo('__title__');
+       if ( $ShowHostsStats =~ /P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
        }
-}
-close DIR;
-
-# If at least one file found, get value for LastLine
-if ($lastyearbeforeupdate) {
-
-       # Read 'general' section of last history file for LastLine
-       &Read_History_With_TmpUpdate( $lastyearbeforeupdate, $lastmonthbeforeupdate,
-               $lastdaybeforeupdate, $lasthourbeforeupdate, 0, 0, "general" );
-}
-
-# Warning if lastline in future
-if ( $LastLine > ( $nowtime + 20000 ) ) {
-       warning(
-"WARNING: LastLine parameter in history file is '$LastLine' so in future. May be you need to correct manually the line LastLine in some awstats*.$SiteConfig.conf files."
-       );
-}
-
-# Force LastLine
-if ( $QueryString =~ /lastline=(\d{14})/i ) {
-       $LastLine = $1;
-}
-if ($Debug) {
-       debug(
-               "Last year=$lastyearbeforeupdate - Last month=$lastmonthbeforeupdate");
-       debug("Last day=$lastdaybeforeupdate - Last hour=$lasthourbeforeupdate");
-       debug("LastLine=$LastLine");
-       debug("LastLineNumber=$LastLineNumber");
-       debug("LastLineOffset=$LastLineOffset");
-       debug("LastLineChecksum=$LastLineChecksum");
-}
-
-# Init vars
-&Init_HashArray();
-
-#------------------------------------------
-# UPDATE PROCESS
-#------------------------------------------
-my $lastlinenb         = 0;
-my $lastlineoffset     = 0;
-my $lastlineoffsetnext = 0;
-
-if ($Debug) { debug( "UpdateStats is $UpdateStats", 2 ); }
-if ( $UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft' )
-{    # Update only on index page or when not framed to avoid update twice
-
-       my %MonthNum = (
-               "Jan", "01", "jan", "01", "Feb", "02", "feb", "02", "Mar", "03",
-               "mar", "03", "Apr", "04", "apr", "04", "May", "05", "may", "05",
-               "Jun", "06", "jun", "06", "Jul", "07", "jul", "07", "Aug", "08",
-               "aug", "08", "Sep", "09", "sep", "09", "Oct", "10", "oct", "10",
-               "Nov", "11", "nov", "11", "Dec", "12", "dec", "12"
-         )
-         ; # MonthNum must be in english because used to translate log date in apache log files
-
-       if ( !scalar keys %HTMLOutput ) {
+       if ( $ShowHostsStats =~ /H/i ) {
                print
-"Create/Update database for config \"$FileConfig\" by AWStats version $VERSION\n";
-               print "From data in log file \"$LogFile\"...\n";
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
        }
-
-       my $lastprocessedyear  = $lastyearbeforeupdate  || 0;
-       my $lastprocessedmonth = $lastmonthbeforeupdate || 0;
-       my $lastprocessedday   = $lastdaybeforeupdate   || 0;
-       my $lastprocessedhour  = $lasthourbeforeupdate  || 0;
-       my $lastprocesseddate  = '';
-       if ( $DatabaseBreak eq 'month' ) {
-               $lastprocesseddate =
-                 sprintf( "%04i%02i", $lastprocessedyear, $lastprocessedmonth );
+       if ( $ShowHostsStats =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
        }
-       elsif ( $DatabaseBreak eq 'year' ) {
-               $lastprocesseddate = sprintf( "%04i%", $lastprocessedyear );
+       if ( $ShowHostsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
        }
-       elsif ( $DatabaseBreak eq 'day' ) {
-               $lastprocesseddate = sprintf( "%04i%02i%02i",
-                       $lastprocessedyear, $lastprocessedmonth, $lastprocessedday );
+       print "</tr>\n";
+       $total_p = $total_h = $total_k = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
+               \%_host_p );
+       foreach my $key (@keylist) {
+               my $host = CleanXSS($key);
+               print "<tr><td class=\"aws\">$host</td>";
+               &HTMLShowHostInfo($key);
+               if ( $ShowHostsStats =~ /P/i ) {
+                       print "<td>"
+                         . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
+                         . "</td>";
+               }
+               if ( $ShowHostsStats =~ /H/i ) {
+                       print "<td>".Format_Number($_host_h{$key})."</td>";
+               }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_host_l{$key}
+                               ? Format_Date( $_host_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
+               $total_p += $_host_p{$key};
+               $total_h += $_host_h{$key};
+               $total_k += $_host_k{$key} || 0;
+               $count++;
        }
-       elsif ( $DatabaseBreak eq 'hour' ) {
-               $lastprocesseddate = sprintf(
-                       "%04i%02i%02i%02i",
-                       $lastprocessedyear, $lastprocessedmonth,
-                       $lastprocessedday,  $lastprocessedhour
+       if ($Debug) {
+               debug(
+"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
+                       2
                );
        }
+       $rest_p = $TotalPages - $total_p;
+       $rest_h = $TotalHits - $total_h;
+       $rest_k = $TotalBytes - $total_k;
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
+       {    # All other visitors (known or not)
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[82]</span></td>";
+               &HTMLShowHostInfo('');
+               if ( $ShowHostsStats =~ /P/i ) {
+                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
+       }
+       &tab_end();
+       &html_end(1);
+}
 
-       my @list;
+#------------------------------------------------------------------------------
+# Function:     Prints the Host details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowHosts{
+       my $total_p = 0;
+       my $total_h = 0;
+       my $total_k = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $rest_k = 0;
+       print "$Center<a name=\"hosts\">&nbsp;</a><br />\n";
 
-       # Init RobotsSearchIDOrder required for update process
-       @list = ();
-       if ( $LevelForRobotsDetection >= 1 ) {
-               foreach ( 1 .. $LevelForRobotsDetection ) { push @list, "list$_"; }
-               push @list, "listgen";    # Always added
+       # Show filter form
+       &HTMLShowFormFilter( "hostfilter", $FilterIn{'host'},
+               $FilterEx{'host'} );
+
+       # Show hosts list
+       my $title = '';
+       my $cpt   = 0;
+       if ( $HTMLOutput{'allhosts'} ) {
+               $title .= "$Message[81]";
+               $cpt = ( scalar keys %_host_h );
+       }
+       if ( $HTMLOutput{'lasthosts'} ) {
+               $title .= "$Message[9]";
+               $cpt = ( scalar keys %_host_h );
+       }
+       &tab_head( "$title", 19, 0, 'hosts' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
+       if ( $FilterIn{'host'} || $FilterEx{'host'} ) {    # With filter
+               if ( $FilterIn{'host'} ) {
+                       print "$Message[79] '<b>$FilterIn{'host'}</b>'";
+               }
+               if ( $FilterIn{'host'} && $FilterEx{'host'} ) { print " - "; }
+               if ( $FilterEx{'host'} ) {
+                       print " Exlude $Message[79] '<b>$FilterEx{'host'}</b>'";
+               }
+               if ( $FilterIn{'host'} || $FilterEx{'host'} ) { print ": "; }
+               print "$cpt $Message[81]";
+               if ( $MonthRequired ne 'all' ) {
+                       if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
+                               print
+"<br />$Message[102]: ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
+                       }
+               }
        }
-       foreach my $key (@list) {
-               push @RobotsSearchIDOrder, @{"RobotsSearchIDOrder_$key"};
-               if ($Debug) {
-                       debug(
-                               "Add "
-                                 . @{"RobotsSearchIDOrder_$key"}
-                                 . " elements from RobotsSearchIDOrder_$key into RobotsSearchIDOrder",
-                               2
-                       );
+       else {    # Without filter
+               if ( $MonthRequired ne 'all' ) {
+                       print
+"$Message[102] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
                }
+               else { print "$Message[102] : " . Format_Number(( scalar keys %_host_h )); }
        }
-       if ($Debug) {
-               debug(
-                       "RobotsSearchIDOrder has now " . @RobotsSearchIDOrder . " elements",
-                       1
-               );
+       print "</th>";
+       &HTMLShowHostInfo('__title__');
+       if ( $ShowHostsStats =~ /P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
        }
-
-       # Init SearchEnginesIDOrder required for update process
-       @list = ();
-       if ( $LevelForSearchEnginesDetection >= 1 ) {
-               foreach ( 1 .. $LevelForSearchEnginesDetection ) {
-                       push @list, "list$_";
-               }
-               push @list, "listgen";    # Always added
+       if ( $ShowHostsStats =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
        }
-       foreach my $key (@list) {
-               push @SearchEnginesSearchIDOrder, @{"SearchEnginesSearchIDOrder_$key"};
-               if ($Debug) {
-                       debug(
-                               "Add "
-                                 . @{"SearchEnginesSearchIDOrder_$key"}
-                                 . " elements from SearchEnginesSearchIDOrder_$key into SearchEnginesSearchIDOrder",
-                               2
-                       );
+       if ( $ShowHostsStats =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ShowHostsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       $total_p = $total_h = $total_k = 0;
+       my $count = 0;
+       if ( $HTMLOutput{'allhosts'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
+                       \%_host_p );
+       }
+       if ( $HTMLOutput{'lasthosts'} ) {
+               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
+                       \%_host_l );
+       }
+       foreach my $key (@keylist) {
+               my $host = CleanXSS($key);
+               print "<tr><td class=\"aws\">"
+                 . ( $_robot_l{$key} ? '<b>'  : '' ) . "$host"
+                 . ( $_robot_l{$key} ? '</b>' : '' ) . "</td>";
+               &HTMLShowHostInfo($key);
+               if ( $ShowHostsStats =~ /P/i ) {
+                       print "<td>"
+                         . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
+                         . "</td>";
                }
+               if ( $ShowHostsStats =~ /H/i ) {
+                       print "<td>".Format_Number($_host_h{$key})."</td>";
+               }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_host_l{$key}
+                               ? Format_Date( $_host_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
+               $total_p += $_host_p{$key};
+               $total_h += $_host_h{$key};
+               $total_k += $_host_k{$key} || 0;
+               $count++;
        }
        if ($Debug) {
                debug(
-                       "SearchEnginesSearchIDOrder has now "
-                         . @SearchEnginesSearchIDOrder
-                         . " elements",
-                       1
+"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
+                       2
                );
        }
-
-       # Complete HostAliases array
-       my $sitetoanalyze = quotemeta( lc($SiteDomain) );
-       if ( !@HostAliases ) {
-               warning(
-"Warning: HostAliases parameter is not defined, $PROG choose \"$SiteDomain localhost 127.0.0.1\"."
-               );
-               push @HostAliases, qr/^$sitetoanalyze$/i;
-               push @HostAliases, qr/^localhost$/i;
-               push @HostAliases, qr/^127\.0\.0\.1$/i;
+       $rest_p = $TotalPages - $total_p;
+       $rest_h = $TotalHits - $total_h;
+       $rest_k = $TotalBytes - $total_k;
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
+       {    # All other visitors (known or not)
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               &HTMLShowHostInfo('');
+               if ( $ShowHostsStats =~ /P/i ) {
+                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
        }
-       else {
-               unshift @HostAliases, qr/^$sitetoanalyze$/i;
-       }    # Add SiteDomain as first value
+       &tab_end();
+       &html_end(1);
+}
 
-       # Optimize arrays
-       @HostAliases = &OptimizeArray( \@HostAliases, 1 );
-       if ($Debug) {
-               debug( "HostAliases precompiled regex list is now @HostAliases", 1 );
-       }
-       @SkipDNSLookupFor = &OptimizeArray( \@SkipDNSLookupFor, 1 );
-       if ($Debug) {
-               debug(
-                       "SkipDNSLookupFor precompiled regex list is now @SkipDNSLookupFor",
-                       1
-               );
-       }
-       @SkipHosts = &OptimizeArray( \@SkipHosts, 1 );
-       if ($Debug) {
-               debug( "SkipHosts precompiled regex list is now @SkipHosts", 1 );
+#------------------------------------------------------------------------------
+# Function:     Prints the Domains details frame or static page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLShowDomains{
+       my $total_p = 0;
+       my $total_h = 0;
+       my $total_k = 0;
+       my $total_v = 0;
+       my $total_u = 0;
+       my $rest_p = 0;
+       my $rest_h = 0;
+       my $rest_k = 0;
+       my $rest_v = 0;
+       my $rest_u = 0;
+       print "$Center<a name=\"domains\">&nbsp;</a><br />\n";
+
+       # Show domains list
+       my $title = '';
+       my $cpt   = 0;
+       if ( $HTMLOutput{'alldomains'} ) {
+               $title .= "$Message[25]";
+               $cpt = ( scalar keys %_domener_h );
+       }
+       &tab_head( "$title", 19, 0, 'domains' );
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
+       if ( $ShowDomainsStats =~ /U/i ) {
+               print
+                 "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
        }
-       @SkipReferrers = &OptimizeArray( \@SkipReferrers, 1 );
-       if ($Debug) {
-               debug( "SkipReferrers precompiled regex list is now @SkipReferrers",
-                       1 );
+       if ( $ShowDomainsStats =~ /V/i ) {
+               print
+                 "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
        }
-       @SkipUserAgents = &OptimizeArray( \@SkipUserAgents, 1 );
-       if ($Debug) {
-               debug( "SkipUserAgents precompiled regex list is now @SkipUserAgents",
-                       1 );
+       if ( $ShowDomainsStats =~ /P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
        }
-       @SkipFiles = &OptimizeArray( \@SkipFiles, $URLNotCaseSensitive );
-       if ($Debug) {
-               debug( "SkipFiles precompiled regex list is now @SkipFiles", 1 );
+       if ( $ShowDomainsStats =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
        }
-       @OnlyHosts = &OptimizeArray( \@OnlyHosts, 1 );
-       if ($Debug) {
-               debug( "OnlyHosts precompiled regex list is now @OnlyHosts", 1 );
+       if ( $ShowDomainsStats =~ /B/i ) {
+               print
+"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
        }
-       @OnlyUsers = &OptimizeArray( \@OnlyUsers, 1 );
-       if ($Debug) {
-               debug( "OnlyUsers precompiled regex list is now @OnlyUsers", 1 );
+       print "<th>&nbsp;</th>";
+       print "</tr>\n";
+       $total_u = $total_v = $total_p = $total_h = $total_k = 0;
+       my $max_h = 1;
+       foreach ( values %_domener_h ) {
+               if ( $_ > $max_h ) { $max_h = $_; }
        }
-       @OnlyUserAgents = &OptimizeArray( \@OnlyUserAgents, 1 );
-       if ($Debug) {
-               debug( "OnlyUserAgents precompiled regex list is now @OnlyUserAgents",
-                       1 );
+       my $max_k = 1;
+       foreach ( values %_domener_k ) {
+               if ( $_ > $max_k ) { $max_k = $_; }
        }
-       @OnlyFiles = &OptimizeArray( \@OnlyFiles, $URLNotCaseSensitive );
-       if ($Debug) {
-               debug( "OnlyFiles precompiled regex list is now @OnlyFiles", 1 );
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_domener_h,
+               \%_domener_p );
+       foreach my $key (@keylist) {
+               my ( $_domener_u, $_domener_v );
+               my $bredde_p = 0;
+               my $bredde_h = 0;
+               my $bredde_k = 0;
+               if ( $max_h > 0 ) {
+                       $bredde_p =
+                         int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
+               }    # use max_h to enable to compare pages with hits
+               if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
+               if ( $max_h > 0 ) {
+                       $bredde_h =
+                         int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
+               }
+               if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
+               if ( $max_k > 0 ) {
+                       $bredde_k =
+                         int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
+                         1;
+               }
+               if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
+               my $newkey = lc($key);
+               if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
+                       print
+"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
+                         . AltTitle("$Message[0]")
+                         . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
+               }
+               else {
+                       print
+"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
+                         . AltTitle("$newkey")
+                         . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
+               }
+               ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
+               if ( $ShowDomainsStats =~ /U/i ) {
+                       $_domener_u = (
+                                 $_domener_p{$key}
+                               ? $_domener_p{$key} / $TotalPages
+                               : 0
+                       );
+                       $_domener_u += ( $_domener_h{$key} / $TotalHits );
+                       $_domener_u =
+                         sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
+                       print "<td>".Format_Number($_domener_u)." ("
+                         . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
+                         . ")</td>";
+               }
+               if ( $ShowDomainsStats =~ /V/i ) {
+                       $_domener_v = (
+                                 $_domener_p{$key}
+                               ? $_domener_p{$key} / $TotalPages
+                               : 0
+                       );
+                       $_domener_v += ( $_domener_h{$key} / $TotalHits );
+                       $_domener_v =
+                         sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
+                       print "<td>".Format_Number($_domener_v)." ("
+                         . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
+                         . ")</td>";
+               }
+               if ( $ShowDomainsStats =~ /P/i ) {
+                       print "<td>".Format_Number($_domener_p{$key})."</td>";
+               }
+               if ( $ShowDomainsStats =~ /H/i ) {
+                       print "<td>".Format_Number($_domener_h{$key})."</td>";
+               }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
+               }
+               print "<td class=\"aws\">";
+               if ( $ShowDomainsStats =~ /P/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
+                         . AltTitle( "$Message[56]: " . int( $_domener_p{$key} ) )
+                         . " /><br />\n";
+               }
+               if ( $ShowDomainsStats =~ /H/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
+                         . AltTitle( "$Message[57]: " . int( $_domener_h{$key} ) )
+                         . " /><br />\n";
+               }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
+                         . AltTitle(
+                               "$Message[75]: " . Format_Bytes( $_domener_k{$key} ) )
+                         . " />";
+               }
+               print "</td>";
+               print "</tr>\n";
+               $total_u += $_domener_u;
+               $total_v += $_domener_v;
+               $total_p += $_domener_p{$key};
+               $total_h += $_domener_h{$key};
+               $total_k += $_domener_k{$key} || 0;
+               $count++;
        }
-       @NotPageFiles = &OptimizeArray( \@NotPageFiles, $URLNotCaseSensitive );
-       if ($Debug) {
-               debug( "NotPageFiles precompiled regex list is now @NotPageFiles", 1 );
+       my $rest_u = $TotalUnique - $total_u;
+       my $rest_v = $TotalVisits - $total_v;
+       $rest_p = $TotalPages - $total_p;
+       $rest_h = $TotalHits - $total_h;
+       $rest_k = $TotalBytes - $total_k;
+       if (   $rest_u > 0
+               || $rest_v > 0
+               || $rest_p > 0
+               || $rest_h > 0
+               || $rest_k > 0 )
+       {    # All other domains (known or not)
+               print
+"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
+               if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
+               if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
+               if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               print "<td class=\"aws\">&nbsp;</td>";
+               print "</tr>\n";
        }
+       &tab_end();
+       &html_end(1);
+}
 
-       # Precompile the regex search strings with qr
-       @RobotsSearchIDOrder        = map { qr/$_/i } @RobotsSearchIDOrder;
-       @WormsSearchIDOrder         = map { qr/$_/i } @WormsSearchIDOrder;
-       @BrowsersSearchIDOrder      = map { qr/$_/i } @BrowsersSearchIDOrder;
-       @OSSearchIDOrder            = map { qr/$_/i } @OSSearchIDOrder;
-       @SearchEnginesSearchIDOrder = map { qr/$_/i } @SearchEnginesSearchIDOrder;
-       my $miscquoted     = quotemeta("$MiscTrackerUrl");
-       my $defquoted      = quotemeta("/$DefaultFile[0]");
-       my $sitewithoutwww = lc($SiteDomain);
-       $sitewithoutwww =~ s/www\.//;
-       $sitewithoutwww = quotemeta($sitewithoutwww);
-
-       # Define precompiled regex
-       my $regmisc        = qr/^$miscquoted/;
-       my $regfavico      = qr/\/favicon\.ico$/i;
-       my $regrobot       = qr/\/robots\.txt$/i;
-       my $regtruncanchor = qr/#(\w*)$/;
-       my $regtruncurl    = qr/([$URLQuerySeparators])(.*)$/;
-       my $regext         = qr/\.(\w{1,6})$/;
-       my $regdefault;
-       if ($URLNotCaseSensitive) { $regdefault = qr/$defquoted$/i; }
-       else { $regdefault = qr/$defquoted$/; }
-       my $regipv4           = qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
-       my $regipv4l          = qr/^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
-       my $regipv6           = qr/^[0-9A-F]*:/i;
-       my $regvermsie        = qr/msie([+_ ]|)([\d\.]*)/i;
-       my $regvernetscape    = qr/netscape.?\/([\d\.]*)/i;
-       my $regverfirefox     = qr/firefox\/([\d\.]*)/i;
-       my $regveropera       = qr/opera\/([\d\.]*)/i;
-       my $regversafari      = qr/safari\/([\d\.]*)/i;
-       my $regversafariver   = qr/version\/([\d\.]*)/i;
-       my $regverchrome      = qr/chrome\/([\d\.]*)/i;
-       my $regverkonqueror   = qr/konqueror\/([\d\.]*)/i;
-       my $regversvn         = qr/svn\/([\d\.]*)/i;
-       my $regvermozilla     = qr/mozilla(\/|)([\d\.]*)/i;
-       my $regnotie          = qr/webtv|omniweb|opera/i;
-       my $regnotnetscape    = qr/gecko|compatible|opera|galeon|safari|charon/i;
-       my $regnotfirefox     = qr/flock/i;
-       my $regnotsafari      = qr/android|arora|chrome|shiira/i;
-       my $regreferer        = qr/^(\w+):\/\/([^\/:]+)(:\d+|)/;
-       my $regreferernoquery = qr/^([^$URLQuerySeparators]+)/;
-       my $reglocal          = qr/^(www\.|)$sitewithoutwww/i;
-       my $regget            = qr/get|out/i;
-       my $regsent           = qr/sent|put|in/i;
-
-       # Define value of $pos_xxx, @fieldlib, $PerlParsingFormat
-       &DefinePerlParsingFormat($LogFormat);
-
-       # Load DNS Cache Files
-       #------------------------------------------
-       if ($DNSLookup) {
-               &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 )
-                 ; # Load with save into a second plugin file if plugin enabled and second file not up to date. No use of FileSuffix
-               if ( $DNSLookup == 1 ) {    # System DNS lookup required
-                        #if (! eval("use Socket;")) { error("Failed to load perl module Socket."); }
-                        #use Socket;
-                       &Read_DNS_Cache( \%TmpDNSLookup, "$DNSLastUpdateCacheFile",
-                               "$FileSuffix", 0 )
-                         ;    # Load with no save into a second plugin file. Use FileSuffix
+#------------------------------------------------------------------------------
+# Function:     Prints the Summary section at the top of the main page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainSummary{
+       if ($Debug) { debug( "ShowSummary", 2 ); }
+       # FirstTime LastTime
+       my $FirstTime = 0;
+       my $LastTime  = 0;
+       foreach my $key ( keys %FirstTime ) {
+               my $keyqualified = 0;
+               if ( $MonthRequired eq 'all' ) { $keyqualified = 1; }
+               if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; }
+               if ($keyqualified) {
+                       if ( $FirstTime{$key}
+                               && ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) )
+                       {
+                               $FirstTime = $FirstTime{$key};
+                       }
+                       if ( $LastTime < ( $LastTime{$key} || 0 ) ) {
+                               $LastTime = $LastTime{$key};
+                       }
                }
        }
+                       
+       #print "$Center<a name=\"summary\">&nbsp;</a><br />\n";
+       my $title = "$Message[128]";
+       &tab_head( "$title", 0, 0, 'month' );
 
-       # Processing log
-       #------------------------------------------
-
-       if ($EnableLockForUpdate) {
+       my $NewLinkParams = ${QueryString};
+       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
+       $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
+       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+       $NewLinkParams =~ s/^&amp;//;
+       $NewLinkParams =~ s/&amp;$//;
+       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
+       my $NewLinkTarget = '';
 
-               # Trap signals to remove lock
-               $SIG{INT} = \&SigHandler;    # 2
-                                            #$SIG{KILL} = \&SigHandler;        # 9
-                                            #$SIG{TERM} = \&SigHandler;        # 15
-                                            # Set AWStats update lock
-               &Lock_Update(1);
+       if ( $FrameName eq 'mainright' ) {
+               $NewLinkTarget = " target=\"_parent\"";
        }
 
-       if ($Debug) {
-               debug("Start Update process (lastprocesseddate=$lastprocesseddate)");
+       # Ratio
+       my $RatioVisits = 0;
+       my $RatioPages  = 0;
+       my $RatioHits   = 0;
+       my $RatioBytes  = 0;
+       if ( $TotalUnique > 0 ) {
+               $RatioVisits = int( $TotalVisits / $TotalUnique * 100 ) / 100;
+       }
+       if ( $TotalVisits > 0 ) {
+               $RatioPages = int( $TotalPages / $TotalVisits * 100 ) / 100;
+       }
+       if ( $TotalVisits > 0 ) {
+               $RatioHits = int( $TotalHits / $TotalVisits * 100 ) / 100;
+       }
+       if ( $TotalVisits > 0 ) {
+               $RatioBytes =
+                 int( ( $TotalBytes / 1024 ) * 100 /
+                         ( $LogType eq 'M' ? $TotalHits : $TotalVisits ) ) / 100;
        }
 
-       # Open log file
-       if ($Debug) { debug("Open log file \"$LogFile\""); }
-       open( LOG, "$LogFile" )
-         || error("Couldn't open server log file \"$LogFile\" : $!");
-       binmode LOG
-         ;   # Avoid premature EOF due to log files corrupted with \cZ or bin chars
-
-       # Define local variables for loop scan
-       my @field               = ();
-       my $counterforflushtest = 0;
-       my $qualifdrop          = '';
-       my $countedtraffic      = 0;
-
-       # Reset chrono for benchmark (first call to GetDelaySinceStart)
-       &GetDelaySinceStart(1);
-       if ( !scalar keys %HTMLOutput ) {
-               print "Phase 1 : First bypass old records, searching new record...\n";
+       my $colspan = 5;
+       my $w       = '20';
+       if ( $LogType eq 'W' || $LogType eq 'S' ) {
+               $w       = '17';
+               $colspan = 6;
        }
 
-       # Can we try a direct seek access in log ?
-       my $line;
-       if ( $LastLine && $LastLineNumber && $LastLineOffset && $LastLineChecksum )
-       {
+       # Show first/last
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+       print
+"<td class=\"aws\"><b>$Message[133]</b></td><td class=\"aws\" colspan=\""
+         . ( $colspan - 1 ) . "\">\n";
+       print( $MonthRequired eq 'all'
+               ? "$Message[6] $YearRequired"
+               : "$Message[5] "
+                 . $MonthNumLib{$MonthRequired}
+                 . " $YearRequired"
+       );
+       print "</td></tr>\n";
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+       print "<td class=\"aws\"><b>$Message[8]</b></td>\n";
+       print "<td class=\"aws\" colspan=\""
+         . ( $colspan - 1 ) . "\">"
+         . ( $FirstTime ? Format_Date( $FirstTime, 0 ) : "NA" ) . "</td>";
+       print "</tr>\n";
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+       print "<td class=\"aws\"><b>$Message[9]</b></td>\n";
+       print "<td class=\"aws\" colspan=\""
+         . ( $colspan - 1 ) . "\">"
+         . ( $LastTime ? Format_Date( $LastTime, 0 ) : "NA" )
+         . "</td>\n";
+       print "</tr>\n";
 
-               # Try a direct seek access to save time
-               if ($Debug) {
-                       debug(
-"Try a direct access to LastLine=$LastLine, LastLineNumber=$LastLineNumber, LastLineOffset=$LastLineOffset, LastLineChecksum=$LastLineChecksum"
-                       );
-               }
-               seek( LOG, $LastLineOffset, 0 );
-               if ( $line = <LOG> ) {
-                       chomp $line;
-                       $line =~ s/\r$//;
-                       @field = map( /$PerlParsingFormat/, $line );
-                       if ($Debug) {
-                               my $string = '';
-                               foreach ( 0 .. @field - 1 ) {
-                                       $string .= "$fieldlib[$_]=$field[$_] ";
-                               }
-                               if ($Debug) {
-                                       debug( " Read line after direct access: $string", 1 );
-                               }
-                       }
-                       my $checksum = &CheckSum($line);
-                       if ($Debug) {
-                               debug(
-" LastLineChecksum=$LastLineChecksum, Read line checksum=$checksum",
-                                       1
-                               );
-                       }
-                       if ( $checksum == $LastLineChecksum ) {
-                               if ( !scalar keys %HTMLOutput ) {
-                                       print
-"Direct access after last parsed record (after line $LastLineNumber)\n";
-                               }
-                               $lastlinenb         = $LastLineNumber;
-                               $lastlineoffset     = $LastLineOffset;
-                               $lastlineoffsetnext = tell LOG;
-                               $NewLinePhase       = 1;
-                       }
-                       else {
-                               if ( !scalar keys %HTMLOutput ) {
-                                       print
-"Direct access to last remembered record has fallen on another record.\nSo searching new records from beginning of log file...\n";
-                               }
-                               $lastlinenb         = 0;
-                               $lastlineoffset     = 0;
-                               $lastlineoffsetnext = 0;
-                               seek( LOG, 0, 0 );
-                       }
-               }
-               else {
-                       if ( !scalar keys %HTMLOutput ) {
-                               print
-"Direct access to last remembered record is out of file.\nSo searching it from beginning of log file...\n";
-                       }
-                       $lastlinenb         = 0;
-                       $lastlineoffset     = 0;
-                       $lastlineoffsetnext = 0;
-                       seek( LOG, 0, 0 );
-               }
+       # Show main indicators title row
+       print "<tr>";
+       if ( $LogType eq 'W' || $LogType eq 'S' ) {
+               print "<td bgcolor=\"#$color_TableBGTitle\">&nbsp;</td>";
+       }
+       if ( $ShowSummary =~ /U/i ) {
+               print "<td width=\"$w%\" bgcolor=\"#$color_u\""
+                 . Tooltip(2)
+                 . ">$Message[11]</td>";
+       }
+       else {
+               print
+"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+       }
+       if ( $ShowSummary =~ /V/i ) {
+               print "<td width=\"$w%\" bgcolor=\"#$color_v\""
+                 . Tooltip(1)
+                 . ">$Message[10]</td>";
+       }
+       else {
+               print
+"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+       }
+       if ( $ShowSummary =~ /P/i ) {
+               print "<td width=\"$w%\" bgcolor=\"#$color_p\""
+                 . Tooltip(3)
+                 . ">$Message[56]</td>";
+       }
+       else {
+               print
+"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+       }
+       if ( $ShowSummary =~ /H/i ) {
+               print "<td width=\"$w%\" bgcolor=\"#$color_h\""
+                 . Tooltip(4)
+                 . ">$Message[57]</td>";
+       }
+       else {
+               print
+"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+       }
+       if ( $ShowSummary =~ /B/i ) {
+               print "<td width=\"$w%\" bgcolor=\"#$color_k\""
+                 . Tooltip(5)
+                 . ">$Message[75]</td>";
        }
        else {
+               print
+"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+       }
+       print "</tr>\n";
 
-               # No try of direct seek access
-               if ( !scalar keys %HTMLOutput ) {
-                       print "Searching new records from beginning of log file...\n";
+       # Show main indicators values for viewed traffic
+       print "<tr>";
+       if ( $LogType eq 'M' ) {
+               print "<td class=\"aws\">$Message[165]</td>";
+               print "<td>&nbsp;<br />&nbsp;</td>\n";
+               print "<td>&nbsp;<br />&nbsp;</td>\n";
+               if ( $ShowSummary =~ /H/i ) {
+                       print "<td><b>".Format_Number($TotalHits)."</b>"
+                         . (
+                               $LogType eq 'M'
+                               ? ""
+                               : "<br />($RatioHits&nbsp;"
+                                 . lc( $Message[57] . "/" . $Message[12] ) . ")"
+                         )
+                         . "</td>";
                }
-               $lastlinenb         = 0;
-               $lastlineoffset     = 0;
-               $lastlineoffsetnext = 0;
+               else { print "<td>&nbsp;</td>"; }
+               if ( $ShowSummary =~ /B/i ) {
+                       print "<td><b>"
+                         . Format_Bytes( int($TotalBytes) )
+                         . "</b><br />($RatioBytes&nbsp;$Message[108]/"
+                         . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
+                         . ")</td>";
+               }
+               else { print "<td>&nbsp;</td>"; }
        }
-
-       #
-       # Loop on each log line
-       #
-       while ( $line = <LOG> ) {
-               
-               # 20080525 BEGIN Patch to test if first char of $line = hex "00" then conclude corrupted with binary code
-               my $FirstHexChar;
-               $FirstHexChar = sprintf( "%02X", ord( substr( $line, 0, 1 ) ) );
-               if ( $FirstHexChar eq '00' ) {
-                       $NbOfLinesCorrupted++;
-                       if ($ShowCorrupted) {
-                               print "Corrupted record line "
-                                 . ( $lastlinenb + $NbOfLinesParsed )
-                                 . " (record starts with hex 00; binary code): $line\n";
-                       }
-                       if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
-                               && $NbOfLinesParsed == $NbOfLinesCorrupted )
-                       {
-                               error( "Format error", $line, $LogFile );
-                       }    # Exit with format error
-                       next;
+       else {
+               if ( $LogType eq 'W' || $LogType eq 'S' ) {
+                       print "<td class=\"aws\">$Message[160]&nbsp;*</td>";
                }
-               # 20080525 END
-
-               chomp $line;
-               $line =~ s/\r$//;
-               if ( $UpdateFor && $NbOfLinesParsed >= $UpdateFor ) { last; }
-               $NbOfLinesParsed++;
-
-               $lastlineoffset     = $lastlineoffsetnext;
-               $lastlineoffsetnext = tell LOG;
-
-               if ($ShowSteps) {
-                       if ( ( ++$NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) == 0 ) {
-                               my $delay = &GetDelaySinceStart(0);
-                               print "$NbOfLinesParsed lines processed ("
-                                 . ( $delay > 0 ? $delay : 1000 ) . " ms, "
-                                 . int(
-                                       1000 * $NbOfLinesShowsteps / ( $delay > 0 ? $delay : 1000 )
-                                 )
-                                 . " lines/second)\n";
-                       }
+               if ( $ShowSummary =~ /U/i ) {
+                       print "<td>"
+                         . (
+                               $MonthRequired eq 'all'
+                               ? "<b>&lt;= ".Format_Number($TotalUnique)."</b><br />$Message[129]"
+                               : "<b>".Format_Number($TotalUnique)."</b><br />&nbsp;"
+                         )
+                         . "</td>";
                }
-
-               if ( $LogFormat eq '2' && $line =~ /^#Fields:/ ) {
-                       my @fixField = map( /^#Fields: (.*)/, $line );
-                       if ( $fixField[0] !~ /s-kernel-time/ ) {
-                               debug( "Found new log format: '" . $fixField[0] . "'", 1 );
-                               &DefinePerlParsingFormat( $fixField[0] );
-                       }
+               else { print "<td>&nbsp;</td>"; }
+               if ( $ShowSummary =~ /V/i ) {
+                       print
+"<td><b>".Format_Number($TotalVisits)."</b><br />($RatioVisits&nbsp;$Message[52])</td>";
                }
-
-               # Parse line record to get all required fields
-               if ( !( @field = map( /$PerlParsingFormat/, $line ) ) ) {
-                       $NbOfLinesCorrupted++;
-                       if ($ShowCorrupted) {
-                               if ( $line =~ /^#/ || $line =~ /^!/ ) {
-                                       print "Corrupted record line "
-                                         . ( $lastlinenb + $NbOfLinesParsed )
-                                         . " (comment line): $line\n";
-                               }
-                               elsif ( $line =~ /^\s*$/ ) {
-                                       print "Corrupted record line "
-                                         . ( $lastlinenb + $NbOfLinesParsed )
-                                         . " (blank line)\n";
-                               }
-                               else {
-                                       print "Corrupted record line "
-                                         . ( $lastlinenb + $NbOfLinesParsed )
-                                         . " (record format does not match LogFormat parameter): $line\n";
-                               }
-                       }
-                       if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
-                               && $NbOfLinesParsed == $NbOfLinesCorrupted )
-                       {
-                               error( "Format error", $line, $LogFile );
-                       }    # Exit with format error
-                       if ( $line =~ /^__end_of_file__/i ) { last; } # For test purpose only
-                       next;
+               else { print "<td>&nbsp;</td>"; }
+               if ( $ShowSummary =~ /P/i ) {
+                       print "<td><b>".Format_Number($TotalPages)."</b><br />($RatioPages&nbsp;"
+                         . $Message[56] . "/"
+                         . $Message[12]
+                         . ")</td>";
+               }
+               else { print "<td>&nbsp;</td>"; }
+               if ( $ShowSummary =~ /H/i ) {
+                       print "<td><b>".Format_Number($TotalHits)."</b>"
+                         . (
+                               $LogType eq 'M'
+                               ? ""
+                               : "<br />($RatioHits&nbsp;"
+                                 . $Message[57] . "/"
+                                 . $Message[12] . ")"
+                         )
+                         . "</td>";
+               }
+               else { print "<td>&nbsp;</td>"; }
+               if ( $ShowSummary =~ /B/i ) {
+                       print "<td><b>"
+                         . Format_Bytes( int($TotalBytes) )
+                         . "</b><br />($RatioBytes&nbsp;$Message[108]/"
+                         . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
+                         . ")</td>";
                }
+               else { print "<td>&nbsp;</td>"; }
+       }
+       print "</tr>\n";
 
-               if ($Debug) {
-                       my $string = '';
-                       foreach ( 0 .. @field - 1 ) {
-                               $string .= "$fieldlib[$_]=$field[$_] ";
+       # Show main indicators values for not viewed traffic values
+       if ( $LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S' ) {
+               print "<tr>";
+               if ( $LogType eq 'M' ) {
+                       print "<td class=\"aws\">$Message[166]</td>";
+                       print "<td>&nbsp;<br />&nbsp;</td>\n";
+                       print "<td>&nbsp;<br />&nbsp;</td>\n";
+                       if ( $ShowSummary =~ /H/i ) {
+                               print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
                        }
-                       if ($Debug) {
-                               debug(
-                                       " Correct format line "
-                                         . ( $lastlinenb + $NbOfLinesParsed )
-                                         . ": $string",
-                                       4
-                               );
+                       else { print "<td>&nbsp;</td>"; }
+                       if ( $ShowSummary =~ /B/i ) {
+                               print "<td><b>"
+                                 . Format_Bytes( int($TotalNotViewedBytes) )
+                                 . "</b></td>";
                        }
+                       else { print "<td>&nbsp;</td>"; }
                }
-
-               # Drop wrong virtual host name
-               #----------------------------------------------------------------------
-               if ( $pos_vh >= 0 && $field[$pos_vh] !~ /^$SiteDomain$/i ) {
-                       my $skip = 1;
-                       foreach (@HostAliases) {
-                               if ( $field[$pos_vh] =~ /$_/ ) { $skip = 0; last; }
+               else {
+                       if ( $LogType eq 'W' || $LogType eq 'S' ) {
+                               print "<td class=\"aws\">$Message[161]&nbsp;*</td>";
                        }
-                       if ($skip) {
-                               $NbOfLinesDropped++;
-                               if ($ShowDropped) {
-                                       print
-"Dropped record (virtual hostname '$field[$pos_vh]' does not match SiteDomain='$SiteDomain' nor HostAliases parameters): $line\n";
-                               }
-                               next;
+                       print "<td colspan=\"2\">&nbsp;<br />&nbsp;</td>\n";
+                       if ( $ShowSummary =~ /P/i ) {
+                               print "<td><b>".Format_Number($TotalNotViewedPages)."</b></td>";
+                       }
+                       else { print "<td>&nbsp;</td>"; }
+                       if ( $ShowSummary =~ /H/i ) {
+                               print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
+                       }
+                       else { print "<td>&nbsp;</td>"; }
+                       if ( $ShowSummary =~ /B/i ) {
+                               print "<td><b>"
+                                 . Format_Bytes( int($TotalNotViewedBytes) )
+                                 . "</b></td>";
                        }
+                       else { print "<td>&nbsp;</td>"; }
                }
+               print "</tr>\n";
+       }
+       &tab_end($LogType eq 'W'
+                 || $LogType eq 'S' ? "* $Message[159]" : "" );
+}
 
-               # Drop wrong method/protocol
-               #---------------------------
-               if ( $LogType ne 'M' ) { $field[$pos_url] =~ s/\s/%20/g; }
+#------------------------------------------------------------------------------
+# Function:     Prints the Monthly section on the main page
+# Parameters:   _
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainMonthly{
+       if ($Debug) { debug( "ShowMonthStats", 2 ); }
+       print "$Center<a name=\"month\">&nbsp;</a><br />\n";
+       my $title = "$Message[162]";
+       &tab_head( "$title", 0, 0, 'month' );
+       print "<tr><td align=\"center\">\n";
+       print "<center>\n";
+
+       my $average_nb = my $average_u = my $average_v = my $average_p = 0;
+       my $average_h = my $average_k = 0;
+       my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
+       my $max_v = my $max_p = my $max_h = my $max_k = 1;
+
+       # Define total and max
+       for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+               my $monthix = sprintf( "%02s", $ix );
+               $total_u += $MonthUnique{ $YearRequired . $monthix } || 0;
+               $total_v += $MonthVisits{ $YearRequired . $monthix } || 0;
+               $total_p += $MonthPages{ $YearRequired . $monthix }  || 0;
+               $total_h += $MonthHits{ $YearRequired . $monthix }   || 0;
+               $total_k += $MonthBytes{ $YearRequired . $monthix }  || 0;
+
+#if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
                if (
-                       $LogType eq 'W'
-                       && (
-                                  $field[$pos_method] eq 'GET'
-                               || $field[$pos_method] eq 'POST'
-                               || $field[$pos_method] eq 'HEAD'
-                               || $field[$pos_method] eq 'PROPFIND'
-                               || $field[$pos_method] eq 'CHECKOUT'
-                               || $field[$pos_method] eq 'LOCK'
-                               || $field[$pos_method] eq 'PROPPATCH'
-                               || $field[$pos_method] eq 'OPTIONS'
-                               || $field[$pos_method] eq 'MKACTIVITY'
-                               || $field[$pos_method] eq 'PUT'
-                               || $field[$pos_method] eq 'MERGE'
-                               || $field[$pos_method] eq 'DELETE'
-                               || $field[$pos_method] eq 'REPORT'
-                               || $field[$pos_method] eq 'MKCOL'
-                               || $field[$pos_method] eq 'COPY'
-                               || $field[$pos_method] eq 'RPC_IN_DATA'
-                               || $field[$pos_method] eq 'RPC_OUT_DATA'
-                               || $field[$pos_method] eq 'OK'             # Webstar
-                               || $field[$pos_method] eq 'ERR!'           # Webstar
-                               || $field[$pos_method] eq 'PRIV'           # Webstar
-                       )
-                 )
+                       ( $MonthVisits{ $YearRequired . $monthix } || 0 ) > $max_v )
                {
+                       $max_v = $MonthVisits{ $YearRequired . $monthix };
+               }
 
-# HTTP request.        Keep only GET, POST, HEAD, *OK* and ERR! for Webstar. Do not keep OPTIONS, TRACE
+#if (($MonthPages{$YearRequired.$monthix}||0) > $max_p)  { $max_p=$MonthPages{$YearRequired.$monthix}; }
+               if ( ( $MonthHits{ $YearRequired . $monthix } || 0 ) > $max_h )
+               {
+                       $max_h = $MonthHits{ $YearRequired . $monthix };
                }
-               elsif (
-                       ( $LogType eq 'W' || $LogType eq 'S' )
-                       && (   $field[$pos_method] eq 'GET'
-                               || $field[$pos_method] eq 'mms'
-                               || $field[$pos_method] eq 'rtsp'
-                               || $field[$pos_method] eq 'http'
-                               || $field[$pos_method] eq 'RTP' )
-                 )
+               if ( ( $MonthBytes{ $YearRequired . $monthix } || 0 ) > $max_k )
                {
-
-# Streaming request (windows media server, realmedia or darwin streaming server)
+                       $max_k = $MonthBytes{ $YearRequired . $monthix };
                }
-               elsif ( $LogType eq 'M' && $field[$pos_method] eq 'SMTP' ) {
-
-               # Mail request ('SMTP' for mail log with maillogconvert.pl preprocessor)
-               }
-               elsif (
-                       $LogType eq 'F'
-                       && (   $field[$pos_method] eq 'RETR'
-                               || $field[$pos_method] eq 'o'
-                               || $field[$pos_method] =~ /$regget/o )
-                 )
-               {
+       }
 
-                       # FTP GET request
-               }
-               elsif (
-                       $LogType eq 'F'
-                       && (   $field[$pos_method] eq 'STOR'
-                               || $field[$pos_method] eq 'i'
-                               || $field[$pos_method] =~ /$regsent/o )
-                 )
-               {
+       # Define average
+       # TODO
 
-                       # FTP SENT request
+       # Show bars for month
+       my $graphdone=0;
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+       {
+               my @blocklabel = ();
+               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+                       my $monthix = sprintf( "%02s", $ix );
+                       push @blocklabel,
+                         "$MonthNumLib{$monthix}\n$YearRequired";
+               }
+               my @vallabel = (
+                       "$Message[11]", "$Message[10]",
+                       "$Message[56]", "$Message[57]",
+                       "$Message[75]"
+               );
+               my @valcolor =
+                 ( "$color_u", "$color_v", "$color_p", "$color_h",
+                       "$color_k" );
+               my @valmax = ( $max_v, $max_v, $max_h, $max_h, $max_k );
+               my @valtotal =
+                 ( $total_u, $total_v, $total_p, $total_h, $total_k );
+               my @valaverage = ();
+
+               #my @valaverage=($average_v,$average_p,$average_h,$average_k);
+               my @valdata = ();
+               my $xx      = 0;
+               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+                       my $monthix = sprintf( "%02s", $ix );
+                       $valdata[ $xx++ ] = $MonthUnique{ $YearRequired . $monthix }
+                         || 0;
+                       $valdata[ $xx++ ] = $MonthVisits{ $YearRequired . $monthix }
+                         || 0;
+                       $valdata[ $xx++ ] = $MonthPages{ $YearRequired . $monthix }
+                         || 0;
+                       $valdata[ $xx++ ] = $MonthHits{ $YearRequired . $monthix }
+                         || 0;
+                       $valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix }
+                         || 0;
                }
-               else {
-                       $NbOfLinesDropped++;
-                       if ($ShowDropped) {
+               
+               my $function = "ShowGraph_$pluginname";
+               &$function(
+                       "$title",        "month",
+                       $ShowMonthStats, \@blocklabel,
+                       \@vallabel,      \@valcolor,
+                       \@valmax,        \@valtotal,
+                       \@valaverage,    \@valdata
+               );
+               $graphdone=1;
+       }
+       if (! $graphdone)
+       {
+               print "<table>\n";
+               print "<tr valign=\"bottom\">";
+               print "<td>&nbsp;</td>\n";
+               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+                       my $monthix  = sprintf( "%02s", $ix );
+                       my $bredde_u = 0;
+                       my $bredde_v = 0;
+                       my $bredde_p = 0;
+                       my $bredde_h = 0;
+                       my $bredde_k = 0;
+                       if ( $max_v > 0 ) {
+                               $bredde_u =
+                                 int(
+                                       ( $MonthUnique{ $YearRequired . $monthix } || 0 ) /
+                                         $max_v * $BarHeight ) + 1;
+                       }
+                       if ( $max_v > 0 ) {
+                               $bredde_v =
+                                 int(
+                                       ( $MonthVisits{ $YearRequired . $monthix } || 0 ) /
+                                         $max_v * $BarHeight ) + 1;
+                       }
+                       if ( $max_h > 0 ) {
+                               $bredde_p =
+                                 int(
+                                       ( $MonthPages{ $YearRequired . $monthix } || 0 ) /
+                                         $max_h * $BarHeight ) + 1;
+                       }
+                       if ( $max_h > 0 ) {
+                               $bredde_h =
+                                 int( ( $MonthHits{ $YearRequired . $monthix } || 0 ) /
+                                         $max_h * $BarHeight ) + 1;
+                       }
+                       if ( $max_k > 0 ) {
+                               $bredde_k =
+                                 int(
+                                       ( $MonthBytes{ $YearRequired . $monthix } || 0 ) /
+                                         $max_k * $BarHeight ) + 1;
+                       }
+                       print "<td>";
+                       if ( $ShowMonthStats =~ /U/i ) {
                                print
-"Dropped record (method/protocol '$field[$pos_method]' not qualified when LogType=$LogType): $line\n";
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vu'}\" height=\"$bredde_u\" width=\"6\""
+                                 . AltTitle( "$Message[11]: "
+                                         . ( $MonthUnique{ $YearRequired . $monthix }
+                                                 || 0 ) )
+                                 . " />";
                        }
-                       next;
+                       if ( $ShowMonthStats =~ /V/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"6\""
+                                 . AltTitle( "$Message[10]: "
+                                         . ( $MonthVisits{ $YearRequired . $monthix }
+                                                 || 0 ) )
+                                 . " />";
+                       }
+                       if ( $ShowMonthStats =~ /P/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
+                                 . AltTitle( "$Message[56]: "
+                                         . ( $MonthPages{ $YearRequired . $monthix } || 0 )
+                                 )
+                                 . " />";
+                       }
+                       if ( $ShowMonthStats =~ /H/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
+                                 . AltTitle( "$Message[57]: "
+                                         . ( $MonthHits{ $YearRequired . $monthix } || 0 )
+                                 )
+                                 . " />";
+                       }
+                       if ( $ShowMonthStats =~ /B/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
+                                         . AltTitle(
+                                       "$Message[75]: "
+                                         . Format_Bytes(
+                                               $MonthBytes{ $YearRequired . $monthix }
+                                         )
+                                 )
+                                 . " />";
+                       }
+                       print "</td>\n";
                }
+               print "<td>&nbsp;</td>";
+               print "</tr>\n";
 
-               $field[$pos_date] =~
-                 tr/,-\/ \t/:::::/s;  # " \t" is used instead of "\s" not known with tr
-               my @dateparts =
-                 split( /:/, $field[$pos_date] )
-                 ; # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
-                # Detected date format: dddddddddd, YYYY-MM-DD HH:MM:SS (IIS), MM/DD/YY\tHH:MM:SS,
-                # DD/Month/YYYY:HH:MM:SS (Apache), DD/MM/YYYY HH:MM:SS, Mon DD HH:MM:SS
-               if ( !$dateparts[1] ) {    # Unix timestamp
-                       (
-                               $dateparts[5], $dateparts[4], $dateparts[3],
-                               $dateparts[0], $dateparts[1], $dateparts[2]
-                         )
-                         = localtime( int( $field[$pos_date] ) );
-                       $dateparts[1]++;
-                       $dateparts[2] += 1900;
+               # Show lib for month
+               print "<tr valign=\"middle\">";
+
+               #if (!$StaticLinks) {
+               #       print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=12&year=".($YearRequired-1))."\">&lt;&lt;</a></td>";
+               #}
+               #else {
+               print "<td>&nbsp;</td>";
+
+               #                               }
+               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+                       my $monthix = sprintf( "%02s", $ix );
+
+#                      if (!$StaticLinks) {
+#                              print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=$monthix&year=$YearRequired")."\">$MonthNumLib{$monthix}<br />$YearRequired</a></td>";
+#                      }
+#                      else {
+                       print "<td>"
+                         . (
+                               !$StaticLinks
+                                 && $monthix == $nowmonth
+                                 && $YearRequired == $nowyear
+                               ? '<font class="currentday">'
+                               : ''
+                         );
+                       print "$MonthNumLib{$monthix}<br />$YearRequired";
+                       print(   !$StaticLinks
+                                 && $monthix == $nowmonth
+                                 && $YearRequired == $nowyear ? '</font>' : '' );
+                       print "</td>";
+
+                       #                                       }
                }
-               elsif ( $dateparts[0] =~ /^....$/ ) {
-                       my $tmp = $dateparts[0];
-                       $dateparts[0] = $dateparts[2];
-                       $dateparts[2] = $tmp;
+
+#              if (!$StaticLinks) {
+#                      print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=1&year=".($YearRequired+1))."\">&gt;&gt;</a></td>";
+#              }
+#              else {
+               print "<td>&nbsp;</td>";
+
+               #                               }
+               print "</tr>\n";
+               print "</table>\n";
+       }
+       print "<br />\n";
+
+       # Show data array for month
+       if ($AddDataArrayMonthStats) {
+               print "<table>\n";
+               print
+"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[5]</td>";
+               if ( $ShowMonthStats =~ /U/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_u\""
+                         . Tooltip(2)
+                         . ">$Message[11]</td>";
                }
-               elsif ( $field[$pos_date] =~ /^..:..:..:/ ) {
-                       $dateparts[2] += 2000;
-                       my $tmp = $dateparts[0];
-                       $dateparts[0] = $dateparts[1];
-                       $dateparts[1] = $tmp;
+               if ( $ShowMonthStats =~ /V/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_v\""
+                         . Tooltip(1)
+                         . ">$Message[10]</td>";
                }
-               elsif ( $dateparts[0] =~ /^...$/ ) {
-                       my $tmp = $dateparts[0];
-                       $dateparts[0] = $dateparts[1];
-                       $dateparts[1] = $tmp;
-                       $tmp          = $dateparts[5];
-                       $dateparts[5] = $dateparts[4];
-                       $dateparts[4] = $dateparts[3];
-                       $dateparts[3] = $dateparts[2];
-                       $dateparts[2] = $tmp || $nowyear;
+               if ( $ShowMonthStats =~ /P/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_p\""
+                         . Tooltip(3)
+                         . ">$Message[56]</td>";
                }
-               if ( exists( $MonthNum{ $dateparts[1] } ) ) {
-                       $dateparts[1] = $MonthNum{ $dateparts[1] };
-               }    # Change lib month in num month if necessary
-               if ( $dateparts[1] <= 0 )
-               { # Date corrupted (for example $dateparts[1]='dic' for december month in a spanish log file)
-                       $NbOfLinesCorrupted++;
-                       if ($ShowCorrupted) {
-                               print "Corrupted record line "
-                                 . ( $lastlinenb + $NbOfLinesParsed )
-                                 . " (bad date format for month, may be month are not in english ?): $line\n";
+               if ( $ShowMonthStats =~ /H/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_h\""
+                         . Tooltip(4)
+                         . ">$Message[57]</td>";
+               }
+               if ( $ShowMonthStats =~ /B/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_k\""
+                         . Tooltip(5)
+                         . ">$Message[75]</td>";
+               }
+               print "</tr>\n";
+               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
+                       my $monthix = sprintf( "%02s", $ix );
+                       print "<tr>";
+                       print "<td>"
+                         . (
+                               !$StaticLinks
+                                 && $monthix == $nowmonth
+                                 && $YearRequired == $nowyear
+                               ? '<font class="currentday">'
+                               : ''
+                         );
+                       print "$MonthNumLib{$monthix} $YearRequired";
+                       print(   !$StaticLinks
+                                 && $monthix == $nowmonth
+                                 && $YearRequired == $nowyear ? '</font>' : '' );
+                       print "</td>";
+                       if ( $ShowMonthStats =~ /U/i ) {
+                               print "<td>",
+                                 Format_Number($MonthUnique{ $YearRequired . $monthix }
+                                 ? $MonthUnique{ $YearRequired . $monthix }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowMonthStats =~ /V/i ) {
+                               print "<td>",
+                                 Format_Number($MonthVisits{ $YearRequired . $monthix }
+                                 ? $MonthVisits{ $YearRequired . $monthix }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowMonthStats =~ /P/i ) {
+                               print "<td>",
+                                 Format_Number($MonthPages{ $YearRequired . $monthix }
+                                 ? $MonthPages{ $YearRequired . $monthix }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowMonthStats =~ /H/i ) {
+                               print "<td>",
+                                 Format_Number($MonthHits{ $YearRequired . $monthix }
+                                 ? $MonthHits{ $YearRequired . $monthix }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowMonthStats =~ /B/i ) {
+                               print "<td>",
+                                 Format_Bytes(
+                                       int( $MonthBytes{ $YearRequired . $monthix } || 0 )
+                                 ), "</td>";
                        }
-                       next;
+                       print "</tr>\n";
                }
 
-# Now @dateparts is (DD,MM,YYYY,HH,MM,SS) and we're going to create $timerecord=YYYYMMDDHHMMSS
-               if ( $PluginsLoaded{'ChangeTime'}{'timezone'} ) {
-                       @dateparts = ChangeTime_timezone( \@dateparts );
+               # Average row
+               # TODO
+               # Total row
+               print
+"<tr><td bgcolor=\"#$color_TableBGRowTitle\">$Message[102]</td>";
+               if ( $ShowMonthStats =~ /U/i ) {
+                       print
+                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_u)."</td>";
                }
-               my $yearrecord  = int( $dateparts[2] );
-               my $monthrecord = int( $dateparts[1] );
-               my $dayrecord   = int( $dateparts[0] );
-               my $hourrecord  = int( $dateparts[3] );
-               my $daterecord  = '';
-               if ( $DatabaseBreak eq 'month' ) {
-                       $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
+               if ( $ShowMonthStats =~ /V/i ) {
+                       print
+                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_v)."</td>";
                }
-               elsif ( $DatabaseBreak eq 'year' ) {
-                       $daterecord = sprintf( "%04i%", $yearrecord );
+               if ( $ShowMonthStats =~ /P/i ) {
+                       print
+                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_p)."</td>";
                }
-               elsif ( $DatabaseBreak eq 'day' ) {
-                       $daterecord =
-                         sprintf( "%04i%02i%02i", $yearrecord, $monthrecord, $dayrecord );
+               if ( $ShowMonthStats =~ /H/i ) {
+                       print
+                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_h)."</td>";
                }
-               elsif ( $DatabaseBreak eq 'hour' ) {
-                       $daterecord = sprintf( "%04i%02i%02i%02i",
-                               $yearrecord, $monthrecord, $dayrecord, $hourrecord );
+               if ( $ShowMonthStats =~ /B/i ) {
+                       print "<td bgcolor=\"#$color_TableBGRowTitle\">"
+                         . Format_Bytes($total_k) . "</td>";
                }
+               print "</tr>\n";
+               print "</table>\n<br />\n";
+       }
 
-               # TODO essayer de virer yearmonthrecord
-               my $yearmonthdayrecord =
-                 sprintf( "$dateparts[2]%02i%02i", $dateparts[1], $dateparts[0] );
-               my $timerecord =
-                 ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
-                         $dateparts[4] ) * 100 + $dateparts[5];
+       print "</center>\n";
+       print "</td></tr>\n";
+       &tab_end();
+}
 
-               # Check date
-               #-----------------------
-               if ( $LogType eq 'M' && $timerecord > $tomorrowtime ) {
+#------------------------------------------------------------------------------
+# Function:     Prints the Daily section on the main page
+# Parameters:   $firstdaytocountaverage, $lastdaytocountaverage
+#                              $firstdaytoshowtime, $lastdaytoshowtime
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainDaily{
+       my $firstdaytocountaverage = shift;
+       my $lastdaytocountaverage = shift;
+       my $firstdaytoshowtime = shift;
+       my $lastdaytoshowtime = shift;
+       
+       if ($Debug) { debug( "ShowDaysOfMonthStats", 2 ); }
+       print "$Center<a name=\"daysofmonth\">&nbsp;</a><br />\n";
+       my $title = "$Message[138]";
+       &tab_head( "$title", 0, 0, 'daysofmonth' );
+       print "<tr>";
+       print "<td align=\"center\">\n";
+       print "<center>\n";
 
-# Postfix/Sendmail does not store year, so we assume that year is year-1 if record is in future
-                       $yearrecord--;
-                       if ( $DatabaseBreak eq 'month' ) {
-                               $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
-                       }
-                       elsif ( $DatabaseBreak eq 'year' ) {
-                               $daterecord = sprintf( "%04i%", $yearrecord );
-                       }
-                       elsif ( $DatabaseBreak eq 'day' ) {
-                               $daterecord = sprintf( "%04i%02i%02i",
-                                       $yearrecord, $monthrecord, $dayrecord );
-                       }
-                       elsif ( $DatabaseBreak eq 'hour' ) {
-                               $daterecord = sprintf( "%04i%02i%02i%02i",
-                                       $yearrecord, $monthrecord, $dayrecord, $hourrecord );
-                       }
+       my $NewLinkParams = ${QueryString};
+       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
+       $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
+       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+       $NewLinkParams =~ s/^&amp;//;
+       $NewLinkParams =~ s/&amp;$//;
+       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
+       my $NewLinkTarget = '';
 
-                       # TODO essayer de virer yearmonthrecord
-                       $yearmonthdayrecord =
-                         sprintf( "$yearrecord%02i%02i", $dateparts[1], $dateparts[0] );
-                       $timerecord =
-                         ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
-                                 $dateparts[4] ) * 100 + $dateparts[5];
+       if ( $FrameName eq 'mainright' ) {
+               $NewLinkTarget = " target=\"_parent\"";
+       }
+
+       my $average_v = my $average_p = 0;
+       my $average_h = my $average_k = 0;
+       my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
+       my $max_v = my $max_h = my $max_k = 0;    # Start from 0 because can be lower than 1
+       foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
+       {
+               $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+               my $year  = $1;
+               my $month = $2;
+               my $day   = $3;
+               if ( !DateIsValid( $day, $month, $year ) ) {
+                       next;
+               }    # If not an existing day, go to next
+               $total_v += $DayVisits{ $year . $month . $day } || 0;
+               $total_p += $DayPages{ $year . $month . $day }  || 0;
+               $total_h += $DayHits{ $year . $month . $day }   || 0;
+               $total_k += $DayBytes{ $year . $month . $day }  || 0;
+               if ( ( $DayVisits{ $year . $month . $day } || 0 ) > $max_v ) {
+                       $max_v = $DayVisits{ $year . $month . $day };
                }
-               if ( $timerecord < 10000000000000 || $timerecord > $tomorrowtime ) {
-                       $NbOfLinesCorrupted++;
-                       if ($ShowCorrupted) {
-                               print
-"Corrupted record (invalid date, timerecord=$timerecord): $line\n";
-                       }
-                       next;   # Should not happen, kept in case of parasite/corrupted line
+
+#if (($DayPages{$year.$month.$day}||0) > $max_p)  { $max_p=$DayPages{$year.$month.$day}; }
+               if ( ( $DayHits{ $year . $month . $day } || 0 ) > $max_h ) {
+                       $max_h = $DayHits{ $year . $month . $day };
                }
-               if ($NewLinePhase) {
+               if ( ( $DayBytes{ $year . $month . $day } || 0 ) > $max_k ) {
+                       $max_k = $DayBytes{ $year . $month . $day };
+               }
+       }
 
-                       # TODO NOTSORTEDRECORDTOLERANCE does not work around midnight
-                       if ( $timerecord < ( $LastLine - $NOTSORTEDRECORDTOLERANCE ) ) {
+       # Show bars for day
+       my $graphdone=0;
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+       {
+               my @blocklabel = ();
+               foreach
+                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
+               {
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
+                               next;
+                       }    # If not an existing day, go to next
+                       my $bold =
+                         (      $day == $nowday
+                                 && $month == $nowmonth
+                                 && $year == $nowyear ? ':' : '' );
+                       my $weekend =
+                         ( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' );
+                       push @blocklabel,
+                         "$day\n$MonthNumLib{$month}$weekend$bold";
+               }
+               my @vallabel = (
+                       "$Message[10]", "$Message[56]",
+                       "$Message[57]", "$Message[75]"
+               );
+               my @valcolor =
+                 ( "$color_v", "$color_p", "$color_h", "$color_k" );
+               my @valmax   = ( $max_v,   $max_h,   $max_h,   $max_k );
+               my @valtotal = ( $total_v, $total_p, $total_h, $total_k );
+               $average_v = sprintf( "%.2f", $AverageVisits );
+               $average_p = sprintf( "%.2f", $AveragePages );
+               $average_h = sprintf( "%.2f", $AverageHits );
+               $average_k = (
+                       int($average_k)
+                       ? Format_Bytes( sprintf( "%.2f", $AverageBytes ) )
+                       : "0.00"
+               );
+               my @valaverage =
+                 ( $average_v, $average_p, $average_h, $average_k );
+               my @valdata = ();
+               my $xx      = 0;
 
-                               # Should not happen, kept in case of parasite/corrupted old line
-                               $NbOfLinesCorrupted++;
-                               if ($ShowCorrupted) {
-                                       print
-"Corrupted record (date $timerecord lower than $LastLine-$NOTSORTEDRECORDTOLERANCE): $line\n";
-                               }
+               foreach
+                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
+               {
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
                                next;
-                       }
-               }
-               else {
-                       if ( $timerecord <= $LastLine ) {    # Already processed
-                               $NbOfOldLines++;
+                       }    # If not an existing day, go to next
+                       $valdata[ $xx++ ] = $DayVisits{ $year . $month . $day }
+                         || 0;
+                       $valdata[ $xx++ ] = $DayPages{ $year . $month . $day } || 0;
+                       $valdata[ $xx++ ] = $DayHits{ $year . $month . $day }  || 0;
+                       $valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0;
+               }
+               my $function = "ShowGraph_$pluginname";
+               &$function(
+                       "$title",              "daysofmonth",
+                       $ShowDaysOfMonthStats, \@blocklabel,
+                       \@vallabel,            \@valcolor,
+                       \@valmax,              \@valtotal,
+                       \@valaverage,          \@valdata
+               );
+               $graphdone=1;
+       }
+       if (! $graphdone) {
+               print "<table>\n";
+               print "<tr valign=\"bottom\">\n";
+               foreach
+                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
+               {
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
                                next;
+                       }    # If not an existing day, go to next
+                       my $bredde_v = 0;
+                       my $bredde_p = 0;
+                       my $bredde_h = 0;
+                       my $bredde_k = 0;
+                       if ( $max_v > 0 ) {
+                               $bredde_v =
+                                 int( ( $DayVisits{ $year . $month . $day } || 0 ) /
+                                         $max_v * $BarHeight ) + 1;
+                       }
+                       if ( $max_h > 0 ) {
+                               $bredde_p =
+                                 int( ( $DayPages{ $year . $month . $day } || 0 ) /
+                                         $max_h * $BarHeight ) + 1;
+                       }
+                       if ( $max_h > 0 ) {
+                               $bredde_h =
+                                 int( ( $DayHits{ $year . $month . $day } || 0 ) /
+                                         $max_h * $BarHeight ) + 1;
+                       }
+                       if ( $max_k > 0 ) {
+                               $bredde_k =
+                                 int( ( $DayBytes{ $year . $month . $day } || 0 ) /
+                                         $max_k * $BarHeight ) + 1;
+                       }
+                       print "<td>";
+                       if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
+                                 . AltTitle( "$Message[10]: "
+                                         . int( $DayVisits{ $year . $month . $day } || 0 )
+                                 )
+                                 . " />";
                        }
-
-# We found a new line. This will replace comparison "<=" with "<" between timerecord and LastLine (we should have only new lines now)
-                       $NewLinePhase = 1;    # We will never enter here again
-                       if ($ShowSteps) {
-                               if ( $NbOfLinesShowsteps > 1
-                                       && ( $NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) )
-                               {
-                                       my $delay = &GetDelaySinceStart(0);
-                                       print ""
-                                         . ( $NbOfLinesParsed - 1 )
-                                         . " lines processed ("
-                                         . ( $delay > 0 ? $delay : 1000 ) . " ms, "
-                                         . int( 1000 * ( $NbOfLinesShowsteps - 1 ) /
-                                                 ( $delay > 0 ? $delay : 1000 ) )
-                                         . " lines/second)\n";
-                               }
-                               &GetDelaySinceStart(1);
-                               $NbOfLinesShowsteps = 1;
-                       }
-                       if ( !scalar keys %HTMLOutput ) {
+                       if ( $ShowDaysOfMonthStats =~ /P/i ) {
                                print
-"Phase 2 : Now process new records (Flush history on disk after "
-                                 . ( $LIMITFLUSH << 2 )
-                                 . " hosts)...\n";
-
-#print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts or ".($LIMITFLUSH)." URLs)...\n";
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
+                                 . AltTitle( "$Message[56]: "
+                                         . int( $DayPages{ $year . $month . $day } || 0 ) )
+                                 . " />";
+                       }
+                       if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
+                                 . AltTitle( "$Message[57]: "
+                                         . int( $DayHits{ $year . $month . $day } || 0 ) )
+                                 . " />";
+                       }
+                       if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
+                                 . AltTitle(
+                                       "$Message[75]: "
+                                         . Format_Bytes(
+                                               $DayBytes{ $year . $month . $day }
+                                         )
+                                 )
+                                 . " />";
                        }
+                       print "</td>\n";
                }
+               print "<td>&nbsp;</td>";
 
-               # Convert URL for Webstar to common URL
-               if ( $LogFormat eq '3' ) {
-                       $field[$pos_url] =~ s/:/\//g;
-                       if ( $field[$pos_code] eq '-' ) { $field[$pos_code] = '200'; }
+               # Show average value cell
+               print "<td>";
+               my $bredde_v = 0;
+               my $bredde_p = 0;
+               my $bredde_h = 0;
+               my $bredde_k = 0;
+               if ( $max_v > 0 ) {
+                       $bredde_v = int( $average_v / $max_v * $BarHeight ) + 1;
                }
-
-# Here, field array, timerecord and yearmonthdayrecord are initialized for log record
-               if ($Debug) {
-                       debug( "  This is a not already processed record ($timerecord)",
-                               4 );
+               if ( $max_h > 0 ) {
+                       $bredde_p = int( $average_p / $max_h * $BarHeight ) + 1;
                }
-
-               # We found a new line
-               #----------------------------------------
-               if ( $timerecord > $LastLine ) {
-                       $LastLine = $timerecord;
-               }    # Test should always be true except with not sorted log files
-
-               # Skip for some client host IP addresses, some URLs, other URLs
-               if (
-                       @SkipHosts
-                       && ( &SkipHost( $field[$pos_host] )
-                               || ( $pos_hostr && &SkipHost( $field[$pos_hostr] ) ) )
-                 )
-               {
-                       $qualifdrop =
-                           "Dropped record (host $field[$pos_host]"
-                         . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
-                         . " not qualified by SkipHosts)";
+               if ( $max_h > 0 ) {
+                       $bredde_h = int( $average_h / $max_h * $BarHeight ) + 1;
                }
-               elsif ( @SkipFiles && &SkipFile( $field[$pos_url] ) ) {
-                       $qualifdrop =
-"Dropped record (URL $field[$pos_url] not qualified by SkipFiles)";
+               if ( $max_k > 0 ) {
+                       $bredde_k = int( $average_k / $max_k * $BarHeight ) + 1;
+               }
+               $average_v = sprintf( "%.2f", $average_v );
+               $average_p = sprintf( "%.2f", $average_p );
+               $average_h = sprintf( "%.2f", $average_h );
+               $average_k = (
+                       int($average_k)
+                       ? Format_Bytes( sprintf( "%.2f", $average_k ) )
+                       : "0.00"
+               );
+               if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                       print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
+                         . AltTitle("$Message[10]: $average_v") . " />";
                }
-               elsif (@SkipUserAgents
-                       && $pos_agent >= 0
-                       && &SkipUserAgent( $field[$pos_agent] ) )
-               {
-                       $qualifdrop =
-"Dropped record (user agent '$field[$pos_agent]' not qualified by SkipUserAgents)";
+               if ( $ShowDaysOfMonthStats =~ /P/i ) {
+                       print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
+                         . AltTitle("$Message[56]: $average_p") . " />";
                }
-               elsif (@SkipReferrers
-                       && $pos_referer >= 0
-                       && &SkipReferrer( $field[$pos_referer] ) )
+               if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                       print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
+                         . AltTitle("$Message[57]: $average_h") . " />";
+               }
+               if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                       print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
+                         . AltTitle("$Message[75]: $average_k") . " />";
+               }
+               print "</td>\n";
+               print "</tr>\n";
+
+               # Show lib for day
+               print "<tr valign=\"middle\">";
+               foreach
+                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
                {
-                       $qualifdrop =
-"Dropped record (URL $field[$pos_referer] not qualified by SkipReferrers)";
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
+                               next;
+                       }    # If not an existing day, go to next
+                       my $dayofweekcursor = DayOfWeek( $day, $month, $year );
+                       print "<td"
+                         . (
+                               $dayofweekcursor =~ /[06]/
+                               ? " bgcolor=\"#$color_weekend\""
+                               : ""
+                         )
+                         . ">";
+                       print(
+                               !$StaticLinks
+                                 && $day == $nowday
+                                 && $month == $nowmonth
+                                 && $year == $nowyear
+                               ? '<font class="currentday">'
+                               : ''
+                       );
+                       print "$day<br /><span style=\"font-size: "
+                         . (    $FrameName ne 'mainright'
+                                 && $QueryString !~ /buildpdf/i ? "9" : "8" )
+                         . "px;\">"
+                         . $MonthNumLib{$month}
+                         . "</span>";
+                       print(   !$StaticLinks
+                                 && $day == $nowday
+                                 && $month == $nowmonth
+                                 && $year == $nowyear ? '</font>' : '' );
+                       print "</td>\n";
                }
-               elsif (@OnlyHosts
-                       && !&OnlyHost( $field[$pos_host] )
-                       && ( !$pos_hostr || !&OnlyHost( $field[$pos_hostr] ) ) )
+               print "<td>&nbsp;</td>";
+               print "<td valign=\"middle\""
+                 . Tooltip(18)
+                 . ">$Message[96]</td>\n";
+               print "</tr>\n";
+               print "</table>\n";
+       }
+       print "<br />\n";
+
+       # Show data array for days
+       if ($AddDataArrayShowDaysOfMonthStats) {
+               print "<table>\n";
+               print
+"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
+               if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_v\""
+                         . Tooltip(1)
+                         . ">$Message[10]</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /P/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_p\""
+                         . Tooltip(3)
+                         . ">$Message[56]</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_h\""
+                         . Tooltip(4)
+                         . ">$Message[57]</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_k\""
+                         . Tooltip(5)
+                         . ">$Message[75]</td>";
+               }
+               print "</tr>";
+               foreach
+                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
                {
-                       $qualifdrop =
-                           "Dropped record (host $field[$pos_host]"
-                         . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
-                         . " not qualified by OnlyHosts)";
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
+                               next;
+                       }    # If not an existing day, go to next
+                       my $dayofweekcursor = DayOfWeek( $day, $month, $year );
+                       print "<tr"
+                         . (
+                               $dayofweekcursor =~ /[06]/
+                               ? " bgcolor=\"#$color_weekend\""
+                               : ""
+                         )
+                         . ">";
+                       print "<td>"
+                         . (
+                               !$StaticLinks
+                                 && $day == $nowday
+                                 && $month == $nowmonth
+                                 && $year == $nowyear
+                               ? '<font class="currentday">'
+                               : ''
+                         );
+                       print Format_Date( "$year$month$day" . "000000", 2 );
+                       print(   !$StaticLinks
+                                 && $day == $nowday
+                                 && $month == $nowmonth
+                                 && $year == $nowyear ? '</font>' : '' );
+                       print "</td>";
+                       if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                               print "<td>",
+                                 Format_Number($DayVisits{ $year . $month . $day }
+                                 ? $DayVisits{ $year . $month . $day }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowDaysOfMonthStats =~ /P/i ) {
+                               print "<td>",
+                                 Format_Number($DayPages{ $year . $month . $day }
+                                 ? $DayPages{ $year . $month . $day }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                               print "<td>",
+                                 Format_Number($DayHits{ $year . $month . $day }
+                                 ? $DayHits{ $year . $month . $day }
+                                 : "0"), "</td>";
+                       }
+                       if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                               print "<td>",
+                                 Format_Bytes(
+                                       int( $DayBytes{ $year . $month . $day } || 0 ) ),
+                                 "</td>";
+                       }
+                       print "</tr>\n";
                }
-               elsif ( @OnlyUsers && !&OnlyUser( $field[$pos_logname] ) ) {
-                       $qualifdrop =
-"Dropped record (URL $field[$pos_logname] not qualified by OnlyUsers)";
+
+               # Average row
+               print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[96]</td>";
+               if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                       print "<td>".Format_Number($average_v)."</td>";
                }
-               elsif ( @OnlyFiles && !&OnlyFile( $field[$pos_url] ) ) {
-                       $qualifdrop =
-"Dropped record (URL $field[$pos_url] not qualified by OnlyFiles)";
+               if ( $ShowDaysOfMonthStats =~ /P/i ) {
+                       print "<td>".Format_Number($average_p)."</td>";
                }
-               elsif ( @OnlyUserAgents && !&OnlyUserAgent( $field[$pos_agent] ) ) {
-                       $qualifdrop =
-"Dropped record (user agent '$field[$pos_agent]' not qualified by OnlyUserAgents)";
+               if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                       print "<td>".Format_Number($average_h)."</td>";
                }
-               if ($qualifdrop) {
-                       $NbOfLinesDropped++;
-                       if ($Debug) { debug( "$qualifdrop: $line", 4 ); }
-                       if ($ShowDropped) { print "$qualifdrop: $line\n"; }
-                       $qualifdrop = '';
-                       next;
+               if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                       print "<td>".Format_Number($average_k)."</td>";
                }
+               print "</tr>\n";
 
-               # Record is approved
-               #-------------------
+               # Total row
+               print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[102]</td>";
+               if ( $ShowDaysOfMonthStats =~ /V/i ) {
+                       print "<td>".Format_Number($total_v)."</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /P/i ) {
+                       print "<td>".Format_Number($total_p)."</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /H/i ) {
+                       print "<td>".Format_Number($total_h)."</td>";
+               }
+               if ( $ShowDaysOfMonthStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($total_k) . "</td>";
+               }
+               print "</tr>\n";
+               print "</table>\n<br />";
+       }
 
-               # Is it in a new break section ?
-               #-------------------------------
-               if ( $daterecord > $lastprocesseddate ) {
+       print "</center>\n";
+       print "</td></tr>\n";
+       &tab_end();
+}
 
-                       # A new break to process
-                       if ( $lastprocesseddate > 0 ) {
+#------------------------------------------------------------------------------
+# Function:     Prints the Days of the Week section on the main page
+# Parameters:   $firstdaytocountaverage, $lastdaytocountaverage
+# Input:        _
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainDaysofWeek{
+       my $firstdaytocountaverage = shift;
+       my $lastdaytocountaverage = shift;
+       if ($Debug) { debug( "ShowDaysOfWeekStats", 2 ); }
+                       print "$Center<a name=\"daysofweek\">&nbsp;</a><br />\n";
+                       my $title = "$Message[91]";
+                       &tab_head( "$title", 18, 0, 'daysofweek' );
+                       print "<tr>";
+                       print "<td align=\"center\">";
+                       print "<center>\n";
 
-                               # We save data of previous break
-                               &Read_History_With_TmpUpdate(
-                                       $lastprocessedyear, $lastprocessedmonth,
-                                       $lastprocessedday,  $lastprocessedhour,
-                                       1,                  1,
-                                       "all", ( $lastlinenb + $NbOfLinesParsed ),
-                                       $lastlineoffset, &CheckSum($line)
-                               );
-                               $counterforflushtest = 0;    # We reset counterforflushtest
-                       }
-                       $lastprocessedyear  = $yearrecord;
-                       $lastprocessedmonth = $monthrecord;
-                       $lastprocessedday   = $dayrecord;
-                       $lastprocessedhour  = $hourrecord;
-                       if ( $DatabaseBreak eq 'month' ) {
-                               $lastprocesseddate =
-                                 sprintf( "%04i%02i", $yearrecord, $monthrecord );
-                       }
-                       elsif ( $DatabaseBreak eq 'year' ) {
-                               $lastprocesseddate = sprintf( "%04i%", $yearrecord );
-                       }
-                       elsif ( $DatabaseBreak eq 'day' ) {
-                               $lastprocesseddate = sprintf( "%04i%02i%02i",
-                                       $yearrecord, $monthrecord, $dayrecord );
+                       my $max_h = my $max_k = 0;    # Start from 0 because can be lower than 1
+                                               # Get average value for day of week
+                       my @avg_dayofweek_nb = ();
+                       my @avg_dayofweek_p  = ();
+                       my @avg_dayofweek_h  = ();
+                       my @avg_dayofweek_k  = ();
+                       foreach my $daycursor (
+                               $firstdaytocountaverage .. $lastdaytocountaverage )
+                       {
+                               $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                               my $year  = $1;
+                               my $month = $2;
+                               my $day   = $3;
+                               if ( !DateIsValid( $day, $month, $year ) ) {
+                                       next;
+                               }    # If not an existing day, go to next
+                               my $dayofweekcursor = DayOfWeek( $day, $month, $year );
+                               $avg_dayofweek_nb[$dayofweekcursor]
+                                 ++; # Increase number of day used to count for this day of week
+                               $avg_dayofweek_p[$dayofweekcursor] +=
+                                 ( $DayPages{$daycursor} || 0 );
+                               $avg_dayofweek_h[$dayofweekcursor] +=
+                                 ( $DayHits{$daycursor} || 0 );
+                               $avg_dayofweek_k[$dayofweekcursor] +=
+                                 ( $DayBytes{$daycursor} || 0 );
                        }
-                       elsif ( $DatabaseBreak eq 'hour' ) {
-                               $lastprocesseddate = sprintf( "%04i%02i%02i%02i",
-                                       $yearrecord, $monthrecord, $dayrecord, $hourrecord );
+                       for (@DOWIndex) {
+                               if ( $avg_dayofweek_nb[$_] ) {
+                                       $avg_dayofweek_p[$_] =
+                                         $avg_dayofweek_p[$_] / $avg_dayofweek_nb[$_];
+                                       $avg_dayofweek_h[$_] =
+                                         $avg_dayofweek_h[$_] / $avg_dayofweek_nb[$_];
+                                       $avg_dayofweek_k[$_] =
+                                         $avg_dayofweek_k[$_] / $avg_dayofweek_nb[$_];
+
+                 #if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
+                                       if ( $avg_dayofweek_h[$_] > $max_h ) {
+                                               $max_h = $avg_dayofweek_h[$_];
+                                       }
+                                       if ( $avg_dayofweek_k[$_] > $max_k ) {
+                                               $max_k = $avg_dayofweek_k[$_];
+                                       }
+                               }
+                               else {
+                                       $avg_dayofweek_p[$_] = "?";
+                                       $avg_dayofweek_h[$_] = "?";
+                                       $avg_dayofweek_k[$_] = "?";
+                               }
                        }
-               }
 
-               $countedtraffic = 0;
-               $NbOfNewLines++;
+                       # Show bars for days of week
+                       my $graphdone=0;
+                       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+                       {
+                               my @blocklabel = ();
+                               for (@DOWIndex) {
+                                       push @blocklabel,
+                                         ( $Message[ $_ + 84 ] . ( $_ =~ /[06]/ ? "!" : "" ) );
+                               }
+                               my @vallabel =
+                                 ( "$Message[56]", "$Message[57]", "$Message[75]" );
+                               my @valcolor = ( "$color_p", "$color_h", "$color_k" );
+                               my @valmax = ( int($max_h), int($max_h), int($max_k) );
+                               my @valtotal = ( $TotalPages, $TotalHits, $TotalBytes );
+                               # TEMP
+                               my $average_p = my $average_h = my $average_k = 0;
+                               $average_p = sprintf( "%.2f", $AveragePages );
+                               $average_h = sprintf( "%.2f", $AverageHits );
+                               $average_k = (
+                                       int($average_k)
+                                       ? Format_Bytes( sprintf( "%.2f", $AverageBytes ) )
+                                       : "0.00"
+                               );
+                               my @valaverage = ( $average_p, $average_h, $average_k );
+                               my @valdata    = ();
+                               my $xx         = 0;
 
-               # Convert $field[$pos_size]
-               # if ($field[$pos_size] eq '-') { $field[$pos_size]=0; }
+                               for (@DOWIndex) {
+                                       $valdata[ $xx++ ] = $avg_dayofweek_p[$_] || 0;
+                                       $valdata[ $xx++ ] = $avg_dayofweek_h[$_] || 0;
+                                       $valdata[ $xx++ ] = $avg_dayofweek_k[$_] || 0;
 
-       # Define a clean target URL and referrer URL
-       # We keep a clean $field[$pos_url] and
-       # we store original value for urlwithnoquery, tokenquery and standalonequery
-       #---------------------------------------------------------------------------
-               if ($URLNotCaseSensitive) { $field[$pos_url] = lc( $field[$pos_url] ); }
-
-# Possible URL syntax for $field[$pos_url]: /mydir/mypage.ext?param1=x&param2=y#aaa, /mydir/mypage.ext#aaa, /
-               my $urlwithnoquery;
-               my $tokenquery;
-               my $standalonequery;
-               my $anchor = '';
-               if ( $field[$pos_url] =~ s/$regtruncanchor//o ) {
-                       $anchor = $1;
-               }    # Remove and save anchor
-               if ($URLWithQuery) {
-                       $urlwithnoquery = $field[$pos_url];
-                       my $foundparam = ( $urlwithnoquery =~ s/$regtruncurl//o );
-                       $tokenquery      = $1 || '';
-                       $standalonequery = $2 || '';
-
-# For IIS setup, if pos_query is enabled we need to combine the URL to query strings
-                       if (   !$foundparam
-                               && $pos_query >= 0
-                               && $field[$pos_query]
-                               && $field[$pos_query] ne '-' )
-                       {
-                               $foundparam      = 1;
-                               $tokenquery      = '?';
-                               $standalonequery = $field[$pos_query];
-
-                               # Define query
-                               $field[$pos_url] .= '?' . $field[$pos_query];
-                       }
-                       if ($foundparam) {
+                                       # Round to be ready to show array
+                                       $avg_dayofweek_p[$_] =
+                                         sprintf( "%.2f", $avg_dayofweek_p[$_] );
+                                       $avg_dayofweek_h[$_] =
+                                         sprintf( "%.2f", $avg_dayofweek_h[$_] );
+                                       $avg_dayofweek_k[$_] =
+                                         sprintf( "%.2f", $avg_dayofweek_k[$_] );
 
-  # Keep only params that are defined in URLWithQueryWithOnlyFollowingParameters
-                               my $newstandalonequery = '';
-                               if (@URLWithQueryWithOnly) {
-                                       foreach (@URLWithQueryWithOnly) {
-                                               foreach my $p ( split( /&/, $standalonequery ) ) {
-                                                       if ($URLNotCaseSensitive) {
-                                                               if ( $p =~ /^$_=/i ) {
-                                                                       $newstandalonequery .= "$p&";
-                                                                       last;
-                                                               }
-                                                       }
-                                                       else {
-                                                               if ( $p =~ /^$_=/ ) {
-                                                                       $newstandalonequery .= "$p&";
-                                                                       last;
-                                                               }
-                                                       }
-                                               }
+                                       # Remove decimal part that are .0
+                                       if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
+                                               $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
+                                       }
+                                       if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
+                                               $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
                                        }
-                                       chop $newstandalonequery;
                                }
+                               my $function = "ShowGraph_$pluginname";
+                               &$function(
+                                       "$title",             "daysofweek",
+                                       $ShowDaysOfWeekStats, \@blocklabel,
+                                       \@vallabel,           \@valcolor,
+                                       \@valmax,             \@valtotal,
+                                       \@valaverage,         \@valdata
+                               );
+                               $graphdone=1;
+                       }
+                       if (! $graphdone) 
+                       {
+                               print "<table>\n";
+                               print "<tr valign=\"bottom\">\n";
+                               for (@DOWIndex) {
+                                       my $bredde_p = 0;
+                                       my $bredde_h = 0;
+                                       my $bredde_k = 0;
+                                       if ( $max_h > 0 ) {
+                                               $bredde_p = int(
+                                                       (
+                                                                 $avg_dayofweek_p[$_] ne '?'
+                                                               ? $avg_dayofweek_p[$_]
+                                                               : 0
+                                                       ) / $max_h * $BarHeight
+                                               ) + 1;
+                                       }
+                                       if ( $max_h > 0 ) {
+                                               $bredde_h = int(
+                                                       (
+                                                                 $avg_dayofweek_h[$_] ne '?'
+                                                               ? $avg_dayofweek_h[$_]
+                                                               : 0
+                                                       ) / $max_h * $BarHeight
+                                               ) + 1;
+                                       }
+                                       if ( $max_k > 0 ) {
+                                               $bredde_k = int(
+                                                       (
+                                                                 $avg_dayofweek_k[$_] ne '?'
+                                                               ? $avg_dayofweek_k[$_]
+                                                               : 0
+                                                       ) / $max_k * $BarHeight
+                                               ) + 1;
+                                       }
+                                       $avg_dayofweek_p[$_] = sprintf(
+                                               "%.2f",
+                                               (
+                                                         $avg_dayofweek_p[$_] ne '?'
+                                                       ? $avg_dayofweek_p[$_]
+                                                       : 0
+                                               )
+                                       );
+                                       $avg_dayofweek_h[$_] = sprintf(
+                                               "%.2f",
+                                               (
+                                                         $avg_dayofweek_h[$_] ne '?'
+                                                       ? $avg_dayofweek_h[$_]
+                                                       : 0
+                                               )
+                                       );
+                                       $avg_dayofweek_k[$_] = sprintf(
+                                               "%.2f",
+                                               (
+                                                         $avg_dayofweek_k[$_] ne '?'
+                                                       ? $avg_dayofweek_k[$_]
+                                                       : 0
+                                               )
+                                       );
 
-# Remove params that are marked to be ignored in URLWithQueryWithoutFollowingParameters
-                               elsif (@URLWithQueryWithout) {
-                                       foreach my $p ( split( /&/, $standalonequery ) ) {
-                                               my $found = 0;
-                                               foreach (@URLWithQueryWithout) {
-
-#if ($Debug) { debug("  Check if '$_=' is param '$p' to remove it from query",5); }
-                                                       if ($URLNotCaseSensitive) {
-                                                               if ( $p =~ /^$_=/i ) { $found = 1; last; }
-                                                       }
-                                                       else {
-                                                               if ( $p =~ /^$_=/ ) { $found = 1; last; }
-                                                       }
-                                               }
-                                               if ( !$found ) { $newstandalonequery .= "$p&"; }
+                                       # Remove decimal part that are .0
+                                       if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
+                                               $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
                                        }
-                                       chop $newstandalonequery;
+                                       if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
+                                               $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
+                                       }
+                                       print "<td valign=\"bottom\">";
+                                       if ( $ShowDaysOfWeekStats =~ /P/i ) {
+                                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
+                                                 . AltTitle("$Message[56]: $avg_dayofweek_p[$_]")
+                                                 . " />";
+                                       }
+                                       if ( $ShowDaysOfWeekStats =~ /H/i ) {
+                                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
+                                                 . AltTitle("$Message[57]: $avg_dayofweek_h[$_]")
+                                                 . " />";
+                                       }
+                                       if ( $ShowDaysOfWeekStats =~ /B/i ) {
+                                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
+                                                 . AltTitle( "$Message[75]: "
+                                                         . Format_Bytes( $avg_dayofweek_k[$_] ) )
+                                                 . " />";
+                                       }
+                                       print "</td>\n";
                                }
-                               else { $newstandalonequery = $standalonequery; }
-
-                               # Define query
-                               $field[$pos_url] = $urlwithnoquery;
-                               if ($newstandalonequery) {
-                                       $field[$pos_url] .= "$tokenquery$newstandalonequery";
+                               print "</tr>\n";
+                               print "<tr" . Tooltip(17) . ">\n";
+                               for (@DOWIndex) {
+                                       print "<td"
+                                         . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
+                                         . ">"
+                                         . (
+                                               !$StaticLinks
+                                                 && $_ == ( $nowwday - 1 )
+                                                 && $MonthRequired == $nowmonth
+                                                 && $YearRequired == $nowyear
+                                               ? '<font class="currentday">'
+                                               : ''
+                                         );
+                                       print $Message[ $_ + 84 ];
+                                       print(   !$StaticLinks
+                                                 && $_ == ( $nowwday - 1 )
+                                                 && $MonthRequired == $nowmonth
+                                                 && $YearRequired == $nowyear ? '</font>' : '' );
+                                       print "</td>";
                                }
+                               print "</tr>\n</table>\n";
                        }
-               }
-               else {
-
-                       # Trunc parameters of URL
-                       $field[$pos_url] =~ s/$regtruncurl//o;
-                       $urlwithnoquery  = $field[$pos_url];
-                       $tokenquery      = $1 || '';
-                       $standalonequery = $2 || '';
-
-       # For IIS setup, if pos_query is enabled we need to use it for query strings
-                       if (   $pos_query >= 0
-                               && $field[$pos_query]
-                               && $field[$pos_query] ne '-' )
-                       {
-                               $tokenquery      = '?';
-                               $standalonequery = $field[$pos_query];
-                       }
-               }
-               if ( $URLWithAnchor && $anchor ) {
-                       $field[$pos_url] .= "#$anchor";
-               }   # Restore anchor
-                   # Here now urlwithnoquery is /mydir/mypage.ext, /mydir, /, /page#XXX
-                   # Here now tokenquery is '' or '?' or ';'
-                   # Here now standalonequery is '' or 'param1=x'
-
-               # Define page and extension
-               #--------------------------
-               my $PageBool = 1;
-
-               # Extension
-               my $extension;
-               if ( $urlwithnoquery =~ /$regext/o
-                       || ( $urlwithnoquery =~ /[\\\/]$/ && $DefaultFile[0] =~ /$regext/o )
-                 )
-               {
-                       $extension =
-                         ( $LevelForFileTypesDetection >= 2 || $MimeHashFamily{$1} )
-                         ? lc($1)
-                         : 'Unknown';
-                       if ( $NotPageList{$extension} ) { $PageBool = 0; }
-               }
-               else {
-                       $extension = 'Unknown';
-               }
-
-               if ( @NotPageFiles && &NotPageFile( $field[$pos_url] ) ) {
-                       $PageBool = 0;
-               }
+                       print "<br />\n";
 
-               # Analyze: misc tracker (must be before return code)
-               #---------------------------------------------------
-               if ( $urlwithnoquery =~ /$regmisc/o ) {
-                       if ($Debug) {
-                               debug(
-"  Found an URL that is a MiscTracker record with standalonequery=$standalonequery",
-                                       2
-                               );
-                       }
-                       my $foundparam = 0;
-                       foreach ( split( /&/, $standalonequery ) ) {
-                               if ( $_ =~ /^screen=(\d+)x(\d+)/i ) {
-                                       $foundparam++;
-                                       $_screensize_h{"$1x$2"}++;
-                                       next;
-                               }
-
-   #if ($_ =~ /cdi=(\d+)/i)                    { $foundparam++; $_screendepth_h{"$1"}++; next; }
-                               if ( $_ =~ /^nojs=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"JavascriptDisabled"}++; }
-                                       next;
-                               }
-                               if ( $_ =~ /^java=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'true' ) { $_misc_h{"JavaEnabled"}++; }
-                                       next;
-                               }
-                               if ( $_ =~ /^shk=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"DirectorSupport"}++; }
-                                       next;
-                               }
-                               if ( $_ =~ /^fla=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"FlashSupport"}++; }
-                                       next;
+                       # Show data array for days of week
+                       if ($AddDataArrayShowDaysOfWeekStats) {
+                               print "<table>\n";
+                               print
+"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
+                               if ( $ShowDaysOfWeekStats =~ /P/i ) {
+                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
+                                         . Tooltip(3)
+                                         . ">$Message[56]</td>";
                                }
-                               if ( $_ =~ /^rp=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"RealPlayerSupport"}++; }
-                                       next;
+                               if ( $ShowDaysOfWeekStats =~ /H/i ) {
+                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
+                                         . Tooltip(4)
+                                         . ">$Message[57]</td>";
                                }
-                               if ( $_ =~ /^mov=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"QuickTimeSupport"}++; }
-                                       next;
+                               if ( $ShowDaysOfWeekStats =~ /B/i ) {
+                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
+                                         . Tooltip(5)
+                                         . ">$Message[75]</td></tr>";
                                }
-                               if ( $_ =~ /^wma=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) {
-                                               $_misc_h{"WindowsMediaPlayerSupport"}++;
+                               for (@DOWIndex) {
+                                       print "<tr"
+                                         . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
+                                         . ">";
+                                       print "<td>"
+                                         . (
+                                               !$StaticLinks
+                                                 && $_ == ( $nowwday - 1 )
+                                                 && $MonthRequired == $nowmonth
+                                                 && $YearRequired == $nowyear
+                                               ? '<font class="currentday">'
+                                               : ''
+                                         );
+                                       print $Message[ $_ + 84 ];
+                                       print(   !$StaticLinks
+                                                 && $_ == ( $nowwday - 1 )
+                                                 && $MonthRequired == $nowmonth
+                                                 && $YearRequired == $nowyear ? '</font>' : '' );
+                                       print "</td>";
+                                       if ( $ShowDaysOfWeekStats =~ /P/i ) {
+                                               print "<td>", Format_Number($avg_dayofweek_p[$_]), "</td>";
                                        }
-                                       next;
-                               }
-                               if ( $_ =~ /^pdf=(\w+)/i ) {
-                                       $foundparam++;
-                                       if ( $1 eq 'y' ) { $_misc_h{"PDFSupport"}++; }
-                                       next;
+                                       if ( $ShowDaysOfWeekStats =~ /H/i ) {
+                                               print "<td>", Format_Number($avg_dayofweek_h[$_]), "</td>";
+                                       }
+                                       if ( $ShowDaysOfWeekStats =~ /B/i ) {
+                                               print "<td>", Format_Bytes( $avg_dayofweek_k[$_] ),
+                                                 "</td>";
+                                       }
+                                       print "</tr>\n";
                                }
+                               print "</table>\n<br />\n";
                        }
-                       if ($foundparam) { $_misc_h{"TotalMisc"}++; }
-               }
 
-               # Analyze: successful favicon (=> countedtraffic=1 if favicon)
-               #--------------------------------------------------
-               if ( $urlwithnoquery =~ /$regfavico/o ) {
-                       if ( $field[$pos_code] != 404 ) {
-                               $_misc_h{'AddToFavourites'}++;
+                       print "</center></td>";
+                       print "</tr>\n";
+                       &tab_end();
+}
+
+#------------------------------------------------------------------------------
+# Function:     Prints the hours chart and table
+# Parameters:   -
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainHours{
+       if ($Debug) { debug( "ShowHoursStats", 2 ); }
+       print "$Center<a name=\"hours\">&nbsp;</a><br />\n";
+       my $title = "$Message[20]";
+       if ( $PluginsLoaded{'GetTimeZoneTitle'}{'timezone'} ) {
+               $title .= " (GMT "
+                 . ( GetTimeZoneTitle_timezone() >= 0 ? "+" : "" )
+                 . int( GetTimeZoneTitle_timezone() ) . ")";
+       }
+       &tab_head( "$title", 19, 0, 'hours' );
+       print "<tr><td align=\"center\">\n";
+       print "<center>\n";
+
+       my $max_h = my $max_k = 1;
+       for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
+
+               #if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
+               if ( $_time_h[$ix] > $max_h ) { $max_h = $_time_h[$ix]; }
+               if ( $_time_k[$ix] > $max_k ) { $max_k = $_time_k[$ix]; }
+       }
+
+       # Show bars for hour
+       my $graphdone=0;
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+       {
+               my @blocklabel = ( 0 .. 23 );
+               my @vallabel   =
+                 ( "$Message[56]", "$Message[57]", "$Message[75]" );
+               my @valcolor = ( "$color_p", "$color_h", "$color_k" );
+               my @valmax = ( int($max_h), int($max_h), int($max_k) );
+               my @valtotal   = ( $TotalPages,   $TotalHits,   $TotalBytes );
+               my @valaverage = ( $AveragePages, $AverageHits, $AverageBytes );
+               my @valdata    = ();
+               my $xx         = 0;
+               for ( 0 .. 23 ) {
+                       $valdata[ $xx++ ] = $_time_p[$_] || 0;
+                       $valdata[ $xx++ ] = $_time_h[$_] || 0;
+                       $valdata[ $xx++ ] = $_time_k[$_] || 0;
+               }
+               my $function = "ShowGraph_$pluginname";
+               &$function(
+                       "$title",        "hours",
+                       $ShowHoursStats, \@blocklabel,
+                       \@vallabel,      \@valcolor,
+                       \@valmax,        \@valtotal,
+                       \@valaverage,    \@valdata
+               );
+               $graphdone=1;
+       }
+       if (! $graphdone) 
+       {
+               print "<table>\n";
+               print "<tr valign=\"bottom\">\n";
+               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
+                       my $bredde_p = 0;
+                       my $bredde_h = 0;
+                       my $bredde_k = 0;
+                       if ( $max_h > 0 ) {
+                               $bredde_p =
+                                 int( $BarHeight * $_time_p[$ix] / $max_h ) + 1;
+                       }
+                       if ( $max_h > 0 ) {
+                               $bredde_h =
+                                 int( $BarHeight * $_time_h[$ix] / $max_h ) + 1;
+                       }
+                       if ( $max_k > 0 ) {
+                               $bredde_k =
+                                 int( $BarHeight * $_time_k[$ix] / $max_k ) + 1;
+                       }
+                       print "<td>";
+                       if ( $ShowHoursStats =~ /P/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
+                                 . AltTitle( "$Message[56]: " . int( $_time_p[$ix] ) )
+                                 . " />";
                        }
-                       $countedtraffic =
-                         1;    # favicon is a case that must not be counted anywhere else
-                       $_time_nv_h[$hourrecord]++;
-                       if ( $field[$pos_code] != 404 ) {
-                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
+                       if ( $ShowHoursStats =~ /H/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
+                                 . AltTitle( "$Message[57]: " . int( $_time_h[$ix] ) )
+                                 . " />";
+                       }
+                       if ( $ShowHoursStats =~ /B/i ) {
+                               print
+"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
+                                 . AltTitle(
+                                       "$Message[75]: " . Format_Bytes( $_time_k[$ix] ) )
+                                 . " />";
                        }
+                       print "</td>\n";
                }
+               print "</tr>\n";
 
-               # Analyze: Worms (=> countedtraffic=2 if worm)
-               #---------------------------------------------
-               if ( !$countedtraffic ) {
-                       if ($LevelForWormsDetection) {
-                               foreach (@WormsSearchIDOrder) {
-                                       if ( $field[$pos_url] =~ /$_/ ) {
+               # Show hour lib
+               print "<tr" . Tooltip(17) . ">";
+               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
+                       print "<th width=\"19\">$ix</th>\n"
+                         ;   # width=19 instead of 18 to avoid a MacOS browser bug.
+               }
+               print "</tr>\n";
 
-                                               # It's a worm
-                                               my $worm = &UnCompileRegex($_);
-                                               if ($Debug) {
-                                                       debug(
-" Record is a hit from a worm identified by '$worm'",
-                                                               2
-                                                       );
-                                               }
-                                               $worm = $WormsHashID{$worm} || 'unknown';
-                                               $_worm_h{$worm}++;
-                                               $_worm_k{$worm} += int( $field[$pos_size] );
-                                               $_worm_l{$worm} = $timerecord;
-                                               $countedtraffic = 2;
-                                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                                               $_time_nv_h[$hourrecord]++;
-                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
-                                               last;
-                                       }
-                               }
-                       }
+               # Show clock icon
+               print "<tr" . Tooltip(17) . ">\n";
+               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
+                       my $hrs = ( $ix >= 12 ? $ix - 12 : $ix );
+                       my $hre = ( $ix >= 12 ? $ix - 11 : $ix + 1 );
+                       my $apm = ( $ix >= 12 ? "pm"     : "am" );
+                       print
+"<td><img src=\"$DirIcons\/clock\/hr$hre.png\" width=\"12\" alt=\"$hrs:00 - $hre:00 $apm\" /></td>\n";
                }
+               print "</tr>\n";
+               print "</table>\n";
+       }
+       print "<br />\n";
 
-               # Analyze: Status code (=> countedtraffic=3 if error)
-               #----------------------------------------------------
-               if ( !$countedtraffic ) {
-                       if ( $LogType eq 'W' || $LogType eq 'S' )
-                       {    # HTTP record or Stream record
-                               if ( $ValidHTTPCodes{ $field[$pos_code] } ) {    # Code is valid
-                                       if ( $field[$pos_code] == 304 ) { $field[$pos_size] = 0; }
-                               }
-                               else {    # Code is not valid
-                                       if ( $field[$pos_code] !~ /^\d\d\d$/ ) {
-                                               $field[$pos_code] = 999;
-                                       }
-                                       $_errors_h{ $field[$pos_code] }++;
-                                       $_errors_k{ $field[$pos_code] } += int( $field[$pos_size] );
-                                       foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
-                                               if ( $field[$pos_code] == $code ) {
+       # Show data array for hours
+       if ($AddDataArrayShowHoursStats) {
+               print "<table width=\"650\"><tr>\n";
+               print "<td align=\"center\"><center>\n";
 
-                                          # This is an error code which referrer need to be tracked
-                                                       my $newurl =
-                                                         substr( $field[$pos_url], 0,
-                                                               $MaxLengthOfStoredURL );
-                                                       $newurl =~ s/[$URLQuerySeparators].*$//;
-                                                       $_sider404_h{$newurl}++;
-                                                       if ( $pos_referer >= 0 ) {
-                                                               my $newreferer = $field[$pos_referer];
-                                                               if ( !$URLReferrerWithQuery ) {
-                                                                       $newreferer =~ s/[$URLQuerySeparators].*$//;
-                                                               }
-                                                               $_referer404_h{$newurl} = $newreferer;
-                                                               last;
-                                                       }
-                                               }
-                                       }
-                                       if ($Debug) {
-                                               debug(
-" Record stored in the status code chart (status code=$field[$pos_code])",
-                                                       3
-                                               );
-                                       }
-                                       $countedtraffic = 3;
-                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                                       $_time_nv_h[$hourrecord]++;
-                                       $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
-                               }
+               print "<table>\n";
+               print
+"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
+               if ( $ShowHoursStats =~ /P/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_p\""
+                         . Tooltip(3)
+                         . ">$Message[56]</td>";
+               }
+               if ( $ShowHoursStats =~ /H/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_h\""
+                         . Tooltip(4)
+                         . ">$Message[57]</td>";
+               }
+               if ( $ShowHoursStats =~ /B/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_k\""
+                         . Tooltip(5)
+                         . ">$Message[75]</td>";
+               }
+               print "</tr>";
+               for ( my $ix = 0 ; $ix <= 11 ; $ix++ ) {
+                       my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
+                       print "<tr>";
+                       print "<td>$monthix</td>";
+                       if ( $ShowHoursStats =~ /P/i ) {
+                               print "<td>",
+                                 Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
+                                 "</td>";
                        }
-                       elsif ( $LogType eq 'M' ) {    # Mail record
-                               if ( !$ValidSMTPCodes{ $field[$pos_code] } )
-                               {                          # Code is not valid
-                                       $_errors_h{ $field[$pos_code] }++;
-                                       if ( $field[$pos_size] ne '-' ) {
-                                               $_errors_k{ $field[$pos_code] } +=
-                                                 int( $field[$pos_size] );
-                                       }
-                                       if ($Debug) {
-                                               debug(
-" Record stored in the status code chart (status code=$field[$pos_code])",
-                                                       3
-                                               );
-                                       }
-                                       $countedtraffic = 3;
-                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                                       $_time_nv_h[$hourrecord]++;
-                                       if ( $field[$pos_size] ne '-' ) {
-                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
-                                       }
-                               }
+                       if ( $ShowHoursStats =~ /H/i ) {
+                               print "<td>",
+                                 Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
+                                 "</td>";
                        }
-                       elsif ( $LogType eq 'F' ) {    # FTP record
+                       if ( $ShowHoursStats =~ /B/i ) {
+                               print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
+                                 "</td>";
                        }
+                       print "</tr>\n";
                }
+               print "</table>\n";
 
-               # Analyze: Robot from robot database (=> countedtraffic=4 if robot)
-               #------------------------------------------------------------------
-               if ( !$countedtraffic ) {
-                       if ( $pos_agent >= 0 ) {
-                               if ($DecodeUA) {
-                                       $field[$pos_agent] =~ s/%20/_/g;
-                               } # This is to support servers (like Roxen) that writes user agent with %20 in it
-                               $UserAgent = $field[$pos_agent];
-                               if ( $UserAgent && $UserAgent eq '-' ) { $UserAgent = ''; }
-
-                               if ($LevelForRobotsDetection) {
-
-                                       if ($UserAgent) {
-                                               my $uarobot = $TmpRobot{$UserAgent};
-                                               if ( !$uarobot ) {
+               print "</center></td>";
+               print "<td width=\"10\">&nbsp;</td>";
+               print "<td align=\"center\"><center>\n";
 
-                                                       #study $UserAgent;              Does not increase speed
-                                                       foreach (@RobotsSearchIDOrder) {
-                                                               if ( $UserAgent =~ /$_/ ) {
-                                                                       my $bot = &UnCompileRegex($_);
-                                                                       $TmpRobot{$UserAgent} = $uarobot = "$bot"
-                                                                         ; # Last time, we won't search if robot or not. We know it is.
-                                                                       if ($Debug) {
-                                                                               debug(
-"  UserAgent '$UserAgent' is added to TmpRobot with value '$bot'",
-                                                                                       2
-                                                                               );
-                                                                       }
-                                                                       last;
-                                                               }
-                                                       }
-                                                       if ( !$uarobot )
-                                                       { # Last time, we won't search if robot or not. We know it's not.
-                                                               $TmpRobot{$UserAgent} = $uarobot = '-';
-                                                       }
-                                               }
-                                               if ( $uarobot ne '-' ) {
-
-                                                       # If robot, we stop here
-                                                       if ($Debug) {
-                                                               debug(
-"  UserAgent '$UserAgent' contains robot ID '$uarobot'",
-                                                                       2
-                                                               );
-                                                       }
-                                                       $_robot_h{$uarobot}++;
-                                                       if ( $field[$pos_size] ne '-' ) {
-                                                               $_robot_k{$uarobot} += int( $field[$pos_size] );
-                                                       }
-                                                       $_robot_l{$uarobot} = $timerecord;
-                                                       if ( $urlwithnoquery =~ /$regrobot/o ) {
-                                                               $_robot_r{$uarobot}++;
-                                                       }
-                                                       $countedtraffic = 4;
-                                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                                                       $_time_nv_h[$hourrecord]++;
-                                                       if ( $field[$pos_size] ne '-' ) {
-                                                               $_time_nv_k[$hourrecord] +=
-                                                                 int( $field[$pos_size] );
-                                                       }
-                                               }
-                                       }
-                                       else {
-                                               my $uarobot = 'no_user_agent';
-
-                                               # It's a robot or at least a bad browser, we stop here
-                                               if ($Debug) {
-                                                       debug(
-"  UserAgent not defined so it should be a robot, saved as robot 'no_user_agent'",
-                                                               2
-                                                       );
-                                               }
-                                               $_robot_h{$uarobot}++;
-                                               $_robot_k{$uarobot} += int( $field[$pos_size] );
-                                               $_robot_l{$uarobot} = $timerecord;
-                                               if ( $urlwithnoquery =~ /$regrobot/o ) {
-                                                       $_robot_r{$uarobot}++;
-                                               }
-                                               $countedtraffic = 4;
-                                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                                               $_time_nv_h[$hourrecord]++;
-                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
-                                       }
-                               }
-                       }
+               print "<table>\n";
+               print
+"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
+               if ( $ShowHoursStats =~ /P/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_p\""
+                         . Tooltip(3)
+                         . ">$Message[56]</td>";
                }
-
-   # Analyze: Robot from "hit on robots.txt" file (=> countedtraffic=5 if robot)
-   # -------------------------------------------------------------------------
-               if ( !$countedtraffic ) {
-                       if ( $urlwithnoquery =~ /$regrobot/o ) {
-                               if ($Debug) { debug( "  It's an unknown robot", 2 ); }
-                               $_robot_h{'unknown'}++;
-                               $_robot_k{'unknown'} += int( $field[$pos_size] );
-                               $_robot_l{'unknown'} = $timerecord;
-                               $_robot_r{'unknown'}++;
-                               $countedtraffic = 5;    # Must not be counted somewhere else
-                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
-                               $_time_nv_h[$hourrecord]++;
-                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
-                       }
+               if ( $ShowHoursStats =~ /H/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_h\""
+                         . Tooltip(4)
+                         . ">$Message[57]</td>";
                }
-
-               # Analyze: File type - Compression
-               #---------------------------------
-               if ( !$countedtraffic ) {
-                       if ($LevelForFileTypesDetection) {
-                               $_filetypes_h{$extension}++;
-                               if ( $field[$pos_size] ne '-' ) {
-                                       $_filetypes_k{$extension} += int( $field[$pos_size] );
-                               }
-
-                               # Compression
-                               if ( $pos_gzipin >= 0 && $field[$pos_gzipin] )
-                               {    # If in and out in log
-                                       my ( $notused, $in ) = split( /:/, $field[$pos_gzipin] );
-                                       my ( $notused1, $out, $notused2 ) =
-                                         split( /:/, $field[$pos_gzipout] );
-                                       if ($out) {
-                                               $_filetypes_gz_in{$extension}  += $in;
-                                               $_filetypes_gz_out{$extension} += $out;
-                                       }
-                               }
-                               elsif ( $pos_compratio >= 0
-                                       && ( $field[$pos_compratio] =~ /(\d+)/ ) )
-                               {    # Calculate in/out size from percentage
-                                       if ( $fieldlib[$pos_compratio] eq 'gzipratio' ) {
-
-       # with mod_gzip:    % is size (before-after)/before (low for jpg) ??????????
-                                               $_filetypes_gz_in{$extension} +=
-                                                 int(
-                                                       $field[$pos_size] * 100 / ( ( 100 - $1 ) || 1 ) );
-                                       }
-                                       else {
-
-                                          # with mod_deflate: % is size after/before (high for jpg)
-                                               $_filetypes_gz_in{$extension} +=
-                                                 int( $field[$pos_size] * 100 / ( $1 || 1 ) );
-                                       }
-                                       $_filetypes_gz_out{$extension} += int( $field[$pos_size] );
-                               }
+               if ( $ShowHoursStats =~ /B/i ) {
+                       print "<td width=\"80\" bgcolor=\"#$color_k\""
+                         . Tooltip(5)
+                         . ">$Message[75]</td>";
+               }
+               print "</tr>\n";
+               for ( my $ix = 12 ; $ix <= 23 ; $ix++ ) {
+                       my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
+                       print "<tr>";
+                       print "<td>$monthix</td>";
+                       if ( $ShowHoursStats =~ /P/i ) {
+                               print "<td>",
+                                 Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
+                                 "</td>";
                        }
-
-                       # Analyze: Date - Hour - Pages - Hits - Kilo
-                       #-------------------------------------------
-                       if ($PageBool) {
-
-# Replace default page name with / only ('if' is to increase speed when only 1 value in @DefaultFile)
-                               if ( @DefaultFile > 1 ) {
-                                       foreach my $elem (@DefaultFile) {
-                                               if ( $field[$pos_url] =~ s/\/$elem$/\// ) { last; }
-                                       }
-                               }
-                               else { $field[$pos_url] =~ s/$regdefault/\//o; }
-
-# FirstTime and LastTime are First and Last human visits (so changed if access to a page)
-                               $FirstTime{$lastprocesseddate} ||= $timerecord;
-                               $LastTime{$lastprocesseddate} = $timerecord;
-                               $DayPages{$yearmonthdayrecord}++;
-                               $_url_p{ $field[$pos_url] }++;   #Count accesses for page (page)
-                               if ( $field[$pos_size] ne '-' ) {
-                                       $_url_k{ $field[$pos_url] } += int( $field[$pos_size] );
-                               }
-                               $_time_p[$hourrecord]++;    #Count accesses for hour (page)
-                                                           # TODO Use an id for hash key of url
-                                                           # $_url_t{$_url_id}
+                       if ( $ShowHoursStats =~ /H/i ) {
+                               print "<td>",
+                                 Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
+                                 "</td>";
                        }
-                       $_time_h[$hourrecord]++;
-                       $DayHits{$yearmonthdayrecord}++;    #Count accesses for hour (hit)
-                       if ( $field[$pos_size] ne '-' ) {
-                               $_time_k[$hourrecord]          += int( $field[$pos_size] );
-                               $DayBytes{$yearmonthdayrecord} +=
-                                 int( $field[$pos_size] );     #Count accesses for hour (kb)
+                       if ( $ShowHoursStats =~ /B/i ) {
+                               print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
+                                 "</td>";
                        }
+                       print "</tr>\n";
+               }
+               print "</table>\n";
 
-                       # Analyze: Login
-                       #---------------
-                       if (   $pos_logname >= 0
-                               && $field[$pos_logname]
-                               && $field[$pos_logname] ne '-' )
-                       {
-                               $field[$pos_logname] =~
-                                 s/ /_/g;    # This is to allow space in logname
-                               if ( $LogFormat eq '6' ) {
-                                       $field[$pos_logname] =~ s/^\"//;
-                                       $field[$pos_logname] =~ s/\"$//;
-                               }             # logname field has " with Domino 6+
-                               if ($AuthenticatedUsersNotCaseSensitive) {
-                                       $field[$pos_logname] = lc( $field[$pos_logname] );
-                               }
+               print "</center></td></tr></table>\n";
+               print "<br />\n";
+       }
 
-                               # We found an authenticated user
-                               if ($PageBool) {
-                                       $_login_p{ $field[$pos_logname] }++;
-                               }             #Count accesses for page (page)
-                               $_login_h{ $field[$pos_logname] }
-                                 ++;         #Count accesses for page (hit)
-                               $_login_k{ $field[$pos_logname] } +=
-                                 int( $field[$pos_size] );    #Count accesses for page (kb)
-                               $_login_l{ $field[$pos_logname] } = $timerecord;
+       print "</center></td></tr>\n";
+       &tab_end();
+}
+
+#------------------------------------------------------------------------------
+# Function:     Prints the countries chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainCountries{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowDomainsStats", 2 ); }
+       print "$Center<a name=\"countries\">&nbsp;</a><br />\n";
+       my $title =
+"$Message[25] ($Message[77] $MaxNbOf{'Domain'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=alldomains")
+               : "$StaticLinks.alldomains.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a>";
+       &tab_head( "$title", 19, 0, 'countries' );
+       
+       my $total_u = my $total_v = my $total_p = my $total_h = my $total_k = 0;
+       my $max_h = 1;
+       foreach ( values %_domener_h ) {
+               if ( $_ > $max_h ) { $max_h = $_; }
+       }
+       my $max_k = 1;
+       foreach ( values %_domener_k ) {
+               if ( $_ > $max_k ) { $max_k = $_; }
+       }
+       my $count = 0;
+       
+       &BuildKeyList(
+               $MaxNbOf{'Domain'}, $MinHit{'Domain'},
+               \%_domener_h,       \%_domener_p
+       );
+       
+       # print the map
+       if (scalar @keylist > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int( $_domener_h{$key} );
+                               push @blocklabel, $DomainsHashIDLib{$key};
+                               $cnt++;
+                               if ($cnt > 99) { last; }
                        }
+                       print "<tr><td colspan=\"7\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "AWStatsCountryMap",              "countries_map",
+                               0,                                              \@blocklabel,
+                               0,                              0,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
                }
+       }
+       
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
 
-               # Do DNS lookup
-               #--------------
-               my $Host         = $field[$pos_host];
-               my $HostResolved = ''
-                 ; # HostResolved will be defined in next paragraf if countedtraffic is true
+       ## to add unique visitors and number of visits by calculation of average of the relation with total
+       ## pages and total hits, and total visits and total unique
+       ## by Josep Ruano @ CAPSiDE
+       if ( $ShowDomainsStats =~ /U/i ) {
+               print "<th bgcolor=\"#$color_u\" width=\"80\""
+                 . Tooltip(2)
+                 . ">$Message[11]</th>";
+       }
+       if ( $ShowDomainsStats =~ /V/i ) {
+               print "<th bgcolor=\"#$color_v\" width=\"80\""
+                 . Tooltip(1)
+                 . ">$Message[10]</th>";
+       }
+       if ( $ShowDomainsStats =~ /P/i ) {
+               print "<th bgcolor=\"#$color_p\" width=\"80\""
+                 . Tooltip(3)
+                 . ">$Message[56]</th>";
+       }
+       if ( $ShowDomainsStats =~ /H/i ) {
+               print "<th bgcolor=\"#$color_h\" width=\"80\""
+                 . Tooltip(4)
+                 . ">$Message[57]</th>";
+       }
+       if ( $ShowDomainsStats =~ /B/i ) {
+               print "<th bgcolor=\"#$color_k\" width=\"80\""
+                 . Tooltip(5)
+                 . ">$Message[75]</th>";
+       }
+       print "<th>&nbsp;</th>";
+       print "</tr>\n";
+       
+       foreach my $key (@keylist) {
+               my ( $_domener_u, $_domener_v );
+               my $bredde_p = 0;
+               my $bredde_h = 0;
+               my $bredde_k = 0;
+               my $bredde_u = 0;
+               my $bredde_v = 0;
+               if ( $max_h > 0 ) {
+                       $bredde_p =
+                         int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
+               }    # use max_h to enable to compare pages with hits
+               if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
+               if ( $max_h > 0 ) {
+                       $bredde_h =
+                         int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
+               }
+               if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
+               if ( $max_k > 0 ) {
+                       $bredde_k =
+                         int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
+                         1;
+               }
+               if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
+               my $newkey = lc($key);
+               if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
+                       print
+"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
+                         . AltTitle("$Message[0]")
+                         . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
+               }
+               else {
+                       print
+"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
+                         . AltTitle("$newkey")
+                         . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
+               }
+               ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
+               if ( $ShowDomainsStats =~ /U/i ) {
+                       $_domener_u = (
+                                 $_domener_p{$key}
+                               ? $_domener_p{$key} / $TotalPages
+                               : 0
+                       );
+                       $_domener_u += ( $_domener_h{$key} / $TotalHits );
+                       $_domener_u =
+                         sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
+                       print "<td>".Format_Number($_domener_u)." ("
+                         . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
+                         . ")</td>";
+               }
+               if ( $ShowDomainsStats =~ /V/i ) {
+                       $_domener_v = (
+                                 $_domener_p{$key}
+                               ? $_domener_p{$key} / $TotalPages
+                               : 0
+                       );
+                       $_domener_v += ( $_domener_h{$key} / $TotalHits );
+                       $_domener_v =
+                         sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
+                       print "<td>".Format_Number($_domener_v)." ("
+                         . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
+                         . ")</td>";
+               }
 
-               if ( !$countedtraffic ) {
-                       my $ip = 0;
-                       if ($DNSLookup) {    # DNS lookup is 1 or 2
-                               if ( $Host =~ /$regipv4l/o ) {    # IPv4 lighttpd
-                                       $Host =~ s/^::ffff://;
-                                       $ip = 4;
-                               }
-                               elsif ( $Host =~ /$regipv4/o ) { $ip = 4; }    # IPv4
-                               elsif ( $Host =~ /$regipv6/o ) { $ip = 6; }    # IPv6
-                               if ($ip) {
+               if ( $ShowDomainsStats =~ /P/i ) {
+                       print "<td>"
+                         . ( $_domener_p{$key} ? Format_Number($_domener_p{$key}) : '&nbsp;' )
+                         . "</td>";
+               }
+               if ( $ShowDomainsStats =~ /H/i ) {
+                       print "<td>".Format_Number($_domener_h{$key})."</td>";
+               }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
+               }
+               print "<td class=\"aws\">";
 
-                                       # Check in static DNS cache file
-                                       $HostResolved = $MyDNSTable{$Host};
-                                       if ($HostResolved) {
-                                               if ($Debug) {
-                                                       debug(
-"  DNS lookup asked for $Host and found in static DNS cache file: $HostResolved",
-                                                               4
-                                                       );
-                                               }
-                                       }
-                                       elsif ( $DNSLookup == 1 ) {
+               if ( $ShowDomainsStats =~ /P/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
+                         . AltTitle("")
+                         . " /><br />\n";
+               }
+               if ( $ShowDomainsStats =~ /H/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
+                         . AltTitle("")
+                         . " /><br />\n";
+               }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
+                         . AltTitle("") . " />";
+               }
+               print "</td>";
+               print "</tr>\n";
 
-                  # Check in session cache (dynamic DNS cache file + session DNS cache)
-                                               $HostResolved = $TmpDNSLookup{$Host};
-                                               if ( !$HostResolved ) {
-                                                       if ( @SkipDNSLookupFor && &SkipDNSLookup($Host) ) {
-                                                               $HostResolved = $TmpDNSLookup{$Host} = '*';
-                                                               if ($Debug) {
-                                                                       debug(
-"  No need of reverse DNS lookup for $Host, skipped at user request.",
-                                                                               4
-                                                                       );
-                                                               }
-                                                       }
-                                                       else {
-                                                               if ( $ip == 4 ) {
-                                                                       my $lookupresult =
-                                                                         gethostbyaddr(
-                                                                               pack( "C4", split( /\./, $Host ) ),
-                                                                               AF_INET )
-                                                                         ; # This is very slow, may spend 20 seconds
-                                                                       if (   !$lookupresult
-                                                                               || $lookupresult =~ /$regipv4/o
-                                                                               || !IsAscii($lookupresult) )
-                                                                       {
-                                                                               $TmpDNSLookup{$Host} = $HostResolved =
-                                                                                 '*';
-                                                                       }
-                                                                       else {
-                                                                               $TmpDNSLookup{$Host} = $HostResolved =
-                                                                                 $lookupresult;
-                                                                       }
-                                                                       if ($Debug) {
-                                                                               debug(
-"  Reverse DNS lookup for $Host done: $HostResolved",
-                                                                                       4
-                                                                               );
-                                                                       }
-                                                               }
-                                                               elsif ( $ip == 6 ) {
-                                                                       if ( $PluginsLoaded{'GetResolvedIP'}
-                                                                               {'ipv6'} )
-                                                                       {
-                                                                               my $lookupresult =
-                                                                                 GetResolvedIP_ipv6($Host);
-                                                                               if (   !$lookupresult
-                                                                                       || !IsAscii($lookupresult) )
-                                                                               {
-                                                                                       $TmpDNSLookup{$Host} =
-                                                                                         $HostResolved = '*';
-                                                                               }
-                                                                               else {
-                                                                                       $TmpDNSLookup{$Host} =
-                                                                                         $HostResolved = $lookupresult;
-                                                                               }
-                                                                       }
-                                                                       else {
-                                                                               $TmpDNSLookup{$Host} = $HostResolved =
-                                                                                 '*';
-                                                                               warning(
-"Reverse DNS lookup for $Host not available without ipv6 plugin enabled."
-                                                                               );
-                                                                       }
-                                                               }
-                                                               else { error("Bad value vor ip"); }
-                                                       }
-                                               }
-                                       }
-                                       else {
-                                               $HostResolved = '*';
-                                               if ($Debug) {
-                                                       debug(
-"  DNS lookup by static DNS cache file asked for $Host but not found.",
-                                                               4
-                                                       );
-                                               }
-                                       }
-                               }
-                               else {
-                                       if ($Debug) {
-                                               debug(
-"  DNS lookup asked for $Host but this is not an IP address.",
-                                                       4
-                                               );
-                                       }
-                                       $DNSLookupAlreadyDone = $LogFile;
-                               }
-                       }
-                       else {
-                               if ( $Host =~ /$regipv4l/o ) {
-                                       $Host =~ s/^::ffff://;
-                                       $HostResolved = '*';
-                                       $ip           = 4;
-                               }
-                               elsif ( $Host =~ /$regipv4/o ) {
-                                       $HostResolved = '*';
-                                       $ip           = 4;
-                               }    # IPv4
-                               elsif ( $Host =~ /$regipv6/o ) {
-                                       $HostResolved = '*';
-                                       $ip           = 6;
-                               }    # IPv6
-                               if ($Debug) { debug( "  No DNS lookup asked.", 4 ); }
-                       }
+               $total_u += $_domener_u;
+               $total_v += $_domener_v;
+               $total_p += $_domener_p{$key};
+               $total_h += $_domener_h{$key};
+               $total_k += $_domener_k{$key} || 0;
+               $count++;
+       }
+       my $rest_u = $TotalUnique - $total_u;
+       my $rest_v = $TotalVisits - $total_v;
+       my $rest_p = $TotalPages - $total_p;
+       my $rest_h = $TotalHits - $total_h;
+       my $rest_k = $TotalBytes - $total_k;
+       if (   $rest_u > 0
+               || $rest_v > 0
+               || $rest_p > 0
+               || $rest_h > 0
+               || $rest_k > 0 )
+       {    # All other domains (known or not)
+               print
+"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
+               if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
+               if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
+               if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
+               if ( $ShowDomainsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               print "<td class=\"aws\">&nbsp;</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                       # Analyze: Country (Top-level domain)
-                       #------------------------------------
-                       if ($Debug) {
-                               debug(
-"  Search country (Host=$Host HostResolved=$HostResolved ip=$ip)",
-                                       4
-                               );
+#------------------------------------------------------------------------------
+# Function:     Prints the hosts chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainHosts{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowHostsStats", 2 ); }
+       print "$Center<a name=\"visitors\">&nbsp;</a><br />\n";
+       my $title =
+"$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=allhosts")
+               : "$StaticLinks.allhosts.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=lasthosts")
+               : "$StaticLinks.lasthosts.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[9]</a> &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownip")
+               : "$StaticLinks.unknownip.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[45]</a>";
+       &tab_head( "$title", 19, 0, 'visitors' );
+       
+       &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
+               \%_host_p );
+               
+       # Graph the top five in a pie chart
+       if (scalar @keylist > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int( $_host_h{$key} / $TotalHits * 1000 ) / 10;
+                               push @blocklabel, "$key";
+                               $cnt++;
+                               if ($cnt > 4) { last; }
                        }
-                       my $Domain = 'ip';
-
-                       # Set $HostResolved to host and resolve domain
-                       if ( $HostResolved eq '*' ) {
-
-# $Host is an IP address and is not resolved (failed or not asked) or resolution gives an IP address
-                               $HostResolved = $Host;
+                       print "<tr><td colspan=\"7\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "Hosts",              "hosts",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+       print "<th>";
+       if ( $MonthRequired ne 'all' ) {
+               print
+"$Message[81] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1]<br />".Format_Number($TotalUnique)." $Message[11]</th>";
+       }
+       else {
+               print "$Message[81] : " . ( scalar keys %_host_h ) . "</th>";
+       }
+       &HTMLShowHostInfo('__title__');
+       if ( $ShowHostsStats =~ /P/i ) {
+               print "<th bgcolor=\"#$color_p\" width=\"80\""
+                 . Tooltip(3)
+                 . ">$Message[56]</th>";
+       }
+       if ( $ShowHostsStats =~ /H/i ) {
+               print "<th bgcolor=\"#$color_h\" width=\"80\""
+                 . Tooltip(4)
+                 . ">$Message[57]</th>";
+       }
+       if ( $ShowHostsStats =~ /B/i ) {
+               print "<th bgcolor=\"#$color_k\" width=\"80\""
+                 . Tooltip(5)
+                 . ">$Message[75]</th>";
+       }
+       if ( $ShowHostsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = 0;
+       my $count = 0;
+       
+       foreach my $key (@keylist) {
+               print "<tr>";
+               print "<td class=\"aws\">$key</td>";
+               &HTMLShowHostInfo($key);
+               if ( $ShowHostsStats =~ /P/i ) {
+                       print '<td>' . ( Format_Number($_host_p{$key}) || "&nbsp;" ) . '</td>';
+               }
+               if ( $ShowHostsStats =~ /H/i ) {
+                       print "<td>".Format_Number($_host_h{$key})."</td>";
+               }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print '<td>' . Format_Bytes( $_host_k{$key} ) . '</td>';
+               }
+               if ( $ShowHostsStats =~ /L/i ) {
+                       print '<td nowrap="nowrap">'
+                         . (
+                               $_host_l{$key}
+                               ? Format_Date( $_host_l{$key}, 1 )
+                               : '-'
+                         )
+                         . '</td>';
+               }
+               print "</tr>\n";
+               $total_p += $_host_p{$key};
+               $total_h += $_host_h{$key};
+               $total_k += $_host_k{$key} || 0;
+               $count++;
+       }
+       my $rest_p = $TotalPages - $total_p;
+       my $rest_h = $TotalHits - $total_h;
+       my $rest_k = $TotalBytes - $total_k;
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
+       {    # All other visitors (known or not)
+               print "<tr>";
+               print
+"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               &HTMLShowHostInfo('');
+               if ( $ShowHostsStats =~ /P/i ) { print "<td>".Format_Number($rest_p)."</td>"; }
+               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
+               if ( $ShowHostsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                               # Resolve Domain
-                               if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
-                                       $Domain = GetCountryCodeByAddr_geoip($HostResolved);
-                               }
+#------------------------------------------------------------------------------
+# Function:     Prints the logins chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainLogins{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowAuthenticatedUsers", 2 ); }
+       print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
+       my $title =
+"$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=alllogins")
+               : "$StaticLinks.alllogins.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a>";
+       if ( $ShowAuthenticatedUsers =~ /L/i ) {
+               $title .= " &nbsp; - &nbsp; <a href=\""
+                 . (
+                       $ENV{'GATEWAY_INTERFACE'}
+                         || !$StaticLinks
+                       ? XMLEncode("$AWScript?${NewLinkParams}output=lastlogins")
+                       : "$StaticLinks.lastlogins.$StaticExt"
+                 )
+                 . "\"$NewLinkTarget>$Message[9]</a>";
+       }
+       &tab_head( "$title", 19, 0, 'logins' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
+         . Format_Number(( scalar keys %_login_h )) . "</th>";
+       &HTMLShowUserInfo('__title__');
+       if ( $ShowAuthenticatedUsers =~ /P/i ) {
+               print "<th bgcolor=\"#$color_p\" width=\"80\""
+                 . Tooltip(3)
+                 . ">$Message[56]</th>";
+       }
+       if ( $ShowAuthenticatedUsers =~ /H/i ) {
+               print "<th bgcolor=\"#$color_h\" width=\"80\""
+                 . Tooltip(4)
+                 . ">$Message[57]</th>";
+       }
+       if ( $ShowAuthenticatedUsers =~ /B/i ) {
+               print "<th bgcolor=\"#$color_k\" width=\"80\""
+                 . Tooltip(5)
+                 . ">$Message[75]</th>";
+       }
+       if ( $ShowAuthenticatedUsers =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = 0;
+       my $max_h = 1;
+       foreach ( values %_login_h ) {
+               if ( $_ > $max_h ) { $max_h = $_; }
+       }
+       my $max_k = 1;
+       foreach ( values %_login_k ) {
+               if ( $_ > $max_k ) { $max_k = $_; }
+       }
+       my $count = 0;
+       &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
+               \%_login_p );
+       foreach my $key (@keylist) {
+               my $bredde_p = 0;
+               my $bredde_h = 0;
+               my $bredde_k = 0;
+               if ( $max_h > 0 ) {
+                       $bredde_p = int( $BarWidth * $_login_p{$key} / $max_h ) + 1;
+               }    # use max_h to enable to compare pages with hits
+               if ( $max_h > 0 ) {
+                       $bredde_h = int( $BarWidth * $_login_h{$key} / $max_h ) + 1;
+               }
+               if ( $max_k > 0 ) {
+                       $bredde_k = int( $BarWidth * $_login_k{$key} / $max_k ) + 1;
+               }
+               print "<tr><td class=\"aws\">$key</td>";
+               &HTMLShowUserInfo($key);
+               if ( $ShowAuthenticatedUsers =~ /P/i ) {
+                       print "<td>"
+                         . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
+                         . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /H/i ) {
+                       print "<td>".Format_Number($_login_h{$key})."</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_login_l{$key}
+                               ? Format_Date( $_login_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
+               $total_p += $_login_p{$key};
+               $total_h += $_login_h{$key};
+               $total_k += $_login_k{$key};
+               $count++;
+       }
+       my $rest_p = $TotalPages - $total_p;
+       my $rest_h = $TotalHits - $total_h;
+       my $rest_k = $TotalBytes - $total_k;
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
+       {    # All other logins
+               print
+                 "<tr><td class=\"aws\"><span style=\"color: #$color_other\">"
+                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                 . "$Message[125]"
+                 . ( $PageDir eq 'rtl' ? "</span>" : "" )
+                 . "</span></td>";
+               &HTMLShowUserInfo('');
+               if ( $ShowAuthenticatedUsers =~ /P/i ) {
+                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /H/i ) {
+                       print "<td>".Format_Number($rest_h)."</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /B/i ) {
+                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+               if ( $ShowAuthenticatedUsers =~ /L/i ) {
+                       print "<td>&nbsp;</td>";
+               }
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-#                      elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($HostResolved); }
-#                      elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($HostResolved); }
-                               elsif ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} ) {
-                                       $Domain = GetCountryCodeByAddr_geoipfree($HostResolved);
-                               }
-                               if ($AtLeastOneSectionPlugin) {
-                                       foreach my $pluginname (
-                                               keys %{ $PluginsLoaded{'SectionProcessIp'} } )
-                                       {
-                                               my $function = "SectionProcessIp_$pluginname";
-                                               if ($Debug) {
-                                                       debug( "  Call to plugin function $function", 5 );
-                                               }
-                                               &$function($HostResolved);
-                                       }
-                               }
-                       }
-                       else {
+#------------------------------------------------------------------------------
+# Function:     Prints the robots chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainRobots{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowRobotStats", 2 ); }
+       print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
+       &tab_head(
+"$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) &nbsp; - &nbsp; <a href=\""
+                 . (
+                       $ENV{'GATEWAY_INTERFACE'}
+                         || !$StaticLinks
+                       ? XMLEncode("$AWScript?${NewLinkParams}output=allrobots")
+                       : "$StaticLinks.allrobots.$StaticExt"
+                 )
+                 . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
+                 . (
+                       $ENV{'GATEWAY_INTERFACE'}
+                         || !$StaticLinks
+                       ? XMLEncode("$AWScript?${NewLinkParams}output=lastrobots")
+                       : "$StaticLinks.lastrobots.$StaticExt"
+                 )
+                 . "\"$NewLinkTarget>$Message[9]</a>",
+               19, 0, 'robots'
+       );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+         . Tooltip(16) . "><th>"
+         . Format_Number(( scalar keys %_robot_h ))
+         . " $Message[51]*</th>";
+       if ( $ShowRobotsStats =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+       }
+       if ( $ShowRobotsStats =~ /B/i ) {
+               print
+                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ShowRobotsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = my $total_r = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
+               \%_robot_h );
+       foreach my $key (@keylist) {
+               print "<tr><td class=\"aws\">"
+                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                 . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
+                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
+               if ( $ShowRobotsStats =~ /H/i ) {
+                       print "<td>"
+                         . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
+                         . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_robot_l{$key}
+                               ? Format_Date( $_robot_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
 
-# $Host was already a host name ($ip=0, $Host=name, $HostResolved='') or has been resolved ($ip>0, $Host=ip, $HostResolved defined)
-                               $HostResolved = lc( $HostResolved ? $HostResolved : $Host );
+               #$total_p += $_robot_p{$key};
+               $total_h += $_robot_h{$key};
+               $total_k += $_robot_k{$key} || 0;
+               $total_r += $_robot_r{$key} || 0;
+               $count++;
+       }
 
-                               # Resolve Domain
-                               if ($ip)
-                               {    # If we have ip, we use it in priority instead of hostname
-                                       if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
-                                               $Domain = GetCountryCodeByAddr_geoip($Host);
-                                       }
+       # For bots we need to count Totals
+       my $TotalPagesRobots =
+         0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
+       my $TotalHitsRobots = 0;
+       foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
+       my $TotalBytesRobots = 0;
+       foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
+       my $TotalRRobots = 0;
+       foreach ( values %_robot_r ) { $TotalRRobots += $_; }
+       my $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
+       my $rest_h = $TotalHitsRobots - $total_h;
+       my $rest_k = $TotalBytesRobots - $total_k;
+       my $rest_r = $TotalRRobots - $total_r;
+
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
+       {               # All other robots
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowRobotsStats =~ /H/i ) {
+                       print "<td>"
+                         . Format_Number(( $rest_h - $rest_r ))
+                         . ( $rest_r ? "+$rest_r" : "" ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /B/i ) {
+                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
+               }
+               if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
+       }
+       &tab_end(
+               "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
+}
 
-#                              elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($Host); }
-#                              elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($Host); }
-                                       elsif (
-                                               $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} )
-                                       {
-                                               $Domain = GetCountryCodeByAddr_geoipfree($Host);
-                                       }
-                                       elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
-                                       if ($AtLeastOneSectionPlugin) {
-                                               foreach my $pluginname (
-                                                       keys %{ $PluginsLoaded{'SectionProcessIp'} } )
-                                               {
-                                                       my $function = "SectionProcessIp_$pluginname";
-                                                       if ($Debug) {
-                                                               debug( "  Call to plugin function $function",
-                                                                       5 );
-                                                       }
-                                                       &$function($Host);
-                                               }
-                                       }
-                               }
-                               else {
-                                       if ( $PluginsLoaded{'GetCountryCodeByName'}{'geoip'} ) {
-                                               $Domain = GetCountryCodeByName_geoip($HostResolved);
-                                       }
+#------------------------------------------------------------------------------
+# Function:     Prints the worms chart and table
+# Parameters:   -
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainWorms{
+       if ($Debug) { debug( "ShowWormsStats", 2 ); }
+       print "$Center<a name=\"worms\">&nbsp;</a><br />\n";
+       &tab_head( "$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",
+               19, 0, 'worms' );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\"" . Tooltip(21) . ">";
+       print "<th>" . Format_Number(( scalar keys %_worm_h )) . " $Message[164]*</th>";
+       print "<th>$Message[167]</th>";
+       if ( $ShowWormsStats =~ /H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+       }
+       if ( $ShowWormsStats =~ /B/i ) {
+               print
+                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ShowWormsStats =~ /L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
+               \%_worm_h );
+       foreach my $key (@keylist) {
+               print "<tr>";
+               print "<td class=\"aws\">"
+                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                 . ( $WormsHashLib{$key} ? $WormsHashLib{$key} : $key )
+                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
+               print "<td class=\"aws\">"
+                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                 . ( $WormsHashTarget{$key} ? $WormsHashTarget{$key} : $key )
+                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
+               if ( $ShowWormsStats =~ /H/i ) {
+                       print "<td>" . Format_Number($_worm_h{$key}) . "</td>";
+               }
+               if ( $ShowWormsStats =~ /B/i ) {
+                       print "<td>" . Format_Bytes( $_worm_k{$key} ) . "</td>";
+               }
+               if ( $ShowWormsStats =~ /L/i ) {
+                       print "<td>"
+                         . (
+                               $_worm_l{$key}
+                               ? Format_Date( $_worm_l{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
 
-#                              elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByName_geoip_region_maxmind($HostResolved); }
-#                              elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByName_geoip_city_maxmind($HostResolved); }
-                                       elsif (
-                                               $PluginsLoaded{'GetCountryCodeByName'}{'geoipfree'} )
-                                       {
-                                               $Domain = GetCountryCodeByName_geoipfree($HostResolved);
-                                       }
-                                       elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
-                                       if ($AtLeastOneSectionPlugin) {
-                                               foreach my $pluginname (
-                                                       keys %{ $PluginsLoaded{'SectionProcessHostname'} } )
-                                               {
-                                                       my $function = "SectionProcessHostname_$pluginname";
-                                                       if ($Debug) {
-                                                               debug( "  Call to plugin function $function",
-                                                                       5 );
-                                                       }
-                                                       &$function($HostResolved);
-                                               }
-                                       }
-                               }
-                       }
+               #$total_p += $_worm_p{$key};
+               $total_h += $_worm_h{$key};
+               $total_k += $_worm_k{$key} || 0;
+               $count++;
+       }
 
-                       # Store country
-                       if ($PageBool) { $_domener_p{$Domain}++; }
-                       $_domener_h{$Domain}++;
-                       if ( $field[$pos_size] ne '-' ) {
-                               $_domener_k{$Domain} += int( $field[$pos_size] );
-                       }
+       # For worms we need to count Totals
+       my $TotalPagesWorms =
+         0;    #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
+       my $TotalHitsWorms = 0;
+       foreach ( values %_worm_h ) { $TotalHitsWorms += $_; }
+       my $TotalBytesWorms = 0;
+       foreach ( values %_worm_k ) { $TotalBytesWorms += $_; }
+       my $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
+       my $rest_h = $TotalHitsWorms - $total_h;
+       my $rest_k = $TotalBytesWorms - $total_k;
 
-                       # Analyze: Host, URL entry+exit and Session
-                       #------------------------------------------
-                       if ($PageBool) {
-                               my $timehostl = $_host_l{$HostResolved};
-                               if ($timehostl) {
+       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other worms
+               print "<tr>";
+               print
+"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td class=\"aws\">-</td>";
+               if ( $ShowWormsStats =~ /H/i ) {
+                       print "<td>" . Format_Number(($rest_h)) . "</td>";
+               }
+               if ( $ShowWormsStats =~ /B/i ) {
+                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
+               }
+               if ( $ShowWormsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
+               print "</tr>\n";
+       }
+       &tab_end("* $Message[158]");
+}
 
-# A visit for this host was already detected
-# TODO everywhere there is $VISITTIMEOUT
-#                              $timehostl =~ /^\d\d\d\d\d\d(\d\d)/; my $daytimehostl=$1;
-#                              if ($timerecord > ($timehostl+$VISITTIMEOUT+($dateparts[3]>$daytimehostl?$NEWDAYVISITTIMEOUT:0))) {
-                                       if ( $timerecord > ( $timehostl + $VISITTIMEOUT ) ) {
+#------------------------------------------------------------------------------
+# Function:     Prints the sessions chart and table
+# Parameters:   -
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainSessions{
+       if ($Debug) { debug( "ShowSessionsStats", 2 ); }
+       print "$Center<a name=\"sessions\">&nbsp;</a><br />\n";
+       my $title = "$Message[117]";
+       &tab_head( $title, 19, 0, 'sessions' );
+       my $Totals = 0;
+       my $average_s = 0;
+       foreach (@SessionsRange) {
+               $average_s += ( $_session{$_} || 0 ) * $SessionsAverage{$_};
+               $Totals += $_session{$_} || 0;
+       }
+       if ($Totals) { $average_s = int( $average_s / $Totals ); }
+       else { $average_s = '?'; }
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+         . Tooltip(1)
+         . "><th>$Message[10]: ".Format_Number($TotalVisits)." - $Message[96]: ".Format_Number($average_s)." s</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[10]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
+       $average_s = 0;
+       my $total_s   = 0;
+       my $count = 0;
+       foreach my $key (@SessionsRange) {
+               my $p = 0;
+               if ($TotalVisits) {
+                       $p = int( $_session{$key} / $TotalVisits * 1000 ) / 10;
+               }
+               $total_s += $_session{$key} || 0;
+               print "<tr><td class=\"aws\">$key</td>";
+               print "<td>"
+                 . ( $_session{$key} ? Format_Number($_session{$key}) : "&nbsp;" ) . "</td>";
+               print "<td>"
+                 . ( $_session{$key} ? "$p %" : "&nbsp;" ) . "</td>";
+               print "</tr>\n";
+               $count++;
+       }
+       my $rest_s = $TotalVisits - $total_s;
+       if ( $rest_s > 0 ) {    # All others sessions
+               my $p = 0;
+               if ($TotalVisits) {
+                       $p = int( $rest_s / $TotalVisits * 1000 ) / 10;
+               }
+               print "<tr"
+                 . Tooltip(20)
+                 . "><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
+               print "<td>".Format_Number($rest_s)."</td>";
+               print "<td>" . ( $rest_s ? "$p %" : "&nbsp;" ) . "</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                                               # This is a second visit or more
-                                               if ( !$_waithost_s{$HostResolved} ) {
+#------------------------------------------------------------------------------
+# Function:     Prints the pages chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainPages{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) {
+               debug(
+"ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",
+                       2
+               );
+       }
+       print
+"$Center<a name=\"urls\">&nbsp;</a><a name=\"entry\">&nbsp;</a><a name=\"exit\">&nbsp;</a><br />\n";
+       my $title =
+"$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=urldetail")
+               : "$StaticLinks.urldetail.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a>";
+       if ( $ShowPagesStats =~ /E/i ) {
+               $title .= " &nbsp; - &nbsp; <a href=\""
+                 . (
+                       $ENV{'GATEWAY_INTERFACE'}
+                         || !$StaticLinks
+                       ? XMLEncode("$AWScript?${NewLinkParams}output=urlentry")
+                       : "$StaticLinks.urlentry.$StaticExt"
+                 )
+                 . "\"$NewLinkTarget>$Message[104]</a>";
+       }
+       if ( $ShowPagesStats =~ /X/i ) {
+               $title .= " &nbsp; - &nbsp; <a href=\""
+                 . (
+                       $ENV{'GATEWAY_INTERFACE'}
+                         || !$StaticLinks
+                       ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
+                       : "$StaticLinks.urlexit.$StaticExt"
+                 )
+                 . "\"$NewLinkTarget>$Message[116]</a>";
+       }
+       &tab_head( "$title", 19, 0, 'urls' );
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentPages)." $Message[28]</th>";
+       if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
+       }
+       if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+       }
+       if ( $ShowPagesStats =~ /B/i ) {
+               print
+                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
+       }
+       if ( $ShowPagesStats =~ /E/i ) {
+               print
+                 "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
+       }
+       if ( $ShowPagesStats =~ /X/i ) {
+               print
+                 "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
+       }
 
-                                                       # This is a second visit or more
-                                                       # We count 'visit','exit','entry','DayVisits'
-                                                       if ($Debug) {
-                                                               debug(
-"  This is a second visit for $HostResolved.",
-                                                                       4
-                                                               );
-                                                       }
-                                                       my $timehosts = $_host_s{$HostResolved};
-                                                       my $page      = $_host_u{$HostResolved};
-                                                       if ($page) { $_url_x{$page}++; }
-                                                       $_url_e{ $field[$pos_url] }++;
-                                                       $DayVisits{$yearmonthdayrecord}++;
+       # Call to plugins' function ShowPagesAddField
+       foreach
+         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+       {
 
-                                # We can't count session yet because we don't have the start so
-                                # we save params of first 'wait' session
-                                                       $_waithost_l{$HostResolved} = $timehostl;
-                                                       $_waithost_s{$HostResolved} = $timehosts;
-                                                       $_waithost_u{$HostResolved} = $page;
-                                               }
-                                               else {
+               #                               my $function="ShowPagesAddField_$pluginname('title')";
+               #                               eval("$function");
+               my $function = "ShowPagesAddField_$pluginname";
+               &$function('title');
+       }
+       print "<th>&nbsp;</th></tr>\n";
+       my $total_p = my $total_e = my $total_x = my $total_k = 0;
+       my $max_p   = 1;
+       my $max_k   = 1;
+       my $count = 0;
+       &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
+               \%_url_p );
+       foreach my $key (@keylist) {
+               if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
+               if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
+                       $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
+               }
+       }
+       foreach my $key (@keylist) {
+               print "<tr><td class=\"aws\">";
+               &HTMLShowURLInfo($key);
+               print "</td>";
+               my $bredde_p = 0;
+               my $bredde_e = 0;
+               my $bredde_x = 0;
+               my $bredde_k = 0;
+               if ( $max_p > 0 ) {
+                       $bredde_p =
+                         int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
+               if ( $max_p > 0 ) {
+                       $bredde_e =
+                         int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
+               if ( $max_p > 0 ) {
+                       $bredde_x =
+                         int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
+               }
+               if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
+               if ( $max_k > 0 ) {
+                       $bredde_k =
+                         int( $BarWidth *
+                                 ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
+                                 $max_k ) + 1;
+               }
+               if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
+               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
+                       print "<td>".Format_Number($_url_p{$key})."</td>";
+               }
+               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
+                       print "<td>".Format_Number($_url_p{$key})."</td>";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print "<td>"
+                         . (
+                               $_url_k{$key}
+                               ? Format_Bytes(
+                                       $_url_k{$key} / ( $_url_p{$key} || 1 )
+                                 )
+                               : "&nbsp;"
+                         )
+                         . "</td>";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print "<td>"
+                         . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print "<td>"
+                         . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
+               }
 
-                                                # This is third visit or more
-                                                # We count 'session','visit','exit','entry','DayVisits'
-                                                       if ($Debug) {
-                                                               debug(
-"  This is a third visit or more for $HostResolved.",
-                                                                       4
-                                                               );
-                                                       }
-                                                       my $timehosts = $_host_s{$HostResolved};
-                                                       my $page      = $_host_u{$HostResolved};
-                                                       if ($page) { $_url_x{$page}++; }
-                                                       $_url_e{ $field[$pos_url] }++;
-                                                       $DayVisits{$yearmonthdayrecord}++;
-                                                       if ($timehosts) {
-                                                               $_session{ GetSessionRange( $timehosts,
-                                                                               $timehostl ) }++;
-                                                       }
-                                               }
-
-                                               # Save new session properties
-                                               $_host_s{$HostResolved} = $timerecord;
-                                               $_host_l{$HostResolved} = $timerecord;
-                                               $_host_u{$HostResolved} = $field[$pos_url];
-                                       }
-                                       elsif ( $timerecord > $timehostl ) {
+               # Call to plugins' function ShowPagesAddField
+               foreach my $pluginname (
+                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+               {
 
-                                               # This is a same visit we can count
-                                               if ($Debug) {
-                                                       debug(
-"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
-                                                               4
-                                                       );
-                                               }
-                                               $_host_l{$HostResolved} = $timerecord;
-                                               $_host_u{$HostResolved} = $field[$pos_url];
-                                       }
-                                       elsif ( $timerecord == $timehostl ) {
+                       #                                       my $function="ShowPagesAddField_$pluginname('$key')";
+                       #                                       eval("$function");
+                       my $function = "ShowPagesAddField_$pluginname";
+                       &$function($key);
+               }
+               print "<td class=\"aws\">";
+               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\""
+                         . AltTitle("")
+                         . " /><br />";
+               }
+               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_p\" height=\"4\""
+                         . AltTitle("")
+                         . " /><br />";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\""
+                         . AltTitle("")
+                         . " /><br />";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\""
+                         . AltTitle("")
+                         . " /><br />";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print
+"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\""
+                         . AltTitle("") . " />";
+               }
+               print "</td></tr>\n";
+               $total_p += $_url_p{$key} || 0;
+               $total_e += $_url_e{$key} || 0;
+               $total_x += $_url_x{$key} || 0;
+               $total_k += $_url_k{$key} || 0;
+               $count++;
+       }
+       my $rest_p = $TotalPages - $total_p;
+       my $rest_e = $TotalEntries - $total_e;
+       my $rest_x = $TotalExits - $total_x;
+       my $rest_k = $TotalBytesPages - $total_k;
+       if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
+       {    # All other urls
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
+                       print "<td>".Format_Number($rest_p)."</td>";
+               }
+               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
+                       print "<td>".Format_Number($rest_p)."</td>";
+               }
+               if ( $ShowPagesStats =~ /B/i ) {
+                       print "<td>"
+                         . (
+                               $rest_k
+                               ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
+                               : "&nbsp;"
+                         )
+                         . "</td>";
+               }
+               if ( $ShowPagesStats =~ /E/i ) {
+                       print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowPagesStats =~ /X/i ) {
+                       print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
+               }
 
-                                               # This is a same visit we can count
-                                               if ($Debug) {
-                                                       debug(
-"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
-                                                               4
-                                                       );
-                                               }
-                                               $_host_u{$HostResolved} = $field[$pos_url];
-                                       }
-                                       elsif ( $timerecord < $_host_s{$HostResolved} ) {
+               # Call to plugins' function ShowPagesAddField
+               foreach my $pluginname (
+                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
+               {
 
-                                          # Should happens only with not correctly sorted log files
-                                               if ($Debug) {
-                                                       debug(
-"  This is same visit still running for $HostResolved with start not in order. host_s changed to $timerecord (entry page also changed if first visit)",
-                                                               4
-                                                       );
-                                               }
-                                               if ( !$_waithost_s{$HostResolved} ) {
+                       #                                       my $function="ShowPagesAddField_$pluginname('')";
+                       #                                       eval("$function");
+                       my $function = "ShowPagesAddField_$pluginname";
+                       &$function('');
+               }
+               print "<td>&nbsp;</td></tr>\n";
+       }
+       &tab_end();
+}
 
-# We can reorder entry page only if it's the first visit found in this update run (The saved entry page was $_waithost_e if $_waithost_s{$HostResolved} is not defined. If second visit or more, entry was directly counted and not saved)
-                                                       $_waithost_e{$HostResolved} = $field[$pos_url];
-                                               }
-                                               else {
+#------------------------------------------------------------------------------
+# Function:     Prints the OS chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainOS{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
 
-# We can't change entry counted as we dont't know what was the url counted as entry
-                                               }
-                                               $_host_s{$HostResolved} = $timerecord;
-                                       }
-                                       else {
-                                               if ($Debug) {
-                                                       debug(
-"  This is same visit still running for $HostResolved with hit between start and last hits. No change",
-                                                               4
-                                                       );
-                                               }
+       if ($Debug) { debug( "ShowOSStats", 2 ); }
+       print "$Center<a name=\"os\">&nbsp;</a><br />\n";
+       my $Totalh   = 0;
+       my %new_os_h = ();
+  OSLOOP: foreach my $key ( keys %_os_h ) {
+               $Totalh += $_os_h{$key};
+               foreach my $family ( keys %OSFamily ) {
+                       if ( $key =~ /^$family/i ) {
+                               $new_os_h{"${family}cumul"} += $_os_h{$key};
+                               next OSLOOP;
+                       }
+               }
+               $new_os_h{$key} += $_os_h{$key};
+       }
+       my $title =
+"$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=osdetail")
+               : "$StaticLinks.osdetail.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownos")
+               : "$StaticLinks.unknownos.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[0]</a>";
+       &tab_head( "$title", 19, 0, 'os' );
+       
+       &BuildKeyList( $MaxNbOf{'OsShown'}, $MinHit{'Os'}, \%new_os_h,
+               \%new_os_h );
+               
+       # Graph the top five in a pie chart
+       if (scalar %BrowsersFamily > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int(  $new_os_h{$key} / $Totalh * 1000 ) / 10;
+                               if ($key eq 'Unknown'){push @blocklabel, "$key"; }
+                               else{
+                                       my $keywithoutcumul = $key;
+                                       $keywithoutcumul =~ s/cumul$//i;
+                                       my $libos = $OSHashLib{$keywithoutcumul}
+                                         || $keywithoutcumul;
+                                       my $nameicon = $keywithoutcumul;
+                                       $nameicon =~ s/[^\w]//g;
+                                       if ( $OSFamily{$keywithoutcumul} ) {
+                                               $libos = $OSFamily{$keywithoutcumul};
                                        }
+                                       push @blocklabel, "$libos";
                                }
-                               else {
+                               $cnt++;
+                               if ($cnt > 4) { last; }
+                       }
+                       print "<tr><td colspan=\"5\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "Top 5 Operating Systems",       "oss",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th>$Message[59]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       
+       foreach my $key (@keylist) {
+               my $p = '&nbsp;';
+               if ($Totalh) {
+                       $p = int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               if ( $key eq 'Unknown' ) {
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/os\/unknown.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td>".Format_Number($_os_h{$key})."</td><td>$p</td></tr>\n";
+               }
+               else {
+                       my $keywithoutcumul = $key;
+                       $keywithoutcumul =~ s/cumul$//i;
+                       my $libos = $OSHashLib{$keywithoutcumul}
+                         || $keywithoutcumul;
+                       my $nameicon = $keywithoutcumul;
+                       $nameicon =~ s/[^\w]//g;
+                       if ( $OSFamily{$keywithoutcumul} ) {
+                               $libos = "<b>" . $OSFamily{$keywithoutcumul} . "</b>";
+                       }
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/os\/$nameicon.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\">$libos</td><td>".Format_Number($new_os_h{$key})."</td><td>$p</td></tr>\n";
+               }
+               $total_h += $new_os_h{$key};
+               $count++;
+       }
+       if ($Debug) {
+               debug( "Total real / shown : $Totalh / $total_h", 2 );
+       }
+       my $rest_h = $Totalh - $total_h;
+       if ( $rest_h > 0 ) {
+               my $p;
+               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
+               print "<tr>";
+               print "<td>&nbsp;</td>";
+               print
+"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>".Format_Number($rest_h)."</td>";
+               print "<td>$p %</td></tr>\n";
+       }
+       &tab_end();
+}
 
-# This is a new visit (may be). First new visit found for this host. We save in wait array the entry page to count later
-                                       if ($Debug) {
-                                               debug(
-"  New session (may be) for $HostResolved. Save in wait array to see later",
-                                                       4
-                                               );
+#------------------------------------------------------------------------------
+# Function:     Prints the Browsers chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainBrowsers{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowBrowsersStats", 2 ); }
+       print "$Center<a name=\"browsers\">&nbsp;</a><br />\n";
+       my $Totalh        = 0;
+       my %new_browser_h = ();
+  BROWSERLOOP: foreach my $key ( keys %_browser_h ) {
+               $Totalh += $_browser_h{$key};
+               foreach my $family ( keys %BrowsersFamily ) {
+                       if ( $key =~ /^$family/i ) {
+                               $new_browser_h{"${family}cumul"} += $_browser_h{$key};
+                               next BROWSERLOOP;
+                       }
+               }
+               $new_browser_h{$key} += $_browser_h{$key};
+       }
+       my $title =
+"$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=browserdetail")
+               : "$StaticLinks.browserdetail.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownbrowser")
+               : "$StaticLinks.unknownbrowser.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[0]</a>";
+       &tab_head( "$title", 19, 0, 'browsers' );
+       
+       &BuildKeyList(
+               $MaxNbOf{'BrowsersShown'}, $MinHit{'Browser'},
+               \%new_browser_h,           \%new_browser_h
+       );
+       
+       # Graph the top five in a pie chart
+       if (scalar %BrowsersFamily > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int(  $new_browser_h{$key} / $TotalHits * 1000 ) / 10;
+                               if ($key eq 'Unknown'){push @blocklabel, "$key"; }
+                               else{
+                                       my $keywithoutcumul = $key;
+                                       $keywithoutcumul =~ s/cumul$//i;
+                                       my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
+                                         || $keywithoutcumul;
+                                       my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
+                                         || "notavailable";
+                                       if ( $BrowsersFamily{$keywithoutcumul} ) {
+                                               $libbrowser = "$libbrowser";
                                        }
-                                       $_waithost_e{$HostResolved} = $field[$pos_url];
-
-                                       # Save new session properties
-                                       $_host_u{$HostResolved} = $field[$pos_url];
-                                       $_host_s{$HostResolved} = $timerecord;
-                                       $_host_l{$HostResolved} = $timerecord;
+                                       push @blocklabel, "$libbrowser";
                                }
-                               $_host_p{$HostResolved}++;
-                       }
-                       $_host_h{$HostResolved}++;
-                       if ( $field[$pos_size] ne '-' ) {
-                               $_host_k{$HostResolved} += int( $field[$pos_size] );
+                               $cnt++;
+                               if ($cnt > 4) { last; }
                        }
+                       print "<tr><td colspan=\"5\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "Top 5 Browsers",       "browsers",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th>$Message[21]</th><th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       foreach my $key (@keylist) {
+               my $p = '&nbsp;';
+               if ($Totalh) {
+                       $p = int( $new_browser_h{$key} / $Totalh * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               if ( $key eq 'Unknown' ) {
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td><td>".Format_Number($_browser_h{$key})."</td><td>$p</td></tr>\n";
+               }
+               else {
+                       my $keywithoutcumul = $key;
+                       $keywithoutcumul =~ s/cumul$//i;
+                       my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
+                         || $keywithoutcumul;
+                       my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
+                         || "notavailable";
+                       if ( $BrowsersFamily{$keywithoutcumul} ) {
+                               $libbrowser = "<b>$libbrowser</b>";
+                       }
+                       print "<tr><td"
+                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
+                         . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
+                         . AltTitle("")
+                         . " /></td><td class=\"aws\">"
+                         . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                         . "$libbrowser"
+                         . ( $PageDir eq 'rtl' ? "</span>" : "" )
+                         . "</td><td>"
+                         . (
+                               $BrowsersHereAreGrabbers{$key}
+                               ? "<b>$Message[112]</b>"
+                               : "$Message[113]"
+                         )
+                         . "</td><td>".Format_Number($new_browser_h{$key})."</td><td>$p</td></tr>\n";
+               }
+               $total_h += $new_browser_h{$key};
+               $count++;
+       }
+       if ($Debug) {
+               debug( "Total real / shown : $Totalh / $total_h", 2 );
+       }
+       my $rest_h = $Totalh - $total_h;
+       if ( $rest_h > 0 ) {
+               my $p;
+               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
+               print "<tr>";
+               print "<td>&nbsp;</td>";
+               print
+"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>&nbsp;</td><td>$rest_h</td>";
+                       print "<td>$p %</td></tr>\n";
+               }
+               &tab_end();
+}
 
-                       # Analyze: Browser - OS
-                       #----------------------
-                       if ( $pos_agent >= 0 ) {
-
-                               if ($LevelForBrowsersDetection) {
-
-                                       # Analyze: Browser
-                                       #-----------------
-                                       my $uabrowser = $TmpBrowser{$UserAgent};
-                                       if ( !$uabrowser ) {
-                                               my $found = 1;
+#------------------------------------------------------------------------------
+# Function:     Prints the ScreenSize chart and table
+# Parameters:   -
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainScreenSize{
+       if ($Debug) { debug( "ShowScreenSizeStats", 2 ); }
+       print "$Center<a name=\"screensizes\">&nbsp;</a><br />\n";
+       my $Totalh = 0;
+       foreach ( keys %_screensize_h ) { $Totalh += $_screensize_h{$_}; }
+       my $title =
+         "$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
+       &tab_head( "$title", 0, 0, 'screensizes' );
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[135]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
+       my $total_h = 0;
+       my $count   = 0;
+       &BuildKeyList( $MaxNbOf{'ScreenSizesShown'},
+               $MinHit{'ScreenSize'}, \%_screensize_h, \%_screensize_h );
 
-                                               # Firefox ?
-                                               if (   $UserAgent =~ /$regverfirefox/o
-                                                       && $UserAgent !~ /$regnotfirefox/o )
-                                               {
-                                                       $_browser_h{"firefox$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "firefox$1";
-                                               }
+       foreach my $key (@keylist) {
+               my $p = '&nbsp;';
+               if ($Totalh) {
+                       $p = int( $_screensize_h{$key} / $Totalh * 1000 ) / 10;
+                       $p = "$p %";
+               }
+               $total_h += $_screensize_h{$key} || 0;
+               print "<tr>";
+               if ( $key eq 'Unknown' ) {
+                       print
+"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
+                       print "<td>$p</td>";
+               }
+               else {
+                       my $screensize = $key;
+                       print "<td class=\"aws\">$screensize</td>";
+                       print "<td>$p</td>";
+               }
+               print "</tr>\n";
+               $count++;
+       }
+       my $rest_h = $Totalh - $total_h;
+       if ( $rest_h > 0 ) {    # All others sessions
+               my $p = 0;
+               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
+               print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
+               print "<td>" . ( $rest_h ? "$p %" : "&nbsp;" ) . "</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                                               # Opera ?
-                                               elsif ( $UserAgent =~ /$regveropera/o ) {
-                                                       $_browser_h{"opera$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "opera$1";
-                                               }
+#------------------------------------------------------------------------------
+# Function:     Prints the Referrers chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainReferrers{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowOriginStats", 2 ); }
+       print "$Center<a name=\"referer\">&nbsp;</a><br />\n";
+       my $Totalp = 0;
+       foreach ( 0 .. 5 ) {
+               $Totalp +=
+                 ( $_ != 4 || $IncludeInternalLinksInOriginSection )
+                 ? $_from_p[$_]
+                 : 0;
+       }
+       my $Totalh = 0;
+       foreach ( 0 .. 5 ) {
+               $Totalh +=
+                 ( $_ != 4 || $IncludeInternalLinksInOriginSection )
+                 ? $_from_h[$_]
+                 : 0;
+       }
+       &tab_head( $Message[36], 19, 0, 'referer' );
+       my @p_p = ( 0, 0, 0, 0, 0, 0 );
+       if ( $Totalp > 0 ) {
+               $p_p[0] = int( $_from_p[0] / $Totalp * 1000 ) / 10;
+               $p_p[1] = int( $_from_p[1] / $Totalp * 1000 ) / 10;
+               $p_p[2] = int( $_from_p[2] / $Totalp * 1000 ) / 10;
+               $p_p[3] = int( $_from_p[3] / $Totalp * 1000 ) / 10;
+               $p_p[4] = int( $_from_p[4] / $Totalp * 1000 ) / 10;
+               $p_p[5] = int( $_from_p[5] / $Totalp * 1000 ) / 10;
+       }
+       my @p_h = ( 0, 0, 0, 0, 0, 0 );
+       if ( $Totalh > 0 ) {
+               $p_h[0] = int( $_from_h[0] / $Totalh * 1000 ) / 10;
+               $p_h[1] = int( $_from_h[1] / $Totalh * 1000 ) / 10;
+               $p_h[2] = int( $_from_h[2] / $Totalh * 1000 ) / 10;
+               $p_h[3] = int( $_from_h[3] / $Totalh * 1000 ) / 10;
+               $p_h[4] = int( $_from_h[4] / $Totalh * 1000 ) / 10;
+               $p_h[5] = int( $_from_h[5] / $Totalh * 1000 ) / 10;
+       }
+       print
+         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[37]</th>";
+       if ( $ShowOriginStats =~ /P/i ) {
+               print
+"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
+       }
+       if ( $ShowOriginStats =~ /H/i ) {
+               print
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       }
+       print "</tr>\n";
 
-                                               # Chrome ?
-                                               elsif ( $UserAgent =~ /$regverchrome/o ) {
-                                                       $_browser_h{"chrome$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "chrome$1";
-                                               }
+       #------- Referrals by direct address/bookmark/link in email/etc...
+       print "<tr><td class=\"aws\"><b>$Message[38]</b></td>";
+       if ( $ShowOriginStats =~ /P/i ) {
+               print "<td>"
+                 . ( $_from_p[0] ? Format_Number($_from_p[0]) : "&nbsp;" )
+                 . "</td><td>"
+                 . ( $_from_p[0] ? "$p_p[0] %" : "&nbsp;" ) . "</td>";
+       }
+       if ( $ShowOriginStats =~ /H/i ) {
+               print "<td>"
+                 . ( $_from_h[0] ? Format_Number($_from_h[0]) : "&nbsp;" )
+                 . "</td><td>"
+                 . ( $_from_h[0] ? "$p_h[0] %" : "&nbsp;" ) . "</td>";
+       }
+       print "</tr>\n";
 
-                                               # Safari ?
-                                               elsif ($UserAgent =~ /$regversafari/o
-                                                       && $UserAgent !~ /$regnotsafari/o )
-                                               {
-                                                       my $safariver = $SafariBuildToVersion{$1};
-                                                       if ( $UserAgent =~ /$regversafariver/o ) {
-                                                               $safariver = $1;
-                                                       }
-                                                       $_browser_h{"safari$safariver"}++;
-                                                       $TmpBrowser{$UserAgent} = "safari$safariver";
-                                               }
+       #------- Referrals by search engines
+       print "<tr"
+         . Tooltip(13)
+         . "><td class=\"aws\"><b>$Message[40]</b> - <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=refererse")
+               : "$StaticLinks.refererse.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a><br />\n";
+       if ( scalar keys %_se_referrals_h ) {
+               print "<table>\n";
+               my $total_p = 0;
+               my $total_h = 0;
+               my $count = 0;
+               &BuildKeyList(
+                       $MaxNbOf{'RefererShown'},
+                       $MinHit{'Refer'},
+                       \%_se_referrals_h,
+                       (
+                               ( scalar keys %_se_referrals_p )
+                               ? \%_se_referrals_p
+                               : \%_se_referrals_h
+                       )
+               );
+               foreach my $key (@keylist) {
+                       my $newreferer = $SearchEnginesHashLib{$key}
+                         || CleanXSS($key);
+                       print "<tr><td class=\"aws\">- $newreferer</td>";
+                       print "<td>"
+                         . (
+                               Format_Number($_se_referrals_p{$key} ? $_se_referrals_p{$key} : '0' ))
+                         . "</td>";
+                       print "<td> / ".Format_Number($_se_referrals_h{$key})."</td>";
+                       print "</tr>\n";
+                       $total_p += $_se_referrals_p{$key};
+                       $total_h += $_se_referrals_h{$key};
+                       $count++;
+               }
+               if ($Debug) {
+                       debug(
+"Total real / shown : $TotalSearchEnginesPages / $total_p -  $TotalSearchEnginesHits / $total_h",
+                               2
+                       );
+               }
+               my $rest_p = $TotalSearchEnginesPages - $total_p;
+               my $rest_h = $TotalSearchEnginesHits - $total_h;
+               if ( $rest_p > 0 || $rest_h > 0 ) {
+                       print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
+                       print "<td>".Format_Number($rest_p)."</td>";
+                       print "<td> / ".Format_Number($rest_h)."</td>";
+                       print "</tr>\n";
+               }
+               print "</table>";
+       }
+       print "</td>\n";
+       if ( $ShowOriginStats =~ /P/i ) {
+               print "<td valign=\"top\">"
+                 . ( $_from_p[2] ? Format_Number($_from_p[2]) : "&nbsp;" )
+                 . "</td><td valign=\"top\">"
+                 . ( $_from_p[2] ? "$p_p[2] %" : "&nbsp;" ) . "</td>";
+       }
+       if ( $ShowOriginStats =~ /H/i ) {
+               print "<td valign=\"top\">"
+                 . ( $_from_h[2] ? Format_Number($_from_h[2]) : "&nbsp;" )
+                 . "</td><td valign=\"top\">"
+                 . ( $_from_h[2] ? "$p_h[2] %" : "&nbsp;" ) . "</td>";
+       }
+       print "</tr>\n";
 
-                                               # Konqueror ?
-                                               elsif ( $UserAgent =~ /$regverkonqueror/o ) {
-                                                       $_browser_h{"konqueror$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "konqueror$1";
-                                               }
+       #------- Referrals by external HTML link
+       print "<tr"
+         . Tooltip(14)
+         . "><td class=\"aws\"><b>$Message[41]</b> - <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'}
+                 || !$StaticLinks
+               ? XMLEncode("$AWScript?${NewLinkParams}output=refererpages")
+               : "$StaticLinks.refererpages.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a><br />\n";
+       if ( scalar keys %_pagesrefs_h ) {
+               print "<table>\n";
+               my $total_p = 0;
+               my $total_h = 0;
+               my $count = 0;
+               &BuildKeyList(
+                       $MaxNbOf{'RefererShown'},
+                       $MinHit{'Refer'},
+                       \%_pagesrefs_h,
+                       (
+                               ( scalar keys %_pagesrefs_p )
+                               ? \%_pagesrefs_p
+                               : \%_pagesrefs_h
+                       )
+               );
+               foreach my $key (@keylist) {
+                       print "<tr><td class=\"aws\">- ";
+                       &HTMLShowURLInfo($key);
+                       print "</td>";
+                       print "<td>"
+                         . Format_Number(( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '0' ))
+                         . "</td>";
+                       print "<td>".Format_Number($_pagesrefs_h{$key})."</td>";
+                       print "</tr>\n";
+                       $total_p += $_pagesrefs_p{$key};
+                       $total_h += $_pagesrefs_h{$key};
+                       $count++;
+               }
+               if ($Debug) {
+                       debug(
+"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
+                               2
+                       );
+               }
+               my $rest_p = $TotalRefererPages - $total_p;
+               my $rest_h = $TotalRefererHits - $total_h;
+               if ( $rest_p > 0 || $rest_h > 0 ) {
+                       print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
+                       print "<td>".Format_Number($rest_p)."</td>";
+                       print "<td>".Format_Number($rest_h)."</td>";
+                       print "</tr>\n";
+               }
+               print "</table>";
+       }
+       print "</td>\n";
+       if ( $ShowOriginStats =~ /P/i ) {
+               print "<td valign=\"top\">"
+                 . ( $_from_p[3] ? Format_Number($_from_p[3]) : "&nbsp;" )
+                 . "</td><td valign=\"top\">"
+                 . ( $_from_p[3] ? "$p_p[3] %" : "&nbsp;" ) . "</td>";
+       }
+       if ( $ShowOriginStats =~ /H/i ) {
+               print "<td valign=\"top\">"
+                 . ( $_from_h[3] ? Format_Number($_from_h[3]) : "&nbsp;" )
+                 . "</td><td valign=\"top\">"
+                 . ( $_from_h[3] ? "$p_h[3] %" : "&nbsp;" ) . "</td>";
+       }
+       print "</tr>\n";
 
-                                               # Subversion ?
-                                               elsif ( $UserAgent =~ /$regversvn/o ) {
-                                                       $_browser_h{"svn$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "svn$1";
-                                               }
+       #------- Referrals by internal HTML link
+       if ($IncludeInternalLinksInOriginSection) {
+               print "<tr><td class=\"aws\"><b>$Message[42]</b></td>";
+               if ( $ShowOriginStats =~ /P/i ) {
+                       print "<td>"
+                         . ( $_from_p[4] ? Format_Number($_from_p[4]) : "&nbsp;" )
+                         . "</td><td>"
+                         . ( $_from_p[4] ? "$p_p[4] %" : "&nbsp;" ) . "</td>";
+               }
+               if ( $ShowOriginStats =~ /H/i ) {
+                       print "<td>"
+                         . ( $_from_h[4] ? Format_Number($_from_h[4]) : "&nbsp;" )
+                         . "</td><td>"
+                         . ( $_from_h[4] ? "$p_h[4] %" : "&nbsp;" ) . "</td>";
+               }
+               print "</tr>\n";
+       }
 
-                                               # IE ? (must be at end of test)
-                                               elsif ($UserAgent =~ /$regvermsie/o
-                                                       && $UserAgent !~ /$regnotie/o )
-                                               {
-                                                       $_browser_h{"msie$2"}++;
-                                                       $TmpBrowser{$UserAgent} = "msie$2";
-                                               }
+       #------- Referrals by news group
+       #print "<tr><td class=\"aws\"><b>$Message[107]</b></td>";
+       #if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[5]?$_from_p[5]:"&nbsp;")."</td><td>".($_from_p[5]?"$p_p[5] %":"&nbsp;")."</td>"; }
+       #if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[5]?$_from_h[5]:"&nbsp;")."</td><td>".($_from_h[5]?"$p_h[5] %":"&nbsp;")."</td>"; }
+       #print "</tr>\n";
+       
+       #------- Unknown origin
+       print "<tr><td class=\"aws\"><b>$Message[39]</b></td>";
+       if ( $ShowOriginStats =~ /P/i ) {
+               print "<td>"
+                 . ( $_from_p[1] ? Format_Number($_from_p[1]) : "&nbsp;" )
+                 . "</td><td>"
+                 . ( $_from_p[1] ? "$p_p[1] %" : "&nbsp;" ) . "</td>";
+       }
+       if ( $ShowOriginStats =~ /H/i ) {
+               print "<td>"
+                 . ( $_from_h[1] ? Format_Number($_from_h[1]) : "&nbsp;" )
+                 . "</td><td>"
+                 . ( $_from_h[1] ? "$p_h[1] %" : "&nbsp;" ) . "</td>";
+       }
+       print "</tr>\n";
+       &tab_end();
 
-                                               # Netscape 6.x, 7.x ... ? (must be at end of test)
-                                               elsif ( $UserAgent =~ /$regvernetscape/o ) {
-                                                       $_browser_h{"netscape$1"}++;
-                                                       $TmpBrowser{$UserAgent} = "netscape$1";
-                                               }
+       # 0: Direct
+       # 1: Unknown
+       # 2: SE
+       # 3: External link
+       # 4: Internal link
+       # 5: Newsgroup (deprecated)
+}
 
-                                               # Netscape 3.x, 4.x ... ? (must be at end of test)
-                                               elsif ($UserAgent =~ /$regvermozilla/o
-                                                       && $UserAgent !~ /$regnotnetscape/o )
-                                               {
-                                                       $_browser_h{"netscape$2"}++;
-                                                       $TmpBrowser{$UserAgent} = "netscape$2";
-                                               }
+#------------------------------------------------------------------------------
+# Function:     Prints the Key Phrases and Keywords chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainKeys{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($ShowKeyphrasesStats) {
+               print "$Center<a name=\"keyphrases\">&nbsp;</a>";
+       }
+       if ($ShowKeywordsStats) {
+               print "$Center<a name=\"keywords\">&nbsp;</a>";
+       }
+       if ( $ShowKeyphrasesStats || $ShowKeywordsStats ) { print "<br />\n"; }
+       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+               print
+                 "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
+       }
+       if ($ShowKeyphrasesStats) {
+               
+               # By Keyphrases
+               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+                       print "<td width=\"50%\" valign=\"top\">\n";
+               }
+               if ($Debug) { debug( "ShowKeyphrasesStats", 2 ); }
+               &tab_head(
+"$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})<br /><a href=\""
+                         . (
+                               $ENV{'GATEWAY_INTERFACE'}
+                                 || !$StaticLinks
+                               ? XMLEncode("$AWScript?${NewLinkParams}output=keyphrases")
+                               : "$StaticLinks.keyphrases.$StaticExt"
+                         )
+                         . "\"$NewLinkTarget>$Message[80]</a>",
+                       19,
+                       ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
+                       'keyphrases'
+               );
+               print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+                 . Tooltip(15)
+                 . "><th>$TotalDifferentKeyphrases $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
+               my $total_s = 0;
+               my $count = 0;
+               &BuildKeyList( $MaxNbOf{'KeyphrasesShown'},
+                       $MinHit{'Keyphrase'}, \%_keyphrases, \%_keyphrases );
+               foreach my $key (@keylist) {
+                       my $mot;
 
-                                               # Other known browsers ?
-                                               else {
-                                                       $found = 0;
-                                                       foreach (@BrowsersSearchIDOrder)
-                                                       {    # Search ID in order of BrowsersSearchIDOrder
-                                                               if ( $UserAgent =~ /$_/ ) {
-                                                                       my $browser = &UnCompileRegex($_);
+  # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
+                       if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
+                               $mot = CleanXSS(
+                                       DecodeKey_decodeutfkeys(
+                                               $key, $PageCode || 'iso-8859-1'
+                                       )
+                               );
+                       }
+                       else { $mot = CleanXSS( DecodeEncodedString($key) ); }
+                       my $p;
+                       if ($TotalKeyphrases) {
+                               $p =
+                                 int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
+                       }
+                       print "<tr><td class=\"aws\">"
+                         . XMLEncode($mot)
+                         . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
+                       $total_s += $_keyphrases{$key};
+                       $count++;
+               }
+               if ($Debug) {
+                       debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
+               }
+               my $rest_s = $TotalKeyphrases - $total_s;
+               if ( $rest_s > 0 ) {
+                       my $p;
+                       if ($TotalKeyphrases) {
+                               $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
+                       }
+                       print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
+                       print "<td>$p&nbsp;%</td></tr>\n";
+               }
+               &tab_end();
+               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+                       print "</td>\n";
+               }
+       }
+       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+               print "<td> &nbsp; </td>";
+       }
+       if ($ShowKeywordsStats) {
 
-                                                                  # TODO If browser is in a family, use version
-                                                                       $_browser_h{"$browser"}++;
-                                                                       $TmpBrowser{$UserAgent} = "$browser";
-                                                                       $found = 1;
-                                                                       last;
-                                                               }
-                                                       }
-                                               }
+               # By Keywords
+               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+                       print "<td width=\"50%\" valign=\"top\">\n";
+               }
+               if ($Debug) { debug( "ShowKeywordsStats", 2 ); }
+               &tab_head(
+"$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})<br /><a href=\""
+                         . (
+                               $ENV{'GATEWAY_INTERFACE'}
+                                 || !$StaticLinks
+                               ? XMLEncode("$AWScript?${NewLinkParams}output=keywords")
+                               : "$StaticLinks.keywords.$StaticExt"
+                         )
+                         . "\"$NewLinkTarget>$Message[80]</a>",
+                       19,
+                       ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
+                       'keywords'
+               );
+               print "<tr bgcolor=\"#$color_TableBGRowTitle\""
+                 . Tooltip(15)
+                 . "><th>$TotalDifferentKeywords $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
+               my $total_s = 0;
+               my $count = 0;
+               &BuildKeyList( $MaxNbOf{'KeywordsShown'},
+                       $MinHit{'Keyword'}, \%_keywords, \%_keywords );
+               foreach my $key (@keylist) {
+                       my $mot;
 
-                                               # Unknown browser ?
-                                               if ( !$found ) {
-                                                       $_browser_h{'Unknown'}++;
-                                                       $TmpBrowser{$UserAgent} = 'Unknown';
-                                                       my $newua = $UserAgent;
-                                                       $newua =~ tr/\+ /__/;
-                                                       $_unknownrefererbrowser_l{$newua} = $timerecord;
-                                               }
-                                       }
-                                       else {
-                                               $_browser_h{$uabrowser}++;
-                                               if ( $uabrowser eq 'Unknown' ) {
-                                                       my $newua = $UserAgent;
-                                                       $newua =~ tr/\+ /__/;
-                                                       $_unknownrefererbrowser_l{$newua} = $timerecord;
-                                               }
-                                       }
+  # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
+                       if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
+                               $mot = CleanXSS(
+                                       DecodeKey_decodeutfkeys(
+                                               $key, $PageCode || 'iso-8859-1'
+                                       )
+                               );
+                       }
+                       else { $mot = CleanXSS( DecodeEncodedString($key) ); }
+                       my $p;
+                       if ($TotalKeywords) {
+                               $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
+                       }
+                       print "<tr><td class=\"aws\">"
+                         . XMLEncode($mot)
+                         . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
+                       $total_s += $_keywords{$key};
+                       $count++;
+               }
+               if ($Debug) {
+                       debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
+               }
+               my $rest_s = $TotalKeywords - $total_s;
+               if ( $rest_s > 0 ) {
+                       my $p;
+                       if ($TotalKeywords) {
+                               $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
+                       }
+                       print
+"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
+                       print "<td>$p %</td></tr>\n";
+               }
+               &tab_end();
+               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+                       print "</td>\n";
+               }
+       }
+       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
+               print "</tr></table>\n";
+       }
+}
 
-                               }
+#------------------------------------------------------------------------------
+# Function:     Prints the miscellaneous table
+# Parameters:   -
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainMisc{
+       if ($Debug) { debug( "ShowMiscStats", 2 ); }
+       print "$Center<a name=\"misc\">&nbsp;</a><br />\n";
+       my $title = "$Message[139]";
+       &tab_head( "$title", 19, 0, 'misc' );
+       print
+         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[139]</th>";
+       print "<th width=\"100\">&nbsp;</th>";
+       print "<th width=\"100\">&nbsp;</th>";
+       print "</tr>\n";
+       my %label = (
+               'AddToFavourites'           => $Message[137],
+               'JavascriptDisabled'        => $Message[168],
+               'JavaEnabled'               => $Message[140],
+               'DirectorSupport'           => $Message[141],
+               'FlashSupport'              => $Message[142],
+               'RealPlayerSupport'         => $Message[143],
+               'QuickTimeSupport'          => $Message[144],
+               'WindowsMediaPlayerSupport' => $Message[145],
+               'PDFSupport'                => $Message[146]
+       );
 
-                               if ($LevelForOSDetection) {
+       foreach my $key (@MiscListOrder) {
+               my $mischar = substr( $key, 0, 1 );
+               if ( $ShowMiscStats !~ /$mischar/i ) { next; }
+               my $total = 0;
+               my $p;
+               if ( $MiscListCalc{$key} eq 'v' ) { $total = $TotalVisits; }
+               if ( $MiscListCalc{$key} eq 'u' ) { $total = $TotalUnique; }
+               if ( $MiscListCalc{$key} eq 'hm' ) {
+                       $total = $_misc_h{'TotalMisc'} || 0;
+               }
+               if ($total) {
+                       $p =
+                         int( ( $_misc_h{$key} ? $_misc_h{$key} : 0 ) / $total *
+                                 1000 ) / 10;
+               }
+               print "<tr>";
+               print "<td class=\"aws\">"
+                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
+                 . $label{$key}
+                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
+               if ( $MiscListCalc{$key} eq 'v' ) {
+                       print "<td>"
+                         . Format_Number(( $_misc_h{$key} || 0 ))
+                         . " / ".Format_Number($total)." $Message[12]</td>";
+               }
+               if ( $MiscListCalc{$key} eq 'u' ) {
+                       print "<td>"
+                         . Format_Number(( $_misc_h{$key} || 0 ))
+                         . " / ".Format_Number($total)." $Message[18]</td>";
+               }
+               if ( $MiscListCalc{$key} eq 'hm' ) { print "<td>-</td>"; }
+               print "<td>" . ( $total ? "$p %" : "&nbsp;" ) . "</td>";
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                                       # Analyze: OS
-                                       #------------
-                                       my $uaos = $TmpOS{$UserAgent};
-                                       if ( !$uaos ) {
-                                               my $found = 0;
+#------------------------------------------------------------------------------
+# Function:     Prints the Status codes chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainHTTPStatus{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowHTTPErrorsStats", 2 ); }
+       print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
+       my $title = "$Message[32]";
+       &tab_head( "$title", 19, 0, 'errors' );
+       
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
+               
+       # Graph the top five in a pie chart
+       if (scalar @keylist > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
+                               push @blocklabel, "$key";
+                               $cnt++;
+                               if ($cnt > 4) { last; }
+                       }
+                       print "<tr><td colspan=\"5\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "$title",              "httpstatus",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[32]*</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       foreach my $key (@keylist) {
+               my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
+               print "<tr" . Tooltip( $key, $key ) . ">";
+               if ( $TrapInfosForHTTPErrorCodes{$key} ) {
+                       print "<td><a href=\""
+                         . (
+                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+                               ? XMLEncode(
+                                       "$AWScript?${NewLinkParams}output=errors$key")
+                               : "$StaticLinks.errors$key.$StaticExt"
+                         )
+                         . "\"$NewLinkTarget>$key</a></td>";
+               }
+               else { print "<td valign=\"top\">$key</td>"; }
+               print "<td class=\"aws\">"
+                 . (
+                       $httpcodelib{$key} ? $httpcodelib{$key} : 'Unknown error' )
+                 . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
+                 . Format_Bytes( $_errors_k{$key} ) . "</td>";
+               print "</tr>\n";
+               $total_h += $_errors_h{$key};
+               $count++;
+       }
+       &tab_end("* $Message[154]");
+}
 
-                                               # in OSHashID list ?
-                                               foreach (@OSSearchIDOrder)
-                                               {    # Search ID in order of OSSearchIDOrder
-                                                       if ( $UserAgent =~ /$_/ ) {
-                                                               my $osid = $OSHashID{ &UnCompileRegex($_) };
-                                                               $_os_h{"$osid"}++;
-                                                               $TmpOS{$UserAgent} = "$osid";
-                                                               $found = 1;
-                                                               last;
-                                                       }
-                                               }
+#------------------------------------------------------------------------------
+# Function:     Prints the Status codes chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainSMTPStatus{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowSMTPErrorsStats", 2 ); }
+       print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
+       my $title = "$Message[147]";
+       &tab_head( "$title", 19, 0, 'errors' );
+       print
+"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[147]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
+       my $total_h = 0;
+       my $count = 0;
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
 
-                                               # Unknown OS ?
-                                               if ( !$found ) {
-                                                       $_os_h{'Unknown'}++;
-                                                       $TmpOS{$UserAgent} = 'Unknown';
-                                                       my $newua = $UserAgent;
-                                                       $newua =~ tr/\+ /__/;
-                                                       $_unknownreferer_l{$newua} = $timerecord;
-                                               }
-                                       }
-                                       else {
-                                               $_os_h{$uaos}++;
-                                               if ( $uaos eq 'Unknown' ) {
-                                                       my $newua = $UserAgent;
-                                                       $newua =~ tr/\+ /__/;
-                                                       $_unknownreferer_l{$newua} = $timerecord;
-                                               }
-                                       }
-
-                               }
+       foreach my $key (@keylist) {
+               my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
+               print "<tr" . Tooltip( $key, $key ) . ">";
+               print "<td valign=\"top\">$key</td>";
+               print "<td class=\"aws\">"
+                 . (
+                       $smtpcodelib{$key} ? $smtpcodelib{$key} : 'Unknown error' )
+                 . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
+                 . Format_Bytes( $_errors_k{$key} ) . "</td>";
+               print "</tr>\n";
+               $total_h += $_errors_h{$key};
+               $count++;
+       }
+       &tab_end();
+}
 
+#------------------------------------------------------------------------------
+# Function:     Prints the cluster information chart and table
+# Parameters:   $NewLinkParams, $NewLinkTarget
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainCluster{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       
+       if ($Debug) { debug( "ShowClusterStats", 2 ); }
+       print "$Center<a name=\"clusters\">&nbsp;</a><br />\n";
+       my $title = "$Message[155]";
+       &tab_head( "$title", 19, 0, 'clusters' );
+       
+       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_cluster_p, \%_cluster_p );
+       
+       # Graph the top five in a pie chart
+       if (scalar @keylist > 1){
+               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+               {
+                       my @blocklabel = ();
+                       my @valdata = ();
+                       my @valcolor = ($color_p);
+                       my $cnt = 0;
+                       foreach my $key (@keylist) {
+                               push @valdata, int( $_cluster_p{$key} / $TotalHits * 1000 ) / 10;
+                               push @blocklabel, "$key";
+                               $cnt++;
+                               if ($cnt > 4) { last; }
                        }
-                       else {
-                               $_browser_h{'Unknown'}++;
-                               $_os_h{'Unknown'}++;
-                       }
+                       print "<tr><td colspan=\"7\">";
+                       my $function = "ShowGraph_$pluginname";
+                       &$function(
+                               "$title",              "cluster",
+                               0,                                              \@blocklabel,
+                               0,                              \@valcolor,
+                               0,                              0,
+                               0,                              \@valdata
+                       );
+                       print "</td></tr>";
+               }
+       }
+       
+       print
+         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[155]</th>";
+       &HTMLShowClusterInfo('__title__');
+       if ( $ShowClusterStats =~ /P/i ) {
+               print
+"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
+       }
+       if ( $ShowClusterStats =~ /H/i ) {
+               print
+"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
+       }
+       if ( $ShowClusterStats =~ /B/i ) {
+               print
+"<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = 0;
 
-                       # Analyze: Referer
-                       #-----------------
-                       my $found = 0;
-                       if (   $pos_referer >= 0
-                               && $LevelForRefererAnalyze
-                               && $field[$pos_referer] )
-                       {
+# Cluster feature might have been enable in middle of month so we recalculate
+# total for cluster section only, to calculate ratio, instead of using global total
+       foreach my $key (@keylist) {
+               $total_p += int( $_cluster_p{$key} || 0 );
+               $total_h += int( $_cluster_h{$key} || 0 );
+               $total_k += int( $_cluster_k{$key} || 0 );
+       }
+       my $count = 0;
+       foreach my $key (@keylist) {
+               my $p_p = int( $_cluster_p{$key} / $total_p * 1000 ) / 10;
+               my $p_h = int( $_cluster_h{$key} / $total_h * 1000 ) / 10;
+               my $p_k = int( $_cluster_k{$key} / $total_k * 1000 ) / 10;
+               print "<tr>";
+               print "<td class=\"aws\">Computer $key</td>";
+               &HTMLShowClusterInfo($key);
+               if ( $ShowClusterStats =~ /P/i ) {
+                       print "<td>"
+                         . ( $_cluster_p{$key} ? Format_Number($_cluster_p{$key}) : "&nbsp;" )
+                         . "</td><td>$p_p %</td>";
+               }
+               if ( $ShowClusterStats =~ /H/i ) {
+                       print "<td>".Format_Number($_cluster_h{$key})."</td><td>$p_h %</td>";
+               }
+               if ( $ShowClusterStats =~ /B/i ) {
+                       print "<td>"
+                         . Format_Bytes( $_cluster_k{$key} )
+                         . "</td><td>$p_k %</td>";
+               }
+               print "</tr>\n";
+               $count++;
+       }
+       &tab_end();
+}
 
-                               # Direct ?
-                               if (   $field[$pos_referer] eq '-'
-                                       || $field[$pos_referer] eq 'bookmarks' )
-                               {  # "bookmarks" is sent by Netscape, '-' by all others browsers
-                                           # Direct access
-                                       if ($PageBool) {
-                                               if ($ShowDirectOrigin) {
-                                                       print "Direct access for line $line\n";
-                                               }
-                                               $_from_p[0]++;
-                                       }
-                                       $_from_h[0]++;
-                                       $found = 1;
-                               }
-                               else {
-                                       $field[$pos_referer] =~ /$regreferer/o;
-                                       my $refererprot   = $1;
-                                       my $refererserver =
-                                           ( $2 || '' )
-                                         . ( !$3 || $3 eq ':80' ? '' : $3 )
-                                         ; # refererserver is www.xxx.com or www.xxx.com:81 but not www.xxx.com:80
-                                           # HTML link ?
-                                       if ( $refererprot =~ /^http/i ) {
+#------------------------------------------------------------------------------
+# Function:     Prints a chart or table for each extra section
+# Parameters:   $NewLinkParams, $NewLinkTarget, $extranum
+# Input:        -
+# Output:       HTML
+# Return:       -
+#------------------------------------------------------------------------------
+sub HTMLMainExtra{
+       my $NewLinkParams = shift;
+       my $NewLinkTarget = shift;
+       my $extranum = shift;
+       
+       if ($Debug) { debug( "ExtraName$extranum", 2 ); }
+       print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
+       my $title = $ExtraName[$extranum];
+       &tab_head( "$title", 19, 0, "extra$extranum" );
+       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
+       print "<th>" . $ExtraFirstColumnTitle[$extranum];
+       print "&nbsp; - &nbsp; <a href=\""
+         . (
+               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
+               ? XMLEncode(
+                       "$AWScript?${NewLinkParams}output=allextra$extranum")
+               : "$StaticLinks.allextra$extranum.$StaticExt"
+         )
+         . "\"$NewLinkTarget>$Message[80]</a>";
+       print "</th>";
 
-#if ($Debug) { debug("  Analyze referer refererprot=$refererprot refererserver=$refererserver",5); }
+       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+               print
+                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
+       }
+       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+               print
+                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
+       }
+       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+               print
+                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+       }
+       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+               print "<th width=\"120\">$Message[9]</th>";
+       }
+       print "</tr>\n";
+       my $total_p = my $total_h = my $total_k = 0;
 
-                                               # Kind of origin
-                                               if ( !$TmpRefererServer{$refererserver} )
-                                               { # TmpRefererServer{$refererserver} is "=" if same site, "search egine key" if search engine, not defined otherwise
-                                                       if ( $refererserver =~ /$reglocal/o ) {
+        #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
+        #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
+       my $count = 0;
+       if ( $MaxNbOfExtra[$extranum] ) {
+               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                       &BuildKeyList(
+                               $MaxNbOfExtra[$extranum],
+                               $MinHitExtra[$extranum],
+                               \%{ '_section_' . $extranum . '_h' },
+                               \%{ '_section_' . $extranum . '_p' }
+                       );
+               }
+               else {
+                       &BuildKeyList(
+                               $MaxNbOfExtra[$extranum],
+                               $MinHitExtra[$extranum],
+                               \%{ '_section_' . $extranum . '_h' },
+                               \%{ '_section_' . $extranum . '_h' }
+                       );
+               }
+       }
+       else {
+               @keylist = ();
+       }
+       my %keysinkeylist = ();
+       foreach my $key (@keylist) {
+               $keysinkeylist{$key} = 1;
+               my $firstcol = CleanXSS( DecodeEncodedString($key) );
+               $total_p += ${ '_section_' . $extranum . '_p' }{$key};
+               $total_h += ${ '_section_' . $extranum . '_h' }{$key};
+               $total_k += ${ '_section_' . $extranum . '_k' }{$key};
+               print "<tr>";
+               printf(
+                       "<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
+                       $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
+               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                       print "<td>"
+                         . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                       print "<td>"
+                         . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                       print "<td>"
+                         . Format_Bytes(
+                               ${ '_section_' . $extranum . '_k' }{$key} )
+                         . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                       print "<td>"
+                         . (
+                               ${ '_section_' . $extranum . '_l' }{$key}
+                               ? Format_Date(
+                                       ${ '_section_' . $extranum . '_l' }{$key}, 1 )
+                               : '-'
+                         )
+                         . "</td>";
+               }
+               print "</tr>\n";
+               $count++;
+       }
 
-                                                 # Intern (This hit came from another page of the site)
-                                                               if ($Debug) {
-                                                                       debug(
-"  Server '$refererserver' is added to TmpRefererServer with value '='",
-                                                                               2
-                                                                       );
-                                                               }
-                                                               $TmpRefererServer{$refererserver} = '=';
-                                                               $found = 1;
-                                                       }
-                                                       else {
-                                                               foreach (@HostAliases) {
-                                                                       if ( $refererserver =~ /$_/ ) {
+       # If we ask average or sum, we loop on all other records
+       if ( $ExtraAddAverageRow[$extranum] || $ExtraAddSumRow[$extranum] )
+       {
+               foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
+                       if ( $keysinkeylist{$_} ) { next; }
+                       $total_p += ${ '_section_' . $extranum . '_p' }{$_};
+                       $total_h += ${ '_section_' . $extranum . '_h' }{$_};
+                       $total_k += ${ '_section_' . $extranum . '_k' }{$_};
+                       $count++;
+               }
+       }
 
-                                                 # Intern (This hit came from another page of the site)
-                                                                               if ($Debug) {
-                                                                                       debug(
-"  Server '$refererserver' is added to TmpRefererServer with value '='",
-                                                                                               2
-                                                                                       );
-                                                                               }
-                                                                               $TmpRefererServer{$refererserver} = '=';
-                                                                               $found = 1;
-                                                                               last;
-                                                                       }
-                                                               }
-                                                               if ( !$found ) {
+       # Add average row
+       if ( $ExtraAddAverageRow[$extranum] ) {
+               print "<tr>";
+               print "<td class=\"aws\"><b>$Message[96]</b></td>";
+               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                       print "<td>"
+                         . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                       print "<td>"
+                         . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" ) . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                       print "<td>"
+                         . (
+                               $count ? Format_Bytes( $total_k / $count ) : "&nbsp;" )
+                         . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                       print "<td>&nbsp;</td>";
+               }
+               print "</tr>\n";
+       }
 
-                                                        # Extern (This hit came from an external web site).
+       # Add sum row
+       if ( $ExtraAddSumRow[$extranum] ) {
+               print "<tr>";
+               print "<td class=\"aws\"><b>$Message[102]</b></td>";
+               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
+                       print "<td>" . Format_Number(($total_p)) . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
+                       print "<td>" . Format_Number(($total_h)) . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
+                       print "<td>" . Format_Bytes($total_k) . "</td>";
+               }
+               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
+                       print "<td>&nbsp;</td>";
+               }
+               print "</tr>\n";
+       }
+       &tab_end();
+}
 
-                                                                       if ($LevelForSearchEnginesDetection) {
+#------------------------------------------------------------------------------
+# MAIN
+#------------------------------------------------------------------------------
+( $DIR  = $0 ) =~ s/([^\/\\]+)$//;
+( $PROG = $1 ) =~ s/\.([^\.]*)$//;
+$Extension = $1;
+$DIR ||= '.';
+$DIR =~ s/([^\/\\])[\\\/]+$/$1/;
 
-                                                                               foreach (@SearchEnginesSearchIDOrder)
-                                                                               { # Search ID in order of SearchEnginesSearchIDOrder
-                                                                                       if ( $refererserver =~ /$_/ ) {
-                                                                                               my $key = &UnCompileRegex($_);
-                                                                                               if (
-                                                                                                       !$NotSearchEnginesKeys{$key}
-                                                                                                       || $refererserver !~
-/$NotSearchEnginesKeys{$key}/i
-                                                                                                 )
-                                                                                               {
+$starttime = time();
 
-                                                                        # This hit came from the search engine $key
-                                                                                                       if ($Debug) {
-                                                                                                               debug(
-"  Server '$refererserver' is added to TmpRefererServer with value '$key'",
-                                                                                                                       2
-                                                                                                               );
-                                                                                                       }
-                                                                                                       $TmpRefererServer{
-                                                                                                               $refererserver} =
-                                                                                                         $SearchEnginesHashID{ $key
-                                                                                                         };
-                                                                                                       $found = 1;
-                                                                                               }
-                                                                                               last;
-                                                                                       }
-                                                                               }
+# Get current time (time when AWStats was started)
+( $nowsec, $nowmin, $nowhour, $nowday, $nowmonth, $nowyear, $nowwday, $nowyday )
+  = localtime($starttime);
+$nowweekofmonth = int( $nowday / 7 );
+$nowweekofyear  =
+  int( ( $nowyday - 1 + 6 - ( $nowwday == 0 ? 6 : $nowwday - 1 ) ) / 7 ) + 1;
+if ( $nowweekofyear > 52 ) { $nowweekofyear = 1; }
+$nowdaymod = $nowday % 7;
+$nowwday++;
+$nowns = Time::Local::timegm( 0, 0, 0, $nowday, $nowmonth, $nowyear );
 
-                                                                       }
-                                                               }
-                                                       }
-                                               }
+if ( $nowdaymod <= $nowwday ) {
+       if ( ( $nowwday != 7 ) || ( $nowdaymod != 0 ) ) {
+               $nowweekofmonth = $nowweekofmonth + 1;
+       }
+}
+if ( $nowdaymod > $nowwday ) { $nowweekofmonth = $nowweekofmonth + 2; }
 
-                                               my $tmprefererserver =
-                                                 $TmpRefererServer{$refererserver};
-                                               if ($tmprefererserver) {
-                                                       if ( $tmprefererserver eq '=' ) {
-
-                                                 # Intern (This hit came from another page of the site)
-                                                               if ($PageBool) { $_from_p[4]++; }
-                                                               $_from_h[4]++;
-                                                               $found = 1;
-                                                       }
-                                                       else {
-
-                                                               # This hit came from a search engine
-                                                               if ($PageBool) {
-                                                                       $_from_p[2]++;
-                                                                       $_se_referrals_p{$tmprefererserver}++;
-                                                               }
-                                                               $_from_h[2]++;
-                                                               $_se_referrals_h{$tmprefererserver}++;
-                                                               $found = 1;
-                                                               if ( $PageBool && $LevelForKeywordsDetection ) {
-
-                                                                       # we will complete %_keyphrases hash array
-                                                                       my @refurl =
-                                                                         split( /\?/, $field[$pos_referer], 2 )
-                                                                         ; # TODO Use \? or [$URLQuerySeparators] ?
-                                                                       if ( $refurl[1] ) {
+# Change format of time variables
+$nowweekofmonth = "0$nowweekofmonth";
+if ( $nowweekofyear < 10 ) { $nowweekofyear = "0$nowweekofyear"; }
+if ( $nowyear < 100 ) { $nowyear += 2000; }
+else { $nowyear += 1900; }
+$nowsmallyear = $nowyear;
+$nowsmallyear =~ s/^..//;
+if ( ++$nowmonth < 10 ) { $nowmonth = "0$nowmonth"; }
+if ( $nowday < 10 )     { $nowday   = "0$nowday"; }
+if ( $nowhour < 10 )    { $nowhour  = "0$nowhour"; }
+if ( $nowmin < 10 )     { $nowmin   = "0$nowmin"; }
+if ( $nowsec < 10 )     { $nowsec   = "0$nowsec"; }
+$nowtime = int( $nowyear . $nowmonth . $nowday . $nowhour . $nowmin . $nowsec );
 
-# Extract params of referer query string (q=cache:mmm:www/zzz+aaa+bbb q=aaa+bbb/ccc key=ddd%20eee lang_en ie=UTF-8 ...)
-                                                                               if (
-                                                                                       $SearchEnginesKnownUrl{
-                                                                                               $tmprefererserver} )
-                                                                               {  # Search engine with known URL syntax
-                                                                                       foreach my $param (
-                                                                                               split(
-                                                                                                       /&/,
-                                                                                                       $KeyWordsNotSensitive
-                                                                                                       ? lc( $refurl[1] )
-                                                                                                       : $refurl[1]
-                                                                                               )
-                                                                                         )
-                                                                                       {
-                                                                                               if ( $param =~
-s/^$SearchEnginesKnownUrl{$tmprefererserver}//
-                                                                                                 )
-                                                                                               {
+# Get tomorrow time (will be used to discard some record with corrupted date (future date))
+my (
+       $tomorrowsec, $tomorrowmin,   $tomorrowhour,
+       $tomorrowday, $tomorrowmonth, $tomorrowyear
+  )
+  = localtime( $starttime + 86400 );
+if ( $tomorrowyear < 100 ) { $tomorrowyear += 2000; }
+else { $tomorrowyear += 1900; }
+if ( ++$tomorrowmonth < 10 ) { $tomorrowmonth = "0$tomorrowmonth"; }
+if ( $tomorrowday < 10 )     { $tomorrowday   = "0$tomorrowday"; }
+if ( $tomorrowhour < 10 )    { $tomorrowhour  = "0$tomorrowhour"; }
+if ( $tomorrowmin < 10 )     { $tomorrowmin   = "0$tomorrowmin"; }
+if ( $tomorrowsec < 10 )     { $tomorrowsec   = "0$tomorrowsec"; }
+$tomorrowtime =
+  int(  $tomorrowyear
+         . $tomorrowmonth
+         . $tomorrowday
+         . $tomorrowhour
+         . $tomorrowmin
+         . $tomorrowsec );
 
-        # We found good parameter
-        # Now param is keyphrase: "cache:mmm:www/zzz+aaa+bbb/ccc+ddd%20eee'fff,ggg"
-                                                                                                       $param =~
-s/^(cache|related):[^\+]+//
-                                                                                                         ; # Should be useless since this is for hit on 'not pages'
-                                                                                                       &ChangeWordSeparatorsIntoSpace
-                                                                                                         ($param)
-                                                                                                         ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg]
-                                                                                                       $param =~ s/^ +//;
-                                                                                                       $param =~ s/ +$//;    # Trim
-                                                                                                       $param =~ tr/ /\+/s;
-                                                                                                       if ( ( length $param ) > 0 )
-                                                                                                       {
-                                                                                                               $_keyphrases{$param}++;
-                                                                                                       }
-                                                                                                       last;
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                               elsif (
-                                                                                       $LevelForKeywordsDetection >= 2 )
-                                                                               { # Search engine with unknown URL syntax
-                                                                                       foreach my $param (
-                                                                                               split(
-                                                                                                       /&/,
-                                                                                                       $KeyWordsNotSensitive
-                                                                                                       ? lc( $refurl[1] )
-                                                                                                       : $refurl[1]
-                                                                                               )
-                                                                                         )
-                                                                                       {
-                                                                                               my $foundexcludeparam = 0;
-                                                                                               foreach my $paramtoexclude (
-                                                                                                       @WordsToCleanSearchUrl)
-                                                                                               {
-                                                                                                       if ( $param =~
-                                                                                                               /$paramtoexclude/i )
-                                                                                                       {
-                                                                                                               $foundexcludeparam = 1;
-                                                                                                               last;
-                                                                                                       } # Not the param with search criteria
-                                                                                               }
-                                                                                               if ($foundexcludeparam) {
-                                                                                                       next;
-                                                                                               }
+# Allowed option
+my @AllowedCLIArgs = (
+       'migrate',            'config',
+       'logfile',            'output',
+       'runascli',           'update',
+       'staticlinks',        'staticlinksext',
+       'noloadplugin',       'loadplugin',
+       'hostfilter',         'urlfilter',
+       'refererpagesfilter', 'lang',
+       'month',              'year',
+       'framename',          'debug',
+       'showsteps',          'showdropped',
+       'showcorrupted',      'showunknownorigin',
+       'showdirectorigin',   'limitflush',
+       'confdir',            'updatefor',
+       'hostfilter',         'hostfilterex',
+       'urlfilter',          'urlfilterex',
+       'refererpagesfilter', 'refererpagesfilterex',
+       'pluginmode',         'filterrawlog'
+);
 
-                                                                                               # We found good parameter
-                                                                                               $param =~ s/.*=//;
+# Parse input parameters and sanitize them for security reasons
+$QueryString = '';
 
-                                          # Now param is keyphrase: "aaa+bbb/ccc+ddd%20eee'fff,ggg"
-                                                                                               $param =~
-                                                                                                 s/^(cache|related):[^\+]+//
-                                                                                                 ; # Should be useless since this is for hit on 'not pages'
-                                                                                               &ChangeWordSeparatorsIntoSpace(
-                                                                                                       $param)
-                                                                                                 ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg ]
-                                                                                               $param =~ s/^ +//;
-                                                                                               $param =~ s/ +$//;     # Trim
-                                                                                               $param =~ tr/ /\+/s;
-                                                                                               if ( ( length $param ) > 2 ) {
-                                                                                                       $_keyphrases{$param}++;
-                                                                                                       last;
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       }    # End of elsif refurl[1]
-                                                                       elsif (
-                                                                               $SearchEnginesWithKeysNotInQuery{
-                                                                                       $tmprefererserver} )
-                                                                       {
+# AWStats use GATEWAY_INTERFACE to known if ran as CLI or CGI. AWSTATS_DEL_GATEWAY_INTERFACE can
+# be set to force AWStats to be ran as CLI even from a web page.
+if ( $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'} ) { $ENV{'GATEWAY_INTERFACE'} = ''; }
+if ( $ENV{'GATEWAY_INTERFACE'} ) {    # Run from a browser as CGI
+       $DebugMessages = 0;
 
-#                                                                              debug("xxx".$refurl[0]);
-# If search engine with key inside page url like a9 (www.a9.com/searchkey1%20searchkey2)
-                                                                               if ( $refurl[0] =~
-/$SearchEnginesKnownUrl{$tmprefererserver}(.*)$/
-                                                                                 )
-                                                                               {
-                                                                                       my $param = $1;
-                                                                                       &ChangeWordSeparatorsIntoSpace(
-                                                                                               $param);
-                                                                                       $param =~ tr/ /\+/s;
-                                                                                       if ( ( length $param ) > 0 ) {
-                                                                                               $_keyphrases{$param}++;
-                                                                                       }
-                                                                               }
-                                                                       }
+       # Prepare QueryString
+       if ( $ENV{'CONTENT_LENGTH'} ) {
+               binmode STDIN;
+               read( STDIN, $QueryString, $ENV{'CONTENT_LENGTH'} );
+       }
+       if ( $ENV{'QUERY_STRING'} ) {
+               $QueryString = $ENV{'QUERY_STRING'};
 
-                                                               }
-                                                       }
-                                               }    # End of if ($TmpRefererServer)
-                                               else {
+               # Set & and &amp; to &amp;
+               $QueryString =~ s/&amp;/&/g;
+               $QueryString =~ s/&/&amp;/g;
+       }
 
-                                                 # This hit came from a site other than a search engine
-                                                       if ($PageBool) { $_from_p[3]++; }
-                                                       $_from_h[3]++;
+       # Remove all XSS vulnerabilities coming from AWStats parameters
+       $QueryString = CleanXSS( &DecodeEncodedString($QueryString) );
 
-# http://www.mysite.com/ must be same referer than http://www.mysite.com but .../mypage/ differs of .../mypage
-#if ($refurl[0] =~ /^[^\/]+\/$/) { $field[$pos_referer] =~ s/\/$//; }  # Code moved in Save_History
-# TODO: lowercase the value for referer server to have refering server not case sensitive
-                                                       if ($URLReferrerWithQuery) {
-                                                               if ($PageBool) {
-                                                                       $_pagesrefs_p{ $field[$pos_referer] }++;
-                                                               }
-                                                               $_pagesrefs_h{ $field[$pos_referer] }++;
-                                                       }
-                                                       else {
+       # Security test
+       if ( $QueryString =~ /LogFile=([^&]+)/i ) {
+               error(
+"Logfile parameter can't be overwritten when AWStats is used from a CGI"
+               );
+       }
 
-                                                               # We discard query for referer
-                                                               if ( $field[$pos_referer] =~
-                                                                       /$regreferernoquery/o )
-                                                               {
-                                                                       if ($PageBool) { $_pagesrefs_p{"$1"}++; }
-                                                                       $_pagesrefs_h{"$1"}++;
-                                                               }
-                                                               else {
-                                                                       if ($PageBool) {
-                                                                               $_pagesrefs_p{ $field[$pos_referer] }++;
-                                                                       }
-                                                                       $_pagesrefs_h{ $field[$pos_referer] }++;
-                                                               }
-                                                       }
-                                                       $found = 1;
-                                               }
-                                       }
+       # No update but report by default when run from a browser
+       $UpdateStats = ( $QueryString =~ /update=1/i ? 1 : 0 );
 
-                                       # News Link ?
-                                       #if (! $found && $refererprot =~ /^news/i) {
-                                       #       $found=1;
-                                       #       if ($PageBool) { $_from_p[5]++; }
-                                       #       $_from_h[5]++;
-                                       #}
-                               }
-                       }
+       if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
+       if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
+       if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
+               $PluginMode = &Sanitize( "$1", 1 );
+       }
+       if ( $QueryString =~ /configdir=([^&]+)/i ) {
+               $DirConfig = &Sanitize("$1");
+       }
 
-                       # Origin not found
-                       if ( !$found ) {
-                               if ($ShowUnknownOrigin) {
-                                       print "Unknown origin: $field[$pos_referer]\n";
-                               }
-                               if ($PageBool) { $_from_p[1]++; }
-                               $_from_h[1]++;
-                       }
+       # All filters
+       if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       }    # Filter on host list can also be defined with hostfilter=filter
+       if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
+               $FilterEx{'host'} = "$1";
+       }    #
+       if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
+               $FilterIn{'url'} = "$1";
+       }    # Filter on URL list can also be defined with urlfilter=filter
+       if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
+       if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
+               $FilterIn{'refererpages'} = "$1";
+       } # Filter on referer list can also be defined with refererpagesfilter=filter
+       if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
+               $FilterEx{'refererpages'} = "$1";
+       }    #
+            # All output
+       if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
+               $FilterIn{'url'} = "$1";
+       } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
+               $FilterIn{'refererpages'} = "$1";
+       } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
 
-                       # Analyze: EMail
-                       #---------------
-                       if ( $pos_emails >= 0 && $field[$pos_emails] ) {
-                               if ( $field[$pos_emails] eq '<>' ) {
-                                       $field[$pos_emails] = 'Unknown';
-                               }
-                               elsif ( $field[$pos_emails] !~ /\@/ ) {
-                                       $field[$pos_emails] .= "\@$SiteDomain";
-                               }
-                               $_emails_h{ lc( $field[$pos_emails] ) }
-                                 ++;    #Count accesses for sender email (hit)
-                               $_emails_k{ lc( $field[$pos_emails] ) } +=
-                                 int( $field[$pos_size] )
-                                 ;      #Count accesses for sender email (kb)
-                               $_emails_l{ lc( $field[$pos_emails] ) } = $timerecord;
-                       }
-                       if ( $pos_emailr >= 0 && $field[$pos_emailr] ) {
-                               if ( $field[$pos_emailr] !~ /\@/ ) {
-                                       $field[$pos_emailr] .= "\@$SiteDomain";
-                               }
-                               $_emailr_h{ lc( $field[$pos_emailr] ) }
-                                 ++;    #Count accesses for receiver email (hit)
-                               $_emailr_k{ lc( $field[$pos_emailr] ) } +=
-                                 int( $field[$pos_size] )
-                                 ;      #Count accesses for receiver email (kb)
-                               $_emailr_l{ lc( $field[$pos_emailr] ) } = $timerecord;
-                       }
-               }
+       # If migrate
+       if ( $QueryString =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
+               $MigrateStats = &Sanitize("$2");
+               $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
+               $SiteConfig = $5 ? $5 : 'xxx';
+               $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
+       }
+}
+else {                             # Run from command line
+       $DebugMessages = 1;
 
-               # Check cluster
-               #--------------
-               if ( $pos_cluster >= 0 ) {
-                       if ($PageBool) {
-                               $_cluster_p{ $field[$pos_cluster] }++;
-                       }    #Count accesses for page (page)
-                       $_cluster_h{ $field[$pos_cluster] }
-                         ++;    #Count accesses for page (hit)
-                       $_cluster_k{ $field[$pos_cluster] } +=
-                         int( $field[$pos_size] );    #Count accesses for page (kb)
+       # Prepare QueryString
+       for ( 0 .. @ARGV - 1 ) {
+
+               # If migrate
+               if ( $ARGV[$_] =~ /(^|-|&|&amp;)migrate=([^&]+)/i ) {
+                       $MigrateStats = "$2";
+                       $MigrateStats =~ /^(.*)$PROG(\d{0,2})(\d\d)(\d\d\d\d)(.*)\.txt$/;
+                       $SiteConfig = $5 ? $5 : 'xxx';
+                       $SiteConfig =~ s/^\.//;    # SiteConfig is used to find config file
+                       next;
                }
 
-               # Analyze: Extra
-               #---------------
-               foreach my $extranum ( 1 .. @ExtraName - 1 ) {
-                       if ($Debug) { debug( "  Process extra analyze $extranum", 4 ); }
+               # TODO Check if ARGV is in @AllowedArg
+               if ($QueryString) { $QueryString .= '&amp;'; }
+               my $NewLinkParams = $ARGV[$_];
+               $NewLinkParams =~ s/^-+//;
+               $QueryString .= "$NewLinkParams";
+       }
 
-                       # Check code
-                       my $conditionok = 0;
-                       if ( $ExtraCodeFilter[$extranum] ) {
-                               foreach
-                                 my $condnum ( 0 .. @{ $ExtraCodeFilter[$extranum] } - 1 )
-                               {
-                                       if ($Debug) {
-                                               debug(
-"  Check code '$field[$pos_code]' must be '$ExtraCodeFilter[$extranum][$condnum]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[$pos_code] eq
-                                               "$ExtraCodeFilter[$extranum][$condnum]" )
-                                       {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               if ( !$conditionok && @{ $ExtraCodeFilter[$extranum] } ) {
-                                       next;
-                               }    # End for this section
-                               if ($Debug) {
-                                       debug(
-"  No check on code or code is OK. Now we check other conditions.",
-                                               5
-                                       );
-                               }
-                       }
+       # Remove all XSS vulnerabilities coming from AWStats parameters
+       $QueryString = CleanXSS($QueryString);
 
-                       # Check conditions
-                       $conditionok = 0;
-                       foreach my $condnum ( 0 .. @{ $ExtraConditionType[$extranum] } - 1 )
-                       {
-                               my $conditiontype    = $ExtraConditionType[$extranum][$condnum];
-                               my $conditiontypeval =
-                                 $ExtraConditionTypeVal[$extranum][$condnum];
-                               if ( $conditiontype eq 'URL' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $urlwithnoquery =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'QUERY_STRING' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$standalonequery'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $standalonequery =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'URLWITHQUERY' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery$tokenquery$standalonequery'",
-                                                       5
-                                               );
-                                       }
-                                       if ( "$urlwithnoquery$tokenquery$standalonequery" =~
-                                               /$conditiontypeval/ )
-                                       {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'REFERER' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_referer]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[$pos_referer] =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'UA' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_agent]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[$pos_agent] =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'HOSTINLOG' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_host]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[$pos_host] =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'HOST' ) {
-                                       my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$hosttouse'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $hosttouse =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype eq 'VHOST' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condision '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_vh]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[$pos_vh] =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $conditiontype =~ /extra(\d+)/i ) {
-                                       if ($Debug) {
-                                               debug(
-"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_extra[$1]]'",
-                                                       5
-                                               );
-                                       }
-                                       if ( $field[ $pos_extra[$1] ] =~ /$conditiontypeval/ ) {
-                                               $conditionok = 1;
-                                               last;
-                                       }
-                               }
-                               else {
-                                       error(
-"Wrong value of parameter ExtraSectionCondition$extranum"
-                                       );
-                               }
-                       }
-                       if ( !$conditionok && @{ $ExtraConditionType[$extranum] } ) {
-                               next;
-                       }    # End for this section
-                       if ($Debug) {
-                               debug(
-"  No condition or condition is OK. Now we extract value for first column of extra chart.",
-                                       5
-                               );
-                       }
+       # Security test
+       if (   $ENV{'AWSTATS_DEL_GATEWAY_INTERFACE'}
+               && $QueryString =~ /LogFile=([^&]+)/i )
+       {
+               error(
+"Logfile parameter can't be overwritten when AWStats is used from a CGI"
+               );
+       }
+
+       # Update with no report by default when run from command line
+       $UpdateStats = 1;
+
+       if ( $QueryString =~ /config=([^&]+)/i ) { $SiteConfig = &Sanitize("$1"); }
+       if ( $QueryString =~ /diricons=([^&]+)/i ) { $DirIcons = "$1"; }
+       if ( $QueryString =~ /pluginmode=([^&]+)/i ) {
+               $PluginMode = &Sanitize( "$1", 1 );
+       }
+       if ( $QueryString =~ /configdir=([^&]+)/i ) {
+               $DirConfig = &Sanitize("$1");
+       }
+
+       # All filters
+       if ( $QueryString =~ /hostfilter=([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       }    # Filter on host list can also be defined with hostfilter=filter
+       if ( $QueryString =~ /hostfilterex=([^&]+)/i ) {
+               $FilterEx{'host'} = "$1";
+       }    #
+       if ( $QueryString =~ /urlfilter=([^&]+)/i ) {
+               $FilterIn{'url'} = "$1";
+       }    # Filter on URL list can also be defined with urlfilter=filter
+       if ( $QueryString =~ /urlfilterex=([^&]+)/i ) { $FilterEx{'url'} = "$1"; } #
+       if ( $QueryString =~ /refererpagesfilter=([^&]+)/i ) {
+               $FilterIn{'refererpages'} = "$1";
+       } # Filter on referer list can also be defined with refererpagesfilter=filter
+       if ( $QueryString =~ /refererpagesfilterex=([^&]+)/i ) {
+               $FilterEx{'refererpages'} = "$1";
+       }    #
+            # All output
+       if ( $QueryString =~ /output=allhosts:([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       } # Filter on host list can be defined with output=allhosts:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=lasthosts:([^&]+)/i ) {
+               $FilterIn{'host'} = "$1";
+       } # Filter on host list can be defined with output=lasthosts:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=urldetail:([^&]+)/i ) {
+               $FilterIn{'url'} = "$1";
+       } # Filter on URL list can be defined with output=urldetail:filter to reduce number of lines read and showed
+       if ( $QueryString =~ /output=refererpages:([^&]+)/i ) {
+               $FilterIn{'refererpages'} = "$1";
+       } # Filter on referer list can be defined with output=refererpages:filter to reduce number of lines read and showed
+         # Config parameters
+       if ( $QueryString =~ /LogFile=([^&]+)/i ) { $LogFile = "$1"; }
+
+       # If show options
+       if ( $QueryString =~ /showsteps/i ) {
+               $ShowSteps = 1;
+               $QueryString =~ s/showsteps[^&]*//i;
+       }
+       if ( $QueryString =~ /showcorrupted/i ) {
+               $ShowCorrupted = 1;
+               $QueryString =~ s/showcorrupted[^&]*//i;
+       }
+       if ( $QueryString =~ /showdropped/i ) {
+               $ShowDropped = 1;
+               $QueryString =~ s/showdropped[^&]*//i;
+       }
+       if ( $QueryString =~ /showunknownorigin/i ) {
+               $ShowUnknownOrigin = 1;
+               $QueryString =~ s/showunknownorigin[^&]*//i;
+       }
+       if ( $QueryString =~ /showdirectorigin/i ) {
+               $ShowDirectOrigin = 1;
+               $QueryString =~ s/showdirectorigin[^&]*//i;
+       }
+}
+if ( $QueryString =~ /(^|&|&amp;)staticlinks/i ) {
+       $StaticLinks = "$PROG.$SiteConfig";
+}
+if ( $QueryString =~ /(^|&|&amp;)staticlinks=([^&]+)/i ) {
+       $StaticLinks = "$2";
+}    # When ran from awstatsbuildstaticpages.pl
+if ( $QueryString =~ /(^|&|&amp;)staticlinksext=([^&]+)/i ) {
+       $StaticExt = "$2";
+}
+if ( $QueryString =~ /(^|&|&amp;)framename=([^&]+)/i ) { $FrameName = "$2"; }
+if ( $QueryString =~ /(^|&|&amp;)debug=(\d+)/i )       { $Debug     = $2; }
+if ( $QueryString =~ /(^|&|&amp;)databasebreak=(\w+)/i ) {
+       $DatabaseBreak = $2;
+}
+if ( $QueryString =~ /(^|&|&amp;)updatefor=(\d+)/i ) { $UpdateFor = $2; }
+
+if ( $QueryString =~ /(^|&|&amp;)noloadplugin=([^&]+)/i ) {
+       foreach ( split( /,/, $2 ) ) { $NoLoadPlugin{ &Sanitize( "$_", 1 ) } = 1; }
+}
+if ( $QueryString =~ /(^|&|&amp;)limitflush=(\d+)/i ) { $LIMITFLUSH = $2; }
+
+# Get/Define output
+if ( $QueryString =~
+       /(^|&|&amp;)output(=[^&]*|)(.*)(&|&amp;)output(=[^&]*|)(&|$)/i )
+{
+       error( "Only 1 output option is allowed", "", "", 1 );
+}
+if ( $QueryString =~ /(^|&|&amp;)output(=[^&]*|)(&|$)/i ) {
+
+       # At least one output expected. We define %HTMLOutput
+       my $outputlist = "$2";
+       if ($outputlist) {
+               $outputlist =~ s/^=//;
+               foreach my $outputparam ( split( /,/, $outputlist ) ) {
+                       $outputparam =~ s/:(.*)$//;
+                       if ($outputparam) { $HTMLOutput{ lc($outputparam) } = "$1" || 1; }
+               }
+       }
+
+       # If on command line and no update
+       if ( !$ENV{'GATEWAY_INTERFACE'} && $QueryString !~ /update/i ) {
+               $UpdateStats = 0;
+       }
+
+       # If no output defined, used default value
+       if ( !scalar keys %HTMLOutput ) { $HTMLOutput{'main'} = 1; }
+}
+if ( $ENV{'GATEWAY_INTERFACE'} && !scalar keys %HTMLOutput ) {
+       $HTMLOutput{'main'} = 1;
+}
+
+# Remove -output option with no = from QueryString
+$QueryString =~ s/(^|&|&amp;)output(&|$)/$1$2/i;
+$QueryString =~ s/&+$//;
+
+# Check year, month, day, hour parameters
+if ( $QueryString =~ /(^|&|&amp;)month=(year)/i ) {
+       error("month=year is a deprecated option. Use month=all instead.");
+}
+if ( $QueryString =~ /(^|&|&amp;)year=(\d\d\d\d)/i ) {
+       $YearRequired = sprintf( "%04d", $2 );
+}
+else { $YearRequired = "$nowyear"; }
+if ( $QueryString =~ /(^|&|&amp;)month=(\d{1,2})/i ) {
+       $MonthRequired = sprintf( "%02d", $2 );
+}
+elsif ( $QueryString =~ /(^|&|&amp;)month=(all)/i ) { $MonthRequired = 'all'; }
+else { $MonthRequired = "$nowmonth"; }
+if ( $QueryString =~ /(^|&|&amp;)day=(\d{1,2})/i ) {
+       $DayRequired = sprintf( "%02d", $2 );
+} # day is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
+else { $DayRequired = ''; }
+if ( $QueryString =~ /(^|&|&amp;)hour=(\d{1,2})/i ) {
+       $HourRequired = sprintf( "%02d", $2 );
+} # hour is a hidden option. Must not be used (Make results not understandable). Available for users that rename history files with day.
+else { $HourRequired = ''; }
+
+# Check parameter validity
+# TODO
+
+# Print AWStats and Perl version
+if ($Debug) {
+       debug( ucfirst($PROG) . " - $VERSION - Perl $^X $]", 1 );
+       debug( "DIR=$DIR PROG=$PROG Extension=$Extension",   2 );
+       debug( "QUERY_STRING=$QueryString",                  2 );
+       debug( "HTMLOutput=" . join( ',', keys %HTMLOutput ), 1 );
+       debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
+       debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
+       debug( "UpdateFor=$UpdateFor",                                     2 );
+       debug( "PluginMode=$PluginMode",                                   2 );
+       debug( "DirConfig=$DirConfig",                                     2 );
+}
+
+# Force SiteConfig if AWSTATS_FORCE_CONFIG is defined
+if ( $ENV{'AWSTATS_CONFIG'} ) {
+       $ENV{'AWSTATS_FORCE_CONFIG'} = $ENV{'AWSTATS_CONFIG'};
+}    # For backward compatibility
+if ( $ENV{'AWSTATS_FORCE_CONFIG'} ) {
+       if ($Debug) {
+               debug(  "AWSTATS_FORCE_CONFIG parameter is defined to '"
+                         . $ENV{'AWSTATS_FORCE_CONFIG'}
+                         . "'. $PROG will use this as config value." );
+       }
+       $SiteConfig = &Sanitize( $ENV{'AWSTATS_FORCE_CONFIG'} );
+}
+
+# Display help information
+if ( ( !$ENV{'GATEWAY_INTERFACE'} ) && ( !$SiteConfig ) ) {
+       &PrintCLIHelp();
+       exit 2;
+}
+$SiteConfig ||= &Sanitize( $ENV{'SERVER_NAME'} );
+
+#$ENV{'SERVER_NAME'}||=$SiteConfig;    # For thoose who use __SERVER_NAME__ in conf file and use CLI.
+$ENV{'AWSTATS_CURRENT_CONFIG'} = $SiteConfig;
+
+# Read config file (SiteConfig must be defined)
+&Read_Config($DirConfig);
+
+# Check language
+if ( $QueryString =~ /(^|&|&amp;)lang=([^&]+)/i ) { $Lang = "$2"; }
+if ( !$Lang || $Lang eq 'auto' ) {    # If lang not defined or forced to auto
+       my $langlist = $ENV{'HTTP_ACCEPT_LANGUAGE'} || '';
+       $langlist =~ s/;[^,]*//g;
+       if ($Debug) {
+               debug(
+                       "Search an available language among HTTP_ACCEPT_LANGUAGE=$langlist",
+                       1
+               );
+       }
+       foreach my $code ( split( /,/, $langlist ) )
+       {                                 # Search for a valid lang in priority
+               if ( $LangBrowserToLangAwstats{$code} ) {
+                       $Lang = $LangBrowserToLangAwstats{$code};
+                       if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
+                       last;
+               }
+               $code =~ s/-.*$//;
+               if ( $LangBrowserToLangAwstats{$code} ) {
+                       $Lang = $LangBrowserToLangAwstats{$code};
+                       if ($Debug) { debug( " Will try to use Lang=$Lang", 1 ); }
+                       last;
+               }
+       }
+}
+if ( !$Lang || $Lang eq 'auto' ) {
+       if ($Debug) {
+               debug( " No language defined or available. Will use Lang=en", 1 );
+       }
+       $Lang = 'en';
+}
+
+# Check and correct bad parameters
+&Check_Config();
+
+# Now SiteDomain is defined
+
+if ( $Debug && !$DebugMessages ) {
+       error(
+"Debug has not been allowed. Change DebugMessages parameter in config file to allow debug."
+       );
+}
+
+# Define frame name and correct variable for frames
+if ( !$FrameName ) {
+       if (   $ENV{'GATEWAY_INTERFACE'}
+               && $UseFramesWhenCGI
+               && $HTMLOutput{'main'}
+               && !$PluginMode )
+       {
+               $FrameName = 'index';
+       }
+       else { $FrameName = 'main'; }
+}
+
+# Load Message files, Reference data files and Plugins
+if ($Debug) { debug( "FrameName=$FrameName", 1 ); }
+if ( $FrameName ne 'index' ) {
+       &Read_Language_Data($Lang);
+       if ( $FrameName ne 'mainleft' ) {
+               my %datatoload = ();
+               my (
+                       $filedomains, $filemime, $filerobots, $fileworms,
+                       $filebrowser, $fileos,   $filese
+                 )
+                 = (
+                       'domains',  'mime',
+                       'robots',   'worms',
+                       'browsers', 'operating_systems',
+                       'search_engines'
+                 );
+               my ( $filestatushttp, $filestatussmtp ) =
+                 ( 'status_http', 'status_smtp' );
+               if ( $LevelForBrowsersDetection eq 'allphones' ) {
+                       $filebrowser = 'browsers_phone';
+               }
+               if ($UpdateStats) {    # If update
+                       if ( $LevelForFileTypesDetection < 2 ) {
+                               $datatoload{$filemime} = 1;
+                       }                  # Only if need to filter on known extensions
+                       if ($LevelForRobotsDetection) {
+                               $datatoload{$filerobots} = 1;
+                       }                  # ua
+                       if ($LevelForWormsDetection) {
+                               $datatoload{$fileworms} = 1;
+                       }                  # url
+                       if ($LevelForBrowsersDetection) {
+                               $datatoload{$filebrowser} = 1;
+                       }                  # ua
+                       if ($LevelForOSDetection) {
+                               $datatoload{$fileos} = 1;
+                       }                  # ua
+                       if ($LevelForRefererAnalyze) {
+                               $datatoload{$filese} = 1;
+                       }                  # referer
+                                          # if (...) { $datatoload{'referer_spam'}=1; }
+               }
+               if ( scalar keys %HTMLOutput ) {    # If output
+                       if ( $ShowDomainsStats || $ShowHostsStats ) {
+                               $datatoload{$filedomains} = 1;
+                       } # TODO Replace by test if ($ShowDomainsStats) when plugins geoip can force load of domains datafile.
+                       if ($ShowFileTypesStats)  { $datatoload{$filemime}       = 1; }
+                       if ($ShowRobotsStats)     { $datatoload{$filerobots}     = 1; }
+                       if ($ShowWormsStats)      { $datatoload{$fileworms}      = 1; }
+                       if ($ShowBrowsersStats)   { $datatoload{$filebrowser}    = 1; }
+                       if ($ShowOSStats)         { $datatoload{$fileos}         = 1; }
+                       if ($ShowOriginStats)     { $datatoload{$filese}         = 1; }
+                       if ($ShowHTTPErrorsStats) { $datatoload{$filestatushttp} = 1; }
+                       if ($ShowSMTPErrorsStats) { $datatoload{$filestatussmtp} = 1; }
+               }
+               &Read_Ref_Data( keys %datatoload );
+       }
+       &Read_Plugins();
+}
+
+# Here charset is defined, so we can send the http header (Need BuildReportFormat,PageCode)
+if ( !$HeaderHTTPSent && $ENV{'GATEWAY_INTERFACE'} ) {
+       http_head();
+}    # Run from a browser as CGI
+
+# Init other parameters
+$NBOFLINESFORBENCHMARK--;
+if ( $ENV{'GATEWAY_INTERFACE'} ) { $DirCgi = ''; }
+if ( $DirCgi && !( $DirCgi =~ /\/$/ ) && !( $DirCgi =~ /\\$/ ) ) {
+       $DirCgi .= '/';
+}
+if ( !$DirData || $DirData =~ /^\./ ) {
+       if ( !$DirData || $DirData eq '.' ) {
+               $DirData = "$DIR";
+       }    # If not defined or chosen to '.' value then DirData is current dir
+       elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
+}
+$DirData ||= '.';    # If current dir not defined then we put it to '.'
+$DirData =~ s/[\\\/]+$//;
+
+if ( $FirstDayOfWeek == 1 ) { @DOWIndex = ( 1, 2, 3, 4, 5, 6, 0 ); }
+else { @DOWIndex = ( 0, 1, 2, 3, 4, 5, 6 ); }
+
+# Should we link to ourselves or to a wrapper script
+$AWScript = ( $WrapperScript ? "$WrapperScript" : "$DirCgi$PROG.$Extension" );
+
+# Print html header (Need HTMLOutput,Expires,Lang,StyleSheet,HTMLHeadSectionExpires defined by Read_Config, PageCode defined by Read_Language_Data)
+if ( !$HeaderHTMLSent ) { &html_head; }
+
+# AWStats output is replaced by a plugin output
+if ($PluginMode) {
+
+       #       my $function="BuildFullHTMLOutput_$PluginMode()";
+       #       eval("$function");
+       my $function = "BuildFullHTMLOutput_$PluginMode";
+       &$function();
+       if ( $? || $@ ) { error("$@"); }
+       &html_end(0);
+       exit 0;
+}
+
+# Security check
+if ( $AllowAccessFromWebToAuthenticatedUsersOnly && $ENV{'GATEWAY_INTERFACE'} )
+{
+       if ($Debug) { debug( "REMOTE_USER=" . $ENV{"REMOTE_USER"} ); }
+       if ( !$ENV{"REMOTE_USER"} ) {
+               error(
+"Access to statistics is only allowed from an authenticated session to authenticated users."
+               );
+       }
+       if (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
+               my $userisinlist = 0;
+               my $remoteuser   = quotemeta( $ENV{"REMOTE_USER"} );
+               $remoteuser =~ s/\s/%20/g
+                 ; # Allow authenticated user with space in name to be compared to allowed user list
+               my $currentuser = qr/^$remoteuser$/i;    # Set precompiled regex
+               foreach (@AllowAccessFromWebToFollowingAuthenticatedUsers) {
+                       if (/$currentuser/o) { $userisinlist = 1; last; }
+               }
+               if ( !$userisinlist ) {
+                       error(  "User '"
+                                 . $ENV{"REMOTE_USER"}
+                                 . "' is not allowed to access statistics of this domain/config."
+                       );
+               }
+       }
+}
+if ( $AllowAccessFromWebToFollowingIPAddresses && $ENV{'GATEWAY_INTERFACE'} ) {
+       my $IPAddress     = $ENV{"REMOTE_ADDR"};                  # IPv4 or IPv6
+       my $useripaddress = &Convert_IP_To_Decimal($IPAddress);
+       my @allowaccessfromipaddresses =
+         split( /[\s,]+/, $AllowAccessFromWebToFollowingIPAddresses );
+       my $allowaccess = 0;
+       foreach my $ipaddressrange (@allowaccessfromipaddresses) {
+               if ( $ipaddressrange !~
+                       /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/
+                       && $ipaddressrange !~
+                       /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
+               {
+                       error(
+"AllowAccessFromWebToFollowingIPAddresses is defined to '$AllowAccessFromWebToFollowingIPAddresses' but part of value does not match the correct syntax: IPv4AddressMin[-IPv4AddressMax] or IPv6Address[\/prefix] in \"$ipaddressrange\""
+                       );
+               }
 
-                       # Determine actual column value to use.
-                       my $rowkeyval;
-                       my $rowkeyok = 0;
-                       foreach my $rowkeynum (
-                               0 .. @{ $ExtraFirstColumnValuesType[$extranum] } - 1 )
+               # Test ip v4
+               if ( $ipaddressrange =~
+                       /^(\d+\.\d+\.\d+\.\d+)(?:-(\d+\.\d+\.\d+\.\d+))*$/ )
+               {
+                       my $ipmin = &Convert_IP_To_Decimal($1);
+                       my $ipmax = $2 ? &Convert_IP_To_Decimal($2) : $ipmin;
+
+                       # Is it an authorized ip ?
+                       if ( ( $useripaddress >= $ipmin ) && ( $useripaddress <= $ipmax ) )
                        {
-                               my $rowkeytype =
-                                 $ExtraFirstColumnValuesType[$extranum][$rowkeynum];
-                               my $rowkeytypeval =
-                                 $ExtraFirstColumnValuesTypeVal[$extranum][$rowkeynum];
-                               if ( $rowkeytype eq 'URL' ) {
-                                       if ( $urlwithnoquery =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'QUERY_STRING' ) {
-                                       if ($Debug) {
-                                               debug(
-"  Extract value from '$standalonequery' with regex '$rowkeytypeval'.",
-                                                       5
-                                               );
-                                       }
-                                       if ( $standalonequery =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'URLWITHQUERY' ) {
-                                       if ( "$urlwithnoquery$tokenquery$standalonequery" =~
-                                               /$rowkeytypeval/ )
-                                       {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'REFERER' ) {
-                                       if ( $field[$pos_referer] =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'UA' ) {
-                                       if ( $field[$pos_agent] =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'HOSTINLOG' ) {
-                                       if ( $field[$pos_host] =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'HOST' ) {
-                                       my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
-                                       if ( $hosttouse =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype eq 'VHOST' ) {
-                                       if ( $field[$pos_vh] =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               elsif ( $rowkeytype =~ /extra(\d+)/i ) {
-                                       if ( $field[ $pos_extra[$1] ] =~ /$rowkeytypeval/ ) {
-                                               $rowkeyval = "$1";
-                                               $rowkeyok  = 1;
-                                               last;
-                                       }
-                               }
-                               else {
-                                       error(
-"Wrong value of parameter ExtraSectionFirstColumnValues$extranum"
-                                       );
+                               $allowaccess = 1;
+                               last;
+                       }
+               }
+
+               # Test ip v6
+               if ( $ipaddressrange =~
+                       /^([0-9A-Fa-f]{1,4}:){1,7}(:|)([0-9A-Fa-f]{1,4}|\/\d)/ )
+               {
+                       if ( $ipaddressrange =~ /::\// ) {
+                               my @IPv6split = split( /::/, $ipaddressrange );
+                               if ( $IPAddress =~ /^$IPv6split[0]/ ) {
+                                       $allowaccess = 1;
+                                       last;
                                }
                        }
-                       if ( !$rowkeyok ) { next; }    # End for this section
-                       if ( !$rowkeyval ) { $rowkeyval = 'Failed to extract key'; }
-                       if ($Debug) { debug( "  Key val found: $rowkeyval", 5 ); }
+                       elsif ( $ipaddressrange == $IPAddress ) {
+                               $allowaccess = 1;
+                               last;
+                       }
+               }
+       }
+       if ( !$allowaccess ) {
+               error( "Access to statistics is not allowed from your IP Address "
+                         . $ENV{"REMOTE_ADDR"} );
+       }
+}
+if (   ( $UpdateStats || $MigrateStats )
+       && ( !$AllowToUpdateStatsFromBrowser )
+       && $ENV{'GATEWAY_INTERFACE'} )
+{
+       error(  ""
+                 . ( $UpdateStats ? "Update" : "Migrate" )
+                 . " of statistics has not been allowed from a browser (AllowToUpdateStatsFromBrowser should be set to 1)."
+       );
+}
+if ( scalar keys %HTMLOutput && $MonthRequired eq 'all' ) {
+       if ( !$AllowFullYearView ) {
+               error(
+"Full year view has not been allowed (AllowFullYearView is set to 0)."
+               );
+       }
+       if ( $AllowFullYearView < 3 && $ENV{'GATEWAY_INTERFACE'} ) {
+               error(
+"Full year view has not been allowed from a browser (AllowFullYearView should be set to 3)."
+               );
+       }
+}
+
+#------------------------------------------
+# MIGRATE PROCESS (Must be after reading config cause we need MaxNbOf... and Min...)
+#------------------------------------------
+if ($MigrateStats) {
+       if ($Debug) { debug( "MigrateStats is $MigrateStats", 2 ); }
+       if ( $MigrateStats !~
+               /^(.*)$PROG(\d\d)(\d\d\d\d)(\d{0,2})(\d{0,2})(.*)\.txt$/ )
+       {
+               error(
+"AWStats history file name must match following syntax: ${PROG}MMYYYY[.config].txt",
+                       "", "", 1
+               );
+       }
+       $DirData       = "$1";
+       $MonthRequired = "$2";
+       $YearRequired  = "$3";
+       $DayRequired   = "$4";
+       $HourRequired  = "$5";
+       $FileSuffix    = "$6";
+
+       # Correct DirData
+       if ( !$DirData || $DirData =~ /^\./ ) {
+               if ( !$DirData || $DirData eq '.' ) {
+                       $DirData = "$DIR";
+               }    # If not defined or chosen to '.' value then DirData is current dir
+               elsif ( $DIR && $DIR ne '.' ) { $DirData = "$DIR/$DirData"; }
+       }
+       $DirData ||= '.';    # If current dir not defined then we put it to '.'
+       $DirData =~ s/[\\\/]+$//;
+       print "Start migration for file '$MigrateStats'.";
+       print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
+       if ($EnableLockForUpdate) { &Lock_Update(1); }
+       my $newhistory =
+         &Read_History_With_TmpUpdate( $YearRequired, $MonthRequired, $DayRequired,
+               $HourRequired, 1, 0, 'all' );
+       if ( rename( "$newhistory", "$MigrateStats" ) == 0 ) {
+               unlink "$newhistory";
+               error(
+"Failed to rename \"$newhistory\" into \"$MigrateStats\".\nWrite permissions on \"$MigrateStats\" might be wrong"
+                         . (
+                               $ENV{'GATEWAY_INTERFACE'} ? " for a 'migration from web'" : ""
+                         )
+                         . " or file might be opened."
+               );
+       }
+       if ($EnableLockForUpdate) { &Lock_Update(0); }
+       print "Migration for file '$MigrateStats' successful.";
+       print $ENV{'GATEWAY_INTERFACE'} ? "<br />\n" : "\n";
+       &html_end(1);
+       exit 0;
+}
+
+# Output main frame page and exit. This must be after the security check.
+if ( $FrameName eq 'index' ) {
+
+       # Define the NewLinkParams for main chart
+       my $NewLinkParams = ${QueryString};
+       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+       $NewLinkParams =~ s/^&amp;//;
+       $NewLinkParams =~ s/&amp;$//;
+       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
+
+       # Exit if main frame
+       print "<frameset cols=\"$FRAMEWIDTH,*\">\n";
+       print "<frame name=\"mainleft\" src=\""
+         . XMLEncode("$AWScript?${NewLinkParams}framename=mainleft")
+         . "\" noresize=\"noresize\" frameborder=\"0\" />\n";
+       print "<frame name=\"mainright\" src=\""
+         . XMLEncode("$AWScript?${NewLinkParams}framename=mainright")
+         . "\" noresize=\"noresize\" scrolling=\"yes\" frameborder=\"0\" />\n";
+       print "<noframes><body>";
+       print "Your browser does not support frames.<br />\n";
+       print "You must set AWStats UseFramesWhenCGI parameter to 0\n";
+       print "to see your reports.<br />\n";
+       print "</body></noframes>\n";
+       print "</frameset>\n";
+       &html_end(0);
+       exit 0;
+}
+
+%MonthNumLib = (
+       "01", "$Message[60]", "02", "$Message[61]", "03", "$Message[62]",
+       "04", "$Message[63]", "05", "$Message[64]", "06", "$Message[65]",
+       "07", "$Message[66]", "08", "$Message[67]", "09", "$Message[68]",
+       "10", "$Message[69]", "11", "$Message[70]", "12", "$Message[71]"
+);
+
+# Build ListOfYears list with all existing years
+(
+       $lastyearbeforeupdate, $lastmonthbeforeupdate, $lastdaybeforeupdate,
+       $lasthourbeforeupdate, $lastdatebeforeupdate
+  )
+  = ( 0, 0, 0, 0, 0 );
+my $datemask = '';
+if    ( $DatabaseBreak eq 'month' ) { $datemask = '(\d\d)(\d\d\d\d)'; }
+elsif ( $DatabaseBreak eq 'year' )  { $datemask = '(\d\d\d\d)'; }
+elsif ( $DatabaseBreak eq 'day' )   { $datemask = '(\d\d)(\d\d\d\d)(\d\d)'; }
+elsif ( $DatabaseBreak eq 'hour' )  {
+       $datemask = '(\d\d)(\d\d\d\d)(\d\d)(\d\d)';
+}
 
-                       # Apply function on $rowkeyval
-                       if ( $ExtraFirstColumnFunction[$extranum] ) {
+if ($Debug) {
+       debug(
+"Scan for last history files into DirData='$DirData' with mask='$datemask'"
+       );
+}
+opendir( DIR, "$DirData" );
+my $regfilesuffix = quotemeta($FileSuffix);
+foreach ( grep /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i,
+       file_filt sort readdir DIR )
+{
+       /^$PROG$datemask$regfilesuffix\.txt(|\.gz)$/i;
+       if ( !$ListOfYears{"$2"} || "$1" gt $ListOfYears{"$2"} ) {
 
-                               # Todo call function on string $rowkeyval
-                       }
+               # ListOfYears contains max month found
+               $ListOfYears{"$2"} = "$1";
+       }
+       my $rangestring = ( $2 || "" ) . ( $1 || "" ) . ( $3 || "" ) . ( $4 || "" );
+       if ( $rangestring gt $lastdatebeforeupdate ) {
 
-                       # Here we got all values to increase counters
-                       if ( $PageBool && $ExtraStatTypes[$extranum] =~ /P/i ) {
-                               ${ '_section_' . $extranum . '_p' }{$rowkeyval}++;
-                       }
-                       ${ '_section_' . $extranum . '_h' }{$rowkeyval}++;    # Must be set
-                       if ( $ExtraStatTypes[$extranum] =~ /B/i ) {
-                               ${ '_section_' . $extranum . '_k' }{$rowkeyval} +=
-                                 int( $field[$pos_size] );
-                       }
-                       if ( $ExtraStatTypes[$extranum] =~ /L/i ) {
-                               if ( ${ '_section_' . $extranum . '_l' }{$rowkeyval}
-                                       || 0 < $timerecord )
-                               {
-                                       ${ '_section_' . $extranum . '_l' }{$rowkeyval} =
-                                         $timerecord;
-                               }
-                       }
+               # We are on a new max for mask
+               $lastyearbeforeupdate  = ( $2 || "" );
+               $lastmonthbeforeupdate = ( $1 || "" );
+               $lastdaybeforeupdate   = ( $3 || "" );
+               $lasthourbeforeupdate  = ( $4 || "" );
+               $lastdatebeforeupdate = $rangestring;
+       }
+}
+close DIR;
 
-                       # Check to avoid too large extra sections
-                       if (
-                               scalar keys %{ '_section_' . $extranum . '_h' } >
-                               $ExtraTrackedRowsLimit )
-                       {
-                               error(<<END_ERROR_TEXT);
-The number of values found for extra section $extranum has grown too large.
-In order to prevent awstats from using an excessive amount of memory, the number
-of values is currently limited to $ExtraTrackedRowsLimit. Perhaps you should consider
-revising extract parameters for extra section $extranum. If you are certain you
-want to track such a large data set, you can increase the limit by setting
-ExtraTrackedRowsLimit in your awstats configuration file.
-END_ERROR_TEXT
-                       }
-               }
+# If at least one file found, get value for LastLine
+if ($lastyearbeforeupdate) {
 
-# Every 20,000 approved lines after a flush, we test to clean too large hash arrays to flush data in tmp file
-               if ( ++$counterforflushtest >= 20000 ) {
+       # Read 'general' section of last history file for LastLine
+       &Read_History_With_TmpUpdate( $lastyearbeforeupdate, $lastmonthbeforeupdate,
+               $lastdaybeforeupdate, $lasthourbeforeupdate, 0, 0, "general" );
+}
 
-                       #if (++$counterforflushtest >= 1) {
-                       if (   ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 )
-                               || ( scalar keys %_url_p ) > $LIMITFLUSH )
-                       {
+# Warning if lastline in future
+if ( $LastLine > ( $nowtime + 20000 ) ) {
+       warning(
+"WARNING: LastLine parameter in history file is '$LastLine' so in future. May be you need to correct manually the line LastLine in some awstats*.$SiteConfig.conf files."
+       );
+}
 
-# warning("Warning: Try to run AWStats update process more frequently to analyze smaler log files.");
-                               if ( $^X =~ /activestate/i || $^X =~ /activeperl/i ) {
+# Force LastLine
+if ( $QueryString =~ /lastline=(\d{14})/i ) {
+       $LastLine = $1;
+}
+if ($Debug) {
+       debug(
+               "Last year=$lastyearbeforeupdate - Last month=$lastmonthbeforeupdate");
+       debug("Last day=$lastdaybeforeupdate - Last hour=$lasthourbeforeupdate");
+       debug("LastLine=$LastLine");
+       debug("LastLineNumber=$LastLineNumber");
+       debug("LastLineOffset=$LastLineOffset");
+       debug("LastLineChecksum=$LastLineChecksum");
+}
 
-# We don't flush if perl is activestate to avoid slowing process because of memory hole
-                               }
-                               else {
+# Init vars
+&Init_HashArray();
 
-                                       # Clean tmp hash arrays
-                                       #%TmpDNSLookup = ();
-                                       %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
+#------------------------------------------
+# UPDATE PROCESS
+#------------------------------------------
+my $lastlinenb         = 0;
+my $lastlineoffset     = 0;
+my $lastlineoffsetnext = 0;
 
-                                       # We flush if perl is not activestate
-                                       print "Flush history file on disk";
-                                       if ( ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 ) ) {
-                                               print " (unique hosts reach flush limit of "
-                                                 . ( $LIMITFLUSH << 2 ) . ")";
-                                       }
-                                       if ( ( scalar keys %_url_p ) > $LIMITFLUSH ) {
-                                               print " (unique url reach flush limit of "
-                                                 . ($LIMITFLUSH) . ")";
-                                       }
-                                       print "\n";
-                                       if ($Debug) {
-                                               debug(
-"End of set of $counterforflushtest records: Some hash arrays are too large. We flush and clean some.",
-                                                       2
-                                               );
-                                               print " _host_p:"
-                                                 . ( scalar keys %_host_p )
-                                                 . " _host_h:"
-                                                 . ( scalar keys %_host_h )
-                                                 . " _host_k:"
-                                                 . ( scalar keys %_host_k )
-                                                 . " _host_l:"
-                                                 . ( scalar keys %_host_l )
-                                                 . " _host_s:"
-                                                 . ( scalar keys %_host_s )
-                                                 . " _host_u:"
-                                                 . ( scalar keys %_host_u ) . "\n";
-                                               print " _url_p:"
-                                                 . ( scalar keys %_url_p )
-                                                 . " _url_k:"
-                                                 . ( scalar keys %_url_k )
-                                                 . " _url_e:"
-                                                 . ( scalar keys %_url_e )
-                                                 . " _url_x:"
-                                                 . ( scalar keys %_url_x ) . "\n";
-                                               print " _waithost_e:"
-                                                 . ( scalar keys %_waithost_e )
-                                                 . " _waithost_l:"
-                                                 . ( scalar keys %_waithost_l )
-                                                 . " _waithost_s:"
-                                                 . ( scalar keys %_waithost_s )
-                                                 . " _waithost_u:"
-                                                 . ( scalar keys %_waithost_u ) . "\n";
-                                       }
-                                       &Read_History_With_TmpUpdate(
-                                               $lastprocessedyear,
-                                               $lastprocessedmonth,
-                                               $lastprocessedday,
-                                               $lastprocessedhour,
-                                               1,
-                                               1,
-                                               "all",
-                                               ( $lastlinenb + $NbOfLinesParsed ),
-                                               $lastlineoffset,
-                                               &CheckSum($_)
-                                       );
-                                       &GetDelaySinceStart(1);
-                                       $NbOfLinesShowsteps = 1;
-                               }
-                       }
-                       $counterforflushtest = 0;
-               }
+if ($Debug) { debug( "UpdateStats is $UpdateStats", 2 ); }
+if ( $UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft' )
+{    # Update only on index page or when not framed to avoid update twice
 
-       }    # End of loop for processing new record.
+       my %MonthNum = (
+               "Jan", "01", "jan", "01", "Feb", "02", "feb", "02", "Mar", "03",
+               "mar", "03", "Apr", "04", "apr", "04", "May", "05", "may", "05",
+               "Jun", "06", "jun", "06", "Jul", "07", "jul", "07", "Aug", "08",
+               "aug", "08", "Sep", "09", "sep", "09", "Oct", "10", "oct", "10",
+               "Nov", "11", "nov", "11", "Dec", "12", "dec", "12"
+         )
+         ; # MonthNum must be in english because used to translate log date in apache log files
 
-       if ($Debug) {
-               debug(
-                       " _host_p:"
-                         . ( scalar keys %_host_p )
-                         . " _host_h:"
-                         . ( scalar keys %_host_h )
-                         . " _host_k:"
-                         . ( scalar keys %_host_k )
-                         . " _host_l:"
-                         . ( scalar keys %_host_l )
-                         . " _host_s:"
-                         . ( scalar keys %_host_s )
-                         . " _host_u:"
-                         . ( scalar keys %_host_u ) . "\n",
-                       1
-               );
-               debug(
-                       " _url_p:"
-                         . ( scalar keys %_url_p )
-                         . " _url_k:"
-                         . ( scalar keys %_url_k )
-                         . " _url_e:"
-                         . ( scalar keys %_url_e )
-                         . " _url_x:"
-                         . ( scalar keys %_url_x ) . "\n",
-                       1
-               );
-               debug(
-                       " _waithost_e:"
-                         . ( scalar keys %_waithost_e )
-                         . " _waithost_l:"
-                         . ( scalar keys %_waithost_l )
-                         . " _waithost_s:"
-                         . ( scalar keys %_waithost_s )
-                         . " _waithost_u:"
-                         . ( scalar keys %_waithost_u ) . "\n",
-                       1
-               );
-               debug(
-                       "End of processing log file (AWStats memory cache is TmpDNSLookup="
-                         . ( scalar keys %TmpDNSLookup )
-                         . " TmpBrowser="
-                         . ( scalar keys %TmpBrowser )
-                         . " TmpOS="
-                         . ( scalar keys %TmpOS )
-                         . " TmpRefererServer="
-                         . ( scalar keys %TmpRefererServer )
-                         . " TmpRobot="
-                         . ( scalar keys %TmpRobot ) . ")",
-                       1
+       if ( !scalar keys %HTMLOutput ) {
+               print
+"Create/Update database for config \"$FileConfig\" by AWStats version $VERSION\n";
+               print "From data in log file \"$LogFile\"...\n";
+       }
+
+       my $lastprocessedyear  = $lastyearbeforeupdate  || 0;
+       my $lastprocessedmonth = $lastmonthbeforeupdate || 0;
+       my $lastprocessedday   = $lastdaybeforeupdate   || 0;
+       my $lastprocessedhour  = $lasthourbeforeupdate  || 0;
+       my $lastprocesseddate  = '';
+       if ( $DatabaseBreak eq 'month' ) {
+               $lastprocesseddate =
+                 sprintf( "%04i%02i", $lastprocessedyear, $lastprocessedmonth );
+       }
+       elsif ( $DatabaseBreak eq 'year' ) {
+               $lastprocesseddate = sprintf( "%04i%", $lastprocessedyear );
+       }
+       elsif ( $DatabaseBreak eq 'day' ) {
+               $lastprocesseddate = sprintf( "%04i%02i%02i",
+                       $lastprocessedyear, $lastprocessedmonth, $lastprocessedday );
+       }
+       elsif ( $DatabaseBreak eq 'hour' ) {
+               $lastprocesseddate = sprintf(
+                       "%04i%02i%02i%02i",
+                       $lastprocessedyear, $lastprocessedmonth,
+                       $lastprocessedday,  $lastprocessedhour
                );
        }
 
-# Save current processed break section
-# If lastprocesseddate > 0 means there is at least one approved new record in log or at least one existing history file
-       if ( $lastprocesseddate > 0 )
-       {    # TODO: Do not save if we are sure a flush was just already done
-                   # Get last line
-               seek( LOG, $lastlineoffset, 0 );
-               my $line = <LOG>;
-               chomp $line;
-               $line =~ s/\r$//;
-               if ( !$NbOfLinesParsed ) {
+       my @list;
 
-# TODO If there was no lines parsed (log was empty), we only update LastUpdate line with YYYYMMDDHHMMSS 0 0 0 0 0
-                       &Read_History_With_TmpUpdate(
-                               $lastprocessedyear, $lastprocessedmonth,
-                               $lastprocessedday,  $lastprocessedhour,
-                               1,                  1,
-                               "all", ( $lastlinenb + $NbOfLinesParsed ),
-                               $lastlineoffset, &CheckSum($line)
-                       );
-               }
-               else {
-                       &Read_History_With_TmpUpdate(
-                               $lastprocessedyear, $lastprocessedmonth,
-                               $lastprocessedday,  $lastprocessedhour,
-                               1,                  1,
-                               "all", ( $lastlinenb + $NbOfLinesParsed ),
-                               $lastlineoffset, &CheckSum($line)
+       # Init RobotsSearchIDOrder required for update process
+       @list = ();
+       if ( $LevelForRobotsDetection >= 1 ) {
+               foreach ( 1 .. $LevelForRobotsDetection ) { push @list, "list$_"; }
+               push @list, "listgen";    # Always added
+       }
+       foreach my $key (@list) {
+               push @RobotsSearchIDOrder, @{"RobotsSearchIDOrder_$key"};
+               if ($Debug) {
+                       debug(
+                               "Add "
+                                 . @{"RobotsSearchIDOrder_$key"}
+                                 . " elements from RobotsSearchIDOrder_$key into RobotsSearchIDOrder",
+                               2
                        );
                }
        }
-
-       if ($Debug) { debug("Close log file \"$LogFile\""); }
-       close LOG || error("Command for pipe '$LogFile' failed");
-
-       # Process the Rename - Archive - Purge phase
-       my $renameok  = 1;
-       my $archiveok = 1;
-
-       # Open Log file for writing if PurgeLogFile is on
-       if ($PurgeLogFile) {
-               if ($ArchiveLogRecords) {
-                       if ( $ArchiveLogRecords == 1 ) {    # For backward compatibility
-                               $ArchiveFileName = "$DirData/${PROG}_archive$FileSuffix.log";
-                       }
-                       else {
-                               $ArchiveFileName =
-                                 "$DirData/${PROG}_archive$FileSuffix."
-                                 . &Substitute_Tags($ArchiveLogRecords) . ".log";
-                       }
-                       open( LOG, "+<$LogFile" )
-                         || error(
-"Enable to archive log records of \"$LogFile\" into \"$ArchiveFileName\" because source can't be opened for read and write: $!<br />\n"
-                         );
-               }
-               else {
-                       open( LOG, "+<$LogFile" );
-               }
-               binmode LOG;
+       if ($Debug) {
+               debug(
+                       "RobotsSearchIDOrder has now " . @RobotsSearchIDOrder . " elements",
+                       1
+               );
        }
 
-       # Rename all HISTORYTMP files into HISTORYTXT
-       &Rename_All_Tmp_History();
-
-       # Purge Log file if option is on and all renaming are ok
-       if ($PurgeLogFile) {
-
-               # Archive LOG file into ARCHIVELOG
-               if ($ArchiveLogRecords) {
-                       if ($Debug) { debug("Start of archiving log file"); }
-                       open( ARCHIVELOG, ">>$ArchiveFileName" )
-                         || error(
-                               "Couldn't open file \"$ArchiveFileName\" to archive log: $!");
-                       binmode ARCHIVELOG;
-                       while (<LOG>) {
-                               if ( !print ARCHIVELOG $_ ) { $archiveok = 0; last; }
-                       }
-                       close(ARCHIVELOG)
-                         || error("Archiving failed during closing archive: $!");
-                       if ($SaveDatabaseFilesWithPermissionsForEveryone) {
-                               chmod 0666, "$ArchiveFileName";
-                       }
-                       if ($Debug) { debug("End of archiving log file"); }
+       # Init SearchEnginesIDOrder required for update process
+       @list = ();
+       if ( $LevelForSearchEnginesDetection >= 1 ) {
+               foreach ( 1 .. $LevelForSearchEnginesDetection ) {
+                       push @list, "list$_";
                }
-
-               # If rename and archive ok
-               if ( $renameok && $archiveok ) {
-                       if ($Debug) { debug("Purge log file"); }
-                       my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
-                       my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
-                       my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
-                       truncate( LOG, 0 )
-                         || warning(
-"Warning: $bold$PROG$unbold couldn't purge logfile \"$bold$LogFile$unbold\".$br\nChange your logfile permissions to allow write for your web server CGI process or change PurgeLogFile=1 into PurgeLogFile=0 in configure file and think to purge sometimes manually your logfile (just after running an update process to not loose any not already processed records your log file contains)."
-                         );
+               push @list, "listgen";    # Always added
+       }
+       foreach my $key (@list) {
+               push @SearchEnginesSearchIDOrder, @{"SearchEnginesSearchIDOrder_$key"};
+               if ($Debug) {
+                       debug(
+                               "Add "
+                                 . @{"SearchEnginesSearchIDOrder_$key"}
+                                 . " elements from SearchEnginesSearchIDOrder_$key into SearchEnginesSearchIDOrder",
+                               2
+                       );
                }
-               close(LOG);
+       }
+       if ($Debug) {
+               debug(
+                       "SearchEnginesSearchIDOrder has now "
+                         . @SearchEnginesSearchIDOrder
+                         . " elements",
+                       1
+               );
        }
 
-       if ( $DNSLookup == 1 && $DNSLookupAlreadyDone ) {
-
-               # DNSLookup warning
-               my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
-               my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
-               my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
+       # Complete HostAliases array
+       my $sitetoanalyze = quotemeta( lc($SiteDomain) );
+       if ( !@HostAliases ) {
                warning(
-"Warning: $bold$PROG$unbold has detected that some hosts names were already resolved in your logfile $bold$DNSLookupAlreadyDone$unbold.$br\nIf DNS lookup was already made by the logger (web server), you should change your setup DNSLookup=$DNSLookup into DNSLookup=0 to increase $PROG speed."
+"Warning: HostAliases parameter is not defined, $PROG choose \"$SiteDomain localhost 127.0.0.1\"."
                );
+               push @HostAliases, qr/^$sitetoanalyze$/i;
+               push @HostAliases, qr/^localhost$/i;
+               push @HostAliases, qr/^127\.0\.0\.1$/i;
        }
-       if ( $DNSLookup == 1 && $NbOfNewLines ) {
+       else {
+               unshift @HostAliases, qr/^$sitetoanalyze$/i;
+       }    # Add SiteDomain as first value
 
-               # Save new DNS last update cache file
-               Save_DNS_Cache_File( \%TmpDNSLookup, "$DirData/$DNSLastUpdateCacheFile",
-                       "$FileSuffix" );    # Save into file using FileSuffix
+       # Optimize arrays
+       @HostAliases = &OptimizeArray( \@HostAliases, 1 );
+       if ($Debug) {
+               debug( "HostAliases precompiled regex list is now @HostAliases", 1 );
        }
-
-       if ($EnableLockForUpdate) {
-
-               # Remove lock
-               &Lock_Update(0);
-
-               # Restore signals handler
-               $SIG{INT} = 'DEFAULT';    # 2
-                                         #$SIG{KILL} = 'DEFAULT';      # 9
-                                         #$SIG{TERM} = 'DEFAULT';      # 15
+       @SkipDNSLookupFor = &OptimizeArray( \@SkipDNSLookupFor, 1 );
+       if ($Debug) {
+               debug(
+                       "SkipDNSLookupFor precompiled regex list is now @SkipDNSLookupFor",
+                       1
+               );
        }
-
-}
-
-# End of log processing if ($UPdateStats)
-
-#---------------------------------------------------------------------
-# SHOW REPORT
-#---------------------------------------------------------------------
-
-if ( scalar keys %HTMLOutput ) {
-
-       debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
-       debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
-
-       my $max_p;
-       my $max_h;
-       my $max_k;
-       my $max_v;
-       my $total_u;
-       my $total_v;
-       my $total_p;
-       my $total_h;
-       my $total_k;
-       my $total_e;
-       my $total_x;
-       my $total_s;
-       my $total_l;
-       my $total_r;
-       my $average_u;
-       my $average_v;
-       my $average_p;
-       my $average_h;
-       my $average_k;
-       my $average_s;
-       my $rest_p;
-       my $rest_h;
-       my $rest_k;
-       my $rest_e;
-       my $rest_x;
-       my $rest_s;
-       my $rest_l;
-       my $rest_r;
-       my $average_nb;
-
-       # Define the NewLinkParams for main chart
-       my $NewLinkParams = ${QueryString};
-       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
-       $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
-       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
-       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-       my $NewLinkTarget = '';
-       if ($DetailedReportsOnNewWindows) {
-               $NewLinkTarget = " target=\"awstatsbis\"";
+       @SkipHosts = &OptimizeArray( \@SkipHosts, 1 );
+       if ($Debug) {
+               debug( "SkipHosts precompiled regex list is now @SkipHosts", 1 );
        }
-       if ( ( $FrameName eq 'mainleft' || $FrameName eq 'mainright' )
-               && $DetailedReportsOnNewWindows < 2 )
-       {
-               $NewLinkParams .= "&amp;framename=mainright";
-               $NewLinkTarget = " target=\"mainright\"";
+       @SkipReferrers = &OptimizeArray( \@SkipReferrers, 1 );
+       if ($Debug) {
+               debug( "SkipReferrers precompiled regex list is now @SkipReferrers",
+                       1 );
+       }
+       @SkipUserAgents = &OptimizeArray( \@SkipUserAgents, 1 );
+       if ($Debug) {
+               debug( "SkipUserAgents precompiled regex list is now @SkipUserAgents",
+                       1 );
+       }
+       @SkipFiles = &OptimizeArray( \@SkipFiles, $URLNotCaseSensitive );
+       if ($Debug) {
+               debug( "SkipFiles precompiled regex list is now @SkipFiles", 1 );
+       }
+       @OnlyHosts = &OptimizeArray( \@OnlyHosts, 1 );
+       if ($Debug) {
+               debug( "OnlyHosts precompiled regex list is now @OnlyHosts", 1 );
+       }
+       @OnlyUsers = &OptimizeArray( \@OnlyUsers, 1 );
+       if ($Debug) {
+               debug( "OnlyUsers precompiled regex list is now @OnlyUsers", 1 );
+       }
+       @OnlyUserAgents = &OptimizeArray( \@OnlyUserAgents, 1 );
+       if ($Debug) {
+               debug( "OnlyUserAgents precompiled regex list is now @OnlyUserAgents",
+                       1 );
+       }
+       @OnlyFiles = &OptimizeArray( \@OnlyFiles, $URLNotCaseSensitive );
+       if ($Debug) {
+               debug( "OnlyFiles precompiled regex list is now @OnlyFiles", 1 );
+       }
+       @NotPageFiles = &OptimizeArray( \@NotPageFiles, $URLNotCaseSensitive );
+       if ($Debug) {
+               debug( "NotPageFiles precompiled regex list is now @NotPageFiles", 1 );
        }
-       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-       $NewLinkParams =~ s/^&amp;//;
-       $NewLinkParams =~ s/&amp;$//;
-       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
-       if ( $FrameName ne 'mainleft' ) {
+       # Precompile the regex search strings with qr
+       @RobotsSearchIDOrder        = map { qr/$_/i } @RobotsSearchIDOrder;
+       @WormsSearchIDOrder         = map { qr/$_/i } @WormsSearchIDOrder;
+       @BrowsersSearchIDOrder      = map { qr/$_/i } @BrowsersSearchIDOrder;
+       @OSSearchIDOrder            = map { qr/$_/i } @OSSearchIDOrder;
+       @SearchEnginesSearchIDOrder = map { qr/$_/i } @SearchEnginesSearchIDOrder;
+       my $miscquoted     = quotemeta("$MiscTrackerUrl");
+       my $defquoted      = quotemeta("/$DefaultFile[0]");
+       my $sitewithoutwww = lc($SiteDomain);
+       $sitewithoutwww =~ s/www\.//;
+       $sitewithoutwww = quotemeta($sitewithoutwww);
 
-               # READING DATA
-               #-------------
-               &Init_HashArray();
+       # Define precompiled regex
+       my $regmisc        = qr/^$miscquoted/;
+       my $regfavico      = qr/\/favicon\.ico$/i;
+       my $regrobot       = qr/\/robots\.txt$/i;
+       my $regtruncanchor = qr/#(\w*)$/;
+       my $regtruncurl    = qr/([$URLQuerySeparators])(.*)$/;
+       my $regext         = qr/\.(\w{1,6})$/;
+       my $regdefault;
+       if ($URLNotCaseSensitive) { $regdefault = qr/$defquoted$/i; }
+       else { $regdefault = qr/$defquoted$/; }
+       my $regipv4           = qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
+       my $regipv4l          = qr/^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
+       my $regipv6           = qr/^[0-9A-F]*:/i;
+       my $regvermsie        = qr/msie([+_ ]|)([\d\.]*)/i;
+       my $regvernetscape    = qr/netscape.?\/([\d\.]*)/i;
+       my $regverfirefox     = qr/firefox\/([\d\.]*)/i;
+       my $regveropera       = qr/opera\/([\d\.]*)/i;
+       my $regversafari      = qr/safari\/([\d\.]*)/i;
+       my $regversafariver   = qr/version\/([\d\.]*)/i;
+       my $regverchrome      = qr/chrome\/([\d\.]*)/i;
+       my $regverkonqueror   = qr/konqueror\/([\d\.]*)/i;
+       my $regversvn         = qr/svn\/([\d\.]*)/i;
+       my $regvermozilla     = qr/mozilla(\/|)([\d\.]*)/i;
+       my $regnotie          = qr/webtv|omniweb|opera/i;
+       my $regnotnetscape    = qr/gecko|compatible|opera|galeon|safari|charon/i;
+       my $regnotfirefox     = qr/flock/i;
+       my $regnotsafari      = qr/android|arora|chrome|shiira/i;
+       my $regreferer        = qr/^(\w+):\/\/([^\/:]+)(:\d+|)/;
+       my $regreferernoquery = qr/^([^$URLQuerySeparators]+)/;
+       my $reglocal          = qr/^(www\.|)$sitewithoutwww/i;
+       my $regget            = qr/get|out/i;
+       my $regsent           = qr/sent|put|in/i;
 
-               # Lecture des fichiers history
-               if ( $DatabaseBreak eq 'month' ) {
-                       for ( my $ix = 12 ; $ix >= 1 ; $ix-- ) {
-                               my $stringforload = '';
-                               my $monthix = sprintf( "%02s", $ix );
-                               if ( $MonthRequired eq 'all' || $monthix eq $MonthRequired ) {
-                                       $stringforload = 'all';    # Read full history file
-                               }
-                               elsif ( ( $HTMLOutput{'main'} && $ShowMonthStats )
-                                       || $HTMLOutput{'alldays'} )
-                               {
-                                       $stringforload =
-                                         'general time';          # Read general and time sections.
-                               }
-                               if ($stringforload) {
+       # Define value of $pos_xxx, @fieldlib, $PerlParsingFormat
+       &DefinePerlParsingFormat($LogFormat);
 
-                                       # On charge fichier
-                                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, '',
-                                               '', 0, 0, $stringforload );
-                               }
-                       }
-               }
-               if ( $DatabaseBreak eq 'day' ) {
-                       my $stringforload = 'all';
-                       my $monthix       = sprintf( "%02s", $MonthRequired );
-                       my $dayix         = sprintf( "%02s", $DayRequired );
-                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix, '',
-                               0, 0, $stringforload );
-               }
-               if ( $DatabaseBreak eq 'hour' ) {
-                       my $stringforload = 'all';
-                       my $monthix       = sprintf( "%02s", $MonthRequired );
-                       my $dayix         = sprintf( "%02s", $DayRequired );
-                       my $hourix        = sprintf( "%02s", $HourRequired );
-                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix,
-                               $hourix, 0, 0, $stringforload );
+       # Load DNS Cache Files
+       #------------------------------------------
+       if ($DNSLookup) {
+               &Read_DNS_Cache( \%MyDNSTable, "$DNSStaticCacheFile", "", 1 )
+                 ; # Load with save into a second plugin file if plugin enabled and second file not up to date. No use of FileSuffix
+               if ( $DNSLookup == 1 ) {    # System DNS lookup required
+                        #if (! eval("use Socket;")) { error("Failed to load perl module Socket."); }
+                        #use Socket;
+                       &Read_DNS_Cache( \%TmpDNSLookup, "$DNSLastUpdateCacheFile",
+                               "$FileSuffix", 0 )
+                         ;    # Load with no save into a second plugin file. Use FileSuffix
                }
-
        }
 
-       # HTMLHeadSection
-       if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
-               print "<a name=\"top\"></a>\n\n";
-               my $newhead = $HTMLHeadSection;
-               $newhead =~ s/\\n/\n/g;
-               print "$newhead\n";
-               print "\n";
-       }
+       # Processing log
+       #------------------------------------------
 
-       # Call to plugins' function AddHTMLBodyHeader
-       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyHeader'} } ) {
+       if ($EnableLockForUpdate) {
 
-               #               my $function="AddHTMLBodyHeader_$pluginname()";
-               #               eval("$function");
-               my $function = "AddHTMLBodyHeader_$pluginname";
-               &$function();
+               # Trap signals to remove lock
+               $SIG{INT} = \&SigHandler;    # 2
+                                            #$SIG{KILL} = \&SigHandler;        # 9
+                                            #$SIG{TERM} = \&SigHandler;        # 15
+                                            # Set AWStats update lock
+               &Lock_Update(1);
        }
 
-       my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
+       if ($Debug) {
+               debug("Start Update process (lastprocesseddate=$lastprocesseddate)");
+       }
 
-       # TOP BAN
-       #---------------------------------------------------------------------
-       if ( $ShowMenu || $FrameName eq 'mainleft' ) {
-               my $frame = ( $FrameName eq 'mainleft' );
+       # Open log file
+       if ($Debug) { debug("Open log file \"$LogFile\""); }
+       open( LOG, "$LogFile" )
+         || error("Couldn't open server log file \"$LogFile\" : $!");
+       binmode LOG
+         ;   # Avoid premature EOF due to log files corrupted with \cZ or bin chars
 
-               if ($Debug) { debug( "ShowTopBan", 2 ); }
-               print "$Center<a name=\"menu\">&nbsp;</a>\n";
+       # Define local variables for loop scan
+       my @field               = ();
+       my $counterforflushtest = 0;
+       my $qualifdrop          = '';
+       my $countedtraffic      = 0;
 
-               if ( $FrameName ne 'mainleft' ) {
-                       my $NewLinkParams = ${QueryString};
-                       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-                       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-                       $NewLinkParams =~ s/^&amp;//;
-                       $NewLinkParams =~ s/&amp;$//;
-                       my $NewLinkTarget = '';
+       # Reset chrono for benchmark (first call to GetDelaySinceStart)
+       &GetDelaySinceStart(1);
+       if ( !scalar keys %HTMLOutput ) {
+               print "Phase 1 : First bypass old records, searching new record...\n";
+       }
 
-                       if ( $FrameName eq 'mainright' ) {
-                               $NewLinkTarget = " target=\"_parent\"";
-                       }
-                       print "<form name=\"FormDateFilter\" action=\""
-                         . XMLEncode("$AWScript?${NewLinkParams}")
-                         . "\" style=\"padding: 0px 0px 0px 0px; margin-top: 0\"$NewLinkTarget>\n";
-               }
+       # Can we try a direct seek access in log ?
+       my $line;
+       if ( $LastLine && $LastLineNumber && $LastLineOffset && $LastLineChecksum )
+       {
 
-               if ( $QueryString !~ /buildpdf/i ) {
-                       print
-"<table class=\"aws_border\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">\n";
-                       print "<tr><td>\n";
-                       print
-"<table class=\"aws_data sortable\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">\n";
-               }
-               else {
-                       print "<table width=\"100%\">\n";
+               # Try a direct seek access to save time
+               if ($Debug) {
+                       debug(
+"Try a direct access to LastLine=$LastLine, LastLineNumber=$LastLineNumber, LastLineOffset=$LastLineOffset, LastLineChecksum=$LastLineChecksum"
+                       );
                }
-
-               if ( $FrameName ne 'mainright' ) {
-
-                       # Print Statistics Of
-                       if ( $FrameName eq 'mainleft' ) {
-                               my $shortSiteDomain = $SiteDomain;
-                               if ( length($SiteDomain) > 30 ) {
-                                       $shortSiteDomain =
-                                           substr( $SiteDomain, 0, 20 ) . "..."
-                                         . substr( $SiteDomain, length($SiteDomain) - 5, 5 );
+               seek( LOG, $LastLineOffset, 0 );
+               if ( $line = <LOG> ) {
+                       chomp $line;
+                       $line =~ s/\r$//;
+                       @field = map( /$PerlParsingFormat/, $line );
+                       if ($Debug) {
+                               my $string = '';
+                               foreach ( 0 .. @field - 1 ) {
+                                       $string .= "$fieldlib[$_]=$field[$_] ";
                                }
-                               print
-"<tr><td class=\"awsm\"><b>$Message[7]:</b></td></tr><tr><td class=\"aws\"><span style=\"font-size: 12px;\">$shortSiteDomain</span></td>";
+                               if ($Debug) {
+                                       debug( " Read line after direct access: $string", 1 );
+                               }
+                       }
+                       my $checksum = &CheckSum($line);
+                       if ($Debug) {
+                               debug(
+" LastLineChecksum=$LastLineChecksum, Read line checksum=$checksum",
+                                       1
+                               );
+                       }
+                       if ( $checksum == $LastLineChecksum ) {
+                               if ( !scalar keys %HTMLOutput ) {
+                                       print
+"Direct access after last parsed record (after line $LastLineNumber)\n";
+                               }
+                               $lastlinenb         = $LastLineNumber;
+                               $lastlineoffset     = $LastLineOffset;
+                               $lastlineoffsetnext = tell LOG;
+                               $NewLinePhase       = 1;
                        }
                        else {
+                               if ( !scalar keys %HTMLOutput ) {
+                                       print
+"Direct access to last remembered record has fallen on another record.\nSo searching new records from beginning of log file...\n";
+                               }
+                               $lastlinenb         = 0;
+                               $lastlineoffset     = 0;
+                               $lastlineoffsetnext = 0;
+                               seek( LOG, 0, 0 );
+                       }
+               }
+               else {
+                       if ( !scalar keys %HTMLOutput ) {
                                print
-"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[7]:</b>&nbsp;</td><td class=\"aws\" valign=\"middle\"><span style=\"font-size: 14px;\">$SiteDomain</span></td>";
+"Direct access to last remembered record is out of file.\nSo searching it from beginning of log file...\n";
                        }
+                       $lastlinenb         = 0;
+                       $lastlineoffset     = 0;
+                       $lastlineoffsetnext = 0;
+                       seek( LOG, 0, 0 );
+               }
+       }
+       else {
 
-                       # Logo and flags
-                       if ( $FrameName ne 'mainleft' ) {
-                               if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
-                                       print "<td align=\"right\" rowspan=\"3\"><a href=\""
-                                         . XMLEncode($LogoLink)
-                                         . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
-                                         . AltTitle( ucfirst($PROG) . " Web Site" )
-                                         . " /></a>";
-                               }
-                               else {
-                                       print "<td align=\"right\" rowspan=\"3\"><a href=\""
-                                         . XMLEncode($LogoLink)
-                                         . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>";
-                               }
-                               if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
-                               print "</td>";
+               # No try of direct seek access
+               if ( !scalar keys %HTMLOutput ) {
+                       print "Searching new records from beginning of log file...\n";
+               }
+               $lastlinenb         = 0;
+               $lastlineoffset     = 0;
+               $lastlineoffsetnext = 0;
+       }
+
+       #
+       # Loop on each log line
+       #
+       while ( $line = <LOG> ) {
+               
+               # 20080525 BEGIN Patch to test if first char of $line = hex "00" then conclude corrupted with binary code
+               my $FirstHexChar;
+               $FirstHexChar = sprintf( "%02X", ord( substr( $line, 0, 1 ) ) );
+               if ( $FirstHexChar eq '00' ) {
+                       $NbOfLinesCorrupted++;
+                       if ($ShowCorrupted) {
+                               print "Corrupted record line "
+                                 . ( $lastlinenb + $NbOfLinesParsed )
+                                 . " (record starts with hex 00; binary code): $line\n";
                        }
-                       print "</tr>\n";
+                       if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
+                               && $NbOfLinesParsed == $NbOfLinesCorrupted )
+                       {
+                               error( "Format error", $line, $LogFile );
+                       }    # Exit with format error
+                       next;
                }
-               if ( $FrameName ne 'mainleft' ) {
+               # 20080525 END
 
-                       # Print Last Update
-                       print
-"<tr valign=\"middle\"><td class=\"aws\" valign=\"middle\" width=\"$WIDTHMENU1\"><b>$Message[35]:</b>&nbsp;</td>";
-                       print
-"<td class=\"aws\" valign=\"middle\"><span style=\"font-size: 12px;\">";
-                       if ($LastUpdate) { print Format_Date( $LastUpdate, 0 ); }
-                       else {
+               chomp $line;
+               $line =~ s/\r$//;
+               if ( $UpdateFor && $NbOfLinesParsed >= $UpdateFor ) { last; }
+               $NbOfLinesParsed++;
 
-                               # Here NbOfOldLines = 0 (because LastUpdate is not defined)
-                               if ( !$UpdateStats ) {
-                                       print "<span style=\"color: #880000\">$Message[24]</span>";
-                               }
-                               else {
-                                       print
-"<span style=\"color: #880000\">No qualified records found in log ($NbOfLinesCorrupted corrupted, $NbOfLinesDropped dropped)</span>";
-                               }
+               $lastlineoffset     = $lastlineoffsetnext;
+               $lastlineoffsetnext = tell LOG;
 
+               if ($ShowSteps) {
+                       if ( ( ++$NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) == 0 ) {
+                               my $delay = &GetDelaySinceStart(0);
+                               print "$NbOfLinesParsed lines processed ("
+                                 . ( $delay > 0 ? $delay : 1000 ) . " ms, "
+                                 . int(
+                                       1000 * $NbOfLinesShowsteps / ( $delay > 0 ? $delay : 1000 )
+                                 )
+                                 . " lines/second)\n";
                        }
-                       print "</span>";
+               }
 
-                       # Print Update Now link
-                       if ( $AllowToUpdateStatsFromBrowser && !$StaticLinks ) {
-                               my $NewLinkParams = ${QueryString};
-                               $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
-                               $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
-                               $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-                               if ( $FrameName eq 'mainright' ) {
-                                       $NewLinkParams .= "&amp;framename=mainright";
-                               }
-                               $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-                               $NewLinkParams =~ s/^&amp;//;
-                               $NewLinkParams =~ s/&amp;$//;
-                               if ($NewLinkParams) {
-                                       $NewLinkParams = "${NewLinkParams}&amp;";
-                               }
-                               print "&nbsp; &nbsp; &nbsp; &nbsp;";
-                               print "<a href=\""
-                                 . XMLEncode("$AWScript?${NewLinkParams}update=1")
-                                 . "\">$Message[74]</a>";
+               if ( $LogFormat eq '2' && $line =~ /^#Fields:/ ) {
+                       my @fixField = map( /^#Fields: (.*)/, $line );
+                       if ( $fixField[0] !~ /s-kernel-time/ ) {
+                               debug( "Found new log format: '" . $fixField[0] . "'", 1 );
+                               &DefinePerlParsingFormat( $fixField[0] );
                        }
-                       print "</td>";
+               }
 
-                       # Logo and flags
-                       if ( $FrameName eq 'mainright' ) {
-                               if ( $LogoLink =~ "http://awstats.sourceforge.net" ) {
-                                       print "<td align=\"right\" rowspan=\"2\"><a href=\""
-                                         . XMLEncode($LogoLink)
-                                         . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\""
-                                         . AltTitle( ucfirst($PROG) . " Web Site" )
-                                         . " /></a>\n";
+               # Parse line record to get all required fields
+               if ( !( @field = map( /$PerlParsingFormat/, $line ) ) ) {
+                       $NbOfLinesCorrupted++;
+                       if ($ShowCorrupted) {
+                               if ( $line =~ /^#/ || $line =~ /^!/ ) {
+                                       print "Corrupted record line "
+                                         . ( $lastlinenb + $NbOfLinesParsed )
+                                         . " (comment line): $line\n";
+                               }
+                               elsif ( $line =~ /^\s*$/ ) {
+                                       print "Corrupted record line "
+                                         . ( $lastlinenb + $NbOfLinesParsed )
+                                         . " (blank line)\n";
                                }
                                else {
-                                       print "<td align=\"right\" rowspan=\"2\"><a href=\""
-                                         . XMLEncode($LogoLink)
-                                         . "\" target=\"awstatshome\"><img src=\"$DirIcons/other/$Logo\" border=\"0\" /></a>\n";
+                                       print "Corrupted record line "
+                                         . ( $lastlinenb + $NbOfLinesParsed )
+                                         . " (record format does not match LogFormat parameter): $line\n";
                                }
-                               if ( !$StaticLinks ) { print "<br />"; Show_Flag_Links($Lang); }
-                               print "</td>";
                        }
+                       if (   $NbOfLinesParsed >= $NbOfLinesForCorruptedLog
+                               && $NbOfLinesParsed == $NbOfLinesCorrupted )
+                       {
+                               error( "Format error", $line, $LogFile );
+                       }    # Exit with format error
+                       if ( $line =~ /^__end_of_file__/i ) { last; } # For test purpose only
+                       next;
+               }
 
-                       print "</tr>\n";
+               if ($Debug) {
+                       my $string = '';
+                       foreach ( 0 .. @field - 1 ) {
+                               $string .= "$fieldlib[$_]=$field[$_] ";
+                       }
+                       if ($Debug) {
+                               debug(
+                                       " Correct format line "
+                                         . ( $lastlinenb + $NbOfLinesParsed )
+                                         . ": $string",
+                                       4
+                               );
+                       }
+               }
 
-                       # Print selected period of analysis (month and year required)
-                       print
-"<tr><td class=\"aws\" valign=\"middle\"><b>$Message[133]:</b></td>";
-                       print "<td class=\"aws\" valign=\"middle\">";
-                       if ( $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks ) {
-                               print "<select class=\"aws_formfield\" name=\"month\">\n";
-                               foreach ( 1 .. 12 ) {
-                                       my $monthix = sprintf( "%02s", $_ );
-                                       print "<option"
-                                         . (
-                                                 "$MonthRequired" eq "$monthix"
-                                               ? " selected=\"true\""
-                                               : ""
-                                         )
-                                         . " value=\"$monthix\">$MonthNumLib{$monthix}</option>\n";
-                               }
-                               if ( $AllowFullYearView >= 2 ) {
-                                       print "<option"
-                                         . ( $MonthRequired eq 'all' ? " selected=\"true\"" : "" )
-                                         . " value=\"all\">- $Message[6] -</option>\n";
-                               }
-                               print "</select>\n";
-                               print "<select class=\"aws_formfield\" name=\"year\">\n";
-
-                               # Add YearRequired in list if not in ListOfYears
-                               $ListOfYears{$YearRequired} ||= $MonthRequired;
-                               foreach ( sort keys %ListOfYears ) {
-                                       print "<option"
-                                         . ( $YearRequired eq "$_" ? " selected=\"true\"" : "" )
-                                         . " value=\"$_\">$_</option>\n";
-                               }
-                               print "</select>\n";
-                               print "<input type=\"hidden\" name=\"output\" value=\""
-                                 . join( ',', keys %HTMLOutput )
-                                 . "\" />\n";
-                               if ($SiteConfig) {
-                                       print
-"<input type=\"hidden\" name=\"config\" value=\"$SiteConfig\" />\n";
-                               }
-                               if ($DirConfig) {
-                                       print
-"<input type=\"hidden\" name=\"configdir\" value=\"$DirConfig\" />\n";
-                               }
-                               if ( $QueryString =~ /lang=(\w+)/i ) {
-                                       print
-                                         "<input type=\"hidden\" name=\"lang\" value=\"$1\" />\n";
-                               }
-                               if ( $QueryString =~ /debug=(\d+)/i ) {
-                                       print
-                                         "<input type=\"hidden\" name=\"debug\" value=\"$1\" />\n";
-                               }
-                               if ( $FrameName eq 'mainright' ) {
-                                       print
-"<input type=\"hidden\" name=\"framename\" value=\"index\" />\n";
-                               }
-                               print
-"<input type=\"submit\" value=\" $Message[115] \" class=\"aws_button\" />";
+               # Drop wrong virtual host name
+               #----------------------------------------------------------------------
+               if ( $pos_vh >= 0 && $field[$pos_vh] !~ /^$SiteDomain$/i ) {
+                       my $skip = 1;
+                       foreach (@HostAliases) {
+                               if ( $field[$pos_vh] =~ /$_/ ) { $skip = 0; last; }
                        }
-                       else {
-                               print "<span style=\"font-size: 14px;\">";
-                               if ($DayRequired) { print "$Message[4] $DayRequired - "; }
-                               if ( $MonthRequired eq 'all' ) {
-                                       print "$Message[6] $YearRequired";
-                               }
-                               else {
+                       if ($skip) {
+                               $NbOfLinesDropped++;
+                               if ($ShowDropped) {
                                        print
-                                         "$Message[5] $MonthNumLib{$MonthRequired} $YearRequired";
+"Dropped record (virtual hostname '$field[$pos_vh]' does not match SiteDomain='$SiteDomain' nor HostAliases parameters): $line\n";
                                }
-                               print "</span>";
+                               next;
                        }
-                       print "</td></tr>\n";
                }
-               if ( $QueryString !~ /buildpdf/i ) {
-                       print "</table>\n";
-                       print "</td></tr></table>\n";
-               }
-               else {
-                       print "</table>\n";
-               }
-
-               if ( $FrameName ne 'mainleft' ) { print "</form>\n"; }
-               else { print "<br />\n"; }
-               print "\n";
-       }
-
-       # Call to plugins' function AddHTMLMenuHeader
-       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuHeader'} } ) {
-
-               #               my $function="AddHTMLMenuHeader_$pluginname()";
-               #               eval("$function");
-               my $function = "AddHTMLMenuHeader_$pluginname";
-               &$function();
-       }
 
-       # MENU (ON LEFT IF FRAME OR TOP)
-       #---------------------------------------------------------------------
-       if ( $ShowMenu || $FrameName eq 'mainleft' ) {
-               my $frame = ( $FrameName eq 'mainleft' );
-
-               if ($Debug) { debug( "ShowMenu", 2 ); }
-
-               # Print menu links
-               if ( ( $HTMLOutput{'main'} && $FrameName ne 'mainright' )
-                       || $FrameName eq 'mainleft' )
-               {    # If main page asked
-                           # Define link anchor
-                       my $linkanchor =
-                         ( $FrameName eq 'mainleft' ? "$AWScript?${NewLinkParams}" : "" );
-                       if ( $linkanchor && ( $linkanchor !~ /framename=mainright/ ) ) {
-                               $linkanchor .= "framename=mainright";
-                       }
-                       $linkanchor =~ s/(&|&amp;)$//;
-                       $linkanchor = XMLEncode("$linkanchor");
-
-                       # Define target
-                       my $targetpage =
-                         ( $FrameName eq 'mainleft' ? " target=\"mainright\"" : "" );
-
-                       # Print Menu
-                       my $linetitle;    # TODO a virer
-                       if ( !$PluginsLoaded{'ShowMenu'}{'menuapplet'} ) {
-                               my $menuicon = 0;    # TODO a virer
-                                                    # Menu HTML
-                               print "<table"
-                                 . (
-                                       $frame
-                                       ? " cellspacing=\"0\" cellpadding=\"0\" border=\"0\""
-                                       : ""
-                                 )
-                                 . ">\n";
-                               if ( $FrameName eq 'mainleft' && $ShowMonthStats ) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#top\"$targetpage>$Message[128]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               my %menu     = ();
-                               my %menulink = ();
-                               my %menutext = ();
-
-                               # When
-                               %menu = (
-                                       'month'       => $ShowMonthStats       ? 1 : 0,
-                                       'daysofmonth' => $ShowDaysOfMonthStats ? 2 : 0,
-                                       'daysofweek'  => $ShowDaysOfWeekStats  ? 3 : 0,
-                                       'hours'       => $ShowHoursStats       ? 4 : 0
-                               );
-                               %menulink = (
-                                       'month'       => 1,
-                                       'daysofmonth' => 1,
-                                       'daysofweek'  => 1,
-                                       'hours'       => 1
-                               );
-                               %menutext = (
-                                       'month'       => $Message[162],
-                                       'daysofmonth' => $Message[138],
-                                       'daysofweek'  => $Message[91],
-                                       'hours'       => $Message[20]
-                               );
-                               ShowMenuCateg(
-                                       'when',         $Message[93],
-                                       'menu4.png',    $frame,
-                                       $targetpage,    $linkanchor,
-                                       $NewLinkParams, $NewLinkTarget,
-                                       \%menu,         \%menulink,
-                                       \%menutext
-                               );
+               # Drop wrong method/protocol
+               #---------------------------
+               if ( $LogType ne 'M' ) { $field[$pos_url] =~ s/\s/%20/g; }
+               if (
+                       $LogType eq 'W'
+                       && (
+                                  $field[$pos_method] eq 'GET'
+                               || $field[$pos_method] eq 'POST'
+                               || $field[$pos_method] eq 'HEAD'
+                               || $field[$pos_method] eq 'PROPFIND'
+                               || $field[$pos_method] eq 'CHECKOUT'
+                               || $field[$pos_method] eq 'LOCK'
+                               || $field[$pos_method] eq 'PROPPATCH'
+                               || $field[$pos_method] eq 'OPTIONS'
+                               || $field[$pos_method] eq 'MKACTIVITY'
+                               || $field[$pos_method] eq 'PUT'
+                               || $field[$pos_method] eq 'MERGE'
+                               || $field[$pos_method] eq 'DELETE'
+                               || $field[$pos_method] eq 'REPORT'
+                               || $field[$pos_method] eq 'MKCOL'
+                               || $field[$pos_method] eq 'COPY'
+                               || $field[$pos_method] eq 'RPC_IN_DATA'
+                               || $field[$pos_method] eq 'RPC_OUT_DATA'
+                               || $field[$pos_method] eq 'OK'             # Webstar
+                               || $field[$pos_method] eq 'ERR!'           # Webstar
+                               || $field[$pos_method] eq 'PRIV'           # Webstar
+                       )
+                 )
+               {
 
-                               # Who
-                               %menu = (
-                                       'countries'  => $ShowDomainsStats ? 1 : 0,
-                                       'alldomains' => $ShowDomainsStats ? 2 : 0,
-                                       'visitors'   => $ShowHostsStats   ? 3 : 0,
-                                       'allhosts'   => $ShowHostsStats   ? 4 : 0,
-                                       'lasthosts' => ( $ShowHostsStats =~ /L/i ) ? 5 : 0,
-                                       'unknownip' => $ShowHostsStats         ? 6 : 0,
-                                       'logins'    => $ShowAuthenticatedUsers ? 7 : 0,
-                                       'alllogins' => $ShowAuthenticatedUsers ? 8 : 0,
-                                       'lastlogins' => ( $ShowAuthenticatedUsers =~ /L/i ) ? 9 : 0,
-                                       'emailsenders' => $ShowEMailSenders ? 10 : 0,
-                                       'allemails'    => $ShowEMailSenders ? 11 : 0,
-                                       'lastemails' => ( $ShowEMailSenders =~ /L/i ) ? 12 : 0,
-                                       'emailreceivers' => $ShowEMailReceivers ? 13 : 0,
-                                       'allemailr'      => $ShowEMailReceivers ? 14 : 0,
-                                       'lastemailr' => ( $ShowEMailReceivers =~ /L/i ) ? 15 : 0,
-                                       'robots'    => $ShowRobotsStats ? 16 : 0,
-                                       'allrobots' => $ShowRobotsStats ? 17 : 0,
-                                       'lastrobots' => ( $ShowRobotsStats =~ /L/i ) ? 18 : 0,
-                                       'worms' => $ShowWormsStats ? 19 : 0
-                               );
-                               %menulink = (
-                                       'countries'      => 1,
-                                       'alldomains'     => 2,
-                                       'visitors'       => 1,
-                                       'allhosts'       => 2,
-                                       'lasthosts'      => 2,
-                                       'unknownip'      => 2,
-                                       'logins'         => 1,
-                                       'alllogins'      => 2,
-                                       'lastlogins'     => 2,
-                                       'emailsenders'   => 1,
-                                       'allemails'      => 2,
-                                       'lastemails'     => 2,
-                                       'emailreceivers' => 1,
-                                       'allemailr'      => 2,
-                                       'lastemailr'     => 2,
-                                       'robots'         => 1,
-                                       'allrobots'      => 2,
-                                       'lastrobots'     => 2,
-                                       'worms'          => 1
-                               );
-                               %menutext = (
-                                       'countries'      => $Message[148],
-                                       'alldomains'     => $Message[80],
-                                       'visitors'       => $Message[81],
-                                       'allhosts'       => $Message[80],
-                                       'lasthosts'      => $Message[9],
-                                       'unknownip'      => $Message[45],
-                                       'logins'         => $Message[94],
-                                       'alllogins'      => $Message[80],
-                                       'lastlogins'     => $Message[9],
-                                       'emailsenders'   => $Message[131],
-                                       'allemails'      => $Message[80],
-                                       'lastemails'     => $Message[9],
-                                       'emailreceivers' => $Message[132],
-                                       'allemailr'      => $Message[80],
-                                       'lastemailr'     => $Message[9],
-                                       'robots'         => $Message[53],
-                                       'allrobots'      => $Message[80],
-                                       'lastrobots'     => $Message[9],
-                                       'worms'          => $Message[136]
-                               );
-                               ShowMenuCateg(
-                                       'who',          $Message[92],
-                                       'menu5.png',    $frame,
-                                       $targetpage,    $linkanchor,
-                                       $NewLinkParams, $NewLinkTarget,
-                                       \%menu,         \%menulink,
-                                       \%menutext
-                               );
+# HTTP request.        Keep only GET, POST, HEAD, *OK* and ERR! for Webstar. Do not keep OPTIONS, TRACE
+               }
+               elsif (
+                       ( $LogType eq 'W' || $LogType eq 'S' )
+                       && (   $field[$pos_method] eq 'GET'
+                               || $field[$pos_method] eq 'mms'
+                               || $field[$pos_method] eq 'rtsp'
+                               || $field[$pos_method] eq 'http'
+                               || $field[$pos_method] eq 'RTP' )
+                 )
+               {
 
-                               # Navigation
-                               $linetitle = &AtLeastOneNotNull(
-                                       $ShowSessionsStats,  $ShowPagesStats,
-                                       $ShowFileTypesStats, $ShowFileSizesStats,
-                                       $ShowOSStats,        $ShowBrowsersStats,
-                                       $ShowScreenSizeStats
-                               );
-                               if ($linetitle) {
-                                       print "<tr><td class=\"awsm\""
-                                         . ( $frame ? "" : " valign=\"top\"" ) . ">"
-                                         . (
-                                               $menuicon
-                                               ? "<img src=\"$DirIcons/other/menu2.png\" />&nbsp;"
-                                               : ""
-                                         )
-                                         . "<b>$Message[72]:</b></td>\n";
-                               }
-                               if ($linetitle) {
-                                       print( $frame? "</tr>\n" : "<td class=\"awsm\">" );
-                               }
-                               if ($ShowSessionsStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#sessions\"$targetpage>$Message[117]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowFileTypesStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#filetypes\"$targetpage>$Message[73]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowPagesStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#urls\"$targetpage>$Message[29]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowPagesStats) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=urldetail")
-                                               : "$StaticLinks.urldetail.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[80]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=urlentry")
-                                               : "$StaticLinks.urlentry.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[104]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'}
-                                                 || !$StaticLinks
-                                               ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
-                                               : "$StaticLinks.urlexit.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[116]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowOSStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-                                         "<a href=\"$linkanchor#os\"$targetpage>$Message[59]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowOSStats) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=osdetail")
-                                               : "$StaticLinks.osdetail.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[58]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowOSStats) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=unknownos")
-                                               : "$StaticLinks.unknownos.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[0]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowBrowsersStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#browsers\"$targetpage>$Message[21]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowBrowsersStats) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=browserdetail")
-                                               : "$StaticLinks.browserdetail.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[58]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowBrowsersStats) {
-                                       print( $frame
-                                               ? "<tr><td class=\"awsm\"> &nbsp; <img height=\"8\" width=\"9\" src=\"$DirIcons/other/page.png\" alt=\"...\" /> "
-                                               : ""
-                                       );
-                                       print "<a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=unknownbrowser")
-                                               : "$StaticLinks.unknownbrowser.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$Message[0]</a>\n";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($ShowScreenSizeStats) {
-                                       print( $frame? "<tr><td class=\"awsm\">" : "" );
-                                       print
-"<a href=\"$linkanchor#screensizes\"$targetpage>$Message[135]</a>";
-                                       print( $frame? "</td></tr>\n" : " &nbsp; " );
-                               }
-                               if ($linetitle) { print( $frame? "" : "</td></tr>\n" ); }
-
-                               # Referers
-                               %menu = (
-                                       'referer'      => $ShowOriginStats ? 1 : 0,
-                                       'refererse'    => $ShowOriginStats ? 2 : 0,
-                                       'refererpages' => $ShowOriginStats ? 3 : 0,
-                                       'keys' => ( $ShowKeyphrasesStats || $ShowKeywordsStats )
-                                       ? 4
-                                       : 0,
-                                       'keyphrases' => $ShowKeyphrasesStats ? 5 : 0,
-                                       'keywords'   => $ShowKeywordsStats   ? 6 : 0
-                               );
-                               %menulink = (
-                                       'referer'      => 1,
-                                       'refererse'    => 2,
-                                       'refererpages' => 2,
-                                       'keys'         => 1,
-                                       'keyphrases'   => 2,
-                                       'keywords'     => 2
-                               );
-                               %menutext = (
-                                       'referer'      => $Message[37],
-                                       'refererse'    => $Message[126],
-                                       'refererpages' => $Message[127],
-                                       'keys'         => $Message[14],
-                                       'keyphrases'   => $Message[120],
-                                       'keywords'     => $Message[121]
-                               );
-                               ShowMenuCateg(
-                                       'referers',     $Message[23],
-                                       'menu7.png',    $frame,
-                                       $targetpage,    $linkanchor,
-                                       $NewLinkParams, $NewLinkTarget,
-                                       \%menu,         \%menulink,
-                                       \%menutext
-                               );
+# Streaming request (windows media server, realmedia or darwin streaming server)
+               }
+               elsif ( $LogType eq 'M' && $field[$pos_method] eq 'SMTP' ) {
 
-                               # Others
-                               %menu = (
-                                       'filetypes' => ( $ShowFileTypesStats =~ /C/i ) ? 1 : 0,
-                                       'misc' => $ShowMiscStats ? 2 : 0,
-                                       'errors' => ( $ShowHTTPErrorsStats || $ShowSMTPErrorsStats )
-                                       ? 3
-                                       : 0,
-                                       'clusters' => $ShowClusterStats ? 5 : 0
-                               );
-                               %menulink = (
-                                       'filetypes' => 1,
-                                       'misc'      => 1,
-                                       'errors'    => 1,
-                                       'clusters'  => 1
-                               );
-                               %menutext = (
-                                       'filetypes' => $Message[98],
-                                       'misc'      => $Message[139],
-                                       'errors'    =>
-                                         ( $ShowSMTPErrorsStats ? $Message[147] : $Message[32] ),
-                                       'clusters' => $Message[155]
-                               );
-                               foreach ( keys %TrapInfosForHTTPErrorCodes ) {
-                                       $menu{"errors$_"}     = $ShowHTTPErrorsStats ? 4 : 0;
-                                       $menulink{"errors$_"} = 2;
-                                       $menutext{"errors$_"} = $Message[31];
-                               }
-                               ShowMenuCateg(
-                                       'others',       $Message[2],
-                                       'menu8.png',    $frame,
-                                       $targetpage,    $linkanchor,
-                                       $NewLinkParams, $NewLinkTarget,
-                                       \%menu,         \%menulink,
-                                       \%menutext
-                               );
+               # Mail request ('SMTP' for mail log with maillogconvert.pl preprocessor)
+               }
+               elsif (
+                       $LogType eq 'F'
+                       && (   $field[$pos_method] eq 'RETR'
+                               || $field[$pos_method] eq 'o'
+                               || $field[$pos_method] =~ /$regget/o )
+                 )
+               {
 
-                               # Extra/Marketing
-                               %menu     = ();
-                               %menulink = ();
-                               %menutext = ();
-                               my $i = 1;
-                               foreach ( 1 .. @ExtraName - 1 ) {
-                                       $menu{"extra$_"}        = $i++;
-                                       $menulink{"extra$_"}    = 1;
-                                       $menutext{"extra$_"}    = $ExtraName[$_];
-                                       $menu{"allextra$_"}     = $i++;
-                                       $menulink{"allextra$_"} = 2;
-                                       $menutext{"allextra$_"} = $Message[80];
-                               }
-                               ShowMenuCateg(
-                                       'extra',        $Message[134],
-                                       '',             $frame,
-                                       $targetpage,    $linkanchor,
-                                       $NewLinkParams, $NewLinkTarget,
-                                       \%menu,         \%menulink,
-                                       \%menutext
-                               );
-                               print "</table>\n";
+                       # FTP GET request
+               }
+               elsif (
+                       $LogType eq 'F'
+                       && (   $field[$pos_method] eq 'STOR'
+                               || $field[$pos_method] eq 'i'
+                               || $field[$pos_method] =~ /$regsent/o )
+                 )
+               {
+
+                       # FTP SENT request
+               }
+               else {
+                       $NbOfLinesDropped++;
+                       if ($ShowDropped) {
+                               print
+"Dropped record (method/protocol '$field[$pos_method]' not qualified when LogType=$LogType): $line\n";
                        }
-                       else {
+                       next;
+               }
 
-                               # Menu Applet
-                               if ($frame) { }
-                               else { }
+               $field[$pos_date] =~
+                 tr/,-\/ \t/:::::/s;  # " \t" is used instead of "\s" not known with tr
+               my @dateparts =
+                 split( /:/, $field[$pos_date] )
+                 ; # tr and split faster than @dateparts=split(/[\/\-:\s]/,$field[$pos_date])
+                # Detected date format: dddddddddd, YYYY-MM-DD HH:MM:SS (IIS), MM/DD/YY\tHH:MM:SS,
+                # DD/Month/YYYY:HH:MM:SS (Apache), DD/MM/YYYY HH:MM:SS, Mon DD HH:MM:SS
+               if ( !$dateparts[1] ) {    # Unix timestamp
+                       (
+                               $dateparts[5], $dateparts[4], $dateparts[3],
+                               $dateparts[0], $dateparts[1], $dateparts[2]
+                         )
+                         = localtime( int( $field[$pos_date] ) );
+                       $dateparts[1]++;
+                       $dateparts[2] += 1900;
+               }
+               elsif ( $dateparts[0] =~ /^....$/ ) {
+                       my $tmp = $dateparts[0];
+                       $dateparts[0] = $dateparts[2];
+                       $dateparts[2] = $tmp;
+               }
+               elsif ( $field[$pos_date] =~ /^..:..:..:/ ) {
+                       $dateparts[2] += 2000;
+                       my $tmp = $dateparts[0];
+                       $dateparts[0] = $dateparts[1];
+                       $dateparts[1] = $tmp;
+               }
+               elsif ( $dateparts[0] =~ /^...$/ ) {
+                       my $tmp = $dateparts[0];
+                       $dateparts[0] = $dateparts[1];
+                       $dateparts[1] = $tmp;
+                       $tmp          = $dateparts[5];
+                       $dateparts[5] = $dateparts[4];
+                       $dateparts[4] = $dateparts[3];
+                       $dateparts[3] = $dateparts[2];
+                       $dateparts[2] = $tmp || $nowyear;
+               }
+               if ( exists( $MonthNum{ $dateparts[1] } ) ) {
+                       $dateparts[1] = $MonthNum{ $dateparts[1] };
+               }    # Change lib month in num month if necessary
+               if ( $dateparts[1] <= 0 )
+               { # Date corrupted (for example $dateparts[1]='dic' for december month in a spanish log file)
+                       $NbOfLinesCorrupted++;
+                       if ($ShowCorrupted) {
+                               print "Corrupted record line "
+                                 . ( $lastlinenb + $NbOfLinesParsed )
+                                 . " (bad date format for month, may be month are not in english ?): $line\n";
                        }
+                       next;
+               }
 
-                       #print ($frame?"":"<br />\n");
-                       print "<br />\n";
+# Now @dateparts is (DD,MM,YYYY,HH,MM,SS) and we're going to create $timerecord=YYYYMMDDHHMMSS
+               if ( $PluginsLoaded{'ChangeTime'}{'timezone'} ) {
+                       @dateparts = ChangeTime_timezone( \@dateparts );
+               }
+               my $yearrecord  = int( $dateparts[2] );
+               my $monthrecord = int( $dateparts[1] );
+               my $dayrecord   = int( $dateparts[0] );
+               my $hourrecord  = int( $dateparts[3] );
+               my $daterecord  = '';
+               if ( $DatabaseBreak eq 'month' ) {
+                       $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
+               }
+               elsif ( $DatabaseBreak eq 'year' ) {
+                       $daterecord = sprintf( "%04i%", $yearrecord );
+               }
+               elsif ( $DatabaseBreak eq 'day' ) {
+                       $daterecord =
+                         sprintf( "%04i%02i%02i", $yearrecord, $monthrecord, $dayrecord );
+               }
+               elsif ( $DatabaseBreak eq 'hour' ) {
+                       $daterecord = sprintf( "%04i%02i%02i%02i",
+                               $yearrecord, $monthrecord, $dayrecord, $hourrecord );
                }
 
-               # Print Back link
-               elsif ( !$HTMLOutput{'main'} ) {
-                       print "<table>\n";
-                       $NewLinkParams =~ s/(^|&|&amp;)hostfilter=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)urlfilter=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)refererpagesfilter=[^&]*//i;
-                       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-                       $NewLinkParams =~ s/^&amp;//;
-                       $NewLinkParams =~ s/&amp;$//;
-                       if (   !$DetailedReportsOnNewWindows
-                               || $FrameName eq 'mainright'
-                               || $QueryString =~ /buildpdf/i )
-                       {
-                               print "<tr><td class=\"aws\"><a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                       ? XMLEncode(
-                                               "$AWScript"
-                                                 . ( ${NewLinkParams} ? "?${NewLinkParams}" : "" )
-                                         )
-                                       : "$StaticLinks.$StaticExt"
-                                 )
-                                 . "\">$Message[76]</a></td></tr>\n";
+               # TODO essayer de virer yearmonthrecord
+               my $yearmonthdayrecord =
+                 sprintf( "$dateparts[2]%02i%02i", $dateparts[1], $dateparts[0] );
+               my $timerecord =
+                 ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
+                         $dateparts[4] ) * 100 + $dateparts[5];
+
+               # Check date
+               #-----------------------
+               if ( $LogType eq 'M' && $timerecord > $tomorrowtime ) {
+
+# Postfix/Sendmail does not store year, so we assume that year is year-1 if record is in future
+                       $yearrecord--;
+                       if ( $DatabaseBreak eq 'month' ) {
+                               $daterecord = sprintf( "%04i%02i", $yearrecord, $monthrecord );
                        }
-                       else {
+                       elsif ( $DatabaseBreak eq 'year' ) {
+                               $daterecord = sprintf( "%04i%", $yearrecord );
+                       }
+                       elsif ( $DatabaseBreak eq 'day' ) {
+                               $daterecord = sprintf( "%04i%02i%02i",
+                                       $yearrecord, $monthrecord, $dayrecord );
+                       }
+                       elsif ( $DatabaseBreak eq 'hour' ) {
+                               $daterecord = sprintf( "%04i%02i%02i%02i",
+                                       $yearrecord, $monthrecord, $dayrecord, $hourrecord );
+                       }
+
+                       # TODO essayer de virer yearmonthrecord
+                       $yearmonthdayrecord =
+                         sprintf( "$yearrecord%02i%02i", $dateparts[1], $dateparts[0] );
+                       $timerecord =
+                         ( ( int("$yearmonthdayrecord") * 100 + $dateparts[3] ) * 100 +
+                                 $dateparts[4] ) * 100 + $dateparts[5];
+               }
+               if ( $timerecord < 10000000000000 || $timerecord > $tomorrowtime ) {
+                       $NbOfLinesCorrupted++;
+                       if ($ShowCorrupted) {
                                print
-"<tr><td class=\"aws\"><a href=\"javascript:parent.window.close();\">$Message[118]</a></td></tr>\n";
+"Corrupted record (invalid date, timerecord=$timerecord): $line\n";
                        }
-                       print "</table>\n";
-                       print "\n";
+                       next;   # Should not happen, kept in case of parasite/corrupted line
                }
-       }
-
-       # Call to plugins' function AddHTMLMenuFooter
-       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuFooter'} } ) {
+               if ($NewLinePhase) {
 
-               #               my $function="AddHTMLMenuFooter_$pluginname()";
-               #               eval("$function");
-               my $function = "AddHTMLMenuFooter_$pluginname";
-               &$function();
-       }
+                       # TODO NOTSORTEDRECORDTOLERANCE does not work around midnight
+                       if ( $timerecord < ( $LastLine - $NOTSORTEDRECORDTOLERANCE ) ) {
 
-       # Exit if left frame
-       if ( $FrameName eq 'mainleft' ) {
-               &html_end(0);
-               exit 0;
-       }
+                               # Should not happen, kept in case of parasite/corrupted old line
+                               $NbOfLinesCorrupted++;
+                               if ($ShowCorrupted) {
+                                       print
+"Corrupted record (date $timerecord lower than $LastLine-$NOTSORTEDRECORDTOLERANCE): $line\n";
+                               }
+                               next;
+                       }
+               }
+               else {
+                       if ( $timerecord <= $LastLine ) {    # Already processed
+                               $NbOfOldLines++;
+                               next;
+                       }
 
-       # FirstTime LastTime
-       my $FirstTime = 0;
-       my $LastTime  = 0;
-       foreach my $key ( keys %FirstTime ) {
-               my $keyqualified = 0;
-               if ( $MonthRequired eq 'all' ) { $keyqualified = 1; }
-               if ( $key =~ /^$YearRequired$MonthRequired/ ) { $keyqualified = 1; }
-               if ($keyqualified) {
-                       if ( $FirstTime{$key}
-                               && ( $FirstTime == 0 || $FirstTime > $FirstTime{$key} ) )
-                       {
-                               $FirstTime = $FirstTime{$key};
+# We found a new line. This will replace comparison "<=" with "<" between timerecord and LastLine (we should have only new lines now)
+                       $NewLinePhase = 1;    # We will never enter here again
+                       if ($ShowSteps) {
+                               if ( $NbOfLinesShowsteps > 1
+                                       && ( $NbOfLinesShowsteps & $NBOFLINESFORBENCHMARK ) )
+                               {
+                                       my $delay = &GetDelaySinceStart(0);
+                                       print ""
+                                         . ( $NbOfLinesParsed - 1 )
+                                         . " lines processed ("
+                                         . ( $delay > 0 ? $delay : 1000 ) . " ms, "
+                                         . int( 1000 * ( $NbOfLinesShowsteps - 1 ) /
+                                                 ( $delay > 0 ? $delay : 1000 ) )
+                                         . " lines/second)\n";
+                               }
+                               &GetDelaySinceStart(1);
+                               $NbOfLinesShowsteps = 1;
                        }
-                       if ( $LastTime < ( $LastTime{$key} || 0 ) ) {
-                               $LastTime = $LastTime{$key};
+                       if ( !scalar keys %HTMLOutput ) {
+                               print
+"Phase 2 : Now process new records (Flush history on disk after "
+                                 . ( $LIMITFLUSH << 2 )
+                                 . " hosts)...\n";
+
+#print "Phase 2 : Now process new records (Flush history on disk after ".($LIMITFLUSH<<2)." hosts or ".($LIMITFLUSH)." URLs)...\n";
                        }
                }
-       }
-
-# TotalVisits TotalUnique TotalPages TotalHits TotalBytes TotalHostsKnown TotalHostsUnknown
-       $TotalUnique = $TotalVisits = $TotalPages = $TotalHits = $TotalBytes = 0;
-       $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
-       $TotalHostsKnown = $TotalHostsUnknown = 0;
-       my $beginmonth = $MonthRequired;
-       my $endmonth   = $MonthRequired;
-       if ( $MonthRequired eq 'all' ) { $beginmonth = 1; $endmonth = 12; }
-       for ( my $month = $beginmonth ; $month <= $endmonth ; $month++ ) {
-               my $monthix = sprintf( "%02s", $month );
-               $TotalHostsKnown += $MonthHostsKnown{ $YearRequired . $monthix }
-                 || 0;    # Wrong in year view
-               $TotalHostsUnknown += $MonthHostsUnknown{ $YearRequired . $monthix }
-                 || 0;    # Wrong in year view
-               $TotalUnique += $MonthUnique{ $YearRequired . $monthix }
-                 || 0;    # Wrong in year view
-               $TotalVisits += $MonthVisits{ $YearRequired . $monthix }
-                 || 0;    # Not completely true
-               $TotalPages += $MonthPages{ $YearRequired . $monthix } || 0;
-               $TotalHits  += $MonthHits{ $YearRequired . $monthix }  || 0;
-               $TotalBytes += $MonthBytes{ $YearRequired . $monthix } || 0;
-               $TotalNotViewedPages += $MonthNotViewedPages{ $YearRequired . $monthix }
-                 || 0;
-               $TotalNotViewedHits += $MonthNotViewedHits{ $YearRequired . $monthix }
-                 || 0;
-               $TotalNotViewedBytes += $MonthNotViewedBytes{ $YearRequired . $monthix }
-                 || 0;
-       }
 
-       # TotalHitsErrors TotalBytesErrors
-       my $TotalHitsErrors  = 0;
-       my $TotalBytesErrors = 0;
-       foreach ( keys %_errors_h ) {
+               # Convert URL for Webstar to common URL
+               if ( $LogFormat eq '3' ) {
+                       $field[$pos_url] =~ s/:/\//g;
+                       if ( $field[$pos_code] eq '-' ) { $field[$pos_code] = '200'; }
+               }
 
-               #               print "xxxx".$_." zzz".$_errors_h{$_};
-               $TotalHitsErrors  += $_errors_h{$_};
-               $TotalBytesErrors += $_errors_k{$_};
-       }
+# Here, field array, timerecord and yearmonthdayrecord are initialized for log record
+               if ($Debug) {
+                       debug( "  This is a not already processed record ($timerecord)",
+                               4 );
+               }
 
-# TotalEntries (if not already specifically counted, we init it from _url_e hash table)
-       if ( !$TotalEntries ) {
-               foreach ( keys %_url_e ) { $TotalEntries += $_url_e{$_}; }
-       }
+               # We found a new line
+               #----------------------------------------
+               if ( $timerecord > $LastLine ) {
+                       $LastLine = $timerecord;
+               }    # Test should always be true except with not sorted log files
 
-# TotalExits (if not already specifically counted, we init it from _url_x hash table)
-       if ( !$TotalExits ) {
-               foreach ( keys %_url_x ) { $TotalExits += $_url_x{$_}; }
-       }
+               # Skip for some client host IP addresses, some URLs, other URLs
+               if (
+                       @SkipHosts
+                       && ( &SkipHost( $field[$pos_host] )
+                               || ( $pos_hostr && &SkipHost( $field[$pos_hostr] ) ) )
+                 )
+               {
+                       $qualifdrop =
+                           "Dropped record (host $field[$pos_host]"
+                         . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
+                         . " not qualified by SkipHosts)";
+               }
+               elsif ( @SkipFiles && &SkipFile( $field[$pos_url] ) ) {
+                       $qualifdrop =
+"Dropped record (URL $field[$pos_url] not qualified by SkipFiles)";
+               }
+               elsif (@SkipUserAgents
+                       && $pos_agent >= 0
+                       && &SkipUserAgent( $field[$pos_agent] ) )
+               {
+                       $qualifdrop =
+"Dropped record (user agent '$field[$pos_agent]' not qualified by SkipUserAgents)";
+               }
+               elsif (@SkipReferrers
+                       && $pos_referer >= 0
+                       && &SkipReferrer( $field[$pos_referer] ) )
+               {
+                       $qualifdrop =
+"Dropped record (URL $field[$pos_referer] not qualified by SkipReferrers)";
+               }
+               elsif (@OnlyHosts
+                       && !&OnlyHost( $field[$pos_host] )
+                       && ( !$pos_hostr || !&OnlyHost( $field[$pos_hostr] ) ) )
+               {
+                       $qualifdrop =
+                           "Dropped record (host $field[$pos_host]"
+                         . ( $pos_hostr ? " and $field[$pos_hostr]" : "" )
+                         . " not qualified by OnlyHosts)";
+               }
+               elsif ( @OnlyUsers && !&OnlyUser( $field[$pos_logname] ) ) {
+                       $qualifdrop =
+"Dropped record (URL $field[$pos_logname] not qualified by OnlyUsers)";
+               }
+               elsif ( @OnlyFiles && !&OnlyFile( $field[$pos_url] ) ) {
+                       $qualifdrop =
+"Dropped record (URL $field[$pos_url] not qualified by OnlyFiles)";
+               }
+               elsif ( @OnlyUserAgents && !&OnlyUserAgent( $field[$pos_agent] ) ) {
+                       $qualifdrop =
+"Dropped record (user agent '$field[$pos_agent]' not qualified by OnlyUserAgents)";
+               }
+               if ($qualifdrop) {
+                       $NbOfLinesDropped++;
+                       if ($Debug) { debug( "$qualifdrop: $line", 4 ); }
+                       if ($ShowDropped) { print "$qualifdrop: $line\n"; }
+                       $qualifdrop = '';
+                       next;
+               }
 
-# TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
-       if ( !$TotalBytesPages ) {
-               foreach ( keys %_url_k ) { $TotalBytesPages += $_url_k{$_}; }
-       }
+               # Record is approved
+               #-------------------
 
-# TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
-       if ( !$TotalKeyphrases ) {
-               foreach ( keys %_keyphrases ) { $TotalKeyphrases += $_keyphrases{$_}; }
-       }
+               # Is it in a new break section ?
+               #-------------------------------
+               if ( $daterecord > $lastprocesseddate ) {
 
-# TotalKeywords (if not already specifically counted, we init it from _keywords hash table)
-       if ( !$TotalKeywords ) {
-               foreach ( keys %_keywords ) { $TotalKeywords += $_keywords{$_}; }
-       }
+                       # A new break to process
+                       if ( $lastprocesseddate > 0 ) {
 
-# TotalSearchEnginesPages (if not already specifically counted, we init it from _se_referrals_p hash table)
-       if ( !$TotalSearchEnginesPages ) {
-               foreach ( keys %_se_referrals_p ) {
-                       $TotalSearchEnginesPages += $_se_referrals_p{$_};
+                               # We save data of previous break
+                               &Read_History_With_TmpUpdate(
+                                       $lastprocessedyear, $lastprocessedmonth,
+                                       $lastprocessedday,  $lastprocessedhour,
+                                       1,                  1,
+                                       "all", ( $lastlinenb + $NbOfLinesParsed ),
+                                       $lastlineoffset, &CheckSum($line)
+                               );
+                               $counterforflushtest = 0;    # We reset counterforflushtest
+                       }
+                       $lastprocessedyear  = $yearrecord;
+                       $lastprocessedmonth = $monthrecord;
+                       $lastprocessedday   = $dayrecord;
+                       $lastprocessedhour  = $hourrecord;
+                       if ( $DatabaseBreak eq 'month' ) {
+                               $lastprocesseddate =
+                                 sprintf( "%04i%02i", $yearrecord, $monthrecord );
+                       }
+                       elsif ( $DatabaseBreak eq 'year' ) {
+                               $lastprocesseddate = sprintf( "%04i%", $yearrecord );
+                       }
+                       elsif ( $DatabaseBreak eq 'day' ) {
+                               $lastprocesseddate = sprintf( "%04i%02i%02i",
+                                       $yearrecord, $monthrecord, $dayrecord );
+                       }
+                       elsif ( $DatabaseBreak eq 'hour' ) {
+                               $lastprocesseddate = sprintf( "%04i%02i%02i%02i",
+                                       $yearrecord, $monthrecord, $dayrecord, $hourrecord );
+                       }
                }
-       }
 
-# TotalSearchEnginesHits (if not already specifically counted, we init it from _se_referrals_h hash table)
-       if ( !$TotalSearchEnginesHits ) {
-               foreach ( keys %_se_referrals_h ) {
-                       $TotalSearchEnginesHits += $_se_referrals_h{$_};
-               }
-       }
+               $countedtraffic = 0;
+               $NbOfNewLines++;
 
-# TotalRefererPages (if not already specifically counted, we init it from _pagesrefs_p hash table)
-       if ( !$TotalRefererPages ) {
-               foreach ( keys %_pagesrefs_p ) {
-                       $TotalRefererPages += $_pagesrefs_p{$_};
-               }
-       }
+               # Convert $field[$pos_size]
+               # if ($field[$pos_size] eq '-') { $field[$pos_size]=0; }
 
-# TotalRefererHits (if not already specifically counted, we init it from _pagesrefs_h hash table)
-       if ( !$TotalRefererHits ) {
-               foreach ( keys %_pagesrefs_h ) {
-                       $TotalRefererHits += $_pagesrefs_h{$_};
-               }
-       }
+       # Define a clean target URL and referrer URL
+       # We keep a clean $field[$pos_url] and
+       # we store original value for urlwithnoquery, tokenquery and standalonequery
+       #---------------------------------------------------------------------------
+               if ($URLNotCaseSensitive) { $field[$pos_url] = lc( $field[$pos_url] ); }
 
-# TotalDifferentPages (if not already specifically counted, we init it from _url_p hash table)
-       $TotalDifferentPages ||= scalar keys %_url_p;
+# Possible URL syntax for $field[$pos_url]: /mydir/mypage.ext?param1=x&param2=y#aaa, /mydir/mypage.ext#aaa, /
+               my $urlwithnoquery;
+               my $tokenquery;
+               my $standalonequery;
+               my $anchor = '';
+               if ( $field[$pos_url] =~ s/$regtruncanchor//o ) {
+                       $anchor = $1;
+               }    # Remove and save anchor
+               if ($URLWithQuery) {
+                       $urlwithnoquery = $field[$pos_url];
+                       my $foundparam = ( $urlwithnoquery =~ s/$regtruncurl//o );
+                       $tokenquery      = $1 || '';
+                       $standalonequery = $2 || '';
 
-# TotalDifferentKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
-       $TotalDifferentKeyphrases ||= scalar keys %_keyphrases;
+# For IIS setup, if pos_query is enabled we need to combine the URL to query strings
+                       if (   !$foundparam
+                               && $pos_query >= 0
+                               && $field[$pos_query]
+                               && $field[$pos_query] ne '-' )
+                       {
+                               $foundparam      = 1;
+                               $tokenquery      = '?';
+                               $standalonequery = $field[$pos_query];
 
-# TotalDifferentKeywords (if not already specifically counted, we init it from _keywords hash table)
-       $TotalDifferentKeywords ||= scalar keys %_keywords;
+                               # Define query
+                               $field[$pos_url] .= '?' . $field[$pos_query];
+                       }
+                       if ($foundparam) {
 
-# TotalDifferentSearchEngines (if not already specifically counted, we init it from _se_referrals_h hash table)
-       $TotalDifferentSearchEngines ||= scalar keys %_se_referrals_h;
+  # Keep only params that are defined in URLWithQueryWithOnlyFollowingParameters
+                               my $newstandalonequery = '';
+                               if (@URLWithQueryWithOnly) {
+                                       foreach (@URLWithQueryWithOnly) {
+                                               foreach my $p ( split( /&/, $standalonequery ) ) {
+                                                       if ($URLNotCaseSensitive) {
+                                                               if ( $p =~ /^$_=/i ) {
+                                                                       $newstandalonequery .= "$p&";
+                                                                       last;
+                                                               }
+                                                       }
+                                                       else {
+                                                               if ( $p =~ /^$_=/ ) {
+                                                                       $newstandalonequery .= "$p&";
+                                                                       last;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                                       chop $newstandalonequery;
+                               }
 
-# TotalDifferentReferer (if not already specifically counted, we init it from _pagesrefs_h hash table)
-       $TotalDifferentReferer ||= scalar keys %_pagesrefs_h;
+# Remove params that are marked to be ignored in URLWithQueryWithoutFollowingParameters
+                               elsif (@URLWithQueryWithout) {
+                                       foreach my $p ( split( /&/, $standalonequery ) ) {
+                                               my $found = 0;
+                                               foreach (@URLWithQueryWithout) {
 
-# Define firstdaytocountaverage, lastdaytocountaverage, firstdaytoshowtime, lastdaytoshowtime
-       my $firstdaytocountaverage =
-         $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
-       my $firstdaytoshowtime =
-         $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
-       my $lastdaytocountaverage =
-         $nowyear . $nowmonth . $nowday;    # Set day cursor to today
-       my $lastdaytoshowtime =
-         $nowyear . $nowmonth . "31";       # Set day cursor to last day of month
-       if ( $MonthRequired eq 'all' ) {
-               $firstdaytocountaverage =
-                 $YearRequired
-                 . "0101";    # Set day cursor to 1st day of the required year
-       }
-       if ( ( $MonthRequired ne $nowmonth && $MonthRequired ne 'all' )
-               || $YearRequired ne $nowyear )
-       {
-               if ( $MonthRequired eq 'all' ) {
-                       $firstdaytocountaverage =
-                         $YearRequired
-                         . "0101";    # Set day cursor to 1st day of the required year
-                       $firstdaytoshowtime =
-                         $YearRequired . "1201"
-                         ;    # Set day cursor to 1st day of last month of required year
-                       $lastdaytocountaverage =
-                         $YearRequired
-                         . "1231";    # Set day cursor to last day of the required year
-                       $lastdaytoshowtime =
-                         $YearRequired . "1231"
-                         ;    # Set day cursor to last day of last month of required year
+#if ($Debug) { debug("  Check if '$_=' is param '$p' to remove it from query",5); }
+                                                       if ($URLNotCaseSensitive) {
+                                                               if ( $p =~ /^$_=/i ) { $found = 1; last; }
+                                                       }
+                                                       else {
+                                                               if ( $p =~ /^$_=/ ) { $found = 1; last; }
+                                                       }
+                                               }
+                                               if ( !$found ) { $newstandalonequery .= "$p&"; }
+                                       }
+                                       chop $newstandalonequery;
+                               }
+                               else { $newstandalonequery = $standalonequery; }
+
+                               # Define query
+                               $field[$pos_url] = $urlwithnoquery;
+                               if ($newstandalonequery) {
+                                       $field[$pos_url] .= "$tokenquery$newstandalonequery";
+                               }
+                       }
                }
                else {
-                       $firstdaytocountaverage =
-                           $YearRequired
-                         . $MonthRequired
-                         . "01";    # Set day cursor to 1st day of the required month
-                       $firstdaytoshowtime =
-                           $YearRequired
-                         . $MonthRequired
-                         . "01";    # Set day cursor to 1st day of the required month
-                       $lastdaytocountaverage =
-                           $YearRequired
-                         . $MonthRequired
-                         . "31";    # Set day cursor to last day of the required month
-                       $lastdaytoshowtime =
-                           $YearRequired
-                         . $MonthRequired
-                         . "31";    # Set day cursor to last day of the required month
-               }
-       }
-       if ($Debug) {
-               debug(
-"firstdaytocountaverage=$firstdaytocountaverage, lastdaytocountaverage=$lastdaytocountaverage",
-                       1
-               );
-               debug(
-"firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",
-                       1
-               );
-       }
 
-       # Call to plugins' function AddHTMLContentHeader
-       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLContentHeader'} } )
-       {
+                       # Trunc parameters of URL
+                       $field[$pos_url] =~ s/$regtruncurl//o;
+                       $urlwithnoquery  = $field[$pos_url];
+                       $tokenquery      = $1 || '';
+                       $standalonequery = $2 || '';
 
-               #               my $function="AddHTMLContentHeader_$pluginname()";
-               #               eval("$function");
-               # to add unique visitors & number of visits, by J Ruano @ CAPSiDE
-               if ( $ShowDomainsStats =~ /U/i ) {
-                       print "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
-               }
-               if ( $ShowDomainsStats =~ /V/i ) {
-                       print "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
+       # For IIS setup, if pos_query is enabled we need to use it for query strings
+                       if (   $pos_query >= 0
+                               && $field[$pos_query]
+                               && $field[$pos_query] ne '-' )
+                       {
+                               $tokenquery      = '?';
+                               $standalonequery = $field[$pos_query];
+                       }
                }
+               if ( $URLWithAnchor && $anchor ) {
+                       $field[$pos_url] .= "#$anchor";
+               }   # Restore anchor
+                   # Here now urlwithnoquery is /mydir/mypage.ext, /mydir, /, /page#XXX
+                   # Here now tokenquery is '' or '?' or ';'
+                   # Here now standalonequery is '' or 'param1=x'
 
-               my $function = "AddHTMLContentHeader_$pluginname";
-               &$function();
-       }
+               # Define page and extension
+               #--------------------------
+               my $PageBool = 1;
 
-       # Output particular part
-       #-----------------------
-       if ( scalar keys %HTMLOutput == 1 ) {
+               # Extension
+               my $extension;
+               if ( $urlwithnoquery =~ /$regext/o
+                       || ( $urlwithnoquery =~ /[\\\/]$/ && $DefaultFile[0] =~ /$regext/o )
+                 )
+               {
+                       $extension =
+                         ( $LevelForFileTypesDetection >= 2 || $MimeHashFamily{$1} )
+                         ? lc($1)
+                         : 'Unknown';
+                       if ( $NotPageList{$extension} ) { $PageBool = 0; }
+               }
+               else {
+                       $extension = 'Unknown';
+               }
 
-               if ( $HTMLOutput{'alldomains'} ) {
-                       print "$Center<a name=\"domains\">&nbsp;</a><br />\n";
+               if ( @NotPageFiles && &NotPageFile( $field[$pos_url] ) ) {
+                       $PageBool = 0;
+               }
 
-                       # Show domains list
-                       my $title = '';
-                       my $cpt   = 0;
-                       if ( $HTMLOutput{'alldomains'} ) {
-                               $title .= "$Message[25]";
-                               $cpt = ( scalar keys %_domener_h );
-                       }
-                       &tab_head( "$title", 19, 0, 'domains' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
-                       if ( $ShowDomainsStats =~ /U/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /V/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       print "<th>&nbsp;</th>";
-                       print "</tr>\n";
-                       $total_u = $total_v = $total_p = $total_h = $total_k = 0;
-                       $max_h = 1;
-                       foreach ( values %_domener_h ) {
-                               if ( $_ > $max_h ) { $max_h = $_; }
-                       }
-                       $max_k = 1;
-                       foreach ( values %_domener_k ) {
-                               if ( $_ > $max_k ) { $max_k = $_; }
+               # Analyze: misc tracker (must be before return code)
+               #---------------------------------------------------
+               if ( $urlwithnoquery =~ /$regmisc/o ) {
+                       if ($Debug) {
+                               debug(
+"  Found an URL that is a MiscTracker record with standalonequery=$standalonequery",
+                                       2
+                               );
                        }
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_domener_h,
-                               \%_domener_p );
-                       foreach my $key (@keylist) {
-                               my ( $_domener_u, $_domener_v );
-                               my $bredde_p = 0;
-                               my $bredde_h = 0;
-                               my $bredde_k = 0;
-                               if ( $max_h > 0 ) {
-                                       $bredde_p =
-                                         int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
-                               }    # use max_h to enable to compare pages with hits
-                               if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
-                               if ( $max_h > 0 ) {
-                                       $bredde_h =
-                                         int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
-                               }
-                               if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k =
-                                         int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
-                                         1;
-                               }
-                               if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
-                               my $newkey = lc($key);
-                               if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
-                                       print
-"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
-                                         . AltTitle("$Message[0]")
-                                         . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
-                               }
-                               else {
-                                       print
-"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
-                                         . AltTitle("$newkey")
-                                         . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
-                               }
-                               ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
-                               if ( $ShowDomainsStats =~ /U/i ) {
-                                       $_domener_u = (
-                                                 $_domener_p{$key}
-                                               ? $_domener_p{$key} / $TotalPages
-                                               : 0
-                                       );
-                                       $_domener_u += ( $_domener_h{$key} / $TotalHits );
-                                       $_domener_u =
-                                         sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
-                                       print "<td>".Format_Number($_domener_u)." ("
-                                         . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
-                                         . ")</td>";
-                               }
-                               if ( $ShowDomainsStats =~ /V/i ) {
-                                       $_domener_v = (
-                                                 $_domener_p{$key}
-                                               ? $_domener_p{$key} / $TotalPages
-                                               : 0
-                                       );
-                                       $_domener_v += ( $_domener_h{$key} / $TotalHits );
-                                       $_domener_v =
-                                         sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
-                                       print "<td>".Format_Number($_domener_v)." ("
-                                         . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
-                                         . ")</td>";
+                       my $foundparam = 0;
+                       foreach ( split( /&/, $standalonequery ) ) {
+                               if ( $_ =~ /^screen=(\d+)x(\d+)/i ) {
+                                       $foundparam++;
+                                       $_screensize_h{"$1x$2"}++;
+                                       next;
                                }
-                               if ( $ShowDomainsStats =~ /P/i ) {
-                                       print "<td>".Format_Number($_domener_p{$key})."</td>";
+
+   #if ($_ =~ /cdi=(\d+)/i)                    { $foundparam++; $_screendepth_h{"$1"}++; next; }
+                               if ( $_ =~ /^nojs=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"JavascriptDisabled"}++; }
+                                       next;
                                }
-                               if ( $ShowDomainsStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_domener_h{$key})."</td>";
+                               if ( $_ =~ /^java=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'true' ) { $_misc_h{"JavaEnabled"}++; }
+                                       next;
                                }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
+                               if ( $_ =~ /^shk=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"DirectorSupport"}++; }
+                                       next;
                                }
-                               print "<td class=\"aws\">";
-                               if ( $ShowDomainsStats =~ /P/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
-                                         . AltTitle( "$Message[56]: " . int( $_domener_p{$key} ) )
-                                         . " /><br />\n";
+                               if ( $_ =~ /^fla=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"FlashSupport"}++; }
+                                       next;
                                }
-                               if ( $ShowDomainsStats =~ /H/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
-                                         . AltTitle( "$Message[57]: " . int( $_domener_h{$key} ) )
-                                         . " /><br />\n";
+                               if ( $_ =~ /^rp=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"RealPlayerSupport"}++; }
+                                       next;
                                }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
-                                         . AltTitle(
-                                               "$Message[75]: " . Format_Bytes( $_domener_k{$key} ) )
-                                         . " />";
+                               if ( $_ =~ /^mov=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"QuickTimeSupport"}++; }
+                                       next;
                                }
-                               print "</td>";
-                               print "</tr>\n";
-                               $total_u += $_domener_u;
-                               $total_v += $_domener_v;
-                               $total_p += $_domener_p{$key};
-                               $total_h += $_domener_h{$key};
-                               $total_k += $_domener_k{$key} || 0;
-                               $count++;
-                       }
-                       my $rest_u = $TotalUnique - $total_u;
-                       my $rest_v = $TotalVisits - $total_v;
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if (   $rest_u > 0
-                               || $rest_v > 0
-                               || $rest_p > 0
-                               || $rest_h > 0
-                               || $rest_k > 0 )
-                       {    # All other domains (known or not)
-                               print
-"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
-                               if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
-                               if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
-                               if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
-                               }
-                               print "<td class=\"aws\">&nbsp;</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
-                       print "$Center<a name=\"hosts\">&nbsp;</a><br />\n";
-
-                       # Show filter form
-                       &ShowFormFilter( "hostfilter", $FilterIn{'host'},
-                               $FilterEx{'host'} );
-
-                       # Show hosts list
-                       my $title = '';
-                       my $cpt   = 0;
-                       if ( $HTMLOutput{'allhosts'} ) {
-                               $title .= "$Message[81]";
-                               $cpt = ( scalar keys %_host_h );
-                       }
-                       if ( $HTMLOutput{'lasthosts'} ) {
-                               $title .= "$Message[9]";
-                               $cpt = ( scalar keys %_host_h );
-                       }
-                       &tab_head( "$title", 19, 0, 'hosts' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
-                       if ( $FilterIn{'host'} || $FilterEx{'host'} ) {    # With filter
-                               if ( $FilterIn{'host'} ) {
-                                       print "$Message[79] '<b>$FilterIn{'host'}</b>'";
-                               }
-                               if ( $FilterIn{'host'} && $FilterEx{'host'} ) { print " - "; }
-                               if ( $FilterEx{'host'} ) {
-                                       print " Exlude $Message[79] '<b>$FilterEx{'host'}</b>'";
-                               }
-                               if ( $FilterIn{'host'} || $FilterEx{'host'} ) { print ": "; }
-                               print "$cpt $Message[81]";
-                               if ( $MonthRequired ne 'all' ) {
-                                       if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
-                                               print
-"<br />$Message[102]: ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
+                               if ( $_ =~ /^wma=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) {
+                                               $_misc_h{"WindowsMediaPlayerSupport"}++;
                                        }
+                                       next;
                                }
-                       }
-                       else {    # Without filter
-                               if ( $MonthRequired ne 'all' ) {
-                                       print
-"$Message[102] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1] - ".Format_Number($TotalUnique)." $Message[11]";
-                               }
-                               else { print "$Message[102] : " . Format_Number(( scalar keys %_host_h )); }
-                       }
-                       print "</th>";
-                       &ShowHostInfo('__title__');
-                       if ( $ShowHostsStats =~ /P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       my $count = 0;
-                       if ( $HTMLOutput{'allhosts'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
-                                       \%_host_p );
-                       }
-                       if ( $HTMLOutput{'lasthosts'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
-                                       \%_host_l );
-                       }
-                       foreach my $key (@keylist) {
-                               my $host = CleanXSS($key);
-                               print "<tr><td class=\"aws\">"
-                                 . ( $_robot_l{$key} ? '<b>'  : '' ) . "$host"
-                                 . ( $_robot_l{$key} ? '</b>' : '' ) . "</td>";
-                               &ShowHostInfo($key);
-                               if ( $ShowHostsStats =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
-                                         . "</td>";
-                               }
-                               if ( $ShowHostsStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_host_h{$key})."</td>";
-                               }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
-                               }
-                               if ( $ShowHostsStats =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_host_l{$key}
-                                               ? Format_Date( $_host_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
-                               }
-                               print "</tr>\n";
-                               $total_p += $_host_p{$key};
-                               $total_h += $_host_h{$key};
-                               $total_k += $_host_k{$key} || 0;
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
-                                       2
-                               );
-                       }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
-                       {    # All other visitors (known or not)
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               &ShowHostInfo('');
-                               if ( $ShowHostsStats =~ /P/i ) {
-                                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+                               if ( $_ =~ /^pdf=(\w+)/i ) {
+                                       $foundparam++;
+                                       if ( $1 eq 'y' ) { $_misc_h{"PDFSupport"}++; }
+                                       next;
                                }
-                               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
                        }
-                       &tab_end();
-                       &html_end(1);
+                       if ($foundparam) { $_misc_h{"TotalMisc"}++; }
                }
-               if ( $HTMLOutput{'unknownip'} ) {
-                       print "$Center<a name=\"unknownip\">&nbsp;</a><br />\n";
-                       &tab_head( "$Message[45]", 19, 0, 'unknownwip' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
-                         . Format_Number(( scalar keys %_host_h ))
-                         . " $Message[1]</th>";
-                       &ShowHostInfo('__title__');
-                       if ( $ShowHostsStats =~ /P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
+
+               # Analyze: successful favicon (=> countedtraffic=1 if favicon)
+               #--------------------------------------------------
+               if ( $urlwithnoquery =~ /$regfavico/o ) {
+                       if ( $field[$pos_code] != 404 ) {
+                               $_misc_h{'AddToFavourites'}++;
                        }
-                       if ( $ShowHostsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
+                       $countedtraffic =
+                         1;    # favicon is a case that must not be counted anywhere else
+                       $_time_nv_h[$hourrecord]++;
+                       if ( $field[$pos_code] != 404 ) {
+                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
                        }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'}, \%_host_h,
-                               \%_host_p );
-                       foreach my $key (@keylist) {
-                               my $host = CleanXSS($key);
-                               print "<tr><td class=\"aws\">$host</td>";
-                               &ShowHostInfo($key);
-                               if ( $ShowHostsStats =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_host_p{$key} ? Format_Number($_host_p{$key}) : "&nbsp;" )
-                                         . "</td>";
+               }
+
+               # Analyze: Worms (=> countedtraffic=2 if worm)
+               #---------------------------------------------
+               if ( !$countedtraffic ) {
+                       if ($LevelForWormsDetection) {
+                               foreach (@WormsSearchIDOrder) {
+                                       if ( $field[$pos_url] =~ /$_/ ) {
+
+                                               # It's a worm
+                                               my $worm = &UnCompileRegex($_);
+                                               if ($Debug) {
+                                                       debug(
+" Record is a hit from a worm identified by '$worm'",
+                                                               2
+                                                       );
+                                               }
+                                               $worm = $WormsHashID{$worm} || 'unknown';
+                                               $_worm_h{$worm}++;
+                                               $_worm_k{$worm} += int( $field[$pos_size] );
+                                               $_worm_l{$worm} = $timerecord;
+                                               $countedtraffic = 2;
+                                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                                               $_time_nv_h[$hourrecord]++;
+                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
+                                               last;
+                                       }
                                }
-                               if ( $ShowHostsStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_host_h{$key})."</td>";
+                       }
+               }
+
+               # Analyze: Status code (=> countedtraffic=3 if error)
+               #----------------------------------------------------
+               if ( !$countedtraffic ) {
+                       if ( $LogType eq 'W' || $LogType eq 'S' )
+                       {    # HTTP record or Stream record
+                               if ( $ValidHTTPCodes{ $field[$pos_code] } ) {    # Code is valid
+                                       if ( $field[$pos_code] == 304 ) { $field[$pos_size] = 0; }
                                }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_host_k{$key} ) . "</td>";
+                               else {    # Code is not valid
+                                       if ( $field[$pos_code] !~ /^\d\d\d$/ ) {
+                                               $field[$pos_code] = 999;
+                                       }
+                                       $_errors_h{ $field[$pos_code] }++;
+                                       $_errors_k{ $field[$pos_code] } += int( $field[$pos_size] );
+                                       foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
+                                               if ( $field[$pos_code] == $code ) {
+
+                                          # This is an error code which referrer need to be tracked
+                                                       my $newurl =
+                                                         substr( $field[$pos_url], 0,
+                                                               $MaxLengthOfStoredURL );
+                                                       $newurl =~ s/[$URLQuerySeparators].*$//;
+                                                       $_sider404_h{$newurl}++;
+                                                       if ( $pos_referer >= 0 ) {
+                                                               my $newreferer = $field[$pos_referer];
+                                                               if ( !$URLReferrerWithQuery ) {
+                                                                       $newreferer =~ s/[$URLQuerySeparators].*$//;
+                                                               }
+                                                               $_referer404_h{$newurl} = $newreferer;
+                                                               last;
+                                                       }
+                                               }
+                                       }
+                                       if ($Debug) {
+                                               debug(
+" Record stored in the status code chart (status code=$field[$pos_code])",
+                                                       3
+                                               );
+                                       }
+                                       $countedtraffic = 3;
+                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                                       $_time_nv_h[$hourrecord]++;
+                                       $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
                                }
-                               if ( $ShowHostsStats =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_host_l{$key}
-                                               ? Format_Date( $_host_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
+                       }
+                       elsif ( $LogType eq 'M' ) {    # Mail record
+                               if ( !$ValidSMTPCodes{ $field[$pos_code] } )
+                               {                          # Code is not valid
+                                       $_errors_h{ $field[$pos_code] }++;
+                                       if ( $field[$pos_size] ne '-' ) {
+                                               $_errors_k{ $field[$pos_code] } +=
+                                                 int( $field[$pos_size] );
+                                       }
+                                       if ($Debug) {
+                                               debug(
+" Record stored in the status code chart (status code=$field[$pos_code])",
+                                                       3
+                                               );
+                                       }
+                                       $countedtraffic = 3;
+                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                                       $_time_nv_h[$hourrecord]++;
+                                       if ( $field[$pos_size] ne '-' ) {
+                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
+                                       }
                                }
-                               print "</tr>\n";
-                               $total_p += $_host_p{$key};
-                               $total_h += $_host_h{$key};
-                               $total_k += $_host_k{$key} || 0;
-                               $count++;
                        }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
-                                       2
-                               );
+                       elsif ( $LogType eq 'F' ) {    # FTP record
                        }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
-                       {    # All other visitors (known or not)
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[82]</span></td>";
-                               &ShowHostInfo('');
-                               if ( $ShowHostsStats =~ /P/i ) {
-                                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+               }
+
+               # Analyze: Robot from robot database (=> countedtraffic=4 if robot)
+               #------------------------------------------------------------------
+               if ( !$countedtraffic ) {
+                       if ( $pos_agent >= 0 ) {
+                               if ($DecodeUA) {
+                                       $field[$pos_agent] =~ s/%20/_/g;
+                               } # This is to support servers (like Roxen) that writes user agent with %20 in it
+                               $UserAgent = $field[$pos_agent];
+                               if ( $UserAgent && $UserAgent eq '-' ) { $UserAgent = ''; }
+
+                               if ($LevelForRobotsDetection) {
+
+                                       if ($UserAgent) {
+                                               my $uarobot = $TmpRobot{$UserAgent};
+                                               if ( !$uarobot ) {
+
+                                                       #study $UserAgent;              Does not increase speed
+                                                       foreach (@RobotsSearchIDOrder) {
+                                                               if ( $UserAgent =~ /$_/ ) {
+                                                                       my $bot = &UnCompileRegex($_);
+                                                                       $TmpRobot{$UserAgent} = $uarobot = "$bot"
+                                                                         ; # Last time, we won't search if robot or not. We know it is.
+                                                                       if ($Debug) {
+                                                                               debug(
+"  UserAgent '$UserAgent' is added to TmpRobot with value '$bot'",
+                                                                                       2
+                                                                               );
+                                                                       }
+                                                                       last;
+                                                               }
+                                                       }
+                                                       if ( !$uarobot )
+                                                       { # Last time, we won't search if robot or not. We know it's not.
+                                                               $TmpRobot{$UserAgent} = $uarobot = '-';
+                                                       }
+                                               }
+                                               if ( $uarobot ne '-' ) {
+
+                                                       # If robot, we stop here
+                                                       if ($Debug) {
+                                                               debug(
+"  UserAgent '$UserAgent' contains robot ID '$uarobot'",
+                                                                       2
+                                                               );
+                                                       }
+                                                       $_robot_h{$uarobot}++;
+                                                       if ( $field[$pos_size] ne '-' ) {
+                                                               $_robot_k{$uarobot} += int( $field[$pos_size] );
+                                                       }
+                                                       $_robot_l{$uarobot} = $timerecord;
+                                                       if ( $urlwithnoquery =~ /$regrobot/o ) {
+                                                               $_robot_r{$uarobot}++;
+                                                       }
+                                                       $countedtraffic = 4;
+                                                       if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                                                       $_time_nv_h[$hourrecord]++;
+                                                       if ( $field[$pos_size] ne '-' ) {
+                                                               $_time_nv_k[$hourrecord] +=
+                                                                 int( $field[$pos_size] );
+                                                       }
+                                               }
+                                       }
+                                       else {
+                                               my $uarobot = 'no_user_agent';
+
+                                               # It's a robot or at least a bad browser, we stop here
+                                               if ($Debug) {
+                                                       debug(
+"  UserAgent not defined so it should be a robot, saved as robot 'no_user_agent'",
+                                                               2
+                                                       );
+                                               }
+                                               $_robot_h{$uarobot}++;
+                                               $_robot_k{$uarobot} += int( $field[$pos_size] );
+                                               $_robot_l{$uarobot} = $timerecord;
+                                               if ( $urlwithnoquery =~ /$regrobot/o ) {
+                                                       $_robot_r{$uarobot}++;
+                                               }
+                                               $countedtraffic = 4;
+                                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                                               $_time_nv_h[$hourrecord]++;
+                                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
+                                       }
                                }
-                               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
                        }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
-                       &ShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
-                       &ShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
-                       &html_end(1);
                }
-               if ( $HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'} ) {
-                       print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
-                       my $title = '';
-                       if ( $HTMLOutput{'alllogins'} )  { $title .= "$Message[94]"; }
-                       if ( $HTMLOutput{'lastlogins'} ) { $title .= "$Message[9]"; }
-                       &tab_head( "$title", 19, 0, 'logins' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
-                         . Format_Number(( scalar keys %_login_h )) . "</th>";
-                       &ShowUserInfo('__title__');
-                       if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       my $count = 0;
-                       if ( $HTMLOutput{'alllogins'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
-                                       \%_login_h, \%_login_p );
-                       }
-                       if ( $HTMLOutput{'lastlogins'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Host'},
-                                       \%_login_h, \%_login_l );
+
+   # Analyze: Robot from "hit on robots.txt" file (=> countedtraffic=5 if robot)
+   # -------------------------------------------------------------------------
+               if ( !$countedtraffic ) {
+                       if ( $urlwithnoquery =~ /$regrobot/o ) {
+                               if ($Debug) { debug( "  It's an unknown robot", 2 ); }
+                               $_robot_h{'unknown'}++;
+                               $_robot_k{'unknown'} += int( $field[$pos_size] );
+                               $_robot_l{'unknown'} = $timerecord;
+                               $_robot_r{'unknown'}++;
+                               $countedtraffic = 5;    # Must not be counted somewhere else
+                               if ($PageBool) { $_time_nv_p[$hourrecord]++; }
+                               $_time_nv_h[$hourrecord]++;
+                               $_time_nv_k[$hourrecord] += int( $field[$pos_size] );
                        }
-                       foreach my $key (@keylist) {
-                               print "<tr><td class=\"aws\">$key</td>";
-                               &ShowUserInfo($key);
-                               if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
-                                         . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                                       print "<td>".Format_Number($_login_h{$key})."</td>";
+               }
+
+               # Analyze: File type - Compression
+               #---------------------------------
+               if ( !$countedtraffic ) {
+                       if ($LevelForFileTypesDetection) {
+                               $_filetypes_h{$extension}++;
+                               if ( $field[$pos_size] ne '-' ) {
+                                       $_filetypes_k{$extension} += int( $field[$pos_size] );
                                }
-                               if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
+
+                               # Compression
+                               if ( $pos_gzipin >= 0 && $field[$pos_gzipin] )
+                               {    # If in and out in log
+                                       my ( $notused, $in ) = split( /:/, $field[$pos_gzipin] );
+                                       my ( $notused1, $out, $notused2 ) =
+                                         split( /:/, $field[$pos_gzipout] );
+                                       if ($out) {
+                                               $_filetypes_gz_in{$extension}  += $in;
+                                               $_filetypes_gz_out{$extension} += $out;
+                                       }
                                }
-                               if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_login_l{$key}
-                                               ? Format_Date( $_login_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
+                               elsif ( $pos_compratio >= 0
+                                       && ( $field[$pos_compratio] =~ /(\d+)/ ) )
+                               {    # Calculate in/out size from percentage
+                                       if ( $fieldlib[$pos_compratio] eq 'gzipratio' ) {
+
+       # with mod_gzip:    % is size (before-after)/before (low for jpg) ??????????
+                                               $_filetypes_gz_in{$extension} +=
+                                                 int(
+                                                       $field[$pos_size] * 100 / ( ( 100 - $1 ) || 1 ) );
+                                       }
+                                       else {
+
+                                          # with mod_deflate: % is size after/before (high for jpg)
+                                               $_filetypes_gz_in{$extension} +=
+                                                 int( $field[$pos_size] * 100 / ( $1 || 1 ) );
+                                       }
+                                       $_filetypes_gz_out{$extension} += int( $field[$pos_size] );
                                }
-                               print "</tr>\n";
-                               $total_p += $_login_p{$key} || 0;
-                               $total_h += $_login_h{$key};
-                               $total_k += $_login_k{$key} || 0;
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalPages / $total_p - $TotalHits / $total_h - $TotalBytes / $total_h",
-                                       2
-                               );
                        }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
-                       {    # All other logins and/or anonymous
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[125]</span></td>";
-                               &ShowUserInfo('');
-                               if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                                       print "<td>".Format_Number($rest_h)."</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
+
+                       # Analyze: Date - Hour - Pages - Hits - Kilo
+                       #-------------------------------------------
+                       if ($PageBool) {
+
+# Replace default page name with / only ('if' is to increase speed when only 1 value in @DefaultFile)
+                               if ( @DefaultFile > 1 ) {
+                                       foreach my $elem (@DefaultFile) {
+                                               if ( $field[$pos_url] =~ s/\/$elem$/\// ) { last; }
+                                       }
                                }
-                               if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                                       print "<td>&nbsp;</td>";
+                               else { $field[$pos_url] =~ s/$regdefault/\//o; }
+
+# FirstTime and LastTime are First and Last human visits (so changed if access to a page)
+                               $FirstTime{$lastprocesseddate} ||= $timerecord;
+                               $LastTime{$lastprocesseddate} = $timerecord;
+                               $DayPages{$yearmonthdayrecord}++;
+                               $_url_p{ $field[$pos_url] }++;   #Count accesses for page (page)
+                               if ( $field[$pos_size] ne '-' ) {
+                                       $_url_k{ $field[$pos_url] } += int( $field[$pos_size] );
                                }
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'} ) {
-                       print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
-                       my $title = '';
-                       if ( $HTMLOutput{'allrobots'} )  { $title .= "$Message[53]"; }
-                       if ( $HTMLOutput{'lastrobots'} ) { $title .= "$Message[9]"; }
-                       &tab_head( "$title", 19, 0, 'robots' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>"
-                         . Format_Number(( scalar keys %_robot_h ))
-                         . " $Message[51]</th>";
-                       if ( $ShowRobotsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowRobotsStats =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ShowRobotsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
+                               $_time_p[$hourrecord]++;    #Count accesses for hour (page)
+                                                           # TODO Use an id for hash key of url
+                                                           # $_url_t{$_url_id}
                        }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = $total_r = 0;
-                       my $count = 0;
-                       if ( $HTMLOutput{'allrobots'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
-                                       \%_robot_h, \%_robot_h );
+                       $_time_h[$hourrecord]++;
+                       $DayHits{$yearmonthdayrecord}++;    #Count accesses for hour (hit)
+                       if ( $field[$pos_size] ne '-' ) {
+                               $_time_k[$hourrecord]          += int( $field[$pos_size] );
+                               $DayBytes{$yearmonthdayrecord} +=
+                                 int( $field[$pos_size] );     #Count accesses for hour (kb)
                        }
-                       if ( $HTMLOutput{'lastrobots'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Robot'},
-                                       \%_robot_h, \%_robot_l );
+
+                       # Analyze: Login
+                       #---------------
+                       if (   $pos_logname >= 0
+                               && $field[$pos_logname]
+                               && $field[$pos_logname] ne '-' )
+                       {
+                               $field[$pos_logname] =~
+                                 s/ /_/g;    # This is to allow space in logname
+                               if ( $LogFormat eq '6' ) {
+                                       $field[$pos_logname] =~ s/^\"//;
+                                       $field[$pos_logname] =~ s/\"$//;
+                               }             # logname field has " with Domino 6+
+                               if ($AuthenticatedUsersNotCaseSensitive) {
+                                       $field[$pos_logname] = lc( $field[$pos_logname] );
+                               }
+
+                               # We found an authenticated user
+                               if ($PageBool) {
+                                       $_login_p{ $field[$pos_logname] }++;
+                               }             #Count accesses for page (page)
+                               $_login_h{ $field[$pos_logname] }
+                                 ++;         #Count accesses for page (hit)
+                               $_login_k{ $field[$pos_logname] } +=
+                                 int( $field[$pos_size] );    #Count accesses for page (kb)
+                               $_login_l{ $field[$pos_logname] } = $timerecord;
                        }
-                       foreach my $key (@keylist) {
-                               print "<tr><td class=\"aws\">"
-                                 . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
-                                 . "</td>";
-                               if ( $ShowRobotsStats =~ /H/i ) {
-                                       print "<td>"
-                                         . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
-                                         . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
+               }
+
+               # Do DNS lookup
+               #--------------
+               my $Host         = $field[$pos_host];
+               my $HostResolved = ''
+                 ; # HostResolved will be defined in next paragraf if countedtraffic is true
+
+               if ( !$countedtraffic ) {
+                       my $ip = 0;
+                       if ($DNSLookup) {    # DNS lookup is 1 or 2
+                               if ( $Host =~ /$regipv4l/o ) {    # IPv4 lighttpd
+                                       $Host =~ s/^::ffff://;
+                                       $ip = 4;
+                               }
+                               elsif ( $Host =~ /$regipv4/o ) { $ip = 4; }    # IPv4
+                               elsif ( $Host =~ /$regipv6/o ) { $ip = 6; }    # IPv6
+                               if ($ip) {
+
+                                       # Check in static DNS cache file
+                                       $HostResolved = $MyDNSTable{$Host};
+                                       if ($HostResolved) {
+                                               if ($Debug) {
+                                                       debug(
+"  DNS lookup asked for $Host and found in static DNS cache file: $HostResolved",
+                                                               4
+                                                       );
+                                               }
+                                       }
+                                       elsif ( $DNSLookup == 1 ) {
+
+                  # Check in session cache (dynamic DNS cache file + session DNS cache)
+                                               $HostResolved = $TmpDNSLookup{$Host};
+                                               if ( !$HostResolved ) {
+                                                       if ( @SkipDNSLookupFor && &SkipDNSLookup($Host) ) {
+                                                               $HostResolved = $TmpDNSLookup{$Host} = '*';
+                                                               if ($Debug) {
+                                                                       debug(
+"  No need of reverse DNS lookup for $Host, skipped at user request.",
+                                                                               4
+                                                                       );
+                                                               }
+                                                       }
+                                                       else {
+                                                               if ( $ip == 4 ) {
+                                                                       my $lookupresult =
+                                                                         gethostbyaddr(
+                                                                               pack( "C4", split( /\./, $Host ) ),
+                                                                               AF_INET )
+                                                                         ; # This is very slow, may spend 20 seconds
+                                                                       if (   !$lookupresult
+                                                                               || $lookupresult =~ /$regipv4/o
+                                                                               || !IsAscii($lookupresult) )
+                                                                       {
+                                                                               $TmpDNSLookup{$Host} = $HostResolved =
+                                                                                 '*';
+                                                                       }
+                                                                       else {
+                                                                               $TmpDNSLookup{$Host} = $HostResolved =
+                                                                                 $lookupresult;
+                                                                       }
+                                                                       if ($Debug) {
+                                                                               debug(
+"  Reverse DNS lookup for $Host done: $HostResolved",
+                                                                                       4
+                                                                               );
+                                                                       }
+                                                               }
+                                                               elsif ( $ip == 6 ) {
+                                                                       if ( $PluginsLoaded{'GetResolvedIP'}
+                                                                               {'ipv6'} )
+                                                                       {
+                                                                               my $lookupresult =
+                                                                                 GetResolvedIP_ipv6($Host);
+                                                                               if (   !$lookupresult
+                                                                                       || !IsAscii($lookupresult) )
+                                                                               {
+                                                                                       $TmpDNSLookup{$Host} =
+                                                                                         $HostResolved = '*';
+                                                                               }
+                                                                               else {
+                                                                                       $TmpDNSLookup{$Host} =
+                                                                                         $HostResolved = $lookupresult;
+                                                                               }
+                                                                       }
+                                                                       else {
+                                                                               $TmpDNSLookup{$Host} = $HostResolved =
+                                                                                 '*';
+                                                                               warning(
+"Reverse DNS lookup for $Host not available without ipv6 plugin enabled."
+                                                                               );
+                                                                       }
+                                                               }
+                                                               else { error("Bad value vor ip"); }
+                                                       }
+                                               }
+                                       }
+                                       else {
+                                               $HostResolved = '*';
+                                               if ($Debug) {
+                                                       debug(
+"  DNS lookup by static DNS cache file asked for $Host but not found.",
+                                                               4
+                                                       );
+                                               }
+                                       }
                                }
-                               if ( $ShowRobotsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
+                               else {
+                                       if ($Debug) {
+                                               debug(
+"  DNS lookup asked for $Host but this is not an IP address.",
+                                                       4
+                                               );
+                                       }
+                                       $DNSLookupAlreadyDone = $LogFile;
                                }
-                               if ( $ShowRobotsStats =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_robot_l{$key}
-                                               ? Format_Date( $_robot_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
+                       }
+                       else {
+                               if ( $Host =~ /$regipv4l/o ) {
+                                       $Host =~ s/^::ffff://;
+                                       $HostResolved = '*';
+                                       $ip           = 4;
                                }
-                               print "</tr>\n";
-
-                               #$total_p += $_robot_p{$key}||0;
-                               $total_h += $_robot_h{$key};
-                               $total_k += $_robot_k{$key} || 0;
-                               $total_r += $_robot_r{$key} || 0;
-                               $count++;
+                               elsif ( $Host =~ /$regipv4/o ) {
+                                       $HostResolved = '*';
+                                       $ip           = 4;
+                               }    # IPv4
+                               elsif ( $Host =~ /$regipv6/o ) {
+                                       $HostResolved = '*';
+                                       $ip           = 6;
+                               }    # IPv6
+                               if ($Debug) { debug( "  No DNS lookup asked.", 4 ); }
                        }
 
-                       # For bots we need to count Totals
-                       my $TotalPagesRobots =
-                         0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
-                       my $TotalHitsRobots = 0;
-                       foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
-                       my $TotalBytesRobots = 0;
-                       foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
-                       my $TotalRRobots = 0;
-                       foreach ( values %_robot_r ) { $TotalRRobots += $_; }
-                       $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
-                       $rest_h = $TotalHitsRobots - $total_h;
-                       $rest_k = $TotalBytesRobots - $total_k;
-                       $rest_r = $TotalRRobots - $total_r;
-
+                       # Analyze: Country (Top-level domain)
+                       #------------------------------------
                        if ($Debug) {
                                debug(
-"Total real / shown : $TotalPagesRobots / $total_p - $TotalHitsRobots / $total_h - $TotalBytesRobots / $total_k",
-                                       2
+"  Search country (Host=$Host HostResolved=$HostResolved ip=$ip)",
+                                       4
                                );
                        }
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
-                       {               # All other robots
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowRobotsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
-                               if ( $ShowRobotsStats =~ /B/i ) {
-                                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
-                               }
-                               if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
-                       }
-                       &tab_end(
-                               "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
-                       &html_end(1);
-               }
-               if (   $HTMLOutput{'urldetail'}
-                       || $HTMLOutput{'urlentry'}
-                       || $HTMLOutput{'urlexit'} )
-               {
+                       my $Domain = 'ip';
 
-                       # Call to plugins' function ShowPagesFilter
-                       foreach
-                         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesFilter'} } )
-                       {
+                       # Set $HostResolved to host and resolve domain
+                       if ( $HostResolved eq '*' ) {
 
-                               #                       my $function="ShowPagesFilter_$pluginname()";
-                               #                       eval("$function");
-                               my $function = "ShowPagesFilter_$pluginname";
-                               &$function();
-                       }
-                       print "$Center<a name=\"urls\">&nbsp;</a><br />\n";
+# $Host is an IP address and is not resolved (failed or not asked) or resolution gives an IP address
+                               $HostResolved = $Host;
 
-                       # Show filter form
-                       &ShowFormFilter( "urlfilter", $FilterIn{'url'}, $FilterEx{'url'} );
+                               # Resolve Domain
+                               if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
+                                       $Domain = GetCountryCodeByAddr_geoip($HostResolved);
+                               }
 
-                       # Show URL list
-                       my $title = '';
-                       my $cpt   = 0;
-                       if ( $HTMLOutput{'urldetail'} ) {
-                               $title = $Message[19];
-                               $cpt   = ( scalar keys %_url_p );
-                       }
-                       if ( $HTMLOutput{'urlentry'} ) {
-                               $title = $Message[104];
-                               $cpt   = ( scalar keys %_url_e );
-                       }
-                       if ( $HTMLOutput{'urlexit'} ) {
-                               $title = $Message[116];
-                               $cpt   = ( scalar keys %_url_x );
-                       }
-                       &tab_head( "$title", 19, 0, 'urls' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
-                       if ( $FilterIn{'url'} || $FilterEx{'url'} ) {
-                               if ( $FilterIn{'url'} ) {
-                                       print "$Message[79] <b>$FilterIn{'url'}</b>";
-                               }
-                               if ( $FilterIn{'url'} && $FilterEx{'url'} ) { print " - "; }
-                               if ( $FilterEx{'url'} ) {
-                                       print "Exclude $Message[79] <b>$FilterEx{'url'}</b>";
-                               }
-                               if ( $FilterIn{'url'} || $FilterEx{'url'} ) { print ": "; }
-                               print Format_Number($cpt)." $Message[28]";
-                               if ( $MonthRequired ne 'all' ) {
-                                       if ( $HTMLOutput{'urldetail'} ) {
-                                               print
-"<br />$Message[102]: ".Format_Number($TotalDifferentPages)." $Message[28]";
+#                      elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($HostResolved); }
+#                      elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($HostResolved); }
+                               elsif ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} ) {
+                                       $Domain = GetCountryCodeByAddr_geoipfree($HostResolved);
+                               }
+                               if ($AtLeastOneSectionPlugin) {
+                                       foreach my $pluginname (
+                                               keys %{ $PluginsLoaded{'SectionProcessIp'} } )
+                                       {
+                                               my $function = "SectionProcessIp_$pluginname";
+                                               if ($Debug) {
+                                                       debug( "  Call to plugin function $function", 5 );
+                                               }
+                                               &$function($HostResolved);
                                        }
                                }
                        }
-                       else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
-                       print "</th>";
-                       if ( $ShowPagesStats =~ /P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /B/i ) {
-                               print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /E/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /X/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
-                       }
-
-                       # Call to plugins' function ShowPagesAddField
-                       foreach
-                         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                       {
-
-                               #                       my $function="ShowPagesAddField_$pluginname('title')";
-                               #                       eval("$function");
-                               my $function = "ShowPagesAddField_$pluginname";
-                               &$function('title');
-                       }
-                       print "<th>&nbsp;</th></tr>\n";
-                       $total_p = $total_k = $total_e = $total_x = 0;
-                       my $count = 0;
-                       if ( $HTMLOutput{'urlentry'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_e,
-                                       \%_url_e );
-                       }
-                       elsif ( $HTMLOutput{'urlexit'} ) {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_x,
-                                       \%_url_x );
-                       }
                        else {
-                               &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'File'}, \%_url_p,
-                                       \%_url_p );
-                       }
-                       $max_p = 1;
-                       $max_k = 1;
-                       foreach my $key (@keylist) {
-                               if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
-                               if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
-                                       $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
-                               }
-                       }
-                       foreach my $key (@keylist) {
-                               print "<tr><td class=\"aws\">";
-                               &ShowURLInfo($key);
-                               print "</td>";
-                               my $bredde_p = 0;
-                               my $bredde_e = 0;
-                               my $bredde_x = 0;
-                               my $bredde_k = 0;
-                               if ( $max_p > 0 ) {
-                                       $bredde_p =
-                                         int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
-                               if ( $max_p > 0 ) {
-                                       $bredde_e =
-                                         int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
-                               if ( $max_p > 0 ) {
-                                       $bredde_x =
-                                         int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k =
-                                         int( $BarWidth *
-                                                 ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
-                                                 $max_k ) + 1;
-                               }
-                               if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
-                               if ( $ShowPagesStats =~ /P/i ) {
-                                       print "<td>".Format_Number($_url_p{$key})."</td>";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_url_k{$key}
-                                               ? Format_Bytes(
-                                                       $_url_k{$key} / ( $_url_p{$key} || 1 )
-                                                 )
-                                               : "&nbsp;"
-                                         )
-                                         . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print "<td>"
-                                         . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print "<td>"
-                                         . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
-                               }
 
-                               # Call to plugins' function ShowPagesAddField
-                               foreach my $pluginname (
-                                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                               {
+# $Host was already a host name ($ip=0, $Host=name, $HostResolved='') or has been resolved ($ip>0, $Host=ip, $HostResolved defined)
+                               $HostResolved = lc( $HostResolved ? $HostResolved : $Host );
 
-                                 #                             my $function="ShowPagesAddField_$pluginname('$key')";
-                                 #                             eval("$function");
-                                       my $function = "ShowPagesAddField_$pluginname";
-                                       &$function($key);
-                               }
-                               print "<td class=\"aws\">";
+                               # Resolve Domain
+                               if ($ip)
+                               {    # If we have ip, we use it in priority instead of hostname
+                                       if ( $PluginsLoaded{'GetCountryCodeByAddr'}{'geoip'} ) {
+                                               $Domain = GetCountryCodeByAddr_geoip($Host);
+                                       }
 
-                               # alt and title are not provided to reduce page size
-                               if ( $ShowPagesStats =~ /P/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\" /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\" /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\" /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\" />";
-                               }
-                               print "</td></tr>\n";
-                               $total_p += $_url_p{$key};
-                               $total_e += $_url_e{$key};
-                               $total_x += $_url_x{$key};
-                               $total_k += $_url_k{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalPages / $total_p - $TotalEntries / $total_e - $TotalExits / $total_x - $TotalBytesPages / $total_k",
-                                       2
-                               );
-                       }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_k = $TotalBytesPages - $total_k;
-                       $rest_e = $TotalEntries - $total_e;
-                       $rest_x = $TotalExits - $total_x;
-                       if ( $rest_p > 0 || $rest_e > 0 || $rest_k > 0 ) {
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowPagesStats =~ /P/i ) {
-                                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print "<td>"
-                                         . (
-                                               $rest_k
-                                               ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
-                                               : "&nbsp;"
-                                         )
-                                         . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
+#                              elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByAddr_geoip_region_maxmind($Host); }
+#                              elsif ($PluginsLoaded{'GetCountryCodeByAddr'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByAddr_geoip_city_maxmind($Host); }
+                                       elsif (
+                                               $PluginsLoaded{'GetCountryCodeByAddr'}{'geoipfree'} )
+                                       {
+                                               $Domain = GetCountryCodeByAddr_geoipfree($Host);
+                                       }
+                                       elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
+                                       if ($AtLeastOneSectionPlugin) {
+                                               foreach my $pluginname (
+                                                       keys %{ $PluginsLoaded{'SectionProcessIp'} } )
+                                               {
+                                                       my $function = "SectionProcessIp_$pluginname";
+                                                       if ($Debug) {
+                                                               debug( "  Call to plugin function $function",
+                                                                       5 );
+                                                       }
+                                                       &$function($Host);
+                                               }
+                                       }
                                }
+                               else {
+                                       if ( $PluginsLoaded{'GetCountryCodeByName'}{'geoip'} ) {
+                                               $Domain = GetCountryCodeByName_geoip($HostResolved);
+                                       }
 
-                               # Call to plugins' function ShowPagesAddField
-                               foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                               {
-                                       my $function = "ShowPagesAddField_$pluginname";
-                                       &$function('');
+#                              elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_region_maxmind'}) { $Domain=GetCountryCodeByName_geoip_region_maxmind($HostResolved); }
+#                              elsif ($PluginsLoaded{'GetCountryCodeByName'}{'geoip_city_maxmind'})   { $Domain=GetCountryCodeByName_geoip_city_maxmind($HostResolved); }
+                                       elsif (
+                                               $PluginsLoaded{'GetCountryCodeByName'}{'geoipfree'} )
+                                       {
+                                               $Domain = GetCountryCodeByName_geoipfree($HostResolved);
+                                       }
+                                       elsif ( $HostResolved =~ /\.(\w+)$/ ) { $Domain = $1; }
+                                       if ($AtLeastOneSectionPlugin) {
+                                               foreach my $pluginname (
+                                                       keys %{ $PluginsLoaded{'SectionProcessHostname'} } )
+                                               {
+                                                       my $function = "SectionProcessHostname_$pluginname";
+                                                       if ($Debug) {
+                                                               debug( "  Call to plugin function $function",
+                                                                       5 );
+                                                       }
+                                                       &$function($HostResolved);
+                                               }
+                                       }
                                }
-                               print "<td>&nbsp;</td></tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'unknownos'} ) {
-                       print "$Center<a name=\"unknownos\">&nbsp;</a><br />\n";
-                       my $title = "$Message[46]";
-                       &tab_head( "$title", 19, 0, 'unknownos' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
-                         . ( scalar keys %_unknownreferer_l )
-                         . ")</th><th>$Message[9]</th></tr>\n";
-                       $total_l = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownreferer_l,
-                               \%_unknownreferer_l );
-                       foreach my $key (@keylist) {
-                               my $useragent = XMLEncode( CleanXSS($key) );
-                               print "<tr><td class=\"aws\">$useragent</td>";
-                               print "<td nowrap=\"nowrap\">"
-                                 . Format_Date( $_unknownreferer_l{$key}, 1 ) . "</td>";
-                               print "</tr>\n";
-                               $total_l += 1;
-                               $count++;
                        }
-                       $rest_l = ( scalar keys %_unknownreferer_l ) - $total_l;
-                       if ( $rest_l > 0 ) {
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td>-</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'unknownbrowser'} ) {
-                       print "$Center<a name=\"unknownbrowser\">&nbsp;</a><br />\n";
-                       my $title = "$Message[50]";
-                       &tab_head( "$title", 19, 0, 'unknownbrowser' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>User agent ("
-                         . ( scalar keys %_unknownrefererbrowser_l )
-                         . ")</th><th>$Message[9]</th></tr>\n";
-                       $total_l = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_unknownrefererbrowser_l,
-                               \%_unknownrefererbrowser_l );
-                       foreach my $key (@keylist) {
-                               my $useragent = XMLEncode( CleanXSS($key) );
-                               print
-                                 "<tr><td class=\"aws\">$useragent</td><td nowrap=\"nowrap\">"
-                                 . Format_Date( $_unknownrefererbrowser_l{$key}, 1 )
-                                 . "</td></tr>\n";
-                               $total_l += 1;
-                               $count++;
-                       }
-                       $rest_l = ( scalar keys %_unknownrefererbrowser_l ) - $total_l;
-                       if ( $rest_l > 0 ) {
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td>-</td>";
-                               print "</tr>\n";
+
+                       # Store country
+                       if ($PageBool) { $_domener_p{$Domain}++; }
+                       $_domener_h{$Domain}++;
+                       if ( $field[$pos_size] ne '-' ) {
+                               $_domener_k{$Domain} += int( $field[$pos_size] );
                        }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'osdetail'} ) {
 
-                       # Show os versions
-                       print "$Center<a name=\"osversions\">&nbsp;</a><br />";
-                       my $title = "$Message[59]";
-                       &tab_head( "$title", 19, 0, 'osversions' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
-                       print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       print "<th>&nbsp;</th>";
-                       print "</tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList( MinimumButNoZero( scalar keys %_os_h, 500 ),
-                               1, \%_os_h, \%_os_h );
-                       my %keysinkeylist = ();
-                       $max_h = 1;
-
-                       # Count total by family
-                       my %totalfamily_h = ();
-                       my $TotalFamily   = 0;
-                 OSLOOP: foreach my $key (@keylist) {
-                               $total_h += $_os_h{$key};
-                               if ( $_os_h{$key} > $max_h ) { $max_h = $_os_h{$key}; }
-                               foreach my $family ( keys %OSFamily ) {
-                                       if ( $key =~ /^$family/i ) {
-                                               $totalfamily_h{$family} += $_os_h{$key};
-                                               $TotalFamily            += $_os_h{$key};
-                                               next OSLOOP;
+                       # Analyze: Host, URL entry+exit and Session
+                       #------------------------------------------
+                       if ($PageBool) {
+                               my $timehostl = $_host_l{$HostResolved};
+                               if ($timehostl) {
+
+# A visit for this host was already detected
+# TODO everywhere there is $VISITTIMEOUT
+#                              $timehostl =~ /^\d\d\d\d\d\d(\d\d)/; my $daytimehostl=$1;
+#                              if ($timerecord > ($timehostl+$VISITTIMEOUT+($dateparts[3]>$daytimehostl?$NEWDAYVISITTIMEOUT:0))) {
+                                       if ( $timerecord > ( $timehostl + $VISITTIMEOUT ) ) {
+
+                                               # This is a second visit or more
+                                               if ( !$_waithost_s{$HostResolved} ) {
+
+                                                       # This is a second visit or more
+                                                       # We count 'visit','exit','entry','DayVisits'
+                                                       if ($Debug) {
+                                                               debug(
+"  This is a second visit for $HostResolved.",
+                                                                       4
+                                                               );
+                                                       }
+                                                       my $timehosts = $_host_s{$HostResolved};
+                                                       my $page      = $_host_u{$HostResolved};
+                                                       if ($page) { $_url_x{$page}++; }
+                                                       $_url_e{ $field[$pos_url] }++;
+                                                       $DayVisits{$yearmonthdayrecord}++;
+
+                                # We can't count session yet because we don't have the start so
+                                # we save params of first 'wait' session
+                                                       $_waithost_l{$HostResolved} = $timehostl;
+                                                       $_waithost_s{$HostResolved} = $timehosts;
+                                                       $_waithost_u{$HostResolved} = $page;
+                                               }
+                                               else {
+
+                                                # This is third visit or more
+                                                # We count 'session','visit','exit','entry','DayVisits'
+                                                       if ($Debug) {
+                                                               debug(
+"  This is a third visit or more for $HostResolved.",
+                                                                       4
+                                                               );
+                                                       }
+                                                       my $timehosts = $_host_s{$HostResolved};
+                                                       my $page      = $_host_u{$HostResolved};
+                                                       if ($page) { $_url_x{$page}++; }
+                                                       $_url_e{ $field[$pos_url] }++;
+                                                       $DayVisits{$yearmonthdayrecord}++;
+                                                       if ($timehosts) {
+                                                               $_session{ GetSessionRange( $timehosts,
+                                                                               $timehostl ) }++;
+                                                       }
+                                               }
+
+                                               # Save new session properties
+                                               $_host_s{$HostResolved} = $timerecord;
+                                               $_host_l{$HostResolved} = $timerecord;
+                                               $_host_u{$HostResolved} = $field[$pos_url];
                                        }
-                               }
-                       }
+                                       elsif ( $timerecord > $timehostl ) {
 
-                       # Write records grouped in a browser family
-                       foreach my $family ( keys %OSFamily ) {
-                               my $p = '&nbsp;';
-                               if ($total_h) {
-                                       $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               my $familyheadershown = 0;
-                               foreach my $key ( reverse sort keys %_os_h ) {
-                                       if ( $key =~ /^$family(.*)/i ) {
-                                               if ( !$familyheadershown ) {
-                                                       my $family_name = '';
-                                                       if ( $OSFamily{$family} ) {
-                                                               $family_name = $OSFamily{$family};
-                                                       }
-                                                       print
-"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$family_name</b></td>";
-                                                       print "<td><b>"
-                                                         . Format_Number(int( $totalfamily_h{$family} ))
-                                                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
-                                                       print "</tr>\n";
-                                                       $familyheadershown = 1;
+                                               # This is a same visit we can count
+                                               if ($Debug) {
+                                                       debug(
+"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
+                                                               4
+                                                       );
                                                }
-                                               $keysinkeylist{$key} = 1;
-                                               my $ver = $1;
-                                               my $p   = '&nbsp;';
-                                               if ($total_h) {
-                                                       $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
-                                                       $p = "$p %";
+                                               $_host_l{$HostResolved} = $timerecord;
+                                               $_host_u{$HostResolved} = $field[$pos_url];
+                                       }
+                                       elsif ( $timerecord == $timehostl ) {
+
+                                               # This is a same visit we can count
+                                               if ($Debug) {
+                                                       debug(
+"  This is same visit still running for $HostResolved. host_l/host_u changed to $timerecord/$field[$pos_url]",
+                                                               4
+                                                       );
                                                }
-                                               print "<tr>";
-                                               print "<td"
-                                                 . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                                 . "><img src=\"$DirIcons\/os\/$key.png\""
-                                                 . AltTitle("")
-                                                 . " /></td>";
-
-                                               print "<td class=\"aws\">$OSHashLib{$key}</td>";
-                                               my $bredde_h = 0;
-                                               if ( $max_h > 0 ) {
-                                                       $bredde_h =
-                                                         int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h )
-                                                         + 1;
+                                               $_host_u{$HostResolved} = $field[$pos_url];
+                                       }
+                                       elsif ( $timerecord < $_host_s{$HostResolved} ) {
+
+                                          # Should happens only with not correctly sorted log files
+                                               if ($Debug) {
+                                                       debug(
+"  This is same visit still running for $HostResolved with start not in order. host_s changed to $timerecord (entry page also changed if first visit)",
+                                                               4
+                                                       );
                                                }
-                                               if ( ( $bredde_h == 1 ) && $_os_h{$key} ) {
-                                                       $bredde_h = 2;
+                                               if ( !$_waithost_s{$HostResolved} ) {
+
+# We can reorder entry page only if it's the first visit found in this update run (The saved entry page was $_waithost_e if $_waithost_s{$HostResolved} is not defined. If second visit or more, entry was directly counted and not saved)
+                                                       $_waithost_e{$HostResolved} = $field[$pos_url];
                                                }
-                                               print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
-                                               print "<td class=\"aws\">";
+                                               else {
 
-                                               # alt and title are not provided to reduce page size
-                                               if ($ShowOSStats) {
-                                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+# We can't change entry counted as we dont't know what was the url counted as entry
                                                }
-                                               print "</td>";
-                                               print "</tr>\n";
-                                               $count++;
+                                               $_host_s{$HostResolved} = $timerecord;
                                        }
-                               }
-                       }
-
-                       # Write other records
-                       my $familyheadershown = 0;
-                       foreach my $key (@keylist) {
-                               if ( $keysinkeylist{$key} ) { next; }
-                               if ( !$familyheadershown )  {
-                                       my $p = '&nbsp;';
-                                       if ($total_h) {
-                                               $p =
-                                                 int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
-                                                 10;
-                                               $p = "$p %";
+                                       else {
+                                               if ($Debug) {
+                                                       debug(
+"  This is same visit still running for $HostResolved with hit between start and last hits. No change",
+                                                               4
+                                                       );
+                                               }
                                        }
-                                       print
-"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
-                                       print "<td><b>"
-                                         . Format_Number(( $total_h - $TotalFamily ))
-                                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
-                                       print "</tr>\n";
-                                       $familyheadershown = 1;
-                               }
-                               my $p = '&nbsp;';
-                               if ($total_h) {
-                                       $p = int( $_os_h{$key} / $total_h * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               print "<tr>";
-                               if ( $key eq 'Unknown' ) {
-                                       print "<td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
                                }
                                else {
-                                       my $keywithoutcumul = $key;
-                                       $keywithoutcumul =~ s/cumul$//i;
-                                       my $libos = $OSHashLib{$keywithoutcumul}
-                                         || $keywithoutcumul;
-                                       my $nameicon = $keywithoutcumul;
-                                       $nameicon =~ s/[^\w]//g;
-                                       print "<td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/os\/$nameicon.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\">$libos</td>";
-                               }
-                               my $bredde_h = 0;
-                               if ( $max_h > 0 ) {
-                                       $bredde_h =
-                                         int( $BarWidth * ( $_os_h{$key} || 0 ) / $max_h ) + 1;
-                               }
-                               if ( ( $bredde_h == 1 ) && $_os_h{$key} ) { $bredde_h = 2; }
-                               print "<td>".Format_Number($_os_h{$key})."</td><td>$p</td>";
-                               print "<td class=\"aws\">";
-
-                               # alt and title are not provided to reduce page size
-                               if ($ShowOSStats) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
-                               }
-                               print "</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'browserdetail'} ) {
 
-                       # Show browsers versions
-                       print "$Center<a name=\"browsersversions\">&nbsp;</a><br />";
-                       my $title = "$Message[21]";
-                       &tab_head( "$title", 19, 0, 'browsersversions' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[58]</th>";
-                       print
-"<th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       print "<th>&nbsp;</th>";
-                       print "</tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList( MinimumButNoZero( scalar keys %_browser_h, 500 ),
-                               1, \%_browser_h, \%_browser_h );
-                       my %keysinkeylist = ();
-                       $max_h = 1;
-
-                       # Count total by family
-                       my %totalfamily_h = ();
-                       my $TotalFamily   = 0;
-                 BROWSERLOOP: foreach my $key (@keylist) {
-                               $total_h += $_browser_h{$key};
-                               if ( $_browser_h{$key} > $max_h ) {
-                                       $max_h = $_browser_h{$key};
-                               }
-                               foreach my $family ( keys %BrowsersFamily ) {
-                                       if ( $key =~ /^$family/i ) {
-                                               $totalfamily_h{$family} += $_browser_h{$key};
-                                               $TotalFamily            += $_browser_h{$key};
-                                               next BROWSERLOOP;
+# This is a new visit (may be). First new visit found for this host. We save in wait array the entry page to count later
+                                       if ($Debug) {
+                                               debug(
+"  New session (may be) for $HostResolved. Save in wait array to see later",
+                                                       4
+                                               );
                                        }
+                                       $_waithost_e{$HostResolved} = $field[$pos_url];
+
+                                       # Save new session properties
+                                       $_host_u{$HostResolved} = $field[$pos_url];
+                                       $_host_s{$HostResolved} = $timerecord;
+                                       $_host_l{$HostResolved} = $timerecord;
                                }
+                               $_host_p{$HostResolved}++;
+                       }
+                       $_host_h{$HostResolved}++;
+                       if ( $field[$pos_size] ne '-' ) {
+                               $_host_k{$HostResolved} += int( $field[$pos_size] );
                        }
 
-                       # Write records grouped in a browser family
-                       foreach my $family (
-                               sort { $BrowsersFamily{$a} <=> $BrowsersFamily{$b} }
-                               keys %BrowsersFamily
-                         )
-                       {
-                               my $p = '&nbsp;';
-                               if ($total_h) {
-                                       $p = int( $totalfamily_h{$family} / $total_h * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               my $familyheadershown = 0;
+                       # Analyze: Browser - OS
+                       #----------------------
+                       if ( $pos_agent >= 0 ) {
 
-                               #foreach my $key ( reverse sort keys %_browser_h ) {
-                               foreach my $key ( reverse sort SortBrowsers keys %_browser_h ) {
-                                       if ( $key =~ /^$family(.*)/i ) {
-                                               if ( !$familyheadershown ) {
-                                                       print
-"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>"
-                                                         . uc($family)
-                                                         . "</b></td>";
-                                                       print "<td>&nbsp;</td><td><b>"
-                                                         . Format_Number(int( $totalfamily_h{$family} ))
-                                                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
-                                                       print "</tr>\n";
-                                                       $familyheadershown = 1;
+                               if ($LevelForBrowsersDetection) {
+
+                                       # Analyze: Browser
+                                       #-----------------
+                                       my $uabrowser = $TmpBrowser{$UserAgent};
+                                       if ( !$uabrowser ) {
+                                               my $found = 1;
+
+                                               # Firefox ?
+                                               if (   $UserAgent =~ /$regverfirefox/o
+                                                       && $UserAgent !~ /$regnotfirefox/o )
+                                               {
+                                                       $_browser_h{"firefox$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "firefox$1";
+                                               }
+
+                                               # Opera ?
+                                               elsif ( $UserAgent =~ /$regveropera/o ) {
+                                                       $_browser_h{"opera$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "opera$1";
                                                }
-                                               $keysinkeylist{$key} = 1;
-                                               my $ver = $1;
-                                               my $p   = '&nbsp;';
-                                               if ($total_h) {
-                                                       $p =
-                                                         int( $_browser_h{$key} / $total_h * 1000 ) / 10;
-                                                       $p = "$p %";
+
+                                               # Chrome ?
+                                               elsif ( $UserAgent =~ /$regverchrome/o ) {
+                                                       $_browser_h{"chrome$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "chrome$1";
                                                }
-                                               print "<tr>";
-                                               print "<td"
-                                                 . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                                 . "><img src=\"$DirIcons\/browser\/$family.png\""
-                                                 . AltTitle("")
-                                                 . " /></td>";
-                                               print "<td class=\"aws\">"
-                                                 . ucfirst($family) . " "
-                                                 . ( $ver ? "$ver" : "?" ) . "</td>";
-                                               print "<td>"
-                                                 . (
-                                                       $BrowsersHereAreGrabbers{$family}
-                                                       ? "<b>$Message[112]</b>"
-                                                       : "$Message[113]"
-                                                 )
-                                                 . "</td>";
-                                               my $bredde_h = 0;
-                                               if ( $max_h > 0 ) {
-                                                       $bredde_h =
-                                                         int( $BarWidth * ( $_browser_h{$key} || 0 ) /
-                                                                 $max_h ) + 1;
+
+                                               # Safari ?
+                                               elsif ($UserAgent =~ /$regversafari/o
+                                                       && $UserAgent !~ /$regnotsafari/o )
+                                               {
+                                                       my $safariver = $SafariBuildToVersion{$1};
+                                                       if ( $UserAgent =~ /$regversafariver/o ) {
+                                                               $safariver = $1;
+                                                       }
+                                                       $_browser_h{"safari$safariver"}++;
+                                                       $TmpBrowser{$UserAgent} = "safari$safariver";
+                                               }
+
+                                               # Konqueror ?
+                                               elsif ( $UserAgent =~ /$regverkonqueror/o ) {
+                                                       $_browser_h{"konqueror$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "konqueror$1";
+                                               }
+
+                                               # Subversion ?
+                                               elsif ( $UserAgent =~ /$regversvn/o ) {
+                                                       $_browser_h{"svn$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "svn$1";
+                                               }
+
+                                               # IE ? (must be at end of test)
+                                               elsif ($UserAgent =~ /$regvermsie/o
+                                                       && $UserAgent !~ /$regnotie/o )
+                                               {
+                                                       $_browser_h{"msie$2"}++;
+                                                       $TmpBrowser{$UserAgent} = "msie$2";
+                                               }
+
+                                               # Netscape 6.x, 7.x ... ? (must be at end of test)
+                                               elsif ( $UserAgent =~ /$regvernetscape/o ) {
+                                                       $_browser_h{"netscape$1"}++;
+                                                       $TmpBrowser{$UserAgent} = "netscape$1";
+                                               }
+
+                                               # Netscape 3.x, 4.x ... ? (must be at end of test)
+                                               elsif ($UserAgent =~ /$regvermozilla/o
+                                                       && $UserAgent !~ /$regnotnetscape/o )
+                                               {
+                                                       $_browser_h{"netscape$2"}++;
+                                                       $TmpBrowser{$UserAgent} = "netscape$2";
+                                               }
+
+                                               # Other known browsers ?
+                                               else {
+                                                       $found = 0;
+                                                       foreach (@BrowsersSearchIDOrder)
+                                                       {    # Search ID in order of BrowsersSearchIDOrder
+                                                               if ( $UserAgent =~ /$_/ ) {
+                                                                       my $browser = &UnCompileRegex($_);
+
+                                                                  # TODO If browser is in a family, use version
+                                                                       $_browser_h{"$browser"}++;
+                                                                       $TmpBrowser{$UserAgent} = "$browser";
+                                                                       $found = 1;
+                                                                       last;
+                                                               }
+                                                       }
+                                               }
+
+                                               # Unknown browser ?
+                                               if ( !$found ) {
+                                                       $_browser_h{'Unknown'}++;
+                                                       $TmpBrowser{$UserAgent} = 'Unknown';
+                                                       my $newua = $UserAgent;
+                                                       $newua =~ tr/\+ /__/;
+                                                       $_unknownrefererbrowser_l{$newua} = $timerecord;
+                                               }
+                                       }
+                                       else {
+                                               $_browser_h{$uabrowser}++;
+                                               if ( $uabrowser eq 'Unknown' ) {
+                                                       my $newua = $UserAgent;
+                                                       $newua =~ tr/\+ /__/;
+                                                       $_unknownrefererbrowser_l{$newua} = $timerecord;
                                                }
-                                               if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
-                                                       $bredde_h = 2;
+                                       }
+
+                               }
+
+                               if ($LevelForOSDetection) {
+
+                                       # Analyze: OS
+                                       #------------
+                                       my $uaos = $TmpOS{$UserAgent};
+                                       if ( !$uaos ) {
+                                               my $found = 0;
+
+                                               # in OSHashID list ?
+                                               foreach (@OSSearchIDOrder)
+                                               {    # Search ID in order of OSSearchIDOrder
+                                                       if ( $UserAgent =~ /$_/ ) {
+                                                               my $osid = $OSHashID{ &UnCompileRegex($_) };
+                                                               $_os_h{"$osid"}++;
+                                                               $TmpOS{$UserAgent} = "$osid";
+                                                               $found = 1;
+                                                               last;
+                                                       }
                                                }
-                                               print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
-                                               print "<td class=\"aws\">";
 
-                                               # alt and title are not provided to reduce page size
-                                               if ($ShowBrowsersStats) {
-                                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
+                                               # Unknown OS ?
+                                               if ( !$found ) {
+                                                       $_os_h{'Unknown'}++;
+                                                       $TmpOS{$UserAgent} = 'Unknown';
+                                                       my $newua = $UserAgent;
+                                                       $newua =~ tr/\+ /__/;
+                                                       $_unknownreferer_l{$newua} = $timerecord;
                                                }
-                                               print "</td>";
-                                               print "</tr>\n";
-                                               $count++;
                                        }
-                               }
-                       }
-
-                       # Write other records
-                       my $familyheadershown = 0;
-                       foreach my $key (@keylist) {
-                               if ( $keysinkeylist{$key} ) { next; }
-                               if ( !$familyheadershown )  {
-                                       my $p = '&nbsp;';
-                                       if ($total_h) {
-                                               $p =
-                                                 int( ( $total_h - $TotalFamily ) / $total_h * 1000 ) /
-                                                 10;
-                                               $p = "$p %";
+                                       else {
+                                               $_os_h{$uaos}++;
+                                               if ( $uaos eq 'Unknown' ) {
+                                                       my $newua = $UserAgent;
+                                                       $newua =~ tr/\+ /__/;
+                                                       $_unknownreferer_l{$newua} = $timerecord;
+                                               }
                                        }
-                                       print
-"<tr bgcolor=\"#F6F6F6\"><td class=\"aws\" colspan=\"2\"><b>$Message[2]</b></td>";
-                                       print "<td>&nbsp;</td><td><b>"
-                                         . Format_Number(( $total_h - $TotalFamily ))
-                                         . "</b></td><td><b>$p</b></td><td>&nbsp;</td>";
-                                       print "</tr>\n";
-                                       $familyheadershown = 1;
-                               }
-                               my $p = '&nbsp;';
-                               if ($total_h) {
-                                       $p = int( $_browser_h{$key} / $total_h * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               print "<tr>";
-                               if ( $key eq 'Unknown' ) {
-                                       print "<td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td>";
-                               }
-                               else {
-                                       my $keywithoutcumul = $key;
-                                       $keywithoutcumul =~ s/cumul$//i;
-                                       my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
-                                         || $keywithoutcumul;
-                                       my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
-                                         || "notavailable";
-                                       print "<td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\">$libbrowser</td><td>"
-                                         . (
-                                               $BrowsersHereAreGrabbers{$key}
-                                               ? "<b>$Message[112]</b>"
-                                               : "$Message[113]"
-                                         )
-                                         . "</td>";
-                               }
-                               my $bredde_h = 0;
-                               if ( $max_h > 0 ) {
-                                       $bredde_h =
-                                         int( $BarWidth * ( $_browser_h{$key} || 0 ) / $max_h ) +
-                                         1;
-                               }
-                               if ( ( $bredde_h == 1 ) && $_browser_h{$key} ) {
-                                       $bredde_h = 2;
-                               }
-                               print "<td>".Format_Number($_browser_h{$key})."</td><td>$p</td>";
-                               print "<td class=\"aws\">";
 
-                               # alt and title are not provided to reduce page size
-                               if ($ShowBrowsersStats) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\" /><br />";
                                }
-                               print "</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'refererse'} ) {
-                       print "$Center<a name=\"refererse\">&nbsp;</a><br />\n";
-                       my $title = "$Message[40]";
-                       &tab_head( "$title", 19, 0, 'refererse' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentSearchEngines)." $Message[122]</th>";
-                       print
-"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
-                       print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       print "</tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList(
-                               $MaxRowsInHTMLOutput,
-                               $MinHit{'Refer'},
-                               \%_se_referrals_h,
-                               (
-                                       ( scalar keys %_se_referrals_p )
-                                       ? \%_se_referrals_p
-                                       : \%_se_referrals_h
-                               )
-                       );    # before 5.4 only hits were recorded
 
-                       foreach my $key (@keylist) {
-                               my $newreferer = $SearchEnginesHashLib{$key} || CleanXSS($key);
-                               my $p_p;
-                               my $p_h;
-                               if ($TotalSearchEnginesPages) {
-                                       $p_p =
-                                         int( $_se_referrals_p{$key} / $TotalSearchEnginesPages *
-                                                 1000 ) / 10;
-                               }
-                               if ($TotalSearchEnginesHits) {
-                                       $p_h =
-                                         int( $_se_referrals_h{$key} / $TotalSearchEnginesHits *
-                                                 1000 ) / 10;
-                               }
-                               print "<tr><td class=\"aws\">$newreferer</td>";
-                               print "<td>"
-                                 . (
-                                       $_se_referrals_p{$key} ? $_se_referrals_p{$key} : '&nbsp;' )
-                                 . "</td>";
-                               print "<td>"
-                                 . ( $_se_referrals_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
-                               print "<td>".Format_Number($_se_referrals_h{$key})."</td>";
-                               print "<td>$p_h %</td>";
-                               print "</tr>\n";
-                               $total_p += $_se_referrals_p{$key};
-                               $total_h += $_se_referrals_h{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalSearchEnginesPages / $total_p - $TotalSearchEnginesHits / $total_h",
-                                       2
-                               );
                        }
-                       $rest_p = $TotalSearchEnginesPages - $total_p;
-                       $rest_h = $TotalSearchEnginesHits - $total_h;
-                       if ( $rest_p > 0 || $rest_h > 0 ) {
-                               my $p_p;
-                               my $p_h;
-                               if ($TotalSearchEnginesPages) {
-                                       $p_p =
-                                         int( $rest_p / $TotalSearchEnginesPages * 1000 ) / 10;
-                               }
-                               if ($TotalSearchEnginesHits) {
-                                       $p_h = int( $rest_h / $TotalSearchEnginesHits * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
-                               print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
-                               print "<td>".Format_Number($rest_h)."</td>";
-                               print "<td>$p_h %</td>";
-                               print "</tr>\n";
+                       else {
+                               $_browser_h{'Unknown'}++;
+                               $_os_h{'Unknown'}++;
                        }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'refererpages'} ) {
-                       print "$Center<a name=\"refererpages\">&nbsp;</a><br />\n";
 
-                       # Show filter form
-                       &ShowFormFilter(
-                               "refererpagesfilter",
-                               $FilterIn{'refererpages'},
-                               $FilterEx{'refererpages'}
-                       );
-                       my $title = "$Message[41]";
-                       my $cpt   = 0;
-                       $cpt = ( scalar keys %_pagesrefs_h );
-                       &tab_head( "$title", 19, 0, 'refererpages' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>";
-                       if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
+                       # Analyze: Referer
+                       #-----------------
+                       my $found = 0;
+                       if (   $pos_referer >= 0
+                               && $LevelForRefererAnalyze
+                               && $field[$pos_referer] )
+                       {
 
-                               if ( $FilterIn{'refererpages'} ) {
-                                       print "$Message[79] <b>$FilterIn{'refererpages'}</b>";
-                               }
-                               if ( $FilterIn{'refererpages'} && $FilterEx{'refererpages'} ) {
-                                       print " - ";
-                               }
-                               if ( $FilterEx{'refererpages'} ) {
-                                       print
-                                         "Exclude $Message[79] <b>$FilterEx{'refererpages'}</b>";
-                               }
-                               if ( $FilterIn{'refererpages'} || $FilterEx{'refererpages'} ) {
-                                       print ": ";
+                               # Direct ?
+                               if (   $field[$pos_referer] eq '-'
+                                       || $field[$pos_referer] eq 'bookmarks' )
+                               {  # "bookmarks" is sent by Netscape, '-' by all others browsers
+                                           # Direct access
+                                       if ($PageBool) {
+                                               if ($ShowDirectOrigin) {
+                                                       print "Direct access for line $line\n";
+                                               }
+                                               $_from_p[0]++;
+                                       }
+                                       $_from_h[0]++;
+                                       $found = 1;
                                }
-                               print "$cpt $Message[28]";
-
-#if ($MonthRequired ne 'all') {
-#      if ($HTMLOutput{'refererpages'}) { print "<br />$Message[102]: $TotalDifferentPages $Message[28]"; }
-#}
-                       }
-                       else { print "$Message[102]: ".Format_Number($cpt)." $Message[28]"; }
-                       print "</th>";
-                       print
-"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
-                       print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       print "</tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList(
-                               $MaxRowsInHTMLOutput,
-                               $MinHit{'Refer'},
-                               \%_pagesrefs_h,
-                               (
-                                       ( scalar keys %_pagesrefs_p )
-                                       ? \%_pagesrefs_p
-                                       : \%_pagesrefs_h
-                               )
-                       );
+                               else {
+                                       $field[$pos_referer] =~ /$regreferer/o;
+                                       my $refererprot   = $1;
+                                       my $refererserver =
+                                           ( $2 || '' )
+                                         . ( !$3 || $3 eq ':80' ? '' : $3 )
+                                         ; # refererserver is www.xxx.com or www.xxx.com:81 but not www.xxx.com:80
+                                           # HTML link ?
+                                       if ( $refererprot =~ /^http/i ) {
 
-                       foreach my $key (@keylist) {
-                               my $nompage = CleanXSS($key);
-                               if ( length($nompage) > $MaxLengthOfShownURL ) {
-                                       $nompage =
-                                         substr( $nompage, 0, $MaxLengthOfShownURL ) . "...";
-                               }
-                               my $p_p;
-                               my $p_h;
-                               if ($TotalRefererPages) {
-                                       $p_p =
-                                         int( $_pagesrefs_p{$key} / $TotalRefererPages * 1000 ) /
-                                         10;
-                               }
-                               if ($TotalRefererHits) {
-                                       $p_h =
-                                         int( $_pagesrefs_h{$key} / $TotalRefererHits * 1000 ) /
-                                         10;
-                               }
-                               print "<tr><td class=\"aws\">";
-                               &ShowURLInfo($key);
-                               print "</td>";
-                               print "<td>"
-                                 . ( $_pagesrefs_p{$key} ? Format_Number($_pagesrefs_p{$key}) : '&nbsp;' )
-                                 . "</td><td>"
-                                 . ( $_pagesrefs_p{$key} ? "$p_p %" : '&nbsp;' ) . "</td>";
-                               print "<td>"
-                                 . ( $_pagesrefs_h{$key} ? Format_Number($_pagesrefs_h{$key}) : '&nbsp;' )
-                                 . "</td><td>"
-                                 . ( $_pagesrefs_h{$key} ? "$p_h %" : '&nbsp;' ) . "</td>";
-                               print "</tr>\n";
-                               $total_p += $_pagesrefs_p{$key};
-                               $total_h += $_pagesrefs_h{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug(
-"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
-                                       2
-                               );
-                       }
-                       $rest_p = $TotalRefererPages - $total_p;
-                       $rest_h = $TotalRefererHits - $total_h;
-                       if ( $rest_p > 0 || $rest_h > 0 ) {
-                               my $p_p;
-                               my $p_h;
-                               if ($TotalRefererPages) {
-                                       $p_p = int( $rest_p / $TotalRefererPages * 1000 ) / 10;
-                               }
-                               if ($TotalRefererHits) {
-                                       $p_h = int( $rest_h / $TotalRefererHits * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td>" . ( $rest_p ? Format_Number($rest_p)  : '&nbsp;' ) . "</td>";
-                               print "<td>" . ( $rest_p ? "$p_p %" : '&nbsp;' ) . "</td>";
-                               print "<td>".Format_Number($rest_h)."</td>";
-                               print "<td>$p_h %</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'keyphrases'} ) {
-                       print "$Center<a name=\"keyphrases\">&nbsp;</a><br />\n";
-                       &tab_head( $Message[43], 19, 0, 'keyphrases' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(15)
-                         . "><th>".Format_Number($TotalDifferentKeyphrases)." $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList(
-                               $MaxRowsInHTMLOutput, $MinHit{'Keyphrase'},
-                               \%_keyphrases,        \%_keyphrases
-                       );
-                       foreach my $key (@keylist) {
-                               my $mot;
+#if ($Debug) { debug("  Analyze referer refererprot=$refererprot refererserver=$refererserver",5); }
 
-         # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
-                               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
-                                       $mot = CleanXSS(
-                                               DecodeKey_decodeutfkeys(
-                                                       $key, $PageCode || 'iso-8859-1'
-                                               )
-                                       );
-                               }
-                               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
-                               my $p;
-                               if ($TotalKeyphrases) {
-                                       $p =
-                                         int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
-                               }
-                               print "<tr><td class=\"aws\">"
-                                 . XMLEncode($mot)
-                                 . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
-                               $total_s += $_keyphrases{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
-                       }
-                       $rest_s = $TotalKeyphrases - $total_s;
-                       if ( $rest_s > 0 ) {
-                               my $p;
-                               if ($TotalKeyphrases) {
-                                       $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>".Format_Number($rest_s)."</td>";
-                               print "<td>$p %</td></tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               if ( $HTMLOutput{'keywords'} ) {
-                       print "$Center<a name=\"keywords\">&nbsp;</a><br />\n";
-                       &tab_head( $Message[44], 19, 0, 'keywords' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(15)
-                         . "><th>".Format_Number($TotalDifferentKeywords)." $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, $MinHit{'Keyword'},
-                               \%_keywords, \%_keywords );
-                       foreach my $key (@keylist) {
-                               my $mot;
+                                               # Kind of origin
+                                               if ( !$TmpRefererServer{$refererserver} )
+                                               { # TmpRefererServer{$refererserver} is "=" if same site, "search egine key" if search engine, not defined otherwise
+                                                       if ( $refererserver =~ /$reglocal/o ) {
 
-         # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
-                               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
-                                       $mot = CleanXSS(
-                                               DecodeKey_decodeutfkeys(
-                                                       $key, $PageCode || 'iso-8859-1'
-                                               )
-                                       );
-                               }
-                               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
-                               my $p;
-                               if ($TotalKeywords) {
-                                       $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
-                               }
-                               print "<tr><td class=\"aws\">"
-                                 . XMLEncode($mot)
-                                 . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
-                               $total_s += $_keywords{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
-                       }
-                       $rest_s = $TotalKeywords - $total_s;
-                       if ( $rest_s > 0 ) {
-                               my $p;
-                               if ($TotalKeywords) {
-                                       $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>".Format_Number($rest_s)."</td>";
-                               print "<td>$p %</td></tr>\n";
-                       }
-                       &tab_end();
-                       &html_end(1);
-               }
-               foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
-                       if ( $HTMLOutput{"errors$code"} ) {
-                               print "$Center<a name=\"errors$code\">&nbsp;</a><br />\n";
-                               &tab_head( $Message[47], 19, 0, "errors$code" );
-                               print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>URL ("
-                                 . Format_Number(( scalar keys %_sider404_h ))
-                                 . ")</th><th bgcolor=\"#$color_h\">$Message[49]</th><th>$Message[23]</th></tr>\n";
-                               $total_h = 0;
-                               my $count = 0;
-                               &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_sider404_h,
-                                       \%_sider404_h );
-                               foreach my $key (@keylist) {
-                                       my $nompage = XMLEncode( CleanXSS($key) );
-
-#if (length($nompage)>$MaxLengthOfShownURL) { $nompage=substr($nompage,0,$MaxLengthOfShownURL)."..."; }
-                                       my $referer = XMLEncode( CleanXSS( $_referer404_h{$key} ) );
-                                       print "<tr><td class=\"aws\">$nompage</td>";
-                                       print "<td>".Format_Number($_sider404_h{$key})."</td>";
-                                       print "<td class=\"aws\">"
-                                         . ( $referer ? "$referer" : "&nbsp;" ) . "</td>";
-                                       print "</tr>\n";
-                                       $total_s += $_sider404_h{$key};
-                                       $count++;
-                               }
+                                                 # Intern (This hit came from another page of the site)
+                                                               if ($Debug) {
+                                                                       debug(
+"  Server '$refererserver' is added to TmpRefererServer with value '='",
+                                                                               2
+                                                                       );
+                                                               }
+                                                               $TmpRefererServer{$refererserver} = '=';
+                                                               $found = 1;
+                                                       }
+                                                       else {
+                                                               foreach (@HostAliases) {
+                                                                       if ( $refererserver =~ /$_/ ) {
 
-# TODO Build TotalErrorHits
-#                      if ($Debug) { debug("Total real / shown : $TotalErrorHits / $total_h",2); }
-#                      $rest_h=$TotalErrorHits-$total_h;
-#                      if ($rest_h > 0) {
-#                              my $p;
-#                              if ($TotalErrorHits) { $p=int($rest_h/$TotalErrorHits*1000)/10; }
-#                              print "<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td>";
-#                              print "<td>$rest_h</td>";
-#                              print "<td>...</td>";
-#                              print "</tr>\n";
-#                      }
-                               &tab_end();
-                               &html_end(1);
-                       }
-               }
+                                                 # Intern (This hit came from another page of the site)
+                                                                               if ($Debug) {
+                                                                                       debug(
+"  Server '$refererserver' is added to TmpRefererServer with value '='",
+                                                                                               2
+                                                                                       );
+                                                                               }
+                                                                               $TmpRefererServer{$refererserver} = '=';
+                                                                               $found = 1;
+                                                                               last;
+                                                                       }
+                                                               }
+                                                               if ( !$found ) {
 
-               # BY EXTRA SECTIONS
-               #----------------------------
-               foreach my $extranum ( 1 .. @ExtraName - 1 ) {
-                       if ( $HTMLOutput{"allextra$extranum"} ) {
-                               if ($Debug) { debug( "ExtraName$extranum", 2 ); }
-                               print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
-                               my $title = $ExtraName[$extranum];
-                               &tab_head( "$title", 19, 0, "extra$extranum" );
-                               print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                               print "<th>" . $ExtraFirstColumnTitle[$extranum] . "</th>";
+                                                        # Extern (This hit came from an external web site).
 
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       print
-"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                       print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                       print
-"<th class=\"datasize\" bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                       print "<th width=\"120\">$Message[9]</th>";
-                               }
-                               print "</tr>\n";
-                               $total_p = $total_h = $total_k = 0;
+                                                                       if ($LevelForSearchEnginesDetection) {
 
-        #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
-        #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
-                               my $count = 0;
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       &BuildKeyList(
-                                               $MaxRowsInHTMLOutput,
-                                               $MinHitExtra[$extranum],
-                                               \%{ '_section_' . $extranum . '_h' },
-                                               \%{ '_section_' . $extranum . '_p' }
-                                       );
-                               }
-                               else {
-                                       &BuildKeyList(
-                                               $MaxRowsInHTMLOutput,
-                                               $MinHitExtra[$extranum],
-                                               \%{ '_section_' . $extranum . '_h' },
-                                               \%{ '_section_' . $extranum . '_h' }
-                                       );
-                               }
-                               my %keysinkeylist = ();
-                               foreach my $key (@keylist) {
-                                       $keysinkeylist{$key} = 1;
-                                       my $firstcol = CleanXSS( DecodeEncodedString($key) );
-                                       $total_p += ${ '_section_' . $extranum . '_p' }{$key};
-                                       $total_h += ${ '_section_' . $extranum . '_h' }{$key};
-                                       $total_k += ${ '_section_' . $extranum . '_k' }{$key};
-                                       print "<tr>";
-                                       printf(
-"<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
-                                               $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
-                                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                               print "<td>"
-                                                 . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                               print "<td>"
-                                                 . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                               print "<td>"
-                                                 . Format_Bytes(
-                                                       ${ '_section_' . $extranum . '_k' }{$key} )
-                                                 . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                               print "<td>"
-                                                 . (
-                                                       ${ '_section_' . $extranum . '_l' }{$key}
-                                                       ? Format_Date(
-                                                               ${ '_section_' . $extranum . '_l' }{$key}, 1 )
-                                                       : '-'
-                                                 )
-                                                 . "</td>";
-                                       }
-                                       print "</tr>\n";
-                                       $count++;
-                               }
+                                                                               foreach (@SearchEnginesSearchIDOrder)
+                                                                               { # Search ID in order of SearchEnginesSearchIDOrder
+                                                                                       if ( $refererserver =~ /$_/ ) {
+                                                                                               my $key = &UnCompileRegex($_);
+                                                                                               if (
+                                                                                                       !$NotSearchEnginesKeys{$key}
+                                                                                                       || $refererserver !~
+/$NotSearchEnginesKeys{$key}/i
+                                                                                                 )
+                                                                                               {
 
-                               # If we ask average or sum, we loop on all other records
-                               if (   $ExtraAddAverageRow[$extranum]
-                                       || $ExtraAddSumRow[$extranum] )
-                               {
-                                       foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
-                                               if ( $keysinkeylist{$_} ) { next; }
-                                               $total_p += ${ '_section_' . $extranum . '_p' }{$_};
-                                               $total_h += ${ '_section_' . $extranum . '_h' }{$_};
-                                               $total_k += ${ '_section_' . $extranum . '_k' }{$_};
-                                               $count++;
-                                       }
-                               }
+                                                                        # This hit came from the search engine $key
+                                                                                                       if ($Debug) {
+                                                                                                               debug(
+"  Server '$refererserver' is added to TmpRefererServer with value '$key'",
+                                                                                                                       2
+                                                                                                               );
+                                                                                                       }
+                                                                                                       $TmpRefererServer{
+                                                                                                               $refererserver} =
+                                                                                                         $SearchEnginesHashID{ $key
+                                                                                                         };
+                                                                                                       $found = 1;
+                                                                                               }
+                                                                                               last;
+                                                                                       }
+                                                                               }
 
-                               # Add average row
-                               if ( $ExtraAddAverageRow[$extranum] ) {
-                                       print "<tr>";
-                                       print "<td class=\"aws\"><b>$Message[96]</b></td>";
-                                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                               print "<td>"
-                                                 . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" )
-                                                 . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                               print "<td>"
-                                                 . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" )
-                                                 . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                               print "<td>"
-                                                 . (
-                                                       $count
-                                                       ? Format_Bytes( $total_k / $count )
-                                                       : "&nbsp;"
-                                                 )
-                                                 . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                               print "<td>&nbsp;</td>";
-                                       }
-                                       print "</tr>\n";
-                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
 
-                               # Add sum row
-                               if ( $ExtraAddSumRow[$extranum] ) {
-                                       print "<tr>";
-                                       print "<td class=\"aws\"><b>$Message[102]</b></td>";
-                                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                               print "<td>" . ($total_p) . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                               print "<td>" . ($total_h) . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                               print "<td>" . Format_Bytes($total_k) . "</td>";
-                                       }
-                                       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                               print "<td>&nbsp;</td>";
-                                       }
-                                       print "</tr>\n";
-                               }
-                               &tab_end();
-                               &html_end(1);
-                       }
-               }
-               if ( $HTMLOutput{'info'} ) {
+                                               my $tmprefererserver =
+                                                 $TmpRefererServer{$refererserver};
+                                               if ($tmprefererserver) {
+                                                       if ( $tmprefererserver eq '=' ) {
 
-                       # Not yet available
-                       print "$Center<a name=\"info\">&nbsp;</a><br />";
-                       &html_end(1);
-               }
+                                                 # Intern (This hit came from another page of the site)
+                                                               if ($PageBool) { $_from_p[4]++; }
+                                                               $_from_h[4]++;
+                                                               $found = 1;
+                                                       }
+                                                       else {
 
-               my $htmloutput = '';
-               foreach my $key ( keys %HTMLOutput ) { $htmloutput = $key; }
-               if ( $htmloutput =~ /^plugin_(\w+)$/ ) {
-                       my $pluginname = $1;
-                       print "$Center<a name=\"plugin_$pluginname\">&nbsp;</a><br />";
+                                                               # This hit came from a search engine
+                                                               if ($PageBool) {
+                                                                       $_from_p[2]++;
+                                                                       $_se_referrals_p{$tmprefererserver}++;
+                                                               }
+                                                               $_from_h[2]++;
+                                                               $_se_referrals_h{$tmprefererserver}++;
+                                                               $found = 1;
+                                                               if ( $PageBool && $LevelForKeywordsDetection ) {
 
-                       #                       my $function="AddHTMLGraph_$pluginname()";
-                       #                       eval("$function");
-                       my $function = "AddHTMLGraph_$pluginname";
-                       &$function();
-                       &html_end(1);
-               }
-       }
+                                                                       # we will complete %_keyphrases hash array
+                                                                       my @refurl =
+                                                                         split( /\?/, $field[$pos_referer], 2 )
+                                                                         ; # TODO Use \? or [$URLQuerySeparators] ?
+                                                                       if ( $refurl[1] ) {
 
-       # Output main page
-       #-----------------
+# Extract params of referer query string (q=cache:mmm:www/zzz+aaa+bbb q=aaa+bbb/ccc key=ddd%20eee lang_en ie=UTF-8 ...)
+                                                                               if (
+                                                                                       $SearchEnginesKnownUrl{
+                                                                                               $tmprefererserver} )
+                                                                               {  # Search engine with known URL syntax
+                                                                                       foreach my $param (
+                                                                                               split(
+                                                                                                       /&/,
+                                                                                                       $KeyWordsNotSensitive
+                                                                                                       ? lc( $refurl[1] )
+                                                                                                       : $refurl[1]
+                                                                                               )
+                                                                                         )
+                                                                                       {
+                                                                                               if ( $param =~
+s/^$SearchEnginesKnownUrl{$tmprefererserver}//
+                                                                                                 )
+                                                                                               {
 
-       if ( $HTMLOutput{'main'} ) {
+        # We found good parameter
+        # Now param is keyphrase: "cache:mmm:www/zzz+aaa+bbb/ccc+ddd%20eee'fff,ggg"
+                                                                                                       $param =~
+s/^(cache|related):[^\+]+//
+                                                                                                         ; # Should be useless since this is for hit on 'not pages'
+                                                                                                       &ChangeWordSeparatorsIntoSpace
+                                                                                                         ($param)
+                                                                                                         ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg]
+                                                                                                       $param =~ s/^ +//;
+                                                                                                       $param =~ s/ +$//;    # Trim
+                                                                                                       $param =~ tr/ /\+/s;
+                                                                                                       if ( ( length $param ) > 0 )
+                                                                                                       {
+                                                                                                               $_keyphrases{$param}++;
+                                                                                                       }
+                                                                                                       last;
+                                                                                               }
+                                                                                       }
+                                                                               }
+                                                                               elsif (
+                                                                                       $LevelForKeywordsDetection >= 2 )
+                                                                               { # Search engine with unknown URL syntax
+                                                                                       foreach my $param (
+                                                                                               split(
+                                                                                                       /&/,
+                                                                                                       $KeyWordsNotSensitive
+                                                                                                       ? lc( $refurl[1] )
+                                                                                                       : $refurl[1]
+                                                                                               )
+                                                                                         )
+                                                                                       {
+                                                                                               my $foundexcludeparam = 0;
+                                                                                               foreach my $paramtoexclude (
+                                                                                                       @WordsToCleanSearchUrl)
+                                                                                               {
+                                                                                                       if ( $param =~
+                                                                                                               /$paramtoexclude/i )
+                                                                                                       {
+                                                                                                               $foundexcludeparam = 1;
+                                                                                                               last;
+                                                                                                       } # Not the param with search criteria
+                                                                                               }
+                                                                                               if ($foundexcludeparam) {
+                                                                                                       next;
+                                                                                               }
 
-               # SUMMARY
-               #---------------------------------------------------------------------
-               if ($ShowSummary) {
-                       if ($Debug) { debug( "ShowSummary", 2 ); }
+                                                                                               # We found good parameter
+                                                                                               $param =~ s/.*=//;
+
+                                          # Now param is keyphrase: "aaa+bbb/ccc+ddd%20eee'fff,ggg"
+                                                                                               $param =~
+                                                                                                 s/^(cache|related):[^\+]+//
+                                                                                                 ; # Should be useless since this is for hit on 'not pages'
+                                                                                               &ChangeWordSeparatorsIntoSpace(
+                                                                                                       $param)
+                                                                                                 ; # Change [ aaa+bbb/ccc+ddd%20eee'fff,ggg ] into [ aaa bbb/ccc ddd eee fff ggg ]
+                                                                                               $param =~ s/^ +//;
+                                                                                               $param =~ s/ +$//;     # Trim
+                                                                                               $param =~ tr/ /\+/s;
+                                                                                               if ( ( length $param ) > 2 ) {
+                                                                                                       $_keyphrases{$param}++;
+                                                                                                       last;
+                                                                                               }
+                                                                                       }
+                                                                               }
+                                                                       }    # End of elsif refurl[1]
+                                                                       elsif (
+                                                                               $SearchEnginesWithKeysNotInQuery{
+                                                                                       $tmprefererserver} )
+                                                                       {
+
+#                                                                              debug("xxx".$refurl[0]);
+# If search engine with key inside page url like a9 (www.a9.com/searchkey1%20searchkey2)
+                                                                               if ( $refurl[0] =~
+/$SearchEnginesKnownUrl{$tmprefererserver}(.*)$/
+                                                                                 )
+                                                                               {
+                                                                                       my $param = $1;
+                                                                                       &ChangeWordSeparatorsIntoSpace(
+                                                                                               $param);
+                                                                                       $param =~ tr/ /\+/s;
+                                                                                       if ( ( length $param ) > 0 ) {
+                                                                                               $_keyphrases{$param}++;
+                                                                                       }
+                                                                               }
+                                                                       }
 
-                       #print "$Center<a name=\"summary\">&nbsp;</a><br />\n";
-                       my $title = "$Message[128]";
-                       &tab_head( "$title", 0, 0, 'month' );
+                                                               }
+                                                       }
+                                               }    # End of if ($TmpRefererServer)
+                                               else {
 
-                       my $NewLinkParams = ${QueryString};
-                       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-                       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-                       $NewLinkParams =~ s/^&amp;//;
-                       $NewLinkParams =~ s/&amp;$//;
-                       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
-                       my $NewLinkTarget = '';
+                                                 # This hit came from a site other than a search engine
+                                                       if ($PageBool) { $_from_p[3]++; }
+                                                       $_from_h[3]++;
 
-                       if ( $FrameName eq 'mainright' ) {
-                               $NewLinkTarget = " target=\"_parent\"";
-                       }
+# http://www.mysite.com/ must be same referer than http://www.mysite.com but .../mypage/ differs of .../mypage
+#if ($refurl[0] =~ /^[^\/]+\/$/) { $field[$pos_referer] =~ s/\/$//; }  # Code moved in Save_History
+# TODO: lowercase the value for referer server to have refering server not case sensitive
+                                                       if ($URLReferrerWithQuery) {
+                                                               if ($PageBool) {
+                                                                       $_pagesrefs_p{ $field[$pos_referer] }++;
+                                                               }
+                                                               $_pagesrefs_h{ $field[$pos_referer] }++;
+                                                       }
+                                                       else {
 
-                       # Ratio
-                       my $RatioVisits = 0;
-                       my $RatioPages  = 0;
-                       my $RatioHits   = 0;
-                       my $RatioBytes  = 0;
-                       if ( $TotalUnique > 0 ) {
-                               $RatioVisits = int( $TotalVisits / $TotalUnique * 100 ) / 100;
-                       }
-                       if ( $TotalVisits > 0 ) {
-                               $RatioPages = int( $TotalPages / $TotalVisits * 100 ) / 100;
-                       }
-                       if ( $TotalVisits > 0 ) {
-                               $RatioHits = int( $TotalHits / $TotalVisits * 100 ) / 100;
-                       }
-                       if ( $TotalVisits > 0 ) {
-                               $RatioBytes =
-                                 int( ( $TotalBytes / 1024 ) * 100 /
-                                         ( $LogType eq 'M' ? $TotalHits : $TotalVisits ) ) / 100;
-                       }
+                                                               # We discard query for referer
+                                                               if ( $field[$pos_referer] =~
+                                                                       /$regreferernoquery/o )
+                                                               {
+                                                                       if ($PageBool) { $_pagesrefs_p{"$1"}++; }
+                                                                       $_pagesrefs_h{"$1"}++;
+                                                               }
+                                                               else {
+                                                                       if ($PageBool) {
+                                                                               $_pagesrefs_p{ $field[$pos_referer] }++;
+                                                                       }
+                                                                       $_pagesrefs_h{ $field[$pos_referer] }++;
+                                                               }
+                                                       }
+                                                       $found = 1;
+                                               }
+                                       }
 
-                       my $colspan = 5;
-                       my $w       = '20';
-                       if ( $LogType eq 'W' || $LogType eq 'S' ) {
-                               $w       = '17';
-                               $colspan = 6;
+                                       # News Link ?
+                                       #if (! $found && $refererprot =~ /^news/i) {
+                                       #       $found=1;
+                                       #       if ($PageBool) { $_from_p[5]++; }
+                                       #       $_from_h[5]++;
+                                       #}
+                               }
                        }
 
-                       # Show first/last
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                       print
-"<td class=\"aws\"><b>$Message[133]</b></td><td class=\"aws\" colspan=\""
-                         . ( $colspan - 1 ) . "\">\n";
-                       print( $MonthRequired eq 'all'
-                               ? "$Message[6] $YearRequired"
-                               : "$Message[5] "
-                                 . $MonthNumLib{$MonthRequired}
-                                 . " $YearRequired"
-                       );
-                       print "</td></tr>\n";
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                       print "<td class=\"aws\"><b>$Message[8]</b></td>\n";
-                       print "<td class=\"aws\" colspan=\""
-                         . ( $colspan - 1 ) . "\">"
-                         . ( $FirstTime ? Format_Date( $FirstTime, 0 ) : "NA" ) . "</td>";
-                       print "</tr>\n";
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                       print "<td class=\"aws\"><b>$Message[9]</b></td>\n";
-                       print "<td class=\"aws\" colspan=\""
-                         . ( $colspan - 1 ) . "\">"
-                         . ( $LastTime ? Format_Date( $LastTime, 0 ) : "NA" )
-                         . "</td>\n";
-                       print "</tr>\n";
-
-                       # Show main indicators title row
-                       print "<tr>";
-                       if ( $LogType eq 'W' || $LogType eq 'S' ) {
-                               print "<td bgcolor=\"#$color_TableBGTitle\">&nbsp;</td>";
-                       }
-                       if ( $ShowSummary =~ /U/i ) {
-                               print "<td width=\"$w%\" bgcolor=\"#$color_u\""
-                                 . Tooltip(2)
-                                 . ">$Message[11]</td>";
-                       }
-                       else {
-                               print
-"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
-                       }
-                       if ( $ShowSummary =~ /V/i ) {
-                               print "<td width=\"$w%\" bgcolor=\"#$color_v\""
-                                 . Tooltip(1)
-                                 . ">$Message[10]</td>";
-                       }
-                       else {
-                               print
-"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
-                       }
-                       if ( $ShowSummary =~ /P/i ) {
-                               print "<td width=\"$w%\" bgcolor=\"#$color_p\""
-                                 . Tooltip(3)
-                                 . ">$Message[56]</td>";
-                       }
-                       else {
-                               print
-"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
-                       }
-                       if ( $ShowSummary =~ /H/i ) {
-                               print "<td width=\"$w%\" bgcolor=\"#$color_h\""
-                                 . Tooltip(4)
-                                 . ">$Message[57]</td>";
-                       }
-                       else {
-                               print
-"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
-                       }
-                       if ( $ShowSummary =~ /B/i ) {
-                               print "<td width=\"$w%\" bgcolor=\"#$color_k\""
-                                 . Tooltip(5)
-                                 . ">$Message[75]</td>";
-                       }
-                       else {
-                               print
-"<td bgcolor=\"#$color_TableBGTitle\" width=\"20%\">&nbsp;</td>";
+                       # Origin not found
+                       if ( !$found ) {
+                               if ($ShowUnknownOrigin) {
+                                       print "Unknown origin: $field[$pos_referer]\n";
+                               }
+                               if ($PageBool) { $_from_p[1]++; }
+                               $_from_h[1]++;
                        }
-                       print "</tr>\n";
 
-                       # Show main indicators values for viewed traffic
-                       print "<tr>";
-                       if ( $LogType eq 'M' ) {
-                               print "<td class=\"aws\">$Message[165]</td>";
-                               print "<td>&nbsp;<br />&nbsp;</td>\n";
-                               print "<td>&nbsp;<br />&nbsp;</td>\n";
-                               if ( $ShowSummary =~ /H/i ) {
-                                       print "<td><b>".Format_Number($TotalHits)."</b>"
-                                         . (
-                                               $LogType eq 'M'
-                                               ? ""
-                                               : "<br />($RatioHits&nbsp;"
-                                                 . lc( $Message[57] . "/" . $Message[12] ) . ")"
-                                         )
-                                         . "</td>";
+                       # Analyze: EMail
+                       #---------------
+                       if ( $pos_emails >= 0 && $field[$pos_emails] ) {
+                               if ( $field[$pos_emails] eq '<>' ) {
+                                       $field[$pos_emails] = 'Unknown';
                                }
-                               else { print "<td>&nbsp;</td>"; }
-                               if ( $ShowSummary =~ /B/i ) {
-                                       print "<td><b>"
-                                         . Format_Bytes( int($TotalBytes) )
-                                         . "</b><br />($RatioBytes&nbsp;$Message[108]/"
-                                         . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
-                                         . ")</td>";
+                               elsif ( $field[$pos_emails] !~ /\@/ ) {
+                                       $field[$pos_emails] .= "\@$SiteDomain";
                                }
-                               else { print "<td>&nbsp;</td>"; }
+                               $_emails_h{ lc( $field[$pos_emails] ) }
+                                 ++;    #Count accesses for sender email (hit)
+                               $_emails_k{ lc( $field[$pos_emails] ) } +=
+                                 int( $field[$pos_size] )
+                                 ;      #Count accesses for sender email (kb)
+                               $_emails_l{ lc( $field[$pos_emails] ) } = $timerecord;
                        }
-                       else {
-                               if ( $LogType eq 'W' || $LogType eq 'S' ) {
-                                       print "<td class=\"aws\">$Message[160]&nbsp;*</td>";
-                               }
-                               if ( $ShowSummary =~ /U/i ) {
-                                       print "<td>"
-                                         . (
-                                               $MonthRequired eq 'all'
-                                               ? "<b>&lt;= ".Format_Number($TotalUnique)."</b><br />$Message[129]"
-                                               : "<b>".Format_Number($TotalUnique)."</b><br />&nbsp;"
-                                         )
-                                         . "</td>";
-                               }
-                               else { print "<td>&nbsp;</td>"; }
-                               if ( $ShowSummary =~ /V/i ) {
-                                       print
-"<td><b>".Format_Number($TotalVisits)."</b><br />($RatioVisits&nbsp;$Message[52])</td>";
-                               }
-                               else { print "<td>&nbsp;</td>"; }
-                               if ( $ShowSummary =~ /P/i ) {
-                                       print "<td><b>".Format_Number($TotalPages)."</b><br />($RatioPages&nbsp;"
-                                         . $Message[56] . "/"
-                                         . $Message[12]
-                                         . ")</td>";
+                       if ( $pos_emailr >= 0 && $field[$pos_emailr] ) {
+                               if ( $field[$pos_emailr] !~ /\@/ ) {
+                                       $field[$pos_emailr] .= "\@$SiteDomain";
                                }
-                               else { print "<td>&nbsp;</td>"; }
-                               if ( $ShowSummary =~ /H/i ) {
-                                       print "<td><b>".Format_Number($TotalHits)."</b>"
-                                         . (
-                                               $LogType eq 'M'
-                                               ? ""
-                                               : "<br />($RatioHits&nbsp;"
-                                                 . $Message[57] . "/"
-                                                 . $Message[12] . ")"
-                                         )
-                                         . "</td>";
+                               $_emailr_h{ lc( $field[$pos_emailr] ) }
+                                 ++;    #Count accesses for receiver email (hit)
+                               $_emailr_k{ lc( $field[$pos_emailr] ) } +=
+                                 int( $field[$pos_size] )
+                                 ;      #Count accesses for receiver email (kb)
+                               $_emailr_l{ lc( $field[$pos_emailr] ) } = $timerecord;
+                       }
+               }
+
+               # Check cluster
+               #--------------
+               if ( $pos_cluster >= 0 ) {
+                       if ($PageBool) {
+                               $_cluster_p{ $field[$pos_cluster] }++;
+                       }    #Count accesses for page (page)
+                       $_cluster_h{ $field[$pos_cluster] }
+                         ++;    #Count accesses for page (hit)
+                       $_cluster_k{ $field[$pos_cluster] } +=
+                         int( $field[$pos_size] );    #Count accesses for page (kb)
+               }
+
+               # Analyze: Extra
+               #---------------
+               foreach my $extranum ( 1 .. @ExtraName - 1 ) {
+                       if ($Debug) { debug( "  Process extra analyze $extranum", 4 ); }
+
+                       # Check code
+                       my $conditionok = 0;
+                       if ( $ExtraCodeFilter[$extranum] ) {
+                               foreach
+                                 my $condnum ( 0 .. @{ $ExtraCodeFilter[$extranum] } - 1 )
+                               {
+                                       if ($Debug) {
+                                               debug(
+"  Check code '$field[$pos_code]' must be '$ExtraCodeFilter[$extranum][$condnum]'",
+                                                       5
+                                               );
+                                       }
+                                       if ( $field[$pos_code] eq
+                                               "$ExtraCodeFilter[$extranum][$condnum]" )
+                                       {
+                                               $conditionok = 1;
+                                               last;
+                                       }
                                }
-                               else { print "<td>&nbsp;</td>"; }
-                               if ( $ShowSummary =~ /B/i ) {
-                                       print "<td><b>"
-                                         . Format_Bytes( int($TotalBytes) )
-                                         . "</b><br />($RatioBytes&nbsp;$Message[108]/"
-                                         . $Message[ ( $LogType eq 'M' ? 149 : 12 ) ]
-                                         . ")</td>";
+                               if ( !$conditionok && @{ $ExtraCodeFilter[$extranum] } ) {
+                                       next;
+                               }    # End for this section
+                               if ($Debug) {
+                                       debug(
+"  No check on code or code is OK. Now we check other conditions.",
+                                               5
+                                       );
                                }
-                               else { print "<td>&nbsp;</td>"; }
                        }
-                       print "</tr>\n";
 
-                       # Show main indicators values for not viewed traffic values
-                       if ( $LogType eq 'M' || $LogType eq 'W' || $LogType eq 'S' ) {
-                               print "<tr>";
-                               if ( $LogType eq 'M' ) {
-                                       print "<td class=\"aws\">$Message[166]</td>";
-                                       print "<td>&nbsp;<br />&nbsp;</td>\n";
-                                       print "<td>&nbsp;<br />&nbsp;</td>\n";
-                                       if ( $ShowSummary =~ /H/i ) {
-                                               print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
+                       # Check conditions
+                       $conditionok = 0;
+                       foreach my $condnum ( 0 .. @{ $ExtraConditionType[$extranum] } - 1 )
+                       {
+                               my $conditiontype    = $ExtraConditionType[$extranum][$condnum];
+                               my $conditiontypeval =
+                                 $ExtraConditionTypeVal[$extranum][$condnum];
+                               if ( $conditiontype eq 'URL' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery'",
+                                                       5
+                                               );
                                        }
-                                       else { print "<td>&nbsp;</td>"; }
-                                       if ( $ShowSummary =~ /B/i ) {
-                                               print "<td><b>"
-                                                 . Format_Bytes( int($TotalNotViewedBytes) )
-                                                 . "</b></td>";
+                                       if ( $urlwithnoquery =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       else { print "<td>&nbsp;</td>"; }
                                }
-                               else {
-                                       if ( $LogType eq 'W' || $LogType eq 'S' ) {
-                                               print "<td class=\"aws\">$Message[161]&nbsp;*</td>";
+                               elsif ( $conditiontype eq 'QUERY_STRING' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$standalonequery'",
+                                                       5
+                                               );
                                        }
-                                       print "<td colspan=\"2\">&nbsp;<br />&nbsp;</td>\n";
-                                       if ( $ShowSummary =~ /P/i ) {
-                                               print "<td><b>".Format_Number($TotalNotViewedPages)."</b></td>";
+                                       if ( $standalonequery =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       else { print "<td>&nbsp;</td>"; }
-                                       if ( $ShowSummary =~ /H/i ) {
-                                               print "<td><b>".Format_Number($TotalNotViewedHits)."</b></td>";
+                               }
+                               elsif ( $conditiontype eq 'URLWITHQUERY' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$urlwithnoquery$tokenquery$standalonequery'",
+                                                       5
+                                               );
                                        }
-                                       else { print "<td>&nbsp;</td>"; }
-                                       if ( $ShowSummary =~ /B/i ) {
-                                               print "<td><b>"
-                                                 . Format_Bytes( int($TotalNotViewedBytes) )
-                                                 . "</b></td>";
+                                       if ( "$urlwithnoquery$tokenquery$standalonequery" =~
+                                               /$conditiontypeval/ )
+                                       {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       else { print "<td>&nbsp;</td>"; }
-                               }
-                               print "</tr>\n";
-                       }
-                       &tab_end($LogType eq 'W'
-                                 || $LogType eq 'S' ? "* $Message[159]" : "" );
-               }
-
-               # BY MONTH
-               #---------------------------------------------------------------------
-               if ($ShowMonthStats) {
-
-                       if ($Debug) { debug( "ShowMonthStats", 2 ); }
-                       print "$Center<a name=\"month\">&nbsp;</a><br />\n";
-                       my $title = "$Message[162]";
-                       &tab_head( "$title", 0, 0, 'month' );
-                       print "<tr><td align=\"center\">\n";
-                       print "<center>\n";
-
-                       $average_nb = $average_u = $average_v = $average_p = $average_h =
-                         $average_k = 0;
-                       $total_u     = $total_v = $total_p = $total_h = $total_k = 0;
-
-                       $max_v = $max_p = $max_h = $max_k = 1;
-
-                       # Define total and max
-                       for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                               my $monthix = sprintf( "%02s", $ix );
-                               $total_u += $MonthUnique{ $YearRequired . $monthix } || 0;
-                               $total_v += $MonthVisits{ $YearRequired . $monthix } || 0;
-                               $total_p += $MonthPages{ $YearRequired . $monthix }  || 0;
-                               $total_h += $MonthHits{ $YearRequired . $monthix }   || 0;
-                               $total_k += $MonthBytes{ $YearRequired . $monthix }  || 0;
-
-#if (($MonthUnique{$YearRequired.$monthix}||0) > $max_v) { $max_v=$MonthUnique{$YearRequired.$monthix}; }
-                               if (
-                                       ( $MonthVisits{ $YearRequired . $monthix } || 0 ) > $max_v )
-                               {
-                                       $max_v = $MonthVisits{ $YearRequired . $monthix };
-                               }
-
-#if (($MonthPages{$YearRequired.$monthix}||0) > $max_p)  { $max_p=$MonthPages{$YearRequired.$monthix}; }
-                               if ( ( $MonthHits{ $YearRequired . $monthix } || 0 ) > $max_h )
-                               {
-                                       $max_h = $MonthHits{ $YearRequired . $monthix };
-                               }
-                               if ( ( $MonthBytes{ $YearRequired . $monthix } || 0 ) > $max_k )
-                               {
-                                       $max_k = $MonthBytes{ $YearRequired . $monthix };
                                }
-                       }
-
-                       # Define average
-                       # TODO
-
-                       # Show bars for month
-                       my $graphdone=0;
-                       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
-                       {
-                               my @blocklabel = ();
-                               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                                       my $monthix = sprintf( "%02s", $ix );
-                                       push @blocklabel,
-                                         "$MonthNumLib{$monthix}\n$YearRequired";
+                               elsif ( $conditiontype eq 'REFERER' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_referer]'",
+                                                       5
+                                               );
+                                       }
+                                       if ( $field[$pos_referer] =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
+                                       }
                                }
-                               my @vallabel = (
-                                       "$Message[11]", "$Message[10]",
-                                       "$Message[56]", "$Message[57]",
-                                       "$Message[75]"
-                               );
-                               my @valcolor =
-                                 ( "$color_u", "$color_v", "$color_p", "$color_h",
-                                       "$color_k" );
-                               my @valmax = ( $max_v, $max_v, $max_h, $max_h, $max_k );
-                               my @valtotal =
-                                 ( $total_u, $total_v, $total_p, $total_h, $total_k );
-                               my @valaverage = ();
-
-                               #my @valaverage=($average_v,$average_p,$average_h,$average_k);
-                               my @valdata = ();
-                               my $xx      = 0;
-                               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                                       my $monthix = sprintf( "%02s", $ix );
-                                       $valdata[ $xx++ ] = $MonthUnique{ $YearRequired . $monthix }
-                                         || 0;
-                                       $valdata[ $xx++ ] = $MonthVisits{ $YearRequired . $monthix }
-                                         || 0;
-                                       $valdata[ $xx++ ] = $MonthPages{ $YearRequired . $monthix }
-                                         || 0;
-                                       $valdata[ $xx++ ] = $MonthHits{ $YearRequired . $monthix }
-                                         || 0;
-                                       $valdata[ $xx++ ] = $MonthBytes{ $YearRequired . $monthix }
-                                         || 0;
-                               }
-                               
-                               my $function = "ShowGraph_$pluginname";
-                               &$function(
-                                       "$title",        "month",
-                                       $ShowMonthStats, \@blocklabel,
-                                       \@vallabel,      \@valcolor,
-                                       \@valmax,        \@valtotal,
-                                       \@valaverage,    \@valdata
-                               );
-                               $graphdone=1;
-                       }
-                       if (! $graphdone)
-                       {
-                               print "<table>\n";
-                               print "<tr valign=\"bottom\">";
-                               print "<td>&nbsp;</td>\n";
-                               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                                       my $monthix  = sprintf( "%02s", $ix );
-                                       my $bredde_u = 0;
-                                       my $bredde_v = 0;
-                                       my $bredde_p = 0;
-                                       my $bredde_h = 0;
-                                       my $bredde_k = 0;
-                                       if ( $max_v > 0 ) {
-                                               $bredde_u =
-                                                 int(
-                                                       ( $MonthUnique{ $YearRequired . $monthix } || 0 ) /
-                                                         $max_v * $BarHeight ) + 1;
+                               elsif ( $conditiontype eq 'UA' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_agent]'",
+                                                       5
+                                               );
                                        }
-                                       if ( $max_v > 0 ) {
-                                               $bredde_v =
-                                                 int(
-                                                       ( $MonthVisits{ $YearRequired . $monthix } || 0 ) /
-                                                         $max_v * $BarHeight ) + 1;
+                                       if ( $field[$pos_agent] =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_p =
-                                                 int(
-                                                       ( $MonthPages{ $YearRequired . $monthix } || 0 ) /
-                                                         $max_h * $BarHeight ) + 1;
+                               }
+                               elsif ( $conditiontype eq 'HOSTINLOG' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_host]'",
+                                                       5
+                                               );
                                        }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_h =
-                                                 int( ( $MonthHits{ $YearRequired . $monthix } || 0 ) /
-                                                         $max_h * $BarHeight ) + 1;
+                                       if ( $field[$pos_host] =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       if ( $max_k > 0 ) {
-                                               $bredde_k =
-                                                 int(
-                                                       ( $MonthBytes{ $YearRequired . $monthix } || 0 ) /
-                                                         $max_k * $BarHeight ) + 1;
+                               }
+                               elsif ( $conditiontype eq 'HOST' ) {
+                                       my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$hosttouse'",
+                                                       5
+                                               );
                                        }
-                                       print "<td>";
-                                       if ( $ShowMonthStats =~ /U/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vu'}\" height=\"$bredde_u\" width=\"6\""
-                                                 . AltTitle( "$Message[11]: "
-                                                         . ( $MonthUnique{ $YearRequired . $monthix }
-                                                                 || 0 ) )
-                                                 . " />";
+                                       if ( $hosttouse =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       if ( $ShowMonthStats =~ /V/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"6\""
-                                                 . AltTitle( "$Message[10]: "
-                                                         . ( $MonthVisits{ $YearRequired . $monthix }
-                                                                 || 0 ) )
-                                                 . " />";
+                               }
+                               elsif ( $conditiontype eq 'VHOST' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condision '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_vh]'",
+                                                       5
+                                               );
                                        }
-                                       if ( $ShowMonthStats =~ /P/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
-                                                 . AltTitle( "$Message[56]: "
-                                                         . ( $MonthPages{ $YearRequired . $monthix } || 0 )
-                                                 )
-                                                 . " />";
+                                       if ( $field[$pos_vh] =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       if ( $ShowMonthStats =~ /H/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
-                                                 . AltTitle( "$Message[57]: "
-                                                         . ( $MonthHits{ $YearRequired . $monthix } || 0 )
-                                                 )
-                                                 . " />";
+                               }
+                               elsif ( $conditiontype =~ /extra(\d+)/i ) {
+                                       if ($Debug) {
+                                               debug(
+"  Check condition '$conditiontype' must contain '$conditiontypeval' in '$field[$pos_extra[$1]]'",
+                                                       5
+                                               );
                                        }
-                                       if ( $ShowMonthStats =~ /B/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
-                                                 . AltTitle(
-                                                       "$Message[75]: "
-                                                         . Format_Bytes(
-                                                               $MonthBytes{ $YearRequired . $monthix }
-                                                         )
-                                                 )
-                                                 . " />";
+                                       if ( $field[ $pos_extra[$1] ] =~ /$conditiontypeval/ ) {
+                                               $conditionok = 1;
+                                               last;
                                        }
-                                       print "</td>\n";
                                }
-                               print "<td>&nbsp;</td>";
-                               print "</tr>\n";
-
-                               # Show lib for month
-                               print "<tr valign=\"middle\">";
-
-#                              if (!$StaticLinks) {
-#                                      print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=12&year=".($YearRequired-1))."\">&lt;&lt;</a></td>";
-#                              }
-#                              else {
-                               print "<td>&nbsp;</td>";
-
-                               #                               }
-                               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                                       my $monthix = sprintf( "%02s", $ix );
-
-#                                      if (!$StaticLinks) {
-#                                              print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=$monthix&year=$YearRequired")."\">$MonthNumLib{$monthix}<br />$YearRequired</a></td>";
-#                                      }
-#                                      else {
-                                       print "<td>"
-                                         . (
-                                               !$StaticLinks
-                                                 && $monthix == $nowmonth
-                                                 && $YearRequired == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                         );
-                                       print "$MonthNumLib{$monthix}<br />$YearRequired";
-                                       print(   !$StaticLinks
-                                                 && $monthix == $nowmonth
-                                                 && $YearRequired == $nowyear ? '</font>' : '' );
-                                       print "</td>";
-
-                                       #                                       }
+                               else {
+                                       error(
+"Wrong value of parameter ExtraSectionCondition$extranum"
+                                       );
                                }
-
-#                              if (!$StaticLinks) {
-#                                      print "<td><a href=\"".XMLEncode("$AWScript?${NewLinkParams}month=1&year=".($YearRequired+1))."\">&gt;&gt;</a></td>";
-#                              }
-#                              else {
-                               print "<td>&nbsp;</td>";
-
-                               #                               }
-                               print "</tr>\n";
-                               print "</table>\n";
                        }
-                       print "<br />\n";
+                       if ( !$conditionok && @{ $ExtraConditionType[$extranum] } ) {
+                               next;
+                       }    # End for this section
+                       if ($Debug) {
+                               debug(
+"  No condition or condition is OK. Now we extract value for first column of extra chart.",
+                                       5
+                               );
+                       }
 
-                       # Show data array for month
-                       if ($AddDataArrayMonthStats) {
-                               print "<table>\n";
-                               print
-"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[5]</td>";
-                               if ( $ShowMonthStats =~ /U/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_u\""
-                                         . Tooltip(2)
-                                         . ">$Message[11]</td>";
-                               }
-                               if ( $ShowMonthStats =~ /V/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_v\""
-                                         . Tooltip(1)
-                                         . ">$Message[10]</td>";
-                               }
-                               if ( $ShowMonthStats =~ /P/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
-                                         . Tooltip(3)
-                                         . ">$Message[56]</td>";
-                               }
-                               if ( $ShowMonthStats =~ /H/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
-                                         . Tooltip(4)
-                                         . ">$Message[57]</td>";
-                               }
-                               if ( $ShowMonthStats =~ /B/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
-                                         . Tooltip(5)
-                                         . ">$Message[75]</td>";
-                               }
-                               print "</tr>\n";
-                               for ( my $ix = 1 ; $ix <= 12 ; $ix++ ) {
-                                       my $monthix = sprintf( "%02s", $ix );
-                                       print "<tr>";
-                                       print "<td>"
-                                         . (
-                                               !$StaticLinks
-                                                 && $monthix == $nowmonth
-                                                 && $YearRequired == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                         );
-                                       print "$MonthNumLib{$monthix} $YearRequired";
-                                       print(   !$StaticLinks
-                                                 && $monthix == $nowmonth
-                                                 && $YearRequired == $nowyear ? '</font>' : '' );
-                                       print "</td>";
-                                       if ( $ShowMonthStats =~ /U/i ) {
-                                               print "<td>",
-                                                 Format_Number($MonthUnique{ $YearRequired . $monthix }
-                                                 ? $MonthUnique{ $YearRequired . $monthix }
-                                                 : "0"), "</td>";
+                       # Determine actual column value to use.
+                       my $rowkeyval;
+                       my $rowkeyok = 0;
+                       foreach my $rowkeynum (
+                               0 .. @{ $ExtraFirstColumnValuesType[$extranum] } - 1 )
+                       {
+                               my $rowkeytype =
+                                 $ExtraFirstColumnValuesType[$extranum][$rowkeynum];
+                               my $rowkeytypeval =
+                                 $ExtraFirstColumnValuesTypeVal[$extranum][$rowkeynum];
+                               if ( $rowkeytype eq 'URL' ) {
+                                       if ( $urlwithnoquery =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
                                        }
-                                       if ( $ShowMonthStats =~ /V/i ) {
-                                               print "<td>",
-                                                 Format_Number($MonthVisits{ $YearRequired . $monthix }
-                                                 ? $MonthVisits{ $YearRequired . $monthix }
-                                                 : "0"), "</td>";
+                               }
+                               elsif ( $rowkeytype eq 'QUERY_STRING' ) {
+                                       if ($Debug) {
+                                               debug(
+"  Extract value from '$standalonequery' with regex '$rowkeytypeval'.",
+                                                       5
+                                               );
                                        }
-                                       if ( $ShowMonthStats =~ /P/i ) {
-                                               print "<td>",
-                                                 Format_Number($MonthPages{ $YearRequired . $monthix }
-                                                 ? $MonthPages{ $YearRequired . $monthix }
-                                                 : "0"), "</td>";
+                                       if ( $standalonequery =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
                                        }
-                                       if ( $ShowMonthStats =~ /H/i ) {
-                                               print "<td>",
-                                                 Format_Number($MonthHits{ $YearRequired . $monthix }
-                                                 ? $MonthHits{ $YearRequired . $monthix }
-                                                 : "0"), "</td>";
+                               }
+                               elsif ( $rowkeytype eq 'URLWITHQUERY' ) {
+                                       if ( "$urlwithnoquery$tokenquery$standalonequery" =~
+                                               /$rowkeytypeval/ )
+                                       {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
                                        }
-                                       if ( $ShowMonthStats =~ /B/i ) {
-                                               print "<td>",
-                                                 Format_Bytes(
-                                                       int( $MonthBytes{ $YearRequired . $monthix } || 0 )
-                                                 ), "</td>";
+                               }
+                               elsif ( $rowkeytype eq 'REFERER' ) {
+                                       if ( $field[$pos_referer] =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
                                        }
-                                       print "</tr>\n";
                                }
-
-                               # Average row
-                               # TODO
-                               # Total row
-                               print
-"<tr><td bgcolor=\"#$color_TableBGRowTitle\">$Message[102]</td>";
-                               if ( $ShowMonthStats =~ /U/i ) {
-                                       print
-                                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_u)."</td>";
+                               elsif ( $rowkeytype eq 'UA' ) {
+                                       if ( $field[$pos_agent] =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
+                                       }
                                }
-                               if ( $ShowMonthStats =~ /V/i ) {
-                                       print
-                                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_v)."</td>";
+                               elsif ( $rowkeytype eq 'HOSTINLOG' ) {
+                                       if ( $field[$pos_host] =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
+                                       }
                                }
-                               if ( $ShowMonthStats =~ /P/i ) {
-                                       print
-                                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_p)."</td>";
+                               elsif ( $rowkeytype eq 'HOST' ) {
+                                       my $hosttouse = ( $HostResolved ? $HostResolved : $Host );
+                                       if ( $hosttouse =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
+                                       }
                                }
-                               if ( $ShowMonthStats =~ /H/i ) {
-                                       print
-                                         "<td bgcolor=\"#$color_TableBGRowTitle\">".Format_Number($total_h)."</td>";
+                               elsif ( $rowkeytype eq 'VHOST' ) {
+                                       if ( $field[$pos_vh] =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
+                                       }
                                }
-                               if ( $ShowMonthStats =~ /B/i ) {
-                                       print "<td bgcolor=\"#$color_TableBGRowTitle\">"
-                                         . Format_Bytes($total_k) . "</td>";
+                               elsif ( $rowkeytype =~ /extra(\d+)/i ) {
+                                       if ( $field[ $pos_extra[$1] ] =~ /$rowkeytypeval/ ) {
+                                               $rowkeyval = "$1";
+                                               $rowkeyok  = 1;
+                                               last;
+                                       }
+                               }
+                               else {
+                                       error(
+"Wrong value of parameter ExtraSectionFirstColumnValues$extranum"
+                                       );
                                }
-                               print "</tr>\n";
-                               print "</table>\n<br />\n";
-                       }
-
-                       print "</center>\n";
-                       print "</td></tr>\n";
-                       &tab_end();
-               }
-
-               print "\n<a name=\"when\">&nbsp;</a>\n\n";
-
-               # BY DAY OF MONTH
-               #---------------------------------------------------------------------
-               if ($ShowDaysOfMonthStats) {
-                       if ($Debug) { debug( "ShowDaysOfMonthStats", 2 ); }
-                       print "$Center<a name=\"daysofmonth\">&nbsp;</a><br />\n";
-                       my $title = "$Message[138]";
-                       &tab_head( "$title", 0, 0, 'daysofmonth' );
-                       print "<tr>";
-                       print "<td align=\"center\">\n";
-                       print "<center>\n";
-
-                       my $NewLinkParams = ${QueryString};
-                       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)year=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)month=[^&]*//i;
-                       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
-                       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
-                       $NewLinkParams =~ s/^&amp;//;
-                       $NewLinkParams =~ s/&amp;$//;
-                       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
-                       my $NewLinkTarget = '';
-
-                       if ( $FrameName eq 'mainright' ) {
-                               $NewLinkTarget = " target=\"_parent\"";
                        }
+                       if ( !$rowkeyok ) { next; }    # End for this section
+                       if ( !$rowkeyval ) { $rowkeyval = 'Failed to extract key'; }
+                       if ($Debug) { debug( "  Key val found: $rowkeyval", 5 ); }
 
-                       $average_nb = $average_u = $average_v = $average_p = $average_h =
-                         $average_k = 0;
-                       $total_u     = $total_v = $total_p = $total_h = $total_k = 0;
+                       # Apply function on $rowkeyval
+                       if ( $ExtraFirstColumnFunction[$extranum] ) {
 
-                       # Define total and max
-                       $max_v = $max_h = $max_k =
-                         0;    # Start from 0 because can be lower than 1
-                       foreach my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                       {
-                               $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                               my $year  = $1;
-                               my $month = $2;
-                               my $day   = $3;
-                               if ( !DateIsValid( $day, $month, $year ) ) {
-                                       next;
-                               }    # If not an existing day, go to next
-                               $total_v += $DayVisits{ $year . $month . $day } || 0;
-                               $total_p += $DayPages{ $year . $month . $day }  || 0;
-                               $total_h += $DayHits{ $year . $month . $day }   || 0;
-                               $total_k += $DayBytes{ $year . $month . $day }  || 0;
-                               if ( ( $DayVisits{ $year . $month . $day } || 0 ) > $max_v ) {
-                                       $max_v = $DayVisits{ $year . $month . $day };
-                               }
+                               # Todo call function on string $rowkeyval
+                       }
 
-#if (($DayPages{$year.$month.$day}||0) > $max_p)  { $max_p=$DayPages{$year.$month.$day}; }
-                               if ( ( $DayHits{ $year . $month . $day } || 0 ) > $max_h ) {
-                                       $max_h = $DayHits{ $year . $month . $day };
-                               }
-                               if ( ( $DayBytes{ $year . $month . $day } || 0 ) > $max_k ) {
-                                       $max_k = $DayBytes{ $year . $month . $day };
+                       # Here we got all values to increase counters
+                       if ( $PageBool && $ExtraStatTypes[$extranum] =~ /P/i ) {
+                               ${ '_section_' . $extranum . '_p' }{$rowkeyval}++;
+                       }
+                       ${ '_section_' . $extranum . '_h' }{$rowkeyval}++;    # Must be set
+                       if ( $ExtraStatTypes[$extranum] =~ /B/i ) {
+                               ${ '_section_' . $extranum . '_k' }{$rowkeyval} +=
+                                 int( $field[$pos_size] );
+                       }
+                       if ( $ExtraStatTypes[$extranum] =~ /L/i ) {
+                               if ( ${ '_section_' . $extranum . '_l' }{$rowkeyval}
+                                       || 0 < $timerecord )
+                               {
+                                       ${ '_section_' . $extranum . '_l' }{$rowkeyval} =
+                                         $timerecord;
                                }
                        }
 
-                       # Define average
-                       foreach my $daycursor (
-                               $firstdaytocountaverage .. $lastdaytocountaverage )
+                       # Check to avoid too large extra sections
+                       if (
+                               scalar keys %{ '_section_' . $extranum . '_h' } >
+                               $ExtraTrackedRowsLimit )
                        {
-                               $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                               my $year  = $1;
-                               my $month = $2;
-                               my $day   = $3;
-                               if ( !DateIsValid( $day, $month, $year ) ) {
-                                       next;
-                               }                 # If not an existing day, go to next
-                               $average_nb++;    # Increase number of day used to count
-                               $average_v += ( $DayVisits{$daycursor} || 0 );
-                               $average_p += ( $DayPages{$daycursor}  || 0 );
-                               $average_h += ( $DayHits{$daycursor}   || 0 );
-                               $average_k += ( $DayBytes{$daycursor}  || 0 );
-                       }
-                       if ($average_nb) {
-                               $average_v = $average_v / $average_nb;
-                               $average_p = $average_p / $average_nb;
-                               $average_h = $average_h / $average_nb;
-                               $average_k = $average_k / $average_nb;
-                               if ( $average_v > $max_v ) { $max_v = $average_v; }
-
-                               #if ($average_p > $max_p) { $max_p=$average_p; }
-                               if ( $average_h > $max_h ) { $max_h = $average_h; }
-                               if ( $average_k > $max_k ) { $max_k = $average_k; }
-                       }
-                       else {
-                               $average_v = "?";
-                               $average_p = "?";
-                               $average_h = "?";
-                               $average_k = "?";
+                               error(<<END_ERROR_TEXT);
+The number of values found for extra section $extranum has grown too large.
+In order to prevent awstats from using an excessive amount of memory, the number
+of values is currently limited to $ExtraTrackedRowsLimit. Perhaps you should consider
+revising extract parameters for extra section $extranum. If you are certain you
+want to track such a large data set, you can increase the limit by setting
+ExtraTrackedRowsLimit in your awstats configuration file.
+END_ERROR_TEXT
                        }
+               }
 
-                       # Show bars for day
-                       my $graphdone=0;
-                       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
+# Every 20,000 approved lines after a flush, we test to clean too large hash arrays to flush data in tmp file
+               if ( ++$counterforflushtest >= 20000 ) {
+
+                       #if (++$counterforflushtest >= 1) {
+                       if (   ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 )
+                               || ( scalar keys %_url_p ) > $LIMITFLUSH )
                        {
-                               my @blocklabel = ();
-                               foreach
-                                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                               {
-                                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                                       my $year  = $1;
-                                       my $month = $2;
-                                       my $day   = $3;
-                                       if ( !DateIsValid( $day, $month, $year ) ) {
-                                               next;
-                                       }    # If not an existing day, go to next
-                                       my $bold =
-                                         (      $day == $nowday
-                                                 && $month == $nowmonth
-                                                 && $year == $nowyear ? ':' : '' );
-                                       my $weekend =
-                                         ( DayOfWeek( $day, $month, $year ) =~ /[06]/ ? '!' : '' );
-                                       push @blocklabel,
-                                         "$day\n$MonthNumLib{$month}$weekend$bold";
-                               }
-                               my @vallabel = (
-                                       "$Message[10]", "$Message[56]",
-                                       "$Message[57]", "$Message[75]"
-                               );
-                               my @valcolor =
-                                 ( "$color_v", "$color_p", "$color_h", "$color_k" );
-                               my @valmax   = ( $max_v,   $max_h,   $max_h,   $max_k );
-                               my @valtotal = ( $total_v, $total_p, $total_h, $total_k );
-                               $average_v = sprintf( "%.2f", $average_v );
-                               $average_p = sprintf( "%.2f", $average_p );
-                               $average_h = sprintf( "%.2f", $average_h );
-                               $average_k = (
-                                       int($average_k)
-                                       ? Format_Bytes( sprintf( "%.2f", $average_k ) )
-                                       : "0.00"
-                               );
-                               my @valaverage =
-                                 ( $average_v, $average_p, $average_h, $average_k );
-                               my @valdata = ();
-                               my $xx      = 0;
 
-                               foreach
-                                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                               {
-                                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                                       my $year  = $1;
-                                       my $month = $2;
-                                       my $day   = $3;
-                                       if ( !DateIsValid( $day, $month, $year ) ) {
-                                               next;
-                                       }    # If not an existing day, go to next
-                                       $valdata[ $xx++ ] = $DayVisits{ $year . $month . $day }
-                                         || 0;
-                                       $valdata[ $xx++ ] = $DayPages{ $year . $month . $day } || 0;
-                                       $valdata[ $xx++ ] = $DayHits{ $year . $month . $day }  || 0;
-                                       $valdata[ $xx++ ] = $DayBytes{ $year . $month . $day } || 0;
+# warning("Warning: Try to run AWStats update process more frequently to analyze smaler log files.");
+                               if ( $^X =~ /activestate/i || $^X =~ /activeperl/i ) {
+
+# We don't flush if perl is activestate to avoid slowing process because of memory hole
                                }
-                               my $function = "ShowGraph_$pluginname";
-                               &$function(
-                                       "$title",              "daysofmonth",
-                                       $ShowDaysOfMonthStats, \@blocklabel,
-                                       \@vallabel,            \@valcolor,
-                                       \@valmax,              \@valtotal,
-                                       \@valaverage,          \@valdata
-                               );
-                               $graphdone=1;
-                       }
-                       if (! $graphdone) {
-                               print "<table>\n";
-                               print "<tr valign=\"bottom\">\n";
-                               foreach
-                                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                               {
-                                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                                       my $year  = $1;
-                                       my $month = $2;
-                                       my $day   = $3;
-                                       if ( !DateIsValid( $day, $month, $year ) ) {
-                                               next;
-                                       }    # If not an existing day, go to next
-                                       my $bredde_v = 0;
-                                       my $bredde_p = 0;
-                                       my $bredde_h = 0;
-                                       my $bredde_k = 0;
-                                       if ( $max_v > 0 ) {
-                                               $bredde_v =
-                                                 int( ( $DayVisits{ $year . $month . $day } || 0 ) /
-                                                         $max_v * $BarHeight ) + 1;
-                                       }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_p =
-                                                 int( ( $DayPages{ $year . $month . $day } || 0 ) /
-                                                         $max_h * $BarHeight ) + 1;
-                                       }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_h =
-                                                 int( ( $DayHits{ $year . $month . $day } || 0 ) /
-                                                         $max_h * $BarHeight ) + 1;
-                                       }
-                                       if ( $max_k > 0 ) {
-                                               $bredde_k =
-                                                 int( ( $DayBytes{ $year . $month . $day } || 0 ) /
-                                                         $max_k * $BarHeight ) + 1;
-                                       }
-                                       print "<td>";
-                                       if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
-                                                 . AltTitle( "$Message[10]: "
-                                                         . int( $DayVisits{ $year . $month . $day } || 0 )
-                                                 )
-                                                 . " />";
-                                       }
-                                       if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
-                                                 . AltTitle( "$Message[56]: "
-                                                         . int( $DayPages{ $year . $month . $day } || 0 ) )
-                                                 . " />";
+                               else {
+
+                                       # Clean tmp hash arrays
+                                       #%TmpDNSLookup = ();
+                                       %TmpOS = %TmpRefererServer = %TmpRobot = %TmpBrowser = ();
+
+                                       # We flush if perl is not activestate
+                                       print "Flush history file on disk";
+                                       if ( ( scalar keys %_host_u ) > ( $LIMITFLUSH << 2 ) ) {
+                                               print " (unique hosts reach flush limit of "
+                                                 . ( $LIMITFLUSH << 2 ) . ")";
                                        }
-                                       if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
-                                                 . AltTitle( "$Message[57]: "
-                                                         . int( $DayHits{ $year . $month . $day } || 0 ) )
-                                                 . " />";
+                                       if ( ( scalar keys %_url_p ) > $LIMITFLUSH ) {
+                                               print " (unique url reach flush limit of "
+                                                 . ($LIMITFLUSH) . ")";
                                        }
-                                       if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
-                                                 . AltTitle(
-                                                       "$Message[75]: "
-                                                         . Format_Bytes(
-                                                               $DayBytes{ $year . $month . $day }
-                                                         )
-                                                 )
-                                                 . " />";
+                                       print "\n";
+                                       if ($Debug) {
+                                               debug(
+"End of set of $counterforflushtest records: Some hash arrays are too large. We flush and clean some.",
+                                                       2
+                                               );
+                                               print " _host_p:"
+                                                 . ( scalar keys %_host_p )
+                                                 . " _host_h:"
+                                                 . ( scalar keys %_host_h )
+                                                 . " _host_k:"
+                                                 . ( scalar keys %_host_k )
+                                                 . " _host_l:"
+                                                 . ( scalar keys %_host_l )
+                                                 . " _host_s:"
+                                                 . ( scalar keys %_host_s )
+                                                 . " _host_u:"
+                                                 . ( scalar keys %_host_u ) . "\n";
+                                               print " _url_p:"
+                                                 . ( scalar keys %_url_p )
+                                                 . " _url_k:"
+                                                 . ( scalar keys %_url_k )
+                                                 . " _url_e:"
+                                                 . ( scalar keys %_url_e )
+                                                 . " _url_x:"
+                                                 . ( scalar keys %_url_x ) . "\n";
+                                               print " _waithost_e:"
+                                                 . ( scalar keys %_waithost_e )
+                                                 . " _waithost_l:"
+                                                 . ( scalar keys %_waithost_l )
+                                                 . " _waithost_s:"
+                                                 . ( scalar keys %_waithost_s )
+                                                 . " _waithost_u:"
+                                                 . ( scalar keys %_waithost_u ) . "\n";
                                        }
-                                       print "</td>\n";
+                                       &Read_History_With_TmpUpdate(
+                                               $lastprocessedyear,
+                                               $lastprocessedmonth,
+                                               $lastprocessedday,
+                                               $lastprocessedhour,
+                                               1,
+                                               1,
+                                               "all",
+                                               ( $lastlinenb + $NbOfLinesParsed ),
+                                               $lastlineoffset,
+                                               &CheckSum($_)
+                                       );
+                                       &GetDelaySinceStart(1);
+                                       $NbOfLinesShowsteps = 1;
                                }
-                               print "<td>&nbsp;</td>";
+                       }
+                       $counterforflushtest = 0;
+               }
+
+       }    # End of loop for processing new record.
+
+       if ($Debug) {
+               debug(
+                       " _host_p:"
+                         . ( scalar keys %_host_p )
+                         . " _host_h:"
+                         . ( scalar keys %_host_h )
+                         . " _host_k:"
+                         . ( scalar keys %_host_k )
+                         . " _host_l:"
+                         . ( scalar keys %_host_l )
+                         . " _host_s:"
+                         . ( scalar keys %_host_s )
+                         . " _host_u:"
+                         . ( scalar keys %_host_u ) . "\n",
+                       1
+               );
+               debug(
+                       " _url_p:"
+                         . ( scalar keys %_url_p )
+                         . " _url_k:"
+                         . ( scalar keys %_url_k )
+                         . " _url_e:"
+                         . ( scalar keys %_url_e )
+                         . " _url_x:"
+                         . ( scalar keys %_url_x ) . "\n",
+                       1
+               );
+               debug(
+                       " _waithost_e:"
+                         . ( scalar keys %_waithost_e )
+                         . " _waithost_l:"
+                         . ( scalar keys %_waithost_l )
+                         . " _waithost_s:"
+                         . ( scalar keys %_waithost_s )
+                         . " _waithost_u:"
+                         . ( scalar keys %_waithost_u ) . "\n",
+                       1
+               );
+               debug(
+                       "End of processing log file (AWStats memory cache is TmpDNSLookup="
+                         . ( scalar keys %TmpDNSLookup )
+                         . " TmpBrowser="
+                         . ( scalar keys %TmpBrowser )
+                         . " TmpOS="
+                         . ( scalar keys %TmpOS )
+                         . " TmpRefererServer="
+                         . ( scalar keys %TmpRefererServer )
+                         . " TmpRobot="
+                         . ( scalar keys %TmpRobot ) . ")",
+                       1
+               );
+       }
+
+# Save current processed break section
+# If lastprocesseddate > 0 means there is at least one approved new record in log or at least one existing history file
+       if ( $lastprocesseddate > 0 )
+       {    # TODO: Do not save if we are sure a flush was just already done
+                   # Get last line
+               seek( LOG, $lastlineoffset, 0 );
+               my $line = <LOG>;
+               chomp $line;
+               $line =~ s/\r$//;
+               if ( !$NbOfLinesParsed ) {
+
+# TODO If there was no lines parsed (log was empty), we only update LastUpdate line with YYYYMMDDHHMMSS 0 0 0 0 0
+                       &Read_History_With_TmpUpdate(
+                               $lastprocessedyear, $lastprocessedmonth,
+                               $lastprocessedday,  $lastprocessedhour,
+                               1,                  1,
+                               "all", ( $lastlinenb + $NbOfLinesParsed ),
+                               $lastlineoffset, &CheckSum($line)
+                       );
+               }
+               else {
+                       &Read_History_With_TmpUpdate(
+                               $lastprocessedyear, $lastprocessedmonth,
+                               $lastprocessedday,  $lastprocessedhour,
+                               1,                  1,
+                               "all", ( $lastlinenb + $NbOfLinesParsed ),
+                               $lastlineoffset, &CheckSum($line)
+                       );
+               }
+       }
 
-                               # Show average value cell
-                               print "<td>";
-                               my $bredde_v = 0;
-                               my $bredde_p = 0;
-                               my $bredde_h = 0;
-                               my $bredde_k = 0;
-                               if ( $max_v > 0 ) {
-                                       $bredde_v = int( $average_v / $max_v * $BarHeight ) + 1;
-                               }
-                               if ( $max_h > 0 ) {
-                                       $bredde_p = int( $average_p / $max_h * $BarHeight ) + 1;
-                               }
-                               if ( $max_h > 0 ) {
-                                       $bredde_h = int( $average_h / $max_h * $BarHeight ) + 1;
-                               }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k = int( $average_k / $max_k * $BarHeight ) + 1;
-                               }
-                               $average_v = sprintf( "%.2f", $average_v );
-                               $average_p = sprintf( "%.2f", $average_p );
-                               $average_h = sprintf( "%.2f", $average_h );
-                               $average_k = (
-                                       int($average_k)
-                                       ? Format_Bytes( sprintf( "%.2f", $average_k ) )
-                                       : "0.00"
-                               );
-                               if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                       print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vv'}\" height=\"$bredde_v\" width=\"4\""
-                                         . AltTitle("$Message[10]: $average_v") . " />";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                       print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"4\""
-                                         . AltTitle("$Message[56]: $average_p") . " />";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                       print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"4\""
-                                         . AltTitle("$Message[57]: $average_h") . " />";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                       print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"4\""
-                                         . AltTitle("$Message[75]: $average_k") . " />";
-                               }
-                               print "</td>\n";
-                               print "</tr>\n";
+       if ($Debug) { debug("Close log file \"$LogFile\""); }
+       close LOG || error("Command for pipe '$LogFile' failed");
 
-                               # Show lib for day
-                               print "<tr valign=\"middle\">";
-                               foreach
-                                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                               {
-                                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                                       my $year  = $1;
-                                       my $month = $2;
-                                       my $day   = $3;
-                                       if ( !DateIsValid( $day, $month, $year ) ) {
-                                               next;
-                                       }    # If not an existing day, go to next
-                                       my $dayofweekcursor = DayOfWeek( $day, $month, $year );
-                                       print "<td"
-                                         . (
-                                               $dayofweekcursor =~ /[06]/
-                                               ? " bgcolor=\"#$color_weekend\""
-                                               : ""
-                                         )
-                                         . ">";
-                                       print(
-                                               !$StaticLinks
-                                                 && $day == $nowday
-                                                 && $month == $nowmonth
-                                                 && $year == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                       );
-                                       print "$day<br /><span style=\"font-size: "
-                                         . (    $FrameName ne 'mainright'
-                                                 && $QueryString !~ /buildpdf/i ? "9" : "8" )
-                                         . "px;\">"
-                                         . $MonthNumLib{$month}
-                                         . "</span>";
-                                       print(   !$StaticLinks
-                                                 && $day == $nowday
-                                                 && $month == $nowmonth
-                                                 && $year == $nowyear ? '</font>' : '' );
-                                       print "</td>\n";
-                               }
-                               print "<td>&nbsp;</td>";
-                               print "<td valign=\"middle\""
-                                 . Tooltip(18)
-                                 . ">$Message[96]</td>\n";
-                               print "</tr>\n";
-                               print "</table>\n";
+       # Process the Rename - Archive - Purge phase
+       my $renameok  = 1;
+       my $archiveok = 1;
+
+       # Open Log file for writing if PurgeLogFile is on
+       if ($PurgeLogFile) {
+               if ($ArchiveLogRecords) {
+                       if ( $ArchiveLogRecords == 1 ) {    # For backward compatibility
+                               $ArchiveFileName = "$DirData/${PROG}_archive$FileSuffix.log";
                        }
-                       print "<br />\n";
+                       else {
+                               $ArchiveFileName =
+                                 "$DirData/${PROG}_archive$FileSuffix."
+                                 . &Substitute_Tags($ArchiveLogRecords) . ".log";
+                       }
+                       open( LOG, "+<$LogFile" )
+                         || error(
+"Enable to archive log records of \"$LogFile\" into \"$ArchiveFileName\" because source can't be opened for read and write: $!<br />\n"
+                         );
+               }
+               else {
+                       open( LOG, "+<$LogFile" );
+               }
+               binmode LOG;
+       }
 
-                       # Show data array for days
-                       if ($AddDataArrayShowDaysOfMonthStats) {
-                               print "<table>\n";
-                               print
-"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
-                               if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_v\""
-                                         . Tooltip(1)
-                                         . ">$Message[10]</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
-                                         . Tooltip(3)
-                                         . ">$Message[56]</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
-                                         . Tooltip(4)
-                                         . ">$Message[57]</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
-                                         . Tooltip(5)
-                                         . ">$Message[75]</td>";
-                               }
-                               print "</tr>";
-                               foreach
-                                 my $daycursor ( $firstdaytoshowtime .. $lastdaytoshowtime )
-                               {
-                                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                                       my $year  = $1;
-                                       my $month = $2;
-                                       my $day   = $3;
-                                       if ( !DateIsValid( $day, $month, $year ) ) {
-                                               next;
-                                       }    # If not an existing day, go to next
-                                       my $dayofweekcursor = DayOfWeek( $day, $month, $year );
-                                       print "<tr"
-                                         . (
-                                               $dayofweekcursor =~ /[06]/
-                                               ? " bgcolor=\"#$color_weekend\""
-                                               : ""
-                                         )
-                                         . ">";
-                                       print "<td>"
-                                         . (
-                                               !$StaticLinks
-                                                 && $day == $nowday
-                                                 && $month == $nowmonth
-                                                 && $year == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                         );
-                                       print Format_Date( "$year$month$day" . "000000", 2 );
-                                       print(   !$StaticLinks
-                                                 && $day == $nowday
-                                                 && $month == $nowmonth
-                                                 && $year == $nowyear ? '</font>' : '' );
-                                       print "</td>";
-                                       if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                               print "<td>",
-                                                 Format_Number($DayVisits{ $year . $month . $day }
-                                                 ? $DayVisits{ $year . $month . $day }
-                                                 : "0"), "</td>";
-                                       }
-                                       if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                               print "<td>",
-                                                 Format_Number($DayPages{ $year . $month . $day }
-                                                 ? $DayPages{ $year . $month . $day }
-                                                 : "0"), "</td>";
-                                       }
-                                       if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                               print "<td>",
-                                                 Format_Number($DayHits{ $year . $month . $day }
-                                                 ? $DayHits{ $year . $month . $day }
-                                                 : "0"), "</td>";
-                                       }
-                                       if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                               print "<td>",
-                                                 Format_Bytes(
-                                                       int( $DayBytes{ $year . $month . $day } || 0 ) ),
-                                                 "</td>";
-                                       }
-                                       print "</tr>\n";
-                               }
+       # Rename all HISTORYTMP files into HISTORYTXT
+       &Rename_All_Tmp_History();
 
-                               # Average row
-                               print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[96]</td>";
-                               if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                       print "<td>".Format_Number($average_v)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                       print "<td>".Format_Number($average_p)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                       print "<td>".Format_Number($average_h)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                       print "<td>".Format_Number($average_k)."</td>";
-                               }
-                               print "</tr>\n";
+       # Purge Log file if option is on and all renaming are ok
+       if ($PurgeLogFile) {
 
-                               # Total row
-                               print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><td>$Message[102]</td>";
-                               if ( $ShowDaysOfMonthStats =~ /V/i ) {
-                                       print "<td>".Format_Number($total_v)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /P/i ) {
-                                       print "<td>".Format_Number($total_p)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /H/i ) {
-                                       print "<td>".Format_Number($total_h)."</td>";
-                               }
-                               if ( $ShowDaysOfMonthStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($total_k) . "</td>";
-                               }
-                               print "</tr>\n";
-                               print "</table>\n<br />";
+               # Archive LOG file into ARCHIVELOG
+               if ($ArchiveLogRecords) {
+                       if ($Debug) { debug("Start of archiving log file"); }
+                       open( ARCHIVELOG, ">>$ArchiveFileName" )
+                         || error(
+                               "Couldn't open file \"$ArchiveFileName\" to archive log: $!");
+                       binmode ARCHIVELOG;
+                       while (<LOG>) {
+                               if ( !print ARCHIVELOG $_ ) { $archiveok = 0; last; }
+                       }
+                       close(ARCHIVELOG)
+                         || error("Archiving failed during closing archive: $!");
+                       if ($SaveDatabaseFilesWithPermissionsForEveryone) {
+                               chmod 0666, "$ArchiveFileName";
                        }
+                       if ($Debug) { debug("End of archiving log file"); }
+               }
 
-                       print "</center>\n";
-                       print "</td></tr>\n";
-                       &tab_end();
+               # If rename and archive ok
+               if ( $renameok && $archiveok ) {
+                       if ($Debug) { debug("Purge log file"); }
+                       my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
+                       my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
+                       my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
+                       truncate( LOG, 0 )
+                         || warning(
+"Warning: $bold$PROG$unbold couldn't purge logfile \"$bold$LogFile$unbold\".$br\nChange your logfile permissions to allow write for your web server CGI process or change PurgeLogFile=1 into PurgeLogFile=0 in configure file and think to purge sometimes manually your logfile (just after running an update process to not loose any not already processed records your log file contains)."
+                         );
                }
+               close(LOG);
+       }
 
-               # BY DAY OF WEEK
-               #-------------------------
-               if ($ShowDaysOfWeekStats) {
-                       if ($Debug) { debug( "ShowDaysOfWeekStats", 2 ); }
-                       print "$Center<a name=\"daysofweek\">&nbsp;</a><br />\n";
-                       my $title = "$Message[91]";
-                       &tab_head( "$title", 18, 0, 'daysofweek' );
-                       print "<tr>";
-                       print "<td align=\"center\">";
-                       print "<center>\n";
+       if ( $DNSLookup == 1 && $DNSLookupAlreadyDone ) {
 
-                       $max_h = $max_k = 0;    # Start from 0 because can be lower than 1
-                                               # Get average value for day of week
-                       my @avg_dayofweek_nb = ();
-                       my @avg_dayofweek_p  = ();
-                       my @avg_dayofweek_h  = ();
-                       my @avg_dayofweek_k  = ();
-                       foreach my $daycursor (
-                               $firstdaytocountaverage .. $lastdaytocountaverage )
-                       {
-                               $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
-                               my $year  = $1;
-                               my $month = $2;
-                               my $day   = $3;
-                               if ( !DateIsValid( $day, $month, $year ) ) {
-                                       next;
-                               }    # If not an existing day, go to next
-                               my $dayofweekcursor = DayOfWeek( $day, $month, $year );
-                               $avg_dayofweek_nb[$dayofweekcursor]
-                                 ++; # Increase number of day used to count for this day of week
-                               $avg_dayofweek_p[$dayofweekcursor] +=
-                                 ( $DayPages{$daycursor} || 0 );
-                               $avg_dayofweek_h[$dayofweekcursor] +=
-                                 ( $DayHits{$daycursor} || 0 );
-                               $avg_dayofweek_k[$dayofweekcursor] +=
-                                 ( $DayBytes{$daycursor} || 0 );
-                       }
-                       for (@DOWIndex) {
-                               if ( $avg_dayofweek_nb[$_] ) {
-                                       $avg_dayofweek_p[$_] =
-                                         $avg_dayofweek_p[$_] / $avg_dayofweek_nb[$_];
-                                       $avg_dayofweek_h[$_] =
-                                         $avg_dayofweek_h[$_] / $avg_dayofweek_nb[$_];
-                                       $avg_dayofweek_k[$_] =
-                                         $avg_dayofweek_k[$_] / $avg_dayofweek_nb[$_];
+               # DNSLookup warning
+               my $bold   = ( $ENV{'GATEWAY_INTERFACE'} ? '<b>'    : '' );
+               my $unbold = ( $ENV{'GATEWAY_INTERFACE'} ? '</b>'   : '' );
+               my $br     = ( $ENV{'GATEWAY_INTERFACE'} ? '<br />' : '' );
+               warning(
+"Warning: $bold$PROG$unbold has detected that some hosts names were already resolved in your logfile $bold$DNSLookupAlreadyDone$unbold.$br\nIf DNS lookup was already made by the logger (web server), you should change your setup DNSLookup=$DNSLookup into DNSLookup=0 to increase $PROG speed."
+               );
+       }
+       if ( $DNSLookup == 1 && $NbOfNewLines ) {
 
-                 #if ($avg_dayofweek_p[$_] > $max_p) { $max_p = $avg_dayofweek_p[$_]; }
-                                       if ( $avg_dayofweek_h[$_] > $max_h ) {
-                                               $max_h = $avg_dayofweek_h[$_];
-                                       }
-                                       if ( $avg_dayofweek_k[$_] > $max_k ) {
-                                               $max_k = $avg_dayofweek_k[$_];
-                                       }
-                               }
-                               else {
-                                       $avg_dayofweek_p[$_] = "?";
-                                       $avg_dayofweek_h[$_] = "?";
-                                       $avg_dayofweek_k[$_] = "?";
-                               }
-                       }
+               # Save new DNS last update cache file
+               Save_DNS_Cache_File( \%TmpDNSLookup, "$DirData/$DNSLastUpdateCacheFile",
+                       "$FileSuffix" );    # Save into file using FileSuffix
+       }
+
+       if ($EnableLockForUpdate) {
+
+               # Remove lock
+               &Lock_Update(0);
+
+               # Restore signals handler
+               $SIG{INT} = 'DEFAULT';    # 2
+                                         #$SIG{KILL} = 'DEFAULT';      # 9
+                                         #$SIG{TERM} = 'DEFAULT';      # 15
+       }
+
+}
+
+# End of log processing if ($UPdateStats)
+
+#---------------------------------------------------------------------
+# SHOW REPORT
+#---------------------------------------------------------------------
+
+if ( scalar keys %HTMLOutput ) {
 
-                       # Show bars for days of week
-                       my $graphdone=0;
-                       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
-                       {
-                               my @blocklabel = ();
-                               for (@DOWIndex) {
-                                       push @blocklabel,
-                                         ( $Message[ $_ + 84 ] . ( $_ =~ /[06]/ ? "!" : "" ) );
-                               }
-                               my @vallabel =
-                                 ( "$Message[56]", "$Message[57]", "$Message[75]" );
-                               my @valcolor = ( "$color_p", "$color_h", "$color_k" );
-                               my @valmax = ( int($max_h), int($max_h), int($max_k) );
-                               my @valtotal = ( $total_p, $total_h, $total_k );
-                               $average_p = sprintf( "%.2f", $average_p );
-                               $average_h = sprintf( "%.2f", $average_h );
-                               $average_k = (
-                                       int($average_k)
-                                       ? Format_Bytes( sprintf( "%.2f", $average_k ) )
-                                       : "0.00"
-                               );
-                               my @valaverage = ( $average_p, $average_h, $average_k );
-                               my @valdata    = ();
-                               my $xx         = 0;
+       debug( "YearRequired=$YearRequired, MonthRequired=$MonthRequired", 2 );
+       debug( "DayRequired=$DayRequired, HourRequired=$HourRequired",     2 );
 
-                               for (@DOWIndex) {
-                                       $valdata[ $xx++ ] = $avg_dayofweek_p[$_] || 0;
-                                       $valdata[ $xx++ ] = $avg_dayofweek_h[$_] || 0;
-                                       $valdata[ $xx++ ] = $avg_dayofweek_k[$_] || 0;
+       # Define the NewLinkParams for main chart
+       my $NewLinkParams = ${QueryString};
+       $NewLinkParams =~ s/(^|&|&amp;)update(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)output(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)staticlinks(=\w*|$)//i;
+       $NewLinkParams =~ s/(^|&|&amp;)framename=[^&]*//i;
+       my $NewLinkTarget = '';
+       if ($DetailedReportsOnNewWindows) {
+               $NewLinkTarget = " target=\"awstatsbis\"";
+       }
+       if ( ( $FrameName eq 'mainleft' || $FrameName eq 'mainright' )
+               && $DetailedReportsOnNewWindows < 2 )
+       {
+               $NewLinkParams .= "&amp;framename=mainright";
+               $NewLinkTarget = " target=\"mainright\"";
+       }
+       $NewLinkParams =~ s/(&amp;|&)+/&amp;/i;
+       $NewLinkParams =~ s/^&amp;//;
+       $NewLinkParams =~ s/&amp;$//;
+       if ($NewLinkParams) { $NewLinkParams = "${NewLinkParams}&amp;"; }
 
-                                       # Round to be ready to show array
-                                       $avg_dayofweek_p[$_] =
-                                         sprintf( "%.2f", $avg_dayofweek_p[$_] );
-                                       $avg_dayofweek_h[$_] =
-                                         sprintf( "%.2f", $avg_dayofweek_h[$_] );
-                                       $avg_dayofweek_k[$_] =
-                                         sprintf( "%.2f", $avg_dayofweek_k[$_] );
+       if ( $FrameName ne 'mainleft' ) {
 
-                                       # Remove decimal part that are .0
-                                       if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
-                                               $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
-                                       }
-                                       if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
-                                               $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
-                                       }
-                               }
-                               my $function = "ShowGraph_$pluginname";
-                               &$function(
-                                       "$title",             "daysofweek",
-                                       $ShowDaysOfWeekStats, \@blocklabel,
-                                       \@vallabel,           \@valcolor,
-                                       \@valmax,             \@valtotal,
-                                       \@valaverage,         \@valdata
-                               );
-                               $graphdone=1;
-                       }
-                       if (! $graphdone) 
-                       {
-                               print "<table>\n";
-                               print "<tr valign=\"bottom\">\n";
-                               for (@DOWIndex) {
-                                       my $bredde_p = 0;
-                                       my $bredde_h = 0;
-                                       my $bredde_k = 0;
-                                       if ( $max_h > 0 ) {
-                                               $bredde_p = int(
-                                                       (
-                                                                 $avg_dayofweek_p[$_] ne '?'
-                                                               ? $avg_dayofweek_p[$_]
-                                                               : 0
-                                                       ) / $max_h * $BarHeight
-                                               ) + 1;
-                                       }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_h = int(
-                                                       (
-                                                                 $avg_dayofweek_h[$_] ne '?'
-                                                               ? $avg_dayofweek_h[$_]
-                                                               : 0
-                                                       ) / $max_h * $BarHeight
-                                               ) + 1;
-                                       }
-                                       if ( $max_k > 0 ) {
-                                               $bredde_k = int(
-                                                       (
-                                                                 $avg_dayofweek_k[$_] ne '?'
-                                                               ? $avg_dayofweek_k[$_]
-                                                               : 0
-                                                       ) / $max_k * $BarHeight
-                                               ) + 1;
-                                       }
-                                       $avg_dayofweek_p[$_] = sprintf(
-                                               "%.2f",
-                                               (
-                                                         $avg_dayofweek_p[$_] ne '?'
-                                                       ? $avg_dayofweek_p[$_]
-                                                       : 0
-                                               )
-                                       );
-                                       $avg_dayofweek_h[$_] = sprintf(
-                                               "%.2f",
-                                               (
-                                                         $avg_dayofweek_h[$_] ne '?'
-                                                       ? $avg_dayofweek_h[$_]
-                                                       : 0
-                                               )
-                                       );
-                                       $avg_dayofweek_k[$_] = sprintf(
-                                               "%.2f",
-                                               (
-                                                         $avg_dayofweek_k[$_] ne '?'
-                                                       ? $avg_dayofweek_k[$_]
-                                                       : 0
-                                               )
-                                       );
+               # READING DATA
+               #-------------
+               &Init_HashArray();
 
-                                       # Remove decimal part that are .0
-                                       if ( $avg_dayofweek_p[$_] == int( $avg_dayofweek_p[$_] ) ) {
-                                               $avg_dayofweek_p[$_] = int( $avg_dayofweek_p[$_] );
-                                       }
-                                       if ( $avg_dayofweek_h[$_] == int( $avg_dayofweek_h[$_] ) ) {
-                                               $avg_dayofweek_h[$_] = int( $avg_dayofweek_h[$_] );
-                                       }
-                                       print "<td valign=\"bottom\">";
-                                       if ( $ShowDaysOfWeekStats =~ /P/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
-                                                 . AltTitle("$Message[56]: $avg_dayofweek_p[$_]")
-                                                 . " />";
-                                       }
-                                       if ( $ShowDaysOfWeekStats =~ /H/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
-                                                 . AltTitle("$Message[57]: $avg_dayofweek_h[$_]")
-                                                 . " />";
-                                       }
-                                       if ( $ShowDaysOfWeekStats =~ /B/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
-                                                 . AltTitle( "$Message[75]: "
-                                                         . Format_Bytes( $avg_dayofweek_k[$_] ) )
-                                                 . " />";
-                                       }
-                                       print "</td>\n";
+               # Lecture des fichiers history / reading history file
+               if ( $DatabaseBreak eq 'month' ) {
+                       for ( my $ix = 12 ; $ix >= 1 ; $ix-- ) {
+                               my $stringforload = '';
+                               my $monthix = sprintf( "%02s", $ix );
+                               if ( $MonthRequired eq 'all' || $monthix eq $MonthRequired ) {
+                                       $stringforload = 'all';    # Read full history file
                                }
-                               print "</tr>\n";
-                               print "<tr" . Tooltip(17) . ">\n";
-                               for (@DOWIndex) {
-                                       print "<td"
-                                         . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
-                                         . ">"
-                                         . (
-                                               !$StaticLinks
-                                                 && $_ == ( $nowwday - 1 )
-                                                 && $MonthRequired == $nowmonth
-                                                 && $YearRequired == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                         );
-                                       print $Message[ $_ + 84 ];
-                                       print(   !$StaticLinks
-                                                 && $_ == ( $nowwday - 1 )
-                                                 && $MonthRequired == $nowmonth
-                                                 && $YearRequired == $nowyear ? '</font>' : '' );
-                                       print "</td>";
+                               elsif ( ( $HTMLOutput{'main'} && $ShowMonthStats )
+                                       || $HTMLOutput{'alldays'} )
+                               {
+                                       $stringforload =
+                                         'general time';          # Read general and time sections.
                                }
-                               print "</tr>\n</table>\n";
-                       }
-                       print "<br />\n";
+                               if ($stringforload) {
 
-                       # Show data array for days of week
-                       if ($AddDataArrayShowDaysOfWeekStats) {
-                               print "<table>\n";
-                               print
-"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[4]</td>";
-                               if ( $ShowDaysOfWeekStats =~ /P/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
-                                         . Tooltip(3)
-                                         . ">$Message[56]</td>";
-                               }
-                               if ( $ShowDaysOfWeekStats =~ /H/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
-                                         . Tooltip(4)
-                                         . ">$Message[57]</td>";
-                               }
-                               if ( $ShowDaysOfWeekStats =~ /B/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
-                                         . Tooltip(5)
-                                         . ">$Message[75]</td></tr>";
-                               }
-                               for (@DOWIndex) {
-                                       print "<tr"
-                                         . ( $_ =~ /[06]/ ? " bgcolor=\"#$color_weekend\"" : "" )
-                                         . ">";
-                                       print "<td>"
-                                         . (
-                                               !$StaticLinks
-                                                 && $_ == ( $nowwday - 1 )
-                                                 && $MonthRequired == $nowmonth
-                                                 && $YearRequired == $nowyear
-                                               ? '<font class="currentday">'
-                                               : ''
-                                         );
-                                       print $Message[ $_ + 84 ];
-                                       print(   !$StaticLinks
-                                                 && $_ == ( $nowwday - 1 )
-                                                 && $MonthRequired == $nowmonth
-                                                 && $YearRequired == $nowyear ? '</font>' : '' );
-                                       print "</td>";
-                                       if ( $ShowDaysOfWeekStats =~ /P/i ) {
-                                               print "<td>", Format_Number($avg_dayofweek_p[$_]), "</td>";
-                                       }
-                                       if ( $ShowDaysOfWeekStats =~ /H/i ) {
-                                               print "<td>", Format_Number($avg_dayofweek_h[$_]), "</td>";
-                                       }
-                                       if ( $ShowDaysOfWeekStats =~ /B/i ) {
-                                               print "<td>", Format_Bytes( $avg_dayofweek_k[$_] ),
-                                                 "</td>";
-                                       }
-                                       print "</tr>\n";
+                                       # On charge fichier / file is loaded
+                                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, '',
+                                               '', 0, 0, $stringforload );
                                }
-                               print "</table>\n<br />\n";
-                       }
-
-                       print "</center></td>";
-                       print "</tr>\n";
-                       &tab_end();
+                       }
+               }
+               if ( $DatabaseBreak eq 'day' ) {
+                       my $stringforload = 'all';
+                       my $monthix       = sprintf( "%02s", $MonthRequired );
+                       my $dayix         = sprintf( "%02s", $DayRequired );
+                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix, '',
+                               0, 0, $stringforload );
+               }
+               if ( $DatabaseBreak eq 'hour' ) {
+                       my $stringforload = 'all';
+                       my $monthix       = sprintf( "%02s", $MonthRequired );
+                       my $dayix         = sprintf( "%02s", $DayRequired );
+                       my $hourix        = sprintf( "%02s", $HourRequired );
+                       &Read_History_With_TmpUpdate( $YearRequired, $monthix, $dayix,
+                               $hourix, 0, 0, $stringforload );
                }
 
-               # BY HOUR
-               #----------------------------
-               if ($ShowHoursStats) {
-                       if ($Debug) { debug( "ShowHoursStats", 2 ); }
-                       print "$Center<a name=\"hours\">&nbsp;</a><br />\n";
-                       my $title = "$Message[20]";
-                       if ( $PluginsLoaded{'GetTimeZoneTitle'}{'timezone'} ) {
-                               $title .= " (GMT "
-                                 . ( GetTimeZoneTitle_timezone() >= 0 ? "+" : "" )
-                                 . int( GetTimeZoneTitle_timezone() ) . ")";
-                       }
-                       &tab_head( "$title", 19, 0, 'hours' );
-                       print "<tr><td align=\"center\">\n";
-                       print "<center>\n";
+       }
 
-                       $max_h = $max_k = 1;
-                       for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
+       # HTMLHeadSection
+       if ( $FrameName ne 'index' && $FrameName ne 'mainleft' ) {
+               print "<a name=\"top\"></a>\n\n";
+               my $newhead = $HTMLHeadSection;
+               $newhead =~ s/\\n/\n/g;
+               print "$newhead\n";
+               print "\n";
+       }
 
-                               #if ($_time_p[$ix]>$max_p) { $max_p=$_time_p[$ix]; }
-                               if ( $_time_h[$ix] > $max_h ) { $max_h = $_time_h[$ix]; }
-                               if ( $_time_k[$ix] > $max_k ) { $max_k = $_time_k[$ix]; }
-                       }
+       # Call to plugins' function AddHTMLBodyHeader
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLBodyHeader'} } ) {
+               my $function = "AddHTMLBodyHeader_$pluginname";
+               &$function();
+       }
 
-                       # Show bars for hour
-                       my $graphdone=0;
-                       foreach my $pluginname ( keys %{ $PluginsLoaded{'ShowGraph'} } )
-                       {
-                               my @blocklabel = ( 0 .. 23 );
-                               my @vallabel   =
-                                 ( "$Message[56]", "$Message[57]", "$Message[75]" );
-                               my @valcolor = ( "$color_p", "$color_h", "$color_k" );
-                               my @valmax = ( int($max_h), int($max_h), int($max_k) );
-                               my @valtotal   = ( $total_p,   $total_h,   $total_k );
-                               my @valaverage = ( $average_p, $average_h, $average_k );
-                               my @valdata    = ();
-                               my $xx         = 0;
-                               for ( 0 .. 23 ) {
-                                       $valdata[ $xx++ ] = $_time_p[$_] || 0;
-                                       $valdata[ $xx++ ] = $_time_h[$_] || 0;
-                                       $valdata[ $xx++ ] = $_time_k[$_] || 0;
-                               }
-                               my $function = "ShowGraph_$pluginname";
-                               &$function(
-                                       "$title",        "hours",
-                                       $ShowHoursStats, \@blocklabel,
-                                       \@vallabel,      \@valcolor,
-                                       \@valmax,        \@valtotal,
-                                       \@valaverage,    \@valdata
-                               );
-                               $graphdone=1;
-                       }
-                       if (! $graphdone) 
-                       {
-                               print "<table>\n";
-                               print "<tr valign=\"bottom\">\n";
-                               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
-                                       my $bredde_p = 0;
-                                       my $bredde_h = 0;
-                                       my $bredde_k = 0;
-                                       if ( $max_h > 0 ) {
-                                               $bredde_p =
-                                                 int( $BarHeight * $_time_p[$ix] / $max_h ) + 1;
-                                       }
-                                       if ( $max_h > 0 ) {
-                                               $bredde_h =
-                                                 int( $BarHeight * $_time_h[$ix] / $max_h ) + 1;
-                                       }
-                                       if ( $max_k > 0 ) {
-                                               $bredde_k =
-                                                 int( $BarHeight * $_time_k[$ix] / $max_k ) + 1;
-                                       }
-                                       print "<td>";
-                                       if ( $ShowHoursStats =~ /P/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vp'}\" height=\"$bredde_p\" width=\"6\""
-                                                 . AltTitle( "$Message[56]: " . int( $_time_p[$ix] ) )
-                                                 . " />";
-                                       }
-                                       if ( $ShowHoursStats =~ /H/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vh'}\" height=\"$bredde_h\" width=\"6\""
-                                                 . AltTitle( "$Message[57]: " . int( $_time_h[$ix] ) )
-                                                 . " />";
-                                       }
-                                       if ( $ShowHoursStats =~ /B/i ) {
-                                               print
-"<img align=\"bottom\" src=\"$DirIcons\/other\/$BarPng{'vk'}\" height=\"$bredde_k\" width=\"6\""
-                                                 . AltTitle(
-                                                       "$Message[75]: " . Format_Bytes( $_time_k[$ix] ) )
-                                                 . " />";
-                                       }
-                                       print "</td>\n";
-                               }
-                               print "</tr>\n";
+       my $WIDTHMENU1 = ( $FrameName eq 'mainleft' ? $FRAMEWIDTH : 150 );
 
-                               # Show hour lib
-                               print "<tr" . Tooltip(17) . ">";
-                               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
-                                       print "<th width=\"19\">$ix</th>\n"
-                                         ;   # width=19 instead of 18 to avoid a MacOS browser bug.
-                               }
-                               print "</tr>\n";
+       # TOP BAN
+       #---------------------------------------------------------------------
+       if ( $ShowMenu || $FrameName eq 'mainleft' ) {
+               HTMLTopBanner($WIDTHMENU1);
+       }
 
-                               # Show clock icon
-                               print "<tr" . Tooltip(17) . ">\n";
-                               for ( my $ix = 0 ; $ix <= 23 ; $ix++ ) {
-                                       my $hrs = ( $ix >= 12 ? $ix - 12 : $ix );
-                                       my $hre = ( $ix >= 12 ? $ix - 11 : $ix + 1 );
-                                       my $apm = ( $ix >= 12 ? "pm"     : "am" );
-                                       print
-"<td><img src=\"$DirIcons\/clock\/hr$hre.png\" width=\"12\" alt=\"$hrs:00 - $hre:00 $apm\" /></td>\n";
-                               }
-                               print "</tr>\n";
-                               print "</table>\n";
-                       }
-                       print "<br />\n";
+       # Call to plugins' function AddHTMLMenuHeader
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuHeader'} } ) {
+               my $function = "AddHTMLMenuHeader_$pluginname";
+               &$function();
+       }
 
-                       # Show data array for hours
-                       if ($AddDataArrayShowHoursStats) {
-                               print "<table width=\"650\"><tr>\n";
-                               print "<td align=\"center\"><center>\n";
+       # MENU (ON LEFT IF FRAME OR TOP)
+       #---------------------------------------------------------------------
+       if ( $ShowMenu || $FrameName eq 'mainleft' ) {
+               HTMLMenu($NewLinkParams, $NewLinkTarget);
+       }
 
-                               print "<table>\n";
-                               print
-"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
-                               if ( $ShowHoursStats =~ /P/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
-                                         . Tooltip(3)
-                                         . ">$Message[56]</td>";
-                               }
-                               if ( $ShowHoursStats =~ /H/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
-                                         . Tooltip(4)
-                                         . ">$Message[57]</td>";
-                               }
-                               if ( $ShowHoursStats =~ /B/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
-                                         . Tooltip(5)
-                                         . ">$Message[75]</td>";
-                               }
-                               print "</tr>";
-                               for ( my $ix = 0 ; $ix <= 11 ; $ix++ ) {
-                                       my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
-                                       print "<tr>";
-                                       print "<td>$monthix</td>";
-                                       if ( $ShowHoursStats =~ /P/i ) {
-                                               print "<td>",
-                                                 Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
-                                                 "</td>";
-                                       }
-                                       if ( $ShowHoursStats =~ /H/i ) {
-                                               print "<td>",
-                                                 Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
-                                                 "</td>";
-                                       }
-                                       if ( $ShowHoursStats =~ /B/i ) {
-                                               print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
-                                                 "</td>";
-                                       }
-                                       print "</tr>\n";
-                               }
-                               print "</table>\n";
+       # Call to plugins' function AddHTMLMenuFooter
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLMenuFooter'} } ) {
+               my $function = "AddHTMLMenuFooter_$pluginname";
+               &$function();
+       }
 
-                               print "</center></td>";
-                               print "<td width=\"10\">&nbsp;</td>";
-                               print "<td align=\"center\"><center>\n";
+       # Exit if left frame
+       if ( $FrameName eq 'mainleft' ) {
+               &html_end(0);
+               exit 0;
+       }
 
-                               print "<table>\n";
-                               print
-"<tr><td width=\"80\" bgcolor=\"#$color_TableBGRowTitle\">$Message[20]</td>";
-                               if ( $ShowHoursStats =~ /P/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_p\""
-                                         . Tooltip(3)
-                                         . ">$Message[56]</td>";
-                               }
-                               if ( $ShowHoursStats =~ /H/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_h\""
-                                         . Tooltip(4)
-                                         . ">$Message[57]</td>";
-                               }
-                               if ( $ShowHoursStats =~ /B/i ) {
-                                       print "<td width=\"80\" bgcolor=\"#$color_k\""
-                                         . Tooltip(5)
-                                         . ">$Message[75]</td>";
-                               }
-                               print "</tr>\n";
-                               for ( my $ix = 12 ; $ix <= 23 ; $ix++ ) {
-                                       my $monthix = ( $ix < 10 ? "0$ix" : "$ix" );
-                                       print "<tr>";
-                                       print "<td>$monthix</td>";
-                                       if ( $ShowHoursStats =~ /P/i ) {
-                                               print "<td>",
-                                                 Format_Number($_time_p[$monthix] ? $_time_p[$monthix] : "0"),
-                                                 "</td>";
-                                       }
-                                       if ( $ShowHoursStats =~ /H/i ) {
-                                               print "<td>",
-                                                 Format_Number($_time_h[$monthix] ? $_time_h[$monthix] : "0"),
-                                                 "</td>";
-                                       }
-                                       if ( $ShowHoursStats =~ /B/i ) {
-                                               print "<td>", Format_Bytes( int( $_time_k[$monthix] ) ),
-                                                 "</td>";
-                                       }
-                                       print "</tr>\n";
-                               }
-                               print "</table>\n";
+       
 
-                               print "</center></td></tr></table>\n";
-                               print "<br />\n";
-                       }
+# TotalVisits TotalUnique TotalPages TotalHits TotalBytes TotalHostsKnown TotalHostsUnknown
+       $TotalUnique = $TotalVisits = $TotalPages = $TotalHits = $TotalBytes = 0;
+       $TotalNotViewedPages = $TotalNotViewedHits = $TotalNotViewedBytes = 0;
+       $TotalHostsKnown = $TotalHostsUnknown = 0;
+       my $beginmonth = $MonthRequired;
+       my $endmonth   = $MonthRequired;
+       if ( $MonthRequired eq 'all' ) { $beginmonth = 1; $endmonth = 12; }
+       for ( my $month = $beginmonth ; $month <= $endmonth ; $month++ ) {
+               my $monthix = sprintf( "%02s", $month );
+               $TotalHostsKnown += $MonthHostsKnown{ $YearRequired . $monthix }
+                 || 0;    # Wrong in year view
+               $TotalHostsUnknown += $MonthHostsUnknown{ $YearRequired . $monthix }
+                 || 0;    # Wrong in year view
+               $TotalUnique += $MonthUnique{ $YearRequired . $monthix }
+                 || 0;    # Wrong in year view
+               $TotalVisits += $MonthVisits{ $YearRequired . $monthix }
+                 || 0;    # Not completely true
+               $TotalPages += $MonthPages{ $YearRequired . $monthix } || 0;
+               $TotalHits  += $MonthHits{ $YearRequired . $monthix }  || 0;
+               $TotalBytes += $MonthBytes{ $YearRequired . $monthix } || 0;
+               $TotalNotViewedPages += $MonthNotViewedPages{ $YearRequired . $monthix }
+                 || 0;
+               $TotalNotViewedHits += $MonthNotViewedHits{ $YearRequired . $monthix }
+                 || 0;
+               $TotalNotViewedBytes += $MonthNotViewedBytes{ $YearRequired . $monthix }
+                 || 0;
+       }
 
-                       print "</center></td></tr>\n";
-                       &tab_end();
-               }
+       # TotalHitsErrors TotalBytesErrors
+       $TotalHitsErrors  = 0;
+       my $TotalBytesErrors = 0;
+       foreach ( keys %_errors_h ) {
 
-               print "\n<a name=\"who\">&nbsp;</a>\n\n";
+               #               print "xxxx".$_." zzz".$_errors_h{$_};
+               $TotalHitsErrors  += $_errors_h{$_};
+               $TotalBytesErrors += $_errors_k{$_};
+       }
 
-               # BY COUNTRY/DOMAIN
-               #---------------------------
-               if ($ShowDomainsStats) {
-                       if ($Debug) { debug( "ShowDomainsStats", 2 ); }
-                       print "$Center<a name=\"countries\">&nbsp;</a><br />\n";
-                       my $title =
-"$Message[25] ($Message[77] $MaxNbOf{'Domain'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=alldomains")
-                               : "$StaticLinks.alldomains.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a>";
-                       &tab_head( "$title", 19, 0, 'countries' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th colspan=\"2\">$Message[17]</th>";
+# TotalEntries (if not already specifically counted, we init it from _url_e hash table)
+       if ( !$TotalEntries ) {
+               foreach ( keys %_url_e ) { $TotalEntries += $_url_e{$_}; }
+       }
 
-                       ## to add unique visitors and number of visits by calculation of average of the relation with total
-                       ## pages and total hits, and total visits and total unique
-                       ## by Josep Ruano @ CAPSiDE
-                       if ( $ShowDomainsStats =~ /U/i ) {
-                               print "<th bgcolor=\"#$color_u\" width=\"80\""
-                                 . Tooltip(2)
-                                 . ">$Message[11]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /V/i ) {
-                               print "<th bgcolor=\"#$color_v\" width=\"80\""
-                                 . Tooltip(1)
-                                 . ">$Message[10]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /P/i ) {
-                               print "<th bgcolor=\"#$color_p\" width=\"80\""
-                                 . Tooltip(3)
-                                 . ">$Message[56]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /H/i ) {
-                               print "<th bgcolor=\"#$color_h\" width=\"80\""
-                                 . Tooltip(4)
-                                 . ">$Message[57]</th>";
-                       }
-                       if ( $ShowDomainsStats =~ /B/i ) {
-                               print "<th bgcolor=\"#$color_k\" width=\"80\""
-                                 . Tooltip(5)
-                                 . ">$Message[75]</th>";
-                       }
-                       print "<th>&nbsp;</th>";
-                       print "</tr>\n";
-                       $total_u = $total_v = $total_p = $total_h = $total_k = 0;
-                       $max_h = 1;
-                       foreach ( values %_domener_h ) {
-                               if ( $_ > $max_h ) { $max_h = $_; }
-                       }
-                       $max_k = 1;
-                       foreach ( values %_domener_k ) {
-                               if ( $_ > $max_k ) { $max_k = $_; }
-                       }
-                       my $count = 0;
-                       &BuildKeyList(
-                               $MaxNbOf{'Domain'}, $MinHit{'Domain'},
-                               \%_domener_h,       \%_domener_p
-                       );
-                       foreach my $key (@keylist) {
-                               my ( $_domener_u, $_domener_v );
-                               my $bredde_p = 0;
-                               my $bredde_h = 0;
-                               my $bredde_k = 0;
-                               my $bredde_u = 0;
-                               my $bredde_v = 0;
-                               if ( $max_h > 0 ) {
-                                       $bredde_p =
-                                         int( $BarWidth * $_domener_p{$key} / $max_h ) + 1;
-                               }    # use max_h to enable to compare pages with hits
-                               if ( $_domener_p{$key} && $bredde_p == 1 ) { $bredde_p = 2; }
-                               if ( $max_h > 0 ) {
-                                       $bredde_h =
-                                         int( $BarWidth * $_domener_h{$key} / $max_h ) + 1;
-                               }
-                               if ( $_domener_h{$key} && $bredde_h == 1 ) { $bredde_h = 2; }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k =
-                                         int( $BarWidth * ( $_domener_k{$key} || 0 ) / $max_k ) +
-                                         1;
-                               }
-                               if ( $_domener_k{$key} && $bredde_k == 1 ) { $bredde_k = 2; }
-                               my $newkey = lc($key);
-                               if ( $newkey eq 'ip' || !$DomainsHashIDLib{$newkey} ) {
-                                       print
-"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/ip.png\" height=\"14\""
-                                         . AltTitle("$Message[0]")
-                                         . " /></td><td class=\"aws\">$Message[0]</td><td>$newkey</td>";
-                               }
-                               else {
-                                       print
-"<tr><td width=\"$WIDTHCOLICON\"><img src=\"$DirIcons\/flags\/$newkey.png\" height=\"14\""
-                                         . AltTitle("$newkey")
-                                         . " /></td><td class=\"aws\">$DomainsHashIDLib{$newkey}</td><td>$newkey</td>";
-                               }
-                               ## to add unique visitors and number of visits, by Josep Ruano @ CAPSiDE
-                               if ( $ShowDomainsStats =~ /U/i ) {
-                                       $_domener_u = (
-                                                 $_domener_p{$key}
-                                               ? $_domener_p{$key} / $TotalPages
-                                               : 0
-                                       );
-                                       $_domener_u += ( $_domener_h{$key} / $TotalHits );
-                                       $_domener_u =
-                                         sprintf( "%.0f", ( $_domener_u * $TotalUnique ) / 2 );
-                                       print "<td>".Format_Number($_domener_u)." ("
-                                         . sprintf( "%.1f%", 100 * $_domener_u / $TotalUnique )
-                                         . ")</td>";
-                               }
-                               if ( $ShowDomainsStats =~ /V/i ) {
-                                       $_domener_v = (
-                                                 $_domener_p{$key}
-                                               ? $_domener_p{$key} / $TotalPages
-                                               : 0
-                                       );
-                                       $_domener_v += ( $_domener_h{$key} / $TotalHits );
-                                       $_domener_v =
-                                         sprintf( "%.0f", ( $_domener_v * $TotalVisits ) / 2 );
-                                       print "<td>".Format_Number($_domener_v)." ("
-                                         . sprintf( "%.1f%", 100 * $_domener_v / $TotalVisits )
-                                         . ")</td>";
-                               }
+# TotalExits (if not already specifically counted, we init it from _url_x hash table)
+       if ( !$TotalExits ) {
+               foreach ( keys %_url_x ) { $TotalExits += $_url_x{$_}; }
+       }
 
-                               if ( $ShowDomainsStats =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_domener_p{$key} ? Format_Number($_domener_p{$key}) : '&nbsp;' )
-                                         . "</td>";
-                               }
-                               if ( $ShowDomainsStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_domener_h{$key})."</td>";
-                               }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_domener_k{$key} ) . "</td>";
-                               }
-                               print "<td class=\"aws\">";
+# TotalBytesPages (if not already specifically counted, we init it from _url_k hash table)
+       if ( !$TotalBytesPages ) {
+               foreach ( keys %_url_k ) { $TotalBytesPages += $_url_k{$_}; }
+       }
 
-                               if ( $ShowDomainsStats =~ /P/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"5\""
-                                         . AltTitle("")
-                                         . " /><br />\n";
-                               }
-                               if ( $ShowDomainsStats =~ /H/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_h\" height=\"5\""
-                                         . AltTitle("")
-                                         . " /><br />\n";
-                               }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"5\""
-                                         . AltTitle("") . " />";
-                               }
-                               print "</td>";
-                               print "</tr>\n";
+# TotalKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
+       if ( !$TotalKeyphrases ) {
+               foreach ( keys %_keyphrases ) { $TotalKeyphrases += $_keyphrases{$_}; }
+       }
 
-                               $total_u += $_domener_u;
-                               $total_v += $_domener_v;
-                               $total_p += $_domener_p{$key};
-                               $total_h += $_domener_h{$key};
-                               $total_k += $_domener_k{$key} || 0;
-                               $count++;
-                       }
-                       my $rest_u = $TotalUnique - $total_u;
-                       my $rest_v = $TotalVisits - $total_v;
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if (   $rest_u > 0
-                               || $rest_v > 0
-                               || $rest_p > 0
-                               || $rest_h > 0
-                               || $rest_k > 0 )
-                       {    # All other domains (known or not)
-                               print
-"<tr><td width=\"$WIDTHCOLICON\">&nbsp;</td><td colspan=\"2\" class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowDomainsStats =~ /U/i ) { print "<td>$rest_u</td>"; }
-                               if ( $ShowDomainsStats =~ /V/i ) { print "<td>$rest_v</td>"; }
-                               if ( $ShowDomainsStats =~ /P/i ) { print "<td>$rest_p</td>"; }
-                               if ( $ShowDomainsStats =~ /H/i ) { print "<td>$rest_h</td>"; }
-                               if ( $ShowDomainsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
-                               }
-                               print "<td class=\"aws\">&nbsp;</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
-               }
+# TotalKeywords (if not already specifically counted, we init it from _keywords hash table)
+       if ( !$TotalKeywords ) {
+               foreach ( keys %_keywords ) { $TotalKeywords += $_keywords{$_}; }
+       }
 
-               # BY HOST/VISITOR
-               #--------------------------
-               if ($ShowHostsStats) {
-                       if ($Debug) { debug( "ShowHostsStats", 2 ); }
-                       print "$Center<a name=\"visitors\">&nbsp;</a><br />\n";
-                       my $title =
-"$Message[81] ($Message[77] $MaxNbOf{'HostsShown'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=allhosts")
-                               : "$StaticLinks.allhosts.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=lasthosts")
-                               : "$StaticLinks.lasthosts.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[9]</a> &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownip")
-                               : "$StaticLinks.unknownip.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[45]</a>";
-                       &tab_head( "$title", 19, 0, 'visitors' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                       print "<th>";
-                       if ( $MonthRequired ne 'all' ) {
-                               print
-"$Message[81] : ".Format_Number($TotalHostsKnown)." $Message[82], ".Format_Number($TotalHostsUnknown)." $Message[1]<br />".Format_Number($TotalUnique)." $Message[11]</th>";
-                       }
-                       else {
-                               print "$Message[81] : " . ( scalar keys %_host_h ) . "</th>";
-                       }
-                       &ShowHostInfo('__title__');
-                       if ( $ShowHostsStats =~ /P/i ) {
-                               print "<th bgcolor=\"#$color_p\" width=\"80\""
-                                 . Tooltip(3)
-                                 . ">$Message[56]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /H/i ) {
-                               print "<th bgcolor=\"#$color_h\" width=\"80\""
-                                 . Tooltip(4)
-                                 . ">$Message[57]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /B/i ) {
-                               print "<th bgcolor=\"#$color_k\" width=\"80\""
-                                 . Tooltip(5)
-                                 . ">$Message[75]</th>";
-                       }
-                       if ( $ShowHostsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'HostsShown'}, $MinHit{'Host'}, \%_host_h,
-                               \%_host_p );
-                       foreach my $key (@keylist) {
-                               print "<tr>";
-                               print "<td class=\"aws\">$key</td>";
-                               &ShowHostInfo($key);
-                               if ( $ShowHostsStats =~ /P/i ) {
-                                       print '<td>' . ( Format_Number($_host_p{$key}) || "&nbsp;" ) . '</td>';
-                               }
-                               if ( $ShowHostsStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_host_h{$key})."</td>";
-                               }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print '<td>' . Format_Bytes( $_host_k{$key} ) . '</td>';
-                               }
-                               if ( $ShowHostsStats =~ /L/i ) {
-                                       print '<td nowrap="nowrap">'
-                                         . (
-                                               $_host_l{$key}
-                                               ? Format_Date( $_host_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . '</td>';
-                               }
-                               print "</tr>\n";
-                               $total_p += $_host_p{$key};
-                               $total_h += $_host_h{$key};
-                               $total_k += $_host_k{$key} || 0;
-                               $count++;
-                       }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
-                       {    # All other visitors (known or not)
-                               print "<tr>";
-                               print
-"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               &ShowHostInfo('');
-                               if ( $ShowHostsStats =~ /P/i ) { print "<td>".Format_Number($rest_p)."</td>"; }
-                               if ( $ShowHostsStats =~ /H/i ) { print "<td>".Format_Number($rest_h)."</td>"; }
-                               if ( $ShowHostsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
-                               }
-                               if ( $ShowHostsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+# TotalSearchEnginesPages (if not already specifically counted, we init it from _se_referrals_p hash table)
+       if ( !$TotalSearchEnginesPages ) {
+               foreach ( keys %_se_referrals_p ) {
+                       $TotalSearchEnginesPages += $_se_referrals_p{$_};
                }
+       }
 
-               # BY SENDER EMAIL
-               #----------------------------
-               if ($ShowEMailSenders) {
-                       &ShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
+# TotalSearchEnginesHits (if not already specifically counted, we init it from _se_referrals_h hash table)
+       if ( !$TotalSearchEnginesHits ) {
+               foreach ( keys %_se_referrals_h ) {
+                       $TotalSearchEnginesHits += $_se_referrals_h{$_};
                }
+       }
 
-               # BY RECEIVER EMAIL
-               #----------------------------
-               if ($ShowEMailReceivers) {
-                       &ShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
+# TotalRefererPages (if not already specifically counted, we init it from _pagesrefs_p hash table)
+       if ( !$TotalRefererPages ) {
+               foreach ( keys %_pagesrefs_p ) {
+                       $TotalRefererPages += $_pagesrefs_p{$_};
                }
+       }
 
-               # BY LOGIN
-               #----------------------------
-               if ($ShowAuthenticatedUsers) {
-                       if ($Debug) { debug( "ShowAuthenticatedUsers", 2 ); }
-                       print "$Center<a name=\"logins\">&nbsp;</a><br />\n";
-                       my $title =
-"$Message[94] ($Message[77] $MaxNbOf{'LoginShown'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=alllogins")
-                               : "$StaticLinks.alllogins.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a>";
-                       if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                               $title .= " &nbsp; - &nbsp; <a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=lastlogins")
-                                       : "$StaticLinks.lastlogins.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[9]</a>";
-                       }
-                       &tab_head( "$title", 19, 0, 'logins' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[94] : "
-                         . Format_Number(( scalar keys %_login_h )) . "</th>";
-                       &ShowUserInfo('__title__');
-                       if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                               print "<th bgcolor=\"#$color_p\" width=\"80\""
-                                 . Tooltip(3)
-                                 . ">$Message[56]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                               print "<th bgcolor=\"#$color_h\" width=\"80\""
-                                 . Tooltip(4)
-                                 . ">$Message[57]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                               print "<th bgcolor=\"#$color_k\" width=\"80\""
-                                 . Tooltip(5)
-                                 . ">$Message[75]</th>";
-                       }
-                       if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       $max_h = 1;
-                       foreach ( values %_login_h ) {
-                               if ( $_ > $max_h ) { $max_h = $_; }
-                       }
-                       $max_k = 1;
-                       foreach ( values %_login_k ) {
-                               if ( $_ > $max_k ) { $max_k = $_; }
-                       }
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'LoginShown'}, $MinHit{'Login'}, \%_login_h,
-                               \%_login_p );
-                       foreach my $key (@keylist) {
-                               my $bredde_p = 0;
-                               my $bredde_h = 0;
-                               my $bredde_k = 0;
-                               if ( $max_h > 0 ) {
-                                       $bredde_p = int( $BarWidth * $_login_p{$key} / $max_h ) + 1;
-                               }    # use max_h to enable to compare pages with hits
-                               if ( $max_h > 0 ) {
-                                       $bredde_h = int( $BarWidth * $_login_h{$key} / $max_h ) + 1;
-                               }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k = int( $BarWidth * $_login_k{$key} / $max_k ) + 1;
-                               }
-                               print "<tr><td class=\"aws\">$key</td>";
-                               &ShowUserInfo($key);
-                               if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_login_p{$key} ? Format_Number($_login_p{$key}) : "&nbsp;" )
-                                         . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                                       print "<td>".Format_Number($_login_h{$key})."</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_login_k{$key} ) . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_login_l{$key}
-                                               ? Format_Date( $_login_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
-                               }
-                               print "</tr>\n";
-                               $total_p += $_login_p{$key};
-                               $total_h += $_login_h{$key};
-                               $total_k += $_login_k{$key};
-                               $count++;
-                       }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_h = $TotalHits - $total_h;
-                       $rest_k = $TotalBytes - $total_k;
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 )
-                       {    # All other logins
-                               print
-                                 "<tr><td class=\"aws\"><span style=\"color: #$color_other\">"
-                                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                 . "$Message[125]"
-                                 . ( $PageDir eq 'rtl' ? "</span>" : "" )
-                                 . "</span></td>";
-                               &ShowUserInfo('');
-                               if ( $ShowAuthenticatedUsers =~ /P/i ) {
-                                       print "<td>" . ( $rest_p ? Format_Number($rest_p) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /H/i ) {
-                                       print "<td>".Format_Number($rest_h)."</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /B/i ) {
-                                       print "<td>" . Format_Bytes($rest_k) . "</td>";
-                               }
-                               if ( $ShowAuthenticatedUsers =~ /L/i ) {
-                                       print "<td>&nbsp;</td>";
-                               }
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+# TotalRefererHits (if not already specifically counted, we init it from _pagesrefs_h hash table)
+       if ( !$TotalRefererHits ) {
+               foreach ( keys %_pagesrefs_h ) {
+                       $TotalRefererHits += $_pagesrefs_h{$_};
                }
+       }
 
-               # BY ROBOTS
-               #----------------------------
-               if ($ShowRobotsStats) {
-                       if ($Debug) { debug( "ShowRobotStats", 2 ); }
-                       print "$Center<a name=\"robots\">&nbsp;</a><br />\n";
-                       &tab_head(
-"$Message[53] ($Message[77] $MaxNbOf{'RobotShown'}) &nbsp; - &nbsp; <a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=allrobots")
-                                       : "$StaticLinks.allrobots.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[80]</a> &nbsp; - &nbsp; <a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=lastrobots")
-                                       : "$StaticLinks.lastrobots.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[9]</a>",
-                               19, 0, 'robots'
-                       );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(16) . "><th>"
-                         . Format_Number(( scalar keys %_robot_h ))
-                         . " $Message[51]*</th>";
-                       if ( $ShowRobotsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowRobotsStats =~ /B/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ShowRobotsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = $total_r = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'RobotShown'}, $MinHit{'Robot'}, \%_robot_h,
-                               \%_robot_h );
-                       foreach my $key (@keylist) {
-                               print "<tr><td class=\"aws\">"
-                                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                 . ( $RobotsHashIDLib{$key} ? $RobotsHashIDLib{$key} : $key )
-                                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
-                               if ( $ShowRobotsStats =~ /H/i ) {
-                                       print "<td>"
-                                         . Format_Number(( $_robot_h{$key} - $_robot_r{$key} ))
-                                         . ( $_robot_r{$key} ? "+$_robot_r{$key}" : "" ) . "</td>";
-                               }
-                               if ( $ShowRobotsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_robot_k{$key} ) . "</td>";
-                               }
-                               if ( $ShowRobotsStats =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_robot_l{$key}
-                                               ? Format_Date( $_robot_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
-                               }
-                               print "</tr>\n";
+# TotalDifferentPages (if not already specifically counted, we init it from _url_p hash table)
+       $TotalDifferentPages ||= scalar keys %_url_p;
 
-                               #$total_p += $_robot_p{$key};
-                               $total_h += $_robot_h{$key};
-                               $total_k += $_robot_k{$key} || 0;
-                               $total_r += $_robot_r{$key} || 0;
-                               $count++;
-                       }
+# TotalDifferentKeyphrases (if not already specifically counted, we init it from _keyphrases hash table)
+       $TotalDifferentKeyphrases ||= scalar keys %_keyphrases;
 
-                       # For bots we need to count Totals
-                       my $TotalPagesRobots =
-                         0;    #foreach (values %_robot_p) { $TotalPagesRobots+=$_; }
-                       my $TotalHitsRobots = 0;
-                       foreach ( values %_robot_h ) { $TotalHitsRobots += $_; }
-                       my $TotalBytesRobots = 0;
-                       foreach ( values %_robot_k ) { $TotalBytesRobots += $_; }
-                       my $TotalRRobots = 0;
-                       foreach ( values %_robot_r ) { $TotalRRobots += $_; }
-                       $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
-                       $rest_h = $TotalHitsRobots - $total_h;
-                       $rest_k = $TotalBytesRobots - $total_k;
-                       $rest_r = $TotalRRobots - $total_r;
-
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 || $rest_r > 0 )
-                       {               # All other robots
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowRobotsStats =~ /H/i ) {
-                                       print "<td>"
-                                         . Format_Number(( $rest_h - $rest_r ))
-                                         . ( $rest_r ? "+$rest_r" : "" ) . "</td>";
-                               }
-                               if ( $ShowRobotsStats =~ /B/i ) {
-                                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
-                               }
-                               if ( $ShowRobotsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
-                       }
-                       &tab_end(
-                               "* $Message[156]" . ( $TotalRRobots ? " $Message[157]" : "" ) );
+# TotalDifferentKeywords (if not already specifically counted, we init it from _keywords hash table)
+       $TotalDifferentKeywords ||= scalar keys %_keywords;
+
+# TotalDifferentSearchEngines (if not already specifically counted, we init it from _se_referrals_h hash table)
+       $TotalDifferentSearchEngines ||= scalar keys %_se_referrals_h;
+
+# TotalDifferentReferer (if not already specifically counted, we init it from _pagesrefs_h hash table)
+       $TotalDifferentReferer ||= scalar keys %_pagesrefs_h;
+
+# Define firstdaytocountaverage, lastdaytocountaverage, firstdaytoshowtime, lastdaytoshowtime
+       my $firstdaytocountaverage =
+         $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
+       my $firstdaytoshowtime =
+         $nowyear . $nowmonth . "01";    # Set day cursor to 1st day of month
+       my $lastdaytocountaverage =
+         $nowyear . $nowmonth . $nowday;    # Set day cursor to today
+       my $lastdaytoshowtime =
+         $nowyear . $nowmonth . "31";       # Set day cursor to last day of month
+       if ( $MonthRequired eq 'all' ) {
+               $firstdaytocountaverage =
+                 $YearRequired
+                 . "0101";    # Set day cursor to 1st day of the required year
+       }
+       if ( ( $MonthRequired ne $nowmonth && $MonthRequired ne 'all' )
+               || $YearRequired ne $nowyear )
+       {
+               if ( $MonthRequired eq 'all' ) {
+                       $firstdaytocountaverage =
+                         $YearRequired
+                         . "0101";    # Set day cursor to 1st day of the required year
+                       $firstdaytoshowtime =
+                         $YearRequired . "1201"
+                         ;    # Set day cursor to 1st day of last month of required year
+                       $lastdaytocountaverage =
+                         $YearRequired
+                         . "1231";    # Set day cursor to last day of the required year
+                       $lastdaytoshowtime =
+                         $YearRequired . "1231"
+                         ;    # Set day cursor to last day of last month of required year
+               }
+               else {
+                       $firstdaytocountaverage =
+                           $YearRequired
+                         . $MonthRequired
+                         . "01";    # Set day cursor to 1st day of the required month
+                       $firstdaytoshowtime =
+                           $YearRequired
+                         . $MonthRequired
+                         . "01";    # Set day cursor to 1st day of the required month
+                       $lastdaytocountaverage =
+                           $YearRequired
+                         . $MonthRequired
+                         . "31";    # Set day cursor to last day of the required month
+                       $lastdaytoshowtime =
+                           $YearRequired
+                         . $MonthRequired
+                         . "31";    # Set day cursor to last day of the required month
+               }
+       }
+       if ($Debug) {
+               debug(
+"firstdaytocountaverage=$firstdaytocountaverage, lastdaytocountaverage=$lastdaytocountaverage",
+                       1
+               );
+               debug(
+"firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",
+                       1
+               );
+       }
+
+       # Call to plugins' function AddHTMLContentHeader
+       foreach my $pluginname ( keys %{ $PluginsLoaded{'AddHTMLContentHeader'} } )
+       {
+               # to add unique visitors & number of visits, by J Ruano @ CAPSiDE
+               if ( $ShowDomainsStats =~ /U/i ) {
+                       print "<th bgcolor=\"#$color_u\" width=\"80\">$Message[11]</th>";
+               }
+               if ( $ShowDomainsStats =~ /V/i ) {
+                       print "<th bgcolor=\"#$color_v\" width=\"80\">$Message[10]</th>";
                }
 
-               # BY WORMS
-               #----------------------------
-               if ($ShowWormsStats) {
-                       if ($Debug) { debug( "ShowWormsStats", 2 ); }
-                       print "$Center<a name=\"worms\">&nbsp;</a><br />\n";
-                       &tab_head( "$Message[163] ($Message[77] $MaxNbOf{'WormsShown'})",
-                               19, 0, 'worms' );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\"" . Tooltip(21) . ">";
-                       print "<th>" . Format_Number(( scalar keys %_worm_h )) . " $Message[164]*</th>";
-                       print "<th>$Message[167]</th>";
-                       if ( $ShowWormsStats =~ /H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowWormsStats =~ /B/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ShowWormsStats =~ /L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'WormsShown'}, $MinHit{'Worm'}, \%_worm_h,
-                               \%_worm_h );
-                       foreach my $key (@keylist) {
-                               print "<tr>";
-                               print "<td class=\"aws\">"
-                                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                 . ( $WormsHashLib{$key} ? $WormsHashLib{$key} : $key )
-                                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
-                               print "<td class=\"aws\">"
-                                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                 . ( $WormsHashTarget{$key} ? $WormsHashTarget{$key} : $key )
-                                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
-                               if ( $ShowWormsStats =~ /H/i ) {
-                                       print "<td>" . Format_Number($_worm_h{$key}) . "</td>";
-                               }
-                               if ( $ShowWormsStats =~ /B/i ) {
-                                       print "<td>" . Format_Bytes( $_worm_k{$key} ) . "</td>";
-                               }
-                               if ( $ShowWormsStats =~ /L/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_worm_l{$key}
-                                               ? Format_Date( $_worm_l{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
-                               }
-                               print "</tr>\n";
-
-                               #$total_p += $_worm_p{$key};
-                               $total_h += $_worm_h{$key};
-                               $total_k += $_worm_k{$key} || 0;
-                               $count++;
-                       }
+               my $function = "AddHTMLContentHeader_$pluginname";
+               &$function();
+       }
 
-                       # For worms we need to count Totals
-                       my $TotalPagesWorms =
-                         0;    #foreach (values %_worm_p) { $TotalPagesWorms+=$_; }
-                       my $TotalHitsWorms = 0;
-                       foreach ( values %_worm_h ) { $TotalHitsWorms += $_; }
-                       my $TotalBytesWorms = 0;
-                       foreach ( values %_worm_k ) { $TotalBytesWorms += $_; }
-                       $rest_p = 0;    #$rest_p=$TotalPagesRobots-$total_p;
-                       $rest_h = $TotalHitsWorms - $total_h;
-                       $rest_k = $TotalBytesWorms - $total_k;
+       # Output individual frames or static pages for specific sections
+       #-----------------------
+       if ( scalar keys %HTMLOutput == 1 ) {
 
-                       if ( $rest_p > 0 || $rest_h > 0 || $rest_k > 0 ) { # All other worms
-                               print "<tr>";
-                               print
-"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td class=\"aws\">-</td>";
-                               if ( $ShowWormsStats =~ /H/i ) {
-                                       print "<td>" . Format_Number(($rest_h)) . "</td>";
-                               }
-                               if ( $ShowWormsStats =~ /B/i ) {
-                                       print "<td>" . ( Format_Bytes($rest_k) ) . "</td>";
-                               }
-                               if ( $ShowWormsStats =~ /L/i ) { print "<td>&nbsp;</td>"; }
-                               print "</tr>\n";
+               if ( $HTMLOutput{'alldomains'} ) {
+                       &HTMLShowDomains();
+               }
+               if ( $HTMLOutput{'allhosts'} || $HTMLOutput{'lasthosts'} ) {
+                       &HTMLShowHosts();
+               }
+               if ( $HTMLOutput{'unknownip'} ) {
+                       &HTMLShowHostsUnknown();
+               }
+               if ( $HTMLOutput{'allemails'} || $HTMLOutput{'lastemails'} ) {
+                       &HTMLShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
+                       &html_end(1);
+               }
+               if ( $HTMLOutput{'allemailr'} || $HTMLOutput{'lastemailr'} ) {
+                       &HTMLShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
+                       &html_end(1);
+               }
+               if ( $HTMLOutput{'alllogins'} || $HTMLOutput{'lastlogins'} ) {
+                       &HTMLShowLogins();
+               }
+               if ( $HTMLOutput{'allrobots'} || $HTMLOutput{'lastrobots'} ) {
+                       &HTMLShowRobots();
+               }
+               if (   $HTMLOutput{'urldetail'}
+                       || $HTMLOutput{'urlentry'}
+                       || $HTMLOutput{'urlexit'} )
+               {
+                       &HTMLShowURLDetail();
+               }
+               if ( $HTMLOutput{'unknownos'} ) {
+                       &HTMLShowOSUnknown();
+               }
+               if ( $HTMLOutput{'unknownbrowser'} ) {
+                       &HTMLShowBrowserUnknown();
+               }
+               if ( $HTMLOutput{'osdetail'} ) {
+                       &HTMLShowOSDetail();
+               }
+               if ( $HTMLOutput{'browserdetail'} ) {
+                       &HTMLShowBrowserDetail();
+               }
+               if ( $HTMLOutput{'refererse'} ) {
+                       &HTMLShowReferers();
+               }
+               if ( $HTMLOutput{'refererpages'} ) {
+                       &HTMLShowRefererPages();
+               }
+               if ( $HTMLOutput{'keyphrases'} ) {
+                       &HTMLShowKeyPhrases();
+               }
+               if ( $HTMLOutput{'keywords'} ) {
+                       &HTMLShowKeywords();
+               }
+               foreach my $code ( keys %TrapInfosForHTTPErrorCodes ) {
+                       if ( $HTMLOutput{"errors$code"} ) {
+                               &HTMLShowErrorCodes($code);
                        }
-                       &tab_end("* $Message[158]");
                }
 
-               print "\n<a name=\"how\">&nbsp;</a>\n\n";
-
-               # BY SESSION
+               # BY EXTRA SECTIONS
                #----------------------------
-               if ($ShowSessionsStats) {
-                       if ($Debug) { debug( "ShowSessionsStats", 2 ); }
-                       print "$Center<a name=\"sessions\">&nbsp;</a><br />\n";
-                       my $title = "$Message[117]";
-                       &tab_head( $title, 19, 0, 'sessions' );
-                       my $Totals = 0;
-                       foreach (@SessionsRange) {
-                               $average_s += ( $_session{$_} || 0 ) * $SessionsAverage{$_};
-                               $Totals += $_session{$_} || 0;
-                       }
-                       if ($Totals) { $average_s = int( $average_s / $Totals ); }
-                       else { $average_s = '?'; }
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(1)
-                         . "><th>$Message[10]: ".Format_Number($TotalVisits)." - $Message[96]: ".Format_Number($average_s)." s</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[10]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
-                       $average_s = 0;
-                       $total_s   = 0;
-                       my $count = 0;
-                       foreach my $key (@SessionsRange) {
-                               my $p = 0;
-                               if ($TotalVisits) {
-                                       $p = int( $_session{$key} / $TotalVisits * 1000 ) / 10;
-                               }
-                               $total_s += $_session{$key} || 0;
-                               print "<tr><td class=\"aws\">$key</td>";
-                               print "<td>"
-                                 . ( $_session{$key} ? Format_Number($_session{$key}) : "&nbsp;" ) . "</td>";
-                               print "<td>"
-                                 . ( $_session{$key} ? "$p %" : "&nbsp;" ) . "</td>";
-                               print "</tr>\n";
-                               $count++;
-                       }
-                       $rest_s = $TotalVisits - $total_s;
-                       if ( $rest_s > 0 ) {    # All others sessions
-                               my $p = 0;
-                               if ($TotalVisits) {
-                                       $p = int( $rest_s / $TotalVisits * 1000 ) / 10;
-                               }
-                               print "<tr"
-                                 . Tooltip(20)
-                                 . "><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
-                               print "<td>".Format_Number($rest_s)."</td>";
-                               print "<td>" . ( $rest_s ? "$p %" : "&nbsp;" ) . "</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+               HTMLShowExtraSections();
+               
+               if ( $HTMLOutput{'info'} ) {
+                       # TODO Not yet available
+                       print "$Center<a name=\"info\">&nbsp;</a><br />";
+                       &html_end(1);
                }
 
-               # BY FILE TYPE
-               #-------------------------
-               if ($ShowFileTypesStats) {
-                       if ($Debug) { debug( "ShowFileTypesStatsCompressionStats", 2 ); }
-                       print "$Center<a name=\"filetypes\">&nbsp;</a><br />\n";
-                       my $Totalh = 0;
-                       foreach ( keys %_filetypes_h ) { $Totalh += $_filetypes_h{$_}; }
-                       my $Totalk = 0;
-                       foreach ( keys %_filetypes_k ) { $Totalk += $_filetypes_k{$_}; }
-                       my $title = "$Message[73]";
-                       if ( $ShowFileTypesStats =~ /C/i ) { $title .= " - $Message[98]"; }
-                       &tab_head( "$title", 19, 0, 'filetypes' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"3\">$Message[73]</th>";
-
-                       if ( $ShowFileTypesStats =~ /H/i ) {
-                               print "<th bgcolor=\"#$color_h\" width=\"80\""
-                                 . Tooltip(4)
-                                 . ">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       }
-                       if ( $ShowFileTypesStats =~ /B/i ) {
-                               print "<th bgcolor=\"#$color_k\" width=\"80\""
-                                 . Tooltip(5)
-                                 . ">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
-                       }
-                       if ( $ShowFileTypesStats =~ /C/i ) {
-                               print
-"<th bgcolor=\"#$color_k\" width=\"100\">$Message[100]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[101]</th><th bgcolor=\"#$color_k\" width=\"100\">$Message[99]</th>";
-                       }
-                       print "</tr>\n";
-                       my $total_con = 0;
-                       my $total_cre = 0;
-                       my $count     = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_filetypes_h,
-                               \%_filetypes_h );
-                       foreach my $key (@keylist) {
-                               my $p_h = '&nbsp;';
-                               my $p_k = '&nbsp;';
-                               if ($Totalh) {
-                                       $p_h = int( $_filetypes_h{$key} / $Totalh * 1000 ) / 10;
-                                       $p_h = "$p_h %";
-                               }
-                               if ($Totalk) {
-                                       $p_k = int( $_filetypes_k{$key} / $Totalk * 1000 ) / 10;
-                                       $p_k = "$p_k %";
-                               }
-                               if ( $key eq 'Unknown' ) {
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/mime\/unknown.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\" colspan=\"2\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
-                               }
-                               else {
-                                       my $nameicon = $MimeHashIcon{$key} || "notavailable";
-                                       my $nametype =
-                                         $MimeHashLib{ $MimeHashFamily{$key} || "" } || "&nbsp;";
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/mime\/$nameicon.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\">$key</td>";
-                                       print "<td class=\"aws\">$nametype</td>";
-                               }
-                               if ( $ShowFileTypesStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_filetypes_h{$key})."</td><td>$p_h</td>";
-                               }
-                               if ( $ShowFileTypesStats =~ /B/i ) {
-                                       print '<td nowrap="nowrap">'
-                                         . Format_Bytes( $_filetypes_k{$key} )
-                                         . "</td><td>$p_k</td>";
-                               }
-                               if ( $ShowFileTypesStats =~ /C/i ) {
-                                       if ( $_filetypes_gz_in{$key} ) {
-                                               my $percent = int(
-                                                       100 * (
-                                                               1 - $_filetypes_gz_out{$key} /
-                                                                 $_filetypes_gz_in{$key}
-                                                       )
-                                               );
-                                               printf(
-                                                       "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
-                                                       Format_Bytes( $_filetypes_gz_in{$key} ),
-                                                       Format_Bytes( $_filetypes_gz_out{$key} ),
-                                                       Format_Bytes(
-                                                               $_filetypes_gz_in{$key} -
-                                                                 $_filetypes_gz_out{$key}
-                                                       ),
-                                                       $percent
-                                               );
-                                               $total_con += $_filetypes_gz_in{$key};
-                                               $total_cre += $_filetypes_gz_out{$key};
-                                       }
-                                       else {
-                                               print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
-                                       }
-                               }
-                               print "</tr>\n";
-                               $count++;
-                       }
-
-                       # Add total (only usefull if compression is enabled)
-                       if ( $ShowFileTypesStats =~ /C/i ) {
-                               my $colspan = 3;
-                               if ( $ShowFileTypesStats =~ /H/i ) { $colspan += 2; }
-                               if ( $ShowFileTypesStats =~ /B/i ) { $colspan += 2; }
-                               print "<tr>";
-                               print
-"<td class=\"aws\" colspan=\"$colspan\"><b>$Message[98]</b></td>";
-                               if ( $ShowFileTypesStats =~ /C/i ) {
-                                       if ($total_con) {
-                                               my $percent =
-                                                 int( 100 * ( 1 - $total_cre / $total_con ) );
-                                               printf(
-                                                       "<td>%s</td><td>%s</td><td>%s (%s%)</td>",
-                                                       Format_Bytes($total_con),
-                                                       Format_Bytes($total_cre),
-                                                       Format_Bytes( $total_con - $total_cre ),
-                                                       $percent
-                                               );
-                                       }
-                                       else {
-                                               print "<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
-                                       }
-                               }
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+               # Print any plugins that have individual pages
+               # TODO - change name, graph isn't so descriptive
+               my $htmloutput = '';
+               foreach my $key ( keys %HTMLOutput ) { $htmloutput = $key; }
+               if ( $htmloutput =~ /^plugin_(\w+)$/ ) {
+                       my $pluginname = $1;
+                       print "$Center<a name=\"plugin_$pluginname\">&nbsp;</a><br />";
+                       my $function = "AddHTMLGraph_$pluginname";
+                       &$function();
+                       &html_end(1);
                }
+       }
 
-               # BY FILE SIZE
-               #-------------------------
-               if ($ShowFileSizesStats) {
-
+       # Output main page
+       #-----------------
+       if ( $HTMLOutput{'main'} ) {
+               
+               # Calculate averages
+               my $max_p = 0;
+               my $max_h = 0;
+               my $max_k = 0;
+               my $max_v = 0;
+               my $average_nb = 0;
+               foreach my $daycursor (
+                       $firstdaytocountaverage .. $lastdaytocountaverage )
+               {
+                       $daycursor =~ /^(\d\d\d\d)(\d\d)(\d\d)/;
+                       my $year  = $1;
+                       my $month = $2;
+                       my $day   = $3;
+                       if ( !DateIsValid( $day, $month, $year ) ) {
+                               next;
+                       }                 # If not an existing day, go to next
+                       $average_nb++;    # Increase number of day used to count
+                       $AverageVisits += ( $DayVisits{$daycursor} || 0 );
+                       $AveragePages += ( $DayPages{$daycursor}  || 0 );
+                       $AverageHits += ( $DayHits{$daycursor}   || 0 );
+                       $AverageBytes += ( $DayBytes{$daycursor}  || 0 );
+               }
+               if ($average_nb) {
+                       $AverageVisits = $AverageVisits / $average_nb;
+                       $AveragePages = $AveragePages / $average_nb;
+                       $AverageHits = $AverageHits / $average_nb;
+                       $AverageBytes = $AverageBytes / $average_nb;
+                       if ( $AverageVisits > $max_v ) { $max_v = $AverageVisits; }
+                       #if ($average_p > $max_p) { $max_p=$average_p; }
+                       if ( $AverageHits > $max_h ) { $max_h = $AverageHits; }
+                       if ( $AverageBytes > $max_k ) { $max_k = $AverageBytes; }
+               }
+               else {
+                       $AverageVisits = "?";
+                       $AveragePages = "?";
+                       $AverageHits = "?";
+                       $AverageBytes = "?";
                }
 
-               # BY FILE/URL
-               #-------------------------
-               if ($ShowPagesStats) {
-                       if ($Debug) {
-                               debug(
-"ShowPagesStats (MaxNbOf{'PageShown'}=$MaxNbOf{'PageShown'} TotalDifferentPages=$TotalDifferentPages)",
-                                       2
-                               );
-                       }
-                       print
-"$Center<a name=\"urls\">&nbsp;</a><a name=\"entry\">&nbsp;</a><a name=\"exit\">&nbsp;</a><br />\n";
-                       my $title =
-"$Message[19] ($Message[77] $MaxNbOf{'PageShown'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=urldetail")
-                               : "$StaticLinks.urldetail.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a>";
-                       if ( $ShowPagesStats =~ /E/i ) {
-                               $title .= " &nbsp; - &nbsp; <a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=urlentry")
-                                       : "$StaticLinks.urlentry.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[104]</a>";
-                       }
-                       if ( $ShowPagesStats =~ /X/i ) {
-                               $title .= " &nbsp; - &nbsp; <a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=urlexit")
-                                       : "$StaticLinks.urlexit.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[116]</a>";
-                       }
-                       &tab_head( "$title", 19, 0, 'urls' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>".Format_Number($TotalDifferentPages)." $Message[28]</th>";
-                       if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[29]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /B/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[106]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /E/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_e\" width=\"80\">$Message[104]</th>";
-                       }
-                       if ( $ShowPagesStats =~ /X/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_x\" width=\"80\">$Message[116]</th>";
-                       }
-
-                       # Call to plugins' function ShowPagesAddField
-                       foreach
-                         my $pluginname ( keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                       {
-
-                               #                               my $function="ShowPagesAddField_$pluginname('title')";
-                               #                               eval("$function");
-                               my $function = "ShowPagesAddField_$pluginname";
-                               &$function('title');
-                       }
-                       print "<th>&nbsp;</th></tr>\n";
-                       $total_p = $total_e = $total_x = $total_k = 0;
-                       $max_p   = 1;
-                       $max_k   = 1;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'PageShown'}, $MinHit{'File'}, \%_url_p,
-                               \%_url_p );
-                       foreach my $key (@keylist) {
-                               if ( $_url_p{$key} > $max_p ) { $max_p = $_url_p{$key}; }
-                               if ( $_url_k{$key} / ( $_url_p{$key} || 1 ) > $max_k ) {
-                                       $max_k = $_url_k{$key} / ( $_url_p{$key} || 1 );
-                               }
-                       }
-                       foreach my $key (@keylist) {
-                               print "<tr><td class=\"aws\">";
-                               &ShowURLInfo($key);
-                               print "</td>";
-                               my $bredde_p = 0;
-                               my $bredde_e = 0;
-                               my $bredde_x = 0;
-                               my $bredde_k = 0;
-                               if ( $max_p > 0 ) {
-                                       $bredde_p =
-                                         int( $BarWidth * ( $_url_p{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_p == 1 ) && $_url_p{$key} ) { $bredde_p = 2; }
-                               if ( $max_p > 0 ) {
-                                       $bredde_e =
-                                         int( $BarWidth * ( $_url_e{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_e == 1 ) && $_url_e{$key} ) { $bredde_e = 2; }
-                               if ( $max_p > 0 ) {
-                                       $bredde_x =
-                                         int( $BarWidth * ( $_url_x{$key} || 0 ) / $max_p ) + 1;
-                               }
-                               if ( ( $bredde_x == 1 ) && $_url_x{$key} ) { $bredde_x = 2; }
-                               if ( $max_k > 0 ) {
-                                       $bredde_k =
-                                         int( $BarWidth *
-                                                 ( ( $_url_k{$key} || 0 ) / ( $_url_p{$key} || 1 ) ) /
-                                                 $max_k ) + 1;
-                               }
-                               if ( ( $bredde_k == 1 ) && $_url_k{$key} ) { $bredde_k = 2; }
-                               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
-                                       print "<td>".Format_Number($_url_p{$key})."</td>";
-                               }
-                               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
-                                       print "<td>".Format_Number($_url_p{$key})."</td>";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print "<td>"
-                                         . (
-                                               $_url_k{$key}
-                                               ? Format_Bytes(
-                                                       $_url_k{$key} / ( $_url_p{$key} || 1 )
-                                                 )
-                                               : "&nbsp;"
-                                         )
-                                         . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print "<td>"
-                                         . ( $_url_e{$key} ? Format_Number($_url_e{$key}) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print "<td>"
-                                         . ( $_url_x{$key} ? Format_Number($_url_x{$key}) : "&nbsp;" ) . "</td>";
-                               }
-
-                               # Call to plugins' function ShowPagesAddField
-                               foreach my $pluginname (
-                                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                               {
-
-                                       #                                       my $function="ShowPagesAddField_$pluginname('$key')";
-                                       #                                       eval("$function");
-                                       my $function = "ShowPagesAddField_$pluginname";
-                                       &$function($key);
-                               }
-                               print "<td class=\"aws\">";
-                               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hp'}\" width=\"$bredde_p\" height=\"4\""
-                                         . AltTitle("")
-                                         . " /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hh'}\" width=\"$bredde_p\" height=\"4\""
-                                         . AltTitle("")
-                                         . " /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hk'}\" width=\"$bredde_k\" height=\"4\""
-                                         . AltTitle("")
-                                         . " /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'he'}\" width=\"$bredde_e\" height=\"4\""
-                                         . AltTitle("")
-                                         . " /><br />";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print
-"<img src=\"$DirIcons\/other\/$BarPng{'hx'}\" width=\"$bredde_x\" height=\"4\""
-                                         . AltTitle("") . " />";
-                               }
-                               print "</td></tr>\n";
-                               $total_p += $_url_p{$key} || 0;
-                               $total_e += $_url_e{$key} || 0;
-                               $total_x += $_url_x{$key} || 0;
-                               $total_k += $_url_k{$key} || 0;
-                               $count++;
-                       }
-                       $rest_p = $TotalPages - $total_p;
-                       $rest_e = $TotalEntries - $total_e;
-                       $rest_x = $TotalExits - $total_x;
-                       $rest_k = $TotalBytesPages - $total_k;
-                       if ( $rest_p > 0 || $rest_k > 0 || $rest_e > 0 || $rest_x > 0 )
-                       {    # All other urls
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               if ( $ShowPagesStats =~ /P/i && $LogType ne 'F' ) {
-                                       print "<td>".Format_Number($rest_p)."</td>";
-                               }
-                               if ( $ShowPagesStats =~ /[PH]/i && $LogType eq 'F' ) {
-                                       print "<td>".Format_Number($rest_p)."</td>";
-                               }
-                               if ( $ShowPagesStats =~ /B/i ) {
-                                       print "<td>"
-                                         . (
-                                               $rest_k
-                                               ? Format_Bytes( $rest_k / ( $rest_p || 1 ) )
-                                               : "&nbsp;"
-                                         )
-                                         . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /E/i ) {
-                                       print "<td>" . ( $rest_e ? Format_Number($rest_e) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowPagesStats =~ /X/i ) {
-                                       print "<td>" . ( $rest_x ? Format_Number($rest_x) : "&nbsp;" ) . "</td>";
-                               }
-
-                               # Call to plugins' function ShowPagesAddField
-                               foreach my $pluginname (
-                                       keys %{ $PluginsLoaded{'ShowPagesAddField'} } )
-                               {
+               # SUMMARY
+               #---------------------------------------------------------------------
+               if ($ShowSummary) {
+                       &HTMLMainSummary();
+               }
 
-                                       #                                       my $function="ShowPagesAddField_$pluginname('')";
-                                       #                                       eval("$function");
-                                       my $function = "ShowPagesAddField_$pluginname";
-                                       &$function('');
-                               }
-                               print "<td>&nbsp;</td></tr>\n";
-                       }
-                       &tab_end();
+               # BY MONTH
+               #---------------------------------------------------------------------
+               if ($ShowMonthStats) {
+                       &HTMLMainMonthly();
                }
 
-               # BY OS
-               #----------------------------
-               if ($ShowOSStats) {
-                       if ($Debug) { debug( "ShowOSStats", 2 ); }
-                       print "$Center<a name=\"os\">&nbsp;</a><br />\n";
-                       my $Totalh   = 0;
-                       my %new_os_h = ();
-                 OSLOOP: foreach my $key ( keys %_os_h ) {
-                               $Totalh += $_os_h{$key};
-                               foreach my $family ( keys %OSFamily ) {
-                                       if ( $key =~ /^$family/i ) {
-                                               $new_os_h{"${family}cumul"} += $_os_h{$key};
-                                               next OSLOOP;
-                                       }
-                               }
-                               $new_os_h{$key} += $_os_h{$key};
-                       }
-                       my $title =
-"$Message[59] ($Message[77] $MaxNbOf{'OsShown'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=osdetail")
-                               : "$StaticLinks.osdetail.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownos")
-                               : "$StaticLinks.unknownos.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[0]</a>";
-                       &tab_head( "$title", 19, 0, 'os' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th>$Message[59]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'OsShown'}, $MinHit{'Os'}, \%new_os_h,
-                               \%new_os_h );
-                       foreach my $key (@keylist) {
-                               my $p = '&nbsp;';
-                               if ($Totalh) {
-                                       $p = int( $new_os_h{$key} / $Totalh * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               if ( $key eq 'Unknown' ) {
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/os\/unknown.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td>".Format_Number($_os_h{$key})."</td><td>$p</td></tr>\n";
-                               }
-                               else {
-                                       my $keywithoutcumul = $key;
-                                       $keywithoutcumul =~ s/cumul$//i;
-                                       my $libos = $OSHashLib{$keywithoutcumul}
-                                         || $keywithoutcumul;
-                                       my $nameicon = $keywithoutcumul;
-                                       $nameicon =~ s/[^\w]//g;
-                                       if ( $OSFamily{$keywithoutcumul} ) {
-                                               $libos = "<b>" . $OSFamily{$keywithoutcumul} . "</b>";
-                                       }
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/os\/$nameicon.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\">$libos</td><td>".Format_Number($new_os_h{$key})."</td><td>$p</td></tr>\n";
-                               }
-                               $total_h += $new_os_h{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $Totalh / $total_h", 2 );
-                       }
-                       $rest_h = $Totalh - $total_h;
-                       if ( $rest_h > 0 ) {
-                               my $p;
-                               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
-                               print "<tr>";
-                               print "<td>&nbsp;</td>";
-                               print
-"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>".Format_Number($rest_h)."</td>";
-                               print "<td>$p %</td></tr>\n";
-                       }
-                       &tab_end();
+               print "\n<a name=\"when\">&nbsp;</a>\n\n";
+
+               # BY DAY OF MONTH
+               #---------------------------------------------------------------------
+               if ($ShowDaysOfMonthStats) {
+                       &HTMLMainDaily($firstdaytocountaverage, $lastdaytocountaverage,
+                                                 $firstdaytoshowtime, $lastdaytoshowtime);
                }
 
-               # BY BROWSER
-               #----------------------------
-               if ($ShowBrowsersStats) {
-                       if ($Debug) { debug( "ShowBrowsersStats", 2 ); }
-                       print "$Center<a name=\"browsers\">&nbsp;</a><br />\n";
-                       my $Totalh        = 0;
-                       my %new_browser_h = ();
-                 BROWSERLOOP: foreach my $key ( keys %_browser_h ) {
-                               $Totalh += $_browser_h{$key};
-                               foreach my $family ( keys %BrowsersFamily ) {
-                                       if ( $key =~ /^$family/i ) {
-                                               $new_browser_h{"${family}cumul"} += $_browser_h{$key};
-                                               next BROWSERLOOP;
-                                       }
-                               }
-                               $new_browser_h{$key} += $_browser_h{$key};
-                       }
-                       my $title =
-"$Message[21] ($Message[77] $MaxNbOf{'BrowsersShown'}) &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=browserdetail")
-                               : "$StaticLinks.browserdetail.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]/$Message[58]</a> &nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=unknownbrowser")
-                               : "$StaticLinks.unknownbrowser.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[0]</a>";
-                       &tab_head( "$title", 19, 0, 'browsers' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th width=\"$WIDTHCOLICON\">&nbsp;</th><th>$Message[21]</th><th width=\"80\">$Message[111]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList(
-                               $MaxNbOf{'BrowsersShown'}, $MinHit{'Browser'},
-                               \%new_browser_h,           \%new_browser_h
-                       );
-                       foreach my $key (@keylist) {
-                               my $p = '&nbsp;';
-                               if ($Totalh) {
-                                       $p = int( $new_browser_h{$key} / $Totalh * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               if ( $key eq 'Unknown' ) {
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/browser\/unknown.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td><td width=\"80\">?</td><td>".Format_Number($_browser_h{$key})."</td><td>$p</td></tr>\n";
-                               }
-                               else {
-                                       my $keywithoutcumul = $key;
-                                       $keywithoutcumul =~ s/cumul$//i;
-                                       my $libbrowser = $BrowsersHashIDLib{$keywithoutcumul}
-                                         || $keywithoutcumul;
-                                       my $nameicon = $BrowsersHashIcon{$keywithoutcumul}
-                                         || "notavailable";
-                                       if ( $BrowsersFamily{$keywithoutcumul} ) {
-                                               $libbrowser = "<b>$libbrowser</b>";
-                                       }
-                                       print "<tr><td"
-                                         . ( $count ? "" : " width=\"$WIDTHCOLICON\"" )
-                                         . "><img src=\"$DirIcons\/browser\/$nameicon.png\""
-                                         . AltTitle("")
-                                         . " /></td><td class=\"aws\">"
-                                         . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                         . "$libbrowser"
-                                         . ( $PageDir eq 'rtl' ? "</span>" : "" )
-                                         . "</td><td>"
-                                         . (
-                                               $BrowsersHereAreGrabbers{$key}
-                                               ? "<b>$Message[112]</b>"
-                                               : "$Message[113]"
-                                         )
-                                         . "</td><td>".Format_Number($new_browser_h{$key})."</td><td>$p</td></tr>\n";
-                               }
-                               $total_h += $new_browser_h{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $Totalh / $total_h", 2 );
-                       }
-                       $rest_h = $Totalh - $total_h;
-                       if ( $rest_h > 0 ) {
-                               my $p;
-                               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
-                               print "<tr>";
-                               print "<td>&nbsp;</td>";
-                               print
-"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td><td>&nbsp;</td><td>$rest_h</td>";
-                               print "<td>$p %</td></tr>\n";
-                       }
-                       &tab_end();
+               # BY DAY OF WEEK
+               #-------------------------
+               if ($ShowDaysOfWeekStats) {
+                       &HTMLMainDaysofWeek($firstdaytocountaverage, $lastdaytocountaverage);
                }
 
-               # BY SCREEN SIZE
+               # BY HOUR
                #----------------------------
-               if ($ShowScreenSizeStats) {
-                       if ($Debug) { debug( "ShowScreenSizeStats", 2 ); }
-                       print "$Center<a name=\"screensizes\">&nbsp;</a><br />\n";
-                       my $Totalh = 0;
-                       foreach ( keys %_screensize_h ) { $Totalh += $_screensize_h{$_}; }
-                       my $title =
-                         "$Message[135] ($Message[77] $MaxNbOf{'ScreenSizesShown'})";
-                       &tab_head( "$title", 0, 0, 'screensizes' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[135]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th></tr>\n";
-                       my $total_h = 0;
-                       my $count   = 0;
-                       &BuildKeyList( $MaxNbOf{'ScreenSizesShown'},
-                               $MinHit{'ScreenSize'}, \%_screensize_h, \%_screensize_h );
-
-                       foreach my $key (@keylist) {
-                               my $p = '&nbsp;';
-                               if ($Totalh) {
-                                       $p = int( $_screensize_h{$key} / $Totalh * 1000 ) / 10;
-                                       $p = "$p %";
-                               }
-                               $total_h += $_screensize_h{$key} || 0;
-                               print "<tr>";
-                               if ( $key eq 'Unknown' ) {
-                                       print
-"<td class=\"aws\"><span style=\"color: #$color_other\">$Message[0]</span></td>";
-                                       print "<td>$p</td>";
-                               }
-                               else {
-                                       my $screensize = $key;
-                                       print "<td class=\"aws\">$screensize</td>";
-                                       print "<td>$p</td>";
-                               }
-                               print "</tr>\n";
-                               $count++;
-                       }
-                       $rest_h = $Totalh - $total_h;
-                       if ( $rest_h > 0 ) {    # All others sessions
-                               my $p = 0;
-                               if ($Totalh) { $p = int( $rest_h / $Totalh * 1000 ) / 10; }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[2]</span></td>";
-                               print "<td>" . ( $rest_h ? "$p %" : "&nbsp;" ) . "</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+               if ($ShowHoursStats) {
+                       &HTMLMainHours();
                }
 
-               print "\n<a name=\"refering\">&nbsp;</a>\n\n";
+               print "\n<a name=\"who\">&nbsp;</a>\n\n";
 
-               # BY REFERENCE
+               # BY COUNTRY/DOMAIN
                #---------------------------
-               if ($ShowOriginStats) {
-                       if ($Debug) { debug( "ShowOriginStats", 2 ); }
-                       print "$Center<a name=\"referer\">&nbsp;</a><br />\n";
-                       my $Totalp = 0;
-                       foreach ( 0 .. 5 ) {
-                               $Totalp +=
-                                 ( $_ != 4 || $IncludeInternalLinksInOriginSection )
-                                 ? $_from_p[$_]
-                                 : 0;
-                       }
-                       my $Totalh = 0;
-                       foreach ( 0 .. 5 ) {
-                               $Totalh +=
-                                 ( $_ != 4 || $IncludeInternalLinksInOriginSection )
-                                 ? $_from_h[$_]
-                                 : 0;
-                       }
-                       &tab_head( $Message[36], 19, 0, 'referer' );
-                       my @p_p = ( 0, 0, 0, 0, 0, 0 );
-                       if ( $Totalp > 0 ) {
-                               $p_p[0] = int( $_from_p[0] / $Totalp * 1000 ) / 10;
-                               $p_p[1] = int( $_from_p[1] / $Totalp * 1000 ) / 10;
-                               $p_p[2] = int( $_from_p[2] / $Totalp * 1000 ) / 10;
-                               $p_p[3] = int( $_from_p[3] / $Totalp * 1000 ) / 10;
-                               $p_p[4] = int( $_from_p[4] / $Totalp * 1000 ) / 10;
-                               $p_p[5] = int( $_from_p[5] / $Totalp * 1000 ) / 10;
-                       }
-                       my @p_h = ( 0, 0, 0, 0, 0, 0 );
-                       if ( $Totalh > 0 ) {
-                               $p_h[0] = int( $_from_h[0] / $Totalh * 1000 ) / 10;
-                               $p_h[1] = int( $_from_h[1] / $Totalh * 1000 ) / 10;
-                               $p_h[2] = int( $_from_h[2] / $Totalh * 1000 ) / 10;
-                               $p_h[3] = int( $_from_h[3] / $Totalh * 1000 ) / 10;
-                               $p_h[4] = int( $_from_h[4] / $Totalh * 1000 ) / 10;
-                               $p_h[5] = int( $_from_h[5] / $Totalh * 1000 ) / 10;
-                       }
-                       print
-                         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[37]</th>";
-                       if ( $ShowOriginStats =~ /P/i ) {
-                               print
-"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
-                       }
-                       if ( $ShowOriginStats =~ /H/i ) {
-                               print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       }
-                       print "</tr>\n";
+               if ($ShowDomainsStats) {
+                       &HTMLMainCountries($NewLinkParams, $NewLinkTarget);
+               }
 
-                       #------- Referrals by direct address/bookmark/link in email/etc...
-                       print "<tr><td class=\"aws\"><b>$Message[38]</b></td>";
-                       if ( $ShowOriginStats =~ /P/i ) {
-                               print "<td>"
-                                 . ( $_from_p[0] ? Format_Number($_from_p[0]) : "&nbsp;" )
-                                 . "</td><td>"
-                                 . ( $_from_p[0] ? "$p_p[0] %" : "&nbsp;" ) . "</td>";
-                       }
-                       if ( $ShowOriginStats =~ /H/i ) {
-                               print "<td>"
-                                 . ( $_from_h[0] ? Format_Number($_from_h[0]) : "&nbsp;" )
-                                 . "</td><td>"
-                                 . ( $_from_h[0] ? "$p_h[0] %" : "&nbsp;" ) . "</td>";
-                       }
-                       print "</tr>\n";
+               # BY HOST/VISITOR
+               #--------------------------
+               if ($ShowHostsStats) {
+                       &HTMLMainHosts($NewLinkParams, $NewLinkTarget);
+               }
 
-                       #------- Referrals by search engines
-                       print "<tr"
-                         . Tooltip(13)
-                         . "><td class=\"aws\"><b>$Message[40]</b> - <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=refererse")
-                               : "$StaticLinks.refererse.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a><br />\n";
-                       if ( scalar keys %_se_referrals_h ) {
-                               print "<table>\n";
-                               $total_p = 0;
-                               $total_h = 0;
-                               my $count = 0;
-                               &BuildKeyList(
-                                       $MaxNbOf{'RefererShown'},
-                                       $MinHit{'Refer'},
-                                       \%_se_referrals_h,
-                                       (
-                                               ( scalar keys %_se_referrals_p )
-                                               ? \%_se_referrals_p
-                                               : \%_se_referrals_h
-                                       )
-                               );
-                               foreach my $key (@keylist) {
-                                       my $newreferer = $SearchEnginesHashLib{$key}
-                                         || CleanXSS($key);
-                                       print "<tr><td class=\"aws\">- $newreferer</td>";
-                                       print "<td>"
-                                         . (
-                                               Format_Number($_se_referrals_p{$key} ? $_se_referrals_p{$key} : '0' ))
-                                         . "</td>";
-                                       print "<td> / ".Format_Number($_se_referrals_h{$key})."</td>";
-                                       print "</tr>\n";
-                                       $total_p += $_se_referrals_p{$key};
-                                       $total_h += $_se_referrals_h{$key};
-                                       $count++;
-                               }
-                               if ($Debug) {
-                                       debug(
-"Total real / shown : $TotalSearchEnginesPages / $total_p -  $TotalSearchEnginesHits / $total_h",
-                                               2
-                                       );
-                               }
-                               $rest_p = $TotalSearchEnginesPages - $total_p;
-                               $rest_h = $TotalSearchEnginesHits - $total_h;
-                               if ( $rest_p > 0 || $rest_h > 0 ) {
-                                       print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
-                                       print "<td>".Format_Number($rest_p)."</td>";
-                                       print "<td> / ".Format_Number($rest_h)."</td>";
-                                       print "</tr>\n";
-                               }
-                               print "</table>";
-                       }
-                       print "</td>\n";
-                       if ( $ShowOriginStats =~ /P/i ) {
-                               print "<td valign=\"top\">"
-                                 . ( $_from_p[2] ? Format_Number($_from_p[2]) : "&nbsp;" )
-                                 . "</td><td valign=\"top\">"
-                                 . ( $_from_p[2] ? "$p_p[2] %" : "&nbsp;" ) . "</td>";
-                       }
-                       if ( $ShowOriginStats =~ /H/i ) {
-                               print "<td valign=\"top\">"
-                                 . ( $_from_h[2] ? Format_Number($_from_h[2]) : "&nbsp;" )
-                                 . "</td><td valign=\"top\">"
-                                 . ( $_from_h[2] ? "$p_h[2] %" : "&nbsp;" ) . "</td>";
-                       }
-                       print "</tr>\n";
+               # BY SENDER EMAIL
+               #----------------------------
+               if ($ShowEMailSenders) {
+                       &HTMLShowEmailSendersChart( $NewLinkParams, $NewLinkTarget );
+               }
 
-                       #------- Referrals by external HTML link
-                       print "<tr"
-                         . Tooltip(14)
-                         . "><td class=\"aws\"><b>$Message[41]</b> - <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'}
-                                 || !$StaticLinks
-                               ? XMLEncode("$AWScript?${NewLinkParams}output=refererpages")
-                               : "$StaticLinks.refererpages.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a><br />\n";
-                       if ( scalar keys %_pagesrefs_h ) {
-                               print "<table>\n";
-                               $total_p = 0;
-                               $total_h = 0;
-                               my $count = 0;
-                               &BuildKeyList(
-                                       $MaxNbOf{'RefererShown'},
-                                       $MinHit{'Refer'},
-                                       \%_pagesrefs_h,
-                                       (
-                                               ( scalar keys %_pagesrefs_p )
-                                               ? \%_pagesrefs_p
-                                               : \%_pagesrefs_h
-                                       )
-                               );
-                               foreach my $key (@keylist) {
-                                       print "<tr><td class=\"aws\">- ";
-                                       &ShowURLInfo($key);
-                                       print "</td>";
-                                       print "<td>"
-                                         . Format_Number(( $_pagesrefs_p{$key} ? $_pagesrefs_p{$key} : '0' ))
-                                         . "</td>";
-                                       print "<td>".Format_Number($_pagesrefs_h{$key})."</td>";
-                                       print "</tr>\n";
-                                       $total_p += $_pagesrefs_p{$key};
-                                       $total_h += $_pagesrefs_h{$key};
-                                       $count++;
-                               }
-                               if ($Debug) {
-                                       debug(
-"Total real / shown : $TotalRefererPages / $total_p - $TotalRefererHits / $total_h",
-                                               2
-                                       );
-                               }
-                               $rest_p = $TotalRefererPages - $total_p;
-                               $rest_h = $TotalRefererHits - $total_h;
-                               if ( $rest_p > 0 || $rest_h > 0 ) {
-                                       print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">- $Message[2]</span></td>";
-                                       print "<td>".Format_Number($rest_p)."</td>";
-                                       print "<td>".Format_Number($rest_h)."</td>";
-                                       print "</tr>\n";
-                               }
-                               print "</table>";
-                       }
-                       print "</td>\n";
-                       if ( $ShowOriginStats =~ /P/i ) {
-                               print "<td valign=\"top\">"
-                                 . ( $_from_p[3] ? Format_Number($_from_p[3]) : "&nbsp;" )
-                                 . "</td><td valign=\"top\">"
-                                 . ( $_from_p[3] ? "$p_p[3] %" : "&nbsp;" ) . "</td>";
-                       }
-                       if ( $ShowOriginStats =~ /H/i ) {
-                               print "<td valign=\"top\">"
-                                 . ( $_from_h[3] ? Format_Number($_from_h[3]) : "&nbsp;" )
-                                 . "</td><td valign=\"top\">"
-                                 . ( $_from_h[3] ? "$p_h[3] %" : "&nbsp;" ) . "</td>";
-                       }
-                       print "</tr>\n";
+               # BY RECEIVER EMAIL
+               #----------------------------
+               if ($ShowEMailReceivers) {
+                       &HTMLShowEmailReceiversChart( $NewLinkParams, $NewLinkTarget );
+               }
 
-                       #------- Referrals by internal HTML link
-                       if ($IncludeInternalLinksInOriginSection) {
-                               print "<tr><td class=\"aws\"><b>$Message[42]</b></td>";
-                               if ( $ShowOriginStats =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_from_p[4] ? Format_Number($_from_p[4]) : "&nbsp;" )
-                                         . "</td><td>"
-                                         . ( $_from_p[4] ? "$p_p[4] %" : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ShowOriginStats =~ /H/i ) {
-                                       print "<td>"
-                                         . ( $_from_h[4] ? Format_Number($_from_h[4]) : "&nbsp;" )
-                                         . "</td><td>"
-                                         . ( $_from_h[4] ? "$p_h[4] %" : "&nbsp;" ) . "</td>";
-                               }
-                               print "</tr>\n";
-                       }
+               # BY LOGIN
+               #----------------------------
+               if ($ShowAuthenticatedUsers) {
+                       &HTMLMainLogins($NewLinkParams, $NewLinkTarget);
+               }
 
-#------- Referrals by news group
-#print "<tr><td class=\"aws\"><b>$Message[107]</b></td>";
-#if ($ShowOriginStats =~ /P/i) { print "<td>".($_from_p[5]?$_from_p[5]:"&nbsp;")."</td><td>".($_from_p[5]?"$p_p[5] %":"&nbsp;")."</td>"; }
-#if ($ShowOriginStats =~ /H/i) { print "<td>".($_from_h[5]?$_from_h[5]:"&nbsp;")."</td><td>".($_from_h[5]?"$p_h[5] %":"&nbsp;")."</td>"; }
-#print "</tr>\n";
-#------- Unknown origin
-                       print "<tr><td class=\"aws\"><b>$Message[39]</b></td>";
-                       if ( $ShowOriginStats =~ /P/i ) {
-                               print "<td>"
-                                 . ( $_from_p[1] ? Format_Number($_from_p[1]) : "&nbsp;" )
-                                 . "</td><td>"
-                                 . ( $_from_p[1] ? "$p_p[1] %" : "&nbsp;" ) . "</td>";
-                       }
-                       if ( $ShowOriginStats =~ /H/i ) {
-                               print "<td>"
-                                 . ( $_from_h[1] ? Format_Number($_from_h[1]) : "&nbsp;" )
-                                 . "</td><td>"
-                                 . ( $_from_h[1] ? "$p_h[1] %" : "&nbsp;" ) . "</td>";
-                       }
-                       print "</tr>\n";
-                       &tab_end();
+               # BY ROBOTS
+               #----------------------------
+               if ($ShowRobotsStats) {
+                       &HTMLMainRobots($NewLinkParams, $NewLinkTarget);
+               }
 
-                       # 0: Direct
-                       # 1: Unknown
-                       # 2: SE
-                       # 3: External link
-                       # 4: Internal link
-                       # 5: Newsgroup (deprecated)
+               # BY WORMS
+               #----------------------------
+               if ($ShowWormsStats) {
+                       &HTMLMainWorms();
                }
 
-               print "\n<a name=\"keys\">&nbsp;</a>\n\n";
+               print "\n<a name=\"how\">&nbsp;</a>\n\n";
 
-               # BY SEARCH KEYWORDS AND/OR KEYPHRASES
-               #-------------------------------------
-               if ($ShowKeyphrasesStats) {
-                       print "$Center<a name=\"keyphrases\">&nbsp;</a>";
+               # BY SESSION
+               #----------------------------
+               if ($ShowSessionsStats) {
+                       &HTMLMainSessions();
                }
-               if ($ShowKeywordsStats) {
-                       print "$Center<a name=\"keywords\">&nbsp;</a>";
+
+               # BY FILE TYPE
+               #-------------------------
+               if ($ShowFileTypesStats) {
+                       &HTMLMainFileType();
                }
-               if ( $ShowKeyphrasesStats || $ShowKeywordsStats ) { print "<br />\n"; }
-               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                       print
-                         "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr>";
+
+               # BY FILE SIZE
+               #-------------------------
+               if ($ShowFileSizesStats) {
+                       # TODO
+               }
+
+               # BY PAGE
+               #-------------------------
+               if ($ShowPagesStats) {
+                       &HTMLMainPages($NewLinkParams, $NewLinkTarget);
                }
-               if ($ShowKeyphrasesStats) {
 
-                       # By Keyphrases
-                       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                               print "<td width=\"50%\" valign=\"top\">\n";
-                       }
-                       if ($Debug) { debug( "ShowKeyphrasesStats", 2 ); }
-                       &tab_head(
-"$Message[120] ($Message[77] $MaxNbOf{'KeyphrasesShown'})<br /><a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=keyphrases")
-                                       : "$StaticLinks.keyphrases.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[80]</a>",
-                               19,
-                               ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
-                               'keyphrases'
-                       );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(15)
-                         . "><th>$TotalDifferentKeyphrases $Message[103]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'KeyphrasesShown'},
-                               $MinHit{'Keyphrase'}, \%_keyphrases, \%_keyphrases );
-                       foreach my $key (@keylist) {
-                               my $mot;
+               # BY OS
+               #----------------------------
+               if ($ShowOSStats) {
+                       &HTMLMainOS($NewLinkParams, $NewLinkTarget);
+               }
 
-         # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
-                               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
-                                       $mot = CleanXSS(
-                                               DecodeKey_decodeutfkeys(
-                                                       $key, $PageCode || 'iso-8859-1'
-                                               )
-                                       );
-                               }
-                               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
-                               my $p;
-                               if ($TotalKeyphrases) {
-                                       $p =
-                                         int( $_keyphrases{$key} / $TotalKeyphrases * 1000 ) / 10;
-                               }
-                               print "<tr><td class=\"aws\">"
-                                 . XMLEncode($mot)
-                                 . "</td><td>$_keyphrases{$key}</td><td>$p %</td></tr>\n";
-                               $total_s += $_keyphrases{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $TotalKeyphrases / $total_s", 2 );
-                       }
-                       $rest_s = $TotalKeyphrases - $total_s;
-                       if ( $rest_s > 0 ) {
-                               my $p;
-                               if ($TotalKeyphrases) {
-                                       $p = int( $rest_s / $TotalKeyphrases * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[124]</span></td><td>$rest_s</td>";
-                               print "<td>$p&nbsp;%</td></tr>\n";
-                       }
-                       &tab_end();
-                       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                               print "</td>\n";
-                       }
+               # BY BROWSER
+               #----------------------------
+               if ($ShowBrowsersStats) {
+                       &HTMLMainBrowsers($NewLinkParams, $NewLinkTarget);
                }
-               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                       print "<td> &nbsp; </td>";
+
+               # BY SCREEN SIZE
+               #----------------------------
+               if ($ShowScreenSizeStats) {
+                       &HTMLMainScreenSize();
                }
-               if ($ShowKeywordsStats) {
 
-                       # By Keywords
-                       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                               print "<td width=\"50%\" valign=\"top\">\n";
-                       }
-                       if ($Debug) { debug( "ShowKeywordsStats", 2 ); }
-                       &tab_head(
-"$Message[121] ($Message[77] $MaxNbOf{'KeywordsShown'})<br /><a href=\""
-                                 . (
-                                       $ENV{'GATEWAY_INTERFACE'}
-                                         || !$StaticLinks
-                                       ? XMLEncode("$AWScript?${NewLinkParams}output=keywords")
-                                       : "$StaticLinks.keywords.$StaticExt"
-                                 )
-                                 . "\"$NewLinkTarget>$Message[80]</a>",
-                               19,
-                               ( $ShowKeyphrasesStats && $ShowKeywordsStats ) ? 95 : 70,
-                               'keywords'
-                       );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\""
-                         . Tooltip(15)
-                         . "><th>$TotalDifferentKeywords $Message[13]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[14]</th><th bgcolor=\"#$color_s\" width=\"80\">$Message[15]</th></tr>\n";
-                       $total_s = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxNbOf{'KeywordsShown'},
-                               $MinHit{'Keyword'}, \%_keywords, \%_keywords );
-                       foreach my $key (@keylist) {
-                               my $mot;
+               print "\n<a name=\"refering\">&nbsp;</a>\n\n";
 
-         # Convert coded keywords (utf8,...) to be correctly reported in HTML page.
-                               if ( $PluginsLoaded{'DecodeKey'}{'decodeutfkeys'} ) {
-                                       $mot = CleanXSS(
-                                               DecodeKey_decodeutfkeys(
-                                                       $key, $PageCode || 'iso-8859-1'
-                                               )
-                                       );
-                               }
-                               else { $mot = CleanXSS( DecodeEncodedString($key) ); }
-                               my $p;
-                               if ($TotalKeywords) {
-                                       $p = int( $_keywords{$key} / $TotalKeywords * 1000 ) / 10;
-                               }
-                               print "<tr><td class=\"aws\">"
-                                 . XMLEncode($mot)
-                                 . "</td><td>$_keywords{$key}</td><td>$p %</td></tr>\n";
-                               $total_s += $_keywords{$key};
-                               $count++;
-                       }
-                       if ($Debug) {
-                               debug( "Total real / shown : $TotalKeywords / $total_s", 2 );
-                       }
-                       $rest_s = $TotalKeywords - $total_s;
-                       if ( $rest_s > 0 ) {
-                               my $p;
-                               if ($TotalKeywords) {
-                                       $p = int( $rest_s / $TotalKeywords * 1000 ) / 10;
-                               }
-                               print
-"<tr><td class=\"aws\"><span style=\"color: #$color_other\">$Message[30]</span></td><td>$rest_s</td>";
-                               print "<td>$p %</td></tr>\n";
-                       }
-                       &tab_end();
-                       if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                               print "</td>\n";
-                       }
-               }
-               if ( $ShowKeyphrasesStats && $ShowKeywordsStats ) {
-                       print "</tr></table>\n";
+               # BY REFERENCE
+               #---------------------------
+               if ($ShowOriginStats) {
+                       &HTMLMainReferrers($NewLinkParams, $NewLinkTarget);
                }
 
+               print "\n<a name=\"keys\">&nbsp;</a>\n\n";
+
+               # BY SEARCH KEYWORDS AND/OR KEYPHRASES
+               #-------------------------------------
+               if ($ShowKeyphrasesStats || $ShowKeywordsStats){
+                       &HTMLMainKeys($NewLinkParams, $NewLinkTarget);
+               }       
+
                print "\n<a name=\"other\">&nbsp;</a>\n\n";
 
                # BY MISC
                #----------------------------
                if ($ShowMiscStats) {
-                       if ($Debug) { debug( "ShowMiscStats", 2 ); }
-                       print "$Center<a name=\"misc\">&nbsp;</a><br />\n";
-                       my $title = "$Message[139]";
-                       &tab_head( "$title", 19, 0, 'misc' );
-                       print
-                         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[139]</th>";
-                       print "<th width=\"100\">&nbsp;</th>";
-                       print "<th width=\"100\">&nbsp;</th>";
-                       print "</tr>\n";
-                       my %label = (
-                               'AddToFavourites'           => $Message[137],
-                               'JavascriptDisabled'        => $Message[168],
-                               'JavaEnabled'               => $Message[140],
-                               'DirectorSupport'           => $Message[141],
-                               'FlashSupport'              => $Message[142],
-                               'RealPlayerSupport'         => $Message[143],
-                               'QuickTimeSupport'          => $Message[144],
-                               'WindowsMediaPlayerSupport' => $Message[145],
-                               'PDFSupport'                => $Message[146]
-                       );
-
-                       foreach my $key (@MiscListOrder) {
-                               my $mischar = substr( $key, 0, 1 );
-                               if ( $ShowMiscStats !~ /$mischar/i ) { next; }
-                               my $total = 0;
-                               my $p;
-                               if ( $MiscListCalc{$key} eq 'v' ) { $total = $TotalVisits; }
-                               if ( $MiscListCalc{$key} eq 'u' ) { $total = $TotalUnique; }
-                               if ( $MiscListCalc{$key} eq 'hm' ) {
-                                       $total = $_misc_h{'TotalMisc'} || 0;
-                               }
-                               if ($total) {
-                                       $p =
-                                         int( ( $_misc_h{$key} ? $_misc_h{$key} : 0 ) / $total *
-                                                 1000 ) / 10;
-                               }
-                               print "<tr>";
-                               print "<td class=\"aws\">"
-                                 . ( $PageDir eq 'rtl' ? "<span dir=\"ltr\">" : "" )
-                                 . $label{$key}
-                                 . ( $PageDir eq 'rtl' ? "</span>" : "" ) . "</td>";
-                               if ( $MiscListCalc{$key} eq 'v' ) {
-                                       print "<td>"
-                                         . Format_Number(( $_misc_h{$key} || 0 ))
-                                         . " / ".Format_Number($total)." $Message[12]</td>";
-                               }
-                               if ( $MiscListCalc{$key} eq 'u' ) {
-                                       print "<td>"
-                                         . Format_Number(( $_misc_h{$key} || 0 ))
-                                         . " / ".Format_Number($total)." $Message[18]</td>";
-                               }
-                               if ( $MiscListCalc{$key} eq 'hm' ) { print "<td>-</td>"; }
-                               print "<td>" . ( $total ? "$p %" : "&nbsp;" ) . "</td>";
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+                       &HTMLMainMisc();
                }
 
                # BY HTTP STATUS
                #----------------------------
                if ($ShowHTTPErrorsStats) {
-                       if ($Debug) { debug( "ShowHTTPErrorsStats", 2 ); }
-                       print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
-                       my $title = "$Message[32]";
-                       &tab_head( "$title", 19, 0, 'errors' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[32]*</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
-
-                       foreach my $key (@keylist) {
-                               my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
-                               print "<tr" . Tooltip( $key, $key ) . ">";
-                               if ( $TrapInfosForHTTPErrorCodes{$key} ) {
-                                       print "<td><a href=\""
-                                         . (
-                                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                                               ? XMLEncode(
-                                                       "$AWScript?${NewLinkParams}output=errors$key")
-                                               : "$StaticLinks.errors$key.$StaticExt"
-                                         )
-                                         . "\"$NewLinkTarget>$key</a></td>";
-                               }
-                               else { print "<td valign=\"top\">$key</td>"; }
-                               print "<td class=\"aws\">"
-                                 . (
-                                       $httpcodelib{$key} ? $httpcodelib{$key} : 'Unknown error' )
-                                 . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
-                                 . Format_Bytes( $_errors_k{$key} ) . "</td>";
-                               print "</tr>\n";
-                               $total_h += $_errors_h{$key};
-                               $count++;
-                       }
-                       &tab_end("* $Message[154]");
+                       &HTMLMainHTTPStatus($NewLinkParams, $NewLinkTarget);
                }
 
                # BY SMTP STATUS
                #----------------------------
                if ($ShowSMTPErrorsStats) {
-                       if ($Debug) { debug( "ShowSMTPErrorsStats", 2 ); }
-                       print "$Center<a name=\"errors\">&nbsp;</a><br />\n";
-                       my $title = "$Message[147]";
-                       &tab_head( "$title", 19, 0, 'errors' );
-                       print
-"<tr bgcolor=\"#$color_TableBGRowTitle\"><th colspan=\"2\">$Message[147]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th></tr>\n";
-                       $total_h = 0;
-                       my $count = 0;
-                       &BuildKeyList( $MaxRowsInHTMLOutput, 1, \%_errors_h, \%_errors_h );
-
-                       foreach my $key (@keylist) {
-                               my $p = int( $_errors_h{$key} / $TotalHitsErrors * 1000 ) / 10;
-                               print "<tr" . Tooltip( $key, $key ) . ">";
-                               print "<td valign=\"top\">$key</td>";
-                               print "<td class=\"aws\">"
-                                 . (
-                                       $smtpcodelib{$key} ? $smtpcodelib{$key} : 'Unknown error' )
-                                 . "</td><td>".Format_Number($_errors_h{$key})."</td><td>$p %</td><td>"
-                                 . Format_Bytes( $_errors_k{$key} ) . "</td>";
-                               print "</tr>\n";
-                               $total_h += $_errors_h{$key};
-                               $count++;
-                       }
-                       &tab_end();
+                       &HTMLMainSMTPStatus($NewLinkParams, $NewLinkTarget);
                }
 
                # BY CLUSTER
                #----------------------------
                if ($ShowClusterStats) {
-                       if ($Debug) { debug( "ShowClusterStats", 2 ); }
-                       print "$Center<a name=\"clusters\">&nbsp;</a><br />\n";
-                       my $title = "$Message[155]";
-                       &tab_head( "$title", 19, 0, 'clusters' );
-                       print
-                         "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>$Message[155]</th>";
-                       &ShowClusterInfo('__title__');
-                       if ( $ShowClusterStats =~ /P/i ) {
-                               print
-"<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th><th bgcolor=\"#$color_p\" width=\"80\">$Message[15]</th>";
-                       }
-                       if ( $ShowClusterStats =~ /H/i ) {
-                               print
-"<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th><th bgcolor=\"#$color_h\" width=\"80\">$Message[15]</th>";
-                       }
-                       if ( $ShowClusterStats =~ /B/i ) {
-                               print
-"<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th><th bgcolor=\"#$color_k\" width=\"80\">$Message[15]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-
-# Cluster feature might have been enable in middle of month so we recalculate
-# total for cluster section only, to calculate ratio, instead of using global total
-                       foreach my $key ( keys %_cluster_h ) {
-                               $total_p += int( $_cluster_p{$key} || 0 );
-                               $total_h += int( $_cluster_h{$key} || 0 );
-                               $total_k += int( $_cluster_k{$key} || 0 );
-                       }
-                       my $count = 0;
-                       foreach my $key ( keys %_cluster_h ) {
-                               my $p_p = int( $_cluster_p{$key} / $total_p * 1000 ) / 10;
-                               my $p_h = int( $_cluster_h{$key} / $total_h * 1000 ) / 10;
-                               my $p_k = int( $_cluster_k{$key} / $total_k * 1000 ) / 10;
-                               print "<tr>";
-                               print "<td class=\"aws\">Computer $key</td>";
-                               &ShowClusterInfo($key);
-                               if ( $ShowClusterStats =~ /P/i ) {
-                                       print "<td>"
-                                         . ( $_cluster_p{$key} ? Format_Number($_cluster_p{$key}) : "&nbsp;" )
-                                         . "</td><td>$p_p %</td>";
-                               }
-                               if ( $ShowClusterStats =~ /H/i ) {
-                                       print "<td>".Format_Number($_cluster_h{$key})."</td><td>$p_h %</td>";
-                               }
-                               if ( $ShowClusterStats =~ /B/i ) {
-                                       print "<td>"
-                                         . Format_Bytes( $_cluster_k{$key} )
-                                         . "</td><td>$p_k %</td>";
-                               }
-                               print "</tr>\n";
-                               $count++;
-                       }
-                       &tab_end();
+                       &HTMLMainCluster($NewLinkParams, $NewLinkTarget);
                }
 
                # BY EXTRA SECTIONS
                #----------------------------
                foreach my $extranum ( 1 .. @ExtraName - 1 ) {
-                       if ($Debug) { debug( "ExtraName$extranum", 2 ); }
-                       print "$Center<a name=\"extra$extranum\">&nbsp;</a><br />";
-                       my $title = $ExtraName[$extranum];
-                       &tab_head( "$title", 19, 0, "extra$extranum" );
-                       print "<tr bgcolor=\"#$color_TableBGRowTitle\">";
-                       print "<th>" . $ExtraFirstColumnTitle[$extranum];
-                       print "&nbsp; - &nbsp; <a href=\""
-                         . (
-                               $ENV{'GATEWAY_INTERFACE'} || !$StaticLinks
-                               ? XMLEncode(
-                                       "$AWScript?${NewLinkParams}output=allextra$extranum")
-                               : "$StaticLinks.allextra$extranum.$StaticExt"
-                         )
-                         . "\"$NewLinkTarget>$Message[80]</a>";
-                       print "</th>";
-
-                       if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_p\" width=\"80\">$Message[56]</th>";
-                       }
-                       if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_h\" width=\"80\">$Message[57]</th>";
-                       }
-                       if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                               print
-                                 "<th bgcolor=\"#$color_k\" width=\"80\">$Message[75]</th>";
-                       }
-                       if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                               print "<th width=\"120\">$Message[9]</th>";
-                       }
-                       print "</tr>\n";
-                       $total_p = $total_h = $total_k = 0;
-
-        #$max_h=1; foreach (values %_login_h) { if ($_ > $max_h) { $max_h = $_; } }
-        #$max_k=1; foreach (values %_login_k) { if ($_ > $max_k) { $max_k = $_; } }
-                       my $count = 0;
-                       if ( $MaxNbOfExtra[$extranum] ) {
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       &BuildKeyList(
-                                               $MaxNbOfExtra[$extranum],
-                                               $MinHitExtra[$extranum],
-                                               \%{ '_section_' . $extranum . '_h' },
-                                               \%{ '_section_' . $extranum . '_p' }
-                                       );
-                               }
-                               else {
-                                       &BuildKeyList(
-                                               $MaxNbOfExtra[$extranum],
-                                               $MinHitExtra[$extranum],
-                                               \%{ '_section_' . $extranum . '_h' },
-                                               \%{ '_section_' . $extranum . '_h' }
-                                       );
-                               }
-                       }
-                       else {
-                               @keylist = ();
-                       }
-                       my %keysinkeylist = ();
-                       foreach my $key (@keylist) {
-                               $keysinkeylist{$key} = 1;
-                               my $firstcol = CleanXSS( DecodeEncodedString($key) );
-                               $total_p += ${ '_section_' . $extranum . '_p' }{$key};
-                               $total_h += ${ '_section_' . $extranum . '_h' }{$key};
-                               $total_k += ${ '_section_' . $extranum . '_k' }{$key};
-                               print "<tr>";
-                               printf(
-                                       "<td class=\"aws\">$ExtraFirstColumnFormat[$extranum]</td>",
-                                       $firstcol, $firstcol, $firstcol, $firstcol, $firstcol );
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       print "<td>"
-                                         . ${ '_section_' . $extranum . '_p' }{$key} . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                       print "<td>"
-                                         . ${ '_section_' . $extranum . '_h' }{$key} . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                       print "<td>"
-                                         . Format_Bytes(
-                                               ${ '_section_' . $extranum . '_k' }{$key} )
-                                         . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                       print "<td>"
-                                         . (
-                                               ${ '_section_' . $extranum . '_l' }{$key}
-                                               ? Format_Date(
-                                                       ${ '_section_' . $extranum . '_l' }{$key}, 1 )
-                                               : '-'
-                                         )
-                                         . "</td>";
-                               }
-                               print "</tr>\n";
-                               $count++;
-                       }
-
-                       # If we ask average or sum, we loop on all other records
-                       if ( $ExtraAddAverageRow[$extranum] || $ExtraAddSumRow[$extranum] )
-                       {
-                               foreach ( keys %{ '_section_' . $extranum . '_h' } ) {
-                                       if ( $keysinkeylist{$_} ) { next; }
-                                       $total_p += ${ '_section_' . $extranum . '_p' }{$_};
-                                       $total_h += ${ '_section_' . $extranum . '_h' }{$_};
-                                       $total_k += ${ '_section_' . $extranum . '_k' }{$_};
-                                       $count++;
-                               }
-                       }
-
-                       # Add average row
-                       if ( $ExtraAddAverageRow[$extranum] ) {
-                               print "<tr>";
-                               print "<td class=\"aws\"><b>$Message[96]</b></td>";
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       print "<td>"
-                                         . ( $count ? Format_Number(( $total_p / $count )) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                       print "<td>"
-                                         . ( $count ? Format_Number(( $total_h / $count )) : "&nbsp;" ) . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                       print "<td>"
-                                         . (
-                                               $count ? Format_Bytes( $total_k / $count ) : "&nbsp;" )
-                                         . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                       print "<td>&nbsp;</td>";
-                               }
-                               print "</tr>\n";
-                       }
-
-                       # Add sum row
-                       if ( $ExtraAddSumRow[$extranum] ) {
-                               print "<tr>";
-                               print "<td class=\"aws\"><b>$Message[102]</b></td>";
-                               if ( $ExtraStatTypes[$extranum] =~ m/P/i ) {
-                                       print "<td>" . Format_Number(($total_p)) . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/H/i ) {
-                                       print "<td>" . Format_Number(($total_h)) . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/B/i ) {
-                                       print "<td>" . Format_Bytes($total_k) . "</td>";
-                               }
-                               if ( $ExtraStatTypes[$extranum] =~ m/L/i ) {
-                                       print "<td>&nbsp;</td>";
-                               }
-                               print "</tr>\n";
-                       }
-                       &tab_end();
+                       &HTMLMainExtra($NewLinkParams, $NewLinkTarget, $extranum);
                }
 
+               # close the HTML page
                &html_end(1);
        }
 }
index 193971c325e2a20651005b41bdb6e79d4b2523fc..f330415cbed802755b744ff18b93ebb00e013a60 100644 (file)
@@ -6,12 +6,13 @@
 # Perl Required Modules: None
 #-----------------------------------------------------------------------------
 # $Revision$ - $Author$ - $Date$
+# $Revision$ - $Author$ - $Date$
 # 
 # Changelog
 #
 # 1.0 - Initial release
 # 1.1 - Changed scaling: making it independent of chart series
-
+# 1.6 - Added pie charts, visualization hook, map and axis labels
 
 # <-----
 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
 no strict "refs";
 
 
-
 #-----------------------------------------------------------------------------
 # PLUGIN VARIABLES
 #-----------------------------------------------------------------------------
 # <-----
 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
-my $PluginNeedAWStatsVersion = "6.0";
-my $PluginHooksFunctions = "ShowGraph";
+my $PluginNeedAWStatsVersion = "6.95";
+my $PluginHooksFunctions = "Init ShowGraph AddHTMLHeader";
+my $PluginName = "graphgooglechartapi";
+my $ChartProtocol = "http://";
+my $ChartURI = "chart.apis.google.com/chart?"; # Don't put the HTTP part here!
+my $ChartIndex = 0;
+my $title;
+my $type;
+my $imagewidth = 640;                  # maximum image width. 
+my $imageratio = .25;                  # Height is defaulted to 25% of width
+my $pieratio = .20;                            # Height for pie charts should be different
+my $mapratio = .62;                            # Height for maps is different
+my $labellength;
+my @blocklabel = ();
+my @vallabel = ();
+my @valcolor = ();
+my @valmax = ();
+my @valtotal = ();
+my @valaverage = ();
+my @valdata = ();
 # ----->
 
 # <-----
 # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 use vars qw/
 $DirClasses
+$URLIndex
 /;
 # ----->
 
-
 #-----------------------------------------------------------------------------
 # PLUGIN FUNCTION: Init_pluginname
 #-----------------------------------------------------------------------------
@@ -51,97 +69,581 @@ sub Init_graphgooglechartapi {
        $DirClasses = $InitParams;
        # ----->
 
+       $title = "";
+       $type = "";
+       $labellength=2;
+       $ChartIndex = -1;
+       
        return ($checkversion?$checkversion:"$PluginHooksFunctions");
 }
 
-
 #-------------------------------------------------------
 # PLUGIN FUNCTION: ShowGraph_pluginname
 # UNIQUE: YES (Only one plugin using this function can be loaded)
-# Add the code for call to applet awgraphapplet
-# Parameters:  $title $type $showmonthstats \@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal
+# Prints the proper chart depending on the $type provided
+# Parameters:  $title $type $imagewidth \@blocklabel,\@vallabel,\@valcolor,\@valmax,\@valtotal
 # Input:        None
 # Output:       HTML code for awgraphapplet insertion
 # Return:              0 OK, 1 Error
 #-------------------------------------------------------
 sub ShowGraph_graphgooglechartapi() {
-       my $title = shift;
-       my $type = shift;
-       my $showmonthstats = shift;
-       my $blocklabel = shift;
-       my $vallabel = shift;
-       my $valcolor = shift;
-       my $valmax = shift;
-       my $valtotal = shift;
-       my $valaverage = shift;
-       my $valdata = shift;
-
-       my $graphwidth = 780;
-       my $graphheight = 400;
-
-       my $color1 = "4477dd";
-       my $color2 = "66f0ff";
-       my $maxlabellen = 3;
+       $title = shift;
+       $type = shift;
+       $imagewidth = shift || 640;
+       $blocklabel = shift;
+       $vallabel = shift;
+       $valcolor = shift;
+       $valmax = shift;
+       $valtotal = shift;
+       $valaverage = shift;
+       $valdata = shift;
+       
+       # check width
+       if ($imagewidth < 1){$imagewidth=640;}
 
        if ($type eq 'month') {
-               $graphwidth = 540;
-               $graphheight = 160;
-               $color1 = "ffb055";
-               $color2 = "f8e880";
+               $labellength=3;
+               print Get_Img_Tag(Graph_Monthly(), $title);
        }
        elsif ($type eq 'daysofmonth') {
-               $graphwidth = 640;
-               $graphheight = 160;
-               $color1 = "f8e880";
-               $color2 = "4477DD";
-               $maxlabellen = 2; 
+               $labellength=2;
+               print Get_Img_Tag(Graph_Daily(), $title);               
        }
        elsif ($type eq 'daysofweek') {
-               $graphwidth = 300;
-               $graphheight = 160;
+               $labellength=3;
+               print Get_Img_Tag(Graph_Weekly(), $title);              
        }
        elsif ($type eq 'hours') {
-               $graphwidth = 600;
-               $graphheight = 160;
+               $labellength=2;
+               print Get_Img_Tag(Graph_Hourly(), $title);              
+       }
+       elsif ($type eq 'cluster'){
+               $labellength=32;
+               print Get_Img_Tag(Graph_Pie(), $title);         
+       }
+       elsif ($type eq 'filetypes'){
+               $labellength=4;
+               print Get_Img_Tag(Graph_Pie(), $title);
+       }
+       elsif ($type eq 'httpstatus'){
+               $labellength=4;
+               print Get_Img_Tag(Graph_Pie(), $title);
+       }
+       elsif ($type eq 'browsers'){
+               $labellength=32;
+               print Get_Img_Tag(Graph_Pie(), $title);
+       }
+       elsif ($type eq 'oss'){
+               $labellength=32;
+               print Get_Img_Tag(Graph_Pie(), $title);
+       }
+       elsif ($type eq 'hosts'){
+               $labellength=32;
+               print Get_Img_Tag(Graph_Pie(), $title);
+       }
+       elsif ($type eq 'countries_map'){
+               print Chart_Map();
        }
        else {
-               error("Unknown type parameter in ShowGraph_graphgooglechartapi function");
+               debug("Unknown type parameter in ShowGraph_graphgooglechartapi function: $title",1);
+               #error("Unknown type parameter in ShowGraph_graphgooglechartapi function");
+       }
+
+       return 0;
+}
+
+#-------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLHeader_pluginname
+# UNIQUE: NO
+# Prints javascript includes for Google Visualizations
+# Parameters:  None
+# Input:        None
+# Output:       HTML code for Google Visualizations
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub AddHTMLHeader_graphgooglechartapi(){
+       print "<script type='text/javascript' src='http://www.google.com/jsapi'></script>\n";
+}
+
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Graph_Monthly
+# Prints the image code to display a column chart of monthly usage
+# Parameters:  None
+# Input:        None
+# Output:       HTML code to print a chart
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Graph_Monthly(){
+       my $chxt = "chxt=";
+       my $chxl = "chxl=";
+       my $chxs = "chxs=";
+       my $chco = "chco=";
+       my $chg = "chg=";
+       my $chs = "chs=";
+       my $cht = "cht=bvg";
+       my $chd = "chd=t:";
+       my $cba = "chbh=a";                             # shows the whole month
+       my $graphwidth = $imagewidth;
+       my $graphheight = int ($imagewidth * $imageratio);
+       
+       # round max values
+       foreach my $i(0..(scalar @$valmax)){
+               @$valmax[$i] = Round_Up(@$valmax[$i]);
+       }
+       
+       # setup axis
+       $chxt .= "x,y,y,r"; # add an x for years
+       
+       # get the month labels
+       $chxl .= "0:|";
+       $chxl .= Get_Labels();
+       # get the hits/pages max
+       $chxl .= "1:|0|".Get_Suffixed((@$valmax[0]/2),0)."|".Get_Suffixed(@$valmax[0],0)."|";
+       # get the visitors/pages max
+       $chxl .= "2:|0|".Get_Suffixed((@$valmax[2]/2),0)."|".Get_Suffixed(@$valmax[2],0)."|";
+       # get bytes
+       $chxl .= "3:|0|".Get_Suffixed((@$valmax[4]/2),1)."|".Get_Suffixed(@$valmax[4],1);
+       # TODO add the year at the start and end
+       
+       # set the axis colors
+       $chxs .= "1,".@$valcolor[0]."|2,".@$valcolor[2]."|3,".@$valcolor[4];
+       
+       # dump colors
+       foreach my $i(0..(scalar @$valcolor)){
+               $chco .= @$valcolor[$i];
+               if ($i < (scalar @$valcolor)-1){ $chco .= ",";}
+       }
+       
+       # grid lines
+       $chg .= "0,50";
+       
+       # size
+       $chs .= $graphwidth."x".$graphheight;
+       
+       # finally get the data
+       $chd .= Get_Column_Data();
+       
+       # string and dump
+       return "$cht&$chxl&$chxt&$chxs&$chco&$chg&$chs&$chd&$cba";
+}
+
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Graph_Daily
+# Prints the image code to display a column chart of daily usage
+# Parameters:  None
+# Input:        None
+# Output:       HTML code to print a chart
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Graph_Daily(){
+       my $chxt = "chxt=";
+       my $chxl = "chxl=";
+       my $chxs = "chxs=";
+       my $chco = "chco=";
+       my $chg = "chg=";
+       my $chs = "chs=";
+       my $cht = "cht=bvg";
+       my $chd = "chd=t:";
+       my $cba = "chbh=a";                             # shows the whole month
+       my $graphwidth = $imagewidth;
+       my $graphheight = int ($imagewidth * $imageratio);
+       
+       # round max values
+       foreach my $i(0..(scalar @$valmax)){
+               @$valmax[$i] = Round_Up(@$valmax[$i]);
+       }
+       
+       # setup axis
+       $chxt .= "x,y,y,r"; # add an x for years
+       
+       # setup axis labels
+       # get day labels
+       $chxl .= "0:|";
+       $chxl .= Get_Labels();
+       # get the hits/pages max
+       $chxl .= "1:|0|".Get_Suffixed((@$valmax[0]/2),0)."|".Get_Suffixed(@$valmax[0],0)."|";
+       # get the visitors/pages max
+       $chxl .= "2:|0|".Get_Suffixed((@$valmax[1]/2),0)."|".Get_Suffixed(@$valmax[1],0)."|";
+       # get bytes
+       $chxl .= "3:|0|".Get_Suffixed((@$valmax[3]/2),1)."|".Get_Suffixed(@$valmax[3],1);
+       # TODO month name
+       
+       # set the axis colors
+       $chxs .= "1,".@$valcolor[0]."|2,".@$valcolor[1]."|3,".@$valcolor[3];
+       
+       # dump colors
+       foreach my $i(0..(scalar @$valcolor)){
+               $chco .= @$valcolor[$i];
+               if ($i < (scalar @$valcolor)-1){ $chco .= ",";}
+       }
+       
+       # grid lines
+       $chg .= "0,50";
+       
+       # size
+       $chs .= $graphwidth."x".$graphheight;
+       
+       # finally get the data
+       $chd .= Get_Column_Data();
+       
+       # string and dump
+       return "$cht&$chxl&$chxt&$chxs&$chco&$chg&$chs&$chd&$cba";
+}
+
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Graph_Weekly
+# Prints the image code to display a column chart of weekly usage
+# Parameters:  None
+# Input:        None
+# Output:       HTML code to print a chart
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Graph_Weekly(){
+       my $chxt = "chxt=";
+       my $chxl = "chxl=";
+       my $chxs = "chxs=";
+       my $chco = "chco=";
+       my $chg = "chg=";
+       my $chs = "chs=";
+       my $cht = "cht=bvg";
+       my $chd = "chd=t:";
+       my $cba = "chbh=a";                             # shows the whole month
+       my $graphwidth = int ($imagewidth * .75);   # to maintain old look/ratio, reduce width of the weekly
+       my $graphheight = int ($imagewidth * $imageratio);
+       
+       # round max values
+       foreach my $i(0..(scalar @$valmax)){
+               @$valmax[$i] = Round_Up(@$valmax[$i]);
        }
+       
+       # setup axis
+       $chxt .= "x,y,y,r"; # add an x for years
+       
+       # setup axis labels
+       # get the day labels
+       $chxl .= "0:|";
+       $chxl .= Get_Labels();
+       # get the hits/pages max
+       $chxl .= "1:|0|".Get_Suffixed((@$valmax[0]/2),0)."|".Get_Suffixed(@$valmax[0],0)."|";
+       # get the visitors/pages max
+       $chxl .= "2:|0|".Get_Suffixed((@$valmax[1]/2),0)."|".Get_Suffixed(@$valmax[1],0)."|";
+       # get bytes
+       $chxl .= "3:|0|".Get_Suffixed((@$valmax[2]/2),1)."|".Get_Suffixed(@$valmax[2],1);
+       
+       # set the axis colors
+       $chxs .= "1,".@$valcolor[0]."|2,".@$valcolor[1]."|3,".@$valcolor[2];
+       
+       # dump colors
+       foreach my $i(0..(scalar @$valcolor)){
+               $chco .= @$valcolor[$i];
+               if ($i < (scalar @$valcolor)-1){ $chco .= ",";}
+       }
+       
+       # grid lines
+       $chg .= "0,50";
+       
+       # size
+       $chs .= $graphwidth."x".$graphheight;
+       
+       # finally get the data
+       $chd .= Get_Column_Data();
+       
+       # string and dump
+       return "$cht&$chxl&$chxt&$chxs&$chco&$chg&$chs&$chd&$cba";
+}
+       
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Graph_Hourly
+# Prints the image code to display a column chart of hourly usage
+# Parameters:  None
+# Input:        None
+# Output:       HTML code to print a chart
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Graph_Hourly(){
+       my $chxt = "chxt=";
+       my $chxl = "chxl=";
+       my $chxs = "chxs=";
+       my $chco = "chco=";
+       my $chg = "chg=";
+       my $chs = "chs=";
+       my $cht = "cht=bvg";
+       my $chd = "chd=t:";
+       my $cba = "chbh=a";                             # shows the whole month
+       my $graphwidth = $imagewidth;
+       my $graphheight = int ($imagewidth * $imageratio);
+       
+       # round max values
+       foreach my $i(0..(scalar @$valmax - 1)){
+               @$valmax[$i] = Round_Up(@$valmax[$i]);
+       }
+       
+       # setup axis
+       $chxt .= "x,y,y,r"; # add an x for years
+       
+       # setup axis labels
+       $chxl .= "0:|";
+       $chxl .= Get_Labels();
+       # get the hits/pages max
+       $chxl .= "1:|0|".Get_Suffixed((@$valmax[0]/2),0)."|".Get_Suffixed(@$valmax[0],0)."|";
+       # get the visitors/pages max
+       $chxl .= "2:|0|".Get_Suffixed((@$valmax[1]/2),0)."|".Get_Suffixed(@$valmax[1],0)."|";
+       # get bytes
+       $chxl .= "3:|0|".Get_Suffixed((@$valmax[2]/2),1)."|".Get_Suffixed(@$valmax[2],1);
+       # TODO years
+       
+       # set the axis colors
+       $chxs .= "1,".@$valcolor[0]."|2,".@$valcolor[1]."|3,".@$valcolor[2];
+       
+       # dump colors
+       foreach my $i(0..(scalar @$valcolor)){
+               $chco .= @$valcolor[$i];
+               if ($i < (scalar @$valcolor)-1){ $chco .= ",";}
+       }
+       
+       # grid lines
+       $chg .= "0,50";
+       
+       # size
+       $chs .= $graphwidth."x".$graphheight;
+       
+       # finally get the data
+       $chd .= Get_Column_Data();
+       
+       # string and dump
+       return "$cht&$chxl&$chxt&$chxs&$chco&$chg&$chs&$chd&$cba";
+}
 
-       print "<img src = \"http://chart.apis.google.com/chart?cht=bvg&chd=t:";
-       $s = "";
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Graph_Pie
+# Prints the image code to display a pie chart of the provided data
+# Parameters:  None
+# Input:        None
+# Output:       HTML code to print a chart
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Graph_Pie(){
+       my $chl = "chl=";
+       my $chs = "chs=";
+       my $chco = "chco=";
+       my $cht = "cht=p3";
+       my $chd = "chd=t:";
+       my $graphwidth = $imagewidth;
+       my $graphheight = int ($imagewidth * $pieratio);
+       
+       # get labels
+       $chl .= Get_Labels();
+       
+       # get data, just read off the array for however many labels we have
+       foreach my $i (0..((scalar @$blocklabel)-1)) {
+               $chd .= int(@$valdata[$i]);
+               $chd .= ($i < ((scalar @$blocklabel)-1) ? "," : "");
+       }
+       
+       # get color, just the first color passed
+       $chco .= @$valcolor[0];
+       
+       # set size
+       $chs .= $graphwidth."x".$graphheight;
+       
+       return "$cht&$chs&$chco&$chl&$chd";
+}
 
-       # initialise array for 2 data series
-    @max = (0,0);
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Chart_Map
+# Prints a Javascript and DIV tag to display a Google Visualization GeoMap
+# that uses the Flash plugin to display a map of the world shaded to reflect
+# the provided data
+# Parameters:  None
+# Input:        None
+# Output:       Javascript and DIV tag
+# Return:              0 OK, 1 Error
+#-------------------------------------------------------
+sub Chart_Map(){
+       my $graphwidth = $imagewidth;
+       my $graphheight = int ($imagewidth * $mapratio);
+       
+       # Assume we've already included the proper headers so just call our script inline
+       print "\n<script type='text/javascript'>\n";
+       print "google.load('visualization', '1', {'packages': ['geomap']});\n";
+       print "google.setOnLoadCallback(drawMap);\n";
+       print "function drawMap() {\n\tvar data = new google.visualization.DataTable();\n";
+             
+       # get the total number of rows
+       print "\tdata.addRows(".scalar @$blocklabel.");\n";
+       print "\tdata.addColumn('string', 'Country');\n";
+       print "\tdata.addColumn('number', 'Hits');\n";
+             
+       # loop and dump
+    my $i = 0;
+    for ($i .. (scalar @$blocklabel - 1)) {
+       print "\tdata.setValue($i, 0, \"".@$blocklabel[$i]."\");\n";
+       print "\tdata.setValue($i, 1, ".@$valdata[$i].");\n";
+       $i++;
+       # Google's Geomap only supports up to 400 entries
+       if ($i >= 400){ last; }
+    }
+       
+       print "\tvar options = {};\n";
+       print "\toptions['dataMode'] = 'regions';\n";
+       print "\toptions['width'] = $graphwidth;\n";
+       print "\toptions['height'] = $graphheight;\n";
+       print "\tvar container = document.getElementById('$title');\n";
+       print "\tvar geomap = new google.visualization.GeoMap(container);\n";
+       print "\tgeomap.draw(data, options);\n";
+       print "};\n";                   
+       print "</script>\n";
+       
+       # print the div tag that will contain the map
+       print "<div id='$title'></div>\n";
+       return;
+}
 
-       # display only x series
-       $x=1;
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Get_Column_Data
+# Loops through the data array and prints a CHD string to send to a Google
+# chart via the API
+# Parameters:  None
+# Input:        @valcolor, @blocklabel, @valdata, @valmax
+# Output:       None
+# Return:              A pipe delimited string of data. REQUIRES the "chd=t:" prepended
+#-------------------------------------------------------
+# Returns a string with the CHD data
+sub Get_Column_Data(){
+       my $chd = "";
+       
+       # use the # of colors to determine how many values we have
+       $x= scalar @$valcolor;
        for ($serie = 0; $serie <= $x; $serie++) {
-               foreach my $j (1..(scalar @$blocklabel)) {
-                       if ($j > 1) { $s .= ","; }
-                       $val = @$valdata[($j-1)*(scalar @$vallabel)+$serie];
-                       $s .= "$val";
-                       if ($val > $max[$serie]) {
-                               $max[$serie] = $val;
-                       }
+               foreach my $j (1.. (scalar @$blocklabel)) {
+                       if ($j > 1) { $chd .= ","; }
+                       $val = @$valdata[($j-1)*$x+$serie];
+                       # convert our values to a percent of max
+                       $chd .= (@$valmax[$serie] > 0 ? int(($val / Round_Up(@$valmax[$serie])) * 100) : 0);
                }
                if ($serie < $x) {
-                       $s .= "|";
+                       $chd .= "|";
                }
-        }
-       print $s."&chds=0,$max[0],0,$max[1]&chbh=a&chl=";
+    }
+       
+       # return
+       return $chd;
+}
 
-       # display labels
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Get_Labels
+# Returns a CHXL string with labels to send to the Google chart API. Long labels
+# are shortened to $labellength
+# TODO - better shortening method instead of just lopping off the end of strings
+# Parameters:  None
+# Input:        @blocklabel, $labellength
+# Output:       None
+# Return:              A pipe delimited string of labels. REQUIRES the "chxl=" prepended
+#-------------------------------------------------------
+sub Get_Labels(){
+       my $chxl = "";
        foreach my $i (1..(scalar @$blocklabel)) {
-               $b = "".@$blocklabel[$i-1];
-               $b = substr($b,0,$maxlabellen);
-               print $b ."|";
+               $temp = @$blocklabel[$i-1];
+               if (length($temp) > $labellength){
+                       $temp = (substr($temp,0,$labellength));
+               }
+               $chxl .= "$temp|";
        }
-        print "&chs=$graphwidth"; print "x$graphheight&chco=$color1,$color2\" alt=\"\" /><br />\n";
+       return $chxl;
+}
 
-       return 0;
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Round_Up
+# Rounds a number up to the next most significant digit, i.e. 1234 becomes 2000
+# Useful for getting the max values of our graph
+# Parameters:  $num
+# Input:        None
+# Output:       None
+# Return:              The rounded number
+#-------------------------------------------------------
+sub Round_Up(){
+       my $num = shift;
+       $num = int($num);
+       if ($num < 1){ return $num; }
+       
+       # under 100, just increment and dump
+       if ($num < 100){return $num++; }
+       
+       $i = int(substr($num,0,2))+1;
+       
+       # pad with 0s
+       $l = length($i);
+       while ($l<(length($num))){
+               $i .= "0";
+               $l++;
+       }
+       return $i;
 }
 
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Get_Suffixed
+# Converts a number for axis labels and appends the scientific notation suffix
+# or proper size in bytes
+# Parameters:  $num
+# Input:        @Message array from AWStats
+# Output:       None
+# Return:              A number with suffix, i.e. 400 MB or 200 K
+#-------------------------------------------------------
+sub Get_Suffixed(){
+       my $num = shift || 0;
+       my $isbytes = shift || 0;
+       my $float = 0;
+       if ( $num >= ( 1 << 30 ) ) {
+               $float = (split(/\./, $num / 1000000000))[1];
+               if ($float){
+                       return sprintf( "%.1f", $num / 1000000000 ) . ($isbytes ? " $Message[110]" : " B");
+               }else{
+                       return sprintf( "%.0f", $num / 1000000000 ) . ($isbytes ? " $Message[110]" : " B");
+               }
+       }
+       if ( $num >= ( 1 << 20 ) ) {
+               $float = (split(/\./, $num / 1000000))[1];
+               if ($float){
+                       return sprintf( "%.1f", $num / 1000000 ) . ($isbytes ? " $Message[109]" : " M");
+               }else{
+                       return sprintf( "%.0f", $num / 1000000 ) . ($isbytes ? " $Message[109]" : " M");
+               }               
+       }
+       if ( $num >= ( 1 << 10 ) ) {
+               $float = (split(/\./, $num / 1000))[1];
+               if ($float){
+                       return sprintf( "%.1f", $num / 1000 ) . ($isbytes ? " $Message[108]" : " K");
+               }else{
+                       return sprintf( "%.0f", $num / 1000 ) . ($isbytes ? " $Message[108]" : " K");
+               }
+       }
+       return int($num);
+}
 
+#-------------------------------------------------------
+# PLUGIN FUNCTION: Get_Img_Tag
+# Builds the full IMG tag to place in HTML that will call the Google Charts API
+# Parameters:  $params, $title
+# Input:        $ChartProtocol, $ChartURI, $ChartIndex
+# Output:       None
+# Return:              An HTML IMG tag
+#-------------------------------------------------------
+sub Get_Img_Tag(){
+       my $params = shift || "";
+       my $title = shift || "";
+       my $tag = "<img src=\"$ChartProtocol";
+       # for optimization, we can prepend a number to the host address and google will
+       # use different servers to generate our images. This is important if we have multiple
+       # images on the same page
+       # TODO - debug why chart index isn't working as Google says it should
+#      if ($URLIndex < 0){
+               $tag .= "$ChartURI";
+#      }else{
+#              $tag .= "$ChartIndex.$ChartURI";
+#      }
+       $ChartIndex = ($ChartIndex >= 9 ? 0 : $ChartIndex + 1);
+       $tag .= $params;
+       $tag .= "\" alt=\"$title\"/>";
+}
 
 1;     # Do not remove this line