X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fcalendar_view.c;h=c43cb5b979f92abc36022bd9292cbba077657f47;hb=aa8ca3b0af3efdabd8559b886efb3164319bdce1;hp=94ba0833d81279a776b2d8ec1f551f523fc0b1ca;hpb=2781973f43a71bd9c31fb8223ff607702a3613bd;p=citadel.git diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 94ba0833d..c43cb5b97 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -1,35 +1,20 @@ /* * $Id$ * - * + * Handles the HTML display of calendar items. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "webcit.h" #include "webserver.h" #ifndef WEBCIT_WITH_CALENDAR_SERVICE void do_calendar_view(void) { /* stub for non-libical builds */ - wprintf("
Calendar view not available

\n"); + wprintf("
Calendar view not available

\n"); +} + +void do_tasks_view(void) { /* stub for non-libical builds */ + wprintf("
Tasks view not available

\n"); } #else /* WEBCIT_WITH_CALENDAR_SERVICE */ @@ -48,31 +33,38 @@ void calendar_month_view_display_events(time_t thetime) { int all_day_event = 0; if (WC->num_cal == 0) { - wprintf("


\n"); + wprintf("


\n"); return; } - memcpy(&today_tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &today_tm); month = today_tm.tm_mon + 1; day = today_tm.tm_mday; year = today_tm.tm_year + 1900; for (i=0; i<(WC->num_cal); ++i) { - p = icalcomponent_get_first_property(WC->disp_cal[i], + p = icalcomponent_get_first_property(WC->disp_cal[i].cal, ICAL_DTSTART_PROPERTY); if (p != NULL) { t = icalproperty_get_dtstart(p); event_tt = icaltime_as_timet(t); - memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm)); + + if (t.is_date) all_day_event = 1; + else all_day_event = 0; + + if (all_day_event) { + gmtime_r(&event_tt, &event_tm); + } + else { + localtime_r(&event_tt, &event_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; - else all_day_event = 0; - p = icalcomponent_get_first_property( - WC->disp_cal[i], + WC->disp_cal[i].cal, ICAL_SUMMARY_PROPERTY); if (p != NULL) { @@ -84,7 +76,7 @@ void calendar_month_view_display_events(time_t thetime) { wprintf("" "", - WC->cal_msgnum[i], + WC->disp_cal[i].cal_msgnum, bstr("calview"), bstr("year"), bstr("month"), @@ -92,7 +84,7 @@ void calendar_month_view_display_events(time_t thetime) { ); escputs((char *) icalproperty_get_comment(p)); - wprintf("
\n"); + wprintf("
\n"); if (all_day_event) { wprintf(""); @@ -129,7 +121,7 @@ void calendar_month_view(int year, int month, int day) { memcpy(&tm, &starting_tm, sizeof(struct tm)); while (tm.tm_mday != 1) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); } /* Determine previous and next months ... for links */ @@ -137,64 +129,58 @@ void calendar_month_view(int year, int month, int day) { next_month = thetime + (time_t)(31L * 86400L); /* ahead 31 days */ /* Now back up until we're on a Sunday */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); while (tm.tm_wday != 0) { thetime = thetime - (time_t)86400; /* go back 24 hours */ - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); } /* Outer table (to get the background color) */ - wprintf("" + "
\n"); - wprintf("" - "\n", - year, month, day - ); + wprintf("
" - " " - "Add new calendar event" - "
\n"); - wprintf("

"); + wprintf("

"); - memcpy(&tm, localtime(&previous_month), sizeof(struct tm)); + localtime_r(&previous_month, &tm); wprintf("", (int)(tm.tm_year)+1900, tm.tm_mon + 1); - wprintf("\n"); + wprintf("\n"); wprintf("  " - "" + "" "%s %d" "" "  ", months[month-1], year); - memcpy(&tm, localtime(&next_month), sizeof(struct tm)); + localtime_r(&next_month, &tm); wprintf("", (int)(tm.tm_year)+1900, tm.tm_mon + 1); - wprintf("\n"); + wprintf("\n"); - wprintf("" - "Click on any date for day view " - "
\n"); + wprintf("
\n"); /* Inner table (the real one) */ wprintf(""); + "bgcolor=#204B78>"); for (i=0; i<7; ++i) { - wprintf("", days[i]); + wprintf("\n"); /* Now do 35 days */ for (i = 0; i < 35; ++i) { - memcpy(&tm, localtime(&thetime), sizeof(struct tm)); + localtime_r(&thetime, &tm); /* Before displaying Sunday, start a new row */ if ((i % 7) == 0) { wprintf(""); } - wprintf("
%s" + "%s", days[i]); } + wprintf("
", + wprintf("", ((tm.tm_mon != month-1) ? "DDDDDD" : ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" : "FFFFFF")) @@ -203,7 +189,7 @@ void calendar_month_view(int year, int month, int day) { wprintf("%s ", months[tm.tm_mon]); } wprintf("" - "%d
", + "%d
", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, @@ -224,12 +210,12 @@ void calendar_month_view(int year, int month, int day) { wprintf("
" /* end of inner table */ "" /* end of outer table */ - "\n"); + "\n"); } void calendar_week_view(int year, int month, int day) { - wprintf("
week view FIXME

\n"); + wprintf("
week view FIXME

\n"); } @@ -247,27 +233,34 @@ void calendar_day_view_display_events(int year, int month, int all_day_event = 0; if (WC->num_cal == 0) { - wprintf("


\n"); + // FIXME wprintf("


\n"); return; } for (i=0; i<(WC->num_cal); ++i) { - p = icalcomponent_get_first_property(WC->disp_cal[i], + p = icalcomponent_get_first_property(WC->disp_cal[i].cal, ICAL_DTSTART_PROPERTY); if (p != NULL) { t = icalproperty_get_dtstart(p); event_tt = icaltime_as_timet(t); - event_tm = localtime(&event_tt); + if (t.is_date) all_day_event = 1; + + if (all_day_event) { + event_tm = gmtime(&event_tt); + } + else { + event_tm = localtime(&event_tt); + } + if ((event_tm->tm_year == (year-1900)) && (event_tm->tm_mon == (month-1)) && (event_tm->tm_mday == day) && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) ) ) { - if (t.is_date) all_day_event = 1; p = icalcomponent_get_first_property( - WC->disp_cal[i], + WC->disp_cal[i].cal, ICAL_SUMMARY_PROPERTY); if (p != NULL) { @@ -279,12 +272,12 @@ void calendar_day_view_display_events(int year, int month, wprintf("" "", - WC->cal_msgnum[i], + WC->disp_cal[i].cal_msgnum, year, month, day ); escputs((char *) icalproperty_get_comment(p)); - wprintf("
\n"); + wprintf("
\n"); if (all_day_event) { wprintf(""); @@ -303,7 +296,9 @@ void calendar_day_view_display_events(int year, int month, void calendar_day_view(int year, int month, int day) { int hour; struct icaltimetype today, yesterday, tomorrow; + char calhourformat[16]; + get_preference("calhourformat", calhourformat, sizeof calhourformat); /* Figure out the dates for "yesterday" and "tomorrow" links */ @@ -323,7 +318,8 @@ void calendar_day_view(int year, int month, int day) { /* Outer table (to get the background color) */ - wprintf("" + "
\n"); /* Inner table (the real one) */ @@ -352,10 +348,17 @@ void calendar_day_view(int year, int month, int day) { "&year=%d&month=%d&day=%d&hour=%d&minute=0\">", year, month, day, hour ); - wprintf("%d:00%s ", - (hour <= 12 ? hour : hour-12), - (hour < 12 ? "am" : "pm") - ); + + if (!strcasecmp(calhourformat, "24")) { + wprintf("%2d:00 ", hour); + } + else { + wprintf("%d:00%s ", + (hour <= 12 ? hour : hour-12), + (hour < 12 ? "am" : "pm") + ); + } + wprintf(""); /* put the data here, stupid */ @@ -382,40 +385,37 @@ void calendar_day_view(int year, int month, int day) { /* Begin todays-date-with-left-and-right-arrows */ - wprintf("
\n"); - - wprintf("\n"); - - wprintf("", + wprintf("
" - "", - yesterday.year, yesterday.month, yesterday.day - ); - wprintf("" - "" - "

%s

%d

%d

" - "
\n"); + wprintf(""); + + /* Left arrow */ + wprintf(""); + + /* Today's date */ + wprintf(""); - wprintf("\n"); + /* Right arrow */ + wprintf(""); - wprintf("
"); + wprintf("", + yesterday.year, yesterday.month, yesterday.day); + wprintf(""); + wprintf(""); + wprintf("%s
" + "%d
" + "%d
", months[month-1], day, year); + wprintf("
" - "", - tomorrow.year, tomorrow.month, tomorrow.day - ); - wprintf(""); + wprintf("", + tomorrow.year, tomorrow.month, tomorrow.day); + wprintf("\n"); + wprintf("
\n"); + wprintf("
\n"); /* End todays-date-with-left-and-right-arrows */ - wprintf("
" - " " - "Add new calendar event" - "

\n", - year, month, day - ); - - wprintf("" - "Back to month view\n", year, month); + /* In the future we might want to put a month-o-matic here */ wprintf("
\n"); @@ -424,7 +424,7 @@ void calendar_day_view(int year, int month, int day) { wprintf("" /* end of inner table */ - "" /* end of outer table */ + "" /* end of outer table */ ); @@ -450,38 +450,41 @@ void calendar_summary_view(void) { } now = time(NULL); - memcpy(&today_tm, localtime(&now), sizeof(struct tm)); - - wprintf("
    "); + localtime_r(&now, &today_tm); for (i=0; i<(WC->num_cal); ++i) { - p = icalcomponent_get_first_property(WC->disp_cal[i], + p = icalcomponent_get_first_property(WC->disp_cal[i].cal, ICAL_DTSTART_PROPERTY); if (p != NULL) { t = icalproperty_get_dtstart(p); event_tt = icaltime_as_timet(t); + if (t.is_date) all_day_event = 1; fmt_time(timestring, event_tt); - memcpy(&event_tm, localtime(&event_tt), sizeof(struct tm)); + + if (all_day_event) { + gmtime_r(&event_tt, &event_tm); + } + else { + localtime_r(&event_tt, &event_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], + WC->disp_cal[i].cal, ICAL_SUMMARY_PROPERTY); if (p != NULL) { - wprintf("
  • "); escputs((char *) icalproperty_get_comment(p)); - wprintf(" (%s)\n", timestring); + wprintf(" (%s)
    \n", timestring); } } } } - wprintf("
\n"); free_calendar_buffer(); } @@ -490,13 +493,11 @@ void calendar_summary_view(void) { 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]); + icalcomponent_free(WC->disp_cal[i].cal); } WC->num_cal = 0; free(WC->disp_cal); WC->disp_cal = NULL; - free(WC->cal_msgnum); - WC->cal_msgnum = NULL; } @@ -510,7 +511,7 @@ void do_calendar_view(void) { /* In case no date was specified, go with today */ now = time(NULL); - memcpy(&tm, localtime(&now), sizeof(struct tm)); + localtime_r(&now, &tm); year = tm.tm_year + 1900; month = tm.tm_mon + 1; day = tm.tm_mday; @@ -544,4 +545,115 @@ void do_calendar_view(void) { } + +/* + * Helper function for do_tasks_view(). Returns the date/time due. + */ +time_t get_task_due_date(icalcomponent *vtodo) { + icalproperty *p; + + if (vtodo == NULL) { + return(0L); + } + + /* If we're looking at a fully encapsulated VCALENDAR + * rather than a VTODO component, recurse into the data + * structure until we get a VTODO. + */ + if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) { + return get_task_due_date( + icalcomponent_get_first_component( + vtodo, ICAL_VTODO_COMPONENT + ) + ); + } + + p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY); + if (p != NULL) { + return(icaltime_as_timet(icalproperty_get_due(p))); + } + else { + return(0L); + } +} + + +/* + * Compare the due dates of two tasks (this is for sorting) + */ +int task_due_cmp(const void *task1, const void *task2) { + time_t t1; + time_t t2; + + t1 = get_task_due_date(((struct disp_cal *)task1)->cal); + t2 = get_task_due_date(((struct disp_cal *)task2)->cal); + + if (t1 < t2) return(-1); + if (t1 > t2) return(1); + return(0); +} + + + + + +void do_tasks_view(void) { + int i; + time_t due; + int bg = 0; + char buf[SIZ]; + icalproperty *p; + + wprintf("
" + "\n\n" + "\n" + "\n" + ); + + /* Sort them if necessary */ + if (WC->num_cal > 1) { + qsort(WC->disp_cal, + WC->num_cal, + sizeof(struct disp_cal), + task_due_cmp + ); + } + + if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) { + + bg = 1 - bg; + wprintf("\n"); + + due = get_task_due_date(WC->disp_cal[i].cal); + fmt_date(buf, due, 0); + wprintf("\n", buf); + } + + wprintf("
Name of taskDate due
", + (bg ? "DDDDDD" : "FFFFFF") + ); + + p = icalcomponent_get_first_property(WC->disp_cal[i].cal, + ICAL_SUMMARY_PROPERTY); + wprintf("disp_cal[i].cal_msgnum ); + urlescputs(WC->wc_roomname); + wprintf("\">"); + wprintf(" "); + if (p != NULL) { + escputs((char *)icalproperty_get_comment(p)); + } + wprintf("\n"); + wprintf("%s
\n"); + + /* Free the list */ + free_calendar_buffer(); + +} + #endif /* WEBCIT_WITH_CALENDAR_SERVICE */