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;
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, "DLAT %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 serv_read(serialized_vcard, total_len);
104 serialized_vcard[total_len] = 0;
106 v = vcard_load(serialized_vcard);
107 free(serialized_vcard);
109 /* Populate the variables for our form */
111 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
112 value = vcard_get_prop(v, "", 0, i++, 0);
114 if (!strcasecmp(key, "n")) {
115 extract_token(lastname, value, 0, ';', sizeof lastname);
116 extract_token(firstname, value, 1, ';', sizeof firstname);
117 extract_token(middlename, value, 2, ';', sizeof middlename);
118 extract_token(prefix, value, 3, ';', sizeof prefix);
119 extract_token(suffix, value, 4, ';', sizeof suffix);
122 else if (!strcasecmp(key, "fn")) {
123 safestrncpy(fullname, value, sizeof fullname);
126 else if (!strcasecmp(key, "title")) {
127 safestrncpy(title, value, sizeof title);
130 else if (!strcasecmp(key, "org")) {
131 safestrncpy(org, value, sizeof org);
134 else if (!strcasecmp(key, "adr")) {
135 extract_token(pobox, value, 0, ';', sizeof pobox);
136 extract_token(extadr, value, 1, ';', sizeof extadr);
137 extract_token(street, value, 2, ';', sizeof street);
138 extract_token(city, value, 3, ';', sizeof city);
139 extract_token(state, value, 4, ';', sizeof state);
140 extract_token(zipcode, value, 5, ';', sizeof zipcode);
141 extract_token(country, value, 6, ';', sizeof country);
144 else if (!strcasecmp(key, "tel;home")) {
145 extract_token(hometel, value, 0, ';', sizeof hometel);
148 else if (!strcasecmp(key, "tel;work")) {
149 extract_token(worktel, value, 0, ';', sizeof worktel);
152 else if (!strcasecmp(key, "email;internet")) {
153 if (primary_inetemail[0] == 0) {
154 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
157 if (other_inetemail[0] != 0) {
158 strcat(other_inetemail, "\n");
160 strcat(other_inetemail, value);
165 strcat(extrafields, key);
166 strcat(extrafields, ":");
167 strcat(extrafields, value);
168 strcat(extrafields, "\n");
176 /** Display the form */
177 output_headers(1, 1, 1, 0, 0, 0);
179 svprintf("BOXTITLE", WCS_STRING, _("Edit contact information"));
180 do_template("beginbox");
182 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
183 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
185 if (force_room != NULL) {
186 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
191 wprintf("<div class=\"fix_scrollbar_bug\">"
192 "<table class=\"vcard_edit_background\"><tr><td>\n");
194 wprintf("<table border=0><tr>"
199 "<td>%s</td></tr>\n",
200 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
202 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
203 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
205 wprintf("<td><input type=\"text\" name=\"firstname\" "
206 "value=\"%s\" maxlength=\"29\"></td>",
208 wprintf("<td><input type=\"text\" name=\"middlename\" "
209 "value=\"%s\" maxlength=\"29\"></td>",
211 wprintf("<td><input type=\"text\" name=\"lastname\" "
212 "value=\"%s\" maxlength=\"29\"></td>",
214 wprintf("<td><input type=\"text\" name=\"suffix\" "
215 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
218 wprintf("<table class=\"vcard_edit_background_alt\">");
221 wprintf(_("Display name:"));
223 "<input type=\"text\" name=\"fullname\" "
224 "value=\"%s\" maxlength=\"40\"><br><br>\n",
228 wprintf(_("Title:"));
230 "<input type=\"text\" name=\"title\" "
231 "value=\"%s\" maxlength=\"40\"><br><br>\n",
235 wprintf(_("Organization:"));
237 "<input type=\"text\" name=\"org\" "
238 "value=\"%s\" maxlength=\"40\"><br><br>\n",
242 wprintf("</td><td>");
244 wprintf("<table border=0>");
246 wprintf(_("PO box:"));
248 "<input type=\"text\" name=\"pobox\" "
249 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
252 wprintf(_("Address:"));
254 "<input type=\"text\" name=\"extadr\" "
255 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
257 wprintf("<tr><td> </td><td>"
258 "<input type=\"text\" name=\"street\" "
259 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
264 "<input type=\"text\" name=\"city\" "
265 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
268 wprintf(_("State:"));
270 "<input type=\"text\" name=\"state\" "
271 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
274 wprintf(_("ZIP code:"));
276 "<input type=\"text\" name=\"zipcode\" "
277 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
280 wprintf(_("Country:"));
282 "<input type=\"text\" name=\"country\" "
283 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
285 wprintf("</table>\n");
287 wprintf("</table>\n");
289 wprintf("<table border=0><tr><td>");
290 wprintf(_("Home telephone:"));
292 "<td><input type=\"text\" name=\"hometel\" "
293 "value=\"%s\" maxlength=\"29\"></td>\n",
296 wprintf(_("Work telephone:"));
298 "<td><input type=\"text\" name=\"worktel\" "
299 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
302 wprintf("<table class=\"vcard_edit_background_alt\">");
305 wprintf("<table border=0><TR>"
307 wprintf(_("Primary Internet e-mail address"));
309 "<input type=\"text\" name=\"primary_inetemail\" "
310 "size=40 maxlength=60 value=\"");
311 escputs(primary_inetemail);
313 "</td><td valign=top>");
314 wprintf(_("Internet e-mail aliases"));
316 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
317 escputs(other_inetemail);
318 wprintf("</textarea></td></tr></table>\n");
320 wprintf("</td></tr></table>\n");
322 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
323 escputs(extrafields);
326 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
327 urlescputs(return_to);
330 wprintf("<div class=\"buttons\">\n"
331 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
333 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
339 wprintf("</td></tr></table>\n");
340 do_template("endbox");
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, "", NULL);
360 * \brief parse edited vcard from the browser
362 void submit_vcard(void) {
364 char *serialized_vcard;
368 if (IsEmptyStr(bstr("ok_button"))) {
373 if (!IsEmptyStr(bstr("force_room"))) {
374 gotoroom(bstr("force_room"));
377 sprintf(buf, "ENT0 1|||4||");
379 serv_getln(buf, sizeof buf);
385 /** Make a vCard structure out of the data supplied in the form */
387 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
390 v = vcard_load(buf); /** Start with the extra fields */
392 safestrncpy(WC->ImportantMessage,
393 _("An error has occurred."),
394 sizeof WC->ImportantMessage
400 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
406 vcard_add_prop(v, "n", buf);
408 vcard_add_prop(v, "title", bstr("title"));
409 vcard_add_prop(v, "fn", bstr("fullname"));
410 vcard_add_prop(v, "org", bstr("org"));
412 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
420 vcard_add_prop(v, "adr", buf);
422 vcard_add_prop(v, "tel;home", bstr("hometel"));
423 vcard_add_prop(v, "tel;work", bstr("worktel"));
424 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
426 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
427 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
428 if (!IsEmptyStr(buf)) {
429 vcard_add_prop(v, "email;internet", buf);
433 serialized_vcard = vcard_serialize(v);
435 if (serialized_vcard == NULL) {
436 safestrncpy(WC->ImportantMessage,
437 _("An error has occurred."),
438 sizeof WC->ImportantMessage
444 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
446 serv_printf("%s\r\n", serialized_vcard);
448 free(serialized_vcard);
450 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
451 select_user_to_edit(NULL, NULL);
453 else if (!strcmp(bstr("return_to"), "do_welcome")) {