From 75d263706baa6e79d0d311749f50ac8b4024475e Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 22 Sep 2002 05:20:27 +0000 Subject: [PATCH] * Began implementing month view --- webcit/ChangeLog | 4 ++ webcit/calendar_tools.c | 10 ++- webcit/calendar_view.c | 136 ++++++++++++++++++++++++++++++++++++++-- webcit/messages.c | 16 +++-- webcit/webcit.h | 3 + 5 files changed, 156 insertions(+), 13 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index a79e4bdab..d75cbbf61 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 400.21 2002/09/22 05:20:27 ajc +* Began implementing month view + Revision 400.20 2002/09/21 04:38:05 ajc * Added utility functions for displaying vcalendar timestamps in web forms and translating form data back to timestamps. @@ -1009,3 +1012,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index 77f478ee4..581d044d9 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -26,13 +26,19 @@ #include "webcit.h" #include "webserver.h" -#ifdef HAVE_ICAL_H - char *months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; +char *days[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" +}; + +#ifdef HAVE_ICAL_H + + void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { int i; time_t now; diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 148786a0a..987d4c555 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -36,12 +36,138 @@ void do_calendar_view(void) { /* stub for non-libical builds */ /****************************************************************************/ -/* - * We loaded calendar events into memory during a pass through the - * messages in this room ... now display them. - */ + +void calendar_month_view(int year, int month, int day) { + struct tm starting_tm; + struct tm *tm; + time_t thetime; + int i; + time_t previous_month; + time_t next_month; + + /* Determine what day to start. + * First, back up to the 1st of the month... + */ + memset(&starting_tm, 0, sizeof(struct tm)); + starting_tm.tm_year = year - 1900; + starting_tm.tm_mon = month; + starting_tm.tm_mday = day; + thetime = mktime(&starting_tm); + + tm = &starting_tm; + while (tm->tm_mday != 1) { + thetime = thetime - (time_t)86400; /* go back 24 hours */ + tm = localtime(&thetime); + } + + /* Determine previous and next months ... for links */ + previous_month = thetime - (time_t)864000L; /* back 10 days */ + next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */ + + /* Now back up until we're on a Sunday */ + tm = localtime(&thetime); + while (tm->tm_wday != 0) { + thetime = thetime - (time_t)86400; /* go back 24 hours */ + tm = localtime(&thetime); + } + + wprintf("

"); + + tm = localtime(&previous_month); + wprintf("", + (int)(tm->tm_year)+1900, tm->tm_mon); + wprintf("\n"); + + wprintf("  %s %d  ", months[month], year); + + tm = localtime(&next_month); + wprintf("", + (int)(tm->tm_year)+1900, tm->tm_mon + 1); + wprintf("\n"); + + wprintf("

"); + + wprintf(""); + for (i=0; i<7; ++i) { + wprintf("", days[i]); + } + + /* Now do 35 days */ + for (i = 0; i < 35; ++i) { + tm = localtime(&thetime); + if (tm->tm_wday == 0) { + wprintf(""); + } + + wprintf(""); + + if (tm->tm_wday == 6) { + wprintf("\n"); + } + + thetime += (time_t)86400; /* ahead 24 hours */ + } + + wprintf("
%s
"); + if ((i==0) || (tm->tm_mday == 1)) { + wprintf("%s ", months[tm->tm_mon]); + } + wprintf("%d", tm->tm_mday); + + /* FIXME ... put the data here, stupid */ + wprintf("


"); + + wprintf("
\n"); +} + + +void calendar_week_view(int year, int month, int day) { + wprintf("
week view FIXME

\n"); +} + + +void calendar_day_view(int year, int month, int day) { + wprintf("
day view FIXME

\n"); +} + + + void do_calendar_view(void) { - wprintf("
Calendar view not available

\n"); + time_t now; + struct tm *tm; + int year, month, day; + char calview[SIZ]; + + /* In case no date was specified, go with today */ + now = time(NULL); + tm = localtime(&now); + year = tm->tm_year + 1900; + month = tm->tm_mon; + day = tm->tm_mday; + + /* Now see if a date was specified */ + if (strlen(bstr("year")) > 0) year = atoi(bstr("year")); + if (strlen(bstr("month")) > 0) month = atoi(bstr("month")); + if (strlen(bstr("day")) > 0) day = atoi(bstr("day")); + + /* How would you like that cooked? */ + if (strlen(bstr("calview")) > 0) { + strcpy(calview, bstr("calview")); + } + else { + strcpy(calview, "month"); + } + + /* Display the selected view */ + if (!strcasecmp(calview, "day")) { + calendar_day_view(year, month, day); + } + else if (!strcasecmp(calview, "week")) { + calendar_week_view(year, month, day); + } + else { + calendar_month_view(year, month, day); + } } diff --git a/webcit/messages.c b/webcit/messages.c index 91e282d71..b40b587f4 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -744,13 +744,17 @@ void readloop(char *oper) nummsgs = load_msg_ptrs(cmd); if (nummsgs == 0) { - if (!strcmp(oper, "readnew")) { - wprintf("No new messages in this room.\n"); - } else if (!strcmp(oper, "readold")) { - wprintf("No old messages in this room.\n"); - } else { - wprintf("This room is empty.\n"); + + if ((!is_tasks) && (!is_calendar)) { + if (!strcmp(oper, "readnew")) { + wprintf("No new messages in this room.\n"); + } else if (!strcmp(oper, "readold")) { + wprintf("No old messages in this room.\n"); + } else { + wprintf("This room is empty.\n"); + } } + goto DONE; } diff --git a/webcit/webcit.h b/webcit/webcit.h index edcf5e43a..fe1986300 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -356,3 +356,6 @@ void save_task(void); void display_icaltimetype_as_webform(struct icaltimetype *, char *); struct icaltimetype icaltime_from_webform(char *prefix); #endif + +extern char *months[]; +extern char *days[]; -- 2.30.2