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