2 * Editing calendar events.
4 * Copyright (c) 1996-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
26 * Display an event by itself (for editing)
27 * supplied_vevent the event to edit
28 * msgnum reference on the citserver
30 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
31 int unread, calview *calv)
33 icalcomponent *vevent;
36 struct icaltimetype t_start, t_end;
39 int created_new_vevent = 0;
40 icalproperty *organizer = NULL;
41 char organizer_string[SIZ];
42 icalproperty *attendee = NULL;
43 char attendee_string[SIZ];
45 int organizer_is_me = 0;
48 char weekday_labels[7][32];
49 char month_labels[12][32];
51 icalproperty *rrule = NULL;
52 struct icalrecurrencetype recur;
53 char weekday_is_selected[7];
54 int which_rrmonthtype_is_preselected = 0;
65 int which_rrend_is_preselected;
66 int which_rryeartype_is_preselected;
70 const char *frequency_units[8];
71 const char *ordinals[6];
73 frequency_units[0] = _("seconds");
74 frequency_units[1] = _("minutes");
75 frequency_units[2] = _("hours");
76 frequency_units[3] = _("days");
77 frequency_units[4] = _("weeks");
78 frequency_units[5] = _("months");
79 frequency_units[6] = _("years");
80 frequency_units[7] = _("never");
84 ordinals[1] = _("first");
85 ordinals[2] = _("second");
86 ordinals[3] = _("third");
87 ordinals[4] = _("fourth");
88 ordinals[5] = _("fifth");
91 tabnames[0] = _("Event");
92 tabnames[1] = _("Attendees");
93 tabnames[2] = _("Recurrence");
95 get_pref_long("weekstart", &weekstart, 17);
96 if (weekstart > 6) weekstart = 0;
98 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
99 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
102 /* populate the weekday names - begin */
104 localtime_r(&now, &tm_now);
105 while (tm_now.tm_wday != 0) {
107 localtime_r(&now, &tm_now);
109 for (i=0; i<7; ++i) {
110 localtime_r(&now, &tm_now);
111 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
114 /* populate the weekday names - end */
116 /* populate the month names - begin */
117 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
118 localtime_r(&now, &tm_now);
119 for (i=0; i<12; ++i) {
120 localtime_r(&now, &tm_now);
121 wc_strftime(month_labels[i], 32, "%B", &tm_now);
124 /* populate the month names - end */
127 strcpy(organizer_string, "");
128 strcpy(attendee_string, "");
130 if (supplied_vevent != NULL) {
131 vevent = supplied_vevent;
133 /* Convert all timestamps to UTC to make them easier to process. */
134 ical_dezonify(vevent);
137 * If we're looking at a fully encapsulated VCALENDAR
138 * rather than a VEVENT component, attempt to use the first
139 * relevant VEVENT subcomponent. If there is none, the
140 * NULL returned by icalcomponent_get_first_component() will
141 * tell the next iteration of this function to create a
144 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
145 display_edit_individual_event(
146 icalcomponent_get_first_component(
147 vevent, ICAL_VEVENT_COMPONENT),
148 msgnum, from, unread, NULL
154 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
155 created_new_vevent = 1;
158 /* Learn the sequence */
159 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
161 sequence = icalproperty_get_sequence(p);
165 output_headers(1, 1, 2, 0, 0, 0);
166 wc_printf("<div id=\"banner\">\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));
181 wc_printf("<br />\n");
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=\"msgnum\" value=\"%ld\">\n",
190 wc_printf("<input type=\"hidden\" name=\"calview\" value=\"%s\">\n",
192 wc_printf("<input type=\"hidden\" name=\"year\" value=\"%s\">\n",
194 wc_printf("<input type=\"hidden\" name=\"month\" value=\"%s\">\n",
196 wc_printf("<input type=\"hidden\" name=\"day\" value=\"%s\">\n",
200 tabbed_dialog(3, tabnames);
203 /* Put it in a borderless table so it lines up nicely */
204 wc_printf("<table border='0' width='100%%'>\n");
206 wc_printf("<tr><td><b>");
207 wc_printf(_("Summary"));
208 wc_printf("</b></td><td>\n"
209 "<input type=\"text\" name=\"summary\" "
210 "maxlength=\"64\" size=\"64\" value=\"");
211 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
213 escputs((char *)icalproperty_get_comment(p));
215 wc_printf("\"></td></tr>\n");
217 wc_printf("<tr><td><b>");
218 wc_printf(_("Location"));
219 wc_printf("</b></td><td>\n"
220 "<input type=\"text\" name=\"location\" "
221 "maxlength=\"64\" size=\"64\" value=\"");
222 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
224 escputs((char *)icalproperty_get_comment(p));
226 wc_printf("\"></td></tr>\n");
228 wc_printf("<tr><td><b>");
229 wc_printf(_("Start"));
230 wc_printf("</b></td><td>\n");
231 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
233 t_start = icalproperty_get_dtstart(p);
234 if (t_start.is_date) {
241 localtime_r(&now, &tm_now);
242 if (havebstr("year")) {
243 tm_now.tm_year = ibstr("year") - 1900;
244 tm_now.tm_mon = ibstr("month") - 1;
245 tm_now.tm_mday = ibstr("day");
247 if (havebstr("hour")) {
248 tm_now.tm_hour = ibstr("hour");
249 tm_now.tm_min = ibstr("minute");
258 t_start = icaltime_from_timet_with_zone(
260 ((yesbstr("alldayevent")) ? 1 : 0),
261 icaltimezone_get_utc_timezone()
266 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
268 wc_printf("<input type=\"checkbox\" id=\"alldayevent\" name=\"alldayevent\" "
269 "value=\"yes\" onclick=\"eventEditAllDay();\""
271 (t_start.is_date ? "checked=\"checked\"" : "" ),
275 wc_printf("</td></tr>\n");
277 wc_printf("<tr><td><b>");
279 wc_printf("</b></td><td id=\"dtendcell\">\n");
280 p = icalcomponent_get_first_property(vevent,
281 ICAL_DTEND_PROPERTY);
283 t_end = icalproperty_get_dtend(p);
286 * If this is an all-day-event, the end time is set to real end
287 * day + 1, so we have to adjust accordingly.
289 if (t_start.is_date) {
290 icaltime_adjust(&t_end, -1, 0, 0, 0);
294 if (created_new_vevent == 1) {
295 /* set default duration */
296 if (t_start.is_date) {
298 * If this is an all-day-event, set the end time to be identical to
299 * the start time (the hour/minute/second will be set to midnight).
305 * If this is not an all-day event and there is no
306 * end time specified, make the default one hour
307 * from the start time.
312 t_end = icaltime_normalize(t_end);
313 /* t_end = icaltime_from_timet(now, 0); */
318 * If an existing event has no end date/time this is
319 * supposed to mean end = start.
324 display_icaltimetype_as_webform(&t_end, "dtend", 0);
325 wc_printf("</td></tr>\n");
327 wc_printf("<tr><td><b>");
328 wc_printf(_("Notes"));
329 wc_printf("</b></td><td>\n"
330 "<textarea name=\"description\" "
331 "rows='5' cols='72' style='width:72'>\n"
333 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
335 escputs((char *)icalproperty_get_comment(p));
337 wc_printf("</textarea></td></tr>");
340 * For a new event, the user creating the event should be the
341 * organizer. Set this field accordingly.
343 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
345 sprintf(organizer_string, "mailto:%s", ChrPtr(WC->cs_inet_email));
346 icalcomponent_add_property(vevent,
347 icalproperty_new_organizer(organizer_string)
352 * Determine who is the organizer of this event.
353 * We need to determine "me" or "not me."
355 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
356 if (organizer != NULL) {
357 strcpy(organizer_string, icalproperty_get_organizer(organizer));
358 if (!strncasecmp(organizer_string, "mailto:", 7)) {
359 strcpy(organizer_string, &organizer_string[7]);
360 striplt(organizer_string);
361 serv_printf("ISME %s", organizer_string);
362 serv_getln(buf, sizeof buf);
369 wc_printf("<tr><td><b>");
370 wc_printf(_("Organizer"));
371 wc_printf("</b></td><td>");
372 escputs(organizer_string);
373 if (organizer_is_me) {
374 wc_printf(" <font size='-1'><i>");
375 wc_printf(_("(you are the organizer)"));
376 wc_printf("</i></font>\n");
380 * Transmit the organizer as a hidden field. We don't want the user
381 * to be able to change it, but we do want it fed back to the server,
382 * especially if this is a new event and there is no organizer already
383 * in the calendar object.
385 wc_printf("<input type=\"hidden\" name=\"organizer\" value=\"");
386 escputs(organizer_string);
389 wc_printf("</td></tr>\n");
392 wc_printf("<tr><td><b>");
393 wc_printf(_("Show time as:"));
394 wc_printf("</b></td><td>");
396 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
398 /* No transparency found. Default to opaque (busy). */
399 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
401 icalcomponent_add_property(vevent, p);
405 v = icalproperty_get_value(p);
411 wc_printf("<input type=\"radio\" name=\"transp\" value=\"transparent\"");
412 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
413 wc_printf(" CHECKED");
416 wc_printf(_("Free"));
417 wc_printf(" ");
419 wc_printf("<input type=\"radio\" name=\"transp\" value=\"opaque\"");
420 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
421 wc_printf(" CHECKED");
424 wc_printf(_("Busy"));
426 wc_printf("</td></tr>\n");
429 /* Done with properties. */
430 wc_printf("</TABLE>\n");
434 /* Attendees tab (need to move things here) */
436 wc_printf("<table border='0' width='100%%'>\n"); /* same table style as the event tab */
437 wc_printf("<tr><td><b>");
438 wc_printf(_("Attendees"));
439 wc_printf("</b><br />"
441 wc_printf(_("(One per line)"));
442 wc_printf("</font>\n");
444 /* Pop open an address book -- begin */
446 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
448 "<img alt='' align='middle' border='0' width='24' height='24' src=\"static/viewcontacts_24x.gif\">"
453 /* Pop open an address book -- end */
455 wc_printf("</td><td>"
456 "<textarea %s name=\"attendees\" id=\"attendees_box\" "
457 "onchange=\"EnableOrDisableCheckButton();\" "
458 "onKeyPress=\"EnableOrDisableCheckButton();\" "
459 "rows='10' cols='72' style='width:72'>\n",
460 (organizer_is_me ? "" : "disabled='disabled' ")
463 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
465 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
466 strcpy(attendee_string, icalproperty_get_attendee(attendee));
467 if (!strncasecmp(attendee_string, "mailto:", 7)) {
469 /* screen name or email address */
470 strcpy(attendee_string, &attendee_string[7]);
471 striplt(attendee_string);
472 if (i++) wc_printf("\n");
473 escputs(attendee_string);
476 /* participant status */
477 partstat_as_string(buf, attendee);
481 wc_printf("</textarea></td></tr>\n");
482 wc_printf("</table>\n");
488 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
490 recur = icalproperty_get_rrule(rrule);
493 /* blank recurrence with some sensible defaults */
494 memset(&recur, 0, sizeof(struct icalrecurrencetype));
496 recur.until = icaltime_null_time();
498 recur.freq = ICAL_WEEKLY_RECURRENCE;
501 wc_printf("<input type=\"checkbox\" id=\"is_recur\" name=\"is_recur\" "
503 "onclick=\"RecurrenceShowHide();\""
505 (rrule ? "checked=\"checked\"" : "" ),
506 _("This is a recurring event")
509 wc_printf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
511 wc_printf("<table border='0' cellspacing='10' width='100%%'>\n");
513 wc_printf("<tr><td><b>");
514 wc_printf(_("Recurrence rule"));
515 wc_printf("</b></td><td>");
517 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
518 wc_printf("%s ", _("Repeats every"));
520 wc_printf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
521 wc_printf("value=\"%d\"> ", recur.interval);
523 wc_printf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
524 "onChange=\"RecurrenceShowHide();\">\n");
525 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
526 wc_printf("<option %s%svalue=\"%d\">%s</option>\n",
527 ((i == recur.freq) ? "selected='selected' " : ""),
528 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled='disabled' "),
533 wc_printf("</select>\n");
535 wc_printf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
536 wc_printf("%s<br>", _("on these weekdays:"));
538 memset(weekday_is_selected, 0, 7);
540 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
541 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
542 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
545 for (j=0; j<7; ++j) {
546 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
547 weekday_is_selected[j] = 1;
553 for (j=0; j<7; ++j) {
554 i = ((j + (int)weekstart) % 7);
555 wc_printf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
556 if (weekday_is_selected[i]) wc_printf(" checked='checked'");
557 wc_printf(">%s\n", weekday_labels[i]);
559 wc_printf("</div>\n"); /* end 'weekday_selector' div */
565 wc_printf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
567 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
568 "value=\"rrmonthtype_mday\" "
569 "%s onChange=\"RecurrenceShowHide();\">",
570 ((which_rrmonthtype_is_preselected == 0) ? "checked='checked'" : "")
573 rrmday = t_start.day;
574 rrmweekday = icaltime_day_of_week(t_start) - 1;
576 /* Figure out what week of the month we're in */
579 weekbase = icaltime_week_number(day1);
580 rrmweek = icaltime_week_number(t_start) - weekbase + 1;
582 /* Are we going by day of the month or week/day? */
584 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
585 which_rrmonthtype_is_preselected = 0;
586 rrmday = recur.by_month_day[0];
588 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
589 which_rrmonthtype_is_preselected = 1;
590 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
591 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
594 wc_printf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
595 wc_printf("<br />\n");
597 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
598 "value=\"rrmonthtype_wday\" "
599 "%s onChange=\"RecurrenceShowHide();\">",
600 ((which_rrmonthtype_is_preselected == 1) ? "checked='checked'" : "")
603 wc_printf(_("on the "));
604 wc_printf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
605 "onChange=\"RecurrenceShowHide();\">\n");
606 for (i=1; i<=5; ++i) {
607 wc_printf("<option %svalue=\"%d\">%s</option>\n",
608 ((i==rrmweek) ? "selected='selected' " : ""),
613 wc_printf("</select> \n");
615 wc_printf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
616 "onChange=\"RecurrenceShowHide();\">\n");
617 for (j=0; j<7; ++j) {
618 i = ((j + (int)weekstart) % 7);
619 wc_printf("<option %svalue=\"%d\">%s</option>\n",
620 ((i==rrmweekday) ? "selected='selected' " : ""),
625 wc_printf("</select>");
627 wc_printf(" %s<br />\n", _("of the month"));
629 wc_printf("</div>\n"); /* end 'monthday_selector' div */
633 rrymweekday = rrmweekday;
634 rrymonth = t_start.month;
635 which_rryeartype_is_preselected = 0;
638 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
639 && (recur.by_day[0] != 0)
640 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
641 && (recur.by_month[0] != 0)
643 which_rryeartype_is_preselected = 1;
644 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
645 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
646 rrymonth = recur.by_month[0];
649 wc_printf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
651 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
652 "value=\"rryeartype_ymday\" "
653 "%s onChange=\"RecurrenceShowHide();\">",
654 ((which_rryeartype_is_preselected == 0) ? "checked='checked'" : "")
656 wc_printf(_("every "));
657 wc_printf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
659 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
660 "value=\"rryeartype_ywday\" "
661 "%s onChange=\"RecurrenceShowHide();\">",
662 ((which_rryeartype_is_preselected == 1) ? "checked='checked'" : "")
665 wc_printf(_("on the "));
666 wc_printf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
667 "onChange=\"RecurrenceShowHide();\">\n");
668 for (i=1; i<=5; ++i) {
669 wc_printf("<option %svalue=\"%d\">%s</option>\n",
670 ((i==rrymweek) ? "selected='selected' " : ""),
675 wc_printf("</select> \n");
677 wc_printf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
678 "onChange=\"RecurrenceShowHide();\">\n");
679 for (j=0; j<7; ++j) {
680 i = ((j + (int)weekstart) % 7);
681 wc_printf("<option %svalue=\"%d\">%s</option>\n",
682 ((i==rrymweekday) ? "selected='selected' " : ""),
687 wc_printf("</select>");
689 wc_printf(" %s ", _("of"));
691 wc_printf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
692 "onChange=\"RecurrenceShowHide();\">\n");
693 for (i=1; i<=12; ++i) {
694 wc_printf("<option %svalue=\"%d\">%s</option>\n",
695 ((i==rrymonth) ? "selected='selected' " : ""),
700 wc_printf("</select>");
701 wc_printf("<br />\n");
703 wc_printf("</div>\n"); /* end 'yearday_selector' div */
705 wc_printf("</td></tr>\n");
708 which_rrend_is_preselected = 0;
709 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
710 if (recur.count > 0) which_rrend_is_preselected = 1;
712 wc_printf("<tr><td><b>");
713 wc_printf(_("Recurrence range"));
714 wc_printf("</b></td><td>\n");
716 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
717 "value=\"rrend_none\" "
718 "%s onChange=\"RecurrenceShowHide();\">",
719 ((which_rrend_is_preselected == 0) ? "checked='checked'" : "")
721 wc_printf("%s<br />\n", _("No ending date"));
723 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
724 "value=\"rrend_count\" "
725 "%s onChange=\"RecurrenceShowHide();\">",
726 ((which_rrend_is_preselected == 1) ? "checked='checked'" : "")
728 wc_printf(_("Repeat this event"));
729 wc_printf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
730 wc_printf("value=\"%d\"> ", recur.count);
731 wc_printf(_("times"));
732 wc_printf("<br />\n");
734 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
735 "value=\"rrend_until\" "
736 "%s onChange=\"RecurrenceShowHide();\">",
737 ((which_rrend_is_preselected == 2) ? "checked='checked'" : "")
739 wc_printf(_("Repeat this event until "));
741 if (icaltime_is_null_time(recur.until)) {
742 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
744 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
745 wc_printf("<br />\n");
747 wc_printf("</td></tr>\n");
749 wc_printf("</table>\n");
750 wc_printf("</div>\n"); /* end 'rrule' div */
754 /* submit buttons (common area beneath the tabs) */
757 "<input type=\"submit\" name=\"save_button\" value=\"%s\">"
759 "<input type=\"submit\" name=\"delete_button\" value=\"%s\">\n"
761 "<input type=\"submit\" id=\"check_button\" name=\"check_button\" value=\"%s\">\n"
763 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n"
767 _("Check attendee availability"),
771 wc_printf("</form>\n");
773 StrBufAppendPrintf(WC->trailing_javascript,
774 "eventEditAllDay(); \n"
775 "RecurrenceShowHide(); \n"
776 "EnableOrDisableCheckButton(); \n"
778 address_book_popup();
781 if (created_new_vevent) {
782 icalcomponent_free(vevent);
787 * Save an edited event
789 * supplied_vevent: the event to save
790 * msgnum: the index on the citserver
792 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
793 int unread, calview *calv) {
796 icalcomponent *vevent, *encaps;
797 int created_new_vevent = 0;
798 int all_day_event = 0;
799 struct icaltimetype event_start, t;
800 icalproperty *attendee = NULL;
801 char attendee_string[SIZ];
804 char form_attendees[SIZ];
805 char organizer_string[SIZ];
807 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 if (!strcasecmp(attendee_string,
1103 icalproperty_get_attendee(attendee)))
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 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1121 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1122 strcpy(attendee_string, &attendee_string[7]);
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);
1154 if (buf[0] == '8') {
1155 serv_puts("Content-type: text/calendar");
1157 serv_puts(icalcomponent_as_ical_string(encaps));
1160 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1161 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1164 if (buf[0] == '2') {
1165 strcpy(WC->ImportantMessage, &buf[4]);
1167 icalmemory_free_ring ();
1168 icalcomponent_free(encaps);
1172 /* Or, check attendee availability if the user asked for that. */
1173 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1175 /* Call this function, which does the real work */
1176 check_attendee_availability(encaps);
1178 /* This displays the form again, with our annotations */
1179 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1181 icalcomponent_free(encaps);
1184 if (encaps != NULL) {
1185 icalcomponent_free(encaps);
1192 * If the user clicked 'Delete' then delete it.
1194 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1195 serv_printf("DELE %ld", lbstr("msgnum"));
1196 serv_getln(buf, sizeof buf);
1199 if (created_new_vevent) {
1200 icalcomponent_free(vevent);
1203 /* If this was a save or delete, go back to the calendar or summary view. */
1204 if (!havebstr("check_button")) {
1205 if (!strcasecmp(bstr("calview"), "summary")) {
1209 readloop(readfwd, eUseDefault);