]> code.citadel.org Git - citadel.git/blob - webcit/event.c
70d9a64030fda3055d5d9fd9cd6d5946c5b23aa0
[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: ");
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("<CENTER><TEXTAREA NAME=\"description\" wrap=soft "
94                 "ROWS=10 COLS=80 WIDTH=80>\n"
95         );
96         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
97         if (p != NULL) {
98                 escputs((char *)icalproperty_get_comment(p));
99         }
100         wprintf("</TEXTAREA><BR>\n");
101
102         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
103                 "&nbsp;&nbsp;"
104                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
105                 "&nbsp;&nbsp;"
106                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
107                 "</CENTER>\n"
108         );
109
110         wprintf("</FORM>\n");
111
112         wDumpContent(1);
113
114         if (created_new_vevent) {
115                 icalcomponent_free(vevent);
116         }
117 }
118
119 /*
120  * Save an edited event
121  */
122 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
123         char buf[SIZ];
124         int delete_existing = 0;
125         icalproperty *prop;
126         icalcomponent *vevent;
127         int created_new_vevent = 0;
128
129         if (supplied_vevent != NULL) {
130                 vevent = supplied_vevent;
131         }
132         else {
133                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
134                 created_new_vevent = 1;
135         }
136
137         if (!strcasecmp(bstr("sc"), "Save")) {
138
139                 /* Replace values in the component with ones from the form */
140
141                 while (prop = icalcomponent_get_first_property(vevent,
142                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
143                         icalcomponent_remove_property(vevent, prop);
144                 }
145                 icalcomponent_add_property(vevent,
146                         icalproperty_new_summary(bstr("summary")));
147                 
148                 while (prop = icalcomponent_get_first_property(vevent,
149                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
150                         icalcomponent_remove_property(vevent, prop);
151                 }
152                 icalcomponent_add_property(vevent,
153                         icalproperty_new_description(bstr("description")));
154         
155                 while (prop = icalcomponent_get_first_property(vevent,
156                       ICAL_DTSTART_PROPERTY), prop != NULL) {
157                         icalcomponent_remove_property(vevent, prop);
158                 }
159                 icalcomponent_add_property(vevent,
160                         icalproperty_new_dtstart(
161                                 icaltime_from_webform("dtstart")
162                         )
163                 );
164         
165                 while (prop = icalcomponent_get_first_property(vevent,
166                       ICAL_DUE_PROPERTY), prop != NULL) {
167                         icalcomponent_remove_property(vevent, prop);
168                 }
169                 icalcomponent_add_property(vevent,
170                         icalproperty_new_due(
171                                 icaltime_from_webform("due")
172                         )
173                 );
174         
175                 /* Serialize it and save it to the message base */
176                 serv_puts("ENT0 1|||4");
177                 serv_gets(buf);
178                 if (buf[0] == '4') {
179                         serv_puts("Content-type: text/calendar");
180                         serv_puts("");
181                         serv_puts(icalcomponent_as_ical_string(vevent));
182                         serv_puts("000");
183                         delete_existing = 1;
184                 }
185         }
186
187         /*
188          * If the user clicked 'Delete' then delete it, period.
189          */
190         if (!strcasecmp(bstr("sc"), "Delete")) {
191                 delete_existing = 1;
192         }
193
194         if ( (delete_existing) && (msgnum > 0L) ) {
195                 serv_printf("DELE %ld", atol(bstr("msgnum")));
196                 serv_gets(buf);
197         }
198
199         if (created_new_vevent) {
200                 icalcomponent_free(vevent);
201         }
202
203         /* Go back to the event list */
204         readloop("readfwd");
205 }
206
207
208 #endif /* HAVE_ICAL_H */