calendar_view.c

00001 /*
00002  * $Id: calendar_view.c 5178 2007-05-24 22:18:51Z ajc $
00003  */
00009 #include "webcit.h"
00010 #include "webserver.h"
00011 
00012 #ifndef WEBCIT_WITH_CALENDAR_SERVICE
00013 
00015 void do_calendar_view(void) {
00016         wprintf("<center><i>");
00017         wprintf(_("The calendar view is not available."));
00018         wprintf("</i></center><br />\n");
00019 }
00020 
00022 void do_tasks_view(void) {      
00023         wprintf("<center><I>");
00024         wprintf(_("The tasks view is not available."));
00025         wprintf("</i></center><br />\n");
00026 }
00027 
00028 #else   /* WEBCIT_WITH_CALENDAR_SERVICE */
00029 
00030 /****************************************************************************/
00031 
00036 void calendar_month_view_display_events(time_t thetime) {
00037         int i;
00038         time_t event_tt;
00039         struct tm event_tm;
00040         struct tm today_tm;
00041         icalproperty *p = NULL;
00042         icalproperty *q = NULL;
00043         struct icaltimetype t;
00044         int month, day, year;
00045         int all_day_event = 0;
00046         time_t tt;
00047         char buf[256];
00048 
00049         if (WC->num_cal == 0) {
00050                 wprintf("<br /><br /><br />\n");
00051                 return;
00052         }
00053 
00054         localtime_r(&thetime, &today_tm);
00055         month = today_tm.tm_mon + 1;
00056         day = today_tm.tm_mday;
00057         year = today_tm.tm_year + 1900;
00058 
00059         for (i=0; i<(WC->num_cal); ++i) {
00060                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00061                                                 ICAL_DTSTART_PROPERTY);
00062                 if (p != NULL) {
00063                         t = icalproperty_get_dtstart(p);
00064                         event_tt = icaltime_as_timet(t);
00065 
00066                         if (t.is_date) all_day_event = 1;
00067                         else all_day_event = 0;
00068 
00069                         if (all_day_event) {
00070                                 gmtime_r(&event_tt, &event_tm);
00071                         }
00072                         else {
00073                                 localtime_r(&event_tt, &event_tm);
00074                         }
00075 
00076                         if ((event_tm.tm_year == today_tm.tm_year)
00077                            && (event_tm.tm_mon == today_tm.tm_mon)
00078                            && (event_tm.tm_mday == today_tm.tm_mday)) {
00079 
00080                                 p = icalcomponent_get_first_property(
00081                                                         WC->disp_cal[i].cal,
00082                                                         ICAL_SUMMARY_PROPERTY);
00083                                 if (p != NULL) {
00084 
00085                                         if (all_day_event) {
00086                                                 wprintf("<table border=0 cellpadding=2><TR>"
00087                                                         "<td bgcolor=\"#CCCCDD\">"
00088                                                 );
00089                                         }
00090 
00091                                         wprintf("<font size=-1>"
00092                                                 "<a href=\"display_edit_event?"
00093                                                 "msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\""
00094                                                 " btt_tooltext=\"",
00095                                                 WC->disp_cal[i].cal_msgnum,
00096                                                 bstr("calview"),
00097                                                 bstr("year"),
00098                                                 bstr("month"),
00099                                                 bstr("day")
00100                                         );
00101 
00102                                         wprintf("<i>%s</i> ", _("Summary:"));
00103                                         escputs((char *)icalproperty_get_comment(p));
00104                                         wprintf("<br />");
00105 
00106                                         q = icalcomponent_get_first_property(
00107                                                         WC->disp_cal[i].cal,
00108                                                         ICAL_LOCATION_PROPERTY);
00109                                         if (q) {
00110                                                 wprintf("<i>%s</i> ", _("Location:"));
00111                                                 escputs((char *)icalproperty_get_comment(q));
00112                                                 wprintf("<br />");
00113                                         }
00114 
00119                                         if (icalcomponent_isa(WC->disp_cal[i].cal) == ICAL_VEVENT_COMPONENT) {
00120                                 
00121                                                 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00122                                                                                 ICAL_DTSTART_PROPERTY);
00123                                                 if (q != NULL) {
00124                                                         t = icalproperty_get_dtstart(q);
00125                                 
00126                                                         if (t.is_date) {
00127                                                                 struct tm d_tm;
00128                                                                 char d_str[32];
00129                                                                 memset(&d_tm, 0, sizeof d_tm);
00130                                                                 d_tm.tm_year = t.year - 1900;
00131                                                                 d_tm.tm_mon = t.month - 1;
00132                                                                 d_tm.tm_mday = t.day;
00133                                                                 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
00134                                                                 wprintf("<i>%s</i> %s<br>",
00135                                                                         _("Date:"), d_str);
00136                                                         }
00137                                                         else {
00138                                                                 tt = icaltime_as_timet(t);
00139                                                                 fmt_date(buf, tt, 1);
00140                                                                 wprintf("<i>%s</i> %s<br>",
00141                                                                         _("Starting date/time:"), buf);
00142 
00143                                                                 /* Embed the 'show end date/time' loop inside here so it
00144                                                                  * only executes if this is NOT an all day event.
00145                                                                  */
00146                                                                 q = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00147                                                                                                         ICAL_DTEND_PROPERTY);
00148                                                                 if (q != NULL) {
00149                                                                         t = icalproperty_get_dtend(q);
00150                                                                         tt = icaltime_as_timet(t);
00151                                                                         fmt_date(buf, tt, 1);
00152                                                                         wprintf("<i>%s</i> %s<br>",
00153                                                                                 _("Ending date/time:"), buf);
00154                                                                 }
00155 
00156                                                         }
00157                                                 }
00158                                         
00159                                         }
00160 
00161                                         q = icalcomponent_get_first_property(
00162                                                         WC->disp_cal[i].cal,
00163                                                         ICAL_DESCRIPTION_PROPERTY);
00164                                         if (q) {
00165                                                 wprintf("<i>%s</i> ", _("Notes:"));
00166                                                 escputs((char *)icalproperty_get_comment(q));
00167                                                 wprintf("<br />");
00168                                         }
00169 
00170                                         wprintf("\">");
00171                                         escputs((char *)
00172                                                 icalproperty_get_comment(p));
00173                                         wprintf("</a></font><br />\n");
00174 
00175                                         if (all_day_event) {
00176                                                 wprintf("</td></tr></table>");
00177                                         }
00178 
00179                                 }
00180 
00181                         }
00182 
00183 
00184                 }
00185         }
00186 }
00187 
00188 
00193 void calendar_month_view_brief_events(time_t thetime, const char *daycolor) {
00194         int i;
00195         time_t event_tt;
00196         time_t event_tts;
00197         time_t event_tte;
00198         struct tm event_tms;
00199         struct tm event_tme;
00200         struct tm today_tm;
00201         icalproperty *p;
00202         icalproperty *e;
00203         struct icaltimetype t;
00204         int month, day, year;
00205         int all_day_event = 0;
00206         char calhourformat[16];
00207         char *timeformat;
00208 
00209         get_preference("calhourformat", calhourformat, sizeof calhourformat);
00210         if (!strcasecmp(calhourformat, "24"))   timeformat="%k:%M";
00211         else timeformat="%I:%M %p";
00212 
00213         localtime_r(&thetime, &today_tm);
00214         month = today_tm.tm_mon + 1;
00215         day = today_tm.tm_mday;
00216         year = today_tm.tm_year + 1900;
00217 
00218         for (i=0; i<(WC->num_cal); ++i) {
00219                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00220                                                 ICAL_DTSTART_PROPERTY);
00221                 if (p != NULL) {
00222                         t = icalproperty_get_dtstart(p);
00223                         event_tt = icaltime_as_timet(t);
00224                         event_tts=event_tt;
00225                         if (t.is_date) all_day_event = 1;
00226                         else all_day_event = 0;
00227 
00228                         if (all_day_event) {
00229                                 gmtime_r(&event_tts, &event_tms);
00230                         }
00231                         else {
00232                                 localtime_r(&event_tts, &event_tms);
00233                         }
00235                         if ((event_tms.tm_year == today_tm.tm_year)
00236                            && (event_tms.tm_mon == today_tm.tm_mon)
00237                            && (event_tms.tm_mday == today_tm.tm_mday)) {
00238                                 
00239                                 
00240                                 char sbuf[255];
00241                                 char ebuf[255];
00242 
00243                                 p = icalcomponent_get_first_property(
00244                                                         WC->disp_cal[i].cal,
00245                                                         ICAL_SUMMARY_PROPERTY);
00246                                 e = icalcomponent_get_first_property(
00247                                                         WC->disp_cal[i].cal, 
00248                                                         ICAL_DTEND_PROPERTY);
00249                                 if ((p != NULL) && (e != NULL)) {
00250                                         time_t difftime;
00251                                         int hours, minutes;
00252                                         t = icalproperty_get_dtend(e);
00253                                         event_tte = icaltime_as_timet(t);
00254                                         localtime_r(&event_tte, &event_tme);
00255                                         difftime=(event_tte-event_tts)/60;
00256                                         hours=(int)(difftime / 60);
00257                                         minutes=difftime % 60;
00258                                         wprintf("<tr><td bgcolor='%s'>%i:%2i</td><td bgcolor='%s'>"
00259                                                         "<font size=-1>"
00260                                                         "<a href=\"display_edit_event?msgnum=%ld&calview=%s&year=%s&month=%s&day=%s\">",
00261                                                         daycolor,
00262                                                         hours, minutes,
00263                                                         daycolor,
00264                                                         WC->disp_cal[i].cal_msgnum,
00265                                                         bstr("calview"),
00266                                                         bstr("year"),
00267                                                         bstr("month"),
00268                                                         bstr("day")
00269                                                         );
00270 
00271                                         escputs((char *)
00272                                                         icalproperty_get_comment(p));
00274                                         wc_strftime(&sbuf[0], sizeof(sbuf), timeformat, &event_tms);
00275                                         wc_strftime(&ebuf[0], sizeof(sbuf), timeformat, &event_tme);
00276 
00277                                         wprintf("</a></font></td>"
00278                                                         "<td bgcolor='%s'>%s</td><td bgcolor='%s'>%s</td></tr>",
00279                                                         daycolor,
00280                                                         sbuf,
00281                                                         daycolor,
00282                                                         ebuf);
00283                                         
00284                                 }
00285                                 
00286                         }
00287                         
00288                         
00289                 }
00290         }
00291 }
00292 
00293 
00300 void calendar_month_view(int year, int month, int day) {
00301         struct tm starting_tm;
00302         struct tm tm;
00303         time_t thetime;
00304         int i;
00305         time_t previous_month;
00306         time_t next_month;
00307         time_t colheader_time;
00308         struct tm colheader_tm;
00309         char colheader_label[32];
00310 
00314         memset(&starting_tm, 0, sizeof(struct tm));
00315         starting_tm.tm_year = year - 1900;
00316         starting_tm.tm_mon = month - 1;
00317         starting_tm.tm_mday = day;
00318         thetime = mktime(&starting_tm);
00319 
00320         memcpy(&tm, &starting_tm, sizeof(struct tm));
00321         while (tm.tm_mday != 1) {
00322                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
00323                 localtime_r(&thetime, &tm);
00324         }
00325 
00327         previous_month = thetime - (time_t)864000L;     /* back 10 days */
00328         next_month = thetime + (time_t)(31L * 86400L);  /* ahead 31 days */
00329 
00331         localtime_r(&thetime, &tm);
00332         while (tm.tm_wday != 0) {
00333                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
00334                 localtime_r(&thetime, &tm);
00335         }
00336 
00338         wprintf("<div class=\"fix_scrollbar_bug\">"
00339                 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
00340                 "bgcolor=#204B78><TR><TD>\n");
00341 
00342         wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
00343 
00344         wprintf("<td align=center>");
00345 
00346         localtime_r(&previous_month, &tm);
00347         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
00348                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
00349         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
00350 
00351         wc_strftime(colheader_label, sizeof colheader_label, "%B", &starting_tm);
00352         wprintf("&nbsp;&nbsp;"
00353                 "<font size=+1 color=\"#FFFFFF\">"
00354                 "%s %d"
00355                 "</font>"
00356                 "&nbsp;&nbsp;", colheader_label, year);
00357 
00358         localtime_r(&next_month, &tm);
00359         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
00360                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
00361         wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
00362 
00363         wprintf("</td></tr></table>\n");
00364 
00366         wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
00367                 "bgcolor=#204B78 id=\"inner_month\"><tr>");
00368         colheader_time = thetime;
00369         for (i=0; i<7; ++i) {
00370                 colheader_time = thetime + (i * 86400) ;
00371                 localtime_r(&colheader_time, &colheader_tm);
00372                 wc_strftime(colheader_label, sizeof colheader_label, "%A", &colheader_tm);
00373                 wprintf("<td align=center width=14%%>"
00374                         "<font color=\"#FFFFFF\">%s</font></th>", colheader_label);
00375 
00376         }
00377         wprintf("</tr>\n");
00378 
00380         for (i = 0; i < 35; ++i) {
00381                 localtime_r(&thetime, &tm);
00382 
00384                 if ((i % 7) == 0) {
00385                         wprintf("<tr>");
00386                 }
00387 
00388                 wprintf("<td bgcolor=\"#%s\" width=14%% height=60 align=left valign=top><b>",
00389                         ((tm.tm_mon != month-1) ? "DDDDDD" :
00390                         ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
00391                         "FFFFFF"))
00392                 );
00393                 if ((i==0) || (tm.tm_mday == 1)) {
00394                         wc_strftime(colheader_label, sizeof colheader_label, "%B", &tm);
00395                         wprintf("%s ", colheader_label);
00396                 }
00397                 wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">"
00398                         "%d</a></b><br />",
00399                         tm.tm_year + 1900,
00400                         tm.tm_mon + 1,
00401                         tm.tm_mday,
00402                         tm.tm_mday);
00403 
00405                 calendar_month_view_display_events(thetime);
00406 
00407                 wprintf("</td>");
00408 
00410                 if ((i % 7) == 6) {
00411                         wprintf("</tr>\n");
00412                 }
00413 
00414                 thetime += (time_t)86400;               
00415         }
00416 
00417         wprintf("</table>"                      
00418                 "</td></tr></table>"            
00419                 "</div>\n");
00420 
00432         wprintf("<script type=\"text/javascript\">"
00433                 " setTimeout(\"btt_enableTooltips('inner_month')\", 1); "
00434                 "</script>\n"
00435         );
00436 }
00437 
00444 void calendar_brief_month_view(int year, int month, int day) {
00445         struct tm starting_tm;
00446         struct tm tm;
00447         time_t thetime;
00448         int i;
00449         time_t previous_month;
00450         time_t next_month;
00451         char month_label[32];
00452 
00456         memset(&starting_tm, 0, sizeof(struct tm));
00457         starting_tm.tm_year = year - 1900;
00458         starting_tm.tm_mon = month - 1;
00459         starting_tm.tm_mday = day;
00460         thetime = mktime(&starting_tm);
00461 
00462         memcpy(&tm, &starting_tm, sizeof(struct tm));
00463         while (tm.tm_mday != 1) {
00464                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
00465                 localtime_r(&thetime, &tm);
00466         }
00467 
00469         previous_month = thetime - (time_t)864000L;     /* back 10 days */
00470         next_month = thetime + (time_t)(31L * 86400L);  /* ahead 31 days */
00471 
00473         localtime_r(&thetime, &tm);
00474         while (tm.tm_wday != 0) {
00475                 thetime = thetime - (time_t)86400;      /* go back 24 hours */
00476                 localtime_r(&thetime, &tm);
00477         }
00478 
00480         wprintf("<div class=\"fix_scrollbar_bug\">"
00481                 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
00482                 "bgcolor=#204B78><TR><TD>\n");
00483 
00484         wprintf("<table width=100%% border=0 cellpadding=0 cellspacing=0><tr>\n");
00485 
00486         wprintf("<td align=center>");
00487 
00488         localtime_r(&previous_month, &tm);
00489         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
00490                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
00491         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>\n");
00492 
00493         wc_strftime(month_label, sizeof month_label, "%B", &tm);
00494         wprintf("&nbsp;&nbsp;"
00495                 "<font size=+1 color=\"#FFFFFF\">"
00496                 "%s %d"
00497                 "</font>"
00498                 "&nbsp;&nbsp;", month_label, year);
00499 
00500         localtime_r(&next_month, &tm);
00501         wprintf("<a href=\"readfwd?calview=month&year=%d&month=%d&day=1\">",
00502                 (int)(tm.tm_year)+1900, tm.tm_mon + 1);
00503         wprintf("<img align=middle src=\"static/nextdate_32x.gif\" border=0></A>\n");
00504 
00505         wprintf("</td></tr></table>\n");
00506 
00508         wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
00509                 "bgcolor=#EEEECC><TR>");
00510         wprintf("</tr>\n");
00511         wprintf("<tr><td colspan=\"100%\">\n");
00512 
00514         for (i = 0; i < 35; ++i) {
00515                 char weeknumber[255];
00516                 char weekday_name[32];
00517                 char *daycolor;
00518                 localtime_r(&thetime, &tm);
00519 
00520 
00522                 if ((i % 7) == 0) {
00523                         wc_strftime(&weeknumber[0], sizeof(weeknumber), "%U", &tm);
00524                         wprintf("<table border='0' bgcolor=\"#EEEECC\" width='100%'> <tr><th colspan='4'>%s %s</th></tr>"
00525                                         "   <tr><td>%s</td><td width=70%%>%s</td><td>%s</td><td>%s</td></tr>\n",
00526                                         _("Week"), 
00527                                         weeknumber,
00528                                         _("Hours"),
00529                                         _("Subject"),
00530                                         _("Start"),
00531                                         _("End")
00532                                         );
00533                 }
00534                 
00535                 daycolor=((tm.tm_mon != month-1) ? "DDDDDD" :
00536                                   ((tm.tm_wday==0 || tm.tm_wday==6) ? "EEEECC" :
00537                                    "FFFFFF"));
00538                 
00540                 wc_strftime(weekday_name, sizeof weekday_name, "%A", &tm);
00541                 wprintf("<tr><td bgcolor='%s' colspan='1' align='left'> %s,%i."
00542                                 "</td><td bgcolor='%s' colspan='3'><hr></td></tr>\n",
00543                                 daycolor,
00544                                 weekday_name,tm.tm_mday,
00545                                 daycolor);
00546 
00548                 calendar_month_view_brief_events(thetime, daycolor);
00549 
00550 
00552                 if ((i % 7) == 6) {
00553                         wprintf("</td></tr></table>\n");
00554                 }
00555 
00556                 thetime += (time_t)86400;               
00557         }
00558 
00559         wprintf("</table>"                      
00560                 "</td></tr></table>"            
00561                 "</div>\n");
00562 }
00563 
00572 void calendar_week_view(int year, int month, int day) {
00573         wprintf("<center><i>week view FIXME</i></center><br />\n");
00574 }
00575 
00576 
00586 void calendar_day_view_display_events(int year, int month,
00587                                         int day, int hour) {
00588         int i;
00589         icalproperty *p;
00590         struct icaltimetype t;
00591         time_t event_tt;
00592         struct tm *event_tm;
00593         int all_day_event = 0;
00594 
00595         if (WC->num_cal == 0) {
00596                 // \todo FIXME wprintf("<br /><br /><br />\n");
00597                 return;
00598         }
00599 
00600         for (i=0; i<(WC->num_cal); ++i) {
00601                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00602                                                 ICAL_DTSTART_PROPERTY);
00603                 if (p != NULL) {
00604                         t = icalproperty_get_dtstart(p);
00605                         event_tt = icaltime_as_timet(t);
00606                         if (t.is_date) {
00607                                 all_day_event = 1;
00608                         }
00609                         else {
00610                                 all_day_event = 0;
00611                         }
00612 
00613                         if (all_day_event) {
00614                                 event_tm = gmtime(&event_tt);
00615                         }
00616                         else {
00617                                 event_tm = localtime(&event_tt);
00618                         }
00619 
00620                         if ((event_tm->tm_year == (year-1900))
00621                            && (event_tm->tm_mon == (month-1))
00622                            && (event_tm->tm_mday == day)
00623                            && ( ((event_tm->tm_hour == hour)&&(!t.is_date)) || ((hour<0)&&(t.is_date)) )
00624                            ) {
00625 
00626 
00627                                 p = icalcomponent_get_first_property(
00628                                                         WC->disp_cal[i].cal,
00629                                                         ICAL_SUMMARY_PROPERTY);
00630                                 if (p != NULL) {
00631 
00632                                         if (all_day_event) {
00633                                                 wprintf("<table border=1 cellpadding=2><TR>"
00634                                                         "<td bgcolor=\"#CCCCCC\">"
00635                                                 );
00636                                         }
00637 
00638                                         wprintf("<font size=-1>"
00639                                                 "<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d\">",
00640                                                 WC->disp_cal[i].cal_msgnum,
00641                                                 year, month, day
00642                                         );
00643                                         escputs((char *)
00644                                                 icalproperty_get_comment(p));
00645                                         wprintf("</a></font><br />\n");
00646 
00647                                         if (all_day_event) {
00648                                                 wprintf("</td></tr></table>");
00649                                         }
00650                                 }
00651 
00652                         }
00653 
00654 
00655                 }
00656         }
00657 }
00658 
00659 
00666 void calendar_day_view(int year, int month, int day) {
00667         int hour;
00668         struct icaltimetype today, yesterday, tomorrow;
00669         char calhourformat[16];
00670         int daystart = 8;
00671         int dayend = 17;
00672         char daystart_str[16], dayend_str[16];
00673         struct tm d_tm;
00674         char d_str[128];
00675 
00676         get_preference("calhourformat", calhourformat, sizeof calhourformat);
00677         get_preference("daystart", daystart_str, sizeof daystart_str);
00678         if (strlen(daystart_str) > 0) daystart = atoi(daystart_str);
00679         get_preference("dayend", dayend_str, sizeof dayend_str);
00680         if (strlen(dayend_str) > 0) dayend = atoi(dayend_str);
00681         
00682 
00685         memset(&today, 0, sizeof(struct icaltimetype));
00686         today.year = year;
00687         today.month = month;
00688         today.day = day;
00689         today.is_date = 1;
00690 
00691         memcpy(&yesterday, &today, sizeof(struct icaltimetype));
00692         --yesterday.day;
00693         yesterday = icaltime_normalize(yesterday);
00694 
00695         memcpy(&tomorrow, &today, sizeof(struct icaltimetype));
00696         ++tomorrow.day;
00697         tomorrow = icaltime_normalize(tomorrow);
00698 
00699 
00701         wprintf("<div class=\"fix_scrollbar_bug\">"
00702                 "<table width=100%% border=0 cellpadding=0 cellspacing=0 "
00703                 "bgcolor=#204B78><tr><td>\n");
00704 
00706         wprintf("<table width=100%% border=0 cellpadding=1 cellspacing=1 "
00707                 "bgcolor=#204B78><tr>\n");
00708 
00710         wprintf("<td width=80%%>"
00711                 "<table width=100%% border=0 cellpadding=1 cellspacing=1 "
00712                 "bgcolor=#204B78>\n");
00713 
00715         wprintf("<tr>"
00716                 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
00717                 "<td bgcolor=\"#FFFFFF\" valign=top>");
00718         for (hour = (-1); hour <= (daystart-1); ++hour) {
00719                 calendar_day_view_display_events(year, month, day, hour);
00720         }
00721         wprintf("</td></tr>\n");
00722 
00724         for (hour = daystart; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
00725                 wprintf("<tr height=30><td bgcolor=\"#CCCCDD\" align=middle "
00726                         "valign=middle width=10%%>");
00727                 wprintf("<a href=\"display_edit_event?msgnum=0"
00728                         "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
00729                         year, month, day, hour
00730                 );
00731 
00732                 if (!strcasecmp(calhourformat, "24")) {
00733                         wprintf("%2d:00</a> ", hour);
00734                 }
00735                 else {
00736                         wprintf("%d:00%s</a> ",
00737                                 (hour <= 12 ? hour : hour-12),
00738                                 (hour < 12 ? "am" : "pm")
00739                         );
00740                 }
00741 
00742                 wprintf("</td><td bgcolor=\"#FFFFFF\" valign=top>");
00743 
00744                 /* put the data here, stupid */
00745                 calendar_day_view_display_events(year, month, day, hour);
00746 
00747                 wprintf("</td></tr>\n");
00748         }
00749 
00751         wprintf("<tr>"
00752                 "<td bgcolor=\"#CCCCDD\" valign=middle width=10%%></td>"
00753                 "<td bgcolor=\"#FFFFFF\" valign=top>");
00754         for (hour = (dayend+1); hour <= 23; ++hour) {
00755                 calendar_day_view_display_events(year, month, day, hour);
00756         }
00757         wprintf("</td></tr>\n");
00758 
00759 
00760         wprintf("</table>"                      /* end of innermost table */
00761                 "</td>"
00762         );
00763 
00764         wprintf("<td width=20%% valign=top>");  /* begin stuff-on-the-right */
00765 
00766 
00768         wprintf("<table border=0 width=100%% "
00769                 "cellspacing=0 cellpadding=0 bgcolor=\"#FFFFFF\">\n");
00770         wprintf("<tr>");
00771 
00773         wprintf("<td align=center>");
00774         wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
00775                 yesterday.year, yesterday.month, yesterday.day);
00776         wprintf("<img align=middle src=\"static/prevdate_32x.gif\" border=0></A>");
00777         wprintf("</td>");
00778 
00780         memset(&d_tm, 0, sizeof d_tm);
00781         d_tm.tm_year = year - 1900;
00782         d_tm.tm_mon = month - 1;
00783         d_tm.tm_mday = day;
00784         wc_strftime(d_str, sizeof d_str,
00785                 "<td align=center>"
00786                 "<font size=+2>%B</font><br />"
00787                 "<font size=+3>%d</font><br />"
00788                 "<font size=+2>%Y</font><br />"
00789                 "</td>",
00790                 &d_tm
00791         );
00792         wprintf("%s", d_str);
00793 
00795         wprintf("<td align=center>");
00796         wprintf("<a href=\"readfwd?calview=day&year=%d&month=%d&day=%d\">",
00797                 tomorrow.year, tomorrow.month, tomorrow.day);
00798         wprintf("<img align=middle src=\"static/nextdate_32x.gif\""
00799                 " border=0></A>\n");
00800         wprintf("</td>");
00801 
00802         wprintf("</tr></table>\n");
00807         wprintf("</font></center>\n");
00808 
00809         wprintf("</td>");                       
00813         wprintf("</tr></table>"                 
00814                 "</td></tr></table></div>"      
00815         );
00816 
00817 
00818 
00819 }
00820 
00824 void calendar_summary_view(void) {
00825         int i;
00826         icalproperty *p;
00827         struct icaltimetype t;
00828         time_t event_tt;
00829         struct tm event_tm;
00830         struct tm today_tm;
00831         time_t now;
00832         int all_day_event = 0;
00833         char timestring[SIZ];
00834 
00835         if (WC->num_cal == 0) {
00836                 return;
00837         }
00838 
00839         now = time(NULL);
00840         localtime_r(&now, &today_tm);
00841 
00842         for (i=0; i<(WC->num_cal); ++i) {
00843                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
00844                                                 ICAL_DTSTART_PROPERTY);
00845                 if (p != NULL) {
00846                         t = icalproperty_get_dtstart(p);
00847                         event_tt = icaltime_as_timet(t);
00848                         if (t.is_date) {
00849                                 all_day_event = 1;
00850                         }
00851                         else {
00852                                 all_day_event = 0;
00853                         }
00854                         fmt_time(timestring, event_tt);
00855 
00856                         if (all_day_event) {
00857                                 gmtime_r(&event_tt, &event_tm);
00858                         }
00859                         else {
00860                                 localtime_r(&event_tt, &event_tm);
00861                         }
00862 
00863                         if ( (event_tm.tm_year == today_tm.tm_year)
00864                            && (event_tm.tm_mon == today_tm.tm_mon)
00865                            && (event_tm.tm_mday == today_tm.tm_mday)
00866                            ) {
00867 
00868 
00869                                 p = icalcomponent_get_first_property(
00870                                                         WC->disp_cal[i].cal,
00871                                                         ICAL_SUMMARY_PROPERTY);
00872                                 if (p != NULL) {
00873                                         escputs((char *)
00874                                                 icalproperty_get_comment(p));
00875                                         wprintf(" (%s)<br />\n", timestring);
00876                                 }
00877                         }
00878                 }
00879         }
00880         free_calendar_buffer();
00881 }
00882 
00883 
00888 void free_calendar_buffer(void) {
00889         int i;
00890         if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
00891                 icalcomponent_free(WC->disp_cal[i].cal);
00892         }
00893         WC->num_cal = 0;
00894         free(WC->disp_cal);
00895         WC->disp_cal = NULL;
00896 }
00897 
00898 
00899 
00904 void do_calendar_view(void) {
00905         time_t now;
00906         struct tm tm;
00907         int year, month, day;
00908         char calview[SIZ];
00909 
00911         now = time(NULL);
00912         localtime_r(&now, &tm);
00913         year = tm.tm_year + 1900;
00914         month = tm.tm_mon + 1;
00915         day = tm.tm_mday;
00916 
00918         if (strlen(bstr("year")) > 0) year = atoi(bstr("year"));
00919         if (strlen(bstr("month")) > 0) month = atoi(bstr("month"));
00920         if (strlen(bstr("day")) > 0) day = atoi(bstr("day"));
00921 
00923         if (strlen(bstr("calview")) > 0) {
00924                 strcpy(calview, bstr("calview"));
00925         }
00926         else {
00927                 strcpy(calview, "month");
00928         }
00929 
00931         if (!strcasecmp(calview, "day")) {
00932                 calendar_day_view(year, month, day);
00933         }
00934         else if (!strcasecmp(calview, "week")) {
00935                 calendar_week_view(year, month, day);
00936         }
00937         else {
00938                 if (WC->wc_view == VIEW_CALBRIEF) {
00939                         calendar_brief_month_view(year, month, day);
00940                 }
00941                 else {
00942                         calendar_month_view(year, month, day);
00943                 }
00944         }
00945 
00947         free_calendar_buffer();
00948 
00949 }
00950 
00951 
00958 time_t get_task_due_date(icalcomponent *vtodo) {
00959         icalproperty *p;
00960 
00961         if (vtodo == NULL) {
00962                 return(0L);
00963         }
00964 
00970         if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
00971                 return get_task_due_date(
00972                         icalcomponent_get_first_component(
00973                                 vtodo, ICAL_VTODO_COMPONENT
00974                         )
00975                 );
00976         }
00977 
00978         p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
00979         if (p != NULL) {
00980                 return(icaltime_as_timet(icalproperty_get_due(p)));
00981         }
00982         else {
00983                 return(0L);
00984         }
00985 }
00986 
00987 
00993 int task_due_cmp(const void *task1, const void *task2) {
00994         time_t t1;
00995         time_t t2;
00996 
00997         t1 =  get_task_due_date(((struct disp_cal *)task1)->cal);
00998         t2 =  get_task_due_date(((struct disp_cal *)task2)->cal);
00999 
01000         if (t1 < t2) return(-1);
01001         if (t1 > t2) return(1);
01002         return(0);
01003 }
01004 
01005 
01006 
01007 
01011 void do_tasks_view(void) {
01012         int i;
01013         time_t due;
01014         int bg = 0;
01015         char buf[SIZ];
01016         icalproperty *p;
01017 
01018         wprintf("<div class=\"fix_scrollbar_bug\">"
01019                 "<table class=\"calendar_view_background\">\n<tr>\n"
01020                 "<th>");
01021         wprintf(_("Name of task"));
01022         wprintf("</th><th>");
01023         wprintf(_("Date due"));
01024         wprintf("</th></tr>\n"
01025         );
01026 
01028         if (WC->num_cal > 1) {
01029                 qsort(WC->disp_cal,
01030                         WC->num_cal,
01031                         sizeof(struct disp_cal),
01032                         task_due_cmp
01033                 );
01034         }
01035 
01036         if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
01037 
01038                 bg = 1 - bg;
01039                 wprintf("<tr bgcolor=\"#%s\"><td>",
01040                         (bg ? "DDDDDD" : "FFFFFF")
01041                 );
01042 
01043                 p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
01044                                                         ICAL_SUMMARY_PROPERTY);
01045                 wprintf("<a href=\"display_edit_task?msgnum=%ld&taskrm=",
01046                         WC->disp_cal[i].cal_msgnum );
01047                 urlescputs(WC->wc_roomname);
01048                 wprintf("\">");
01049                 wprintf("<img align=middle "
01050                         "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;");
01051                 if (p != NULL) {
01052                         escputs((char *)icalproperty_get_comment(p));
01053                 }
01054                 wprintf("</a>\n");
01055                 wprintf("</td>\n");
01056 
01057                 due = get_task_due_date(WC->disp_cal[i].cal);
01058                 fmt_date(buf, due, 0);
01059                 wprintf("<td><font");
01060                 if (due < time(NULL)) {
01061                         wprintf(" color=\"#FF0000\"");
01062                 }
01063                 wprintf(">%s</font></td></tr>\n", buf);
01064         }
01065 
01066         wprintf("</table></div>\n");
01067 
01069         free_calendar_buffer();
01070 
01071 }
01072 
01073 #endif  /* WEBCIT_WITH_CALENDAR_SERVICE */
01074 

Generated on Wed Jun 20 23:13:07 2007 for webcit by  doxygen 1.5.2