5 * \defgroup Sieve view/edit sieve config
6 * \ingroup WebcitDisplayItems
11 #define MAX_SCRIPTS 100
14 * \brief view/edit sieve config
16 void display_sieve(void)
18 char script_names[MAX_SCRIPTS][64];
20 int active_script = (-1);
25 memset(script_names, 0, sizeof script_names);
27 serv_puts("MSIV listscripts");
28 serv_getln(buf, sizeof(buf));
29 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
30 if (num_scripts < MAX_SCRIPTS) {
31 extract_token(script_names[num_scripts], buf, 0, '|', 64);
32 if (extract_int(buf, 1) > 0) {
33 active_script = num_scripts;
39 output_headers(1, 1, 2, 0, 0, 0);
41 wprintf("<script type=\"text/javascript\"> \n"
43 "var previously_active_script; \n"
45 "function ToggleSievePanels() { \n"
46 " d = ($('sieveform').bigaction.options[$('sieveform').bigaction.selectedIndex].value); \n"
47 " for (i=0; i<3; ++i) { \n"
49 " $('sievediv' + i).style.display = 'block'; \n"
52 " $('sievediv' + i).style.display = 'none'; \n"
57 "function ToggleScriptPanels() { \n"
58 " d = ($('sieveform').active_script.options[$('sieveform').active_script.selectedIndex].value); \n"
59 " if ($('script_' + previously_active_script)) { \n"
60 " $('script_' + previously_active_script).style.display = 'none'; \n"
62 " $('script_' + d).style.display = 'block'; \n"
63 " previously_active_script = d; \n"
69 wprintf("<div id=\"banner\">\n");
70 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
71 wprintf("<SPAN CLASS=\"titlebar\">");
72 wprintf(_("View/edit server-side mail filters"));
74 wprintf("</TD></TR></TABLE>\n");
75 wprintf("</div>\n<div id=\"content\">\n");
77 wprintf("<div class=\"fix_scrollbar_bug\">"
78 "<table border=0 width=100%% bgcolor=\"#FFFFFF\">"
79 "<tr><td valign=top>\n");
82 wprintf("<form id=\"sieveform\" method=\"post\" action=\"save_sieve\">\n");
84 wprintf(_("When new mail arrives: "));
85 wprintf("<select name=\"bigaction\" size=1 onChange=\"ToggleSievePanels();\">\n");
87 wprintf("<option %s value=\"0\">", ((active_script < 0) ? "selected" : ""));
88 wprintf(_("Leave it in my inbox without filtering"));
89 wprintf("</option>\n");
92 * FIXME uncomment this when we write the rules editor
94 wprintf("<option value=\"1\">");
95 wprintf(_("Filter it according to rules selected below"));
96 wprintf("</option>\n");
100 wprintf("<option %s value=\"2\">", ((active_script >= 0) ? "selected" : ""));
101 wprintf(_("Filter it through a manually edited script (advanced users only)"));
102 wprintf("</option>\n");
104 wprintf("</select>");
108 /* The "no filtering" div */
110 wprintf("<div id=\"sievediv0\" style=\"display:none\">\n");
111 wprintf("<div align=\"center\"><br /><br />");
112 wprintf(_("Your incoming mail will not be filtered through any scripts."));
113 wprintf("<br /><br /></div>\n");
116 /* The "webcit managed scripts" div */
118 wprintf("<div id=\"sievediv1\" style=\"display:none\">\n");
119 wprintf("<div align=\"center\"><br /><br />");
121 wprintf("<br /><br /></div>\n");
124 /* The "I'm smart and can write my own Sieve scripts" div */
126 wprintf("<div id=\"sievediv2\" style=\"display:none\">\n");
128 if (num_scripts > 0) {
129 wprintf(_("The currently active script is: "));
130 wprintf("<select name=\"active_script\" size=1 onChange=\"ToggleScriptPanels();\">\n");
131 for (i=0; i<num_scripts; ++i) {
132 wprintf("<option %s value=\"%s\">%s</option>\n",
133 ((active_script == i) ? "selected" : ""),
138 wprintf("</select>\n");
141 wprintf(" ");
142 wprintf("<a href=\"display_add_remove_scripts\">%s</a>\n", _("Add or delete scripts"));
146 if (num_scripts > 0) {
147 for (i=0; i<num_scripts; ++i) {
148 wprintf("<div id=\"script_%s\" style=\"display:none\">\n", script_names[i]);
149 wprintf("<textarea name=\"text_%s\" wrap=soft rows=20 cols=80 width=80>\n", script_names[i]);
150 serv_printf("MSIV getscript|%s", script_names[i]);
151 serv_getln(buf, sizeof buf);
152 if (buf[0] == '1') while(serv_getln(buf, sizeof (buf)), strcmp(buf, "000")) {
153 wprintf("%s\n", buf);
155 wprintf("</textarea>\n");
160 wprintf("<script type=\"text/javascript\"> \n"
161 "ToggleScriptPanels(); \n"
168 /* The rest of this is common for all panels... */
170 wprintf("<div align=\"center\"><br>");
171 wprintf("<input type=\"submit\" name=\"save_button\" value=\"%s\">", _("Save changes"));
173 wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
174 wprintf("</div></form>\n");
176 wprintf("</td></tr></table></div>\n");
178 wprintf("<script type=\"text/javascript\"> \n"
179 "ToggleSievePanels(); \n"
189 * \brief save sieve config
191 void save_sieve(void) {
193 char script_names[MAX_SCRIPTS][64];
195 int active_script = (-1);
200 if (strlen(bstr("save_button")) == 0) {
201 strcpy(WC->ImportantMessage,
202 _("Cancelled. Changes were not saved."));
207 serv_puts("MSIV listscripts");
208 serv_getln(buf, sizeof(buf));
209 if (buf[0] == '1') while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
210 if (num_scripts < MAX_SCRIPTS) {
211 extract_token(script_names[num_scripts], buf, 0, '|', 64);
212 if (extract_int(buf, 1) > 0) {
213 active_script = num_scripts;
219 bigaction = atoi(bstr("bigaction"));
221 if (bigaction == 0) {
222 serv_puts("MSIV setactive||");
223 serv_getln(buf, sizeof buf);
226 else if (bigaction == 2) {
227 serv_printf("MSIV setactive|%s|", bstr("active_script"));
228 serv_getln(buf, sizeof buf);
231 if (num_scripts > 0) {
232 for (i=0; i<num_scripts; ++i) {
233 serv_printf("MSIV putscript|%s|", script_names[i]);
234 serv_getln(buf, sizeof buf);
236 snprintf(this_name, sizeof this_name, "text_%s", script_names[i]);
237 striplt(bstr(this_name));
238 serv_printf("%s", bstr(this_name));
244 strcpy(WC->ImportantMessage, _("Your changes have been saved."));
251 * \brief show a list of available scripts to add/remove them
253 void display_add_remove_scripts(char *message)
256 char script_name[256];
258 output_headers(1, 1, 2, 0, 0, 0);
259 wprintf("<div id=\"banner\">\n");
260 wprintf("<table width=100%% border=0 bgcolor=#444455><tr>"
262 "<span class=\"titlebar\">"
263 "<img src=\"static/usermanag_48x.gif\">");
264 wprintf(_("Add/remove Sieve scripts"));
265 wprintf("</span></td></tr></table>\n"
266 "</div>\n<div id=\"content\">\n"
269 if (message != NULL) wprintf(message);
271 wprintf("<table border=0 cellspacing=10><tr valign=top><td>\n");
273 svprintf("BOXTITLE", WCS_STRING, _("Add a new script"));
274 do_template("beginbox");
276 wprintf(_("To create a new script, enter the desired "
277 "script name in the box below and click 'Create'."));
278 wprintf("<br /><br />");
280 wprintf("<center><form method=\"POST\" action=\"create_script\">\n");
281 wprintf(_("Script name: "));
282 wprintf("<input type=\"text\" name=\"script_name\"><br />\n"
283 "<input type=\"submit\" name=\"create_button\" value=\"%s\">"
284 "</form></center>\n", _("Create"));
286 do_template("endbox");
288 svprintf("BOXTITLE", WCS_STRING, _("Edit scripts"));
289 do_template("beginbox");
290 wprintf("<br /><div align=center><a href=\"display_sieve\">%s</a><br /><br />\n",
291 _("Return to the script editing screen")
293 do_template("endbox");
295 wprintf("</td><td>");
297 svprintf("BOXTITLE", WCS_STRING, _("Delete scripts"));
298 do_template("beginbox");
300 wprintf(_("To delete an existing script, select the script "
301 "name from the list and click 'Delete'."));
302 wprintf("<br /><br />");
305 "<form method=\"POST\" action=\"delete_script\">\n");
306 wprintf("<select name=\"script_name\" size=10 style=\"width:100%%\">\n");
308 serv_puts("MSIV listscripts");
309 serv_getln(buf, sizeof buf);
311 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
312 extract_token(script_name, buf, 0, '|', sizeof script_name);
313 if (extract_int(buf, 1) == 0) {
315 escputs(script_name);
316 wprintf("</option>\n");
320 wprintf("</select><br />\n");
322 wprintf("<input type=\"submit\" name=\"delete_button\" value=\"%s\" "
323 "onClick=\"return confirm('%s');\">", _("Delete script"), _("Delete this script?"));
324 wprintf("</form></center>\n");
325 do_template("endbox");
327 wprintf("</td></tr></table>\n");
335 * \brief delete a script
337 void delete_script(void) {
340 serv_printf("MSIV deletescript|%s", bstr("script_name"));
341 serv_getln(buf, sizeof buf);
342 display_add_remove_scripts(&buf[4]);
348 * \brief create a new script
349 * take the web environment script name and create it on the citadel server
351 void create_script(void) {
354 serv_printf("MSIV getscript|%s", bstr("script_name"));
355 serv_getln(buf, sizeof buf);
357 while (serv_getln(buf, sizeof(buf)), strcmp(buf, "000")) {
360 display_add_remove_scripts(_("A script by that name already exists."));
364 serv_printf("MSIV putscript|%s", bstr("script_name"));
365 serv_getln(buf, sizeof buf);
369 display_add_remove_scripts(_("A new script has been created. Return to the script editing screen to edit and activate it."));
373 display_add_remove_scripts(&buf[4]);