13 #include <sys/types.h>
15 #include <sys/socket.h>
17 #include <netinet/in.h>
27 #include "webserver.h"
30 "January", "February", "March", "April", "May", "June", "July",
31 "August", "September", "October", "November", "December"
35 "Sunday", "Monday", "Tuesday", "Wednesday",
36 "Thursday", "Friday", "Saturday"
40 "12am", "1am", "2am", "3am", "4am", "5am", "6am",
41 "7am", "8am", "9am", "10am", "11am", "12pm",
42 "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
43 "7pm", "8pm", "9pm", "10pm", "11pm"
46 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
49 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
50 * handle the display and editing of date/time properties in web pages. The
51 * first one converts an icaltimetype into valid HTML markup -- a series of form
52 * fields for editing the date and time. When the user submits the form, the
53 * results can be fed back into the second function, which turns it back into
54 * an icaltimetype. The "prefix" string required by both functions is prepended
55 * to all field names. This allows a form to contain more than one date/time
56 * property (for example, a start and end time) by ensuring the field names are
57 * unique within the form.
59 * NOTE: These functions assume that the icaltimetype being edited is in UTC, and
60 * will convert to/from local time for editing. "local" in this case is assumed
61 * to be the time zone in which the WebCit server is running. A future improvement
62 * might be to allow the user to specify his/her timezone.
66 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
74 int all_day_event = 0;
77 localtime_r(&now, &tm_now);
78 this_year = tm_now.tm_year + 1900;
80 if (t == NULL) return;
81 if (t->is_date) all_day_event = 1;
82 tt = icaltime_as_timet(*t);
87 localtime_r(&tt, &tm);
91 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
92 for (i=0; i<=11; ++i) {
93 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
94 ((tm.tm_mon == i) ? "SELECTED" : ""),
99 wprintf("</SELECT>\n");
102 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
103 for (i=1; i<=31; ++i) {
104 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
105 ((tm.tm_mday == i) ? "SELECTED" : ""),
109 wprintf("</SELECT>\n");
112 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
113 if ((this_year - t->year) > span) {
114 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
117 for (i=(this_year-span); i<=(this_year+span); ++i) {
118 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
119 ((t->year == i) ? "SELECTED" : ""),
123 if ((t->year - this_year) > span) {
124 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
127 wprintf("</SELECT>\n");
130 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
131 for (i=0; i<=23; ++i) {
132 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
133 ((tm.tm_hour == i) ? "SELECTED" : ""),
137 wprintf("</SELECT>\n");
140 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
141 for (i=0; i<=59; ++i) {
142 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
143 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
144 ((tm.tm_min == i) ? "SELECTED" : ""),
149 wprintf("</SELECT>\n");
153 struct icaltimetype icaltime_from_webform(char *prefix) {
154 struct icaltimetype t;
160 localtime_r(&tt, &tm);
162 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
163 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
164 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
165 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
166 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
169 t = icaltime_from_timet(tt, 0);
170 t = icaltime_normalize(t);
176 * Render a PARTSTAT parameter as a string (and put it in parentheses)
178 void partstat_as_string(char *buf, icalproperty *attendee) {
179 icalparameter *partstat_param;
180 icalparameter_partstat partstat;
182 strcpy(buf, "(status unknown)");
184 partstat_param = icalproperty_get_first_parameter(
186 ICAL_PARTSTAT_PARAMETER
188 if (partstat_param == NULL) {
192 partstat = icalparameter_get_partstat(partstat_param);
194 case ICAL_PARTSTAT_X:
197 case ICAL_PARTSTAT_NEEDSACTION:
198 strcpy(buf, "(needs action)");
200 case ICAL_PARTSTAT_ACCEPTED:
201 strcpy(buf, "(accepted)");
203 case ICAL_PARTSTAT_DECLINED:
204 strcpy(buf, "(declined)");
206 case ICAL_PARTSTAT_TENTATIVE:
207 strcpy(buf, "(tenative)");
209 case ICAL_PARTSTAT_DELEGATED:
210 strcpy(buf, "(delegated)");
212 case ICAL_PARTSTAT_COMPLETED:
213 strcpy(buf, "(completed)");
215 case ICAL_PARTSTAT_INPROCESS:
216 strcpy(buf, "(in process)");
218 case ICAL_PARTSTAT_NONE:
219 strcpy(buf, "(none)");
226 * Utility function to encapsulate a subcomponent into a full VCALENDAR
228 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
229 icalcomponent *encaps;
231 lprintf(9, "ical_encapsulate_subcomponent() called\n");
233 if (subcomp == NULL) {
234 lprintf(3, "ERROR: called with NULL argument!\n");
238 /* If we're already looking at a full VCALENDAR component,
239 * don't bother ... just return itself.
241 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
242 lprintf(9, "Already encapsulated. Returning itself.\n");
246 /* Encapsulate the VEVENT component into a complete VCALENDAR */
247 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
248 if (encaps == NULL) {
249 lprintf(3, "Error at %s:%d - could not allocate component!\n",
254 /* Set the Product ID */
255 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
257 /* Set the Version Number */
258 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
260 /* Encapsulate the subcomponent inside */
261 lprintf(9, "Doing the encapsulation\n");
262 icalcomponent_add_component(encaps, subcomp);
264 /* Convert all timestamps to UTC so we don't have to deal with
265 * stupid VTIMEZONE crap.
267 ical_dezonify(encaps);
269 /* Return the object we just created. */