]> code.citadel.org Git - citadel.git/blob - webcit/tasks.c
fix counting of UTF8-charwidth
[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         int created_new_vtodo = 0;
185         icalproperty_status todoStatus;
186
187         if (supplied_vtodo != NULL) {
188                 vtodo = supplied_vtodo;
189
190                 /*
191                  * It's safe to convert to UTC here because there are no recurrences to worry about.
192                  */
193                 ical_dezonify(vtodo);
194
195                 /*
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
201                  * new one.
202                  */
203                 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
204                         display_edit_individual_task(
205                                 icalcomponent_get_first_component(
206                                         vtodo, ICAL_VTODO_COMPONENT
207                                         ), 
208                                 msgnum, from, unread, calv
209                                 );
210                         return;
211                 }
212         }
213         else {
214                 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
215                 created_new_vtodo = 1;
216         }
217         
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"));
226         wc_printf("- ");
227         if (p != NULL) {
228                 escputs((char *)icalproperty_get_comment(p));
229         }
230         wc_printf("</div>");
231         
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"));
239         wc_printf("</div>");
240         wc_printf("<table class=\"calendar_background\"><tr><td>");
241         wc_printf("<TABLE STYLE=\"border: none;\">\n");
242
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);
249         if (p != NULL) {
250                 escputs((char *)icalproperty_get_comment(p));
251         }
252         wc_printf("\"></TD></TR>\n");
253
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\" ");
259         if (p == NULL) {
260                 wc_printf("CHECKED=\"CHECKED\"");
261         }
262         wc_printf(">");
263         wc_printf(_("No date"));
264         
265         wc_printf(" ");
266         wc_printf("<span ID=\"dtstart_date\">");
267         wc_printf(_("or"));
268         wc_printf(" ");
269         if (p != NULL) {
270                 IcalTime = icalproperty_get_dtstart(p);
271         }
272         else
273                 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
274         display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
275
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\"");
279         }
280         wc_printf(">");
281         wc_printf(_("Time associated"));
282         wc_printf("</span></TD></TR>\n");
283
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\"");
289         if (p == NULL) {
290                 wc_printf("CHECKED=\"CHECKED\"");
291         }
292         wc_printf(">");
293         wc_printf(_("No date"));
294         wc_printf(" ");
295         wc_printf("<span ID=\"due_date\">\n");
296         wc_printf(_("or"));
297         wc_printf(" ");
298         if (p != NULL) {
299                 IcalTime = icalproperty_get_due(p);
300         }
301         else
302                 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
303         display_icaltimetype_as_webform(&IcalTime, "due", 0);
304
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\"");
308         }
309         wc_printf(">");
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\"");
319         } 
320         wc_printf(" >");
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=\"");
328         if (p != NULL) {
329                 escputs((char *)icalproperty_get_categories(p));
330         }
331         wc_printf("\">");
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"
339                 );
340         p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
341         if (p != NULL) {
342                 escputs((char *)icalproperty_get_comment(p));
343         }
344         wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
345
346         wc_printf("<SPAN STYLE=\"text-align: center;\">"
347                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
348                 "&nbsp;&nbsp;"
349                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
350                 "&nbsp;&nbsp;"
351                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
352                 "</SPAN>\n",
353                 _("Save"),
354                 _("Delete"),
355                 _("Cancel")
356                 );
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 -->");
361         wDumpContent(1);
362
363         if (created_new_vtodo) {
364                 icalcomponent_free(vtodo);
365         }
366 }
367
368 /*
369  * Save an edited task
370  *
371  * supplied_vtodo       the task to save
372  * msgnum               number of the mesage in our db
373  */
374 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
375                           calview *calv)
376 {
377         char buf[SIZ];
378         int delete_existing = 0;
379         icalproperty *prop;
380         icalcomponent *vtodo, *encaps;
381         int created_new_vtodo = 0;
382         int i;
383         int sequence = 0;
384         struct icaltimetype t;
385
386         if (supplied_vtodo != NULL) {
387                 vtodo = supplied_vtodo;
388                 /**
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
394                  * new one.
395                  */
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
401                                 );
402                         return;
403                 }
404         }
405         else {
406                 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
407                 created_new_vtodo = 1;
408         }
409
410         if (havebstr("save_button")) {
411
412                 /** Replace values in the component with ones from the form */
413
414                 while (prop = icalcomponent_get_first_property(vtodo,
415                                                                ICAL_SUMMARY_PROPERTY), prop != NULL) {
416                         icalcomponent_remove_property(vtodo, prop);
417                         icalproperty_free(prop);
418                 }
419                 if (havebstr("summary")) {
420
421                         icalcomponent_add_property(vtodo,
422                                                    icalproperty_new_summary(bstr("summary")));
423                 } else {
424                         icalcomponent_add_property(vtodo,
425                                                    icalproperty_new_summary(_("Untitled Task")));
426                 }
427         
428                 while (prop = icalcomponent_get_first_property(vtodo,
429                                                                ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
430                         icalcomponent_remove_property(vtodo, prop);
431                         icalproperty_free(prop);
432                 }
433                 if (havebstr("description")) {
434                         icalcomponent_add_property(vtodo,
435                                                    icalproperty_new_description(bstr("description")));
436                 }
437         
438                 while (prop = icalcomponent_get_first_property(vtodo,
439                                                                ICAL_DTSTART_PROPERTY), prop != NULL) {
440                         icalcomponent_remove_property(vtodo, prop);
441                         icalproperty_free(prop);
442                 }
443                 if (IsEmptyStr(bstr("nodtstart"))) {
444                         if (yesbstr("dtstart_time")) {
445                                 icaltime_from_webform(&t, "dtstart");
446                         }
447                         else {
448                                 icaltime_from_webform_dateonly(&t, "dtstart");
449                         }
450                         icalcomponent_add_property(vtodo,
451                                                    icalproperty_new_dtstart(t)
452                                 );
453                 }
454                 while(prop = icalcomponent_get_first_property(vtodo,
455                                                               ICAL_STATUS_PROPERTY), prop != NULL) {
456                         icalcomponent_remove_property(vtodo,prop);
457                         icalproperty_free(prop);
458                 }
459                 while(prop = icalcomponent_get_first_property(vtodo,
460                                                               ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
461                         icalcomponent_remove_property(vtodo,prop);
462                         icalproperty_free(prop);
463                 }
464
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)
471                                 )
472                         );
473                 }
474                 else {
475                         icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
476                 }
477                 while (prop = icalcomponent_get_first_property(vtodo,
478                                                                ICAL_CATEGORIES_PROPERTY), prop != NULL) {
479                         icalcomponent_remove_property(vtodo,prop);
480                         icalproperty_free(prop);
481                 }
482                 if (!IsEmptyStr(bstr("category"))) {
483                         prop = icalproperty_new_categories(bstr("category"));
484                         icalcomponent_add_property(vtodo,prop);
485                 }
486                 while (prop = icalcomponent_get_first_property(vtodo,
487                                                                ICAL_DUE_PROPERTY), prop != NULL) {
488                         icalcomponent_remove_property(vtodo, prop);
489                         icalproperty_free(prop);
490                 }
491                 if (IsEmptyStr(bstr("nodue"))) {
492                         if (yesbstr("due_time")) {
493                                 icaltime_from_webform(&t, "due");
494                         }
495                         else {
496                                 icaltime_from_webform_dateonly(&t, "due");
497                         }
498                         icalcomponent_add_property(vtodo,
499                                                    icalproperty_new_due(t)
500                                 );
501                 }
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) {
506                         generate_uuid(buf);
507                         icalcomponent_add_property(vtodo,
508                                                    icalproperty_new_uid(buf)
509                                 );
510                 }
511
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);
521                 }
522                 ++sequence;
523                 lprintf(9, "New sequence is %d.  Adding...\n", sequence);
524                 icalcomponent_add_property(vtodo,
525                                            icalproperty_new_sequence(sequence)
526                         );
527
528                 /*
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
533                  * somewhere else.
534                  */
535                 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
536                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
537
538                 /* Serialize it and save it to the message base */
539                 serv_puts("ENT0 1|||4");
540                 serv_getln(buf, sizeof buf);
541                 if (buf[0] == '4') {
542                         serv_puts("Content-type: text/calendar");
543                         serv_puts("");
544                         serv_puts(icalcomponent_as_ical_string(encaps));
545                         serv_puts("000");
546
547                         /*
548                          * Probably not necessary; the server will see the UID
549                          * of the object and delete the old one anyway, but
550                          * just in case...
551                          */
552                         delete_existing = 1;
553                 }
554                 icalcomponent_free(encaps);
555         }
556
557         /**
558          * If the user clicked 'Delete' then explicitly delete the message.
559          */
560         if (havebstr("delete_button")) {
561                 delete_existing = 1;
562         }
563
564         if ( (delete_existing) && (msgnum > 0L) ) {
565                 serv_printf("DELE %ld", lbstr("msgnum"));
566                 serv_getln(buf, sizeof buf);
567         }
568
569         if (created_new_vtodo) {
570                 icalcomponent_free(vtodo);
571         }
572
573         /* Go back to wherever we came from */
574         if (ibstr("return_to_summary") == 1) {
575                 summary();
576         }
577         else {
578                 readloop(readfwd, eUseDefault);
579         }
580 }
581
582 /*
583  * Display task view
584  */
585 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat, 
586                             void **ViewSpecific, 
587                             message_summary* Msg, 
588                             int is_new, 
589                             int i)
590 {
591         /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
592
593         load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0);
594         return 0;
595 }
596
597 /*
598  * Display the editor component for a task
599  */
600 void display_edit_task(void) {
601         long msgnum = 0L;
602                         
603         /* Force change the room if we have to */
604         if (havebstr("taskrm")) {
605                 gotoroom(sbstr("taskrm"));
606         }
607
608         msgnum = lbstr("msgnum");
609         if (msgnum > 0L) {
610                 /* existing task */
611                 load_ical_object(msgnum, 0,
612                                  ICAL_VTODO_COMPONENT,
613                                  display_edit_individual_task,
614                                  NULL, 0
615                 );
616         }
617         else {
618                 /* new task */
619                 display_edit_individual_task(NULL, 0L, "", 0, NULL);
620         }
621 }
622
623 /*
624  * save an edited task
625  */
626 void save_task(void) {
627         long msgnum = 0L;
628         msgnum = lbstr("msgnum");
629         if (msgnum > 0L) {
630                 load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
631         }
632         else {
633                 save_individual_task(NULL, 0L, "", 0, NULL);
634         }
635 }
636
637
638
639 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat, 
640                                  void **ViewSpecific, 
641                                  long oper, 
642                                  char *cmd, 
643                                  long len)
644 {
645         strcpy(cmd, "MSGS ALL");
646         Stat->maxmsgs = 32767;
647         return 200;
648 }
649
650
651 int tasks_Cleanup(void **ViewSpecific)
652 {
653         wDumpContent(1);
654 /* Tasks doesn't need the calview struct... 
655         free (*ViewSpecific);
656         *ViewSpecific = NULL;
657         */
658         return 0;
659 }
660
661 void 
662 InitModule_TASKS
663 (void)
664 {
665         RegisterReadLoopHandlerset(
666                 VIEW_TASKS,
667                 tasks_GetParamsGetServerCall,
668                 NULL,
669                 NULL,
670                 tasks_LoadMsgFromServer,
671                 tasks_RenderView_or_Tail,
672                 tasks_Cleanup);
673         WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);
674 }