]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
* don't run into unused buffer parts.
[citadel.git] / webcit / calendar_view.c
index db5c45346f02feb506bcce742840cfe8010c99d5..1c6d098c7aa55f136bab1877873efea42ae8af65 100644 (file)
@@ -146,16 +146,21 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
  * ajax embedder for the above mini calendar 
  */
 void ajax_mini_calendar(void) {
+       const StrBuf *Buf;
        char urlformat[256];
-       int i, len;
-       char *escaped_urlformat;
+       int i, j, len;
+       const char *escaped_urlformat;
 
-       escaped_urlformat = bstr("urlformat");
-        len = strlen(escaped_urlformat) * 2 ;
-       for (i=0; i<len; ++i) {
-               urlformat[i] = xtoi(&escaped_urlformat[i*2], 2);
-               urlformat[i+1] = 0;
+       Buf = sbstr("urlformat");
+       escaped_urlformat = ChrPtr(Buf);
+        len = StrLength(Buf);
+       if (len * 2 > sizeof(urlformat))
+               len = sizeof(urlformat) / 2;
+
+       for (i=0, j = 0; i < len ; i+=2, j++) {
+               urlformat[j] = xtoi(&escaped_urlformat[i], 2);
        }
+       urlformat[j] = '\0';
 
        embeddable_mini_calendar( ibstr("year"), ibstr("month"), urlformat );
 }
@@ -1241,9 +1246,9 @@ void calendar_day_view(int year, int month, int day) {
 
 
 /*
- * Display today's events.
+ * Display today's events.  Returns the number of items displayed.
  */
-void calendar_summary_view(void) {
+int calendar_summary_view(void) {
        long hklen;
        const char *HashKey;
        void *vCal;
@@ -1258,9 +1263,10 @@ void calendar_summary_view(void) {
        int all_day_event = 0;
        char timestring[SIZ];
        wcsession *WCC = WC;
+       int num_displayed = 0;
 
        if (GetCount(WC->disp_cal_items) == 0) {
-               return;
+               return(0);
        }
 
        now = time(NULL);
@@ -1269,8 +1275,7 @@ void calendar_summary_view(void) {
        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);
@@ -1291,26 +1296,54 @@ 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));
+                                       if (!all_day_event) {
+                                               wprintf(" (%s)", timestring);
+                                       }
+                                       wprintf("</a><br />\n");
+                                       ++num_displayed;
+                               }
                        }
                }
        }
        DeleteHashPos(&Pos);
        DeleteHash(&WC->disp_cal_items);
+       return(num_displayed);
 }
 
-
 /*
  * Parse the URL variables in order to determine the scope and display of a calendar view
  */
@@ -1318,6 +1351,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);
@@ -1346,6 +1380,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;
@@ -1364,11 +1401,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;
@@ -1456,10 +1493,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;
@@ -1513,9 +1550,11 @@ void do_tasks_view(void) {
 
        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\" ");
@@ -1523,9 +1562,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;"); */