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