5 * \defgroup vCardEdit Handles on-screen editing of vCard objects.
13 * \brief Edit the vCard component of a MIME message.
14 * Supply the message number
15 * and MIME part number to fetch. Or, specify -1 for the message number
16 * to start with a blank card.
17 * \param msgnum number of the item on the citadel server
18 * \param partnum what???
19 * \param return_to where to go back in the browser after edit ????
21 void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
23 char *serialized_vcard = NULL;
46 char primary_inetemail[256];
47 char other_inetemail[SIZ];
48 char extrafields[SIZ];
69 primary_inetemail[0] = 0;
70 other_inetemail[0] = 0;
76 safestrncpy(whatuser, "", sizeof whatuser);
79 sprintf(buf, "MSG0 %ld|1", msgnum);
81 serv_getln(buf, sizeof buf);
83 convenience_page("770000", _("Error"), &buf[4]);
86 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
87 if (!strncasecmp(buf, "from=", 5)) {
88 safestrncpy(whatuser, &buf[5], sizeof whatuser);
90 else if (!strncasecmp(buf, "node=", 5)) {
91 strcat(whatuser, " @ ");
92 strcat(whatuser, &buf[5]);
96 sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
98 serv_getln(buf, sizeof buf);
100 convenience_page("770000", "Error", &buf[4]);
104 total_len = atoi(&buf[4]);
105 serialized_vcard = malloc(total_len + 2);
107 serv_read(serialized_vcard, total_len);
108 serialized_vcard[total_len] = 0;
110 v = vcard_load(serialized_vcard);
111 free(serialized_vcard);
113 /* Populate the variables for our form */
115 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
116 value = vcard_get_prop(v, "", 0, i++, 0);
118 if (!strcasecmp(key, "n")) {
119 extract_token(lastname, value, 0, ';', sizeof lastname);
120 extract_token(firstname, value, 1, ';', sizeof firstname);
121 extract_token(middlename, value, 2, ';', sizeof middlename);
122 extract_token(prefix, value, 3, ';', sizeof prefix);
123 extract_token(suffix, value, 4, ';', sizeof suffix);
126 else if (!strcasecmp(key, "fn")) {
127 safestrncpy(fullname, value, sizeof fullname);
130 else if (!strcasecmp(key, "title")) {
131 safestrncpy(title, value, sizeof title);
134 else if (!strcasecmp(key, "org")) {
135 safestrncpy(org, value, sizeof org);
138 else if (!strcasecmp(key, "adr")) {
139 extract_token(pobox, value, 0, ';', sizeof pobox);
140 extract_token(extadr, value, 1, ';', sizeof extadr);
141 extract_token(street, value, 2, ';', sizeof street);
142 extract_token(city, value, 3, ';', sizeof city);
143 extract_token(state, value, 4, ';', sizeof state);
144 extract_token(zipcode, value, 5, ';', sizeof zipcode);
145 extract_token(country, value, 6, ';', sizeof country);
148 else if (!strcasecmp(key, "tel;home")) {
149 extract_token(hometel, value, 0, ';', sizeof hometel);
152 else if (!strcasecmp(key, "tel;work")) {
153 extract_token(worktel, value, 0, ';', sizeof worktel);
156 else if (!strcasecmp(key, "tel;fax")) {
157 extract_token(faxtel, value, 0, ';', sizeof faxtel);
160 else if (!strcasecmp(key, "tel;cell")) {
161 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
164 else if (!strcasecmp(key, "email;internet")) {
165 if (primary_inetemail[0] == 0) {
166 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
169 if (other_inetemail[0] != 0) {
170 strcat(other_inetemail, "\n");
172 strcat(other_inetemail, value);
177 strcat(extrafields, key);
178 strcat(extrafields, ":");
179 strcat(extrafields, value);
180 strcat(extrafields, "\n");
188 /** Display the form */
189 output_headers(1, 1, 1, 0, 0, 0);
191 svprintf("BOXTITLE", WCS_STRING, _("Edit contact information"));
192 do_template("beginbox");
194 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
195 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
197 if (force_room != NULL) {
198 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
203 wprintf("<div class=\"fix_scrollbar_bug\">"
204 "<table class=\"vcard_edit_background\"><tr><td>\n");
206 wprintf("<table border=0><tr>"
211 "<td>%s</td></tr>\n",
212 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
214 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
215 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
217 wprintf("<td><input type=\"text\" name=\"firstname\" "
218 "value=\"%s\" maxlength=\"29\"></td>",
220 wprintf("<td><input type=\"text\" name=\"middlename\" "
221 "value=\"%s\" maxlength=\"29\"></td>",
223 wprintf("<td><input type=\"text\" name=\"lastname\" "
224 "value=\"%s\" maxlength=\"29\"></td>",
226 wprintf("<td><input type=\"text\" name=\"suffix\" "
227 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
230 wprintf("<table class=\"vcard_edit_background_alt\">");
233 wprintf(_("Display name:"));
235 "<input type=\"text\" name=\"fullname\" "
236 "value=\"%s\" maxlength=\"40\"><br><br>\n",
240 wprintf(_("Title:"));
242 "<input type=\"text\" name=\"title\" "
243 "value=\"%s\" maxlength=\"40\"><br><br>\n",
247 wprintf(_("Organization:"));
249 "<input type=\"text\" name=\"org\" "
250 "value=\"%s\" maxlength=\"40\"><br><br>\n",
254 wprintf("</td><td>");
256 wprintf("<table border=0>");
258 wprintf(_("PO box:"));
260 "<input type=\"text\" name=\"pobox\" "
261 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
264 wprintf(_("Address:"));
266 "<input type=\"text\" name=\"extadr\" "
267 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
269 wprintf("<tr><td> </td><td>"
270 "<input type=\"text\" name=\"street\" "
271 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
276 "<input type=\"text\" name=\"city\" "
277 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
280 wprintf(_("State:"));
282 "<input type=\"text\" name=\"state\" "
283 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
286 wprintf(_("ZIP code:"));
288 "<input type=\"text\" name=\"zipcode\" "
289 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
292 wprintf(_("Country:"));
294 "<input type=\"text\" name=\"country\" "
295 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
297 wprintf("</table>\n");
299 wprintf("</table>\n");
301 wprintf("<table border=0><tr><td>");
302 wprintf(_("Home telephone:"));
304 "<td><input type=\"text\" name=\"hometel\" "
305 "value=\"%s\" maxlength=\"29\"></td>\n",
308 wprintf(_("Work telephone:"));
310 "<td><input type=\"text\" name=\"worktel\" "
311 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
314 wprintf(_("Mobile telephone:"));
316 "<td><input type=\"text\" name=\"mobiletel\" "
317 "value=\"%s\" maxlength=\"29\"></td>\n",
320 wprintf(_("Fax number:"));
322 "<td><input type=\"text\" name=\"faxtel\" "
323 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
326 wprintf("<table class=\"vcard_edit_background_alt\">");
329 wprintf("<table border=0><TR>"
331 wprintf(_("Primary Internet e-mail address"));
333 "<input type=\"text\" name=\"primary_inetemail\" "
334 "size=40 maxlength=60 value=\"");
335 escputs(primary_inetemail);
337 "</td><td valign=top>");
338 wprintf(_("Internet e-mail aliases"));
340 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
341 escputs(other_inetemail);
342 wprintf("</textarea></td></tr></table>\n");
344 wprintf("</td></tr></table>\n");
346 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
347 escputs(extrafields);
350 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
351 urlescputs(return_to);
354 wprintf("<div class=\"buttons\">\n"
355 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
357 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
363 wprintf("</td></tr></table>\n");
364 do_template("endbox");
370 * \brief commit the edits to the citadel server
372 void edit_vcard(void) {
376 msgnum = atol(bstr("msgnum"));
377 partnum = bstr("partnum");
378 do_edit_vcard(msgnum, partnum, "", NULL);
384 * \brief parse edited vcard from the browser
386 void submit_vcard(void) {
388 char *serialized_vcard;
392 if (IsEmptyStr(bstr("ok_button"))) {
397 if (!IsEmptyStr(bstr("force_room"))) {
398 gotoroom(bstr("force_room"));
401 sprintf(buf, "ENT0 1|||4||");
403 serv_getln(buf, sizeof buf);
409 /** Make a vCard structure out of the data supplied in the form */
411 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
414 v = vcard_load(buf); /** Start with the extra fields */
416 safestrncpy(WC->ImportantMessage,
417 _("An error has occurred."),
418 sizeof WC->ImportantMessage
424 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
430 vcard_add_prop(v, "n", buf);
432 vcard_add_prop(v, "title", bstr("title"));
433 vcard_add_prop(v, "fn", bstr("fullname"));
434 vcard_add_prop(v, "org", bstr("org"));
436 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
444 vcard_add_prop(v, "adr", buf);
446 vcard_add_prop(v, "tel;home", bstr("hometel"));
447 vcard_add_prop(v, "tel;work", bstr("worktel"));
448 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
449 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
450 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
452 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
453 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
454 if (!IsEmptyStr(buf)) {
455 vcard_add_prop(v, "email;internet", buf);
459 serialized_vcard = vcard_serialize(v);
461 if (serialized_vcard == NULL) {
462 safestrncpy(WC->ImportantMessage,
463 _("An error has occurred."),
464 sizeof WC->ImportantMessage
470 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
472 serv_printf("%s\r\n", serialized_vcard);
474 free(serialized_vcard);
476 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
477 select_user_to_edit(NULL, NULL);
479 else if (!strcmp(bstr("return_to"), "do_welcome")) {