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) {
23 char *serialized_vcard = NULL;
44 char primary_inetemail[256];
45 char other_inetemail[SIZ];
46 char extrafields[SIZ];
65 primary_inetemail[0] = 0;
66 other_inetemail[0] = 0;
72 safestrncpy(whatuser, "", sizeof whatuser);
75 sprintf(buf, "MSG0 %ld|1", msgnum);
77 serv_getln(buf, sizeof buf);
79 convenience_page("770000", _("Error"), &buf[4]);
82 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
83 if (!strncasecmp(buf, "from=", 5)) {
84 safestrncpy(whatuser, &buf[5], sizeof whatuser);
86 else if (!strncasecmp(buf, "node=", 5)) {
87 strcat(whatuser, " @ ");
88 strcat(whatuser, &buf[5]);
92 sprintf(buf, "OPNA %ld|%s", msgnum, partnum);
94 serv_getln(buf, sizeof buf);
96 convenience_page("770000", "Error", &buf[4]);
100 total_len = atoi(&buf[4]);
101 serialized_vcard = malloc(total_len + 2);
103 read_server_binary(serialized_vcard, total_len);
106 serv_getln(buf, sizeof buf);
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, "email;internet")) {
156 if (primary_inetemail[0] == 0) {
157 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
160 if (other_inetemail[0] != 0) {
161 strcat(other_inetemail, "\n");
163 strcat(other_inetemail, value);
168 strcat(extrafields, key);
169 strcat(extrafields, ":");
170 strcat(extrafields, value);
171 strcat(extrafields, "\n");
179 /** Display the form */
180 output_headers(1, 1, 2, 0, 0, 0);
181 wprintf("<div id=\"banner\">\n"
182 "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>"
183 "<span class=\"titlebar\">"
184 "<img src=\"static/savecontact_48x.gif\">");
185 wprintf(_("Edit contact information"));
187 "</td></tr></table>\n"
188 "</div>\n<div id=\"content\">\n"
191 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
192 wprintf("<div class=\"fix_scrollbar_bug\">"
193 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
195 wprintf("<table border=0><tr>"
200 "<td>%s</td></tr>\n",
201 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
203 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
204 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
206 wprintf("<td><input type=\"text\" name=\"firstname\" "
207 "value=\"%s\" maxlength=\"29\"></td>",
209 wprintf("<td><input type=\"text\" name=\"middlename\" "
210 "value=\"%s\" maxlength=\"29\"></td>",
212 wprintf("<td><input type=\"text\" name=\"lastname\" "
213 "value=\"%s\" maxlength=\"29\"></td>",
215 wprintf("<td><input type=\"text\" name=\"suffix\" "
216 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
219 wprintf("<table border=0 width=100%% bgcolor=\"#dddddd\">");
222 wprintf(_("Display name:"));
224 "<input type=\"text\" name=\"fullname\" "
225 "value=\"%s\" maxlength=\"40\"><br><br>\n",
229 wprintf(_("Title:"));
231 "<input type=\"text\" name=\"title\" "
232 "value=\"%s\" maxlength=\"40\"><br><br>\n",
236 wprintf(_("Organization:"));
238 "<input type=\"text\" name=\"org\" "
239 "value=\"%s\" maxlength=\"40\"><br><br>\n",
243 wprintf("</td><td>");
245 wprintf("<table border=0>");
247 wprintf(_("PO box:"));
249 "<input type=\"text\" name=\"pobox\" "
250 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
253 wprintf(_("Address:"));
255 "<input type=\"text\" name=\"extadr\" "
256 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
258 wprintf("<tr><td> </td><td>"
259 "<input type=\"text\" name=\"street\" "
260 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
265 "<input type=\"text\" name=\"city\" "
266 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
269 wprintf(_("State:"));
271 "<input type=\"text\" name=\"state\" "
272 "value=\"%s\" maxlength=\"2\"></td></tr>\n",
275 wprintf(_("ZIP code:"));
277 "<input type=\"text\" name=\"zipcode\" "
278 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
281 wprintf(_("Country:"));
283 "<input type=\"text\" name=\"country\" "
284 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
286 wprintf("</table>\n");
288 wprintf("</table>\n");
290 wprintf("<table border=0><tr><td>");
291 wprintf(_("Home telephone:"));
293 "<td><input type=\"text\" name=\"hometel\" "
294 "value=\"%s\" maxlength=\"29\"></td>\n",
297 wprintf(_("Work telephone:"));
299 "<td><input type=\"text\" name=\"worktel\" "
300 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
303 wprintf("<table border=0 width=100%% bgcolor=\"#dddddd\">");
306 wprintf("<table border=0><TR>"
308 wprintf(_("Primary Internet e-mail address"));
310 "<input type=\"text\" name=\"primary_inetemail\" "
311 "size=40 maxlength=40 value=\"");
312 escputs(primary_inetemail);
314 "</td><td valign=top>");
315 wprintf(_("Internet e-mail aliases"));
317 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
318 escputs(other_inetemail);
319 wprintf("</textarea></td></tr></table>\n");
321 wprintf("</td></tr></table>\n");
323 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
324 escputs(extrafields);
327 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
328 urlescputs(return_to);
332 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
334 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
335 "</center></form>\n",
340 wprintf("</td></tr></table></div>\n");
346 * \brief commit the edits to the citadel server
348 void edit_vcard(void) {
352 msgnum = atol(bstr("msgnum"));
353 partnum = bstr("partnum");
354 do_edit_vcard(msgnum, partnum, "");
360 * \brief parse edited vcard from the browser
362 void submit_vcard(void) {
364 char *serialized_vcard;
368 if (strlen(bstr("ok_button")) == 0) {
373 sprintf(buf, "ENT0 1|||4||");
375 serv_getln(buf, sizeof buf);
381 /** Make a vCard structure out of the data supplied in the form */
383 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
386 v = vcard_load(buf); /** Start with the extra fields */
388 safestrncpy(WC->ImportantMessage,
389 _("An error has occurred."),
390 sizeof WC->ImportantMessage
396 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
402 vcard_add_prop(v, "n", buf);
404 vcard_add_prop(v, "title", bstr("title"));
405 vcard_add_prop(v, "fn", bstr("fullname"));
406 vcard_add_prop(v, "org", bstr("org"));
408 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
416 vcard_add_prop(v, "adr", buf);
418 vcard_add_prop(v, "tel;home", bstr("hometel"));
419 vcard_add_prop(v, "tel;work", bstr("worktel"));
420 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
422 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
423 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
424 if (strlen(buf) > 0) {
425 vcard_add_prop(v, "email;internet", buf);
429 serialized_vcard = vcard_serialize(v);
431 if (serialized_vcard == NULL) {
432 safestrncpy(WC->ImportantMessage,
433 _("An error has occurred."),
434 sizeof WC->ImportantMessage
440 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
442 serv_printf("%s\r\n", serialized_vcard);
444 free(serialized_vcard);
446 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
447 select_user_to_edit(NULL, NULL);
449 else if (!strcmp(bstr("return_to"), "do_welcome")) {