6 * qsort filter to move completed tasks to bottom of task list
8 int task_completed_cmp(const void *vtask1, const void *vtask2) {
9 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
10 /* disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
12 icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
13 /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
15 if (t1 == ICAL_STATUS_COMPLETED)
22 * Helper function for do_tasks_view(). Returns the due date/time of a vtodo.
24 time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
32 * If we're looking at a fully encapsulated VCALENDAR
33 * rather than a VTODO component, recurse into the data
34 * structure until we get a VTODO.
36 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
37 return get_task_due_date(
38 icalcomponent_get_first_component(
39 vtodo, ICAL_VTODO_COMPONENT
44 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
46 struct icaltimetype t = icalproperty_get_due(p);
50 return(icaltime_as_timet(t));
58 * Compare the due dates of two tasks (this is for sorting)
60 int task_due_cmp(const void *vtask1, const void *vtask2) {
61 disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
62 disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
67 t1 = get_task_due_date(Task1->cal, NULL);
68 t2 = get_task_due_date(Task2->cal, NULL);
69 if (t1 < t2) return(-1);
70 if (t1 > t2) return(1);
75 * do the whole task view stuff
77 int tasks_RenderView_or_Tail(SharedMessageStatus *Stat,
92 wc_printf("<div class=\"fix_scrollbar_bug\">"
93 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
95 wc_printf(_("Completed?"));
96 wc_printf("</th><th>");
97 wc_printf(_("Name of task"));
98 wc_printf("</th><th>");
99 wc_printf(_("Date due"));
100 wc_printf("</th><th>");
101 wc_printf(_("Category"));
102 wc_printf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
105 nItems = GetCount(WC->disp_cal_items);
107 /* Sort them if necessary
109 SortByPayload(WC->disp_cal_items, task_due_cmp);
111 * this shouldn't be neccessary, since we sort by the start time.
114 /* And then again, by completed */
116 SortByPayload(WC->disp_cal_items,
120 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
121 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
122 icalproperty_status todoStatus;
125 Cal = (disp_cal*)vCal;
126 wc_printf("<tr><td>");
127 todoStatus = icalcomponent_get_status(Cal->cal);
128 wc_printf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
129 if (todoStatus == ICAL_STATUS_COMPLETED) {
130 wc_printf("checked=\"checked\" ");
132 wc_printf("disabled=\"disabled\">\n</td><td>");
133 p = icalcomponent_get_first_property(Cal->cal,
134 ICAL_SUMMARY_PROPERTY);
135 wc_printf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
136 urlescputs(ChrPtr(WC->CurRoom.name));
138 /* wc_printf("<img align=middle "
139 "src=\"static/taskmanag_16x.gif\" border=0> "); */
141 escputs((char *)icalproperty_get_comment(p));
144 wc_printf("</td>\n");
146 due = get_task_due_date(Cal->cal, &is_date);
147 wc_printf("<td><span");
149 webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
150 wc_printf(">%s",buf);
155 wc_printf("</span></td>");
157 p = icalcomponent_get_first_property(Cal->cal,
158 ICAL_CATEGORIES_PROPERTY);
160 escputs((char *)icalproperty_get_categories(p));
166 wc_printf("</tbody></table></div>\n");
169 DeleteHash(&WC->disp_cal_items);
176 * Display a task by itself (for editing)
178 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from,
179 int unread, calview *calv)
181 icalcomponent *vtodo;
183 struct icaltimetype IcalTime;
184 int created_new_vtodo = 0;
185 icalproperty_status todoStatus;
187 if (supplied_vtodo != NULL) {
188 vtodo = supplied_vtodo;
191 * It's safe to convert to UTC here because there are no recurrences to worry about.
193 ical_dezonify(vtodo);
196 * If we're looking at a fully encapsulated VCALENDAR
197 * rather than a VTODO component, attempt to use the first
198 * relevant VTODO subcomponent. If there is none, the
199 * NULL returned by icalcomponent_get_first_component() will
200 * tell the next iteration of this function to create a
203 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
204 display_edit_individual_task(
205 icalcomponent_get_first_component(
206 vtodo, ICAL_VTODO_COMPONENT
208 msgnum, from, unread, calv
214 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
215 created_new_vtodo = 1;
218 /* TODO: Can we take all this and move it into a template? */
219 output_headers(1, 1, 1, 0, 0, 0);
220 wc_printf("<!-- start task edit form -->");
221 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
222 /* Get summary early for title */
223 wc_printf("<div class=\"box\">\n");
224 wc_printf("<div class=\"boxlabel\">");
225 wc_printf(_("Edit task"));
228 escputs((char *)icalproperty_get_comment(p));
232 wc_printf("<div class=\"boxcontent\">\n");
233 wc_printf("<FORM METHOD=\"POST\" action=\"save_task\">\n");
234 wc_printf("<div style=\"display: none;\">\n ");
235 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
236 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n", msgnum);
237 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"return_to_summary\" VALUE=\"%d\">\n",
238 ibstr("return_to_summary"));
240 wc_printf("<table class=\"calendar_background\"><tr><td>");
241 wc_printf("<TABLE STYLE=\"border: none;\">\n");
243 wc_printf("<TR><TD>");
244 wc_printf(_("Summary:"));
245 wc_printf("</TD><TD>"
246 "<INPUT TYPE=\"text\" NAME=\"summary\" "
247 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
248 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
250 escputs((char *)icalproperty_get_comment(p));
252 wc_printf("\"></TD></TR>\n");
254 wc_printf("<TR><TD>");
255 wc_printf(_("Start date:"));
256 wc_printf("</TD><TD>");
257 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
258 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodtstart\" ID=\"nodtstart\" VALUE=\"NODTSTART\" ");
260 wc_printf("CHECKED=\"CHECKED\"");
263 wc_printf(_("No date"));
266 wc_printf("<span ID=\"dtstart_date\">");
270 IcalTime = icalproperty_get_dtstart(p);
273 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
274 display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
276 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"dtstart_time_assoc\" ID=\"dtstart_time_assoc\" VALUE=\"yes\"");
277 if (!IcalTime.is_date) {
278 wc_printf("CHECKED=\"CHECKED\"");
281 wc_printf(_("Time associated"));
282 wc_printf("</span></TD></TR>\n");
284 wc_printf("<TR><TD>");
285 wc_printf(_("Due date:"));
286 wc_printf("</TD><TD>");
287 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
288 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodue\" ID=\"nodue\" VALUE=\"NODUE\"");
290 wc_printf("CHECKED=\"CHECKED\"");
293 wc_printf(_("No date"));
295 wc_printf("<span ID=\"due_date\">\n");
299 IcalTime = icalproperty_get_due(p);
302 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
303 display_icaltimetype_as_webform(&IcalTime, "due", 0);
305 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"due_time_assoc\" ID=\"due_time_assoc\" VALUE=\"yes\"");
306 if (!IcalTime.is_date) {
307 wc_printf("CHECKED=\"CHECKED\"");
310 wc_printf(_("Time associated"));
311 wc_printf("</span></TD></TR>\n");
312 todoStatus = icalcomponent_get_status(vtodo);
313 wc_printf("<TR><TD>\n");
314 wc_printf(_("Completed:"));
315 wc_printf("</TD><TD>");
316 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"status\" VALUE=\"COMPLETED\"");
317 if (todoStatus == ICAL_STATUS_COMPLETED) {
318 wc_printf(" CHECKED=\"CHECKED\"");
321 wc_printf("</TD></TR>");
322 /* start category field */
323 p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY);
324 wc_printf("<TR><TD>");
325 wc_printf(_("Category:"));
326 wc_printf("</TD><TD>");
327 wc_printf("<INPUT TYPE=\"text\" NAME=\"category\" MAXLENGTH=\"32\" SIZE=\"32\" VALUE=\"");
329 escputs((char *)icalproperty_get_categories(p));
332 wc_printf("</TD></TR>\n ");
333 /* end category field */
334 wc_printf("<TR><TD>");
335 wc_printf(_("Description:"));
336 wc_printf("</TD><TD>");
337 wc_printf("<TEXTAREA NAME=\"description\" "
338 "ROWS=\"10\" COLS=\"80\">\n"
340 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
342 escputs((char *)icalproperty_get_comment(p));
344 wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
346 wc_printf("<SPAN STYLE=\"text-align: center;\">"
347 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
349 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
351 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
357 wc_printf("</td></tr></table>");
358 wc_printf("</FORM>\n");
359 wc_printf("</div></div></div>\n");
360 wc_printf("<!-- end task edit form -->");
363 if (created_new_vtodo) {
364 icalcomponent_free(vtodo);
369 * Save an edited task
371 * supplied_vtodo the task to save
372 * msgnum number of the mesage in our db
374 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
378 int delete_existing = 0;
380 icalcomponent *vtodo, *encaps;
381 int created_new_vtodo = 0;
384 struct icaltimetype t;
386 if (supplied_vtodo != NULL) {
387 vtodo = supplied_vtodo;
389 * If we're looking at a fully encapsulated VCALENDAR
390 * rather than a VTODO component, attempt to use the first
391 * relevant VTODO subcomponent. If there is none, the
392 * NULL returned by icalcomponent_get_first_component() will
393 * tell the next iteration of this function to create a
396 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
397 save_individual_task(
398 icalcomponent_get_first_component(
399 vtodo, ICAL_VTODO_COMPONENT),
400 msgnum, from, unread, calv
406 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
407 created_new_vtodo = 1;
410 if (havebstr("save_button")) {
412 /** Replace values in the component with ones from the form */
414 while (prop = icalcomponent_get_first_property(vtodo,
415 ICAL_SUMMARY_PROPERTY), prop != NULL) {
416 icalcomponent_remove_property(vtodo, prop);
417 icalproperty_free(prop);
419 if (havebstr("summary")) {
421 icalcomponent_add_property(vtodo,
422 icalproperty_new_summary(bstr("summary")));
424 icalcomponent_add_property(vtodo,
425 icalproperty_new_summary(_("Untitled Task")));
428 while (prop = icalcomponent_get_first_property(vtodo,
429 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
430 icalcomponent_remove_property(vtodo, prop);
431 icalproperty_free(prop);
433 if (havebstr("description")) {
434 icalcomponent_add_property(vtodo,
435 icalproperty_new_description(bstr("description")));
438 while (prop = icalcomponent_get_first_property(vtodo,
439 ICAL_DTSTART_PROPERTY), prop != NULL) {
440 icalcomponent_remove_property(vtodo, prop);
441 icalproperty_free(prop);
443 if (IsEmptyStr(bstr("nodtstart"))) {
444 if (yesbstr("dtstart_time")) {
445 icaltime_from_webform(&t, "dtstart");
448 icaltime_from_webform_dateonly(&t, "dtstart");
450 icalcomponent_add_property(vtodo,
451 icalproperty_new_dtstart(t)
454 while(prop = icalcomponent_get_first_property(vtodo,
455 ICAL_STATUS_PROPERTY), prop != NULL) {
456 icalcomponent_remove_property(vtodo,prop);
457 icalproperty_free(prop);
459 while(prop = icalcomponent_get_first_property(vtodo,
460 ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
461 icalcomponent_remove_property(vtodo,prop);
462 icalproperty_free(prop);
465 if (havebstr("status")) {
466 icalproperty_status taskStatus = icalproperty_string_to_status(bstr("status"));
467 icalcomponent_set_status(vtodo, taskStatus);
468 icalcomponent_add_property(vtodo,
469 icalproperty_new_percentcomplete(
470 (strcasecmp(bstr("status"), "completed") ? 0 : 100)
475 icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
477 while (prop = icalcomponent_get_first_property(vtodo,
478 ICAL_CATEGORIES_PROPERTY), prop != NULL) {
479 icalcomponent_remove_property(vtodo,prop);
480 icalproperty_free(prop);
482 if (!IsEmptyStr(bstr("category"))) {
483 prop = icalproperty_new_categories(bstr("category"));
484 icalcomponent_add_property(vtodo,prop);
486 while (prop = icalcomponent_get_first_property(vtodo,
487 ICAL_DUE_PROPERTY), prop != NULL) {
488 icalcomponent_remove_property(vtodo, prop);
489 icalproperty_free(prop);
491 if (IsEmptyStr(bstr("nodue"))) {
492 if (yesbstr("due_time")) {
493 icaltime_from_webform(&t, "due");
496 icaltime_from_webform_dateonly(&t, "due");
498 icalcomponent_add_property(vtodo,
499 icalproperty_new_due(t)
502 /** Give this task a UID if it doesn't have one. */
503 lprintf(9, "Give this task a UID if it doesn't have one.\n");
504 if (icalcomponent_get_first_property(vtodo,
505 ICAL_UID_PROPERTY) == NULL) {
507 icalcomponent_add_property(vtodo,
508 icalproperty_new_uid(buf)
512 /* Increment the sequence ID */
513 lprintf(9, "Increment the sequence ID\n");
514 while (prop = icalcomponent_get_first_property(vtodo,
515 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
516 i = icalproperty_get_sequence(prop);
517 lprintf(9, "Sequence was %d\n", i);
518 if (i > sequence) sequence = i;
519 icalcomponent_remove_property(vtodo, prop);
520 icalproperty_free(prop);
523 lprintf(9, "New sequence is %d. Adding...\n", sequence);
524 icalcomponent_add_property(vtodo,
525 icalproperty_new_sequence(sequence)
529 * Encapsulate event into full VCALENDAR component. Clone it first,
530 * for two reasons: one, it's easier to just free the whole thing
531 * when we're done instead of unbundling, but more importantly, we
532 * can't encapsulate something that may already be encapsulated
535 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
536 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
538 /* Serialize it and save it to the message base */
539 serv_puts("ENT0 1|||4");
540 serv_getln(buf, sizeof buf);
542 serv_puts("Content-type: text/calendar");
544 serv_puts(icalcomponent_as_ical_string(encaps));
548 * Probably not necessary; the server will see the UID
549 * of the object and delete the old one anyway, but
554 icalcomponent_free(encaps);
558 * If the user clicked 'Delete' then explicitly delete the message.
560 if (havebstr("delete_button")) {
564 if ( (delete_existing) && (msgnum > 0L) ) {
565 serv_printf("DELE %ld", lbstr("msgnum"));
566 serv_getln(buf, sizeof buf);
569 if (created_new_vtodo) {
570 icalcomponent_free(vtodo);
573 /* Go back to wherever we came from */
574 if (ibstr("return_to_summary") == 1) {
578 readloop(readfwd, eUseDefault);
585 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat,
587 message_summary* Msg,
591 /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
593 load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0);
598 * Display the editor component for a task
600 void display_edit_task(void) {
603 /* Force change the room if we have to */
604 if (havebstr("taskrm")) {
605 gotoroom(sbstr("taskrm"));
608 msgnum = lbstr("msgnum");
611 load_ical_object(msgnum, 0,
612 ICAL_VTODO_COMPONENT,
613 display_edit_individual_task,
619 display_edit_individual_task(NULL, 0L, "", 0, NULL);
624 * save an edited task
626 void save_task(void) {
628 msgnum = lbstr("msgnum");
630 load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
633 save_individual_task(NULL, 0L, "", 0, NULL);
639 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat,
645 strcpy(cmd, "MSGS ALL");
646 Stat->maxmsgs = 32767;
651 int tasks_Cleanup(void **ViewSpecific)
654 /* Tasks doesn't need the calview struct...
655 free (*ViewSpecific);
656 *ViewSpecific = NULL;
665 RegisterReadLoopHandlerset(
667 tasks_GetParamsGetServerCall,
670 tasks_LoadMsgFromServer,
671 tasks_RenderView_or_Tail,
673 WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);