]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar.c
* Repaired all my b0rken COLOR tags
[citadel.git] / webcit / calendar.c
index 7c436ccad6c336c3280216838134343f2bfa6b9c..616bfe2ce1f95f4b0f33261470aacd2c785f5ca7 100644 (file)
@@ -27,7 +27,7 @@
 #include "webcit.h"
 #include "webserver.h"
 
-#ifndef HAVE_ICAL_H
+#ifndef WEBCIT_WITH_CALENDAR_SERVICE
 
 /*
  * Handler stubs for builds with no calendar library available
@@ -59,7 +59,7 @@ void display_task(long msgnum) {
                "</i><br>\n");
 }
 
-#else /* HAVE_ICAL_H */
+#else /* WEBCIT_WITH_CALENDAR_SERVICE */
 
 
 /******   End of handler stubs.  Everything below this line is real.   ******/
@@ -70,6 +70,9 @@ void display_task(long msgnum) {
 /*
  * Process a calendar object
  * ...at this point it's already been deserialized by cal_process_attachment()
+ *
+ * ok for complete vcalendar objects
+ *
  */
 void cal_process_object(icalcomponent *cal,
                        int recursion_level,
@@ -107,6 +110,15 @@ void cal_process_object(icalcomponent *cal,
                                </TD></TR>\n"
                        );
                        break;
+                   case ICAL_METHOD_REPLY:
+                       wprintf("<TR><TD COLSPAN=2>\n"
+                               "<IMG ALIGN=CENTER "
+                               "SRC=\"/static/vcalendar.gif\">"
+                               "&nbsp;&nbsp;"  
+                               "<B>Attendee's reply to your invitation</B>
+                               </TD></TR>\n"
+                       );
+                       break;
                    case ICAL_METHOD_PUBLISH:
                        wprintf("<TR><TD COLSPAN=2>\n"
                                "<IMG ALIGN=CENTER "
@@ -186,6 +198,25 @@ void cal_process_object(icalcomponent *cal,
                wprintf("</TD></TR>\n");
        }
 
+       /* If the component has attendees, iterate through them. */
+       for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY); (p != NULL); p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) {
+               wprintf("<TR><TD><B>Attendee:</B></TD><TD>");
+               strcpy(buf, icalproperty_get_attendee(p));
+               if (!strncasecmp(buf, "MAILTO:", 7)) {
+
+                       /* screen name or email address */
+                       strcpy(buf, &buf[7]);
+                       striplt(buf);
+                       escputs(buf);
+                       wprintf(" ");
+
+                       /* participant status */
+                       partstat_as_string(buf, p);
+                       escputs(buf);
+               }
+               wprintf("</TD></TR>\n");
+       }
+
        /* If the component has subcomponents, recurse through them. */
        for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
            (c != 0);
@@ -198,6 +229,7 @@ void cal_process_object(icalcomponent *cal,
        if (the_method == ICAL_METHOD_REQUEST) {
 
                /* Check for conflicts */
+               lprintf(9, "Checking server calendar for conflicts...\n");
                serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
                serv_gets(buf);
                if (buf[0] == '1') {
@@ -226,6 +258,7 @@ void cal_process_object(icalcomponent *cal,
                                        "</TD></TR>\n");
                        }
                }
+               lprintf(9, "...done.\n");
 
                /* Display the Accept/Decline buttons */
                wprintf("<TR><TD COLSPAN=2>"
@@ -250,6 +283,39 @@ void cal_process_object(icalcomponent *cal,
 
        }
 
+       /* If this is a REPLY, display update button */
+       if (the_method == ICAL_METHOD_REPLY) {
+
+               /***********
+                * In the future, if we want to validate this object before
+                * continuing, we can do it this way:
+               serv_printf("ICAL whatever|%ld|%s|", msgnum, cal_partnum);
+               serv_gets(buf);
+               }
+                ***********/
+
+               /* Display the update buttons */
+               wprintf("<TR><TD COLSPAN=2>"
+                       "Click <i>Update</i> to accept this reply and "
+                       "update your calendar."
+                       "<FORM METHOD=\"GET\" "
+                       "ACTION=\"/handle_rsvp\">\n"
+                       "<INPUT TYPE=\"submit\" NAME=\"sc\" "
+                               "VALUE=\"Update\">\n"
+                       "&nbsp;&nbsp;"
+                       "<INPUT TYPE=\"submit\" NAME=\"sc\" "
+                               "VALUE=\"Ignore\">\n"
+                       "<INPUT TYPE=\"hidden\" NAME=\"msgnum\" "
+                               "VALUE=\"%ld\">"
+                       "<INPUT TYPE=\"hidden\" NAME=\"cal_partnum\" "
+                               "VALUE=\"%s\">"
+                       "</FORM>"
+                       "</TD></TR>\n",
+                       msgnum, cal_partnum
+               );
+
+       }
+
        /* Trailing HTML for the display of this object */
        if (recursion_level == 0) {
 
@@ -261,6 +327,7 @@ void cal_process_object(icalcomponent *cal,
 /*
  * Deserialize a calendar object in a message so it can be processed.
  * (This is the main entry point for these things)
+ * ok for complete vcalendar objects
  */
 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
        icalcomponent *cal;
@@ -268,11 +335,11 @@ void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum) {
        cal = icalcomponent_new_from_string(part_source);
 
        if (cal == NULL) {
-               wprintf("Error parsing calendar object: %s<BR>\n",
-                       icalerror_strerror(icalerrno));
+               wprintf("Error parsing calendar object<BR>\n");
                return;
        }
 
+       ical_dezonify(cal);
        cal_process_object(cal, 0, msgnum, cal_partnum);
 
        /* Free the memory we obtained from libical's constructor */
@@ -290,10 +357,9 @@ void respond_to_request(void) {
 
        output_headers(3);
 
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
-               "<FONT SIZE=+1 COLOR=\"FFFFFF\""
-               "<B>Respond to meeting request</B>"
-               "</FONT></TD></TR></TABLE><BR>\n"
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>"
+               "<SPAN CLASS=\"titlebar\">Respond to meeting request</SPAN>"
+               "</TD></TR></TABLE><BR>\n"
        );
 
        serv_printf("ICAL respond|%s|%s|%s|",
@@ -331,7 +397,58 @@ void respond_to_request(void) {
 
        wprintf("<A HREF=\"/dotskip?room=");
        urlescputs(WC->wc_roomname);
-       wprintf("\">Return to messages</A><BR>\n");
+       wprintf("\"><BR>Return to messages</A><BR>\n");
+
+       wDumpContent(1);
+}
+
+
+
+/*
+ * Handle an incoming RSVP
+ */
+void handle_rsvp(void) {
+       char buf[SIZ];
+
+       output_headers(3);
+
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>"
+               "<SPAN CLASS=\"titlebar\">"
+               "Update your calendar with this RSVP</SPAN>"
+               "</TD></TR></TABLE><BR>\n"
+       );
+
+       serv_printf("ICAL handle_rsvp|%s|%s|%s|",
+               bstr("msgnum"),
+               bstr("cal_partnum"),
+               bstr("sc")
+       );
+       serv_gets(buf);
+
+       if (buf[0] == '2') {
+               wprintf("<TABLE BORDER=0><TR><TD>"
+                       "<IMG SRC=\"static/vcalendar.gif\" ALIGN=CENTER>"
+                       "</TD><TD>"
+               );
+               if (!strcasecmp(bstr("sc"), "update")) {
+                       wprintf("Your calendar has been updated "
+                               "to reflect this RSVP."
+                       );
+               } else if (!strcasecmp(bstr("sc"), "ignore")) {
+                       wprintf("You have chosen to ignore this RSVP. "
+                               "Your calendar has <b>not</b> been updated."
+                       );
+               }
+               wprintf("</TD></TR></TABLE>\n"
+               );
+       } else {
+               wprintf("<IMG SRC=\"static/error.gif\" ALIGN=CENTER>"
+                       "%s\n", &buf[4]);
+       }
+
+       wprintf("<A HREF=\"/dotskip?room=");
+       urlescputs(WC->wc_roomname);
+       wprintf("\"><BR>Return to messages</A><BR>\n");
 
        wDumpContent(1);
 }
@@ -375,7 +492,9 @@ void display_individual_task(icalcomponent *vtodo, long msgnum) {
        icalproperty *p;
 
        p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
-       wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld\">", msgnum);
+       wprintf("<LI><A HREF=\"/display_edit_task?msgnum=%ld&taskrm=", msgnum);
+       urlescputs(WC->wc_roomname);
+       wprintf("\">");
        if (p != NULL) {
                escputs((char *)icalproperty_get_comment(p));
        }
@@ -385,6 +504,8 @@ void display_individual_task(icalcomponent *vtodo, long msgnum) {
 
 /*
  * Display a task by itself (for editing)
+ *
+ * ok for complete vcalendar objects
  */
 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
        icalcomponent *vtodo;
@@ -397,6 +518,22 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
 
        if (supplied_vtodo != NULL) {
                vtodo = supplied_vtodo;
+
+               /* 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
+                * NULL returned by icalcomponent_get_first_component() will
+                * tell the next iteration of this function to create a
+                * new one.
+                */
+               if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
+                       display_edit_individual_task(
+                               icalcomponent_get_first_component(
+                                       vtodo, ICAL_VTODO_COMPONENT
+                               ), msgnum
+                       );
+                       return;
+               }
        }
        else {
                vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
@@ -404,10 +541,9 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
        }
 
        output_headers(3);
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
-               "<FONT SIZE=+1 COLOR=\"FFFFFF\""
-               "<B>Edit task</B>"
-               "</FONT></TD></TR></TABLE><BR>\n"
+       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>"
+               "<SPAN CLASS=\"titlebar\">Edit task</SPAN>"
+               "</TD></TR></TABLE><BR>\n"
        );
 
        wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_task\">\n");
@@ -473,6 +609,8 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
 
 /*
  * Save an edited task
+ *
+ * ok 
  */
 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
        char buf[SIZ];
@@ -483,6 +621,21 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
 
        if (supplied_vtodo != NULL) {
                vtodo = supplied_vtodo;
+               /* 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
+                * NULL returned by icalcomponent_get_first_component() will
+                * tell the next iteration of this function to create a
+                * new one.
+                */
+               if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
+                       save_individual_task(
+                               icalcomponent_get_first_component(
+                                       vtodo, ICAL_VTODO_COMPONENT
+                               ), msgnum
+                       );
+                       return;
+               }
        }
        else {
                vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
@@ -575,6 +728,8 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum) {
  * type, we load the message and hunt for that MIME type.  If found, we load
  * the relevant part, deserialize it into a libical component, filter it for
  * the requested object type, and feed it to the specified handler.
+ *
+ * ok
  */
 void display_using_handler(long msgnum,
                        char *mimetype,
@@ -618,6 +773,8 @@ void display_using_handler(long msgnum,
                        cal = icalcomponent_new_from_string(relevant_source);
                        if (cal != NULL) {
 
+                               ical_dezonify(cal);
+
                                /* Simple components of desired type */
                                if (icalcomponent_isa(cal) == which_kind) {
                                        callback(cal, msgnum);
@@ -654,6 +811,11 @@ void display_task(long msgnum) {
 void display_edit_task(void) {
        long msgnum = 0L;
 
+       /* Force change the room if we have to */
+       if (strlen(bstr("taskrm")) > 0) {
+               gotoroom(bstr("taskrm"), 0);
+       }
+
        msgnum = atol(bstr("msgnum"));
        if (msgnum > 0L) {
                /* existing task */
@@ -712,4 +874,4 @@ void save_event(void) {
        }
 }
 
-#endif /* HAVE_ICAL_H */
+#endif /* WEBCIT_WITH_CALENDAR_SERVICE */