/*
* 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;
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);
time_t colheader_time;
struct tm colheader_tm;
char colheader_label[32];
- int chg_month = 0;
long weekstart = 0;
/*
/* 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 */
/* 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;
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,
/*
- * 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")) {
/* 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);
}
}
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>");