From d3699d4296d4884446a7426e4e19db5ce5005690 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Tue, 3 Feb 2004 08:38:23 +0000 Subject: [PATCH] Validation now works with attributes containing blanks SVN revision: 734 --- src/elogd.c | 139 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 53 deletions(-) diff --git a/src/elogd.c b/src/elogd.c index 1813202b..805813ae 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.225 2004/02/03 08:38:23 midas + Validation now works with attributes containing blanks + Revision 1.224 2004/02/02 21:13:06 midas Form validatin now also works for radio buttons @@ -761,6 +764,18 @@ Encode the given string in-place by adding %XX escapes /*-------------------------------------------------------------------*/ +void btou(char *str) +/* convert all blanks to underscores in a string */ +{ + int i; + + for (i = 0; i < (int) strlen(str); i++) + if (str[i] == ' ') + str[i] = '_'; +} + +/*-------------------------------------------------------------------*/ + char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int cind(char c) @@ -5833,14 +5848,13 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL { int i, j, n, index, size, width, height, fh, length, first, input_size, input_maxlen, format_flags; - char str[1000], preset[1000], *p, *pend, star[80], comment[10000], reply_string[256]; - char list[MAX_N_ATTR][NAME_LENGTH], file_name[256], *buffer, format[256]; - char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], - orig_tag[80], reply_tag[MAX_REPLY_TO * 10], - att[MAX_ATTACHMENTS][256], encoding[80], - slist[MAX_N_ATTR + 10][NAME_LENGTH], - svalue[MAX_N_ATTR + 10][NAME_LENGTH], owner[256], locked_by[256], class_value[80], - class_name[80], condition[256]; + char str[1000], preset[1000], *p, *pend, star[80], comment[10000], reply_string[256], + list[MAX_N_ATTR][NAME_LENGTH], file_name[256], *buffer, format[256], date[80], + attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], orig_tag[80], + reply_tag[MAX_REPLY_TO * 10], att[MAX_ATTACHMENTS][256], encoding[80], + slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], + owner[256], locked_by[256], class_value[80], class_name[80], condition[256], + ua[NAME_LENGTH]; time_t now; char fl[8][NAME_LENGTH]; struct tm *pts, ts; @@ -6037,10 +6051,14 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL for (i = 0; i < lbs->n_attr; i++) if (attr_flags[i] & AF_REQUIRED) { + /* convert blanks to underscores */ + strcpy(ua, attr_list[i]); + btou(ua); + if (attr_flags[i] & AF_MULTI) { rsprintf(" if (\n"); for (j = 0; j < MAX_N_LIST && attr_options[i][j][0]; j++) { - sprintf(str, "%s_%d", attr_list[i], j); + sprintf(str, "%s_%d", ua, j); rsprintf(" !document.form1.%s.checked", str); if (attr_options[i][j + 1][0]) rsprintf(" &&\n"); @@ -6048,24 +6066,25 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL rsprintf(") {\n"); sprintf(str, loc("Please select at least one '%s'"), attr_list[i]); rsprintf(" alert(\"%s\");\n", str); - rsprintf(" document.form1.%s_0.focus();\n", attr_list[i]); + rsprintf(" document.form1.%s_0.focus();\n", ua); rsprintf(" return false;\n"); rsprintf(" }\n"); + } else if (attr_flags[i] & AF_RADIO) { - rsprintf(" for (var i=0 ; iname, condition, str, format)) { @@ -6231,7 +6252,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (attr_flags[index] & AF_MULTI) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s_%d", attr_list[index], i); + sprintf(str, "%s_%d", ua, i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6239,7 +6260,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } else if (attr_flags[index] & AF_RADIO) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s_%d", attr_list[index], i); + sprintf(str, "%s_%d", ua, i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6247,7 +6268,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } else if (attr_flags[index] & AF_ICON) { for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s_%d", attr_list[index], i); + sprintf(str, "%s_%d", ua, i); if (strstr(attrib[index], attr_options[index][i])) rsprintf("\n", str, @@ -6255,30 +6276,30 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } else rsprintf("\n", - attr_list[index], attrib[index]); + ua, attrib[index]); } else { if (attr_options[index][0][0] == 0) { rsprintf ("\n", - input_size, input_maxlen, attr_list[index], attrib[index]); + input_size, input_maxlen, ua, attrib[index]); } else { if (equal_ustring(attr_options[index][0], "boolean")) { /* display checkbox */ if (atoi(attrib[index]) == 1) rsprintf ("\n", - attr_list[index]); + ua); else rsprintf ("\n", - attr_list[index]); + ua); } else { if (attr_flags[index] & AF_MULTI) { /* display multiple check boxes */ rsprintf("\n"); for (i = 0; i < MAX_N_LIST && attr_options[index][i][0]; i++) { - sprintf(str, "%s_%d", attr_list[index], i); + sprintf(str, "%s_%d", ua, i); if (strstr(attrib[index], attr_options[index][i])) rsprintf @@ -6302,13 +6323,11 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (strstr(attrib[index], attr_options[index][i])) rsprintf ("%s\n", - attr_list[index], attr_options[index][i], - attr_options[index][i]); + ua, attr_options[index][i], attr_options[index][i]); else rsprintf ("%s\n", - attr_list[index], attr_options[index][i], - attr_options[index][i]); + ua, attr_options[index][i], attr_options[index][i]); if (format_flags & AFF_MULTI_LINE) rsprintf("
"); @@ -6323,10 +6342,10 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (strstr(attrib[index], attr_options[index][i])) rsprintf ("", - attr_list[index], attr_options[index][i]); + ua, attr_options[index][i]); else rsprintf("", - attr_list[index], attr_options[index][i]); + ua, attr_options[index][i]); sprintf(str, "Icon comment %s", attr_options[index][i]); getcfg_cond(lbs->name, condition, str, comment); @@ -6356,13 +6375,13 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL rsprintf ("\n", - input_maxlen, attr_list[index], attrib[index]); + input_maxlen, ua, attrib[index]); } else { /* display drop-down box */ - rsprintf("