]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
* split tasks view into its own file
[citadel.git] / webcit / calendar_view.c
index f5f440baf0fdec0b92ebc05ef6978112f86441d8..48ac994666d7fa64fe4b77293b809b101fd4d569 100644 (file)
@@ -6,14 +6,18 @@
 
 #include "webcit.h"
 #include "webserver.h"
+#include "calendar.h"
 
+/* These define how high the hour rows are in the day view */
+#define TIMELINE       30
+#define EXTRATIMELINE  (TIMELINE / 2)
 
-void embeddable_mini_calendar(int year, int month, char *urlformat)
+void embeddable_mini_calendar(int year, int month)
 {
        struct tm starting_tm;
        struct tm tm;
        time_t thetime;
-       int i, len;
+       int i;
        time_t previous_month;
        time_t next_month;
        time_t colheader_time;
@@ -22,8 +26,7 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
        long weekstart = 0;
        char url[256];
        char div_id[256];
-       char escaped_urlformat[256];
-
+       
        snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
 
        /* Determine what day to start.  If an impossible value is found, start on Sunday.
@@ -47,11 +50,11 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
                localtime_r(&thetime, &tm);
        }
 
-       /** Determine previous and next months ... for links */
+       /* 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 the user's preferred start day */
+       /* Now back up until we're on the user's preferred start day */
        localtime_r(&thetime, &tm);
        while (tm.tm_wday != weekstart) {
                thetime = thetime - (time_t)86400;      /* go back 24 hours */
@@ -90,19 +93,19 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
        wprintf("</tr>\n");
 
 
-        /** Now do 35 or 42 days */
+        /* Now do 35 or 42 days */
         for (i = 0; i < 42; ++i) {
                 localtime_r(&thetime, &tm);
 
                 if (i < 35) {
 
-                       /** Before displaying Sunday, start a new row */
+                       /* Before displaying Sunday, start a new row */
                        if ((i % 7) == 0) {
                                wprintf("<tr>");
                        }
 
                        if (tm.tm_mon == month-1) {
-                               snprintf(url, sizeof url, urlformat,
+                               snprintf(url, sizeof url, "readfwd?calview=day&year=%d&month=%d&day=%d", 
                                        tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday);
                                wprintf("<td><a href=\"%s\">%d</a></td>", url, tm.tm_mday);
                        }
@@ -110,61 +113,43 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
                                wprintf("<td> </td>");
                        }
 
-                       /** After displaying one week, end the row */
+                       /* After displaying one week, end the row */
                        if ((i % 7) == 6) {
                                wprintf("</tr>\n");
                        }
 
                }
 
-               thetime += (time_t)86400;               /** ahead 24 hours */
+               thetime += (time_t)86400;               /* ahead 24 hours */
        }
 
-       wprintf("</table>"                      /** end of inner table */
+       wprintf("</table>"                      /* end of inner table */
                "</div>\n");
 
-       /* javascript for previous and next month */
-       len = strlen(urlformat);
-       for (i=0; i<len; ++i) {
-               sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
-       }
-
-       wprintf("<script type=\"text/javascript\">                                                      "
-               "       function minical_change_month(year, month) {                                    "
-               "               p = 'year=' + year + '&month=' + month                                  "
-               "                       + '&urlformat=%s&r=' + CtdlRandomString();                      "
-               "               new Ajax.Updater('%s', 'mini_calendar',                                 "
-               "                       { method: 'get', parameters: p, evalScripts: true } );          "
-               "       }                                                                               "
-               "</script>\n"
-               ,
-               escaped_urlformat, div_id
-               );
+       StrBufAppendPrintf(WC->trailing_javascript,
+               "       function minical_change_month(year, month) {                                    \n"
+               "               p = 'year=' + year + '&month=' + month                                  \n"
+               "                       + '&r=' + CtdlRandomString();                                   \n"
+               "               new Ajax.Updater('%s', 'mini_calendar',                                 \n"
+               "                       { method: 'get', parameters: p, evalScripts: true } );          \n"
+               "       }                                                                               \n"
+               "",
+               div_id
+       );
 
 }
 
-/**
- * \brief  ajax embedder for the above mini calendar 
+/*
+ * ajax embedder for the above mini calendar 
  */
-void ajax_mini_calendar(void) {
-       char urlformat[256];
-       int i, len;
-       char *escaped_urlformat;
-
-       escaped_urlformat = bstr("urlformat");
-        len = strlen(escaped_urlformat) * 2 ;
-       for (i=0; i<len; ++i) {
-               urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
-               urlformat[i+1] = 0;
-       }
-
-       embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
+void ajax_mini_calendar(void) 
+{
+       embeddable_mini_calendar( ibstr("year"), ibstr("month"));
 }
 
 
-/**
- * \brief Display one day of a whole month view of a calendar
- * \param thetime the month we want to see 
+/*
+ * Display one day of a whole month view of a calendar
  */
 void calendar_month_view_display_events(int year, int month, int day)
 {
@@ -179,12 +164,13 @@ void calendar_month_view_display_events(int year, int month, int day)
        struct icaltimetype end_t;
        struct icaltimetype today_start_t;
        struct icaltimetype today_end_t;
+       struct icaltimetype today_t;
        struct tm starting_tm;
        struct tm ending_tm;
        int all_day_event = 0;
        int show_event = 0;
        char buf[256];
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
        time_t tt;
 
        if (GetCount(WCC->disp_cal_items) == 0) {
@@ -192,7 +178,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                return;
        }
 
-       /**
+       /*
         * Create an imaginary event which spans the 24 hours of today.  Any events which
         * overlap with this one take place at least partially in this day.  We have to
         * convert it from a struct tm in order to make it UTC.
@@ -215,10 +201,18 @@ void calendar_month_view_display_events(int year, int month, int day)
        today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
        today_end_t.is_utc = 1;
 
-       /**
+       /*
+        * Create another one without caring about the timezone for all day events.
+        */
+       today_t = icaltime_null_date();
+       today_t.year = year;
+       today_t.month = month;
+       today_t.day = day;
+
+       /*
         * Now loop through our list of events to see which ones occur today.
         */
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                Cal = (disp_cal*)vCal;
                all_day_event = 0;
@@ -240,18 +234,22 @@ void calendar_month_view_display_events(int year, int month, int day)
 
                if (all_day_event)
                {
-                       show_event = ((t.year == year) && (t.month == month) && (t.day == day));
+                       show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
                }
                else
                {
                        show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
                }
 
-               /**
+               /*
                 * If we determined that this event occurs today, then display it.
                 */
                if (show_event) {
                        p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+                       if (p == NULL) {
+                               p = icalproperty_new_summary(_("Untitled Event"));
+                               icalcomponent_add_property(Cal->cal, p);
+                       }
                        if (p != NULL) {
 
                                if (all_day_event) {
@@ -260,9 +258,9 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                );
                                }
 
-                               wprintf("<font size=-1>"
+                               wprintf("<font size=\"-1\">"
                                        "<a class=\"event%s\" href=\"display_edit_event?"
-                                       "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
+                                       "msgnum=%ld?calview=month?year=%d?month=%d?day=%d\""
                                        " btt_tooltext=\"",
                                        (Cal->unread)?"_unread":"_read",
                                        Cal->cal_msgnum,
@@ -283,7 +281,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                        wprintf("<br />");
                                }
                                
-                               /**
+                               /*
                                 * Only show start/end times if we're actually looking at the VEVENT
                                 * component.  Otherwise it shows bogus dates for e.g. timezones
                                 */
@@ -291,34 +289,63 @@ void calendar_month_view_display_events(int year, int month, int day)
                                        
                                        q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
                                        if (q != NULL) {
+                                               int no_end = 0;
+
                                                t = icalproperty_get_dtstart(q);
-                                               
+                                               q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+                                               if (q != NULL) {
+                                                       end_t = icalproperty_get_dtend(q);
+                                               }
+                                               else {
+                                                       /*
+                                                        * events with starting date/time equal
+                                                        * ending date/time might get only
+                                                        * DTSTART but no DTEND
+                                                        */
+                                                       no_end = 1;
+                                               }
+
                                                if (t.is_date) {
+                                                       /* all day event */
                                                        struct tm d_tm;
-                                                       char d_str[32];
+
+                                                       if (!no_end) {
+                                                               /* end given, have to adjust it */
+                                                               icaltime_adjust(&end_t, -1, 0, 0, 0);
+                                                       }
                                                        memset(&d_tm, 0, sizeof d_tm);
                                                        d_tm.tm_year = t.year - 1900;
                                                        d_tm.tm_mon = t.month - 1;
                                                        d_tm.tm_mday = t.day;
-                                                       wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
-                                                       wprintf("<i>%s</i> %s<br>",
-                                                               _("Date:"), d_str);
+                                                       wc_strftime(buf, sizeof buf, "%x", &d_tm);
+
+                                                       if (no_end || !icaltime_compare(t, end_t)) {
+                                                               wprintf("<i>%s</i> %s<br>",
+                                                                       _("Date:"), buf);
+                                                       }
+                                                       else {
+                                                               wprintf("<i>%s</i> %s<br>",
+                                                                       _("Starting date:"), buf);
+                                                               d_tm.tm_year = end_t.year - 1900;
+                                                               d_tm.tm_mon = end_t.month - 1;
+                                                               d_tm.tm_mday = end_t.day;
+                                                               wc_strftime(buf, sizeof buf, "%x", &d_tm);
+                                                               wprintf("<i>%s</i> %s<br>",
+                                                                       _("Ending date:"), buf);
+                                                       }
                                                }
                                                else {
                                                        tt = icaltime_as_timet(t);
-                                                       webcit_fmt_date(buf, tt, 1);
-                                                       wprintf("<i>%s</i> %s<br>",
-                                                               _("Starting date/time:"), buf);
-                                                       
-                                                       /**
-                                                        * Embed the 'show end date/time' loop inside here so it
-                                                        * only executes if this is NOT an all day event.
-                                                        */
-                                                       q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
-                                                       if (q != NULL) {
-                                                               t = icalproperty_get_dtend(q);
-                                                               tt = icaltime_as_timet(t);
-                                                               webcit_fmt_date(buf, tt, 1);
+                                                       webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
+                                                       if (no_end || !icaltime_compare(t, end_t)) {
+                                                               wprintf("<i>%s</i> %s<br>",
+                                                                       _("Date/time:"), buf);
+                                                       }
+                                                       else {
+                                                               wprintf("<i>%s</i> %s<br>",
+                                                                       _("Starting date/time:"), buf);
+                                                               tt = icaltime_as_timet(end_t);
+                                                               webcit_fmt_date(buf, 256, tt, DATEFMT_BRIEF);
                                                                wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                                        }
                                                        
@@ -353,9 +380,8 @@ void calendar_month_view_display_events(int year, int month, int day)
 }
 
 
-/**
- * \brief Display one day of a whole month view of a calendar
- * \param thetime the month we want to see 
+/*
+ * Display one day of a whole month view of a calendar
  */
 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        long hklen;
@@ -365,7 +391,7 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        time_t event_tt;
        time_t event_tts;
        time_t event_tte;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
        struct tm event_tms;
        struct tm event_tme;
        struct tm today_tm;
@@ -388,7 +414,7 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        day = today_tm.tm_mday;
        year = today_tm.tm_year + 1900;
 
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                Cal = (disp_cal*)vCal;
                p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
@@ -417,6 +443,10 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
                        p = icalcomponent_get_first_property(
                                Cal->cal,
                                ICAL_SUMMARY_PROPERTY);
+                       if (p == NULL) {
+                               p = icalproperty_new_summary(_("Untitled Event"));
+                               icalcomponent_add_property(Cal->cal, p);
+                       }
                        e = icalcomponent_get_first_property(
                                Cal->cal, 
                                ICAL_DTEND_PROPERTY);
@@ -430,8 +460,8 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
                                hours=(int)(difftime / 60);
                                minutes=difftime % 60;
                                wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
-                                       "<font size=-1>"
-                                       "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld&calview=calbrief&year=%s&month=%s&day=%s\">",
+                                       "<font size=\"-1\">"
+                                       "<a class=\"event%s\" href=\"display_edit_event?msgnum=%ld?calview=calbrief?year=%s?month=%s?day=%s\">",
                                        daycolor,
                                        hours, minutes,
                                        (Cal->unread)?"_unread":"_read",                                                
@@ -478,7 +508,6 @@ void calendar_month_view(int year, int month, int day) {
        time_t colheader_time;
        struct tm colheader_tm;
        char colheader_label[32];
-       int chg_month = 0;
        long weekstart = 0;
 
        /*
@@ -511,9 +540,7 @@ void calendar_month_view(int year, int month, int day) {
        localtime_r(&thetime, &tm);
        while (tm.tm_wday != weekstart) {
                thetime = thetime - (time_t)86400;      /* go back 24 hours */
-               lprintf(9, "Subtracting a day, thetime is now %d - %s", thetime, ctime(&thetime));
                localtime_r(&thetime, &tm);
-               lprintf(9, "tm.tm_wday is %d, weekstart is %d\n", tm.tm_wday, weekstart);
        }
 
        /* Outer table (to get the background color) */
@@ -525,7 +552,7 @@ void calendar_month_view(int year, int month, int day) {
        wprintf("<td align=center>");
 
        localtime_r(&previous_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       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/prevdate_32x.gif\" border=0></A>\n");
 
@@ -537,7 +564,7 @@ void calendar_month_view(int year, int month, int day) {
                "&nbsp;&nbsp;", colheader_label, year);
 
        localtime_r(&next_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       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/nextdate_32x.gif\" border=0></A>\n");
 
@@ -559,56 +586,50 @@ void calendar_month_view(int year, int month, int day) {
 
 
         /* Now do 35 or 42 days */
-        for (i = 0; i < 42; ++i) {
-                localtime_r(&thetime, &tm);
-
-                if ((i < 35) || (chg_month == 0)) {
-
-                        if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
-                                chg_month = 1;
-                        }
-                        if (i > 35) {
-                                chg_month = 0;
-                        }
-
-                       /* Before displaying the first day of the week, start a new row */
-                       if ((i % 7) == 0) {
-                               wprintf("<tr>");
-                       }
+       localtime_r(&thetime, &tm);
+        for (i = 0; i<42; ++i) {
 
-                       wprintf("<td class=\"cal%s\"><div class=\"day\">",
-                               ((tm.tm_mon != month-1) ? "out" :
-                                       ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
-                                               "day"))
-                               );
-                       if ((i==0) || (tm.tm_mday == 1)) {
-                               wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
-                               wprintf("%s ", colheader_label);
-                       }
-                       wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
-                               "%d</a></div>",
-                               tm.tm_year + 1900,
-                               tm.tm_mon + 1,
-                               tm.tm_mday,
-                               tm.tm_mday);
-
-                       /** put the data here, stupid */
-                       calendar_month_view_display_events(
-                               tm.tm_year + 1900,
-                               tm.tm_mon + 1,
-                               tm.tm_mday
-                               );
+               /* Before displaying the first day of the week, start a new row */
+               if ((i % 7) == 0) {
+                       wprintf("<tr>");
+               }
 
-                       wprintf("</td>");
+               wprintf("<td class=\"cal%s\"><div class=\"day\">",
+                       ((tm.tm_mon != month-1) ? "out" :
+                               ((tm.tm_wday==0 || tm.tm_wday==6) ? "weekend" :
+                                       "day"))
+                       );
+               if ((i==0) || (tm.tm_mday == 1)) {
+                       wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
+                       wprintf("%s ", colheader_label);
+               }
+               wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">"
+                       "%d</a></div>",
+                       tm.tm_year + 1900,
+                       tm.tm_mon + 1,
+                       tm.tm_mday,
+                       tm.tm_mday);
+
+               /* put the data here, stupid */
+               calendar_month_view_display_events(
+                       tm.tm_year + 1900,
+                       tm.tm_mon + 1,
+                       tm.tm_mday
+                       );
 
-                       /* After displaying the last day of the week, end the row */
-                       if ((i % 7) == 6) {
-                               wprintf("</tr>\n");
-                       }
+               wprintf("</td>");
 
+               /* After displaying the last day of the week, end the row */
+               if ((i % 7) == 6) {
+                       wprintf("</tr>\n");
                }
 
                thetime += (time_t)86400;               /* ahead 24 hours */
+               localtime_r(&thetime, &tm);
+
+               if ( ((i % 7) == 6) && (tm.tm_mon != month-1) && (tm.tm_mday < 15) ) {
+                       i = 100;        /* break out of the loop */
+               }
        }
 
        wprintf("</table>"                      /* end of inner table */
@@ -626,9 +647,8 @@ void calendar_month_view(int year, int month, int day) {
         * being rendered.  See http://www.shaftek.org/blog/archives/000212.html
         * for more information.
         */ 
-       wprintf("<script type=\"text/javascript\">"
-               " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
-               "</script>\n"
+       StrBufAppendPrintf(WC->trailing_javascript,
+               " setTimeout(\"btt_enableTooltips('inner_month')\", 1); \n"
        );
 }
 
@@ -680,7 +700,7 @@ void calendar_brief_month_view(int year, int month, int day) {
        wprintf("<td align=center>");
 
        localtime_r(&previous_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       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/prevdate_32x.gif\" border=0></A>\n");
 
@@ -692,7 +712,7 @@ void calendar_brief_month_view(int year, int month, int day) {
                "&nbsp;&nbsp;", month_label, year);
 
        localtime_r(&next_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       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/nextdate_32x.gif\" border=0></A>\n");
 
@@ -747,11 +767,11 @@ void calendar_brief_month_view(int year, int month, int day) {
                        wprintf("</td></tr></table>\n");
                }
 
-               thetime += (time_t)86400;               /** ahead 24 hours */
+               thetime += (time_t)86400;               /* ahead 24 hours */
        }
 
-       wprintf("</table>"                      /** end of inner table */
-               "</td></tr></table>"            /** end of outer table */
+       wprintf("</table>"                      /* end of inner table */
+               "</td></tr></table>"            /* end of outer table */
                "</div>\n");
 }
 
@@ -791,12 +811,13 @@ void calendar_day_view_display_events(time_t thetime,
        int show_event = 0;
        int all_day_event = 0;
        int ongoing_event = 0;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
        disp_cal *Cal;
        struct icaltimetype t;
        struct icaltimetype end_t;
        struct icaltimetype today_start_t;
        struct icaltimetype today_end_t;
+       struct icaltimetype today_t;
        struct tm starting_tm;
        struct tm ending_tm;
        int top = 0;
@@ -807,8 +828,6 @@ void calendar_day_view_display_events(time_t thetime,
        int endmin = 0;
 
         char buf[256];
-        struct tm d_tm;
-        char d_str[32];
 
        if (GetCount(WCC->disp_cal_items) == 0) {
                /* nothing to display */
@@ -836,9 +855,17 @@ void calendar_day_view_display_events(time_t thetime,
        today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
        today_end_t.is_utc = 1;
 
+       /*
+        * Create another one without caring about the timezone for all day events.
+        */
+       today_t = icaltime_null_date();
+       today_t.year = year;
+       today_t.month = month;
+       today_t.day = day;
+
        /* Now loop through our list of events to see which ones occur today.
         */
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                Cal = (disp_cal*)vCal;
 
@@ -854,29 +881,46 @@ void calendar_day_view_display_events(time_t thetime,
                else {
                        memset(&t, 0, sizeof t);
                }
+
+               if (t.is_date) all_day_event = 1;
+
                q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
                if (q != NULL) {
                        end_t = icalproperty_get_dtend(q);
-                       event_tte = icaltime_as_timet(end_t);
-                       localtime_r(&event_tte, &event_tm);
                }
                else {
-                       memset(&end_t, 0, sizeof end_t);
+                       /* no end given means end = start */
+                       memcpy(&end_t, &t, sizeof(struct icaltimetype));
                }
-               if (t.is_date) all_day_event = 1;
 
                if (all_day_event)
                {
-                       show_event = ((t.year == year) && (t.month == month) && (t.day == day) && (notime_events));
+                       show_event = ical_ctdl_is_overlap(t, end_t, today_t, icaltime_null_time());
+                       if (icaltime_compare(t, end_t)) {
+                               /*
+                                * the end date is non-inclusive so adjust it by one
+                                * day because our test is inclusive, note that a day is
+                                * not to much because we are talking about all day
+                                * events
+                                */
+                               icaltime_adjust(&end_t, -1, 0, 0, 0);
+                       }
                }
                else
                {
                        show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
                }
 
+               event_tte = icaltime_as_timet(end_t);
+               localtime_r(&event_tte, &event_tm);
+
                /* If we determined that this event occurs today, then display it.
                 */
                p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
+               if (p == NULL) {
+                       p = icalproperty_new_summary(_("Untitled Event"));
+                       icalcomponent_add_property(Cal->cal, p);
+               }
 
                if ((show_event) && (p != NULL)) {
 
@@ -886,7 +930,7 @@ void calendar_day_view_display_events(time_t thetime,
                        {
                                wprintf("<li class=\"event_framed%s\"> "
                                        "<a href=\"display_edit_event?"
-                                       "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
+                                       "msgnum=%ld?calview=day?year=%d?month=%d?day=%d\" "
                                        " class=\"event_title\" "
                                        " btt_tooltext=\"",
                                        (Cal->unread)?"_unread":"_read",
@@ -901,13 +945,17 @@ void calendar_day_view_display_events(time_t thetime,
                                         wprintf("<i>%s</i> ", _("Location:"));
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
-                                                               }
-                                memset(&d_tm, 0, sizeof d_tm);
-                                d_tm.tm_year = t.year - 1900;
-                                d_tm.tm_mon = t.month - 1;
-                                d_tm.tm_mday = t.day;
-                                wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
-                                wprintf("<i>%s</i> %s<br>",_("Date:"), d_str);
+                               }
+                               if (!icaltime_compare(t, end_t)) { /* one day only */
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
+                                       wprintf("<i>%s</i> %s<br>", _("Date:"), buf);
+                               }
+                               else {
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_LOCALEDATE);
+                                       wprintf("<i>%s</i> %s<br>", _("Starting date:"), buf);
+                                       webcit_fmt_date(buf, 256, event_tte, DATEFMT_LOCALEDATE);
+                                       wprintf("<i>%s</i> %s<br>", _("Ending date:"), buf);
+                               }
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
                                         wprintf("<i>%s</i> ", _("Notes:"));
@@ -924,7 +972,7 @@ void calendar_day_view_display_events(time_t thetime,
                        {
                                wprintf("<li class=\"event_framed%s\"> "
                                        "<a href=\"display_edit_event?"
-                                       "msgnum=%ld&calview=day&year=%d&month=%d&day=%d\" "
+                                       "msgnum=%ld&calview=day?year=%d?month=%d?day=%d\" "
                                        " class=\"event_title\" " 
                                        "btt_tooltext=\"",
                                        (Cal->unread)?"_unread":"_read",
@@ -940,9 +988,9 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                                                }
-                                webcit_fmt_date(buf, event_tt, 1);
+                                webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                webcit_fmt_date(buf, event_tte, 1);
+                                webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
                                 wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
                                 q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
@@ -966,15 +1014,15 @@ void calendar_day_view_display_events(time_t thetime,
                                /* Calculate the location of the top of the box */
                                if (event_te.tm_hour < dstart) {
                                        startmin = diffmin = event_te.tm_min / 6;
-                                       top = (event_te.tm_hour * 10) + startmin;
+                                       top = (event_te.tm_hour * EXTRATIMELINE) + startmin;
                                }
                                else if ((event_te.tm_hour >= dstart) && (event_te.tm_hour <= dend)) {
                                        startmin = diffmin = (event_te.tm_min / 2);
-                                       top = (dstart * 10) + ((event_te.tm_hour - dstart) * 30) + startmin;
+                                       top = (dstart * EXTRATIMELINE) + ((event_te.tm_hour - dstart) * TIMELINE) + startmin;
                                }
                                else if (event_te.tm_hour >dend) {
                                        startmin = diffmin = event_te.tm_min / 6;
-                                       top = (dstart * 10) + ((dend - dstart - 1) * 30) + ((event_tm.tm_hour - dend + 1) * 10) + startmin ;
+                                       top = (dstart * EXTRATIMELINE) + ((dend - dstart - 1) * TIMELINE) + ((event_tm.tm_hour - dend + 1) * EXTRATIMELINE) + startmin ;
                                }
                                else {
                                        /* should never get here */
@@ -983,15 +1031,15 @@ void calendar_day_view_display_events(time_t thetime,
                                /* Calculate the location of the bottom of the box */
                                if (event_tm.tm_hour < dstart) {
                                        endmin = diffmin = event_tm.tm_min / 6;
-                                       bottom = (event_tm.tm_hour * 10) + endmin;
+                                       bottom = (event_tm.tm_hour * EXTRATIMELINE) + endmin;
                                }
                                else if ((event_tm.tm_hour >= dstart) && (event_tm.tm_hour <= dend)) {
                                        endmin = diffmin = (event_tm.tm_min / 2);
-                                       bottom = (dstart * 10) + ((event_tm.tm_hour - dstart) * 30) + endmin ;
+                                       bottom = (dstart * EXTRATIMELINE) + ((event_tm.tm_hour - dstart) * TIMELINE) + endmin ;
                                }
                                else if (event_tm.tm_hour >dend) {
                                        endmin = diffmin = event_tm.tm_min / 6;
-                                       bottom = (dstart * 10) + ((dend - dstart + 1) * 30) + ((event_tm.tm_hour - dend - 1) * 10) + endmin;
+                                       bottom = (dstart * EXTRATIMELINE) + ((dend - dstart + 1) * TIMELINE) + ((event_tm.tm_hour - dend - 1) * EXTRATIMELINE) + endmin;
                                }
                                else {
                                        /* should never get here */
@@ -1005,7 +1053,7 @@ void calendar_day_view_display_events(time_t thetime,
                                        top, (gap * 40), (bottom-top)
                                        );
                                wprintf("<a href=\"display_edit_event?"
-                                       "msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\" "
+                                       "msgnum=%ld?calview=day?year=%d?month=%d?day=%d?hour=%d\" "
                                        "class=\"event_title\" "
                                                "btt_tooltext=\"",
                                        Cal->cal_msgnum, year, month, day, t.hour);
@@ -1019,10 +1067,16 @@ void calendar_day_view_display_events(time_t thetime,
                                         escputs((char *)icalproperty_get_comment(q));
                                         wprintf("<br />");
                                                                }
-                                webcit_fmt_date(buf, event_tt, 1);
-                                wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
-                                webcit_fmt_date(buf, event_tte, 1);
-                                wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
+                               if (!icaltime_compare(t, end_t)) { /* one day only */
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
+                                       wprintf("<i>%s</i> %s<br>", _("Date/time:"), buf);
+                               }
+                               else {
+                                       webcit_fmt_date(buf, 256, event_tt, DATEFMT_BRIEF);
+                                       wprintf("<i>%s</i> %s<br>", _("Starting date/time:"), buf);
+                                       webcit_fmt_date(buf, 256, event_tte, DATEFMT_BRIEF);
+                                       wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
+                               }
                                q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY);
                                 if (q) {
                                         wprintf("<i>%s</i> ", _("Notes:"));
@@ -1051,9 +1105,11 @@ void calendar_day_view(int year, int month, int day) {
        char d_str[128];
        int time_format;
        time_t today_t;
-       int timeline = 30;
-       int extratimeline = 0;
+       int timeline = TIMELINE;
+       int extratimeline = EXTRATIMELINE;
        int gap = 0;
+       int hourlabel;
+       int extrahourlabel;
 
        time_format = get_time_format_cached ();
        get_pref_long("daystart", &daystart, 8);
@@ -1099,18 +1155,23 @@ void calendar_day_view(int year, int month, int day) {
 
        /* Now the middle of the day... */
 
-       extratimeline = timeline / 3;   
+       extrahourlabel = extratimeline - 2;
+       hourlabel = extrahourlabel * 150 / 100;
+       if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
 
        for (hour = 0; hour < daystart; ++hour) {       /* could do HEIGHT=xx */
                wprintf("<dt class=\"extrahour\"        "
                        "style=\"               "
                        "position: absolute;    "
                        "top: %dpx; left: 0px;  "
-                       "height: %dpx;          "       
+                       "height: %dpx;          "
+                       "font-size: %dpx;       "
                        "\" >                   "
                        "<a href=\"display_edit_event?msgnum=0"
-                       "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
-                       (hour * extratimeline ), extratimeline, 
+                       "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
+                       (hour * extratimeline ),
+                       extratimeline,
+                       extrahourlabel,
                        year, month, day, hour
                        );
 
@@ -1119,7 +1180,7 @@ void calendar_day_view(int year, int month, int day) {
                }
                else {
                        wprintf("%d:00%s</a> ",
-                               (hour <= 12 ? hour : hour-12),
+                               ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
                                (hour < 12 ? "am" : "pm")
                                );
                }
@@ -1133,12 +1194,15 @@ void calendar_day_view(int year, int month, int day) {
                 wprintf("<dt class=\"hour\"     "
                         "style=\"               "
                         "position: absolute;    "
-                        "top: %ldpx; left: 0px;  "
+                        "top: %ldpx; left: 0px; "
                         "height: %dpx;          "
+                       "font-size: %dpx;       "
                         "\" >                   "
-                        "<a href=\"display_edit_event?msgnum=0&calview=day"
-                        "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
-                        gap + ((hour - daystart) * timeline ), timeline,
+                        "<a href=\"display_edit_event?msgnum=0?calview=day"
+                        "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
+                        gap + ((hour - daystart) * timeline ),
+                       timeline,
+                       hourlabel,
                         year, month, day, hour
                        );
 
@@ -1163,10 +1227,13 @@ void calendar_day_view(int year, int month, int day) {
                         "position: absolute;    "
                         "top: %ldpx; left: 0px; "
                         "height: %dpx;          "
+                       "font-size: %dpx;       "
                         "\" >                   "
-                        "<a href=\"display_edit_event?msgnum=0&calview=day"
-                        "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
-                        gap + ((hour - dayend - 1) * extratimeline ), extratimeline,
+                        "<a href=\"display_edit_event?msgnum=0?calview=day"
+                        "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
+                        gap + ((hour - dayend - 1) * extratimeline ),
+                       extratimeline,
+                       extrahourlabel,
                         year, month, day, hour
                 );
 
@@ -1199,9 +1266,9 @@ void calendar_day_view(int year, int month, int day) {
 
         wprintf("</ul>");
 
-       wprintf("</td>");       /** end extra on the middle */
+       wprintf("</td>");       /* end extra on the middle */
 
-       wprintf("<td width=20%% align=center valign=top>");     /** begin stuff-on-the-right */
+       wprintf("<td width=20%% align=center valign=top>");     /* begin stuff-on-the-right */
 
        /* Begin todays-date-with-left-and-right-arrows */
        wprintf("<table border=0 width=100%% "
@@ -1210,7 +1277,7 @@ void calendar_day_view(int year, int month, int day) {
 
        /* Left arrow */        
        wprintf("<td align=center>");
-       wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
+       wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
                yesterday.year, yesterday.month, yesterday.day);
        wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
        wprintf("</td>");
@@ -1227,7 +1294,7 @@ void calendar_day_view(int year, int month, int day) {
 
        /* Right arrow */
        wprintf("<td align=center>");
-       wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
+       wprintf("<a href=\"readfwd?calview=day?year=%d?month=%d?day=%d\">",
                tomorrow.year, tomorrow.month, tomorrow.day);
        wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
                " border=0></a>\n");
@@ -1238,26 +1305,25 @@ void calendar_day_view(int year, int month, int day) {
 
        /* Embed a mini month calendar in this space */
        wprintf("<br />\n");
-       embeddable_mini_calendar(year, month, "readfwd?calview=day&year=%d&month=%d&day=%d");
+       embeddable_mini_calendar(year, month);
 
        wprintf("</font></center>\n");
 
-       wprintf("</td></tr>");                  /** end stuff-on-the-right */
+       wprintf("</td></tr>");                  /* end stuff-on-the-right */
 
-       wprintf("</table>"                      /** end of inner table */
+       wprintf("</table>"                      /* end of inner table */
                "</div>");
 
-        wprintf("<script type=\"text/javascript\">"
-                " setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
-                "</script>\n"
+       StrBufAppendPrintf(WC->trailing_javascript,
+                " setTimeout(\"btt_enableTooltips('inner_day')\", 1);  \n"
         );
 }
 
 
 /*
- * Display today's events.
+ * Display today's events.  Returns the number of items displayed.
  */
-void calendar_summary_view(void) {
+int calendar_summary_view(void) {
        long hklen;
        const char *HashKey;
        void *vCal;
@@ -1271,20 +1337,20 @@ void calendar_summary_view(void) {
        time_t now;
        int all_day_event = 0;
        char timestring[SIZ];
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
+       int num_displayed = 0;
 
        if (GetCount(WC->disp_cal_items) == 0) {
-               return;
+               return(0);
        }
 
        now = time(NULL);
        localtime_r(&now, &today_tm);
 
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                Cal = (disp_cal*)vCal;
-               p = icalcomponent_get_first_property(Cal->cal,
-                                               ICAL_DTSTART_PROPERTY);
+               p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
                        event_tt = icaltime_as_timet(t);
@@ -1294,7 +1360,7 @@ void calendar_summary_view(void) {
                        else {
                                all_day_event = 0;
                        }
-                       fmt_time(timestring, event_tt);
+                       fmt_time(timestring, SIZ, event_tt);
 
                        if (all_day_event) {
                                gmtime_r(&event_tt, &event_tm);
@@ -1305,235 +1371,173 @@ void calendar_summary_view(void) {
 
                        if ( (event_tm.tm_year == today_tm.tm_year)
                                && (event_tm.tm_mon == today_tm.tm_mon)
-                       && (event_tm.tm_mday == today_tm.tm_mday)
+                               && (event_tm.tm_mday == today_tm.tm_mday)
                        ) {
 
+                               p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+                               if (p == NULL) {
+                                       p = icalproperty_new_summary(_("Untitled Task"));
+                                       icalcomponent_add_property(Cal->cal, p);
+                               }
+                               if (p != NULL) {
 
-                       p = icalcomponent_get_first_property(
-                               Cal->cal,
-                               ICAL_SUMMARY_PROPERTY);
-                       if (p != NULL) {
-                               escputs((char *)
-                                       icalproperty_get_comment(p));
-                               wprintf(" (%s)<br />\n", timestring);
-                       }
+
+                                       if (WCC->wc_view == VIEW_TASKS) {
+                                               wprintf("<a href=\"display_edit_task"
+                                                       "?msgnum=%ld"
+                                                       "?return_to_summary=1"
+                                                       "?gotofirst=",
+                                                       Cal->cal_msgnum
+                                               );
+                                               escputs(ChrPtr(WCC->wc_roomname));
+                                               wprintf("\">");
+                                       }
+                                       else {
+                                               wprintf("<a href=\"display_edit_event"
+                                                       "?msgnum=%ld"
+                                                       "?calview=summary"
+                                                       "?year=%d"
+                                                       "?month=%d"
+                                                       "?day=%d"
+                                                       "?gotofirst=",
+                                                       Cal->cal_msgnum,
+                                                       today_tm.tm_year + 1900,
+                                                       today_tm.tm_mon + 1,
+                                                       today_tm.tm_mday
+                                               );
+                                               escputs(ChrPtr(WCC->wc_roomname));
+                                               wprintf("\">");
+                                       }
+                                       escputs((char *) icalproperty_get_comment(p));
+                                       if (!all_day_event) {
+                                               wprintf(" (%s)", timestring);
+                                       }
+                                       wprintf("</a><br />\n");
+                                       ++num_displayed;
+                               }
                        }
                }
        }
        DeleteHashPos(&Pos);
        DeleteHash(&WC->disp_cal_items);
+       return(num_displayed);
 }
 
-
 /*
- * do the whole calendar page
- * view any part of the calender. decide which way, etc.
+ * Parse the URL variables in order to determine the scope and display of a calendar view
  */
-void do_calendar_view(void) {
+int calendar_GetParamsGetServerCall(SharedMessageStatus *Stat, 
+                                   void **ViewSpecific, 
+                                   long oper, 
+                                   char *cmd, 
+                                   long len)
+{
+       calview *c;
        time_t now;
        struct tm tm;
-       int year, month, day;
-       char calview[SIZ];
+       char cv[32];
 
+       int span = 3888000;
+
+       c = (calview*) malloc(sizeof(calview));
+       memset(c, 0, sizeof(calview));
+       *ViewSpecific = (void*)c;
+
+       Stat->load_seen = 1;
+       strcpy(cmd, "MSGS ALL");
+       Stat->maxmsgs = 32767;
+       
        /* In case no date was specified, go with today */
        now = time(NULL);
        localtime_r(&now, &tm);
-       year = tm.tm_year + 1900;
-       month = tm.tm_mon + 1;
-       day = tm.tm_mday;
+       c->year = tm.tm_year + 1900;
+       c->month = tm.tm_mon + 1;
+       c->day = tm.tm_mday;
 
        /* Now see if a date was specified */
-       if (havebstr("year")) year = ibstr("year");
-       if (havebstr("month")) month = ibstr("month");
-       if (havebstr("day")) day = ibstr("day");
+       if (havebstr("year")) c->year = ibstr("year");
+       if (havebstr("month")) c->month = ibstr("month");
+       if (havebstr("day")) c->day = ibstr("day");
 
        /* How would you like that cooked? */
        if (havebstr("calview")) {
-               strcpy(calview, bstr("calview"));
+               strcpy(cv, bstr("calview"));
        }
        else {
-               strcpy(calview, "month");
+               strcpy(cv, "month");
        }
 
        /* Display the selected view */
-       if (!strcasecmp(calview, "day")) {
-               calendar_day_view(year, month, day);
+       if (!strcasecmp(cv, "day")) {
+               c->view = calview_day;
        }
-       else if (!strcasecmp(calview, "week")) {
-               calendar_week_view(year, month, day);
+       else if (!strcasecmp(cv, "week")) {
+               c->view = calview_week;
+       }
+       else if (!strcasecmp(cv, "summary")) {  /* shouldn't ever happen, but just in case */
+               c->view = calview_day;
        }
        else {
                if (WC->wc_view == VIEW_CALBRIEF) {
-                       calendar_brief_month_view(year, month, day);
+                       c->view = calview_brief;
                }
                else {
-                       calendar_month_view(year, month, day);
+                       c->view = calview_month;
                }
        }
 
-       /* Free the in-memory list of calendar items */
-       DeleteHash(&WC->disp_cal_items);
-}
-
-
-/*
- * Helper function for do_tasks_view().  Returns the due date/time of a vtodo.
- */
-time_t get_task_due_date(icalcomponent *vtodo) {
-       icalproperty *p;
-
-       if (vtodo == NULL) {
-               return(0L);
-       }
-
-       /*
-        * If we're looking at a fully encapsulated VCALENDAR
-        * rather than a VTODO component, recurse into the data
-        * structure until we get a VTODO.
+       /* Now try and set the lower and upper bounds so that we don't
+        * burn too many cpu cycles parsing data way in the past or future
         */
-       if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
-               return get_task_due_date(
-                       icalcomponent_get_first_component(
-                               vtodo, ICAL_VTODO_COMPONENT
-                               )
-                       );
-       }
 
-       p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
-       if (p != NULL) {
-               return(icaltime_as_timet(icalproperty_get_due(p)));
-       }
-       else {
-               return(0L);
-       }
-}
+       tm.tm_year = c->year - 1900;
+       tm.tm_mon = c->month - 1;
+       tm.tm_mday = c->day;
+       now = mktime(&tm);
 
+       if (c->view == calview_month)   span = 3888000;
+       if (c->view == calview_brief)   span = 3888000;
+       if (c->view == calview_week)    span = 604800;
+       if (c->view == calview_day)     span = 86400;
+       if (c->view == calview_summary) span = 86400;
 
-/*
- * Compare the due dates of two tasks (this is for sorting)
- */
-int task_due_cmp(const void *vtask1, const void *vtask2) {
-       disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
-       disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
-
-       time_t t1;
-       time_t t2;
-
-       t1 =  get_task_due_date(Task1->cal);
-       t2 =  get_task_due_date(Task2->cal);
-       if (t1 < t2) return(-1);
-       if (t1 > t2) return(1);
-       return(0);
-}
-
-/*
- * qsort filter to move completed tasks to bottom of task list
- */
-int task_completed_cmp(const void *vtask1, const void *vtask2) {
-       disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
-//     disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
-
-       icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
-       // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
-       
-       if (t1 == ICAL_STATUS_COMPLETED) 
-               return 1;
-       return 0;
+       c->lower_bound = now - span;
+       c->upper_bound = now + span;
+       return 200;
 }
 
 
 
 /*
- * do the whole task view stuff
+ * Render a calendar view from data previously loaded into memory
  */
-void do_tasks_view(void) {
-       long hklen;
-       const char *HashKey;
-       void *vCal;
-       disp_cal *Cal;
-       HashPos *Pos;
-       int nItems;
-       time_t due;
-       char buf[SIZ];
-       icalproperty *p;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+int calendar_RenderView_or_Tail(SharedMessageStatus *Stat, 
+                               void **ViewSpecific, 
+                               long oper)
+{
+       calview *c = (calview*) *ViewSpecific;
 
-       wprintf("<div class=\"fix_scrollbar_bug\">"
-               "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
-               "<th>");
-       wprintf(_("Completed?"));
-       wprintf("</th><th>");
-       wprintf(_("Name of task"));
-       wprintf("</th><th>");
-       wprintf(_("Date due"));
-       wprintf("</th><th>");
-       wprintf(_("Category"));
-       wprintf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
-               _("Show All"));
-
-       nItems = GetCount(WC->disp_cal_items);
-
-       /* Sort them if necessary
-       if (nItems > 1) {
-               SortByPayload(WC->disp_cal_items, task_due_cmp);
+       if (c->view == calview_day) {
+               calendar_day_view(c->year, c->month, c->day);
        }
-       * this shouldn't be neccessary, since we sort by the start time.
-       */
-
-       /* And then again, by completed */
-       if (nItems > 1) {
-               SortByPayload(WC->disp_cal_items, 
-                             task_completed_cmp);
+       else if (c->view == calview_week) {
+               calendar_week_view(c->year, c->month, c->day);
        }
-
-       Pos = GetNewHashPos();
-       while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
-               Cal = (disp_cal*)vCal;
-               wprintf("<tr><td>");
-               icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
-               wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
-               if (todoStatus == ICAL_STATUS_COMPLETED) {
-                       wprintf("checked=\"checked\" ");
-               }
-               wprintf("disabled=\"disabled\">\n</td><td>");
-               p = icalcomponent_get_first_property(Cal->cal,
-                       ICAL_SUMMARY_PROPERTY);
-               wprintf("<a href=\"display_edit_task?msgnum=%ld&amp;taskrm=",
-                       Cal->cal_msgnum );
-               urlescputs(WC->wc_roomname);
-               wprintf("\">");
-               /* wprintf("<img align=middle "
-               "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;"); */
-               if (p != NULL) {
-                       escputs((char *)icalproperty_get_comment(p));
-               }
-               wprintf("</a>\n");
-               wprintf("</td>\n");
-
-               due = get_task_due_date(Cal->cal);
-               wprintf("<td><span");
-               if (due > 0) {
-                       webcit_fmt_date(buf, due, 0);
-                       wprintf(">%s",buf);
+       else {
+               if (WC->wc_view == VIEW_CALBRIEF) {
+                       calendar_brief_month_view(c->year, c->month, c->day);
                }
                else {
-                       wprintf(">");
+                       calendar_month_view(c->year, c->month, c->day);
                }
-               wprintf("</span></td>");
-               wprintf("<td>");
-               p = icalcomponent_get_first_property(Cal->cal,
-                       ICAL_CATEGORIES_PROPERTY);
-               if (p != NULL) {
-                       escputs((char *)icalproperty_get_categories(p));
-               }
-               wprintf("</td>");
-               wprintf("</tr>");
        }
 
-       wprintf("</tbody></table></div>\n");
-
-       /* Free the list */
+       /* Free the in-memory list of calendar items */
        DeleteHash(&WC->disp_cal_items);
-       DeleteHashPos(&Pos);
+       return 0;
 }
 
+
+
+
+