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];
36 icalproperty *rrule = NULL;
37 struct icalrecurrencetype recur;
40 tabnames[0] = _("Event");
41 tabnames[1] = _("Attendees");
42 tabnames[2] = _("Recurrence");
44 get_pref_long("weekstart", &weekstart, 17);
45 if (weekstart > 6) weekstart = 0;
47 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
48 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
51 /* populate the weekday names - begin */
53 localtime_r(&now, &tm_now);
54 while (tm_now.tm_wday != 0) {
56 localtime_r(&now, &tm_now);
59 localtime_r(&now, &tm_now);
60 wc_strftime(weekday_labels[i], 32, "%A", &tm_now);
63 /* populate the weekday names - end */
65 /* populate the month names - begin */
66 now = 259200L; /* 1970-jan-04 is the first Sunday ever */
67 localtime_r(&now, &tm_now);
68 for (i=0; i<12; ++i) {
69 localtime_r(&now, &tm_now);
70 wc_strftime(month_labels[i], 32, "%B", &tm_now);
73 /* populate the month names - end */
76 strcpy(organizer_string, "");
77 strcpy(attendee_string, "");
79 if (supplied_vevent != NULL) {
80 vevent = supplied_vevent;
82 /* Convert all timestamps to UTC to make them easier to process. */
83 ical_dezonify(vevent);
86 * If we're looking at a fully encapsulated VCALENDAR
87 * rather than a VEVENT component, attempt to use the first
88 * relevant VEVENT subcomponent. If there is none, the
89 * NULL returned by icalcomponent_get_first_component() will
90 * tell the next iteration of this function to create a
93 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
94 display_edit_individual_event(
95 icalcomponent_get_first_component(
96 vevent, ICAL_VEVENT_COMPONENT),
97 msgnum, from, unread, NULL
103 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
104 created_new_vevent = 1;
107 /* Learn the sequence */
108 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
110 sequence = icalproperty_get_sequence(p);
114 output_headers(1, 1, 2, 0, 0, 0);
115 wprintf("<div id=\"banner\">\n");
117 wprintf(_("Add or edit an event"));
121 wprintf("<div id=\"content\" class=\"service\">\n");
123 wprintf("<div class=\"fix_scrollbar_bug\">");
125 /************************************************************
126 * Uncomment this to see the UID in calendar events for debugging
128 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
130 escputs((char *)icalproperty_get_comment(p));
133 wprintf("SEQUENCE == %d<br />\n", sequence);
134 *************************************************************/
136 wprintf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
137 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
139 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
141 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
143 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
145 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
147 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
151 tabbed_dialog(3, tabnames);
154 /* Put it in a borderless table so it lines up nicely */
155 wprintf("<TABLE border=0 width=100%%>\n");
157 wprintf("<TR><TD><B>");
158 wprintf(_("Summary"));
159 wprintf("</B></TD><TD>\n"
160 "<INPUT TYPE=\"text\" NAME=\"summary\" "
161 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
162 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
164 escputs((char *)icalproperty_get_comment(p));
166 wprintf("\"></TD></TR>\n");
168 wprintf("<TR><TD><B>");
169 wprintf(_("Location"));
170 wprintf("</B></TD><TD>\n"
171 "<INPUT TYPE=\"text\" NAME=\"location\" "
172 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
173 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
175 escputs((char *)icalproperty_get_comment(p));
177 wprintf("\"></TD></TR>\n");
179 wprintf("<TR><TD><B>");
181 wprintf("</B></TD><TD>\n");
182 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
184 t_start = icalproperty_get_dtstart(p);
185 if (t_start.is_date) {
192 localtime_r(&now, &tm_now);
193 if (havebstr("year")) {
194 tm_now.tm_year = ibstr("year") - 1900;
195 tm_now.tm_mon = ibstr("month") - 1;
196 tm_now.tm_mday = ibstr("day");
198 if (havebstr("hour")) {
199 tm_now.tm_hour = ibstr("hour");
200 tm_now.tm_min = ibstr("minute");
209 t_start = icaltime_from_timet_with_zone(
211 ((yesbstr("alldayevent")) ? 1 : 0),
212 icaltimezone_get_utc_timezone()
217 display_icaltimetype_as_webform(&t_start, "dtstart", 0);
219 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
220 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
222 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
226 wprintf("</TD></TR>\n");
228 wprintf("<TR><TD><B>");
230 wprintf("</B></TD><TD id=\"dtendcell\">\n");
231 p = icalcomponent_get_first_property(vevent,
232 ICAL_DTEND_PROPERTY);
234 t_end = icalproperty_get_dtend(p);
237 * If this is an all-day-event, the end time is set to real end
238 * day + 1, so we have to adjust accordingly.
240 if (t_start.is_date) {
241 icaltime_adjust(&t_end, -1, 0, 0, 0);
245 if (created_new_vevent == 1) {
246 /* set default duration */
247 if (t_start.is_date) {
249 * If this is an all-day-event, set the end time to be identical to
250 * the start time (the hour/minute/second will be set to midnight).
256 * If this is not an all-day event and there is no
257 * end time specified, make the default one hour
258 * from the start time.
263 t_end = icaltime_normalize(t_end);
264 /* t_end = icaltime_from_timet(now, 0); */
269 * If an existing event has no end date/time this is
270 * supposed to mean end = start.
275 display_icaltimetype_as_webform(&t_end, "dtend", 0);
276 wprintf("</TD></TR>\n");
278 wprintf("<TR><TD><B>");
280 wprintf("</B></TD><TD>\n"
281 "<TEXTAREA NAME=\"description\" wrap=soft "
282 "ROWS=5 COLS=72 WIDTH=72>\n"
284 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
286 escputs((char *)icalproperty_get_comment(p));
288 wprintf("</TEXTAREA></TD></TR>");
291 * For a new event, the user creating the event should be the
292 * organizer. Set this field accordingly.
294 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
296 sprintf(organizer_string, "MAILTO:%s", ChrPtr(WC->cs_inet_email));
297 icalcomponent_add_property(vevent,
298 icalproperty_new_organizer(organizer_string)
303 * Determine who is the organizer of this event.
304 * We need to determine "me" or "not me."
306 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
307 if (organizer != NULL) {
308 strcpy(organizer_string, icalproperty_get_organizer(organizer));
309 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
310 strcpy(organizer_string, &organizer_string[7]);
311 striplt(organizer_string);
312 serv_printf("ISME %s", organizer_string);
313 serv_getln(buf, sizeof buf);
320 wprintf("<TR><TD><B>");
321 wprintf(_("Organizer"));
322 wprintf("</B></TD><TD>");
323 escputs(organizer_string);
324 if (organizer_is_me) {
325 wprintf(" <FONT SIZE=-1><I>");
326 wprintf(_("(you are the organizer)"));
327 wprintf("</I></FONT>\n");
331 * Transmit the organizer as a hidden field. We don't want the user
332 * to be able to change it, but we do want it fed back to the server,
333 * especially if this is a new event and there is no organizer already
334 * in the calendar object.
336 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
337 escputs(organizer_string);
340 wprintf("</TD></TR>\n");
343 wprintf("<TR><TD><B>");
344 wprintf(_("Show time as:"));
345 wprintf("</B></TD><TD>");
347 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
349 /* No transparency found. Default to opaque (busy). */
350 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
352 icalcomponent_add_property(vevent, p);
356 v = icalproperty_get_value(p);
362 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
363 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)) {
368 wprintf(" ");
370 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
371 if ((v != NULL) && (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)) {
377 wprintf("</TD></TR>\n");
380 /* Done with properties. */
381 wprintf("</TABLE>\n");
385 /* Attendees tab (need to move things here) */
387 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
388 wprintf("<TR><TD><B>");
389 wprintf(_("Attendees"));
392 wprintf(_("(One per line)"));
393 wprintf("</font>\n");
395 /* Pop open an address book -- begin */
397 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
399 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
404 /* Pop open an address book -- end */
407 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
408 "onchange=\"EnableOrDisableCheckButton();\" "
409 "onKeyPress=\"EnableOrDisableCheckButton();\" "
410 "ROWS=10 COLS=72 WIDTH=72>\n",
411 (organizer_is_me ? "" : "DISABLED ")
414 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
416 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
417 strcpy(attendee_string, icalproperty_get_attendee(attendee));
418 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
420 /* screen name or email address */
421 strcpy(attendee_string, &attendee_string[7]);
422 striplt(attendee_string);
423 if (i++) wprintf("\n");
424 escputs(attendee_string);
427 /* participant status */
428 partstat_as_string(buf, attendee);
432 wprintf("</TEXTAREA></TD></TR>\n");
433 wprintf("</TABLE>\n");
439 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
441 recur = icalproperty_get_rrule(rrule);
444 /* blank recurrence with some sensible defaults */
445 memset(&recur, 0, sizeof(struct icalrecurrencetype));
447 recur.until = icaltime_null_time();
449 recur.freq = ICAL_WEEKLY_RECURRENCE;
452 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
454 "onclick=\"RecurrenceShowHide();\""
456 (rrule ? "CHECKED=\"CHECKED\"" : "" ),
457 _("This is a recurring event")
460 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
462 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
464 char *frequency_units[] = {
484 wprintf("<tr><td><b>");
485 wprintf(_("Recurrence rule"));
486 wprintf("</b></td><td>");
488 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
489 wprintf("%s ", _("Repeats every"));
491 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
492 wprintf("value=\"%d\"> ", recur.interval);
494 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
495 "onChange=\"RecurrenceShowHide();\">\n");
496 for (i=0; i<(sizeof frequency_units / sizeof(char *)); ++i) {
497 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
498 ((i == recur.freq) ? "selected " : ""),
499 (((i == recur.freq) || ((i>=3)&&(i<=6))) ? "" : "disabled "),
504 wprintf("</select>\n");
506 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
507 wprintf("%s<br>", _("on these weekdays:"));
509 char weekday_is_selected[7];
510 memset(weekday_is_selected, 0, 7);
512 for (i=0; i<ICAL_BY_DAY_SIZE; ++i) {
513 if (recur.by_day[i] == ICAL_RECURRENCE_ARRAY_MAX) {
514 i = ICAL_RECURRENCE_ARRAY_MAX; /* all done */
517 for (j=0; j<7; ++j) {
518 if (icalrecurrencetype_day_day_of_week(recur.by_day[i]) == j+1) {
519 weekday_is_selected[j] = 1;
525 for (j=0; j<7; ++j) {
526 i = ((j + (int)weekstart) % 7);
527 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i);
528 if (weekday_is_selected[i]) wprintf(" checked");
529 wprintf(">%s\n", weekday_labels[i]);
531 wprintf("</div>\n"); /* end 'weekday_selector' div */
537 int which_rrmonthtype_is_preselected = 0;
538 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
540 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
541 "value=\"rrmonthtype_mday\" "
542 "%s onChange=\"RecurrenceShowHide();\">",
543 ((which_rrmonthtype_is_preselected == 0) ? "checked" : "")
546 int rrmday = t_start.day;
547 int rrmweekday = icaltime_day_of_week(t_start) - 1;
549 /* Figure out what week of the month we're in */
550 icaltimetype day1 = t_start;
552 int weekbase = icaltime_week_number(day1);
553 int rrmweek = icaltime_week_number(t_start) - weekbase + 1;
555 /* Are we going by day of the month or week/day? */
557 if (recur.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
558 which_rrmonthtype_is_preselected = 0;
559 rrmday = recur.by_month_day[0];
561 else if (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
562 which_rrmonthtype_is_preselected = 1;
563 rrmweek = icalrecurrencetype_day_position(recur.by_day[0]);
564 rrmweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
567 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
570 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
571 "value=\"rrmonthtype_wday\" "
572 "%s onChange=\"RecurrenceShowHide();\">",
573 ((which_rrmonthtype_is_preselected == 1) ? "checked" : "")
576 wprintf(_("on the "));
577 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
578 "onChange=\"RecurrenceShowHide();\">\n");
579 for (i=1; i<=5; ++i) {
580 wprintf("<option %svalue=\"%d\">%s</option>\n",
581 ((i==rrmweek) ? "selected " : ""),
586 wprintf("</select> \n");
588 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
589 "onChange=\"RecurrenceShowHide();\">\n");
590 for (j=0; j<7; ++j) {
591 i = ((j + (int)weekstart) % 7);
592 wprintf("<option %svalue=\"%d\">%s</option>\n",
593 ((i==rrmweekday) ? "selected " : ""),
598 wprintf("</select>");
600 wprintf(" %s<br />\n", _("of the month"));
602 wprintf("</div>\n"); /* end 'monthday_selector' div */
605 int rrymweek = rrmweek;
606 int rrymweekday = rrmweekday;
607 int rrymonth = t_start.month;
608 int which_rryeartype_is_preselected = 0;
611 (recur.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX)
612 && (recur.by_day[0] != 0)
613 && (recur.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX)
614 && (recur.by_month[0] != 0)
616 which_rryeartype_is_preselected = 1;
617 rrymweek = icalrecurrencetype_day_position(recur.by_day[0]);
618 rrymweekday = icalrecurrencetype_day_day_of_week(recur.by_day[0]) - 1;
619 rrymonth = recur.by_month[0];
622 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
624 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
625 "value=\"rryeartype_ymday\" "
626 "%s onChange=\"RecurrenceShowHide();\">",
627 ((which_rryeartype_is_preselected == 0) ? "checked" : "")
629 wprintf(_("every "));
630 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
632 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
633 "value=\"rryeartype_ywday\" "
634 "%s onChange=\"RecurrenceShowHide();\">",
635 ((which_rryeartype_is_preselected == 1) ? "checked" : "")
638 wprintf(_("on the "));
639 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
640 "onChange=\"RecurrenceShowHide();\">\n");
641 for (i=1; i<=5; ++i) {
642 wprintf("<option %svalue=\"%d\">%s</option>\n",
643 ((i==rrymweek) ? "selected " : ""),
648 wprintf("</select> \n");
650 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
651 "onChange=\"RecurrenceShowHide();\">\n");
652 for (j=0; j<7; ++j) {
653 i = ((j + (int)weekstart) % 7);
654 wprintf("<option %svalue=\"%d\">%s</option>\n",
655 ((i==rrymweekday) ? "selected " : ""),
660 wprintf("</select>");
662 wprintf(" %s ", _("of"));
664 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
665 "onChange=\"RecurrenceShowHide();\">\n");
666 for (i=1; i<=12; ++i) {
667 wprintf("<option %svalue=\"%d\">%s</option>\n",
668 ((i==rrymonth) ? "selected " : ""),
673 wprintf("</select>");
676 wprintf("</div>\n"); /* end 'yearday_selector' div */
678 wprintf("</td></tr>\n");
681 int which_rrend_is_preselected = 0;
682 if (!icaltime_is_null_time(recur.until)) which_rrend_is_preselected = 2;
683 if (recur.count > 0) which_rrend_is_preselected = 1;
685 wprintf("<tr><td><b>");
686 wprintf(_("Recurrence range"));
687 wprintf("</b></td><td>\n");
689 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
690 "value=\"rrend_none\" "
691 "%s onChange=\"RecurrenceShowHide();\">",
692 ((which_rrend_is_preselected == 0) ? "checked" : "")
694 wprintf("%s<br />\n", _("No ending date"));
696 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
697 "value=\"rrend_count\" "
698 "%s onChange=\"RecurrenceShowHide();\">",
699 ((which_rrend_is_preselected == 1) ? "checked" : "")
701 wprintf(_("Repeat this event"));
702 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
703 wprintf("value=\"%d\"> ", recur.count);
707 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
708 "value=\"rrend_until\" "
709 "%s onChange=\"RecurrenceShowHide();\">",
710 ((which_rrend_is_preselected == 2) ? "checked" : "")
712 wprintf(_("Repeat this event until "));
714 if (icaltime_is_null_time(recur.until)) {
715 recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
717 display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
720 wprintf("</td></tr>\n");
722 wprintf("</table>\n");
723 wprintf("</div>\n"); /* end 'rrule' div */
727 /* submit buttons (common area beneath the tabs) */
730 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
732 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
734 "<INPUT TYPE=\"submit\" id=\"check_button\" NAME=\"check_button\" VALUE=\"%s\">\n"
736 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
740 _("Check attendee availability"),
743 wprintf("</FORM>\n");
746 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
748 StrBufAppendPrintf(WC->trailing_javascript,
749 "eventEditAllDay(); \n"
750 "RecurrenceShowHide(); \n"
751 "EnableOrDisableCheckButton(); \n"
753 address_book_popup();
756 if (created_new_vevent) {
757 icalcomponent_free(vevent);
762 * Save an edited event
764 * supplied_vevent: the event to save
765 * msgnum: the index on the citserver
767 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
768 int unread, struct calview *calv) {
771 icalcomponent *vevent, *encaps;
772 int created_new_vevent = 0;
773 int all_day_event = 0;
774 struct icaltimetype event_start, t;
775 icalproperty *attendee = NULL;
776 char attendee_string[SIZ];
779 char form_attendees[SIZ];
780 char organizer_string[SIZ];
782 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
784 if (supplied_vevent != NULL) {
785 vevent = supplied_vevent;
787 /* Convert all timestamps to UTC to make them easier to process. */
788 ical_dezonify(vevent);
791 * If we're looking at a fully encapsulated VCALENDAR
792 * rather than a VEVENT component, attempt to use the first
793 * relevant VEVENT subcomponent. If there is none, the
794 * NULL returned by icalcomponent_get_first_component() will
795 * tell the next iteration of this function to create a
798 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
799 save_individual_event(
800 icalcomponent_get_first_component(
801 vevent, ICAL_VEVENT_COMPONENT),
802 msgnum, from, unread, NULL
808 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
809 created_new_vevent = 1;
812 if ( (havebstr("save_button"))
813 || (havebstr("check_button")) ) {
815 /* Replace values in the component with ones from the form */
817 while (prop = icalcomponent_get_first_property(vevent,
818 ICAL_SUMMARY_PROPERTY), prop != NULL) {
819 icalcomponent_remove_property(vevent, prop);
820 icalproperty_free(prop);
823 /* Add NOW() to the calendar object... */
824 icalcomponent_set_dtstamp(vevent,
828 if (havebstr("summary")) {
829 icalcomponent_add_property(vevent,
830 icalproperty_new_summary(bstr("summary")));
832 icalcomponent_add_property(vevent,
833 icalproperty_new_summary(_("Untitled Event")));
836 while (prop = icalcomponent_get_first_property(vevent,
837 ICAL_LOCATION_PROPERTY), prop != NULL) {
838 icalcomponent_remove_property(vevent, prop);
839 icalproperty_free(prop);
841 if (havebstr("location")) {
842 icalcomponent_add_property(vevent,
843 icalproperty_new_location(bstr("location")));
845 while (prop = icalcomponent_get_first_property(vevent,
846 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
847 icalcomponent_remove_property(vevent, prop);
848 icalproperty_free(prop);
850 if (havebstr("description")) {
851 icalcomponent_add_property(vevent,
852 icalproperty_new_description(bstr("description")));
855 while (prop = icalcomponent_get_first_property(vevent,
856 ICAL_DTSTART_PROPERTY), prop != NULL) {
857 icalcomponent_remove_property(vevent, prop);
858 icalproperty_free(prop);
861 if (yesbstr("alldayevent")) {
869 icaltime_from_webform_dateonly(&event_start, "dtstart");
872 icaltime_from_webform(&event_start, "dtstart");
875 prop = icalproperty_new_dtstart(event_start);
878 /* Force it to serialize as a date-only rather than date/time */
879 icalproperty_set_value(prop, icalvalue_new_date(event_start));
882 if (prop) icalcomponent_add_property(vevent, prop);
883 else icalproperty_free(prop);
885 while (prop = icalcomponent_get_first_property(vevent,
886 ICAL_DTEND_PROPERTY), prop != NULL) {
887 icalcomponent_remove_property(vevent, prop);
888 icalproperty_free(prop);
890 while (prop = icalcomponent_get_first_property(vevent,
891 ICAL_DURATION_PROPERTY), prop != NULL) {
892 icalcomponent_remove_property(vevent, prop);
893 icalproperty_free(prop);
897 icaltime_from_webform_dateonly(&t, "dtend");
899 /* with this field supposed to be non-inclusive we have to add one day */
900 icaltime_adjust(&t, 1, 0, 0, 0);
903 icaltime_from_webform(&t, "dtend");
906 icalcomponent_add_property(vevent,
907 icalproperty_new_dtend(icaltime_normalize(t)
911 /* recurrence rules -- begin */
913 /* remove any existing rule */
914 while (prop = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY), prop != NULL) {
915 icalcomponent_remove_property(vevent, prop);
916 icalproperty_free(prop);
919 if (yesbstr("is_recur")) {
920 struct icalrecurrencetype recur;
921 icalrecurrencetype_clear(&recur);
923 recur.interval = atoi(bstr("interval"));
924 recur.freq = atoi(bstr("freq"));
928 /* These can't happen; they're disabled. */
929 case ICAL_SECONDLY_RECURRENCE:
931 case ICAL_MINUTELY_RECURRENCE:
933 case ICAL_HOURLY_RECURRENCE:
936 /* Daily is valid but there are no further inputs. */
937 case ICAL_DAILY_RECURRENCE:
940 /* These are the real options. */
942 case ICAL_WEEKLY_RECURRENCE:
944 for (i=0; i<7; ++i) {
945 snprintf(buf, sizeof buf, "weekday%d", i);
946 if (YESBSTR(buf)) recur.by_day[j++] =
947 icalrecurrencetype_day_day_of_week(i+1);
949 recur.by_day[j++] = ICAL_RECURRENCE_ARRAY_MAX;
952 case ICAL_MONTHLY_RECURRENCE:
953 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
954 recur.by_month_day[0] = event_start.day;
955 recur.by_month_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
957 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
958 recur.by_day[0] = (atoi(bstr("rrmweek")) * 8)
959 + atoi(bstr("rrmweekday")) + 1;
960 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
964 case ICAL_YEARLY_RECURRENCE:
965 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
966 /* no further action is needed here */
968 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
969 recur.by_month[0] = atoi(bstr("rrymonth"));
970 recur.by_month[1] = ICAL_RECURRENCE_ARRAY_MAX;
971 recur.by_day[0] = (atoi(bstr("rrymweek")) * 8)
972 + atoi(bstr("rrymweekday")) + 1;
973 recur.by_day[1] = ICAL_RECURRENCE_ARRAY_MAX;
977 /* This one can't happen either. */
978 case ICAL_NO_RECURRENCE:
982 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
983 recur.count = atoi(bstr("rrcount"));
985 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
986 icaltime_from_webform_dateonly(&recur.until, "rruntil");
989 icalcomponent_add_property(vevent, icalproperty_new_rrule(recur));
992 /* recurrence rules -- end */
994 /* See if transparency is indicated */
995 if (havebstr("transp")) {
996 if (!strcasecmp(bstr("transp"), "opaque")) {
997 formtransp = ICAL_TRANSP_OPAQUE;
999 else if (!strcasecmp(bstr("transp"), "transparent")) {
1000 formtransp = ICAL_TRANSP_TRANSPARENT;
1003 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
1005 icalcomponent_remove_property(vevent, prop);
1006 icalproperty_free(prop);
1009 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
1012 /* Give this event a UID if it doesn't have one. */
1013 if (icalcomponent_get_first_property(vevent,
1014 ICAL_UID_PROPERTY) == NULL) {
1016 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
1019 /* Increment the sequence ID */
1020 while (prop = icalcomponent_get_first_property(vevent,
1021 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
1022 i = icalproperty_get_sequence(prop);
1023 if (i > sequence) sequence = i;
1024 icalcomponent_remove_property(vevent, prop);
1025 icalproperty_free(prop);
1028 icalcomponent_add_property(vevent,
1029 icalproperty_new_sequence(sequence)
1033 * Set the organizer, only if one does not already exist *and*
1034 * the form is supplying one
1036 strcpy(buf, bstr("organizer"));
1037 if ( (icalcomponent_get_first_property(vevent,
1038 ICAL_ORGANIZER_PROPERTY) == NULL)
1039 && (!IsEmptyStr(buf)) ) {
1041 /* set new organizer */
1042 sprintf(organizer_string, "MAILTO:%s", buf);
1043 icalcomponent_add_property(vevent,
1044 icalproperty_new_organizer(organizer_string)
1050 * Add any new attendees listed in the web form
1053 /* First, strip out the parenthesized partstats. */
1054 strcpy(form_attendees, bstr("attendees"));
1055 while ( stripout(form_attendees, '(', ')') != 0);
1057 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1058 j = strlen(form_attendees);
1059 for (i=0; i<j; ++i) {
1060 if (form_attendees[i] == ',') {
1061 form_attendees[i] = '\n';
1062 while (isspace(form_attendees[i+1])) {
1063 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
1069 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1070 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1072 if (!IsEmptyStr(buf)) {
1073 sprintf(attendee_string, "MAILTO:%s", buf);
1076 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1077 if (!strcasecmp(attendee_string,
1078 icalproperty_get_attendee(attendee)))
1084 icalcomponent_add_property(vevent,
1085 icalproperty_new_attendee(attendee_string)
1092 * Remove any attendees *not* listed in the web form
1094 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
1095 strcpy(attendee_string, icalproperty_get_attendee(attendee));
1096 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
1097 strcpy(attendee_string, &attendee_string[7]);
1098 striplt(attendee_string);
1100 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
1101 extract_token(buf, form_attendees, i, '\n', sizeof buf);
1103 if (!strcasecmp(buf, attendee_string)) ++foundit;
1106 icalcomponent_remove_property(vevent, attendee);
1107 icalproperty_free(attendee);
1114 * Encapsulate event into full VCALENDAR component. Clone it first,
1115 * for two reasons: one, it's easier to just free the whole thing
1116 * when we're done instead of unbundling, but more importantly, we
1117 * can't encapsulate something that may already be encapsulated
1120 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
1122 /* Set the method to PUBLISH */
1123 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1125 /* If the user clicked 'Save' then save it to the server. */
1126 if ( (encaps != NULL) && (havebstr("save_button")) ) {
1127 serv_puts("ENT0 1|||4|||1|");
1128 serv_getln(buf, sizeof buf);
1129 if (buf[0] == '8') {
1130 serv_puts("Content-type: text/calendar");
1132 serv_puts(icalcomponent_as_ical_string(encaps));
1135 if ( (buf[0] == '8') || (buf[0] == '4') ) {
1136 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1139 if (buf[0] == '2') {
1140 strcpy(WC->ImportantMessage, &buf[4]);
1142 icalmemory_free_ring ();
1143 icalcomponent_free(encaps);
1147 /* Or, check attendee availability if the user asked for that. */
1148 if ( (encaps != NULL) && (havebstr("check_button")) ) {
1150 /* Call this function, which does the real work */
1151 check_attendee_availability(encaps);
1153 /* This displays the form again, with our annotations */
1154 display_edit_individual_event(encaps, msgnum, from, unread, NULL);
1156 icalcomponent_free(encaps);
1159 if (encaps != NULL) {
1160 icalcomponent_free(encaps);
1167 * If the user clicked 'Delete' then delete it.
1169 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
1170 serv_printf("DELE %ld", lbstr("msgnum"));
1171 serv_getln(buf, sizeof buf);
1174 if (created_new_vevent) {
1175 icalcomponent_free(vevent);
1178 /* If this was a save or delete, go back to the calendar or summary view. */
1179 if (!havebstr("check_button")) {
1180 if (!strcasecmp(bstr("calview"), "summary")) {