* Created IsEmptyStr define to be used rather then using some weird strlen constructs
[citadel.git] / webcit / event.c
index 9c283c6e4bc201d0880c50d6ce828e4d20bd9b84..4aa7f9ef1e7bc1a67f7453bf51809e1e63d0468b 100644 (file)
@@ -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);
@@ -174,12 +175,12 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
        }
        else {
                localtime_r(&now, &tm_now);
-               if (strlen(bstr("year")) > 0) {
+               if (!IsEmptyStr(bstr("year"))) {
                        tm_now.tm_year = atoi(bstr("year")) - 1900;
                        tm_now.tm_mon = atoi(bstr("month")) - 1;
                        tm_now.tm_mday = atoi(bstr("day"));
                }
-               if (strlen(bstr("hour")) > 0) {
+               if (!IsEmptyStr(bstr("hour"))) {
                        tm_now.tm_hour = atoi(bstr("hour"));
                        tm_now.tm_min = atoi(bstr("minute"));
                        tm_now.tm_sec = 0;
@@ -345,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 ")
        );
@@ -397,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) {
@@ -418,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];
@@ -449,8 +465,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                created_new_vevent = 1;
        }
 
-       if ( (strlen(bstr("save_button")) > 0)
-          || (strlen(bstr("check_button")) > 0) ) {
+       if ( (!IsEmptyStr(bstr("save_button")))
+          || (!IsEmptyStr(bstr("check_button"))) ) {
 
                /** Replace values in the component with ones from the form */
 
@@ -460,7 +476,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        icalproperty_free(prop);
                }
 
-               if (strlen(bstr("summary")) > 0) {
+               if (!IsEmptyStr(bstr("summary"))) {
        
                        icalcomponent_add_property(vevent,
                                        icalproperty_new_summary(bstr("summary")));
@@ -474,7 +490,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        icalcomponent_remove_property(vevent, prop);
                        icalproperty_free(prop);
                }
-               if (strlen(bstr("location")) > 0) {
+               if (!IsEmptyStr(bstr("location"))) {
                        icalcomponent_add_property(vevent,
                                        icalproperty_new_location(bstr("location")));
                }
@@ -483,7 +499,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        icalcomponent_remove_property(vevent, prop);
                        icalproperty_free(prop);
                }
-               if (strlen(bstr("description")) > 0) {
+               if (!IsEmptyStr(bstr("description"))) {
                        icalcomponent_add_property(vevent,
                                icalproperty_new_description(bstr("description")));
                }
@@ -546,7 +562,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                }
 
                /** See if transparency is indicated */
-               if (strlen(bstr("transp")) > 0) {
+               if (!IsEmptyStr(bstr("transp"))) {
                        if (!strcasecmp(bstr("transp"), "opaque")) {
                                formtransp = ICAL_TRANSP_OPAQUE;
                        }
@@ -599,7 +615,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                strcpy(buf, bstr("organizer"));
                if ( (icalcomponent_get_first_property(vevent,
                   ICAL_ORGANIZER_PROPERTY) == NULL) 
-                  && (strlen(buf) > 0) ) {
+                  && (!IsEmptyStr(buf)) ) {
 
                        /** set new organizer */
                        sprintf(organizer_string, "MAILTO:%s", buf);
@@ -618,11 +634,22 @@ 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);
                        striplt(buf);
-                       if (strlen(buf) > 0) {
+                       if (!IsEmptyStr(buf)) {
                                lprintf(9, "Attendee: <%s>\n", buf);
                                sprintf(attendee_string, "MAILTO:%s", buf);
                                foundit = 0;
@@ -680,7 +707,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
 
                /** 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) ) {
+               if ( (encaps != NULL) && (!IsEmptyStr(bstr("save_button"))) ) {
                        serv_puts("ENT0 1|||4|||1|");
                        serv_getln(buf, sizeof buf);
                        if (buf[0] == '8') {
@@ -701,7 +728,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
                }
 
                /** Or, check attendee availability if the user asked for that. */
-               if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) {
+               if ( (encaps != NULL) && (!IsEmptyStr(bstr("check_button"))) ) {
 
                        /** Call this function, which does the real work */
                        check_attendee_availability(encaps);
@@ -718,7 +745,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
         * If the user clicked 'Delete' then delete it.
         */
        lprintf(9, "Checking to see if we have to delete an old event\n");
-       if ( (strlen(bstr("delete_button")) > 0) && (msgnum > 0L) ) {
+       if ( (!IsEmptyStr(bstr("delete_button"))) && (msgnum > 0L) ) {
                serv_printf("DELE %ld", atol(bstr("msgnum")));
                serv_getln(buf, sizeof buf);
        }
@@ -728,7 +755,7 @@ STARTOVER:  lprintf(9, "Remove unlisted attendees\n");
        }
 
        /** If this was a save or delete, go back to the calendar view. */
-       if (strlen(bstr("check_button")) == 0) {
+       if (IsEmptyStr(bstr("check_button"))) {
                readloop("readfwd");
        }
 }