]> code.citadel.org Git - citadel.git/blobdiff - webcit/useredit.c
*** empty log message ***
[citadel.git] / webcit / useredit.c
index 8424f9d91960d87a72f3a1a4424d894a8d7146b2..040282c55cfdc348defb1a8e57d18e5d96f01578 100644 (file)
@@ -35,20 +35,20 @@ void select_user_to_edit(char *message, char *preselect)
        char buf[SIZ];
        char username[SIZ];
 
-       output_headers(3);      /* No room banner on this screen */
+       output_headers(1, 1, 0, 0, 0, 0, 0);    /* No room banner on this screen */
 
        if (message != NULL) wprintf(message);
 
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
-       wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
-               "Add/change/delete user accounts"
-               "</B></FONT></TD></TR></TABLE>\n");
+       wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP><TD>\n");
 
-       wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
-               "<TD>To edit an existing user account, select the user "
-               "name from the list and click 'Edit'.<BR><BR>");
+       svprintf("BOXTITLE", WCS_STRING, "Edit or Delete users");
+       do_template("beginbox");
+
+       wprintf("To edit an existing user account, select the user "
+               "name from the list and click 'Edit'.<br /><br />");
        
-        wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_edituser\">\n");
+        wprintf("<CENTER>"
+               "<FORM METHOD=\"POST\" ACTION=\"/display_edituser\">\n");
         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
         serv_puts("LIST");
         serv_gets(buf);
@@ -64,22 +64,28 @@ void select_user_to_edit(char *message, char *preselect)
                         wprintf("\n");
                 }
         }
-        wprintf("</SELECT><BR>\n");
+        wprintf("</SELECT><br />\n");
 
         wprintf("<input type=submit name=sc value=\"Edit configuration\">");
         wprintf("<input type=submit name=sc value=\"Edit address book entry\">");
         wprintf("</FORM></CENTER>\n");
+       do_template("endbox");
+
+       wprintf("</TD><TD>");
 
-       wprintf("</TD><TD>"
-               "To create a new user account, enter the desired "
-               "user name in the box below and click 'Create'.<BR><BR>");
+       svprintf("BOXTITLE", WCS_STRING, "Add users");
+       do_template("beginbox");
+
+       wprintf("To create a new user account, enter the desired "
+               "user name in the box below and click 'Create'.<br /><br />");
 
         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/create_user\">\n");
         wprintf("New user: ");
-        wprintf("<input type=text name=username><BR>\n"
+        wprintf("<input type=text name=username><br />\n"
                "<input type=submit value=\"Create\">"
                "</FORM></CENTER>\n");
 
+       do_template("endbox");
        wprintf("</TD></TR></TABLE>\n");
 
        wDumpContent(1);
@@ -88,12 +94,10 @@ void select_user_to_edit(char *message, char *preselect)
 
 
 /* 
- * Display the form for editing a user's address book entry
+ * Locate the message number of a user's vCard in the current room
  */
-void display_edit_address_book_entry(char *username, long usernum) {
-       char roomname[SIZ];
+long locate_user_vcard(char *username, long usernum) {
        char buf[SIZ];
-       char error_message[SIZ];
        long vcard_msgnum = (-1L);
        char content_type[SIZ];
        char partnum[SIZ];
@@ -107,25 +111,6 @@ void display_edit_address_book_entry(char *username, long usernum) {
        struct stuff_t *stuff = NULL;
        struct stuff_t *ptr;
 
-
-       /* Locate the user's config room, creating it if necessary */
-       sprintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM);
-       serv_printf("GOTO %s||1", roomname);
-       serv_gets(buf);
-       if (buf[0] != '2') {
-               serv_printf("CRE8 1|%s|5|||1|", roomname);
-               serv_gets(buf);
-               serv_printf("GOTO %s||1", roomname);
-               serv_gets(buf);
-               if (buf[0] != '2') {
-                       sprintf(error_message,
-                               "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                               "%s<BR><BR>\n", &buf[4]);
-                       select_user_to_edit(error_message, username);
-                       return;
-               }
-       }
-
 TRYAGAIN:
        /* Search for the user's vCard */
        serv_puts("MSGS ALL");
@@ -137,7 +122,7 @@ TRYAGAIN:
                stuff = ptr;
        }
 
-       /* Iterate throught the message list looking for vCards */
+       /* Iterate through the message list looking for vCards */
        while (stuff != NULL) {
                serv_printf("MSG0 %ld|2", stuff->msgnum);
                serv_gets(buf);
@@ -159,8 +144,6 @@ TRYAGAIN:
                stuff = ptr;
        }
 
-       lprintf(9, "vcard_msgnum == %ld\n", vcard_msgnum);
-
        /* If there's no vcard, create one */
        if (vcard_msgnum < 0) if (already_tried_creating_one == 0) {
                already_tried_creating_one = 1;
@@ -176,10 +159,45 @@ TRYAGAIN:
                goto TRYAGAIN;
        }
 
+       return(vcard_msgnum);
+}
+
+
+/* 
+ * Display the form for editing a user's address book entry
+ */
+void display_edit_address_book_entry(char *username, long usernum) {
+       char roomname[SIZ];
+       char buf[SIZ];
+       char error_message[SIZ];
+       long vcard_msgnum = (-1L);
+
+       /* Locate the user's config room, creating it if necessary */
+       sprintf(roomname, "%010ld.%s", usernum, USERCONFIGROOM);
+       serv_printf("GOTO %s||1", roomname);
+       serv_gets(buf);
+       if (buf[0] != '2') {
+               serv_printf("CRE8 1|%s|5|||1|", roomname);
+               serv_gets(buf);
+               serv_printf("GOTO %s||1", roomname);
+               serv_gets(buf);
+               if (buf[0] != '2') {
+                       sprintf(error_message,
+                               "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                               "%s<br /><br />\n", &buf[4]);
+                       select_user_to_edit(error_message, username);
+                       return;
+               }
+       }
+
+       vcard_msgnum = locate_user_vcard(username, usernum);
+
        if (vcard_msgnum < 0) {
                sprintf(error_message,
                        "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                       "Could not create/edit vCard<BR><BR>\n");
+                       "Could not create/edit vCard"
+                       "<br /><br />\n"
+               );
                select_user_to_edit(error_message, username);
                return;
        }
@@ -193,8 +211,11 @@ TRYAGAIN:
 /*
  * Edit a user.  If supplied_username is null, look in the "username"
  * web variable for the name of the user to edit.
+ * 
+ * If "is_new" is set to nonzero, this screen will set the web variables
+ * to send the user to the vCard editor next.
  */
-void display_edituser(char *supplied_username) {
+void display_edituser(char *supplied_username, int is_new) {
        char buf[SIZ];
        char error_message[SIZ];
        time_t now;
@@ -222,7 +243,7 @@ void display_edituser(char *supplied_username) {
        if (buf[0] != '2') {
                sprintf(error_message,
                        "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                       "%s<BR><BR>\n", &buf[4]);
+                       "%s<br /><br />\n", &buf[4]);
                select_user_to_edit(error_message, username);
                return;
        }
@@ -242,17 +263,23 @@ void display_edituser(char *supplied_username) {
                return;
        }
 
-       output_headers(3);      /* No room banner on this screen */
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
-       wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
+       output_headers(1, 1, 2, 0, 0, 0, 0);
+       wprintf("<div id=\"banner\">\n");
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
+       wprintf("<SPAN CLASS=\"titlebar\">"
                "Edit user account: ");
        escputs(username);
-       wprintf("</B></FONT></TD></TR></TABLE>\n");
+       wprintf("</SPAN></TD></TR></TABLE>\n");
+       wprintf("</div>\n<div id=\"content\">\n");
 
+       do_template("beginbox_nt");
        wprintf("<FORM METHOD=\"POST\" ACTION=\"/edituser\">\n"
                "<INPUT TYPE=\"hidden\" NAME=\"username\" VALUE=\"");
        escputs(username);
        wprintf("\">\n");
+       wprintf("<INPUT TYPE=\"hidden\" NAME=\"is_new\" VALUE=\"%d\">\n"
+               "<INPUT TYPE=\"hidden\" NAME=\"usernum\" VALUE=\"%ld\">\n",
+               is_new, usernum);
 
        wprintf("<INPUT TYPE=\"hidden\" NAME=\"flags\" VALUE=\"%d\">\n", flags);
 
@@ -312,10 +339,12 @@ void display_edituser(char *supplied_username) {
        wprintf("</TABLE>\n");
 
        wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"OK\">\n"
+               "&nbsp;"
                "<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Cancel\">\n"
-               "<BR><BR></FORM>\n");
+               "<br /><br /></FORM>\n");
 
        wprintf("</CENTER>\n");
+       do_template("endbox");
 
        wDumpContent(1);
 
@@ -326,6 +355,9 @@ void display_edituser(char *supplied_username) {
 void edituser(void) {
        char message[SIZ];
        char buf[SIZ];
+       int is_new = 0;
+
+       is_new = atoi(bstr("is_new"));
 
        if (strcasecmp(bstr("action"), "OK")) {
                strcpy(message, "Edit user cancelled.");
@@ -348,14 +380,22 @@ void edituser(void) {
                if (buf[0] != '2') {
                        sprintf(message,
                                "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                               "%s<BR><BR>\n", &buf[4]);
+                               "%s<br /><br />\n", &buf[4]);
                }
                else {
                        strcpy(message, "");
                }
        }
 
-       select_user_to_edit(message, bstr("username"));
+       /* If we are in the middle of creating a new user, move on to
+        * the vCard edit screen.
+        */
+       if (is_new) {
+               display_edit_address_book_entry( bstr("username"), atol(bstr("usernum")) );
+       }
+       else {
+               select_user_to_edit(message, bstr("username"));
+       }
 }
 
 
@@ -372,13 +412,14 @@ void create_user(void) {
        serv_gets(buf);
 
        if (buf[0] == '2') {
-               sprintf(error_message, "<b>User has been created.</b>");
-               select_user_to_edit(error_message, username);
+               /* sprintf(error_message, "<b>User has been created.</b>");
+               select_user_to_edit(error_message, username); */
+               display_edituser(username, 1);
        }
        else {
                sprintf(error_message,
                        "<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
-                       "%s<BR><BR>\n", &buf[4]);
+                       "%s<br /><br />\n", &buf[4]);
                select_user_to_edit(error_message, NULL);
        }