]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't show empty colums in top users report when columns are not requested in sarg...
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 30 Jan 2010 19:10:05 +0000 (19:10 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 30 Jan 2010 19:10:05 +0000 (19:10 +0000)
CMakeLists.txt
html.c
include/conf.h
include/info.h
index.c
topuser.c

index 163a0b9c898741544a7d2758ac1b7fadd7a1c93a..8ebe2457c695d48b584d7c9a524fa0648dd6db4c 100755 (executable)
@@ -3,7 +3,7 @@ PROJECT(sarg C)
 SET(sarg_VERSION 2)
 SET(sarg_REVISION "3rc1")
 SET(sarg_BUILD "")
-SET(sarg_BUILDDATE "Jan-28-2010")
+SET(sarg_BUILDDATE "Jan-30-2010")
 
 INCLUDE(AddFileDependencies)
 INCLUDE(CheckIncludeFile)
diff --git a/html.c b/html.c
index 4e1f188ba1232f0be4e6d4e50a60de2248480ae0..48a9e0d6ee8006e194af08b0748fd3667a06fb81 100644 (file)
--- a/html.c
+++ b/html.c
@@ -34,7 +34,7 @@ void htmlrel(void)
    struct dirent *direntp;
    long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
    long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
-   long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0;
+   long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
    long long int ltemp;
    long long int ntotuser;
    long long int userbytes, userelap;
@@ -44,12 +44,11 @@ void htmlrel(void)
    char userurl[1024], userhora[9], userdia[9];
    char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
    char denied_report[255], name2[MAXLEN];
-   //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
    char *str;
    char warea[MAXLEN];
    char totuser[8];
    long long int tnacc=0, ttnacc=0, unacc=0;
-   float perc=0, perc2=0, ouperc=0, inperc=0;
+   double perc=0, perc2=0, ouperc=0, inperc=0;
    char *s;
    int count;
    int cstatus;
@@ -69,12 +68,10 @@ void htmlrel(void)
 
    strcpy(arqper,dirname);
    strcat(arqper,"/sarg-period");
-
    if ((fp_in = fopen(arqper, "r")) == 0){
       fprintf(stderr, "SARG: (html1) %s: %s\n",text[45],arqper);
       exit(1);
    }
-
    if (!fgets(period,sizeof(period),fp_in)) {
       fprintf(stderr,"SARG: (html1) read error in %s\n",arqper);
       exit(1);
@@ -83,14 +80,15 @@ void htmlrel(void)
 
    strcpy(arqper,dirname);
    strcat(arqper,"/sarg-general");
-
    if ((fp_in = fopen(arqper, "r")) == 0){
       fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
       exit(1);
    }
-
+   ttnacc=0;
+   totbytes=0;
+   totelap=0;
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if(strstr(buf,"TOTAL") == 0) {
+      if(strncmp(buf,"TOTAL\t",6) == 0) {
          getword_start(&gwarea,buf);
          if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
@@ -102,17 +100,28 @@ void htmlrel(void)
             exit(1);
          }
          totbytes+=ltemp;
-         if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
-             getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
-             getword_atoll(&ltemp,&gwarea,'\t')<0) {
+         if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
             printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__);
             exit(1);
          }
          totelap+=ltemp;
       }
    }
+   fclose(fp_in);
 
+   strcpy(arqper,dirname);
+   strcat(arqper,"/sarg-users");
+   if ((fp_in = fopen(arqper, "r")) == 0){
+      fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
+      exit(1);
+   }
+   if (!fgets(totuser,sizeof(totuser),fp_in)) {
+      fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
+      exit(1);
+   }
    fclose(fp_in);
+   ntotuser=my_atoll(totuser);
+   if (ntotuser<=0) ntotuser=1;
 
    dirp = opendir(tmp);
    while ( (direntp = readdir( dirp )) != NULL ) {
@@ -183,6 +192,11 @@ void htmlrel(void)
          exit(1);
       }
 
+      tnacc=0;
+      tnbytes=0;
+      tnelap=0;
+      tnincache=0;
+      tnoucache=0;
       while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
          getword_start(&gwarea,buf);
          if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
@@ -312,29 +326,6 @@ void htmlrel(void)
             exit(1);
          }
 
-         if(nnbytes) {
-            perc=nnbytes * 100;
-            perc=perc / tnbytes;
-         } else {
-            perc=0;
-            ouperc=0;
-         }
-
-         if(nnelap) {
-            perc2=nnelap * 100;
-            perc2=perc2 / tnelap;
-         } else perc2=0;
-
-         if(incache) {
-            inperc=incache * 100;
-            inperc=inperc / nnbytes;
-         } else inperc=0;
-
-         if(oucache) {
-            ouperc=oucache * 100;
-            ouperc=ouperc / nnbytes;
-         } else ouperc=0;
-
          if(UserReportLimit<=0 || count<=UserReportLimit) {
             fputs("<tr>",fp_ou);
 
@@ -387,16 +378,23 @@ void htmlrel(void)
                fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(twork,1));
             if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
                fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(nnbytes,1));
-            if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
-               fprintf(fp_ou,"<td class=\"data\">%3.2f%%</td>",perc);
-            if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
-               fprintf(fp_ou,"<td class=\"data\">%3.2f%%</td><td class=\"data\">%3.2f%%s</td>",inperc,ouperc);
+            if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
+               perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
+               fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
+            }
+            if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
+               inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
+               ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
+               fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
+            }
             if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
                fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(nnelap));
             if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
                fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(nnelap,1));
-            if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
-               fprintf(fp_ou,"<td class=\"data\">%3.2f%%</td>",perc2);
+            if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+               perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
+               fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
+            }
 
             if(strncmp(tmsg,"OK",2) != 0)
                fprintf(fp_ou,"<td class=\"data\">%s</td>",text[46]);
@@ -498,54 +496,40 @@ void htmlrel(void)
          unacc=0;
          unbytes=0;
          unelap=0;
-
       }
 
+      fclose(fp_in);
+
       if(iprel)
          unlink(arqip);
       unlink(arqin);
 
-      if(tnbytes) {
-         perc=totbytes / 100;
-         perc=tnbytes / perc;
-      } else perc=0;
-
-      if(tnelap) {
-         perc2=totelap / 100;
-         perc2=tnelap / perc2;
-      } else perc2=0;
-
-      if(tnoucache) {
-         ouperc=tnoucache * 100;
-         ouperc=ouperc / tnbytes;
-      } else ouperc=0;
-
-      if(tnincache) {
-         inperc=tnincache * 100;
-         inperc=inperc / tnbytes;
-      } else inperc=0;
-
       if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
          fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[107]);
          if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
             fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(tnacc,1));
          if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
             fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(tnbytes,1));
-         if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
-            fprintf(fp_ou,"<th class=\"header2\">%3.2f%%</th>",perc);
-         if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
-            fprintf(fp_ou,"<th class=\"header2\">%3.2f%%</th><th class=\"header2\">%3.2f%%</th>",inperc,ouperc);
+         if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
+            perc=(totbytes) ? tnbytes *100. / totbytes :0.;
+            fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc);
+         }
+         if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
+            inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
+            ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
+            fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th><th class=\"header2\">%3.2lf%%</th>",inperc,ouperc);
+         }
          if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
             fprintf(fp_ou,"<th class=\"header2\">%s</th>",buildtime(tnelap));
          if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
             fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum2(tnelap,1));
-         if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
-            fprintf(fp_ou,"<th class=\"header2\">%3.2f%%</th>",perc2);
+         if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+            perc2=(totelap) ? tnelap * 100. / totelap : 0.;
+            fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc2);
+         }
          fputs("</tr>\n",fp_ou);
       }
 
-      fclose(fp_in);
-
       if(PerUserLimit > 0) {
          if(tnbytes > (PerUserLimit*1000000)) {
             limit_flag=0;
@@ -555,8 +539,7 @@ void htmlrel(void)
                   exit(1);
                }
                while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
-                  if(strstr(tmp6,"\n") != 0)
-                     tmp6[strlen(tmp6)-1]='\0';
+                  fixendofline(tmp6);
                   if(strcmp(tmp6,u2) == 0) {
                      limit_flag=1;
                      break;
@@ -584,60 +567,26 @@ void htmlrel(void)
 //     continue;
 //      }
 
-      if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
-         strcpy(arqper,dirname);
-         strcat(arqper,"/sarg-users");
-
-         if ((fp_in = fopen(arqper, "r")) == 0){
-            fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
-            exit(1);
-         }
-
-         if (!fgets(totuser,sizeof(totuser),fp_in)) {
-            fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
-            exit(1);
-         }
-         fclose(fp_in);
-
-         ntotuser=my_atoll(totuser);
-         if (ntotuser<=0) ntotuser=1;
+      if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
          totbytes2=totbytes/ntotuser;
          totelap2=totelap/ntotuser;
 
-         if(totbytes2) {
-            perc = totbytes / 100;
-            perc = totbytes2 / perc;
-         } else perc=0;
-
-         if(totelap2) {
-            perc2 = totelap / 100;
-            perc2 = totelap2 / perc2;
-         } else perc2=0;
-
-         twork2=ntotuser;
-         twork=ttnacc/twork2;
-
-         if((UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
-            fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[96]);
-            if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
-               fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(twork,1));
-            if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
-               fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(totbytes2,1));
-            fprintf(fp_ou,"<th></th><th></th><th></th>");
-            if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
-               fprintf(fp_ou,"<th class=\"header2\">%s</th>",buildtime(totelap2));
-            if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
-               fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum2(totelap2,1));
-            if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
-               fprintf(fp_ou,"<th class=\"header2\">%3.2f%%</th>",perc2);
-            fputs("</tr>\n",fp_ou);
+         fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th>",text[96]);
+         if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+            fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(ttnacc/ntotuser,1));
+         if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+            fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum(totbytes2,1));
+         fprintf(fp_ou,"<th></th><th></th><th></th>");
+         if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+            fprintf(fp_ou,"<th class=\"header2\">%s</th>",buildtime(totelap2));
+         if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+            fprintf(fp_ou,"<th class=\"header2\">%s</th>",fixnum2(totelap2,1));
+         if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+            perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
+            fprintf(fp_ou,"<th class=\"header2\">%3.2lf%%</th>",perc2);
          }
-      } /* added */
-      tnacc=0;
-      tnbytes=0;
-      tnelap=0;
-      tnincache=0;
-      tnoucache=0;
+         fputs("</tr>\n",fp_ou);
+      }
 
       fputs("</table></div>\n",fp_ou);
 
@@ -648,7 +597,6 @@ void htmlrel(void)
       fclose(fp_ou);
 
       htaccess(wusuario);
-
    }
 
    (void)closedir(dirp);
index 9e52f8a5c6586fd1512c4949be080956b7241544..55729a01ebd6c71290f826573b24f7ff15c12a90 100755 (executable)
@@ -315,16 +315,6 @@ char ExternalCSSFile[MAXLEN];
 char BlockIt[255];
 char BlockImage[512];
 char NtlmUserFormat[30];
-char hbc1[30];
-char hbc2[255];
-char hbc3[30];
-char hbc4[30];
-char hbc5[30];
-char hbc6[30];
-char hbc7[30];
-char hbc8[30];
-char hbc9[30];
-char hbc10[30];
 unsigned long int IndexTree;
 int UserAuthentication;
 char AuthUserFile[255];
index 4bf8b6f1ded8969f80b46525aab6281b38263a0c..ae73c399306a7f873d90fcf4f480d3442eb1219c 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION PACKAGE_VERSION" Jan-28-2010"
+#define VERSION PACKAGE_VERSION" Jan-30-2010"
 #define PGM PACKAGE_NAME
 #define URL "http://sarg.sourceforge.net"
diff --git a/index.c b/index.c
index ab272bce108c4a6e76a6d998cfcf2f67c5c5a963..d013d512e3c85a8ad96ba89f324ce829920758ae 100644 (file)
--- a/index.c
+++ b/index.c
@@ -73,7 +73,6 @@ static void make_date_index(void)
    struct dirent *direntp;
    struct dirent *direntp2;
    struct dirent *direntp3;
-   char hbc1[30];
    char yearindex[MAXLEN];
    char yeardir[MAXLEN];
    char yearnum[10];
@@ -97,7 +96,6 @@ static void make_date_index(void)
    int order;
 
    sprintf(yearindex,"%sindex.html",outdir);
-   strcpy(hbc1,"class=\"header\"");
 
    nyears=0;
    dirp = opendir(outdir);
@@ -133,7 +131,7 @@ static void make_date_index(void)
       exit(1);
    }
    write_html_header(fp_ou, ".");
-   fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[130],hbc1,text[132]);
+   fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[130],text[132]);
    for (y=0 ; y<nyears ; y++) {
       if (order>0)
          year=yearsort[y];
@@ -174,7 +172,7 @@ static void make_date_index(void)
          exit(1);
       }
       write_html_header(fp_ou2,"..");
-      fprintf(fp_ou2,"<tr><th %s>%s/%s</th></tr>\n",hbc1,text[130],text[131]);
+      fprintf(fp_ou2,"<tr><th class=\"header\">%s/%s</th></tr>\n",text[130],text[131]);
       for (m=0 ; m<nmonths ; m++) {
          if (order>0)
             month=monthsort[m];
@@ -229,7 +227,7 @@ static void make_date_index(void)
             exit(1);
          }
          write_html_header(fp_ou3,"../..");
-         fprintf(fp_ou3,"<tr><th %s>%s/%s/%s</th></tr>\n",hbc1,text[130],text[131],text[127]);
+         fprintf(fp_ou3,"<tr><th class=\"header\">%s/%s/%s</th></tr>\n",text[130],text[131],text[127]);
          for (d=0 ; d<ndays ; d++) {
             if (order>0)
                day=daysort[d];
@@ -286,7 +284,6 @@ static void make_file_index(void)
    } **sortlist, *item, **tempsort;
 
    sprintf(wdir,"%sindex.html",outdir);
-   strcpy(hbc1,"class=\"header\"");
 
    order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
 
@@ -384,7 +381,7 @@ static void make_file_index(void)
       exit(1);
    }
    write_html_header(fp_ou,".");
-   fprintf(fp_ou,"<tr><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,text[101],hbc1,text[102],hbc1,text[103],hbc1,text[93],hbc1,text[96]);
+   fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[101],text[102],text[103],text[93],text[96]);
    for (i=0 ; i<nsort ; i++) {
       if (order>0)
          item=sortlist[i];
index 19db7e23355efda9ff04736757017f20f2da5c64..c25f7ab0fd1ec2eb828dd6999a207197f008f32b 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -33,23 +33,20 @@ void topuser(void)
    long long int ttnbytes=0, ttnacc=0, tnacc=0;
    long long int tnbytes=0, ttnelap=0, tnelap=0;
    long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0;
-   long long int twork;
-   long long int twork2;
    long long int nbytes;
    long long int nacc;
    long long int elap, incac, oucac;
-   float perc=0.00;
-   float perc2=0.00;
-   float inperc=0.00, ouperc=0.00;
+   double perc=0.00;
+   double perc2=0.00;
+   double inperc=0.00, ouperc=0.00;
    int posicao=0;
    char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN];
    char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
-   char user[MAXLEN], preg[MAXLEN], tusr[MAXLEN];
+   char user[MAXLEN], tusr[MAXLEN];
    char ip[MAXLEN], time[30], date[30];
    char ipantes[MAXLEN], nameantes[MAXLEN];
    char sfield[10]="2,2";
    char order[255]="-r";
-   char wheader[512]="";
    int  totuser=0;
    int  topcount=0;
    char *s;
@@ -57,17 +54,26 @@ void topuser(void)
    char warea[MAXLEN];
    char user2[MAXLEN];
    char name[MAXLEN];
-   char href1[MAXLEN];
-   char href2[MAXLEN];
-   char href3[MAXLEN];
-   char href1end[5];
-   char href2end[5];
-   char href3end[5];
    struct getwordstruct gwarea;
 
    ipantes[0]='\0';
    nameantes[0]='\0';
 
+   /*
+   * get period
+   */
+   strcpy(arqper,dirname);
+   strcat(arqper,"/sarg-period");
+   if ((fp_in = fopen(arqper, "r")) == 0) {
+      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper);
+      exit(1);
+   }
+   if (!fgets(period,sizeof(period),fp_in)) {
+      fprintf(stderr,"SARG: (topuser) Read error in %s\n",arqper);
+      exit(1);
+   }
+   fclose(fp_in);
+
    strcpy(wger,dirname);
    strcpy(top1,dirname);
    strcpy(top2,dirname);
@@ -169,6 +175,7 @@ void topuser(void)
       tnincache+=incac;
       tnoucache+=oucac;
    }
+   fclose(fp_in);
 
    if (olduser[0] != '\0') {
       my_lltoa(tnbytes,val1,15);
@@ -183,16 +190,8 @@ void topuser(void)
       ttnelap+=tnelap;
       ttnincache+=tnincache;
       ttnoucache+=tnoucache;
-
    }
-
-   my_lltoa(ttnbytes,val1,15);
-   my_lltoa(ttnacc,val2,15);
-   my_lltoa(ttnelap,val3,15);
-   my_lltoa(ttnincache,val4,15);
-   my_lltoa(ttnoucache,val5,15);
-   if (fp_in) fclose(fp_in);
-   if (fp_top2) fclose(fp_top2);
+   fclose(fp_top2);
 
    strup(TopuserSortField);
    strlow(TopuserSortOrder);
@@ -216,40 +215,14 @@ void topuser(void)
       fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
-   if((fp_top1=fopen(top1,"a"))==NULL) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
-      fprintf(stderr, "SARG: sort command: %s\n",csort);
-      exit(1);
-   }
-
-   unlink(top2);
-
-   fprintf(fp_top1,"TOTAL\t%s\t%s\t%s\t%s\t%s\n",val1,val2,val3,val4,val5);
-   fclose(fp_top1);
-
-   /*
-   * get period
-   */
-
-   strcpy(arqper,dirname);
-   strcat(arqper,"/sarg-period");
-
-   if ((fp_in = fopen(arqper, "r")) == 0) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],arqper);
-      exit(1);
-   }
-
-   if (!fgets(period,sizeof(period),fp_in)) {
-      fprintf(stderr,"SARG: (topuser) Read error in %s\n",arqper);
-      exit(1);
-   }
-   fclose(fp_in);
 
    if((fp_top1=fopen(top1,"r"))==NULL) {
       fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1);
       exit(1);
    }
 
+   unlink(top2);
+
    if((fp_top3=fopen(top3,"w"))==NULL) {
       fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top3);
       exit(1);
@@ -266,19 +239,13 @@ void topuser(void)
       show_sarg(fp_top3, "..");
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_top3);
    fprintf(fp_top3,"<tr><th align=\"center\" class=\"title\">%s</th></tr>\n",Title);
-
    fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
-   strcat(wheader,(char *)text[104]);
-   strcat(wheader,": ");
-   strcat(wheader,TopuserSortField);
-   strcat(wheader,", ");
-   strcat(wheader,TopuserSortOrder);
-   fprintf(fp_top3,"<tr><td class=\"header3\">%s</td></tr>\n",wheader);
+   fprintf(fp_top3,"<tr><td class=\"header3\">%s: %s, %s</td></tr>\n",text[104],TopuserSortField,TopuserSortOrder);
    fprintf(fp_top3,"<tr><th class=\"header3\">%s</th></tr>\n",text[137]);
-
    fputs("</table></div>\n",fp_top3);
+
    fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_top3);
-   fputs("<tr><td><br></td><td></td></tr>\n",fp_top3);
+   fputs("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n",fp_top3);
 
    if((ReportType & REPORT_TYPE_TOPSITES) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"11\"><a href=\"topsites.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[119]);
    if((ReportType & REPORT_TYPE_SITES_USERS) != 0 && !Privacy) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"11\"><a href=\"siteuser.html\"><font class=\"link\">%s</font></a><font class=\"text\"></font></td></tr>\n",text[85]);
@@ -292,81 +259,34 @@ void topuser(void)
 
    if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
       fputs("</body>\n</html>\n",fp_top3);
-      if (fp_top3) fclose (fp_top3);
+      fclose (fp_top3);
       return;
    }
 
-   strcpy(hbc10,"class=\"header\"");
-
-   if((TopUserFields & TOPUSERFIELDS_NUM) == 0) {
-      bzero(val1, 255);
-      bzero(hbc1, 30);
-   } else {
-      strcpy(val1,text[100]);
-      strcpy(hbc1,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_USERID) == 0) {
-      bzero(val2, 255);
-      bzero(hbc2, 30);
-   } else {
-      strcpy(val2,text[98]);
-      strcpy(hbc2,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) {
-      bzero(val3, 255);
-      bzero(hbc3, 30);
-   } else {
-      strcpy(val3,text[92]);
-      strcpy(hbc3,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) {
-      bzero(val4, 255);
-      bzero(hbc4, 30);
-   } else {
-      strcpy(val4,text[93]);
-      strcpy(hbc4,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_SETYB) == 0) {
-      bzero(val11, 255);
-      bzero(hbc9, 30);
-   } else {
-      sprintf(val11,"%%%s",text[93]);
-      strcpy(hbc9,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) {
-      bzero(val5, 255);
-      bzero(hbc5, 30);
-      bzero(val9, 255);
-      strcpy(val10,"<td></td>");
-   } else {
-      sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
-      strcpy(hbc5,"class=\"header3\"");
-      strcpy(val9,"colspan=\"2\"");
-      bzero(val10, 255);
-   }
-   if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) {
-      bzero(val6, 255);
-      bzero(hbc6, 30);
-   } else {
-      strcpy(val6,text[94]);
-      strcpy(hbc6,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) {
-      bzero(val7, 255);
-      bzero(hbc7, 30);
-   } else {
-      strcpy(val7,text[95]);
-      strcpy(hbc7,"class=\"header\"");
-   }
-   if((TopUserFields & TOPUSERFIELDS_PTIME) == 0) {
-      bzero(val8, 255);
-      bzero(hbc8, 30);
-   } else {
-      sprintf(val8,"%%%s",text[99]);
-      strcpy(hbc8,"class=\"header\"");
-   }
-
-   fprintf(fp_top3,"<tr><th %s>%s</th><th %s></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s %s>%s%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc1,val1,hbc1,hbc2,val2,hbc3,val3,hbc4,val4,hbc9,val11,hbc5,val9,val5,val10,hbc6,val6,hbc7,val7,hbc8,val8);
+   fputs("<tr>",fp_top3);
+
+   if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[100]);
+   if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+      fputs("<th class=\"header\"></th>",fp_top3);
+   if((TopUserFields & TOPUSERFIELDS_USERID) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[98]);
+   if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[92]);
+   if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[93]);
+   if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%%%s</th>",text[93]);
+   if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+      fprintf(fp_top3,"<th class=\"header3\" colspan=\"2\">%s-%s-%s</th>",text[113],text[114],text[112]);
+   if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[94]);
+   if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[95]);
+   if((TopUserFields & TOPUSERFIELDS_PTIME) != 0)
+      fprintf(fp_top3,"<th class=\"header\">%%%s</th>",text[99]);
+
+   fputs("</tr>\n",fp_top3);
 
    ntopuser = 0;
 
@@ -385,69 +305,25 @@ void topuser(void)
          exit(1);
       }
       if (getword_atoll(&elap,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken elpased time in your %s file.\n",wger);
+         printf("SARG: Maybe you have a broken elpased time in your %s file.\n",top1);
          exit(1);
       }
       if (getword_atoll(&incac,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",wger);
+         printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",top1);
          exit(1);
       }
       if (getword_atoll(&oucac,&gwarea,'\n')<0) {
-         printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",wger);
+         printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",top1);
          exit(1);
       }
-      if(nacc < 1) {
+      if(nacc < 1)
          continue;
-      }
       ntopuser = 1;
       if(TopUsersNum > 0 && topcount >= TopUsersNum) goto final;
-      strcpy(user2,user);
       tnbytes=nbytes;
-
-      if(tnbytes) {
-         perc=tnbytes * 100;
-         perc=perc / ttnbytes;
-      } else perc = 0;
-
-      if(elap) {
-         perc2=elap;
-         perc2=((perc2 * 100) / ttnelap);
-      } else perc2 = 0;
-
-      if(incac) {
-         inperc=incac;
-         inperc=((inperc * 100) / tnbytes);
-      } else inperc = 0;
-
-      if(oucac) {
-         ouperc=oucac;
-         ouperc=((ouperc * 100) / tnbytes);
-      } else ouperc = 0;
-
-      if(strcmp(user,"TOTAL") != 0){
-         sprintf(href1,"<a href=\"%s/%s.html\">",user,user);
-         strcpy(href1end,"</a>");
-         sprintf(href2,"<a href=\"%s/d%s.html\">",user,user);
-         strcpy(href2end,"</a>");
-         sprintf(href3,"<a href=\"%s/graph_day.png\">",user);
-         strcpy(href3end,"</a>");
-         posicao++;
-      } else {
-         strcpy(href1," ");
-         strcpy(href1end,"");
-         strcpy(href2," ");
-         strcpy(href2end,"");
-         strcpy(href3," ");
-         strcpy(href3end,"");
-      }
-
-      if(!Graphs) {
-         bzero(href3,MAXLEN);
-         strcpy(href3end,"");
-      }
-
       tnelap=elap;
 
+      strcpy(user2,user);
       if(userip) {
          fixip(user2);
          if(Ip2Name) {
@@ -459,214 +335,125 @@ void topuser(void)
          }
       }
 
-      if((ReportType & REPORT_TYPE_DATE_TIME) != 0) {
-         sprintf(ltext110,"%s",text[110]);
-         for(s=ltext110; *s; ++s)
-            *s=tolower(*s);
-      } else {
-         bzero(href2, MAXLEN);
-         href2end[0]='\0';
-         bzero(ltext110, 50);
-         sprintf(val1,"%s/d%s.html",dirname,user);
-         unlink(val1);
-      }
+      fputs("<tr>",fp_top3);
 
-      if(strcmp(user2,"TOTAL") != 0) {
-         user_find(name, sizeof(name), user2);
+      posicao++;
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%d</td>",posicao);
 
-         if(Ip2Name &&
-            ((str=(char *) strstr(name, ".")) != (char *) NULL) &&
-            ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
-            ip2name(name,sizeof(name));
-      } else {
-         name[0]='\0';
+      user_find(name, sizeof(name), user2);
+      if(Ip2Name &&
+         ((str=(char *) strstr(name, ".")) != (char *) NULL) &&
+         ((str=(char *) strstr(str+1, ".")) != (char *) NULL))
+         ip2name(name,sizeof(name));
+      if(dotinuser && strchr(name,'_')) {
+         subs(name,sizeof(name),"_",".");
       }
 
-      strcpy(wwork1,fixnum(nacc,1));
-      strcpy(wwork2,fixnum(tnbytes,1));
-      strcpy(wwork3,fixnum2(tnelap,1));
-
-      sprintf(val1,"%d",posicao);
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) {
+         sprintf(ltext110,"%s",text[110]);
+         for(s=ltext110; *s; ++s)
+            *s=tolower(*s);
+         fputs("<td class=\"data2\">",fp_top3);
 #ifdef HAVE_GD
-      sprintf(val2,"%s<img src=\"%s/graph.png\" border=\"0\" title=\"%s\" alt=\"G\">%s&nbsp;%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\" alt=\"T\">%s\n",href3,ImageFile,text[126],href3end,href2,ImageFile,ltext110,text[55],href2end);
-#else
-      sprintf(val2,"%s<img src=\"%s/datetime.png\" border=\"0\" title=\"%s\" alt=\"T\">%s\n",href2,ImageFile,ltext110,href2end);
+         if(Graphs) {
+            fprintf(fp_top3,"<a href=\"%s/graph_day.png\"><img src=\"%s/graph.png\" border=\"0\" title=\"%s\" alt=\"G\"></a>&nbsp;",user,ImageFile,text[126]);
+         }
 #endif
-
-      sprintf(val3,"%3.2f%%",perc);
-      sprintf(val4,"%3.2f%%",inperc);
-      sprintf(val5,"%3.2f%%",ouperc);
-      sprintf(val6,"%s",buildtime(tnelap));
-      sprintf(val7,"%3.2f%%",perc2);
-
-      strcpy(hbc1,"class=\"data\"");
-      strcpy(hbc2,"class=\"data2\"");
-      strcpy(hbc3,"class=\"data\"");
-      strcpy(hbc4,"class=\"data\"");
-      strcpy(hbc5,"class=\"data\"");
-      strcpy(hbc6,"class=\"data\"");
-      strcpy(hbc7,"class=\"data\"");
-      strcpy(hbc8,"class=\"data\"");
-      strcpy(hbc9,"class=\"data\"");
-      strcpy(hbc10,"class=\"data\"");
-
-      if((TopUserFields & TOPUSERFIELDS_NUM) == 0) {
-         bzero(val1, 255);
-         bzero(hbc1, 30);
-      }
-      if((TopUserFields & TOPUSERFIELDS_USERID) == 0) {
-         bzero(val2, 255);
-         bzero(hbc2, 30);
-      }
-      if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) {
-         bzero(wwork1, 255);
-         bzero(hbc3, 30);
-      }
-      if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) {
-         bzero(wwork2, 255);
-         bzero(hbc4, 30);
-      }
-      if((TopUserFields & TOPUSERFIELDS_SETYB) == 0) {
-         bzero(val3, 255);
-         bzero(hbc5, 30);
-      }
-
-      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) {
-         bzero(val4, 255);
-         bzero(hbc6, 30);
-      }
-      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) {
-         bzero(val5, 255);
-         bzero(hbc7, 30);
+         fprintf(fp_top3,"<a href=\"%s/d%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s",user,user,ImageFile,ltext110);
+#ifdef HAVE_GD
+         fprintf(fp_top3," %s",text[55]);
+#endif
+         fputs("\" alt=\"T\"></a></td>",fp_top3);
+      } else {
+         sprintf(val1,"%s/d%s.html",dirname,user);
+         unlink(val1);
       }
-      if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) {
-         bzero(val6, 255);
-         bzero(hbc8, 30);
+      if((TopUserFields & TOPUSERFIELDS_USERID) != 0) {
+         if((ReportType & REPORT_TYPE_USERS_SITES) == 0)
+            fprintf(fp_top3,"<td class=\"data2\">%s</td>",name);
+         else
+            fprintf(fp_top3,"<td class=\"data2\"><a href=\"%s/%s.html\">%s</a></td>",user,user,name);
       }
-      if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) {
-         bzero(wwork3, 255);
-         bzero(hbc9, 30);
+      if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(nacc,1));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum(tnbytes,1));
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0) {
+         perc=(ttnbytes) ? tnbytes * 100. / ttnbytes : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc);
       }
-      if((TopUserFields & TOPUSERFIELDS_PTIME) == 0) {
-         bzero(val7, 255);
-         bzero(hbc10, 30);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0) {
+         inperc=(tnbytes) ? incac * 100. / tnbytes : 0.;
+         ouperc=(tnbytes) ? oucac * 100. / tnbytes : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
       }
-
-      if((ReportType & REPORT_TYPE_USERS_SITES) == 0) {
-         href1[0]='\0';
-         href1end[0]='\0';
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",buildtime(tnelap));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<td class=\"data\">%s</td>",fixnum2(tnelap,1));
+      if((TopUserFields & TOPUSERFIELDS_PTIME) != 0) {
+         perc2=(ttnelap) ? elap * 100. / ttnelap : 0.;
+         fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td>",perc2);
       }
 
-      if(dotinuser && strchr(name,'_')) {
-         subs(name,sizeof(name),"_",".");
-      }
-
-      sprintf(preg,"<tr><td %s>%s</td><td %s>%s</td><td %s>%s%s%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s</td><td %s>%s<td %s>%s</td></tr>\n",hbc1,val1,hbc2,val2,hbc2,href1,name,href1end,hbc3,wwork1,hbc4,wwork2,hbc5,val3,hbc6,val4,hbc7,val5,hbc8,val6,hbc9,wwork3,hbc10,val7);
-
-      if(strstr(user,"TOTAL") != 0) {
-
-         if(incac) {
-            inperc=ttnbytes / 100;
-            inperc=incac / inperc;
-         } else inperc = 0;
-
-         if(oucac) {
-            ouperc=ttnbytes / 100;
-            ouperc=oucac / ouperc;
-         } else ouperc = 0;
-
-         sprintf(wwork1,"%s",fixnum(ttnacc,1));
-         sprintf(wwork2,"%s",fixnum(ttnbytes,1));
-         sprintf(wwork3,"%s",fixnum2(ttnelap,1));
-
-         strcpy(hbc1,"class=\"header2\"");
-         strcpy(hbc2,"class=\"header2\"");
-         strcpy(hbc3,"class=\"header2\"");
-         strcpy(hbc4,"class=\"header2\"");
-         strcpy(hbc5,"class=\"header2\"");
-         strcpy(hbc6,"class=\"header2\"");
-         strcpy(hbc7,"class=\"header2\"");
-         strcpy(hbc8,"class=\"header2\"");
-         strcpy(hbc9,"class=\"header2\"");
-         strcpy(hbc10,"class=\"header\"");
-
-         sprintf(val4,"%3.2f%%",inperc);
-         sprintf(val5,"%3.2f%%",ouperc);
-         sprintf(val6,"%s",buildtime(ttnelap));
-         sprintf(val7,"%3.2f%%",perc2);
-
-         if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) {
-            bzero(wwork1, 255);
-            bzero(hbc1, 30);
-         }
-         if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) {
-            bzero(wwork2, 255);
-            bzero(hbc2, 30);
-         }
-         if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) {
-            bzero(val4, 255);
-            bzero(val5, 255);
-            bzero(hbc3, 30);
-            bzero(hbc4, 30);
-         }
-         if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) {
-            bzero(val6, 255);
-            bzero(hbc5, 30);
-         }
-         if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) {
-            bzero(wwork3, 255);
-            bzero(hbc6, 30);
-         }
-
-         if((ReportType & REPORT_TYPE_DATE_TIME) != 0) {
-           if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0)
-               sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3);
-        } else if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0)
-            sprintf(preg,"<tr><td></td><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[107],hbc1,wwork1,hbc2,wwork2,hbc3,val4,hbc4,val5,hbc5,val6,hbc6,wwork3);
-      }
-
-      fputs(preg,fp_top3);
+      fputs("</tr>\n",fp_top3);
 
       topcount++;
    }
 
-   if(ttnbytes) tnbytes=ttnbytes / totuser;
-   else tnbytes=0;
-
-   twork=ttnacc/totuser;
-   twork2=ttnelap/totuser;
-   strcpy(wwork1,fixnum(twork,1));
-   strcpy(wwork2,fixnum(tnbytes,1));
-   strcpy(wwork3,fixnum2(twork2,1));
-
-   if((TopUserFields & TOPUSERFIELDS_CONNECT) == 0) {
-      bzero(wwork1, 255);
-      bzero(hbc1, 30);
-   }
-   if((TopUserFields & TOPUSERFIELDS_BYTES) == 0) {
-      bzero(wwork2, 255);
-      bzero(hbc2, 30);
-   }
-   if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) == 0) {
-      bzero(val4, 255);
-      bzero(val5, 255);
-      bzero(hbc3, 30);
-      bzero(hbc4, 30);
-   }
-   if((TopUserFields & TOPUSERFIELDS_USED_TIME) == 0) {
-      bzero(val6, 255);
-      bzero(hbc5, 30);
-   }
-   if((TopUserFields & TOPUSERFIELDS_MILISEC) == 0) {
-      bzero(wwork3, 255);
-      bzero(hbc6, 30);
+   if((TopUserFields & TOPUSERFIELDS_TOTAL) != 0) {
+
+      fputs("<tr>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+         fputs("<td></td>",fp_top3);
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[107]);
+
+      if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum(ttnacc,1));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%15s</th>",fixnum(ttnbytes,1));
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+      {
+         inperc=(ttnbytes) ? ttnincache * 100. / ttnbytes : 0.;
+         ouperc=(ttnbytes) ? ttnoucache *100. / ttnbytes : 0.;
+         fprintf(fp_top3,"<th class=\"header2\">%3.2lf%%</th><th class=\"header2\">%3.2lf%%</th>",inperc,ouperc);
+      }
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",buildtime(ttnelap));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum2(ttnelap,1));
+
+      fputs("</tr>\n",fp_top3);
    }
 
-   if(ntopuser) {
-      if(((ReportType & REPORT_TYPE_DATE_TIME) != 0 && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0))
-         fprintf(fp_top3,"<tr><td></td><th></th><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3);
-      else if((TopUserFields & TOPUSERFIELDS_AVERAGE) != 0)
-         fprintf(fp_top3,"<tr><td></td><th></th><td></td><th %s>%s</th><th %s>%s</th><th %s>%15s</th><td></td><td></td><td></td><th %s>%s</th><th %s>%s</th></tr>\n",hbc10,text[96],hbc1,wwork1,hbc2,wwork2,hbc3,buildtime(ttnelap/totuser),hbc4,wwork3);
+   if(ntopuser && (TopUserFields & TOPUSERFIELDS_AVERAGE) != 0) {
+      fputs("<tr>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_NUM) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0)
+         fputs("<td></td>",fp_top3);
+      fprintf(fp_top3,"<th class=\"header\">%s</th>",text[96]);
+
+      if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum(ttnacc/totuser,1));
+      if((TopUserFields & TOPUSERFIELDS_BYTES) != 0) {
+         tnbytes=(totuser) ? ttnbytes / totuser : 0;
+         fprintf(fp_top3,"<th class=\"header2\">%15s</th>",fixnum(tnbytes,1));
+      }
+      if((TopUserFields & TOPUSERFIELDS_SETYB) != 0)
+         fputs("<td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_IN_CACHE_OUT) != 0)
+         fputs("<td></td><td></td>",fp_top3);
+      if((TopUserFields & TOPUSERFIELDS_USED_TIME) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",buildtime(ttnelap/totuser));
+      if((TopUserFields & TOPUSERFIELDS_MILISEC) != 0)
+         fprintf(fp_top3,"<th class=\"header2\">%s</th>",fixnum2(ttnelap/totuser,1));
+      fputs("</tr>\n",fp_top3);
    }
 
    if(UserAgentLog[0] != '\0') {