4 * Editing calendar events.
11 * Display an event by itself (for editing)
12 * supplied_vevent the event to edit
13 * msgnum reference on the citserver
15 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
16 int unread, struct calview *calv)
18 icalcomponent *vevent;
21 struct icaltimetype t_start, t_end;
24 int created_new_vevent = 0;
25 icalproperty *organizer = NULL;
26 char organizer_string[SIZ];
27 icalproperty *attendee = NULL;
28 char attendee_string[SIZ];
30 int organizer_is_me = 0;
33 char weekday_labels[7][32];
34 char month_labels[12][32];
37 get_pref_long("weekstart", &weekstart, 17);
38 if (weekstart > 6) weekstart = 0;
40 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
41 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
44 /* populate the weekday names - begin */
46 localtime_r(&now, &tm_now);
47 while (tm_now.tm_wday != 0) {
49 localtime_r(&now, &tm_now);
52 localtime_r(&now, &tm_now);
53 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
56 /* populate the weekday names - end */
58 /* populate the month names - begin */
59 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
60 localtime_r(&now, &tm_now);
61 for (i=0; i<12; ++i) {
62 localtime_r(&now, &tm_now);
63 wc_strftime(month_labels[i], 32, "%B", &tm_now);
66 /* populate the month names - end */
69 strcpy(organizer_string, "");
70 strcpy(attendee_string, "");
72 if (supplied_vevent != NULL) {
73 vevent = supplied_vevent;
75 /* Convert all timestamps to UTC to make them easier to process. */
76 ical_dezonify(vevent);
79 * If we're looking at a fully encapsulated VCALENDAR
80 * rather than a VEVENT component, attempt to use the first
81 * relevant VEVENT subcomponent. If there is none, the
82 * NULL returned by icalcomponent_get_first_component() will
83 * tell the next iteration of this function to create a
86 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
87 display_edit_individual_event(
88 icalcomponent_get_first_component(
89 vevent, ICAL_VEVENT_COMPONENT),
90 msgnum, from, unread, NULL
96 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
97 created_new_vevent = 1;
100 /* Learn the sequence */
101 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
103 sequence = icalproperty_get_sequence(p);
107 output_headers(1, 1, 2, 0, 0, 0);
108 wprintf("<div id=\"banner\">\n");
110 wprintf(_("Add or edit an event"));
114 wprintf("<div id=\"content\" class=\"service\">\n");
116 wprintf("<div class=\"fix_scrollbar_bug\">");
118 /************************************************************
119 * Uncomment this to see the UID in calendar events for debugging
121 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
123 escputs((char *)icalproperty_get_comment(p));
126 wprintf("SEQUENCE == %d<br />\n", sequence);
127 *************************************************************/
129 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
130 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
132 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
134 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
136 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
138 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
140 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
149 tabbed_dialog(3, tabnames);
152 /* Put it in a borderless table so it lines up nicely */
153 wprintf("<TABLE border=0 width=100%%>\n");
155 wprintf("<TR><TD><B>");
156 wprintf(_("Summary"));
157 wprintf("</B></TD><TD>\n"
158 "<INPUT TYPE=\"text\" NAME=\"summary\" "
159 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
160 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
162 escputs((char *)icalproperty_get_comment(p));
164 wprintf("\"></TD></TR>\n");
166 wprintf("<TR><TD><B>");
167 wprintf(_("Location"));
168 wprintf("</B></TD><TD>\n"
169 "<INPUT TYPE=\"text\" NAME=\"location\" "
170 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
171 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
173 escputs((char *)icalproperty_get_comment(p));
175 wprintf("\"></TD></TR>\n");
177 wprintf("<TR><TD><B>");
179 wprintf("</B></TD><TD>\n");
180 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
182 t_start = icalproperty_get_dtstart(p);
183 if (t_start.is_date) {
190 localtime_r(&now, &tm_now);
191 if (havebstr("year")) {
192 tm_now.tm_year = ibstr("year") - 1900;
193 tm_now.tm_mon = ibstr("month") - 1;
194 tm_now.tm_mday = ibstr("day");
196 if (havebstr("hour")) {
197 tm_now.tm_hour = ibstr("hour");
198 tm_now.tm_min = ibstr("minute");
207 t_start = icaltime_from_timet_with_zone(
209 ((yesbstr("alldayevent")) ? 1 : 0),
210 icaltimezone_get_utc_timezone()
215 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
217 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
218 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
220 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
224 wprintf("</TD></TR>\n");
227 * If this is an all-day-event, set the end time to be identical to
228 * the start time (the hour/minute/second will be set to midnight).
229 * Otherwise extract or create it.
231 wprintf("<TR><TD><B>");
233 wprintf("</B></TD><TD id=\"dtendcell\">\n");
234 if (t_start.is_date) {
238 p = icalcomponent_get_first_property(vevent,
239 ICAL_DTEND_PROPERTY);
241 t_end = icalproperty_get_dtend(p);
245 * If this is not an all-day event and there is no
246 * end time specified, make the default one hour
247 * from the start time.
252 t_end = icaltime_normalize(t_end);
253 /* t_end = icaltime_from_timet(now, 0); */
256 display_icaltimetype_as_webform(&t_end, "dtend", 0);
257 wprintf("</TD></TR>\n");
259 wprintf("<TR><TD><B>");
261 wprintf("</B></TD><TD>\n"
262 "<TEXTAREA NAME=\"description\" wrap=soft "
263 "ROWS=5 COLS=80 WIDTH=80>\n"
265 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
267 escputs((char *)icalproperty_get_comment(p));
269 wprintf("</TEXTAREA></TD></TR>");
272 * For a new event, the user creating the event should be the
273 * organizer. Set this field accordingly.
275 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
277 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
278 icalcomponent_add_property(vevent,
279 icalproperty_new_organizer(organizer_string)
284 * Determine who is the organizer of this event.
285 * We need to determine "me" or "not me."
287 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
288 if (organizer != NULL) {
289 strcpy(organizer_string, icalproperty_get_organizer(organizer));
290 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
291 strcpy(organizer_string, &organizer_string[7]);
292 striplt(organizer_string);
293 serv_printf("ISME %s", organizer_string);
294 serv_getln(buf, sizeof buf);
301 wprintf("<TR><TD><B>");
302 wprintf(_("Organizer"));
303 wprintf("</B></TD><TD>");
304 escputs(organizer_string);
305 if (organizer_is_me) {
306 wprintf(" <FONT SIZE=-1><I>");
307 wprintf(_("(you are the organizer)"));
308 wprintf("</I></FONT>\n");
312 * Transmit the organizer as a hidden field. We don't want the user
313 * to be able to change it, but we do want it fed back to the server,
314 * especially if this is a new event and there is no organizer already
315 * in the calendar object.
317 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
318 escputs(organizer_string);
321 wprintf("</TD></TR>\n");
324 wprintf("<TR><TD><B>");
325 wprintf(_("Show time as:"));
326 wprintf("</B></TD><TD>");
328 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
330 /* No transparency found. Default to opaque (busy). */
331 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
333 icalcomponent_add_property(vevent, p);
337 v = icalproperty_get_value(p);
343 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
344 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
349 wprintf(" ");
351 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
352 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
358 wprintf("</TD></TR>\n");
361 /* Done with properties. */
362 wprintf("</TABLE>\n");
366 /* Attendees tab (need to move things here) */
368 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
369 wprintf("<TR><TD><B>");
370 wprintf(_("Attendees"));
373 wprintf(_("(One per line)"));
374 wprintf("</font>\n");
376 /* Pop open an address book -- begin */
378 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
380 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
385 /* Pop open an address book -- end */
388 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
389 "ROWS=3 COLS=80 WIDTH=80>\n",
390 (organizer_is_me ? "" : "DISABLED ")
393 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
395 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
396 strcpy(attendee_string, icalproperty_get_attendee(attendee));
397 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
399 /* screen name or email address */
400 strcpy(attendee_string, &attendee_string[7]);
401 striplt(attendee_string);
402 if (i++) wprintf("\n");
403 escputs(attendee_string);
406 /* participant status */
407 partstat_as_string(buf, attendee);
411 wprintf("</TEXTAREA></TD></TR>\n");
412 wprintf("</TABLE>\n");
417 icalproperty *rrule = NULL;
418 struct icalrecurrencetype recur;
420 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
422 recur = icalproperty_get_rrule(rrule);
425 /* blank recurrence with some sensible defaults */
426 memset(&recur, 0, sizeof(struct icalrecurrencetype));
428 recur.until = icaltime_null_time();
430 recur.freq = ICAL_WEEKLY_RECURRENCE;
433 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
435 "onclick=\"RecurrenceShowHide();\""
437 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
438 _("This is a recurring event")
441 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
443 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
445 char *frequency_units[] = {
465 wprintf("<tr><td><b>");
466 wprintf(_("Recurrence rule"));
467 wprintf("</b></td><td>");
469 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
470 wprintf("%s ", _("Repeats every"));
472 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
473 wprintf("value=\"%d\"> ", recur.interval);
475 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
476 "onChange=\"RecurrenceShowHide();\">\n");
477 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
478 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
479 ((i == recur.freq) ? "selected " : ""),
480 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
485 wprintf("</select>\n");
487 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
488 wprintf("%s<br>", _("on these weekdays:"));
490 char weekday_is_selected[7];
491 memset(weekday_is_selected, 0, 7);
493 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
494 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
495 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
498 for (j=0; j<7; ++j) {
499 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
500 weekday_is_selected[j] = 1;
506 for (j=0; j<7; ++j) {
507 i = ((j + (int)weekstart) % 7);
508 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
509 if (weekday_is_selected[i]) wprintf(" checked");
510 wprintf(">%s\n", weekday_labels[i]);
512 wprintf("</div>\n"); /* end 'weekday_selector' div */
518 int which_rrmonthtype_is_preselected = 0;
519 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
521 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
522 "value=\"rrmonthtype_mday\" "
523 "%s onChange=\"RecurrenceShowHide();\">",
524 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
527 int rrmday = t_start.day;
528 int rrmweekday = icaltime_day_of_week(t_start) - 1;
530 /* Figure out what week of the month we're in */
531 icaltimetype day1 = t_start;
533 int weekbase = icaltime_week_number(day1);
534 int rrmweek = icaltime_week_number(t_start) - weekbase + 1;
536 /* Are we going by day of the month or week/day? */
538 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
539 which_rrmonthtype_is_preselected = 0;
540 rrmday = recur.by_month_day[0];
542 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
543 which_rrmonthtype_is_preselected = 1;
544 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
545 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
548 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
551 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
552 "value=\"rrmonthtype_wday\" "
553 "%s onChange=\"RecurrenceShowHide();\">",
554 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
557 wprintf(_("on the "));
558 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
559 "onChange=\"RecurrenceShowHide();\">\n");
560 for (i=1; i<=5; ++i) {
561 wprintf("<option %svalue=\"%d\">%s</option>\n",
562 ((i==rrmweek) ? "selected " : ""),
567 wprintf("</select> \n");
569 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
570 "onChange=\"RecurrenceShowHide();\">\n");
571 for (j=0; j<7; ++j) {
572 i = ((j + (int)weekstart) % 7);
573 wprintf("<option %svalue=\"%d\">%s</option>\n",
574 ((i==rrmweekday) ? "selected " : ""),
579 wprintf("</select>");
581 wprintf(" %s<br />\n", _("of the month"));
583 wprintf("</div>\n"); /* end 'monthday_selector' div */
586 int rrymweek = rrmweek;
587 int rrymweekday = rrmweekday;
588 int rrymonth = t_start.month;
589 int which_rryeartype_is_preselected = 0;
591 if ( (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
592 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) ) {
593 which_rryeartype_is_preselected = 1;
594 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
595 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
596 rrymonth = recur.by_month[0];
599 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
601 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
602 "value=\"rryeartype_ymday\" "
603 "%s onChange=\"RecurrenceShowHide();\">",
604 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
606 wprintf(_("every "));
607 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
609 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
610 "value=\"rryeartype_ywday\" "
611 "%s onChange=\"RecurrenceShowHide();\">",
612 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
615 wprintf(_("on the "));
616 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
617 "onChange=\"RecurrenceShowHide();\">\n");
618 for (i=1; i<=5; ++i) {
619 wprintf("<option %svalue=\"%d\">%s</option>\n",
620 ((i==rrymweek) ? "selected " : ""),
625 wprintf("</select> \n");
627 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
628 "onChange=\"RecurrenceShowHide();\">\n");
629 for (j=0; j<7; ++j) {
630 i = ((j + (int)weekstart) % 7);
631 wprintf("<option %svalue=\"%d\">%s</option>\n",
632 ((i==rrymweekday) ? "selected " : ""),
637 wprintf("</select>");
639 wprintf(" %s ", _("of"));
641 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
642 "onChange=\"RecurrenceShowHide();\">\n");
643 for (i=1; i<=12; ++i) {
644 wprintf("<option %svalue=\"%d\">%s</option>\n",
645 ((i==rrymonth) ? "selected " : ""),
650 wprintf("</select>");
653 wprintf("</div>\n"); /* end 'yearday_selector' div */
655 wprintf("</td></tr>\n");
658 int which_rrend_is_preselected = 0;
659 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
660 if (recur.count > 0) which_rrend_is_preselected = 1;
662 wprintf("<tr><td><b>");
663 wprintf(_("Recurrence range"));
664 wprintf("</b></td><td>\n");
666 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
667 "value=\"rrend_none\" "
668 "%s onChange=\"RecurrenceShowHide();\">",
669 ((which_rrend_is_preselected == 0) ? "checked" : "")
671 wprintf("%s<br />\n", _("No ending date"));
673 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
674 "value=\"rrend_count\" "
675 "%s onChange=\"RecurrenceShowHide();\">",
676 ((which_rrend_is_preselected == 1) ? "checked" : "")
678 wprintf(_("Repeat this event"));
679 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
680 wprintf("value=\"%d\"> ", recur.count);
684 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
685 "value=\"rrend_until\" "
686 "%s onChange=\"RecurrenceShowHide();\">",
687 ((which_rrend_is_preselected == 2) ? "checked" : "")
689 wprintf(_("Repeat this event until "));
691 if (icaltime_is_null_time(recur.until)) {
692 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
694 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
697 wprintf("</td></tr>\n");
699 wprintf("</table>\n");
700 wprintf("</div>\n"); /* end 'rrule' div */
704 /* submit buttons (common area beneath the tabs) */
707 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
709 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
711 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
714 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
718 _("Check attendee availability"),
721 wprintf("</FORM>\n");
724 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
726 StrBufAppendPrintf(WC->trailing_javascript,
727 "eventEditAllDay(); \n"
728 "RecurrenceShowHide(); \n"
730 address_book_popup();
733 if (created_new_vevent) {
734 icalcomponent_free(vevent);
739 * Save an edited event
741 * supplied_vevent: the event to save
742 * msgnum: the index on the citserver
744 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
745 int unread, struct calview *calv) {
748 icalcomponent *vevent, *encaps;
749 int created_new_vevent = 0;
750 int all_day_event = 0;
751 struct icaltimetype event_start, t;
752 icalproperty *attendee = NULL;
753 char attendee_string[SIZ];
756 char form_attendees[SIZ];
757 char organizer_string[SIZ];
759 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
761 if (supplied_vevent != NULL) {
762 vevent = supplied_vevent;
764 /* Convert all timestamps to UTC to make them easier to process. */
765 ical_dezonify(vevent);
768 * If we're looking at a fully encapsulated VCALENDAR
769 * rather than a VEVENT component, attempt to use the first
770 * relevant VEVENT subcomponent. If there is none, the
771 * NULL returned by icalcomponent_get_first_component() will
772 * tell the next iteration of this function to create a
775 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
776 save_individual_event(
777 icalcomponent_get_first_component(
778 vevent, ICAL_VEVENT_COMPONENT),
779 msgnum, from, unread, NULL
785 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
786 created_new_vevent = 1;
789 if ( (havebstr("save_button"))
790 || (havebstr("check_button")) ) {
792 /* Replace values in the component with ones from the form */
794 while (prop = icalcomponent_get_first_property(vevent,
795 ICAL_SUMMARY_PROPERTY), prop != NULL) {
796 icalcomponent_remove_property(vevent, prop);
797 icalproperty_free(prop);
800 if (havebstr("summary")) {
802 icalcomponent_add_property(vevent,
803 icalproperty_new_summary(bstr("summary")));
805 icalcomponent_add_property(vevent,
806 icalproperty_new_summary("Untitled Event"));
809 while (prop = icalcomponent_get_first_property(vevent,
810 ICAL_LOCATION_PROPERTY), prop != NULL) {
811 icalcomponent_remove_property(vevent, prop);
812 icalproperty_free(prop);
814 if (havebstr("location")) {
815 icalcomponent_add_property(vevent,
816 icalproperty_new_location(bstr("location")));
818 while (prop = icalcomponent_get_first_property(vevent,
819 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
820 icalcomponent_remove_property(vevent, prop);
821 icalproperty_free(prop);
823 if (havebstr("description")) {
824 icalcomponent_add_property(vevent,
825 icalproperty_new_description(bstr("description")));
828 while (prop = icalcomponent_get_first_property(vevent,
829 ICAL_DTSTART_PROPERTY), prop != NULL) {
830 icalcomponent_remove_property(vevent, prop);
831 icalproperty_free(prop);
834 if (yesbstr("alldayevent")) {
842 icaltime_from_webform_dateonly(&event_start, "dtstart");
845 icaltime_from_webform(&event_start, "dtstart");
849 * The following odd-looking snippet of code looks like it
850 * takes some unnecessary steps. It is done this way because
851 * libical incorrectly turns an "all day event" into a normal
852 * event starting at midnight (i.e. it serializes as date/time
853 * instead of just date) unless icalvalue_new_date() is used.
854 * So we force it, if this is an all day event.
856 prop = icalproperty_new_dtstart(event_start);
858 icalproperty_set_value(prop, icalvalue_new_date(event_start));
861 if (prop) icalcomponent_add_property(vevent, prop);
862 else icalproperty_free(prop);
864 while (prop = icalcomponent_get_first_property(vevent,
865 ICAL_DTEND_PROPERTY), prop != NULL) {
866 icalcomponent_remove_property(vevent, prop);
867 icalproperty_free(prop);
869 while (prop = icalcomponent_get_first_property(vevent,
870 ICAL_DURATION_PROPERTY), prop != NULL) {
871 icalcomponent_remove_property(vevent, prop);
872 icalproperty_free(prop);
875 if (all_day_event == 0) {
876 icaltime_from_webform(&t, "dtend");
877 icalcomponent_add_property(vevent,
878 icalproperty_new_dtend(icaltime_normalize(t)
883 /* recurrence rules -- begin */
885 /* remove any existing rule */
886 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
887 icalcomponent_remove_property(vevent, prop);
888 icalproperty_free(prop);
891 if (yesbstr("is_recur")) {
892 struct icalrecurrencetype recur;
893 icalrecurrencetype_clear(&recur);
895 recur.interval = atoi(bstr("interval"));
896 recur.freq = atoi(bstr("freq"));
900 /* These can't happen; they're disabled. */
901 case ICAL_SECONDLY_RECURRENCE:
903 case ICAL_MINUTELY_RECURRENCE:
905 case ICAL_HOURLY_RECURRENCE:
908 /* Daily is valid but there are no further inputs. */
909 case ICAL_DAILY_RECURRENCE:
912 /* These are the real options. */
914 case ICAL_WEEKLY_RECURRENCE:
916 for (i=0; i<7; ++i) {
917 snprintf(buf, sizeof buf, "weekday%d", i);
918 if (YESBSTR(buf)) recur.by_day[j++] =
919 icalrecurrencetype_day_day_of_week(i+1);
921 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
924 case ICAL_MONTHLY_RECURRENCE:
925 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
926 recur.by_month_day[0] = event_start.day;
927 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
929 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
930 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
931 + atoi(bstr("rrmweekday")) + 1;
932 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
936 case ICAL_YEARLY_RECURRENCE:
937 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
938 /* no further action is needed here */
940 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
941 recur.by_month[0] = atoi(bstr("rrymonth"));
942 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
943 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
944 + atoi(bstr("rrymweekday")) + 1;
945 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
949 /* This one can't happen either. */
950 case ICAL_NO_RECURRENCE:
954 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
955 recur.count = atoi(bstr("rrcount"));
957 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
958 icaltime_from_webform_dateonly(&recur.until, "rruntil");
961 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
964 /* recurrence rules -- end */
966 /* See if transparency is indicated */
967 if (havebstr("transp")) {
968 if (!strcasecmp(bstr("transp"), "opaque")) {
969 formtransp = ICAL_TRANSP_OPAQUE;
971 else if (!strcasecmp(bstr("transp"), "transparent")) {
972 formtransp = ICAL_TRANSP_TRANSPARENT;
975 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
977 icalcomponent_remove_property(vevent, prop);
978 icalproperty_free(prop);
981 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
984 /* Give this event a UID if it doesn't have one. */
985 if (icalcomponent_get_first_property(vevent,
986 ICAL_UID_PROPERTY) == NULL) {
988 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
991 /* Increment the sequence ID */
992 while (prop = icalcomponent_get_first_property(vevent,
993 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
994 i = icalproperty_get_sequence(prop);
995 if (i > sequence) sequence = i;
996 icalcomponent_remove_property(vevent, prop);
997 icalproperty_free(prop);
1000 icalcomponent_add_property(vevent,
1001 icalproperty_new_sequence(sequence)
1005 * Set the organizer, only if one does not already exist *and*
1006 * the form is supplying one
1008 strcpy(buf, bstr("organizer"));
1009 if ( (icalcomponent_get_first_property(vevent,
1010 ICAL_ORGANIZER_PROPERTY) == NULL)
1011 && (!IsEmptyStr(buf)) ) {
1013 /* set new organizer */
1014 sprintf(organizer_string, "MAILTO:%s", buf);
1015 icalcomponent_add_property(vevent,
1016 icalproperty_new_organizer(organizer_string)
1022 * Add any new attendees listed in the web form
1025 /* First, strip out the parenthesized partstats. */
1026 strcpy(form_attendees, bstr("attendees"));
1027 stripout(form_attendees, '(', ')');
1029 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1030 j = strlen(form_attendees);
1031 for (i=0; i<j; ++i) {
1032 if (form_attendees[i] == ',') {
1033 form_attendees[i] = '\n';
1034 while (isspace(form_attendees[i+1])) {
1035 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1041 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1042 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1044 if (!IsEmptyStr(buf)) {
1045 sprintf(attendee_string, "MAILTO:%s", buf);
1048 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1049 if (!strcasecmp(attendee_string,
1050 icalproperty_get_attendee(attendee)))
1056 icalcomponent_add_property(vevent,
1057 icalproperty_new_attendee(attendee_string)
1064 * Remove any attendees *not* listed in the web form
1066 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1067 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1068 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1069 strcpy(attendee_string, &attendee_string[7]);
1070 striplt(attendee_string);
1072 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1073 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1075 if (!strcasecmp(buf, attendee_string)) ++foundit;
1078 icalcomponent_remove_property(vevent, attendee);
1079 icalproperty_free(attendee);
1086 * Encapsulate event into full VCALENDAR component. Clone it first,
1087 * for two reasons: one, it's easier to just free the whole thing
1088 * when we're done instead of unbundling, but more importantly, we
1089 * can't encapsulate something that may already be encapsulated
1092 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1094 /* Set the method to PUBLISH */
1095 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1097 /* If the user clicked 'Save' then save it to the server. */
1098 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1099 serv_puts("ENT0 1|||4|||1|");
1100 serv_getln(buf, sizeof buf);
1101 if (buf[0] == '8') {
1102 serv_puts("Content-type: text/calendar");
1104 serv_puts(icalcomponent_as_ical_string(encaps));
1107 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1108 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1111 if (buf[0] == '2') {
1112 strcpy(WC->ImportantMessage, &buf[4]);
1114 icalmemory_free_ring ();
1115 icalcomponent_free(encaps);
1119 /* Or, check attendee availability if the user asked for that. */
1120 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1122 /* Call this function, which does the real work */
1123 check_attendee_availability(encaps);
1125 /* This displays the form again, with our annotations */
1126 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1128 icalcomponent_free(encaps);
1131 if (encaps != NULL) {
1132 icalcomponent_free(encaps);
1139 * If the user clicked 'Delete' then delete it.
1141 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1142 serv_printf("DELE %ld", lbstr("msgnum"));
1143 serv_getln(buf, sizeof buf);
1146 if (created_new_vevent) {
1147 icalcomponent_free(vevent);
1150 /* If this was a save or delete, go back to the calendar view. */
1151 if (!havebstr("check_button")) {
1152 readloop("readfwd");