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);
180 wprintf("<div id=\"banner\">\n");
181 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
182 wprintf("<IMG SRC=\"/static/advanpage2_48x.gif\" ALT=\" \" ALIGN=MIDDLE>");
183 wprintf("<SPAN CLASS=\"titlebar\"> ");
184 wprintf(_("Preferences and settings"));
185 wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
187 wprintf("</TD></TR></TABLE>\n");
189 "<div id=\"content\">\n");
191 wprintf("<div id=\"fix_scrollbar_bug\">"
192 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
196 "<form name=\"prefform\" action=\"set_preferences\" "
198 "<table border=0 cellspacing=5 cellpadding=5>\n");
203 get_preference("roomlistview", buf, sizeof buf);
205 wprintf(_("Room list view"));
206 wprintf("</td><td>");
208 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"folders\"");
209 if (!strcasecmp(buf, "folders")) wprintf(" checked");
211 wprintf(_("Tree (folders) view"));
212 wprintf("<br></input>\n");
214 wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"rooms\"");
215 if (!strcasecmp(buf, "rooms")) wprintf(" checked");
217 wprintf(_("Table (rooms) view"));
218 wprintf("<br></input>\n");
220 wprintf("</td></tr>\n");
223 * Calendar hour format
225 get_preference("calhourformat", buf, sizeof buf);
226 if (buf[0] == 0) strcpy(buf, "12");
228 wprintf(_("Calendar hour format"));
229 wprintf("</td><td>");
231 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
232 if (!strcasecmp(buf, "12")) wprintf(" checked");
234 wprintf(_("12 hour (am/pm)"));
235 wprintf("<br></input>\n");
237 wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
238 if (!strcasecmp(buf, "24")) wprintf(" checked");
240 wprintf(_("24 hour"));
241 wprintf("<br></input>\n");
243 wprintf("</td></tr>\n");
248 get_preference("use_sig", buf, sizeof buf);
249 if (buf[0] == 0) strcpy(buf, "no");
251 wprintf(_("Attach signature to email messages?"));
252 wprintf("</td><td>");
254 wprintf(" <script type=\"text/javascript\"> "
255 " function show_or_hide_sigbox() { "
256 " if ( $F('yes_sig') ) { "
257 " $('signature_box').style.display = 'inline'; "
260 " $('signature_box').style.display = 'none'; "
266 wprintf("<input type=\"radio\" id=\"no_sig\" name=\"use_sig\" VALUE=\"no\"");
267 if (!strcasecmp(buf, "no")) wprintf(" checked");
268 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
269 wprintf(_("No signature"));
270 wprintf("<br></input>\n");
272 wprintf("<input type=\"radio\" id=\"yes_sig\" name=\"use_sig\" VALUE=\"yes\"");
273 if (!strcasecmp(buf, "yes")) wprintf(" checked");
274 wprintf(" onChange=\"show_or_hide_sigbox();\" >");
275 wprintf(_("Use this signature:"));
276 wprintf("<div id=\"signature_box\">"
277 "<br><textarea name=\"signature\" cols=\"40\" rows=\"5\">"
279 get_preference("signature", ebuf, sizeof ebuf);
280 euid_unescapize(buf, ebuf);
282 wprintf("</textarea>"
286 wprintf("<br></input>\n");
288 wprintf("</td></tr>\n");
290 wprintf(" <script type=\"text/javascript\"> "
291 " show_or_hide_sigbox(); "
297 "<input type=\"submit\" name=\"change_button\" value=\"%s\">"
299 "<INPUT type=\"submit\" name=\"cancel_button\" value=\"%s\">\n",
304 wprintf("</form></center>\n");
309 wprintf("</td></tr></table></div>\n");
314 * Commit new preferences and settings
316 void set_preferences(void)
320 if (strlen(bstr("change_button")) == 0) {
321 safestrncpy(WC->ImportantMessage,
322 _("Cancelled. No settings were changed."),
323 sizeof WC->ImportantMessage);
328 /* Set the last argument to 1 only for the final setting, so
329 * we don't send the prefs file to the server repeatedly
331 set_preference("roomlistview", bstr("roomlistview"), 0);
332 set_preference("calhourformat", bstr("calhourformat"), 0);
333 set_preference("use_sig", bstr("use_sig"), 0);
335 euid_escapize(ebuf, bstr("signature"));
336 set_preference("signature", ebuf, 1);