2 * Editing calendar events.
4 * Copyright (c) 1996-2010 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 as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (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;
47 /************************************************************
48 * Uncomment this to see the UID in calendar events for debugging
51 char weekday_labels[7][32];
52 char month_labels[12][32];
54 icalproperty *rrule = NULL;
55 struct icalrecurrencetype recur;
56 char weekday_is_selected[7];
57 int which_rrmonthtype_is_preselected = 0;
68 int which_rrend_is_preselected;
69 int which_rryeartype_is_preselected;
73 const char *frequency_units[8];
74 const char *ordinals[6];
76 frequency_units[0] = _("seconds");
77 frequency_units[1] = _("minutes");
78 frequency_units[2] = _("hours");
79 frequency_units[3] = _("days");
80 frequency_units[4] = _("weeks");
81 frequency_units[5] = _("months");
82 frequency_units[6] = _("years");
83 frequency_units[7] = _("never");
87 ordinals[1] = _("first");
88 ordinals[2] = _("second");
89 ordinals[3] = _("third");
90 ordinals[4] = _("fourth");
91 ordinals[5] = _("fifth");
94 tabnames[0] = _("Event");
95 tabnames[1] = _("Attendees");
96 tabnames[2] = _("Recurrence");
98 get_pref_long("weekstart", &weekstart, 17);
99 if (weekstart > 6) weekstart = 0;
101 syslog(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
102 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
105 /* populate the weekday names - begin */
107 localtime_r(&now, &tm_now);
108 while (tm_now.tm_wday != 0) {
110 localtime_r(&now, &tm_now);
112 for (i=0; i<7; ++i) {
113 localtime_r(&now, &tm_now);
114 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
117 /* populate the weekday names - end */
119 /* populate the month names - begin */
120 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
121 localtime_r(&now, &tm_now);
122 for (i=0; i<12; ++i) {
123 localtime_r(&now, &tm_now);
124 wc_strftime(month_labels[i], 32, "%B", &tm_now);
127 /* populate the month names - end */
130 strcpy(organizer_string, "");
131 strcpy(attendee_string, "");
133 if (supplied_vevent != NULL) {
134 vevent = supplied_vevent;
136 /* Convert all timestamps to UTC to make them easier to process. */
137 ical_dezonify(vevent);
140 * If we're looking at a fully encapsulated VCALENDAR
141 * rather than a VEVENT component, attempt to use the first
142 * relevant VEVENT subcomponent. If there is none, the
143 * NULL returned by icalcomponent_get_first_component() will
144 * tell the next iteration of this function to create a
147 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
148 display_edit_individual_event(
149 icalcomponent_get_first_component(
150 vevent, ICAL_VEVENT_COMPONENT),
151 msgnum, from, unread, NULL
157 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
158 created_new_vevent = 1;
161 /* Learn the sequence */
162 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
163 /************************************************************
164 * Uncomment this to see the UID in calendar events for debugging
166 sequence = icalproperty_get_sequence(p);
170 output_headers(1, 1, 2, 0, 0, 0);
171 wc_printf("<div id=\"banner\">\n");
173 wc_printf(_("Add or edit an event"));
175 wc_printf("</div>\n");
177 wc_printf("<div id=\"content\" class=\"service\">\n");
179 /************************************************************
180 * Uncomment this to see the UID in calendar events for debugging
181 wc_printf("UID == ");
182 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
184 escputs((char *)icalproperty_get_comment(p));
187 wc_printf("SEQUENCE == %d<br>\n", sequence);
188 *************************************************************/
190 wc_printf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
191 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
193 wc_printf("<input type=\"hidden\" name=\"msgnum\" value=\"%ld\">\n",
195 wc_printf("<input type=\"hidden\" name=\"calview\" value=\"%s\">\n",
197 wc_printf("<input type=\"hidden\" name=\"year\" value=\"%s\">\n",
199 wc_printf("<input type=\"hidden\" name=\"month\" value=\"%s\">\n",
201 wc_printf("<input type=\"hidden\" name=\"day\" value=\"%s\">\n",
205 tabbed_dialog(3, tabnames);
208 /* Put it in a borderless table so it lines up nicely */
209 wc_printf("<table border='0' width='100%%'>\n");
211 wc_printf("<tr><td><b>");
212 wc_printf(_("Summary"));
213 wc_printf("</b></td><td>\n"
214 "<input type=\"text\" name=\"summary\" "
215 "maxlength=\"64\" size=\"64\" value=\"");
216 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
218 escputs((char *)icalproperty_get_comment(p));
220 wc_printf("\"></td></tr>\n");
222 wc_printf("<tr><td><b>");
223 wc_printf(_("Location"));
224 wc_printf("</b></td><td>\n"
225 "<input type=\"text\" name=\"location\" "
226 "maxlength=\"64\" size=\"64\" value=\"");
227 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
229 escputs((char *)icalproperty_get_comment(p));
231 wc_printf("\"></td></tr>\n");
233 wc_printf("<tr><td><b>");
234 wc_printf(_("Start"));
235 wc_printf("</b></td><td>\n");
236 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
238 t_start = icalproperty_get_dtstart(p);
239 if (t_start.is_date) {
246 localtime_r(&now, &tm_now);
247 if (havebstr("year")) {
248 tm_now.tm_year = ibstr("year") - 1900;
249 tm_now.tm_mon = ibstr("month") - 1;
250 tm_now.tm_mday = ibstr("day");
252 if (havebstr("hour")) {
253 tm_now.tm_hour = ibstr("hour");
254 tm_now.tm_min = ibstr("minute");
263 t_start = icaltime_from_timet_with_zone(
265 ((yesbstr("alldayevent")) ? 1 : 0),
266 icaltimezone_get_utc_timezone()
271 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
273 wc_printf("<input type=\"checkbox\" id=\"alldayevent\" name=\"alldayevent\" "
274 "value=\"yes\" onclick=\"eventEditAllDay();\""
276 (t_start.is_date ? "checked=\"checked\"" : "" ),
280 wc_printf("</td></tr>\n");
282 wc_printf("<tr><td><b>");
284 wc_printf("</b></td><td id=\"dtendcell\">\n");
285 p = icalcomponent_get_first_property(vevent,
286 ICAL_DTEND_PROPERTY);
288 t_end = icalproperty_get_dtend(p);
291 * If this is an all-day-event, the end time is set to real end
292 * day + 1, so we have to adjust accordingly.
294 if (t_start.is_date) {
295 icaltime_adjust(&t_end, -1, 0, 0, 0);
299 if (created_new_vevent == 1) {
300 /* set default duration */
301 if (t_start.is_date) {
303 * If this is an all-day-event, set the end time to be identical to
304 * the start time (the hour/minute/second will be set to midnight).
310 * If this is not an all-day event and there is no
311 * end time specified, make the default one hour
312 * from the start time.
317 t_end = icaltime_normalize(t_end);
318 /* t_end = icaltime_from_timet(now, 0); */
323 * If an existing event has no end date/time this is
324 * supposed to mean end = start.
329 display_icaltimetype_as_webform(&t_end, "dtend", 0);
330 wc_printf("</td></tr>\n");
332 wc_printf("<tr><td><b>");
333 wc_printf(_("Notes"));
334 wc_printf("</b></td><td>\n"
335 "<textarea name=\"description\" "
336 "rows='5' cols='72' style='width:72'>\n"
338 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
340 escputs((char *)icalproperty_get_comment(p));
342 wc_printf("</textarea></td></tr>");
345 * For a new event, the user creating the event should be the
346 * organizer. Set this field accordingly.
348 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
350 sprintf(organizer_string, "mailto:%s", ChrPtr(WC->cs_inet_email));
351 icalcomponent_add_property(vevent,
352 icalproperty_new_organizer(organizer_string)
357 * Determine who is the organizer of this event.
358 * We need to determine "me" or "not me."
360 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
361 if (organizer != NULL) {
362 strcpy(organizer_string, icalproperty_get_organizer(organizer));
363 if (!strncasecmp(organizer_string, "mailto:", 7)) {
364 strcpy(organizer_string, &organizer_string[7]);
365 striplt(organizer_string);
366 serv_printf("ISME %s", organizer_string);
367 serv_getln(buf, sizeof buf);
374 wc_printf("<tr><td><b>");
375 wc_printf(_("Organizer"));
376 wc_printf("</b></td><td>");
377 escputs(organizer_string);
378 if (organizer_is_me) {
379 wc_printf(" <font size='-1'><i>");
380 wc_printf(_("(you are the organizer)"));
381 wc_printf("</i></font>\n");
385 * Transmit the organizer as a hidden field. We don't want the user
386 * to be able to change it, but we do want it fed back to the server,
387 * especially if this is a new event and there is no organizer already
388 * in the calendar object.
390 wc_printf("<input type=\"hidden\" name=\"organizer\" value=\"");
391 escputs(organizer_string);
394 wc_printf("</td></tr>\n");
397 wc_printf("<tr><td><b>");
398 wc_printf(_("Show time as:"));
399 wc_printf("</b></td><td>");
401 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
403 /* No transparency found. Default to opaque (busy). */
404 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
406 icalcomponent_add_property(vevent, p);
410 v = icalproperty_get_value(p);
416 wc_printf("<input type=\"radio\" name=\"transp\" value=\"transparent\"");
417 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
418 wc_printf(" CHECKED");
421 wc_printf(_("Free"));
422 wc_printf(" ");
424 wc_printf("<input type=\"radio\" name=\"transp\" value=\"opaque\"");
425 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
426 wc_printf(" CHECKED");
429 wc_printf(_("Busy"));
431 wc_printf("</td></tr>\n");
434 /* Done with properties. */
435 wc_printf("</TABLE>\n");
439 /* Attendees tab (need to move things here) */
441 wc_printf("<table border='0' width='100%%'>\n"); /* same table style as the event tab */
442 wc_printf("<tr><td><b>");
443 wc_printf(_("Attendees"));
446 wc_printf(_("(One per line)"));
447 wc_printf("</font>\n");
449 /* Pop open an address book -- begin */
451 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
453 "<img alt='' align='middle' border='0' width='16' height='16' src=\"static/webcit_icons/essen/16x16/contact.png\">"
458 /* Pop open an address book -- end */
460 wc_printf("</td><td>"
461 "<textarea %s name=\"attendees\" id=\"attendees_box\" "
462 "onchange=\"EnableOrDisableCheckButton();\" "
463 "onKeyPress=\"EnableOrDisableCheckButton();\" "
464 "rows='10' cols='72' style='width:72'>\n",
465 (organizer_is_me ? "" : "disabled='disabled' ")
468 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
470 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
471 ch = icalproperty_get_attendee(attendee);
472 if ((ch != NULL) && !strncasecmp(ch, "mailto:", 7)) {
474 /* screen name or email address */
475 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
476 striplt(attendee_string);
477 if (i++) wc_printf("\n");
478 escputs(attendee_string);
481 /* participant status */
482 partstat_as_string(buf, attendee);
486 wc_printf("</textarea></td></tr>\n");
487 wc_printf("</table>\n");
493 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
495 recur = icalproperty_get_rrule(rrule);
498 /* blank recurrence with some sensible defaults */
499 memset(&recur, 0, sizeof(struct icalrecurrencetype));
501 recur.until = icaltime_null_time();
503 recur.freq = ICAL_WEEKLY_RECURRENCE;
506 wc_printf("<input type=\"checkbox\" id=\"is_recur\" name=\"is_recur\" "
508 "onclick=\"RecurrenceShowHide();\""
510 (rrule ? "checked=\"checked\"" : "" ),
511 _("This is a recurring event")
514 wc_printf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
516 wc_printf("<table border='0' cellspacing='10' width='100%%'>\n");
518 wc_printf("<tr><td><b>");
519 wc_printf(_("Recurrence rule"));
520 wc_printf("</b></td><td>");
522 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
523 wc_printf("%s ", _("Repeats every"));
525 wc_printf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
526 wc_printf("value=\"%d\"> ", recur.interval);
528 wc_printf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
529 "onChange=\"RecurrenceShowHide();\">\n");
530 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
531 wc_printf("<option %s%svalue=\"%d\">%s</option>\n",
532 ((i == recur.freq) ? "selected='selected' " : ""),
533 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled='disabled' "),
538 wc_printf("</select>\n");
540 wc_printf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
541 wc_printf("%s<br>", _("on these weekdays:"));
543 memset(weekday_is_selected, 0, 7);
545 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
546 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
547 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
550 for (j=0; j<7; ++j) {
551 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
552 weekday_is_selected[j] = 1;
558 for (j=0; j<7; ++j) {
559 i = ((j + (int)weekstart) % 7);
560 wc_printf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
561 if (weekday_is_selected[i]) wc_printf(" checked='checked'");
562 wc_printf(">%s\n", weekday_labels[i]);
564 wc_printf("</div>\n"); /* end 'weekday_selector' div */
570 wc_printf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
572 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
573 "value=\"rrmonthtype_mday\" "
574 "%s onChange=\"RecurrenceShowHide();\">",
575 ((which_rrmonthtype_is_preselected == 0) ? "checked='checked'" : "")
578 rrmday = t_start.day;
579 rrmweekday = icaltime_day_of_week(t_start) - 1;
581 /* Figure out what week of the month we're in */
584 weekbase = icaltime_week_number(day1);
585 rrmweek = icaltime_week_number(t_start) - weekbase + 1;
587 /* Are we going by day of the month or week/day? */
589 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
590 which_rrmonthtype_is_preselected = 0;
591 rrmday = recur.by_month_day[0];
593 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
594 which_rrmonthtype_is_preselected = 1;
595 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
596 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
599 wc_printf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
602 wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
603 "value=\"rrmonthtype_wday\" "
604 "%s onChange=\"RecurrenceShowHide();\">",
605 ((which_rrmonthtype_is_preselected == 1) ? "checked='checked'" : "")
608 wc_printf(_("on the "));
609 wc_printf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
610 "onChange=\"RecurrenceShowHide();\">\n");
611 for (i=1; i<=5; ++i) {
612 wc_printf("<option %svalue=\"%d\">%s</option>\n",
613 ((i==rrmweek) ? "selected='selected' " : ""),
618 wc_printf("</select> \n");
620 wc_printf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
621 "onChange=\"RecurrenceShowHide();\">\n");
622 for (j=0; j<7; ++j) {
623 i = ((j + (int)weekstart) % 7);
624 wc_printf("<option %svalue=\"%d\">%s</option>\n",
625 ((i==rrmweekday) ? "selected='selected' " : ""),
630 wc_printf("</select>");
632 wc_printf(" %s<br>\n", _("of the month"));
634 wc_printf("</div>\n"); /* end 'monthday_selector' div */
638 rrymweekday = rrmweekday;
639 rrymonth = t_start.month;
640 which_rryeartype_is_preselected = 0;
643 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
644 && (recur.by_day[0] != 0)
645 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
646 && (recur.by_month[0] != 0)
648 which_rryeartype_is_preselected = 1;
649 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
650 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
651 rrymonth = recur.by_month[0];
654 wc_printf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
656 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
657 "value=\"rryeartype_ymday\" "
658 "%s onChange=\"RecurrenceShowHide();\">",
659 ((which_rryeartype_is_preselected == 0) ? "checked='checked'" : "")
661 wc_printf(_("every "));
662 wc_printf("<span id=\"ymday\">%s</span><br>", _("year on this date"));
664 wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
665 "value=\"rryeartype_ywday\" "
666 "%s onChange=\"RecurrenceShowHide();\">",
667 ((which_rryeartype_is_preselected == 1) ? "checked='checked'" : "")
670 wc_printf(_("on the "));
671 wc_printf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
672 "onChange=\"RecurrenceShowHide();\">\n");
673 for (i=1; i<=5; ++i) {
674 wc_printf("<option %svalue=\"%d\">%s</option>\n",
675 ((i==rrymweek) ? "selected='selected' " : ""),
680 wc_printf("</select> \n");
682 wc_printf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
683 "onChange=\"RecurrenceShowHide();\">\n");
684 for (j=0; j<7; ++j) {
685 i = ((j + (int)weekstart) % 7);
686 wc_printf("<option %svalue=\"%d\">%s</option>\n",
687 ((i==rrymweekday) ? "selected='selected' " : ""),
692 wc_printf("</select>");
694 wc_printf(" %s ", _("of"));
696 wc_printf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
697 "onChange=\"RecurrenceShowHide();\">\n");
698 for (i=1; i<=12; ++i) {
699 wc_printf("<option %svalue=\"%d\">%s</option>\n",
700 ((i==rrymonth) ? "selected='selected' " : ""),
705 wc_printf("</select>");
708 wc_printf("</div>\n"); /* end 'yearday_selector' div */
710 wc_printf("</td></tr>\n");
713 which_rrend_is_preselected = 0;
714 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
715 if (recur.count > 0) which_rrend_is_preselected = 1;
717 wc_printf("<tr><td><b>");
718 wc_printf(_("Recurrence range"));
719 wc_printf("</b></td><td>\n");
721 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
722 "value=\"rrend_none\" "
723 "%s onChange=\"RecurrenceShowHide();\">",
724 ((which_rrend_is_preselected == 0) ? "checked='checked'" : "")
726 wc_printf("%s<br>\n", _("No ending date"));
728 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
729 "value=\"rrend_count\" "
730 "%s onChange=\"RecurrenceShowHide();\">",
731 ((which_rrend_is_preselected == 1) ? "checked='checked'" : "")
733 wc_printf(_("Repeat this event"));
734 wc_printf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
735 wc_printf("value=\"%d\"> ", recur.count);
736 wc_printf(_("times"));
739 wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
740 "value=\"rrend_until\" "
741 "%s onChange=\"RecurrenceShowHide();\">",
742 ((which_rrend_is_preselected == 2) ? "checked='checked'" : "")
744 wc_printf(_("Repeat this event until "));
746 if (icaltime_is_null_time(recur.until)) {
747 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
749 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
752 wc_printf("</td></tr>\n");
754 wc_printf("</table>\n");
755 wc_printf("</div>\n"); /* end 'rrule' div */
759 /* submit buttons (common area beneath the tabs) */
762 "<input type=\"submit\" name=\"save_button\" value=\"%s\">"
764 "<input type=\"submit\" name=\"delete_button\" value=\"%s\">\n"
766 "<input type=\"submit\" id=\"check_button\" name=\"check_button\" value=\"%s\">\n"
768 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n"
772 _("Check attendee availability"),
776 wc_printf("</form>\n");
778 StrBufAppendPrintf(WC->trailing_javascript,
779 "eventEditAllDay(); \n"
780 "RecurrenceShowHide(); \n"
781 "EnableOrDisableCheckButton(); \n"
783 address_book_popup();
786 if (created_new_vevent) {
787 icalcomponent_free(vevent);
792 * Save an edited event
794 * supplied_vevent: the event to save
795 * msgnum: the index on the citserver
797 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
798 int unread, calview *calv) {
801 icalcomponent *vevent, *encaps;
802 int created_new_vevent = 0;
803 int all_day_event = 0;
804 struct icaltimetype event_start, t;
805 icalproperty *attendee = NULL;
806 char attendee_string[SIZ];
809 char form_attendees[SIZ];
810 char organizer_string[SIZ];
812 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
815 if (supplied_vevent != NULL) {
816 vevent = supplied_vevent;
818 /* Convert all timestamps to UTC to make them easier to process. */
819 ical_dezonify(vevent);
822 * If we're looking at a fully encapsulated VCALENDAR
823 * rather than a VEVENT component, attempt to use the first
824 * relevant VEVENT subcomponent. If there is none, the
825 * NULL returned by icalcomponent_get_first_component() will
826 * tell the next iteration of this function to create a
829 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
830 save_individual_event(
831 icalcomponent_get_first_component(
832 vevent, ICAL_VEVENT_COMPONENT),
833 msgnum, from, unread, NULL
839 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
840 created_new_vevent = 1;
843 if ( (havebstr("save_button"))
844 || (havebstr("check_button")) ) {
846 /* Replace values in the component with ones from the form */
848 while (prop = icalcomponent_get_first_property(vevent,
849 ICAL_SUMMARY_PROPERTY), prop != NULL) {
850 icalcomponent_remove_property(vevent, prop);
851 icalproperty_free(prop);
854 /* Add NOW() to the calendar object... */
855 icalcomponent_set_dtstamp(vevent,
859 if (havebstr("summary")) {
860 icalcomponent_add_property(vevent,
861 icalproperty_new_summary(bstr("summary")));
863 icalcomponent_add_property(vevent,
864 icalproperty_new_summary(_("Untitled Event")));
867 while (prop = icalcomponent_get_first_property(vevent,
868 ICAL_LOCATION_PROPERTY), prop != NULL) {
869 icalcomponent_remove_property(vevent, prop);
870 icalproperty_free(prop);
872 if (havebstr("location")) {
873 icalcomponent_add_property(vevent,
874 icalproperty_new_location(bstr("location")));
876 while (prop = icalcomponent_get_first_property(vevent,
877 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
878 icalcomponent_remove_property(vevent, prop);
879 icalproperty_free(prop);
881 if (havebstr("description")) {
882 icalcomponent_add_property(vevent,
883 icalproperty_new_description(bstr("description")));
886 while (prop = icalcomponent_get_first_property(vevent,
887 ICAL_DTSTART_PROPERTY), prop != NULL) {
888 icalcomponent_remove_property(vevent, prop);
889 icalproperty_free(prop);
892 if (yesbstr("alldayevent")) {
900 icaltime_from_webform_dateonly(&event_start, "dtstart");
903 icaltime_from_webform(&event_start, "dtstart");
906 prop = icalproperty_new_dtstart(event_start);
909 /* Force it to serialize as a date-only rather than date/time */
910 icalproperty_set_value(prop, icalvalue_new_date(event_start));
913 if (prop) icalcomponent_add_property(vevent, prop);
914 else icalproperty_free(prop);
916 while (prop = icalcomponent_get_first_property(vevent,
917 ICAL_DTEND_PROPERTY), prop != NULL) {
918 icalcomponent_remove_property(vevent, prop);
919 icalproperty_free(prop);
921 while (prop = icalcomponent_get_first_property(vevent,
922 ICAL_DURATION_PROPERTY), prop != NULL) {
923 icalcomponent_remove_property(vevent, prop);
924 icalproperty_free(prop);
928 icaltime_from_webform_dateonly(&t, "dtend");
930 /* with this field supposed to be non-inclusive we have to add one day */
931 icaltime_adjust(&t, 1, 0, 0, 0);
934 icaltime_from_webform(&t, "dtend");
937 icalcomponent_add_property(vevent,
938 icalproperty_new_dtend(icaltime_normalize(t)
942 /* recurrence rules -- begin */
944 /* remove any existing rule */
945 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
946 icalcomponent_remove_property(vevent, prop);
947 icalproperty_free(prop);
950 if (yesbstr("is_recur")) {
951 struct icalrecurrencetype recur;
952 icalrecurrencetype_clear(&recur);
954 recur.interval = atoi(bstr("interval"));
955 recur.freq = atoi(bstr("freq"));
959 /* These can't happen; they're disabled. */
960 case ICAL_SECONDLY_RECURRENCE:
962 case ICAL_MINUTELY_RECURRENCE:
964 case ICAL_HOURLY_RECURRENCE:
967 /* Daily is valid but there are no further inputs. */
968 case ICAL_DAILY_RECURRENCE:
971 /* These are the real options. */
973 case ICAL_WEEKLY_RECURRENCE:
975 for (i=0; i<7; ++i) {
976 snprintf(buf, sizeof buf, "weekday%d", i);
977 if (YESBSTR(buf)) recur.by_day[j++] =
978 icalrecurrencetype_day_day_of_week(i+1);
980 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
983 case ICAL_MONTHLY_RECURRENCE:
984 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
985 recur.by_month_day[0] = event_start.day;
986 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
988 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
989 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
990 + atoi(bstr("rrmweekday")) + 1;
991 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
995 case ICAL_YEARLY_RECURRENCE:
996 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
997 /* no further action is needed here */
999 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
1000 recur.by_month[0] = atoi(bstr("rrymonth"));
1001 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
1002 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
1003 + atoi(bstr("rrymweekday")) + 1;
1004 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
1008 /* This one can't happen either. */
1009 case ICAL_NO_RECURRENCE:
1013 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
1014 recur.count = atoi(bstr("rrcount"));
1016 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
1017 icaltime_from_webform_dateonly(&recur.until, "rruntil");
1020 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
1023 /* recurrence rules -- end */
1025 /* See if transparency is indicated */
1026 if (havebstr("transp")) {
1027 if (!strcasecmp(bstr("transp"), "opaque")) {
1028 formtransp = ICAL_TRANSP_OPAQUE;
1030 else if (!strcasecmp(bstr("transp"), "transparent")) {
1031 formtransp = ICAL_TRANSP_TRANSPARENT;
1034 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1036 icalcomponent_remove_property(vevent, prop);
1037 icalproperty_free(prop);
1040 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1043 /* Give this event a UID if it doesn't have one. */
1044 if (icalcomponent_get_first_property(vevent,
1045 ICAL_UID_PROPERTY) == NULL) {
1047 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1050 /* Increment the sequence ID */
1051 while (prop = icalcomponent_get_first_property(vevent,
1052 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1053 i = icalproperty_get_sequence(prop);
1054 if (i > sequence) sequence = i;
1055 icalcomponent_remove_property(vevent, prop);
1056 icalproperty_free(prop);
1059 icalcomponent_add_property(vevent,
1060 icalproperty_new_sequence(sequence)
1064 * Set the organizer, only if one does not already exist *and*
1065 * the form is supplying one
1067 strcpy(buf, bstr("organizer"));
1068 if ( (icalcomponent_get_first_property(vevent,
1069 ICAL_ORGANIZER_PROPERTY) == NULL)
1070 && (!IsEmptyStr(buf)) ) {
1072 /* set new organizer */
1073 sprintf(organizer_string, "MAILTO:%s", buf);
1074 icalcomponent_add_property(vevent,
1075 icalproperty_new_organizer(organizer_string)
1081 * Add any new attendees listed in the web form
1084 /* First, strip out the parenthesized partstats. */
1085 strcpy(form_attendees, bstr("attendees"));
1086 while ( stripout(form_attendees, '(', ')') != 0);
1088 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1089 j = strlen(form_attendees);
1090 for (i=0; i<j; ++i) {
1091 if (form_attendees[i] == ',') {
1092 form_attendees[i] = '\n';
1093 while (isspace(form_attendees[i+1])) {
1094 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1100 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1101 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1103 if (!IsEmptyStr(buf)) {
1104 sprintf(attendee_string, "MAILTO:%s", buf);
1107 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1108 ch = icalproperty_get_attendee(attendee);
1109 if ((ch != NULL) && !strcasecmp(attendee_string, ch))
1115 icalcomponent_add_property(vevent,
1116 icalproperty_new_attendee(attendee_string)
1123 * Remove any attendees *not* listed in the web form
1125 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1126 ch = icalproperty_get_attendee(attendee);
1127 if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) {
1128 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
1129 striplt(attendee_string);
1131 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1132 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1134 if (!strcasecmp(buf, attendee_string)) ++foundit;
1137 icalcomponent_remove_property(vevent, attendee);
1138 icalproperty_free(attendee);
1145 * Encapsulate event into full VCALENDAR component. Clone it first,
1146 * for two reasons: one, it's easier to just free the whole thing
1147 * when we're done instead of unbundling, but more importantly, we
1148 * can't encapsulate something that may already be encapsulated
1151 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1153 /* Set the method to PUBLISH */
1154 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1156 /* If the user clicked 'Save' then save it to the server. */
1157 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1158 serv_puts("ENT0 1|||4|||1|");
1159 serv_getln(buf, sizeof buf);
1162 serv_puts("Content-type: text/calendar");
1163 serv_puts("Content-Transfer-Encoding: quoted-printable");
1165 text_to_server_qp(icalcomponent_as_ical_string(encaps));
1166 // serv_puts(icalcomponent_as_ical_string(encaps));
1169 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {}
1172 AppendImportantMessage(buf + 4, - 1);
1177 icalmemory_free_ring ();
1178 icalcomponent_free(encaps);
1182 /* Or, check attendee availability if the user asked for that. */
1183 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1185 /* Call this function, which does the real work */
1186 check_attendee_availability(encaps);
1188 /* This displays the form again, with our annotations */
1189 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1191 icalcomponent_free(encaps);
1194 if (encaps != NULL) {
1195 icalcomponent_free(encaps);
1202 * If the user clicked 'Delete' then delete it.
1204 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1205 serv_printf("DELE %ld", lbstr("msgnum"));
1206 serv_getln(buf, sizeof buf);
1209 if (created_new_vevent) {
1210 icalcomponent_free(vevent);
1213 /* If this was a save or delete, go back to the calendar or summary view. */
1214 if (!havebstr("check_button")) {
1215 if (!strcasecmp(bstr("calview"), "summary")) {
1216 do_template("summary_page");
1219 readloop(readfwd, eUseDefault);