5 * \defgroup vCardEdit Handles on-screen editing of vCard objects.
12 * \brief Edit the vCard component of a MIME message.
13 * Supply the message number
14 * and MIME part number to fetch. Or, specify -1 for the message number
15 * to start with a blank card.
16 * \param msgnum number of the item on the citadel server
17 * \param partnum what???
18 * \param return_to where to go back in the browser after edit ????
20 void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
22 char *serialized_vcard = NULL;
45 char primary_inetemail[256];
46 char other_inetemail[SIZ];
47 char extrafields[SIZ];
68 primary_inetemail[0] = 0;
69 other_inetemail[0] = 0;
75 safestrncpy(whatuser, "", sizeof whatuser);
78 sprintf(buf, "MSG0 %ld|1", msgnum);
80 serv_getln(buf, sizeof buf);
82 convenience_page("770000", _("Error"), &buf[4]);
85 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
86 if (!strncasecmp(buf, "from=", 5)) {
87 safestrncpy(whatuser, &buf[5], sizeof whatuser);
89 else if (!strncasecmp(buf, "node=", 5)) {
90 strcat(whatuser, " @ ");
91 strcat(whatuser, &buf[5]);
95 sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
97 serv_getln(buf, sizeof buf);
99 convenience_page("770000", "Error", &buf[4]);
103 total_len = atoi(&buf[4]);
104 serialized_vcard = malloc(total_len + 2);
106 serv_read(serialized_vcard, total_len);
107 serialized_vcard[total_len] = 0;
109 v = vcard_load(serialized_vcard);
110 free(serialized_vcard);
112 /* Populate the variables for our form */
114 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
115 value = vcard_get_prop(v, "", 0, i++, 0);
117 if (!strcasecmp(key, "n")) {
118 extract_token(lastname, value, 0, ';', sizeof lastname);
119 extract_token(firstname, value, 1, ';', sizeof firstname);
120 extract_token(middlename, value, 2, ';', sizeof middlename);
121 extract_token(prefix, value, 3, ';', sizeof prefix);
122 extract_token(suffix, value, 4, ';', sizeof suffix);
125 else if (!strcasecmp(key, "fn")) {
126 safestrncpy(fullname, value, sizeof fullname);
129 else if (!strcasecmp(key, "title")) {
130 safestrncpy(title, value, sizeof title);
133 else if (!strcasecmp(key, "org")) {
134 safestrncpy(org, value, sizeof org);
137 else if (!strcasecmp(key, "adr")) {
138 extract_token(pobox, value, 0, ';', sizeof pobox);
139 extract_token(extadr, value, 1, ';', sizeof extadr);
140 extract_token(street, value, 2, ';', sizeof street);
141 extract_token(city, value, 3, ';', sizeof city);
142 extract_token(state, value, 4, ';', sizeof state);
143 extract_token(zipcode, value, 5, ';', sizeof zipcode);
144 extract_token(country, value, 6, ';', sizeof country);
147 else if (!strcasecmp(key, "tel;home")) {
148 extract_token(hometel, value, 0, ';', sizeof hometel);
151 else if (!strcasecmp(key, "tel;work")) {
152 extract_token(worktel, value, 0, ';', sizeof worktel);
155 else if (!strcasecmp(key, "tel;fax")) {
156 extract_token(faxtel, value, 0, ';', sizeof faxtel);
159 else if (!strcasecmp(key, "tel;cell")) {
160 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
163 else if (!strcasecmp(key, "email;internet")) {
164 if (primary_inetemail[0] == 0) {
165 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
168 if (other_inetemail[0] != 0) {
169 strcat(other_inetemail, "\n");
171 strcat(other_inetemail, value);
176 strcat(extrafields, key);
177 strcat(extrafields, ":");
178 strcat(extrafields, value);
179 strcat(extrafields, "\n");
187 /** Display the form */
188 output_headers(1, 1, 1, 0, 0, 0);
190 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
191 do_template("beginbox");
193 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
194 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
196 if (force_room != NULL) {
197 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
202 wprintf("<div class=\"fix_scrollbar_bug\">"
203 "<table class=\"vcard_edit_background\"><tr><td>\n");
205 wprintf("<table border=0><tr>"
210 "<td>%s</td></tr>\n",
211 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
213 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
214 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
216 wprintf("<td><input type=\"text\" name=\"firstname\" "
217 "value=\"%s\" maxlength=\"29\"></td>",
219 wprintf("<td><input type=\"text\" name=\"middlename\" "
220 "value=\"%s\" maxlength=\"29\"></td>",
222 wprintf("<td><input type=\"text\" name=\"lastname\" "
223 "value=\"%s\" maxlength=\"29\"></td>",
225 wprintf("<td><input type=\"text\" name=\"suffix\" "
226 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
229 wprintf("<table class=\"vcard_edit_background_alt\">");
232 wprintf(_("Display name:"));
234 "<input type=\"text\" name=\"fullname\" "
235 "value=\"%s\" maxlength=\"40\"><br><br>\n",
239 wprintf(_("Title:"));
241 "<input type=\"text\" name=\"title\" "
242 "value=\"%s\" maxlength=\"40\"><br><br>\n",
246 wprintf(_("Organization:"));
248 "<input type=\"text\" name=\"org\" "
249 "value=\"%s\" maxlength=\"40\"><br><br>\n",
253 wprintf("</td><td>");
255 wprintf("<table border=0>");
257 wprintf(_("PO box:"));
259 "<input type=\"text\" name=\"pobox\" "
260 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
263 wprintf(_("Address:"));
265 "<input type=\"text\" name=\"extadr\" "
266 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
268 wprintf("<tr><td> </td><td>"
269 "<input type=\"text\" name=\"street\" "
270 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
275 "<input type=\"text\" name=\"city\" "
276 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
279 wprintf(_("State:"));
281 "<input type=\"text\" name=\"state\" "
282 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
285 wprintf(_("ZIP code:"));
287 "<input type=\"text\" name=\"zipcode\" "
288 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
291 wprintf(_("Country:"));
293 "<input type=\"text\" name=\"country\" "
294 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
296 wprintf("</table>\n");
298 wprintf("</table>\n");
300 wprintf("<table border=0><tr><td>");
301 wprintf(_("Home telephone:"));
303 "<td><input type=\"text\" name=\"hometel\" "
304 "value=\"%s\" maxlength=\"29\"></td>\n",
307 wprintf(_("Work telephone:"));
309 "<td><input type=\"text\" name=\"worktel\" "
310 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
313 wprintf(_("Mobile telephone:"));
315 "<td><input type=\"text\" name=\"mobiletel\" "
316 "value=\"%s\" maxlength=\"29\"></td>\n",
319 wprintf(_("Fax number:"));
321 "<td><input type=\"text\" name=\"faxtel\" "
322 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
325 wprintf("<table class=\"vcard_edit_background_alt\">");
328 wprintf("<table border=0><TR>"
330 wprintf(_("Primary Internet e-mail address"));
332 "<input type=\"text\" name=\"primary_inetemail\" "
333 "size=40 maxlength=60 value=\"");
334 escputs(primary_inetemail);
336 "</td><td valign=top>");
337 wprintf(_("Internet e-mail aliases"));
339 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
340 escputs(other_inetemail);
341 wprintf("</textarea></td></tr></table>\n");
343 wprintf("</td></tr></table>\n");
345 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
346 escputs(extrafields);
349 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
350 urlescputs(return_to);
353 wprintf("<div class=\"buttons\">\n"
354 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
356 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
362 wprintf("</td></tr></table>\n");
363 do_template("endbox");
369 * \brief commit the edits to the citadel server
371 void edit_vcard(void) {
375 msgnum = lbstr("msgnum");
376 partnum = bstr("partnum");
377 do_edit_vcard(msgnum, partnum, "", NULL);
383 * \brief parse edited vcard from the browser
385 void submit_vcard(void) {
387 char *serialized_vcard;
391 if (!havebstr("ok_button")) {
396 if (havebstr("force_room")) {
397 gotoroom(bstr("force_room"));
400 sprintf(buf, "ENT0 1|||4||");
402 serv_getln(buf, sizeof buf);
408 /** Make a vCard structure out of the data supplied in the form */
410 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
413 v = vcard_load(buf); /** Start with the extra fields */
415 safestrncpy(WC->ImportantMessage,
416 _("An error has occurred."),
417 sizeof WC->ImportantMessage
423 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
429 vcard_add_prop(v, "n", buf);
431 vcard_add_prop(v, "title", bstr("title"));
432 vcard_add_prop(v, "fn", bstr("fullname"));
433 vcard_add_prop(v, "org", bstr("org"));
435 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
443 vcard_add_prop(v, "adr", buf);
445 vcard_add_prop(v, "tel;home", bstr("hometel"));
446 vcard_add_prop(v, "tel;work", bstr("worktel"));
447 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
448 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
449 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
451 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
452 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
453 if (!IsEmptyStr(buf)) {
454 vcard_add_prop(v, "email;internet", buf);
458 serialized_vcard = vcard_serialize(v);
460 if (serialized_vcard == NULL) {
461 safestrncpy(WC->ImportantMessage,
462 _("An error has occurred."),
463 sizeof WC->ImportantMessage
469 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
471 serv_printf("%s\r\n", serialized_vcard);
473 free(serialized_vcard);
475 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
476 select_user_to_edit(NULL, NULL);
478 else if (!strcmp(bstr("return_to"), "do_welcome")) {
492 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
493 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);