From: Art Cancro Date: Fri, 24 Jun 2005 19:58:03 +0000 (+0000) Subject: * Added a "preferences and settings" screen for each user. X-Git-Tag: v7.86~4816 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=fc6832083dc3c224c955853a827a9151b19c2d12 * Added a "preferences and settings" screen for each user. * Removed the javascript date output stuff because it's not granular or international enough. * All dates and times can now be 12 or 24 hours. --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 224ef1a65..3f804065c 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,10 @@ $Log$ +Revision 619.12 2005/06/24 19:58:02 ajc +* Added a "preferences and settings" screen for each user. +* Removed the javascript date output stuff because it's not granular + or international enough. +* All dates and times can now be 12 or 24 hours. + Revision 619.11 2005/06/24 15:17:48 ajc * The date/time stamp of messages are now output using JavaScript's toLocaleString() function, observing the browser's locale and timezone @@ -2648,4 +2654,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 09f5f833e..0526a1dd0 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -37,7 +37,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \ mime_parser.o graphics.o netconf.o siteconfig.o subst.o \ calendar.o calendar_tools.o calendar_view.o event.o \ availability.o iconbar.o crypto.o inetconf.o notes.o \ - groupdav_main.o groupdav_get.o groupdav_propfind.o \ + groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \ groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \ $(LIBOBJS) $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \ @@ -48,7 +48,7 @@ webserver: webserver.o context_loop.o tools.o ical_dezonify.o \ summary.o calendar.o calendar_tools.o calendar_view.o event.o \ availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \ groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \ - groupdav_put.o http_datestring.o setup_wizard.o \ + groupdav_put.o http_datestring.o setup_wizard.o fmt_date.o \ $(LIBOBJS) $(LIBS) $(LDFLAGS) -o webserver .c.o: diff --git a/webcit/auth.c b/webcit/auth.c index 1564dbc4c..4ed68ff68 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -196,7 +196,7 @@ void do_welcome(void) get_preference("startpage", buf, sizeof buf); if (strlen(buf)==0) { safestrncpy(buf, "/dotskip&room=_BASEROOM_", sizeof buf); - set_preference("startpage", buf); + set_preference("startpage", buf, 1); } http_redirect(buf); } diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index b36497a98..d67ffd1d4 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -72,6 +72,9 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { struct tm tm; const int span = 10; int all_day_event = 0; + char calhourformat[16]; + + get_preference("calhourformat", calhourformat, sizeof calhourformat); now = time(NULL); localtime_r(&now, &tm_now); @@ -129,10 +132,20 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { wprintf("Hour: "); wprintf("\n"); diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 2ebe3b36b..4059bc9a9 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -315,7 +315,9 @@ void calendar_day_view_display_events(int year, int month, void calendar_day_view(int year, int month, int day) { int hour; struct icaltimetype today, yesterday, tomorrow; + char calhourformat[16]; + get_preference("calhourformat", calhourformat, sizeof calhourformat); /* Figure out the dates for "yesterday" and "tomorrow" links */ @@ -365,10 +367,17 @@ void calendar_day_view(int year, int month, int day) { "&year=%d&month=%d&day=%d&hour=%d&minute=0\">", year, month, day, hour ); - wprintf("%d:00%s ", - (hour <= 12 ? hour : hour-12), - (hour < 12 ? "am" : "pm") - ); + + if (!strcasecmp(calhourformat, "24")) { + wprintf("%2d:00 ", hour); + } + else { + wprintf("%d:00%s ", + (hour <= 12 ? hour : hour-12), + (hour < 12 ? "am" : "pm") + ); + } + wprintf(""); /* put the data here, stupid */ diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c new file mode 100644 index 000000000..55b9897c8 --- /dev/null +++ b/webcit/fmt_date.c @@ -0,0 +1,170 @@ +/* + * $Id$ + * + * Miscellaneous routines + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" +#include "webserver.h" + +typedef unsigned char byte; + +#define FALSE 0 +#define TRUE 1 + +char *ascmonths[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +char *ascdays[] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +/* + * Format a date/time stamp for output + */ +void fmt_date(char *buf, time_t thetime, int brief) +{ + struct tm tm; + struct tm today_tm; + time_t today_timet; + int hour; + char calhourformat[16]; + + get_preference("calhourformat", calhourformat, sizeof calhourformat); + + today_timet = time(NULL); + localtime_r(&today_timet, &today_tm); + + localtime_r(&thetime, &tm); + hour = tm.tm_hour; + if (hour == 0) + hour = 12; + else if (hour > 12) + hour = hour - 12; + + buf[0] = 0; + + if (brief) { + + if ((tm.tm_year == today_tm.tm_year) + &&(tm.tm_mon == today_tm.tm_mon) + &&(tm.tm_mday == today_tm.tm_mday)) { + if (!strcasecmp(calhourformat, "24")) { + sprintf(buf, "%2d:%02d", + tm.tm_hour, tm.tm_min + ); + } + else { + sprintf(buf, "%2d:%02d%s", + hour, tm.tm_min, + ((tm.tm_hour >= 12) ? "pm" : "am") + ); + } + } + else { + sprintf(buf, "%s %d %d", + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900 + ); + } + } + else { + if (!strcasecmp(calhourformat, "24")) { + sprintf(buf, "%s %d %d %2d:%02d", + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900, + tm.tm_hour, tm.tm_min + ); + } + else { + sprintf(buf, "%s %d %d %2d:%02d%s", + ascmonths[tm.tm_mon], + tm.tm_mday, + tm.tm_year + 1900, + hour, tm.tm_min, ((tm.tm_hour >= 12) ? "pm" : "am") + ); + } + } +} + + + +/* + * Format TIME ONLY for output + */ +void fmt_time(char *buf, time_t thetime) +{ + struct tm *tm; + int hour; + char calhourformat[16]; + + get_preference("calhourformat", calhourformat, sizeof calhourformat); + + buf[0] = 0; + tm = localtime(&thetime); + hour = tm->tm_hour; + if (hour == 0) + hour = 12; + else if (hour > 12) + hour = hour - 12; + + if (!strcasecmp(calhourformat, "24")) { + sprintf(buf, "%2d:%02d", + tm->tm_hour, tm->tm_min + ); + } + else { + sprintf(buf, "%d:%02d%s", + hour, tm->tm_min, ((tm->tm_hour > 12) ? "pm" : "am") + ); + } +} + + + + +/* + * Format a date/time stamp to the format used in HTTP headers + */ +void httpdate(char *buf, time_t thetime) +{ + struct tm *tm; + + buf[0] = 0; + tm = localtime(&thetime); + + sprintf(buf, "%s, %02d %s %4d %02d:%02d:%02d", + ascdays[tm->tm_wday], + tm->tm_mday, + ascmonths[tm->tm_mon], + tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec); +} + + + + + diff --git a/webcit/iconbar.c b/webcit/iconbar.c index 7341a1032..5cd42c8ed 100644 --- a/webcit/iconbar.c +++ b/webcit/iconbar.c @@ -608,7 +608,7 @@ void commit_iconbar(void) { } } - set_preference("iconbar", iconbar); + set_preference("iconbar", iconbar, 1); output_headers(1, 1, 0, 0, 0, 0, 0); wprintf( diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index f8b9a6ddb..5eea557eb 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -136,9 +136,14 @@ void display_main_menu(void) svprintf("BOXTITLE", WCS_STRING, "Your info"); do_template("beginbox"); + wprintf("" + "" + "Change your preferences and settings" + "
\n"); + wprintf("
" "" - "Update your contact information " + "Update your contact information" "
\n"); wprintf("
" diff --git a/webcit/messages.c b/webcit/messages.c index 6e4890d54..908a871a0 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -416,6 +416,7 @@ void read_message(long msgnum) { char node[SIZ]; char rfca[SIZ]; char reply_to[512]; + char now[SIZ]; int format_type = 0; int nhdr = 0; int bq = 0; @@ -499,9 +500,8 @@ void read_message(long msgnum) { if (!strncasecmp(buf, "rcpt=", 5)) wprintf("to %s ", &buf[5]); if (!strncasecmp(buf, "time=", 5)) { - wprintf(" ", &buf[5]); + fmt_date(now, atol(&buf[5]), 0); + wprintf("%s ", now); } if (!strncasecmp(buf, "part=", 5)) { @@ -1663,7 +1663,7 @@ void display_enter(void) } now = time(NULL); - strcpy(buf, ""); + fmt_date(buf, now, 0); strcat(&buf[strlen(buf)], " from "); stresc(&buf[strlen(buf)], WC->wc_username, 1, 1); if (strlen(bstr("recp")) > 0) { @@ -1686,11 +1686,7 @@ void display_enter(void) wprintf("\n", now); - /* header bar */ - wprintf(" ", now); - wprintf("%s
\n", buf); + wprintf("%s
\n", buf); /* header bar */ wprintf("\""); /* "onLoad=\"document.enterform.msgtext.focus();\" " */ wprintf("Subject (optional):" diff --git a/webcit/preferences.c b/webcit/preferences.c index eab5f8cdd..1c51b9844 100644 --- a/webcit/preferences.c +++ b/webcit/preferences.c @@ -150,7 +150,7 @@ void get_preference(char *key, char *value, size_t value_len) { } } -void set_preference(char *key, char *value) { +void set_preference(char *key, char *value, int save_to_server) { int num_prefs; int i; char buf[SIZ]; @@ -180,5 +180,100 @@ void set_preference(char *key, char *value) { free(WC->preferences); WC->preferences = newprefs; - save_preferences(); + if (save_to_server) save_preferences(); +} + + + + +/* + * display form for changing your preferences and settings + */ +void display_preferences(void) +{ + output_headers(1, 1, 2, 0, 0, 0, 0); + char buf[256]; + + wprintf("
\n"); + wprintf("
"); + wprintf("\""); + wprintf(" Preferences and settings"); + wprintf(""); + offer_start_page(); + wprintf("
\n"); + wprintf("
\n" + "
\n"); + + wprintf("
" + "
\n"); + + /* begin form */ + wprintf("
\n" + "
\n" + "\n"); + + + get_preference("roomlistview", buf, sizeof buf); + wprintf("\n"); + + + get_preference("calhourformat", buf, sizeof buf); + if (buf[0] == 0) strcpy(buf, "12"); + wprintf("\n"); + + wprintf("
Room list view"); + + wprintf("Tree (folders) view
\n"); + + wprintf("Table (rooms) view
\n"); + + wprintf("
Calendar hour format"); + + wprintf("12 hour (am/pm)
\n"); + + wprintf("24 hour
\n"); + + wprintf("
\n" + "" + " " + "\n"); + + wprintf("
\n"); + + /* end form */ + + + wprintf("
\n"); + wDumpContent(1); +} + +/* + * Commit new preferences and settings + */ +void set_preferences(void) +{ + if (strcmp(bstr("action"), "Change")) { + safestrncpy(WC->ImportantMessage, + "Cancelled. No settings were changed.", + sizeof WC->ImportantMessage); + display_main_menu(); + return; + } + + /* Set the last argument to 1 only for the final setting, so + * we don't send the prefs file to the server repeatedly + */ + set_preference("roomlistview", bstr("roomlistview"), 0); + set_preference("calhourformat", bstr("calhourformat"), 1); + + display_main_menu(); } diff --git a/webcit/roomops.c b/webcit/roomops.c index f61670f4c..69ff9461e 100644 --- a/webcit/roomops.c +++ b/webcit/roomops.c @@ -2588,7 +2588,7 @@ void knrooms() { /* Determine whether the user is trying to change views */ if (bstr("view") != NULL) { if (strlen(bstr("view")) > 0) { - set_preference("roomlistview", bstr("view")); + set_preference("roomlistview", bstr("view"), 1); } } diff --git a/webcit/static/wclib.js b/webcit/static/wclib.js index 25ca7d6dc..014a8ef66 100644 --- a/webcit/static/wclib.js +++ b/webcit/static/wclib.js @@ -28,11 +28,3 @@ function hide_page_popup() { document.poppedLayer.style.visibility = "hidden"; } - -// Given a unix timestamp, outputs a date/time using the browser's -// timezone and locale. -function output_datetime(unixtimestamp) { - var now = new Date(); - now.setTime(unixtimestamp * 1000); - document.write(now.toLocaleString()); -} diff --git a/webcit/tools.c b/webcit/tools.c index 149f48d3f..d85e47ed7 100644 --- a/webcit/tools.c +++ b/webcit/tools.c @@ -32,15 +32,6 @@ typedef unsigned char byte; #define FALSE 0 #define TRUE 1 -char *ascmonths[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -char *ascdays[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -}; - static byte dtable[256]; /* base64 encode / decode table */ char *safestrncpy(char *dest, const char *src, size_t n) @@ -192,103 +183,6 @@ char ch; } -/* - * Format a date/time stamp for output - */ -void fmt_date(char *buf, time_t thetime, int brief) -{ - struct tm tm; - struct tm today_tm; - time_t today_timet; - int hour; - - today_timet = time(NULL); - localtime_r(&today_timet, &today_tm); - - localtime_r(&thetime, &tm); - hour = tm.tm_hour; - if (hour == 0) - hour = 12; - else if (hour > 12) - hour = hour - 12; - - buf[0] = 0; - - if (brief) { - - if ((tm.tm_year == today_tm.tm_year) - &&(tm.tm_mon == today_tm.tm_mon) - &&(tm.tm_mday == today_tm.tm_mday)) { - sprintf(buf, "%2d:%02d%s", - hour, tm.tm_min, - ((tm.tm_hour >= 12) ? "pm" : "am") - ); - } - else { - sprintf(buf, "%s %d %d", - ascmonths[tm.tm_mon], - tm.tm_mday, - tm.tm_year + 1900 - ); - } - } - else { - sprintf(buf, "%s %d %d %2d:%02d%s", - ascmonths[tm.tm_mon], - tm.tm_mday, - tm.tm_year + 1900, - hour, tm.tm_min, ((tm.tm_hour >= 12) ? "pm" : "am") - ); - } -} - - - -/* - * Format TIME ONLY for output - */ -void fmt_time(char *buf, time_t thetime) -{ - struct tm *tm; - int hour; - - buf[0] = 0; - tm = localtime(&thetime); - hour = tm->tm_hour; - if (hour == 0) - hour = 12; - else if (hour > 12) - hour = hour - 12; - - sprintf(buf, "%d:%02d%s", - hour, tm->tm_min, ((tm->tm_hour > 12) ? "pm" : "am") - ); -} - - - - -/* - * Format a date/time stamp to the format used in HTTP headers - */ -void httpdate(char *buf, time_t thetime) -{ - struct tm *tm; - - buf[0] = 0; - tm = localtime(&thetime); - - sprintf(buf, "%s, %02d %s %4d %02d:%02d:%02d", - ascdays[tm->tm_wday], - tm->tm_mday, - ascmonths[tm->tm_mon], - tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec); -} - - - - - /* * Utility function to "readline" from memory * (returns new pointer) diff --git a/webcit/webcit.c b/webcit/webcit.c index f1190b8f5..57ecff156 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -762,7 +762,7 @@ void change_start_page(void) { return; } - set_preference("startpage", bstr("startpage")); + set_preference("startpage", bstr("startpage"), 1); output_headers(1, 1, 0, 0, 0, 0, 0); do_template("newstartpage"); @@ -1359,6 +1359,10 @@ void session_loop(struct httprequest *req) save_inetconf(); } else if (!strcasecmp(action, "setup_wizard")) { do_setup_wizard(); + } else if (!strcasecmp(action, "display_preferences")) { + display_preferences(); + } else if (!strcasecmp(action, "set_preferences")) { + set_preferences(); } else if (!strcasecmp(action, "diagnostics")) { output_headers(1, 1, 1, 0, 0, 0, 0); diff --git a/webcit/webcit.h b/webcit/webcit.h index 6300e23fe..24ee4dfc3 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -419,7 +419,7 @@ void do_stuff_to_msgs(void); void load_preferences(void); void save_preferences(void); void get_preference(char *key, char *value, size_t value_len); -void set_preference(char *key, char *value); +void set_preference(char *key, char *value, int save_to_server); void knrooms(void); int is_msg_in_mset(char *mset, long msgnum); char *safestrncpy(char *dest, const char *src, size_t n); @@ -452,7 +452,8 @@ void set_room_policy(void); void display_inetconf(void); void save_inetconf(void); void generate_uuid(char *); - +void display_preferences(void); +void set_preferences(void); #ifdef WEBCIT_WITH_CALENDAR_SERVICE void display_edit_task(void);