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("<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n<th>");
93 wc_printf(_("Completed?"));
94 wc_printf("</th><th>");
95 wc_printf(_("Name of task"));
96 wc_printf("</th><th>");
97 wc_printf(_("Date due"));
98 wc_printf("</th><th>");
99 wc_printf(_("Category"));
100 wc_printf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
103 nItems = GetCount(WC->disp_cal_items);
105 /* Sort them if necessary
107 SortByPayload(WC->disp_cal_items, task_due_cmp);
109 * this shouldn't be neccessary, since we sort by the start time.
112 /* And then again, by completed */
114 SortByPayload(WC->disp_cal_items,
118 Pos = GetNewHashPos(WCC->disp_cal_items, 0);
119 while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
120 icalproperty_status todoStatus;
123 Cal = (disp_cal*)vCal;
124 wc_printf("<tr><td>");
125 todoStatus = icalcomponent_get_status(Cal->cal);
126 wc_printf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
127 if (todoStatus == ICAL_STATUS_COMPLETED) {
128 wc_printf("checked=\"checked\" ");
130 wc_printf("disabled=\"disabled\">\n</td><td>");
131 p = icalcomponent_get_first_property(Cal->cal,
132 ICAL_SUMMARY_PROPERTY);
133 wc_printf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
134 urlescputs(ChrPtr(WC->CurRoom.name));
136 /* wc_printf("<img align=middle "
137 "src=\"static/taskmanag_16x.gif\" border=0> "); */
139 escputs((char *)icalproperty_get_comment(p));
142 wc_printf("</td>\n");
144 due = get_task_due_date(Cal->cal, &is_date);
145 wc_printf("<td><span");
147 webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
148 wc_printf(">%s",buf);
153 wc_printf("</span></td>");
155 p = icalcomponent_get_first_property(Cal->cal,
156 ICAL_CATEGORIES_PROPERTY);
158 escputs((char *)icalproperty_get_categories(p));
164 wc_printf("</tbody></table>\n");
167 DeleteHash(&WC->disp_cal_items);
174 * Display a task by itself (for editing)
176 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from,
177 int unread, calview *calv)
179 icalcomponent *vtodo;
181 struct icaltimetype IcalTime;
183 int created_new_vtodo = 0;
184 icalproperty_status todoStatus;
188 if (supplied_vtodo != NULL) {
189 vtodo = supplied_vtodo;
192 * It's safe to convert to UTC here because there are no recurrences to worry about.
194 ical_dezonify(vtodo);
197 * If we're looking at a fully encapsulated VCALENDAR
198 * rather than a VTODO component, attempt to use the first
199 * relevant VTODO subcomponent. If there is none, the
200 * NULL returned by icalcomponent_get_first_component() will
201 * tell the next iteration of this function to create a
204 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
205 display_edit_individual_task(
206 icalcomponent_get_first_component(
207 vtodo, ICAL_VTODO_COMPONENT
209 msgnum, from, unread, calv
215 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
216 created_new_vtodo = 1;
219 /* TODO: Can we take all this and move it into a template? */
220 output_headers(1, 1, 1, 0, 0, 0);
221 wc_printf("<!-- start task edit form -->");
222 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
223 /* Get summary early for title */
224 wc_printf("<div class=\"box\">\n");
225 wc_printf("<div class=\"boxlabel\">");
226 wc_printf(_("Edit task"));
229 escputs((char *)icalproperty_get_comment(p));
233 wc_printf("<div class=\"boxcontent\">\n");
234 wc_printf("<FORM METHOD=\"POST\" action=\"save_task\">\n");
235 wc_printf("<div style=\"display: none;\">\n ");
236 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
237 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n", msgnum);
238 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"return_to_summary\" VALUE=\"%d\">\n",
239 ibstr("return_to_summary"));
241 wc_printf("<table class=\"calendar_background\"><tr><td>");
242 wc_printf("<TABLE STYLE=\"border: none;\">\n");
244 wc_printf("<TR><TD>");
245 wc_printf(_("Summary:"));
246 wc_printf("</TD><TD>"
247 "<INPUT TYPE=\"text\" NAME=\"summary\" "
248 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
249 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
251 escputs((char *)icalproperty_get_comment(p));
253 wc_printf("\"></TD></TR>\n");
255 wc_printf("<TR><TD>");
256 wc_printf(_("Start date:"));
257 wc_printf("</TD><TD>");
258 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
259 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodtstart\" ID=\"nodtstart\" VALUE=\"NODTSTART\" ");
261 wc_printf("CHECKED=\"CHECKED\"");
264 wc_printf(_("No date"));
267 wc_printf("<span ID=\"dtstart_date\">");
271 IcalTime = icalproperty_get_dtstart(p);
274 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
275 display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
277 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"dtstart_time_assoc\" ID=\"dtstart_time_assoc\" VALUE=\"yes\"");
278 if (!IcalTime.is_date) {
279 wc_printf("CHECKED=\"CHECKED\"");
282 wc_printf(_("Time associated"));
283 wc_printf("</span></TD></TR>\n");
285 wc_printf("<TR><TD>");
286 wc_printf(_("Due date:"));
287 wc_printf("</TD><TD>");
288 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
289 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodue\" ID=\"nodue\" VALUE=\"NODUE\"");
291 wc_printf("CHECKED=\"CHECKED\"");
294 wc_printf(_("No date"));
296 wc_printf("<span ID=\"due_date\">\n");
300 IcalTime = icalproperty_get_due(p);
303 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
304 display_icaltimetype_as_webform(&IcalTime, "due", 0);
306 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"due_time_assoc\" ID=\"due_time_assoc\" VALUE=\"yes\"");
307 if (!IcalTime.is_date) {
308 wc_printf("CHECKED=\"CHECKED\"");
311 wc_printf(_("Time associated"));
312 wc_printf("</span></TD></TR>\n");
313 todoStatus = icalcomponent_get_status(vtodo);
314 wc_printf("<TR><TD>\n");
315 wc_printf(_("Completed:"));
316 wc_printf("</TD><TD>");
317 wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"status\" VALUE=\"COMPLETED\"");
318 if (todoStatus == ICAL_STATUS_COMPLETED) {
319 wc_printf(" CHECKED=\"CHECKED\"");
322 wc_printf("</TD></TR>");
323 /* start category field */
324 p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY);
325 wc_printf("<TR><TD>");
326 wc_printf(_("Category:"));
327 wc_printf("</TD><TD>");
328 wc_printf("<INPUT TYPE=\"text\" NAME=\"category\" MAXLENGTH=\"32\" SIZE=\"32\" VALUE=\"");
330 escputs((char *)icalproperty_get_categories(p));
333 wc_printf("</TD></TR>\n ");
334 /* end category field */
335 wc_printf("<TR><TD>");
336 wc_printf(_("Description:"));
337 wc_printf("</TD><TD>");
338 wc_printf("<TEXTAREA NAME=\"description\" "
339 "ROWS=\"10\" COLS=\"80\">\n"
341 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
343 escputs((char *)icalproperty_get_comment(p));
345 wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
347 wc_printf("<SPAN STYLE=\"text-align: center;\">"
348 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
350 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
352 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
358 wc_printf("</td></tr></table>");
359 wc_printf("</FORM>\n");
360 wc_printf("</div></div></div>\n");
361 wc_printf("<!-- end task edit form -->");
364 if (created_new_vtodo) {
365 icalcomponent_free(vtodo);
370 * Save an edited task
372 * supplied_vtodo the task to save
373 * msgnum number of the mesage in our db
375 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
379 int delete_existing = 0;
381 icalcomponent *vtodo, *encaps;
382 int created_new_vtodo = 0;
385 struct icaltimetype t;
387 if (supplied_vtodo != NULL) {
388 vtodo = supplied_vtodo;
390 * If we're looking at a fully encapsulated VCALENDAR
391 * rather than a VTODO component, attempt to use the first
392 * relevant VTODO subcomponent. If there is none, the
393 * NULL returned by icalcomponent_get_first_component() will
394 * tell the next iteration of this function to create a
397 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
398 save_individual_task(
399 icalcomponent_get_first_component(
400 vtodo, ICAL_VTODO_COMPONENT),
401 msgnum, from, unread, calv
407 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
408 created_new_vtodo = 1;
411 if (havebstr("save_button")) {
413 /** Replace values in the component with ones from the form */
415 while (prop = icalcomponent_get_first_property(vtodo,
416 ICAL_SUMMARY_PROPERTY), prop != NULL) {
417 icalcomponent_remove_property(vtodo, prop);
418 icalproperty_free(prop);
420 if (havebstr("summary")) {
422 icalcomponent_add_property(vtodo,
423 icalproperty_new_summary(bstr("summary")));
425 icalcomponent_add_property(vtodo,
426 icalproperty_new_summary(_("Untitled Task")));
429 while (prop = icalcomponent_get_first_property(vtodo,
430 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
431 icalcomponent_remove_property(vtodo, prop);
432 icalproperty_free(prop);
434 if (havebstr("description")) {
435 icalcomponent_add_property(vtodo,
436 icalproperty_new_description(bstr("description")));
439 while (prop = icalcomponent_get_first_property(vtodo,
440 ICAL_DTSTART_PROPERTY), prop != NULL) {
441 icalcomponent_remove_property(vtodo, prop);
442 icalproperty_free(prop);
444 if (IsEmptyStr(bstr("nodtstart"))) {
445 if (yesbstr("dtstart_time")) {
446 icaltime_from_webform(&t, "dtstart");
449 icaltime_from_webform_dateonly(&t, "dtstart");
451 icalcomponent_add_property(vtodo,
452 icalproperty_new_dtstart(t)
455 while(prop = icalcomponent_get_first_property(vtodo,
456 ICAL_STATUS_PROPERTY), prop != NULL) {
457 icalcomponent_remove_property(vtodo,prop);
458 icalproperty_free(prop);
460 while(prop = icalcomponent_get_first_property(vtodo,
461 ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
462 icalcomponent_remove_property(vtodo,prop);
463 icalproperty_free(prop);
466 if (havebstr("status")) {
467 icalproperty_status taskStatus = icalproperty_string_to_status(bstr("status"));
468 icalcomponent_set_status(vtodo, taskStatus);
469 icalcomponent_add_property(vtodo,
470 icalproperty_new_percentcomplete(
471 (strcasecmp(bstr("status"), "completed") ? 0 : 100)
476 icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
478 while (prop = icalcomponent_get_first_property(vtodo,
479 ICAL_CATEGORIES_PROPERTY), prop != NULL) {
480 icalcomponent_remove_property(vtodo,prop);
481 icalproperty_free(prop);
483 if (!IsEmptyStr(bstr("category"))) {
484 prop = icalproperty_new_categories(bstr("category"));
485 icalcomponent_add_property(vtodo,prop);
487 while (prop = icalcomponent_get_first_property(vtodo,
488 ICAL_DUE_PROPERTY), prop != NULL) {
489 icalcomponent_remove_property(vtodo, prop);
490 icalproperty_free(prop);
492 if (IsEmptyStr(bstr("nodue"))) {
493 if (yesbstr("due_time")) {
494 icaltime_from_webform(&t, "due");
497 icaltime_from_webform_dateonly(&t, "due");
499 icalcomponent_add_property(vtodo,
500 icalproperty_new_due(t)
503 /** Give this task a UID if it doesn't have one. */
504 lprintf(9, "Give this task a UID if it doesn't have one.\n");
505 if (icalcomponent_get_first_property(vtodo,
506 ICAL_UID_PROPERTY) == NULL) {
508 icalcomponent_add_property(vtodo,
509 icalproperty_new_uid(buf)
513 /* Increment the sequence ID */
514 lprintf(9, "Increment the sequence ID\n");
515 while (prop = icalcomponent_get_first_property(vtodo,
516 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
517 i = icalproperty_get_sequence(prop);
518 lprintf(9, "Sequence was %d\n", i);
519 if (i > sequence) sequence = i;
520 icalcomponent_remove_property(vtodo, prop);
521 icalproperty_free(prop);
524 lprintf(9, "New sequence is %d. Adding...\n", sequence);
525 icalcomponent_add_property(vtodo,
526 icalproperty_new_sequence(sequence)
530 * Encapsulate event into full VCALENDAR component. Clone it first,
531 * for two reasons: one, it's easier to just free the whole thing
532 * when we're done instead of unbundling, but more importantly, we
533 * can't encapsulate something that may already be encapsulated
536 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
537 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
539 /* Serialize it and save it to the message base */
540 serv_puts("ENT0 1|||4");
541 serv_getln(buf, sizeof buf);
543 serv_puts("Content-type: text/calendar");
545 serv_puts(icalcomponent_as_ical_string(encaps));
549 * Probably not necessary; the server will see the UID
550 * of the object and delete the old one anyway, but
555 icalcomponent_free(encaps);
559 * If the user clicked 'Delete' then explicitly delete the message.
561 if (havebstr("delete_button")) {
565 if ( (delete_existing) && (msgnum > 0L) ) {
566 serv_printf("DELE %ld", lbstr("msgnum"));
567 serv_getln(buf, sizeof buf);
570 if (created_new_vtodo) {
571 icalcomponent_free(vtodo);
574 /* Go back to wherever we came from */
575 if (ibstr("return_to_summary") == 1) {
579 readloop(readfwd, eUseDefault);
586 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat,
588 message_summary* Msg,
592 /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
594 load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0);
599 * Display the editor component for a task
601 void display_edit_task(void) {
604 /* Force change the room if we have to */
605 if (havebstr("taskrm")) {
606 gotoroom(sbstr("taskrm"));
609 msgnum = lbstr("msgnum");
612 load_ical_object(msgnum, 0,
613 ICAL_VTODO_COMPONENT,
614 display_edit_individual_task,
620 display_edit_individual_task(NULL, 0L, "", 0, NULL);
625 * save an edited task
627 void save_task(void) {
629 msgnum = lbstr("msgnum");
631 load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
634 save_individual_task(NULL, 0L, "", 0, NULL);
640 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat,
646 strcpy(cmd, "MSGS ALL");
647 Stat->maxmsgs = 32767;
652 int tasks_Cleanup(void **ViewSpecific)
655 /* Tasks doesn't need the calview struct...
656 free (*ViewSpecific);
657 *ViewSpecific = NULL;
666 RegisterReadLoopHandlerset(
668 tasks_GetParamsGetServerCall,
671 tasks_LoadMsgFromServer,
672 tasks_RenderView_or_Tail,
674 WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);