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"
42 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
43 * handle the display and editing of date/time properties in web pages. The
44 * first one converts an icaltimetype into valid HTML markup -- a series of form
45 * fields for editing the date and time. When the user submits the form, the
46 * results can be fed back into the second function, which turns it back into
47 * an icaltimetype. The "prefix" string required by both functions is prepended
48 * to all field names. This allows a form to contain more than one date/time
49 * property (for example, a start and end time) by ensuring the field names are
50 * unique within the form.
52 * NOTE: These functions assume that the icaltimetype being edited is in UTC, and
53 * will convert to/from local time for editing. "local" in this case is assumed
54 * to be the time zone in which the WebCit server is running. A future improvement
55 * might be to allow the user to specify his/her timezone.
59 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
72 tm_now = localtime(&now);
73 this_year = tm_now->tm_year + 1900;
75 if (t == NULL) return;
76 tt = icaltime_as_timet(*t);
80 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
81 for (i=0; i<=11; ++i) {
82 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
83 ((tm->tm_mon == i) ? "SELECTED" : ""),
88 wprintf("</SELECT>\n");
91 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
92 for (i=1; i<=31; ++i) {
93 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
94 ((tm->tm_mday == i) ? "SELECTED" : ""),
98 wprintf("</SELECT>\n");
101 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
102 if ((this_year - t->year) > span) {
103 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
106 for (i=(this_year-span); i<=(this_year+span); ++i) {
107 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
108 ((t->year == i) ? "SELECTED" : ""),
112 if ((t->year - this_year) > span) {
113 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
116 wprintf("</SELECT>\n");
119 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
120 for (i=0; i<=23; ++i) {
121 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
122 ((tm->tm_hour == i) ? "SELECTED" : ""),
126 wprintf("</SELECT>\n");
129 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
130 for (i=0; i<=59; ++i) {
131 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
132 ((tm->tm_min == i) ? "SELECTED" : ""),
136 wprintf("</SELECT>\n");
140 struct icaltimetype icaltime_from_webform(char *prefix) {
141 struct icaltimetype t;
147 memcpy(&tm, localtime(&tt), sizeof(struct tm));
149 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
150 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
151 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
152 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
153 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
156 t = icaltime_from_timet(tt, 0);
157 t = icaltime_normalize(t);
163 * Generae a new, globally unique UID parameter for a calendar object.
165 void generate_new_uid(char *buf) {
168 sprintf(buf, "%ld-%d@%s",
171 serv_info.serv_fqdn);