$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
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
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 \
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:
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);
}
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);
wprintf("Hour: ");
wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
for (i=0; i<=23; ++i) {
- wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
- ((tm.tm_hour == i) ? "SELECTED" : ""),
- i, hourname[i]
- );
+
+ if (!strcasecmp(calhourformat, "24")) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((tm.tm_hour == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ else {
+ wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
+ ((tm.tm_hour == i) ? "SELECTED" : ""),
+ i, hourname[i]
+ );
+ }
+
}
wprintf("</SELECT>\n");
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 */
"&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
year, month, day, hour
);
- wprintf("%d:00%s</A> ",
- (hour <= 12 ? hour : hour-12),
- (hour < 12 ? "am" : "pm")
- );
+
+ if (!strcasecmp(calhourformat, "24")) {
+ wprintf("%2d:00</A> ", hour);
+ }
+ else {
+ wprintf("%d:00%s</A> ",
+ (hour <= 12 ? hour : hour-12),
+ (hour < 12 ? "am" : "pm")
+ );
+ }
+
wprintf("</TD><TD BGCOLOR=\"#FFFFFF\" VALIGN=TOP>");
/* put the data here, stupid */
--- /dev/null
+/*
+ * $Id$
+ *
+ * Miscellaneous routines
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <limits.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
+#include <sys/time.h>
+#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);
+}
+
+
+
+
+
}
}
- set_preference("iconbar", iconbar);
+ set_preference("iconbar", iconbar, 1);
output_headers(1, 1, 0, 0, 0, 0, 0);
wprintf(
svprintf("BOXTITLE", WCS_STRING, "Your info");
do_template("beginbox");
+ wprintf("<A HREF=\"/display_preferences\">"
+ "<span class=\"mainmenu\">"
+ "Change your preferences and settings"
+ "</span><br />\n");
+
wprintf("<A HREF=\"/display_reg\">"
"<span class=\"mainmenu\">"
- "Update your contact information "
+ "Update your contact information"
"</span><br />\n");
wprintf("<A HREF=\"/display_changepw\">"
char node[SIZ];
char rfca[SIZ];
char reply_to[512];
+ char now[SIZ];
int format_type = 0;
int nhdr = 0;
int bq = 0;
if (!strncasecmp(buf, "rcpt=", 5))
wprintf("to %s ", &buf[5]);
if (!strncasecmp(buf, "time=", 5)) {
- wprintf("<script type=\"text/javascript\">"
- "output_datetime(%s);"
- "</script> ", &buf[5]);
+ fmt_date(now, atol(&buf[5]), 0);
+ wprintf("%s ", now);
}
if (!strncasecmp(buf, "part=", 5)) {
}
now = time(NULL);
- strcpy(buf, "");
+ fmt_date(buf, now, 0);
strcat(&buf[strlen(buf)], " <I>from</I> ");
stresc(&buf[strlen(buf)], WC->wc_username, 1, 1);
if (strlen(bstr("recp")) > 0) {
wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n",
now);
- /* header bar */
- wprintf("<script type=\"text/javascript\">"
- "output_datetime(%ld);"
- "</script> ", now);
- wprintf("%s<br>\n", buf);
+ wprintf("%s<br>\n", buf); /* header bar */
wprintf("<img src=\"static/enter.gif\" align=middle alt=\" \">");
/* "onLoad=\"document.enterform.msgtext.focus();\" " */
wprintf("<font size=-1>Subject (optional):</font>"
}
}
-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];
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("<div id=\"banner\">\n");
+ wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
+ wprintf("<IMG SRC=\"/static/advanpage2_48x.gif\" ALT=\" \" ALIGN=MIDDLE>");
+ wprintf("<SPAN CLASS=\"titlebar\"> Preferences and settings");
+ wprintf("</SPAN></TD><TD ALIGN=RIGHT>");
+ offer_start_page();
+ wprintf("</TD></TR></TABLE>\n");
+ wprintf("</div>\n"
+ "<div id=\"content\">\n");
+
+ wprintf("<div id=\"fix_scrollbar_bug\">"
+ "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
+
+ /* begin form */
+ wprintf("<center>\n"
+ "<form name=\"prefform\" action=\"set_preferences\" "
+ "method=\"post\">\n"
+ "<table border=0 cellspacing=5 cellpadding=5>\n");
+
+
+ get_preference("roomlistview", buf, sizeof buf);
+ wprintf("<tr><td>Room list view</td><td>");
+
+ wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"folders\"");
+ if (!strcasecmp(buf, "folders")) wprintf(" checked");
+ wprintf(">Tree (folders) view<br></input>\n");
+
+ wprintf("<input type=\"radio\" name=\"roomlistview\" VALUE=\"rooms\"");
+ if (!strcasecmp(buf, "rooms")) wprintf(" checked");
+ wprintf(">Table (rooms) view<br></input>\n");
+
+ wprintf("</td></tr>\n");
+
+
+ get_preference("calhourformat", buf, sizeof buf);
+ if (buf[0] == 0) strcpy(buf, "12");
+ wprintf("<tr><td>Calendar hour format</td><td>");
+
+ wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"12\"");
+ if (!strcasecmp(buf, "12")) wprintf(" checked");
+ wprintf(">12 hour (am/pm)<br></input>\n");
+
+ wprintf("<input type=\"radio\" name=\"calhourformat\" VALUE=\"24\"");
+ if (!strcasecmp(buf, "24")) wprintf(" checked");
+ wprintf(">24 hour<br></input>\n");
+
+ wprintf("</td></tr>\n");
+
+ wprintf("</table>\n"
+ "<input type=\"submit\" name=\"action\" value=\"Change\">"
+ " "
+ "<INPUT type=\"submit\" name=\"action\" value=\"Cancel\">\n");
+
+ wprintf("</form></center>\n");
+
+ /* end form */
+
+
+ wprintf("</td></tr></table></div>\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();
}
/* 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);
}
}
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());
-}
#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)
}
-/*
- * 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)
return;
}
- set_preference("startpage", bstr("startpage"));
+ set_preference("startpage", bstr("startpage"), 1);
output_headers(1, 1, 0, 0, 0, 0, 0);
do_template("newstartpage");
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);
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);
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);