4 * Editing calendar events.
12 * Display an event by itself (for editing)
13 * supplied_vevent the event to edit
14 * msgnum reference on the citserver
16 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
17 int unread, calview *calv)
19 icalcomponent *vevent;
22 struct icaltimetype t_start, t_end;
25 int created_new_vevent = 0;
26 icalproperty *organizer = NULL;
27 char organizer_string[SIZ];
28 icalproperty *attendee = NULL;
29 char attendee_string[SIZ];
31 int organizer_is_me = 0;
34 char weekday_labels[7][32];
35 char month_labels[12][32];
37 icalproperty *rrule = NULL;
38 struct icalrecurrencetype recur;
41 tabnames[0] = _("Event");
42 tabnames[1] = _("Attendees");
43 tabnames[2] = _("Recurrence");
45 get_pref_long("weekstart", &weekstart, 17);
46 if (weekstart > 6) weekstart = 0;
48 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
49 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
52 /* populate the weekday names - begin */
54 localtime_r(&now, &tm_now);
55 while (tm_now.tm_wday != 0) {
57 localtime_r(&now, &tm_now);
60 localtime_r(&now, &tm_now);
61 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
64 /* populate the weekday names - end */
66 /* populate the month names - begin */
67 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
68 localtime_r(&now, &tm_now);
69 for (i=0; i<12; ++i) {
70 localtime_r(&now, &tm_now);
71 wc_strftime(month_labels[i], 32, "%B", &tm_now);
74 /* populate the month names - end */
77 strcpy(organizer_string, "");
78 strcpy(attendee_string, "");
80 if (supplied_vevent != NULL) {
81 vevent = supplied_vevent;
83 /* Convert all timestamps to UTC to make them easier to process. */
84 ical_dezonify(vevent);
87 * If we're looking at a fully encapsulated VCALENDAR
88 * rather than a VEVENT component, attempt to use the first
89 * relevant VEVENT subcomponent. If there is none, the
90 * NULL returned by icalcomponent_get_first_component() will
91 * tell the next iteration of this function to create a
94 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
95 display_edit_individual_event(
96 icalcomponent_get_first_component(
97 vevent, ICAL_VEVENT_COMPONENT),
98 msgnum, from, unread, NULL
104 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
105 created_new_vevent = 1;
108 /* Learn the sequence */
109 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
111 sequence = icalproperty_get_sequence(p);
115 output_headers(1, 1, 2, 0, 0, 0);
116 wprintf("<div id=\"banner\">\n");
118 wprintf(_("Add or edit an event"));
122 wprintf("<div id=\"content\" class=\"service\">\n");
124 wprintf("<div class=\"fix_scrollbar_bug\">");
126 /************************************************************
127 * Uncomment this to see the UID in calendar events for debugging
129 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
131 escputs((char *)icalproperty_get_comment(p));
134 wprintf("SEQUENCE == %d<br />\n", sequence);
135 *************************************************************/
137 wprintf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
138 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
140 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
142 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
144 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
146 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
148 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
152 tabbed_dialog(3, tabnames);
155 /* Put it in a borderless table so it lines up nicely */
156 wprintf("<TABLE border=0 width=100%%>\n");
158 wprintf("<TR><TD><B>");
159 wprintf(_("Summary"));
160 wprintf("</B></TD><TD>\n"
161 "<INPUT TYPE=\"text\" NAME=\"summary\" "
162 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
163 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
165 escputs((char *)icalproperty_get_comment(p));
167 wprintf("\"></TD></TR>\n");
169 wprintf("<TR><TD><B>");
170 wprintf(_("Location"));
171 wprintf("</B></TD><TD>\n"
172 "<INPUT TYPE=\"text\" NAME=\"location\" "
173 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
174 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
176 escputs((char *)icalproperty_get_comment(p));
178 wprintf("\"></TD></TR>\n");
180 wprintf("<TR><TD><B>");
182 wprintf("</B></TD><TD>\n");
183 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
185 t_start = icalproperty_get_dtstart(p);
186 if (t_start.is_date) {
193 localtime_r(&now, &tm_now);
194 if (havebstr("year")) {
195 tm_now.tm_year = ibstr("year") - 1900;
196 tm_now.tm_mon = ibstr("month") - 1;
197 tm_now.tm_mday = ibstr("day");
199 if (havebstr("hour")) {
200 tm_now.tm_hour = ibstr("hour");
201 tm_now.tm_min = ibstr("minute");
210 t_start = icaltime_from_timet_with_zone(
212 ((yesbstr("alldayevent")) ? 1 : 0),
213 icaltimezone_get_utc_timezone()
218 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
220 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
221 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
223 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
227 wprintf("</TD></TR>\n");
229 wprintf("<TR><TD><B>");
231 wprintf("</B></TD><TD id=\"dtendcell\">\n");
232 p = icalcomponent_get_first_property(vevent,
233 ICAL_DTEND_PROPERTY);
235 t_end = icalproperty_get_dtend(p);
238 * If this is an all-day-event, the end time is set to real end
239 * day + 1, so we have to adjust accordingly.
241 if (t_start.is_date) {
242 icaltime_adjust(&t_end, -1, 0, 0, 0);
246 if (created_new_vevent == 1) {
247 /* set default duration */
248 if (t_start.is_date) {
250 * If this is an all-day-event, set the end time to be identical to
251 * the start time (the hour/minute/second will be set to midnight).
257 * If this is not an all-day event and there is no
258 * end time specified, make the default one hour
259 * from the start time.
264 t_end = icaltime_normalize(t_end);
265 /* t_end = icaltime_from_timet(now, 0); */
270 * If an existing event has no end date/time this is
271 * supposed to mean end = start.
276 display_icaltimetype_as_webform(&t_end, "dtend", 0);
277 wprintf("</TD></TR>\n");
279 wprintf("<TR><TD><B>");
281 wprintf("</B></TD><TD>\n"
282 "<TEXTAREA NAME=\"description\" wrap=soft "
283 "ROWS=5 COLS=72 WIDTH=72>\n"
285 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
287 escputs((char *)icalproperty_get_comment(p));
289 wprintf("</TEXTAREA></TD></TR>");
292 * For a new event, the user creating the event should be the
293 * organizer. Set this field accordingly.
295 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
297 sprintf(organizer_string, "MAILTO:%s", ChrPtr(WC->cs_inet_email));
298 icalcomponent_add_property(vevent,
299 icalproperty_new_organizer(organizer_string)
304 * Determine who is the organizer of this event.
305 * We need to determine "me" or "not me."
307 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
308 if (organizer != NULL) {
309 strcpy(organizer_string, icalproperty_get_organizer(organizer));
310 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
311 strcpy(organizer_string, &organizer_string[7]);
312 striplt(organizer_string);
313 serv_printf("ISME %s", organizer_string);
314 serv_getln(buf, sizeof buf);
321 wprintf("<TR><TD><B>");
322 wprintf(_("Organizer"));
323 wprintf("</B></TD><TD>");
324 escputs(organizer_string);
325 if (organizer_is_me) {
326 wprintf(" <FONT SIZE=-1><I>");
327 wprintf(_("(you are the organizer)"));
328 wprintf("</I></FONT>\n");
332 * Transmit the organizer as a hidden field. We don't want the user
333 * to be able to change it, but we do want it fed back to the server,
334 * especially if this is a new event and there is no organizer already
335 * in the calendar object.
337 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
338 escputs(organizer_string);
341 wprintf("</TD></TR>\n");
344 wprintf("<TR><TD><B>");
345 wprintf(_("Show time as:"));
346 wprintf("</B></TD><TD>");
348 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
350 /* No transparency found. Default to opaque (busy). */
351 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
353 icalcomponent_add_property(vevent, p);
357 v = icalproperty_get_value(p);
363 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
364 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
369 wprintf(" ");
371 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
372 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
378 wprintf("</TD></TR>\n");
381 /* Done with properties. */
382 wprintf("</TABLE>\n");
386 /* Attendees tab (need to move things here) */
388 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
389 wprintf("<TR><TD><B>");
390 wprintf(_("Attendees"));
393 wprintf(_("(One per line)"));
394 wprintf("</font>\n");
396 /* Pop open an address book -- begin */
398 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
400 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
405 /* Pop open an address book -- end */
408 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
409 "onchange=\"EnableOrDisableCheckButton();\" "
410 "onKeyPress=\"EnableOrDisableCheckButton();\" "
411 "ROWS=10 COLS=72 WIDTH=72>\n",
412 (organizer_is_me ? "" : "DISABLED ")
415 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
417 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
418 strcpy(attendee_string, icalproperty_get_attendee(attendee));
419 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
421 /* screen name or email address */
422 strcpy(attendee_string, &attendee_string[7]);
423 striplt(attendee_string);
424 if (i++) wprintf("\n");
425 escputs(attendee_string);
428 /* participant status */
429 partstat_as_string(buf, attendee);
433 wprintf("</TEXTAREA></TD></TR>\n");
434 wprintf("</TABLE>\n");
440 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
442 recur = icalproperty_get_rrule(rrule);
445 /* blank recurrence with some sensible defaults */
446 memset(&recur, 0, sizeof(struct icalrecurrencetype));
448 recur.until = icaltime_null_time();
450 recur.freq = ICAL_WEEKLY_RECURRENCE;
453 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
455 "onclick=\"RecurrenceShowHide();\""
457 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
458 _("This is a recurring event")
461 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
463 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
465 char *frequency_units[] = {
485 wprintf("<tr><td><b>");
486 wprintf(_("Recurrence rule"));
487 wprintf("</b></td><td>");
489 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
490 wprintf("%s ", _("Repeats every"));
492 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
493 wprintf("value=\"%d\"> ", recur.interval);
495 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
496 "onChange=\"RecurrenceShowHide();\">\n");
497 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
498 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
499 ((i == recur.freq) ? "selected " : ""),
500 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
505 wprintf("</select>\n");
507 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
508 wprintf("%s<br>", _("on these weekdays:"));
510 char weekday_is_selected[7];
511 memset(weekday_is_selected, 0, 7);
513 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
514 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
515 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
518 for (j=0; j<7; ++j) {
519 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
520 weekday_is_selected[j] = 1;
526 for (j=0; j<7; ++j) {
527 i = ((j + (int)weekstart) % 7);
528 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
529 if (weekday_is_selected[i]) wprintf(" checked");
530 wprintf(">%s\n", weekday_labels[i]);
532 wprintf("</div>\n"); /* end 'weekday_selector' div */
538 int which_rrmonthtype_is_preselected = 0;
539 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
541 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
542 "value=\"rrmonthtype_mday\" "
543 "%s onChange=\"RecurrenceShowHide();\">",
544 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
547 int rrmday = t_start.day;
548 int rrmweekday = icaltime_day_of_week(t_start) - 1;
550 /* Figure out what week of the month we're in */
551 icaltimetype day1 = t_start;
553 int weekbase = icaltime_week_number(day1);
554 int rrmweek = icaltime_week_number(t_start) - weekbase + 1;
556 /* Are we going by day of the month or week/day? */
558 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
559 which_rrmonthtype_is_preselected = 0;
560 rrmday = recur.by_month_day[0];
562 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
563 which_rrmonthtype_is_preselected = 1;
564 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
565 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
568 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
571 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
572 "value=\"rrmonthtype_wday\" "
573 "%s onChange=\"RecurrenceShowHide();\">",
574 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
577 wprintf(_("on the "));
578 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
579 "onChange=\"RecurrenceShowHide();\">\n");
580 for (i=1; i<=5; ++i) {
581 wprintf("<option %svalue=\"%d\">%s</option>\n",
582 ((i==rrmweek) ? "selected " : ""),
587 wprintf("</select> \n");
589 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
590 "onChange=\"RecurrenceShowHide();\">\n");
591 for (j=0; j<7; ++j) {
592 i = ((j + (int)weekstart) % 7);
593 wprintf("<option %svalue=\"%d\">%s</option>\n",
594 ((i==rrmweekday) ? "selected " : ""),
599 wprintf("</select>");
601 wprintf(" %s<br />\n", _("of the month"));
603 wprintf("</div>\n"); /* end 'monthday_selector' div */
606 int rrymweek = rrmweek;
607 int rrymweekday = rrmweekday;
608 int rrymonth = t_start.month;
609 int which_rryeartype_is_preselected = 0;
612 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
613 && (recur.by_day[0] != 0)
614 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
615 && (recur.by_month[0] != 0)
617 which_rryeartype_is_preselected = 1;
618 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
619 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
620 rrymonth = recur.by_month[0];
623 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
625 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
626 "value=\"rryeartype_ymday\" "
627 "%s onChange=\"RecurrenceShowHide();\">",
628 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
630 wprintf(_("every "));
631 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
633 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
634 "value=\"rryeartype_ywday\" "
635 "%s onChange=\"RecurrenceShowHide();\">",
636 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
639 wprintf(_("on the "));
640 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
641 "onChange=\"RecurrenceShowHide();\">\n");
642 for (i=1; i<=5; ++i) {
643 wprintf("<option %svalue=\"%d\">%s</option>\n",
644 ((i==rrymweek) ? "selected " : ""),
649 wprintf("</select> \n");
651 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
652 "onChange=\"RecurrenceShowHide();\">\n");
653 for (j=0; j<7; ++j) {
654 i = ((j + (int)weekstart) % 7);
655 wprintf("<option %svalue=\"%d\">%s</option>\n",
656 ((i==rrymweekday) ? "selected " : ""),
661 wprintf("</select>");
663 wprintf(" %s ", _("of"));
665 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
666 "onChange=\"RecurrenceShowHide();\">\n");
667 for (i=1; i<=12; ++i) {
668 wprintf("<option %svalue=\"%d\">%s</option>\n",
669 ((i==rrymonth) ? "selected " : ""),
674 wprintf("</select>");
677 wprintf("</div>\n"); /* end 'yearday_selector' div */
679 wprintf("</td></tr>\n");
682 int which_rrend_is_preselected = 0;
683 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
684 if (recur.count > 0) which_rrend_is_preselected = 1;
686 wprintf("<tr><td><b>");
687 wprintf(_("Recurrence range"));
688 wprintf("</b></td><td>\n");
690 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
691 "value=\"rrend_none\" "
692 "%s onChange=\"RecurrenceShowHide();\">",
693 ((which_rrend_is_preselected == 0) ? "checked" : "")
695 wprintf("%s<br />\n", _("No ending date"));
697 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
698 "value=\"rrend_count\" "
699 "%s onChange=\"RecurrenceShowHide();\">",
700 ((which_rrend_is_preselected == 1) ? "checked" : "")
702 wprintf(_("Repeat this event"));
703 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
704 wprintf("value=\"%d\"> ", recur.count);
708 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
709 "value=\"rrend_until\" "
710 "%s onChange=\"RecurrenceShowHide();\">",
711 ((which_rrend_is_preselected == 2) ? "checked" : "")
713 wprintf(_("Repeat this event until "));
715 if (icaltime_is_null_time(recur.until)) {
716 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
718 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
721 wprintf("</td></tr>\n");
723 wprintf("</table>\n");
724 wprintf("</div>\n"); /* end 'rrule' div */
728 /* submit buttons (common area beneath the tabs) */
731 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
733 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
735 "<INPUT TYPE=\"submit\" id=\"check_button\" NAME=\"check_button\" VALUE=\"%s\">\n"
737 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
741 _("Check attendee availability"),
744 wprintf("</FORM>\n");
747 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
749 StrBufAppendPrintf(WC->trailing_javascript,
750 "eventEditAllDay(); \n"
751 "RecurrenceShowHide(); \n"
752 "EnableOrDisableCheckButton(); \n"
754 address_book_popup();
757 if (created_new_vevent) {
758 icalcomponent_free(vevent);
763 * Save an edited event
765 * supplied_vevent: the event to save
766 * msgnum: the index on the citserver
768 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
769 int unread, calview *calv) {
772 icalcomponent *vevent, *encaps;
773 int created_new_vevent = 0;
774 int all_day_event = 0;
775 struct icaltimetype event_start, t;
776 icalproperty *attendee = NULL;
777 char attendee_string[SIZ];
780 char form_attendees[SIZ];
781 char organizer_string[SIZ];
783 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
785 if (supplied_vevent != NULL) {
786 vevent = supplied_vevent;
788 /* Convert all timestamps to UTC to make them easier to process. */
789 ical_dezonify(vevent);
792 * If we're looking at a fully encapsulated VCALENDAR
793 * rather than a VEVENT component, attempt to use the first
794 * relevant VEVENT subcomponent. If there is none, the
795 * NULL returned by icalcomponent_get_first_component() will
796 * tell the next iteration of this function to create a
799 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
800 save_individual_event(
801 icalcomponent_get_first_component(
802 vevent, ICAL_VEVENT_COMPONENT),
803 msgnum, from, unread, NULL
809 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
810 created_new_vevent = 1;
813 if ( (havebstr("save_button"))
814 || (havebstr("check_button")) ) {
816 /* Replace values in the component with ones from the form */
818 while (prop = icalcomponent_get_first_property(vevent,
819 ICAL_SUMMARY_PROPERTY), prop != NULL) {
820 icalcomponent_remove_property(vevent, prop);
821 icalproperty_free(prop);
824 /* Add NOW() to the calendar object... */
825 icalcomponent_set_dtstamp(vevent,
829 if (havebstr("summary")) {
830 icalcomponent_add_property(vevent,
831 icalproperty_new_summary(bstr("summary")));
833 icalcomponent_add_property(vevent,
834 icalproperty_new_summary(_("Untitled Event")));
837 while (prop = icalcomponent_get_first_property(vevent,
838 ICAL_LOCATION_PROPERTY), prop != NULL) {
839 icalcomponent_remove_property(vevent, prop);
840 icalproperty_free(prop);
842 if (havebstr("location")) {
843 icalcomponent_add_property(vevent,
844 icalproperty_new_location(bstr("location")));
846 while (prop = icalcomponent_get_first_property(vevent,
847 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
848 icalcomponent_remove_property(vevent, prop);
849 icalproperty_free(prop);
851 if (havebstr("description")) {
852 icalcomponent_add_property(vevent,
853 icalproperty_new_description(bstr("description")));
856 while (prop = icalcomponent_get_first_property(vevent,
857 ICAL_DTSTART_PROPERTY), prop != NULL) {
858 icalcomponent_remove_property(vevent, prop);
859 icalproperty_free(prop);
862 if (yesbstr("alldayevent")) {
870 icaltime_from_webform_dateonly(&event_start, "dtstart");
873 icaltime_from_webform(&event_start, "dtstart");
876 prop = icalproperty_new_dtstart(event_start);
879 /* Force it to serialize as a date-only rather than date/time */
880 icalproperty_set_value(prop, icalvalue_new_date(event_start));
883 if (prop) icalcomponent_add_property(vevent, prop);
884 else icalproperty_free(prop);
886 while (prop = icalcomponent_get_first_property(vevent,
887 ICAL_DTEND_PROPERTY), prop != NULL) {
888 icalcomponent_remove_property(vevent, prop);
889 icalproperty_free(prop);
891 while (prop = icalcomponent_get_first_property(vevent,
892 ICAL_DURATION_PROPERTY), prop != NULL) {
893 icalcomponent_remove_property(vevent, prop);
894 icalproperty_free(prop);
898 icaltime_from_webform_dateonly(&t, "dtend");
900 /* with this field supposed to be non-inclusive we have to add one day */
901 icaltime_adjust(&t, 1, 0, 0, 0);
904 icaltime_from_webform(&t, "dtend");
907 icalcomponent_add_property(vevent,
908 icalproperty_new_dtend(icaltime_normalize(t)
912 /* recurrence rules -- begin */
914 /* remove any existing rule */
915 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
916 icalcomponent_remove_property(vevent, prop);
917 icalproperty_free(prop);
920 if (yesbstr("is_recur")) {
921 struct icalrecurrencetype recur;
922 icalrecurrencetype_clear(&recur);
924 recur.interval = atoi(bstr("interval"));
925 recur.freq = atoi(bstr("freq"));
929 /* These can't happen; they're disabled. */
930 case ICAL_SECONDLY_RECURRENCE:
932 case ICAL_MINUTELY_RECURRENCE:
934 case ICAL_HOURLY_RECURRENCE:
937 /* Daily is valid but there are no further inputs. */
938 case ICAL_DAILY_RECURRENCE:
941 /* These are the real options. */
943 case ICAL_WEEKLY_RECURRENCE:
945 for (i=0; i<7; ++i) {
946 snprintf(buf, sizeof buf, "weekday%d", i);
947 if (YESBSTR(buf)) recur.by_day[j++] =
948 icalrecurrencetype_day_day_of_week(i+1);
950 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
953 case ICAL_MONTHLY_RECURRENCE:
954 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
955 recur.by_month_day[0] = event_start.day;
956 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
958 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
959 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
960 + atoi(bstr("rrmweekday")) + 1;
961 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
965 case ICAL_YEARLY_RECURRENCE:
966 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
967 /* no further action is needed here */
969 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
970 recur.by_month[0] = atoi(bstr("rrymonth"));
971 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
972 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
973 + atoi(bstr("rrymweekday")) + 1;
974 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
978 /* This one can't happen either. */
979 case ICAL_NO_RECURRENCE:
983 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
984 recur.count = atoi(bstr("rrcount"));
986 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
987 icaltime_from_webform_dateonly(&recur.until, "rruntil");
990 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
993 /* recurrence rules -- end */
995 /* See if transparency is indicated */
996 if (havebstr("transp")) {
997 if (!strcasecmp(bstr("transp"), "opaque")) {
998 formtransp = ICAL_TRANSP_OPAQUE;
1000 else if (!strcasecmp(bstr("transp"), "transparent")) {
1001 formtransp = ICAL_TRANSP_TRANSPARENT;
1004 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1006 icalcomponent_remove_property(vevent, prop);
1007 icalproperty_free(prop);
1010 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1013 /* Give this event a UID if it doesn't have one. */
1014 if (icalcomponent_get_first_property(vevent,
1015 ICAL_UID_PROPERTY) == NULL) {
1017 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1020 /* Increment the sequence ID */
1021 while (prop = icalcomponent_get_first_property(vevent,
1022 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1023 i = icalproperty_get_sequence(prop);
1024 if (i > sequence) sequence = i;
1025 icalcomponent_remove_property(vevent, prop);
1026 icalproperty_free(prop);
1029 icalcomponent_add_property(vevent,
1030 icalproperty_new_sequence(sequence)
1034 * Set the organizer, only if one does not already exist *and*
1035 * the form is supplying one
1037 strcpy(buf, bstr("organizer"));
1038 if ( (icalcomponent_get_first_property(vevent,
1039 ICAL_ORGANIZER_PROPERTY) == NULL)
1040 && (!IsEmptyStr(buf)) ) {
1042 /* set new organizer */
1043 sprintf(organizer_string, "MAILTO:%s", buf);
1044 icalcomponent_add_property(vevent,
1045 icalproperty_new_organizer(organizer_string)
1051 * Add any new attendees listed in the web form
1054 /* First, strip out the parenthesized partstats. */
1055 strcpy(form_attendees, bstr("attendees"));
1056 while ( stripout(form_attendees, '(', ')') != 0);
1058 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1059 j = strlen(form_attendees);
1060 for (i=0; i<j; ++i) {
1061 if (form_attendees[i] == ',') {
1062 form_attendees[i] = '\n';
1063 while (isspace(form_attendees[i+1])) {
1064 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1070 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1071 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1073 if (!IsEmptyStr(buf)) {
1074 sprintf(attendee_string, "MAILTO:%s", buf);
1077 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1078 if (!strcasecmp(attendee_string,
1079 icalproperty_get_attendee(attendee)))
1085 icalcomponent_add_property(vevent,
1086 icalproperty_new_attendee(attendee_string)
1093 * Remove any attendees *not* listed in the web form
1095 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1096 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1097 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1098 strcpy(attendee_string, &attendee_string[7]);
1099 striplt(attendee_string);
1101 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1102 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1104 if (!strcasecmp(buf, attendee_string)) ++foundit;
1107 icalcomponent_remove_property(vevent, attendee);
1108 icalproperty_free(attendee);
1115 * Encapsulate event into full VCALENDAR component. Clone it first,
1116 * for two reasons: one, it's easier to just free the whole thing
1117 * when we're done instead of unbundling, but more importantly, we
1118 * can't encapsulate something that may already be encapsulated
1121 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1123 /* Set the method to PUBLISH */
1124 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1126 /* If the user clicked 'Save' then save it to the server. */
1127 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1128 serv_puts("ENT0 1|||4|||1|");
1129 serv_getln(buf, sizeof buf);
1130 if (buf[0] == '8') {
1131 serv_puts("Content-type: text/calendar");
1133 serv_puts(icalcomponent_as_ical_string(encaps));
1136 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1137 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1140 if (buf[0] == '2') {
1141 strcpy(WC->ImportantMessage, &buf[4]);
1143 icalmemory_free_ring ();
1144 icalcomponent_free(encaps);
1148 /* Or, check attendee availability if the user asked for that. */
1149 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1151 /* Call this function, which does the real work */
1152 check_attendee_availability(encaps);
1154 /* This displays the form again, with our annotations */
1155 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1157 icalcomponent_free(encaps);
1160 if (encaps != NULL) {
1161 icalcomponent_free(encaps);
1168 * If the user clicked 'Delete' then delete it.
1170 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1171 serv_printf("DELE %ld", lbstr("msgnum"));
1172 serv_getln(buf, sizeof buf);
1175 if (created_new_vevent) {
1176 icalcomponent_free(vevent);
1179 /* If this was a save or delete, go back to the calendar or summary view. */
1180 if (!havebstr("check_button")) {
1181 if (!strcasecmp(bstr("calview"), "summary")) {