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;
45 char primary_inetemail[256];
46 char other_inetemail[SIZ];
47 char extrafields[SIZ];
67 primary_inetemail[0] = 0;
68 other_inetemail[0] = 0;
74 safestrncpy(whatuser, "", sizeof whatuser);
77 sprintf(buf, "MSG0 %ld|1", msgnum);
79 serv_getln(buf, sizeof buf);
81 convenience_page("770000", _("Error"), &buf[4]);
84 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
85 if (!strncasecmp(buf, "from=", 5)) {
86 safestrncpy(whatuser, &buf[5], sizeof whatuser);
88 else if (!strncasecmp(buf, "node=", 5)) {
89 strcat(whatuser, " @ ");
90 strcat(whatuser, &buf[5]);
94 sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
96 serv_getln(buf, sizeof buf);
98 convenience_page("770000", "Error", &buf[4]);
102 total_len = atoi(&buf[4]);
103 serialized_vcard = malloc(total_len + 2);
105 serv_read(serialized_vcard, total_len);
106 serialized_vcard[total_len] = 0;
108 v = vcard_load(serialized_vcard);
109 free(serialized_vcard);
111 /* Populate the variables for our form */
113 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
114 value = vcard_get_prop(v, "", 0, i++, 0);
116 if (!strcasecmp(key, "n")) {
117 extract_token(lastname, value, 0, ';', sizeof lastname);
118 extract_token(firstname, value, 1, ';', sizeof firstname);
119 extract_token(middlename, value, 2, ';', sizeof middlename);
120 extract_token(prefix, value, 3, ';', sizeof prefix);
121 extract_token(suffix, value, 4, ';', sizeof suffix);
124 else if (!strcasecmp(key, "fn")) {
125 safestrncpy(fullname, value, sizeof fullname);
128 else if (!strcasecmp(key, "title")) {
129 safestrncpy(title, value, sizeof title);
132 else if (!strcasecmp(key, "org")) {
133 safestrncpy(org, value, sizeof org);
136 else if (!strcasecmp(key, "adr")) {
137 extract_token(pobox, value, 0, ';', sizeof pobox);
138 extract_token(extadr, value, 1, ';', sizeof extadr);
139 extract_token(street, value, 2, ';', sizeof street);
140 extract_token(city, value, 3, ';', sizeof city);
141 extract_token(state, value, 4, ';', sizeof state);
142 extract_token(zipcode, value, 5, ';', sizeof zipcode);
143 extract_token(country, value, 6, ';', sizeof country);
146 else if (!strcasecmp(key, "tel;home")) {
147 extract_token(hometel, value, 0, ';', sizeof hometel);
150 else if (!strcasecmp(key, "tel;work")) {
151 extract_token(worktel, value, 0, ';', sizeof worktel);
154 else if (!strcasecmp(key, "tel;fax")) {
155 extract_token(faxtel, value, 0, ';', sizeof faxtel);
158 else if (!strcasecmp(key, "email;internet")) {
159 if (primary_inetemail[0] == 0) {
160 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
163 if (other_inetemail[0] != 0) {
164 strcat(other_inetemail, "\n");
166 strcat(other_inetemail, value);
171 strcat(extrafields, key);
172 strcat(extrafields, ":");
173 strcat(extrafields, value);
174 strcat(extrafields, "\n");
182 /** Display the form */
183 output_headers(1, 1, 1, 0, 0, 0);
185 svprintf("BOXTITLE", WCS_STRING, _("Edit contact information"));
186 do_template("beginbox");
188 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
189 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
191 if (force_room != NULL) {
192 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
197 wprintf("<div class=\"fix_scrollbar_bug\">"
198 "<table class=\"vcard_edit_background\"><tr><td>\n");
200 wprintf("<table border=0><tr>"
205 "<td>%s</td></tr>\n",
206 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
208 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
209 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
211 wprintf("<td><input type=\"text\" name=\"firstname\" "
212 "value=\"%s\" maxlength=\"29\"></td>",
214 wprintf("<td><input type=\"text\" name=\"middlename\" "
215 "value=\"%s\" maxlength=\"29\"></td>",
217 wprintf("<td><input type=\"text\" name=\"lastname\" "
218 "value=\"%s\" maxlength=\"29\"></td>",
220 wprintf("<td><input type=\"text\" name=\"suffix\" "
221 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
224 wprintf("<table class=\"vcard_edit_background_alt\">");
227 wprintf(_("Display name:"));
229 "<input type=\"text\" name=\"fullname\" "
230 "value=\"%s\" maxlength=\"40\"><br><br>\n",
234 wprintf(_("Title:"));
236 "<input type=\"text\" name=\"title\" "
237 "value=\"%s\" maxlength=\"40\"><br><br>\n",
241 wprintf(_("Organization:"));
243 "<input type=\"text\" name=\"org\" "
244 "value=\"%s\" maxlength=\"40\"><br><br>\n",
248 wprintf("</td><td>");
250 wprintf("<table border=0>");
252 wprintf(_("PO box:"));
254 "<input type=\"text\" name=\"pobox\" "
255 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
258 wprintf(_("Address:"));
260 "<input type=\"text\" name=\"extadr\" "
261 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
263 wprintf("<tr><td> </td><td>"
264 "<input type=\"text\" name=\"street\" "
265 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
270 "<input type=\"text\" name=\"city\" "
271 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
274 wprintf(_("State:"));
276 "<input type=\"text\" name=\"state\" "
277 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
280 wprintf(_("ZIP code:"));
282 "<input type=\"text\" name=\"zipcode\" "
283 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
286 wprintf(_("Country:"));
288 "<input type=\"text\" name=\"country\" "
289 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
291 wprintf("</table>\n");
293 wprintf("</table>\n");
295 wprintf("<table border=0><tr><td>");
296 wprintf(_("Home telephone:"));
298 "<td><input type=\"text\" name=\"hometel\" "
299 "value=\"%s\" maxlength=\"29\"></td>\n",
302 wprintf(_("Work telephone:"));
304 "<td><input type=\"text\" name=\"worktel\" "
305 "value=\"%s\" maxlength=\"29\"></td>\n",
308 wprintf(_("Fax number:"));
310 "<td><input type=\"text\" name=\"faxtel\" "
311 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
314 wprintf("<table class=\"vcard_edit_background_alt\">");
317 wprintf("<table border=0><TR>"
319 wprintf(_("Primary Internet e-mail address"));
321 "<input type=\"text\" name=\"primary_inetemail\" "
322 "size=40 maxlength=60 value=\"");
323 escputs(primary_inetemail);
325 "</td><td valign=top>");
326 wprintf(_("Internet e-mail aliases"));
328 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
329 escputs(other_inetemail);
330 wprintf("</textarea></td></tr></table>\n");
332 wprintf("</td></tr></table>\n");
334 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
335 escputs(extrafields);
338 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
339 urlescputs(return_to);
342 wprintf("<div class=\"buttons\">\n"
343 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
345 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
351 wprintf("</td></tr></table>\n");
352 do_template("endbox");
358 * \brief commit the edits to the citadel server
360 void edit_vcard(void) {
364 msgnum = atol(bstr("msgnum"));
365 partnum = bstr("partnum");
366 do_edit_vcard(msgnum, partnum, "", NULL);
372 * \brief parse edited vcard from the browser
374 void submit_vcard(void) {
376 char *serialized_vcard;
380 if (IsEmptyStr(bstr("ok_button"))) {
385 if (!IsEmptyStr(bstr("force_room"))) {
386 gotoroom(bstr("force_room"));
389 sprintf(buf, "ENT0 1|||4||");
391 serv_getln(buf, sizeof buf);
397 /** Make a vCard structure out of the data supplied in the form */
399 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
402 v = vcard_load(buf); /** Start with the extra fields */
404 safestrncpy(WC->ImportantMessage,
405 _("An error has occurred."),
406 sizeof WC->ImportantMessage
412 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
418 vcard_add_prop(v, "n", buf);
420 vcard_add_prop(v, "title", bstr("title"));
421 vcard_add_prop(v, "fn", bstr("fullname"));
422 vcard_add_prop(v, "org", bstr("org"));
424 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
432 vcard_add_prop(v, "adr", buf);
434 vcard_add_prop(v, "tel;home", bstr("hometel"));
435 vcard_add_prop(v, "tel;work", bstr("worktel"));
436 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
437 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
439 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
440 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
441 if (!IsEmptyStr(buf)) {
442 vcard_add_prop(v, "email;internet", buf);
446 serialized_vcard = vcard_serialize(v);
448 if (serialized_vcard == NULL) {
449 safestrncpy(WC->ImportantMessage,
450 _("An error has occurred."),
451 sizeof WC->ImportantMessage
457 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
459 serv_printf("%s\r\n", serialized_vcard);
461 free(serialized_vcard);
463 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
464 select_user_to_edit(NULL, NULL);
466 else if (!strcmp(bstr("return_to"), "do_welcome")) {