4 * Editing calendar events.
6 * Copyright (c) 1996-2010 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "webserver.h"
28 * Display an event by itself (for editing)
29 * supplied_vevent the event to edit
30 * msgnum reference on the citserver
32 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
33 int unread, calview *calv)
35 icalcomponent *vevent;
38 struct icaltimetype t_start, t_end;
41 int created_new_vevent = 0;
42 icalproperty *organizer = NULL;
43 char organizer_string[SIZ];
44 icalproperty *attendee = NULL;
45 char attendee_string[SIZ];
47 int organizer_is_me = 0;
50 char weekday_labels[7][32];
51 char month_labels[12][32];
53 icalproperty *rrule = NULL;
54 struct icalrecurrencetype recur;
55 char weekday_is_selected[7];
56 int which_rrmonthtype_is_preselected = 0;
67 int which_rrend_is_preselected;
68 int which_rryeartype_is_preselected;
72 const char *frequency_units[8];
73 const char *ordinals[6];
75 frequency_units[0] = _("seconds");
76 frequency_units[1] = _("minutes");
77 frequency_units[2] = _("hours");
78 frequency_units[3] = _("days");
79 frequency_units[4] = _("weeks");
80 frequency_units[5] = _("months");
81 frequency_units[6] = _("years");
82 frequency_units[7] = _("never");
86 ordinals[1] = _("first");
87 ordinals[2] = _("second");
88 ordinals[3] = _("third");
89 ordinals[4] = _("fourth");
90 ordinals[5] = _("fifth");
93 tabnames[0] = _("Event");
94 tabnames[1] = _("Attendees");
95 tabnames[2] = _("Recurrence");
97 get_pref_long("weekstart", &weekstart, 17);
98 if (weekstart > 6) weekstart = 0;
100 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
101 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
104 /* populate the weekday names - begin */
106 localtime_r(&now, &tm_now);
107 while (tm_now.tm_wday != 0) {
109 localtime_r(&now, &tm_now);
111 for (i=0; i<7; ++i) {
112 localtime_r(&now, &tm_now);
113 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
116 /* populate the weekday names - end */
118 /* populate the month names - begin */
119 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
120 localtime_r(&now, &tm_now);
121 for (i=0; i<12; ++i) {
122 localtime_r(&now, &tm_now);
123 wc_strftime(month_labels[i], 32, "%B", &tm_now);
126 /* populate the month names - end */
129 strcpy(organizer_string, "");
130 strcpy(attendee_string, "");
132 if (supplied_vevent != NULL) {
133 vevent = supplied_vevent;
135 /* Convert all timestamps to UTC to make them easier to process. */
136 ical_dezonify(vevent);
139 * If we're looking at a fully encapsulated VCALENDAR
140 * rather than a VEVENT component, attempt to use the first
141 * relevant VEVENT subcomponent. If there is none, the
142 * NULL returned by icalcomponent_get_first_component() will
143 * tell the next iteration of this function to create a
146 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
147 display_edit_individual_event(
148 icalcomponent_get_first_component(
149 vevent, ICAL_VEVENT_COMPONENT),
150 msgnum, from, unread, NULL
156 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
157 created_new_vevent = 1;
160 /* Learn the sequence */
161 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
163 sequence = icalproperty_get_sequence(p);
167 output_headers(1, 1, 2, 0, 0, 0);
168 wc_printf("<div id=\"banner\">\n");
170 wc_printf(_("Add or edit an event"));
172 wc_printf("</div>\n");
174 wc_printf("<div id=\"content\" class=\"service\">\n");
176 wc_printf("<div class=\"fix_scrollbar_bug\">");
178 /************************************************************
179 * Uncomment this to see the UID in calendar events for debugging
180 wc_printf("UID == ");
181 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
183 escputs((char *)icalproperty_get_comment(p));
185 wc_printf("<br />\n");
186 wc_printf("SEQUENCE == %d<br />\n", sequence);
187 *************************************************************/
189 wc_printf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
190 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
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()
270 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
272 wc_printf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
273 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
275 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
279 wc_printf("</TD></TR>\n");
281 wc_printf("<TR><TD><B>");
283 wc_printf("</B></TD><TD id=\"dtendcell\">\n");
284 p = icalcomponent_get_first_property(vevent,
285 ICAL_DTEND_PROPERTY);
287 t_end = icalproperty_get_dtend(p);
290 * If this is an all-day-event, the end time is set to real end
291 * day + 1, so we have to adjust accordingly.
293 if (t_start.is_date) {
294 icaltime_adjust(&t_end, -1, 0, 0, 0);
298 if (created_new_vevent == 1) {
299 /* set default duration */
300 if (t_start.is_date) {
302 * If this is an all-day-event, set the end time to be identical to
303 * the start time (the hour/minute/second will be set to midnight).
309 * If this is not an all-day event and there is no
310 * end time specified, make the default one hour
311 * from the start time.
316 t_end = icaltime_normalize(t_end);
317 /* t_end = icaltime_from_timet(now, 0); */
322 * If an existing event has no end date/time this is
323 * supposed to mean end = start.
328 display_icaltimetype_as_webform(&t_end, "dtend", 0);
329 wc_printf("</TD></TR>\n");
331 wc_printf("<TR><TD><B>");
332 wc_printf(_("Notes"));
333 wc_printf("</B></TD><TD>\n"
334 "<TEXTAREA NAME=\"description\" wrap=soft "
335 "ROWS=5 COLS=72 WIDTH=72>\n"
337 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
339 escputs((char *)icalproperty_get_comment(p));
341 wc_printf("</TEXTAREA></TD></TR>");
344 * For a new event, the user creating the event should be the
345 * organizer. Set this field accordingly.
347 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
349 sprintf(organizer_string, "MAILTO:%s", ChrPtr(WC->cs_inet_email));
350 icalcomponent_add_property(vevent,
351 icalproperty_new_organizer(organizer_string)
356 * Determine who is the organizer of this event.
357 * We need to determine "me" or "not me."
359 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
360 if (organizer != NULL) {
361 strcpy(organizer_string, icalproperty_get_organizer(organizer));
362 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
363 strcpy(organizer_string, &organizer_string[7]);
364 striplt(organizer_string);
365 serv_printf("ISME %s", organizer_string);
366 serv_getln(buf, sizeof buf);
373 wc_printf("<TR><TD><B>");
374 wc_printf(_("Organizer"));
375 wc_printf("</B></TD><TD>");
376 escputs(organizer_string);
377 if (organizer_is_me) {
378 wc_printf(" <FONT SIZE=-1><I>");
379 wc_printf(_("(you are the organizer)"));
380 wc_printf("</I></FONT>\n");
384 * Transmit the organizer as a hidden field. We don't want the user
385 * to be able to change it, but we do want it fed back to the server,
386 * especially if this is a new event and there is no organizer already
387 * in the calendar object.
389 wc_printf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
390 escputs(organizer_string);
393 wc_printf("</TD></TR>\n");
396 wc_printf("<TR><TD><B>");
397 wc_printf(_("Show time as:"));
398 wc_printf("</B></TD><TD>");
400 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
402 /* No transparency found. Default to opaque (busy). */
403 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
405 icalcomponent_add_property(vevent, p);
409 v = icalproperty_get_value(p);
415 wc_printf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
416 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
417 wc_printf(" CHECKED");
420 wc_printf(_("Free"));
421 wc_printf(" ");
423 wc_printf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
424 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
425 wc_printf(" CHECKED");
428 wc_printf(_("Busy"));
430 wc_printf("</TD></TR>\n");
433 /* Done with properties. */
434 wc_printf("</TABLE>\n");
438 /* Attendees tab (need to move things here) */
440 wc_printf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
441 wc_printf("<TR><TD><B>");
442 wc_printf(_("Attendees"));
443 wc_printf("</B><br />"
445 wc_printf(_("(One per line)"));
446 wc_printf("</font>\n");
448 /* Pop open an address book -- begin */
450 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
452 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
457 /* Pop open an address book -- end */
459 wc_printf("</TD><TD>"
460 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
461 "onchange=\"EnableOrDisableCheckButton();\" "
462 "onKeyPress=\"EnableOrDisableCheckButton();\" "
463 "ROWS=10 COLS=72 WIDTH=72>\n",
464 (organizer_is_me ? "" : "DISABLED ")
467 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
469 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 " : ""),
533 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "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");
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" : "")
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>");
600 wc_printf("<br />\n");
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" : "")
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 " : ""),
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 " : ""),
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" : "")
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" : "")
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 " : ""),
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 " : ""),
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 " : ""),
705 wc_printf("</select>");
706 wc_printf("<br />\n");
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" : "")
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" : "")
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"));
737 wc_printf("<br />\n");
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" : "")
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);
750 wc_printf("<br />\n");
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"),
775 wc_printf("</FORM>\n");
778 wc_printf("</div>\n"); /* end 'fix_scrollbar_bug' div */
780 StrBufAppendPrintf(WC->trailing_javascript,
781 "eventEditAllDay(); \n"
782 "RecurrenceShowHide(); \n"
783 "EnableOrDisableCheckButton(); \n"
785 address_book_popup();
788 if (created_new_vevent) {
789 icalcomponent_free(vevent);
794 * Save an edited event
796 * supplied_vevent: the event to save
797 * msgnum: the index on the citserver
799 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
800 int unread, calview *calv) {
803 icalcomponent *vevent, *encaps;
804 int created_new_vevent = 0;
805 int all_day_event = 0;
806 struct icaltimetype event_start, t;
807 icalproperty *attendee = NULL;
808 char attendee_string[SIZ];
811 char form_attendees[SIZ];
812 char organizer_string[SIZ];
814 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
817 if (supplied_vevent != NULL) {
818 vevent = supplied_vevent;
820 /* Convert all timestamps to UTC to make them easier to process. */
821 ical_dezonify(vevent);
824 * If we're looking at a fully encapsulated VCALENDAR
825 * rather than a VEVENT component, attempt to use the first
826 * relevant VEVENT subcomponent. If there is none, the
827 * NULL returned by icalcomponent_get_first_component() will
828 * tell the next iteration of this function to create a
831 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
832 save_individual_event(
833 icalcomponent_get_first_component(
834 vevent, ICAL_VEVENT_COMPONENT),
835 msgnum, from, unread, NULL
841 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
842 created_new_vevent = 1;
845 if ( (havebstr("save_button"))
846 || (havebstr("check_button")) ) {
848 /* Replace values in the component with ones from the form */
850 while (prop = icalcomponent_get_first_property(vevent,
851 ICAL_SUMMARY_PROPERTY), prop != NULL) {
852 icalcomponent_remove_property(vevent, prop);
853 icalproperty_free(prop);
856 /* Add NOW() to the calendar object... */
857 icalcomponent_set_dtstamp(vevent,
861 if (havebstr("summary")) {
862 icalcomponent_add_property(vevent,
863 icalproperty_new_summary(bstr("summary")));
865 icalcomponent_add_property(vevent,
866 icalproperty_new_summary(_("Untitled Event")));
869 while (prop = icalcomponent_get_first_property(vevent,
870 ICAL_LOCATION_PROPERTY), prop != NULL) {
871 icalcomponent_remove_property(vevent, prop);
872 icalproperty_free(prop);
874 if (havebstr("location")) {
875 icalcomponent_add_property(vevent,
876 icalproperty_new_location(bstr("location")));
878 while (prop = icalcomponent_get_first_property(vevent,
879 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
880 icalcomponent_remove_property(vevent, prop);
881 icalproperty_free(prop);
883 if (havebstr("description")) {
884 icalcomponent_add_property(vevent,
885 icalproperty_new_description(bstr("description")));
888 while (prop = icalcomponent_get_first_property(vevent,
889 ICAL_DTSTART_PROPERTY), prop != NULL) {
890 icalcomponent_remove_property(vevent, prop);
891 icalproperty_free(prop);
894 if (yesbstr("alldayevent")) {
902 icaltime_from_webform_dateonly(&event_start, "dtstart");
905 icaltime_from_webform(&event_start, "dtstart");
908 prop = icalproperty_new_dtstart(event_start);
911 /* Force it to serialize as a date-only rather than date/time */
912 icalproperty_set_value(prop, icalvalue_new_date(event_start));
915 if (prop) icalcomponent_add_property(vevent, prop);
916 else icalproperty_free(prop);
918 while (prop = icalcomponent_get_first_property(vevent,
919 ICAL_DTEND_PROPERTY), prop != NULL) {
920 icalcomponent_remove_property(vevent, prop);
921 icalproperty_free(prop);
923 while (prop = icalcomponent_get_first_property(vevent,
924 ICAL_DURATION_PROPERTY), prop != NULL) {
925 icalcomponent_remove_property(vevent, prop);
926 icalproperty_free(prop);
930 icaltime_from_webform_dateonly(&t, "dtend");
932 /* with this field supposed to be non-inclusive we have to add one day */
933 icaltime_adjust(&t, 1, 0, 0, 0);
936 icaltime_from_webform(&t, "dtend");
939 icalcomponent_add_property(vevent,
940 icalproperty_new_dtend(icaltime_normalize(t)
944 /* recurrence rules -- begin */
946 /* remove any existing rule */
947 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
948 icalcomponent_remove_property(vevent, prop);
949 icalproperty_free(prop);
952 if (yesbstr("is_recur")) {
953 struct icalrecurrencetype recur;
954 icalrecurrencetype_clear(&recur);
956 recur.interval = atoi(bstr("interval"));
957 recur.freq = atoi(bstr("freq"));
961 /* These can't happen; they're disabled. */
962 case ICAL_SECONDLY_RECURRENCE:
964 case ICAL_MINUTELY_RECURRENCE:
966 case ICAL_HOURLY_RECURRENCE:
969 /* Daily is valid but there are no further inputs. */
970 case ICAL_DAILY_RECURRENCE:
973 /* These are the real options. */
975 case ICAL_WEEKLY_RECURRENCE:
977 for (i=0; i<7; ++i) {
978 snprintf(buf, sizeof buf, "weekday%d", i);
979 if (YESBSTR(buf)) recur.by_day[j++] =
980 icalrecurrencetype_day_day_of_week(i+1);
982 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
985 case ICAL_MONTHLY_RECURRENCE:
986 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
987 recur.by_month_day[0] = event_start.day;
988 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
990 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
991 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
992 + atoi(bstr("rrmweekday")) + 1;
993 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
997 case ICAL_YEARLY_RECURRENCE:
998 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
999 /* no further action is needed here */
1001 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
1002 recur.by_month[0] = atoi(bstr("rrymonth"));
1003 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
1004 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
1005 + atoi(bstr("rrymweekday")) + 1;
1006 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
1010 /* This one can't happen either. */
1011 case ICAL_NO_RECURRENCE:
1015 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
1016 recur.count = atoi(bstr("rrcount"));
1018 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
1019 icaltime_from_webform_dateonly(&recur.until, "rruntil");
1022 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
1025 /* recurrence rules -- end */
1027 /* See if transparency is indicated */
1028 if (havebstr("transp")) {
1029 if (!strcasecmp(bstr("transp"), "opaque")) {
1030 formtransp = ICAL_TRANSP_OPAQUE;
1032 else if (!strcasecmp(bstr("transp"), "transparent")) {
1033 formtransp = ICAL_TRANSP_TRANSPARENT;
1036 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1038 icalcomponent_remove_property(vevent, prop);
1039 icalproperty_free(prop);
1042 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1045 /* Give this event a UID if it doesn't have one. */
1046 if (icalcomponent_get_first_property(vevent,
1047 ICAL_UID_PROPERTY) == NULL) {
1049 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1052 /* Increment the sequence ID */
1053 while (prop = icalcomponent_get_first_property(vevent,
1054 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1055 i = icalproperty_get_sequence(prop);
1056 if (i > sequence) sequence = i;
1057 icalcomponent_remove_property(vevent, prop);
1058 icalproperty_free(prop);
1061 icalcomponent_add_property(vevent,
1062 icalproperty_new_sequence(sequence)
1066 * Set the organizer, only if one does not already exist *and*
1067 * the form is supplying one
1069 strcpy(buf, bstr("organizer"));
1070 if ( (icalcomponent_get_first_property(vevent,
1071 ICAL_ORGANIZER_PROPERTY) == NULL)
1072 && (!IsEmptyStr(buf)) ) {
1074 /* set new organizer */
1075 sprintf(organizer_string, "MAILTO:%s", buf);
1076 icalcomponent_add_property(vevent,
1077 icalproperty_new_organizer(organizer_string)
1083 * Add any new attendees listed in the web form
1086 /* First, strip out the parenthesized partstats. */
1087 strcpy(form_attendees, bstr("attendees"));
1088 while ( stripout(form_attendees, '(', ')') != 0);
1090 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1091 j = strlen(form_attendees);
1092 for (i=0; i<j; ++i) {
1093 if (form_attendees[i] == ',') {
1094 form_attendees[i] = '\n';
1095 while (isspace(form_attendees[i+1])) {
1096 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1102 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1103 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1105 if (!IsEmptyStr(buf)) {
1106 sprintf(attendee_string, "MAILTO:%s", buf);
1109 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1110 ch = icalproperty_get_attendee(attendee);
1111 if ((ch != NULL) && !strcasecmp(attendee_string, ch))
1117 icalcomponent_add_property(vevent,
1118 icalproperty_new_attendee(attendee_string)
1125 * Remove any attendees *not* listed in the web form
1127 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1128 ch = icalproperty_get_attendee(attendee);
1129 if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) {
1130 safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
1131 striplt(attendee_string);
1133 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1134 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1136 if (!strcasecmp(buf, attendee_string)) ++foundit;
1139 icalcomponent_remove_property(vevent, attendee);
1140 icalproperty_free(attendee);
1147 * Encapsulate event into full VCALENDAR component. Clone it first,
1148 * for two reasons: one, it's easier to just free the whole thing
1149 * when we're done instead of unbundling, but more importantly, we
1150 * can't encapsulate something that may already be encapsulated
1153 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1155 /* Set the method to PUBLISH */
1156 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1158 /* If the user clicked 'Save' then save it to the server. */
1159 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1160 serv_puts("ENT0 1|||4|||1|");
1161 serv_getln(buf, sizeof buf);
1162 if (buf[0] == '8') {
1163 serv_puts("Content-type: text/calendar");
1165 serv_puts(icalcomponent_as_ical_string(encaps));
1168 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1169 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1172 if (buf[0] == '2') {
1173 strcpy(WC->ImportantMessage, &buf[4]);
1175 icalmemory_free_ring ();
1176 icalcomponent_free(encaps);
1180 /* Or, check attendee availability if the user asked for that. */
1181 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1183 /* Call this function, which does the real work */
1184 check_attendee_availability(encaps);
1186 /* This displays the form again, with our annotations */
1187 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1189 icalcomponent_free(encaps);
1192 if (encaps != NULL) {
1193 icalcomponent_free(encaps);
1200 * If the user clicked 'Delete' then delete it.
1202 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1203 serv_printf("DELE %ld", lbstr("msgnum"));
1204 serv_getln(buf, sizeof buf);
1207 if (created_new_vevent) {
1208 icalcomponent_free(vevent);
1211 /* If this was a save or delete, go back to the calendar or summary view. */
1212 if (!havebstr("check_button")) {
1213 if (!strcasecmp(bstr("calview"), "summary")) {
1217 readloop(readfwd, eUseDefault);