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;
185 int created_new_vtodo = 0;
186 icalproperty_status todoStatus;
190 if (supplied_vtodo != NULL) {
191 vtodo = supplied_vtodo;
194 * It's safe to convert to UTC here because there are no recurrences to worry about.
196 ical_dezonify(vtodo);
199 * If we're looking at a fully encapsulated VCALENDAR
200 * rather than a VTODO component, attempt to use the first
201 * relevant VTODO subcomponent. If there is none, the
202 * NULL returned by icalcomponent_get_first_component() will
203 * tell the next iteration of this function to create a
206 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
207 display_edit_individual_task(
208 icalcomponent_get_first_component(
209 vtodo, ICAL_VTODO_COMPONENT
211 msgnum, from, unread, calv
217 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
218 created_new_vtodo = 1;
221 /* TODO: Can we take all this and move it into a template? */
222 output_headers(1, 1, 1, 0, 0, 0);
223 wc_printf("<!-- start task edit form -->");
224 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
225 /* Get summary early for title */
226 wc_printf("<div class=\"box\">\n");
227 wc_printf("<div class=\"boxlabel\">");
228 wc_printf(_("Edit task"));
231 escputs((char *)icalproperty_get_comment(p));
235 wc_printf("<div class=\"boxcontent\">\n");
236 wc_printf("<FORM METHOD=\"POST\" action=\"save_task\">\n");
237 wc_printf("<div style=\"display: none;\">\n ");
238 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
239 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n", msgnum);
240 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"return_to_summary\" VALUE=\"%d\">\n",
241 ibstr("return_to_summary"));
243 wc_printf("<table class=\"calendar_background\"><tr><td>");
244 wc_printf("<TABLE STYLE=\"border: none;\">\n");
246 wc_printf("<TR><TD>");
247 wc_printf(_("Summary:"));
248 wc_printf("</TD><TD>"
249 "<INPUT TYPE=\"text\" NAME=\"summary\" "
250 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
251 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
253 escputs((char *)icalproperty_get_comment(p));
255 wc_printf("\"></TD></TR>\n");
257 wc_printf("<TR><TD>");
258 wc_printf(_("Start date:"));
259 wc_printf("</TD><TD>");
260 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
261 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodtstart\" ID=\"nodtstart\" VALUE=\"NODTSTART\" ");
263 wc_printf("CHECKED=\"CHECKED\"");
266 wc_printf(_("No date"));
269 wc_printf("<span ID=\"dtstart_date\">");
273 IcalTime = icalproperty_get_dtstart(p);
276 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
277 display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
279 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"dtstart_time_assoc\" ID=\"dtstart_time_assoc\" VALUE=\"yes\"");
280 if (!IcalTime.is_date) {
281 wc_printf("CHECKED=\"CHECKED\"");
284 wc_printf(_("Time associated"));
285 wc_printf("</span></TD></TR>\n");
287 wc_printf("<TR><TD>");
288 wc_printf(_("Due date:"));
289 wc_printf("</TD><TD>");
290 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
291 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodue\" ID=\"nodue\" VALUE=\"NODUE\"");
293 wc_printf("CHECKED=\"CHECKED\"");
296 wc_printf(_("No date"));
298 wc_printf("<span ID=\"due_date\">\n");
302 IcalTime = icalproperty_get_due(p);
305 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
306 display_icaltimetype_as_webform(&IcalTime, "due", 0);
308 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"due_time_assoc\" ID=\"due_time_assoc\" VALUE=\"yes\"");
309 if (!IcalTime.is_date) {
310 wc_printf("CHECKED=\"CHECKED\"");
313 wc_printf(_("Time associated"));
314 wc_printf("</span></TD></TR>\n");
315 todoStatus = icalcomponent_get_status(vtodo);
316 wc_printf("<TR><TD>\n");
317 wc_printf(_("Completed:"));
318 wc_printf("</TD><TD>");
319 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"status\" VALUE=\"COMPLETED\"");
320 if (todoStatus == ICAL_STATUS_COMPLETED) {
321 wc_printf(" CHECKED=\"CHECKED\"");
324 wc_printf("</TD></TR>");
325 /* start category field */
326 p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY);
327 wc_printf("<TR><TD>");
328 wc_printf(_("Category:"));
329 wc_printf("</TD><TD>");
330 wc_printf("<INPUT TYPE=\"text\" NAME=\"category\" MAXLENGTH=\"32\" SIZE=\"32\" VALUE=\"");
332 escputs((char *)icalproperty_get_categories(p));
335 wc_printf("</TD></TR>\n ");
336 /* end category field */
337 wc_printf("<TR><TD>");
338 wc_printf(_("Description:"));
339 wc_printf("</TD><TD>");
340 wc_printf("<TEXTAREA NAME=\"description\" "
341 "ROWS=\"10\" COLS=\"80\">\n"
343 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
345 escputs((char *)icalproperty_get_comment(p));
347 wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
349 wc_printf("<SPAN STYLE=\"text-align: center;\">"
350 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
352 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
354 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
360 wc_printf("</td></tr></table>");
361 wc_printf("</FORM>\n");
362 wc_printf("</div></div></div>\n");
363 wc_printf("<!-- end task edit form -->");
366 if (created_new_vtodo) {
367 icalcomponent_free(vtodo);
372 * Save an edited task
374 * supplied_vtodo the task to save
375 * msgnum number of the mesage in our db
377 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
381 int delete_existing = 0;
383 icalcomponent *vtodo, *encaps;
384 int created_new_vtodo = 0;
387 struct icaltimetype t;
389 if (supplied_vtodo != NULL) {
390 vtodo = supplied_vtodo;
392 * If we're looking at a fully encapsulated VCALENDAR
393 * rather than a VTODO component, attempt to use the first
394 * relevant VTODO subcomponent. If there is none, the
395 * NULL returned by icalcomponent_get_first_component() will
396 * tell the next iteration of this function to create a
399 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
400 save_individual_task(
401 icalcomponent_get_first_component(
402 vtodo, ICAL_VTODO_COMPONENT),
403 msgnum, from, unread, calv
409 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
410 created_new_vtodo = 1;
413 if (havebstr("save_button")) {
415 /** Replace values in the component with ones from the form */
417 while (prop = icalcomponent_get_first_property(vtodo,
418 ICAL_SUMMARY_PROPERTY), prop != NULL) {
419 icalcomponent_remove_property(vtodo, prop);
420 icalproperty_free(prop);
422 if (havebstr("summary")) {
424 icalcomponent_add_property(vtodo,
425 icalproperty_new_summary(bstr("summary")));
427 icalcomponent_add_property(vtodo,
428 icalproperty_new_summary(_("Untitled Task")));
431 while (prop = icalcomponent_get_first_property(vtodo,
432 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
433 icalcomponent_remove_property(vtodo, prop);
434 icalproperty_free(prop);
436 if (havebstr("description")) {
437 icalcomponent_add_property(vtodo,
438 icalproperty_new_description(bstr("description")));
441 while (prop = icalcomponent_get_first_property(vtodo,
442 ICAL_DTSTART_PROPERTY), prop != NULL) {
443 icalcomponent_remove_property(vtodo, prop);
444 icalproperty_free(prop);
446 if (IsEmptyStr(bstr("nodtstart"))) {
447 if (yesbstr("dtstart_time")) {
448 icaltime_from_webform(&t, "dtstart");
451 icaltime_from_webform_dateonly(&t, "dtstart");
453 icalcomponent_add_property(vtodo,
454 icalproperty_new_dtstart(t)
457 while(prop = icalcomponent_get_first_property(vtodo,
458 ICAL_STATUS_PROPERTY), prop != NULL) {
459 icalcomponent_remove_property(vtodo,prop);
460 icalproperty_free(prop);
462 while(prop = icalcomponent_get_first_property(vtodo,
463 ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
464 icalcomponent_remove_property(vtodo,prop);
465 icalproperty_free(prop);
468 if (havebstr("status")) {
469 icalproperty_status taskStatus = icalproperty_string_to_status(bstr("status"));
470 icalcomponent_set_status(vtodo, taskStatus);
471 icalcomponent_add_property(vtodo,
472 icalproperty_new_percentcomplete(
473 (strcasecmp(bstr("status"), "completed") ? 0 : 100)
478 icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
480 while (prop = icalcomponent_get_first_property(vtodo,
481 ICAL_CATEGORIES_PROPERTY), prop != NULL) {
482 icalcomponent_remove_property(vtodo,prop);
483 icalproperty_free(prop);
485 if (!IsEmptyStr(bstr("category"))) {
486 prop = icalproperty_new_categories(bstr("category"));
487 icalcomponent_add_property(vtodo,prop);
489 while (prop = icalcomponent_get_first_property(vtodo,
490 ICAL_DUE_PROPERTY), prop != NULL) {
491 icalcomponent_remove_property(vtodo, prop);
492 icalproperty_free(prop);
494 if (IsEmptyStr(bstr("nodue"))) {
495 if (yesbstr("due_time")) {
496 icaltime_from_webform(&t, "due");
499 icaltime_from_webform_dateonly(&t, "due");
501 icalcomponent_add_property(vtodo,
502 icalproperty_new_due(t)
505 /** Give this task a UID if it doesn't have one. */
506 lprintf(9, "Give this task a UID if it doesn't have one.\n");
507 if (icalcomponent_get_first_property(vtodo,
508 ICAL_UID_PROPERTY) == NULL) {
510 icalcomponent_add_property(vtodo,
511 icalproperty_new_uid(buf)
515 /* Increment the sequence ID */
516 lprintf(9, "Increment the sequence ID\n");
517 while (prop = icalcomponent_get_first_property(vtodo,
518 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
519 i = icalproperty_get_sequence(prop);
520 lprintf(9, "Sequence was %d\n", i);
521 if (i > sequence) sequence = i;
522 icalcomponent_remove_property(vtodo, prop);
523 icalproperty_free(prop);
526 lprintf(9, "New sequence is %d. Adding...\n", sequence);
527 icalcomponent_add_property(vtodo,
528 icalproperty_new_sequence(sequence)
532 * Encapsulate event into full VCALENDAR component. Clone it first,
533 * for two reasons: one, it's easier to just free the whole thing
534 * when we're done instead of unbundling, but more importantly, we
535 * can't encapsulate something that may already be encapsulated
538 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
539 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
541 /* Serialize it and save it to the message base */
542 serv_puts("ENT0 1|||4");
543 serv_getln(buf, sizeof buf);
545 serv_puts("Content-type: text/calendar");
547 serv_puts(icalcomponent_as_ical_string(encaps));
551 * Probably not necessary; the server will see the UID
552 * of the object and delete the old one anyway, but
557 icalcomponent_free(encaps);
561 * If the user clicked 'Delete' then explicitly delete the message.
563 if (havebstr("delete_button")) {
567 if ( (delete_existing) && (msgnum > 0L) ) {
568 serv_printf("DELE %ld", lbstr("msgnum"));
569 serv_getln(buf, sizeof buf);
572 if (created_new_vtodo) {
573 icalcomponent_free(vtodo);
576 /* Go back to wherever we came from */
577 if (ibstr("return_to_summary") == 1) {
581 readloop(readfwd, eUseDefault);
588 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat,
590 message_summary* Msg,
594 /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
596 load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0);
601 * Display the editor component for a task
603 void display_edit_task(void) {
606 /* Force change the room if we have to */
607 if (havebstr("taskrm")) {
608 gotoroom(sbstr("taskrm"));
611 msgnum = lbstr("msgnum");
614 load_ical_object(msgnum, 0,
615 ICAL_VTODO_COMPONENT,
616 display_edit_individual_task,
622 display_edit_individual_task(NULL, 0L, "", 0, NULL);
627 * save an edited task
629 void save_task(void) {
631 msgnum = lbstr("msgnum");
633 load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
636 save_individual_task(NULL, 0L, "", 0, NULL);
642 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat,
648 strcpy(cmd, "MSGS ALL");
649 Stat->maxmsgs = 32767;
654 int tasks_Cleanup(void **ViewSpecific)
657 /* Tasks doesn't need the calview struct...
658 free (*ViewSpecific);
659 *ViewSpecific = NULL;
668 RegisterReadLoopHandlerset(
670 tasks_GetParamsGetServerCall,
673 tasks_LoadMsgFromServer,
674 tasks_RenderView_or_Tail,
676 WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);