#include <pthread.h>
#include <signal.h>
#include "webcit.h"
+#include "webserver.h"
-void select_user_to_edit(char *message)
+void select_user_to_edit(char *message, char *preselect)
{
char buf[SIZ];
char username[SIZ];
if (message != NULL) wprintf(message);
- wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
+ wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
+ wprintf("<SPAN CLASS=\"titlebar\">"
"Add/change/delete user accounts"
- "</B></FONT></TD></TR></TABLE>\n");
+ "</SPAN></TD></TR></TABLE>\n");
wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
"<TD>To edit an existing user account, select the user "
if (buf[0] == '1') {
while (serv_gets(buf), strcmp(buf, "000")) {
extract(username, buf, 0);
- wprintf("<OPTION>");
+ wprintf("<OPTION");
+ if (preselect != NULL)
+ if (!strcasecmp(username, preselect))
+ wprintf(" SELECTED");
+ wprintf(">");
escputs(username);
wprintf("\n");
}
}
wprintf("</SELECT><BR>\n");
- wprintf("<input type=submit name=sc value=\"Edit\">");
+ wprintf("<input type=submit name=sc value=\"Edit configuration\">");
+ wprintf("<input type=submit name=sc value=\"Edit address book entry\">");
wprintf("</FORM></CENTER>\n");
wprintf("</TD><TD>"
+/*
+ * Locate the message number of a user's vCard in the current room
+ */
+long locate_user_vcard(char *username, long usernum) {
+ char buf[SIZ];
+ long vcard_msgnum = (-1L);
+ char content_type[SIZ];
+ char partnum[SIZ];
+ int already_tried_creating_one = 0;
+
+ struct stuff_t {
+ struct stuff_t *next;
+ long msgnum;
+ };
+
+ struct stuff_t *stuff = NULL;
+ struct stuff_t *ptr;
+
+TRYAGAIN:
+ /* Search for the user's vCard */
+ serv_puts("MSGS ALL");
+ serv_gets(buf);
+ if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
+ ptr = malloc(sizeof(struct stuff_t));
+ ptr->msgnum = atol(buf);
+ ptr->next = stuff;
+ stuff = ptr;
+ }
+
+ /* Iterate through the message list looking for vCards */
+ while (stuff != NULL) {
+ serv_printf("MSG0 %ld|2", stuff->msgnum);
+ serv_gets(buf);
+ if (buf[0]=='1') {
+ while(serv_gets(buf), strcmp(buf, "000")) {
+ if (!strncasecmp(buf, "part=", 5)) {
+ extract(partnum, &buf[5], 2);
+ extract(content_type, &buf[5], 4);
+ if (!strcasecmp(content_type,
+ "text/x-vcard")) {
+ vcard_msgnum = stuff->msgnum;
+ }
+ }
+ }
+ }
+
+ ptr = stuff->next;
+ free(stuff);
+ stuff = ptr;
+ }
+
+ /* If there's no vcard, create one */
+ if (vcard_msgnum < 0) if (already_tried_creating_one == 0) {
+ already_tried_creating_one = 1;
+ serv_puts("ENT0 1|||4");
+ serv_gets(buf);
+ if (buf[0] == '4') {
+ serv_puts("Content-type: text/x-vcard");
+ serv_puts("");
+ serv_puts("begin:vcard");
+ serv_puts("end:vcard");
+ serv_puts("000");
+ }
+ goto TRYAGAIN;
+ }
+
+ return(vcard_msgnum);
+}
+
+
+/*
+ * Display the form for editing a user's address book entry
+ */
+void display_edit_address_book_entry(char *username, long usernum) {
+ char roomname[SIZ];
+ char buf[SIZ];
+ char error_message[SIZ];
+ long vcard_msgnum = (-1L);
+
+ /* Locate the user's config room, creating it if necessary */
+ sprintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM);
+ serv_printf("GOTO %s||1", roomname);
+ serv_gets(buf);
+ if (buf[0] != '2') {
+ serv_printf("CRE8 1|%s|5|||1|", roomname);
+ serv_gets(buf);
+ serv_printf("GOTO %s||1", roomname);
+ serv_gets(buf);
+ if (buf[0] != '2') {
+ sprintf(error_message,
+ "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+ "%s<BR><BR>\n", &buf[4]);
+ select_user_to_edit(error_message, username);
+ return;
+ }
+ }
+
+ vcard_msgnum = locate_user_vcard(username, usernum);
+
+ if (vcard_msgnum < 0) {
+ sprintf(error_message,
+ "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+ "Could not create/edit vCard"
+ "<BR><BR>\n"
+ );
+ select_user_to_edit(error_message, username);
+ return;
+ }
+
+ do_edit_vcard(vcard_msgnum, "1", "/select_user_to_edit");
+}
+
+
+
+
/*
* Edit a user. If supplied_username is null, look in the "username"
* web variable for the name of the user to edit.
serv_gets(buf);
if (buf[0] != '2') {
sprintf(error_message,
- "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
+ "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
"%s<BR><BR>\n", &buf[4]);
- select_user_to_edit(error_message);
+ select_user_to_edit(error_message, username);
return;
}
lastcall = extract_long(&buf[4], 7);
purgedays = extract_long(&buf[4], 8);
+ if (!strcmp(bstr("sc"), "Edit address book entry")) {
+ display_edit_address_book_entry(username, usernum);
+ return;
+ }
+
output_headers(3); /* No room banner on this screen */
- wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
+ wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
+ wprintf("<SPAN CLASS=\"titlebar\">"
"Edit user account: ");
escputs(username);
- wprintf("</B></FONT></TD></TR></TABLE>\n");
+ wprintf("</SPAN></TD></TR></TABLE>\n");
wprintf("<FORM METHOD=\"POST\" ACTION=\"/edituser\">\n"
"<INPUT TYPE=\"hidden\" NAME=\"username\" VALUE=\"");
wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"OK\">\n"
"<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n"
- "</CENTER>\n");
+ "<BR><BR></FORM>\n");
- wprintf("</FORM>\n");
+ wprintf("</CENTER>\n");
wDumpContent(1);
serv_gets(buf);
if (buf[0] != '2') {
sprintf(message,
- "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
+ "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
"%s<BR><BR>\n", &buf[4]);
}
else {
}
}
- select_user_to_edit(message);
+ select_user_to_edit(message, bstr("username"));
}
serv_gets(buf);
if (buf[0] == '2') {
- display_edituser(username);
+ sprintf(error_message, "<b>User has been created.</b>");
+ select_user_to_edit(error_message, username);
}
else {
sprintf(error_message,
- "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
+ "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
"%s<BR><BR>\n", &buf[4]);
- select_user_to_edit(error_message);
+ select_user_to_edit(error_message, NULL);
}
}