]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't fail if report_type doesn't request for topusers
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 31 Jan 2012 19:49:47 +0000 (20:49 +0100)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 31 Jan 2012 19:49:47 +0000 (20:49 +0100)
The topusers page is always generated and now serves as an index for the
other report pages instead of promoting the topsites pages as the main
page.

topsites.c
topuser.c

index 9c05b211791c7b024f385726f481e5bc323dd981..6ca2cfe8eee804798b3afc3dc0bbb7afbe9ca417 100644 (file)
@@ -76,10 +76,7 @@ void topsites(void)
        sprintf(general2,"%s/sarg-general2",outdirname);
        sprintf(general3,"%s/sarg-general3",outdirname);
 
-       if ((ReportType & REPORT_TYPE_TOPUSERS) == 0)
-               sprintf(report,"%s/index.html",outdirname);
-       else
-               sprintf(report,"%s/topsites.html",outdirname);
+       sprintf(report,"%s/topsites.html",outdirname);
 
        if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) {
                debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general,general2);
index 0f1f7125693a7052ac62c50f8b101d496c791f54..24b9b64ea21d62b909a9a67b0fab08f6cb7ba05d 100644 (file)
--- a/topuser.c
+++ b/topuser.c
 
 extern struct globalstatstruct globstat;
 
+/*!
+Save the total number of users. The number is written in sarg-users and set
+in a global variable for further reference.
+
+\param totuser The total number of users.
+*/
+static void set_total_users(int totuser)
+{
+       char tusr[1024];
+       FILE *fp_ou;
+       
+       snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
+       if((fp_ou=fopen(tusr,"w"))==NULL) {
+               debuga(_("(topuser) Cannot open file %s\n"),tusr);
+               exit(EXIT_FAILURE);
+       }
+       fprintf(fp_ou,"%d\n",totuser);
+       if (fclose(fp_ou)==EOF)
+               debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno));
+       globstat.totuser=totuser;
+}
+
 void topuser(void)
 {
-       FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
+       FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
        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;
@@ -44,7 +66,7 @@ void topuser(void)
        int posicao=0;
        char olduser[MAX_USER_LEN], csort[MAXLEN];
        char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN];
-       char user[MAX_USER_LEN], tusr[MAXLEN];
+       char user[MAX_USER_LEN];
        const char *sfield="-n -k 2,2";
        const char *order;
        const char *sort_field;
@@ -139,6 +161,8 @@ void topuser(void)
        }
 #endif
 
+       set_total_users(totuser);
+
        if((TopuserSort & TOPUSER_SORT_USER) != 0) {
                sfield="-k 1,1";
                sort_field=_("user");
@@ -193,10 +217,17 @@ void topuser(void)
        fputs("<tr><td class=\"header_c\">",fp_top3);
        fprintf(fp_top3,_("Period: %s"),period.html);
        fputs("</td></tr>\n",fp_top3);
-       fputs("<tr><td class=\"header_c\">",fp_top3);
-       fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
-       fputs("</td></tr>\n",fp_top3);
-       fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
+       if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
+               fputs("<tr><td class=\"header_c\">",fp_top3);
+               fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order);
+               fputs("</td></tr>\n",fp_top3);
+               fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Top users"));
+       } else {
+               /* TRANSLATORS: This is the title of the main report page when no
+                * top users list are requested.
+                */
+               fprintf(fp_top3,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Table of content"));
+       }
        close_html_header(fp_top3);
 
        if (!indexonly) {
@@ -445,15 +476,5 @@ void topuser(void)
        if (fclose(fp_top3)==EOF)
                debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno));
 
-       snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
-       if((fp_ou=fopen(tusr,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s\n"),tusr);
-               exit(EXIT_FAILURE);
-       }
-       fprintf(fp_ou,"%d\n",totuser);
-       if (fclose(fp_ou)==EOF)
-               debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno));
-       globstat.totuser=totuser;
-
        return;
 }