2 * Editing calendar events.
4 * Copyright (c) 1996-2012 by the citadel.org team
6 * This program is open source software. You can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include "webserver.h"
20 * Display an event by itself (for editing)
21 * supplied_vevent the event to edit
22 * msgnum reference on the citserver
24 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
25 int unread, calview *calv)
27 icalcomponent *vevent;
30 struct icaltimetype t_start, t_end;
33 int created_new_vevent = 0;
34 icalproperty *organizer = NULL;
35 char organizer_string[SIZ];
36 icalproperty *attendee = NULL;
37 char attendee_string[SIZ];
39 int organizer_is_me = 0;
41 /************************************************************
42 * Uncomment this to see the UID in calendar events for debugging
45 char weekday_labels[7][32];
46 char month_labels[12][32];
48 icalproperty *rrule = NULL;
49 struct icalrecurrencetype recur;
50 char weekday_is_selected[7];
51 int which_rrmonthtype_is_preselected = 0;
62 int which_rrend_is_preselected;
63 int which_rryeartype_is_preselected;
67 const char *frequency_units[8];
68 const char *ordinals[6];
70 frequency_units[0] = _("seconds");
71 frequency_units[1] = _("minutes");
72 frequency_units[2] = _("hours");
73 frequency_units[3] = _("days");
74 frequency_units[4] = _("weeks");
75 frequency_units[5] = _("months");
76 frequency_units[6] = _("years");
77 frequency_units[7] = _("never");
81 ordinals[1] = _("first");
82 ordinals[2] = _("second");
83 ordinals[3] = _("third");
84 ordinals[4] = _("fourth");
85 ordinals[5] = _("fifth");
88 tabnames[0] = _("Event");
89 tabnames[1] = _("Attendees");
90 tabnames[2] = _("Recurrence");
92 get_pref_long("weekstart", &weekstart, 17);
93 if (weekstart > 6) weekstart = 0;
95 syslog(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
96 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
99 /* populate the weekday names - begin */
101 localtime_r(&now, &tm_now);
102 while (tm_now.tm_wday != 0) {
104 localtime_r(&now, &tm_now);
106 for (i=0; i<7; ++i) {
107 localtime_r(&now, &tm_now);
108 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
111 /* populate the weekday names - end */
113 /* populate the month names - begin */
114 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
115 localtime_r(&now, &tm_now);
116 for (i=0; i<12; ++i) {
117 localtime_r(&now, &tm_now);
118 wc_strftime(month_labels[i], 32, "%B", &tm_now);
121 /* populate the month names - end */
124 strcpy(organizer_string, "");
125 strcpy(attendee_string, "");
127 if (supplied_vevent != NULL) {
128 vevent = supplied_vevent;
130 /* Convert all timestamps to UTC to make them easier to process. */
131 ical_dezonify(vevent);
134 * If we're looking at a fully encapsulated VCALENDAR
135 * rather than a VEVENT component, attempt to use the first
136 * relevant VEVENT subcomponent. If there is none, the
137 * NULL returned by icalcomponent_get_first_component() will
138 * tell the next iteration of this function to create a
141 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
142 display_edit_individual_event(
143 icalcomponent_get_first_component(
144 vevent, ICAL_VEVENT_COMPONENT),
145 msgnum, from, unread, NULL
151 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
152 created_new_vevent = 1;
155 /* Learn the sequence */
156 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
157 /************************************************************
158 * Uncomment this to see the UID in calendar events for debugging
160 sequence = icalproperty_get_sequence(p);
164 output_headers(1, 1, 1, 0, 0, 0);
165 wc_printf("<div id=\"room_banner_override\">\n");
167 wc_printf(_("Add or edit an event"));
169 wc_printf("</div>\n");
171 wc_printf("<div id=\"content\" class=\"service\">\n");
173 /************************************************************
174 * Uncomment this to see the UID in calendar events for debugging
175 wc_printf("UID == ");
176 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
178 escputs((char *)icalproperty_get_comment(p));
181 wc_printf("SEQUENCE == %d<br>\n", sequence);
182 *************************************************************/
184 wc_printf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
185 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
187 wc_printf("<input type=\"hidden\" name=\"msgnum\" value=\"%ld\">\n",
189 wc_printf("<input type=\"hidden\" name=\"calview\" value=\"%s\">\n",
191 wc_printf("<input type=\"hidden\" name=\"year\" value=\"%s\">\n",
193 wc_printf("<input type=\"hidden\" name=\"month\" value=\"%s\">\n",
195 wc_printf("<input type=\"hidden\" name=\"day\" value=\"%s\">\n",
199 tabbed_dialog(3, tabnames);
202 /* Put it in a borderless table so it lines up nicely */
203 wc_printf("<table border='0' width='100%%'>\n");
205 wc_printf("<tr><td><b>");
206 wc_printf(_("Summary"));
207 wc_printf("</b></td><td>\n"
208 "<input type=\"text\" name=\"summary\" "
209 "maxlength=\"64\" size=\"64\" value=\"");
210 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
212 escputs((char *)icalproperty_get_comment(p));
214 wc_printf("\"></td></tr>\n");
216 wc_printf("<tr><td><b>");
217 wc_printf(_("Location"));
218 wc_printf("</b></td><td>\n"
219 "<input type=\"text\" name=\"location\" "
220 "maxlength=\"64\" size=\"64\" value=\"");
221 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
223 escputs((char *)icalproperty_get_comment(p));
225 wc_printf("\"></td></tr>\n");
227 wc_printf("<tr><td><b>");
228 wc_printf(_("Start"));
229 wc_printf("</b></td><td>\n");
230 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
232 t_start = icalproperty_get_dtstart(p);
233 if (t_start.is_date) {
240 localtime_r(&now, &tm_now);
241 if (havebstr("year")) {
242 tm_now.tm_year = ibstr("year") - 1900;
243 tm_now.tm_mon = ibstr("month") - 1;
244 tm_now.tm_mday = ibstr("day");
246 if (havebstr("hour")) {
247 tm_now.tm_hour = ibstr("hour");
248 tm_now.tm_min = ibstr("minute");
257 t_start = icaltime_from_timet_with_zone(
259 ((yesbstr("alldayevent")) ? 1 : 0),
260 icaltimezone_get_utc_timezone()
265 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
267 wc_printf("<input type=\"checkbox\" id=\"alldayevent\" name=\"alldayevent\" "
268 "value=\"yes\" onclick=\"eventEditAllDay();\""
270 (t_start.is_date ? "checked=\"checked\"" : "" ),
274 wc_printf("</td></tr>\n");
276 wc_printf("<tr><td><b>");
278 wc_printf("</b></td><td id=\"dtendcell\">\n");
279 p = icalcomponent_get_first_property(vevent,
280 ICAL_DTEND_PROPERTY);
282 t_end = icalproperty_get_dtend(p);
285 * If this is an all-day-event, the end time is set to real end
286 * day + 1, so we have to adjust accordingly.
288 if (t_start.is_date) {
289 icaltime_adjust(&t_end, -1, 0, 0, 0);
293 if (created_new_vevent == 1) {
294 /* set default duration */
295 if (t_start.is_date) {
297 * If this is an all-day-event, set the end time to be identical to
298 * the start time (the hour/minute/second will be set to midnight).
304 * If this is not an all-day event and there is no
305 * end time specified, make the default one hour
306 * from the start time.
311 t_end = icaltime_normalize(t_end);
312 /* t_end = icaltime_from_timet(now, 0); */
317 * If an existing event has no end date/time this is
318 * supposed to mean end = start.
323 display_icaltimetype_as_webform(&t_end, "dtend", 0);
324 wc_printf("</td></tr>\n");
326 wc_printf("<tr><td><b>");
327 wc_printf(_("Notes"));
328 wc_printf("</b></td><td>\n"
329 "<textarea name=\"description\" "
330 "rows='5' cols='72' style='width:72'>\n"
332 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
334 escputs((char *)icalproperty_get_comment(p));
336 wc_printf("</textarea></td></tr>");
339 * For a new event, the user creating the event should be the
340 * organizer. Set this field accordingly.
342 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
344 sprintf(organizer_string, "mailto:%s", ChrPtr(WC->cs_inet_email));
345 icalcomponent_add_property(vevent,
346 icalproperty_new_organizer(organizer_string)
351 * Determine who is the organizer of this event.
352 * We need to determine "me" or "not me."
354 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
355 if (organizer != NULL) {
356 strcpy(organizer_string, icalproperty_get_organizer(organizer));
357 if (!strncasecmp(organizer_string, "mailto:", 7)) {
358 strcpy(organizer_string, &organizer_string[7]);
359 striplt(organizer_string);
360 serv_printf("ISME %s", organizer_string);
361 serv_getln(buf, sizeof buf);
368 wc_printf("<tr><td><b>");
369 wc_printf(_("Organizer"));
370 wc_printf("</b></td><td>");
371 escputs(organizer_string);
372 if (organizer_is_me) {
373 wc_printf(" <font size='-1'><i>");
374 wc_printf(_("(you are the organizer)"));
375 wc_printf("</i></font>\n");
379 * Transmit the organizer as a hidden field. We don't want the user
380 * to be able to change it, but we do want it fed back to the server,
381 * especially if this is a new event and there is no organizer already
382 * in the calendar object.
384 wc_printf("<input type=\"hidden\" name=\"organizer\" value=\"");
385 escputs(organizer_string);
388 wc_printf("</td></tr>\n");
391 wc_printf("<tr><td><b>");
392 wc_printf(_("Show time as:"));
393 wc_printf("</b></td><td>");
395 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
397 /* No transparency found. Default to opaque (busy). */
398 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
400 icalcomponent_add_property(vevent, p);
404 v = icalproperty_get_value(p);
410 wc_printf("<input type=\"radio\" name=\"transp\" value=\"transparent\"");
411 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
412 wc_printf(" CHECKED");
415 wc_printf(_("Free"));
416 wc_printf(" ");
418 wc_printf("<input type=\"radio\" name=\"transp\" value=\"opaque\"");
419 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
420 wc_printf(" CHECKED");
423 wc_printf(_("Busy"));
425 wc_printf("</td></tr>\n");
428 /* Done with properties. */
429 wc_printf("</TABLE>\n");
433 /* Attendees tab (need to move things here) */
435 wc_printf("<table border='0' width='100%%'>\n"); /* same table style as the event tab */
436 wc_printf("<tr><td><b>");
437 wc_printf(_("Attendees"));
440 wc_printf(_("(One per line)"));
441 wc_printf("</font>\n");
443 /* Pop open an address book -- begin */
445 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
447 "<img alt='' align='middle' border='0' width='16' height='16' src=\"static/webcit_icons/essen/16x16/contact.png\">"
452 /* Pop open an address book -- end */
454 wc_printf("</td><td>"
455 "<textarea %s name=\"attendees\" id=\"attendees_box\" "
456 "onchange=\"EnableOrDisableCheckButton();\" "
457 "onKeyPress=\"EnableOrDisableCheckButton();\" "
458 "rows='10' cols='72' style='width:72'>\n",
459 (organizer_is_me ? "" : "disabled='disabled' ")
462 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
464 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
465 ch = icalproperty_get_attendee(attendee);
466 if ((ch != NULL) && !strncasecmp(ch, "mailto:", 7)) {
468 /* screen name or email address */
469 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
470 striplt(attendee_string);
471 if (i++) wc_printf("\n");
472 escputs(attendee_string);
475 /* participant status */
476 partstat_as_string(buf, attendee);
480 wc_printf("</textarea></td></tr>\n");
481 wc_printf("</table>\n");
487 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
489 recur = icalproperty_get_rrule(rrule);
492 /* blank recurrence with some sensible defaults */
493 memset(&recur, 0, sizeof(struct icalrecurrencetype));
495 recur.until = icaltime_null_time();
497 recur.freq = ICAL_WEEKLY_RECURRENCE;
500 wc_printf("<input type=\"checkbox\" id=\"is_recur\" name=\"is_recur\" "
502 "onclick=\"RecurrenceShowHide();\""
504 (rrule ? "checked=\"checked\"" : "" ),
505 _("This is a recurring event")
508 wc_printf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
510 wc_printf("<table border='0' cellspacing='10' width='100%%'>\n");
512 wc_printf("<tr><td><b>");
513 wc_printf(_("Recurrence rule"));
514 wc_printf("</b></td><td>");
516 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
517 wc_printf("%s ", _("Repeats every"));
519 wc_printf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
520 wc_printf("value=\"%d\"> ", recur.interval);
522 wc_printf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
523 "onChange=\"RecurrenceShowHide();\">\n");
524 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
525 wc_printf("<option %s%svalue=\"%d\">%s</option>\n",
526 ((i == recur.freq) ? "selected='selected' " : ""),
527 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled='disabled' "),
532 wc_printf("</select>\n");
534 wc_printf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
535 wc_printf("%s<br>", _("on these weekdays:"));
537 memset(weekday_is_selected, 0, 7);
539 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
540 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
541 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
544 for (j=0; j<7; ++j) {
545 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
546 weekday_is_selected[j] = 1;
552 for (j=0; j<7; ++j) {
553 i = ((j + (int)weekstart) % 7);
554 wc_printf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
555 if (weekday_is_selected[i]) wc_printf(" checked='checked'");
556 wc_printf(">%s\n", weekday_labels[i]);
558 wc_printf("</div>\n"); /* end 'weekday_selector' div */
564 wc_printf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
566 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
567 "value=\"rrmonthtype_mday\" "
568 "%s onChange=\"RecurrenceShowHide();\">",
569 ((which_rrmonthtype_is_preselected == 0) ? "checked='checked'" : "")
572 rrmday = t_start.day;
573 rrmweekday = icaltime_day_of_week(t_start) - 1;
575 /* Figure out what week of the month we're in */
578 weekbase = icaltime_week_number(day1);
579 rrmweek = icaltime_week_number(t_start) - weekbase + 1;
581 /* Are we going by day of the month or week/day? */
583 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
584 which_rrmonthtype_is_preselected = 0;
585 rrmday = recur.by_month_day[0];
587 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
588 which_rrmonthtype_is_preselected = 1;
589 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
590 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
593 wc_printf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
596 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
597 "value=\"rrmonthtype_wday\" "
598 "%s onChange=\"RecurrenceShowHide();\">",
599 ((which_rrmonthtype_is_preselected == 1) ? "checked='checked'" : "")
602 wc_printf(_("on the "));
603 wc_printf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
604 "onChange=\"RecurrenceShowHide();\">\n");
605 for (i=1; i<=5; ++i) {
606 wc_printf("<option %svalue=\"%d\">%s</option>\n",
607 ((i==rrmweek) ? "selected='selected' " : ""),
612 wc_printf("</select> \n");
614 wc_printf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
615 "onChange=\"RecurrenceShowHide();\">\n");
616 for (j=0; j<7; ++j) {
617 i = ((j + (int)weekstart) % 7);
618 wc_printf("<option %svalue=\"%d\">%s</option>\n",
619 ((i==rrmweekday) ? "selected='selected' " : ""),
624 wc_printf("</select>");
626 wc_printf(" %s<br>\n", _("of the month"));
628 wc_printf("</div>\n"); /* end 'monthday_selector' div */
632 rrymweekday = rrmweekday;
633 rrymonth = t_start.month;
634 which_rryeartype_is_preselected = 0;
637 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
638 && (recur.by_day[0] != 0)
639 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
640 && (recur.by_month[0] != 0)
642 which_rryeartype_is_preselected = 1;
643 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
644 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
645 rrymonth = recur.by_month[0];
648 wc_printf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
650 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
651 "value=\"rryeartype_ymday\" "
652 "%s onChange=\"RecurrenceShowHide();\">",
653 ((which_rryeartype_is_preselected == 0) ? "checked='checked'" : "")
655 wc_printf(_("every "));
656 wc_printf("<span id=\"ymday\">%s</span><br>", _("year on this date"));
658 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
659 "value=\"rryeartype_ywday\" "
660 "%s onChange=\"RecurrenceShowHide();\">",
661 ((which_rryeartype_is_preselected == 1) ? "checked='checked'" : "")
664 wc_printf(_("on the "));
665 wc_printf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
666 "onChange=\"RecurrenceShowHide();\">\n");
667 for (i=1; i<=5; ++i) {
668 wc_printf("<option %svalue=\"%d\">%s</option>\n",
669 ((i==rrymweek) ? "selected='selected' " : ""),
674 wc_printf("</select> \n");
676 wc_printf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
677 "onChange=\"RecurrenceShowHide();\">\n");
678 for (j=0; j<7; ++j) {
679 i = ((j + (int)weekstart) % 7);
680 wc_printf("<option %svalue=\"%d\">%s</option>\n",
681 ((i==rrymweekday) ? "selected='selected' " : ""),
686 wc_printf("</select>");
688 wc_printf(" %s ", _("of"));
690 wc_printf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
691 "onChange=\"RecurrenceShowHide();\">\n");
692 for (i=1; i<=12; ++i) {
693 wc_printf("<option %svalue=\"%d\">%s</option>\n",
694 ((i==rrymonth) ? "selected='selected' " : ""),
699 wc_printf("</select>");
702 wc_printf("</div>\n"); /* end 'yearday_selector' div */
704 wc_printf("</td></tr>\n");
707 which_rrend_is_preselected = 0;
708 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
709 if (recur.count > 0) which_rrend_is_preselected = 1;
711 wc_printf("<tr><td><b>");
712 wc_printf(_("Recurrence range"));
713 wc_printf("</b></td><td>\n");
715 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
716 "value=\"rrend_none\" "
717 "%s onChange=\"RecurrenceShowHide();\">",
718 ((which_rrend_is_preselected == 0) ? "checked='checked'" : "")
720 wc_printf("%s<br>\n", _("No ending date"));
722 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
723 "value=\"rrend_count\" "
724 "%s onChange=\"RecurrenceShowHide();\">",
725 ((which_rrend_is_preselected == 1) ? "checked='checked'" : "")
727 wc_printf(_("Repeat this event"));
728 wc_printf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
729 wc_printf("value=\"%d\"> ", recur.count);
730 wc_printf(_("times"));
733 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
734 "value=\"rrend_until\" "
735 "%s onChange=\"RecurrenceShowHide();\">",
736 ((which_rrend_is_preselected == 2) ? "checked='checked'" : "")
738 wc_printf(_("Repeat this event until "));
740 if (icaltime_is_null_time(recur.until)) {
741 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
743 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
746 wc_printf("</td></tr>\n");
748 wc_printf("</table>\n");
749 wc_printf("</div>\n"); /* end 'rrule' div */
753 /* submit buttons (common area beneath the tabs) */
756 "<input type=\"submit\" name=\"save_button\" value=\"%s\">"
758 "<input type=\"submit\" name=\"delete_button\" value=\"%s\">\n"
760 "<input type=\"submit\" id=\"check_button\" name=\"check_button\" value=\"%s\">\n"
762 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n"
766 _("Check attendee availability"),
770 wc_printf("</form>\n");
772 StrBufAppendPrintf(WC->trailing_javascript,
773 "eventEditAllDay(); \n"
774 "RecurrenceShowHide(); \n"
775 "EnableOrDisableCheckButton(); \n"
777 address_book_popup();
780 if (created_new_vevent) {
781 icalcomponent_free(vevent);
786 * Save an edited event
788 * supplied_vevent: the event to save
789 * msgnum: the index on the citserver
791 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
792 int unread, calview *calv) {
795 icalcomponent *vevent, *encaps;
796 int created_new_vevent = 0;
797 int all_day_event = 0;
798 struct icaltimetype event_start, t;
799 icalproperty *attendee = NULL;
800 char attendee_string[SIZ];
803 char form_attendees[SIZ];
804 char organizer_string[SIZ];
806 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
809 if (supplied_vevent != NULL) {
810 vevent = supplied_vevent;
812 /* Convert all timestamps to UTC to make them easier to process. */
813 ical_dezonify(vevent);
816 * If we're looking at a fully encapsulated VCALENDAR
817 * rather than a VEVENT component, attempt to use the first
818 * relevant VEVENT subcomponent. If there is none, the
819 * NULL returned by icalcomponent_get_first_component() will
820 * tell the next iteration of this function to create a
823 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
824 save_individual_event(
825 icalcomponent_get_first_component(
826 vevent, ICAL_VEVENT_COMPONENT),
827 msgnum, from, unread, NULL
833 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
834 created_new_vevent = 1;
837 if ( (havebstr("save_button"))
838 || (havebstr("check_button")) ) {
840 /* Replace values in the component with ones from the form */
842 while (prop = icalcomponent_get_first_property(vevent,
843 ICAL_SUMMARY_PROPERTY), prop != NULL) {
844 icalcomponent_remove_property(vevent, prop);
845 icalproperty_free(prop);
848 /* Add NOW() to the calendar object... */
849 icalcomponent_set_dtstamp(vevent,
853 if (havebstr("summary")) {
854 icalcomponent_add_property(vevent,
855 icalproperty_new_summary(bstr("summary")));
857 icalcomponent_add_property(vevent,
858 icalproperty_new_summary(_("Untitled Event")));
861 while (prop = icalcomponent_get_first_property(vevent,
862 ICAL_LOCATION_PROPERTY), prop != NULL) {
863 icalcomponent_remove_property(vevent, prop);
864 icalproperty_free(prop);
866 if (havebstr("location")) {
867 icalcomponent_add_property(vevent,
868 icalproperty_new_location(bstr("location")));
870 while (prop = icalcomponent_get_first_property(vevent,
871 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
872 icalcomponent_remove_property(vevent, prop);
873 icalproperty_free(prop);
875 if (havebstr("description")) {
876 icalcomponent_add_property(vevent,
877 icalproperty_new_description(bstr("description")));
880 while (prop = icalcomponent_get_first_property(vevent,
881 ICAL_DTSTART_PROPERTY), prop != NULL) {
882 icalcomponent_remove_property(vevent, prop);
883 icalproperty_free(prop);
886 if (yesbstr("alldayevent")) {
894 icaltime_from_webform_dateonly(&event_start, "dtstart");
897 icaltime_from_webform(&event_start, "dtstart");
900 prop = icalproperty_new_dtstart(event_start);
903 /* Force it to serialize as a date-only rather than date/time */
904 icalproperty_set_value(prop, icalvalue_new_date(event_start));
907 if (prop) icalcomponent_add_property(vevent, prop);
908 else icalproperty_free(prop);
910 while (prop = icalcomponent_get_first_property(vevent,
911 ICAL_DTEND_PROPERTY), prop != NULL) {
912 icalcomponent_remove_property(vevent, prop);
913 icalproperty_free(prop);
915 while (prop = icalcomponent_get_first_property(vevent,
916 ICAL_DURATION_PROPERTY), prop != NULL) {
917 icalcomponent_remove_property(vevent, prop);
918 icalproperty_free(prop);
922 icaltime_from_webform_dateonly(&t, "dtend");
924 /* with this field supposed to be non-inclusive we have to add one day */
925 icaltime_adjust(&t, 1, 0, 0, 0);
928 icaltime_from_webform(&t, "dtend");
931 icalcomponent_add_property(vevent,
932 icalproperty_new_dtend(icaltime_normalize(t)
936 /* recurrence rules -- begin */
938 /* remove any existing rule */
939 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
940 icalcomponent_remove_property(vevent, prop);
941 icalproperty_free(prop);
944 if (yesbstr("is_recur")) {
945 struct icalrecurrencetype recur;
946 icalrecurrencetype_clear(&recur);
948 recur.interval = atoi(bstr("interval"));
949 recur.freq = atoi(bstr("freq"));
953 /* These can't happen; they're disabled. */
954 case ICAL_SECONDLY_RECURRENCE:
956 case ICAL_MINUTELY_RECURRENCE:
958 case ICAL_HOURLY_RECURRENCE:
961 /* Daily is valid but there are no further inputs. */
962 case ICAL_DAILY_RECURRENCE:
965 /* These are the real options. */
967 case ICAL_WEEKLY_RECURRENCE:
969 for (i=0; i<7; ++i) {
970 snprintf(buf, sizeof buf, "weekday%d", i);
971 if (YESBSTR(buf)) recur.by_day[j++] =
972 icalrecurrencetype_day_day_of_week(i+1);
974 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
977 case ICAL_MONTHLY_RECURRENCE:
978 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
979 recur.by_month_day[0] = event_start.day;
980 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
982 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
983 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
984 + atoi(bstr("rrmweekday")) + 1;
985 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
989 case ICAL_YEARLY_RECURRENCE:
990 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
991 /* no further action is needed here */
993 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
994 recur.by_month[0] = atoi(bstr("rrymonth"));
995 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
996 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
997 + atoi(bstr("rrymweekday")) + 1;
998 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
1002 /* This one can't happen either. */
1003 case ICAL_NO_RECURRENCE:
1007 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
1008 recur.count = atoi(bstr("rrcount"));
1010 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
1011 icaltime_from_webform_dateonly(&recur.until, "rruntil");
1014 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
1017 /* recurrence rules -- end */
1019 /* See if transparency is indicated */
1020 if (havebstr("transp")) {
1021 if (!strcasecmp(bstr("transp"), "opaque")) {
1022 formtransp = ICAL_TRANSP_OPAQUE;
1024 else if (!strcasecmp(bstr("transp"), "transparent")) {
1025 formtransp = ICAL_TRANSP_TRANSPARENT;
1028 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1030 icalcomponent_remove_property(vevent, prop);
1031 icalproperty_free(prop);
1034 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1037 /* Give this event a UID if it doesn't have one. */
1038 if (icalcomponent_get_first_property(vevent,
1039 ICAL_UID_PROPERTY) == NULL) {
1041 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1044 /* Increment the sequence ID */
1045 while (prop = icalcomponent_get_first_property(vevent,
1046 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1047 i = icalproperty_get_sequence(prop);
1048 if (i > sequence) sequence = i;
1049 icalcomponent_remove_property(vevent, prop);
1050 icalproperty_free(prop);
1053 icalcomponent_add_property(vevent,
1054 icalproperty_new_sequence(sequence)
1058 * Set the organizer, only if one does not already exist *and*
1059 * the form is supplying one
1061 strcpy(buf, bstr("organizer"));
1062 if ( (icalcomponent_get_first_property(vevent,
1063 ICAL_ORGANIZER_PROPERTY) == NULL)
1064 && (!IsEmptyStr(buf)) ) {
1066 /* set new organizer */
1067 sprintf(organizer_string, "MAILTO:%s", buf);
1068 icalcomponent_add_property(vevent,
1069 icalproperty_new_organizer(organizer_string)
1075 * Add any new attendees listed in the web form
1078 /* First, strip out the parenthesized partstats. */
1079 strcpy(form_attendees, bstr("attendees"));
1080 while ( stripout(form_attendees, '(', ')') != 0);
1082 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1083 j = strlen(form_attendees);
1084 for (i=0; i<j; ++i) {
1085 if (form_attendees[i] == ',') {
1086 form_attendees[i] = '\n';
1087 while (isspace(form_attendees[i+1])) {
1088 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1094 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1095 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1097 if (!IsEmptyStr(buf)) {
1098 sprintf(attendee_string, "MAILTO:%s", buf);
1101 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1102 ch = icalproperty_get_attendee(attendee);
1103 if ((ch != NULL) && !strcasecmp(attendee_string, ch))
1109 icalcomponent_add_property(vevent,
1110 icalproperty_new_attendee(attendee_string)
1117 * Remove any attendees *not* listed in the web form
1119 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1120 ch = icalproperty_get_attendee(attendee);
1121 if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) {
1122 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
1123 striplt(attendee_string);
1125 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1126 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1128 if (!strcasecmp(buf, attendee_string)) ++foundit;
1131 icalcomponent_remove_property(vevent, attendee);
1132 icalproperty_free(attendee);
1139 * Encapsulate event into full VCALENDAR component. Clone it first,
1140 * for two reasons: one, it's easier to just free the whole thing
1141 * when we're done instead of unbundling, but more importantly, we
1142 * can't encapsulate something that may already be encapsulated
1145 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1147 /* Set the method to PUBLISH */
1148 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1150 /* If the user clicked 'Save' then save it to the server. */
1151 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1152 serv_puts("ENT0 1|||4|||1|");
1153 serv_getln(buf, sizeof buf);
1156 serv_puts("Content-type: text/calendar");
1157 serv_puts("Content-Transfer-Encoding: quoted-printable");
1159 text_to_server_qp(icalcomponent_as_ical_string(encaps));
1160 // serv_puts(icalcomponent_as_ical_string(encaps));
1163 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {}
1166 AppendImportantMessage(buf + 4, - 1);
1171 icalmemory_free_ring ();
1172 icalcomponent_free(encaps);
1176 /* Or, check attendee availability if the user asked for that. */
1177 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1179 /* Call this function, which does the real work */
1180 check_attendee_availability(encaps);
1182 /* This displays the form again, with our annotations */
1183 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1185 icalcomponent_free(encaps);
1188 if (encaps != NULL) {
1189 icalcomponent_free(encaps);
1196 * If the user clicked 'Delete' then delete it.
1198 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1199 serv_printf("DELE %ld", lbstr("msgnum"));
1200 serv_getln(buf, sizeof buf);
1203 if (created_new_vevent) {
1204 icalcomponent_free(vevent);
1207 /* If this was a save or delete, go back to the calendar or summary view. */
1208 if (!havebstr("check_button")) {
1209 if (!strcasecmp(bstr("calview"), "summary")) {
1210 display_summary_page();
1213 readloop(readfwd, eUseDefault);