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");
229 * If this is an all-day-event, set the end time to be identical to
230 * the start time (the hour/minute/second will be set to midnight).
231 * Otherwise extract or create it.
233 wprintf("<TR><TD><B>");
235 wprintf("</B></TD><TD id=\"dtendcell\">\n");
236 if (t_start
.is_date
) {
240 p
= icalcomponent_get_first_property(vevent
,
241 ICAL_DTEND_PROPERTY
);
243 t_end
= icalproperty_get_dtend(p
);
247 * If this is not an all-day event and there is no
248 * end time specified, make the default one hour
249 * from the start time.
254 t_end
= icaltime_normalize(t_end
);
255 /* t_end = icaltime_from_timet(now, 0); */
258 display_icaltimetype_as_webform(&t_end
, "dtend", 0);
259 wprintf("</TD></TR>\n");
261 wprintf("<TR><TD><B>");
263 wprintf("</B></TD><TD>\n"
264 "<TEXTAREA NAME=\"description\" wrap=soft "
265 "ROWS=5 COLS=72 WIDTH=72>\n"
267 p
= icalcomponent_get_first_property(vevent
, ICAL_DESCRIPTION_PROPERTY
);
269 escputs((char *)icalproperty_get_comment(p
));
271 wprintf("</TEXTAREA></TD></TR>");
274 * For a new event, the user creating the event should be the
275 * organizer. Set this field accordingly.
277 if (icalcomponent_get_first_property(vevent
, ICAL_ORGANIZER_PROPERTY
)
279 sprintf(organizer_string
, "MAILTO:%s", WC
->cs_inet_email
);
280 icalcomponent_add_property(vevent
,
281 icalproperty_new_organizer(organizer_string
)
286 * Determine who is the organizer of this event.
287 * We need to determine "me" or "not me."
289 organizer
= icalcomponent_get_first_property(vevent
, ICAL_ORGANIZER_PROPERTY
);
290 if (organizer
!= NULL
) {
291 strcpy(organizer_string
, icalproperty_get_organizer(organizer
));
292 if (!strncasecmp(organizer_string
, "MAILTO:", 7)) {
293 strcpy(organizer_string
, &organizer_string
[7]);
294 striplt(organizer_string
);
295 serv_printf("ISME %s", organizer_string
);
296 serv_getln(buf
, sizeof buf
);
303 wprintf("<TR><TD><B>");
304 wprintf(_("Organizer"));
305 wprintf("</B></TD><TD>");
306 escputs(organizer_string
);
307 if (organizer_is_me
) {
308 wprintf(" <FONT SIZE=-1><I>");
309 wprintf(_("(you are the organizer)"));
310 wprintf("</I></FONT>\n");
314 * Transmit the organizer as a hidden field. We don't want the user
315 * to be able to change it, but we do want it fed back to the server,
316 * especially if this is a new event and there is no organizer already
317 * in the calendar object.
319 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
320 escputs(organizer_string
);
323 wprintf("</TD></TR>\n");
326 wprintf("<TR><TD><B>");
327 wprintf(_("Show time as:"));
328 wprintf("</B></TD><TD>");
330 p
= icalcomponent_get_first_property(vevent
, ICAL_TRANSP_PROPERTY
);
332 /* No transparency found. Default to opaque (busy). */
333 p
= icalproperty_new_transp(ICAL_TRANSP_OPAQUE
);
335 icalcomponent_add_property(vevent
, p
);
339 v
= icalproperty_get_value(p
);
345 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
346 if ((v
!= NULL
) && (icalvalue_get_transp(v
) == ICAL_TRANSP_TRANSPARENT
)) {
351 wprintf(" ");
353 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
354 if ((v
!= NULL
) && (icalvalue_get_transp(v
) == ICAL_TRANSP_OPAQUE
)) {
360 wprintf("</TD></TR>\n");
363 /* Done with properties. */
364 wprintf("</TABLE>\n");
368 /* Attendees tab (need to move things here) */
370 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
371 wprintf("<TR><TD><B>");
372 wprintf(_("Attendees"));
375 wprintf(_("(One per line)"));
376 wprintf("</font>\n");
378 /* Pop open an address book -- begin */
380 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
382 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
387 /* Pop open an address book -- end */
390 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
391 "onchange=\"EnableOrDisableCheckButton();\" "
392 "onKeyPress=\"EnableOrDisableCheckButton();\" "
393 "ROWS=10 COLS=72 WIDTH=72>\n",
394 (organizer_is_me
? "" : "DISABLED ")
397 for (attendee
= icalcomponent_get_first_property(vevent
, ICAL_ATTENDEE_PROPERTY
);
399 attendee
= icalcomponent_get_next_property(vevent
, ICAL_ATTENDEE_PROPERTY
)) {
400 strcpy(attendee_string
, icalproperty_get_attendee(attendee
));
401 if (!strncasecmp(attendee_string
, "MAILTO:", 7)) {
403 /* screen name or email address */
404 strcpy(attendee_string
, &attendee_string
[7]);
405 striplt(attendee_string
);
406 if (i
++) wprintf("\n");
407 escputs(attendee_string
);
410 /* participant status */
411 partstat_as_string(buf
, attendee
);
415 wprintf("</TEXTAREA></TD></TR>\n");
416 wprintf("</TABLE>\n");
422 rrule
= icalcomponent_get_first_property(vevent
, ICAL_RRULE_PROPERTY
);
424 recur
= icalproperty_get_rrule(rrule
);
427 /* blank recurrence with some sensible defaults */
428 memset(&recur
, 0, sizeof(struct icalrecurrencetype
));
430 recur
.until
= icaltime_null_time();
432 recur
.freq
= ICAL_WEEKLY_RECURRENCE
;
435 wprintf("<INPUT TYPE=\"checkbox\" id=\"is_recur\" NAME=\"is_recur\" "
437 "onclick=\"RecurrenceShowHide();\""
439 (rrule
? "CHECKED=\"CHECKED\"" : "" ),
440 _("This is a recurring event")
443 wprintf("<div id=\"rrule_div\">\n"); /* begin 'rrule_div' div */
445 wprintf("<table border=0 cellspacing=\"10\" width=100%%>\n");
447 char *frequency_units
[] = {
467 wprintf("<tr><td><b>");
468 wprintf(_("Recurrence rule"));
469 wprintf("</b></td><td>");
471 if ((recur
.freq
< 0) || (recur
.freq
> 6)) recur
.freq
= 4;
472 wprintf("%s ", _("Repeats every"));
474 wprintf("<input type=\"text\" name=\"interval\" maxlength=\"3\" size=\"3\" ");
475 wprintf("value=\"%d\"> ", recur
.interval
);
477 wprintf("<select name=\"freq\" id=\"freq_selector\" size=\"1\" "
478 "onChange=\"RecurrenceShowHide();\">\n");
479 for (i
=0; i
<(sizeof frequency_units
/ sizeof(char *)); ++i
) {
480 wprintf("<option %s%svalue=\"%d\">%s</option>\n",
481 ((i
== recur
.freq
) ? "selected " : ""),
482 (((i
== recur
.freq
) || ((i
>=3)&&(i
<=6))) ? "" : "disabled "),
487 wprintf("</select>\n");
489 wprintf("<div id=\"weekday_selector\">"); /* begin 'weekday_selector' div */
490 wprintf("%s<br>", _("on these weekdays:"));
492 char weekday_is_selected
[7];
493 memset(weekday_is_selected
, 0, 7);
495 for (i
=0; i
<ICAL_BY_DAY_SIZE
; ++i
) {
496 if (recur
.by_day
[i
] == ICAL_RECURRENCE_ARRAY_MAX
) {
497 i
= ICAL_RECURRENCE_ARRAY_MAX
; /* all done */
500 for (j
=0; j
<7; ++j
) {
501 if (icalrecurrencetype_day_day_of_week(recur
.by_day
[i
]) == j
+1) {
502 weekday_is_selected
[j
] = 1;
508 for (j
=0; j
<7; ++j
) {
509 i
= ((j
+ (int)weekstart
) % 7);
510 wprintf("<input type=\"checkbox\" name=\"weekday%d\" value=\"yes\"", i
);
511 if (weekday_is_selected
[i
]) wprintf(" checked");
512 wprintf(">%s\n", weekday_labels
[i
]);
514 wprintf("</div>\n"); /* end 'weekday_selector' div */
520 int which_rrmonthtype_is_preselected
= 0;
521 wprintf("<div id=\"monthday_selector\">"); /* begin 'monthday_selector' div */
523 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_mday\" "
524 "value=\"rrmonthtype_mday\" "
525 "%s onChange=\"RecurrenceShowHide();\">",
526 ((which_rrmonthtype_is_preselected
== 0) ? "checked" : "")
529 int rrmday
= t_start
.day
;
530 int rrmweekday
= icaltime_day_of_week(t_start
) - 1;
532 /* Figure out what week of the month we're in */
533 icaltimetype day1
= t_start
;
535 int weekbase
= icaltime_week_number(day1
);
536 int rrmweek
= icaltime_week_number(t_start
) - weekbase
+ 1;
538 /* Are we going by day of the month or week/day? */
540 if (recur
.by_month_day
[0] != ICAL_RECURRENCE_ARRAY_MAX
) {
541 which_rrmonthtype_is_preselected
= 0;
542 rrmday
= recur
.by_month_day
[0];
544 else if (recur
.by_day
[0] != ICAL_RECURRENCE_ARRAY_MAX
) {
545 which_rrmonthtype_is_preselected
= 1;
546 rrmweek
= icalrecurrencetype_day_position(recur
.by_day
[0]);
547 rrmweekday
= icalrecurrencetype_day_day_of_week(recur
.by_day
[0]) - 1;
550 wprintf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday
, "</span>");
553 wprintf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
554 "value=\"rrmonthtype_wday\" "
555 "%s onChange=\"RecurrenceShowHide();\">",
556 ((which_rrmonthtype_is_preselected
== 1) ? "checked" : "")
559 wprintf(_("on the "));
560 wprintf("<select name=\"rrmweek\" id=\"rrmweek\" size=\"1\" "
561 "onChange=\"RecurrenceShowHide();\">\n");
562 for (i
=1; i
<=5; ++i
) {
563 wprintf("<option %svalue=\"%d\">%s</option>\n",
564 ((i
==rrmweek
) ? "selected " : ""),
569 wprintf("</select> \n");
571 wprintf("<select name=\"rrmweekday\" id=\"rrmweekday\" size=\"1\" "
572 "onChange=\"RecurrenceShowHide();\">\n");
573 for (j
=0; j
<7; ++j
) {
574 i
= ((j
+ (int)weekstart
) % 7);
575 wprintf("<option %svalue=\"%d\">%s</option>\n",
576 ((i
==rrmweekday
) ? "selected " : ""),
581 wprintf("</select>");
583 wprintf(" %s<br />\n", _("of the month"));
585 wprintf("</div>\n"); /* end 'monthday_selector' div */
588 int rrymweek
= rrmweek
;
589 int rrymweekday
= rrmweekday
;
590 int rrymonth
= t_start
.month
;
591 int which_rryeartype_is_preselected
= 0;
594 (recur
.by_day
[0] != ICAL_RECURRENCE_ARRAY_MAX
)
595 && (recur
.by_day
[0] != 0)
596 && (recur
.by_month
[0] != ICAL_RECURRENCE_ARRAY_MAX
)
597 && (recur
.by_month
[0] != 0)
599 which_rryeartype_is_preselected
= 1;
600 rrymweek
= icalrecurrencetype_day_position(recur
.by_day
[0]);
601 rrymweekday
= icalrecurrencetype_day_day_of_week(recur
.by_day
[0]) - 1;
602 rrymonth
= recur
.by_month
[0];
605 wprintf("<div id=\"yearday_selector\">"); /* begin 'yearday_selector' div */
607 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ymday\" "
608 "value=\"rryeartype_ymday\" "
609 "%s onChange=\"RecurrenceShowHide();\">",
610 ((which_rryeartype_is_preselected
== 0) ? "checked" : "")
612 wprintf(_("every "));
613 wprintf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
615 wprintf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
616 "value=\"rryeartype_ywday\" "
617 "%s onChange=\"RecurrenceShowHide();\">",
618 ((which_rryeartype_is_preselected
== 1) ? "checked" : "")
621 wprintf(_("on the "));
622 wprintf("<select name=\"rrymweek\" id=\"rrymweek\" size=\"1\" "
623 "onChange=\"RecurrenceShowHide();\">\n");
624 for (i
=1; i
<=5; ++i
) {
625 wprintf("<option %svalue=\"%d\">%s</option>\n",
626 ((i
==rrymweek
) ? "selected " : ""),
631 wprintf("</select> \n");
633 wprintf("<select name=\"rrymweekday\" id=\"rrymweekday\" size=\"1\" "
634 "onChange=\"RecurrenceShowHide();\">\n");
635 for (j
=0; j
<7; ++j
) {
636 i
= ((j
+ (int)weekstart
) % 7);
637 wprintf("<option %svalue=\"%d\">%s</option>\n",
638 ((i
==rrymweekday
) ? "selected " : ""),
643 wprintf("</select>");
645 wprintf(" %s ", _("of"));
647 wprintf("<select name=\"rrymonth\" id=\"rrymonth\" size=\"1\" "
648 "onChange=\"RecurrenceShowHide();\">\n");
649 for (i
=1; i
<=12; ++i
) {
650 wprintf("<option %svalue=\"%d\">%s</option>\n",
651 ((i
==rrymonth
) ? "selected " : ""),
656 wprintf("</select>");
659 wprintf("</div>\n"); /* end 'yearday_selector' div */
661 wprintf("</td></tr>\n");
664 int which_rrend_is_preselected
= 0;
665 if (!icaltime_is_null_time(recur
.until
)) which_rrend_is_preselected
= 2;
666 if (recur
.count
> 0) which_rrend_is_preselected
= 1;
668 wprintf("<tr><td><b>");
669 wprintf(_("Recurrence range"));
670 wprintf("</b></td><td>\n");
672 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_none\" "
673 "value=\"rrend_none\" "
674 "%s onChange=\"RecurrenceShowHide();\">",
675 ((which_rrend_is_preselected
== 0) ? "checked" : "")
677 wprintf("%s<br />\n", _("No ending date"));
679 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
680 "value=\"rrend_count\" "
681 "%s onChange=\"RecurrenceShowHide();\">",
682 ((which_rrend_is_preselected
== 1) ? "checked" : "")
684 wprintf(_("Repeat this event"));
685 wprintf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
686 wprintf("value=\"%d\"> ", recur
.count
);
690 wprintf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
691 "value=\"rrend_until\" "
692 "%s onChange=\"RecurrenceShowHide();\">",
693 ((which_rrend_is_preselected
== 2) ? "checked" : "")
695 wprintf(_("Repeat this event until "));
697 if (icaltime_is_null_time(recur
.until
)) {
698 recur
.until
= icaltime_add(t_start
, icaldurationtype_from_int(604800));
700 display_icaltimetype_as_webform(&recur
.until
, "rruntil", 1);
703 wprintf("</td></tr>\n");
705 wprintf("</table>\n");
706 wprintf("</div>\n"); /* end 'rrule' div */
710 /* submit buttons (common area beneath the tabs) */
713 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
715 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
717 "<INPUT TYPE=\"submit\" id=\"check_button\" NAME=\"check_button\" VALUE=\"%s\">\n"
719 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
723 _("Check attendee availability"),
726 wprintf("</FORM>\n");
729 wprintf("</div>\n"); /* end 'fix_scrollbar_bug' div */
731 StrBufAppendPrintf(WC
->trailing_javascript
,
732 "eventEditAllDay(); \n"
733 "RecurrenceShowHide(); \n"
734 "EnableOrDisableCheckButton(); \n"
736 address_book_popup();
739 if (created_new_vevent
) {
740 icalcomponent_free(vevent
);
745 * Save an edited event
747 * supplied_vevent: the event to save
748 * msgnum: the index on the citserver
750 void save_individual_event(icalcomponent
*supplied_vevent
, long msgnum
, char *from
,
751 int unread
, struct calview
*calv
) {
754 icalcomponent
*vevent
, *encaps
;
755 int created_new_vevent
= 0;
756 int all_day_event
= 0;
757 struct icaltimetype event_start
, t
;
758 icalproperty
*attendee
= NULL
;
759 char attendee_string
[SIZ
];
762 char form_attendees
[SIZ
];
763 char organizer_string
[SIZ
];
765 enum icalproperty_transp formtransp
= ICAL_TRANSP_NONE
;
767 if (supplied_vevent
!= NULL
) {
768 vevent
= supplied_vevent
;
770 /* Convert all timestamps to UTC to make them easier to process. */
771 ical_dezonify(vevent
);
774 * If we're looking at a fully encapsulated VCALENDAR
775 * rather than a VEVENT component, attempt to use the first
776 * relevant VEVENT subcomponent. If there is none, the
777 * NULL returned by icalcomponent_get_first_component() will
778 * tell the next iteration of this function to create a
781 if (icalcomponent_isa(vevent
) == ICAL_VCALENDAR_COMPONENT
) {
782 save_individual_event(
783 icalcomponent_get_first_component(
784 vevent
, ICAL_VEVENT_COMPONENT
),
785 msgnum
, from
, unread
, NULL
791 vevent
= icalcomponent_new(ICAL_VEVENT_COMPONENT
);
792 created_new_vevent
= 1;
795 if ( (havebstr("save_button"))
796 || (havebstr("check_button")) ) {
798 /* Replace values in the component with ones from the form */
800 while (prop
= icalcomponent_get_first_property(vevent
,
801 ICAL_SUMMARY_PROPERTY
), prop
!= NULL
) {
802 icalcomponent_remove_property(vevent
, prop
);
803 icalproperty_free(prop
);
806 if (havebstr("summary")) {
807 icalcomponent_add_property(vevent
,
808 icalproperty_new_summary(bstr("summary")));
810 icalcomponent_add_property(vevent
,
811 icalproperty_new_summary(_("Untitled Event")));
814 while (prop
= icalcomponent_get_first_property(vevent
,
815 ICAL_LOCATION_PROPERTY
), prop
!= NULL
) {
816 icalcomponent_remove_property(vevent
, prop
);
817 icalproperty_free(prop
);
819 if (havebstr("location")) {
820 icalcomponent_add_property(vevent
,
821 icalproperty_new_location(bstr("location")));
823 while (prop
= icalcomponent_get_first_property(vevent
,
824 ICAL_DESCRIPTION_PROPERTY
), prop
!= NULL
) {
825 icalcomponent_remove_property(vevent
, prop
);
826 icalproperty_free(prop
);
828 if (havebstr("description")) {
829 icalcomponent_add_property(vevent
,
830 icalproperty_new_description(bstr("description")));
833 while (prop
= icalcomponent_get_first_property(vevent
,
834 ICAL_DTSTART_PROPERTY
), prop
!= NULL
) {
835 icalcomponent_remove_property(vevent
, prop
);
836 icalproperty_free(prop
);
839 if (yesbstr("alldayevent")) {
847 icaltime_from_webform_dateonly(&event_start
, "dtstart");
850 icaltime_from_webform(&event_start
, "dtstart");
853 prop
= icalproperty_new_dtstart(event_start
);
856 /* Force it to serialize as a date-only rather than date/time */
857 icalproperty_set_value(prop
, icalvalue_new_date(event_start
));
860 if (prop
) icalcomponent_add_property(vevent
, prop
);
861 else icalproperty_free(prop
);
863 while (prop
= icalcomponent_get_first_property(vevent
,
864 ICAL_DTEND_PROPERTY
), prop
!= NULL
) {
865 icalcomponent_remove_property(vevent
, prop
);
866 icalproperty_free(prop
);
868 while (prop
= icalcomponent_get_first_property(vevent
,
869 ICAL_DURATION_PROPERTY
), prop
!= NULL
) {
870 icalcomponent_remove_property(vevent
, prop
);
871 icalproperty_free(prop
);
874 if (all_day_event
== 0) {
875 icaltime_from_webform(&t
, "dtend");
876 icalcomponent_add_property(vevent
,
877 icalproperty_new_dtend(icaltime_normalize(t
)
882 /* recurrence rules -- begin */
884 /* remove any existing rule */
885 while (prop
= icalcomponent_get_first_property(vevent
, ICAL_RRULE_PROPERTY
), prop
!= NULL
) {
886 icalcomponent_remove_property(vevent
, prop
);
887 icalproperty_free(prop
);
890 if (yesbstr("is_recur")) {
891 struct icalrecurrencetype recur
;
892 icalrecurrencetype_clear(&recur
);
894 recur
.interval
= atoi(bstr("interval"));
895 recur
.freq
= atoi(bstr("freq"));
899 /* These can't happen; they're disabled. */
900 case ICAL_SECONDLY_RECURRENCE
:
902 case ICAL_MINUTELY_RECURRENCE
:
904 case ICAL_HOURLY_RECURRENCE
:
907 /* Daily is valid but there are no further inputs. */
908 case ICAL_DAILY_RECURRENCE
:
911 /* These are the real options. */
913 case ICAL_WEEKLY_RECURRENCE
:
915 for (i
=0; i
<7; ++i
) {
916 snprintf(buf
, sizeof buf
, "weekday%d", i
);
917 if (YESBSTR(buf
)) recur
.by_day
[j
++] =
918 icalrecurrencetype_day_day_of_week(i
+1);
920 recur
.by_day
[j
++] = ICAL_RECURRENCE_ARRAY_MAX
;
923 case ICAL_MONTHLY_RECURRENCE
:
924 if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_mday")) {
925 recur
.by_month_day
[0] = event_start
.day
;
926 recur
.by_month_day
[1] = ICAL_RECURRENCE_ARRAY_MAX
;
928 else if (!strcasecmp(bstr("rrmonthtype"), "rrmonthtype_wday")) {
929 recur
.by_day
[0] = (atoi(bstr("rrmweek")) * 8)
930 + atoi(bstr("rrmweekday")) + 1;
931 recur
.by_day
[1] = ICAL_RECURRENCE_ARRAY_MAX
;
935 case ICAL_YEARLY_RECURRENCE
:
936 if (!strcasecmp(bstr("rryeartype"), "rryeartype_ymday")) {
937 /* no further action is needed here */
939 else if (!strcasecmp(bstr("rryeartype"), "rryeartype_ywday")) {
940 recur
.by_month
[0] = atoi(bstr("rrymonth"));
941 recur
.by_month
[1] = ICAL_RECURRENCE_ARRAY_MAX
;
942 recur
.by_day
[0] = (atoi(bstr("rrymweek")) * 8)
943 + atoi(bstr("rrymweekday")) + 1;
944 recur
.by_day
[1] = ICAL_RECURRENCE_ARRAY_MAX
;
948 /* This one can't happen either. */
949 case ICAL_NO_RECURRENCE
:
953 if (!strcasecmp(bstr("rrend"), "rrend_count")) {
954 recur
.count
= atoi(bstr("rrcount"));
956 else if (!strcasecmp(bstr("rrend"), "rrend_until")) {
957 icaltime_from_webform_dateonly(&recur
.until
, "rruntil");
960 icalcomponent_add_property(vevent
, icalproperty_new_rrule(recur
));
963 /* recurrence rules -- end */
965 /* See if transparency is indicated */
966 if (havebstr("transp")) {
967 if (!strcasecmp(bstr("transp"), "opaque")) {
968 formtransp
= ICAL_TRANSP_OPAQUE
;
970 else if (!strcasecmp(bstr("transp"), "transparent")) {
971 formtransp
= ICAL_TRANSP_TRANSPARENT
;
974 while (prop
= icalcomponent_get_first_property(vevent
, ICAL_TRANSP_PROPERTY
),
976 icalcomponent_remove_property(vevent
, prop
);
977 icalproperty_free(prop
);
980 icalcomponent_add_property(vevent
, icalproperty_new_transp(formtransp
));
983 /* Give this event a UID if it doesn't have one. */
984 if (icalcomponent_get_first_property(vevent
,
985 ICAL_UID_PROPERTY
) == NULL
) {
987 icalcomponent_add_property(vevent
, icalproperty_new_uid(buf
));
990 /* Increment the sequence ID */
991 while (prop
= icalcomponent_get_first_property(vevent
,
992 ICAL_SEQUENCE_PROPERTY
), (prop
!= NULL
) ) {
993 i
= icalproperty_get_sequence(prop
);
994 if (i
> sequence
) sequence
= i
;
995 icalcomponent_remove_property(vevent
, prop
);
996 icalproperty_free(prop
);
999 icalcomponent_add_property(vevent
,
1000 icalproperty_new_sequence(sequence
)
1004 * Set the organizer, only if one does not already exist *and*
1005 * the form is supplying one
1007 strcpy(buf
, bstr("organizer"));
1008 if ( (icalcomponent_get_first_property(vevent
,
1009 ICAL_ORGANIZER_PROPERTY
) == NULL
)
1010 && (!IsEmptyStr(buf
)) ) {
1012 /* set new organizer */
1013 sprintf(organizer_string
, "MAILTO:%s", buf
);
1014 icalcomponent_add_property(vevent
,
1015 icalproperty_new_organizer(organizer_string
)
1021 * Add any new attendees listed in the web form
1024 /* First, strip out the parenthesized partstats. */
1025 strcpy(form_attendees
, bstr("attendees"));
1026 while ( stripout(form_attendees
, '(', ')') != 0);
1028 /* Next, change any commas to newlines, because we want newline-separated attendees. */
1029 j
= strlen(form_attendees
);
1030 for (i
=0; i
<j
; ++i
) {
1031 if (form_attendees
[i
] == ',') {
1032 form_attendees
[i
] = '\n';
1033 while (isspace(form_attendees
[i
+1])) {
1034 strcpy(&form_attendees
[i
+1], &form_attendees
[i
+2]);
1040 for (i
=0; i
<num_tokens(form_attendees
, '\n'); ++i
) {
1041 extract_token(buf
, form_attendees
, i
, '\n', sizeof buf
);
1043 if (!IsEmptyStr(buf
)) {
1044 sprintf(attendee_string
, "MAILTO:%s", buf
);
1047 for (attendee
= icalcomponent_get_first_property(vevent
, ICAL_ATTENDEE_PROPERTY
); attendee
!= NULL
; attendee
= icalcomponent_get_next_property(vevent
, ICAL_ATTENDEE_PROPERTY
)) {
1048 if (!strcasecmp(attendee_string
,
1049 icalproperty_get_attendee(attendee
)))
1055 icalcomponent_add_property(vevent
,
1056 icalproperty_new_attendee(attendee_string
)
1063 * Remove any attendees *not* listed in the web form
1065 STARTOVER
: for (attendee
= icalcomponent_get_first_property(vevent
, ICAL_ATTENDEE_PROPERTY
); attendee
!= NULL
; attendee
= icalcomponent_get_next_property(vevent
, ICAL_ATTENDEE_PROPERTY
)) {
1066 strcpy(attendee_string
, icalproperty_get_attendee(attendee
));
1067 if (!strncasecmp(attendee_string
, "MAILTO:", 7)) {
1068 strcpy(attendee_string
, &attendee_string
[7]);
1069 striplt(attendee_string
);
1071 for (i
=0; i
<num_tokens(form_attendees
, '\n'); ++i
) {
1072 extract_token(buf
, form_attendees
, i
, '\n', sizeof buf
);
1074 if (!strcasecmp(buf
, attendee_string
)) ++foundit
;
1077 icalcomponent_remove_property(vevent
, attendee
);
1078 icalproperty_free(attendee
);
1085 * Encapsulate event into full VCALENDAR component. Clone it first,
1086 * for two reasons: one, it's easier to just free the whole thing
1087 * when we're done instead of unbundling, but more importantly, we
1088 * can't encapsulate something that may already be encapsulated
1091 encaps
= ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent
));
1093 /* Set the method to PUBLISH */
1094 icalcomponent_set_method(encaps
, ICAL_METHOD_PUBLISH
);
1096 /* If the user clicked 'Save' then save it to the server. */
1097 if ( (encaps
!= NULL
) && (havebstr("save_button")) ) {
1098 serv_puts("ENT0 1|||4|||1|");
1099 serv_getln(buf
, sizeof buf
);
1100 if (buf
[0] == '8') {
1101 serv_puts("Content-type: text/calendar");
1103 serv_puts(icalcomponent_as_ical_string(encaps
));
1106 if ( (buf
[0] == '8') || (buf
[0] == '4') ) {
1107 while (serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
1110 if (buf
[0] == '2') {
1111 strcpy(WC
->ImportantMessage
, &buf
[4]);
1113 icalmemory_free_ring ();
1114 icalcomponent_free(encaps
);
1118 /* Or, check attendee availability if the user asked for that. */
1119 if ( (encaps
!= NULL
) && (havebstr("check_button")) ) {
1121 /* Call this function, which does the real work */
1122 check_attendee_availability(encaps
);
1124 /* This displays the form again, with our annotations */
1125 display_edit_individual_event(encaps
, msgnum
, from
, unread
, NULL
);
1127 icalcomponent_free(encaps
);
1130 if (encaps
!= NULL
) {
1131 icalcomponent_free(encaps
);
1138 * If the user clicked 'Delete' then delete it.
1140 if ( (havebstr("delete_button")) && (msgnum
> 0L) ) {
1141 serv_printf("DELE %ld", lbstr("msgnum"));
1142 serv_getln(buf
, sizeof buf
);
1145 if (created_new_vevent
) {
1146 icalcomponent_free(vevent
);
1149 /* If this was a save or delete, go back to the calendar or summary view. */
1150 if (!havebstr("check_button")) {
1151 if (!strcasecmp(bstr("calview"), "summary")) {