* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[citadel.git] / webcit / event.c
1 /*
2  * $Id$
3  */
4 /**
5  * \defgroup EditCal Editing calendar events.
6  * \ingroup Calendaring
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         /**
258          * For a new event, the user creating the event should be the
259          * organizer.  Set this field accordingly.
260          */
261         if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
262            == NULL) {
263                 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
264                 icalcomponent_add_property(vevent,
265                         icalproperty_new_organizer(organizer_string)
266                 );
267         }
268
269         /**
270          * Determine who is the organizer of this event.
271          * We need to determine "me" or "not me."
272          */
273         organizer = icalcomponent_get_first_property(vevent,
274                                                 ICAL_ORGANIZER_PROPERTY);
275         if (organizer != NULL) {
276                 strcpy(organizer_string, icalproperty_get_organizer(organizer));
277                 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
278                         strcpy(organizer_string, &organizer_string[7]);
279                         striplt(organizer_string);
280                         lprintf(9, "ISME %s\n", organizer_string);
281                         serv_printf("ISME %s", organizer_string);
282                         serv_getln(buf, sizeof buf);
283                         lprintf(9, "%s\n", buf);
284                         if (buf[0] == '2') {
285                                 organizer_is_me = 1;
286                         }
287                 }
288         }
289
290         wprintf("<TR><TD><B>");
291         wprintf(_("Organizer"));
292         wprintf("</B></TD><TD>");
293         escputs(organizer_string);
294         if (organizer_is_me) {
295                 wprintf(" <FONT SIZE=-1><I>");
296                 wprintf(_("(you are the organizer)"));
297                 wprintf("</I></FONT>\n");
298         }
299
300         /**
301          * Transmit the organizer as a hidden field.   We don't want the user
302          * to be able to change it, but we do want it fed back to the server,
303          * especially if this is a new event and there is no organizer already
304          * in the calendar object.
305          */
306         wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
307         escputs(organizer_string);
308         wprintf("\">");
309
310         wprintf("</TD></TR>\n");
311
312         /** Transparency */
313         wprintf("<TR><TD><B>");
314         wprintf(_("Show time as:"));
315         wprintf("</B></TD><TD>");
316
317         p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
318         if (p == NULL) {
319                 /** No transparency found.  Default to opaque (busy). */
320                 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
321                 if (p != NULL) {
322                         icalcomponent_add_property(vevent, p);
323                 }
324         }
325         if (p != NULL) {
326                 v = icalproperty_get_value(p);
327         }
328         else {
329                 v = NULL;
330         }
331
332         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
333         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
334                 wprintf(" CHECKED");
335         wprintf(">");
336         wprintf(_("Free"));
337         wprintf("&nbsp;&nbsp;");
338
339         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
340         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
341                 wprintf(" CHECKED");
342         wprintf(">");
343         wprintf(_("Busy"));
344
345         wprintf("</TD></TR>\n");
346
347         /** Attendees */
348         wprintf("<TR><TD><B>");
349         wprintf(_("Attendees"));
350         wprintf("</B><br />"
351                 "<FONT SIZE=-2>");
352         wprintf(_("(One per line)"));
353         wprintf("</FONT></TD><TD>"
354                 "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
355                 "ROWS=3 COLS=80 WIDTH=80>\n",
356                 (organizer_is_me ? "" : "DISABLED ")
357         );
358         i = 0;
359         for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
360             attendee != NULL;
361             attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
362                 strcpy(attendee_string, icalproperty_get_attendee(attendee));
363                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
364
365                         /** screen name or email address */
366                         strcpy(attendee_string, &attendee_string[7]);
367                         striplt(attendee_string);
368                         if (i++) wprintf("\n");
369                         escputs(attendee_string);
370                         wprintf(" ");
371
372                         /** participant status */
373                         partstat_as_string(buf, attendee);
374                         escputs(buf);
375                 }
376         }
377         wprintf("</TEXTAREA></TD></TR>\n");
378
379         /** Done with properties. */
380         wprintf("</TABLE>\n<CENTER>"
381                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
382                 "&nbsp;&nbsp;"
383                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
384                 "&nbsp;&nbsp;"
385                 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
386                                 "VALUE=\"%s\">\n"
387                 "&nbsp;&nbsp;"
388                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
389                 "</CENTER>\n",
390                 _("Save"),
391                 _("Delete"),
392                 _("Check attendee availability"),
393                 _("Cancel")
394         );
395
396         wprintf("</FORM>\n");
397         
398         wprintf("</td></tr></table></div>\n");
399         wprintf("<script type=\"text/javascript\">"
400                 "grey_all_day();"
401                 "</script>\n"
402         );
403         wDumpContent(1);
404
405         if (created_new_vevent) {
406                 icalcomponent_free(vevent);
407         }
408 }
409
410 /**
411  * \brief Save an edited event
412  * \param supplied_vevent the event to save
413  * \param msgnum the index on the citserver
414  */
415 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
416         char buf[SIZ];
417         icalproperty *prop;
418         icalcomponent *vevent, *encaps;
419         int created_new_vevent = 0;
420         int all_day_event = 0;
421         struct icaltimetype event_start, t;
422         icalproperty *attendee = NULL;
423         char attendee_string[SIZ];
424         int i;
425         int foundit;
426         char form_attendees[SIZ];
427         char organizer_string[SIZ];
428         int sequence = 0;
429         enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
430
431         if (supplied_vevent != NULL) {
432                 vevent = supplied_vevent;
433                 /**
434                  * If we're looking at a fully encapsulated VCALENDAR
435                  * rather than a VEVENT component, attempt to use the first
436                  * relevant VEVENT subcomponent.  If there is none, the
437                  * NULL returned by icalcomponent_get_first_component() will
438                  * tell the next iteration of this function to create a
439                  * new one.
440                  */
441                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
442                         save_individual_event(
443                                 icalcomponent_get_first_component(
444                                         vevent, ICAL_VEVENT_COMPONENT
445                                 ), msgnum
446                         );
447                         return;
448                 }
449         }
450         else {
451                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
452                 created_new_vevent = 1;
453         }
454
455         if ( (strlen(bstr("save_button")) > 0)
456            || (strlen(bstr("check_button")) > 0) ) {
457
458                 /** Replace values in the component with ones from the form */
459
460                 while (prop = icalcomponent_get_first_property(vevent,
461                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
462                         icalcomponent_remove_property(vevent, prop);
463                         icalproperty_free(prop);
464                 }
465                 icalcomponent_add_property(vevent,
466                         icalproperty_new_summary(bstr("summary")));
467
468                 while (prop = icalcomponent_get_first_property(vevent,
469                       ICAL_LOCATION_PROPERTY), prop != NULL) {
470                         icalcomponent_remove_property(vevent, prop);
471                         icalproperty_free(prop);
472                 }
473                 icalcomponent_add_property(vevent,
474                         icalproperty_new_location(bstr("location")));
475                 
476                 while (prop = icalcomponent_get_first_property(vevent,
477                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
478                         icalcomponent_remove_property(vevent, prop);
479                         icalproperty_free(prop);
480                 }
481                 icalcomponent_add_property(vevent,
482                         icalproperty_new_description(bstr("description")));
483         
484                 while (prop = icalcomponent_get_first_property(vevent,
485                       ICAL_DTSTART_PROPERTY), prop != NULL) {
486                         icalcomponent_remove_property(vevent, prop);
487                         icalproperty_free(prop);
488                 }
489
490                 if (!strcmp(bstr("alldayevent"), "yes")) {
491                         all_day_event = 1;
492                 }
493                 else {
494                         all_day_event = 0;
495                 }
496
497                 if (all_day_event) {
498                         icaltime_from_webform_dateonly(&event_start, "dtstart");
499                 }
500                 else {
501                         icaltime_from_webform(&event_start, "dtstart");
502                 }
503
504                 /**
505                  * The following odd-looking snippet of code looks like it
506                  * takes some unnecessary steps.  It is done this way because
507                  * libical incorrectly turns an "all day event" into a normal
508                  * event starting at midnight (i.e. it serializes as date/time
509                  * instead of just date) unless icalvalue_new_date() is used.
510                  * So we force it, if this is an all day event.
511                  */
512                 prop = icalproperty_new_dtstart(event_start);
513                 if (all_day_event) {
514                         icalproperty_set_value(prop,
515                                 icalvalue_new_date(event_start)
516                         );
517                 }
518
519                 if (prop) icalcomponent_add_property(vevent, prop);
520                 else icalproperty_free(prop);
521
522                 while (prop = icalcomponent_get_first_property(vevent,
523                       ICAL_DTEND_PROPERTY), prop != NULL) {
524                         icalcomponent_remove_property(vevent, prop);
525                         icalproperty_free(prop);
526                 }
527                 while (prop = icalcomponent_get_first_property(vevent,
528                       ICAL_DURATION_PROPERTY), prop != NULL) {
529                         icalcomponent_remove_property(vevent, prop);
530                         icalproperty_free(prop);
531                 }
532
533                 if (all_day_event == 0) {
534                         icaltime_from_webform(&t, "dtend");     
535                         icalcomponent_add_property(vevent,
536                                 icalproperty_new_dtend(icaltime_normalize(t)
537                                 )
538                         );
539                 }
540
541                 /** See if transparency is indicated */
542                 if (strlen(bstr("transp")) > 0) {
543                         if (!strcasecmp(bstr("transp"), "opaque")) {
544                                 formtransp = ICAL_TRANSP_OPAQUE;
545                         }
546                         else if (!strcasecmp(bstr("transp"), "transparent")) {
547                                 formtransp = ICAL_TRANSP_TRANSPARENT;
548                         }
549
550                         while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
551                               (prop != NULL)) {
552                                 icalcomponent_remove_property(vevent, prop);
553                                 icalproperty_free(prop);
554                         }
555
556                         lprintf(9, "adding new property...\n");
557                         icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
558                         lprintf(9, "...added it.\n");
559                 }
560
561                 /** Give this event a UID if it doesn't have one. */
562                 lprintf(9, "Give this event a UID if it doesn't have one.\n");
563                 if (icalcomponent_get_first_property(vevent,
564                    ICAL_UID_PROPERTY) == NULL) {
565                         generate_uuid(buf);
566                         icalcomponent_add_property(vevent,
567                                 icalproperty_new_uid(buf)
568                         );
569                 }
570
571                 /** Increment the sequence ID */
572                 lprintf(9, "Increment the sequence ID\n");
573                 while (prop = icalcomponent_get_first_property(vevent,
574                       ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
575                         i = icalproperty_get_sequence(prop);
576                         lprintf(9, "Sequence was %d\n", i);
577                         if (i > sequence) sequence = i;
578                         icalcomponent_remove_property(vevent, prop);
579                         icalproperty_free(prop);
580                 }
581                 ++sequence;
582                 lprintf(9, "New sequence is %d.  Adding...\n", sequence);
583                 icalcomponent_add_property(vevent,
584                         icalproperty_new_sequence(sequence)
585                 );
586                 
587                 /**
588                  * Set the organizer, only if one does not already exist *and*
589                  * the form is supplying one
590                  */
591                 lprintf(9, "Setting the organizer...\n");
592                 strcpy(buf, bstr("organizer"));
593                 if ( (icalcomponent_get_first_property(vevent,
594                    ICAL_ORGANIZER_PROPERTY) == NULL) 
595                    && (strlen(buf) > 0) ) {
596
597                         /** set new organizer */
598                         sprintf(organizer_string, "MAILTO:%s", buf);
599                         icalcomponent_add_property(vevent,
600                                 icalproperty_new_organizer(organizer_string)
601                         );
602
603                 }
604
605                 /**
606                  * Add any new attendees listed in the web form
607                  */
608                 lprintf(9, "Add any new attendees\n");
609
610                 /* First, strip out the parenthesized partstats.  */
611                 strcpy(form_attendees, bstr("attendees"));
612                 stripout(form_attendees, '(', ')');
613
614                 /** Now iterate! */
615                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
616                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
617                         striplt(buf);
618                         if (strlen(buf) > 0) {
619                                 lprintf(9, "Attendee: <%s>\n", buf);
620                                 sprintf(attendee_string, "MAILTO:%s", buf);
621                                 foundit = 0;
622
623                                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
624                                         if (!strcasecmp(attendee_string,
625                                            icalproperty_get_attendee(attendee)))
626                                                 ++foundit;
627                                 }
628
629
630                                 if (foundit == 0) {
631                                         icalcomponent_add_property(vevent,
632                                                 icalproperty_new_attendee(attendee_string)
633                                         );
634                                 }
635                         }
636                 }
637
638                 /**
639                  * Remove any attendees *not* listed in the web form
640                  */
641 STARTOVER:      lprintf(9, "Remove unlisted attendees\n");
642                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
643                         strcpy(attendee_string, icalproperty_get_attendee(attendee));
644                         if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
645                                 strcpy(attendee_string, &attendee_string[7]);
646                                 striplt(attendee_string);
647                                 foundit = 0;
648                                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
649                                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
650                                         striplt(buf);
651                                         if (!strcasecmp(buf, attendee_string)) ++foundit;
652                                 }
653                                 if (foundit == 0) {
654                                         icalcomponent_remove_property(vevent, attendee);
655                                         icalproperty_free(attendee);
656                                         goto STARTOVER;
657                                 }
658                         }
659                 }
660
661                 /**
662                  * Encapsulate event into full VCALENDAR component.  Clone it first,
663                  * for two reasons: one, it's easier to just free the whole thing
664                  * when we're done instead of unbundling, but more importantly, we
665                  * can't encapsulate something that may already be encapsulated
666                  * somewhere else.
667                  */
668                 lprintf(9, "Encapsulating into full VCALENDAR component\n");
669                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
670
671                 /** If the user clicked 'Save' then save it to the server. */
672                 lprintf(9, "Serializing it for saving\n");
673                 if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) {
674                         serv_puts("ENT0 1|||4|||1|");
675                         serv_getln(buf, sizeof buf);
676                         if (buf[0] == '8') {
677                                 serv_puts("Content-type: text/calendar");
678                                 serv_puts("");
679                                 serv_puts(icalcomponent_as_ical_string(encaps));
680                                 serv_puts("000");
681                         }
682                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
683                                 lprintf(9, "ENT0 REPLY: %s\n", buf);
684                         }
685                         icalcomponent_free(encaps);
686                 }
687
688                 /** Or, check attendee availability if the user asked for that. */
689                 if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) {
690
691                         /** Call this function, which does the real work */
692                         check_attendee_availability(encaps);
693
694                         /** This displays the form again, with our annotations */
695                         display_edit_individual_event(encaps, msgnum);
696
697                         icalcomponent_free(encaps);
698                 }
699
700         }
701
702         /**
703          * If the user clicked 'Delete' then delete it.
704          */
705         lprintf(9, "Checking to see if we have to delete an old event\n");
706         if ( (strlen(bstr("delete_button")) > 0) && (msgnum > 0L) ) {
707                 serv_printf("DELE %ld", atol(bstr("msgnum")));
708                 serv_getln(buf, sizeof buf);
709         }
710
711         if (created_new_vevent) {
712                 icalcomponent_free(vevent);
713         }
714
715         /** If this was a save or deelete, go back to the calendar view. */
716         if (strlen(bstr("check_button")) == 0) {
717                 readloop("readfwd");
718         }
719 }
720
721
722 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
723
724 /*@}*/