]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
* follow api-change in several places
[citadel.git] / webcit / calendar_view.c
index f4de52a960e7b306663295b9e25d0bc4d199d8a4..14112d0932918217dd91821ace59899a7f90276a 100644 (file)
@@ -47,11 +47,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,13 +90,13 @@ 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>");
                        }
@@ -110,17 +110,17 @@ 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 */
@@ -129,22 +129,21 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
                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"
-               ,
+       StrBufAppendPrintf(WC->trailing_javascript,
+               "       function minical_change_month(year, month) {                                    \n"
+               "               p = 'year=' + year + '&month=' + month                                  \n"
+               "                       + '&urlformat=%s&r=' + CtdlRandomString();                      \n"
+               "               new Ajax.Updater('%s', 'mini_calendar',                                 \n"
+               "                       { method: 'get', parameters: p, evalScripts: true } );          \n"
+               "       }                                                                               \n"
+               "",
                escaped_urlformat, 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];
@@ -162,9 +161,8 @@ void ajax_mini_calendar(void) {
 }
 
 
-/**
- * \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)
 {
@@ -192,7 +190,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 +213,10 @@ 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;
 
-       /**
+       /*
         * 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;
@@ -247,7 +245,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                        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) {
@@ -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
                                 */
@@ -310,7 +308,7 @@ void calendar_month_view_display_events(int year, int month, int day)
                                                        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.
                                                         */
@@ -353,9 +351,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;
@@ -388,7 +385,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);
@@ -430,8 +427,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 +475,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 +507,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 +519,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 +531,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 +553,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 +614,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 +667,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 +679,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 +734,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");
 }
 
@@ -838,7 +825,7 @@ void calendar_day_view_display_events(time_t thetime,
 
        /* 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;
 
@@ -886,7 +873,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",
@@ -924,7 +911,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",
@@ -1005,7 +992,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);
@@ -1058,6 +1045,12 @@ void calendar_day_view(int year, int month, int day) {
        time_format = get_time_format_cached ();
        get_pref_long("daystart", &daystart, 8);
        get_pref_long("dayend", &dayend, 17);
+
+       /* when loading daystart/dayend, replace missing, corrupt, or impossible values with defaults */
+       if ((daystart < 0) || (dayend < 2) || (daystart >= 23) || (dayend > 23) || (dayend <= daystart)) {
+               daystart = 9;
+               dayend = 17;
+       }
        
        /* Today's date */
        memset(&d_tm, 0, sizeof d_tm);
@@ -1103,7 +1096,7 @@ void calendar_day_view(int year, int month, int day) {
                        "height: %dpx;          "       
                        "\" >                   "
                        "<a href=\"display_edit_event?msgnum=0"
-                       "&calview=day&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
+                       "?calview=day?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
                        (hour * extratimeline ), extratimeline, 
                        year, month, day, hour
                        );
@@ -1130,8 +1123,8 @@ void calendar_day_view(int year, int month, int day) {
                         "top: %ldpx; left: 0px;  "
                         "height: %dpx;          "
                         "\" >                   "
-                        "<a href=\"display_edit_event?msgnum=0&calview=day"
-                        "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
+                        "<a href=\"display_edit_event?msgnum=0?calview=day"
+                        "?year=%d?month=%d?day=%d?hour=%d?minute=0\">",
                         gap + ((hour - daystart) * timeline ), timeline,
                         year, month, day, hour
                        );
@@ -1158,8 +1151,8 @@ void calendar_day_view(int year, int month, int day) {
                         "top: %ldpx; left: 0px; "
                         "height: %dpx;          "
                         "\" >                   "
-                        "<a href=\"display_edit_event?msgnum=0&calview=day"
-                        "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
+                        "<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,
                         year, month, day, hour
                 );
@@ -1193,9 +1186,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%% "
@@ -1204,7 +1197,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>");
@@ -1221,7 +1214,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");
@@ -1232,18 +1225,17 @@ 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, "readfwd?calview=day?year=%d?month=%d?day=%d");
 
        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"
         );
 }
 
@@ -1274,7 +1266,7 @@ void calendar_summary_view(void) {
        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,
@@ -1320,26 +1312,24 @@ void calendar_summary_view(void) {
 
 
 /*
- * 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) {
+void parse_calendar_view_request(struct calview *c) {
        time_t now;
        struct tm tm;
-       int year, month, day;
-       char calview[SIZ];
+       char calview[32];
 
        /* 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")) {
@@ -1351,17 +1341,58 @@ void do_calendar_view(void) {
 
        /* Display the selected view */
        if (!strcasecmp(calview, "day")) {
-               calendar_day_view(year, month, day);
+               c->view = calview_day;
        }
        else if (!strcasecmp(calview, "week")) {
-               calendar_week_view(year, month, day);
+               c->view = calview_week;
+       }
+       else {
+               if (WC->wc_view == VIEW_CALBRIEF) {
+                       c->view = calview_brief;
+               }
+               else {
+                       c->view = calview_month;
+               }
+       }
+
+       /* 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
+        */
+
+       tm.tm_year = c->year - 1900;
+       tm.tm_mon = c->month - 1;
+       tm.tm_mday = c->day;
+       now = mktime(&tm);
+
+       int span = 3888000;
+       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;
+
+       c->lower_bound = now - span;
+       c->upper_bound = now + span;
+}
+
+
+
+/*
+ * Render a calendar view from data previously loaded into memory
+ */
+void render_calendar_view(struct calview *c)
+{
+       if (c->view == calview_day) {
+               calendar_day_view(c->year, c->month, c->day);
+       }
+       else if (c->view == calview_week) {
+               calendar_week_view(c->year, c->month, c->day);
        }
        else {
                if (WC->wc_view == VIEW_CALBRIEF) {
-                       calendar_brief_month_view(year, month, day);
+                       calendar_brief_month_view(c->year, c->month, c->day);
                }
                else {
-                       calendar_month_view(year, month, day);
+                       calendar_month_view(c->year, c->month, c->day);
                }
        }
 
@@ -1480,7 +1511,7 @@ void do_tasks_view(void) {
                              task_completed_cmp);
        }
 
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
                Cal = (disp_cal*)vCal;
                wprintf("<tr><td>");