]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
I began to use CSS for the calendar display
[citadel.git] / webcit / calendar_view.c
index 9315c55565b344dc95a9222628a976ad863a89b1..4deefb22c4ac59adbf4381de2f1ac569f663d844 100644 (file)
@@ -36,9 +36,12 @@ void do_tasks_view(void) {
 void calendar_month_view_display_events(time_t thetime) {
        int i;
        time_t event_tt;
+       time_t event_tte;
        struct tm event_tm;
+       struct tm event_te;
        struct tm today_tm;
        icalproperty *p = NULL;
+       icalproperty *pe = NULL;
        icalproperty *q = NULL;
        struct icaltimetype t;
        int month, day, year;
@@ -59,6 +62,8 @@ void calendar_month_view_display_events(time_t thetime) {
        for (i=0; i<(WC->num_cal); ++i) {
                p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                ICAL_DTSTART_PROPERTY);
+               pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
+                                                     ICAL_DTEND_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
                        event_tt = icaltime_as_timet(t);
@@ -67,15 +72,27 @@ void calendar_month_view_display_events(time_t thetime) {
                        else all_day_event = 0;
 
                        if (all_day_event) {
-                               gmtime_r(&event_tt, &event_tm);
+                               gmtime_r(&event_tt, &event_tm); 
+                               gmtime_r(&event_tt, &event_te);// allday events don't have end-dates.
                        }
                        else {
                                localtime_r(&event_tt, &event_tm);
+                               if (pe != NULL)
+                               {
+                                       t = icalproperty_get_dtend(pe);
+                                       event_tte = icaltime_as_timet(t);
+                                       localtime_r(&event_tte, &event_te);
+                               }
+                               else 
+                                       localtime_r(&event_tt, &event_te);
                        }
 
-                       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 ((event_tm.tm_year <= today_tm.tm_year)
+                          && (event_tm.tm_mon <= today_tm.tm_mon)
+                          && (event_tm.tm_mday <= today_tm.tm_mday)
+                          && (event_te.tm_year >= today_tm.tm_year)
+                          && (event_te.tm_mon >= today_tm.tm_mon)
+                          && (event_te.tm_mday >= today_tm.tm_mday)) {
 
                                p = icalcomponent_get_first_property(
                                                        WC->disp_cal[i].cal,
@@ -203,11 +220,12 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        struct icaltimetype t;
        int month, day, year;
        int all_day_event = 0;
-       char calhourformat[16];
        char *timeformat;
+       int time_format;
+       
+       time_format = get_time_format_cached ();
 
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
-       if (!strcasecmp(calhourformat, "24"))   timeformat="%k:%M";
+       if (time_format == WC_TIMEFORMAT_24) timeformat="%k:%M";
        else timeformat="%I:%M %p";
 
        localtime_r(&thetime, &today_tm);
@@ -307,6 +325,7 @@ void calendar_month_view(int year, int month, int day) {
        time_t colheader_time;
        struct tm colheader_tm;
        char colheader_label[32];
+       int chg_month = 0;
 
        /** Determine what day to start.
         * First, back up to the 1st of the month...
@@ -336,8 +355,7 @@ void calendar_month_view(int year, int month, int day) {
 
        /** Outer table (to get the background color) */
        wprintf("<div class=\"fix_scrollbar_bug\">"
-               "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
-               "bgcolor=#204B78><TR><TD>\n");
+               "<table class=\"calendar\"> \n <tr><td>"); 
 
        wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
 
@@ -376,39 +394,51 @@ void calendar_month_view(int year, int month, int day) {
        }
        wprintf("</tr>\n");
 
-       /** Now do 35 days */
-       for (i = 0; i < 35; ++i) {
-               localtime_r(&thetime, &tm);
 
-               /** Before displaying Sunday, start a new row */
-               if ((i % 7) == 0) {
-                       wprintf("<tr>");
-               }
+        /** Now do 35 or 42 days */
+        for (i = 0; i < 42; ++i) {
+                localtime_r(&thetime, &tm);
 
-               wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left 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)) {
-                       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></b><br />",
-                       tm.tm_year + 1900,
-                       tm.tm_mon + 1,
-                       tm.tm_mday,
-                       tm.tm_mday);
+                if ((i < 35) || (chg_month == 0)) {
 
-               /** put the data here, stupid */
-               calendar_month_view_display_events(thetime);
+                        if ((i > 27) && ((tm.tm_mday == 1) || (tm.tm_mday == 31))) {
+                                chg_month = 1;
+                        }
+                        if (i > 35) {
+                                chg_month = 0;
+                        }
 
-               wprintf("</td>");
+                       /** Before displaying Sunday, start a new row */
+                       if ((i % 7) == 0) {
+                               wprintf("<tr>");
+                       }
+
+                       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(thetime);
+
+                       wprintf("</td>");
+
+                       /** After displaying Saturday, end the row */
+                       if ((i % 7) == 6) {
+                               wprintf("</tr>\n");
+                       }
 
-               /** After displaying Saturday, end the row */
-               if ((i % 7) == 6) {
-                       wprintf("</tr>\n");
                }
 
                thetime += (time_t)86400;               /** ahead 24 hours */
@@ -587,9 +617,13 @@ void calendar_day_view_display_events(int year, int month,
                                        int day, int hour) {
        int i;
        icalproperty *p;
+       icalproperty *pe = NULL;
        struct icaltimetype t;
+       struct icaltimetype te;
        time_t event_tt;
-       struct tm *event_tm;
+       time_t event_tte;
+       struct tm event_te;
+       struct tm event_tm;
        int all_day_event = 0;
 
        if (WC->num_cal == 0) {
@@ -600,6 +634,8 @@ void calendar_day_view_display_events(int year, int month,
        for (i=0; i<(WC->num_cal); ++i) {
                p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
                                                ICAL_DTSTART_PROPERTY);
+               pe = icalcomponent_get_first_property(WC->disp_cal[i].cal,
+                                                     ICAL_DTEND_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
                        event_tt = icaltime_as_timet(t);
@@ -611,19 +647,40 @@ void calendar_day_view_display_events(int year, int month,
                        }
 
                        if (all_day_event) {
-                               event_tm = gmtime(&event_tt);
+                               gmtime_r(&event_tt, &event_tm);
+                               gmtime_r(&event_tt, &event_te);
                        }
                        else {
-                               event_tm = localtime(&event_tt);
+                               localtime_r(&event_tt, &event_tm);
+                               if (pe != NULL)
+                               {
+                                       te = icalproperty_get_dtend(pe);
+                                       event_tte = icaltime_as_timet(te);
+                                       localtime_r(&event_tte, &event_te);
+                               }
+                               else 
+                                       localtime_r(&event_tt, &event_te);
                        }
 
-                       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 (((event_tm.tm_year <= (year-1900))
+                            && (event_tm.tm_mon <= (month-1))
+                            && (event_tm.tm_mday <= day)
+                            && (event_te.tm_year >= (year-1900))
+                            && (event_te.tm_mon >= (month-1))
+                            && (event_te.tm_mday >= day))
+                           && (
+                                 // are we in the start hour?
+                                   ((event_tm.tm_mday == day)
+                                    && (event_tm.tm_hour == hour) 
+                                    && (!t.is_date)) 
+                                 // are we an all day event?
+                                   || ((hour<0)&&(t.is_date))
+                                 // does it span multible days and we're not at the start day?
+                                   || ((hour<0)
+                                       && (event_tm.tm_mday < day) 
+                                       && (event_te.tm_mday >= day))
+                                   ))
+                       {
                                p = icalcomponent_get_first_property(
                                                        WC->disp_cal[i].cal,
                                                        ICAL_SUMMARY_PROPERTY);
@@ -666,18 +723,18 @@ 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];
        int daystart = 8;
        int dayend = 17;
        char daystart_str[16], dayend_str[16];
        struct tm d_tm;
        char d_str[128];
-
-       get_preference("calhourformat", calhourformat, sizeof calhourformat);
+       int time_format;
+       
+       time_format = get_time_format_cached ();
        get_preference("daystart", daystart_str, sizeof daystart_str);
-       if (strlen(daystart_str) > 0) daystart = atoi(daystart_str);
+       if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
        get_preference("dayend", dayend_str, sizeof dayend_str);
-       if (strlen(dayend_str) > 0) dayend = atoi(dayend_str);
+       if (!IsEmptyStr(dayend_str)) dayend = atoi(dayend_str);
        
 
        /** Figure out the dates for "yesterday" and "tomorrow" links */
@@ -729,7 +786,7 @@ void calendar_day_view(int year, int month, int day) {
                        year, month, day, hour
                );
 
-               if (!strcasecmp(calhourformat, "24")) {
+               if (time_format == WC_TIMEFORMAT_24) {
                        wprintf("%2d:00</a> ", hour);
                }
                else {
@@ -915,12 +972,12 @@ void do_calendar_view(void) {
        day = tm.tm_mday;
 
        /** Now see if a date was specified */
-       if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
-       if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
-       if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
+       if (!IsEmptyStr(bstr("year"))) year = atoi(bstr("year"));
+       if (!IsEmptyStr(bstr("month"))) month = atoi(bstr("month"));
+       if (!IsEmptyStr(bstr("day"))) day = atoi(bstr("day"));
 
        /** How would you like that cooked? */
-       if (strlen(bstr("calview")) > 0) {
+       if (!IsEmptyStr(bstr("calview"))) {
                strcpy(calview, bstr("calview"));
        }
        else {