* New, buggy versions of event editing screens
authorArt Cancro <ajc@citadel.org>
Fri, 27 Sep 2002 04:37:21 +0000 (04:37 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 27 Sep 2002 04:37:21 +0000 (04:37 +0000)
webcit/ChangeLog
webcit/Makefile.in
webcit/calendar.c
webcit/calendar_view.c
webcit/event.c [new file with mode: 0644]
webcit/webcit.c
webcit/webcit.h

index 575343e36c255d84e2018930a785f342e20c0d77..9ceedd827436ee021b7d6719646b860fba34e14b 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 400.26  2002/09/27 04:37:21  ajc
+* New, buggy versions of event editing screens
+
 Revision 400.25  2002/09/26 22:00:16  ajc
 * Fixed buggy month-selection algorithm (January is month 0 in 'struct tm' but
   month 1 in libical functions)
@@ -1027,4 +1030,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index ec48965e64994d429b6ea57ff7b664b59e1d8320..4fab904943d3e51db94927f8593c9f691b13b065 100644 (file)
@@ -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 calendar_tools.o calendar_view.o $(LIBOBJS)
+       calendar.o calendar_tools.o calendar_view.o event.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 calendar_tools.o calendar_view.o \
+       summary.o calendar.o calendar_tools.o calendar_view.o event.o \
        $(LIBOBJS) $(LIBS) -o webserver
 
 .c.o:
index e2c005e9f376572839939f947798aa4d7c41b47b..70368254a6b436672df8ac2301b18516cfdcd144 100644 (file)
@@ -553,4 +553,34 @@ void save_task(void) {
        }
 }
 
+void display_edit_event(void) {
+       long msgnum = 0L;
+
+       msgnum = atol(bstr("msgnum"));
+       if (msgnum > 0L) {
+               /* existing event */
+               display_using_handler(msgnum, "text/calendar",
+                               ICAL_VEVENT_COMPONENT,
+                               display_edit_individual_event);
+       }
+       else {
+               /* new event */
+               display_edit_individual_event(NULL, 0L);
+       }
+}
+
+void save_event(void) {
+       long msgnum = 0L;
+
+       msgnum = atol(bstr("msgnum"));
+       if (msgnum > 0L) {
+               display_using_handler(msgnum, "text/calendar",
+                               ICAL_VTODO_COMPONENT,
+                               save_individual_event);
+       }
+       else {
+               save_individual_event(NULL, 0L);
+       }
+}
+
 #endif /* HAVE_ICAL_H */
index b23685dc279f3f26b3c181520a64fe84fb43168f..72147225426ea7bfcd2ed3f81f41c7bd607bfb1b 100644 (file)
@@ -66,8 +66,13 @@ void calendar_month_view_display_events(time_t thetime) {
                                                        WC->disp_cal[i],
                                                        ICAL_SUMMARY_PROPERTY);
                                if (p != NULL) {
+                                       wprintf("<FONT SIZE=-1>"
+                                               "<A HREF=\"/display_edit_event?msgnum=%ld\">",
+                                               WC->cal_msgnum[i]
+                                       );
                                        escputs((char *)
                                                icalproperty_get_comment(p));
+                                       wprintf("</A></FONT>\n");
                                }
 
                        }
@@ -95,12 +100,10 @@ void calendar_month_view(int year, int month, int day) {
        starting_tm.tm_mon = month - 1;
        starting_tm.tm_mday = day;
        thetime = mktime(&starting_tm);
-       lprintf(9, "Starting at %s", asctime(localtime(&thetime)));
 
        tm = &starting_tm;
        while (tm->tm_mday != 1) {
                thetime = thetime - (time_t)86400;      /* go back 24 hours */
-               lprintf(9, "Backing off to %s", asctime(localtime(&thetime)));
                tm = localtime(&thetime);
        }
 
@@ -114,7 +117,6 @@ void calendar_month_view(int year, int month, int day) {
        tm = localtime(&thetime);
        while (tm->tm_wday != 0) {
                thetime = thetime - (time_t)86400;      /* go back 24 hours */
-               lprintf(9, "Backing off to %s", asctime(localtime(&thetime)));
                tm = localtime(&thetime);
        }
 
@@ -202,23 +204,20 @@ void calendar_day_view(int year, int month, int day) {
        starting_tm.tm_mon = month - 1;
        starting_tm.tm_mday = day;
        thetime = mktime(&starting_tm);
-       lprintf(9, "Starting at %s", asctime(localtime(&thetime)));
+
+       wprintf("<CENTER><H3>%s %d, %d</H3></CENTER>\n",
+               months[month-1], day, year);
 
        /* put the data here, stupid */
        calendar_month_view_display_events(thetime);
 
-       wprintf("<CENTER><I>FIXME day view for %02d/%02d/%04d</I>"
-               "</CENTER><BR>\n", month, day, year);
        wprintf("<A HREF=\"readfwd?calview=month&year=%d&month=%d&day=1\">"
                "Back to month view</A><BR>\n", year, month);
-
-
 }
 
 
 
 
-
 void do_calendar_view(void) {
        int i;
        time_t now;
diff --git a/webcit/event.c b/webcit/event.c
new file mode 100644 (file)
index 0000000..f79fff3
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * $Id$
+ *
+ * Editing calendar events.
+ *
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <limits.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <pthread.h>
+#include <signal.h>
+#include <time.h>
+#include "webcit.h"
+#include "webserver.h"
+
+
+#ifdef HAVE_ICAL_H
+
+
+/*
+ * Display an event by itself (for editing)
+ */
+void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
+       icalcomponent *vevent;
+       icalproperty *p;
+       struct icaltimetype t;
+       time_t now;
+       int created_new_vevent = 0;
+
+       now = time(NULL);
+
+       if (supplied_vevent != NULL) {
+               vevent = supplied_vevent;
+       }
+       else {
+               vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
+               created_new_vevent = 1;
+       }
+
+       output_headers(3);
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
+               "<FONT SIZE=+1 COLOR=\"FFFFFF\""
+               "<B>Edit event</B>"
+               "</FONT></TD></TR></TABLE><BR>\n"
+       );
+
+       wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_event\">\n");
+       wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
+               msgnum);
+
+       wprintf("Summary: "
+               "<INPUT TYPE=\"text\" NAME=\"summary\" "
+               "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
+       p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
+       if (p != NULL) {
+               escputs((char *)icalproperty_get_comment(p));
+       }
+       wprintf("\"><BR>\n");
+
+       wprintf("Start date: ");
+       p = icalcomponent_get_first_property(vevent, 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("<BR>\n");
+
+       wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
+               "ROWS=10 COLS=80 WIDTH=80>\n"
+       );
+       p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
+       if (p != NULL) {
+               escputs((char *)icalproperty_get_comment(p));
+       }
+       wprintf("</TEXTAREA><BR>\n");
+
+       wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
+               "&nbsp;&nbsp;"
+               "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
+               "&nbsp;&nbsp;"
+               "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
+               "</CENTER>\n"
+       );
+
+       wprintf("</FORM>\n");
+
+       wDumpContent(1);
+
+       if (created_new_vevent) {
+               icalcomponent_free(vevent);
+       }
+}
+
+/*
+ * Save an edited event
+ */
+void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
+       char buf[SIZ];
+       int delete_existing = 0;
+       icalproperty *prop;
+       icalcomponent *vevent;
+       int created_new_vevent = 0;
+
+       if (supplied_vevent != NULL) {
+               vevent = supplied_vevent;
+       }
+       else {
+               vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
+               created_new_vevent = 1;
+       }
+
+       if (!strcasecmp(bstr("sc"), "Save")) {
+
+               /* Replace values in the component with ones from the form */
+
+               while (prop = icalcomponent_get_first_property(vevent,
+                     ICAL_SUMMARY_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+               }
+               icalcomponent_add_property(vevent,
+                       icalproperty_new_summary(bstr("summary")));
+               
+               while (prop = icalcomponent_get_first_property(vevent,
+                     ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+               }
+               icalcomponent_add_property(vevent,
+                       icalproperty_new_description(bstr("description")));
+       
+               while (prop = icalcomponent_get_first_property(vevent,
+                     ICAL_DTSTART_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+               }
+               icalcomponent_add_property(vevent,
+                       icalproperty_new_dtstart(
+                               icaltime_from_webform("dtstart")
+                       )
+               );
+       
+               while (prop = icalcomponent_get_first_property(vevent,
+                     ICAL_DUE_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+               }
+               icalcomponent_add_property(vevent,
+                       icalproperty_new_due(
+                               icaltime_from_webform("due")
+                       )
+               );
+       
+               /* Serialize it and save it to the message base */
+               serv_puts("ENT0 1|||4");
+               serv_gets(buf);
+               if (buf[0] == '4') {
+                       serv_puts("Content-type: text/calendar");
+                       serv_puts("");
+                       serv_puts(icalcomponent_as_ical_string(vevent));
+                       serv_puts("000");
+                       delete_existing = 1;
+               }
+       }
+
+       /*
+        * If the user clicked 'Delete' then delete it, period.
+        */
+       if (!strcasecmp(bstr("sc"), "Delete")) {
+               delete_existing = 1;
+       }
+
+       if ( (delete_existing) && (msgnum > 0L) ) {
+               serv_printf("DELE %ld", atol(bstr("msgnum")));
+               serv_gets(buf);
+       }
+
+       if (created_new_vevent) {
+               icalcomponent_free(vevent);
+       }
+
+       /* Go back to the event list */
+       readloop("readfwd");
+}
+
+
+#endif /* HAVE_ICAL_H */
index 3a25aafa9311fe62755f372784b28fe32f3ac8ce..dd51681ffb6a9b58f656c2513bec29f8b5ae68c6 100644 (file)
@@ -1242,6 +1242,10 @@ void session_loop(struct httprequest *req, int gzip)
                display_edit_task();
        } else if (!strcasecmp(action, "save_task")) {
                save_task();
+       } else if (!strcasecmp(action, "display_edit_event")) {
+               display_edit_event();
+       } else if (!strcasecmp(action, "save_event")) {
+               save_event();
 #endif
        } else if (!strcasecmp(action, "summary")) {
                summary();
index 8815cfeb42595da919ec7d5d38117de20dac6986..87237648105c1c0b5c1cf572b47dffdbdbd9dfc2 100644 (file)
@@ -359,8 +359,12 @@ ssize_t http_write(int fd, void *buf, size_t count);
 #ifdef HAVE_ICAL_H
 void display_edit_task(void);
 void save_task(void);
+void display_edit_event(void);
+void save_event(void);
 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
 struct icaltimetype icaltime_from_webform(char *prefix);
+void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
+void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
 #endif
 
 extern char *months[];