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) {
78 testFor = GetTemplateTokenNumber(Target, TP, 3, IB_PICTEXT);
79 ib_displayas = IconbarIsEnabled("ib_displayas", IB_PICTEXT);
80 return (testFor == ib_displayas);
83 void LoadIconSettings(StrBuf *iconbar, long lvalue)
93 if (WCC->IconBarSettings == NULL)
94 WCC->IconBarSettings = NewHash(1, NULL);
96 * The initialized values of these variables also happen to
97 * specify the default values for users who haven't customized
98 * their iconbars. These should probably be set in a master
99 * configuration somewhere.
102 nTokens = StrBufNum_tokens(iconbar, ',');
103 for (i=0; i<nTokens; ++i) {
104 StrBufExtract_token(buf, iconbar, i, ',');
105 StrBufExtract_token(key, buf, 0, '=');
106 val = StrBufExtract_long(buf, 1, '=');
107 Put(WCC->IconBarSettings,
108 ChrPtr(key), StrLength(key),
109 (void*)val, DontDeleteThis);
112 #ifdef DBG_ICONBAR_HASH
113 dbg_PrintHash(WCC->IconBarSetttings, PrintInt, NULL);
121 * display a customized version of the iconbar
123 void display_customize_iconbar(void) {
130 output_headers(1, 1, 2, 0, 0, 0);
131 wprintf("<div id=\"banner\">");
133 wprintf(_("Customize the icon bar"));
134 wprintf("</h1></div>\n");
136 wprintf("<div id=\"content\" class=\"service\">\n");
138 wprintf("<div class=\"fix_scrollbar_bug\">");
140 wprintf("<form method=\"post\" action=\"commit_iconbar\">\n");
141 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
143 wprintf("<table class=\"altern\" >\n");
144 wprintf("<tr><td></td><td colspan=\"2\"><b>");
145 wprintf(_("Display icons as:"));
147 ib_displayas = IconbarIsEnabled("ib_displayas",IB_PICTEXT);
148 for (i=0; i<=2; ++i) {
149 wprintf("<input type=\"radio\" name=\"ib_displayas\" value=\"%d\"", i);
150 if (ib_displayas == i) wprintf(" CHECKED");
152 if (i == IB_PICTEXT) wprintf(_("pictures and text"));
153 if (i == IB_PICONLY) wprintf(_("pictures only"));
154 if (i == IB_TEXTONLY) wprintf(_("text only"));
159 wprintf(_("Select the icons you would like to see displayed "
160 "in the 'icon bar' menu on the left side of the "
162 wprintf("</td></tr>\n");
165 val = IconbarIsEnabled("ib_logo", 0);
166 wprintf("<tr class=\"%s\"><td>"
167 "<input type=\"radio\" name=\"ib_logo\" value=\"yes\" %s> %s "
168 "<input type=\"radio\" name=\"ib_logo\" value=\"no\" %s> %s <br />"
170 "<img src=\"image&name=hello\" width=\"48\" alt=\" \">"
175 (bar ? "even" : "odd"),
176 (val ? "CHECKED" : ""),_("Yes"),
177 (!val ? "CHECKED" : ""),_("No"),
179 _("An icon describing this site")
183 val = IconbarIsEnabled("ib_summary", 1);
184 wprintf("<tr class=\"%s\"><td>"
185 "<input type=\"radio\" name=\"ib_summary\" value=\"yes\" %s> %s "
186 "<input type=\"radio\" name=\"ib_summary\" value=\"no\" %s> %s <br />"
188 "<img src=\"static/summscreen_48x.gif\" alt=\" \">"
193 (bar ? "even" : "odd"),
194 (val ? "CHECKED" : ""),_("Yes"),
195 (!val ? "CHECKED" : ""),_("No"),
197 _("Your summary page")
201 val = IconbarIsEnabled("ib_inbox", 1);
202 wprintf("<tr class=\"%s\"><td>"
203 "<input type=\"radio\" name=\"ib_inbox\" value=\"yes\" %s> %s "
204 "<input type=\"radio\" name=\"ib_inbox\" value=\"no\" %s> %s <br />"
206 "<img src=\"static/privatemess_48x.gif\" alt=\" \">"
211 (bar ? "even" : "odd"),
212 (val ? "CHECKED" : ""),_("Yes"),
213 (!val ? "CHECKED" : ""),_("No"),
215 _("A shortcut to your email Inbox")
219 val = IconbarIsEnabled("ib_contacts", 1);
220 wprintf("<tr class=\"%s\"><td>"
221 "<input type=\"radio\" name=\"ib_contacts\" value=\"yes\" %s> %s "
222 "<input type=\"radio\" name=\"ib_contacts\" value=\"no\" %s> %s <br />"
224 "<img src=\"static/viewcontacts_48x.gif\" alt=\" \">"
229 (bar ? "even" : "odd"),
230 (val ? "CHECKED" : ""),_("Yes"),
231 (!val ? "CHECKED" : ""),_("No"),
233 _("Your personal address book")
237 val = IconbarIsEnabled("ib_notes", 1);
238 wprintf("<tr class=\"%s\"><td>"
239 "<input type=\"radio\" name=\"ib_notes\" value=\"yes\" %s> %s "
240 "<input type=\"radio\" name=\"ib_notes\" value=\"no\" %s> %s <br />"
242 "<img src=\"static/storenotes_48x.gif\" alt=\" \">"
247 (bar ? "even" : "odd"),
248 (val ? "CHECKED" : ""),_("Yes"),
249 (!val ? "CHECKED" : ""),_("No"),
251 _("Your personal notes")
255 val = IconbarIsEnabled("ib_calendar", 1);
256 wprintf("<tr class=\"%s\"><td>"
257 "<input type=\"radio\" name=\"ib_calendar\" value=\"yes\" %s> %s "
258 "<input type=\"radio\" name=\"ib_calendar\" value=\"no\" %s> %s <br />"
260 "<img src=\"static/calarea_48x.gif\" alt=\" \">"
265 (bar ? "even" : "odd"),
266 (val ? "CHECKED" : ""),_("Yes"),
267 (!val ? "CHECKED" : ""),_("No"),
269 _("A shortcut to your personal calendar")
273 val = IconbarIsEnabled("ib_tasks", 1);
274 wprintf("<tr class=\"%s\"><td>"
275 "<input type=\"radio\" name=\"ib_tasks\" value=\"yes\" %s> %s "
276 "<input type=\"radio\" name=\"ib_tasks\" value=\"no\" %s> %s <br />"
278 "<img src=\"static/taskmanag_48x.gif\" alt=\" \">"
283 (bar ? "even" : "odd"),
284 (val ? "CHECKED" : ""),_("Yes"),
285 (!val ? "CHECKED" : ""),_("No"),
287 _("A shortcut to your personal task list")
291 val = IconbarIsEnabled("ib_rooms", 1);
292 wprintf("<tr class=\"%s\"><td>"
293 "<input type=\"radio\" name=\"ib_rooms\" value=\"yes\" %s> %s "
294 "<input type=\"radio\" name=\"ib_rooms\" value=\"no\" %s> %s <br />"
296 "<img src=\"static/chatrooms_48x.gif\" alt=\" \">"
301 (bar ? "even" : "odd"),
302 (val ? "CHECKED" : ""),_("Yes"),
303 (!val ? "CHECKED" : ""),_("No"),
305 _("Clicking this icon displays a list of all accessible "
306 "rooms (or folders) available.")
310 val = IconbarIsEnabled("ib_users", 1);
311 wprintf("<tr class=\"%s\"><td>"
312 "<input type=\"radio\" name=\"ib_users\" value=\"yes\" %s> %s "
313 "<input type=\"radio\" name=\"ib_users\" value=\"no\" %s> %s <br />"
314 "<input type=\"radio\" name=\"ib_users\" value=\"yeslist\" %s> %s"
316 "<img src=\"static/usermanag_48x.gif\" alt=\" \">"
321 (bar ? "even" : "odd"),
322 (val ? "CHECKED" : ""),_("Yes"),
323 (!val ? "CHECKED" : ""),_("No"),
324 ((val > 1) ? "CHECKED" : ""),_("Yes with users list"),
326 _("Clicking this icon displays a list of all users "
327 "currently logged in.")
331 val = IconbarIsEnabled("ib_chat", 1);
332 wprintf("<tr class=\"%s\"><td>"
333 "<input type=\"radio\" name=\"ib_chat\" value=\"yes\" %s> %s "
334 "<input type=\"radio\" name=\"ib_chat\" value=\"no\" %s> %s <br />"
336 "<img src=\"static/citadelchat_48x.gif\" alt=\" \">"
341 (bar ? "even" : "odd"),
342 (val ? "CHECKED" : ""),_("Yes"),
343 (!val ? "CHECKED" : ""),_("No"),
345 _("Clicking this icon enters real-time chat mode "
346 "with other users in the same room.")
351 val = IconbarIsEnabled("ib_advanced", 1);
352 wprintf("<tr class=\"%s\"><td>"
353 "<input type=\"radio\" name=\"ib_advanced\" value=\"yes\" %s> %s "
354 "<input type=\"radio\" name=\"ib_advanced\" value=\"no\" %s> %s <br />"
356 "<img src=\"static/advanpage2_48x.gif\" alt=\" \">"
361 (bar ? "even" : "odd"),
362 (val ? "CHECKED" : ""),_("Yes"),
363 (!val ? "CHECKED" : ""),_("No"),
364 _("Advanced options"),
365 _("Access to the complete menu of Citadel functions.")
370 val = IconbarIsEnabled("ib_citadel", 1);
371 wprintf("<tr class=\"%s\"><td>"
372 "<input type=\"radio\" name=\"ib_citadel\" value=\"yes\" %s> %s "
373 "<input type=\"radio\" name=\"ib_citadel\" value=\"no\" %s> %s <br />"
375 "<img border=\"0\" width=\"48\" height=\"48\" "
376 "src=\"static/citadel-logo.gif\" alt=\" \">"
381 (bar ? "even" : "odd"),
382 (val ? "CHECKED" : ""),_("Yes"),
383 (!val ? "CHECKED" : ""),_("No"),
385 _("Displays the 'Powered by Citadel' icon")
388 wprintf("</table><br />\n"
390 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
392 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
398 wprintf("</form></div>\n");
403 * save changes to iconbar settings
405 void commit_iconbar(void) {
426 if (!havebstr("ok_button")) {
431 iconbar = NewStrBuf();
433 StrBufPrintf(iconbar, "ib_displayas=%d", ibstr("ib_displayas"));
434 for (i=0; i<(sizeof(boxen)/sizeof(char *)); ++i) {
436 if (!strcasecmp(BSTR(boxen[i]), "yes")) {
439 else if (!strcasecmp(BSTR(boxen[i]), "yeslist")) {
445 StrBufPrintf(buf, ",%s=%s", boxen[i], Val);
446 StrBufAppendBuf(iconbar, buf, 0);
450 set_preference("iconbar", iconbar, 1);
452 output_headers(1, 1, 2, 0, 0, 0);
454 wprintf("<div id=\"banner\">\n");
456 wprintf(_("Customize the icon bar"));
457 wprintf("</h1></div>\n");
459 wprintf("<div id=\"content\" class=\"service\">\n");
461 "<center><table border=1 bgcolor=\"#ffffff\"><tr><td>"
462 "<img src=\"static/advanpage2_48x.gif\">"
464 wprintf(_("Your icon bar has been updated. Please select any of its "
465 "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>"));
466 wprintf("</td></tr></table>\n");
468 #ifdef DBG_ICONBAR_HASH
469 dbg_PrintHash(WC->IconBarSetttings, PrintInt, NULL);
474 void tmplput_iconbar(StrBuf *Target, WCTemplputParams *TP)
478 if ((WCC != NULL) && (WCC->logged_in)) {
479 DoTemplate(HKEY("iconbar"), NULL, &NoCtx);
487 WebcitAddUrlHandler(HKEY("user_iconbar"), doUserIconStylesheet, 0);
488 WebcitAddUrlHandler(HKEY("commit_iconbar"), commit_iconbar, 0);
489 RegisterConditional(HKEY("COND:ICONBAR:ACTIVE"), 3, ConditionalIsActiveStylesheet, CTX_NONE);
490 WebcitAddUrlHandler(HKEY("display_customize_iconbar"), display_customize_iconbar, 0);
491 RegisterNamespace("ICONBAR", 0, 0, tmplput_iconbar, 0);
493 RegisterPreference("iconbar", _("Iconbar Setting"), PRF_STRING, LoadIconSettings);
499 SessionDestroyModule_ICONBAR
502 DeleteHash(&sess->IconBarSettings);