8 * Edit the vCard component of a MIME message.
9 * Supply the message number
10 * and MIME part number to fetch. Or, specify -1 for the message number
11 * to start with a blank card.
13 void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
15 char *serialized_vcard = NULL;
38 char primary_inetemail[256];
39 char other_inetemail[SIZ];
40 char extrafields[SIZ];
61 primary_inetemail[0] = 0;
62 other_inetemail[0] = 0;
68 safestrncpy(whatuser, "", sizeof whatuser);
71 sprintf(buf, "MSG0 %ld|1", msgnum);
73 serv_getln(buf, sizeof buf);
75 convenience_page("770000", _("Error"), &buf[4]);
78 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
79 if (!strncasecmp(buf, "from=", 5)) {
80 safestrncpy(whatuser, &buf[5], sizeof whatuser);
82 else if (!strncasecmp(buf, "node=", 5)) {
83 strcat(whatuser, " @ ");
84 strcat(whatuser, &buf[5]);
88 sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
90 serv_getln(buf, sizeof buf);
92 convenience_page("770000", "Error", &buf[4]);
96 total_len = atoi(&buf[4]);
97 serialized_vcard = malloc(total_len + 2);
99 serv_read(serialized_vcard, total_len);
100 serialized_vcard[total_len] = 0;
102 v = vcard_load(serialized_vcard);
103 free(serialized_vcard);
105 /* Populate the variables for our form */
107 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
108 value = vcard_get_prop(v, "", 0, i++, 0);
110 if (!strcasecmp(key, "n")) {
111 extract_token(lastname, value, 0, ';', sizeof lastname);
112 extract_token(firstname, value, 1, ';', sizeof firstname);
113 extract_token(middlename, value, 2, ';', sizeof middlename);
114 extract_token(prefix, value, 3, ';', sizeof prefix);
115 extract_token(suffix, value, 4, ';', sizeof suffix);
118 else if (!strcasecmp(key, "fn")) {
119 safestrncpy(fullname, value, sizeof fullname);
122 else if (!strcasecmp(key, "title")) {
123 safestrncpy(title, value, sizeof title);
126 else if (!strcasecmp(key, "org")) {
127 safestrncpy(org, value, sizeof org);
130 else if ( (!strcasecmp(key, "adr")) || (!strncasecmp(key, "adr;", 4)) ) {
131 extract_token(pobox, value, 0, ';', sizeof pobox);
132 extract_token(extadr, value, 1, ';', sizeof extadr);
133 extract_token(street, value, 2, ';', sizeof street);
134 extract_token(city, value, 3, ';', sizeof city);
135 extract_token(state, value, 4, ';', sizeof state);
136 extract_token(zipcode, value, 5, ';', sizeof zipcode);
137 extract_token(country, value, 6, ';', sizeof country);
140 else if ( (!strcasecmp(key, "tel;home")) || (!strcasecmp(key, "tel;type=home")) ) {
141 extract_token(hometel, value, 0, ';', sizeof hometel);
144 else if ( (!strcasecmp(key, "tel;work")) || (!strcasecmp(key, "tel;type=work")) ) {
145 extract_token(worktel, value, 0, ';', sizeof worktel);
148 else if ( (!strcasecmp(key, "tel;fax")) || (!strcasecmp(key, "tel;type=fax")) ) {
149 extract_token(faxtel, value, 0, ';', sizeof faxtel);
152 else if ( (!strcasecmp(key, "tel;cell")) || (!strcasecmp(key, "tel;type=cell")) ) {
153 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
156 else if ( (!strcasecmp(key, "email;internet"))
157 || (!strcasecmp(key, "email;type=internet")) ) {
158 if (primary_inetemail[0] == 0) {
159 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
162 if (other_inetemail[0] != 0) {
163 strcat(other_inetemail, "\n");
165 strcat(other_inetemail, value);
170 strcat(extrafields, key);
171 strcat(extrafields, ":");
172 strcat(extrafields, value);
173 strcat(extrafields, "\n");
181 /** Display the form */
182 output_headers(1, 1, 1, 0, 0, 0);
184 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
185 do_template("beginbox", NULL);
187 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
188 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
190 if (force_room != NULL) {
191 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
196 wprintf("<div class=\"fix_scrollbar_bug\">"
197 "<table class=\"vcard_edit_background\"><tr><td>\n");
199 wprintf("<table border=0><tr>"
204 "<td>%s</td></tr>\n",
205 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
207 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
208 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
210 wprintf("<td><input type=\"text\" name=\"firstname\" "
211 "value=\"%s\" maxlength=\"29\"></td>",
213 wprintf("<td><input type=\"text\" name=\"middlename\" "
214 "value=\"%s\" maxlength=\"29\"></td>",
216 wprintf("<td><input type=\"text\" name=\"lastname\" "
217 "value=\"%s\" maxlength=\"29\"></td>",
219 wprintf("<td><input type=\"text\" name=\"suffix\" "
220 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
223 wprintf("<table class=\"vcard_edit_background_alt\">");
226 wprintf(_("Display name:"));
228 "<input type=\"text\" name=\"fullname\" "
229 "value=\"%s\" maxlength=\"40\"><br><br>\n",
233 wprintf(_("Title:"));
235 "<input type=\"text\" name=\"title\" "
236 "value=\"%s\" maxlength=\"40\"><br><br>\n",
240 wprintf(_("Organization:"));
242 "<input type=\"text\" name=\"org\" "
243 "value=\"%s\" maxlength=\"40\"><br><br>\n",
247 wprintf("</td><td>");
249 wprintf("<table border=0>");
251 wprintf(_("PO box:"));
253 "<input type=\"text\" name=\"pobox\" "
254 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
257 wprintf(_("Address:"));
259 "<input type=\"text\" name=\"extadr\" "
260 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
262 wprintf("<tr><td> </td><td>"
263 "<input type=\"text\" name=\"street\" "
264 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
269 "<input type=\"text\" name=\"city\" "
270 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
273 wprintf(_("State:"));
275 "<input type=\"text\" name=\"state\" "
276 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
279 wprintf(_("ZIP code:"));
281 "<input type=\"text\" name=\"zipcode\" "
282 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
285 wprintf(_("Country:"));
287 "<input type=\"text\" name=\"country\" "
288 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
290 wprintf("</table>\n");
292 wprintf("</table>\n");
294 wprintf("<table border=0><tr><td>");
295 wprintf(_("Home telephone:"));
297 "<td><input type=\"text\" name=\"hometel\" "
298 "value=\"%s\" maxlength=\"29\"></td>\n",
301 wprintf(_("Work telephone:"));
303 "<td><input type=\"text\" name=\"worktel\" "
304 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
307 wprintf(_("Mobile telephone:"));
309 "<td><input type=\"text\" name=\"mobiletel\" "
310 "value=\"%s\" maxlength=\"29\"></td>\n",
313 wprintf(_("Fax number:"));
315 "<td><input type=\"text\" name=\"faxtel\" "
316 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
319 wprintf("<table class=\"vcard_edit_background_alt\">");
322 wprintf("<table border=0><TR>"
324 wprintf(_("Primary Internet e-mail address"));
326 "<input type=\"text\" name=\"primary_inetemail\" "
327 "size=40 maxlength=60 value=\"");
328 escputs(primary_inetemail);
330 "</td><td valign=top>");
331 wprintf(_("Internet e-mail aliases"));
333 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
334 escputs(other_inetemail);
335 wprintf("</textarea></td></tr></table>\n");
337 wprintf("</td></tr></table>\n");
339 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
340 escputs(extrafields);
343 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
344 urlescputs(return_to);
347 wprintf("<div class=\"buttons\">\n"
348 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
350 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
356 wprintf("</td></tr></table>\n");
357 do_template("endbox", NULL);
363 * commit the edits to the citadel server
365 void edit_vcard(void) {
369 msgnum = lbstr("msgnum");
370 partnum = bstr("partnum");
371 do_edit_vcard(msgnum, partnum, "", NULL);
377 * parse edited vcard from the browser
379 void submit_vcard(void) {
381 char *serialized_vcard;
385 if (!havebstr("ok_button")) {
390 if (havebstr("force_room")) {
391 gotoroom(bstr("force_room"));
394 sprintf(buf, "ENT0 1|||4||");
396 serv_getln(buf, sizeof buf);
402 /** Make a vCard structure out of the data supplied in the form */
404 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
407 v = vcard_load(buf); /** Start with the extra fields */
409 safestrncpy(WC->ImportantMessage,
410 _("An error has occurred."),
411 sizeof WC->ImportantMessage
417 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
423 vcard_add_prop(v, "n", buf);
425 vcard_add_prop(v, "title", bstr("title"));
426 vcard_add_prop(v, "fn", bstr("fullname"));
427 vcard_add_prop(v, "org", bstr("org"));
429 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
437 vcard_add_prop(v, "adr", buf);
439 vcard_add_prop(v, "tel;home", bstr("hometel"));
440 vcard_add_prop(v, "tel;work", bstr("worktel"));
441 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
442 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
443 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
445 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
446 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
447 if (!IsEmptyStr(buf)) {
448 vcard_add_prop(v, "email;internet", buf);
452 serialized_vcard = vcard_serialize(v);
454 if (serialized_vcard == NULL) {
455 safestrncpy(WC->ImportantMessage,
456 _("An error has occurred."),
457 sizeof WC->ImportantMessage
463 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
465 serv_printf("%s\r\n", serialized_vcard);
467 free(serialized_vcard);
469 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
470 select_user_to_edit(NULL, NULL);
472 else if (!strcmp(bstr("return_to"), "do_welcome")) {
486 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
487 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);