diff --git a/src/elogd.c b/src/elogd.c index 67dae91f..ce5185bf 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.168 2003/12/31 19:47:06 midas + Implemented conditional attributes + Revision 1.167 2003/12/15 09:36:23 midas Added 'date on reply = 2' option @@ -1625,6 +1628,26 @@ int fh; /*------------------------------------------------------------------*/ +int getcfg_cond(char *group, char *condition, char *param, char *value) +{ +char str[256]; + + if (condition == NULL || condition[0] == 0) + return getcfg(group, param, value); + + sprintf(str, "{%s}%s", condition, param); + if (getcfg(group, str, value)) + return 1; + + sprintf(str, "{%s} %s", condition, param); + if (getcfg(group, str, value)) + return 1; + + return getcfg(group, param, value); +} + +/*------------------------------------------------------------------*/ + int enumcfg(char *group, char *param, char *value, int index) { char str[10000], *p, *pstr; @@ -4187,14 +4210,14 @@ char *p; /*------------------------------------------------------------------*/ -int scan_attributes(char *logbook) +int scan_attributes(char *logbook, char *condition) /* scan configuration file for attributes and fill attr_list, attr_options and attr_flags arrays */ { char list[10000], str[NAME_LENGTH], tmp_list[MAX_N_ATTR][NAME_LENGTH]; int i, j, n, m; - if (getcfg(logbook, "Attributes", list)) + if (getcfg_cond(logbook, condition, "Attributes", list)) { /* reset attribute flags */ memset(attr_flags, 0, sizeof(attr_flags)); @@ -4208,25 +4231,25 @@ int i, j, n, m; for (i=0 ; in_attr ; i++) + { + if (strchr(attrib[i], '{') && strchr(attrib[i], '}')) + { + strlcpy(str, strchr(attrib[i], '{')+1, sizeof(str)); + if (*strchr(str, '}')) + *strchr(str, '}') = 0; + + if (condition[0] == 0) + strlcpy(condition, str, sizeof(condition)); + else + { + strlcat(condition, ",", sizeof(condition)); + strlcat(condition, str, sizeof(condition)); + } + } + } + /* check for maximum number of replies */ if (breply) { @@ -5329,7 +5387,7 @@ struct tm *ts; } /* check for author */ - if (bedit && getcfg(lbs->name, "Restrict edit", str) && atoi(str) == 1) + if (bedit && getcfg_cond(lbs->name, condition, "Restrict edit", str) && atoi(str) == 1) { if (!is_author(lbs, attrib, owner)) { @@ -5340,7 +5398,7 @@ struct tm *ts; } /* check for editing interval */ - if (bedit && getcfg(lbs->name, "Restrict edit time", str)) + if (bedit && getcfg_cond(lbs->name, condition, "Restrict edit time", str)) { for (i = 0 ; i < *lbs->n_el_index ; i++) if (lbs->el_index[i].message_id == message_id) @@ -5357,7 +5415,7 @@ struct tm *ts; /* remove attributes for replies */ if (breply) { - getcfg(lbs->name, "Remove on reply", str); + getcfg_cond(lbs->name, condition, "Remove on reply", str); n = strbreak(str, list, MAX_N_ATTR); for (i=0 ; in_attr ; j++) @@ -5373,7 +5431,7 @@ struct tm *ts; for (index = 0 ; index < lbs->n_attr ; index++) { sprintf(str, "Subst on reply %s", attr_list[index]); - if (getcfg(lbs->name, str, preset)) + if (getcfg_cond(lbs->name, condition, str, preset)) { /* check if already second reply */ if (orig_tag[0] == 0) @@ -5387,12 +5445,12 @@ struct tm *ts; } /* subst attributes for edits */ - if (message_id && bedit && !bupload) + if (message_id && bedit && !breedit) { for (index = 0 ; index < lbs->n_attr ; index++) { sprintf(str, "Subst on edit %s", attr_list[index]); - if (getcfg(lbs->name, str, preset)) + if (getcfg_cond(lbs->name, condition, str, preset)) { i = build_subst_list(lbs, slist, svalue, attrib); strsubst(preset, slist, svalue, i); @@ -5407,7 +5465,7 @@ struct tm *ts; /* header */ show_html_header(lbs, FALSE, "ELOG"); - rsprintf("
\n"); + rsprintf("\n"); /*---- add password in case cookie expires during edit ----*/ @@ -5428,6 +5486,9 @@ struct tm *ts; rsprintf("\n"); + /* default cmd */ + rsprintf("\n", loc("Update")); + rsprintf("\n", loc("Submit")); rsprintf("\n", loc("Back")); rsprintf("\n\n"); @@ -5451,7 +5512,7 @@ struct tm *ts; time(&now); if (bedit) { - if (getcfg(lbs->name, "Date format", format)) + if (getcfg_cond(lbs->name, condition, "Date format", format)) { struct tm ts; @@ -5477,7 +5538,7 @@ struct tm *ts; } else { - if (getcfg(lbs->name, "Date format", format)) + if (getcfg_cond(lbs->name, condition, "Date format", format)) strftime(str, sizeof(str), format, localtime(&now)); else strcpy(str, ctime(&now)); @@ -5489,6 +5550,10 @@ struct tm *ts; rsprintf("%s\n", str); rsprintf("\n", date); + /* rescan attributes if condition set */ + if (condition[0]) + scan_attributes(lbs->name, condition); + /* display attributes */ for (index = 0 ; index < lbs->n_attr ; index++) { @@ -5498,7 +5563,7 @@ struct tm *ts; input_maxlen = NAME_LENGTH; sprintf(str, "Format %s", attr_list[index]); - if (getcfg(lbs->name, str, format)) + if (getcfg_cond(lbs->name, condition, str, format)) { n = strbreak(format, fl, 8); if (n > 0) @@ -5517,7 +5582,7 @@ struct tm *ts; /* check for preset string */ sprintf(str, "Preset %s", attr_list[index]); - if (getcfg(lbs->name, str, preset)) + if (getcfg_cond(lbs->name, condition, str, preset)) { if (!bedit) { @@ -5544,7 +5609,7 @@ struct tm *ts; /* show optional comment */ sprintf(str, "Comment %s", attr_list[index]); - if (getcfg(lbs->name, str, comment)) + if (getcfg_cond(lbs->name, condition, str, comment)) rsprintf("
%s\n", comment); rsprintf("\n"); @@ -5668,7 +5733,7 @@ struct tm *ts; rsprintf("", attr_list[index], attr_options[index][i]); sprintf(str, "Icon comment %s", attr_options[index][i]); - getcfg(lbs->name, str, comment); + getcfg_cond(lbs->name, condition, str, comment); if (comment[0]) rsprintf("\"%s\"\n", attr_options[index][i], comment); @@ -5684,20 +5749,44 @@ struct tm *ts; else { /* display drop-down box */ - rsprintf("\n"); + else + rsprintf(">\n"); /* display emtpy option */ rsprintf("