42ae949ba5a4411f5b295885aaca9acf6134c471
[citadel.git] / webcit / tasks.c
1 #include "webcit.h"
2 #include "calendar.h"
3 #include "webserver.h"
4
5 /*
6  * qsort filter to move completed tasks to bottom of task list
7  */
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); */
11
12         icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
13         /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
14         
15         if (t1 == ICAL_STATUS_COMPLETED) 
16                 return 1;
17         return 0;
18 }
19
20
21 /*
22  * Helper function for do_tasks_view().  Returns the due date/time of a vtodo.
23  */
24 time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
25         icalproperty *p;
26
27         if (vtodo == NULL) {
28                 return(0L);
29         }
30
31         /*
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.
35          */
36         if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
37                 return get_task_due_date(
38                         icalcomponent_get_first_component(
39                                 vtodo, ICAL_VTODO_COMPONENT
40                                 ), is_date
41                         );
42         }
43
44         p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
45         if (p != NULL) {
46                 struct icaltimetype t = icalproperty_get_due(p);
47
48                 if (is_date)
49                         *is_date = t.is_date;
50                 return(icaltime_as_timet(t));
51         }
52         else {
53                 return(0L);
54         }
55 }
56
57 /*
58  * Compare the due dates of two tasks (this is for sorting)
59  */
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);
63
64         time_t t1;
65         time_t t2;
66
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);
71         return(0);
72 }
73
74 /*
75  * do the whole task view stuff
76  */
77 int tasks_RenderView_or_Tail(SharedMessageStatus *Stat, 
78                               void **ViewSpecific, 
79                               long oper)
80 {
81         long hklen;
82         const char *HashKey;
83         void *vCal;
84         disp_cal *Cal;
85         HashPos *Pos;
86         int nItems;
87         time_t due;
88         char buf[SIZ];
89         icalproperty *p;
90         wcsession *WCC = WC;
91
92         wc_printf("<div class=\"fix_scrollbar_bug\">"
93                 "<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n"
94                 "<th>");
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",
103                 _("Show All"));
104
105         nItems = GetCount(WC->disp_cal_items);
106
107         /* Sort them if necessary
108         if (nItems > 1) {
109                 SortByPayload(WC->disp_cal_items, task_due_cmp);
110         }
111         * this shouldn't be neccessary, since we sort by the start time.
112         */
113
114         /* And then again, by completed */
115         if (nItems > 1) {
116                 SortByPayload(WC->disp_cal_items, 
117                               task_completed_cmp);
118         }
119
120         Pos = GetNewHashPos(WCC->disp_cal_items, 0);
121         while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
122                 icalproperty_status todoStatus;
123                 int is_date;
124
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\" ");
131                 }
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));
137                 wc_printf("\">");
138                 /* wc_printf("<img align=middle "
139                 "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;"); */
140                 if (p != NULL) {
141                         escputs((char *)icalproperty_get_comment(p));
142                 }
143                 wc_printf("</a>\n");
144                 wc_printf("</td>\n");
145
146                 due = get_task_due_date(Cal->cal, &is_date);
147                 wc_printf("<td><span");
148                 if (due > 0) {
149                         webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
150                         wc_printf(">%s",buf);
151                 }
152                 else {
153                         wc_printf(">");
154                 }
155                 wc_printf("</span></td>");
156                 wc_printf("<td>");
157                 p = icalcomponent_get_first_property(Cal->cal,
158                         ICAL_CATEGORIES_PROPERTY);
159                 if (p != NULL) {
160                         escputs((char *)icalproperty_get_categories(p));
161                 }
162                 wc_printf("</td>");
163                 wc_printf("</tr>");
164         }
165
166         wc_printf("</tbody></table></div>\n");
167
168         /* Free the list */
169         DeleteHash(&WC->disp_cal_items);
170         DeleteHashPos(&Pos);
171         return 0;
172 }
173
174
175 /*
176  * Display a task by itself (for editing)
177  */
178 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from,
179                         int unread, calview *calv)
180 {
181         icalcomponent *vtodo;
182         icalproperty *p;
183         struct icaltimetype IcalTime;
184         time_t now;
185         int created_new_vtodo = 0;
186         icalproperty_status todoStatus;
187
188         now = time(NULL);
189
190         if (supplied_vtodo != NULL) {
191                 vtodo = supplied_vtodo;
192
193                 /*
194                  * It's safe to convert to UTC here because there are no recurrences to worry about.
195                  */
196                 ical_dezonify(vtodo);
197
198                 /*
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
204                  * new one.
205                  */
206                 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
207                         display_edit_individual_task(
208                                 icalcomponent_get_first_component(
209                                         vtodo, ICAL_VTODO_COMPONENT
210                                         ), 
211                                 msgnum, from, unread, calv
212                                 );
213                         return;
214                 }
215         }
216         else {
217                 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
218                 created_new_vtodo = 1;
219         }
220         
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"));
229         wc_printf("- ");
230         if (p != NULL) {
231                 escputs((char *)icalproperty_get_comment(p));
232         }
233         wc_printf("</div>");
234         
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"));
242         wc_printf("</div>");
243         wc_printf("<table class=\"calendar_background\"><tr><td>");
244         wc_printf("<TABLE STYLE=\"border: none;\">\n");
245
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);
252         if (p != NULL) {
253                 escputs((char *)icalproperty_get_comment(p));
254         }
255         wc_printf("\"></TD></TR>\n");
256
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\" ");
262         if (p == NULL) {
263                 wc_printf("CHECKED=\"CHECKED\"");
264         }
265         wc_printf(">");
266         wc_printf(_("No date"));
267         
268         wc_printf(" ");
269         wc_printf("<span ID=\"dtstart_date\">");
270         wc_printf(_("or"));
271         wc_printf(" ");
272         if (p != NULL) {
273                 IcalTime = icalproperty_get_dtstart(p);
274         }
275         else
276                 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
277         display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
278
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\"");
282         }
283         wc_printf(">");
284         wc_printf(_("Time associated"));
285         wc_printf("</span></TD></TR>\n");
286
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\"");
292         if (p == NULL) {
293                 wc_printf("CHECKED=\"CHECKED\"");
294         }
295         wc_printf(">");
296         wc_printf(_("No date"));
297         wc_printf(" ");
298         wc_printf("<span ID=\"due_date\">\n");
299         wc_printf(_("or"));
300         wc_printf(" ");
301         if (p != NULL) {
302                 IcalTime = icalproperty_get_due(p);
303         }
304         else
305                 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
306         display_icaltimetype_as_webform(&IcalTime, "due", 0);
307
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\"");
311         }
312         wc_printf(">");
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\"");
322         } 
323         wc_printf(" >");
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=\"");
331         if (p != NULL) {
332                 escputs((char *)icalproperty_get_categories(p));
333         }
334         wc_printf("\">");
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"
342                 );
343         p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
344         if (p != NULL) {
345                 escputs((char *)icalproperty_get_comment(p));
346         }
347         wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
348
349         wc_printf("<SPAN STYLE=\"text-align: center;\">"
350                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
351                 "&nbsp;&nbsp;"
352                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
353                 "&nbsp;&nbsp;"
354                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
355                 "</SPAN>\n",
356                 _("Save"),
357                 _("Delete"),
358                 _("Cancel")
359                 );
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 -->");
364         wDumpContent(1);
365
366         if (created_new_vtodo) {
367                 icalcomponent_free(vtodo);
368         }
369 }
370
371 /*
372  * Save an edited task
373  *
374  * supplied_vtodo       the task to save
375  * msgnum               number of the mesage in our db
376  */
377 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
378                           calview *calv)
379 {
380         char buf[SIZ];
381         int delete_existing = 0;
382         icalproperty *prop;
383         icalcomponent *vtodo, *encaps;
384         int created_new_vtodo = 0;
385         int i;
386         int sequence = 0;
387         struct icaltimetype t;
388
389         if (supplied_vtodo != NULL) {
390                 vtodo = supplied_vtodo;
391                 /**
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
397                  * new one.
398                  */
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
404                                 );
405                         return;
406                 }
407         }
408         else {
409                 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
410                 created_new_vtodo = 1;
411         }
412
413         if (havebstr("save_button")) {
414
415                 /** Replace values in the component with ones from the form */
416
417                 while (prop = icalcomponent_get_first_property(vtodo,
418                                                                ICAL_SUMMARY_PROPERTY), prop != NULL) {
419                         icalcomponent_remove_property(vtodo, prop);
420                         icalproperty_free(prop);
421                 }
422                 if (havebstr("summary")) {
423
424                         icalcomponent_add_property(vtodo,
425                                                    icalproperty_new_summary(bstr("summary")));
426                 } else {
427                         icalcomponent_add_property(vtodo,
428                                                    icalproperty_new_summary(_("Untitled Task")));
429                 }
430         
431                 while (prop = icalcomponent_get_first_property(vtodo,
432                                                                ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
433                         icalcomponent_remove_property(vtodo, prop);
434                         icalproperty_free(prop);
435                 }
436                 if (havebstr("description")) {
437                         icalcomponent_add_property(vtodo,
438                                                    icalproperty_new_description(bstr("description")));
439                 }
440         
441                 while (prop = icalcomponent_get_first_property(vtodo,
442                                                                ICAL_DTSTART_PROPERTY), prop != NULL) {
443                         icalcomponent_remove_property(vtodo, prop);
444                         icalproperty_free(prop);
445                 }
446                 if (IsEmptyStr(bstr("nodtstart"))) {
447                         if (yesbstr("dtstart_time")) {
448                                 icaltime_from_webform(&t, "dtstart");
449                         }
450                         else {
451                                 icaltime_from_webform_dateonly(&t, "dtstart");
452                         }
453                         icalcomponent_add_property(vtodo,
454                                                    icalproperty_new_dtstart(t)
455                                 );
456                 }
457                 while(prop = icalcomponent_get_first_property(vtodo,
458                                                               ICAL_STATUS_PROPERTY), prop != NULL) {
459                         icalcomponent_remove_property(vtodo,prop);
460                         icalproperty_free(prop);
461                 }
462                 while(prop = icalcomponent_get_first_property(vtodo,
463                                                               ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
464                         icalcomponent_remove_property(vtodo,prop);
465                         icalproperty_free(prop);
466                 }
467
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)
474                                 )
475                         );
476                 }
477                 else {
478                         icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
479                 }
480                 while (prop = icalcomponent_get_first_property(vtodo,
481                                                                ICAL_CATEGORIES_PROPERTY), prop != NULL) {
482                         icalcomponent_remove_property(vtodo,prop);
483                         icalproperty_free(prop);
484                 }
485                 if (!IsEmptyStr(bstr("category"))) {
486                         prop = icalproperty_new_categories(bstr("category"));
487                         icalcomponent_add_property(vtodo,prop);
488                 }
489                 while (prop = icalcomponent_get_first_property(vtodo,
490                                                                ICAL_DUE_PROPERTY), prop != NULL) {
491                         icalcomponent_remove_property(vtodo, prop);
492                         icalproperty_free(prop);
493                 }
494                 if (IsEmptyStr(bstr("nodue"))) {
495                         if (yesbstr("due_time")) {
496                                 icaltime_from_webform(&t, "due");
497                         }
498                         else {
499                                 icaltime_from_webform_dateonly(&t, "due");
500                         }
501                         icalcomponent_add_property(vtodo,
502                                                    icalproperty_new_due(t)
503                                 );
504                 }
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) {
509                         generate_uuid(buf);
510                         icalcomponent_add_property(vtodo,
511                                                    icalproperty_new_uid(buf)
512                                 );
513                 }
514
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);
524                 }
525                 ++sequence;
526                 lprintf(9, "New sequence is %d.  Adding...\n", sequence);
527                 icalcomponent_add_property(vtodo,
528                                            icalproperty_new_sequence(sequence)
529                         );
530
531                 /*
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
536                  * somewhere else.
537                  */
538                 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
539                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
540
541                 /* Serialize it and save it to the message base */
542                 serv_puts("ENT0 1|||4");
543                 serv_getln(buf, sizeof buf);
544                 if (buf[0] == '4') {
545                         serv_puts("Content-type: text/calendar");
546                         serv_puts("");
547                         serv_puts(icalcomponent_as_ical_string(encaps));
548                         serv_puts("000");
549
550                         /*
551                          * Probably not necessary; the server will see the UID
552                          * of the object and delete the old one anyway, but
553                          * just in case...
554                          */
555                         delete_existing = 1;
556                 }
557                 icalcomponent_free(encaps);
558         }
559
560         /**
561          * If the user clicked 'Delete' then explicitly delete the message.
562          */
563         if (havebstr("delete_button")) {
564                 delete_existing = 1;
565         }
566
567         if ( (delete_existing) && (msgnum > 0L) ) {
568                 serv_printf("DELE %ld", lbstr("msgnum"));
569                 serv_getln(buf, sizeof buf);
570         }
571
572         if (created_new_vtodo) {
573                 icalcomponent_free(vtodo);
574         }
575
576         /* Go back to wherever we came from */
577         if (ibstr("return_to_summary") == 1) {
578                 summary();
579         }
580         else {
581                 readloop(readfwd, eUseDefault);
582         }
583 }
584
585 /*
586  * Display task view
587  */
588 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat, 
589                             void **ViewSpecific, 
590                             message_summary* Msg, 
591                             int is_new, 
592                             int i)
593 {
594         /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
595
596         load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0);
597         return 0;
598 }
599
600 /*
601  * Display the editor component for a task
602  */
603 void display_edit_task(void) {
604         long msgnum = 0L;
605                         
606         /* Force change the room if we have to */
607         if (havebstr("taskrm")) {
608                 gotoroom(sbstr("taskrm"));
609         }
610
611         msgnum = lbstr("msgnum");
612         if (msgnum > 0L) {
613                 /* existing task */
614                 load_ical_object(msgnum, 0,
615                                  ICAL_VTODO_COMPONENT,
616                                  display_edit_individual_task,
617                                  NULL, 0
618                 );
619         }
620         else {
621                 /* new task */
622                 display_edit_individual_task(NULL, 0L, "", 0, NULL);
623         }
624 }
625
626 /*
627  * save an edited task
628  */
629 void save_task(void) {
630         long msgnum = 0L;
631         msgnum = lbstr("msgnum");
632         if (msgnum > 0L) {
633                 load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
634         }
635         else {
636                 save_individual_task(NULL, 0L, "", 0, NULL);
637         }
638 }
639
640
641
642 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat, 
643                                  void **ViewSpecific, 
644                                  long oper, 
645                                  char *cmd, 
646                                  long len)
647 {
648         strcpy(cmd, "MSGS ALL");
649         Stat->maxmsgs = 32767;
650         return 200;
651 }
652
653
654 int tasks_Cleanup(void **ViewSpecific)
655 {
656         wDumpContent(1);
657 /* Tasks doesn't need the calview struct... 
658         free (*ViewSpecific);
659         *ViewSpecific = NULL;
660         */
661         return 0;
662 }
663
664 void 
665 InitModule_TASKS
666 (void)
667 {
668         RegisterReadLoopHandlerset(
669                 VIEW_TASKS,
670                 tasks_GetParamsGetServerCall,
671                 NULL,
672                 NULL,
673                 tasks_LoadMsgFromServer,
674                 tasks_RenderView_or_Tail,
675                 tasks_Cleanup);
676         WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);
677 }