* event.c: fixed a misspelling
[citadel.git] / webcit / event.c
index 45d1e2932f1b0751e017998a01633e4c727cd185..2767a20fac1d9c974cd7f6ea8108a78a3731d214 100644 (file)
@@ -28,7 +28,7 @@
 #include "webserver.h"
 
 
-#ifdef HAVE_ICAL_H
+#ifdef WEBCIT_WITH_CALENDAR_SERVICE
 
 /*
  * Display an event by itself (for editing)
 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        icalcomponent *vevent;
        icalproperty *p;
+       icalvalue *v;
        struct icaltimetype t_start, t_end;
        time_t now;
+       struct tm tm_now;
        int created_new_vevent = 0;
        icalproperty *organizer = NULL;
        char organizer_string[SIZ];
@@ -131,20 +133,28 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                }
        }
        else {
-               memset(&t_start, 0, sizeof t_start);
-               t_start.year = atoi(bstr("year"));
-               t_start.month = atoi(bstr("month"));
-               t_start.day = atoi(bstr("day"));
+               memcpy(&tm_now, localtime(&now), sizeof(struct tm));
+               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) {
-                       t_start.hour = atoi(bstr("hour"));
-                       t_start.minute = atoi(bstr("minute"));
-                       t_start.second = 0;
+                       tm_now.tm_hour = atoi(bstr("hour"));
+                       tm_now.tm_min = atoi(bstr("minute"));
+                       tm_now.tm_sec = 0;
                }
                else {
-                       t_start.hour = 9;
-                       t_start.minute = 0;
-                       t_start.second = 0;
+                       tm_now.tm_hour = 9;
+                       tm_now.tm_min = 0;
+                       tm_now.tm_sec = 0;
                }
+
+               t_start = icaltime_from_timet_with_zone(
+                       mktime(&tm_now),
+                       ((!strcasecmp(bstr("alldayevent"), "yes")) ? 1 : 0),
+                       icaltimezone_get_utc_timezone
+               );
+               t_start.is_utc = 1;
+
        }
        display_icaltimetype_as_webform(&t_start, "dtstart");
 
@@ -250,6 +260,7 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
                        }
                }
        }
+
        wprintf("<TR><TD><B>Organizer</B></TD><TD>");
        escputs(organizer_string);
        if (organizer_is_me) {
@@ -269,8 +280,38 @@ void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum)
 
        wprintf("</TD></TR>\n");
 
-       /* Attendees (do more with this later) */
-       wprintf("<TR><TD><B>Attendes</B><BR>"
+       /* Transparency */
+       wprintf("<TR><TD><B>Show time as:</B></TD><TD>");
+
+       p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
+       if (p == NULL) {
+               /* No transparency found.  Default to opaque (busy). */
+               p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
+               if (p != NULL) {
+                       icalcomponent_add_property(vevent, p);
+               }
+       }
+       if (p != NULL) {
+               v = icalproperty_get_value(p);
+       }
+       else {
+               v = NULL;
+       }
+
+       wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
+       if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
+               wprintf(" CHECKED");
+       wprintf(">Free&nbsp;&nbsp;");
+
+       wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
+       if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
+               wprintf(" CHECKED");
+       wprintf(">Busy");
+
+       wprintf("</TD></TR>\n");
+
+       /* Attendees */
+       wprintf("<TR><TD><B>Attendees</B><BR>"
                "<FONT SIZE=-2>(Separate multiple attendees with commas)"
                "</FONT></TD><TD>"
                "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
@@ -361,6 +402,7 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
        char form_attendees[SIZ];
        char organizer_string[SIZ];
        int sequence = 0;
+       enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
 
        if (supplied_vevent != NULL) {
                vevent = supplied_vevent;
@@ -437,8 +479,6 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                if (prop) icalcomponent_add_property(vevent, prop);
                else icalproperty_free(prop);
 
-
-
                while (prop = icalcomponent_get_first_property(vevent,
                      ICAL_DTEND_PROPERTY), prop != NULL) {
                        icalcomponent_remove_property(vevent, prop);
@@ -458,6 +498,29 @@ void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
                        );
                }
 
+               /* See if transparency is indicated */
+               if (strlen(bstr("transp")) > 0) {
+                       lprintf(9, "FORM VALUE: <%s>\n", bstr("transp"));
+                       if (!strcasecmp(bstr("transp"), "opaque")) {
+                               formtransp = ICAL_TRANSP_OPAQUE;
+                               lprintf(9, "setting to opaque\n");
+                       }
+                       else if (!strcasecmp(bstr("transp"), "transparent")) {
+                               formtransp = ICAL_TRANSP_TRANSPARENT;
+                               lprintf(9, "setting to transparent\n");
+                       }
+
+                       while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
+                             (prop != NULL)) {
+                               lprintf(9, "removing existing property\n");
+                               icalcomponent_remove_property(vevent, prop);
+                               icalproperty_free(prop);
+                       }
+
+                       lprintf(9, "adding new property\n");
+                       icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
+               }
+
                /* Give this event a UID if it doesn't have one. */
                if (icalcomponent_get_first_property(vevent,
                   ICAL_UID_PROPERTY) == NULL) {
@@ -581,4 +644,4 @@ STARTOVER:
 }
 
 
-#endif /* HAVE_ICAL_H */
+#endif /* WEBCIT_WITH_CALENDAR_SERVICE */