4 * Editing calendar events.
11 * Display an event by itself (for editing)
12 * supplied_vevent the event to edit
13 * msgnum reference on the citserver
15 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
16 int unread, struct calview *calv)
18 icalcomponent *vevent;
21 struct icaltimetype t_start, t_end;
24 int created_new_vevent = 0;
25 icalproperty *organizer = NULL;
26 char organizer_string[SIZ];
27 icalproperty *attendee = NULL;
28 char attendee_string[SIZ];
30 int organizer_is_me = 0;
33 char weekday_labels[7][32];
36 get_pref_long("weekstart", &weekstart, 17);
37 if (weekstart > 6) weekstart = 0;
39 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
40 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
43 /* populate the weekday names - begin */
45 localtime_r(&now, &tm_now);
46 while (tm_now.tm_wday != 0) {
48 localtime_r(&now, &tm_now);
51 localtime_r(&now, &tm_now);
52 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
55 /* populate the weekday names - end */
58 strcpy(organizer_string, "");
59 strcpy(attendee_string, "");
61 if (supplied_vevent != NULL) {
62 vevent = supplied_vevent;
64 * If we're looking at a fully encapsulated VCALENDAR
65 * rather than a VEVENT component, attempt to use the first
66 * relevant VEVENT subcomponent. If there is none, the
67 * NULL returned by icalcomponent_get_first_component() will
68 * tell the next iteration of this function to create a
71 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
72 display_edit_individual_event(
73 icalcomponent_get_first_component(
74 vevent, ICAL_VEVENT_COMPONENT),
75 msgnum, from, unread, NULL
81 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
82 created_new_vevent = 1;
85 /* Learn the sequence */
86 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
88 sequence = icalproperty_get_sequence(p);
92 output_headers(1, 1, 2, 0, 0, 0);
93 wprintf("<div id=\"banner\">\n");
95 wprintf(_("Add or edit an event"));
99 wprintf("<div id=\"content\" class=\"service\">\n");
101 wprintf("<div class=\"fix_scrollbar_bug\">");
103 /************************************************************
104 * Uncomment this to see the UID in calendar events for debugging
106 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
108 escputs((char *)icalproperty_get_comment(p));
111 wprintf("SEQUENCE == %d<br />\n", sequence);
112 *************************************************************/
114 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
115 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
117 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
119 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
121 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
123 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
125 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
134 tabbed_dialog(3, tabnames);
137 /* Put it in a borderless table so it lines up nicely */
138 wprintf("<TABLE border=0 width=100%%>\n");
140 wprintf("<TR><TD><B>");
141 wprintf(_("Summary"));
142 wprintf("</B></TD><TD>\n"
143 "<INPUT TYPE=\"text\" NAME=\"summary\" "
144 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
145 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
147 escputs((char *)icalproperty_get_comment(p));
149 wprintf("\"></TD></TR>\n");
151 wprintf("<TR><TD><B>");
152 wprintf(_("Location"));
153 wprintf("</B></TD><TD>\n"
154 "<INPUT TYPE=\"text\" NAME=\"location\" "
155 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
156 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
158 escputs((char *)icalproperty_get_comment(p));
160 wprintf("\"></TD></TR>\n");
162 wprintf("<TR><TD><B>");
164 wprintf("</B></TD><TD>\n");
165 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
167 t_start = icalproperty_get_dtstart(p);
168 if (t_start.is_date) {
175 localtime_r(&now, &tm_now);
176 if (havebstr("year")) {
177 tm_now.tm_year = ibstr("year") - 1900;
178 tm_now.tm_mon = ibstr("month") - 1;
179 tm_now.tm_mday = ibstr("day");
181 if (havebstr("hour")) {
182 tm_now.tm_hour = ibstr("hour");
183 tm_now.tm_min = ibstr("minute");
192 t_start = icaltime_from_timet_with_zone(
194 ((yesbstr("alldayevent")) ? 1 : 0),
195 icaltimezone_get_utc_timezone()
200 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
202 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
203 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
205 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
209 wprintf("</TD></TR>\n");
212 * If this is an all-day-event, set the end time to be identical to
213 * the start time (the hour/minute/second will be set to midnight).
214 * Otherwise extract or create it.
216 wprintf("<TR><TD><B>");
218 wprintf("</B></TD><TD id=\"dtendcell\">\n");
219 if (t_start.is_date) {
223 p = icalcomponent_get_first_property(vevent,
224 ICAL_DTEND_PROPERTY);
226 t_end = icalproperty_get_dtend(p);
230 * If this is not an all-day event and there is no
231 * end time specified, make the default one hour
232 * from the start time.
237 t_end = icaltime_normalize(t_end);
238 /* t_end = icaltime_from_timet(now, 0); */
241 display_icaltimetype_as_webform(&t_end, "dtend", 0);
242 wprintf("</TD></TR>\n");
244 wprintf("<TR><TD><B>");
246 wprintf("</B></TD><TD>\n"
247 "<TEXTAREA NAME=\"description\" wrap=soft "
248 "ROWS=5 COLS=80 WIDTH=80>\n"
250 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
252 escputs((char *)icalproperty_get_comment(p));
254 wprintf("</TEXTAREA></TD></TR>");
257 * For a new event, the user creating the event should be the
258 * organizer. Set this field accordingly.
260 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
262 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
263 icalcomponent_add_property(vevent,
264 icalproperty_new_organizer(organizer_string)
269 * Determine who is the organizer of this event.
270 * We need to determine "me" or "not me."
272 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
273 if (organizer != NULL) {
274 strcpy(organizer_string, icalproperty_get_organizer(organizer));
275 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
276 strcpy(organizer_string, &organizer_string[7]);
277 striplt(organizer_string);
278 serv_printf("ISME %s", organizer_string);
279 serv_getln(buf, sizeof buf);
286 wprintf("<TR><TD><B>");
287 wprintf(_("Organizer"));
288 wprintf("</B></TD><TD>");
289 escputs(organizer_string);
290 if (organizer_is_me) {
291 wprintf(" <FONT SIZE=-1><I>");
292 wprintf(_("(you are the organizer)"));
293 wprintf("</I></FONT>\n");
297 * Transmit the organizer as a hidden field. We don't want the user
298 * to be able to change it, but we do want it fed back to the server,
299 * especially if this is a new event and there is no organizer already
300 * in the calendar object.
302 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
303 escputs(organizer_string);
306 wprintf("</TD></TR>\n");
309 wprintf("<TR><TD><B>");
310 wprintf(_("Show time as:"));
311 wprintf("</B></TD><TD>");
313 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
315 /* No transparency found. Default to opaque (busy). */
316 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
318 icalcomponent_add_property(vevent, p);
322 v = icalproperty_get_value(p);
328 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
329 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
333 wprintf(" ");
335 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
336 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
341 wprintf("</TD></TR>\n");
344 /* Done with properties. */
345 wprintf("</TABLE>\n");
349 /* Attendees tab (need to move things here) */
351 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
352 wprintf("<TR><TD><B>");
353 wprintf(_("Attendees"));
356 wprintf(_("(One per line)"));
357 wprintf("</font>\n");
359 /* Pop open an address book -- begin */
361 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
363 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
368 /* Pop open an address book -- end */
371 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
372 "ROWS=3 COLS=80 WIDTH=80>\n",
373 (organizer_is_me ? "" : "DISABLED ")
376 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
378 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
379 strcpy(attendee_string, icalproperty_get_attendee(attendee));
380 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
382 /* screen name or email address */
383 strcpy(attendee_string, &attendee_string[7]);
384 striplt(attendee_string);
385 if (i++) wprintf("\n");
386 escputs(attendee_string);
389 /* participant status */
390 partstat_as_string(buf, attendee);
394 wprintf("</TEXTAREA></TD></TR>\n");
395 wprintf("</TABLE>\n");
400 icalproperty *rrule = NULL;
401 struct icalrecurrencetype recur;
403 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
405 recur = icalproperty_get_rrule(rrule);
408 /* blank recurrence with some sensible defaults */
409 memset(&recur, 0, sizeof(struct icalrecurrencetype));
411 recur.until = icaltime_null_time();
413 recur.freq = ICAL_WEEKLY_RECURRENCE;
416 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
418 "onclick=\"RecurrenceShowHide();\""
420 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
421 _("This is a recurring event")
424 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
426 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
428 /* Table row displaying raw RRULE data, FIXME remove when finished */
430 wprintf("<tr><td><b>");
432 wprintf("</b></td><td>");
433 wprintf("<tt>%s</tt>", icalrecurrencetype_as_string(&recur));
434 wprintf("</td></tr>\n");
437 char *frequency_units[] = {
457 wprintf("<tr><td><b>");
458 wprintf(_("Recurrence rule"));
459 wprintf("</b></td><td>");
461 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
462 wprintf("%s ", _("Repeats every"));
464 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
465 wprintf("value=\"%d\"> ", recur.interval);
467 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
468 "onChange=\"RecurrenceShowHide();\">\n");
469 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
470 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
471 ((i == recur.freq) ? "selected " : ""),
472 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
477 wprintf("</select>\n");
479 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
480 wprintf("%s<br>", _("on these weekdays:"));
482 char weekday_is_selected[7];
483 memset(weekday_is_selected, 0, 7);
485 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
486 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
487 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
490 for (j=0; j<7; ++j) {
491 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
492 weekday_is_selected[j] = 1;
498 for (j=0; j<7; ++j) {
499 i = ((j + (int)weekstart) % 7);
500 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
501 if (weekday_is_selected[i]) wprintf(" checked");
502 wprintf(">%s\n", weekday_labels[i]);
504 wprintf("</div>\n"); /* end 'weekday_selector' div */
510 int which_rrmonthtype_is_preselected = 0;
511 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
513 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
514 "%s onChange=\"RecurrenceShowHide();\">",
515 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
519 int rrmday = 1; /* FIXME default to same as event start */
520 int rrmweek = 1; /* FIXME default to same as event start */
521 int rrmweekday = 1; /* FIXME default to same as event start */
523 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
524 which_rrmonthtype_is_preselected = 0;
525 rrmday = recur.by_month_day[0];
527 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
528 which_rrmonthtype_is_preselected = 1;
529 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
530 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
533 snprintf(mdaybox, sizeof mdaybox,
534 "<input type=\"text\" name=\"rrmday\" id=\"rrmday\" maxlength=\"2\" size=\"2\" "
535 "value=\"%d\">", rrmday);
536 wprintf(_("on day %s of the month"), mdaybox);
539 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
540 "%s onChange=\"RecurrenceShowHide();\">",
541 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
544 wprintf(_("on the "));
545 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
546 "onChange=\"RecurrenceShowHide();\">\n");
547 for (i=1; i<=5; ++i) {
548 wprintf("<option %svalue=\"%d\">%s</option>\n",
549 ((i==rrmweek) ? "selected " : ""),
554 wprintf("</select> \n");
556 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
557 "onChange=\"RecurrenceShowHide();\">\n");
558 for (j=0; j<7; ++j) {
559 i = ((j + (int)weekstart) % 7);
560 wprintf("<option %svalue=\"%d\">%s</option>\n",
561 ((i==rrmweekday) ? "selected " : ""),
566 wprintf("</select>");
568 wprintf(" %s<br />\n", _("of the month"));
570 wprintf("</div>\n"); /* end 'monthday_selector' div */
574 int which_rryeartype_is_preselected = 0; /* FIXME set default correctly */
575 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
577 wprintf("(X) every (99) (Octobuary)<br />"); /* FIXME */
578 wprintf("(X) on the (Grelfth) (Funday) of (Octobuary)<br />"); /* FIXME */
580 wprintf("</div>\n"); /* end 'yearday_selector' div */
584 wprintf("</td></tr>\n");
587 int which_rrend_is_preselected = 0;
588 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
589 if (recur.count > 0) which_rrend_is_preselected = 1;
591 wprintf("<tr><td><b>");
592 wprintf(_("Recurrence range"));
593 wprintf("</b></td><td>\n");
595 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
596 "%s onChange=\"RecurrenceShowHide();\">",
597 ((which_rrend_is_preselected == 0) ? "checked" : "")
599 wprintf("%s<br />\n", _("No ending date"));
601 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
602 "%s onChange=\"RecurrenceShowHide();\">",
603 ((which_rrend_is_preselected == 1) ? "checked" : "")
605 wprintf(_("Repeat this event"));
606 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
607 wprintf("value=\"%d\"> ", recur.count);
611 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
612 "%s onChange=\"RecurrenceShowHide();\">",
613 ((which_rrend_is_preselected == 2) ? "checked" : "")
615 wprintf(_("Repeat this event until "));
617 if (icaltime_is_null_time(recur.until)) {
618 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
620 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
623 wprintf("</td></tr>\n");
625 wprintf("</table>\n");
626 wprintf("</div>\n"); /* end 'rrule' div */
630 /* submit buttons (common area beneath the tabs) */
633 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
635 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
637 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
640 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
644 _("Check attendee availability"),
647 wprintf("</FORM>\n");
650 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
652 StrBufAppendPrintf(WC->trailing_javascript,
653 "eventEditAllDay(); \n"
654 "RecurrenceShowHide(); \n"
656 address_book_popup();
659 if (created_new_vevent) {
660 icalcomponent_free(vevent);
665 * Save an edited event
667 * supplied_vevent: the event to save
668 * msgnum: the index on the citserver
670 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
671 int unread, struct calview *calv) {
674 icalcomponent *vevent, *encaps;
675 int created_new_vevent = 0;
676 int all_day_event = 0;
677 struct icaltimetype event_start, t;
678 icalproperty *attendee = NULL;
679 char attendee_string[SIZ];
682 char form_attendees[SIZ];
683 char organizer_string[SIZ];
685 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
687 if (supplied_vevent != NULL) {
688 vevent = supplied_vevent;
690 * If we're looking at a fully encapsulated VCALENDAR
691 * rather than a VEVENT component, attempt to use the first
692 * relevant VEVENT subcomponent. If there is none, the
693 * NULL returned by icalcomponent_get_first_component() will
694 * tell the next iteration of this function to create a
697 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
698 save_individual_event(
699 icalcomponent_get_first_component(
700 vevent, ICAL_VEVENT_COMPONENT),
701 msgnum, from, unread, NULL
707 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
708 created_new_vevent = 1;
711 if ( (havebstr("save_button"))
712 || (havebstr("check_button")) ) {
714 /* Replace values in the component with ones from the form */
716 while (prop = icalcomponent_get_first_property(vevent,
717 ICAL_SUMMARY_PROPERTY), prop != NULL) {
718 icalcomponent_remove_property(vevent, prop);
719 icalproperty_free(prop);
722 if (havebstr("summary")) {
724 icalcomponent_add_property(vevent,
725 icalproperty_new_summary(bstr("summary")));
727 icalcomponent_add_property(vevent,
728 icalproperty_new_summary("Untitled Event"));
731 while (prop = icalcomponent_get_first_property(vevent,
732 ICAL_LOCATION_PROPERTY), prop != NULL) {
733 icalcomponent_remove_property(vevent, prop);
734 icalproperty_free(prop);
736 if (havebstr("location")) {
737 icalcomponent_add_property(vevent,
738 icalproperty_new_location(bstr("location")));
740 while (prop = icalcomponent_get_first_property(vevent,
741 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
742 icalcomponent_remove_property(vevent, prop);
743 icalproperty_free(prop);
745 if (havebstr("description")) {
746 icalcomponent_add_property(vevent,
747 icalproperty_new_description(bstr("description")));
750 while (prop = icalcomponent_get_first_property(vevent,
751 ICAL_DTSTART_PROPERTY), prop != NULL) {
752 icalcomponent_remove_property(vevent, prop);
753 icalproperty_free(prop);
756 if (yesbstr("alldayevent")) {
764 icaltime_from_webform_dateonly(&event_start, "dtstart");
767 icaltime_from_webform(&event_start, "dtstart");
771 * The following odd-looking snippet of code looks like it
772 * takes some unnecessary steps. It is done this way because
773 * libical incorrectly turns an "all day event" into a normal
774 * event starting at midnight (i.e. it serializes as date/time
775 * instead of just date) unless icalvalue_new_date() is used.
776 * So we force it, if this is an all day event.
778 prop = icalproperty_new_dtstart(event_start);
780 icalproperty_set_value(prop, icalvalue_new_date(event_start));
783 if (prop) icalcomponent_add_property(vevent, prop);
784 else icalproperty_free(prop);
786 while (prop = icalcomponent_get_first_property(vevent,
787 ICAL_DTEND_PROPERTY), prop != NULL) {
788 icalcomponent_remove_property(vevent, prop);
789 icalproperty_free(prop);
791 while (prop = icalcomponent_get_first_property(vevent,
792 ICAL_DURATION_PROPERTY), prop != NULL) {
793 icalcomponent_remove_property(vevent, prop);
794 icalproperty_free(prop);
797 if (all_day_event == 0) {
798 icaltime_from_webform(&t, "dtend");
799 icalcomponent_add_property(vevent,
800 icalproperty_new_dtend(icaltime_normalize(t)
805 /* See if transparency is indicated */
806 if (havebstr("transp")) {
807 if (!strcasecmp(bstr("transp"), "opaque")) {
808 formtransp = ICAL_TRANSP_OPAQUE;
810 else if (!strcasecmp(bstr("transp"), "transparent")) {
811 formtransp = ICAL_TRANSP_TRANSPARENT;
814 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
816 icalcomponent_remove_property(vevent, prop);
817 icalproperty_free(prop);
820 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
823 /* Give this event a UID if it doesn't have one. */
824 if (icalcomponent_get_first_property(vevent,
825 ICAL_UID_PROPERTY) == NULL) {
827 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
830 /* Increment the sequence ID */
831 while (prop = icalcomponent_get_first_property(vevent,
832 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
833 i = icalproperty_get_sequence(prop);
834 if (i > sequence) sequence = i;
835 icalcomponent_remove_property(vevent, prop);
836 icalproperty_free(prop);
839 icalcomponent_add_property(vevent,
840 icalproperty_new_sequence(sequence)
844 * Set the organizer, only if one does not already exist *and*
845 * the form is supplying one
847 strcpy(buf, bstr("organizer"));
848 if ( (icalcomponent_get_first_property(vevent,
849 ICAL_ORGANIZER_PROPERTY) == NULL)
850 && (!IsEmptyStr(buf)) ) {
852 /* set new organizer */
853 sprintf(organizer_string, "MAILTO:%s", buf);
854 icalcomponent_add_property(vevent,
855 icalproperty_new_organizer(organizer_string)
861 * Add any new attendees listed in the web form
864 /* First, strip out the parenthesized partstats. */
865 strcpy(form_attendees, bstr("attendees"));
866 stripout(form_attendees, '(', ')');
868 /* Next, change any commas to newlines, because we want newline-separated attendees. */
869 j = strlen(form_attendees);
870 for (i=0; i<j; ++i) {
871 if (form_attendees[i] == ',') {
872 form_attendees[i] = '\n';
873 while (isspace(form_attendees[i+1])) {
874 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
880 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
881 extract_token(buf, form_attendees, i, '\n', sizeof buf);
883 if (!IsEmptyStr(buf)) {
884 sprintf(attendee_string, "MAILTO:%s", buf);
887 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
888 if (!strcasecmp(attendee_string,
889 icalproperty_get_attendee(attendee)))
895 icalcomponent_add_property(vevent,
896 icalproperty_new_attendee(attendee_string)
903 * Remove any attendees *not* listed in the web form
905 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
906 strcpy(attendee_string, icalproperty_get_attendee(attendee));
907 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
908 strcpy(attendee_string, &attendee_string[7]);
909 striplt(attendee_string);
911 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
912 extract_token(buf, form_attendees, i, '\n', sizeof buf);
914 if (!strcasecmp(buf, attendee_string)) ++foundit;
917 icalcomponent_remove_property(vevent, attendee);
918 icalproperty_free(attendee);
925 * Encapsulate event into full VCALENDAR component. Clone it first,
926 * for two reasons: one, it's easier to just free the whole thing
927 * when we're done instead of unbundling, but more importantly, we
928 * can't encapsulate something that may already be encapsulated
931 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
933 /* Set the method to PUBLISH */
934 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
936 /* If the user clicked 'Save' then save it to the server. */
937 if ( (encaps != NULL) && (havebstr("save_button")) ) {
938 serv_puts("ENT0 1|||4|||1|");
939 serv_getln(buf, sizeof buf);
941 serv_puts("Content-type: text/calendar");
943 serv_puts(icalcomponent_as_ical_string(encaps));
946 if ( (buf[0] == '8') || (buf[0] == '4') ) {
947 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
951 strcpy(WC->ImportantMessage, &buf[4]);
953 icalmemory_free_ring ();
954 icalcomponent_free(encaps);
958 /* Or, check attendee availability if the user asked for that. */
959 if ( (encaps != NULL) && (havebstr("check_button")) ) {
961 /* Call this function, which does the real work */
962 check_attendee_availability(encaps);
964 /* This displays the form again, with our annotations */
965 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
967 icalcomponent_free(encaps);
970 if (encaps != NULL) {
971 icalcomponent_free(encaps);
978 * If the user clicked 'Delete' then delete it.
980 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
981 serv_printf("DELE %ld", lbstr("msgnum"));
982 serv_getln(buf, sizeof buf);
985 if (created_new_vevent) {
986 icalcomponent_free(vevent);
989 /* If this was a save or delete, go back to the calendar view. */
990 if (!havebstr("check_button")) {