Nearly all <FORM> blocks now contain a hidden input
[citadel.git] / webcit / event.c
index 8f7c83f6e9e036caed731aa7e8b07a5a6418bc3c..37d6af5651cdd69178181fcd5b1880720bf63b6a 100644 (file)
@@ -3,7 +3,7 @@
  */
 /**
  * \defgroup EditCal Editing calendar events.
- *
+ * \ingroup Calendaring
  */
 /*@{*/
 #include "webcit.h"
@@ -71,7 +71,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        /** Begin output */
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n"
-               "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
+               "<TABLE class=\"event_banner\"><TR><TD>"
                "<SPAN CLASS=\"titlebar\">");
        wprintf(_("Add or edit an event"));
        wprintf("</SPAN>"
@@ -109,7 +109,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
 
 
        wprintf("<div class=\"fix_scrollbar_bug\">"
-               "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
+               "<table  class=\"event_background\"><tr><td>\n");
 
        /************************************************************
         * Uncomment this to see the UID in calendar events for debugging
@@ -123,6 +123,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        *************************************************************/
 
        wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
 
        wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
                msgnum);
@@ -270,17 +271,14 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
         * Determine who is the organizer of this event.
         * We need to determine "me" or "not me."
         */
-       organizer = icalcomponent_get_first_property(vevent,
-                                               ICAL_ORGANIZER_PROPERTY);
+       organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
        if (organizer != NULL) {
                strcpy(organizer_string, icalproperty_get_organizer(organizer));
                if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
                        strcpy(organizer_string, &organizer_string[7]);
                        striplt(organizer_string);
-                       lprintf(9, "ISME %s\n", organizer_string);
                        serv_printf("ISME %s", organizer_string);
                        serv_getln(buf, sizeof buf);
-                       lprintf(9, "%s\n", buf);
                        if (buf[0] == '2') {
                                organizer_is_me = 1;
                        }
@@ -348,10 +346,23 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        wprintf("<TR><TD><B>");
        wprintf(_("Attendees"));
        wprintf("</B><br />"
-               "<FONT SIZE=-2>");
+               "<font size=-2>");
        wprintf(_("(One per line)"));
-       wprintf("</FONT></TD><TD>"
-               "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
+       wprintf("</font>\n");
+
+       /** Pop open an address book -- begin **/
+       wprintf(
+               "&nbsp;<a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
+               "title=\"%s\">"
+               "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
+               "</a>",
+               _("Attendees"),
+               _("Contacts")
+       );
+       /** Pop open an address book -- end **/
+
+       wprintf("</TD><TD>"
+               "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
                "ROWS=3 COLS=80 WIDTH=80>\n",
                (organizer_is_me ? "" : "DISABLED ")
        );
@@ -400,6 +411,8 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                "grey_all_day();"
                "</script>\n"
        );
+       
+       address_book_popup();
        wDumpContent(1);
 
        if (created_new_vevent) {
@@ -421,7 +434,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        struct icaltimetype event_start, t;
        icalproperty *attendee = NULL;
        char attendee_string[SIZ];
-       int i;
+       int i, j;
        int foundit;
        char form_attendees[SIZ];
        char organizer_string[SIZ];
@@ -462,25 +475,35 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        icalcomponent_remove_property(vevent, prop);
                        icalproperty_free(prop);
                }
-               icalcomponent_add_property(vevent,
-                       icalproperty_new_summary(bstr("summary")));
 
-               while (prop = icalcomponent_get_first_property(vevent,
-                     ICAL_LOCATION_PROPERTY), prop != NULL) {
-                       icalcomponent_remove_property(vevent, prop);
-                       icalproperty_free(prop);
-               }
-               icalcomponent_add_property(vevent,
-                       icalproperty_new_location(bstr("location")));
-               
-               while (prop = icalcomponent_get_first_property(vevent,
-                     ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
-                       icalcomponent_remove_property(vevent, prop);
-                       icalproperty_free(prop);
-               }
-               icalcomponent_add_property(vevent,
-                       icalproperty_new_description(bstr("description")));
+               if (strlen(bstr("summary")) > 0) {
+       
+                       icalcomponent_add_property(vevent,
+                                       icalproperty_new_summary(bstr("summary")));
+               } else {
+                       icalcomponent_add_property(vevent,
+                                       icalproperty_new_summary("Untitled Event"));
+               }
        
+               while (prop = icalcomponent_get_first_property(vevent,
+                                       ICAL_LOCATION_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+                       icalproperty_free(prop);
+               }
+               if (strlen(bstr("location")) > 0) {
+                       icalcomponent_add_property(vevent,
+                                       icalproperty_new_location(bstr("location")));
+               }
+               while (prop = icalcomponent_get_first_property(vevent,
+                                 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
+                       icalcomponent_remove_property(vevent, prop);
+                       icalproperty_free(prop);
+               }
+               if (strlen(bstr("description")) > 0) {
+                       icalcomponent_add_property(vevent,
+                               icalproperty_new_description(bstr("description")));
+               }
+
                while (prop = icalcomponent_get_first_property(vevent,
                      ICAL_DTSTART_PROPERTY), prop != NULL) {
                        icalcomponent_remove_property(vevent, prop);
@@ -597,7 +620,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        /** set new organizer */
                        sprintf(organizer_string, "MAILTO:%s", buf);
                        icalcomponent_add_property(vevent,
-                               icalproperty_new_organizer(organizer_string)
+                               icalproperty_new_organizer(organizer_string)
                        );
 
                }
@@ -611,6 +634,17 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                strcpy(form_attendees, bstr("attendees"));
                stripout(form_attendees, '(', ')');
 
+               /* Next, change any commas to newlines, because we want newline-separated attendees. */
+               j = strlen(form_attendees);
+               for (i=0; i<j; ++i) {
+                       if (form_attendees[i] == ',') {
+                               form_attendees[i] = '\n';
+                               while (isspace(form_attendees[i+1])) {
+                                       strcpy(&form_attendees[i+1], &form_attendees[i+2]);
+                               }
+                       }
+               }
+
                /** Now iterate! */
                for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
                        extract_token(buf, form_attendees, i, '\n', sizeof buf);
@@ -668,6 +702,9 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
                lprintf(9, "Encapsulating into full VCALENDAR component\n");
                encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
 
+               /* Set the method to PUBLISH */
+               icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
+
                /** If the user clicked 'Save' then save it to the server. */
                lprintf(9, "Serializing it for saving\n");
                if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) {
@@ -679,8 +716,13 @@ STARTOVER: lprintf(9, "Remove unlisted attendees\n");
                                serv_puts(icalcomponent_as_ical_string(encaps));
                                serv_puts("000");
                        }
-                       while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                               lprintf(9, "ENT0 REPLY: %s\n", buf);
+                       if ( (buf[0] == '8') || (buf[0] == '4') ) {
+                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                                       lprintf(9, "ENT0 REPLY: %s\n", buf);
+                               }
+                       }
+                       if (buf[0] == '2') {
+                               strcpy(WC->ImportantMessage, &buf[4]);
                        }
                        icalcomponent_free(encaps);
                }
@@ -712,7 +754,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
                icalcomponent_free(vevent);
        }
 
-       /** If this was a save or deelete, go back to the calendar view. */
+       /** If this was a save or delete, go back to the calendar view. */
        if (strlen(bstr("check_button")) == 0) {
                readloop("readfwd");
        }