#include "webcit.h"
#include "webserver.h"
-#ifndef HAVE_ICAL_H
+#ifndef WEBCIT_WITH_CALENDAR_SERVICE
void do_calendar_view(void) { /* stub for non-libical builds */
wprintf("<CENTER><I>Calendar view not available</I></CENTER><BR>\n");
}
-#else /* HAVE_ICAL_H */
+#else /* WEBCIT_WITH_CALENDAR_SERVICE */
/****************************************************************************/
-#include "ical.h"
void calendar_month_view_display_events(time_t thetime) {
int i;
if (all_day_event) {
wprintf("<TABLE border=0 cellpadding=2><TR>"
- "<TD BGCOLOR=#CCCCDD>"
+ "<TD BGCOLOR=\"#CCCCDD\">"
);
}
void calendar_month_view(int year, int month, int day) {
struct tm starting_tm;
- struct tm *tm;
+ struct tm tm;
time_t thetime;
int i;
time_t previous_month;
starting_tm.tm_mday = day;
thetime = mktime(&starting_tm);
- tm = &starting_tm;
- while (tm->tm_mday != 1) {
+ memcpy(&tm, &starting_tm, sizeof(struct tm));
+ while (tm.tm_mday != 1) {
thetime = thetime - (time_t)86400; /* go back 24 hours */
- tm = localtime(&thetime);
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
}
/* Determine previous and next months ... for links */
next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */
/* Now back up until we're on a Sunday */
- tm = localtime(&thetime);
- while (tm->tm_wday != 0) {
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
+ while (tm.tm_wday != 0) {
thetime = thetime - (time_t)86400; /* go back 24 hours */
- tm = localtime(&thetime);
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
}
/* Outer table (to get the background color) */
wprintf("<TD><CENTER><H3>");
- tm = localtime(&previous_month);
+ memcpy(&tm, localtime(&previous_month), sizeof(struct tm));
wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
- (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+ (int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>\n");
wprintf(" "
- "<FONT COLOR=#FFFFFF>"
+ "<FONT COLOR=\"#FFFFFF\">"
"%s %d"
"</FONT>"
" ", months[month-1], year);
- tm = localtime(&next_month);
+ memcpy(&tm, localtime(&next_month), sizeof(struct tm));
wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
- (int)(tm->tm_year)+1900, tm->tm_mon + 1);
+ (int)(tm.tm_year)+1900, tm.tm_mon + 1);
wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/forward.gif\" BORDER=0></A>\n");
wprintf("</H3></TD><TD align=right><font color=#FFFFFF size=-2>"
wprintf("<TABLE width=100%% border=0 cellpadding=1 cellspacing=1 "
"bgcolor=#4444FF>");
for (i=0; i<7; ++i) {
- wprintf("<TH><FONT COLOR=#FFFFFF>%s</FONT></TH>", days[i]);
+ wprintf("<TH><FONT COLOR=\"#FFFFFF\">%s</FONT></TH>", days[i]);
}
/* Now do 35 days */
for (i = 0; i < 35; ++i) {
- tm = localtime(&thetime);
- if (tm->tm_wday == 0) {
+ memcpy(&tm, localtime(&thetime), sizeof(struct tm));
+
+ /* Before displaying Sunday, start a new row */
+ if ((i % 7) == 0) {
wprintf("<TR>");
}
- wprintf("<TD BGCOLOR=%s WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
- ((tm->tm_mon != month-1) ? "DDDDDD" :
- ((tm->tm_wday==0 || tm->tm_wday==6) ? "EEEECC" :
+ wprintf("<TD BGCOLOR=\"#%s\" WIDTH=14%% HEIGHT=60 VALIGN=TOP><B>",
+ ((tm.tm_mon != month-1) ? "DDDDDD" :
+ ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
"FFFFFF"))
);
- if ((i==0) || (tm->tm_mday == 1)) {
- wprintf("%s ", months[tm->tm_mon]);
+ if ((i==0) || (tm.tm_mday == 1)) {
+ wprintf("%s ", months[tm.tm_mon]);
}
wprintf("<A HREF=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
"%d</A></B><BR>",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_mday);
+ tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday,
+ tm.tm_mday);
/* put the data here, stupid */
calendar_month_view_display_events(thetime);
wprintf("</TD>");
- if (tm->tm_wday == 6) {
+ /* After displaying Saturday, end the row */
+ if ((i % 7) == 6) {
wprintf("</TR>\n");
}
if (all_day_event) {
wprintf("<TABLE border=1 cellpadding=2><TR>"
- "<TD BGCOLOR=#CCCCCC>"
+ "<TD BGCOLOR=\"#CCCCCC\">"
);
}
/* Display events before 8:00 (hour=-1 is all-day events) */
wprintf("<TR>"
- "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
- "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
+ "<TD BGCOLOR=\"#CCCCDD\" VALIGN=MIDDLE WIDTH=10%%></TD>"
+ "<TD BGCOLOR=\"#FFFFFF\" VALIGN=TOP>");
for (hour = (-1); hour <= 7; ++hour) {
calendar_day_view_display_events(year, month, day, hour);
}
/* Now the middle of the day... */
for (hour = 8; hour <= 17; ++hour) { /* could do HEIGHT=xx */
- wprintf("<TR HEIGHT=30><TD BGCOLOR=CCCCDD ALIGN=MIDDLE "
+ wprintf("<TR HEIGHT=30><TD BGCOLOR=\"#CCCCDD\" ALIGN=MIDDLE "
"VALIGN=MIDDLE WIDTH=10%%>");
wprintf("<A HREF=\"/display_edit_event?msgnum=0"
"&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
(hour <= 12 ? hour : hour-12),
(hour < 12 ? "am" : "pm")
);
- wprintf("</TD><TD BGCOLOR=FFFFFF VALIGN=TOP>");
+ wprintf("</TD><TD BGCOLOR=\"#FFFFFF\" VALIGN=TOP>");
/* put the data here, stupid */
calendar_day_view_display_events(year, month, day, hour);
/* Display events after 5:00... */
wprintf("<TR>"
- "<TD BGCOLOR=CCCCDD VALIGN=MIDDLE WIDTH=10%%></TD>"
- "<TD BGCOLOR=FFFFFF VALIGN=TOP>");
+ "<TD BGCOLOR=\"#CCCCDD\" VALIGN=MIDDLE WIDTH=10%%></TD>"
+ "<TD BGCOLOR=\"#FFFFFF\" VALIGN=TOP>");
for (hour = 18; hour <= 23; ++hour) {
calendar_day_view_display_events(year, month, day, hour);
}
wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/back.gif\" BORDER=0></A>"
"</TD>\n");
- wprintf("<TD ALIGN=MIDDLE><FONT COLOR=#FFFFFF>"
+ wprintf("<TD ALIGN=MIDDLE><FONT COLOR=\"#FFFFFF\">"
"<H2>%s</H2><H1>%d</H1><H3>%d</H3>"
"</FONT></TD>",
months[month-1], day, year);
}
+/*
+ * Display today's events.
+ */
+void calendar_summary_view(void) {
+ int i;
+ icalproperty *p;
+ struct icaltimetype t;
+ time_t event_tt;
+ struct tm event_tm;
+ struct tm today_tm;
+ time_t now;
+ int all_day_event = 0;
+ char timestring[SIZ];
+
+ if (WC->num_cal == 0) {
+ return;
+ }
+ now = time(NULL);
+ memcpy(&today_tm, localtime(&now), sizeof(struct tm));
+ wprintf("<UL>");
-void do_calendar_view(void) {
+ for (i=0; i<(WC->num_cal); ++i) {
+ p = icalcomponent_get_first_property(WC->disp_cal[i],
+ ICAL_DTSTART_PROPERTY);
+ if (p != NULL) {
+ t = icalproperty_get_dtstart(p);
+ event_tt = icaltime_as_timet(t);
+ fmt_time(timestring, event_tt);
+ memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm));
+ 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)
+ ) {
+
+ if (t.is_date) all_day_event = 1;
+
+ p = icalcomponent_get_first_property(
+ WC->disp_cal[i],
+ ICAL_SUMMARY_PROPERTY);
+ if (p != NULL) {
+ wprintf("<LI>");
+ escputs((char *)
+ icalproperty_get_comment(p));
+ wprintf(" (%s)\n", timestring);
+ }
+ }
+ }
+ }
+ wprintf("</UL>\n");
+ free_calendar_buffer();
+}
+
+
+
+void free_calendar_buffer(void) {
int i;
+ if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
+ icalcomponent_free(WC->disp_cal[i]);
+ }
+ WC->num_cal = 0;
+ free(WC->disp_cal);
+ WC->disp_cal = NULL;
+ free(WC->cal_msgnum);
+ WC->cal_msgnum = NULL;
+}
+
+
+
+
+void do_calendar_view(void) {
time_t now;
- struct tm *tm;
+ struct tm tm;
int year, month, day;
char calview[SIZ];
/* In case no date was specified, go with today */
now = time(NULL);
- tm = localtime(&now);
- year = tm->tm_year + 1900;
- month = tm->tm_mon + 1;
- day = tm->tm_mday;
+ memcpy(&tm, localtime(&now), sizeof(struct tm));
+ year = tm.tm_year + 1900;
+ month = tm.tm_mon + 1;
+ day = tm.tm_mday;
/* Now see if a date was specified */
if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
}
/* Free the calendar stuff */
- if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
- icalcomponent_free(WC->disp_cal[i]);
- }
- WC->num_cal = 0;
- free(WC->disp_cal);
- WC->disp_cal = NULL;
- free(WC->cal_msgnum);
- WC->cal_msgnum = NULL;
-}
+ free_calendar_buffer();
+}
-#endif /* HAVE_ICAL_H */
+#endif /* WEBCIT_WITH_CALENDAR_SERVICE */