From 1e30bf3e7d323cf4f600cb1a5003c5a57fa18504 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Thu, 12 Dec 2002 12:42:37 +0000 Subject: [PATCH] Added 'quick filter' option SVN revision: 305 --- elogd.c | 307 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 211 insertions(+), 96 deletions(-) diff --git a/elogd.c b/elogd.c index 9744636f..361b7154 100755 --- a/elogd.c +++ b/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 2.113 2002/12/12 12:42:37 midas + Added 'quick filter' option + Revision 2.112 2002/12/10 08:20:09 midas Hide wrong password from URL @@ -6733,10 +6736,66 @@ int msg_compare_reverse(const void *m1, const void *m2) /*------------------------------------------------------------------*/ +void subst_param(char *str, int size, char *param, char *value) +{ +int len; +char *p1, *p2, *s; + + if (!value[0]) + { + if (strstr(str, param) == NULL) + return; + + /* remove parameter */ + p1 = strstr(str, param)-1; + + for (p2 = p1+strlen(param)+1 ; *p2 && *p2 != '&' ; p2++); + strlcpy(p1, p2, size - ((int)p1 - (int)str)); + + if (!strchr(str, '?') && strchr(str, '&')) + *strchr(str, '&') = '?'; + + return; + } + + if (strstr(str, param) == NULL) + { + if (strchr(str, '?')) + strlcat(str, "&", size); + else + strlcat(str, "?", size); + + strlcat(str, param, size); + strlcat(str, "=", size); + strlcat(str, value, size); + return; + } + + p1 = strstr(str, param) + strlen(param) + 1; + for (p2 = p1 ; *p2 && *p2 != '&' ; p2++); + len = (int)p2 - (int)p1; + if (len > (int)strlen(value)) + { + /* new value is shorter than old one */ + strlcpy(p1, value, size - ((int)p1 - (int)str)); + strlcpy(p1 + strlen(value), p2, size - ((int)p1 + strlen(value) - (int)str)); + } + else + { + /* new value is longer than old one */ + s = malloc(size); + strlcpy(s, p2, size); + strlcpy(p1, value, size - ((int)p1 - (int)str)); + strlcat(p1, s, size - ((int)p1 + strlen(value) - (int)str)); + free(s); + } + +} + +/*------------------------------------------------------------------*/ + void build_ref(char *ref, int size, char *mode, char *expand) { -char *p1, *p2; - if (strchr(getparam("cmdline"), '?')) strlcat(ref, strchr(getparam("cmdline"), '?'), size); @@ -6746,58 +6805,34 @@ char *p1, *p2; /* eliminate old mode if new one is present */ if (mode[0]) - { - if ((p1 = strstr(ref, "mode=")) != NULL) - { - for (p2 = p1+5 ; *p2 && *p2 != '&' ; p2++); - strcpy(p1-1, p2); - } - sprintf(ref+strlen(ref), "&mode=%s", mode); - } + subst_param(ref, size, "mode", mode); /* eliminate old expand if new one is present */ if (expand[0]) - { - if ((p1 = strstr(ref, "expand=")) != NULL) - { - for (p2 = p1+8 ; *p2 && *p2 != '&' ; p2++); - strcpy(p1-1, p2); - } - sprintf(ref+strlen(ref), "&expand=%s", expand); - } + subst_param(ref, size, "expand", expand); - if (isparam("last")) - { - /* eliminate old last= */ - if ((p1 = strstr(ref, "last=")) != NULL) - { - for (p2 = p1+5 ; *p2 && isdigit(*p2) ; p2++); - strcpy(p1-1, p2); - } - sprintf(ref+strlen(ref), "&last=%s", getparam("last")); - } - - /* replace first '&' by '?' if not present */ - if (!strchr(ref, '?') && strchr(ref, '&')) - *strchr(ref, '&') = '?'; + /* eliminate old last= */ + subst_param(ref, size, "last", getparam("last")); } -void show_page_navigation(LOGBOOK *lbs, int n_msg, int page_n, int n_page, BOOL top, BOOL mode_commands, - BOOL threaded) -{ -int i, cur_exp; -char ref[256], str[256]; +/*------------------------------------------------------------------*/ - if (!(page_n && n_msg > n_page) && !top) - return; +void show_page_filters(LOGBOOK *lbs, int n_msg, int page_n, int n_page, BOOL top, BOOL mode_commands, + BOOL threaded) +{ +int cur_exp, n, i, j, index; +char ref[256], str[256]; +char list[MAX_N_LIST][NAME_LENGTH]; rsprintf("\n"); rsprintf("
\n", gt("Border width"), gt("Categories cellpadding")); + rsprintf("\n"); + if (mode_commands) { - rsprintf("\n"); + rsprintf("\n"); } + if (getcfg(lbs->name, "Quick filter", str)) + { + rsprintf("\n"); + } + + rsprintf("
\n", gt("Menu1 BGColor")); + rsprintf("\n", gt("Menu1 BGColor")); rsprintf(""); if (page_n != 1) @@ -6836,7 +6871,7 @@ char ref[256], str[256]; if (cur_exp > 0) { - sprintf(str, "%d", max(0, cur_exp-1)); + sprintf(str, "%d", cur_exp > 0 ? cur_exp-1 : 0); build_ref(ref, sizeof(ref), "", str); rsprintf("| %s ", ref, loc("Collapse")); } @@ -6849,7 +6884,7 @@ char ref[256], str[256]; sprintf(ref, "page%d", page_n); else ref[0] = 0; - sprintf(str, "%d", min(3, cur_exp+1)); + sprintf(str, "%d", cur_exp < 3 ? cur_exp+1 : 3); build_ref(ref, sizeof(ref), "", str); rsprintf("| %s ", ref, loc("Expand")); } @@ -6858,9 +6893,101 @@ char ref[256], str[256]; } rsprintf(""); - rsprintf("
\n", gt("Menu1 BGColor")); + n = strbreak(str, list, MAX_N_LIST); + + for (index=0 ; index < n ; index++) + { + if (equal_ustring(list[index], "date")) + { + i = atoi(getparam("last")); + + rsprintf(" \n", loc("Show last")); + + rsprintf(" \n"); + } + else + { + rsprintf(" \n", list[index]); + + rsprintf(" \n"); + } + } + + rsprintf("
\n\n"); +} + +/*------------------------------------------------------------------*/ + +void show_page_navigation(LOGBOOK *lbs, int n_msg, int page_n, int n_page, BOOL top, BOOL mode_commands, + BOOL threaded) +{ +int i; +char ref[256]; + + if (!page_n || n_msg <= n_page) + return; + + rsprintf("\n"); + rsprintf("
\n", + gt("Border width"), gt("Categories cellpadding")); + rsprintf("\n"); if (n_msg > n_page) @@ -6921,46 +7048,6 @@ char ref[256], str[256]; if (n_msg > n_page) rsprintf("\n"); - rsprintf("
\n", gt("Menu1 BGColor")); - - if (top) - { - i = atoi(getparam("last")); - - rsprintf(" \n", loc("Show last")); - - rsprintf("\n"); - } - rsprintf("
\n\n"); } @@ -6989,7 +7076,7 @@ char lbk_list[MAX_N_LIST][NAME_LENGTH]; rsprintf("//--> \n"); rsprintf(" \n"); - rsprintf("Selected entries: \n"); + rsprintf("%s: \n", loc("Selected entries")); rsprintf("\n", loc("Toggle all")); @@ -7119,27 +7206,52 @@ LOGBOOK *lbs_cur; return; } - /* redirect go command */ + /* redirect "go" command */ if (isparam("lastcmd")) //## and not copy to / move to / delete ... { strlcpy(str, getparam("lastcmd"), sizeof(str)); url_decode(str); - /* strip previous "last" */ - if (strstr(str, "last=")) - *(strstr(str, "last=")-1) = 0; - - /* add new "last" */ - if (strchr(str, '?')) - sprintf(str+strlen(str), "&last="); - else - sprintf(str+strlen(str), "?last="); + /* subsitute "last" in command line from new parameter */ + if (isparam("last")) + { + if (equal_ustring(getparam("last"), "_all_")) + subst_param(str, sizeof(str), "last", ""); + else + subst_param(str, sizeof(str), "last", getparam("last")); + } + + /* subsitute attributes in command line from new parameter */ + for (i=0 ; i