* More vCard editing stuff
authorArt Cancro <ajc@citadel.org>
Tue, 5 Mar 2002 05:05:09 +0000 (05:05 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 5 Mar 2002 05:05:09 +0000 (05:05 +0000)
webcit/ChangeLog
webcit/static/vcard.gif [new file with mode: 0644]
webcit/vcard.c
webcit/vcard.h
webcit/vcard_edit.c

index 9b5083baac9dc457004e5dd42ab9c08165680c91..dcc1a6c9261668d71ecc754786edcb8ad5ef0f8f 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 323.8  2002/03/05 05:05:06  ajc
+* More vCard editing stuff
+
 Revision 323.7  2002/03/04 05:28:54  ajc
 * Wrote some skeleton code for robust vCard editing
 
@@ -732,3 +735,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
+
diff --git a/webcit/static/vcard.gif b/webcit/static/vcard.gif
new file mode 100644 (file)
index 0000000..d696d67
Binary files /dev/null and b/webcit/static/vcard.gif differ
index 03a16b689d196c5851ec29d8156131b4bbe772ad..362dbe6b660133a49c888cb79f130dbc1c9e5f5f 100644 (file)
@@ -128,14 +128,15 @@ struct vCard *vcard_load(char *vtext) {
 
 
 /*
- * Fetch the value of a particular key
+ * Fetch the value of a particular key.
  * If is_partial is set to 1, a partial match is ok (for example,
- * a key of "tel;home" will satisfy a search for "tel")
+ * a key of "tel;home" will satisfy a search for "tel").
  * Set "instance" to a value higher than 0 to return subsequent instances
- * of the same key
+ * of the same key.
+ * Set "get_propname" to nonzero to fetch the property name instead of value.
  */
 char *vcard_get_prop(struct vCard *v, char *propname,
-                       int is_partial, int instance) {
+                       int is_partial, int instance, int get_propname) {
        int i;
        int found_instance = 0;
 
@@ -147,7 +148,12 @@ char *vcard_get_prop(struct vCard *v, char *propname,
                         && (v->prop[i].name[strlen(propname)] == ';')
                         && (is_partial) ) ) {
                        if (instance == found_instance++) {
-                               return(v->prop[i].value);
+                               if (get_propname) {
+                                       return(v->prop[i].name);
+                               }
+                               else {
+                                       return(v->prop[i].value);
+                               }
                        }
                }
        }
index 743efa99063c2c415d8167f74239af4b74a54e31..aae58eb3c2b2e9cd5009cff1a03faf29cd1fbb0d 100644 (file)
@@ -29,5 +29,5 @@ struct vCard *vcard_load(char *);
 void vcard_free(struct vCard *);
 void vcard_set_prop(struct vCard *v, char *name, char *value, int append);
 char *vcard_get_prop(struct vCard *v, char *propname, int is_partial,
-                       int instance);
+                       int instance, int return_propname);
 char *vcard_serialize(struct vCard *);
index 9f3912bb43b552f87d9b3a664e518baa23c63e04..12f15cbe7d1b1f2173dc09919cc7ebd6078461e4 100644 (file)
@@ -6,7 +6,6 @@
  * $Id$
  */
 
-
 #include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -39,7 +38,35 @@ void edit_vcard(void) {
        size_t thisblock = 0;
        struct vCard *v;
        int i;
-       char *prop;
+       char *key, *value;
+
+       char lastname[SIZ];
+       char firstname[SIZ];
+       char middlename[SIZ];
+       char prefix[SIZ];
+       char suffix[SIZ];
+       char pobox[SIZ];
+       char extadr[SIZ];
+       char street[SIZ];
+       char city[SIZ];
+       char state[SIZ];
+       char zipcode[SIZ];
+       char country[SIZ];
+       char extrafields[SIZ];
+
+       lastname[0] = 0;
+       firstname[0] = 0;
+       middlename[0] = 0;
+       prefix[0] = 0;
+       suffix[0] = 0;
+       pobox[0] = 0;
+       extadr[0] = 0;
+       street[0] = 0;
+       city[0] = 0;
+       state[0] = 0;
+       zipcode[0] = 0;
+       country[0] = 0;
+       extrafields[0] = 0;
 
        output_headers(1);
        sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("partnum") );
@@ -75,16 +102,95 @@ void edit_vcard(void) {
        v = vcard_load(serialized_vcard);
        free(serialized_vcard);
 
-       wprintf("<BLINK>   FIXME    </BLINK><BR><BR>\n"
-               "This needs to be implemented as an editable form.<BR><BR>\n");
-
+       /* Populate the variables for our form */
        i = 0;
-       while (prop = vcard_get_prop(v, "", 0, i++), prop != NULL) {
-               escputs(prop);
-               wprintf("<BR>\n");
+       while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
+               value = vcard_get_prop(v, "", 0, i++, 0);
+
+               if (!strcasecmp(key, "n")) {
+                       extract_token(lastname, value, 0, ';');
+                       extract_token(firstname, value, 1, ';');
+                       extract_token(middlename, value, 2, ';');
+                       extract_token(prefix, value, 3, ';');
+                       extract_token(suffix, value, 4, ';');
+               }
+
+               else if (!strcasecmp(key, "adr")) {
+                       extract_token(pobox, value, 0, ';');
+                       extract_token(extadr, value, 1, ';');
+                       extract_token(street, value, 2, ';');
+                       extract_token(city, value, 3, ';');
+                       extract_token(state, value, 4, ';');
+                       extract_token(zipcode, value, 5, ';');
+                       extract_token(country, value, 6, ';');
+               }
+
+               else {
+                       strcat(extrafields, key);
+                       strcat(extrafields, ":");
+                       strcat(extrafields, value);
+                       strcat(extrafields, "\n");
+               }
+
        }
        
        vcard_free(v);
+
+       /* Display the form */
+       wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_FIXME_stuff\">\n");
+       wprintf("<H2><IMG VALIGN=CENTER SRC=\"/static/vcard.gif\">"
+               "Contact information for FIXME</H2>\n");
+
+       wprintf("Last name: "
+               "<INPUT TYPE=\"text\" NAME=\"lastname\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
+               lastname);
+       wprintf("First name: "
+               "<INPUT TYPE=\"text\" NAME=\"firstname\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"><BR>\n",
+               firstname);
+       wprintf("Prefix: "
+               "<INPUT TYPE=\"text\" NAME=\"prefix\" "
+               "VALUE=\"%s\" MAXLENGTH=\"5\"><BR>\n",
+               prefix);
+       wprintf("Suffix: "
+               "<INPUT TYPE=\"text\" NAME=\"suffix\" "
+               "VALUE=\"%s\" MAXLENGTH=\"10\"><BR><BR>\n",
+               suffix);
+
+       wprintf("<TABLE border=0><TR><TD>Address - PO box; optional:</TD>"
+               "<TD><INPUT TYPE=\"text\" NAME=\"pobox\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
+               pobox);
+       wprintf("<TR><TD>Street:</TD>"
+               "<TD><INPUT TYPE=\"text\" NAME=\"extadr\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
+               extadr);
+       wprintf("<TR><TD>&nbsp;</TD>"
+               "<TD><INPUT TYPE=\"text\" NAME=\"street\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR>\n",
+               street);
+       wprintf("<TR><TD>City:</TD>"
+               "<TD><INPUT TYPE=\"text\" NAME=\"city\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\">\n",
+               city);
+       wprintf(" State: "
+               "<INPUT TYPE=\"text\" NAME=\"state\" "
+               "VALUE=\"%s\" MAXLENGTH=\"2\">\n",
+               state);
+       wprintf(" ZIP code: "
+               "<INPUT TYPE=\"text\" NAME=\"zipcode\" "
+               "VALUE=\"%s\" MAXLENGTH=\"10\"></TD></TR>\n",
+               zipcode);
+       wprintf("<TR><TD>Country:</TD>"
+               "<TD><INPUT TYPE=\"text\" NAME=\"country\" "
+               "VALUE=\"%s\" MAXLENGTH=\"29\"></TD></TR></TABLE>\n",
+               country);
+
+       wprintf("<TEXTAREA NAME=\"extrafields\" ROWS=10 COLS=80 WIDTH=80>");
+       escputs(extrafields);
+       wprintf("</TEXTAREA><BR>\n");
+
         
        wDumpContent(1);
 }