final touches on dkim test harness
[citadel.git] / webcit / event.c
index 6106ec1dbca0637eb8f3224852f3ef70b4e99a9e..ffe0688aba78ab67e9cbbb6e107dd4a8e1d8a67c 100644 (file)
@@ -1,25 +1,19 @@
 /*
  * Editing calendar events.
  *
- * Copyright (c) 1996-2010 by the citadel.org team
+ * Copyright (c) 2002-2012 by the citadel.org team
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * This program is open source software.  You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License, version 3.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "webcit.h"
-#include "webserver.h"
+
 #include "calendar.h"
 
 /*
@@ -30,6 +24,7 @@
 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
        int unread, calview *calv)
 {
+       wcsession *WCC = WC;
        icalcomponent *vevent;
        icalproperty *p;
        icalvalue *v;
@@ -44,7 +39,10 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        char buf[SIZ];
        int organizer_is_me = 0;
        int i, j = 0;
+       /************************************************************
+        * Uncomment this to see the UID in calendar events for debugging
        int sequence = 0;
+       */
        char weekday_labels[7][32];
        char month_labels[12][32];
        long weekstart = 0;
@@ -65,8 +63,8 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        int which_rrend_is_preselected;
        int which_rryeartype_is_preselected;
 
-
-       char *tabnames[3];
+       const char *ch;
+       const char *tabnames[3];
        const char *frequency_units[8];
        const char *ordinals[6];
 
@@ -95,7 +93,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        get_pref_long("weekstart", &weekstart, 17);
        if (weekstart > 6) weekstart = 0;
 
-       lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
+       syslog(LOG_DEBUG, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
                msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
        );
 
@@ -157,13 +155,15 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
 
        /* Learn the sequence */
        p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
+       /************************************************************
+        * Uncomment this to see the UID in calendar events for debugging
        if (p != NULL) {
                sequence = icalproperty_get_sequence(p);
        }
-
+       */
        /* Begin output */
-       output_headers(1, 1, 2, 0, 0, 0);
-       wc_printf("<div id=\"banner\">\n");
+       output_headers(1, 1, 1, 0, 0, 0);
+       wc_printf("<div id=\"room_banner_override\">\n");
        wc_printf("<h1>");
        wc_printf(_("Add or edit an event"));
        wc_printf("</h1>");
@@ -171,8 +171,6 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
 
        wc_printf("<div id=\"content\" class=\"service\">\n");
 
-       wc_printf("<div class=\"fix_scrollbar_bug\">");
-
        /************************************************************
         * Uncomment this to see the UID in calendar events for debugging
        wc_printf("UID == ");
@@ -180,13 +178,17 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        if (p != NULL) {
                escputs((char *)icalproperty_get_comment(p));
        }
-       wc_printf("<br />\n");
-       wc_printf("SEQUENCE == %d<br />\n", sequence);
+       wc_printf("<br>\n");
+       wc_printf("SEQUENCE == %d<br>\n", sequence);
        *************************************************************/
 
        wc_printf("<form name=\"EventForm\" method=\"POST\" action=\"save_event\">\n");
        wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
 
+       wc_printf("<input type=\"hidden\" name=\"go\" value=\"");
+       StrEscAppend(WCC->WBuf, WCC->CurRoom.name, NULL, 0, 0);
+       wc_printf("\">\n");
+
        wc_printf("<input type=\"hidden\" name=\"msgnum\" value=\"%ld\">\n",
                msgnum);
        wc_printf("<input type=\"hidden\" name=\"calview\" value=\"%s\">\n",
@@ -262,8 +264,6 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                        ((yesbstr("alldayevent")) ? 1 : 0),
                        icaltimezone_get_utc_timezone()
                );
-               t_start.is_utc = 1;
-
        }
        display_icaltimetype_as_webform(&t_start, "dtstart", 0);
 
@@ -359,7 +359,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                strcpy(organizer_string, icalproperty_get_organizer(organizer));
                if (!strncasecmp(organizer_string, "mailto:", 7)) {
                        strcpy(organizer_string, &organizer_string[7]);
-                       striplt(organizer_string);
+                       string_trim(organizer_string);
                        serv_printf("ISME %s", organizer_string);
                        serv_getln(buf, sizeof buf);
                        if (buf[0] == '2') {
@@ -438,7 +438,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        wc_printf("<table border='0' width='100%%'>\n");        /* same table style as the event tab */
        wc_printf("<tr><td><b>");
        wc_printf(_("Attendees"));
-       wc_printf("</b><br />"
+       wc_printf("</b><br>"
                "<font size='-2'>");
        wc_printf(_("(One per line)"));
        wc_printf("</font>\n");
@@ -447,7 +447,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        wc_printf(
                "&nbsp;<a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
                "title=\"%s\">"
-               "<img alt='' align='middle' border='0' width='24' height='24' src=\"static/viewcontacts_24x.gif\">"
+               "<img alt='' align='middle' border='0' width='16' height='16' src=\"static/webcit_icons/essen/16x16/contact.png\">"
                "</a>",
                _("Attendees"),
                _("Contacts")
@@ -465,12 +465,12 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        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)) {
+               ch = icalproperty_get_attendee(attendee);
+               if ((ch != NULL) && !strncasecmp(ch, "mailto:", 7)) {
 
                        /* screen name or email address */
-                       strcpy(attendee_string, &attendee_string[7]);
-                       striplt(attendee_string);
+                       safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
+                       string_trim(attendee_string);
                        if (i++) wc_printf("\n");
                        escputs(attendee_string);
                        wc_printf(" ");
@@ -594,7 +594,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        }
 
        wc_printf(_("on day %s%d%s of the month"), "<span id=\"rrmday\">", rrmday, "</span>");
-       wc_printf("<br />\n");
+       wc_printf("<br>\n");
 
        wc_printf("<input type=\"radio\" name=\"rrmonthtype\" id=\"rrmonthtype_wday\" "
                "value=\"rrmonthtype_wday\" "
@@ -626,7 +626,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        }
        wc_printf("</select>");
 
-       wc_printf(" %s<br />\n", _("of the month"));
+       wc_printf(" %s<br>\n", _("of the month"));
 
        wc_printf("</div>\n");                          /* end 'monthday_selector' div */
 
@@ -656,7 +656,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                ((which_rryeartype_is_preselected == 0) ? "checked='checked'" : "")
        );
        wc_printf(_("every "));
-       wc_printf("<span id=\"ymday\">%s</span><br />", _("year on this date"));
+       wc_printf("<span id=\"ymday\">%s</span><br>", _("year on this date"));
 
        wc_printf("<input type=\"radio\" name=\"rryeartype\" id=\"rryeartype_ywday\" "
                "value=\"rryeartype_ywday\" "
@@ -700,7 +700,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                );
        }
        wc_printf("</select>");
-       wc_printf("<br />\n");
+       wc_printf("<br>\n");
 
        wc_printf("</div>\n");                          /* end 'yearday_selector' div */
 
@@ -720,7 +720,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                "%s onChange=\"RecurrenceShowHide();\">",
                ((which_rrend_is_preselected == 0) ? "checked='checked'" : "")
        );
-       wc_printf("%s<br />\n", _("No ending date"));
+       wc_printf("%s<br>\n", _("No ending date"));
 
        wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_count\" "
                "value=\"rrend_count\" "
@@ -731,7 +731,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        wc_printf(" <input type=\"text\" name=\"rrcount\" id=\"rrcount\" maxlength=\"3\" size=\"3\" ");
        wc_printf("value=\"%d\"> ", recur.count);
        wc_printf(_("times"));
-       wc_printf("<br />\n");
+       wc_printf("<br>\n");
 
        wc_printf("<input type=\"radio\" name=\"rrend\" id=\"rrend_until\" "
                "value=\"rrend_until\" "
@@ -744,7 +744,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
                recur.until = icaltime_add(t_start, icaldurationtype_from_int(604800));
        }
        display_icaltimetype_as_webform(&recur.until, "rruntil", 1);
-       wc_printf("<br />\n");
+       wc_printf("<br>\n");
 
        wc_printf("</td></tr>\n");
 
@@ -772,14 +772,13 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
        end_tab(3, 3);
        wc_printf("</form>\n");
 
-       wc_printf("</div>\n");                  /* end 'fix_scrollbar_bug' div */
-
        StrBufAppendPrintf(WC->trailing_javascript,
                "eventEditAllDay();             \n"
                "RecurrenceShowHide();          \n"
                "EnableOrDisableCheckButton();  \n"
        );
-       address_book_popup();
+       do_template("addressbook_popup");
+
        wDumpContent(1);
 
        if (created_new_vevent) {
@@ -795,6 +794,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum,
  */
 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from,
                        int unread, calview *calv) {
+       StrBuf *Buf;
        char buf[SIZ];
        icalproperty *prop;
        icalcomponent *vevent, *encaps;
@@ -809,6 +809,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *fr
        char organizer_string[SIZ];
        int sequence = 0;
        enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
+       const char *ch;
 
        if (supplied_vevent != NULL) {
                vevent = supplied_vevent;
@@ -851,8 +852,8 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *fr
 
                /* Add NOW() to the calendar object... */
                icalcomponent_set_dtstamp(vevent,
-                                         icaltime_from_timet(
-                                                 time(NULL), 0));
+                                         icaltime_from_timet_with_zone(
+                                                 time(NULL), 0, icaltimezone_get_utc_timezone()));
 
                if (havebstr("summary")) {
                        icalcomponent_add_property(vevent,
@@ -1097,21 +1098,21 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *fr
                /* Now iterate! */
                for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
                        extract_token(buf, form_attendees, i, '\n', sizeof buf);
-                       striplt(buf);
+                       string_trim(buf);
                        if (!IsEmptyStr(buf)) {
                                sprintf(attendee_string, "MAILTO:%s", buf);
                                foundit = 0;
 
                                for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
-                                       if (!strcasecmp(attendee_string,
-                                          icalproperty_get_attendee(attendee)))
+                                       ch = icalproperty_get_attendee(attendee);
+                                       if ((ch != NULL) && !strcasecmp(attendee_string, ch))
                                                ++foundit;
                                }
 
 
                                if (foundit == 0) {
                                        icalcomponent_add_property(vevent,
-                                               icalproperty_new_attendee(attendee_string)
+                                                                  icalproperty_new_attendee(attendee_string)
                                        );
                                }
                        }
@@ -1121,14 +1122,14 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *fr
                 * Remove any attendees *not* listed in the web form
                 */
 STARTOVER:     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)) {
-                               strcpy(attendee_string, &attendee_string[7]);
-                               striplt(attendee_string);
+                       ch = icalproperty_get_attendee(attendee);
+                       if ((ch != NULL) && !strncasecmp(ch, "MAILTO:", 7)) {
+                               safestrncpy(attendee_string, ch + 7, sizeof(attendee_string));
+                               string_trim(attendee_string);
                                foundit = 0;
                                for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
                                        extract_token(buf, form_attendees, i, '\n', sizeof buf);
-                                       striplt(buf);
+                                       string_trim(buf);
                                        if (!strcasecmp(buf, attendee_string)) ++foundit;
                                }
                                if (foundit == 0) {
@@ -1155,18 +1156,24 @@ STARTOVER:      for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDE
                if ( (encaps != NULL) && (havebstr("save_button")) ) {
                        serv_puts("ENT0 1|||4|||1|");
                        serv_getln(buf, sizeof buf);
-                       if (buf[0] == '8') {
+                       switch (buf[0]) {
+                       case '8':
                                serv_puts("Content-type: text/calendar");
+                               serv_puts("Content-Transfer-Encoding: quoted-printable");
                                serv_puts("");
-                               serv_puts(icalcomponent_as_ical_string(encaps));
+                               Buf = NewStrBufPlain(icalcomponent_as_ical_string(encaps), -1);
+                               text_to_server_qp(Buf);
+                               FreeStrBuf(&Buf);
+//                             serv_puts(icalcomponent_as_ical_string(encaps));
                                serv_puts("000");
-                       }
-                       if ( (buf[0] == '8') || (buf[0] == '4') ) {
-                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-                               }
-                       }
-                       if (buf[0] == '2') {
-                               strcpy(WC->ImportantMessage, &buf[4]);
+                       case '4':
+                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {}
+                               break;
+                       case '2':
+                               AppendImportantMessage(buf + 4, - 1);
+                               break;
+                       default:
+                               break;
                        }
                        icalmemory_free_ring ();
                        icalcomponent_free(encaps);
@@ -1207,7 +1214,7 @@ STARTOVER:        for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDE
        /* If this was a save or delete, go back to the calendar or summary view. */
        if (!havebstr("check_button")) {
                if (!strcasecmp(bstr("calview"), "summary")) {
-                       summary();
+                       display_summary_page();
                }
                else {
                        readloop(readfwd, eUseDefault);