]> code.citadel.org Git - citadel.git/blob - webcit/event.c
* minor cleanup
[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("UID == ");
62         p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
63         if (p != NULL) {
64                 escputs((char *)icalproperty_get_comment(p));
65         }
66         wprintf(" (FIXME remove this when done)<BR>\n");
67
68         wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_event\">\n");
69         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
70                 msgnum);
71         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
72                 bstr("calview"));
73         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
74                 bstr("year"));
75         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
76                 bstr("month"));
77         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
78                 bstr("day"));
79
80         /* Put it in a borderless table so it lines up nicely */
81         wprintf("<TABLE border=0 width=100%%>\n");
82
83         wprintf("<TR><TD><B>Summary</B></TD><TD>\n"
84                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
85                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
86         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
87         if (p != NULL) {
88                 escputs((char *)icalproperty_get_comment(p));
89         }
90         wprintf("\"></TD></TR>\n");
91
92         wprintf("<TR><TD><B>Location</B></TD><TD>\n"
93                 "<INPUT TYPE=\"text\" NAME=\"location\" "
94                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
95         p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
96         if (p != NULL) {
97                 escputs((char *)icalproperty_get_comment(p));
98         }
99         wprintf("\"></TD></TR>\n");
100
101         wprintf("<TR><TD><B>Start</B></TD><TD>\n");
102         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
103         if (p != NULL) {
104                 t = icalproperty_get_dtstart(p);
105         }
106         else {
107                 t = icaltime_from_timet(now, 0);
108         }
109         display_icaltimetype_as_webform(&t, "dtstart");
110         wprintf("</TD></TR>\n");
111
112         wprintf("<TR><TD><B>End</B></TD><TD>\n");
113         p = icalcomponent_get_first_property(vevent, ICAL_DTEND_PROPERTY);
114         if (p != NULL) {
115                 t = icalproperty_get_dtend(p);
116         }
117         else {
118                 t = icaltime_from_timet(now, 0);
119         }
120         display_icaltimetype_as_webform(&t, "dtend");
121         wprintf("</TD></TR>\n");
122
123         wprintf("<TR><TD><B>Notes</B></TD><TD>\n"
124                 "<TEXTAREA NAME=\"description\" wrap=soft "
125                 "ROWS=10 COLS=80 WIDTH=80>\n"
126         );
127         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
128         if (p != NULL) {
129                 escputs((char *)icalproperty_get_comment(p));
130         }
131         wprintf("</TEXTAREA></TD></TR></TABLE>\n");
132
133         wprintf("<CENTER>"
134                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
135                 "&nbsp;&nbsp;"
136                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
137                 "&nbsp;&nbsp;"
138                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
139                 "</CENTER>\n"
140         );
141
142         wprintf("</FORM>\n");
143
144         wDumpContent(1);
145
146         if (created_new_vevent) {
147                 icalcomponent_free(vevent);
148         }
149 }
150
151 /*
152  * Save an edited event
153  */
154 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
155         char buf[SIZ];
156         int delete_existing = 0;
157         icalproperty *prop;
158         icalcomponent *vevent;
159         int created_new_vevent = 0;
160
161         if (supplied_vevent != NULL) {
162                 vevent = supplied_vevent;
163         }
164         else {
165                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
166                 created_new_vevent = 1;
167         }
168
169         if (!strcasecmp(bstr("sc"), "Save")) {
170
171                 /* Replace values in the component with ones from the form */
172
173                 while (prop = icalcomponent_get_first_property(vevent,
174                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
175                         icalcomponent_remove_property(vevent, prop);
176                 }
177                 icalcomponent_add_property(vevent,
178                         icalproperty_new_summary(bstr("summary")));
179                 
180                 while (prop = icalcomponent_get_first_property(vevent,
181                       ICAL_LOCATION_PROPERTY), prop != NULL) {
182                         icalcomponent_remove_property(vevent, prop);
183                 }
184                 icalcomponent_add_property(vevent,
185                         icalproperty_new_location(bstr("location")));
186                 
187                 while (prop = icalcomponent_get_first_property(vevent,
188                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
189                         icalcomponent_remove_property(vevent, prop);
190                 }
191                 icalcomponent_add_property(vevent,
192                         icalproperty_new_description(bstr("description")));
193         
194                 while (prop = icalcomponent_get_first_property(vevent,
195                       ICAL_DTSTART_PROPERTY), prop != NULL) {
196                         icalcomponent_remove_property(vevent, prop);
197                 }
198                 icalcomponent_add_property(vevent,
199                         icalproperty_new_dtstart(
200                                 icaltime_from_webform("dtstart")
201                         )
202                 );
203         
204                 while (prop = icalcomponent_get_first_property(vevent,
205                       ICAL_DUE_PROPERTY), prop != NULL) {
206                         icalcomponent_remove_property(vevent, prop);
207                 }
208                 icalcomponent_add_property(vevent,
209                         icalproperty_new_due(
210                                 icaltime_from_webform("due")
211                         )
212                 );
213
214                 /* Give this event a UID if it doesn't have one. */
215                 if (icalcomponent_get_first_property(vevent,
216                    ICAL_UID_PROPERTY) == NULL) {
217                         generate_new_uid(buf);
218                         icalcomponent_add_property(vevent,
219                                 icalproperty_new_uid(buf)
220                         );
221                 }
222         
223                 /* Serialize it and save it to the message base */
224                 serv_puts("ENT0 1|||4");
225                 serv_gets(buf);
226                 if (buf[0] == '4') {
227                         serv_puts("Content-type: text/calendar");
228                         serv_puts("");
229                         serv_puts(icalcomponent_as_ical_string(vevent));
230                         serv_puts("000");
231                         delete_existing = 1;
232                 }
233         }
234
235         /*
236          * If the user clicked 'Delete' then delete it, period.
237          */
238         if (!strcasecmp(bstr("sc"), "Delete")) {
239                 delete_existing = 1;
240         }
241
242         if ( (delete_existing) && (msgnum > 0L) ) {
243                 serv_printf("DELE %ld", atol(bstr("msgnum")));
244                 serv_gets(buf);
245         }
246
247         if (created_new_vevent) {
248                 icalcomponent_free(vevent);
249         }
250
251         /* Go back to the event list */
252         readloop("readfwd");
253 }
254
255
256 #endif /* HAVE_ICAL_H */