Implemented numeric attributes

SVN revision: 771
This commit is contained in:
Stefan Ritt 2004-02-16 20:27:28 +00:00
parent 3402b37960
commit 3cafddd600

View File

@ -6,6 +6,9 @@
Contents: Web server program for Electronic Logbook ELOG Contents: Web server program for Electronic Logbook ELOG
$Log$ $Log$
Revision 1.251 2004/02/16 20:27:28 midas
Implemented numeric attributes
Revision 1.250 2004/02/16 16:28:46 midas Revision 1.250 2004/02/16 16:28:46 midas
Changed indentation Changed indentation
@ -529,6 +532,7 @@ char author_list[MAX_N_LIST][NAME_LENGTH] = {
#define AF_RADIO (1<<6) #define AF_RADIO (1<<6)
#define AF_EXTENDABLE (1<<7) #define AF_EXTENDABLE (1<<7)
#define AF_DATE (1<<8) #define AF_DATE (1<<8)
#define AF_NUMERIC (1<<9)
/* attribute format flags */ /* attribute format flags */
#define AFF_SAME_LINE 1 #define AFF_SAME_LINE 1
@ -569,38 +573,22 @@ struct {
} filetype[] = { } filetype[] = {
{ {
".CSS", "text/css"}, ".CSS", "text/css"}, {
{ ".JPG", "image/jpeg"}, {
".JPG", "image/jpeg"}, ".JPEG", "image/jpeg"}, {
{ ".GIF", "image/gif"}, {
".JPEG", "image/jpeg"}, ".PNG", "image/png"}, {
{ ".PS", "application/postscript"}, {
".GIF", "image/gif"}, ".EPS", "application/postscript"}, {
{ ".HTML", "text/html"}, {
".PNG", "image/png"}, ".HTM", "text/html"}, {
{ ".XLS", "application/x-msexcel"}, {
".PS", "application/postscript"}, ".DOC", "application/msword"}, {
{ ".PDF", "application/pdf"}, {
".EPS", "application/postscript"}, ".JS", "application/x-javascript"}, {
{ ".TXT", "text/plain"}, {
".HTML", "text/html"}, ".ASC", "text/plain"}, {
{ ".ZIP", "application/x-zip-compressed"}, {
".HTM", "text/html"},
{
".XLS", "application/x-msexcel"},
{
".DOC", "application/msword"},
{
".PDF", "application/pdf"},
{
".JS", "application/x-javascript"},
{
".TXT", "text/plain"},
{
".ASC", "text/plain"},
{
".ZIP", "application/x-zip-compressed"},
{
"", ""},}; "", ""},};
typedef struct { typedef struct {
@ -4871,6 +4859,8 @@ and attr_flags arrays */
if (getcfg_cond(logbook, condition, str, type)) { if (getcfg_cond(logbook, condition, str, type)) {
if (strieq(type, "date")) if (strieq(type, "date"))
attr_flags[i] |= AF_DATE; attr_flags[i] |= AF_DATE;
if (strieq(type, "numeric"))
attr_flags[i] |= AF_NUMERIC;
} }
} }
@ -6248,7 +6238,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL
rsprintf("function chkform()\n"); rsprintf("function chkform()\n");
rsprintf("{\n"); rsprintf("{\n");
for (i = 0; i < lbs->n_attr; i++) for (i = 0; i < lbs->n_attr; i++) {
if (attr_flags[i] & AF_REQUIRED) { if (attr_flags[i] & AF_REQUIRED) {
/* convert blanks to underscores */ /* convert blanks to underscores */
@ -6310,6 +6300,23 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL
} }
} }
if (attr_flags[i] & AF_NUMERIC) {
/* convert blanks to underscores */
strcpy(ua, attr_list[i]);
btou(ua);
rsprintf(" for (var i=0 ; i<document.form1.%s.value.length ; i++)\n", ua);
rsprintf(" if (document.form1.%s.value.charAt(i) < \"0\" ||\n", ua);
rsprintf(" document.form1.%s.value.charAt(i) > \"9\") { break }\n", ua);
rsprintf(" if (i<document.form1.%s.value.length) {\n", ua);
sprintf(str, loc("Please enter numeric value for '%s'"), attr_list[i]);
rsprintf(" alert(\"%s\");\n", str);
rsprintf(" document.form1.%s.focus();\n", ua);
rsprintf(" return false;\n");
rsprintf(" }\n");
}
}
rsprintf(" return true;\n"); rsprintf(" return true;\n");
rsprintf("}\n"); rsprintf("}\n");
rsprintf("//-->\n"); rsprintf("//-->\n");
@ -12693,6 +12700,25 @@ void submit_elog(LOGBOOK * lbs)
return; return;
} }
/* check for numeric attributes */
for (index = 0; index < lbs->n_attr; index++)
if (attr_flags[index] & AF_REQUIRED) {
strcpy(ua, attr_list[index]);
btou(ua);
strlcpy(str, getparam(ua), sizeof(str));
for (j = 0; i < (int) strlen(str); i++)
if (!isdigit(str[i]))
break;
if (i < (int) strlen(str)) {
sprintf(error, loc("Error: Attribute <b>%s</b> must be numeric"),
attr_list[index]);
show_error(error);
return;
}
}
/* check for extended attributs */ /* check for extended attributs */
for (i = 0; i < lbs->n_attr; i++) { for (i = 0; i < lbs->n_attr; i++) {
strcpy(ua, attr_list[i]); strcpy(ua, attr_list[i]);
@ -16688,8 +16714,7 @@ i_conn = content_length = 0;
return_length = strlen_retbuf; return_length = strlen_retbuf;
if ((keep_alive && strstr(return_buffer, "Content-Length") == NULL) if ((keep_alive && strstr(return_buffer, "Content-Length") == NULL)
|| strstr(return_buffer, "Content-Length") > || strstr(return_buffer, "Content-Length") >
strstr(return_buffer, strstr(return_buffer, "\r\n\r\n")) {
"\r\n\r\n")) {
/*---- add content-length ----*/ /*---- add content-length ----*/
p = strstr(return_buffer, "\r\n\r\n"); p = strstr(return_buffer, "\r\n\r\n");