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<=5))) ? "" : "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 */
507 int which_rrmonthtype_is_preselected = 0; /* FIXME set default correctly */
509 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
511 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
512 "%s onChange=\"RecurrenceShowHide();\">",
513 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
517 snprintf(mdaybox, sizeof mdaybox,
518 "<input type=\"text\" name=\"rrmday\" id=\"rrmday\" maxlength=\"2\" size=\"2\" "
519 "value=\"%d\">", 0); /* FIXME set the correct default */
520 wprintf(_("on day %s of the month"), mdaybox);
523 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
524 "%s onChange=\"RecurrenceShowHide();\">",
525 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
528 wprintf(_("on the "));
529 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
530 "onChange=\"RecurrenceShowHide();\">\n");
531 for (i=1; i<=5; ++i) {
532 wprintf("<option %svalue=\"%d\">%s</option>\n",
533 ((0) ? "selected " : ""), /* FIXME set correct default */
538 wprintf("</select> \n");
540 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
541 "onChange=\"RecurrenceShowHide();\">\n");
542 for (j=0; j<7; ++j) {
543 i = ((j + (int)weekstart) % 7);
544 wprintf("<option %svalue=\"%d\">%s</option>\n",
545 ((0) ? "selected " : ""), /* FIXME set correct default */
550 wprintf("</select>");
552 wprintf(" %s<br />\n", _("of the month"));
554 wprintf("</div>\n"); /* end 'monthday_selector' div */
558 wprintf("</td></tr>\n");
561 int which_rrend_is_preselected = 0;
562 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
563 if (recur.count > 0) which_rrend_is_preselected = 1;
565 wprintf("<tr><td><b>");
566 wprintf(_("Recurrence range"));
567 wprintf("</b></td><td>\n");
569 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
570 "%s onChange=\"RecurrenceShowHide();\">",
571 ((which_rrend_is_preselected == 0) ? "checked" : "")
573 wprintf("%s<br />\n", _("No ending date"));
575 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
576 "%s onChange=\"RecurrenceShowHide();\">",
577 ((which_rrend_is_preselected == 1) ? "checked" : "")
579 wprintf(_("Repeat this event"));
580 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
581 wprintf("value=\"%d\"> ", recur.count);
585 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
586 "%s onChange=\"RecurrenceShowHide();\">",
587 ((which_rrend_is_preselected == 2) ? "checked" : "")
589 wprintf(_("Repeat this event until "));
591 if (icaltime_is_null_time(recur.until)) {
592 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
594 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
597 wprintf("</td></tr>\n");
599 wprintf("</table>\n");
600 wprintf("</div>\n"); /* end 'rrule' div */
604 /* submit buttons (common area beneath the tabs) */
607 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
609 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
611 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
614 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
618 _("Check attendee availability"),
621 wprintf("</FORM>\n");
624 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
626 StrBufAppendPrintf(WC->trailing_javascript,
627 "eventEditAllDay(); \n"
628 "RecurrenceShowHide(); \n"
630 address_book_popup();
633 if (created_new_vevent) {
634 icalcomponent_free(vevent);
639 * Save an edited event
641 * supplied_vevent: the event to save
642 * msgnum: the index on the citserver
644 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
645 int unread, struct calview *calv) {
648 icalcomponent *vevent, *encaps;
649 int created_new_vevent = 0;
650 int all_day_event = 0;
651 struct icaltimetype event_start, t;
652 icalproperty *attendee = NULL;
653 char attendee_string[SIZ];
656 char form_attendees[SIZ];
657 char organizer_string[SIZ];
659 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
661 if (supplied_vevent != NULL) {
662 vevent = supplied_vevent;
664 * If we're looking at a fully encapsulated VCALENDAR
665 * rather than a VEVENT component, attempt to use the first
666 * relevant VEVENT subcomponent. If there is none, the
667 * NULL returned by icalcomponent_get_first_component() will
668 * tell the next iteration of this function to create a
671 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
672 save_individual_event(
673 icalcomponent_get_first_component(
674 vevent, ICAL_VEVENT_COMPONENT),
675 msgnum, from, unread, NULL
681 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
682 created_new_vevent = 1;
685 if ( (havebstr("save_button"))
686 || (havebstr("check_button")) ) {
688 /** Replace values in the component with ones from the form */
690 while (prop = icalcomponent_get_first_property(vevent,
691 ICAL_SUMMARY_PROPERTY), prop != NULL) {
692 icalcomponent_remove_property(vevent, prop);
693 icalproperty_free(prop);
696 if (havebstr("summary")) {
698 icalcomponent_add_property(vevent,
699 icalproperty_new_summary(bstr("summary")));
701 icalcomponent_add_property(vevent,
702 icalproperty_new_summary("Untitled Event"));
705 while (prop = icalcomponent_get_first_property(vevent,
706 ICAL_LOCATION_PROPERTY), prop != NULL) {
707 icalcomponent_remove_property(vevent, prop);
708 icalproperty_free(prop);
710 if (havebstr("location")) {
711 icalcomponent_add_property(vevent,
712 icalproperty_new_location(bstr("location")));
714 while (prop = icalcomponent_get_first_property(vevent,
715 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
716 icalcomponent_remove_property(vevent, prop);
717 icalproperty_free(prop);
719 if (havebstr("description")) {
720 icalcomponent_add_property(vevent,
721 icalproperty_new_description(bstr("description")));
724 while (prop = icalcomponent_get_first_property(vevent,
725 ICAL_DTSTART_PROPERTY), prop != NULL) {
726 icalcomponent_remove_property(vevent, prop);
727 icalproperty_free(prop);
730 if (yesbstr("alldayevent")) {
738 icaltime_from_webform_dateonly(&event_start, "dtstart");
741 icaltime_from_webform(&event_start, "dtstart");
745 * The following odd-looking snippet of code looks like it
746 * takes some unnecessary steps. It is done this way because
747 * libical incorrectly turns an "all day event" into a normal
748 * event starting at midnight (i.e. it serializes as date/time
749 * instead of just date) unless icalvalue_new_date() is used.
750 * So we force it, if this is an all day event.
752 prop = icalproperty_new_dtstart(event_start);
754 icalproperty_set_value(prop, icalvalue_new_date(event_start));
757 if (prop) icalcomponent_add_property(vevent, prop);
758 else icalproperty_free(prop);
760 while (prop = icalcomponent_get_first_property(vevent,
761 ICAL_DTEND_PROPERTY), prop != NULL) {
762 icalcomponent_remove_property(vevent, prop);
763 icalproperty_free(prop);
765 while (prop = icalcomponent_get_first_property(vevent,
766 ICAL_DURATION_PROPERTY), prop != NULL) {
767 icalcomponent_remove_property(vevent, prop);
768 icalproperty_free(prop);
771 if (all_day_event == 0) {
772 icaltime_from_webform(&t, "dtend");
773 icalcomponent_add_property(vevent,
774 icalproperty_new_dtend(icaltime_normalize(t)
779 /** See if transparency is indicated */
780 if (havebstr("transp")) {
781 if (!strcasecmp(bstr("transp"), "opaque")) {
782 formtransp = ICAL_TRANSP_OPAQUE;
784 else if (!strcasecmp(bstr("transp"), "transparent")) {
785 formtransp = ICAL_TRANSP_TRANSPARENT;
788 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
790 icalcomponent_remove_property(vevent, prop);
791 icalproperty_free(prop);
794 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
797 /** Give this event a UID if it doesn't have one. */
798 if (icalcomponent_get_first_property(vevent,
799 ICAL_UID_PROPERTY) == NULL) {
801 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
804 /** Increment the sequence ID */
805 while (prop = icalcomponent_get_first_property(vevent,
806 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
807 i = icalproperty_get_sequence(prop);
808 if (i > sequence) sequence = i;
809 icalcomponent_remove_property(vevent, prop);
810 icalproperty_free(prop);
813 icalcomponent_add_property(vevent,
814 icalproperty_new_sequence(sequence)
818 * Set the organizer, only if one does not already exist *and*
819 * the form is supplying one
821 strcpy(buf, bstr("organizer"));
822 if ( (icalcomponent_get_first_property(vevent,
823 ICAL_ORGANIZER_PROPERTY) == NULL)
824 && (!IsEmptyStr(buf)) ) {
826 /** set new organizer */
827 sprintf(organizer_string, "MAILTO:%s", buf);
828 icalcomponent_add_property(vevent,
829 icalproperty_new_organizer(organizer_string)
835 * Add any new attendees listed in the web form
838 /* First, strip out the parenthesized partstats. */
839 strcpy(form_attendees, bstr("attendees"));
840 stripout(form_attendees, '(', ')');
842 /* Next, change any commas to newlines, because we want newline-separated attendees. */
843 j = strlen(form_attendees);
844 for (i=0; i<j; ++i) {
845 if (form_attendees[i] == ',') {
846 form_attendees[i] = '\n';
847 while (isspace(form_attendees[i+1])) {
848 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
854 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
855 extract_token(buf, form_attendees, i, '\n', sizeof buf);
857 if (!IsEmptyStr(buf)) {
858 sprintf(attendee_string, "MAILTO:%s", buf);
861 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
862 if (!strcasecmp(attendee_string,
863 icalproperty_get_attendee(attendee)))
869 icalcomponent_add_property(vevent,
870 icalproperty_new_attendee(attendee_string)
877 * Remove any attendees *not* listed in the web form
879 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
880 strcpy(attendee_string, icalproperty_get_attendee(attendee));
881 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
882 strcpy(attendee_string, &attendee_string[7]);
883 striplt(attendee_string);
885 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
886 extract_token(buf, form_attendees, i, '\n', sizeof buf);
888 if (!strcasecmp(buf, attendee_string)) ++foundit;
891 icalcomponent_remove_property(vevent, attendee);
892 icalproperty_free(attendee);
899 * Encapsulate event into full VCALENDAR component. Clone it first,
900 * for two reasons: one, it's easier to just free the whole thing
901 * when we're done instead of unbundling, but more importantly, we
902 * can't encapsulate something that may already be encapsulated
905 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
907 /* Set the method to PUBLISH */
908 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
910 /** If the user clicked 'Save' then save it to the server. */
911 if ( (encaps != NULL) && (havebstr("save_button")) ) {
912 serv_puts("ENT0 1|||4|||1|");
913 serv_getln(buf, sizeof buf);
915 serv_puts("Content-type: text/calendar");
917 serv_puts(icalcomponent_as_ical_string(encaps));
920 if ( (buf[0] == '8') || (buf[0] == '4') ) {
921 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
925 strcpy(WC->ImportantMessage, &buf[4]);
927 icalmemory_free_ring ();
928 icalcomponent_free(encaps);
932 /** Or, check attendee availability if the user asked for that. */
933 if ( (encaps != NULL) && (havebstr("check_button")) ) {
935 /* Call this function, which does the real work */
936 check_attendee_availability(encaps);
938 /** This displays the form again, with our annotations */
939 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
941 icalcomponent_free(encaps);
944 if (encaps != NULL) {
945 icalcomponent_free(encaps);
952 * If the user clicked 'Delete' then delete it.
954 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
955 serv_printf("DELE %ld", lbstr("msgnum"));
956 serv_getln(buf, sizeof buf);
959 if (created_new_vevent) {
960 icalcomponent_free(vevent);
963 /* If this was a save or delete, go back to the calendar view. */
964 if (!havebstr("check_button")) {