Made selections work with 'copy to' and 'move to'

SVN revision: 228
This commit is contained in:
Stefan Ritt 2002-09-10 05:59:04 +00:00
parent 1868d9585e
commit c4e2832e16

264
elogd.c
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 2.71 2002/09/10 05:59:04 midas
Made selections work with 'copy to' and 'move to'
Revision 2.70 2002/09/09 08:04:58 midas Revision 2.70 2002/09/09 08:04:58 midas
Added select boxes Added select boxes
@ -5423,7 +5426,10 @@ char str[256], in_reply_to[80], reply_to[256];
strcpy(str, getparam("nextmsg")); strcpy(str, getparam("nextmsg"));
if (atoi(str) == 0) if (atoi(str) == 0)
sprintf(str, "%d", el_search_message(lbs, EL_LAST, 0, TRUE)); sprintf(str, "%d", el_search_message(lbs, EL_LAST, 0, TRUE));
redirect(str); if (atoi(str) == 0)
redirect("");
else
redirect(str);
return; return;
} }
} }
@ -5746,7 +5752,7 @@ FILE *f;
{ {
/* show select box */ /* show select box */
if (select) if (select)
rsprintf("<td bgcolor=%s><input type=checkbox name=\"s%d\" value=1>\n", col, message_id); rsprintf("<td bgcolor=%s><input type=checkbox name=\"s%d\" value=%d>\n", col, (*n_display)++, message_id);
for (index=0 ; index<n_attr_disp ; index++) for (index=0 ; index<n_attr_disp ; index++)
{ {
@ -6241,7 +6247,11 @@ char ref[256];
void show_select_navigation(LOGBOOK *lbs) void show_select_navigation(LOGBOOK *lbs)
{ {
int i, n_log;
char str[256]; char str[256];
char lbk_list[MAX_N_LIST][NAME_LENGTH];
rsprintf("<tr><td><table width=100%% border=%s cellpadding=%s cellspacing=1>\n", rsprintf("<tr><td><table width=100%% border=%s cellpadding=%s cellspacing=1>\n",
gt("Border width"), gt("Categories cellpadding")); gt("Border width"), gt("Categories cellpadding"));
@ -6265,11 +6275,76 @@ char str[256];
rsprintf("<input type=button value=\"%s\" onClick=\"ToggleAll();\">\n", loc("Toggle all")); rsprintf("<input type=button value=\"%s\" onClick=\"ToggleAll();\">\n", loc("Toggle all"));
if (!getcfg(lbs->name, "Menu commands", str) || if (!getcfg(lbs->name, "Menu commands", str) ||
strstr(str, "Delete")) strstr(str, loc("Delete")))
{ {
rsprintf("<input type=submit name=cmd value=\"Delete\">\n"); rsprintf("<input type=submit name=cmd value=\"Delete\">\n");
} }
if (getcfg(lbs->name, "Menu commands", str) &&
strstr(str, loc("Copy to")))
{
rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Copy to"));
rsprintf("<select name=destc>\n");
if (getcfg(lbs->name, "Copy to", str))
{
n_log = strbreak(str, lbk_list, MAX_N_LIST);
for (i=0 ; i<n_log ; i++)
rsprintf("<option value=\"%s\">%s\n", lbk_list[i], lbk_list[i]);
}
else
{
for (i=0 ; ; i++)
{
if (!enumgrp(i, str))
break;
if (equal_ustring(str, "global"))
continue;
if (equal_ustring(str, lbs->name))
continue;
rsprintf("<option value=\"%s\">%s\n", str, str);
}
}
rsprintf("</select>\n");
}
if (getcfg(lbs->name, "Menu commands", str) &&
strstr(str, loc("Move to")))
{
rsprintf("<input type=submit name=cmd value=\"%s\">\n", loc("Move to"));
rsprintf("<select name=destm>\n");
if (getcfg(lbs->name, "Move to", str))
{
n_log = strbreak(str, lbk_list, MAX_N_LIST);
for (i=0 ; i<n_log ; i++)
rsprintf("<option value=\"%s\">%s\n", lbk_list[i], lbk_list[i]);
}
else
{
for (i=0 ; ; i++)
{
if (!enumgrp(i, str))
break;
if (equal_ustring(str, "global"))
continue;
if (equal_ustring(str, lbs->name))
continue;
rsprintf("<option value=\"%s\">%s\n", str, str);
}
}
rsprintf("</select>\n");
}
rsprintf("</td></tr></table></td></tr>\n\n"); rsprintf("</td></tr></table></td></tr>\n\n");
} }
@ -7478,7 +7553,7 @@ int i, j, n, missing, first, index, n_mail, suppress, message_id;
void copy_to(LOGBOOK *lbs, int src_id, char *dest_logbook, int move) void copy_to(LOGBOOK *lbs, int src_id, char *dest_logbook, int move)
{ {
int size, i, status, fh, message_id; int size, i, n, n_done, index, status, fh, source_id, message_id;
char str[256], file_name[256], attrib[MAX_N_ATTR][NAME_LENGTH]; char str[256], file_name[256], attrib[MAX_N_ATTR][NAME_LENGTH];
char date[80], text[TEXT_SIZE], msg_str[32], in_reply_to[80], reply_to[256], char date[80], text[TEXT_SIZE], msg_str[32], in_reply_to[80], reply_to[256],
attachment[MAX_ATTACHMENTS][256], encoding[80]; attachment[MAX_ATTACHMENTS][256], encoding[80];
@ -7491,83 +7566,106 @@ LOGBOOK *lbs_dest;
return; return;
lbs_dest = &lb_list[i]; lbs_dest = &lb_list[i];
/* get message */ if (src_id)
size = sizeof(text); n = 1;
status = el_retrieve(lbs, src_id, date, attr_list, attrib, lbs->n_attr, else
text, &size, in_reply_to, reply_to, n = atoi(getparam("nsel"));
attachment, encoding);
if (status != EL_SUCCESS) n_done = 0;
for (index=0 ; index<n ; index++)
{ {
sprintf(msg_str, "%d", src_id); if (src_id)
sprintf(str, loc("Message %s cannot be read from logbook \"%s\""), msg_str, lbs->name); source_id = src_id;
show_error(str); else
return;
}
/* read attachments */
for (i=0 ; i<MAX_ATTACHMENTS ; i++)
if (attachment[i][0])
{ {
strcpy(file_name, lbs->data_dir); sprintf(str, "s%d", index);
strcat(file_name, attachment[i]); if (!isparam(str))
continue;
fh = open(file_name, O_RDONLY | O_BINARY); source_id = atoi(getparam(str));
if (fh > 0)
{
lseek(fh, 0, SEEK_END);
_attachment_size[i] = TELL(fh);
lseek(fh, 0, SEEK_SET);
_attachment_buffer[i] = malloc(_attachment_size[i]);
if (_attachment_buffer[i])
read(fh, _attachment_buffer[i], _attachment_size[i]);
close(fh);
}
/* stip date/time from file name */
strcpy(str, attachment[i]);
strcpy(attachment[i], str+14);
} }
/* submit in destination logbook without links */ /* get message */
size = sizeof(text);
status = el_retrieve(lbs, source_id, date, attr_list, attrib, lbs->n_attr,
text, &size, in_reply_to, reply_to,
attachment, encoding);
message_id = el_submit(lbs_dest, 0, date, attr_list, attrib, lbs_dest->n_attr, text, if (status != EL_SUCCESS)
"", "", encoding, {
attachment, sprintf(msg_str, "%d", source_id);
_attachment_buffer, sprintf(str, loc("Message %s cannot be read from logbook \"%s\""), msg_str, lbs->name);
_attachment_size); show_error(str);
return;
}
for (i=0 ; i<MAX_ATTACHMENTS ; i++) /* read attachments */
if (attachment[i][0]) for (i=0 ; i<MAX_ATTACHMENTS ; i++)
free(_attachment_buffer[i]); if (attachment[i][0])
{
strcpy(file_name, lbs->data_dir);
strcat(file_name, attachment[i]);
if (message_id <= 0) fh = open(file_name, O_RDONLY | O_BINARY);
{ if (fh > 0)
sprintf(str, loc("New message cannot be written to directory \"%s\""), lbs_dest->data_dir); {
strcat(str, "\n<p>"); lseek(fh, 0, SEEK_END);
strcat(str, loc("Please check that it exists and elogd has write access")); _attachment_size[i] = TELL(fh);
show_error(str); lseek(fh, 0, SEEK_SET);
return;
}
/* delete original message for move */
if (move) _attachment_buffer[i] = malloc(_attachment_size[i]);
{
el_delete_message(lbs, src_id, TRUE, NULL, TRUE);
/* check if this was the last message */ if (_attachment_buffer[i])
src_id = el_search_message(lbs, EL_NEXT, src_id, FALSE); read(fh, _attachment_buffer[i], _attachment_size[i]);
/* if yes, force display of new last message */ close(fh);
if (src_id <= 0) }
src_id = el_search_message(lbs, EL_LAST, 0, FALSE);
/* stip date/time from file name */
strcpy(str, attachment[i]);
strcpy(attachment[i], str+14);
}
/* submit in destination logbook without links */
message_id = el_submit(lbs_dest, 0, date, attr_list, attrib, lbs_dest->n_attr, text,
"", "", encoding,
attachment,
_attachment_buffer,
_attachment_size);
for (i=0 ; i<MAX_ATTACHMENTS ; i++)
if (attachment[i][0])
free(_attachment_buffer[i]);
if (message_id <= 0)
{
sprintf(str, loc("New message cannot be written to directory \"%s\""), lbs_dest->data_dir);
strcat(str, "\n<p>");
strcat(str, loc("Please check that it exists and elogd has write access"));
show_error(str);
return;
}
n_done++;
/* delete original message for move */
if (move)
{
el_delete_message(lbs, source_id, TRUE, NULL, TRUE);
/* check if this was the last message */
source_id = el_search_message(lbs, EL_NEXT, source_id, FALSE);
/* if yes, force display of new last message */
if (source_id <= 0)
source_id = el_search_message(lbs, EL_LAST, 0, FALSE);
}
} }
/* display status message */ /* display status message */
sprintf(str, "%d", src_id); sprintf(str, "%d", source_id);
show_standard_header(loc("Copy ELog entry"), str); show_standard_header(loc("Copy ELog entry"), str);
rsprintf("<p><p><p><table border=%s width=50%% bgcolor=%s cellpadding=1 cellspacing=0 align=center>", rsprintf("<p><p><p><table border=%s width=50%% bgcolor=%s cellpadding=1 cellspacing=0 align=center>",
@ -7575,14 +7673,29 @@ LOGBOOK *lbs_dest;
rsprintf("<tr><td><table cellpadding=5 cellspacing=0 border=0 width=100%% bgcolor=%s>\n", gt("Frame color")); rsprintf("<tr><td><table cellpadding=5 cellspacing=0 border=0 width=100%% bgcolor=%s>\n", gt("Frame color"));
rsprintf("<tr><td bgcolor=#80FF80 align=center><b>"); rsprintf("<tr><td bgcolor=#80FF80 align=center><b>");
if (move) if (n>1)
rsprintf(loc("Message moved successfully from \"%s\" to \"%s\""), lbs->name, lbs_dest->name); {
if (move)
rsprintf(loc("%d messages moved successfully from \"%s\" to \"%s\""), n_done, lbs->name, lbs_dest->name);
else
rsprintf(loc("%d messages copied successfully from \"%s\" to \"%s\""), n_done, lbs->name, lbs_dest->name);
}
else else
rsprintf(loc("Message copied successfully from \"%s\" to \"%s\""), lbs->name, lbs_dest->name); {
if (move)
rsprintf(loc("Message moved successfully from \"%s\" to \"%s\""), lbs->name, lbs_dest->name);
else
rsprintf(loc("Message copied successfully from \"%s\" to \"%s\""), lbs->name, lbs_dest->name);
}
rsprintf("</b></tr>\n"); rsprintf("</b></tr>\n");
rsprintf("<tr><td bgcolor=%s align=center>%s <a href=\"../%s/%d\">%s</td></tr>\n", if (src_id)
gt("Cell BGColor"), loc("Go to"), lbs->name, src_id, lbs->name); rsprintf("<tr><td bgcolor=%s align=center>%s <a href=\"../%s/%d\">%s</td></tr>\n",
gt("Cell BGColor"), loc("Go to"), lbs->name, source_id, lbs->name);
else
rsprintf("<tr><td bgcolor=%s align=center>%s <a href=\"../%s/%s\">%s</td></tr>\n",
gt("Cell BGColor"), loc("Go to"), lbs->name, getparam("cmdline"), lbs->name);
rsprintf("<tr><td bgcolor=%s align=center>%s <a href=\"../%s/\">%s</td></tr>\n", rsprintf("<tr><td bgcolor=%s align=center>%s <a href=\"../%s/\">%s</td></tr>\n",
gt("Cell BGColor"), loc("Go to"), lbs_dest->name, lbs_dest->name); gt("Cell BGColor"), loc("Go to"), lbs_dest->name, lbs_dest->name);
@ -7603,7 +7716,7 @@ char date[80], text[TEXT_SIZE], menu_str[1000], other_str[1000], cmd[256],
orig_tag[80], reply_tag[80], attachment[MAX_ATTACHMENTS][256], encoding[80], att[256], lattr[256]; orig_tag[80], reply_tag[80], attachment[MAX_ATTACHMENTS][256], encoding[80], att[256], lattr[256];
char menu_item[MAX_N_LIST][NAME_LENGTH], format[80], admin_user[80], char menu_item[MAX_N_LIST][NAME_LENGTH], format[80], admin_user[80],
slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH], *p; slist[MAX_N_ATTR+10][NAME_LENGTH], svalue[MAX_N_ATTR+10][NAME_LENGTH], *p;
char lb_list[MAX_N_LIST][NAME_LENGTH]; char lbk_list[MAX_N_LIST][NAME_LENGTH];
FILE *f; FILE *f;
BOOL first; BOOL first;
@ -8205,10 +8318,10 @@ BOOL first;
if (str[0]) if (str[0])
{ {
n_log = strbreak(str, lb_list, MAX_N_LIST); n_log = strbreak(str, lbk_list, MAX_N_LIST);
for (j=0 ; j<n_log ; j++) for (j=0 ; j<n_log ; j++)
rsprintf("<option value=\"%s\">%s\n", lb_list[j], lb_list[j]); rsprintf("<option value=\"%s\">%s\n", lbk_list[j], lbk_list[j]);
} }
else else
{ {
@ -9371,7 +9484,8 @@ LOGBOOK *cur_lb;
} }
if (strncmp(path, "last", 4) == 0 && strstr(path, ".gif") == NULL && if (strncmp(path, "last", 4) == 0 && strstr(path, ".gif") == NULL &&
!isparam("cmd") && !isparam("newpwd")) (!isparam("cmd") || equal_ustring(getparam("cmd"), loc("Select")))
&& !isparam("newpwd"))
{ {
show_elog_submit_find(cur_lb, 0, atoi(path+4), 0); show_elog_submit_find(cur_lb, 0, atoi(path+4), 0);
return; return;