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 wprintf("<table class=\"event_background\"><tr><td>\n");
86 /************************************************************
87 * Uncomment this to see the UID in calendar events for debugging
89 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
91 escputs((char *)icalproperty_get_comment(p));
94 wprintf("SEQUENCE == %d<br />\n", sequence);
95 *************************************************************/
97 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
98 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
100 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
102 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
104 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
106 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
108 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
112 char *tabnames[] = { // FIXME localize these when the code is finished
118 tabbed_dialog(3, tabnames);
122 /* Put it in a borderless table so it lines up nicely */
123 wprintf("<TABLE border=0 width=100%%>\n");
125 wprintf("<TR><TD><B>");
126 wprintf(_("Summary"));
127 wprintf("</B></TD><TD>\n"
128 "<INPUT TYPE=\"text\" NAME=\"summary\" "
129 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
130 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
132 escputs((char *)icalproperty_get_comment(p));
134 wprintf("\"></TD></TR>\n");
136 wprintf("<TR><TD><B>");
137 wprintf(_("Location"));
138 wprintf("</B></TD><TD>\n"
139 "<INPUT TYPE=\"text\" NAME=\"location\" "
140 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
141 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
143 escputs((char *)icalproperty_get_comment(p));
145 wprintf("\"></TD></TR>\n");
147 wprintf("<TR><TD><B>");
149 wprintf("</B></TD><TD>\n");
150 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
152 t_start = icalproperty_get_dtstart(p);
153 if (t_start.is_date) {
160 localtime_r(&now, &tm_now);
161 if (havebstr("year")) {
162 tm_now.tm_year = ibstr("year") - 1900;
163 tm_now.tm_mon = ibstr("month") - 1;
164 tm_now.tm_mday = ibstr("day");
166 if (havebstr("hour")) {
167 tm_now.tm_hour = ibstr("hour");
168 tm_now.tm_min = ibstr("minute");
177 t_start = icaltime_from_timet_with_zone(
179 ((yesbstr("alldayevent")) ? 1 : 0),
180 icaltimezone_get_utc_timezone()
185 display_icaltimetype_as_webform(&t_start, "dtstart");
187 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
188 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
190 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
194 wprintf("</TD></TR>\n");
197 * If this is an all-day-event, set the end time to be identical to
198 * the start time (the hour/minute/second will be set to midnight).
199 * Otherwise extract or create it.
201 wprintf("<TR><TD><B>");
203 wprintf("</B></TD><TD id=\"dtendcell\">\n");
204 if (t_start.is_date) {
208 p = icalcomponent_get_first_property(vevent,
209 ICAL_DTEND_PROPERTY);
211 t_end = icalproperty_get_dtend(p);
215 * If this is not an all-day event and there is no
216 * end time specified, make the default one hour
217 * from the start time.
222 t_end = icaltime_normalize(t_end);
223 /* t_end = icaltime_from_timet(now, 0); */
226 display_icaltimetype_as_webform(&t_end, "dtend");
227 wprintf("</TD></TR>\n");
229 wprintf("<TR><TD><B>");
231 wprintf("</B></TD><TD>\n"
232 "<TEXTAREA NAME=\"description\" wrap=soft "
233 "ROWS=5 COLS=80 WIDTH=80>\n"
235 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
237 escputs((char *)icalproperty_get_comment(p));
239 wprintf("</TEXTAREA></TD></TR>");
242 * For a new event, the user creating the event should be the
243 * organizer. Set this field accordingly.
245 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
247 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
248 icalcomponent_add_property(vevent,
249 icalproperty_new_organizer(organizer_string)
254 * Determine who is the organizer of this event.
255 * We need to determine "me" or "not me."
257 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
258 if (organizer != NULL) {
259 strcpy(organizer_string, icalproperty_get_organizer(organizer));
260 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
261 strcpy(organizer_string, &organizer_string[7]);
262 striplt(organizer_string);
263 serv_printf("ISME %s", organizer_string);
264 serv_getln(buf, sizeof buf);
271 wprintf("<TR><TD><B>");
272 wprintf(_("Organizer"));
273 wprintf("</B></TD><TD>");
274 escputs(organizer_string);
275 if (organizer_is_me) {
276 wprintf(" <FONT SIZE=-1><I>");
277 wprintf(_("(you are the organizer)"));
278 wprintf("</I></FONT>\n");
282 * Transmit the organizer as a hidden field. We don't want the user
283 * to be able to change it, but we do want it fed back to the server,
284 * especially if this is a new event and there is no organizer already
285 * in the calendar object.
287 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
288 escputs(organizer_string);
291 wprintf("</TD></TR>\n");
294 wprintf("<TR><TD><B>");
295 wprintf(_("Show time as:"));
296 wprintf("</B></TD><TD>");
298 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
300 /** No transparency found. Default to opaque (busy). */
301 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
303 icalcomponent_add_property(vevent, p);
307 v = icalproperty_get_value(p);
313 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
314 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
318 wprintf(" ");
320 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
321 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
326 wprintf("</TD></TR>\n");
329 wprintf("<TR><TD><B>");
330 wprintf(_("Attendees"));
333 wprintf(_("(One per line)"));
334 wprintf("</font>\n");
336 /** Pop open an address book -- begin **/
338 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
340 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
345 /** Pop open an address book -- end **/
348 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
349 "ROWS=3 COLS=80 WIDTH=80>\n",
350 (organizer_is_me ? "" : "DISABLED ")
353 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
355 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
356 strcpy(attendee_string, icalproperty_get_attendee(attendee));
357 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
359 /** screen name or email address */
360 strcpy(attendee_string, &attendee_string[7]);
361 striplt(attendee_string);
362 if (i++) wprintf("\n");
363 escputs(attendee_string);
366 /** participant status */
367 partstat_as_string(buf, attendee);
371 wprintf("</TEXTAREA></TD></TR>\n");
373 /** Done with properties. */
374 wprintf("</TABLE>\n<CENTER>"
375 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
377 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
379 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
382 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
386 _("Check attendee availability"),
390 wprintf("</FORM>\n");
392 wprintf("</td></tr></table>");
398 /* Attendees tab (need to move things here) */
404 icalproperty *rrule = NULL;
405 struct icalrecurrencetype recur;
407 rrule = icalcomponent_get_first_property(vevent, ICAL_RRULE_PROPERTY);
409 recur = icalproperty_get_rrule(rrule);
410 wprintf("<tt>%s</tt><br />\n", icalrecurrencetype_as_string(&recur));
418 wprintf("<script type=\"text/javascript\">"
422 address_book_popup();
425 if (created_new_vevent) {
426 icalcomponent_free(vevent);
431 * \brief Save an edited event
432 * \param supplied_vevent the event to save
433 * \param msgnum the index on the citserver
435 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread) {
438 icalcomponent *vevent, *encaps;
439 int created_new_vevent = 0;
440 int all_day_event = 0;
441 struct icaltimetype event_start, t;
442 icalproperty *attendee = NULL;
443 char attendee_string[SIZ];
446 char form_attendees[SIZ];
447 char organizer_string[SIZ];
449 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
451 if (supplied_vevent != NULL) {
452 vevent = supplied_vevent;
454 * If we're looking at a fully encapsulated VCALENDAR
455 * rather than a VEVENT component, attempt to use the first
456 * relevant VEVENT subcomponent. If there is none, the
457 * NULL returned by icalcomponent_get_first_component() will
458 * tell the next iteration of this function to create a
461 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
462 save_individual_event(
463 icalcomponent_get_first_component(
464 vevent, ICAL_VEVENT_COMPONENT),
471 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
472 created_new_vevent = 1;
475 if ( (havebstr("save_button"))
476 || (havebstr("check_button")) ) {
478 /** Replace values in the component with ones from the form */
480 while (prop = icalcomponent_get_first_property(vevent,
481 ICAL_SUMMARY_PROPERTY), prop != NULL) {
482 icalcomponent_remove_property(vevent, prop);
483 icalproperty_free(prop);
486 if (havebstr("summary")) {
488 icalcomponent_add_property(vevent,
489 icalproperty_new_summary(bstr("summary")));
491 icalcomponent_add_property(vevent,
492 icalproperty_new_summary("Untitled Event"));
495 while (prop = icalcomponent_get_first_property(vevent,
496 ICAL_LOCATION_PROPERTY), prop != NULL) {
497 icalcomponent_remove_property(vevent, prop);
498 icalproperty_free(prop);
500 if (havebstr("location")) {
501 icalcomponent_add_property(vevent,
502 icalproperty_new_location(bstr("location")));
504 while (prop = icalcomponent_get_first_property(vevent,
505 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
506 icalcomponent_remove_property(vevent, prop);
507 icalproperty_free(prop);
509 if (havebstr("description")) {
510 icalcomponent_add_property(vevent,
511 icalproperty_new_description(bstr("description")));
514 while (prop = icalcomponent_get_first_property(vevent,
515 ICAL_DTSTART_PROPERTY), prop != NULL) {
516 icalcomponent_remove_property(vevent, prop);
517 icalproperty_free(prop);
520 if (yesbstr("alldayevent")) {
528 icaltime_from_webform_dateonly(&event_start, "dtstart");
531 icaltime_from_webform(&event_start, "dtstart");
535 * The following odd-looking snippet of code looks like it
536 * takes some unnecessary steps. It is done this way because
537 * libical incorrectly turns an "all day event" into a normal
538 * event starting at midnight (i.e. it serializes as date/time
539 * instead of just date) unless icalvalue_new_date() is used.
540 * So we force it, if this is an all day event.
542 prop = icalproperty_new_dtstart(event_start);
544 icalproperty_set_value(prop, icalvalue_new_date(event_start));
547 if (prop) icalcomponent_add_property(vevent, prop);
548 else icalproperty_free(prop);
550 while (prop = icalcomponent_get_first_property(vevent,
551 ICAL_DTEND_PROPERTY), prop != NULL) {
552 icalcomponent_remove_property(vevent, prop);
553 icalproperty_free(prop);
555 while (prop = icalcomponent_get_first_property(vevent,
556 ICAL_DURATION_PROPERTY), prop != NULL) {
557 icalcomponent_remove_property(vevent, prop);
558 icalproperty_free(prop);
561 if (all_day_event == 0) {
562 icaltime_from_webform(&t, "dtend");
563 icalcomponent_add_property(vevent,
564 icalproperty_new_dtend(icaltime_normalize(t)
569 /** See if transparency is indicated */
570 if (havebstr("transp")) {
571 if (!strcasecmp(bstr("transp"), "opaque")) {
572 formtransp = ICAL_TRANSP_OPAQUE;
574 else if (!strcasecmp(bstr("transp"), "transparent")) {
575 formtransp = ICAL_TRANSP_TRANSPARENT;
578 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
580 icalcomponent_remove_property(vevent, prop);
581 icalproperty_free(prop);
584 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
587 /** Give this event a UID if it doesn't have one. */
588 if (icalcomponent_get_first_property(vevent,
589 ICAL_UID_PROPERTY) == NULL) {
591 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
594 /** Increment the sequence ID */
595 while (prop = icalcomponent_get_first_property(vevent,
596 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
597 i = icalproperty_get_sequence(prop);
598 if (i > sequence) sequence = i;
599 icalcomponent_remove_property(vevent, prop);
600 icalproperty_free(prop);
603 icalcomponent_add_property(vevent,
604 icalproperty_new_sequence(sequence)
608 * Set the organizer, only if one does not already exist *and*
609 * the form is supplying one
611 strcpy(buf, bstr("organizer"));
612 if ( (icalcomponent_get_first_property(vevent,
613 ICAL_ORGANIZER_PROPERTY) == NULL)
614 && (!IsEmptyStr(buf)) ) {
616 /** set new organizer */
617 sprintf(organizer_string, "MAILTO:%s", buf);
618 icalcomponent_add_property(vevent,
619 icalproperty_new_organizer(organizer_string)
625 * Add any new attendees listed in the web form
628 /* First, strip out the parenthesized partstats. */
629 strcpy(form_attendees, bstr("attendees"));
630 stripout(form_attendees, '(', ')');
632 /* Next, change any commas to newlines, because we want newline-separated attendees. */
633 j = strlen(form_attendees);
634 for (i=0; i<j; ++i) {
635 if (form_attendees[i] == ',') {
636 form_attendees[i] = '\n';
637 while (isspace(form_attendees[i+1])) {
638 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
644 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
645 extract_token(buf, form_attendees, i, '\n', sizeof buf);
647 if (!IsEmptyStr(buf)) {
648 sprintf(attendee_string, "MAILTO:%s", buf);
651 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
652 if (!strcasecmp(attendee_string,
653 icalproperty_get_attendee(attendee)))
659 icalcomponent_add_property(vevent,
660 icalproperty_new_attendee(attendee_string)
667 * Remove any attendees *not* listed in the web form
669 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
670 strcpy(attendee_string, icalproperty_get_attendee(attendee));
671 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
672 strcpy(attendee_string, &attendee_string[7]);
673 striplt(attendee_string);
675 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
676 extract_token(buf, form_attendees, i, '\n', sizeof buf);
678 if (!strcasecmp(buf, attendee_string)) ++foundit;
681 icalcomponent_remove_property(vevent, attendee);
682 icalproperty_free(attendee);
689 * Encapsulate event into full VCALENDAR component. Clone it first,
690 * for two reasons: one, it's easier to just free the whole thing
691 * when we're done instead of unbundling, but more importantly, we
692 * can't encapsulate something that may already be encapsulated
695 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
697 /* Set the method to PUBLISH */
698 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
700 /** If the user clicked 'Save' then save it to the server. */
701 if ( (encaps != NULL) && (havebstr("save_button")) ) {
702 serv_puts("ENT0 1|||4|||1|");
703 serv_getln(buf, sizeof buf);
705 serv_puts("Content-type: text/calendar");
707 serv_puts(icalcomponent_as_ical_string(encaps));
710 if ( (buf[0] == '8') || (buf[0] == '4') ) {
711 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
715 strcpy(WC->ImportantMessage, &buf[4]);
717 icalmemory_free_ring ();
718 icalcomponent_free(encaps);
721 /** Or, check attendee availability if the user asked for that. */
722 if ( (encaps != NULL) && (havebstr("check_button")) ) {
724 /* Call this function, which does the real work */
725 check_attendee_availability(encaps);
727 /** This displays the form again, with our annotations */
728 display_edit_individual_event(encaps, msgnum, from, unread);
730 icalcomponent_free(encaps);
736 * If the user clicked 'Delete' then delete it.
738 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
739 serv_printf("DELE %ld", lbstr("msgnum"));
740 serv_getln(buf, sizeof buf);
743 if (created_new_vevent) {
744 icalcomponent_free(vevent);
747 /** If this was a save or delete, go back to the calendar view. */
748 if (!havebstr("check_button")) {