#include <stdarg.h>
#include <pthread.h>
#include <signal.h>
+#include <time.h>
#include "webcit.h"
#include "webserver.h"
-#ifdef HAVE_ICAL_H
-#include <ical.h>
-#endif
-
-
#ifndef HAVE_ICAL_H
/*
p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
- if (p != NULL) escputs((char *)icalproperty_get_comment(p));
+ if (p != NULL) {
+ escputs((char *)icalproperty_get_comment(p));
+ }
wprintf("</A>\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("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
"<INPUT TYPE=\"text\" NAME=\"summary\" "
"MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
- if (p != NULL) escputs((char *)icalproperty_get_comment(p));
- icalproperty_free(p);
+ if (p != NULL) {
+ escputs((char *)icalproperty_get_comment(p));
+ }
wprintf("\"><BR>\n");
- wprintf("Start date: FIXME <BR>\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("<BR>\n");
- wprintf("Due date: FIXME <BR>\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("<BR>\n");
- wprintf("<CENTER><TEXTAREA NAME=\"msgtext\" wrap=soft "
+ wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
"ROWS=10 COLS=80 WIDTH=80>\n"
);
p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
- if (p != NULL) escputs((char *)icalproperty_get_comment(p));
- icalproperty_free(p);
+ if (p != NULL) {
+ escputs((char *)icalproperty_get_comment(p));
+ }
wprintf("</TEXTAREA><BR>\n");
wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
wprintf("</FORM>\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);
serv_puts("");
serv_puts(icalcomponent_as_ical_string(vtodo));
serv_puts("000");
- /* delete_existing = 1; */
+ delete_existing = 1;
}
}
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");
}
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);
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 */
--- /dev/null
+/*
+ * $Id$
+ *
+ *
+ */
+
+#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
+
+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("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
+ for (i=1; i<=12; ++i) {
+ wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
+ ((t->month == i) ? "SELECTED" : ""),
+ i,
+ months[i-1]
+ );
+ }
+ wprintf("</SELECT>\n");
+
+ wprintf("Day: ");
+ wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
+ for (i=1; i<=31; ++i) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((t->day == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ wprintf("</SELECT>\n");
+
+ wprintf("Year: ");
+ wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
+ if ((this_year - t->year) > span) {
+ wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
+ t->year, t->year);
+ }
+ for (i=(this_year-span); i<=(this_year+span); ++i) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((t->year == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ if ((t->year - this_year) > span) {
+ wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
+ t->year, t->year);
+ }
+ wprintf("</SELECT>\n");
+
+ wprintf("Hour: ");
+ wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
+ for (i=0; i<=23; ++i) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((t->hour == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ wprintf("</SELECT>\n");
+
+ wprintf("Minute: ");
+ wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
+ for (i=0; i<=59; ++i) {
+ wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
+ ((t->minute == i) ? "SELECTED" : ""),
+ i, i
+ );
+ }
+ wprintf("</SELECT>\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