+/**
+ * \brief Display one day of a whole month view of a calendar
+ * \param thetime the month we want to see
+ */
+void calendar_month_view_display_events(int year, int month, int day)
+{
+ int i;
+ icalproperty *p = NULL;
+ icalproperty *q = NULL;
+ struct icaltimetype t;
+ struct icaltimetype end_t;
+ struct icaltimetype today_start_t;
+ struct icaltimetype today_end_t;
+ struct tm starting_tm;
+ struct tm ending_tm;
+ int all_day_event = 0;
+ int show_event = 0;
+ char buf[256];
+ struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ struct disp_cal *Cal;
+ time_t tt;
+
+ if (WCC->num_cal == 0) {
+ wprintf("<br /><br /><br />\n");
+ 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.
+ */
+ memset(&starting_tm, 0, sizeof(struct tm));
+ starting_tm.tm_year = year - 1900;
+ starting_tm.tm_mon = month - 1;
+ starting_tm.tm_mday = day;
+ starting_tm.tm_hour = 0;
+ starting_tm.tm_min = 0;
+ today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
+ today_start_t.is_utc = 1;
+
+ memset(&ending_tm, 0, sizeof(struct tm));
+ ending_tm.tm_year = year - 1900;
+ ending_tm.tm_mon = month - 1;
+ ending_tm.tm_mday = day;
+ ending_tm.tm_hour = 23;
+ ending_tm.tm_min = 59;
+ 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.
+ */
+ for (i=0; i<(WCC->num_cal); ++i) {
+ Cal = &WCC->disp_cal[i];
+ all_day_event = 0;
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtstart(q);
+ }
+ else {
+ memset(&t, 0, sizeof t);
+ }
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+ if (q != NULL) {
+ end_t = icalproperty_get_dtend(q);
+ }
+ else {
+ memset(&end_t, 0, sizeof end_t);
+ }
+ if (t.is_date) all_day_event = 1;
+
+ if (all_day_event)
+ {
+ show_event = ((t.year == year) && (t.month == month) && (t.day == day));
+ }
+ else
+ {
+ 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) {
+ p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+ if (p != NULL) {
+
+ if (all_day_event) {
+ wprintf("<table border=0 cellpadding=2><TR>"
+ "<td bgcolor=\"#CCCCDD\">"
+ );
+ }
+
+ wprintf("<font size=-1>"
+ "<a href=\"display_edit_event?"
+ "msgnum=%ld&calview=month&year=%d&month=%d&day=%d\""
+ " btt_tooltext=\"",
+ WC->disp_cal[i].cal_msgnum,
+ year, month, day
+ );
+
+ wprintf("<i>%s</i> ", _("Summary:"));
+ escputs((char *)icalproperty_get_comment(p));
+ wprintf("<br />");
+
+ q = icalcomponent_get_first_property(
+ WC->disp_cal[i].cal,
+ ICAL_LOCATION_PROPERTY);
+ if (q) {
+ wprintf("<i>%s</i> ", _("Location:"));
+ escputs((char *)icalproperty_get_comment(q));
+ 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
+ */
+ if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
+
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtstart(q);
+
+ if (t.is_date) {
+ struct tm d_tm;
+ char d_str[32];
+ memset(&d_tm, 0, sizeof d_tm);
+ d_tm.tm_year = t.year - 1900;
+ d_tm.tm_mon = t.month - 1;
+ d_tm.tm_mday = t.day;
+ wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
+ wprintf("<i>%s</i> %s<br>",
+ _("Date:"), d_str);
+ }
+ else {
+ tt = icaltime_as_timet(t);
+ webcit_fmt_date(buf, tt, 1);
+ 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.
+ */
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtend(q);
+ tt = icaltime_as_timet(t);
+ webcit_fmt_date(buf, tt, 1);
+ wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
+ }
+
+ }
+ }
+
+ }
+
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
+ if (q) {
+ wprintf("<i>%s</i> ", _("Notes:"));
+ escputs((char *)icalproperty_get_comment(q));
+ wprintf("<br />");
+ }
+
+ wprintf("\">");
+ escputs((char *)
+ icalproperty_get_comment(p));
+ wprintf("</a></font><br />\n");
+
+ if (all_day_event) {
+ wprintf("</td></tr></table>");
+ }
+
+ }
+
+ }
+
+
+ }
+}