4 * Editing calendar events.
12 * \brief Display an event by itself (for editing)
13 * \param supplied_vevent the event to edit
14 * \param 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\">"
82 "<table class=\"event_background\"><tr><td>\n");
84 /************************************************************
85 * Uncomment this to see the UID in calendar events for debugging
87 p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
89 escputs((char *)icalproperty_get_comment(p));
92 wprintf("SEQUENCE == %d<br />\n", sequence);
93 *************************************************************/
95 wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
96 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
98 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
100 wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
102 wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
104 wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
106 wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
109 /** Put it in a borderless table so it lines up nicely */
110 wprintf("<TABLE border=0 width=100%%>\n");
112 wprintf("<TR><TD><B>");
113 wprintf(_("Summary"));
114 wprintf("</B></TD><TD>\n"
115 "<INPUT TYPE=\"text\" NAME=\"summary\" "
116 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
117 p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
119 escputs((char *)icalproperty_get_comment(p));
121 wprintf("\"></TD></TR>\n");
123 wprintf("<TR><TD><B>");
124 wprintf(_("Location"));
125 wprintf("</B></TD><TD>\n"
126 "<INPUT TYPE=\"text\" NAME=\"location\" "
127 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
128 p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
130 escputs((char *)icalproperty_get_comment(p));
132 wprintf("\"></TD></TR>\n");
134 wprintf("<TR><TD><B>");
136 wprintf("</B></TD><TD>\n");
137 p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
139 t_start = icalproperty_get_dtstart(p);
140 if (t_start.is_date) {
147 localtime_r(&now, &tm_now);
148 if (havebstr("year")) {
149 tm_now.tm_year = ibstr("year") - 1900;
150 tm_now.tm_mon = ibstr("month") - 1;
151 tm_now.tm_mday = ibstr("day");
153 if (havebstr("hour")) {
154 tm_now.tm_hour = ibstr("hour");
155 tm_now.tm_min = ibstr("minute");
164 t_start = icaltime_from_timet_with_zone(
166 ((yesbstr("alldayevent")) ? 1 : 0),
167 icaltimezone_get_utc_timezone()
172 display_icaltimetype_as_webform(&t_start, "dtstart");
174 wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
175 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
177 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
181 wprintf("</TD></TR>\n");
184 * If this is an all-day-event, set the end time to be identical to
185 * the start time (the hour/minute/second will be set to midnight).
186 * Otherwise extract or create it.
188 wprintf("<TR><TD><B>");
190 wprintf("</B></TD><TD id=\"dtendcell\">\n");
191 if (t_start.is_date) {
195 p = icalcomponent_get_first_property(vevent,
196 ICAL_DTEND_PROPERTY);
198 t_end = icalproperty_get_dtend(p);
202 * If this is not an all-day event and there is no
203 * end time specified, make the default one hour
204 * from the start time.
209 t_end = icaltime_normalize(t_end);
210 /* t_end = icaltime_from_timet(now, 0); */
213 display_icaltimetype_as_webform(&t_end, "dtend");
214 wprintf("</TD></TR>\n");
216 wprintf("<TR><TD><B>");
218 wprintf("</B></TD><TD>\n"
219 "<TEXTAREA NAME=\"description\" wrap=soft "
220 "ROWS=5 COLS=80 WIDTH=80>\n"
222 p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
224 escputs((char *)icalproperty_get_comment(p));
226 wprintf("</TEXTAREA></TD></TR>");
229 * For a new event, the user creating the event should be the
230 * organizer. Set this field accordingly.
232 if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
234 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
235 icalcomponent_add_property(vevent,
236 icalproperty_new_organizer(organizer_string)
241 * Determine who is the organizer of this event.
242 * We need to determine "me" or "not me."
244 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
245 if (organizer != NULL) {
246 strcpy(organizer_string, icalproperty_get_organizer(organizer));
247 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
248 strcpy(organizer_string, &organizer_string[7]);
249 striplt(organizer_string);
250 serv_printf("ISME %s", organizer_string);
251 serv_getln(buf, sizeof buf);
258 wprintf("<TR><TD><B>");
259 wprintf(_("Organizer"));
260 wprintf("</B></TD><TD>");
261 escputs(organizer_string);
262 if (organizer_is_me) {
263 wprintf(" <FONT SIZE=-1><I>");
264 wprintf(_("(you are the organizer)"));
265 wprintf("</I></FONT>\n");
269 * Transmit the organizer as a hidden field. We don't want the user
270 * to be able to change it, but we do want it fed back to the server,
271 * especially if this is a new event and there is no organizer already
272 * in the calendar object.
274 wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
275 escputs(organizer_string);
278 wprintf("</TD></TR>\n");
281 wprintf("<TR><TD><B>");
282 wprintf(_("Show time as:"));
283 wprintf("</B></TD><TD>");
285 p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
287 /** No transparency found. Default to opaque (busy). */
288 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
290 icalcomponent_add_property(vevent, p);
294 v = icalproperty_get_value(p);
300 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
301 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
305 wprintf(" ");
307 wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
308 if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
313 wprintf("</TD></TR>\n");
316 wprintf("<TR><TD><B>");
317 wprintf(_("Attendees"));
320 wprintf(_("(One per line)"));
321 wprintf("</font>\n");
323 /** Pop open an address book -- begin **/
325 " <a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
327 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
332 /** Pop open an address book -- end **/
335 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
336 "ROWS=3 COLS=80 WIDTH=80>\n",
337 (organizer_is_me ? "" : "DISABLED ")
340 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
342 attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
343 strcpy(attendee_string, icalproperty_get_attendee(attendee));
344 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
346 /** screen name or email address */
347 strcpy(attendee_string, &attendee_string[7]);
348 striplt(attendee_string);
349 if (i++) wprintf("\n");
350 escputs(attendee_string);
353 /** participant status */
354 partstat_as_string(buf, attendee);
358 wprintf("</TEXTAREA></TD></TR>\n");
360 /** Done with properties. */
361 wprintf("</TABLE>\n<CENTER>"
362 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
364 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
366 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
369 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
373 _("Check attendee availability"),
377 wprintf("</FORM>\n");
379 wprintf("</td></tr></table></div>\n");
380 wprintf("<script type=\"text/javascript\">"
385 address_book_popup();
388 if (created_new_vevent) {
389 icalcomponent_free(vevent);
394 * \brief Save an edited event
395 * \param supplied_vevent the event to save
396 * \param msgnum the index on the citserver
398 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread) {
401 icalcomponent *vevent, *encaps;
402 int created_new_vevent = 0;
403 int all_day_event = 0;
404 struct icaltimetype event_start, t;
405 icalproperty *attendee = NULL;
406 char attendee_string[SIZ];
409 char form_attendees[SIZ];
410 char organizer_string[SIZ];
412 enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
414 if (supplied_vevent != NULL) {
415 vevent = supplied_vevent;
417 * If we're looking at a fully encapsulated VCALENDAR
418 * rather than a VEVENT component, attempt to use the first
419 * relevant VEVENT subcomponent. If there is none, the
420 * NULL returned by icalcomponent_get_first_component() will
421 * tell the next iteration of this function to create a
424 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
425 save_individual_event(
426 icalcomponent_get_first_component(
427 vevent, ICAL_VEVENT_COMPONENT),
434 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
435 created_new_vevent = 1;
438 if ( (havebstr("save_button"))
439 || (havebstr("check_button")) ) {
441 /** Replace values in the component with ones from the form */
443 while (prop = icalcomponent_get_first_property(vevent,
444 ICAL_SUMMARY_PROPERTY), prop != NULL) {
445 icalcomponent_remove_property(vevent, prop);
446 icalproperty_free(prop);
449 if (havebstr("summary")) {
451 icalcomponent_add_property(vevent,
452 icalproperty_new_summary(bstr("summary")));
454 icalcomponent_add_property(vevent,
455 icalproperty_new_summary("Untitled Event"));
458 while (prop = icalcomponent_get_first_property(vevent,
459 ICAL_LOCATION_PROPERTY), prop != NULL) {
460 icalcomponent_remove_property(vevent, prop);
461 icalproperty_free(prop);
463 if (havebstr("location")) {
464 icalcomponent_add_property(vevent,
465 icalproperty_new_location(bstr("location")));
467 while (prop = icalcomponent_get_first_property(vevent,
468 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
469 icalcomponent_remove_property(vevent, prop);
470 icalproperty_free(prop);
472 if (havebstr("description")) {
473 icalcomponent_add_property(vevent,
474 icalproperty_new_description(bstr("description")));
477 while (prop = icalcomponent_get_first_property(vevent,
478 ICAL_DTSTART_PROPERTY), prop != NULL) {
479 icalcomponent_remove_property(vevent, prop);
480 icalproperty_free(prop);
483 if (yesbstr("alldayevent")) {
491 icaltime_from_webform_dateonly(&event_start, "dtstart");
494 icaltime_from_webform(&event_start, "dtstart");
498 * The following odd-looking snippet of code looks like it
499 * takes some unnecessary steps. It is done this way because
500 * libical incorrectly turns an "all day event" into a normal
501 * event starting at midnight (i.e. it serializes as date/time
502 * instead of just date) unless icalvalue_new_date() is used.
503 * So we force it, if this is an all day event.
505 prop = icalproperty_new_dtstart(event_start);
507 icalproperty_set_value(prop, icalvalue_new_date(event_start));
510 if (prop) icalcomponent_add_property(vevent, prop);
511 else icalproperty_free(prop);
513 while (prop = icalcomponent_get_first_property(vevent,
514 ICAL_DTEND_PROPERTY), prop != NULL) {
515 icalcomponent_remove_property(vevent, prop);
516 icalproperty_free(prop);
518 while (prop = icalcomponent_get_first_property(vevent,
519 ICAL_DURATION_PROPERTY), prop != NULL) {
520 icalcomponent_remove_property(vevent, prop);
521 icalproperty_free(prop);
524 if (all_day_event == 0) {
525 icaltime_from_webform(&t, "dtend");
526 icalcomponent_add_property(vevent,
527 icalproperty_new_dtend(icaltime_normalize(t)
532 /** See if transparency is indicated */
533 if (havebstr("transp")) {
534 if (!strcasecmp(bstr("transp"), "opaque")) {
535 formtransp = ICAL_TRANSP_OPAQUE;
537 else if (!strcasecmp(bstr("transp"), "transparent")) {
538 formtransp = ICAL_TRANSP_TRANSPARENT;
541 while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
543 icalcomponent_remove_property(vevent, prop);
544 icalproperty_free(prop);
547 icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
550 /** Give this event a UID if it doesn't have one. */
551 if (icalcomponent_get_first_property(vevent,
552 ICAL_UID_PROPERTY) == NULL) {
554 icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
557 /** Increment the sequence ID */
558 while (prop = icalcomponent_get_first_property(vevent,
559 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
560 i = icalproperty_get_sequence(prop);
561 if (i > sequence) sequence = i;
562 icalcomponent_remove_property(vevent, prop);
563 icalproperty_free(prop);
566 icalcomponent_add_property(vevent,
567 icalproperty_new_sequence(sequence)
571 * Set the organizer, only if one does not already exist *and*
572 * the form is supplying one
574 strcpy(buf, bstr("organizer"));
575 if ( (icalcomponent_get_first_property(vevent,
576 ICAL_ORGANIZER_PROPERTY) == NULL)
577 && (!IsEmptyStr(buf)) ) {
579 /** set new organizer */
580 sprintf(organizer_string, "MAILTO:%s", buf);
581 icalcomponent_add_property(vevent,
582 icalproperty_new_organizer(organizer_string)
588 * Add any new attendees listed in the web form
591 /* First, strip out the parenthesized partstats. */
592 strcpy(form_attendees, bstr("attendees"));
593 stripout(form_attendees, '(', ')');
595 /* Next, change any commas to newlines, because we want newline-separated attendees. */
596 j = strlen(form_attendees);
597 for (i=0; i<j; ++i) {
598 if (form_attendees[i] == ',') {
599 form_attendees[i] = '\n';
600 while (isspace(form_attendees[i+1])) {
601 strcpy(&form_attendees[i+1], &form_attendees[i+2]);
607 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
608 extract_token(buf, form_attendees, i, '\n', sizeof buf);
610 if (!IsEmptyStr(buf)) {
611 sprintf(attendee_string, "MAILTO:%s", buf);
614 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
615 if (!strcasecmp(attendee_string,
616 icalproperty_get_attendee(attendee)))
622 icalcomponent_add_property(vevent,
623 icalproperty_new_attendee(attendee_string)
630 * Remove any attendees *not* listed in the web form
632 STARTOVER: for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
633 strcpy(attendee_string, icalproperty_get_attendee(attendee));
634 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
635 strcpy(attendee_string, &attendee_string[7]);
636 striplt(attendee_string);
638 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
639 extract_token(buf, form_attendees, i, '\n', sizeof buf);
641 if (!strcasecmp(buf, attendee_string)) ++foundit;
644 icalcomponent_remove_property(vevent, attendee);
645 icalproperty_free(attendee);
652 * Encapsulate event into full VCALENDAR component. Clone it first,
653 * for two reasons: one, it's easier to just free the whole thing
654 * when we're done instead of unbundling, but more importantly, we
655 * can't encapsulate something that may already be encapsulated
658 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
660 /* Set the method to PUBLISH */
661 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
663 /** If the user clicked 'Save' then save it to the server. */
664 if ( (encaps != NULL) && (havebstr("save_button")) ) {
665 serv_puts("ENT0 1|||4|||1|");
666 serv_getln(buf, sizeof buf);
668 serv_puts("Content-type: text/calendar");
670 serv_puts(icalcomponent_as_ical_string(encaps));
673 if ( (buf[0] == '8') || (buf[0] == '4') ) {
674 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
678 strcpy(WC->ImportantMessage, &buf[4]);
680 icalmemory_free_ring ();
681 icalcomponent_free(encaps);
684 /** Or, check attendee availability if the user asked for that. */
685 if ( (encaps != NULL) && (havebstr("check_button")) ) {
687 /** Call this function, which does the real work */
688 check_attendee_availability(encaps);
690 /** This displays the form again, with our annotations */
691 display_edit_individual_event(encaps, msgnum, from, unread);
693 icalcomponent_free(encaps);
699 * If the user clicked 'Delete' then delete it.
701 if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
702 serv_printf("DELE %ld", lbstr("msgnum"));
703 serv_getln(buf, sizeof buf);
706 if (created_new_vevent) {
707 icalcomponent_free(vevent);
710 /** If this was a save or delete, go back to the calendar view. */
711 if (!havebstr("check_button")) {