* added gcc printf format checking to wprintf
[citadel.git] / webcit / vcard_edit.c
index 3a6f33c14d6980a4c6af55cc222ca13ccd44de37..17b781778c9804509c0c7d6138bf97b922ae4e13 100644 (file)
@@ -7,7 +7,6 @@
  */
 /*@{*/
 #include "webcit.h"
-#include "vcard.h"
 
 /**
  * \brief Edit the vCard component of a MIME message.  
@@ -18,7 +17,7 @@
  * \param partnum what???
  * \param return_to where to go back in the browser after edit ????
  */
-void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
+void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
        char buf[SIZ];
        char *serialized_vcard = NULL;
        size_t total_len = 0;
@@ -41,6 +40,8 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        char country[256];
        char hometel[256];
        char worktel[256];
+       char faxtel[256];
+       char mobiletel[256];
        char primary_inetemail[256];
        char other_inetemail[SIZ];
        char extrafields[SIZ];
@@ -62,6 +63,8 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        country[0] = 0;
        hometel[0] = 0;
        worktel[0] = 0;
+       faxtel[0] = 0;
+       mobiletel[0] = 0;
        primary_inetemail[0] = 0;
        other_inetemail[0] = 0;
        title[0] = 0;
@@ -89,21 +92,18 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
                        }
                }
        
-               sprintf(buf, "OPNA %ld|%s", msgnum, partnum);
+               sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
                serv_puts(buf);
                serv_getln(buf, sizeof buf);
-               if (buf[0] != '2') {
+               if (buf[0] != '6') {
                        convenience_page("770000", "Error", &buf[4]);
                        return;
                }
        
                total_len = atoi(&buf[4]);
                serialized_vcard = malloc(total_len + 2);
-       
-               read_server_binary(serialized_vcard, total_len);
-       
-               serv_puts("CLOS");
-               serv_getln(buf, sizeof buf);
+
+               serv_read(serialized_vcard, total_len);
                serialized_vcard[total_len] = 0;
        
                v = vcard_load(serialized_vcard);
@@ -152,6 +152,14 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
                                extract_token(worktel, value, 0, ';', sizeof worktel);
                        }
        
+                       else if (!strcasecmp(key, "tel;fax")) {
+                               extract_token(faxtel, value, 0, ';', sizeof faxtel);
+                       }
+       
+                       else if (!strcasecmp(key, "tel;cell")) {
+                               extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
+                       }
+       
                        else if (!strcasecmp(key, "email;internet")) {
                                if (primary_inetemail[0] == 0) {
                                        safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
@@ -177,20 +185,22 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        }
 
        /** Display the form */
-       output_headers(1, 1, 2, 0, 0, 0);
-       wprintf("<div id=\"banner\">\n"
-               "<table width=100%% border=0 bgcolor=\"#444455\"><tr><td>"
-               "<span class=\"titlebar\">"
-               "<img src=\"static/savecontact_48x.gif\">");
-       wprintf(_("Edit contact information"));
-       wprintf("</span>"
-               "</td></tr></table>\n"
-               "</div>\n<div id=\"content\">\n"
-       );
+       output_headers(1, 1, 1, 0, 0, 0);
+
+       svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
+       do_template("beginbox");
 
        wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+
+       if (force_room != NULL) {
+               wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
+               escputs(force_room);
+               wprintf("\">\n");
+       }
+
        wprintf("<div class=\"fix_scrollbar_bug\">"
-               "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
+               "<table class=\"vcard_edit_background\"><tr><td>\n");
 
        wprintf("<table border=0><tr>"
                "<td>%s</td>"
@@ -216,7 +226,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
                "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
                suffix);
 
-       wprintf("<table border=0 width=100%% bgcolor=\"#dddddd\">");
+       wprintf("<table  class=\"vcard_edit_background_alt\">");
        wprintf("<tr><td>");
 
        wprintf(_("Display name:"));
@@ -269,7 +279,7 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        wprintf(_("State:"));
        wprintf("</td><td>"
                "<input type=\"text\" name=\"state\" "
-               "value=\"%s\" maxlength=\"2\"></td></tr>\n",
+               "value=\"%s\" maxlength=\"29\"></td></tr>\n",
                state);
        wprintf("<tr><td>");
        wprintf(_("ZIP code:"));
@@ -297,10 +307,22 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        wprintf(_("Work telephone:"));
        wprintf("</td>"
                "<td><input type=\"text\" name=\"worktel\" "
-               "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
+               "value=\"%s\" maxlength=\"29\"></td></tr>\n",
                worktel);
+       wprintf("<tr><td>");
+       wprintf(_("Mobile telephone:"));
+       wprintf("</td>"
+               "<td><input type=\"text\" name=\"mobiletel\" "
+               "value=\"%s\" maxlength=\"29\"></td>\n",
+               mobiletel);
+       wprintf("<td>");
+       wprintf(_("Fax number:"));
+       wprintf("</td>"
+               "<td><input type=\"text\" name=\"faxtel\" "
+               "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
+               faxtel);
 
-       wprintf("<table border=0 width=100%% bgcolor=\"#dddddd\">");
+       wprintf("<table class=\"vcard_edit_background_alt\">");
        wprintf("<tr><td>");
 
        wprintf("<table border=0><TR>"
@@ -328,16 +350,17 @@ void do_edit_vcard(long msgnum, char *partnum, char *return_to) {
        urlescputs(return_to);
        wprintf("\">\n");
 
-       wprintf("<center>\n"
+       wprintf("<div class=\"buttons\">\n"
                "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
                "&nbsp;"
                "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
-               "</center></form>\n",
+               "</div></form>\n",
                _("Save changes"),
                _("Cancel")
        );
        
-       wprintf("</td></tr></table></div>\n");
+       wprintf("</td></tr></table>\n");
+       do_template("endbox");
        wDumpContent(1);
 }
 
@@ -349,9 +372,9 @@ void edit_vcard(void) {
        long msgnum;
        char *partnum;
 
-       msgnum = atol(bstr("msgnum"));
+       msgnum = lbstr("msgnum");
        partnum = bstr("partnum");
-       do_edit_vcard(msgnum, partnum, "");
+       do_edit_vcard(msgnum, partnum, "", NULL);
 }
 
 
@@ -365,11 +388,15 @@ void submit_vcard(void) {
        char buf[SIZ];
        int i;
 
-       if (strlen(bstr("ok_button")) == 0) { 
+       if (!havebstr("ok_button")) { 
                readloop("readnew");
                return;
        }
 
+       if (havebstr("force_room")) {
+               gotoroom(bstr("force_room"));
+       }
+
        sprintf(buf, "ENT0 1|||4||");
        serv_puts(buf);
        serv_getln(buf, sizeof buf);
@@ -417,11 +444,13 @@ void submit_vcard(void) {
 
        vcard_add_prop(v, "tel;home", bstr("hometel"));
        vcard_add_prop(v, "tel;work", bstr("worktel"));
+       vcard_add_prop(v, "tel;fax", bstr("faxtel"));
+       vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
        vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
 
        for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
                extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
-               if (strlen(buf) > 0) {
+               if (!IsEmptyStr(buf)) {
                        vcard_add_prop(v, "email;internet", buf);
                }
        }