]> code.citadel.org Git - citadel.git/blobdiff - webcit/event.c
* Calendar objects UID now generated by generate_uuid() which creates
[citadel.git] / webcit / event.c
index dc89fd2d5cec4c6dc7223946f460bdd668e591eb..b9ea1fea389e4a7f37e63bbd15cc6489dbbaad79 100644 (file)
@@ -32,8 +32,6 @@
 
 /*
  * Display an event by itself (for editing)
- *
- * ok
  */
 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        icalcomponent *vevent;
@@ -48,19 +46,19 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        icalproperty *attendee = NULL;
        char attendee_string[SIZ];
        char buf[SIZ];
-       int i;
        int organizer_is_me = 0;
+       int i;
        int sequence = 0;
 
-       now = time(NULL) % 60;  /* mod 60 to force :00 seconds */
+       now = time(NULL) % 60;          /* mod 60 to force :00 seconds */
        strcpy(organizer_string, "");
        strcpy(attendee_string, "");
 
        if (supplied_vevent != NULL) {
                vevent = supplied_vevent;
                /* If we're looking at a fully encapsulated VCALENDAR
-                * rather than a VTODO component, attempt to use the first
-                * relevant VTODO subcomponent.  If there is none, the
+                * rather than a VEVENT component, attempt to use the first
+                * relevant VEVENT subcomponent.  If there is none, the
                 * NULL returned by icalcomponent_get_first_component() will
                 * tell the next iteration of this function to create a
                 * new one.
@@ -68,7 +66,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
                        display_edit_individual_event(
                                icalcomponent_get_first_component(
-                                       vevent, ICAL_VTODO_COMPONENT
+                                       vevent, ICAL_VEVENT_COMPONENT
                                ), msgnum
                        );
                        return;
@@ -87,12 +85,9 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
 
        /* Begin output */
        output_headers(3);
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
-               "<IMG ALIGN=CENTER SRC=\"/static/vcalendar.gif\">"
-               "<FONT SIZE=+1 COLOR=\"FFFFFF\""
-               "<B>Edit event</B>"
-               "</FONT></TD></TR></TABLE><BR>\n"
-       );
+       do_template("beginbox_nt");
+       wprintf("<h3>&nbsp;<IMG ALIGN=CENTER SRC=\"/static/vcalendar.gif\">"
+               "&nbsp;Add or edit an event</h3>\n");
 
        /************************************************************
         * Uncomment this to see the UID in calendar events for debugging
@@ -150,7 +145,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                }
        }
        else {
-               memcpy(&tm_now, localtime(&now), sizeof(struct tm));
+               localtime_r(&now, &tm_now);
                tm_now.tm_year = atoi(bstr("year")) - 1900;
                tm_now.tm_mon = atoi(bstr("month")) - 1;
                tm_now.tm_mday = atoi(bstr("day"));
@@ -168,7 +163,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                t_start = icaltime_from_timet_with_zone(
                        mktime(&tm_now),
                        ((!strcasecmp(bstr("alldayevent"), "yes")) ? 1 : 0),
-                       icaltimezone_get_utc_timezone
+                       icaltimezone_get_utc_timezone()
                );
                t_start.is_utc = 1;
 
@@ -176,33 +171,33 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        display_icaltimetype_as_webform(&t_start, "dtstart");
 
        wprintf("<INPUT TYPE=\"checkbox\" NAME=\"alldayevent\" "
-               "VALUE=\"yes\" onClick=\"
-
-                       if (this.checked) {
-                               this.form.dtstart_hour.value='0';
-                               this.form.dtstart_hour.disabled = true;
-                               this.form.dtstart_minute.value='0';
-                               this.form.dtstart_minute.disabled = true;
-                               this.form.dtend_hour.value='0';
-                               this.form.dtend_hour.disabled = true;
-                               this.form.dtend_minute.value='0';
-                               this.form.dtend_minute.disabled = true;
-                               this.form.dtend_month.disabled = true;
-                               this.form.dtend_day.disabled = true;
-                               this.form.dtend_year.disabled = true;
-                       }
-                       else {
-                               this.form.dtstart_hour.disabled = false;
-                               this.form.dtstart_minute.disabled = false;
-                               this.form.dtend_hour.disabled = false;
-                               this.form.dtend_minute.disabled = false;
-                               this.form.dtend_month.disabled = false;
-                               this.form.dtend_day.disabled = false;
-                               this.form.dtend_year.disabled = false;
-                       }
-
-
-               \" %s >All day event",
+               "VALUE=\"yes\" onClick=\""
+""
+"                      if (this.checked) { "
+"                              this.form.dtstart_hour.value='0'; "
+"                              this.form.dtstart_hour.disabled = true; "
+"                              this.form.dtstart_minute.value='0'; "
+"                              this.form.dtstart_minute.disabled = true; "
+"                              this.form.dtend_hour.value='0'; "
+"                              this.form.dtend_hour.disabled = true; "
+"                              this.form.dtend_minute.value='0'; "
+"                              this.form.dtend_minute.disabled = true; "
+"                              this.form.dtend_month.disabled = true; "
+"                              this.form.dtend_day.disabled = true; "
+"                              this.form.dtend_year.disabled = true; "
+"                      } "
+"                      else { "
+"                              this.form.dtstart_hour.disabled = false; "
+"                              this.form.dtstart_minute.disabled = false; "
+"                              this.form.dtend_hour.disabled = false; "
+"                              this.form.dtend_minute.disabled = false; "
+"                              this.form.dtend_month.disabled = false; "
+"                              this.form.dtend_day.disabled = false; "
+"                              this.form.dtend_year.disabled = false; "
+"                      } "
+" "
+" "
+"              \" %s >All day event",
                (t_start.is_date ? "CHECKED" : "" )
        );
 
@@ -239,7 +234,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
 
        wprintf("<TR><TD><B>Notes</B></TD><TD>\n"
                "<TEXTAREA NAME=\"description\" wrap=soft "
-               "ROWS=10 COLS=80 WIDTH=80>\n"
+               "ROWS=5 COLS=80 WIDTH=80>\n"
        );
        p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
        if (p != NULL) {
@@ -329,21 +324,23 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
 
        /* Attendees */
        wprintf("<TR><TD><B>Attendees</B><BR>"
-               "<FONT SIZE=-2>(Separate multiple attendees with commas)"
+               "<FONT SIZE=-2>(One per line)"
                "</FONT></TD><TD>"
                "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
                "ROWS=3 COLS=80 WIDTH=80>\n",
                (organizer_is_me ? "" : "DISABLED ")
        );
        i = 0;
-       for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
+       for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
+           attendee != NULL;
+           attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
                strcpy(attendee_string, icalproperty_get_attendee(attendee));
                if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
 
                        /* screen name or email address */
                        strcpy(attendee_string, &attendee_string[7]);
                        striplt(attendee_string);
-                       if (i++) wprintf("");
+                       if (i++) wprintf("\n");
                        escputs(attendee_string);
                        wprintf(" ");
 
@@ -360,41 +357,44 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                "&nbsp;&nbsp;"
                "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
                "&nbsp;&nbsp;"
+               "<INPUT TYPE=\"submit\" NAME=\"sc\" "
+                               "VALUE=\"Check attendee availability\">\n"
+               "&nbsp;&nbsp;"
                "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
                "</CENTER>\n"
        );
 
        wprintf("</FORM>\n");
        
-       wprintf("<SCRIPT language=\"javascript\">
-               <!--
-
-                       if (document.EventForm.alldayevent.checked) {
-                               document.EventForm.dtstart_hour.value='0';
-                               document.EventForm.dtstart_hour.disabled = true;
-                               document.EventForm.dtstart_minute.value='0';
-                               document.EventForm.dtstart_minute.disabled = true;
-                               document.EventForm.dtend_hour.value='0';
-                               document.EventForm.dtend_hour.disabled = true;
-                               document.EventForm.dtend_minute.value='0';
-                               document.EventForm.dtend_minute.disabled = true;
-                               document.EventForm.dtend_month.disabled = true;
-                               document.EventForm.dtend_day.disabled = true;
-                               document.EventForm.dtend_year.disabled = true;
-                       }
-                       else {
-                               document.EventForm.dtstart_hour.disabled = false;
-                               document.EventForm.dtstart_minute.disabled = false;
-                               document.EventForm.dtend_hour.disabled = false;
-                               document.EventForm.dtend_minute.disabled = false;
-                               document.EventForm.dtend_month.disabled = false;
-                               document.EventForm.dtend_day.disabled = false;
-                               document.EventForm.dtend_year.disabled = false;
-                       }
-               //-->
-               </SCRIPT>
-       ");
+       wprintf("<SCRIPT language=\"javascript\">"
+               "<!--"
+                       "if (document.EventForm.alldayevent.checked) {"
+                               "document.EventForm.dtstart_hour.value='0';"
+                               "document.EventForm.dtstart_hour.disabled = true;"
+                               "document.EventForm.dtstart_minute.value='0';"
+                               "document.EventForm.dtstart_minute.disabled = true;"
+                               "document.EventForm.dtend_hour.value='0';"
+                               "document.EventForm.dtend_hour.disabled = true;"
+                               "document.EventForm.dtend_minute.value='0';"
+                               "document.EventForm.dtend_minute.disabled = true;"
+                               "document.EventForm.dtend_month.disabled = true;"
+                               "document.EventForm.dtend_day.disabled = true;"
+                               "document.EventForm.dtend_year.disabled = true;"
+                       "}"
+                       "else {"
+                               "document.EventForm.dtstart_hour.disabled = false;"
+                               "document.EventForm.dtstart_minute.disabled = false;"
+                               "document.EventForm.dtend_hour.disabled = false;"
+                               "document.EventForm.dtend_minute.disabled = false;"
+                               "document.EventForm.dtend_month.disabled = false;"
+                               "document.EventForm.dtend_day.disabled = false;"
+                               "document.EventForm.dtend_year.disabled = false;"
+                       "}"
+               "//-->"
+               "</SCRIPT>\n"
+       );
 
+       do_template("endbox");
        wDumpContent(1);
 
        if (created_new_vevent) {
@@ -425,8 +425,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        if (supplied_vevent != NULL) {
                vevent = supplied_vevent;
                /* If we're looking at a fully encapsulated VCALENDAR
-                * rather than a VTODO component, attempt to use the first
-                * relevant VTODO subcomponent.  If there is none, the
+                * rather than a VEVENT component, attempt to use the first
+                * relevant VEVENT subcomponent.  If there is none, the
                 * NULL returned by icalcomponent_get_first_component() will
                 * tell the next iteration of this function to create a
                 * new one.
@@ -434,7 +434,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
                        save_individual_event(
                                icalcomponent_get_first_component(
-                                       vevent, ICAL_VTODO_COMPONENT
+                                       vevent, ICAL_VEVENT_COMPONENT
                                ), msgnum
                        );
                        return;
@@ -445,7 +445,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                created_new_vevent = 1;
        }
 
-       if (!strcasecmp(bstr("sc"), "Save")) {
+       if ( (!strcasecmp(bstr("sc"), "Save"))
+          || (!strcasecmp(bstr("sc"), "Check attendee availability")) ) {
 
                /* Replace values in the component with ones from the form */
 
@@ -555,7 +556,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                lprintf(9, "Give this event a UID if it doesn't have one.\n");
                if (icalcomponent_get_first_property(vevent,
                   ICAL_UID_PROPERTY) == NULL) {
-                       generate_new_uid(buf);
+                       generate_uuid(buf);
                        icalcomponent_add_property(vevent,
                                icalproperty_new_uid(buf)
                        );
@@ -604,8 +605,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                stripout(form_attendees, '(', ')');
 
                /* Now iterate! */
-               for (i=0; i<num_tokens(form_attendees, ','); ++i) {
-                       extract_token(buf, form_attendees, i, ',');
+               for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
+                       extract_token(buf, form_attendees, i, '\n');
                        striplt(buf);
                        if (strlen(buf) > 0) {
                                lprintf(9, "Attendee: <%s>\n", buf);
@@ -637,8 +638,8 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
                                strcpy(attendee_string, &attendee_string[7]);
                                striplt(attendee_string);
                                foundit = 0;
-                               for (i=0; i<num_tokens(form_attendees, ','); ++i) {
-                                       extract_token(buf, form_attendees, i, ',');
+                               for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
+                                       extract_token(buf, form_attendees, i, '\n');
                                        striplt(buf);
                                        if (!strcasecmp(buf, attendee_string)) ++foundit;
                                }
@@ -651,7 +652,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
                }
 
                /*
-                * Serialize it and save it to the message base.  We clone it first,
+                * Encapsulate event into full VCALENDAR component.  Clone it first,
                 * for two reasons: one, it's easier to just free the whole thing
                 * when we're done instead of unbundling, but more importantly, we
                 * can't encapsulate something that may already be encapsulated
@@ -659,8 +660,10 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n");
                 */
                lprintf(9, "Encapsulating into full VCALENDAR component\n");
                encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
+
+               /* If the user clicked 'Save' then save it to the server. */
                lprintf(9, "Serializing it for saving\n");
-               if (encaps != NULL) {
+               if ( (encaps != NULL) && (!strcasecmp(bstr("sc"), "Save")) ) {
                        serv_puts("ENT0 1|||4");
                        serv_gets(buf);
                        if (buf[0] == '4') {
@@ -671,6 +674,19 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n");
                        }
                        icalcomponent_free(encaps);
                }
+
+               /* Or, check attendee availability if the user asked for that. */
+               if ( (encaps != NULL) && (!strcasecmp(bstr("sc"), "Check attendee availability")) ) {
+
+                       /* Call this function, which does the real work */
+                       check_attendee_availability(encaps);
+
+                       /* This displays the form again, with our annotations */
+                       display_edit_individual_event(encaps, msgnum);
+
+                       icalcomponent_free(encaps);
+               }
+
        }
 
        /*
@@ -686,8 +702,10 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n");
                icalcomponent_free(vevent);
        }
 
-       /* Go back to the event list */
-       readloop("readfwd");
+       /* If this was a save or deelete, go back to the calendar view. */
+       if (strcasecmp(bstr("sc"), "Check attendee availability")) {
+               readloop("readfwd");
+       }
 }