]> code.citadel.org Git - citadel.git/blob - webcit/event.c
d9ae239f8da0a4c30fb59ee4ab8d0b52e495a0b5
[citadel.git] / webcit / event.c
1 /*
2  * $Id$
3  *
4  * Editing calendar events.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include <time.h>
27 #include "webcit.h"
28 #include "webserver.h"
29
30
31 #ifdef HAVE_ICAL_H
32
33
34 /*
35  * Display an event by itself (for editing)
36  */
37 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
38         icalcomponent *vevent;
39         icalproperty *p;
40         struct icaltimetype t;
41         time_t now;
42         int created_new_vevent = 0;
43
44         now = time(NULL);
45
46         if (supplied_vevent != NULL) {
47                 vevent = supplied_vevent;
48         }
49         else {
50                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
51                 created_new_vevent = 1;
52         }
53
54         output_headers(3);
55         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
56                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
57                 "<B>Edit event</B>"
58                 "</FONT></TD></TR></TABLE><BR>\n"
59         );
60
61         wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_event\">\n");
62         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
63                 msgnum);
64         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
65                 bstr("calview"));
66         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
67                 bstr("year"));
68         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
69                 bstr("month"));
70         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
71                 bstr("day"));
72
73         wprintf("Summary: "
74                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
75                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
76         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
77         if (p != NULL) {
78                 escputs((char *)icalproperty_get_comment(p));
79         }
80         wprintf("\"><BR>\n");
81
82         wprintf("Start date/time: ");
83         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
84         if (p != NULL) {
85                 t = icalproperty_get_dtstart(p);
86         }
87         else {
88                 t = icaltime_from_timet(now, 0);
89         }
90         display_icaltimetype_as_webform(&t, "dtstart");
91         wprintf("<BR>\n");
92
93         wprintf("End date/time: ");
94         p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
95         if (p != NULL) {
96                 t = icalproperty_get_dtend(p);
97         }
98         else {
99                 t = icaltime_from_timet(now, 0);
100         }
101         display_icaltimetype_as_webform(&t, "dtend");
102         wprintf("<BR>\n");
103
104         wprintf("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
105                 "ROWS=10 COLS=80 WIDTH=80>\n"
106         );
107         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
108         if (p != NULL) {
109                 escputs((char *)icalproperty_get_comment(p));
110         }
111         wprintf("</TEXTAREA><BR>\n");
112
113         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
114                 "&nbsp;&nbsp;"
115                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
116                 "&nbsp;&nbsp;"
117                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
118                 "</CENTER>\n"
119         );
120
121         wprintf("</FORM>\n");
122
123         wDumpContent(1);
124
125         if (created_new_vevent) {
126                 icalcomponent_free(vevent);
127         }
128 }
129
130 /*
131  * Save an edited event
132  */
133 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
134         char buf[SIZ];
135         int delete_existing = 0;
136         icalproperty *prop;
137         icalcomponent *vevent;
138         int created_new_vevent = 0;
139
140         if (supplied_vevent != NULL) {
141                 vevent = supplied_vevent;
142         }
143         else {
144                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
145                 created_new_vevent = 1;
146         }
147
148         if (!strcasecmp(bstr("sc"), "Save")) {
149
150                 /* Replace values in the component with ones from the form */
151
152                 while (prop = icalcomponent_get_first_property(vevent,
153                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
154                         icalcomponent_remove_property(vevent, prop);
155                 }
156                 icalcomponent_add_property(vevent,
157                         icalproperty_new_summary(bstr("summary")));
158                 
159                 while (prop = icalcomponent_get_first_property(vevent,
160                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
161                         icalcomponent_remove_property(vevent, prop);
162                 }
163                 icalcomponent_add_property(vevent,
164                         icalproperty_new_description(bstr("description")));
165         
166                 while (prop = icalcomponent_get_first_property(vevent,
167                       ICAL_DTSTART_PROPERTY), prop != NULL) {
168                         icalcomponent_remove_property(vevent, prop);
169                 }
170                 icalcomponent_add_property(vevent,
171                         icalproperty_new_dtstart(
172                                 icaltime_from_webform("dtstart")
173                         )
174                 );
175         
176                 while (prop = icalcomponent_get_first_property(vevent,
177                       ICAL_DUE_PROPERTY), prop != NULL) {
178                         icalcomponent_remove_property(vevent, prop);
179                 }
180                 icalcomponent_add_property(vevent,
181                         icalproperty_new_due(
182                                 icaltime_from_webform("due")
183                         )
184                 );
185         
186                 /* Serialize it and save it to the message base */
187                 serv_puts("ENT0 1|||4");
188                 serv_gets(buf);
189                 if (buf[0] == '4') {
190                         serv_puts("Content-type: text/calendar");
191                         serv_puts("");
192                         serv_puts(icalcomponent_as_ical_string(vevent));
193                         serv_puts("000");
194                         delete_existing = 1;
195                 }
196         }
197
198         /*
199          * If the user clicked 'Delete' then delete it, period.
200          */
201         if (!strcasecmp(bstr("sc"), "Delete")) {
202                 delete_existing = 1;
203         }
204
205         if ( (delete_existing) && (msgnum > 0L) ) {
206                 serv_printf("DELE %ld", atol(bstr("msgnum")));
207                 serv_gets(buf);
208         }
209
210         if (created_new_vevent) {
211                 icalcomponent_free(vevent);
212         }
213
214         /* Go back to the event list */
215         readloop("readfwd");
216 }
217
218
219 #endif /* HAVE_ICAL_H */