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