00001
00002
00003
00010 #include "webcit.h"
00011 #include "webserver.h"
00012 #include "groupdav.h"
00013
00014
00018 void load_preferences(void) {
00019 char buf[SIZ];
00020 long msgnum = 0L;
00021
00022 serv_printf("GOTO %s", USERCONFIGROOM);
00023 serv_getln(buf, sizeof buf);
00024 if (buf[0] != '2') return;
00025
00026 serv_puts("MSGS ALL|0|1");
00027 serv_getln(buf, sizeof buf);
00028 if (buf[0] == '8') {
00029 serv_puts("subj|__ WebCit Preferences __");
00030 serv_puts("000");
00031 }
00032 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00033 msgnum = atol(buf);
00034 }
00035
00036 if (msgnum > 0L) {
00037 serv_printf("MSG0 %ld", msgnum);
00038 serv_getln(buf, sizeof buf);
00039 if (buf[0] == '1') {
00040 while (serv_getln(buf, sizeof buf),
00041 (strcmp(buf, "text") && strcmp(buf, "000"))) {
00042 }
00043 if (!strcmp(buf, "text")) {
00044 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00045 if (WC->preferences == NULL) {
00046 WC->preferences = malloc(SIZ);
00047 strcpy(WC->preferences, "");
00048 }
00049 else {
00050 WC->preferences = realloc(
00051 WC->preferences,
00052 strlen(WC->preferences)
00053 +SIZ
00054 );
00055 }
00056 strcat(WC->preferences, buf);
00057 strcat(WC->preferences, "\n");
00058 }
00059 }
00060 }
00061 }
00062
00064 serv_printf("GOTO %s", WC->wc_roomname);
00065 serv_getln(buf, sizeof buf);
00066 }
00067
00072 int goto_config_room(void) {
00073 char buf[SIZ];
00074
00075 serv_printf("GOTO %s", USERCONFIGROOM);
00076 serv_getln(buf, sizeof buf);
00077 if (buf[0] != '2') {
00078 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
00079 serv_getln(buf, sizeof buf);
00080 serv_printf("GOTO %s", USERCONFIGROOM);
00081 serv_getln(buf, sizeof buf);
00082 if (buf[0] != '2') return(1);
00083 }
00084 return(0);
00085 }
00086
00090 void save_preferences(void) {
00091 char buf[SIZ];
00092 long msgnum = 0L;
00093
00094 if (goto_config_room() != 0) return;
00095 serv_puts("MSGS ALL|0|1");
00096 serv_getln(buf, sizeof buf);
00097 if (buf[0] == '8') {
00098 serv_puts("subj|__ WebCit Preferences __");
00099 serv_puts("000");
00100 }
00101 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00102 msgnum = atol(buf);
00103 }
00104
00105 if (msgnum > 0L) {
00106 serv_printf("DELE %ld", msgnum);
00107 serv_getln(buf, sizeof buf);
00108 }
00109
00110 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
00111 serv_getln(buf, sizeof buf);
00112 if (buf[0] == '4') {
00113 serv_puts(WC->preferences);
00114 serv_puts("");
00115 serv_puts("000");
00116 }
00117
00119 serv_printf("GOTO %s", WC->wc_roomname);
00120 serv_getln(buf, sizeof buf);
00121 }
00122
00129 void get_preference(char *key, char *value, size_t value_len) {
00130 int num_prefs;
00131 int i;
00132 char buf[SIZ];
00133 char thiskey[SIZ];
00134
00135 strcpy(value, "");
00136
00137 num_prefs = num_tokens(WC->preferences, '\n');
00138 for (i=0; i<num_prefs; ++i) {
00139 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
00140 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
00141 if (!strcasecmp(thiskey, key)) {
00142 extract_token(value, buf, 1, '|', value_len);
00143 }
00144 }
00145 }
00146
00154 void set_preference(char *key, char *value, int save_to_server) {
00155 int num_prefs;
00156 int i;
00157 char buf[SIZ];
00158 char thiskey[SIZ];
00159 char *newprefs = NULL;
00160 size_t newprefs_len = 0;
00161
00162 newprefs_len = strlen(key) + strlen(value) + 10;
00163 if (WC->preferences != NULL) newprefs_len += strlen(WC->preferences);
00164 newprefs = malloc(newprefs_len);
00165 if (newprefs == NULL) return;
00166 strcpy(newprefs, "");
00167
00168 num_prefs = num_tokens(WC->preferences, '\n');
00169 for (i=0; i<num_prefs; ++i) {
00170 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
00171 if (num_tokens(buf, '|') == 2) {
00172 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
00173 if (strcasecmp(thiskey, key)) {
00174 strcat(newprefs, buf);
00175 strcat(newprefs, "\n");
00176 }
00177 }
00178 }
00179
00180 sprintf(&newprefs[strlen(newprefs)], "%s|%s\n", key, value);
00181 free(WC->preferences);
00182 WC->preferences = newprefs;
00183
00184 if (save_to_server) save_preferences();
00185 }
00186
00187
00188
00189
00193 void display_preferences(void)
00194 {
00195 output_headers(1, 1, 2, 0, 0, 0);
00196 char ebuf[300];
00197 char buf[256];
00198 char calhourformat[16];
00199 int i;
00200
00201 wprintf("<div id=\"banner\">\n");
00202 wprintf("<TABLE class=\"preferences_banner\"><TR><TD>");
00203 wprintf("<img src=\"static/advanpage2_48x.gif\" ALT=\" \" ALIGN=MIDDLE>");
00204 wprintf("<SPAN CLASS=\"titlebar\"> ");
00205 wprintf(_("Preferences and settings"));
00206 wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
00207 offer_start_page();
00208 wprintf("</TD></TR></TABLE>\n");
00209 wprintf("</div>\n"
00210 "<div id=\"content\">\n");
00211
00212 wprintf("<div class=\"fix_scrollbar_bug\">"
00213 "<table class=\"preferences_background\"><tr><td>\n");
00214
00216 wprintf("<center>\n"
00217 "<form name=\"prefform\" action=\"set_preferences\" "
00218 "method=\"post\">\n"
00219 "<table border=0 cellspacing=5 cellpadding=5>\n");
00220
00224 get_preference("roomlistview", buf, sizeof buf);
00225 wprintf("<tr><td>");
00226 wprintf(_("Room list view"));
00227 wprintf("</td><td>");
00228
00229 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"folders\"");
00230 if (!strcasecmp(buf, "folders")) wprintf(" checked");
00231 wprintf(">");
00232 wprintf(_("Tree (folders) view"));
00233 wprintf("<br></input>\n");
00234
00235 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"rooms\"");
00236 if (!strcasecmp(buf, "rooms")) wprintf(" checked");
00237 wprintf(">");
00238 wprintf(_("Table (rooms) view"));
00239 wprintf("<br></input>\n");
00240
00241 wprintf("</td></tr>\n");
00242
00246 get_preference("calhourformat", calhourformat, sizeof calhourformat);
00247 if (calhourformat[0] == 0) strcpy(calhourformat, "12");
00248 wprintf("<tr><td>");
00249 wprintf(_("Calendar hour format"));
00250 wprintf("</td><td>");
00251
00252 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
00253 if (!strcasecmp(calhourformat, "12")) wprintf(" checked");
00254 wprintf(">");
00255 wprintf(_("12 hour (am/pm)"));
00256 wprintf("<br></input>\n");
00257
00258 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
00259 if (!strcasecmp(calhourformat, "24")) wprintf(" checked");
00260 wprintf(">");
00261 wprintf(_("24 hour"));
00262 wprintf("<br></input>\n");
00263
00264 wprintf("</td></tr>\n");
00265
00269 get_preference("daystart", buf, sizeof buf);
00270 if (buf[0] == 0) strcpy(buf, "8");
00271 wprintf("<tr><td>");
00272 wprintf(_("Calendar day view begins at:"));
00273 wprintf("</td><td>");
00274
00275 wprintf("<SELECT NAME=\"daystart\" SIZE=\"1\">\n");
00276 for (i=0; i<=23; ++i) {
00277
00278 if (!strcasecmp(calhourformat, "24")) {
00279 wprintf("<OPTION %s VALUE=\"%d\">%d:00</OPTION>\n",
00280 ((atoi(buf) == i) ? "SELECTED" : ""),
00281 i, i
00282 );
00283 }
00284 else {
00285 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
00286 ((atoi(buf) == i) ? "SELECTED" : ""),
00287 i, hourname[i]
00288 );
00289 }
00290
00291 }
00292 wprintf("</SELECT>\n");
00293 wprintf("</td></tr>\n");
00294
00298 get_preference("dayend", buf, sizeof buf);
00299 if (buf[0] == 0) strcpy(buf, "17");
00300 wprintf("<tr><td>");
00301 wprintf(_("Calendar day view ends at:"));
00302 wprintf("</td><td>");
00303
00304 wprintf("<SELECT NAME=\"dayend\" SIZE=\"1\">\n");
00305 for (i=0; i<=23; ++i) {
00306
00307 if (!strcasecmp(calhourformat, "24")) {
00308 wprintf("<OPTION %s VALUE=\"%d\">%d:00</OPTION>\n",
00309 ((atoi(buf) == i) ? "SELECTED" : ""),
00310 i, i
00311 );
00312 }
00313 else {
00314 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
00315 ((atoi(buf) == i) ? "SELECTED" : ""),
00316 i, hourname[i]
00317 );
00318 }
00319
00320 }
00321 wprintf("</SELECT>\n");
00322 wprintf("</td></tr>\n");
00323
00327 get_preference("use_sig", buf, sizeof buf);
00328 if (buf[0] == 0) strcpy(buf, "no");
00329 wprintf("<tr><td>");
00330 wprintf(_("Attach signature to email messages?"));
00331 wprintf("</td><td>");
00332
00333 wprintf(" <script type=\"text/javascript\"> "
00334 " function show_or_hide_sigbox() { "
00335 " if ( $F('yes_sig') ) { "
00336 " $('signature_box').style.display = 'inline'; "
00337 " } "
00338 " else { "
00339 " $('signature_box').style.display = 'none'; "
00340 " } "
00341 " } "
00342 " </script> "
00343 );
00344
00345 wprintf("<input type=\"radio\" id=\"no_sig\" name=\"use_sig\" VALUE=\"no\"");
00346 if (!strcasecmp(buf, "no")) wprintf(" checked");
00347 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
00348 wprintf(_("No signature"));
00349 wprintf("<br></input>\n");
00350
00351 wprintf("<input type=\"radio\" id=\"yes_sig\" name=\"use_sig\" VALUE=\"yes\"");
00352 if (!strcasecmp(buf, "yes")) wprintf(" checked");
00353 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
00354 wprintf(_("Use this signature:"));
00355 wprintf("<div id=\"signature_box\">"
00356 "<br><textarea name=\"signature\" cols=\"40\" rows=\"5\">"
00357 );
00358 get_preference("signature", ebuf, sizeof ebuf);
00359 euid_unescapize(buf, ebuf);
00360 escputs(buf);
00361 wprintf("</textarea>"
00362 "</div>"
00363 );
00364
00365 wprintf("<br></input>\n");
00366
00367 wprintf("</td></tr>\n");
00368
00369 wprintf(" <script type=\"text/javascript\"> "
00370 " show_or_hide_sigbox(); "
00371 " </script> "
00372 );
00373
00375 get_preference("default_header_charset", buf, sizeof buf);
00376 if (buf[0] == 0) strcpy(buf, "UTF-8");
00377 wprintf("<tr><td>");
00378 wprintf(_("Default character set for email headers:"));
00379 wprintf("</td><td>");
00380 wprintf("<input type=\"text\" NAME=\"default_header_charset\" MAXLENGTH=\"32\" VALUE=\"%s\">", buf);
00381 wprintf("</td></tr>");
00382
00384 wprintf("</table>\n"
00385 "<input type=\"submit\" name=\"change_button\" value=\"%s\">"
00386 " "
00387 "<INPUT type=\"submit\" name=\"cancel_button\" value=\"%s\">\n",
00388 _("Change"),
00389 _("Cancel")
00390 );
00391
00393 wprintf("</form></center>\n");
00394 wprintf("</td></tr></table></div>\n");
00395 wDumpContent(1);
00396 }
00397
00401 void set_preferences(void)
00402 {
00403 char ebuf[300];
00404
00405 if (strlen(bstr("change_button")) == 0) {
00406 safestrncpy(WC->ImportantMessage,
00407 _("Cancelled. No settings were changed."),
00408 sizeof WC->ImportantMessage);
00409 display_main_menu();
00410 return;
00411 }
00412
00417 set_preference("roomlistview", bstr("roomlistview"), 0);
00418 set_preference("calhourformat", bstr("calhourformat"), 0);
00419 set_preference("use_sig", bstr("use_sig"), 0);
00420 set_preference("daystart", bstr("daystart"), 0);
00421 set_preference("dayend", bstr("dayend"), 0);
00422 set_preference("default_header_charset", bstr("default_header_charset"), 0);
00423
00424 euid_escapize(ebuf, bstr("signature"));
00425 set_preference("signature", ebuf, 1);
00426
00427 display_main_menu();
00428 }
00429
00430