+
+/*
+ * Helper function for do_tasks_view(). Returns 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.
+ */
+ 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);
+ }
+}
+
+
+/*
+ * Compare the due dates of two tasks (this is for sorting)
+ */
+int task_due_cmp(const void *task1, const void *task2) {
+ time_t t1;
+ time_t t2;
+
+ t1 = get_task_due_date(((struct disp_cal *)task1)->cal);
+ t2 = get_task_due_date(((struct disp_cal *)task2)->cal);
+
+ if (t1 < t2) return(-1);
+ if (t1 > t2) return(1);
+ return(0);
+}
+
+
+
+
+
+void do_tasks_view(void) {
+ int i;
+ time_t due;
+ int bg = 0;
+ char buf[SIZ];
+ icalproperty *p;
+
+ wprintf("<div id=\"fix_scrollbar_bug\">"
+ "<table border=0 cellspacing=0 width=100%% bgcolor=\"#FFFFFF\">\n<tr>\n"
+ "<TH>Name of task</TH>\n"
+ "<TH>Date due</TH></TR>\n"
+ );
+
+ /* Sort them if necessary */
+ if (WC->num_cal > 1) {
+ qsort(WC->disp_cal,
+ WC->num_cal,
+ sizeof(struct disp_cal),
+ task_due_cmp
+ );
+ }
+
+ if (WC->num_cal) for (i=0; i<(WC->num_cal); ++i) {
+
+ bg = 1 - bg;
+ wprintf("<TR BGCOLOR=\"#%s\"><TD>",
+ (bg ? "DDDDDD" : "FFFFFF")
+ );
+
+ p = icalcomponent_get_first_property(WC->disp_cal[i].cal,
+ ICAL_SUMMARY_PROPERTY);
+ wprintf("<A HREF=\"/display_edit_task?msgnum=%ld&taskrm=",
+ WC->disp_cal[i].cal_msgnum );
+ urlescputs(WC->wc_roomname);
+ wprintf("\">");
+ wprintf("<IMG ALIGN=MIDDLE "
+ "SRC=\"/static/taskmanag_16x.gif\" BORDER=0> ");
+ if (p != NULL) {
+ escputs((char *)icalproperty_get_comment(p));
+ }
+ wprintf("</A>\n");
+ wprintf("</TD>\n");
+
+ due = get_task_due_date(WC->disp_cal[i].cal);
+ fmt_date(buf, due, 0);
+ wprintf("<TD><FONT");
+ if (due < time(NULL)) {
+ wprintf(" COLOR=\"#FF0000\"");
+ }
+ wprintf(">%s</FONT></TD></TR>\n", buf);
+ }
+
+ wprintf("</table></div>\n");
+
+ /* Free the list */
+ free_calendar_buffer();
+
+}
+