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")) || (!strncasecmp(key, "adr;", 4)) ) {
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")) || (!strcasecmp(key, "tel;type=home")) ) {
148 extract_token(hometel, value, 0, ';', sizeof hometel);
151 else if ( (!strcasecmp(key, "tel;work")) || (!strcasecmp(key, "tel;type=work")) ) {
152 extract_token(worktel, value, 0, ';', sizeof worktel);
155 else if ( (!strcasecmp(key, "tel;fax")) || (!strcasecmp(key, "tel;type=fax")) ) {
156 extract_token(faxtel, value, 0, ';', sizeof faxtel);
159 else if ( (!strcasecmp(key, "tel;cell")) || (!strcasecmp(key, "tel;type=cell")) ) {
160 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
163 else if ( (!strcasecmp(key, "email;internet"))
164 || (!strcasecmp(key, "email;type=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 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
192 do_template("beginbox", NULL);
194 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
195 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\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", NULL);
370 * \brief commit the edits to the citadel server
372 void edit_vcard(void) {
376 msgnum = lbstr("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 (!havebstr("ok_button")) {
397 if (havebstr("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")) {
493 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
494 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);