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, int unread) {
17 icalcomponent *vevent;
20 struct icaltimetype t_start, t_end;
23 int created_new_vevent = 0;
24 icalproperty *organizer = NULL;
25 char organizer_string[SIZ];
26 icalproperty *attendee = NULL;
27 char attendee_string[SIZ];
29 int organizer_is_me = 0;
33 lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
34 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
38 strcpy(organizer_string, "");
39 strcpy(attendee_string, "");
41 if (supplied_vevent != NULL) {
42 vevent = supplied_vevent;
44 * If we're looking at a fully encapsulated VCALENDAR
45 * rather than a VEVENT component, attempt to use the first
46 * relevant VEVENT subcomponent. If there is none, the
47 * NULL returned by icalcomponent_get_first_component() will
48 * tell the next iteration of this function to create a
51 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
52 display_edit_individual_event(
53 icalcomponent_get_first_component(
54 vevent, ICAL_VEVENT_COMPONENT),
61 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
62 created_new_vevent = 1;
65 /* Learn the sequence */
66 p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
68 sequence = icalproperty_get_sequence(p);
72 output_headers(1, 1, 2, 0, 0, 0);
73 wprintf("<div id=\"banner\">\n");
75 wprintf(_("Add or edit an event"));
79 wprintf("<div id=\"content\" class=\"service\">\n");
81 wprintf("<div class=\"fix_scrollbar_bug\">");
83 /************************************************************
84 * Uncomment this to see the UID in calendar events for debugging
86 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
88 escputs((char *)icalproperty_get_comment(p));
91 wprintf("SEQUENCE == %d<br />\n", sequence);
92 *************************************************************/
94 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
95 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
97 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
99 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
101 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
103 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
105 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
114 tabbed_dialog(3, tabnames);
117 /* Put it in a borderless table so it lines up nicely */
118 wprintf("<TABLE border=0 width=100%%>\n");
120 wprintf("<TR><TD><B>");
121 wprintf(_("Summary"));
122 wprintf("</B></TD><TD>\n"
123 "<INPUT TYPE=\"text\" NAME=\"summary\" "
124 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
125 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
127 escputs((char *)icalproperty_get_comment(p));
129 wprintf("\"></TD></TR>\n");
131 wprintf("<TR><TD><B>");
132 wprintf(_("Location"));
133 wprintf("</B></TD><TD>\n"
134 "<INPUT TYPE=\"text\" NAME=\"location\" "
135 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
136 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
138 escputs((char *)icalproperty_get_comment(p));
140 wprintf("\"></TD></TR>\n");
142 wprintf("<TR><TD><B>");
144 wprintf("</B></TD><TD>\n");
145 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
147 t_start = icalproperty_get_dtstart(p);
148 if (t_start.is_date) {
155 localtime_r(&now, &tm_now);
156 if (havebstr("year")) {
157 tm_now.tm_year = ibstr("year") - 1900;
158 tm_now.tm_mon = ibstr("month") - 1;
159 tm_now.tm_mday = ibstr("day");
161 if (havebstr("hour")) {
162 tm_now.tm_hour = ibstr("hour");
163 tm_now.tm_min = ibstr("minute");
172 t_start = icaltime_from_timet_with_zone(
174 ((yesbstr("alldayevent")) ? 1 : 0),
175 icaltimezone_get_utc_timezone()
180 display_icaltimetype_as_webform(&t_start, "dtstart");
182 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
183 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
185 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
189 wprintf("</TD></TR>\n");
192 * If this is an all-day-event, set the end time to be identical to
193 * the start time (the hour/minute/second will be set to midnight).
194 * Otherwise extract or create it.
196 wprintf("<TR><TD><B>");
198 wprintf("</B></TD><TD id=\"dtendcell\">\n");
199 if (t_start.is_date) {
203 p = icalcomponent_get_first_property(vevent,
204 ICAL_DTEND_PROPERTY);
206 t_end = icalproperty_get_dtend(p);
210 * If this is not an all-day event and there is no
211 * end time specified, make the default one hour
212 * from the start time.
217 t_end = icaltime_normalize(t_end);
218 /* t_end = icaltime_from_timet(now, 0); */
221 display_icaltimetype_as_webform(&t_end, "dtend");
222 wprintf("</TD></TR>\n");
224 wprintf("<TR><TD><B>");
226 wprintf("</B></TD><TD>\n"
227 "<TEXTAREA NAME=\"description\" wrap=soft "
228 "ROWS=5 COLS=80 WIDTH=80>\n"
230 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
232 escputs((char *)icalproperty_get_comment(p));
234 wprintf("</TEXTAREA></TD></TR>");
237 * For a new event, the user creating the event should be the
238 * organizer. Set this field accordingly.
240 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
242 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
243 icalcomponent_add_property(vevent,
244 icalproperty_new_organizer(organizer_string)
249 * Determine who is the organizer of this event.
250 * We need to determine "me" or "not me."
252 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
253 if (organizer != NULL) {
254 strcpy(organizer_string, icalproperty_get_organizer(organizer));
255 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
256 strcpy(organizer_string, &organizer_string[7]);
257 striplt(organizer_string);
258 serv_printf("ISME %s", organizer_string);
259 serv_getln(buf, sizeof buf);
266 wprintf("<TR><TD><B>");
267 wprintf(_("Organizer"));
268 wprintf("</B></TD><TD>");
269 escputs(organizer_string);
270 if (organizer_is_me) {
271 wprintf(" <FONT SIZE=-1><I>");
272 wprintf(_("(you are the organizer)"));
273 wprintf("</I></FONT>\n");
277 * Transmit the organizer as a hidden field. We don't want the user
278 * to be able to change it, but we do want it fed back to the server,
279 * especially if this is a new event and there is no organizer already
280 * in the calendar object.
282 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
283 escputs(organizer_string);
286 wprintf("</TD></TR>\n");
289 wprintf("<TR><TD><B>");
290 wprintf(_("Show time as:"));
291 wprintf("</B></TD><TD>");
293 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
295 /** No transparency found. Default to opaque (busy). */
296 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
298 icalcomponent_add_property(vevent, p);
302 v = icalproperty_get_value(p);
308 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
309 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
313 wprintf(" ");
315 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
316 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
321 wprintf("</TD></TR>\n");
324 /** Done with properties. */
325 wprintf("</TABLE>\n");
329 /* Attendees tab (need to move things here) */
331 wprintf("<TABLE border=0 width=100%%>\n"); /* same table style as the event tab */
332 wprintf("<TR><TD><B>");
333 wprintf(_("Attendees"));
336 wprintf(_("(One per line)"));
337 wprintf("</font>\n");
339 /** Pop open an address book -- begin **/
341 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
343 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
348 /* Pop open an address book -- end **/
351 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
352 "ROWS=3 COLS=80 WIDTH=80>\n",
353 (organizer_is_me ? "" : "DISABLED ")
356 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
358 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
359 strcpy(attendee_string, icalproperty_get_attendee(attendee));
360 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
362 /** screen name or email address */
363 strcpy(attendee_string, &attendee_string[7]);
364 striplt(attendee_string);
365 if (i++) wprintf("\n");
366 escputs(attendee_string);
369 /** participant status */
370 partstat_as_string(buf, attendee);
374 wprintf("</TEXTAREA></TD></TR>\n");
375 wprintf("</TABLE>\n");
380 icalproperty *rrule = NULL;
381 struct icalrecurrencetype recur;
383 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
385 recur = icalproperty_get_rrule(rrule);
387 wprintf("<table border=0 width=100%%>\n"); /* same table style as the event tab */
389 /* Table row displaying raw RRULE data, FIXME remove when finished */
390 wprintf("<tr><td><b>");
392 wprintf("</b></td><td>");
393 wprintf("<tt>%s</tt>", icalrecurrencetype_as_string(&recur));
394 wprintf("</td></tr>\n");
396 char *frequency_units[] = {
407 wprintf("<tr><td><b>");
408 wprintf(_("Repeats"));
409 wprintf("</b></td><td>");
410 if ((recur.freq < 0) || (recur.freq > 6)) recur.freq = 4;
411 wprintf("every %d %s", recur.interval, frequency_units[recur.freq]);
412 wprintf("</td></tr>\n");
414 wprintf("</table>\n");
418 /* submit buttons (common area beneath the tabs) */
421 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
423 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
425 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
428 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
432 _("Check attendee availability"),
435 wprintf("</FORM>\n");
440 wprintf("<script type=\"text/javascript\">"
444 address_book_popup();
447 if (created_new_vevent) {
448 icalcomponent_free(vevent);
453 * Save an edited event
455 * supplied_vevent: the event to save
456 * msgnum: the index on the citserver
458 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread) {
461 icalcomponent *vevent, *encaps;
462 int created_new_vevent = 0;
463 int all_day_event = 0;
464 struct icaltimetype event_start, t;
465 icalproperty *attendee = NULL;
466 char attendee_string[SIZ];
469 char form_attendees[SIZ];
470 char organizer_string[SIZ];
472 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
474 if (supplied_vevent != NULL) {
475 vevent = supplied_vevent;
477 * If we're looking at a fully encapsulated VCALENDAR
478 * rather than a VEVENT component, attempt to use the first
479 * relevant VEVENT subcomponent. If there is none, the
480 * NULL returned by icalcomponent_get_first_component() will
481 * tell the next iteration of this function to create a
484 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
485 save_individual_event(
486 icalcomponent_get_first_component(
487 vevent, ICAL_VEVENT_COMPONENT),
494 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
495 created_new_vevent = 1;
498 if ( (havebstr("save_button"))
499 || (havebstr("check_button")) ) {
501 /** Replace values in the component with ones from the form */
503 while (prop = icalcomponent_get_first_property(vevent,
504 ICAL_SUMMARY_PROPERTY), prop != NULL) {
505 icalcomponent_remove_property(vevent, prop);
506 icalproperty_free(prop);
509 if (havebstr("summary")) {
511 icalcomponent_add_property(vevent,
512 icalproperty_new_summary(bstr("summary")));
514 icalcomponent_add_property(vevent,
515 icalproperty_new_summary("Untitled Event"));
518 while (prop = icalcomponent_get_first_property(vevent,
519 ICAL_LOCATION_PROPERTY), prop != NULL) {
520 icalcomponent_remove_property(vevent, prop);
521 icalproperty_free(prop);
523 if (havebstr("location")) {
524 icalcomponent_add_property(vevent,
525 icalproperty_new_location(bstr("location")));
527 while (prop = icalcomponent_get_first_property(vevent,
528 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
529 icalcomponent_remove_property(vevent, prop);
530 icalproperty_free(prop);
532 if (havebstr("description")) {
533 icalcomponent_add_property(vevent,
534 icalproperty_new_description(bstr("description")));
537 while (prop = icalcomponent_get_first_property(vevent,
538 ICAL_DTSTART_PROPERTY), prop != NULL) {
539 icalcomponent_remove_property(vevent, prop);
540 icalproperty_free(prop);
543 if (yesbstr("alldayevent")) {
551 icaltime_from_webform_dateonly(&event_start, "dtstart");
554 icaltime_from_webform(&event_start, "dtstart");
558 * The following odd-looking snippet of code looks like it
559 * takes some unnecessary steps. It is done this way because
560 * libical incorrectly turns an "all day event" into a normal
561 * event starting at midnight (i.e. it serializes as date/time
562 * instead of just date) unless icalvalue_new_date() is used.
563 * So we force it, if this is an all day event.
565 prop = icalproperty_new_dtstart(event_start);
567 icalproperty_set_value(prop, icalvalue_new_date(event_start));
570 if (prop) icalcomponent_add_property(vevent, prop);
571 else icalproperty_free(prop);
573 while (prop = icalcomponent_get_first_property(vevent,
574 ICAL_DTEND_PROPERTY), prop != NULL) {
575 icalcomponent_remove_property(vevent, prop);
576 icalproperty_free(prop);
578 while (prop = icalcomponent_get_first_property(vevent,
579 ICAL_DURATION_PROPERTY), prop != NULL) {
580 icalcomponent_remove_property(vevent, prop);
581 icalproperty_free(prop);
584 if (all_day_event == 0) {
585 icaltime_from_webform(&t, "dtend");
586 icalcomponent_add_property(vevent,
587 icalproperty_new_dtend(icaltime_normalize(t)
592 /** See if transparency is indicated */
593 if (havebstr("transp")) {
594 if (!strcasecmp(bstr("transp"), "opaque")) {
595 formtransp = ICAL_TRANSP_OPAQUE;
597 else if (!strcasecmp(bstr("transp"), "transparent")) {
598 formtransp = ICAL_TRANSP_TRANSPARENT;
601 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
603 icalcomponent_remove_property(vevent, prop);
604 icalproperty_free(prop);
607 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
610 /** Give this event a UID if it doesn't have one. */
611 if (icalcomponent_get_first_property(vevent,
612 ICAL_UID_PROPERTY) == NULL) {
614 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
617 /** Increment the sequence ID */
618 while (prop = icalcomponent_get_first_property(vevent,
619 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
620 i = icalproperty_get_sequence(prop);
621 if (i > sequence) sequence = i;
622 icalcomponent_remove_property(vevent, prop);
623 icalproperty_free(prop);
626 icalcomponent_add_property(vevent,
627 icalproperty_new_sequence(sequence)
631 * Set the organizer, only if one does not already exist *and*
632 * the form is supplying one
634 strcpy(buf, bstr("organizer"));
635 if ( (icalcomponent_get_first_property(vevent,
636 ICAL_ORGANIZER_PROPERTY) == NULL)
637 && (!IsEmptyStr(buf)) ) {
639 /** set new organizer */
640 sprintf(organizer_string, "MAILTO:%s", buf);
641 icalcomponent_add_property(vevent,
642 icalproperty_new_organizer(organizer_string)
648 * Add any new attendees listed in the web form
651 /* First, strip out the parenthesized partstats. */
652 strcpy(form_attendees, bstr("attendees"));
653 stripout(form_attendees, '(', ')');
655 /* Next, change any commas to newlines, because we want newline-separated attendees. */
656 j = strlen(form_attendees);
657 for (i=0; i<j; ++i) {
658 if (form_attendees[i] == ',') {
659 form_attendees[i] = '\n';
660 while (isspace(form_attendees[i+1])) {
661 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
667 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
668 extract_token(buf, form_attendees, i, '\n', sizeof buf);
670 if (!IsEmptyStr(buf)) {
671 sprintf(attendee_string, "MAILTO:%s", buf);
674 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
675 if (!strcasecmp(attendee_string,
676 icalproperty_get_attendee(attendee)))
682 icalcomponent_add_property(vevent,
683 icalproperty_new_attendee(attendee_string)
690 * Remove any attendees *not* listed in the web form
692 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
693 strcpy(attendee_string, icalproperty_get_attendee(attendee));
694 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
695 strcpy(attendee_string, &attendee_string[7]);
696 striplt(attendee_string);
698 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
699 extract_token(buf, form_attendees, i, '\n', sizeof buf);
701 if (!strcasecmp(buf, attendee_string)) ++foundit;
704 icalcomponent_remove_property(vevent, attendee);
705 icalproperty_free(attendee);
712 * Encapsulate event into full VCALENDAR component. Clone it first,
713 * for two reasons: one, it's easier to just free the whole thing
714 * when we're done instead of unbundling, but more importantly, we
715 * can't encapsulate something that may already be encapsulated
718 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
720 /* Set the method to PUBLISH */
721 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
723 /** If the user clicked 'Save' then save it to the server. */
724 if ( (encaps != NULL) && (havebstr("save_button")) ) {
725 serv_puts("ENT0 1|||4|||1|");
726 serv_getln(buf, sizeof buf);
728 serv_puts("Content-type: text/calendar");
730 serv_puts(icalcomponent_as_ical_string(encaps));
733 if ( (buf[0] == '8') || (buf[0] == '4') ) {
734 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
738 strcpy(WC->ImportantMessage, &buf[4]);
740 icalmemory_free_ring ();
741 icalcomponent_free(encaps);
744 /** Or, check attendee availability if the user asked for that. */
745 if ( (encaps != NULL) && (havebstr("check_button")) ) {
747 /* Call this function, which does the real work */
748 check_attendee_availability(encaps);
750 /** This displays the form again, with our annotations */
751 display_edit_individual_event(encaps, msgnum, from, unread);
753 icalcomponent_free(encaps);
759 * If the user clicked 'Delete' then delete it.
761 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
762 serv_printf("DELE %ld", lbstr("msgnum"));
763 serv_getln(buf, sizeof buf);
766 if (created_new_vevent) {
767 icalcomponent_free(vevent);
770 /* If this was a save or delete, go back to the calendar view. */
771 if (!havebstr("check_button")) {