From b00d86e730c6f0b969d90589f672b3f30d0601f1 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Tue, 4 Oct 2005 17:56:13 +0000 Subject: [PATCH] Modifications made on flight CA931 SVN revision: 1494 --- doc/config.html | 34 ++++++++++++-- src/elogd.c | 119 ++++++++++++++++++++++++++++++------------------ 2 files changed, 103 insertions(+), 50 deletions(-) diff --git a/doc/config.html b/doc/config.html index 0e97f6ba..47defe8e 100755 --- a/doc/config.html +++ b/doc/config.html @@ -861,11 +861,12 @@ attribute which has an options list, the preset value is selected in the drop down box by default.

A special option are automatically generated tags, which are automatically incremented -for each new message. This is achieved by putting a "%" into the preset string, which -is used as a printf format specifier. A statement like +for each new message. This is achieved by putting #'s into the preset string, which +is used as a placeholder for the incrementing index. Each "#" stands for one digit, +thus the statement

-Preset Number = XYZ-%05d
+Preset Number = XYZ-#####
 
results in automatically created attributes "Number" of the form

@@ -873,9 +874,32 @@ XYZ-00001
 XYZ-00002
 XYZ-00003
 
-and so on. +and so on. In addition to the #'s one may specify format specifiers which are passed +to the +strftime function. This allows to create tags wich contain the current year, month +and so on. Once the date part of the attribute changes, the index restarts from one. +The statement

- +

+Preset Number = XYZ-%Y-%b-###
+
+results in automatically created attributes "Number" of the form

+

+XYZ-2005-Oct-001
+XYZ-2005-Oct-002
+XYZ-2005-Oct-003
+
+

+and +

+

+XYZ-2005-Nov-001
+XYZ-2005-Nov-002
+
+

+on the next month. +

+

  • Preset text = <string> or <file>
    This preset value is used for the main body text. It can be a string or a file, diff --git a/src/elogd.c b/src/elogd.c index e55247c1..b12bb939 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.756 2005/10/04 17:55:44 ritt + Modifications made on flight CA931 + Revision 1.755 2005/09/21 06:47:32 ritt Added '\' escape for smileys @@ -8732,29 +8735,56 @@ void show_change_pwd_page(LOGBOOK * lbs) /*------------------------------------------------------------------*/ -int get_last_index(LOGBOOK * lbs, int index) +void get_auto_index(LOGBOOK * lbs, int index, char *format, char *retstr, int size) /* return value of specific attribute of last entry, can be used to auto-increment tags */ { - int i, message_id; - char str[80], attrib[MAX_N_ATTR][NAME_LENGTH], att[MAX_ATTACHMENTS][256]; + int i, message_id, loc, len, old_index; + char str[NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH], att[MAX_ATTACHMENTS][256]; + time_t now; + if (strchr(format, '%') == NULL && strchr(format, '#') == NULL) { + strlcpy(retstr, format, size); + return; + } + + time(&now); + my_strftime(retstr, size, format, localtime(&now)); + + if (strchr(retstr, '#') == NULL) + return; + + /* record location and length of ###'s */ + for (i=loc=0,len=1 ; i<(int)strlen(retstr) ; i++) { + if (retstr[i] == '#') { + if (loc == 0) + loc = i; + if (i>0 && retstr[i-1] == '#') + len++; + } + } + + /* get attribute from last entry */ str[0] = 0; message_id = el_search_message(lbs, EL_LAST, 0, FALSE); - if (!message_id) - return 0; + if (!message_id) { + /* start with 1 */ + sprintf(retstr+loc, "%0*d", len, 1); + return; + } el_retrieve(lbs, message_id, NULL, attr_list, attrib, lbs->n_attr, NULL, 0, NULL, NULL, att, NULL, NULL); - strcpy(str, attrib[index]); + /* if date part changed, start over with inded */ + if (strncmp(attrib[index], retstr, loc) != 0) + old_index = 0; + else + /* retrieve old index */ + old_index = atoi(attrib[index]+loc); - /* look for first digit, return value */ - for (i = 0; i < (int) strlen(str); i++) - if (isdigit(str[i])) - break; - - return atoi(str + i); + /* increment index */ + sprintf(retstr+loc, "%0*d", len, old_index+1); } /*------------------------------------------------------------------*/ @@ -9197,10 +9227,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* check for index substitution */ if (!bedit && strchr(preset, '%')) { /* get index */ - i = get_last_index(lbs, index); - - strcpy(str, preset); - sprintf(preset, str, i + 1); + get_auto_index(lbs, index, preset, str, sizeof(str)); + strcpy(preset, str); } if (!strchr(preset, '%')) @@ -9221,10 +9249,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* check for index substitution */ if (!bedit && strchr(preset, '%')) { /* get index */ - i = get_last_index(lbs, index); - - strcpy(str, preset); - sprintf(preset, str, i + 1); + get_auto_index(lbs, index, preset, str, sizeof(str)); + strcpy(preset, str); } if (!strchr(preset, '%')) @@ -9267,10 +9293,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* check for index substitution */ if (!bedit && strchr(preset, '%')) { /* get index */ - i = get_last_index(lbs, index); - - strcpy(str, preset); - sprintf(preset, str, i + 1); + get_auto_index(lbs, index, preset, str, sizeof(str)); + strcpy(preset, str); } if (!strchr(preset, '%')) @@ -9291,10 +9315,8 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* check for index substitution */ if (!bedit && strchr(preset, '%')) { /* get index */ - i = get_last_index(lbs, index); - - strcpy(str, preset); - sprintf(preset, str, i + 1); + get_auto_index(lbs, index, preset, str, sizeof(str)); + strcpy(preset, str); } if (!strchr(preset, '%')) @@ -10562,14 +10584,16 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL && atoi(str) == 1)) { if (getcfg(lbs->name, "Suppress default", str, sizeof(str))) { if (atoi(str) == 0) { - rsprintf("%s\n", loc("Suppress Email notification")); + rsprintf(""); + rsprintf("\n", loc("Suppress Email notification")); } else if (atoi(str) == 1) { - rsprintf("%s\n", - loc("Suppress Email notification")); + rsprintf(""); + rsprintf("\n", loc("Suppress Email notification")); } } else { - rsprintf("%s\n", loc("Suppress Email notification")); + rsprintf(""); + rsprintf("\n", loc("Suppress Email notification")); } } @@ -10578,16 +10602,17 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (getcfg(lbs->name, "Suppress execute default", str, sizeof(str))) { if (atoi(str) == 0) { rsprintf("        \n"); - rsprintf("%s\n", - loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } else if (atoi(str) == 1) { rsprintf("        \n"); - rsprintf("%s\n", - loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } } else { rsprintf("        \n"); - rsprintf("%s\n", loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } } @@ -10595,16 +10620,17 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (getcfg(lbs->name, "Suppress execute default", str, sizeof(str))) { if (atoi(str) == 0) { rsprintf("        \n"); - rsprintf("%s\n", - loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } else if (atoi(str) == 1) { rsprintf("        \n"); - rsprintf("%s\n", - loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } } else { rsprintf("        \n"); - rsprintf("%s\n", loc("Suppress shell execution")); + rsprintf(""); + rsprintf("\n", loc("Suppress shell execution")); } } @@ -10613,14 +10639,17 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (getcfg(lbs->name, "Resubmit default", str, sizeof(str))) { if (atoi(str) == 0) { rsprintf("        \n"); - rsprintf("%s\n", loc("Resubmit as new entry")); + rsprintf(""); + rsprintf("