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("<input type=\"radio\" name=\"rryeartype\" id=\"rrmonthtype_ymday\" "
578 "%s onChange=\"RecurrenceShowHide();\">",
579 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
581 wprintf(_("every "));
582 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
584 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rrmonthtype_ywday\" "
585 "%s onChange=\"RecurrenceShowHide();\">",
586 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
589 wprintf("on the (Grelfth) (Funday) of (Octobuary)<br />"); /* FIXME */
591 wprintf("</div>\n"); /* end 'yearday_selector' div */
595 wprintf("</td></tr>\n");
598 int which_rrend_is_preselected = 0;
599 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
600 if (recur.count > 0) which_rrend_is_preselected = 1;
602 wprintf("<tr><td><b>");
603 wprintf(_("Recurrence range"));
604 wprintf("</b></td><td>\n");
606 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
607 "%s onChange=\"RecurrenceShowHide();\">",
608 ((which_rrend_is_preselected == 0) ? "checked" : "")
610 wprintf("%s<br />\n", _("No ending date"));
612 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
613 "%s onChange=\"RecurrenceShowHide();\">",
614 ((which_rrend_is_preselected == 1) ? "checked" : "")
616 wprintf(_("Repeat this event"));
617 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
618 wprintf("value=\"%d\"> ", recur.count);
622 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
623 "%s onChange=\"RecurrenceShowHide();\">",
624 ((which_rrend_is_preselected == 2) ? "checked" : "")
626 wprintf(_("Repeat this event until "));
628 if (icaltime_is_null_time(recur.until)) {
629 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
631 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
634 wprintf("</td></tr>\n");
636 wprintf("</table>\n");
637 wprintf("</div>\n"); /* end 'rrule' div */
641 /* submit buttons (common area beneath the tabs) */
644 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
646 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
648 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
651 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
655 _("Check attendee availability"),
658 wprintf("</FORM>\n");
661 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
663 StrBufAppendPrintf(WC->trailing_javascript,
664 "eventEditAllDay(); \n"
665 "RecurrenceShowHide(); \n"
667 address_book_popup();
670 if (created_new_vevent) {
671 icalcomponent_free(vevent);
676 * Save an edited event
678 * supplied_vevent: the event to save
679 * msgnum: the index on the citserver
681 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
682 int unread, struct calview *calv) {
685 icalcomponent *vevent, *encaps;
686 int created_new_vevent = 0;
687 int all_day_event = 0;
688 struct icaltimetype event_start, t;
689 icalproperty *attendee = NULL;
690 char attendee_string[SIZ];
693 char form_attendees[SIZ];
694 char organizer_string[SIZ];
696 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
698 if (supplied_vevent != NULL) {
699 vevent = supplied_vevent;
701 * If we're looking at a fully encapsulated VCALENDAR
702 * rather than a VEVENT component, attempt to use the first
703 * relevant VEVENT subcomponent. If there is none, the
704 * NULL returned by icalcomponent_get_first_component() will
705 * tell the next iteration of this function to create a
708 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
709 save_individual_event(
710 icalcomponent_get_first_component(
711 vevent, ICAL_VEVENT_COMPONENT),
712 msgnum, from, unread, NULL
718 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
719 created_new_vevent = 1;
722 if ( (havebstr("save_button"))
723 || (havebstr("check_button")) ) {
725 /* Replace values in the component with ones from the form */
727 while (prop = icalcomponent_get_first_property(vevent,
728 ICAL_SUMMARY_PROPERTY), prop != NULL) {
729 icalcomponent_remove_property(vevent, prop);
730 icalproperty_free(prop);
733 if (havebstr("summary")) {
735 icalcomponent_add_property(vevent,
736 icalproperty_new_summary(bstr("summary")));
738 icalcomponent_add_property(vevent,
739 icalproperty_new_summary("Untitled Event"));
742 while (prop = icalcomponent_get_first_property(vevent,
743 ICAL_LOCATION_PROPERTY), prop != NULL) {
744 icalcomponent_remove_property(vevent, prop);
745 icalproperty_free(prop);
747 if (havebstr("location")) {
748 icalcomponent_add_property(vevent,
749 icalproperty_new_location(bstr("location")));
751 while (prop = icalcomponent_get_first_property(vevent,
752 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
753 icalcomponent_remove_property(vevent, prop);
754 icalproperty_free(prop);
756 if (havebstr("description")) {
757 icalcomponent_add_property(vevent,
758 icalproperty_new_description(bstr("description")));
761 while (prop = icalcomponent_get_first_property(vevent,
762 ICAL_DTSTART_PROPERTY), prop != NULL) {
763 icalcomponent_remove_property(vevent, prop);
764 icalproperty_free(prop);
767 if (yesbstr("alldayevent")) {
775 icaltime_from_webform_dateonly(&event_start, "dtstart");
778 icaltime_from_webform(&event_start, "dtstart");
782 * The following odd-looking snippet of code looks like it
783 * takes some unnecessary steps. It is done this way because
784 * libical incorrectly turns an "all day event" into a normal
785 * event starting at midnight (i.e. it serializes as date/time
786 * instead of just date) unless icalvalue_new_date() is used.
787 * So we force it, if this is an all day event.
789 prop = icalproperty_new_dtstart(event_start);
791 icalproperty_set_value(prop, icalvalue_new_date(event_start));
794 if (prop) icalcomponent_add_property(vevent, prop);
795 else icalproperty_free(prop);
797 while (prop = icalcomponent_get_first_property(vevent,
798 ICAL_DTEND_PROPERTY), prop != NULL) {
799 icalcomponent_remove_property(vevent, prop);
800 icalproperty_free(prop);
802 while (prop = icalcomponent_get_first_property(vevent,
803 ICAL_DURATION_PROPERTY), prop != NULL) {
804 icalcomponent_remove_property(vevent, prop);
805 icalproperty_free(prop);
808 if (all_day_event == 0) {
809 icaltime_from_webform(&t, "dtend");
810 icalcomponent_add_property(vevent,
811 icalproperty_new_dtend(icaltime_normalize(t)
816 /* See if transparency is indicated */
817 if (havebstr("transp")) {
818 if (!strcasecmp(bstr("transp"), "opaque")) {
819 formtransp = ICAL_TRANSP_OPAQUE;
821 else if (!strcasecmp(bstr("transp"), "transparent")) {
822 formtransp = ICAL_TRANSP_TRANSPARENT;
825 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
827 icalcomponent_remove_property(vevent, prop);
828 icalproperty_free(prop);
831 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
834 /* Give this event a UID if it doesn't have one. */
835 if (icalcomponent_get_first_property(vevent,
836 ICAL_UID_PROPERTY) == NULL) {
838 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
841 /* Increment the sequence ID */
842 while (prop = icalcomponent_get_first_property(vevent,
843 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
844 i = icalproperty_get_sequence(prop);
845 if (i > sequence) sequence = i;
846 icalcomponent_remove_property(vevent, prop);
847 icalproperty_free(prop);
850 icalcomponent_add_property(vevent,
851 icalproperty_new_sequence(sequence)
855 * Set the organizer, only if one does not already exist *and*
856 * the form is supplying one
858 strcpy(buf, bstr("organizer"));
859 if ( (icalcomponent_get_first_property(vevent,
860 ICAL_ORGANIZER_PROPERTY) == NULL)
861 && (!IsEmptyStr(buf)) ) {
863 /* set new organizer */
864 sprintf(organizer_string, "MAILTO:%s", buf);
865 icalcomponent_add_property(vevent,
866 icalproperty_new_organizer(organizer_string)
872 * Add any new attendees listed in the web form
875 /* First, strip out the parenthesized partstats. */
876 strcpy(form_attendees, bstr("attendees"));
877 stripout(form_attendees, '(', ')');
879 /* Next, change any commas to newlines, because we want newline-separated attendees. */
880 j = strlen(form_attendees);
881 for (i=0; i<j; ++i) {
882 if (form_attendees[i] == ',') {
883 form_attendees[i] = '\n';
884 while (isspace(form_attendees[i+1])) {
885 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
891 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
892 extract_token(buf, form_attendees, i, '\n', sizeof buf);
894 if (!IsEmptyStr(buf)) {
895 sprintf(attendee_string, "MAILTO:%s", buf);
898 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
899 if (!strcasecmp(attendee_string,
900 icalproperty_get_attendee(attendee)))
906 icalcomponent_add_property(vevent,
907 icalproperty_new_attendee(attendee_string)
914 * Remove any attendees *not* listed in the web form
916 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
917 strcpy(attendee_string, icalproperty_get_attendee(attendee));
918 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
919 strcpy(attendee_string, &attendee_string[7]);
920 striplt(attendee_string);
922 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
923 extract_token(buf, form_attendees, i, '\n', sizeof buf);
925 if (!strcasecmp(buf, attendee_string)) ++foundit;
928 icalcomponent_remove_property(vevent, attendee);
929 icalproperty_free(attendee);
936 * Encapsulate event into full VCALENDAR component. Clone it first,
937 * for two reasons: one, it's easier to just free the whole thing
938 * when we're done instead of unbundling, but more importantly, we
939 * can't encapsulate something that may already be encapsulated
942 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
944 /* Set the method to PUBLISH */
945 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
947 /* If the user clicked 'Save' then save it to the server. */
948 if ( (encaps != NULL) && (havebstr("save_button")) ) {
949 serv_puts("ENT0 1|||4|||1|");
950 serv_getln(buf, sizeof buf);
952 serv_puts("Content-type: text/calendar");
954 serv_puts(icalcomponent_as_ical_string(encaps));
957 if ( (buf[0] == '8') || (buf[0] == '4') ) {
958 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
962 strcpy(WC->ImportantMessage, &buf[4]);
964 icalmemory_free_ring ();
965 icalcomponent_free(encaps);
969 /* Or, check attendee availability if the user asked for that. */
970 if ( (encaps != NULL) && (havebstr("check_button")) ) {
972 /* Call this function, which does the real work */
973 check_attendee_availability(encaps);
975 /* This displays the form again, with our annotations */
976 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
978 icalcomponent_free(encaps);
981 if (encaps != NULL) {
982 icalcomponent_free(encaps);
989 * If the user clicked 'Delete' then delete it.
991 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
992 serv_printf("DELE %ld", lbstr("msgnum"));
993 serv_getln(buf, sizeof buf);
996 if (created_new_vevent) {
997 icalcomponent_free(vevent);
1000 /* If this was a save or delete, go back to the calendar view. */
1001 if (!havebstr("check_button")) {
1002 readloop("readfwd");