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];
37 get_pref_long("weekstart", &weekstart, 17);
38 if (weekstart > 6) weekstart = 0;
40 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
41 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
44 /* populate the weekday names - begin */
46 localtime_r(&now, &tm_now);
47 while (tm_now.tm_wday != 0) {
49 localtime_r(&now, &tm_now);
52 localtime_r(&now, &tm_now);
53 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
56 /* populate the weekday names - end */
58 /* populate the month names - begin */
59 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
60 localtime_r(&now, &tm_now);
61 for (i=0; i<12; ++i) {
62 localtime_r(&now, &tm_now);
63 wc_strftime(month_labels[i], 32, "%B", &tm_now);
66 /* populate the month names - end */
69 strcpy(organizer_string, "");
70 strcpy(attendee_string, "");
72 if (supplied_vevent != NULL) {
73 vevent = supplied_vevent;
75 * If we're looking at a fully encapsulated VCALENDAR
76 * rather than a VEVENT component, attempt to use the first
77 * relevant VEVENT subcomponent. If there is none, the
78 * NULL returned by icalcomponent_get_first_component() will
79 * tell the next iteration of this function to create a
82 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
83 display_edit_individual_event(
84 icalcomponent_get_first_component(
85 vevent, ICAL_VEVENT_COMPONENT),
86 msgnum, from, unread, NULL
92 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
93 created_new_vevent = 1;
96 /* Learn the sequence */
97 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
99 sequence = icalproperty_get_sequence(p);
103 output_headers(1, 1, 2, 0, 0, 0);
104 wprintf("<div id=\"banner\">\n");
106 wprintf(_("Add or edit an event"));
110 wprintf("<div id=\"content\" class=\"service\">\n");
112 wprintf("<div class=\"fix_scrollbar_bug\">");
114 /************************************************************
115 * Uncomment this to see the UID in calendar events for debugging
117 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
119 escputs((char *)icalproperty_get_comment(p));
122 wprintf("SEQUENCE == %d<br />\n", sequence);
123 *************************************************************/
125 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
126 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
128 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
130 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
132 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
134 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
136 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
145 tabbed_dialog(3, tabnames);
148 /* Put it in a borderless table so it lines up nicely */
149 wprintf("<TABLE border=0 width=100%%>\n");
151 wprintf("<TR><TD><B>");
152 wprintf(_("Summary"));
153 wprintf("</B></TD><TD>\n"
154 "<INPUT TYPE=\"text\" NAME=\"summary\" "
155 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
156 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
158 escputs((char *)icalproperty_get_comment(p));
160 wprintf("\"></TD></TR>\n");
162 wprintf("<TR><TD><B>");
163 wprintf(_("Location"));
164 wprintf("</B></TD><TD>\n"
165 "<INPUT TYPE=\"text\" NAME=\"location\" "
166 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
167 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
169 escputs((char *)icalproperty_get_comment(p));
171 wprintf("\"></TD></TR>\n");
173 wprintf("<TR><TD><B>");
175 wprintf("</B></TD><TD>\n");
176 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
178 t_start = icalproperty_get_dtstart(p);
179 if (t_start.is_date) {
186 localtime_r(&now, &tm_now);
187 if (havebstr("year")) {
188 tm_now.tm_year = ibstr("year") - 1900;
189 tm_now.tm_mon = ibstr("month") - 1;
190 tm_now.tm_mday = ibstr("day");
192 if (havebstr("hour")) {
193 tm_now.tm_hour = ibstr("hour");
194 tm_now.tm_min = ibstr("minute");
203 t_start = icaltime_from_timet_with_zone(
205 ((yesbstr("alldayevent")) ? 1 : 0),
206 icaltimezone_get_utc_timezone()
211 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
213 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
214 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
216 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
220 wprintf("</TD></TR>\n");
223 * If this is an all-day-event, set the end time to be identical to
224 * the start time (the hour/minute/second will be set to midnight).
225 * Otherwise extract or create it.
227 wprintf("<TR><TD><B>");
229 wprintf("</B></TD><TD id=\"dtendcell\">\n");
230 if (t_start.is_date) {
234 p = icalcomponent_get_first_property(vevent,
235 ICAL_DTEND_PROPERTY);
237 t_end = icalproperty_get_dtend(p);
241 * If this is not an all-day event and there is no
242 * end time specified, make the default one hour
243 * from the start time.
248 t_end = icaltime_normalize(t_end);
249 /* t_end = icaltime_from_timet(now, 0); */
252 display_icaltimetype_as_webform(&t_end, "dtend", 0);
253 wprintf("</TD></TR>\n");
255 wprintf("<TR><TD><B>");
257 wprintf("</B></TD><TD>\n"
258 "<TEXTAREA NAME=\"description\" wrap=soft "
259 "ROWS=5 COLS=80 WIDTH=80>\n"
261 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
263 escputs((char *)icalproperty_get_comment(p));
265 wprintf("</TEXTAREA></TD></TR>");
268 * For a new event, the user creating the event should be the
269 * organizer. Set this field accordingly.
271 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
273 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
274 icalcomponent_add_property(vevent,
275 icalproperty_new_organizer(organizer_string)
280 * Determine who is the organizer of this event.
281 * We need to determine "me" or "not me."
283 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
284 if (organizer != NULL) {
285 strcpy(organizer_string, icalproperty_get_organizer(organizer));
286 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
287 strcpy(organizer_string, &organizer_string[7]);
288 striplt(organizer_string);
289 serv_printf("ISME %s", organizer_string);
290 serv_getln(buf, sizeof buf);
297 wprintf("<TR><TD><B>");
298 wprintf(_("Organizer"));
299 wprintf("</B></TD><TD>");
300 escputs(organizer_string);
301 if (organizer_is_me) {
302 wprintf(" <FONT SIZE=-1><I>");
303 wprintf(_("(you are the organizer)"));
304 wprintf("</I></FONT>\n");
308 * Transmit the organizer as a hidden field. We don't want the user
309 * to be able to change it, but we do want it fed back to the server,
310 * especially if this is a new event and there is no organizer already
311 * in the calendar object.
313 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
314 escputs(organizer_string);
317 wprintf("</TD></TR>\n");
320 wprintf("<TR><TD><B>");
321 wprintf(_("Show time as:"));
322 wprintf("</B></TD><TD>");
324 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
326 /* No transparency found. Default to opaque (busy). */
327 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
329 icalcomponent_add_property(vevent, p);
333 v = icalproperty_get_value(p);
339 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
340 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
345 wprintf(" ");
347 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
348 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
354 wprintf("</TD></TR>\n");
357 /* Done with properties. */
358 wprintf("</TABLE>\n");
362 /* Attendees tab (need to move things here) */
364 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
365 wprintf("<TR><TD><B>");
366 wprintf(_("Attendees"));
369 wprintf(_("(One per line)"));
370 wprintf("</font>\n");
372 /* Pop open an address book -- begin */
374 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
376 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
381 /* Pop open an address book -- end */
384 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
385 "ROWS=3 COLS=80 WIDTH=80>\n",
386 (organizer_is_me ? "" : "DISABLED ")
389 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
391 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
392 strcpy(attendee_string, icalproperty_get_attendee(attendee));
393 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
395 /* screen name or email address */
396 strcpy(attendee_string, &attendee_string[7]);
397 striplt(attendee_string);
398 if (i++) wprintf("\n");
399 escputs(attendee_string);
402 /* participant status */
403 partstat_as_string(buf, attendee);
407 wprintf("</TEXTAREA></TD></TR>\n");
408 wprintf("</TABLE>\n");
413 icalproperty *rrule = NULL;
414 struct icalrecurrencetype recur;
416 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
418 recur = icalproperty_get_rrule(rrule);
421 /* blank recurrence with some sensible defaults */
422 memset(&recur, 0, sizeof(struct icalrecurrencetype));
424 recur.until = icaltime_null_time();
426 recur.freq = ICAL_WEEKLY_RECURRENCE;
429 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
431 "onclick=\"RecurrenceShowHide();\""
433 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
434 _("This is a recurring event")
437 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
439 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
441 /* Table row displaying raw RRULE data, FIXME remove when finished */
443 wprintf("<tr><td><b>");
445 wprintf("</b></td><td>");
446 wprintf("<tt>%s</tt>", icalrecurrencetype_as_string(&recur));
447 wprintf("</td></tr>\n");
450 char *frequency_units[] = {
470 wprintf("<tr><td><b>");
471 wprintf(_("Recurrence rule"));
472 wprintf("</b></td><td>");
474 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
475 wprintf("%s ", _("Repeats every"));
477 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
478 wprintf("value=\"%d\"> ", recur.interval);
480 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
481 "onChange=\"RecurrenceShowHide();\">\n");
482 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
483 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
484 ((i == recur.freq) ? "selected " : ""),
485 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
490 wprintf("</select>\n");
492 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
493 wprintf("%s<br>", _("on these weekdays:"));
495 char weekday_is_selected[7];
496 memset(weekday_is_selected, 0, 7);
498 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
499 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
500 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
503 for (j=0; j<7; ++j) {
504 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
505 weekday_is_selected[j] = 1;
511 for (j=0; j<7; ++j) {
512 i = ((j + (int)weekstart) % 7);
513 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
514 if (weekday_is_selected[i]) wprintf(" checked");
515 wprintf(">%s\n", weekday_labels[i]);
517 wprintf("</div>\n"); /* end 'weekday_selector' div */
523 int which_rrmonthtype_is_preselected = 0;
524 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
526 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
527 "value=\"rrmonthtype_mday\" "
528 "%s onChange=\"RecurrenceShowHide();\">",
529 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
532 int rrmday = t_start.day;
533 int rrmweekday = icaltime_day_of_week(t_start) - 1;
535 /* Figure out what week of the month we're in */
536 icaltimetype day1 = t_start;
538 int weekbase = icaltime_week_number(day1);
539 int rrmweek = icaltime_week_number(t_start) - weekbase + 1;
541 /* Are we going by day of the month or week/day? */
543 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
544 which_rrmonthtype_is_preselected = 0;
545 rrmday = recur.by_month_day[0];
547 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
548 which_rrmonthtype_is_preselected = 1;
549 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
550 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
553 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
556 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
557 "value=\"rrmonthtype_wday\" "
558 "%s onChange=\"RecurrenceShowHide();\">",
559 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
562 wprintf(_("on the "));
563 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
564 "onChange=\"RecurrenceShowHide();\">\n");
565 for (i=1; i<=5; ++i) {
566 wprintf("<option %svalue=\"%d\">%s</option>\n",
567 ((i==rrmweek) ? "selected " : ""),
572 wprintf("</select> \n");
574 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
575 "onChange=\"RecurrenceShowHide();\">\n");
576 for (j=0; j<7; ++j) {
577 i = ((j + (int)weekstart) % 7);
578 wprintf("<option %svalue=\"%d\">%s</option>\n",
579 ((i==rrmweekday) ? "selected " : ""),
584 wprintf("</select>");
586 wprintf(" %s<br />\n", _("of the month"));
588 wprintf("</div>\n"); /* end 'monthday_selector' div */
591 int rrymweek = rrmweek;
592 int rrymweekday = rrmweekday;
593 int rrymonth = t_start.month;
595 lprintf(9, "FIXME: RRYMWEEK %d, RRYMWEEKDAY %d, RRYMONTH %d\n", rrymweek, rrymweekday, rrymonth);
597 int which_rryeartype_is_preselected = 0;
599 if ( (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
600 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) ) {
601 which_rryeartype_is_preselected = 1;
602 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
603 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
604 rrymonth = recur.by_month[0];
607 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
609 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
610 "value=\"rryeartype_ymday\" "
611 "%s onChange=\"RecurrenceShowHide();\">",
612 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
614 wprintf(_("every "));
615 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
617 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
618 "value=\"rryeartype_ywday\" "
619 "%s onChange=\"RecurrenceShowHide();\">",
620 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
623 wprintf(_("on the "));
624 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
625 "onChange=\"RecurrenceShowHide();\">\n");
626 for (i=1; i<=5; ++i) {
627 wprintf("<option %svalue=\"%d\">%s</option>\n",
628 ((i==rrymweek) ? "selected " : ""),
633 wprintf("</select> \n");
635 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
636 "onChange=\"RecurrenceShowHide();\">\n");
637 for (j=0; j<7; ++j) {
638 i = ((j + (int)weekstart) % 7);
639 wprintf("<option %svalue=\"%d\">%s</option>\n",
640 ((i==rrymweekday) ? "selected " : ""),
645 wprintf("</select>");
647 wprintf(" %s ", _("of"));
649 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
650 "onChange=\"RecurrenceShowHide();\">\n");
651 for (i=1; i<=12; ++i) {
652 wprintf("<option %svalue=\"%d\">%s</option>\n",
653 ((i==rrymonth) ? "selected " : ""),
658 wprintf("</select>");
661 wprintf("</div>\n"); /* end 'yearday_selector' div */
663 wprintf("</td></tr>\n");
666 int which_rrend_is_preselected = 0;
667 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
668 if (recur.count > 0) which_rrend_is_preselected = 1;
670 wprintf("<tr><td><b>");
671 wprintf(_("Recurrence range"));
672 wprintf("</b></td><td>\n");
674 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
675 "value=\"rrend_none\" "
676 "%s onChange=\"RecurrenceShowHide();\">",
677 ((which_rrend_is_preselected == 0) ? "checked" : "")
679 wprintf("%s<br />\n", _("No ending date"));
681 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
682 "value=\"rrend_count\" "
683 "%s onChange=\"RecurrenceShowHide();\">",
684 ((which_rrend_is_preselected == 1) ? "checked" : "")
686 wprintf(_("Repeat this event"));
687 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
688 wprintf("value=\"%d\"> ", recur.count);
692 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
693 "value=\"rrend_until\" "
694 "%s onChange=\"RecurrenceShowHide();\">",
695 ((which_rrend_is_preselected == 2) ? "checked" : "")
697 wprintf(_("Repeat this event until "));
699 if (icaltime_is_null_time(recur.until)) {
700 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
702 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
705 wprintf("</td></tr>\n");
707 wprintf("</table>\n");
708 wprintf("</div>\n"); /* end 'rrule' div */
712 /* submit buttons (common area beneath the tabs) */
715 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
717 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
719 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
722 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
726 _("Check attendee availability"),
729 wprintf("</FORM>\n");
732 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
734 StrBufAppendPrintf(WC->trailing_javascript,
735 "eventEditAllDay(); \n"
736 "RecurrenceShowHide(); \n"
738 address_book_popup();
741 if (created_new_vevent) {
742 icalcomponent_free(vevent);
747 * Save an edited event
749 * supplied_vevent: the event to save
750 * msgnum: the index on the citserver
752 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
753 int unread, struct calview *calv) {
756 icalcomponent *vevent, *encaps;
757 int created_new_vevent = 0;
758 int all_day_event = 0;
759 struct icaltimetype event_start, t;
760 icalproperty *attendee = NULL;
761 char attendee_string[SIZ];
764 char form_attendees[SIZ];
765 char organizer_string[SIZ];
767 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
769 if (supplied_vevent != NULL) {
770 vevent = supplied_vevent;
772 * If we're looking at a fully encapsulated VCALENDAR
773 * rather than a VEVENT component, attempt to use the first
774 * relevant VEVENT subcomponent. If there is none, the
775 * NULL returned by icalcomponent_get_first_component() will
776 * tell the next iteration of this function to create a
779 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
780 save_individual_event(
781 icalcomponent_get_first_component(
782 vevent, ICAL_VEVENT_COMPONENT),
783 msgnum, from, unread, NULL
789 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
790 created_new_vevent = 1;
793 if ( (havebstr("save_button"))
794 || (havebstr("check_button")) ) {
796 /* Replace values in the component with ones from the form */
798 while (prop = icalcomponent_get_first_property(vevent,
799 ICAL_SUMMARY_PROPERTY), prop != NULL) {
800 icalcomponent_remove_property(vevent, prop);
801 icalproperty_free(prop);
804 if (havebstr("summary")) {
806 icalcomponent_add_property(vevent,
807 icalproperty_new_summary(bstr("summary")));
809 icalcomponent_add_property(vevent,
810 icalproperty_new_summary("Untitled Event"));
813 while (prop = icalcomponent_get_first_property(vevent,
814 ICAL_LOCATION_PROPERTY), prop != NULL) {
815 icalcomponent_remove_property(vevent, prop);
816 icalproperty_free(prop);
818 if (havebstr("location")) {
819 icalcomponent_add_property(vevent,
820 icalproperty_new_location(bstr("location")));
822 while (prop = icalcomponent_get_first_property(vevent,
823 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
824 icalcomponent_remove_property(vevent, prop);
825 icalproperty_free(prop);
827 if (havebstr("description")) {
828 icalcomponent_add_property(vevent,
829 icalproperty_new_description(bstr("description")));
832 while (prop = icalcomponent_get_first_property(vevent,
833 ICAL_DTSTART_PROPERTY), prop != NULL) {
834 icalcomponent_remove_property(vevent, prop);
835 icalproperty_free(prop);
838 if (yesbstr("alldayevent")) {
846 icaltime_from_webform_dateonly(&event_start, "dtstart");
849 icaltime_from_webform(&event_start, "dtstart");
853 * The following odd-looking snippet of code looks like it
854 * takes some unnecessary steps. It is done this way because
855 * libical incorrectly turns an "all day event" into a normal
856 * event starting at midnight (i.e. it serializes as date/time
857 * instead of just date) unless icalvalue_new_date() is used.
858 * So we force it, if this is an all day event.
860 prop = icalproperty_new_dtstart(event_start);
862 icalproperty_set_value(prop, icalvalue_new_date(event_start));
865 if (prop) icalcomponent_add_property(vevent, prop);
866 else icalproperty_free(prop);
868 while (prop = icalcomponent_get_first_property(vevent,
869 ICAL_DTEND_PROPERTY), prop != NULL) {
870 icalcomponent_remove_property(vevent, prop);
871 icalproperty_free(prop);
873 while (prop = icalcomponent_get_first_property(vevent,
874 ICAL_DURATION_PROPERTY), prop != NULL) {
875 icalcomponent_remove_property(vevent, prop);
876 icalproperty_free(prop);
879 if (all_day_event == 0) {
880 icaltime_from_webform(&t, "dtend");
881 icalcomponent_add_property(vevent,
882 icalproperty_new_dtend(icaltime_normalize(t)
887 /* recurrence rules -- begin */
889 /* remove any existing rule */
890 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
891 icalcomponent_remove_property(vevent, prop);
892 icalproperty_free(prop);
895 if (yesbstr("is_recur")) {
896 struct icalrecurrencetype recur;
897 icalrecurrencetype_clear(&recur);
899 recur.interval = atoi(bstr("interval"));
900 recur.freq = atoi(bstr("freq"));
904 /* These can't happen; they're disabled. */
905 case ICAL_SECONDLY_RECURRENCE:
907 case ICAL_MINUTELY_RECURRENCE:
909 case ICAL_HOURLY_RECURRENCE:
912 /* Daily is valid but there are no further inputs. */
913 case ICAL_DAILY_RECURRENCE:
916 /* These are the real options. */
918 case ICAL_WEEKLY_RECURRENCE:
920 for (i=0; i<7; ++i) {
921 snprintf(buf, sizeof buf, "weekday%d", i);
922 if (YESBSTR(buf)) recur.by_day[j++] =
923 icalrecurrencetype_day_day_of_week(i+1);
925 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
928 case ICAL_MONTHLY_RECURRENCE:
929 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
930 recur.by_month_day[0] = event_start.day;
931 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
933 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
934 lprintf(9, "MONTHLY BY WDAY\n");
938 case ICAL_YEARLY_RECURRENCE:
941 /* This one can't happen either. */
942 case ICAL_NO_RECURRENCE:
946 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
947 recur.count = atoi(bstr("rrcount"));
949 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
950 icaltime_from_webform_dateonly(&recur.until, "rruntil");
953 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
956 /* recurrence rules -- end */
958 /* See if transparency is indicated */
959 if (havebstr("transp")) {
960 if (!strcasecmp(bstr("transp"), "opaque")) {
961 formtransp = ICAL_TRANSP_OPAQUE;
963 else if (!strcasecmp(bstr("transp"), "transparent")) {
964 formtransp = ICAL_TRANSP_TRANSPARENT;
967 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
969 icalcomponent_remove_property(vevent, prop);
970 icalproperty_free(prop);
973 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
976 /* Give this event a UID if it doesn't have one. */
977 if (icalcomponent_get_first_property(vevent,
978 ICAL_UID_PROPERTY) == NULL) {
980 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
983 /* Increment the sequence ID */
984 while (prop = icalcomponent_get_first_property(vevent,
985 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
986 i = icalproperty_get_sequence(prop);
987 if (i > sequence) sequence = i;
988 icalcomponent_remove_property(vevent, prop);
989 icalproperty_free(prop);
992 icalcomponent_add_property(vevent,
993 icalproperty_new_sequence(sequence)
997 * Set the organizer, only if one does not already exist *and*
998 * the form is supplying one
1000 strcpy(buf, bstr("organizer"));
1001 if ( (icalcomponent_get_first_property(vevent,
1002 ICAL_ORGANIZER_PROPERTY) == NULL)
1003 && (!IsEmptyStr(buf)) ) {
1005 /* set new organizer */
1006 sprintf(organizer_string, "MAILTO:%s", buf);
1007 icalcomponent_add_property(vevent,
1008 icalproperty_new_organizer(organizer_string)
1014 * Add any new attendees listed in the web form
1017 /* First, strip out the parenthesized partstats. */
1018 strcpy(form_attendees, bstr("attendees"));
1019 stripout(form_attendees, '(', ')');
1021 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1022 j = strlen(form_attendees);
1023 for (i=0; i<j; ++i) {
1024 if (form_attendees[i] == ',') {
1025 form_attendees[i] = '\n';
1026 while (isspace(form_attendees[i+1])) {
1027 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1033 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1034 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1036 if (!IsEmptyStr(buf)) {
1037 sprintf(attendee_string, "MAILTO:%s", buf);
1040 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1041 if (!strcasecmp(attendee_string,
1042 icalproperty_get_attendee(attendee)))
1048 icalcomponent_add_property(vevent,
1049 icalproperty_new_attendee(attendee_string)
1056 * Remove any attendees *not* listed in the web form
1058 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1059 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1060 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1061 strcpy(attendee_string, &attendee_string[7]);
1062 striplt(attendee_string);
1064 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1065 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1067 if (!strcasecmp(buf, attendee_string)) ++foundit;
1070 icalcomponent_remove_property(vevent, attendee);
1071 icalproperty_free(attendee);
1078 * Encapsulate event into full VCALENDAR component. Clone it first,
1079 * for two reasons: one, it's easier to just free the whole thing
1080 * when we're done instead of unbundling, but more importantly, we
1081 * can't encapsulate something that may already be encapsulated
1084 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1086 /* Set the method to PUBLISH */
1087 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1089 /* If the user clicked 'Save' then save it to the server. */
1090 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1091 serv_puts("ENT0 1|||4|||1|");
1092 serv_getln(buf, sizeof buf);
1093 if (buf[0] == '8') {
1094 serv_puts("Content-type: text/calendar");
1096 serv_puts(icalcomponent_as_ical_string(encaps));
1099 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1100 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1103 if (buf[0] == '2') {
1104 strcpy(WC->ImportantMessage, &buf[4]);
1106 icalmemory_free_ring ();
1107 icalcomponent_free(encaps);
1111 /* Or, check attendee availability if the user asked for that. */
1112 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1114 /* Call this function, which does the real work */
1115 check_attendee_availability(encaps);
1117 /* This displays the form again, with our annotations */
1118 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1120 icalcomponent_free(encaps);
1123 if (encaps != NULL) {
1124 icalcomponent_free(encaps);
1131 * If the user clicked 'Delete' then delete it.
1133 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1134 serv_printf("DELE %ld", lbstr("msgnum"));
1135 serv_getln(buf, sizeof buf);
1138 if (created_new_vevent) {
1139 icalcomponent_free(vevent);
1142 /* If this was a save or delete, go back to the calendar view. */
1143 if (!havebstr("check_button")) {
1144 readloop("readfwd");