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