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];
34 char month_labels[12][32];
36 icalproperty *rrule = NULL;
37 struct icalrecurrencetype recur;
40 tabnames[0] = _("Event");
41 tabnames[1] = _("Attendees");
42 tabnames[2] = _("Recurrence");
44 get_pref_long("weekstart", &weekstart, 17);
45 if (weekstart > 6) weekstart = 0;
47 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
48 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
51 /* populate the weekday names - begin */
53 localtime_r(&now, &tm_now);
54 while (tm_now.tm_wday != 0) {
56 localtime_r(&now, &tm_now);
59 localtime_r(&now, &tm_now);
60 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
63 /* populate the weekday names - end */
65 /* populate the month names - begin */
66 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
67 localtime_r(&now, &tm_now);
68 for (i=0; i<12; ++i) {
69 localtime_r(&now, &tm_now);
70 wc_strftime(month_labels[i], 32, "%B", &tm_now);
73 /* populate the month names - end */
76 strcpy(organizer_string, "");
77 strcpy(attendee_string, "");
79 if (supplied_vevent != NULL) {
80 vevent = supplied_vevent;
82 /* Convert all timestamps to UTC to make them easier to process. */
83 ical_dezonify(vevent);
86 * If we're looking at a fully encapsulated VCALENDAR
87 * rather than a VEVENT component, attempt to use the first
88 * relevant VEVENT subcomponent. If there is none, the
89 * NULL returned by icalcomponent_get_first_component() will
90 * tell the next iteration of this function to create a
93 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
94 display_edit_individual_event(
95 icalcomponent_get_first_component(
96 vevent, ICAL_VEVENT_COMPONENT),
97 msgnum, from, unread, NULL
103 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
104 created_new_vevent = 1;
107 /* Learn the sequence */
108 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
110 sequence = icalproperty_get_sequence(p);
114 output_headers(1, 1, 2, 0, 0, 0);
115 wprintf("<div id=\"banner\">\n");
117 wprintf(_("Add or edit an event"));
121 wprintf("<div id=\"content\" class=\"service\">\n");
123 wprintf("<div class=\"fix_scrollbar_bug\">");
125 /************************************************************
126 * Uncomment this to see the UID in calendar events for debugging
128 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
130 escputs((char *)icalproperty_get_comment(p));
133 wprintf("SEQUENCE == %d<br />\n", sequence);
134 *************************************************************/
136 wprintf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
137 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
139 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
141 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
143 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
145 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
147 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
151 tabbed_dialog(3, tabnames);
154 /* Put it in a borderless table so it lines up nicely */
155 wprintf("<TABLE border=0 width=100%%>\n");
157 wprintf("<TR><TD><B>");
158 wprintf(_("Summary"));
159 wprintf("</B></TD><TD>\n"
160 "<INPUT TYPE=\"text\" NAME=\"summary\" "
161 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
162 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
164 escputs((char *)icalproperty_get_comment(p));
166 wprintf("\"></TD></TR>\n");
168 wprintf("<TR><TD><B>");
169 wprintf(_("Location"));
170 wprintf("</B></TD><TD>\n"
171 "<INPUT TYPE=\"text\" NAME=\"location\" "
172 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
173 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
175 escputs((char *)icalproperty_get_comment(p));
177 wprintf("\"></TD></TR>\n");
179 wprintf("<TR><TD><B>");
181 wprintf("</B></TD><TD>\n");
182 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
184 t_start = icalproperty_get_dtstart(p);
185 if (t_start.is_date) {
192 localtime_r(&now, &tm_now);
193 if (havebstr("year")) {
194 tm_now.tm_year = ibstr("year") - 1900;
195 tm_now.tm_mon = ibstr("month") - 1;
196 tm_now.tm_mday = ibstr("day");
198 if (havebstr("hour")) {
199 tm_now.tm_hour = ibstr("hour");
200 tm_now.tm_min = ibstr("minute");
209 t_start = icaltime_from_timet_with_zone(
211 ((yesbstr("alldayevent")) ? 1 : 0),
212 icaltimezone_get_utc_timezone()
217 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
219 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
220 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
222 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
226 wprintf("</TD></TR>\n");
228 wprintf("<TR><TD><B>");
230 wprintf("</B></TD><TD id=\"dtendcell\">\n");
231 p = icalcomponent_get_first_property(vevent,
232 ICAL_DTEND_PROPERTY);
234 t_end = icalproperty_get_dtend(p);
237 * If this is an all-day-event, the end time is set to real end
238 * day + 1, so we have to adjust accordingly.
240 if (t_start.is_date) {
241 icaltime_adjust(&t_end, -1, 0, 0, 0);
246 * If this is an all-day-event, set the end time to be identical to
247 * the start time (the hour/minute/second will be set to midnight).
248 * Otherwise extract or create it.
250 if (t_start.is_date) {
255 * If this is not an all-day event and there is no
256 * end time specified, make the default one hour
257 * from the start time.
262 t_end = icaltime_normalize(t_end);
263 /* t_end = icaltime_from_timet(now, 0); */
266 display_icaltimetype_as_webform(&t_end, "dtend", 0);
267 wprintf("</TD></TR>\n");
269 wprintf("<TR><TD><B>");
271 wprintf("</B></TD><TD>\n"
272 "<TEXTAREA NAME=\"description\" wrap=soft "
273 "ROWS=5 COLS=72 WIDTH=72>\n"
275 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
277 escputs((char *)icalproperty_get_comment(p));
279 wprintf("</TEXTAREA></TD></TR>");
282 * For a new event, the user creating the event should be the
283 * organizer. Set this field accordingly.
285 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
287 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
288 icalcomponent_add_property(vevent,
289 icalproperty_new_organizer(organizer_string)
294 * Determine who is the organizer of this event.
295 * We need to determine "me" or "not me."
297 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
298 if (organizer != NULL) {
299 strcpy(organizer_string, icalproperty_get_organizer(organizer));
300 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
301 strcpy(organizer_string, &organizer_string[7]);
302 striplt(organizer_string);
303 serv_printf("ISME %s", organizer_string);
304 serv_getln(buf, sizeof buf);
311 wprintf("<TR><TD><B>");
312 wprintf(_("Organizer"));
313 wprintf("</B></TD><TD>");
314 escputs(organizer_string);
315 if (organizer_is_me) {
316 wprintf(" <FONT SIZE=-1><I>");
317 wprintf(_("(you are the organizer)"));
318 wprintf("</I></FONT>\n");
322 * Transmit the organizer as a hidden field. We don't want the user
323 * to be able to change it, but we do want it fed back to the server,
324 * especially if this is a new event and there is no organizer already
325 * in the calendar object.
327 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
328 escputs(organizer_string);
331 wprintf("</TD></TR>\n");
334 wprintf("<TR><TD><B>");
335 wprintf(_("Show time as:"));
336 wprintf("</B></TD><TD>");
338 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
340 /* No transparency found. Default to opaque (busy). */
341 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
343 icalcomponent_add_property(vevent, p);
347 v = icalproperty_get_value(p);
353 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
354 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
359 wprintf(" ");
361 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
362 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
368 wprintf("</TD></TR>\n");
371 /* Done with properties. */
372 wprintf("</TABLE>\n");
376 /* Attendees tab (need to move things here) */
378 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
379 wprintf("<TR><TD><B>");
380 wprintf(_("Attendees"));
383 wprintf(_("(One per line)"));
384 wprintf("</font>\n");
386 /* Pop open an address book -- begin */
388 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
390 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
395 /* Pop open an address book -- end */
398 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
399 "onchange=\"EnableOrDisableCheckButton();\" "
400 "onKeyPress=\"EnableOrDisableCheckButton();\" "
401 "ROWS=10 COLS=72 WIDTH=72>\n",
402 (organizer_is_me ? "" : "DISABLED ")
405 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
407 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
408 strcpy(attendee_string, icalproperty_get_attendee(attendee));
409 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
411 /* screen name or email address */
412 strcpy(attendee_string, &attendee_string[7]);
413 striplt(attendee_string);
414 if (i++) wprintf("\n");
415 escputs(attendee_string);
418 /* participant status */
419 partstat_as_string(buf, attendee);
423 wprintf("</TEXTAREA></TD></TR>\n");
424 wprintf("</TABLE>\n");
430 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
432 recur = icalproperty_get_rrule(rrule);
435 /* blank recurrence with some sensible defaults */
436 memset(&recur, 0, sizeof(struct icalrecurrencetype));
438 recur.until = icaltime_null_time();
440 recur.freq = ICAL_WEEKLY_RECURRENCE;
443 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
445 "onclick=\"RecurrenceShowHide();\""
447 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
448 _("This is a recurring event")
451 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
453 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
455 char *frequency_units[] = {
475 wprintf("<tr><td><b>");
476 wprintf(_("Recurrence rule"));
477 wprintf("</b></td><td>");
479 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
480 wprintf("%s ", _("Repeats every"));
482 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
483 wprintf("value=\"%d\"> ", recur.interval);
485 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
486 "onChange=\"RecurrenceShowHide();\">\n");
487 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
488 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
489 ((i == recur.freq) ? "selected " : ""),
490 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
495 wprintf("</select>\n");
497 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
498 wprintf("%s<br>", _("on these weekdays:"));
500 char weekday_is_selected[7];
501 memset(weekday_is_selected, 0, 7);
503 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
504 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
505 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
508 for (j=0; j<7; ++j) {
509 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
510 weekday_is_selected[j] = 1;
516 for (j=0; j<7; ++j) {
517 i = ((j + (int)weekstart) % 7);
518 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
519 if (weekday_is_selected[i]) wprintf(" checked");
520 wprintf(">%s\n", weekday_labels[i]);
522 wprintf("</div>\n"); /* end 'weekday_selector' div */
528 int which_rrmonthtype_is_preselected = 0;
529 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
531 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
532 "value=\"rrmonthtype_mday\" "
533 "%s onChange=\"RecurrenceShowHide();\">",
534 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
537 int rrmday = t_start.day;
538 int rrmweekday = icaltime_day_of_week(t_start) - 1;
540 /* Figure out what week of the month we're in */
541 icaltimetype day1 = t_start;
543 int weekbase = icaltime_week_number(day1);
544 int rrmweek = icaltime_week_number(t_start) - weekbase + 1;
546 /* Are we going by day of the month or week/day? */
548 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
549 which_rrmonthtype_is_preselected = 0;
550 rrmday = recur.by_month_day[0];
552 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
553 which_rrmonthtype_is_preselected = 1;
554 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
555 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
558 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
561 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
562 "value=\"rrmonthtype_wday\" "
563 "%s onChange=\"RecurrenceShowHide();\">",
564 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
567 wprintf(_("on the "));
568 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
569 "onChange=\"RecurrenceShowHide();\">\n");
570 for (i=1; i<=5; ++i) {
571 wprintf("<option %svalue=\"%d\">%s</option>\n",
572 ((i==rrmweek) ? "selected " : ""),
577 wprintf("</select> \n");
579 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
580 "onChange=\"RecurrenceShowHide();\">\n");
581 for (j=0; j<7; ++j) {
582 i = ((j + (int)weekstart) % 7);
583 wprintf("<option %svalue=\"%d\">%s</option>\n",
584 ((i==rrmweekday) ? "selected " : ""),
589 wprintf("</select>");
591 wprintf(" %s<br />\n", _("of the month"));
593 wprintf("</div>\n"); /* end 'monthday_selector' div */
596 int rrymweek = rrmweek;
597 int rrymweekday = rrmweekday;
598 int rrymonth = t_start.month;
599 int which_rryeartype_is_preselected = 0;
602 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
603 && (recur.by_day[0] != 0)
604 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
605 && (recur.by_month[0] != 0)
607 which_rryeartype_is_preselected = 1;
608 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
609 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
610 rrymonth = recur.by_month[0];
613 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
615 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
616 "value=\"rryeartype_ymday\" "
617 "%s onChange=\"RecurrenceShowHide();\">",
618 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
620 wprintf(_("every "));
621 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
623 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
624 "value=\"rryeartype_ywday\" "
625 "%s onChange=\"RecurrenceShowHide();\">",
626 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
629 wprintf(_("on the "));
630 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
631 "onChange=\"RecurrenceShowHide();\">\n");
632 for (i=1; i<=5; ++i) {
633 wprintf("<option %svalue=\"%d\">%s</option>\n",
634 ((i==rrymweek) ? "selected " : ""),
639 wprintf("</select> \n");
641 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
642 "onChange=\"RecurrenceShowHide();\">\n");
643 for (j=0; j<7; ++j) {
644 i = ((j + (int)weekstart) % 7);
645 wprintf("<option %svalue=\"%d\">%s</option>\n",
646 ((i==rrymweekday) ? "selected " : ""),
651 wprintf("</select>");
653 wprintf(" %s ", _("of"));
655 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
656 "onChange=\"RecurrenceShowHide();\">\n");
657 for (i=1; i<=12; ++i) {
658 wprintf("<option %svalue=\"%d\">%s</option>\n",
659 ((i==rrymonth) ? "selected " : ""),
664 wprintf("</select>");
667 wprintf("</div>\n"); /* end 'yearday_selector' div */
669 wprintf("</td></tr>\n");
672 int which_rrend_is_preselected = 0;
673 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
674 if (recur.count > 0) which_rrend_is_preselected = 1;
676 wprintf("<tr><td><b>");
677 wprintf(_("Recurrence range"));
678 wprintf("</b></td><td>\n");
680 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
681 "value=\"rrend_none\" "
682 "%s onChange=\"RecurrenceShowHide();\">",
683 ((which_rrend_is_preselected == 0) ? "checked" : "")
685 wprintf("%s<br />\n", _("No ending date"));
687 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
688 "value=\"rrend_count\" "
689 "%s onChange=\"RecurrenceShowHide();\">",
690 ((which_rrend_is_preselected == 1) ? "checked" : "")
692 wprintf(_("Repeat this event"));
693 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
694 wprintf("value=\"%d\"> ", recur.count);
698 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
699 "value=\"rrend_until\" "
700 "%s onChange=\"RecurrenceShowHide();\">",
701 ((which_rrend_is_preselected == 2) ? "checked" : "")
703 wprintf(_("Repeat this event until "));
705 if (icaltime_is_null_time(recur.until)) {
706 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
708 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
711 wprintf("</td></tr>\n");
713 wprintf("</table>\n");
714 wprintf("</div>\n"); /* end 'rrule' div */
718 /* submit buttons (common area beneath the tabs) */
721 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
723 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
725 "<INPUT TYPE=\"submit\" id=\"check_button\" NAME=\"check_button\" VALUE=\"%s\">\n"
727 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
731 _("Check attendee availability"),
734 wprintf("</FORM>\n");
737 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
739 StrBufAppendPrintf(WC->trailing_javascript,
740 "eventEditAllDay(); \n"
741 "RecurrenceShowHide(); \n"
742 "EnableOrDisableCheckButton(); \n"
744 address_book_popup();
747 if (created_new_vevent) {
748 icalcomponent_free(vevent);
753 * Save an edited event
755 * supplied_vevent: the event to save
756 * msgnum: the index on the citserver
758 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
759 int unread, struct calview *calv) {
762 icalcomponent *vevent, *encaps;
763 int created_new_vevent = 0;
764 int all_day_event = 0;
765 struct icaltimetype event_start, t;
766 icalproperty *attendee = NULL;
767 char attendee_string[SIZ];
770 char form_attendees[SIZ];
771 char organizer_string[SIZ];
773 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
775 if (supplied_vevent != NULL) {
776 vevent = supplied_vevent;
778 /* Convert all timestamps to UTC to make them easier to process. */
779 ical_dezonify(vevent);
782 * If we're looking at a fully encapsulated VCALENDAR
783 * rather than a VEVENT component, attempt to use the first
784 * relevant VEVENT subcomponent. If there is none, the
785 * NULL returned by icalcomponent_get_first_component() will
786 * tell the next iteration of this function to create a
789 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
790 save_individual_event(
791 icalcomponent_get_first_component(
792 vevent, ICAL_VEVENT_COMPONENT),
793 msgnum, from, unread, NULL
799 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
800 created_new_vevent = 1;
803 if ( (havebstr("save_button"))
804 || (havebstr("check_button")) ) {
806 /* Replace values in the component with ones from the form */
808 while (prop = icalcomponent_get_first_property(vevent,
809 ICAL_SUMMARY_PROPERTY), prop != NULL) {
810 icalcomponent_remove_property(vevent, prop);
811 icalproperty_free(prop);
814 if (havebstr("summary")) {
815 icalcomponent_add_property(vevent,
816 icalproperty_new_summary(bstr("summary")));
818 icalcomponent_add_property(vevent,
819 icalproperty_new_summary(_("Untitled Event")));
822 while (prop = icalcomponent_get_first_property(vevent,
823 ICAL_LOCATION_PROPERTY), prop != NULL) {
824 icalcomponent_remove_property(vevent, prop);
825 icalproperty_free(prop);
827 if (havebstr("location")) {
828 icalcomponent_add_property(vevent,
829 icalproperty_new_location(bstr("location")));
831 while (prop = icalcomponent_get_first_property(vevent,
832 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
833 icalcomponent_remove_property(vevent, prop);
834 icalproperty_free(prop);
836 if (havebstr("description")) {
837 icalcomponent_add_property(vevent,
838 icalproperty_new_description(bstr("description")));
841 while (prop = icalcomponent_get_first_property(vevent,
842 ICAL_DTSTART_PROPERTY), prop != NULL) {
843 icalcomponent_remove_property(vevent, prop);
844 icalproperty_free(prop);
847 if (yesbstr("alldayevent")) {
855 icaltime_from_webform_dateonly(&event_start, "dtstart");
858 icaltime_from_webform(&event_start, "dtstart");
861 prop = icalproperty_new_dtstart(event_start);
864 /* Force it to serialize as a date-only rather than date/time */
865 icalproperty_set_value(prop, icalvalue_new_date(event_start));
868 if (prop) icalcomponent_add_property(vevent, prop);
869 else icalproperty_free(prop);
871 while (prop = icalcomponent_get_first_property(vevent,
872 ICAL_DTEND_PROPERTY), prop != NULL) {
873 icalcomponent_remove_property(vevent, prop);
874 icalproperty_free(prop);
876 while (prop = icalcomponent_get_first_property(vevent,
877 ICAL_DURATION_PROPERTY), prop != NULL) {
878 icalcomponent_remove_property(vevent, prop);
879 icalproperty_free(prop);
883 icaltime_from_webform_dateonly(&t, "dtend");
885 /* with this field supposed to be non-inclusive we have to add one day */
886 icaltime_adjust(&t, 1, 0, 0, 0);
889 icaltime_from_webform(&t, "dtend");
892 icalcomponent_add_property(vevent,
893 icalproperty_new_dtend(icaltime_normalize(t)
897 /* recurrence rules -- begin */
899 /* remove any existing rule */
900 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
901 icalcomponent_remove_property(vevent, prop);
902 icalproperty_free(prop);
905 if (yesbstr("is_recur")) {
906 struct icalrecurrencetype recur;
907 icalrecurrencetype_clear(&recur);
909 recur.interval = atoi(bstr("interval"));
910 recur.freq = atoi(bstr("freq"));
914 /* These can't happen; they're disabled. */
915 case ICAL_SECONDLY_RECURRENCE:
917 case ICAL_MINUTELY_RECURRENCE:
919 case ICAL_HOURLY_RECURRENCE:
922 /* Daily is valid but there are no further inputs. */
923 case ICAL_DAILY_RECURRENCE:
926 /* These are the real options. */
928 case ICAL_WEEKLY_RECURRENCE:
930 for (i=0; i<7; ++i) {
931 snprintf(buf, sizeof buf, "weekday%d", i);
932 if (YESBSTR(buf)) recur.by_day[j++] =
933 icalrecurrencetype_day_day_of_week(i+1);
935 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
938 case ICAL_MONTHLY_RECURRENCE:
939 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
940 recur.by_month_day[0] = event_start.day;
941 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
943 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
944 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
945 + atoi(bstr("rrmweekday")) + 1;
946 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
950 case ICAL_YEARLY_RECURRENCE:
951 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
952 /* no further action is needed here */
954 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
955 recur.by_month[0] = atoi(bstr("rrymonth"));
956 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
957 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
958 + atoi(bstr("rrymweekday")) + 1;
959 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
963 /* This one can't happen either. */
964 case ICAL_NO_RECURRENCE:
968 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
969 recur.count = atoi(bstr("rrcount"));
971 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
972 icaltime_from_webform_dateonly(&recur.until, "rruntil");
975 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
978 /* recurrence rules -- end */
980 /* See if transparency is indicated */
981 if (havebstr("transp")) {
982 if (!strcasecmp(bstr("transp"), "opaque")) {
983 formtransp = ICAL_TRANSP_OPAQUE;
985 else if (!strcasecmp(bstr("transp"), "transparent")) {
986 formtransp = ICAL_TRANSP_TRANSPARENT;
989 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
991 icalcomponent_remove_property(vevent, prop);
992 icalproperty_free(prop);
995 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
998 /* Give this event a UID if it doesn't have one. */
999 if (icalcomponent_get_first_property(vevent,
1000 ICAL_UID_PROPERTY) == NULL) {
1002 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1005 /* Increment the sequence ID */
1006 while (prop = icalcomponent_get_first_property(vevent,
1007 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1008 i = icalproperty_get_sequence(prop);
1009 if (i > sequence) sequence = i;
1010 icalcomponent_remove_property(vevent, prop);
1011 icalproperty_free(prop);
1014 icalcomponent_add_property(vevent,
1015 icalproperty_new_sequence(sequence)
1019 * Set the organizer, only if one does not already exist *and*
1020 * the form is supplying one
1022 strcpy(buf, bstr("organizer"));
1023 if ( (icalcomponent_get_first_property(vevent,
1024 ICAL_ORGANIZER_PROPERTY) == NULL)
1025 && (!IsEmptyStr(buf)) ) {
1027 /* set new organizer */
1028 sprintf(organizer_string, "MAILTO:%s", buf);
1029 icalcomponent_add_property(vevent,
1030 icalproperty_new_organizer(organizer_string)
1036 * Add any new attendees listed in the web form
1039 /* First, strip out the parenthesized partstats. */
1040 strcpy(form_attendees, bstr("attendees"));
1041 while ( stripout(form_attendees, '(', ')') != 0);
1043 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1044 j = strlen(form_attendees);
1045 for (i=0; i<j; ++i) {
1046 if (form_attendees[i] == ',') {
1047 form_attendees[i] = '\n';
1048 while (isspace(form_attendees[i+1])) {
1049 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1055 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1056 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1058 if (!IsEmptyStr(buf)) {
1059 sprintf(attendee_string, "MAILTO:%s", buf);
1062 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1063 if (!strcasecmp(attendee_string,
1064 icalproperty_get_attendee(attendee)))
1070 icalcomponent_add_property(vevent,
1071 icalproperty_new_attendee(attendee_string)
1078 * Remove any attendees *not* listed in the web form
1080 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1081 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1082 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1083 strcpy(attendee_string, &attendee_string[7]);
1084 striplt(attendee_string);
1086 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1087 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1089 if (!strcasecmp(buf, attendee_string)) ++foundit;
1092 icalcomponent_remove_property(vevent, attendee);
1093 icalproperty_free(attendee);
1100 * Encapsulate event into full VCALENDAR component. Clone it first,
1101 * for two reasons: one, it's easier to just free the whole thing
1102 * when we're done instead of unbundling, but more importantly, we
1103 * can't encapsulate something that may already be encapsulated
1106 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1108 /* Set the method to PUBLISH */
1109 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1111 /* If the user clicked 'Save' then save it to the server. */
1112 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1113 serv_puts("ENT0 1|||4|||1|");
1114 serv_getln(buf, sizeof buf);
1115 if (buf[0] == '8') {
1116 serv_puts("Content-type: text/calendar");
1118 serv_puts(icalcomponent_as_ical_string(encaps));
1121 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1122 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1125 if (buf[0] == '2') {
1126 strcpy(WC->ImportantMessage, &buf[4]);
1128 icalmemory_free_ring ();
1129 icalcomponent_free(encaps);
1133 /* Or, check attendee availability if the user asked for that. */
1134 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1136 /* Call this function, which does the real work */
1137 check_attendee_availability(encaps);
1139 /* This displays the form again, with our annotations */
1140 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1142 icalcomponent_free(encaps);
1145 if (encaps != NULL) {
1146 icalcomponent_free(encaps);
1153 * If the user clicked 'Delete' then delete it.
1155 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1156 serv_printf("DELE %ld", lbstr("msgnum"));
1157 serv_getln(buf, sizeof buf);
1160 if (created_new_vevent) {
1161 icalcomponent_free(vevent);
1164 /* If this was a save or delete, go back to the calendar or summary view. */
1165 if (!havebstr("check_button")) {
1166 if (!strcasecmp(bstr("calview"), "summary")) {