* Began implementing month view
authorArt Cancro <ajc@citadel.org>
Sun, 22 Sep 2002 05:20:27 +0000 (05:20 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 22 Sep 2002 05:20:27 +0000 (05:20 +0000)
webcit/ChangeLog
webcit/calendar_tools.c
webcit/calendar_view.c
webcit/messages.c
webcit/webcit.h

index a79e4bdabaa4f4d4159024638bc66a79e4cef325..d75cbbf61e44ced754150330cc926c55491f9911 100644 (file)
@@ -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 <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 77f478ee4ee926b4d536a7c3913a33d0e6020a6b..581d044d92442082c401e50f458dfc0b5d975ec0 100644 (file)
 #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;
index 148786a0a2827665569ded3acb530eea14db5109..987d4c5557bc2de3b3570d13dfd1589772f916e1 100644 (file)
@@ -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("<CENTER><H2>");
+
+       tm = localtime(&previous_month);
+       wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+               (int)(tm->tm_year)+1900, tm->tm_mon);
+       wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
+
+       wprintf("&nbsp;&nbsp;%s %d&nbsp;&nbsp;", months[month], year);
+
+       tm = localtime(&next_month);
+       wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+               (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+       wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
+
+       wprintf("</H2>");
+
+       wprintf("<TABLE border=1 width=100%%>");
+       for (i=0; i<7; ++i) {
+               wprintf("<TH>%s</TH>", days[i]);
+       }
+
+       /* Now do 35 days */
+       for (i = 0; i < 35; ++i) {
+               tm = localtime(&thetime);
+               if (tm->tm_wday == 0) {
+                       wprintf("<TR>");
+               }
+
+               wprintf("<TD>");
+               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("<BR><BR><BR>");
+
+               wprintf("</TD>");
+
+               if (tm->tm_wday == 6) {
+                       wprintf("</TR>\n");
+               }
+
+               thetime += (time_t)86400;               /* ahead 24 hours */
+       }
+
+       wprintf("</TABLE></CENTER>\n");
+}
+
+
+void calendar_week_view(int year, int month, int day) {
+       wprintf("<CENTER><I>week view FIXME</I></CENTER><BR>\n");
+}
+
+
+void calendar_day_view(int year, int month, int day) {
+       wprintf("<CENTER><I>day view FIXME</I></CENTER><BR>\n");
+}
+
+
+
 void do_calendar_view(void) {
-       wprintf("<CENTER><I>Calendar view not available</I></CENTER><BR>\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);
+       }
 }
 
 
index 91e282d71cdb151ad74c678fc1dc10a770b03ad9..b40b587f4bd7f455f4fc95e5a52d5e12e15eba15 100644 (file)
@@ -744,13 +744,17 @@ void readloop(char *oper)
 
        nummsgs = load_msg_ptrs(cmd);
        if (nummsgs == 0) {
-               if (!strcmp(oper, "readnew")) {
-                       wprintf("<EM>No new messages in this room.</EM>\n");
-               } else if (!strcmp(oper, "readold")) {
-                       wprintf("<EM>No old messages in this room.</EM>\n");
-               } else {
-                       wprintf("<EM>This room is empty.</EM>\n");
+
+               if ((!is_tasks) && (!is_calendar)) {
+                       if (!strcmp(oper, "readnew")) {
+                               wprintf("<EM>No new messages in this room.</EM>\n");
+                       } else if (!strcmp(oper, "readold")) {
+                               wprintf("<EM>No old messages in this room.</EM>\n");
+                       } else {
+                               wprintf("<EM>This room is empty.</EM>\n");
+                       }
                }
+
                goto DONE;
        }
 
index edcf5e43a682067f68d57b36a10c00d9a4a6da7a..fe1986300d5f2fca1489f5f58480a3d40d7fbe6d 100644 (file)
@@ -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[];