From a3050a6fadbdc2f5a0807e00e7ae6e2eda77e055 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Mon, 10 Jun 2002 10:38:22 +0000 Subject: [PATCH] Added 'top level only' flag SVN revision: 93 --- elogd.c | 870 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 579 insertions(+), 291 deletions(-) diff --git a/elogd.c b/elogd.c index af074cfa..8998c186 100755 --- a/elogd.c +++ b/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 2.6 2002/06/10 10:38:22 midas + Added 'top level only' flag + Revision 2.5 2002/06/07 14:56:53 midas Fixed time offset due to DST when using 'Date format' @@ -1064,6 +1067,9 @@ THEME default_theme [] = { { "BGImage", "" }, { "BGTImage", "" }, + { "Thread image", "" }, + { "Thread reply image", "" }, + { "" } }; @@ -3811,7 +3817,7 @@ time_t now; void show_elog_find(LOGBOOK *lbs) { int i, j, n_attr; -char str[256]; +char str[256], mode[256]; n_attr = scan_attributes(lbs->name); @@ -3841,18 +3847,37 @@ char str[256]; rsprintf("\n", gt("Categories border"), gt("Categories cellpadding"), gt("Frame color")); + rsprintf("\n"); + rsprintf("%s  \n", loc("Display full message")); + + if (equal_ustring(mode, "Summary")) + rsprintf("%s  \n", loc("Summary only")); + else + rsprintf("%s  \n", loc("Summary only")); + + if (equal_ustring(mode, "Threaded")) + rsprintf("%s  \n", loc("Display threads")); + else + rsprintf("%s  \n", loc("Display threads")); + } + + rsprintf("\n"); + + if (!getcfg(lbs->name, "Number attachments", str) || atoi(str) > 0) + { + rsprintf("\n", loc("Show attachments")); } - rsprintf("\n", loc("Show attachments")); rsprintf("\n", loc("Printable output")); @@ -4145,22 +4170,509 @@ char str[256]; /*------------------------------------------------------------------*/ +void display_line(LOGBOOK *lbs, int message_id, int number, char *mode, + int level, BOOL printable, int n_line, int show_attachments, + char *date, char *reply_to, + int n_attr_disp, char disp_attr[MAX_N_ATTR+4][NAME_LENGTH], + char attrib[MAX_N_ATTR][NAME_LENGTH], + int n_attr, char *text, + char attachment[MAX_ATTACHMENTS][256], char *encoding) +{ +char str[256], ref[256], *nowrap, col[80], format[256], file_name[256]; +char slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH]; +char display[256], attr_icon[80]; +int i, j, size, i_line, index, colspan; +BOOL link_displayed, skip_comma; +FILE *f; + + sprintf(ref, "../%s/%d", lbs->name_enc, message_id); + + if (equal_ustring(mode, "Summary")) + { + if (number % 2 == 0) + strcpy(col, gt("List bgcolor1")); + else + strcpy(col, gt("List bgcolor2")); + } + else if (equal_ustring(mode, "Full")) + strcpy(col, gt("List bgcolor1")); + else if (equal_ustring(mode, "Threaded")) + { + if (level == 0) + strcpy(col, gt("List bgcolor1")); + else + strcpy(col, gt("List bgcolor2")); + } + + rsprintf(""); + + /* only single cell for threaded display */ + if (equal_ustring(mode, "Threaded")) + { + rsprintf("", + col, size, ref, message_id); + + link_displayed = TRUE; + } + + if (equal_ustring(disp_attr[index], "Logbook")) + { + if (equal_ustring(mode, "Threaded")) + { + if (!link_displayed) + { + rsprintf("%s", + size, ref, lbs->name); + link_displayed = TRUE; + } + else + if (skip_comma) + { + rsprintf("%s", size, lbs->name); + skip_comma = FALSE; + } + else + rsprintf(", %s", size, lbs->name); + } + else + { + if (!link_displayed) + { + rsprintf("", + nowrap, col, size, ref, lbs->name); + link_displayed = TRUE; + } + else + rsprintf("", nowrap, col, size, lbs->name); + } + } + + if (equal_ustring(disp_attr[index], "Date")) + { + if (getcfg(lbs->name, "Date format", format)) + { + struct tm ts; + + memset(&ts, 0, sizeof(ts)); + + for (i=0 ; i<12 ; i++) + if (strncmp(date+4, mname[i], 3) == 0) + break; + ts.tm_mon = i; + + ts.tm_mday = atoi(date+8); + ts.tm_hour = atoi(date+11); + ts.tm_min = atoi(date+14); + ts.tm_sec = atoi(date+17); + ts.tm_year = atoi(date+20)-1900; + + strftime(str, sizeof(str), format, &ts); + } + else + strcpy(str, date); + + if (equal_ustring(mode, "Threaded")) + { + if (!link_displayed) + { + rsprintf("%s", + size, ref, str); + link_displayed = TRUE; + } + else + if (skip_comma) + { + rsprintf(" %s", size, str); + skip_comma = FALSE; + } + else + rsprintf(", %s", size, str); + } + else + { + if (!link_displayed) + { + rsprintf("", + nowrap, col, size, ref, str); + link_displayed = TRUE; + } + else + rsprintf("", nowrap, col, size, str); + } + } + + for (i=0 ; i", size); + if (!link_displayed) + { + rsprintf("", ref); + rsputs2(attr_list[i]); + rsprintf(""); + link_displayed = TRUE; + } + else + { + if (skip_comma) + { + rsprintf(" "); + skip_comma = FALSE; + } + else + rsprintf(", "); + + rsputs2(attrib[i]); + } + rsprintf(" "); + } + } + + else if (attr_flags[i] & AF_ICON) + { + if (attrib[i][0]) + rsprintf("  ", attrib[i]); + } + + else + { + rsprintf("", size); + if (!link_displayed) + { + rsprintf("", ref); + rsputs2(attrib[i]); + rsprintf(""); + link_displayed = TRUE; + } + else + { + if (skip_comma) + { + rsprintf(" "); + skip_comma = FALSE; + } + else + rsprintf(", "); + + rsputs2(attrib[i]); + } + rsprintf(""); + } + } + else + { + if (equal_ustring(attr_options[i][0], "boolean")) + { + if (atoi(attrib[i]) == 1) + rsprintf("\n", col); + else + rsprintf("\n", col); + } + + else if (attr_flags[i] & AF_ICON) + { + rsprintf(""); + } + + else + { + rsprintf(""); + } + } + } + } + } + + if (equal_ustring(mode, "Threaded")) + rsprintf("\n"); + + if (equal_ustring(mode, "Summary") && n_line > 0) + { + rsprintf("\n"); + } + + rsprintf("\n"); + + colspan = n_attr_disp; + + if (equal_ustring(mode, "Full")) + { + if (!getcfg(lbs->name, "Show text", str) || atoi(str) == 1) + { + rsprintf("\n"); + } + + if (!show_attachments && attachment[0][0]) + { + rsprintf("", colspan, ref); + } + else + { + rsprintf("\n"); + } + } + } + } + + if (!show_attachments && attachment[0][0]) + rsprintf("\n"); + } +} + +/*------------------------------------------------------------------*/ + +void display_reply(LOGBOOK *lbs, int message_id, int printable, int n_attr_disp, + char disp_attr[MAX_N_ATTR+4][NAME_LENGTH], int level) +{ +char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], + in_reply_to[80], reply_to[256], attachment[MAX_ATTACHMENTS][256], encoding[80]; +int status, n_attr, size; +char *p; + + n_attr = scan_attributes(lbs->name); + reply_to[0] = 0; + size = sizeof(text); + status = el_retrieve(lbs, message_id, date, attr_list, attrib, n_attr, + text, &size, in_reply_to, reply_to, + attachment, encoding); + + display_line(lbs, message_id, 0, "threaded", level, printable, 0, + FALSE, date, reply_to, n_attr_disp, disp_attr, + attrib, n_attr, NULL, NULL, encoding); + + if (reply_to[0]) + { + p = reply_to; + do + { + display_reply(lbs, atoi(p), printable, n_attr_disp, disp_attr, level+1); + + while (*p && isdigit(*p)) + p++; + while (*p && (*p == ',' || *p == ' ')) + p++; + } while(*p); + } +} + +/*------------------------------------------------------------------*/ + void show_elog_submit_find(LOGBOOK *lbs, INT past_n, INT last_n) { -int i, j, n, size, status, d1, m1, y1, d2, m2, y2, index, colspan, i_line, n_line, i_col; +int i, j, n, size, status, d1, m1, y1, d2, m2, y2, n_line; int current_year, current_month, current_day, printable, n_logbook, lindex, n_attr, reverse, n_attr_disp, n_found, search_all, message_id; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], disp_attr[MAX_N_ATTR+4][NAME_LENGTH], list[10000], text[TEXT_SIZE], text1[TEXT_SIZE], text2[TEXT_SIZE], in_reply_to[80], reply_to[256], attachment[MAX_ATTACHMENTS][256], encoding[80]; -char str[256], ref[256], file_name[256], col[80]; -char *nowrap, format[80]; +char str[256], col[80]; +char mode[80]; char menu_str[1000], menu_item[MAX_N_LIST][NAME_LENGTH]; char *p , *pt, *pt1, *pt2; -BOOL full, show_attachments, link_displayed; +BOOL show_attachments; time_t ltime, ltime_start, ltime_end, ltime_current, now; struct tm tms, *ptms; -FILE *f; n_attr = scan_attributes(lbs->name); @@ -4195,18 +4707,17 @@ FILE *f; show_standard_title(lbs->name, str, 0); /* get mode */ + strcpy(mode, "Full"); + if (past_n || last_n) { - if (getcfg(lbs->name, "Summary on default", str)) - full = !atoi(str); - else - full = TRUE; - + if (getcfg(lbs->name, "Display Mode", str)) + strcpy(mode, str); show_attachments = FALSE; } else { - full = !(*getparam("mode")); + strcpy(mode, getparam("mode")); show_attachments = (*getparam("attach") > 0); } @@ -4525,7 +5036,6 @@ FILE *f; printable ? "1" : gt("Border width"), gt("Categories cellpadding"), gt("Frame color")); strcpy(col, gt("Categories bgcolor1")); - rsprintf("\n"); size = printable ? 2 : 3; @@ -4552,43 +5062,42 @@ FILE *f; } } - for (i=0 ; i#", - col, size); - - if (equal_ustring(disp_attr[i], "Logbook")) - rsprintf("", - col, size); - - if (equal_ustring(disp_attr[i], "Date")) - rsprintf("", - col, size); } - - for (i=0 ; i\n"); + + for (i=0 ; i#", + col, size); - if (j == n_attr_disp) - continue; + if (equal_ustring(disp_attr[i], "Logbook")) + rsprintf("", + col, size); - rsprintf("", - col, size, attr_list[i]); + if (equal_ustring(disp_attr[i], "Date")) + rsprintf("", + col, size); + + for (j=0 ; j%s", + col, size, attr_list[j]); + } + + if (!equal_ustring(mode, "Full") && n_line > 0) + rsprintf("", + col, size); + + rsprintf("\n\n"); } - if (!full && n_line > 0) - rsprintf("", - col, size); - - rsprintf("\n\n"); - /*---- do find ----*/ - i_col = 0; n_found = 0; if (search_all) @@ -4784,7 +5293,7 @@ FILE *f; /* here: \001='<', \002='>', /003='"', and \004=' ' */ /* see also rsputs2(char* ) */ - if (equal_ustring(encoding, "plain") || !full) + if (equal_ustring(encoding, "plain") || !equal_ustring(mode, "Full")) strcpy(pt2, "\001B\004style=\003color:black;background-color:#ffff66\003\002"); else strcpy(pt2, ""); @@ -4797,7 +5306,7 @@ FILE *f; pt += strlen(str); /* add coloring 2nd part */ - if (equal_ustring(encoding, "plain") || !full) + if (equal_ustring(encoding, "plain") || !equal_ustring(mode, "Full")) strcpy(pt2, "\001/B\002"); else strcpy(pt2, ""); @@ -4809,255 +5318,34 @@ FILE *f; strcpy(text, text2); } + /* check if reply */ + if (equal_ustring(mode, "threaded") && in_reply_to[0]) + goto skip; + /*---- filter passed: display line ----*/ n_found++; - sprintf(ref, "../%s/%d", lbs->name_enc, message_id); + display_line(lbs, message_id, n_found, mode, 0, printable, n_line, + show_attachments, date, reply_to, n_attr_disp, disp_attr, + attrib, n_attr, text, attachment, encoding); - if (!full) + if (equal_ustring(mode, "threaded")) { - if (i_col % 2 == 0) - strcpy(col, gt("List bgcolor1")); - else - strcpy(col, gt("List bgcolor2")); - i_col++; - } - else - strcpy(col, gt("List bgcolor1")); - rsprintf(""); - - size = printable ? 2 : 3; - nowrap = printable ? "" : "nowrap"; - link_displayed = FALSE; - - for (j=0 ; j  %d  ", - col, size, ref, n_found); - link_displayed = TRUE; - } - - for (j=0 ; jname, "Top level only", str) || atoi(str) == 0)) { - rsprintf("", - nowrap, col, size, ref, lbs->name); - link_displayed = TRUE; - } - else - rsprintf("", nowrap, col, size, lbs->name); - } - - for (j=0 ; jname, "Date format", format)) - { - struct tm ts; - - memset(&ts, 0, sizeof(ts)); - - for (i=0 ; i<12 ; i++) - if (strncmp(date+4, mname[i], 3) == 0) - break; - ts.tm_mon = i; - - ts.tm_mday = atoi(date+8); - ts.tm_hour = atoi(date+11); - ts.tm_min = atoi(date+14); - ts.tm_sec = atoi(date+17); - ts.tm_year = atoi(date+20)-1900; - - strftime(str, sizeof(str), format, &ts); - } - else - strcpy(str, date); - - if (!link_displayed) - { - rsprintf("", - nowrap, col, size, ref, str); - link_displayed = TRUE; - } - else - rsprintf("", nowrap, col, size, str); - } - - for (i=0 ; i\n", col); - else - rsprintf("\n", col); - } - - else if (attr_flags[i] & AF_ICON) - { - rsprintf(""); - } - - else - { - rsprintf(""); + display_reply(lbs, atoi(p), printable, n_attr_disp, disp_attr, 1); + + while (*p && isdigit(*p)) + p++; + while (*p && (*p == ',' || *p == ' ')) + p++; + } while(*p); } } - - if (!full && n_line > 0) - { - rsprintf("\n"); - } - - rsprintf("\n"); - - colspan = n_attr_disp; - - if (full) - { - if (!getcfg(lbs->name, "Show text", str) || atoi(str) == 1) - { - rsprintf("\n"); - } - - if (!show_attachments && attachment[0][0]) - { - rsprintf("", colspan, ref); - } - else - { - rsprintf("\n"); - } - } - } - } - - if (!show_attachments && attachment[0][0]) - rsprintf("\n"); - } } /* stop after all found (needed for reverse search) */ @@ -5729,7 +6017,7 @@ BOOL first; if (equal_ustring(command, loc("Search"))) { - if (dec_path[0] && atoi(dec_path) == 0) + if (dec_path[0] && atoi(dec_path) == 0 && strchr(dec_path, '/') != NULL) { sprintf(str, "Invalid URL: %s", dec_path); show_error(str);
", gt("Categories bgcolor2")); + rsprintf("Mode:  "); + + if (!getcfg(lbs->name, "Display mode", mode)) + strcpy(mode, "Full"); + if (!getcfg(lbs->name, "Show text", str) || atoi(str) == 1) { - rsprintf("
", gt("Categories bgcolor2")); - - if (getcfg(lbs->name, "Summary on default", str) && atoi(str) == 1) - rsprintf("%s\n", loc("Summary only")); + if (equal_ustring(mode, "Full")) + rsprintf("%s  \n", loc("Display full message")); else - rsprintf("%s\n", loc("Summary only")); - rsprintf("
", gt("Categories bgcolor2")); + rsprintf("%s
", gt("Categories bgcolor2")); - rsprintf("%s
", gt("Categories bgcolor2")); rsprintf("%s
", col); + for (i=0 ; iname, "Thread display", display)) + { + /* check if to use icon from attributes */ + attr_icon[0] = 0; + if (getcfg(lbs->name, "Thread icon", attr_icon)) + { + for (i=0 ; i ", ref, attr_icon); + else + { + /* if top level only, display reply icon if message has a reply */ + if (getcfg(lbs->name, "Top level only", str) && atoi(str) == 1 && reply_to[0]) + { + if (*gt("Thread reply image")) + rsprintf(" ", ref, gt("Thread reply image")); + else + rsprintf(" %d > ", + size, ref, message_id); + } + else + { + /* display standard icons */ + if (level == 0) + { + if (*gt("Thread image")) + rsprintf(" ", ref, gt("Thread image")); + else + rsprintf(" %d ", + size, ref, message_id); + } + else + { + if (*gt("Thread reply image")) + rsprintf(" ", ref, gt("Thread reply image")); + else + rsprintf(" %d ", + size, ref, message_id); + } + } + } + + j = build_subst_list(lbs, slist, svalue, attrib); + strsubst(display, slist, svalue, j); + rsputs2(display); + } + else + { + for (index=0 ; index ", ref, gt("Thread image")); + else + rsprintf(" %d ", + size, ref, message_id); + } + else + { + if (*gt("Thread reply image")) + rsprintf(" ", ref, gt("Thread reply image")); + else + rsprintf(" %d ", + size, ref, message_id); + } + + skip_comma = TRUE; + } + else + rsprintf("  %d  %s%s%s%s", col); + if (attrib[i][0]) + rsprintf("", attrib[i]); + rsprintf(" ", col, size); + if (!link_displayed) + { + rsprintf("", ref); + rsputs2(attrib[i]); + rsprintf(""); + link_displayed = TRUE; + } + else + rsputs2(attrib[i]); + rsprintf(" ", col, size); + for (i=i_line=0 ; i
", colspan, size); + + if (equal_ustring(encoding, "plain")) + { + rsputs("
");
+        rsputs2(text);
+        rsputs("
"); + } + else + rsputs(text); + + rsprintf("
", colspan, size); + + if (attachment[1][0]) + rsprintf("%s: ", loc("Attachments")); + else + rsprintf("%s: ", loc("Attachment")); + } + + for (index = 0 ; index < MAX_ATTACHMENTS ; index++) + { + if (attachment[index][0]) + { + strcpy(str, attachment[index]); + str[13] = 0; + sprintf(ref, "../%s/%s/%s", lbs->name_enc, str, attachment[index]+14); + + for (i=0 ; i<(int)strlen(attachment[index]) ; i++) + str[i] = toupper(attachment[index][i]); + str[i] = 0; + + if (!show_attachments) + { + rsprintf("%s     ", + ref, attachment[index]+14); + } + else + { + if (strstr(str, ".GIF") || + strstr(str, ".JPG") || + strstr(str, ".JPEG") || + strstr(str, ".PNG")) + { + rsprintf("
%s %d: %s\n", + colspan, gt("List bgcolor2"), loc("Attachment"), index+1, ref, attachment[index]+14); + if (show_attachments) + rsprintf("
%s %d: %s\n", + colspan, gt("List bgcolor2"), loc("Attachment"), index+1, ref, attachment[index]+14); + + if ((strstr(str, ".TXT") || + strstr(str, ".ASC") || + strchr(str, '.') == NULL) && show_attachments) + { + /* display attachment */ + rsprintf("
", size);
+
+              strcpy(file_name, lbs->data_dir);
+
+              strcat(file_name, attachment[index]);
+
+              f = fopen(file_name, "rt");
+              if (f != NULL)
+                {
+                while (!feof(f))
+                  {
+                  str[0] = 0;
+                  fgets(str, sizeof(str), f);
+                  rsputs2(str);
+                  }
+                fclose(f);
+                }
+
+              rsprintf("
\n"); + } + rsprintf("
LogbookDateLogbook%sDateText
Text
%s%s%s%s", col); - if (attrib[i][0]) - rsprintf("", attrib[i]); - rsprintf(" ", col, size); - if (!link_displayed) + p = reply_to; + do { - rsprintf("", ref); - rsputs2(attrib[i]); - rsprintf(""); - link_displayed = TRUE; - } - else - rsputs2(attrib[i]); - rsprintf(" ", col, size); - for (i=i_line=0 ; i
", colspan, size); - - if (equal_ustring(encoding, "plain")) - { - rsputs("
");
-              rsputs2(text);
-              rsputs("
"); - } - else - rsputs(text); - - rsprintf("
", colspan, size); - - if (attachment[1][0]) - rsprintf("%s: ", loc("Attachments")); - else - rsprintf("%s: ", loc("Attachment")); - } - - for (index = 0 ; index < MAX_ATTACHMENTS ; index++) - { - if (attachment[index][0]) - { - strcpy(str, attachment[index]); - str[13] = 0; - sprintf(ref, "../%s/%s/%s", lbs->name_enc, str, attachment[index]+14); - - for (i=0 ; i<(int)strlen(attachment[index]) ; i++) - str[i] = toupper(attachment[index][i]); - str[i] = 0; - - if (!show_attachments) - { - rsprintf("%s     ", - ref, attachment[index]+14); - } - else - { - if (strstr(str, ".GIF") || - strstr(str, ".JPG") || - strstr(str, ".JPEG") || - strstr(str, ".PNG")) - { - rsprintf("
%s %d: %s\n", - colspan, gt("List bgcolor2"), loc("Attachment"), index+1, ref, attachment[index]+14); - if (show_attachments) - rsprintf("
%s %d: %s\n", - colspan, gt("List bgcolor2"), loc("Attachment"), index+1, ref, attachment[index]+14); - - if ((strstr(str, ".TXT") || - strstr(str, ".ASC") || - strchr(str, '.') == NULL) && show_attachments) - { - /* display attachment */ - rsprintf("
", size);
-
-                    strcpy(file_name, lbs->data_dir);
-
-                    strcat(file_name, attachment[index]);
-
-                    f = fopen(file_name, "rt");
-                    if (f != NULL)
-                      {
-                      while (!feof(f))
-                        {
-                        str[0] = 0;
-                        fgets(str, sizeof(str), f);
-                        rsputs2(str);
-                        }
-                      fclose(f);
-                      }
-
-                    rsprintf("
\n"); - } - rsprintf("