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