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;
39 char weekday_is_selected[7];
40 int which_rrmonthtype_is_preselected = 0;
51 int which_rrend_is_preselected;
52 int which_rryeartype_is_preselected;
56 const char *frequency_units[8];
57 const char *ordinals[6];
59 frequency_units[0] = _("seconds");
60 frequency_units[1] = _("minutes");
61 frequency_units[2] = _("hours");
62 frequency_units[3] = _("days");
63 frequency_units[4] = _("weeks");
64 frequency_units[5] = _("months");
65 frequency_units[6] = _("years");
66 frequency_units[7] = _("never");
70 ordinals[1] = _("first");
71 ordinals[2] = _("second");
72 ordinals[3] = _("third");
73 ordinals[4] = _("fourth");
74 ordinals[5] = _("fifth");
77 tabnames[0] = _("Event");
78 tabnames[1] = _("Attendees");
79 tabnames[2] = _("Recurrence");
81 get_pref_long("weekstart", &weekstart, 17);
82 if (weekstart > 6) weekstart = 0;
84 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
85 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
88 /* populate the weekday names - begin */
90 localtime_r(&now, &tm_now);
91 while (tm_now.tm_wday != 0) {
93 localtime_r(&now, &tm_now);
96 localtime_r(&now, &tm_now);
97 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
100 /* populate the weekday names - end */
102 /* populate the month names - begin */
103 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
104 localtime_r(&now, &tm_now);
105 for (i=0; i<12; ++i) {
106 localtime_r(&now, &tm_now);
107 wc_strftime(month_labels[i], 32, "%B", &tm_now);
110 /* populate the month names - end */
113 strcpy(organizer_string, "");
114 strcpy(attendee_string, "");
116 if (supplied_vevent != NULL) {
117 vevent = supplied_vevent;
119 /* Convert all timestamps to UTC to make them easier to process. */
120 ical_dezonify(vevent);
123 * If we're looking at a fully encapsulated VCALENDAR
124 * rather than a VEVENT component, attempt to use the first
125 * relevant VEVENT subcomponent. If there is none, the
126 * NULL returned by icalcomponent_get_first_component() will
127 * tell the next iteration of this function to create a
130 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
131 display_edit_individual_event(
132 icalcomponent_get_first_component(
133 vevent, ICAL_VEVENT_COMPONENT),
134 msgnum, from, unread, NULL
140 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
141 created_new_vevent = 1;
144 /* Learn the sequence */
145 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
147 sequence = icalproperty_get_sequence(p);
151 output_headers(1, 1, 2, 0, 0, 0);
152 wprintf("<div id=\"banner\">\n");
154 wprintf(_("Add or edit an event"));
158 wprintf("<div id=\"content\" class=\"service\">\n");
160 wprintf("<div class=\"fix_scrollbar_bug\">");
162 /************************************************************
163 * Uncomment this to see the UID in calendar events for debugging
165 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
167 escputs((char *)icalproperty_get_comment(p));
170 wprintf("SEQUENCE == %d<br />\n", sequence);
171 *************************************************************/
173 wprintf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
174 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
176 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
178 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
180 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
182 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
184 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
188 tabbed_dialog(3, tabnames);
191 /* Put it in a borderless table so it lines up nicely */
192 wprintf("<TABLE border=0 width=100%%>\n");
194 wprintf("<TR><TD><B>");
195 wprintf(_("Summary"));
196 wprintf("</B></TD><TD>\n"
197 "<INPUT TYPE=\"text\" NAME=\"summary\" "
198 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
199 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
201 escputs((char *)icalproperty_get_comment(p));
203 wprintf("\"></TD></TR>\n");
205 wprintf("<TR><TD><B>");
206 wprintf(_("Location"));
207 wprintf("</B></TD><TD>\n"
208 "<INPUT TYPE=\"text\" NAME=\"location\" "
209 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
210 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
212 escputs((char *)icalproperty_get_comment(p));
214 wprintf("\"></TD></TR>\n");
216 wprintf("<TR><TD><B>");
218 wprintf("</B></TD><TD>\n");
219 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
221 t_start = icalproperty_get_dtstart(p);
222 if (t_start.is_date) {
229 localtime_r(&now, &tm_now);
230 if (havebstr("year")) {
231 tm_now.tm_year = ibstr("year") - 1900;
232 tm_now.tm_mon = ibstr("month") - 1;
233 tm_now.tm_mday = ibstr("day");
235 if (havebstr("hour")) {
236 tm_now.tm_hour = ibstr("hour");
237 tm_now.tm_min = ibstr("minute");
246 t_start = icaltime_from_timet_with_zone(
248 ((yesbstr("alldayevent")) ? 1 : 0),
249 icaltimezone_get_utc_timezone()
254 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
256 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
257 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
259 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
263 wprintf("</TD></TR>\n");
265 wprintf("<TR><TD><B>");
267 wprintf("</B></TD><TD id=\"dtendcell\">\n");
268 p = icalcomponent_get_first_property(vevent,
269 ICAL_DTEND_PROPERTY);
271 t_end = icalproperty_get_dtend(p);
274 * If this is an all-day-event, the end time is set to real end
275 * day + 1, so we have to adjust accordingly.
277 if (t_start.is_date) {
278 icaltime_adjust(&t_end, -1, 0, 0, 0);
282 if (created_new_vevent == 1) {
283 /* set default duration */
284 if (t_start.is_date) {
286 * If this is an all-day-event, set the end time to be identical to
287 * the start time (the hour/minute/second will be set to midnight).
293 * If this is not an all-day event and there is no
294 * end time specified, make the default one hour
295 * from the start time.
300 t_end = icaltime_normalize(t_end);
301 /* t_end = icaltime_from_timet(now, 0); */
306 * If an existing event has no end date/time this is
307 * supposed to mean end = start.
312 display_icaltimetype_as_webform(&t_end, "dtend", 0);
313 wprintf("</TD></TR>\n");
315 wprintf("<TR><TD><B>");
317 wprintf("</B></TD><TD>\n"
318 "<TEXTAREA NAME=\"description\" wrap=soft "
319 "ROWS=5 COLS=72 WIDTH=72>\n"
321 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
323 escputs((char *)icalproperty_get_comment(p));
325 wprintf("</TEXTAREA></TD></TR>");
328 * For a new event, the user creating the event should be the
329 * organizer. Set this field accordingly.
331 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
333 sprintf(organizer_string, "MAILTO:%s", ChrPtr(WC->cs_inet_email));
334 icalcomponent_add_property(vevent,
335 icalproperty_new_organizer(organizer_string)
340 * Determine who is the organizer of this event.
341 * We need to determine "me" or "not me."
343 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
344 if (organizer != NULL) {
345 strcpy(organizer_string, icalproperty_get_organizer(organizer));
346 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
347 strcpy(organizer_string, &organizer_string[7]);
348 striplt(organizer_string);
349 serv_printf("ISME %s", organizer_string);
350 serv_getln(buf, sizeof buf);
357 wprintf("<TR><TD><B>");
358 wprintf(_("Organizer"));
359 wprintf("</B></TD><TD>");
360 escputs(organizer_string);
361 if (organizer_is_me) {
362 wprintf(" <FONT SIZE=-1><I>");
363 wprintf(_("(you are the organizer)"));
364 wprintf("</I></FONT>\n");
368 * Transmit the organizer as a hidden field. We don't want the user
369 * to be able to change it, but we do want it fed back to the server,
370 * especially if this is a new event and there is no organizer already
371 * in the calendar object.
373 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
374 escputs(organizer_string);
377 wprintf("</TD></TR>\n");
380 wprintf("<TR><TD><B>");
381 wprintf(_("Show time as:"));
382 wprintf("</B></TD><TD>");
384 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
386 /* No transparency found. Default to opaque (busy). */
387 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
389 icalcomponent_add_property(vevent, p);
393 v = icalproperty_get_value(p);
399 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
400 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
405 wprintf(" ");
407 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
408 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
414 wprintf("</TD></TR>\n");
417 /* Done with properties. */
418 wprintf("</TABLE>\n");
422 /* Attendees tab (need to move things here) */
424 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
425 wprintf("<TR><TD><B>");
426 wprintf(_("Attendees"));
429 wprintf(_("(One per line)"));
430 wprintf("</font>\n");
432 /* Pop open an address book -- begin */
434 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
436 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
441 /* Pop open an address book -- end */
444 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
445 "onchange=\"EnableOrDisableCheckButton();\" "
446 "onKeyPress=\"EnableOrDisableCheckButton();\" "
447 "ROWS=10 COLS=72 WIDTH=72>\n",
448 (organizer_is_me ? "" : "DISABLED ")
451 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
453 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
454 strcpy(attendee_string, icalproperty_get_attendee(attendee));
455 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
457 /* screen name or email address */
458 strcpy(attendee_string, &attendee_string[7]);
459 striplt(attendee_string);
460 if (i++) wprintf("\n");
461 escputs(attendee_string);
464 /* participant status */
465 partstat_as_string(buf, attendee);
469 wprintf("</TEXTAREA></TD></TR>\n");
470 wprintf("</TABLE>\n");
476 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
478 recur = icalproperty_get_rrule(rrule);
481 /* blank recurrence with some sensible defaults */
482 memset(&recur, 0, sizeof(struct icalrecurrencetype));
484 recur.until = icaltime_null_time();
486 recur.freq = ICAL_WEEKLY_RECURRENCE;
489 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
491 "onclick=\"RecurrenceShowHide();\""
493 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
494 _("This is a recurring event")
497 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
499 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
501 wprintf("<tr><td><b>");
502 wprintf(_("Recurrence rule"));
503 wprintf("</b></td><td>");
505 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
506 wprintf("%s ", _("Repeats every"));
508 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
509 wprintf("value=\"%d\"> ", recur.interval);
511 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
512 "onChange=\"RecurrenceShowHide();\">\n");
513 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
514 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
515 ((i == recur.freq) ? "selected " : ""),
516 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
521 wprintf("</select>\n");
523 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
524 wprintf("%s<br>", _("on these weekdays:"));
526 memset(weekday_is_selected, 0, 7);
528 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
529 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
530 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
533 for (j=0; j<7; ++j) {
534 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
535 weekday_is_selected[j] = 1;
541 for (j=0; j<7; ++j) {
542 i = ((j + (int)weekstart) % 7);
543 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
544 if (weekday_is_selected[i]) wprintf(" checked");
545 wprintf(">%s\n", weekday_labels[i]);
547 wprintf("</div>\n"); /* end 'weekday_selector' div */
553 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
555 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
556 "value=\"rrmonthtype_mday\" "
557 "%s onChange=\"RecurrenceShowHide();\">",
558 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
561 rrmday = t_start.day;
562 rrmweekday = icaltime_day_of_week(t_start) - 1;
564 /* Figure out what week of the month we're in */
567 weekbase = icaltime_week_number(day1);
568 rrmweek = icaltime_week_number(t_start) - weekbase + 1;
570 /* Are we going by day of the month or week/day? */
572 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
573 which_rrmonthtype_is_preselected = 0;
574 rrmday = recur.by_month_day[0];
576 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
577 which_rrmonthtype_is_preselected = 1;
578 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
579 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
582 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
585 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
586 "value=\"rrmonthtype_wday\" "
587 "%s onChange=\"RecurrenceShowHide();\">",
588 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
591 wprintf(_("on the "));
592 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
593 "onChange=\"RecurrenceShowHide();\">\n");
594 for (i=1; i<=5; ++i) {
595 wprintf("<option %svalue=\"%d\">%s</option>\n",
596 ((i==rrmweek) ? "selected " : ""),
601 wprintf("</select> \n");
603 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
604 "onChange=\"RecurrenceShowHide();\">\n");
605 for (j=0; j<7; ++j) {
606 i = ((j + (int)weekstart) % 7);
607 wprintf("<option %svalue=\"%d\">%s</option>\n",
608 ((i==rrmweekday) ? "selected " : ""),
613 wprintf("</select>");
615 wprintf(" %s<br />\n", _("of the month"));
617 wprintf("</div>\n"); /* end 'monthday_selector' div */
621 rrymweekday = rrmweekday;
622 rrymonth = t_start.month;
623 which_rryeartype_is_preselected = 0;
626 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
627 && (recur.by_day[0] != 0)
628 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
629 && (recur.by_month[0] != 0)
631 which_rryeartype_is_preselected = 1;
632 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
633 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
634 rrymonth = recur.by_month[0];
637 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
639 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
640 "value=\"rryeartype_ymday\" "
641 "%s onChange=\"RecurrenceShowHide();\">",
642 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
644 wprintf(_("every "));
645 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
647 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
648 "value=\"rryeartype_ywday\" "
649 "%s onChange=\"RecurrenceShowHide();\">",
650 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
653 wprintf(_("on the "));
654 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
655 "onChange=\"RecurrenceShowHide();\">\n");
656 for (i=1; i<=5; ++i) {
657 wprintf("<option %svalue=\"%d\">%s</option>\n",
658 ((i==rrymweek) ? "selected " : ""),
663 wprintf("</select> \n");
665 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
666 "onChange=\"RecurrenceShowHide();\">\n");
667 for (j=0; j<7; ++j) {
668 i = ((j + (int)weekstart) % 7);
669 wprintf("<option %svalue=\"%d\">%s</option>\n",
670 ((i==rrymweekday) ? "selected " : ""),
675 wprintf("</select>");
677 wprintf(" %s ", _("of"));
679 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
680 "onChange=\"RecurrenceShowHide();\">\n");
681 for (i=1; i<=12; ++i) {
682 wprintf("<option %svalue=\"%d\">%s</option>\n",
683 ((i==rrymonth) ? "selected " : ""),
688 wprintf("</select>");
691 wprintf("</div>\n"); /* end 'yearday_selector' div */
693 wprintf("</td></tr>\n");
696 which_rrend_is_preselected = 0;
697 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
698 if (recur.count > 0) which_rrend_is_preselected = 1;
700 wprintf("<tr><td><b>");
701 wprintf(_("Recurrence range"));
702 wprintf("</b></td><td>\n");
704 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
705 "value=\"rrend_none\" "
706 "%s onChange=\"RecurrenceShowHide();\">",
707 ((which_rrend_is_preselected == 0) ? "checked" : "")
709 wprintf("%s<br />\n", _("No ending date"));
711 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
712 "value=\"rrend_count\" "
713 "%s onChange=\"RecurrenceShowHide();\">",
714 ((which_rrend_is_preselected == 1) ? "checked" : "")
716 wprintf(_("Repeat this event"));
717 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
718 wprintf("value=\"%d\"> ", recur.count);
722 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
723 "value=\"rrend_until\" "
724 "%s onChange=\"RecurrenceShowHide();\">",
725 ((which_rrend_is_preselected == 2) ? "checked" : "")
727 wprintf(_("Repeat this event until "));
729 if (icaltime_is_null_time(recur.until)) {
730 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
732 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
735 wprintf("</td></tr>\n");
737 wprintf("</table>\n");
738 wprintf("</div>\n"); /* end 'rrule' div */
742 /* submit buttons (common area beneath the tabs) */
745 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
747 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
749 "<INPUT TYPE=\"submit\" id=\"check_button\" NAME=\"check_button\" VALUE=\"%s\">\n"
751 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
755 _("Check attendee availability"),
758 wprintf("</FORM>\n");
761 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
763 StrBufAppendPrintf(WC->trailing_javascript,
764 "eventEditAllDay(); \n"
765 "RecurrenceShowHide(); \n"
766 "EnableOrDisableCheckButton(); \n"
768 address_book_popup();
771 if (created_new_vevent) {
772 icalcomponent_free(vevent);
777 * Save an edited event
779 * supplied_vevent: the event to save
780 * msgnum: the index on the citserver
782 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
783 int unread, calview *calv) {
786 icalcomponent *vevent, *encaps;
787 int created_new_vevent = 0;
788 int all_day_event = 0;
789 struct icaltimetype event_start, t;
790 icalproperty *attendee = NULL;
791 char attendee_string[SIZ];
794 char form_attendees[SIZ];
795 char organizer_string[SIZ];
797 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
799 if (supplied_vevent != NULL) {
800 vevent = supplied_vevent;
802 /* Convert all timestamps to UTC to make them easier to process. */
803 ical_dezonify(vevent);
806 * If we're looking at a fully encapsulated VCALENDAR
807 * rather than a VEVENT component, attempt to use the first
808 * relevant VEVENT subcomponent. If there is none, the
809 * NULL returned by icalcomponent_get_first_component() will
810 * tell the next iteration of this function to create a
813 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
814 save_individual_event(
815 icalcomponent_get_first_component(
816 vevent, ICAL_VEVENT_COMPONENT),
817 msgnum, from, unread, NULL
823 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
824 created_new_vevent = 1;
827 if ( (havebstr("save_button"))
828 || (havebstr("check_button")) ) {
830 /* Replace values in the component with ones from the form */
832 while (prop = icalcomponent_get_first_property(vevent,
833 ICAL_SUMMARY_PROPERTY), prop != NULL) {
834 icalcomponent_remove_property(vevent, prop);
835 icalproperty_free(prop);
838 /* Add NOW() to the calendar object... */
839 icalcomponent_set_dtstamp(vevent,
843 if (havebstr("summary")) {
844 icalcomponent_add_property(vevent,
845 icalproperty_new_summary(bstr("summary")));
847 icalcomponent_add_property(vevent,
848 icalproperty_new_summary(_("Untitled Event")));
851 while (prop = icalcomponent_get_first_property(vevent,
852 ICAL_LOCATION_PROPERTY), prop != NULL) {
853 icalcomponent_remove_property(vevent, prop);
854 icalproperty_free(prop);
856 if (havebstr("location")) {
857 icalcomponent_add_property(vevent,
858 icalproperty_new_location(bstr("location")));
860 while (prop = icalcomponent_get_first_property(vevent,
861 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
862 icalcomponent_remove_property(vevent, prop);
863 icalproperty_free(prop);
865 if (havebstr("description")) {
866 icalcomponent_add_property(vevent,
867 icalproperty_new_description(bstr("description")));
870 while (prop = icalcomponent_get_first_property(vevent,
871 ICAL_DTSTART_PROPERTY), prop != NULL) {
872 icalcomponent_remove_property(vevent, prop);
873 icalproperty_free(prop);
876 if (yesbstr("alldayevent")) {
884 icaltime_from_webform_dateonly(&event_start, "dtstart");
887 icaltime_from_webform(&event_start, "dtstart");
890 prop = icalproperty_new_dtstart(event_start);
893 /* Force it to serialize as a date-only rather than date/time */
894 icalproperty_set_value(prop, icalvalue_new_date(event_start));
897 if (prop) icalcomponent_add_property(vevent, prop);
898 else icalproperty_free(prop);
900 while (prop = icalcomponent_get_first_property(vevent,
901 ICAL_DTEND_PROPERTY), prop != NULL) {
902 icalcomponent_remove_property(vevent, prop);
903 icalproperty_free(prop);
905 while (prop = icalcomponent_get_first_property(vevent,
906 ICAL_DURATION_PROPERTY), prop != NULL) {
907 icalcomponent_remove_property(vevent, prop);
908 icalproperty_free(prop);
912 icaltime_from_webform_dateonly(&t, "dtend");
914 /* with this field supposed to be non-inclusive we have to add one day */
915 icaltime_adjust(&t, 1, 0, 0, 0);
918 icaltime_from_webform(&t, "dtend");
921 icalcomponent_add_property(vevent,
922 icalproperty_new_dtend(icaltime_normalize(t)
926 /* recurrence rules -- begin */
928 /* remove any existing rule */
929 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
930 icalcomponent_remove_property(vevent, prop);
931 icalproperty_free(prop);
934 if (yesbstr("is_recur")) {
935 struct icalrecurrencetype recur;
936 icalrecurrencetype_clear(&recur);
938 recur.interval = atoi(bstr("interval"));
939 recur.freq = atoi(bstr("freq"));
943 /* These can't happen; they're disabled. */
944 case ICAL_SECONDLY_RECURRENCE:
946 case ICAL_MINUTELY_RECURRENCE:
948 case ICAL_HOURLY_RECURRENCE:
951 /* Daily is valid but there are no further inputs. */
952 case ICAL_DAILY_RECURRENCE:
955 /* These are the real options. */
957 case ICAL_WEEKLY_RECURRENCE:
959 for (i=0; i<7; ++i) {
960 snprintf(buf, sizeof buf, "weekday%d", i);
961 if (YESBSTR(buf)) recur.by_day[j++] =
962 icalrecurrencetype_day_day_of_week(i+1);
964 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
967 case ICAL_MONTHLY_RECURRENCE:
968 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
969 recur.by_month_day[0] = event_start.day;
970 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
972 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
973 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
974 + atoi(bstr("rrmweekday")) + 1;
975 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
979 case ICAL_YEARLY_RECURRENCE:
980 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
981 /* no further action is needed here */
983 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
984 recur.by_month[0] = atoi(bstr("rrymonth"));
985 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
986 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
987 + atoi(bstr("rrymweekday")) + 1;
988 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
992 /* This one can't happen either. */
993 case ICAL_NO_RECURRENCE:
997 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
998 recur.count = atoi(bstr("rrcount"));
1000 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
1001 icaltime_from_webform_dateonly(&recur.until, "rruntil");
1004 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
1007 /* recurrence rules -- end */
1009 /* See if transparency is indicated */
1010 if (havebstr("transp")) {
1011 if (!strcasecmp(bstr("transp"), "opaque")) {
1012 formtransp = ICAL_TRANSP_OPAQUE;
1014 else if (!strcasecmp(bstr("transp"), "transparent")) {
1015 formtransp = ICAL_TRANSP_TRANSPARENT;
1018 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1020 icalcomponent_remove_property(vevent, prop);
1021 icalproperty_free(prop);
1024 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1027 /* Give this event a UID if it doesn't have one. */
1028 if (icalcomponent_get_first_property(vevent,
1029 ICAL_UID_PROPERTY) == NULL) {
1031 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1034 /* Increment the sequence ID */
1035 while (prop = icalcomponent_get_first_property(vevent,
1036 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1037 i = icalproperty_get_sequence(prop);
1038 if (i > sequence) sequence = i;
1039 icalcomponent_remove_property(vevent, prop);
1040 icalproperty_free(prop);
1043 icalcomponent_add_property(vevent,
1044 icalproperty_new_sequence(sequence)
1048 * Set the organizer, only if one does not already exist *and*
1049 * the form is supplying one
1051 strcpy(buf, bstr("organizer"));
1052 if ( (icalcomponent_get_first_property(vevent,
1053 ICAL_ORGANIZER_PROPERTY) == NULL)
1054 && (!IsEmptyStr(buf)) ) {
1056 /* set new organizer */
1057 sprintf(organizer_string, "MAILTO:%s", buf);
1058 icalcomponent_add_property(vevent,
1059 icalproperty_new_organizer(organizer_string)
1065 * Add any new attendees listed in the web form
1068 /* First, strip out the parenthesized partstats. */
1069 strcpy(form_attendees, bstr("attendees"));
1070 while ( stripout(form_attendees, '(', ')') != 0);
1072 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1073 j = strlen(form_attendees);
1074 for (i=0; i<j; ++i) {
1075 if (form_attendees[i] == ',') {
1076 form_attendees[i] = '\n';
1077 while (isspace(form_attendees[i+1])) {
1078 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1084 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1085 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1087 if (!IsEmptyStr(buf)) {
1088 sprintf(attendee_string, "MAILTO:%s", buf);
1091 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1092 if (!strcasecmp(attendee_string,
1093 icalproperty_get_attendee(attendee)))
1099 icalcomponent_add_property(vevent,
1100 icalproperty_new_attendee(attendee_string)
1107 * Remove any attendees *not* listed in the web form
1109 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1110 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1111 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1112 strcpy(attendee_string, &attendee_string[7]);
1113 striplt(attendee_string);
1115 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1116 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1118 if (!strcasecmp(buf, attendee_string)) ++foundit;
1121 icalcomponent_remove_property(vevent, attendee);
1122 icalproperty_free(attendee);
1129 * Encapsulate event into full VCALENDAR component. Clone it first,
1130 * for two reasons: one, it's easier to just free the whole thing
1131 * when we're done instead of unbundling, but more importantly, we
1132 * can't encapsulate something that may already be encapsulated
1135 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1137 /* Set the method to PUBLISH */
1138 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1140 /* If the user clicked 'Save' then save it to the server. */
1141 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1142 serv_puts("ENT0 1|||4|||1|");
1143 serv_getln(buf, sizeof buf);
1144 if (buf[0] == '8') {
1145 serv_puts("Content-type: text/calendar");
1147 serv_puts(icalcomponent_as_ical_string(encaps));
1150 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1151 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1154 if (buf[0] == '2') {
1155 strcpy(WC->ImportantMessage, &buf[4]);
1157 icalmemory_free_ring ();
1158 icalcomponent_free(encaps);
1162 /* Or, check attendee availability if the user asked for that. */
1163 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1165 /* Call this function, which does the real work */
1166 check_attendee_availability(encaps);
1168 /* This displays the form again, with our annotations */
1169 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1171 icalcomponent_free(encaps);
1174 if (encaps != NULL) {
1175 icalcomponent_free(encaps);
1182 * If the user clicked 'Delete' then delete it.
1184 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1185 serv_printf("DELE %ld", lbstr("msgnum"));
1186 serv_getln(buf, sizeof buf);
1189 if (created_new_vevent) {
1190 icalcomponent_free(vevent);
1193 /* If this was a save or delete, go back to the calendar or summary view. */
1194 if (!havebstr("check_button")) {
1195 if (!strcasecmp(bstr("calview"), "summary")) {