X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=17b781778c9804509c0c7d6138bf97b922ae4e13;hb=2362c3d4de86f20822ab81015222a196137fd20e;hp=58047f7b8c85d937e10f889194751fee14c22dc3;hpb=25085ec2cf0f8a5d34cfb8906e43e2df18d0e0ed;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index 58047f7b8..17b781778 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -1,62 +1,53 @@ /* - * vcard_edit.c - * - * Handles editing of vCard objects. - * * $Id$ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/** + * \defgroup vCardEdit Handles on-screen editing of vCard objects. + * \ingroup VCards + */ +/*@{*/ #include "webcit.h" -#include "vcard.h" - - -void edit_vcard(void) { +/** + * \brief Edit the vCard component of a MIME message. + * Supply the message number + * and MIME part number to fetch. Or, specify -1 for the message number + * to start with a blank card. + * \param msgnum number of the item on the citadel server + * \param partnum what??? + * \param return_to where to go back in the browser after edit ???? + */ +void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) { char buf[SIZ]; char *serialized_vcard = NULL; size_t total_len = 0; - size_t bytes = 0; - size_t thisblock = 0; struct vCard *v; int i; char *key, *value; - char whatuser[SIZ]; - - 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 hometel[SIZ]; - char worktel[SIZ]; - char inetemail[SIZ]; + char whatuser[256]; + + char lastname[256]; + char firstname[256]; + char middlename[256]; + char prefix[256]; + char suffix[256]; + char pobox[256]; + char extadr[256]; + char street[256]; + char city[256]; + char state[256]; + char zipcode[256]; + char country[256]; + char hometel[256]; + char worktel[256]; + char faxtel[256]; + char mobiletel[256]; + char primary_inetemail[256]; + char other_inetemail[SIZ]; char extrafields[SIZ]; + char fullname[256]; + char title[256]; + char org[256]; lastname[0] = 0; firstname[0] = 0; @@ -72,233 +63,376 @@ void edit_vcard(void) { country[0] = 0; hometel[0] = 0; worktel[0] = 0; - inetemail[0] = 0; + faxtel[0] = 0; + mobiletel[0] = 0; + primary_inetemail[0] = 0; + other_inetemail[0] = 0; + title[0] = 0; + org[0] = 0; extrafields[0] = 0; + fullname[0] = 0; - output_headers(1); + safestrncpy(whatuser, "", sizeof whatuser); - strcpy(whatuser, ""); - sprintf(buf, "MSG0 %s|1", bstr("msgnum") ); - serv_puts(buf); - serv_gets(buf); - if (buf[0] != '1') { - wDumpContent(1); - return; - } - while (serv_gets(buf), strcmp(buf, "000")) { - if (!strncasecmp(buf, "from=", 5)) { - strcpy(whatuser, &buf[5]); + if (msgnum >= 0) { + sprintf(buf, "MSG0 %ld|1", msgnum); + serv_puts(buf); + serv_getln(buf, sizeof buf); + if (buf[0] != '1') { + convenience_page("770000", _("Error"), &buf[4]); + return; } - else if (!strncasecmp(buf, "node=", 5)) { - strcat(whatuser, " @ "); - strcat(whatuser, &buf[5]); + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + if (!strncasecmp(buf, "from=", 5)) { + safestrncpy(whatuser, &buf[5], sizeof whatuser); + } + else if (!strncasecmp(buf, "node=", 5)) { + strcat(whatuser, " @ "); + strcat(whatuser, &buf[5]); + } } - } - - total_len = atoi(&buf[4]); - - - sprintf(buf, "OPNA %s|%s", bstr("msgnum"), bstr("partnum") ); - serv_puts(buf); - serv_gets(buf); - if (buf[0] != '2') { - wDumpContent(1); - return; - } - - total_len = atoi(&buf[4]); - serialized_vcard = malloc(total_len + 1); - while (bytes < total_len) { - thisblock = 4000; - if ((total_len - bytes) < thisblock) thisblock = total_len - bytes; - sprintf(buf, "READ %d|%d", bytes, thisblock); + + sprintf(buf, "DLAT %ld|%s", msgnum, partnum); serv_puts(buf); - serv_gets(buf); - if (buf[0] == '6') { - thisblock = atoi(&buf[4]); - serv_read(&serialized_vcard[bytes], thisblock); - bytes += thisblock; - } - else { - wprintf("Error: %s
\n", &buf[4]); + serv_getln(buf, sizeof buf); + if (buf[0] != '6') { + convenience_page("770000", "Error", &buf[4]); + return; } - } - - serv_puts("CLOS"); - serv_gets(buf); - serialized_vcard[total_len + 1] = 0; - - v = vcard_load(serialized_vcard); - free(serialized_vcard); + + total_len = atoi(&buf[4]); + serialized_vcard = malloc(total_len + 2); - /* Populate the variables for our form */ - i = 0; - 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, ';'); - } + serv_read(serialized_vcard, total_len); + serialized_vcard[total_len] = 0; + + v = vcard_load(serialized_vcard); + free(serialized_vcard); + + /* Populate the variables for our form */ + i = 0; + 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, ';', sizeof lastname); + extract_token(firstname, value, 1, ';', sizeof firstname); + extract_token(middlename, value, 2, ';', sizeof middlename); + extract_token(prefix, value, 3, ';', sizeof prefix); + extract_token(suffix, value, 4, ';', sizeof suffix); + } - 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 if (!strcasecmp(key, "fn")) { + safestrncpy(fullname, value, sizeof fullname); + } - else if (!strcasecmp(key, "tel;home")) { - extract_token(hometel, value, 0, ';'); + else if (!strcasecmp(key, "title")) { + safestrncpy(title, value, sizeof title); + } + + else if (!strcasecmp(key, "org")) { + safestrncpy(org, value, sizeof org); + } + + else if (!strcasecmp(key, "adr")) { + extract_token(pobox, value, 0, ';', sizeof pobox); + extract_token(extadr, value, 1, ';', sizeof extadr); + extract_token(street, value, 2, ';', sizeof street); + extract_token(city, value, 3, ';', sizeof city); + extract_token(state, value, 4, ';', sizeof state); + extract_token(zipcode, value, 5, ';', sizeof zipcode); + extract_token(country, value, 6, ';', sizeof country); + } + + else if (!strcasecmp(key, "tel;home")) { + extract_token(hometel, value, 0, ';', sizeof hometel); + } + + else if (!strcasecmp(key, "tel;work")) { + extract_token(worktel, value, 0, ';', sizeof worktel); + } + + else if (!strcasecmp(key, "tel;fax")) { + extract_token(faxtel, value, 0, ';', sizeof faxtel); + } + + else if (!strcasecmp(key, "tel;cell")) { + extract_token(mobiletel, value, 0, ';', sizeof mobiletel); + } + + else if (!strcasecmp(key, "email;internet")) { + if (primary_inetemail[0] == 0) { + safestrncpy(primary_inetemail, value, sizeof primary_inetemail); + } + else { + if (other_inetemail[0] != 0) { + strcat(other_inetemail, "\n"); + } + strcat(other_inetemail, value); + } + } + + else { + strcat(extrafields, key); + strcat(extrafields, ":"); + strcat(extrafields, value); + strcat(extrafields, "\n"); + } + } + + vcard_free(v); + } - else if (!strcasecmp(key, "tel;work")) { - extract_token(worktel, value, 0, ';'); - } + /** Display the form */ + output_headers(1, 1, 1, 0, 0, 0); - else if (!strcasecmp(key, "email;internet")) { - if (inetemail[0] != 0) { - strcat(inetemail, "\n"); - } - strcat(inetemail, value); - } + svput("BOXTITLE", WCS_STRING, _("Edit contact information")); + do_template("beginbox"); - else { - strcat(extrafields, key); - strcat(extrafields, ":"); - strcat(extrafields, value); - strcat(extrafields, "\n"); - } + wprintf("
\n"); + wprintf("\n", WC->nonce); + if (force_room != NULL) { + wprintf("\n"); } - - vcard_free(v); - /* Display the form */ - wprintf("\n"); - wprintf("

" - "Contact information for "); - escputs(whatuser); - wprintf("

\n"); - - wprintf("" - "" - "" - "" - "" - "\n"); - wprintf("", + wprintf("
" + "
PrefixFirstMiddleLastSuffix
\n"); + + wprintf("" + "" + "" + "" + "" + "\n", + _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix") + ); + wprintf("", prefix); - wprintf("", + wprintf("", firstname); - wprintf("", + wprintf("", middlename); - wprintf("", + wprintf("", lastname); - wprintf("
%s%s%s%s%s
\n", + wprintf("
\n", suffix); - wprintf("" - "\n", + wprintf("
PO box (optional):
"); + wprintf("\n", country); + wprintf("
"); + + wprintf(_("Display name:")); + wprintf("
" + "

\n", + fullname + ); + + wprintf(_("Title:")); + wprintf("
" + "

\n", + title + ); + + wprintf(_("Organization:")); + wprintf("
" + "

\n", + org + ); + + wprintf("
"); + + wprintf(""); + wprintf("\n", pobox); - wprintf("" - "\n", + wprintf("\n", extadr); - wprintf("" - "\n", + wprintf("\n", street); - wprintf("" - "\n", city); - wprintf(" State: " - "\n", + wprintf("\n", state); - wprintf(" ZIP code: " - "\n", + wprintf("\n", zipcode); - wprintf("" - "
"); + wprintf(_("PO box:")); + wprintf("" + "
Address line 1:
"); + wprintf(_("Address:")); + wprintf("" + "
Address line 2:
" + "
City:\n", + wprintf("
"); + wprintf(_("City:")); + wprintf("" + "
"); + wprintf(_("State:")); + wprintf("" + "
"); + wprintf(_("ZIP code:")); + wprintf("" + "
Country:
\n", + wprintf("
"); + wprintf(_("Country:")); + wprintf("" + "
\n"); + + wprintf("\n"); - wprintf("" - "\n", + wprintf("
Home telephone:
" + "\n", hometel); - wprintf("" - "
"); + wprintf(_("Home telephone:")); + wprintf("
Work telephone:
\n", + wprintf(""); + wprintf(_("Work telephone:")); + wprintf("" + "\n", worktel); - - wprintf("
Internet e-mail addresses:
" - "For addresses in the Citadel directory, " - "the topmost address will be used in outgoing mail." - "
" - "

\n"); - - wprintf(""); + wprintf(_("Mobile telephone:")); + wprintf("" + "\n", + mobiletel); + wprintf(""); + wprintf(_("Fax number:")); + wprintf("" + "\n", + faxtel); + + wprintf(""); + wprintf("
"); + + wprintf("" + "
"); + wprintf(_("Primary Internet e-mail address")); + wprintf("
" + "
" + "
"); + wprintf(_("Internet e-mail aliases")); + wprintf("
" + "
\n"); + + wprintf("
\n"); + + wprintf("\n"); - wprintf("
\n"); - wprintf(""); - wprintf(""); - wprintf("
\n"); + wprintf("\n"); - + wprintf("
\n" + "" + " " + "" + "
\n", + _("Save changes"), + _("Cancel") + ); + + wprintf("\n"); + do_template("endbox"); wDumpContent(1); } +/** + * \brief commit the edits to the citadel server + */ +void edit_vcard(void) { + long msgnum; + char *partnum; + + msgnum = lbstr("msgnum"); + partnum = bstr("partnum"); + do_edit_vcard(msgnum, partnum, "", NULL); +} + + +/** + * \brief parse edited vcard from the browser + */ void submit_vcard(void) { + struct vCard *v; + char *serialized_vcard; char buf[SIZ]; int i; - if (strcmp(bstr("sc"), "OK")) { + if (!havebstr("ok_button")) { readloop("readnew"); return; } + if (havebstr("force_room")) { + gotoroom(bstr("force_room")); + } + sprintf(buf, "ENT0 1|||4||"); - fprintf(stderr, "%s\n", buf); serv_puts(buf); - serv_gets(buf); - fprintf(stderr, "%s\n", buf); + serv_getln(buf, sizeof buf); if (buf[0] != '4') { edit_vcard(); return; } - serv_puts("Content-type: text/x-vcard"); - serv_puts(""); - serv_puts("begin:vcard"); - serv_printf("n:%s;%s;%s;%s;%s", + /** Make a vCard structure out of the data supplied in the form */ + + snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n", + bstr("extrafields") + ); + v = vcard_load(buf); /** Start with the extra fields */ + if (v == NULL) { + safestrncpy(WC->ImportantMessage, + _("An error has occurred."), + sizeof WC->ImportantMessage + ); + edit_vcard(); + return; + } + + snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s", bstr("lastname"), bstr("firstname"), bstr("middlename"), bstr("prefix"), bstr("suffix") ); - serv_printf("adr:%s;%s;%s;%s;%s;%s;%s", + vcard_add_prop(v, "n", buf); + + vcard_add_prop(v, "title", bstr("title")); + vcard_add_prop(v, "fn", bstr("fullname")); + vcard_add_prop(v, "org", bstr("org")); + + snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s", bstr("pobox"), bstr("extadr"), bstr("street"), @@ -306,19 +440,49 @@ void submit_vcard(void) { bstr("state"), bstr("zipcode"), bstr("country") ); - serv_printf("tel;home:%s", bstr("hometel") ); - serv_printf("tel;work:%s", bstr("worktel") ); - - for (i=0; i 0) { - serv_printf("email;internet:%s", buf); + vcard_add_prop(v, "adr", buf); + + vcard_add_prop(v, "tel;home", bstr("hometel")); + vcard_add_prop(v, "tel;work", bstr("worktel")); + vcard_add_prop(v, "tel;fax", bstr("faxtel")); + vcard_add_prop(v, "tel;cell", bstr("mobiletel")); + vcard_add_prop(v, "email;internet", bstr("primary_inetemail")); + + for (i=0; iImportantMessage, + _("An error has occurred."), + sizeof WC->ImportantMessage + ); + edit_vcard(); + return; + } + + serv_puts("Content-type: text/x-vcard; charset=UTF-8"); + serv_puts(""); + serv_printf("%s\r\n", serialized_vcard); serv_puts("000"); + free(serialized_vcard); - readloop("readnew"); + if (!strcmp(bstr("return_to"), "select_user_to_edit")) { + select_user_to_edit(NULL, NULL); + } + else if (!strcmp(bstr("return_to"), "do_welcome")) { + do_welcome(); + } + else { + readloop("readnew"); + } } + + + +/*@}*/