X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fcalendar.c;h=f5ff9cbb76d7f328304b31dcbaeba3256efc6a6a;hb=13611efa4f0fa6904be010936c153e61945389ee;hp=9bd6c062bf54a02cc6be1500747e552dacd3e5cf;hpb=4388286a3d12a10f9c1bd63cc63ae034c181c07f;p=citadel.git diff --git a/webcit/calendar.c b/webcit/calendar.c index 9bd6c062b..f5ff9cbb7 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -23,14 +23,10 @@ #include #include #include +#include #include "webcit.h" #include "webserver.h" -#ifdef HAVE_ICAL_H -#include -#endif - - #ifndef HAVE_ICAL_H /* @@ -247,17 +243,32 @@ void display_individual_task(icalcomponent *vtodo, long msgnum) { p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY); wprintf("
  • ", msgnum); - if (p != NULL) escputs((char *)icalproperty_get_comment(p)); + if (p != NULL) { + escputs((char *)icalproperty_get_comment(p)); + } wprintf("\n"); - icalproperty_free(p); } /* * Display a task by itself (for editing) */ -void display_edit_individual_task(icalcomponent *vtodo, long msgnum) { +void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) { + icalcomponent *vtodo; icalproperty *p; + struct icaltimetype t; + time_t now; + int created_new_vtodo = 0; + + now = time(NULL); + + if (supplied_vtodo != NULL) { + vtodo = supplied_vtodo; + } + else { + vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); + created_new_vtodo = 1; + } output_headers(3); wprintf("
    " @@ -274,20 +285,40 @@ void display_edit_individual_task(icalcomponent *vtodo, long msgnum) { "
    \n"); - wprintf("Start date: FIXME
    \n"); + wprintf("Start date: "); + p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY); + if (p != NULL) { + t = icalproperty_get_dtstart(p); + } + else { + t = icaltime_from_timet(now, 0); + } + display_icaltimetype_as_webform(&t, "dtstart"); + wprintf("
    \n"); - wprintf("Due date: FIXME
    \n"); + wprintf("Due date: "); + p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY); + if (p != NULL) { + t = icalproperty_get_due(p); + } + else { + t = icaltime_from_timet(now, 0); + } + display_icaltimetype_as_webform(&t, "due"); + wprintf("
    \n"); - wprintf("

    \n"); wprintf("" @@ -301,20 +332,68 @@ void display_edit_individual_task(icalcomponent *vtodo, long msgnum) { wprintf("\n"); wDumpContent(1); + + if (created_new_vtodo) { + icalcomponent_free(vtodo); + } } /* * Save an edited task */ -void save_individual_task(icalcomponent *vtodo, long msgnum) { +void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) { char buf[SIZ]; int delete_existing = 0; + icalproperty *prop; + icalcomponent *vtodo; + int created_new_vtodo = 0; + + if (supplied_vtodo != NULL) { + vtodo = supplied_vtodo; + } + else { + vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); + created_new_vtodo = 1; + } if (!strcasecmp(bstr("sc"), "Save")) { /* Replace values in the component with ones from the form */ - /* FIXME ... do this */ + while (prop = icalcomponent_get_first_property(vtodo, + ICAL_SUMMARY_PROPERTY), prop != NULL) { + icalcomponent_remove_property(vtodo, prop); + } + icalcomponent_add_property(vtodo, + icalproperty_new_summary(bstr("summary"))); + + while (prop = icalcomponent_get_first_property(vtodo, + ICAL_DESCRIPTION_PROPERTY), prop != NULL) { + icalcomponent_remove_property(vtodo, prop); + } + icalcomponent_add_property(vtodo, + icalproperty_new_description(bstr("description"))); + + while (prop = icalcomponent_get_first_property(vtodo, + ICAL_DTSTART_PROPERTY), prop != NULL) { + icalcomponent_remove_property(vtodo, prop); + } + icalcomponent_add_property(vtodo, + icalproperty_new_dtstart( + icaltime_from_webform("dtstart") + ) + ); + + while (prop = icalcomponent_get_first_property(vtodo, + ICAL_DUE_PROPERTY), prop != NULL) { + icalcomponent_remove_property(vtodo, prop); + } + icalcomponent_add_property(vtodo, + icalproperty_new_due( + icaltime_from_webform("due") + ) + ); + /* Serialize it and save it to the message base */ serv_puts("ENT0 1|||4"); serv_gets(buf); @@ -323,7 +402,7 @@ void save_individual_task(icalcomponent *vtodo, long msgnum) { serv_puts(""); serv_puts(icalcomponent_as_ical_string(vtodo)); serv_puts("000"); - /* delete_existing = 1; */ + delete_existing = 1; } } @@ -334,11 +413,15 @@ void save_individual_task(icalcomponent *vtodo, long msgnum) { delete_existing = 1; } - if (delete_existing) { + if ( (delete_existing) && (msgnum > 0L) ) { serv_printf("DELE %ld", atol(bstr("msgnum"))); serv_gets(buf); } + if (created_new_vtodo) { + icalcomponent_free(vtodo); + } + /* Go back to the task list */ readloop("readfwd"); } @@ -390,9 +473,15 @@ void display_using_handler(long msgnum, relevant_source = load_mimepart(msgnum, relevant_partnum); if (relevant_source != NULL) { - /* Display the task */ cal = icalcomponent_new_from_string(relevant_source); if (cal != NULL) { + + /* Simple components of desired type */ + if (icalcomponent_isa(cal) == which_kind) { + callback(cal, msgnum); + } + + /* Subcomponents of desired type */ for (c = icalcomponent_get_first_component(cal, which_kind); (c != 0); @@ -424,18 +513,30 @@ void display_edit_task(void) { long msgnum = 0L; msgnum = atol(bstr("msgnum")); - display_using_handler(msgnum, "text/calendar", + if (msgnum > 0L) { + /* existing task */ + display_using_handler(msgnum, "text/calendar", ICAL_VTODO_COMPONENT, display_edit_individual_task); + } + else { + /* new task */ + display_edit_individual_task(NULL, 0L); + } } void save_task(void) { long msgnum = 0L; msgnum = atol(bstr("msgnum")); - display_using_handler(msgnum, "text/calendar", + if (msgnum > 0L) { + display_using_handler(msgnum, "text/calendar", ICAL_VTODO_COMPONENT, save_individual_task); + } + else { + save_individual_task(NULL, 0L); + } } #endif /* HAVE_ICAL_H */