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)
28 icalcomponent *vevent;
31 struct icaltimetype t_start, t_end;
34 int created_new_vevent = 0;
35 icalproperty *organizer = NULL;
36 char organizer_string[SIZ];
37 icalproperty *attendee = NULL;
38 char attendee_string[SIZ];
40 int organizer_is_me = 0;
42 /************************************************************
43 * Uncomment this to see the UID in calendar events for debugging
46 char weekday_labels[7][32];
47 char month_labels[12][32];
49 icalproperty *rrule = NULL;
50 struct icalrecurrencetype recur;
51 char weekday_is_selected[7];
52 int which_rrmonthtype_is_preselected = 0;
63 int which_rrend_is_preselected;
64 int which_rryeartype_is_preselected;
67 const char *tabnames[3];
68 const char *frequency_units[8];
69 const char *ordinals[6];
71 frequency_units[0] = _("seconds");
72 frequency_units[1] = _("minutes");
73 frequency_units[2] = _("hours");
74 frequency_units[3] = _("days");
75 frequency_units[4] = _("weeks");
76 frequency_units[5] = _("months");
77 frequency_units[6] = _("years");
78 frequency_units[7] = _("never");
82 ordinals[1] = _("first");
83 ordinals[2] = _("second");
84 ordinals[3] = _("third");
85 ordinals[4] = _("fourth");
86 ordinals[5] = _("fifth");
89 tabnames[0] = _("Event");
90 tabnames[1] = _("Attendees");
91 tabnames[2] = _("Recurrence");
93 get_pref_long("weekstart", &weekstart, 17);
94 if (weekstart > 6) weekstart = 0;
96 syslog(LOG_DEBUG, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
97 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
100 /* populate the weekday names - begin */
102 localtime_r(&now, &tm_now);
103 while (tm_now.tm_wday != 0) {
105 localtime_r(&now, &tm_now);
107 for (i=0; i<7; ++i) {
108 localtime_r(&now, &tm_now);
109 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
112 /* populate the weekday names - end */
114 /* populate the month names - begin */
115 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
116 localtime_r(&now, &tm_now);
117 for (i=0; i<12; ++i) {
118 localtime_r(&now, &tm_now);
119 wc_strftime(month_labels[i], 32, "%B", &tm_now);
122 /* populate the month names - end */
125 strcpy(organizer_string, "");
126 strcpy(attendee_string, "");
128 if (supplied_vevent != NULL) {
129 vevent = supplied_vevent;
131 /* Convert all timestamps to UTC to make them easier to process. */
132 ical_dezonify(vevent);
135 * If we're looking at a fully encapsulated VCALENDAR
136 * rather than a VEVENT component, attempt to use the first
137 * relevant VEVENT subcomponent. If there is none, the
138 * NULL returned by icalcomponent_get_first_component() will
139 * tell the next iteration of this function to create a
142 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
143 display_edit_individual_event(
144 icalcomponent_get_first_component(
145 vevent, ICAL_VEVENT_COMPONENT),
146 msgnum, from, unread, NULL
152 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
153 created_new_vevent = 1;
156 /* Learn the sequence */
157 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
158 /************************************************************
159 * Uncomment this to see the UID in calendar events for debugging
161 sequence = icalproperty_get_sequence(p);
165 output_headers(1, 1, 1, 0, 0, 0);
166 wc_printf("<div id=\"room_banner_override\">\n");
168 wc_printf(_("Add or edit an event"));
170 wc_printf("</div>\n");
172 wc_printf("<div id=\"content\" class=\"service\">\n");
174 /************************************************************
175 * Uncomment this to see the UID in calendar events for debugging
176 wc_printf("UID == ");
177 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
179 escputs((char *)icalproperty_get_comment(p));
182 wc_printf("SEQUENCE == %d<br>\n", sequence);
183 *************************************************************/
185 wc_printf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
186 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
188 wc_printf("<input type=\"hidden\" name=\"go\" value=\"");
189 StrEscAppend(WCC->WBuf, WCC->CurRoom.name, NULL, 0, 0);
192 wc_printf("<input type=\"hidden\" name=\"msgnum\" value=\"%ld\">\n",
194 wc_printf("<input type=\"hidden\" name=\"calview\" value=\"%s\">\n",
196 wc_printf("<input type=\"hidden\" name=\"year\" value=\"%s\">\n",
198 wc_printf("<input type=\"hidden\" name=\"month\" value=\"%s\">\n",
200 wc_printf("<input type=\"hidden\" name=\"day\" value=\"%s\">\n",
204 tabbed_dialog(3, tabnames);
207 /* Put it in a borderless table so it lines up nicely */
208 wc_printf("<table border='0' width='100%%'>\n");
210 wc_printf("<tr><td><b>");
211 wc_printf(_("Summary"));
212 wc_printf("</b></td><td>\n"
213 "<input type=\"text\" name=\"summary\" "
214 "maxlength=\"64\" size=\"64\" value=\"");
215 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
217 escputs((char *)icalproperty_get_comment(p));
219 wc_printf("\"></td></tr>\n");
221 wc_printf("<tr><td><b>");
222 wc_printf(_("Location"));
223 wc_printf("</b></td><td>\n"
224 "<input type=\"text\" name=\"location\" "
225 "maxlength=\"64\" size=\"64\" value=\"");
226 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
228 escputs((char *)icalproperty_get_comment(p));
230 wc_printf("\"></td></tr>\n");
232 wc_printf("<tr><td><b>");
233 wc_printf(_("Start"));
234 wc_printf("</b></td><td>\n");
235 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
237 t_start = icalproperty_get_dtstart(p);
238 if (t_start.is_date) {
245 localtime_r(&now, &tm_now);
246 if (havebstr("year")) {
247 tm_now.tm_year = ibstr("year") - 1900;
248 tm_now.tm_mon = ibstr("month") - 1;
249 tm_now.tm_mday = ibstr("day");
251 if (havebstr("hour")) {
252 tm_now.tm_hour = ibstr("hour");
253 tm_now.tm_min = ibstr("minute");
262 t_start = icaltime_from_timet_with_zone(
264 ((yesbstr("alldayevent")) ? 1 : 0),
265 icaltimezone_get_utc_timezone()
268 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
270 wc_printf("<input type=\"checkbox\" id=\"alldayevent\" name=\"alldayevent\" "
271 "value=\"yes\" onclick=\"eventEditAllDay();\""
273 (t_start.is_date ? "checked=\"checked\"" : "" ),
277 wc_printf("</td></tr>\n");
279 wc_printf("<tr><td><b>");
281 wc_printf("</b></td><td id=\"dtendcell\">\n");
282 p = icalcomponent_get_first_property(vevent,
283 ICAL_DTEND_PROPERTY);
285 t_end = icalproperty_get_dtend(p);
288 * If this is an all-day-event, the end time is set to real end
289 * day + 1, so we have to adjust accordingly.
291 if (t_start.is_date) {
292 icaltime_adjust(&t_end, -1, 0, 0, 0);
296 if (created_new_vevent == 1) {
297 /* set default duration */
298 if (t_start.is_date) {
300 * If this is an all-day-event, set the end time to be identical to
301 * the start time (the hour/minute/second will be set to midnight).
307 * If this is not an all-day event and there is no
308 * end time specified, make the default one hour
309 * from the start time.
314 t_end = icaltime_normalize(t_end);
315 /* t_end = icaltime_from_timet(now, 0); */
320 * If an existing event has no end date/time this is
321 * supposed to mean end = start.
326 display_icaltimetype_as_webform(&t_end, "dtend", 0);
327 wc_printf("</td></tr>\n");
329 wc_printf("<tr><td><b>");
330 wc_printf(_("Notes"));
331 wc_printf("</b></td><td>\n"
332 "<textarea name=\"description\" "
333 "rows='5' cols='72' style='width:72'>\n"
335 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
337 escputs((char *)icalproperty_get_comment(p));
339 wc_printf("</textarea></td></tr>");
342 * For a new event, the user creating the event should be the
343 * organizer. Set this field accordingly.
345 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
347 sprintf(organizer_string, "mailto:%s", ChrPtr(WC->cs_inet_email));
348 icalcomponent_add_property(vevent,
349 icalproperty_new_organizer(organizer_string)
354 * Determine who is the organizer of this event.
355 * We need to determine "me" or "not me."
357 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
358 if (organizer != NULL) {
359 strcpy(organizer_string, icalproperty_get_organizer(organizer));
360 if (!strncasecmp(organizer_string, "mailto:", 7)) {
361 strcpy(organizer_string, &organizer_string[7]);
362 striplt(organizer_string);
363 serv_printf("ISME %s", organizer_string);
364 serv_getln(buf, sizeof buf);
371 wc_printf("<tr><td><b>");
372 wc_printf(_("Organizer"));
373 wc_printf("</b></td><td>");
374 escputs(organizer_string);
375 if (organizer_is_me) {
376 wc_printf(" <font size='-1'><i>");
377 wc_printf(_("(you are the organizer)"));
378 wc_printf("</i></font>\n");
382 * Transmit the organizer as a hidden field. We don't want the user
383 * to be able to change it, but we do want it fed back to the server,
384 * especially if this is a new event and there is no organizer already
385 * in the calendar object.
387 wc_printf("<input type=\"hidden\" name=\"organizer\" value=\"");
388 escputs(organizer_string);
391 wc_printf("</td></tr>\n");
394 wc_printf("<tr><td><b>");
395 wc_printf(_("Show time as:"));
396 wc_printf("</b></td><td>");
398 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
400 /* No transparency found. Default to opaque (busy). */
401 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
403 icalcomponent_add_property(vevent, p);
407 v = icalproperty_get_value(p);
413 wc_printf("<input type=\"radio\" name=\"transp\" value=\"transparent\"");
414 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
415 wc_printf(" CHECKED");
418 wc_printf(_("Free"));
419 wc_printf(" ");
421 wc_printf("<input type=\"radio\" name=\"transp\" value=\"opaque\"");
422 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
423 wc_printf(" CHECKED");
426 wc_printf(_("Busy"));
428 wc_printf("</td></tr>\n");
431 /* Done with properties. */
432 wc_printf("</TABLE>\n");
436 /* Attendees tab (need to move things here) */
438 wc_printf("<table border='0' width='100%%'>\n"); /* same table style as the event tab */
439 wc_printf("<tr><td><b>");
440 wc_printf(_("Attendees"));
443 wc_printf(_("(One per line)"));
444 wc_printf("</font>\n");
446 /* Pop open an address book -- begin */
448 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
450 "<img alt='' align='middle' border='0' width='16' height='16' src=\"static/webcit_icons/essen/16x16/contact.png\">"
455 /* Pop open an address book -- end */
457 wc_printf("</td><td>"
458 "<textarea %s name=\"attendees\" id=\"attendees_box\" "
459 "onchange=\"EnableOrDisableCheckButton();\" "
460 "onKeyPress=\"EnableOrDisableCheckButton();\" "
461 "rows='10' cols='72' style='width:72'>\n",
462 (organizer_is_me ? "" : "disabled='disabled' ")
465 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
467 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
468 ch = icalproperty_get_attendee(attendee);
469 if ((ch != NULL) && !strncasecmp(ch, "mailto:", 7)) {
471 /* screen name or email address */
472 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
473 striplt(attendee_string);
474 if (i++) wc_printf("\n");
475 escputs(attendee_string);
478 /* participant status */
479 partstat_as_string(buf, attendee);
483 wc_printf("</textarea></td></tr>\n");
484 wc_printf("</table>\n");
490 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
492 recur = icalproperty_get_rrule(rrule);
495 /* blank recurrence with some sensible defaults */
496 memset(&recur, 0, sizeof(struct icalrecurrencetype));
498 recur.until = icaltime_null_time();
500 recur.freq = ICAL_WEEKLY_RECURRENCE;
503 wc_printf("<input type=\"checkbox\" id=\"is_recur\" name=\"is_recur\" "
505 "onclick=\"RecurrenceShowHide();\""
507 (rrule ? "checked=\"checked\"" : "" ),
508 _("This is a recurring event")
511 wc_printf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
513 wc_printf("<table border='0' cellspacing='10' width='100%%'>\n");
515 wc_printf("<tr><td><b>");
516 wc_printf(_("Recurrence rule"));
517 wc_printf("</b></td><td>");
519 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
520 wc_printf("%s ", _("Repeats every"));
522 wc_printf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
523 wc_printf("value=\"%d\"> ", recur.interval);
525 wc_printf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
526 "onChange=\"RecurrenceShowHide();\">\n");
527 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
528 wc_printf("<option %s%svalue=\"%d\">%s</option>\n",
529 ((i == recur.freq) ? "selected='selected' " : ""),
530 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled='disabled' "),
535 wc_printf("</select>\n");
537 wc_printf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
538 wc_printf("%s<br>", _("on these weekdays:"));
540 memset(weekday_is_selected, 0, 7);
542 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
543 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
544 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
547 for (j=0; j<7; ++j) {
548 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
549 weekday_is_selected[j] = 1;
555 for (j=0; j<7; ++j) {
556 i = ((j + (int)weekstart) % 7);
557 wc_printf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
558 if (weekday_is_selected[i]) wc_printf(" checked='checked'");
559 wc_printf(">%s\n", weekday_labels[i]);
561 wc_printf("</div>\n"); /* end 'weekday_selector' div */
567 wc_printf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
569 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
570 "value=\"rrmonthtype_mday\" "
571 "%s onChange=\"RecurrenceShowHide();\">",
572 ((which_rrmonthtype_is_preselected == 0) ? "checked='checked'" : "")
575 rrmday = t_start.day;
576 rrmweekday = icaltime_day_of_week(t_start) - 1;
578 /* Figure out what week of the month we're in */
581 weekbase = icaltime_week_number(day1);
582 rrmweek = icaltime_week_number(t_start) - weekbase + 1;
584 /* Are we going by day of the month or week/day? */
586 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
587 which_rrmonthtype_is_preselected = 0;
588 rrmday = recur.by_month_day[0];
590 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
591 which_rrmonthtype_is_preselected = 1;
592 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
593 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
596 wc_printf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
599 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
600 "value=\"rrmonthtype_wday\" "
601 "%s onChange=\"RecurrenceShowHide();\">",
602 ((which_rrmonthtype_is_preselected == 1) ? "checked='checked'" : "")
605 wc_printf(_("on the "));
606 wc_printf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
607 "onChange=\"RecurrenceShowHide();\">\n");
608 for (i=1; i<=5; ++i) {
609 wc_printf("<option %svalue=\"%d\">%s</option>\n",
610 ((i==rrmweek) ? "selected='selected' " : ""),
615 wc_printf("</select> \n");
617 wc_printf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
618 "onChange=\"RecurrenceShowHide();\">\n");
619 for (j=0; j<7; ++j) {
620 i = ((j + (int)weekstart) % 7);
621 wc_printf("<option %svalue=\"%d\">%s</option>\n",
622 ((i==rrmweekday) ? "selected='selected' " : ""),
627 wc_printf("</select>");
629 wc_printf(" %s<br>\n", _("of the month"));
631 wc_printf("</div>\n"); /* end 'monthday_selector' div */
635 rrymweekday = rrmweekday;
636 rrymonth = t_start.month;
637 which_rryeartype_is_preselected = 0;
640 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
641 && (recur.by_day[0] != 0)
642 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
643 && (recur.by_month[0] != 0)
645 which_rryeartype_is_preselected = 1;
646 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
647 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
648 rrymonth = recur.by_month[0];
651 wc_printf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
653 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
654 "value=\"rryeartype_ymday\" "
655 "%s onChange=\"RecurrenceShowHide();\">",
656 ((which_rryeartype_is_preselected == 0) ? "checked='checked'" : "")
658 wc_printf(_("every "));
659 wc_printf("<span id=\"ymday\">%s</span><br>", _("year on this date"));
661 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
662 "value=\"rryeartype_ywday\" "
663 "%s onChange=\"RecurrenceShowHide();\">",
664 ((which_rryeartype_is_preselected == 1) ? "checked='checked'" : "")
667 wc_printf(_("on the "));
668 wc_printf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
669 "onChange=\"RecurrenceShowHide();\">\n");
670 for (i=1; i<=5; ++i) {
671 wc_printf("<option %svalue=\"%d\">%s</option>\n",
672 ((i==rrymweek) ? "selected='selected' " : ""),
677 wc_printf("</select> \n");
679 wc_printf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
680 "onChange=\"RecurrenceShowHide();\">\n");
681 for (j=0; j<7; ++j) {
682 i = ((j + (int)weekstart) % 7);
683 wc_printf("<option %svalue=\"%d\">%s</option>\n",
684 ((i==rrymweekday) ? "selected='selected' " : ""),
689 wc_printf("</select>");
691 wc_printf(" %s ", _("of"));
693 wc_printf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
694 "onChange=\"RecurrenceShowHide();\">\n");
695 for (i=1; i<=12; ++i) {
696 wc_printf("<option %svalue=\"%d\">%s</option>\n",
697 ((i==rrymonth) ? "selected='selected' " : ""),
702 wc_printf("</select>");
705 wc_printf("</div>\n"); /* end 'yearday_selector' div */
707 wc_printf("</td></tr>\n");
710 which_rrend_is_preselected = 0;
711 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
712 if (recur.count > 0) which_rrend_is_preselected = 1;
714 wc_printf("<tr><td><b>");
715 wc_printf(_("Recurrence range"));
716 wc_printf("</b></td><td>\n");
718 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
719 "value=\"rrend_none\" "
720 "%s onChange=\"RecurrenceShowHide();\">",
721 ((which_rrend_is_preselected == 0) ? "checked='checked'" : "")
723 wc_printf("%s<br>\n", _("No ending date"));
725 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
726 "value=\"rrend_count\" "
727 "%s onChange=\"RecurrenceShowHide();\">",
728 ((which_rrend_is_preselected == 1) ? "checked='checked'" : "")
730 wc_printf(_("Repeat this event"));
731 wc_printf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
732 wc_printf("value=\"%d\"> ", recur.count);
733 wc_printf(_("times"));
736 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
737 "value=\"rrend_until\" "
738 "%s onChange=\"RecurrenceShowHide();\">",
739 ((which_rrend_is_preselected == 2) ? "checked='checked'" : "")
741 wc_printf(_("Repeat this event until "));
743 if (icaltime_is_null_time(recur.until)) {
744 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
746 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
749 wc_printf("</td></tr>\n");
751 wc_printf("</table>\n");
752 wc_printf("</div>\n"); /* end 'rrule' div */
756 /* submit buttons (common area beneath the tabs) */
759 "<input type=\"submit\" name=\"save_button\" value=\"%s\">"
761 "<input type=\"submit\" name=\"delete_button\" value=\"%s\">\n"
763 "<input type=\"submit\" id=\"check_button\" name=\"check_button\" value=\"%s\">\n"
765 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n"
769 _("Check attendee availability"),
773 wc_printf("</form>\n");
775 StrBufAppendPrintf(WC->trailing_javascript,
776 "eventEditAllDay(); \n"
777 "RecurrenceShowHide(); \n"
778 "EnableOrDisableCheckButton(); \n"
780 do_template("addressbook_popup");
784 if (created_new_vevent) {
785 icalcomponent_free(vevent);
790 * Save an edited event
792 * supplied_vevent: the event to save
793 * msgnum: the index on the citserver
795 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
796 int unread, calview *calv) {
800 icalcomponent *vevent, *encaps;
801 int created_new_vevent = 0;
802 int all_day_event = 0;
803 struct icaltimetype event_start, t;
804 icalproperty *attendee = NULL;
805 char attendee_string[SIZ];
808 char form_attendees[SIZ];
809 char organizer_string[SIZ];
811 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
814 if (supplied_vevent != NULL) {
815 vevent = supplied_vevent;
817 /* Convert all timestamps to UTC to make them easier to process. */
818 ical_dezonify(vevent);
821 * If we're looking at a fully encapsulated VCALENDAR
822 * rather than a VEVENT component, attempt to use the first
823 * relevant VEVENT subcomponent. If there is none, the
824 * NULL returned by icalcomponent_get_first_component() will
825 * tell the next iteration of this function to create a
828 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
829 save_individual_event(
830 icalcomponent_get_first_component(
831 vevent, ICAL_VEVENT_COMPONENT),
832 msgnum, from, unread, NULL
838 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
839 created_new_vevent = 1;
842 if ( (havebstr("save_button"))
843 || (havebstr("check_button")) ) {
845 /* Replace values in the component with ones from the form */
847 while (prop = icalcomponent_get_first_property(vevent,
848 ICAL_SUMMARY_PROPERTY), prop != NULL) {
849 icalcomponent_remove_property(vevent, prop);
850 icalproperty_free(prop);
853 /* Add NOW() to the calendar object... */
854 icalcomponent_set_dtstamp(vevent,
855 icaltime_from_timet_with_zone(
856 time(NULL), 0, icaltimezone_get_utc_timezone()));
858 if (havebstr("summary")) {
859 icalcomponent_add_property(vevent,
860 icalproperty_new_summary(bstr("summary")));
862 icalcomponent_add_property(vevent,
863 icalproperty_new_summary(_("Untitled Event")));
866 while (prop = icalcomponent_get_first_property(vevent,
867 ICAL_LOCATION_PROPERTY), prop != NULL) {
868 icalcomponent_remove_property(vevent, prop);
869 icalproperty_free(prop);
871 if (havebstr("location")) {
872 icalcomponent_add_property(vevent,
873 icalproperty_new_location(bstr("location")));
875 while (prop = icalcomponent_get_first_property(vevent,
876 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
877 icalcomponent_remove_property(vevent, prop);
878 icalproperty_free(prop);
880 if (havebstr("description")) {
881 icalcomponent_add_property(vevent,
882 icalproperty_new_description(bstr("description")));
885 while (prop = icalcomponent_get_first_property(vevent,
886 ICAL_DTSTART_PROPERTY), prop != NULL) {
887 icalcomponent_remove_property(vevent, prop);
888 icalproperty_free(prop);
891 if (yesbstr("alldayevent")) {
899 icaltime_from_webform_dateonly(&event_start, "dtstart");
902 icaltime_from_webform(&event_start, "dtstart");
905 prop = icalproperty_new_dtstart(event_start);
908 /* Force it to serialize as a date-only rather than date/time */
909 icalproperty_set_value(prop, icalvalue_new_date(event_start));
912 if (prop) icalcomponent_add_property(vevent, prop);
913 else icalproperty_free(prop);
915 while (prop = icalcomponent_get_first_property(vevent,
916 ICAL_DTEND_PROPERTY), prop != NULL) {
917 icalcomponent_remove_property(vevent, prop);
918 icalproperty_free(prop);
920 while (prop = icalcomponent_get_first_property(vevent,
921 ICAL_DURATION_PROPERTY), prop != NULL) {
922 icalcomponent_remove_property(vevent, prop);
923 icalproperty_free(prop);
927 icaltime_from_webform_dateonly(&t, "dtend");
929 /* with this field supposed to be non-inclusive we have to add one day */
930 icaltime_adjust(&t, 1, 0, 0, 0);
933 icaltime_from_webform(&t, "dtend");
936 icalcomponent_add_property(vevent,
937 icalproperty_new_dtend(icaltime_normalize(t)
941 /* recurrence rules -- begin */
943 /* remove any existing rule */
944 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
945 icalcomponent_remove_property(vevent, prop);
946 icalproperty_free(prop);
949 if (yesbstr("is_recur")) {
950 struct icalrecurrencetype recur;
951 icalrecurrencetype_clear(&recur);
953 recur.interval = atoi(bstr("interval"));
954 recur.freq = atoi(bstr("freq"));
958 /* These can't happen; they're disabled. */
959 case ICAL_SECONDLY_RECURRENCE:
961 case ICAL_MINUTELY_RECURRENCE:
963 case ICAL_HOURLY_RECURRENCE:
966 /* Daily is valid but there are no further inputs. */
967 case ICAL_DAILY_RECURRENCE:
970 /* These are the real options. */
972 case ICAL_WEEKLY_RECURRENCE:
974 for (i=0; i<7; ++i) {
975 snprintf(buf, sizeof buf, "weekday%d", i);
976 if (YESBSTR(buf)) recur.by_day[j++] =
977 icalrecurrencetype_day_day_of_week(i+1);
979 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
982 case ICAL_MONTHLY_RECURRENCE:
983 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
984 recur.by_month_day[0] = event_start.day;
985 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
987 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
988 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
989 + atoi(bstr("rrmweekday")) + 1;
990 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
994 case ICAL_YEARLY_RECURRENCE:
995 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
996 /* no further action is needed here */
998 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
999 recur.by_month[0] = atoi(bstr("rrymonth"));
1000 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
1001 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
1002 + atoi(bstr("rrymweekday")) + 1;
1003 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
1007 /* This one can't happen either. */
1008 case ICAL_NO_RECURRENCE:
1012 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
1013 recur.count = atoi(bstr("rrcount"));
1015 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
1016 icaltime_from_webform_dateonly(&recur.until, "rruntil");
1019 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
1022 /* recurrence rules -- end */
1024 /* See if transparency is indicated */
1025 if (havebstr("transp")) {
1026 if (!strcasecmp(bstr("transp"), "opaque")) {
1027 formtransp = ICAL_TRANSP_OPAQUE;
1029 else if (!strcasecmp(bstr("transp"), "transparent")) {
1030 formtransp = ICAL_TRANSP_TRANSPARENT;
1033 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1035 icalcomponent_remove_property(vevent, prop);
1036 icalproperty_free(prop);
1039 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1042 /* Give this event a UID if it doesn't have one. */
1043 if (icalcomponent_get_first_property(vevent,
1044 ICAL_UID_PROPERTY) == NULL) {
1046 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1049 /* Increment the sequence ID */
1050 while (prop = icalcomponent_get_first_property(vevent,
1051 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1052 i = icalproperty_get_sequence(prop);
1053 if (i > sequence) sequence = i;
1054 icalcomponent_remove_property(vevent, prop);
1055 icalproperty_free(prop);
1058 icalcomponent_add_property(vevent,
1059 icalproperty_new_sequence(sequence)
1063 * Set the organizer, only if one does not already exist *and*
1064 * the form is supplying one
1066 strcpy(buf, bstr("organizer"));
1067 if ( (icalcomponent_get_first_property(vevent,
1068 ICAL_ORGANIZER_PROPERTY) == NULL)
1069 && (!IsEmptyStr(buf)) ) {
1071 /* set new organizer */
1072 sprintf(organizer_string, "MAILTO:%s", buf);
1073 icalcomponent_add_property(vevent,
1074 icalproperty_new_organizer(organizer_string)
1080 * Add any new attendees listed in the web form
1083 /* First, strip out the parenthesized partstats. */
1084 strcpy(form_attendees, bstr("attendees"));
1085 while ( stripout(form_attendees, '(', ')') != 0);
1087 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1088 j = strlen(form_attendees);
1089 for (i=0; i<j; ++i) {
1090 if (form_attendees[i] == ',') {
1091 form_attendees[i] = '\n';
1092 while (isspace(form_attendees[i+1])) {
1093 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1099 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1100 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1102 if (!IsEmptyStr(buf)) {
1103 sprintf(attendee_string, "MAILTO:%s", buf);
1106 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1107 ch = icalproperty_get_attendee(attendee);
1108 if ((ch != NULL) && !strcasecmp(attendee_string, ch))
1114 icalcomponent_add_property(vevent,
1115 icalproperty_new_attendee(attendee_string)
1122 * Remove any attendees *not* listed in the web form
1124 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1125 ch = icalproperty_get_attendee(attendee);
1126 if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) {
1127 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
1128 striplt(attendee_string);
1130 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1131 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1133 if (!strcasecmp(buf, attendee_string)) ++foundit;
1136 icalcomponent_remove_property(vevent, attendee);
1137 icalproperty_free(attendee);
1144 * Encapsulate event into full VCALENDAR component. Clone it first,
1145 * for two reasons: one, it's easier to just free the whole thing
1146 * when we're done instead of unbundling, but more importantly, we
1147 * can't encapsulate something that may already be encapsulated
1150 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1152 /* Set the method to PUBLISH */
1153 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1155 /* If the user clicked 'Save' then save it to the server. */
1156 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1157 serv_puts("ENT0 1|||4|||1|");
1158 serv_getln(buf, sizeof buf);
1161 serv_puts("Content-type: text/calendar");
1162 serv_puts("Content-Transfer-Encoding: quoted-printable");
1164 Buf = NewStrBufPlain(icalcomponent_as_ical_string(encaps), -1);
1165 text_to_server_qp(Buf);
1167 // serv_puts(icalcomponent_as_ical_string(encaps));
1170 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {}
1173 AppendImportantMessage(buf + 4, - 1);
1178 icalmemory_free_ring ();
1179 icalcomponent_free(encaps);
1183 /* Or, check attendee availability if the user asked for that. */
1184 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1186 /* Call this function, which does the real work */
1187 check_attendee_availability(encaps);
1189 /* This displays the form again, with our annotations */
1190 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1192 icalcomponent_free(encaps);
1195 if (encaps != NULL) {
1196 icalcomponent_free(encaps);
1203 * If the user clicked 'Delete' then delete it.
1205 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1206 serv_printf("DELE %ld", lbstr("msgnum"));
1207 serv_getln(buf, sizeof buf);
1210 if (created_new_vevent) {
1211 icalcomponent_free(vevent);
1214 /* If this was a save or delete, go back to the calendar or summary view. */
1215 if (!havebstr("check_button")) {
1216 if (!strcasecmp(bstr("calview"), "summary")) {
1217 display_summary_page();
1220 readloop(readfwd, eUseDefault);