4bfcb0a8a5a73132b688c343227151bde3454d74
[citadel.git] / webcit / event.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup EditCal Editing calendar events.
6  *
7  */
8 /*@{*/
9 #include "webcit.h"
10 #include "webserver.h"
11
12
13 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14
15 /**
16  * \brief Display an event by itself (for editing)
17  * \param supplied_vevent the event to edit
18  * \param msgnum reference on the citserver
19  */
20 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
21         icalcomponent *vevent;
22         icalproperty *p;
23         icalvalue *v;
24         struct icaltimetype t_start, t_end;
25         time_t now;
26         struct tm tm_now;
27         int created_new_vevent = 0;
28         icalproperty *organizer = NULL;
29         char organizer_string[SIZ];
30         icalproperty *attendee = NULL;
31         char attendee_string[SIZ];
32         char buf[SIZ];
33         int organizer_is_me = 0;
34         int i;
35         int sequence = 0;
36
37         now = time(NULL);
38         strcpy(organizer_string, "");
39         strcpy(attendee_string, "");
40
41         if (supplied_vevent != NULL) {
42                 vevent = supplied_vevent;
43                 /**
44                  * If we're looking at a fully encapsulated VCALENDAR
45                  * rather than a VEVENT component, attempt to use the first
46                  * relevant VEVENT subcomponent.  If there is none, the
47                  * NULL returned by icalcomponent_get_first_component() will
48                  * tell the next iteration of this function to create a
49                  * new one.
50                  */
51                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
52                         display_edit_individual_event(
53                                 icalcomponent_get_first_component(
54                                         vevent, ICAL_VEVENT_COMPONENT
55                                 ), msgnum
56                         );
57                         return;
58                 }
59         }
60         else {
61                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
62                 created_new_vevent = 1;
63         }
64
65         /** Learn the sequence */
66         p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
67         if (p != NULL) {
68                 sequence = icalproperty_get_sequence(p);
69         }
70
71         /** Begin output */
72         output_headers(1, 1, 2, 0, 0, 0);
73         wprintf("<div id=\"banner\">\n"
74                 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
75                 "<SPAN CLASS=\"titlebar\">");
76         wprintf(_("Add or edit an event"));
77         wprintf("</SPAN>"
78                 "</TD></TR></TABLE>\n"
79                 "</div>\n<div id=\"content\">\n"
80         );
81
82         wprintf("<script type=\"text/javascript\">"
83                 "function grey_all_day() { "
84                         "if (document.EventForm.alldayevent.checked) {"
85                                 "document.EventForm.dtstart_hour.value='0';"
86                                 "document.EventForm.dtstart_hour.disabled = true;"
87                                 "document.EventForm.dtstart_minute.value='0';"
88                                 "document.EventForm.dtstart_minute.disabled = true;"
89                                 "document.EventForm.dtend_hour.value='0';"
90                                 "document.EventForm.dtend_hour.disabled = true;"
91                                 "document.EventForm.dtend_minute.value='0';"
92                                 "document.EventForm.dtend_minute.disabled = true;"
93                                 "document.EventForm.dtend_month.disabled = true;"
94                                 "document.EventForm.dtend_day.disabled = true;"
95                                 "document.EventForm.dtend_year.disabled = true;"
96                         "}"
97                         "else {"
98                                 "document.EventForm.dtstart_hour.disabled = false;"
99                                 "document.EventForm.dtstart_minute.disabled = false;"
100                                 "document.EventForm.dtend_hour.disabled = false;"
101                                 "document.EventForm.dtend_minute.disabled = false;"
102                                 "document.EventForm.dtend_month.disabled = false;"
103                                 "document.EventForm.dtend_day.disabled = false;"
104                                 "document.EventForm.dtend_year.disabled = false;"
105                         "}"
106                 "}"
107                 "</script>\n"
108         );
109
110
111         wprintf("<div class=\"fix_scrollbar_bug\">"
112                 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
113
114         /************************************************************
115          * Uncomment this to see the UID in calendar events for debugging
116         wprintf("UID == ");
117         p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
118         if (p != NULL) {
119                 escputs((char *)icalproperty_get_comment(p));
120         }
121         wprintf("<br />\n");
122         wprintf("SEQUENCE == %d<br />\n", sequence);
123         *************************************************************/
124
125         wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
126
127         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
128                 msgnum);
129         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
130                 bstr("calview"));
131         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
132                 bstr("year"));
133         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
134                 bstr("month"));
135         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
136                 bstr("day"));
137
138         /** Put it in a borderless table so it lines up nicely */
139         wprintf("<TABLE border=0 width=100%%>\n");
140
141         wprintf("<TR><TD><B>");
142         wprintf(_("Summary"));
143         wprintf("</B></TD><TD>\n"
144                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
145                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
146         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
147         if (p != NULL) {
148                 escputs((char *)icalproperty_get_comment(p));
149         }
150         wprintf("\"></TD></TR>\n");
151
152         wprintf("<TR><TD><B>");
153         wprintf(_("Location"));
154         wprintf("</B></TD><TD>\n"
155                 "<INPUT TYPE=\"text\" NAME=\"location\" "
156                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
157         p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
158         if (p != NULL) {
159                 escputs((char *)icalproperty_get_comment(p));
160         }
161         wprintf("\"></TD></TR>\n");
162
163         wprintf("<TR><TD><B>");
164         wprintf(_("Start"));
165         wprintf("</B></TD><TD>\n");
166         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
167         if (p != NULL) {
168                 t_start = icalproperty_get_dtstart(p);
169                 if (t_start.is_date) {
170                         t_start.hour = 0;
171                         t_start.minute = 0;
172                         t_start.second = 0;
173                 }
174         }
175         else {
176                 localtime_r(&now, &tm_now);
177                 if (strlen(bstr("year")) > 0) {
178                         tm_now.tm_year = atoi(bstr("year")) - 1900;
179                         tm_now.tm_mon = atoi(bstr("month")) - 1;
180                         tm_now.tm_mday = atoi(bstr("day"));
181                 }
182                 if (strlen(bstr("hour")) > 0) {
183                         tm_now.tm_hour = atoi(bstr("hour"));
184                         tm_now.tm_min = atoi(bstr("minute"));
185                         tm_now.tm_sec = 0;
186                 }
187                 else {
188                         tm_now.tm_hour = 9;
189                         tm_now.tm_min = 0;
190                         tm_now.tm_sec = 0;
191                 }
192
193                 t_start = icaltime_from_timet_with_zone(
194                         mktime(&tm_now),
195                         ((!strcasecmp(bstr("alldayevent"), "yes")) ? 1 : 0),
196                         icaltimezone_get_utc_timezone()
197                 );
198                 t_start.is_utc = 1;
199
200         }
201         display_icaltimetype_as_webform(&t_start, "dtstart");
202
203         wprintf("<INPUT TYPE=\"checkbox\" NAME=\"alldayevent\" "
204                 "VALUE=\"yes\" onClick=\"grey_all_day();\""
205                 " %s >%s",
206                 (t_start.is_date ? "CHECKED" : "" ),
207                 _("All day event")
208         );
209
210         wprintf("</TD></TR>\n");
211
212         /**
213          * If this is an all-day-event, set the end time to be identical to
214          * the start time (the hour/minute/second will be set to midnight).
215          * Otherwise extract or create it.
216          */
217         wprintf("<TR><TD><B>");
218         wprintf(_("End"));
219         wprintf("</B></TD><TD>\n");
220         if (t_start.is_date) {
221                 t_end = t_start;
222         }
223         else {
224                 p = icalcomponent_get_first_property(vevent,
225                                                         ICAL_DTEND_PROPERTY);
226                 if (p != NULL) {
227                         t_end = icalproperty_get_dtend(p);
228                 }
229                 else {
230                         /**
231                          * If this is not an all-day event and there is no
232                          * end time specified, make the default one hour
233                          * from the start time.
234                          */
235                         t_end = t_start;
236                         t_end.hour += 1;
237                         t_end.second = 0;
238                         t_end = icaltime_normalize(t_end);
239                         /* t_end = icaltime_from_timet(now, 0); */
240                 }
241         }
242         display_icaltimetype_as_webform(&t_end, "dtend");
243         wprintf("</TD></TR>\n");
244
245         wprintf("<TR><TD><B>");
246         wprintf(_("Notes"));
247         wprintf("</B></TD><TD>\n"
248                 "<TEXTAREA NAME=\"description\" wrap=soft "
249                 "ROWS=5 COLS=80 WIDTH=80>\n"
250         );
251         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
252         if (p != NULL) {
253                 escputs((char *)icalproperty_get_comment(p));
254         }
255         wprintf("</TEXTAREA></TD></TR>");
256
257         /* For a new event, the user creating the event should be the
258          * organizer.  Set this field accordingly.
259          */
260         if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
261            == NULL) {
262                 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
263                 icalcomponent_add_property(vevent,
264                         icalproperty_new_organizer(organizer_string)
265                 );
266         }
267
268         /**
269          * Determine who is the organizer of this event.
270          * We need to determine "me" or "not me."
271          */
272         organizer = icalcomponent_get_first_property(vevent,
273                                                 ICAL_ORGANIZER_PROPERTY);
274         if (organizer != NULL) {
275                 strcpy(organizer_string, icalproperty_get_organizer(organizer));
276                 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
277                         strcpy(organizer_string, &organizer_string[7]);
278                         striplt(organizer_string);
279                         lprintf(9, "ISME %s\n", organizer_string);
280                         serv_printf("ISME %s", organizer_string);
281                         serv_getln(buf, sizeof buf);
282                         lprintf(9, "%s\n", buf);
283                         if (buf[0] == '2') {
284                                 organizer_is_me = 1;
285                         }
286                 }
287         }
288
289         wprintf("<TR><TD><B>");
290         wprintf(_("Organizer"));
291         wprintf("</B></TD><TD>");
292         escputs(organizer_string);
293         if (organizer_is_me) {
294                 wprintf(" <FONT SIZE=-1><I>");
295                 wprintf(_("(you are the organizer)"));
296                 wprintf("</I></FONT>\n");
297         }
298
299         /**
300          * Transmit the organizer as a hidden field.   We don't want the user
301          * to be able to change it, but we do want it fed back to the server,
302          * especially if this is a new event and there is no organizer already
303          * in the calendar object.
304          */
305         wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
306         escputs(organizer_string);
307         wprintf("\">");
308
309         wprintf("</TD></TR>\n");
310
311         /** Transparency */
312         wprintf("<TR><TD><B>");
313         wprintf(_("Show time as:"));
314         wprintf("</B></TD><TD>");
315
316         p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
317         if (p == NULL) {
318                 /** No transparency found.  Default to opaque (busy). */
319                 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
320                 if (p != NULL) {
321                         icalcomponent_add_property(vevent, p);
322                 }
323         }
324         if (p != NULL) {
325                 v = icalproperty_get_value(p);
326         }
327         else {
328                 v = NULL;
329         }
330
331         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
332         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
333                 wprintf(" CHECKED");
334         wprintf(">");
335         wprintf(_("Free"));
336         wprintf("&nbsp;&nbsp;");
337
338         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
339         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
340                 wprintf(" CHECKED");
341         wprintf(">");
342         wprintf(_("Busy"));
343
344         wprintf("</TD></TR>\n");
345
346         /** Attendees */
347         wprintf("<TR><TD><B>");
348         wprintf(_("Attendees"));
349         wprintf("</B><br />"
350                 "<FONT SIZE=-2>");
351         wprintf(_("(One per line)"));
352         wprintf("</FONT></TD><TD>"
353                 "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
354                 "ROWS=3 COLS=80 WIDTH=80>\n",
355                 (organizer_is_me ? "" : "DISABLED ")
356         );
357         i = 0;
358         for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
359             attendee != NULL;
360             attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
361                 strcpy(attendee_string, icalproperty_get_attendee(attendee));
362                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
363
364                         /** screen name or email address */
365                         strcpy(attendee_string, &attendee_string[7]);
366                         striplt(attendee_string);
367                         if (i++) wprintf("\n");
368                         escputs(attendee_string);
369                         wprintf(" ");
370
371                         /** participant status */
372                         partstat_as_string(buf, attendee);
373                         escputs(buf);
374                 }
375         }
376         wprintf("</TEXTAREA></TD></TR>\n");
377
378         /** Done with properties. */
379         wprintf("</TABLE>\n<CENTER>"
380                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
381                 "&nbsp;&nbsp;"
382                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
383                 "&nbsp;&nbsp;"
384                 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
385                                 "VALUE=\"%s\">\n"
386                 "&nbsp;&nbsp;"
387                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
388                 "</CENTER>\n",
389                 _("Save"),
390                 _("Delete"),
391                 _("Check attendee availability"),
392                 _("Cancel")
393         );
394
395         wprintf("</FORM>\n");
396         
397         wprintf("</td></tr></table></div>\n");
398         wprintf("<script type=\"text/javascript\">"
399                 "grey_all_day();"
400                 "</script>\n"
401         );
402         wDumpContent(1);
403
404         if (created_new_vevent) {
405                 icalcomponent_free(vevent);
406         }
407 }
408
409 /**
410  * \brief Save an edited event
411  * \param supplied_vevent the event to save
412  * \param msgnum the index on the citserver
413  */
414 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
415         char buf[SIZ];
416         icalproperty *prop;
417         icalcomponent *vevent, *encaps;
418         int created_new_vevent = 0;
419         int all_day_event = 0;
420         struct icaltimetype event_start, t;
421         icalproperty *attendee = NULL;
422         char attendee_string[SIZ];
423         int i;
424         int foundit;
425         char form_attendees[SIZ];
426         char organizer_string[SIZ];
427         int sequence = 0;
428         enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
429
430         if (supplied_vevent != NULL) {
431                 vevent = supplied_vevent;
432                 /**
433                  * If we're looking at a fully encapsulated VCALENDAR
434                  * rather than a VEVENT component, attempt to use the first
435                  * relevant VEVENT subcomponent.  If there is none, the
436                  * NULL returned by icalcomponent_get_first_component() will
437                  * tell the next iteration of this function to create a
438                  * new one.
439                  */
440                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
441                         save_individual_event(
442                                 icalcomponent_get_first_component(
443                                         vevent, ICAL_VEVENT_COMPONENT
444                                 ), msgnum
445                         );
446                         return;
447                 }
448         }
449         else {
450                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
451                 created_new_vevent = 1;
452         }
453
454         if ( (strlen(bstr("save_button")) > 0)
455            || (strlen(bstr("check_button")) > 0) ) {
456
457                 /** Replace values in the component with ones from the form */
458
459                 while (prop = icalcomponent_get_first_property(vevent,
460                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
461                         icalcomponent_remove_property(vevent, prop);
462                         icalproperty_free(prop);
463                 }
464                 icalcomponent_add_property(vevent,
465                         icalproperty_new_summary(bstr("summary")));
466
467                 while (prop = icalcomponent_get_first_property(vevent,
468                       ICAL_LOCATION_PROPERTY), prop != NULL) {
469                         icalcomponent_remove_property(vevent, prop);
470                         icalproperty_free(prop);
471                 }
472                 icalcomponent_add_property(vevent,
473                         icalproperty_new_location(bstr("location")));
474                 
475                 while (prop = icalcomponent_get_first_property(vevent,
476                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
477                         icalcomponent_remove_property(vevent, prop);
478                         icalproperty_free(prop);
479                 }
480                 icalcomponent_add_property(vevent,
481                         icalproperty_new_description(bstr("description")));
482         
483                 while (prop = icalcomponent_get_first_property(vevent,
484                       ICAL_DTSTART_PROPERTY), prop != NULL) {
485                         icalcomponent_remove_property(vevent, prop);
486                         icalproperty_free(prop);
487                 }
488
489                 if (!strcmp(bstr("alldayevent"), "yes")) {
490                         all_day_event = 1;
491                 }
492                 else {
493                         all_day_event = 0;
494                 }
495
496                 if (all_day_event) {
497                         icaltime_from_webform_dateonly(&event_start, "dtstart");
498                 }
499                 else {
500                         icaltime_from_webform(&event_start, "dtstart");
501                 }
502
503                 /**
504                  * The following odd-looking snippet of code looks like it
505                  * takes some unnecessary steps.  It is done this way because
506                  * libical incorrectly turns an "all day event" into a normal
507                  * event starting at midnight (i.e. it serializes as date/time
508                  * instead of just date) unless icalvalue_new_date() is used.
509                  * So we force it, if this is an all day event.
510                  */
511                 prop = icalproperty_new_dtstart(event_start);
512                 if (all_day_event) {
513                         icalproperty_set_value(prop,
514                                 icalvalue_new_date(event_start)
515                         );
516                 }
517
518                 if (prop) icalcomponent_add_property(vevent, prop);
519                 else icalproperty_free(prop);
520
521                 while (prop = icalcomponent_get_first_property(vevent,
522                       ICAL_DTEND_PROPERTY), prop != NULL) {
523                         icalcomponent_remove_property(vevent, prop);
524                         icalproperty_free(prop);
525                 }
526                 while (prop = icalcomponent_get_first_property(vevent,
527                       ICAL_DURATION_PROPERTY), prop != NULL) {
528                         icalcomponent_remove_property(vevent, prop);
529                         icalproperty_free(prop);
530                 }
531
532                 if (all_day_event == 0) {
533                         icaltime_from_webform(&t, "dtend");     
534                         icalcomponent_add_property(vevent,
535                                 icalproperty_new_dtend(icaltime_normalize(t)
536                                 )
537                         );
538                 }
539
540                 /** See if transparency is indicated */
541                 if (strlen(bstr("transp")) > 0) {
542                         if (!strcasecmp(bstr("transp"), "opaque")) {
543                                 formtransp = ICAL_TRANSP_OPAQUE;
544                         }
545                         else if (!strcasecmp(bstr("transp"), "transparent")) {
546                                 formtransp = ICAL_TRANSP_TRANSPARENT;
547                         }
548
549                         while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
550                               (prop != NULL)) {
551                                 icalcomponent_remove_property(vevent, prop);
552                                 icalproperty_free(prop);
553                         }
554
555                         lprintf(9, "adding new property...\n");
556                         icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
557                         lprintf(9, "...added it.\n");
558                 }
559
560                 /** Give this event a UID if it doesn't have one. */
561                 lprintf(9, "Give this event a UID if it doesn't have one.\n");
562                 if (icalcomponent_get_first_property(vevent,
563                    ICAL_UID_PROPERTY) == NULL) {
564                         generate_uuid(buf);
565                         icalcomponent_add_property(vevent,
566                                 icalproperty_new_uid(buf)
567                         );
568                 }
569
570                 /** Increment the sequence ID */
571                 lprintf(9, "Increment the sequence ID\n");
572                 while (prop = icalcomponent_get_first_property(vevent,
573                       ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
574                         i = icalproperty_get_sequence(prop);
575                         lprintf(9, "Sequence was %d\n", i);
576                         if (i > sequence) sequence = i;
577                         icalcomponent_remove_property(vevent, prop);
578                         icalproperty_free(prop);
579                 }
580                 ++sequence;
581                 lprintf(9, "New sequence is %d.  Adding...\n", sequence);
582                 icalcomponent_add_property(vevent,
583                         icalproperty_new_sequence(sequence)
584                 );
585                 
586                 /**
587                  * Set the organizer, only if one does not already exist *and*
588                  * the form is supplying one
589                  */
590                 lprintf(9, "Setting the organizer...\n");
591                 strcpy(buf, bstr("organizer"));
592                 if ( (icalcomponent_get_first_property(vevent,
593                    ICAL_ORGANIZER_PROPERTY) == NULL) 
594                    && (strlen(buf) > 0) ) {
595
596                         /** set new organizer */
597                         sprintf(organizer_string, "MAILTO:%s", buf);
598                         icalcomponent_add_property(vevent,
599                                 icalproperty_new_organizer(organizer_string)
600                         );
601
602                 }
603
604                 /**
605                  * Add any new attendees listed in the web form
606                  */
607                 lprintf(9, "Add any new attendees\n");
608
609                 /* First, strip out the parenthesized partstats.  */
610                 strcpy(form_attendees, bstr("attendees"));
611                 stripout(form_attendees, '(', ')');
612
613                 /** Now iterate! */
614                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
615                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
616                         striplt(buf);
617                         if (strlen(buf) > 0) {
618                                 lprintf(9, "Attendee: <%s>\n", buf);
619                                 sprintf(attendee_string, "MAILTO:%s", buf);
620                                 foundit = 0;
621
622                                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
623                                         if (!strcasecmp(attendee_string,
624                                            icalproperty_get_attendee(attendee)))
625                                                 ++foundit;
626                                 }
627
628
629                                 if (foundit == 0) {
630                                         icalcomponent_add_property(vevent,
631                                                 icalproperty_new_attendee(attendee_string)
632                                         );
633                                 }
634                         }
635                 }
636
637                 /**
638                  * Remove any attendees *not* listed in the web form
639                  */
640 STARTOVER:      lprintf(9, "Remove unlisted attendees\n");
641                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
642                         strcpy(attendee_string, icalproperty_get_attendee(attendee));
643                         if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
644                                 strcpy(attendee_string, &attendee_string[7]);
645                                 striplt(attendee_string);
646                                 foundit = 0;
647                                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
648                                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
649                                         striplt(buf);
650                                         if (!strcasecmp(buf, attendee_string)) ++foundit;
651                                 }
652                                 if (foundit == 0) {
653                                         icalcomponent_remove_property(vevent, attendee);
654                                         icalproperty_free(attendee);
655                                         goto STARTOVER;
656                                 }
657                         }
658                 }
659
660                 /**
661                  * Encapsulate event into full VCALENDAR component.  Clone it first,
662                  * for two reasons: one, it's easier to just free the whole thing
663                  * when we're done instead of unbundling, but more importantly, we
664                  * can't encapsulate something that may already be encapsulated
665                  * somewhere else.
666                  */
667                 lprintf(9, "Encapsulating into full VCALENDAR component\n");
668                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
669
670                 /* If the user clicked 'Save' then save it to the server. */
671                 lprintf(9, "Serializing it for saving\n");
672                 if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) {
673                         serv_puts("ENT0 1|||4|||1|");
674                         serv_getln(buf, sizeof buf);
675                         if (buf[0] == '8') {
676                                 serv_puts("Content-type: text/calendar");
677                                 serv_puts("");
678                                 serv_puts(icalcomponent_as_ical_string(encaps));
679                                 serv_puts("000");
680                         }
681                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
682                                 lprintf(9, "ENT0 REPLY: %s\n", buf);
683                         }
684                         icalcomponent_free(encaps);
685                 }
686
687                 /** Or, check attendee availability if the user asked for that. */
688                 if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) {
689
690                         /** Call this function, which does the real work */
691                         check_attendee_availability(encaps);
692
693                         /** This displays the form again, with our annotations */
694                         display_edit_individual_event(encaps, msgnum);
695
696                         icalcomponent_free(encaps);
697                 }
698
699         }
700
701         /**
702          * If the user clicked 'Delete' then delete it.
703          */
704         lprintf(9, "Checking to see if we have to delete an old event\n");
705         if ( (strlen(bstr("delete_button")) > 0) && (msgnum > 0L) ) {
706                 serv_printf("DELE %ld", atol(bstr("msgnum")));
707                 serv_getln(buf, sizeof buf);
708         }
709
710         if (created_new_vevent) {
711                 icalcomponent_free(vevent);
712         }
713
714         /** If this was a save or deelete, go back to the calendar view. */
715         if (strlen(bstr("check_button")) == 0) {
716                 readloop("readfwd");
717         }
718 }
719
720
721 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
722
723 /*@}*/