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 {
@ -3484,9 +3472,9 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit,
char *message, *p, *buffer; char *message, *p, *buffer;
char attachment_all[64 * MAX_ATTACHMENTS]; char attachment_all[64 * MAX_ATTACHMENTS];
tail_size = orig_size = 0; tail_size = orig_size = 0;
buffer = NULL; buffer = NULL;
message = malloc(TEXT_SIZE + 100); message = malloc(TEXT_SIZE + 100);
assert(message); assert(message);
@ -3903,7 +3891,7 @@ INT el_delete_message(LOGBOOK * lbs, int message_id,
lseek(fh, 0, SEEK_END); lseek(fh, 0, SEEK_END);
tail_size = TELL(fh) - (lbs->el_index[index].offset + size); tail_size = TELL(fh) - (lbs->el_index[index].offset + size);
buffer = NULL; buffer = NULL;
if (tail_size > 0) { if (tail_size > 0) {
buffer = malloc(tail_size); buffer = malloc(tail_size);
if (buffer == NULL) { if (buffer == NULL) {
@ -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");
@ -7524,7 +7531,7 @@ int save_admin_config(char *section, char *buffer, char *error)
/* save tail */ /* save tail */
buf2 = NULL; buf2 = NULL;
if (p2) { if (p2) {
buf2 = malloc(strlen(p2) + 1); buf2 = malloc(strlen(p2) + 1);
assert(buf2); assert(buf2);
strlcpy(buf2, p2, strlen(p2) + 1); strlcpy(buf2, p2, strlen(p2) + 1);
@ -9731,7 +9738,7 @@ void synchronize_logbook(LOGBOOK * lbs, BOOL bcron)
if (_logging_level > 1) if (_logging_level > 1)
logf(lbs, "MIRROR send entry #%d", message_id); logf(lbs, "MIRROR send entry #%d", message_id);
remote_id = 0; remote_id = 0;
if (!getcfg(lbs->name, "Mirror simulate", str) || atoi(str) == 0) if (!getcfg(lbs->name, "Mirror simulate", str) || atoi(str) == 0)
remote_id = submit_message(lbs, list[index], message_id, error_str); remote_id = submit_message(lbs, list[index], message_id, error_str);
all_identical = FALSE; all_identical = FALSE;
@ -11368,9 +11375,9 @@ void show_elog_list(LOGBOOK * lbs, INT past_n, INT last_n, INT page_n)
ltime_end = ltime_start = 0; ltime_end = ltime_start = 0;
d1 = m1 = y1 = d2 = m2 = y2 = 0; d1 = m1 = y1 = d2 = m2 = y2 = 0;
if (!past_n && !last_n) { if (!past_n && !last_n) {
ltime_start = retrieve_date("a", TRUE); ltime_start = retrieve_date("a", TRUE);
if (ltime_start < 0) if (ltime_start < 0)
@ -11745,7 +11752,7 @@ if (!past_n && !last_n) {
/*---- number of messages per page ----*/ /*---- number of messages per page ----*/
n_attr_disp = n_line = 0; n_attr_disp = n_line = 0;
n_page = 1000000; n_page = 1000000;
i_start = 0; i_start = 0;
i_stop = n_msg - 1; i_stop = n_msg - 1;
@ -12581,7 +12588,7 @@ int add_attribute_option(LOGBOOK * lbs, char *attrname, char *attrvalue)
p2--; p2--;
/* save tail */ /* save tail */
buf2 = NULL; buf2 = NULL;
if (p2) { if (p2) {
buf2 = malloc(strlen(p2) + 1); buf2 = malloc(strlen(p2) + 1);
assert(buf2); assert(buf2);
@ -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]);
@ -13475,7 +13501,7 @@ void show_elog_message(LOGBOOK * lbs, char *dec_path, char *command)
if (message_id == 0) if (message_id == 0)
message_id = el_search_message(lbs, EL_LAST, 0, FALSE); message_id = el_search_message(lbs, EL_LAST, 0, FALSE);
status = 0; status = 0;
if (message_id) { if (message_id) {
size = sizeof(text); size = sizeof(text);
status = status =
@ -15945,7 +15971,7 @@ void server_loop(int tcp_port, int daemon)
char *net_buffer = NULL; char *net_buffer = NULL;
int net_buffer_size; int net_buffer_size;
i_conn = content_length = 0; i_conn = content_length = 0;
net_buffer_size = 100000; net_buffer_size = 100000;
net_buffer = malloc(net_buffer_size); net_buffer = malloc(net_buffer_size);
return_buffer_size = 100000; return_buffer_size = 100000;
@ -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");