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"
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) {
79 memcpy(&tm_now, localtime(&now), sizeof(struct tm));
80 this_year = tm_now.tm_year + 1900;
82 if (t == NULL) return;
83 tt = icaltime_as_timet(*t);
84 memcpy(&tm, localtime(&tt), sizeof(struct tm));
87 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
88 for (i=0; i<=11; ++i) {
89 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
90 ((tm.tm_mon == i) ? "SELECTED" : ""),
95 wprintf("</SELECT>\n");
98 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
99 for (i=1; i<=31; ++i) {
100 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
101 ((tm.tm_mday == i) ? "SELECTED" : ""),
105 wprintf("</SELECT>\n");
108 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
109 if ((this_year - t->year) > span) {
110 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
113 for (i=(this_year-span); i<=(this_year+span); ++i) {
114 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
115 ((t->year == i) ? "SELECTED" : ""),
119 if ((t->year - this_year) > span) {
120 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
123 wprintf("</SELECT>\n");
126 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
127 for (i=0; i<=23; ++i) {
128 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
129 ((tm.tm_hour == i) ? "SELECTED" : ""),
133 wprintf("</SELECT>\n");
136 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
137 for (i=0; i<=59; ++i) {
138 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
139 ((tm.tm_min == i) ? "SELECTED" : ""),
143 wprintf("</SELECT>\n");
147 struct icaltimetype icaltime_from_webform(char *prefix) {
148 struct icaltimetype t;
154 memcpy(&tm, localtime(&tt), sizeof(struct tm));
156 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
157 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
158 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
159 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
160 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
163 t = icaltime_from_timet(tt, 0);
164 t = icaltime_normalize(t);
170 * Generae a new, globally unique UID parameter for a calendar object.
172 void generate_new_uid(char *buf) {
175 sprintf(buf, "%ld-%d@%s",
178 serv_info.serv_fqdn);