");
-
- /** Inner table (the real one) */
- wprintf("
\n");
-
- /** Innermost cell (contains hours etc.) */
- wprintf("");
- wprintf("",
- (dayend - daystart) * 30,
- (dayend - daystart) * 30
- );
- /** Now the middle of the day... */
- for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
- if (hour >= daystart) {
- wprintf("- ",
- year, month, day, hour
- );
+ /* Inner table (the real one) */
+ wc_printf("
\n");
- if (time_format == WC_TIMEFORMAT_24) {
- wprintf("%2d:00 ", hour);
- }
- else {
- wprintf("%d:00%s ",
- (hour <= 12 ? hour : hour-12),
- (hour < 12 ? "am" : "pm")
- );
- }
+ /* Innermost cell (contains hours etc.) */
+ wc_printf("");
+ wc_printf("");
- wprintf("");
- }
+ /* Now the middle of the day... */
- /* put the data here, stupid */
- calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
+ extrahourlabel = extratimeline - 2;
+ hourlabel = extrahourlabel * 150 / 100;
+ if (hourlabel > (timeline - 2)) hourlabel = timeline - 2;
- }
+ for (hour = 0; hour < daystart; ++hour) { /* could do HEIGHT=xx */
+ wc_printf(" ");
- wprintf(" | "); /* end of innermost table */
+ if (time_format == WC_TIMEFORMAT_24) {
+ wc_printf("%2d:00 ", hour);
+ }
+ else {
+ wc_printf("%d:00%s ",
+ ((hour == 0) ? 12 : (hour <= 12 ? hour : hour-12)),
+ (hour < 12 ? "am" : "pm")
+ );
+ }
- /** Extra events on the middle */
- wprintf(""); /* end of innermost table */
- wprintf(""); /** end extra on the middle */
+ /* Display extra events (start/end times not present or not today) in the middle column */
+ wc_printf(""); /** begin stuff-on-the-right */
+ wc_printf("");
- /** Begin todays-date-with-left-and-right-arrows */
- wprintf("\n");
- wprintf("");
+ /* Display all-day events */
+ calendar_day_view_display_events(today_t, year, month, day, 1, daystart, dayend);
- /** Left arrow */
- wprintf("");
- wprintf("",
+ wc_printf("");
+
+ wc_printf(" | "); /* end extra on the middle */
+
+ wc_printf(""); /* begin stuff-on-the-right */
+
+ /* Begin todays-date-with-left-and-right-arrows */
+ wc_printf("\n");
+ wc_printf("");
+
+ /* Left arrow */
+ wc_printf("");
+ wc_printf("",
yesterday.year, yesterday.month, yesterday.day);
- wprintf("");
- wprintf(" | ");
+ wc_printf("");
+ wc_printf("");
wc_strftime(d_str, sizeof d_str,
- ""
- "%B "
- "%d "
- "%Y "
+ " | "
+ "%A "
+ "%B "
+ "%d "
+ "%Y "
" | ",
&d_tm
- );
- wprintf("%s", d_str);
+ );
+ wc_printf("%s", d_str);
- /** Right arrow */
- wprintf("");
- wprintf("",
+ /* Right arrow */
+ wc_printf(" | ");
+ wc_printf("",
tomorrow.year, tomorrow.month, tomorrow.day);
- wprintf("\n");
- wprintf(" | ");
+ wc_printf("\n", _("next"));
+ wc_printf("");
- wprintf(" \n");
- /** End todays-date-with-left-and-right-arrows */
+ wc_printf(" | \n");
+ /* End todays-date-with-left-and-right-arrows */
- /** \todo In the future we might want to put a month-o-matic here */
+ /* Embed a mini month calendar in this space */
+ wc_printf(" \n");
+ embeddable_mini_calendar(year, month);
- wprintf("\n");
-
- wprintf(" | "); /** end stuff-on-the-right */
-
- wprintf(" " /** end of inner table */
- "");
-
- wprintf("\n"
- );
+ wc_printf(" |
"); /* end stuff-on-the-right */
+ wc_printf("
\n"); /* end of inner table */
+}
-}
-/**
- * \brief Display today's events.
+/*
+ * Display today's events. Returns the number of items displayed.
*/
-void calendar_summary_view(void) {
- int i;
+int calendar_summary_view(void) {
+ long hklen;
+ const char *HashKey;
+ void *vCal;
+ HashPos *Pos;
+ disp_cal *Cal;
icalproperty *p;
struct icaltimetype t;
time_t event_tt;
@@ -912,17 +1331,20 @@ void calendar_summary_view(void) {
time_t now;
int all_day_event = 0;
char timestring[SIZ];
+ wcsession *WCC = WC;
+ int num_displayed = 0;
- if (WC->num_cal == 0) {
- return;
+ if (GetCount(WC->disp_cal_items) == 0) {
+ return(0);
}
now = time(NULL);
localtime_r(&now, &today_tm);
- for (i=0; i<(WC->num_cal); ++i) {
- p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
- ICAL_DTSTART_PROPERTY);
+ 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);
if (p != NULL) {
t = icalproperty_get_dtstart(p);
event_tt = icaltime_as_timet(t);
@@ -932,7 +1354,7 @@ void calendar_summary_view(void) {
else {
all_day_event = 0;
}
- fmt_time(timestring, event_tt);
+ fmt_time(timestring, SIZ, event_tt);
if (all_day_event) {
gmtime_r(&event_tt, &event_tm);
@@ -942,232 +1364,179 @@ 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)
- ) {
-
-
- p = icalcomponent_get_first_property(
- WC->disp_cal[i].cal,
- ICAL_SUMMARY_PROPERTY);
- if (p != NULL) {
- escputs((char *)
- icalproperty_get_comment(p));
- wprintf(" (%s)
\n", timestring);
+ && (event_tm.tm_mon == today_tm.tm_mon)
+ && (event_tm.tm_mday == today_tm.tm_mday)
+ ) {
+
+ p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
+ if (p == NULL) {
+ p = icalproperty_new_summary(_("Untitled Task"));
+ icalcomponent_add_property(Cal->cal, p);
+ }
+ if (p != NULL)
+ {
+ if (WCC->CurRoom.view == VIEW_TASKS) {
+ wc_printf("
cal_msgnum
+ );
+ escputs(ChrPtr(WCC->CurRoom.name));
+ wc_printf("\">");
+ }
+ else {
+ wc_printf("cal_msgnum,
+ today_tm.tm_year + 1900,
+ today_tm.tm_mon + 1,
+ today_tm.tm_mday
+ );
+ escputs(ChrPtr(WCC->CurRoom.name));
+ wc_printf("\">");
+ }
+ escputs((char *) icalproperty_get_comment(p));
+ if (!all_day_event) {
+ wc_printf(" (%s)", timestring);
+ }
+ wc_printf("\n");
+ ++num_displayed;
}
}
}
}
- free_calendar_buffer();
+ DeleteHashPos(&Pos);
+ DeleteHash(&WC->disp_cal_items);
+ return(num_displayed);
}
-
-/**
- * \brief clean up ical memory
- * \todo this could get troubel with future ical versions
+/*
+ * Parse the URL variables in order to determine the scope and display of a calendar view
*/
-void free_calendar_buffer(void) {
- int i;
- if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
- icalcomponent_free(WC->disp_cal[i].cal);
- }
- WC->num_cal = 0;
- free(WC->disp_cal);
- WC->disp_cal = NULL;
-}
+int calendar_GetParamsGetServerCall(SharedMessageStatus *Stat,
+ void **ViewSpecific,
+ long oper,
+ char *cmd,
+ long len,
+ char *filter,
+ long flen)
+{
+ wcsession *WCC = WC;
+ calview *c;
+ time_t now;
+ struct tm tm;
+ char cv[32];
+ int span = 3888000;
+ c = (calview*) malloc(sizeof(calview));
+ memset(c, 0, sizeof(calview));
+ *ViewSpecific = (void*)c;
-/**
- * \brief do the whole calendar page
- * view any part of the calender. decide which way, etc.
- */
-void do_calendar_view(void) {
- time_t now;
- struct tm tm;
- int year, month, day;
- char calview[SIZ];
+ Stat->load_seen = 1;
+ strcpy(cmd, "MSGS ALL");
+ Stat->maxmsgs = 32767;
- /** In case no date was specified, go with today */
+ /* In case no date was specified, go with today */
now = time(NULL);
localtime_r(&now, &tm);
- year = tm.tm_year + 1900;
- month = tm.tm_mon + 1;
- day = tm.tm_mday;
-
- /** Now see if a date was specified */
- 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 (!IsEmptyStr(bstr("calview"))) {
- strcpy(calview, bstr("calview"));
+ c->year = tm.tm_year + 1900;
+ c->month = tm.tm_mon + 1;
+ c->day = tm.tm_mday;
+
+ /* Now see if a date was specified */
+ if (havebstr("year")) c->year = ibstr("year");
+ if (havebstr("month")) c->month = ibstr("month");
+ if (havebstr("day")) c->day = ibstr("day");
+
+ /* How would you like that cooked? */
+ if (havebstr("calview")) {
+ strcpy(cv, bstr("calview"));
}
else {
- strcpy(calview, "month");
+ strcpy(cv, "month");
}
- /** Display the selected view */
- if (!strcasecmp(calview, "day")) {
- calendar_day_view(year, month, day);
+ /* Display the selected view */
+ if (!strcasecmp(cv, "day")) {
+ c->view = calview_day;
+ }
+ else if (!strcasecmp(cv, "week")) {
+ c->view = calview_week;
}
- else if (!strcasecmp(calview, "week")) {
- calendar_week_view(year, month, day);
+ else if (!strcasecmp(cv, "summary")) { /* shouldn't ever happen, but just in case */
+ c->view = calview_day;
}
else {
- if (WC->wc_view == VIEW_CALBRIEF) {
- calendar_brief_month_view(year, month, day);
+ if (WCC->CurRoom.view == VIEW_CALBRIEF) {
+ c->view = calview_brief;
}
else {
- calendar_month_view(year, month, day);
+ c->view = calview_month;
}
}
- /** Free the calendar stuff */
- free_calendar_buffer();
-
-}
-
-
-/**
- * \brief get task due date
- * Helper function for do_tasks_view().
- * \param vtodo a task to get the due date
- * \return the date/time due.
- */
-time_t get_task_due_date(icalcomponent *vtodo) {
- icalproperty *p;
-
- if (vtodo == NULL) {
- return(0L);
- }
-
- /**
- * If we're looking at a fully encapsulated VCALENDAR
- * rather than a VTODO component, recurse into the data
- * structure until we get a VTODO.
+ /* Now try and set the lower and upper bounds so that we don't
+ * burn too many cpu cycles parsing data way in the past or future
*/
- if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
- return get_task_due_date(
- icalcomponent_get_first_component(
- vtodo, ICAL_VTODO_COMPONENT
- )
- );
- }
-
- p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
- if (p != NULL) {
- return(icaltime_as_timet(icalproperty_get_due(p)));
- }
- else {
- return(0L);
- }
-}
-
-/**
- * \brief Compare the due dates of two tasks (this is for sorting)
- * \param task1 first task to compare
- * \param task2 second task to compare
- */
-int task_due_cmp(const void *task1, const void *task2) {
- time_t t1;
- time_t t2;
+ tm.tm_year = c->year - 1900;
+ tm.tm_mon = c->month - 1;
+ tm.tm_mday = c->day;
+ now = mktime(&tm);
- t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
- t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
+ 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;
- if (t1 < t2) return(-1);
- if (t1 > t2) return(1);
- return(0);
+ c->lower_bound = now - span;
+ c->upper_bound = now + span;
+ return 200;
}
-
-/**
- * \brief do the whole task view stuff
+/*
+ * Render a calendar view from data previously loaded into memory
*/
-void do_tasks_view(void) {
- int i;
- time_t due;
- int bg = 0;
- char buf[SIZ];
- icalproperty *p;
-
- wprintf("
\n");
-
- /** Free the list */
- free_calendar_buffer();
-
+ /* Free the in-memory list of calendar items */
+ DeleteHash(&WC->disp_cal_items);
+ return 0;
}
-#else /* WEBCIT_WITH_CALENDAR_SERVICE */
-
-/**\brief stub for non-libical builds */
-void do_calendar_view(void) {
- wprintf("
");
- wprintf(_("The calendar view is not available."));
- wprintf("\n");
-}
-
-/**\brief stub for non-libical builds */
-void do_tasks_view(void) {
- wprintf("
");
- wprintf(_("The tasks view is not available."));
- wprintf("\n");
+void
+InitModule_CALENDAR_VIEW
+(void)
+{
+ WebcitAddUrlHandler(HKEY("mini_calendar"), "", 0, ajax_mini_calendar, AJAX);
}
-
-
-#endif /* WEBCIT_WITH_CALENDAR_SERVICE */
-
-/** @} */