event.c

00001 /*
00002  * $Id: event.c 5147 2007-05-08 15:36:22Z ajc $
00003  */
00009 #include "webcit.h"
00010 #include "webserver.h"
00011 
00012 
00013 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
00014 
00020 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
00021         icalcomponent *vevent;
00022         icalproperty *p;
00023         icalvalue *v;
00024         struct icaltimetype t_start, t_end;
00025         time_t now;
00026         struct tm tm_now;
00027         int created_new_vevent = 0;
00028         icalproperty *organizer = NULL;
00029         char organizer_string[SIZ];
00030         icalproperty *attendee = NULL;
00031         char attendee_string[SIZ];
00032         char buf[SIZ];
00033         int organizer_is_me = 0;
00034         int i;
00035         int sequence = 0;
00036 
00037         now = time(NULL);
00038         strcpy(organizer_string, "");
00039         strcpy(attendee_string, "");
00040 
00041         if (supplied_vevent != NULL) {
00042                 vevent = supplied_vevent;
00051                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
00052                         display_edit_individual_event(
00053                                 icalcomponent_get_first_component(
00054                                         vevent, ICAL_VEVENT_COMPONENT
00055                                 ), msgnum
00056                         );
00057                         return;
00058                 }
00059         }
00060         else {
00061                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
00062                 created_new_vevent = 1;
00063         }
00064 
00066         p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
00067         if (p != NULL) {
00068                 sequence = icalproperty_get_sequence(p);
00069         }
00070 
00072         output_headers(1, 1, 2, 0, 0, 0);
00073         wprintf("<div id=\"banner\">\n"
00074                 "<TABLE class=\"event_banner\"><TR><TD>"
00075                 "<SPAN CLASS=\"titlebar\">");
00076         wprintf(_("Add or edit an event"));
00077         wprintf("</SPAN>"
00078                 "</TD></TR></TABLE>\n"
00079                 "</div>\n<div id=\"content\">\n"
00080         );
00081 
00082         wprintf("<script type=\"text/javascript\">"
00083                 "function grey_all_day() { "
00084                         "if (document.EventForm.alldayevent.checked) {"
00085                                 "document.EventForm.dtstart_hour.value='0';"
00086                                 "document.EventForm.dtstart_hour.disabled = true;"
00087                                 "document.EventForm.dtstart_minute.value='0';"
00088                                 "document.EventForm.dtstart_minute.disabled = true;"
00089                                 "document.EventForm.dtend_hour.value='0';"
00090                                 "document.EventForm.dtend_hour.disabled = true;"
00091                                 "document.EventForm.dtend_minute.value='0';"
00092                                 "document.EventForm.dtend_minute.disabled = true;"
00093                                 "document.EventForm.dtend_month.disabled = true;"
00094                                 "document.EventForm.dtend_day.disabled = true;"
00095                                 "document.EventForm.dtend_year.disabled = true;"
00096                         "}"
00097                         "else {"
00098                                 "document.EventForm.dtstart_hour.disabled = false;"
00099                                 "document.EventForm.dtstart_minute.disabled = false;"
00100                                 "document.EventForm.dtend_hour.disabled = false;"
00101                                 "document.EventForm.dtend_minute.disabled = false;"
00102                                 "document.EventForm.dtend_month.disabled = false;"
00103                                 "document.EventForm.dtend_day.disabled = false;"
00104                                 "document.EventForm.dtend_year.disabled = false;"
00105                         "}"
00106                 "}"
00107                 "</script>\n"
00108         );
00109 
00110 
00111         wprintf("<div class=\"fix_scrollbar_bug\">"
00112                 "<table  class=\"event_background\"><tr><td>\n");
00113 
00114         /************************************************************
00115          * Uncomment this to see the UID in calendar events for debugging
00116         wprintf("UID == ");
00117         p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
00118         if (p != NULL) {
00119                 escputs((char *)icalproperty_get_comment(p));
00120         }
00121         wprintf("<br />\n");
00122         wprintf("SEQUENCE == %d<br />\n", sequence);
00123         *************************************************************/
00124 
00125         wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
00126 
00127         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
00128                 msgnum);
00129         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
00130                 bstr("calview"));
00131         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
00132                 bstr("year"));
00133         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
00134                 bstr("month"));
00135         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
00136                 bstr("day"));
00137 
00139         wprintf("<TABLE border=0 width=100%%>\n");
00140 
00141         wprintf("<TR><TD><B>");
00142         wprintf(_("Summary"));
00143         wprintf("</B></TD><TD>\n"
00144                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
00145                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
00146         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
00147         if (p != NULL) {
00148                 escputs((char *)icalproperty_get_comment(p));
00149         }
00150         wprintf("\"></TD></TR>\n");
00151 
00152         wprintf("<TR><TD><B>");
00153         wprintf(_("Location"));
00154         wprintf("</B></TD><TD>\n"
00155                 "<INPUT TYPE=\"text\" NAME=\"location\" "
00156                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
00157         p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
00158         if (p != NULL) {
00159                 escputs((char *)icalproperty_get_comment(p));
00160         }
00161         wprintf("\"></TD></TR>\n");
00162 
00163         wprintf("<TR><TD><B>");
00164         wprintf(_("Start"));
00165         wprintf("</B></TD><TD>\n");
00166         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
00167         if (p != NULL) {
00168                 t_start = icalproperty_get_dtstart(p);
00169                 if (t_start.is_date) {
00170                         t_start.hour = 0;
00171                         t_start.minute = 0;
00172                         t_start.second = 0;
00173                 }
00174         }
00175         else {
00176                 localtime_r(&now, &tm_now);
00177                 if (strlen(bstr("year")) > 0) {
00178                         tm_now.tm_year = atoi(bstr("year")) - 1900;
00179                         tm_now.tm_mon = atoi(bstr("month")) - 1;
00180                         tm_now.tm_mday = atoi(bstr("day"));
00181                 }
00182                 if (strlen(bstr("hour")) > 0) {
00183                         tm_now.tm_hour = atoi(bstr("hour"));
00184                         tm_now.tm_min = atoi(bstr("minute"));
00185                         tm_now.tm_sec = 0;
00186                 }
00187                 else {
00188                         tm_now.tm_hour = 9;
00189                         tm_now.tm_min = 0;
00190                         tm_now.tm_sec = 0;
00191                 }
00192 
00193                 t_start = icaltime_from_timet_with_zone(
00194                         mktime(&tm_now),
00195                         ((!strcasecmp(bstr("alldayevent"), "yes")) ? 1 : 0),
00196                         icaltimezone_get_utc_timezone()
00197                 );
00198                 t_start.is_utc = 1;
00199 
00200         }
00201         display_icaltimetype_as_webform(&t_start, "dtstart");
00202 
00203         wprintf("<INPUT TYPE=\"checkbox\" NAME=\"alldayevent\" "
00204                 "VALUE=\"yes\" onClick=\"grey_all_day();\""
00205                 " %s >%s",
00206                 (t_start.is_date ? "CHECKED" : "" ),
00207                 _("All day event")
00208         );
00209 
00210         wprintf("</TD></TR>\n");
00211 
00217         wprintf("<TR><TD><B>");
00218         wprintf(_("End"));
00219         wprintf("</B></TD><TD>\n");
00220         if (t_start.is_date) {
00221                 t_end = t_start;
00222         }
00223         else {
00224                 p = icalcomponent_get_first_property(vevent,
00225                                                         ICAL_DTEND_PROPERTY);
00226                 if (p != NULL) {
00227                         t_end = icalproperty_get_dtend(p);
00228                 }
00229                 else {
00235                         t_end = t_start;
00236                         t_end.hour += 1;
00237                         t_end.second = 0;
00238                         t_end = icaltime_normalize(t_end);
00239                         /* t_end = icaltime_from_timet(now, 0); */
00240                 }
00241         }
00242         display_icaltimetype_as_webform(&t_end, "dtend");
00243         wprintf("</TD></TR>\n");
00244 
00245         wprintf("<TR><TD><B>");
00246         wprintf(_("Notes"));
00247         wprintf("</B></TD><TD>\n"
00248                 "<TEXTAREA NAME=\"description\" wrap=soft "
00249                 "ROWS=5 COLS=80 WIDTH=80>\n"
00250         );
00251         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
00252         if (p != NULL) {
00253                 escputs((char *)icalproperty_get_comment(p));
00254         }
00255         wprintf("</TEXTAREA></TD></TR>");
00256 
00261         if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
00262            == NULL) {
00263                 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
00264                 icalcomponent_add_property(vevent,
00265                         icalproperty_new_organizer(organizer_string)
00266                 );
00267         }
00268 
00273         organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
00274         if (organizer != NULL) {
00275                 strcpy(organizer_string, icalproperty_get_organizer(organizer));
00276                 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
00277                         strcpy(organizer_string, &organizer_string[7]);
00278                         striplt(organizer_string);
00279                         serv_printf("ISME %s", organizer_string);
00280                         serv_getln(buf, sizeof buf);
00281                         if (buf[0] == '2') {
00282                                 organizer_is_me = 1;
00283                         }
00284                 }
00285         }
00286 
00287         wprintf("<TR><TD><B>");
00288         wprintf(_("Organizer"));
00289         wprintf("</B></TD><TD>");
00290         escputs(organizer_string);
00291         if (organizer_is_me) {
00292                 wprintf(" <FONT SIZE=-1><I>");
00293                 wprintf(_("(you are the organizer)"));
00294                 wprintf("</I></FONT>\n");
00295         }
00296 
00303         wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
00304         escputs(organizer_string);
00305         wprintf("\">");
00306 
00307         wprintf("</TD></TR>\n");
00308 
00310         wprintf("<TR><TD><B>");
00311         wprintf(_("Show time as:"));
00312         wprintf("</B></TD><TD>");
00313 
00314         p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
00315         if (p == NULL) {
00317                 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
00318                 if (p != NULL) {
00319                         icalcomponent_add_property(vevent, p);
00320                 }
00321         }
00322         if (p != NULL) {
00323                 v = icalproperty_get_value(p);
00324         }
00325         else {
00326                 v = NULL;
00327         }
00328 
00329         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
00330         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
00331                 wprintf(" CHECKED");
00332         wprintf(">");
00333         wprintf(_("Free"));
00334         wprintf("&nbsp;&nbsp;");
00335 
00336         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
00337         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
00338                 wprintf(" CHECKED");
00339         wprintf(">");
00340         wprintf(_("Busy"));
00341 
00342         wprintf("</TD></TR>\n");
00343 
00345         wprintf("<TR><TD><B>");
00346         wprintf(_("Attendees"));
00347         wprintf("</B><br />"
00348                 "<font size=-2>");
00349         wprintf(_("(One per line)"));
00350         wprintf("</font>\n");
00351 
00353         wprintf(
00354                 "&nbsp;<a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
00355                 "title=\"%s\">"
00356                 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
00357                 "</a>",
00358                 _("Attendees"),
00359                 _("Contacts")
00360         );
00363         wprintf("</TD><TD>"
00364                 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
00365                 "ROWS=3 COLS=80 WIDTH=80>\n",
00366                 (organizer_is_me ? "" : "DISABLED ")
00367         );
00368         i = 0;
00369         for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
00370             attendee != NULL;
00371             attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
00372                 strcpy(attendee_string, icalproperty_get_attendee(attendee));
00373                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
00374 
00376                         strcpy(attendee_string, &attendee_string[7]);
00377                         striplt(attendee_string);
00378                         if (i++) wprintf("\n");
00379                         escputs(attendee_string);
00380                         wprintf(" ");
00381 
00383                         partstat_as_string(buf, attendee);
00384                         escputs(buf);
00385                 }
00386         }
00387         wprintf("</TEXTAREA></TD></TR>\n");
00388 
00390         wprintf("</TABLE>\n<CENTER>"
00391                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
00392                 "&nbsp;&nbsp;"
00393                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
00394                 "&nbsp;&nbsp;"
00395                 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
00396                                 "VALUE=\"%s\">\n"
00397                 "&nbsp;&nbsp;"
00398                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
00399                 "</CENTER>\n",
00400                 _("Save"),
00401                 _("Delete"),
00402                 _("Check attendee availability"),
00403                 _("Cancel")
00404         );
00405 
00406         wprintf("</FORM>\n");
00407         
00408         wprintf("</td></tr></table></div>\n");
00409         wprintf("<script type=\"text/javascript\">"
00410                 "grey_all_day();"
00411                 "</script>\n"
00412         );
00413         
00414         address_book_popup();
00415         wDumpContent(1);
00416 
00417         if (created_new_vevent) {
00418                 icalcomponent_free(vevent);
00419         }
00420 }
00421 
00427 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
00428         char buf[SIZ];
00429         icalproperty *prop;
00430         icalcomponent *vevent, *encaps;
00431         int created_new_vevent = 0;
00432         int all_day_event = 0;
00433         struct icaltimetype event_start, t;
00434         icalproperty *attendee = NULL;
00435         char attendee_string[SIZ];
00436         int i, j;
00437         int foundit;
00438         char form_attendees[SIZ];
00439         char organizer_string[SIZ];
00440         int sequence = 0;
00441         enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
00442 
00443         if (supplied_vevent != NULL) {
00444                 vevent = supplied_vevent;
00453                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
00454                         save_individual_event(
00455                                 icalcomponent_get_first_component(
00456                                         vevent, ICAL_VEVENT_COMPONENT
00457                                 ), msgnum
00458                         );
00459                         return;
00460                 }
00461         }
00462         else {
00463                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
00464                 created_new_vevent = 1;
00465         }
00466 
00467         if ( (strlen(bstr("save_button")) > 0)
00468            || (strlen(bstr("check_button")) > 0) ) {
00469 
00472                 while (prop = icalcomponent_get_first_property(vevent,
00473                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
00474                         icalcomponent_remove_property(vevent, prop);
00475                         icalproperty_free(prop);
00476                 }
00477 
00478                 if (strlen(bstr("summary")) > 0) {
00479         
00480                         icalcomponent_add_property(vevent,
00481                                         icalproperty_new_summary(bstr("summary")));
00482                 } else {
00483                         icalcomponent_add_property(vevent,
00484                                         icalproperty_new_summary("Untitled Event"));
00485                 }
00486         
00487                 while (prop = icalcomponent_get_first_property(vevent,
00488                                         ICAL_LOCATION_PROPERTY), prop != NULL) {
00489                         icalcomponent_remove_property(vevent, prop);
00490                         icalproperty_free(prop);
00491                 }
00492                 if (strlen(bstr("location")) > 0) {
00493                         icalcomponent_add_property(vevent,
00494                                         icalproperty_new_location(bstr("location")));
00495                 }
00496                 while (prop = icalcomponent_get_first_property(vevent,
00497                                   ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
00498                         icalcomponent_remove_property(vevent, prop);
00499                         icalproperty_free(prop);
00500                 }
00501                 if (strlen(bstr("description")) > 0) {
00502                         icalcomponent_add_property(vevent,
00503                                 icalproperty_new_description(bstr("description")));
00504                 }
00505 
00506                 while (prop = icalcomponent_get_first_property(vevent,
00507                       ICAL_DTSTART_PROPERTY), prop != NULL) {
00508                         icalcomponent_remove_property(vevent, prop);
00509                         icalproperty_free(prop);
00510                 }
00511 
00512                 if (!strcmp(bstr("alldayevent"), "yes")) {
00513                         all_day_event = 1;
00514                 }
00515                 else {
00516                         all_day_event = 0;
00517                 }
00518 
00519                 if (all_day_event) {
00520                         icaltime_from_webform_dateonly(&event_start, "dtstart");
00521                 }
00522                 else {
00523                         icaltime_from_webform(&event_start, "dtstart");
00524                 }
00525 
00534                 prop = icalproperty_new_dtstart(event_start);
00535                 if (all_day_event) {
00536                         icalproperty_set_value(prop,
00537                                 icalvalue_new_date(event_start)
00538                         );
00539                 }
00540 
00541                 if (prop) icalcomponent_add_property(vevent, prop);
00542                 else icalproperty_free(prop);
00543 
00544                 while (prop = icalcomponent_get_first_property(vevent,
00545                       ICAL_DTEND_PROPERTY), prop != NULL) {
00546                         icalcomponent_remove_property(vevent, prop);
00547                         icalproperty_free(prop);
00548                 }
00549                 while (prop = icalcomponent_get_first_property(vevent,
00550                       ICAL_DURATION_PROPERTY), prop != NULL) {
00551                         icalcomponent_remove_property(vevent, prop);
00552                         icalproperty_free(prop);
00553                 }
00554 
00555                 if (all_day_event == 0) {
00556                         icaltime_from_webform(&t, "dtend");     
00557                         icalcomponent_add_property(vevent,
00558                                 icalproperty_new_dtend(icaltime_normalize(t)
00559                                 )
00560                         );
00561                 }
00562 
00564                 if (strlen(bstr("transp")) > 0) {
00565                         if (!strcasecmp(bstr("transp"), "opaque")) {
00566                                 formtransp = ICAL_TRANSP_OPAQUE;
00567                         }
00568                         else if (!strcasecmp(bstr("transp"), "transparent")) {
00569                                 formtransp = ICAL_TRANSP_TRANSPARENT;
00570                         }
00571 
00572                         while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
00573                               (prop != NULL)) {
00574                                 icalcomponent_remove_property(vevent, prop);
00575                                 icalproperty_free(prop);
00576                         }
00577 
00578                         lprintf(9, "adding new property...\n");
00579                         icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
00580                         lprintf(9, "...added it.\n");
00581                 }
00582 
00584                 lprintf(9, "Give this event a UID if it doesn't have one.\n");
00585                 if (icalcomponent_get_first_property(vevent,
00586                    ICAL_UID_PROPERTY) == NULL) {
00587                         generate_uuid(buf);
00588                         icalcomponent_add_property(vevent,
00589                                 icalproperty_new_uid(buf)
00590                         );
00591                 }
00592 
00594                 lprintf(9, "Increment the sequence ID\n");
00595                 while (prop = icalcomponent_get_first_property(vevent,
00596                       ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
00597                         i = icalproperty_get_sequence(prop);
00598                         lprintf(9, "Sequence was %d\n", i);
00599                         if (i > sequence) sequence = i;
00600                         icalcomponent_remove_property(vevent, prop);
00601                         icalproperty_free(prop);
00602                 }
00603                 ++sequence;
00604                 lprintf(9, "New sequence is %d.  Adding...\n", sequence);
00605                 icalcomponent_add_property(vevent,
00606                         icalproperty_new_sequence(sequence)
00607                 );
00608                 
00613                 lprintf(9, "Setting the organizer...\n");
00614                 strcpy(buf, bstr("organizer"));
00615                 if ( (icalcomponent_get_first_property(vevent,
00616                    ICAL_ORGANIZER_PROPERTY) == NULL) 
00617                    && (strlen(buf) > 0) ) {
00618 
00620                         sprintf(organizer_string, "MAILTO:%s", buf);
00621                         icalcomponent_add_property(vevent,
00622                                 icalproperty_new_organizer(organizer_string)
00623                         );
00624 
00625                 }
00626 
00630                 lprintf(9, "Add any new attendees\n");
00631 
00632                 /* First, strip out the parenthesized partstats.  */
00633                 strcpy(form_attendees, bstr("attendees"));
00634                 stripout(form_attendees, '(', ')');
00635 
00636                 /* Next, change any commas to newlines, because we want newline-separated attendees. */
00637                 j = strlen(form_attendees);
00638                 for (i=0; i<j; ++i) {
00639                         if (form_attendees[i] == ',') {
00640                                 form_attendees[i] = '\n';
00641                                 while (isspace(form_attendees[i+1])) {
00642                                         strcpy(&form_attendees[i+1], &form_attendees[i+2]);
00643                                 }
00644                         }
00645                 }
00646 
00648                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
00649                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
00650                         striplt(buf);
00651                         if (strlen(buf) > 0) {
00652                                 lprintf(9, "Attendee: <%s>\n", buf);
00653                                 sprintf(attendee_string, "MAILTO:%s", buf);
00654                                 foundit = 0;
00655 
00656                                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
00657                                         if (!strcasecmp(attendee_string,
00658                                            icalproperty_get_attendee(attendee)))
00659                                                 ++foundit;
00660                                 }
00661 
00662 
00663                                 if (foundit == 0) {
00664                                         icalcomponent_add_property(vevent,
00665                                                 icalproperty_new_attendee(attendee_string)
00666                                         );
00667                                 }
00668                         }
00669                 }
00670 
00674 STARTOVER:      lprintf(9, "Remove unlisted attendees\n");
00675                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
00676                         strcpy(attendee_string, icalproperty_get_attendee(attendee));
00677                         if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
00678                                 strcpy(attendee_string, &attendee_string[7]);
00679                                 striplt(attendee_string);
00680                                 foundit = 0;
00681                                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
00682                                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
00683                                         striplt(buf);
00684                                         if (!strcasecmp(buf, attendee_string)) ++foundit;
00685                                 }
00686                                 if (foundit == 0) {
00687                                         icalcomponent_remove_property(vevent, attendee);
00688                                         icalproperty_free(attendee);
00689                                         goto STARTOVER;
00690                                 }
00691                         }
00692                 }
00693 
00701                 lprintf(9, "Encapsulating into full VCALENDAR component\n");
00702                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
00703 
00704                 /* Set the method to PUBLISH */
00705                 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
00706 
00708                 lprintf(9, "Serializing it for saving\n");
00709                 if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) {
00710                         serv_puts("ENT0 1|||4|||1|");
00711                         serv_getln(buf, sizeof buf);
00712                         if (buf[0] == '8') {
00713                                 serv_puts("Content-type: text/calendar");
00714                                 serv_puts("");
00715                                 serv_puts(icalcomponent_as_ical_string(encaps));
00716                                 serv_puts("000");
00717                         }
00718                         if ( (buf[0] == '8') || (buf[0] == '4') ) {
00719                                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00720                                         lprintf(9, "ENT0 REPLY: %s\n", buf);
00721                                 }
00722                         }
00723                         if (buf[0] == '2') {
00724                                 strcpy(WC->ImportantMessage, &buf[4]);
00725                         }
00726                         icalcomponent_free(encaps);
00727                 }
00728 
00730                 if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) {
00731 
00733                         check_attendee_availability(encaps);
00734 
00736                         display_edit_individual_event(encaps, msgnum);
00737 
00738                         icalcomponent_free(encaps);
00739                 }
00740 
00741         }
00742 
00746         lprintf(9, "Checking to see if we have to delete an old event\n");
00747         if ( (strlen(bstr("delete_button")) > 0) && (msgnum > 0L) ) {
00748                 serv_printf("DELE %ld", atol(bstr("msgnum")));
00749                 serv_getln(buf, sizeof buf);
00750         }
00751 
00752         if (created_new_vevent) {
00753                 icalcomponent_free(vevent);
00754         }
00755 
00757         if (strlen(bstr("check_button")) == 0) {
00758                 readloop("readfwd");
00759         }
00760 }
00761 
00762 
00763 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */
00764 

Generated on Wed Jun 20 23:13:07 2007 for webcit by  doxygen 1.5.2