4 * Displays and customizes the iconbar.
9 /* Values for ib_displayas ... don't change these or you will break the templates */
10 #define IB_PICTEXT 0 /* picture and text */
11 #define IB_PICONLY 1 /* just a picture */
12 #define IB_TEXTONLY 2 /* just text */
14 void DontDeleteThis(void *Data){}
16 #define IconbarIsEnabled(a, b) IconbarIsENABLED(a, sizeof(a) - 1, b)
18 long IconbarIsENABLED(const char *key, size_t keylen, long defval)
26 if (GetHash(WCC->IconBarSettings,
36 #ifdef DBG_ICONBAR_HASH
38 inline const char *PrintInt(void *Prefstr)
40 snprintf(nbuf, sizeof(nbuf), "%ld", (long)Prefstr);
45 /* Produces a stylesheet which hides any iconbar icons the user does not want */
46 void doUserIconStylesheet(void) {
53 output_custom_content_header("text/css");
54 hprintf("Cache-Control: private\r\n");
57 wprintf("#global { left: 16%%; }\r\n");
58 pos = GetNewHashPos(WC->IconBarSettings, 0);
59 while(GetNextHashPos(WC->IconBarSettings, pos, &HKLen, &key, &Data)) {
62 && strncasecmp("ib_displayas",key,12)
63 && strncasecmp("ib_logoff", key, 9)) {
64 /* Don't shoot me for this */
65 wprintf("#%s { display: none !important; }\r\n",key);
66 } else if (!strncasecmp("ib_users",key, 8) && value == 2) {
67 wprintf("#online_users { display: block; !important } \r\n");
74 int ConditionalIsActiveStylesheet(StrBuf *Target, WCTemplputParams *TP) {
75 long testFor = TP->Tokens->Params[3]->lvalue;
76 int ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
77 return (testFor == ib_displayas);
80 void LoadIconSettings(StrBuf *iconbar, long lvalue)
90 if (WCC->IconBarSettings == NULL)
91 WCC->IconBarSettings = NewHash(1, NULL);
93 * The initialized values of these variables also happen to
94 * specify the default values for users who haven't customized
95 * their iconbars. These should probably be set in a master
96 * configuration somewhere.
99 nTokens = StrBufNum_tokens(iconbar, ',');
100 for (i=0; i<nTokens; ++i) {
101 StrBufExtract_token(buf, iconbar, i, ',');
102 StrBufExtract_token(key, buf, 0, '=');
103 val = StrBufExtract_long(buf, 1, '=');
104 Put(WCC->IconBarSettings,
105 ChrPtr(key), StrLength(key),
106 (void*)val, DontDeleteThis);
109 #ifdef DBG_ICONBAR_HASH
110 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
118 * display a customized version of the iconbar
120 void display_customize_iconbar(void) {
127 output_headers(1, 1, 2, 0, 0, 0);
128 wprintf("<div id=\"banner\">");
130 wprintf(_("Customize the icon bar"));
131 wprintf("</h1></div>\n");
133 wprintf("<div id=\"content\" class=\"service\">\n");
135 wprintf("<div class=\"fix_scrollbar_bug\">");
137 wprintf("<form method=\"post\" action=\"commit_iconbar\">\n");
138 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
140 wprintf("<table class=\"altern\" >\n");
141 wprintf("<tr><td></td><td colspan=\"2\"><b>");
142 wprintf(_("Display icons as:"));
144 ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
145 for (i=0; i<=2; ++i) {
146 wprintf("<input type=\"radio\" name=\"ib_displayas\" value=\"%d\"", i);
147 if (ib_displayas == i) wprintf(" CHECKED");
149 if (i == IB_PICTEXT) wprintf(_("pictures and text"));
150 if (i == IB_PICONLY) wprintf(_("pictures only"));
151 if (i == IB_TEXTONLY) wprintf(_("text only"));
156 wprintf(_("Select the icons you would like to see displayed "
157 "in the 'icon bar' menu on the left side of the "
159 wprintf("</td></tr>\n");
162 val = IconbarIsEnabled("ib_logo", 0);
163 wprintf("<tr class=\"%s\"><td>"
164 "<input type=\"radio\" name=\"ib_logo\" value=\"yes\" %s> %s "
165 "<input type=\"radio\" name=\"ib_logo\" value=\"no\" %s> %s <br />"
167 "<img src=\"image&name=hello\" width=\"48\" alt=\" \">"
172 (bar ? "even" : "odd"),
173 (val ? "CHECKED" : ""),_("Yes"),
174 (!val ? "CHECKED" : ""),_("No"),
176 _("An icon describing this site")
180 val = IconbarIsEnabled("ib_summary", 1);
181 wprintf("<tr class=\"%s\"><td>"
182 "<input type=\"radio\" name=\"ib_summary\" value=\"yes\" %s> %s "
183 "<input type=\"radio\" name=\"ib_summary\" value=\"no\" %s> %s <br />"
185 "<img src=\"static/summscreen_48x.gif\" alt=\" \">"
190 (bar ? "even" : "odd"),
191 (val ? "CHECKED" : ""),_("Yes"),
192 (!val ? "CHECKED" : ""),_("No"),
194 _("Your summary page")
198 val = IconbarIsEnabled("ib_inbox", 1);
199 wprintf("<tr class=\"%s\"><td>"
200 "<input type=\"radio\" name=\"ib_inbox\" value=\"yes\" %s> %s "
201 "<input type=\"radio\" name=\"ib_inbox\" value=\"no\" %s> %s <br />"
203 "<img src=\"static/privatemess_48x.gif\" alt=\" \">"
208 (bar ? "even" : "odd"),
209 (val ? "CHECKED" : ""),_("Yes"),
210 (!val ? "CHECKED" : ""),_("No"),
212 _("A shortcut to your email Inbox")
216 val = IconbarIsEnabled("ib_contacts", 1);
217 wprintf("<tr class=\"%s\"><td>"
218 "<input type=\"radio\" name=\"ib_contacts\" value=\"yes\" %s> %s "
219 "<input type=\"radio\" name=\"ib_contacts\" value=\"no\" %s> %s <br />"
221 "<img src=\"static/viewcontacts_48x.gif\" alt=\" \">"
226 (bar ? "even" : "odd"),
227 (val ? "CHECKED" : ""),_("Yes"),
228 (!val ? "CHECKED" : ""),_("No"),
230 _("Your personal address book")
234 val = IconbarIsEnabled("ib_notes", 1);
235 wprintf("<tr class=\"%s\"><td>"
236 "<input type=\"radio\" name=\"ib_notes\" value=\"yes\" %s> %s "
237 "<input type=\"radio\" name=\"ib_notes\" value=\"no\" %s> %s <br />"
239 "<img src=\"static/storenotes_48x.gif\" alt=\" \">"
244 (bar ? "even" : "odd"),
245 (val ? "CHECKED" : ""),_("Yes"),
246 (!val ? "CHECKED" : ""),_("No"),
248 _("Your personal notes")
252 val = IconbarIsEnabled("ib_calendar", 1);
253 wprintf("<tr class=\"%s\"><td>"
254 "<input type=\"radio\" name=\"ib_calendar\" value=\"yes\" %s> %s "
255 "<input type=\"radio\" name=\"ib_calendar\" value=\"no\" %s> %s <br />"
257 "<img src=\"static/calarea_48x.gif\" alt=\" \">"
262 (bar ? "even" : "odd"),
263 (val ? "CHECKED" : ""),_("Yes"),
264 (!val ? "CHECKED" : ""),_("No"),
266 _("A shortcut to your personal calendar")
270 val = IconbarIsEnabled("ib_tasks", 1);
271 wprintf("<tr class=\"%s\"><td>"
272 "<input type=\"radio\" name=\"ib_tasks\" value=\"yes\" %s> %s "
273 "<input type=\"radio\" name=\"ib_tasks\" value=\"no\" %s> %s <br />"
275 "<img src=\"static/taskmanag_48x.gif\" alt=\" \">"
280 (bar ? "even" : "odd"),
281 (val ? "CHECKED" : ""),_("Yes"),
282 (!val ? "CHECKED" : ""),_("No"),
284 _("A shortcut to your personal task list")
288 val = IconbarIsEnabled("ib_rooms", 1);
289 wprintf("<tr class=\"%s\"><td>"
290 "<input type=\"radio\" name=\"ib_rooms\" value=\"yes\" %s> %s "
291 "<input type=\"radio\" name=\"ib_rooms\" value=\"no\" %s> %s <br />"
293 "<img src=\"static/chatrooms_48x.gif\" alt=\" \">"
298 (bar ? "even" : "odd"),
299 (val ? "CHECKED" : ""),_("Yes"),
300 (!val ? "CHECKED" : ""),_("No"),
302 _("Clicking this icon displays a list of all accessible "
303 "rooms (or folders) available.")
307 val = IconbarIsEnabled("ib_users", 1);
308 wprintf("<tr class=\"%s\"><td>"
309 "<input type=\"radio\" name=\"ib_users\" value=\"yes\" %s> %s "
310 "<input type=\"radio\" name=\"ib_users\" value=\"no\" %s> %s <br />"
311 "<input type=\"radio\" name=\"ib_users\" value=\"yeslist\" %s> %s"
313 "<img src=\"static/usermanag_48x.gif\" alt=\" \">"
318 (bar ? "even" : "odd"),
319 (val ? "CHECKED" : ""),_("Yes"),
320 (!val ? "CHECKED" : ""),_("No"),
321 ((val > 1) ? "CHECKED" : ""),_("Yes with users list"),
323 _("Clicking this icon displays a list of all users "
324 "currently logged in.")
328 val = IconbarIsEnabled("ib_chat", 1);
329 wprintf("<tr class=\"%s\"><td>"
330 "<input type=\"radio\" name=\"ib_chat\" value=\"yes\" %s> %s "
331 "<input type=\"radio\" name=\"ib_chat\" value=\"no\" %s> %s <br />"
333 "<img src=\"static/citadelchat_48x.gif\" alt=\" \">"
338 (bar ? "even" : "odd"),
339 (val ? "CHECKED" : ""),_("Yes"),
340 (!val ? "CHECKED" : ""),_("No"),
342 _("Clicking this icon enters real-time chat mode "
343 "with other users in the same room.")
348 val = IconbarIsEnabled("ib_advanced", 1);
349 wprintf("<tr class=\"%s\"><td>"
350 "<input type=\"radio\" name=\"ib_advanced\" value=\"yes\" %s> %s "
351 "<input type=\"radio\" name=\"ib_advanced\" value=\"no\" %s> %s <br />"
353 "<img src=\"static/advanpage2_48x.gif\" alt=\" \">"
358 (bar ? "even" : "odd"),
359 (val ? "CHECKED" : ""),_("Yes"),
360 (!val ? "CHECKED" : ""),_("No"),
361 _("Advanced options"),
362 _("Access to the complete menu of Citadel functions.")
367 val = IconbarIsEnabled("ib_citadel", 1);
368 wprintf("<tr class=\"%s\"><td>"
369 "<input type=\"radio\" name=\"ib_citadel\" value=\"yes\" %s> %s "
370 "<input type=\"radio\" name=\"ib_citadel\" value=\"no\" %s> %s <br />"
372 "<img border=\"0\" width=\"48\" height=\"48\" "
373 "src=\"static/citadel-logo.gif\" alt=\" \">"
378 (bar ? "even" : "odd"),
379 (val ? "CHECKED" : ""),_("Yes"),
380 (!val ? "CHECKED" : ""),_("No"),
382 _("Displays the 'Powered by Citadel' icon")
385 wprintf("</table><br />\n"
387 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
389 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
395 wprintf("</form></div>\n");
400 * save changes to iconbar settings
402 void commit_iconbar(void) {
423 if (!havebstr("ok_button")) {
428 iconbar = NewStrBuf();
430 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
431 for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
433 if (!strcasecmp(BSTR(boxen[i]), "yes")) {
436 else if (!strcasecmp(BSTR(boxen[i]), "yeslist")) {
442 StrBufPrintf(buf, ",%s=%s", boxen[i], Val);
443 StrBufAppendBuf(iconbar, buf, 0);
447 set_preference("iconbar", iconbar, 1);
449 output_headers(1, 1, 2, 0, 0, 0);
451 wprintf("<div id=\"banner\">\n");
453 wprintf(_("Customize the icon bar"));
454 wprintf("</h1></div>\n");
456 wprintf("<div id=\"content\" class=\"service\">\n");
458 "<center><table border=1 bgcolor=\"#ffffff\"><tr><td>"
459 "<img src=\"static/advanpage2_48x.gif\">"
461 wprintf(_("Your icon bar has been updated. Please select any of its "
462 "choices to continue.<br/><span style=\"font-weight: bold;\">You may need to force refresh (SHIFT-F5) in order for changes to take effect</span>"));
463 wprintf("</td></tr></table>\n");
465 #ifdef DBG_ICONBAR_HASH
466 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
471 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
475 if ((WCC != NULL) && (WCC->logged_in)) {
476 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
484 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
485 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
486 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
487 WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0);
488 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0);
490 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
496 SessionDestroyModule_ICONBAR
499 DeleteHash(&sess->IconBarSettings);