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