* move some more vars from the session context to strbuf (the use of StrBufAppendTemp...
[citadel.git] / webcit / calendar_view.c
index cf5ab1a0836ce52959aa943440f6da26bf2621f0..0af1842ec1d2ec48c207c3cf76322130f4d67ec9 100644 (file)
@@ -182,7 +182,7 @@ void calendar_month_view_display_events(int year, int month, int day)
        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 */
+       wcsession *WCC = WC;
        time_t tt;
 
        if (GetCount(WCC->disp_cal_items) == 0) {
@@ -216,7 +216,7 @@ void calendar_month_view_display_events(int year, int month, int day)
        /*
         * 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;
@@ -362,7 +362,7 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        time_t event_tt;
        time_t event_tts;
        time_t event_tte;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
        struct tm event_tms;
        struct tm event_tme;
        struct tm today_tm;
@@ -385,7 +385,7 @@ void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
        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);
@@ -475,7 +475,6 @@ 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;
        long weekstart = 0;
 
        /*
@@ -554,56 +553,50 @@ void calendar_month_view(int year, int month, int day) {
 
 
         /* 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 */
@@ -785,7 +778,7 @@ void calendar_day_view_display_events(time_t thetime,
        int show_event = 0;
        int all_day_event = 0;
        int ongoing_event = 0;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
        disp_cal *Cal;
        struct icaltimetype t;
        struct icaltimetype end_t;
@@ -832,7 +825,7 @@ void calendar_day_view_display_events(time_t thetime,
 
        /* 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;
 
@@ -1264,7 +1257,7 @@ void calendar_summary_view(void) {
        time_t now;
        int all_day_event = 0;
        char timestring[SIZ];
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
 
        if (GetCount(WC->disp_cal_items) == 0) {
                return;
@@ -1273,11 +1266,10 @@ void calendar_summary_view(void) {
        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,
-                                               ICAL_DTSTART_PROPERTY);
+               p = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
                if (p != NULL) {
                        t = icalproperty_get_dtstart(p);
                        event_tt = icaltime_as_timet(t);
@@ -1298,18 +1290,42 @@ void calendar_summary_view(void) {
 
                        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_tm.tm_mday == today_tm.tm_mday)
                        ) {
 
+                               p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+                               if (p != NULL) {
 
-                       p = icalcomponent_get_first_property(
-                               Cal->cal,
-                               ICAL_SUMMARY_PROPERTY);
-                       if (p != NULL) {
-                               escputs((char *)
-                                       icalproperty_get_comment(p));
-                               wprintf(" (%s)<br />\n", timestring);
-                       }
+
+                                       if (WCC->wc_view == VIEW_TASKS) {
+                                               wprintf("<a href=\"display_edit_task"
+                                                       "?msgnum=%ld"
+                                                       "?return_to_summary=1"
+                                                       "?gotofirst=",
+                                                       Cal->cal_msgnum
+                                               );
+                                               escputs(ChrPtr(WCC->wc_roomname));
+                                               wprintf("\">");
+                                       }
+                                       else {
+                                               wprintf("<a href=\"display_edit_event"
+                                                       "?msgnum=%ld"
+                                                       "?calview=summary"
+                                                       "?year=%d"
+                                                       "?month=%d"
+                                                       "?day=%d"
+                                                       "?gotofirst=",
+                                                       Cal->cal_msgnum,
+                                                       today_tm.tm_year + 1900,
+                                                       today_tm.tm_mon + 1,
+                                                       today_tm.tm_mday
+                                               );
+                                               escputs(ChrPtr(WCC->wc_roomname));
+                                               wprintf("\">");
+                                       }
+                                       escputs((char *) icalproperty_get_comment(p));
+                                       wprintf(" (%s)</a><br />\n", timestring);
+                               }
                        }
                }
        }
@@ -1317,7 +1333,6 @@ void calendar_summary_view(void) {
        DeleteHash(&WC->disp_cal_items);
 }
 
-
 /*
  * Parse the URL variables in order to determine the scope and display of a calendar view
  */
@@ -1325,6 +1340,7 @@ void parse_calendar_view_request(struct calview *c) {
        time_t now;
        struct tm tm;
        char calview[32];
+       int span = 3888000;
 
        /* In case no date was specified, go with today */
        now = time(NULL);
@@ -1353,6 +1369,9 @@ void parse_calendar_view_request(struct calview *c) {
        else if (!strcasecmp(calview, "week")) {
                c->view = calview_week;
        }
+       else if (!strcasecmp(calview, "summary")) {     /* shouldn't ever happen, but just in case */
+               c->view = calview_day;
+       }
        else {
                if (WC->wc_view == VIEW_CALBRIEF) {
                        c->view = calview_brief;
@@ -1371,11 +1390,11 @@ void parse_calendar_view_request(struct calview *c) {
        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;
+       if (c->view == calview_summary) span = 86400;
 
        c->lower_bound = now - span;
        c->upper_bound = now + span;
@@ -1463,10 +1482,10 @@ int task_due_cmp(const void *vtask1, const void *vtask2) {
  */
 int task_completed_cmp(const void *vtask1, const void *vtask2) {
        disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
-//     disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
+/*     disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
 
        icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
-       // icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal);
+       /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
        
        if (t1 == ICAL_STATUS_COMPLETED) 
                return 1;
@@ -1488,7 +1507,7 @@ void do_tasks_view(void) {
        time_t due;
        char buf[SIZ];
        icalproperty *p;
-       struct wcsession *WCC = WC;     /* This is done to make it run faster; WC is a function */
+       wcsession *WCC = WC;
 
        wprintf("<div class=\"fix_scrollbar_bug\">"
                "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
@@ -1518,11 +1537,13 @@ void do_tasks_view(void) {
                              task_completed_cmp);
        }
 
-       Pos = GetNewHashPos();
+       Pos = GetNewHashPos(WCC->disp_cal_items, 0);
        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
+               icalproperty_status todoStatus;
+
                Cal = (disp_cal*)vCal;
                wprintf("<tr><td>");
-               icalproperty_status todoStatus = icalcomponent_get_status(Cal->cal);
+               todoStatus = icalcomponent_get_status(Cal->cal);
                wprintf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
                if (todoStatus == ICAL_STATUS_COMPLETED) {
                        wprintf("checked=\"checked\" ");
@@ -1530,9 +1551,8 @@ void do_tasks_view(void) {
                wprintf("disabled=\"disabled\">\n</td><td>");
                p = icalcomponent_get_first_property(Cal->cal,
                        ICAL_SUMMARY_PROPERTY);
-               wprintf("<a href=\"display_edit_task?msgnum=%ld&amp;taskrm=",
-                       Cal->cal_msgnum );
-               urlescputs(WC->wc_roomname);
+               wprintf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
+               urlescputs(ChrPtr(WC->wc_roomname));
                wprintf("\">");
                /* wprintf("<img align=middle "
                "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;"); */