4 * Editing calendar events.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
28 #include "webserver.h"
35 * Display an event by itself (for editing)
37 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
38 icalcomponent *vevent;
40 struct icaltimetype t_start, t_end;
42 int created_new_vevent = 0;
46 if (supplied_vevent != NULL) {
47 vevent = supplied_vevent;
50 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
51 created_new_vevent = 1;
55 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
56 "<IMG ALIGN=CENTER SRC=\"/static/vcalendar.gif\">"
57 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
59 "</FONT></TD></TR></TABLE><BR>\n"
62 /************************************************************
63 * Uncomment this to see the UID in calendar events for debugging
65 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
67 escputs((char *)icalproperty_get_comment(p));
69 *************************************************************/
71 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" ACTION=\"/save_event\">\n");
73 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
75 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
77 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
79 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
81 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
84 /* Put it in a borderless table so it lines up nicely */
85 wprintf("<TABLE border=0 width=100%%>\n");
87 wprintf("<TR><TD><B>Summary</B></TD><TD>\n"
88 "<INPUT TYPE=\"text\" NAME=\"summary\" "
89 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
90 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
92 escputs((char *)icalproperty_get_comment(p));
94 wprintf("\"></TD></TR>\n");
96 wprintf("<TR><TD><B>Location</B></TD><TD>\n"
97 "<INPUT TYPE=\"text\" NAME=\"location\" "
98 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
99 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
101 escputs((char *)icalproperty_get_comment(p));
103 wprintf("\"></TD></TR>\n");
105 wprintf("<TR><TD><B>Start</B></TD><TD>\n");
106 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
108 t_start = icalproperty_get_dtstart(p);
109 if (t_start.is_date) {
116 t_start = icaltime_from_timet(now, 0);
118 display_icaltimetype_as_webform(&t_start, "dtstart");
120 wprintf("<INPUT TYPE=\"checkbox\" NAME=\"alldayevent\" "
121 "VALUE=\"yes\" onClick=\"
124 this.form.dtstart_hour.value='0';
125 this.form.dtstart_hour.disabled = true;
126 this.form.dtstart_minute.value='0';
127 this.form.dtstart_minute.disabled = true;
128 this.form.dtend_hour.value='0';
129 this.form.dtend_hour.disabled = true;
130 this.form.dtend_minute.value='0';
131 this.form.dtend_minute.disabled = true;
132 this.form.dtend_month.disabled = true;
133 this.form.dtend_day.disabled = true;
134 this.form.dtend_year.disabled = true;
137 this.form.dtstart_hour.disabled = false;
138 this.form.dtstart_minute.disabled = false;
139 this.form.dtend_hour.disabled = false;
140 this.form.dtend_minute.disabled = false;
141 this.form.dtend_month.disabled = false;
142 this.form.dtend_day.disabled = false;
143 this.form.dtend_year.disabled = false;
147 \" %s >All day event",
148 (t_start.is_date ? "CHECKED" : "" )
151 wprintf("</TD></TR>\n");
153 /* If this is an all-day-event, set the end time to be identical to
154 * the start time (the hour/minute/second will be set to midnight).
155 * Otherwise extract or create it.
157 wprintf("<TR><TD><B>End</B></TD><TD>\n");
158 if (t_start.is_date) {
162 p = icalcomponent_get_first_property(vevent,
163 ICAL_DTEND_PROPERTY);
165 t_end = icalproperty_get_dtend(p);
168 t_end = icaltime_from_timet(now, 0);
171 display_icaltimetype_as_webform(&t_end, "dtend");
172 wprintf("</TD></TR>\n");
174 wprintf("<TR><TD><B>Notes</B></TD><TD>\n"
175 "<TEXTAREA NAME=\"description\" wrap=soft "
176 "ROWS=10 COLS=80 WIDTH=80>\n"
178 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
180 escputs((char *)icalproperty_get_comment(p));
182 wprintf("</TEXTAREA></TD></TR></TABLE>\n");
185 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
187 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
189 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
193 wprintf("</FORM>\n");
195 wprintf("<SCRIPT language=\"javascript\">
198 if (document.EventForm.alldayevent.checked) {
199 document.EventForm.dtstart_hour.value='0';
200 document.EventForm.dtstart_hour.disabled = true;
201 document.EventForm.dtstart_minute.value='0';
202 document.EventForm.dtstart_minute.disabled = true;
203 document.EventForm.dtend_hour.value='0';
204 document.EventForm.dtend_hour.disabled = true;
205 document.EventForm.dtend_minute.value='0';
206 document.EventForm.dtend_minute.disabled = true;
207 document.EventForm.dtend_month.disabled = true;
208 document.EventForm.dtend_day.disabled = true;
209 document.EventForm.dtend_year.disabled = true;
212 document.EventForm.dtstart_hour.disabled = false;
213 document.EventForm.dtstart_minute.disabled = false;
214 document.EventForm.dtend_hour.disabled = false;
215 document.EventForm.dtend_minute.disabled = false;
216 document.EventForm.dtend_month.disabled = false;
217 document.EventForm.dtend_day.disabled = false;
218 document.EventForm.dtend_year.disabled = false;
226 if (created_new_vevent) {
227 icalcomponent_free(vevent);
232 * Save an edited event
234 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
236 int delete_existing = 0;
238 icalcomponent *vevent;
239 int created_new_vevent = 0;
240 int all_day_event = 0;
241 struct icaltimetype event_start;
243 if (supplied_vevent != NULL) {
244 vevent = supplied_vevent;
247 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
248 created_new_vevent = 1;
251 if (!strcasecmp(bstr("sc"), "Save")) {
253 /* Replace values in the component with ones from the form */
255 while (prop = icalcomponent_get_first_property(vevent,
256 ICAL_SUMMARY_PROPERTY), prop != NULL) {
257 icalcomponent_remove_property(vevent, prop);
259 icalcomponent_add_property(vevent,
260 icalproperty_new_summary(bstr("summary")));
262 while (prop = icalcomponent_get_first_property(vevent,
263 ICAL_LOCATION_PROPERTY), prop != NULL) {
264 icalcomponent_remove_property(vevent, prop);
266 icalcomponent_add_property(vevent,
267 icalproperty_new_location(bstr("location")));
269 while (prop = icalcomponent_get_first_property(vevent,
270 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
271 icalcomponent_remove_property(vevent, prop);
273 icalcomponent_add_property(vevent,
274 icalproperty_new_description(bstr("description")));
276 while (prop = icalcomponent_get_first_property(vevent,
277 ICAL_DTSTART_PROPERTY), prop != NULL) {
278 icalcomponent_remove_property(vevent, prop);
281 if (!strcmp(bstr("alldayevent"), "yes")) {
283 lprintf(9, "*** all day event ***\n");
289 event_start = icaltime_from_webform("dtstart");
291 event_start.is_date = 1;
292 event_start.hour = 0;
293 event_start.minute = 0;
294 event_start.second = 0;
298 /* The following odd-looking snippet of code looks like it
299 * takes some unnecessary steps. It is done this way because
300 * libical incorrectly turns an "all day event" into a normal
301 * event starting at midnight (i.e. it serializes as date/time
302 * instead of just date) unless icalvalue_new_date() is used.
303 * So we force it, if this is an all day event.
305 prop = icalproperty_new_dtstart(event_start);
307 icalproperty_set_value(prop,
308 icalvalue_new_date(event_start)
312 if (prop) icalcomponent_add_property(vevent, prop);
313 else icalproperty_free(prop);
317 while (prop = icalcomponent_get_first_property(vevent,
318 ICAL_DTEND_PROPERTY), prop != NULL) {
319 icalcomponent_remove_property(vevent, prop);
321 while (prop = icalcomponent_get_first_property(vevent,
322 ICAL_DURATION_PROPERTY), prop != NULL) {
323 icalcomponent_remove_property(vevent, prop);
326 if (all_day_event == 0) {
327 icalcomponent_add_property(vevent,
328 icalproperty_new_dtend(icaltime_normalize(
329 icaltime_from_webform("dtend"))
334 /* Give this event a UID if it doesn't have one. */
335 if (icalcomponent_get_first_property(vevent,
336 ICAL_UID_PROPERTY) == NULL) {
337 generate_new_uid(buf);
338 icalcomponent_add_property(vevent,
339 icalproperty_new_uid(buf)
343 /* Serialize it and save it to the message base */
344 serv_puts("ENT0 1|||4");
347 serv_puts("Content-type: text/calendar");
349 serv_puts(icalcomponent_as_ical_string(vevent));
356 * If the user clicked 'Delete' then delete it, period.
358 if (!strcasecmp(bstr("sc"), "Delete")) {
362 if ( (delete_existing) && (msgnum > 0L) ) {
363 serv_printf("DELE %ld", atol(bstr("msgnum")));
367 if (created_new_vevent) {
368 icalcomponent_free(vevent);
371 /* Go back to the event list */
376 #endif /* HAVE_ICAL_H */