]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar_view.c
Mini month calendar is complete. The 'previous month'
[citadel.git] / webcit / calendar_view.c
index 5b401d1d3ec881f804c3bc0a47bcc2da74ea389b..c26241c017fefef1de07b67f1e4c221bc0078954 100644 (file)
 /****************************************************************************/
 
 
-/**
- */
 void embeddable_mini_calendar(int year, int month, char *urlformat)
 {
        struct tm starting_tm;
        struct tm tm;
        time_t thetime;
-       int i;
+       int i, len;
        time_t previous_month;
        time_t next_month;
        time_t colheader_time;
@@ -31,6 +29,7 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
        char weekstart_buf[16];
        char url[256];
        char div_id[256];
+       char escaped_urlformat[256];
 
        snprintf(div_id, sizeof div_id, "mini_calendar_%d", rand() );
 
@@ -68,15 +67,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
 
        wprintf("<div class=\"mini_calendar\" id=\"%s\">\n", div_id);
 
+       /* Previous month link */
        localtime_r(&previous_month, &tm);
-
-       wprintf("<a href=\"javascript:minical_previous_month();\">&laquo;</a>");
-       wprintf("&nbsp;");
-/* previous month
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">&laquo;</a>", 
                (int)(tm.tm_year)+1900, tm.tm_mon + 1);
-       wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
-*/
 
        wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
        wprintf("&nbsp;&nbsp;"
@@ -85,14 +79,10 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
                "</span>"
                "&nbsp;&nbsp;", colheader_label, year);
 
-       wprintf("&nbsp;");
-       wprintf("<a href=\"javascript:minical_next_month();\">&raquo;</a>");
-/*
+       /* Next month link */
        localtime_r(&next_month, &tm);
-       wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
+       wprintf("<a href=\"javascript:minical_change_month(%d,%d);\">&raquo;</a>",
                (int)(tm.tm_year)+1900, tm.tm_mon + 1);
-       wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
-*/
 
        wprintf("<table border=0 cellpadding=1 cellspacing=1 class=\"mini_calendar_days\">"
                "<tr>");
@@ -139,6 +129,41 @@ void embeddable_mini_calendar(int year, int month, char *urlformat)
 
        wprintf("</table>"                      /** end of inner table */
                "</div>\n");
+
+       /* javascript for previous and next month */
+       len = strlen(urlformat);
+       for (i=0; i<len; ++i) {
+               sprintf(&escaped_urlformat[i*2], "%02X", urlformat[i]);
+       }
+
+       wprintf("<script type=\"text/javascript\">                                                      "
+               "       function minical_change_month(year, month) {                                    "
+               "               p = 'year=' + year + '&month=' + month                                  "
+               "                       + '&urlformat=%s&r=' + CtdlRandomString();                      "
+               "               new Ajax.Updater('%s', 'mini_calendar',                                 "
+               "                       { method: 'get', parameters: p, evalScripts: true } );          "
+               "       }                                                                               "
+               "</script>\n"
+               ,
+               escaped_urlformat, div_id
+       );
+
+}
+
+/* ajax embedder for the above mini calendar */
+void ajax_mini_calendar(void) {
+       char urlformat[256];
+       int i, len;
+       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;
+       }
+
+       embeddable_mini_calendar( atoi(bstr("year")), atoi(bstr("month")), urlformat );
 }
 
 
@@ -774,6 +799,7 @@ void calendar_day_view_display_events(time_t thetime, int year, int month,
        struct tm ending_tm;
        int top = 0;
        int height = 0;
+       int gap = 0;
 
        if (WCC->num_cal == 0) {
                // \todo FIXME wprintf("<br /><br /><br />\n");
@@ -901,14 +927,15 @@ void calendar_day_view_display_events(time_t thetime, int year, int month,
                                        }
                                wprintf("<dd  class=\"event\" "
                                        "style=\"position: absolute; "
-                                       "top:%dpx; left:100px; "
+                                       "top:%dpx; left:%dpx; "
                                        "height:%dpx; \" >",
-                                       top, height
+                                       top, (50 + (gap * 50)), height
                                        );
                                wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
                                        Cal->cal_msgnum, year, month, day, t.hour, hour);
                                escputs((char *) icalproperty_get_comment(p));
                                wprintf("</a></dd>\n");
+                               gap++;
                                }
                                
                        }
@@ -1332,6 +1359,9 @@ void do_tasks_view(void) {
        wprintf("</i></center><br />\n");
 }
 
+/**\brief stub for non-libical builds */
+void ajax_mini_calendar(void) {
+}
 
 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */