* inetconf.c, listsub.c, part of mainmenu.c: i18n
[citadel.git] / webcit / listsub.c
1 /*
2  * $Id$
3  *
4  * Web forms for handling mailing list subscribe/unsubscribe requests.
5  *
6  */
7
8 #include "webcit.h"
9
10
11
12 /*
13  * List subscription handling
14  */
15 void do_listsub(void)
16 {
17         char cmd[256];
18         char room[256];
19         char token[256];
20         char email[256];
21         char subtype[256];
22         char escaped_email[256];
23         char escaped_room[256];
24
25         char buf[SIZ];
26         int self;
27         char sroom[SIZ];
28
29         strcpy(WC->wc_username, "");
30         strcpy(WC->wc_password, "");
31         strcpy(WC->wc_roomname, "");
32
33         wprintf("<HTML><HEAD><TITLE>");
34         wprintf(_("List subscription"));
35         wprintf("</TITLE></HEAD><BODY>\n");
36
37         strcpy(cmd, bstr("cmd"));
38         strcpy(room, bstr("room"));
39         strcpy(token, bstr("token"));
40         strcpy(email, bstr("email"));
41         strcpy(subtype, bstr("subtype"));
42
43         wprintf("<CENTER>"
44                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
45                 "<SPAN CLASS=\"titlebar\">");
46         wprintf(_("List subscribe/unsubscribe"));
47         wprintf("</SPAN></TD></TR></TABLE><br />\n");
48
49         /*
50          * Subscribe command
51          */
52         if (!strcasecmp(cmd, "subscribe")) {
53                 serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
54                         room,
55                         email,
56                         subtype,
57                         WC->http_host
58                 );
59                 serv_getln(buf, sizeof buf);
60                 if (buf[0] == '2') {
61                         stresc(escaped_email, email, 0, 0);
62                         stresc(escaped_room, room, 0, 0);
63
64                         wprintf("<CENTER><H1>");
65                         wprintf(_("Confirmation request sent"));
66                         wprintf("</H1>");
67                         wprintf(_("You are subscribing <TT>%s"
68                                 "</TT> to the <b>%s</b> mailing list.  "
69                                 "The listserver has "
70                                 "sent you an e-mail with one additional "
71                                 "Web link for you to click on to confirm "
72                                 "your subscription.  This extra step is for "
73                                 "your protection, as it prevents others from "
74                                 "being able to subscribe you to lists "
75                                 "without your consent.<br /><br />"
76                                 "Please click on the link which is being "
77                                 "e-mailed to you and your subscription will "
78                                 "be confirmed.<br />\n"),
79                                 escaped_email, escaped_room);
80                         wprintf("<A HREF=\"/listsub\">%s</A></CENTER>\n", _("Go back..."));
81                 }
82                 else {
83                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
84                                 "</FONT><br /><br />\n",
85                                 &buf[4]);
86                         goto FORM;
87                 }
88         }
89
90         /*
91          * Unsubscribe command
92          */
93         else if (!strcasecmp(cmd, "unsubscribe")) {
94                 serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
95                         room,
96                         email,
97                         WC->http_host
98                 );
99                 serv_getln(buf, sizeof buf);
100                 if (buf[0] == '2') {
101                         wprintf("<CENTER><H1>Confirmation request sent</H1>"
102                                 "You are unsubscribing <TT>");
103                         escputs(email);
104                         wprintf("</TT> from the &quot;");
105                         escputs(room);
106                         wprintf("&quot; mailing list.  The listserver has "
107                                 "sent you an e-mail with one additional "
108                                 "Web link for you to click on to confirm "
109                                 "your unsubscription.  This extra step is for "
110                                 "your protection, as it prevents others from "
111                                 "being able to unsubscribe you from "
112                                 "lists without your consent.<br /><br />"
113                                 "Please click on the link which is being "
114                                 "e-mailed to you and your unsubscription will "
115                                 "be confirmed.<br />\n"
116                                 "<A HREF=\"/listsub\">Back...</A></CENTER>\n"
117                         );
118                 }
119                 else {
120                         wprintf("<FONT SIZE=+1><B>ERROR: %s</B>"
121                                 "</FONT><br /><br />\n",
122                                 &buf[4]);
123                         goto FORM;
124                 }
125         }
126
127         /* 
128          * Confirm command
129          */
130         else if (!strcasecmp(cmd, "confirm")) {
131                 serv_printf("SUBS confirm|%s|%s",
132                         room,
133                         token
134                 );
135                 serv_getln(buf, sizeof buf);
136                 if (buf[0] == '2') {
137                         wprintf("<CENTER><H1>Confirmation successful!</H1>");
138                 }
139                 else {
140                         wprintf("<CENTER><H1>Confirmation failed.</H1>"
141                                 "This could mean one of two things:<UL>\n"
142                                 "<LI>You waited too long to confirm your "
143                                 "subscribe/unsubscribe request (the "
144                                 "confirmation link is only valid for three "
145                                 "days)\n<LI>You have <i>already</i> "
146                                 "successfully confirmed your "
147                                 "subscribe/unsubscribe request and are "
148                                 "attempting to do it again.</UL>\n"
149                                 "The error returned by the server was: "
150                         );
151                 }
152                 wprintf("%s</CENTER><br />\n", &buf[4]);
153         }
154
155         /*
156          * Any other (invalid) command causes the form to be displayed
157          */
158         else {
159 FORM:           wprintf("<FORM METHOD=\"POST\" ACTION=\"/listsub\">\n"
160                         "<TABLE BORDER=0>\n"
161                 );
162
163                 wprintf("<TR><TD>Name of list</TD><TD>"
164                         "<SELECT NAME=\"room\" SIZE=1>\n");
165
166                 serv_puts("LPRM");
167                 serv_getln(buf, sizeof buf);
168                 if (buf[0] == '1') {
169                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
170                                 extract_token(sroom, buf, 0, '|', sizeof sroom);
171                                 self = extract_int(buf, 4) & QR2_SELFLIST ;
172                                 if (self) {
173                                         wprintf("<OPTION VALUE=\"");
174                                         escputs(sroom);
175                                         wprintf("\">");
176                                         escputs(sroom);
177                                         wprintf("</OPTION>\n");
178                                 }
179                         }
180                 }
181                 wprintf("</SELECT>"
182                         "</TD></TR>\n");
183
184                 wprintf("<TR><TD>Your e-mail address</TD><TD>"
185                         "<INPUT TYPE=\"text\" NAME=\"email\" "
186                         "VALUE=\""
187                 );
188                 escputs(email);
189                 wprintf("\" MAXLENGTH=128></TD></TR>\n");
190
191                 wprintf("</TABLE>"
192                         "(If subscribing) preferred format: "
193                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
194                         "VALUE=\"list\">One message at a time&nbsp; "
195                         "<INPUT TYPE=\"radio\" NAME=\"subtype\""
196                         "VALUE=\"digest\" CHECKED>Digest format&nbsp; "
197                         "<br />\n"
198                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
199                         " VALUE=\"subscribe\">\n"
200                         "<INPUT TYPE=\"submit\" NAME=\"cmd\""
201                         " VALUE=\"unsubscribe\">\n"
202                         "</FORM>\n"
203                 );
204
205                 wprintf("<br />When you attempt to subscribe or unsubscribe to "
206                         "a mailing list, you will receive an e-mail containing"
207                         " one additional web link to click on for final "
208                         "confirmation.  This extra step is for your "
209                         "protection, as it prevents others from being able to "
210                         "subscribe or unsubscribe you to lists.<br />\n"
211                 );
212
213         }
214
215         /*
216          * Since this isn't part of a normal Citadel session, we bail right
217          * out without maintaining any state.
218          */
219         /* wDumpContent(2); */
220         wprintf("</BODY></HTML>\n");
221         end_webcit_session();
222 }