]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
* follow api-change in several places
[citadel.git] / webcit / calendar_view.c
index cccbdc8129c6141acc9e5975b515a2216df639fe..14112d0932918217dd91821ace59899a7f90276a 100644 (file)
@@ -216,7 +216,7 @@ void calendar_month_view_display_events(int year, int month, int 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;
@@ -385,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);
@@ -475,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;
 
        /*
@@ -554,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 */
@@ -832,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;
 
@@ -1273,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,
@@ -1319,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")) {
@@ -1350,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);
                }
        }
 
@@ -1479,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>");