* Administratively edit other users' vCards. Still needs a couple of lines
authorArt Cancro <ajc@citadel.org>
Sun, 16 Jun 2002 21:49:02 +0000 (21:49 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 16 Jun 2002 21:49:02 +0000 (21:49 +0000)
  of glue code to make it work.

webcit/ChangeLog
webcit/useredit.c
webcit/webcit.h

index 847f34c2c020fddb5e24404c6aa3996053b2a7f5..1e4801c875a569173f64e2dacc88e46a280a7737 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 323.40  2002/06/16 21:49:02  ajc
+* Administratively edit other users' vCards.  Still needs a couple of lines
+  of glue code to make it work.
+
 Revision 323.39  2002/06/15 20:34:39  ajc
 * Use safestrncpy() instead of strncpy() where appropriate
 * Fixed a memory allocation bug in the vCard parser
@@ -835,3 +839,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 79afc94c31c3fcac3769ea881d96e3df5689b937..e47ed8dbb6c4ee40a17f3a19d3bd38a91f3b8331 100644 (file)
@@ -24,6 +24,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include "webcit.h"
+#include "webserver.h"
 
 
 
@@ -61,7 +62,8 @@ void select_user_to_edit(char *message)
         }
         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>"
@@ -81,6 +83,109 @@ void select_user_to_edit(char *message)
 
 
 
+/* 
+ * 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);
+       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;
+
+
+       /* Locate the user's config room, creating it if necessary */
+       sprintf(roomname, "%010ld.My Citadel Config", usernum);
+       serv_printf("GOTO %s", roomname);
+       serv_gets(buf);
+       if (buf[0] != '2') {
+               serv_printf("CRE8 1|%s|5|", roomname);
+               serv_gets(buf);
+               serv_printf("GOTO %s", roomname);
+               serv_gets(buf);
+               if (buf[0] != '2') {
+                       sprintf(error_message,
+                               "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
+                               "%s<BR><BR>\n", &buf[4]);
+                       select_user_to_edit(error_message);
+                       return;
+               }
+       }
+
+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 throught 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;
+       }
+
+       lprintf(9, "vcard_msgnum == %ld\n", vcard_msgnum);
+
+       /* 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;
+       }
+
+       if (vcard_msgnum < 0) {
+               sprintf(error_message,
+                       "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
+                       "Could not create/edit vCard<BR><BR>\n");
+               select_user_to_edit(error_message);
+               return;
+       }
+
+       display_addressbook(vcard_msgnum, 0);
+}
+
+
+
+
 /*
  * Edit a user.  If supplied_username is null, look in the "username"
  * web variable for the name of the user to edit.
@@ -128,6 +233,11 @@ void display_edituser(char *supplied_username) {
        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>"
index 516aff864f597775a281462d9e7f1344c11a4498..a3c6f4cb65f9ff5aa753cb7691d18121b1df39c8 100644 (file)
@@ -309,3 +309,4 @@ void set_preference(char *key, char *value);
 void knrooms(void);
 int is_msg_in_mset(char *mset, long msgnum);
 char *safestrncpy(char *dest, const char *src, size_t n);
+void display_addressbook(long msgnum, char alpha);