4 * Manage user preferences with a little help from the Citadel server.
14 void load_preferences(void) {
18 serv_printf("GOTO %s", USERCONFIGROOM);
19 serv_getln(buf, sizeof buf);
20 if (buf[0] != '2') return;
22 serv_puts("MSGS ALL|0|1");
23 serv_getln(buf, sizeof buf);
25 serv_puts("subj|__ WebCit Preferences __");
28 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
33 serv_printf("MSG0 %ld", msgnum);
34 serv_getln(buf, sizeof buf);
36 while (serv_getln(buf, sizeof buf),
37 (strcmp(buf, "text") && strcmp(buf, "000"))) {
39 if (!strcmp(buf, "text")) {
40 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
41 if (WC->preferences == NULL) {
42 WC->preferences = malloc(SIZ);
43 strcpy(WC->preferences, "");
46 WC->preferences = realloc(
48 strlen(WC->preferences)
52 strcat(WC->preferences, buf);
53 strcat(WC->preferences, "\n");
59 /* Go back to the room we're supposed to be in */
60 serv_printf("GOTO %s", WC->wc_roomname);
61 serv_getln(buf, sizeof buf);
65 * Goto the user's configuration room, creating it if necessary.
66 * Returns 0 on success or nonzero upon failure.
68 int goto_config_room(void) {
71 serv_printf("GOTO %s", USERCONFIGROOM);
72 serv_getln(buf, sizeof buf);
73 if (buf[0] != '2') { /* try to create the config room if not there */
74 serv_printf("CRE8 1|%s|4|0", USERCONFIGROOM);
75 serv_getln(buf, sizeof buf);
76 serv_printf("GOTO %s", USERCONFIGROOM);
77 serv_getln(buf, sizeof buf);
78 if (buf[0] != '2') return(1);
84 void save_preferences(void) {
88 if (goto_config_room() != 0) return; /* oh well. */
89 serv_puts("MSGS ALL|0|1");
90 serv_getln(buf, sizeof buf);
92 serv_puts("subj|__ WebCit Preferences __");
95 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
100 serv_printf("DELE %ld", msgnum);
101 serv_getln(buf, sizeof buf);
104 serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
105 serv_getln(buf, sizeof buf);
107 serv_puts(WC->preferences);
112 /* Go back to the room we're supposed to be in */
113 serv_printf("GOTO %s", WC->wc_roomname);
114 serv_getln(buf, sizeof buf);
117 void get_preference(char *key, char *value, size_t value_len) {
125 num_prefs = num_tokens(WC->preferences, '\n');
126 for (i=0; i<num_prefs; ++i) {
127 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
128 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
129 if (!strcasecmp(thiskey, key)) {
130 extract_token(value, buf, 1, '|', value_len);
135 void set_preference(char *key, char *value, int save_to_server) {
140 char *newprefs = NULL;
142 num_prefs = num_tokens(WC->preferences, '\n');
143 for (i=0; i<num_prefs; ++i) {
144 extract_token(buf, WC->preferences, i, '\n', sizeof buf);
145 if (num_tokens(buf, '|') == 2) {
146 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
147 if (strcasecmp(thiskey, key)) {
148 if (newprefs == NULL) newprefs = strdup("");
149 newprefs = realloc(newprefs,
150 strlen(newprefs) + SIZ );
151 strcat(newprefs, buf);
152 strcat(newprefs, "\n");
158 if (newprefs == NULL) newprefs = strdup("");
159 newprefs = realloc(newprefs, strlen(newprefs) + SIZ);
160 sprintf(&newprefs[strlen(newprefs)], "%s|%s\n", key, value);
162 free(WC->preferences);
163 WC->preferences = newprefs;
165 if (save_to_server) save_preferences();
172 * display form for changing your preferences and settings
174 void display_preferences(void)
176 output_headers(1, 1, 2, 0, 0, 0);
179 char calhourformat[16];
182 wprintf("<div id=\"banner\">\n");
183 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
184 wprintf("<img src=\"static/advanpage2_48x.gif\" ALT=\" \" ALIGN=MIDDLE>");
185 wprintf("<SPAN CLASS=\"titlebar\"> ");
186 wprintf(_("Preferences and settings"));
187 wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
189 wprintf("</TD></TR></TABLE>\n");
191 "<div id=\"content\">\n");
193 wprintf("<div id=\"fix_scrollbar_bug\">"
194 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
198 "<form name=\"prefform\" action=\"set_preferences\" "
200 "<table border=0 cellspacing=5 cellpadding=5>\n");
205 get_preference("roomlistview", buf, sizeof buf);
207 wprintf(_("Room list view"));
208 wprintf("</td><td>");
210 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"folders\"");
211 if (!strcasecmp(buf, "folders")) wprintf(" checked");
213 wprintf(_("Tree (folders) view"));
214 wprintf("<br></input>\n");
216 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"rooms\"");
217 if (!strcasecmp(buf, "rooms")) wprintf(" checked");
219 wprintf(_("Table (rooms) view"));
220 wprintf("<br></input>\n");
222 wprintf("</td></tr>\n");
225 * Calendar hour format
227 get_preference("calhourformat", calhourformat, sizeof calhourformat);
228 if (calhourformat[0] == 0) strcpy(calhourformat, "12");
230 wprintf(_("Calendar hour format"));
231 wprintf("</td><td>");
233 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
234 if (!strcasecmp(calhourformat, "12")) wprintf(" checked");
236 wprintf(_("12 hour (am/pm)"));
237 wprintf("<br></input>\n");
239 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
240 if (!strcasecmp(calhourformat, "24")) wprintf(" checked");
242 wprintf(_("24 hour"));
243 wprintf("<br></input>\n");
245 wprintf("</td></tr>\n");
248 * Calendar day view -- day start time
250 get_preference("daystart", buf, sizeof buf);
251 if (buf[0] == 0) strcpy(buf, "8");
253 wprintf(_("Calendar day view begins at:"));
254 wprintf("</td><td>");
256 wprintf("<SELECT NAME=\"daystart\" SIZE=\"1\">\n");
257 for (i=0; i<=23; ++i) {
259 if (!strcasecmp(calhourformat, "24")) {
260 wprintf("<OPTION %s VALUE=\"%d\">%d:00</OPTION>\n",
261 ((atoi(buf) == i) ? "SELECTED" : ""),
266 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
267 ((atoi(buf) == i) ? "SELECTED" : ""),
273 wprintf("</SELECT>\n");
274 wprintf("</td></tr>\n");
277 * Calendar day view -- day end time
279 get_preference("dayend", buf, sizeof buf);
280 if (buf[0] == 0) strcpy(buf, "17");
282 wprintf(_("Calendar day view ends at:"));
283 wprintf("</td><td>");
285 wprintf("<SELECT NAME=\"dayend\" SIZE=\"1\">\n");
286 for (i=0; i<=23; ++i) {
288 if (!strcasecmp(calhourformat, "24")) {
289 wprintf("<OPTION %s VALUE=\"%d\">%d:00</OPTION>\n",
290 ((atoi(buf) == i) ? "SELECTED" : ""),
295 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
296 ((atoi(buf) == i) ? "SELECTED" : ""),
302 wprintf("</SELECT>\n");
303 wprintf("</td></tr>\n");
308 get_preference("use_sig", buf, sizeof buf);
309 if (buf[0] == 0) strcpy(buf, "no");
311 wprintf(_("Attach signature to email messages?"));
312 wprintf("</td><td>");
314 wprintf(" <script type=\"text/javascript\"> "
315 " function show_or_hide_sigbox() { "
316 " if ( $F('yes_sig') ) { "
317 " $('signature_box').style.display = 'inline'; "
320 " $('signature_box').style.display = 'none'; "
326 wprintf("<input type=\"radio\" id=\"no_sig\" name=\"use_sig\" VALUE=\"no\"");
327 if (!strcasecmp(buf, "no")) wprintf(" checked");
328 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
329 wprintf(_("No signature"));
330 wprintf("<br></input>\n");
332 wprintf("<input type=\"radio\" id=\"yes_sig\" name=\"use_sig\" VALUE=\"yes\"");
333 if (!strcasecmp(buf, "yes")) wprintf(" checked");
334 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
335 wprintf(_("Use this signature:"));
336 wprintf("<div id=\"signature_box\">"
337 "<br><textarea name=\"signature\" cols=\"40\" rows=\"5\">"
339 get_preference("signature", ebuf, sizeof ebuf);
340 euid_unescapize(buf, ebuf);
342 wprintf("</textarea>"
346 wprintf("<br></input>\n");
348 wprintf("</td></tr>\n");
350 wprintf(" <script type=\"text/javascript\"> "
351 " show_or_hide_sigbox(); "
357 "<input type=\"submit\" name=\"change_button\" value=\"%s\">"
359 "<INPUT type=\"submit\" name=\"cancel_button\" value=\"%s\">\n",
364 wprintf("</form></center>\n");
369 wprintf("</td></tr></table></div>\n");
374 * Commit new preferences and settings
376 void set_preferences(void)
380 if (strlen(bstr("change_button")) == 0) {
381 safestrncpy(WC->ImportantMessage,
382 _("Cancelled. No settings were changed."),
383 sizeof WC->ImportantMessage);
388 /* Set the last argument to 1 only for the final setting, so
389 * we don't send the prefs file to the server repeatedly
391 set_preference("roomlistview", bstr("roomlistview"), 0);
392 set_preference("calhourformat", bstr("calhourformat"), 0);
393 set_preference("use_sig", bstr("use_sig"), 0);
394 set_preference("daystart", bstr("daystart"), 0);
395 set_preference("dayend", bstr("dayend"), 0);
397 euid_escapize(ebuf, bstr("signature"));
398 set_preference("signature", ebuf, 1);