From 13611efa4f0fa6904be010936c153e61945389ee Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 21 Sep 2002 04:38:05 +0000 Subject: [PATCH] * Added utility functions for displaying vcalendar timestamps in web forms and translating form data back to timestamps. * Completed the "edit task" and "add new task" screens. --- webcit/ChangeLog | 6 +- webcit/Makefile.in | 4 +- webcit/calendar.c | 145 ++++++++++++++++++++++++++++++++++------ webcit/calendar_tools.c | 132 ++++++++++++++++++++++++++++++++++++ webcit/messages.c | 5 +- webcit/webcit.h | 6 ++ 6 files changed, 272 insertions(+), 26 deletions(-) create mode 100644 webcit/calendar_tools.c diff --git a/webcit/ChangeLog b/webcit/ChangeLog index a31ffbb88..a79e4bdab 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,9 @@ $Log$ +Revision 400.20 2002/09/21 04:38:05 ajc +* Added utility functions for displaying vcalendar timestamps in web forms + and translating form data back to timestamps. +* Completed the "edit task" and "add new task" screens. + Revision 400.19 2002/09/20 20:28:08 ajc * Smooth transition between "list tasks" & "edit task" screens @@ -1004,4 +1009,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/Makefile.in b/webcit/Makefile.in index e2f726a43..c843bbff1 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -28,13 +28,13 @@ webserver: webserver.o context_loop.o tools.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ vcard.o vcard_edit.o preferences.o html2html.o listsub.o \ mime_parser.o graphics.o netconf.o siteconfig.o subst.o \ - calendar.o $(LIBOBJS) + calendar.o calendar_tools.o $(LIBOBJS) $(CC) webserver.o context_loop.o tools.o cookie_conversion.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ locate_host.o siteconfig.o subst.o vcard.o vcard_edit.o floors.o \ mime_parser.o graphics.o netconf.o preferences.o html2html.o \ - summary.o calendar.o \ + summary.o calendar.o calendar_tools.o \ $(LIBOBJS) $(LIBS) -o webserver .c.o: 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 */ diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c new file mode 100644 index 000000000..77f478ee4 --- /dev/null +++ b/webcit/calendar_tools.c @@ -0,0 +1,132 @@ +/* + * $Id$ + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" +#include "webserver.h" + +#ifdef HAVE_ICAL_H + +char *months[] = { + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December" +}; + +void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) { + int i; + time_t now; + struct tm *tm; + int this_year; + const int span = 10; + + now = time(NULL); + tm = localtime(&now); + this_year = tm->tm_year + 1900; + + if (t == NULL) return; + + wprintf("Month: "); + wprintf("\n"); + + wprintf("Day: "); + wprintf("\n"); + + wprintf("Year: "); + wprintf("\n"); + + wprintf("Hour: "); + wprintf("\n"); + + wprintf("Minute: "); + wprintf("\n"); + +} + + +struct icaltimetype icaltime_from_webform(char *prefix) { + struct icaltimetype t; + time_t now; + char vname[SIZ]; + + now = time(NULL); + t = icaltime_from_timet(now, 0); + + sprintf(vname, "%s_month", prefix); t.month = atoi(bstr(vname)); + sprintf(vname, "%s_day", prefix); t.day = atoi(bstr(vname)); + sprintf(vname, "%s_year", prefix); t.year = atoi(bstr(vname)); + sprintf(vname, "%s_hour", prefix); t.hour = atoi(bstr(vname)); + sprintf(vname, "%s_minute", prefix); t.minute = atoi(bstr(vname)); + + t = icaltime_normalize(t); + return(t); +} + + + + +#endif diff --git a/webcit/messages.c b/webcit/messages.c index c98a42aad..f6a88c416 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -837,7 +837,10 @@ void readloop(char *oper) } if (is_tasks) { - wprintf("\n"); + wprintf("\n" + "" + "Add new task\n" + ); } /* Bump these because although we're thinking in zero base, the user diff --git a/webcit/webcit.h b/webcit/webcit.h index 06db86fb1..4f24c5cad 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -4,6 +4,10 @@ #include #endif +#ifdef HAVE_ICAL_H +#include +#endif + #define SIZ 4096 /* generic buffer size */ #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__) @@ -348,4 +352,6 @@ void display_task(long msgnum); #ifdef HAVE_ICAL_H void display_edit_task(void); void save_task(void); +void display_icaltimetype_as_webform(struct icaltimetype *, char *); +struct icaltimetype icaltime_from_webform(char *prefix); #endif -- 2.39.2