5 * \defgroup MiscCal Miscellaneous functions which handle calendar components.
10 #include "webserver.h"
14 "12am", "1am", "2am", "3am", "4am", "5am", "6am",
15 "7am", "8am", "9am", "10am", "11am", "12pm",
16 "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
17 "7pm", "8pm", "9pm", "10pm", "11pm"
20 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
23 * \brief display and edit date/time
24 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
25 * handle the display and editing of date/time properties in web pages. The
26 * first one converts an icaltimetype into valid HTML markup -- a series of form
27 * fields for editing the date and time. When the user submits the form, the
28 * results can be fed back into the second function, which turns it back into
29 * an icaltimetype. The "prefix" string required by both functions is prepended
30 * to all field names. This allows a form to contain more than one date/time
31 * property (for example, a start and end time) by ensuring the field names are
32 * unique within the form.
34 * \todo NOTE: These functions assume that the icaltimetype being edited is in UTC, and
35 * will convert to/from local time for editing. "local" in this case is assumed
36 * to be the time zone in which the WebCit server is running. A future improvement
37 * might be to allow the user to specify his/her timezone.
38 * \param t the time we want to parse
39 * \param prefix ???? \todo
43 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
51 int all_day_event = 0;
52 time_t monthselect_time;
53 struct tm monthselect_tm;
54 char monthselect_str[32];
55 char calhourformat[16];
57 get_preference("calhourformat", calhourformat, sizeof calhourformat);
60 localtime_r(&now, &tm_now);
61 this_year = tm_now.tm_year + 1900;
63 if (t == NULL) return;
64 if (t->is_date) all_day_event = 1;
65 tt = icaltime_as_timet(*t);
70 localtime_r(&tt, &tm);
73 wprintf(_("Month: "));
74 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
75 for (i=0; i<=11; ++i) {
76 monthselect_time = 1137997451 + (i * 2592000);
77 localtime_r(&monthselect_time, &monthselect_tm);
78 wc_strftime(monthselect_str, sizeof monthselect_str, "%B", &monthselect_tm);
79 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
80 ((tm.tm_mon == i) ? "SELECTED" : ""),
85 wprintf("</SELECT>\n");
88 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
89 for (i=1; i<=31; ++i) {
90 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
91 ((tm.tm_mday == i) ? "SELECTED" : ""),
95 wprintf("</SELECT>\n");
98 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
99 if ((this_year - t->year) > span) {
100 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
103 for (i=(this_year-span); i<=(this_year+span); ++i) {
104 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
105 ((t->year == i) ? "SELECTED" : ""),
109 if ((t->year - this_year) > span) {
110 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
113 wprintf("</SELECT>\n");
115 wprintf(_("Hour: "));
116 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
117 for (i=0; i<=23; ++i) {
119 if (!strcasecmp(calhourformat, "24")) {
120 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
121 ((tm.tm_hour == i) ? "SELECTED" : ""),
126 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
127 ((tm.tm_hour == i) ? "SELECTED" : ""),
133 wprintf("</SELECT>\n");
135 wprintf(_("Minute: "));
136 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
137 for (i=0; i<=59; ++i) {
138 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
139 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
140 ((tm.tm_min == i) ? "SELECTED" : ""),
145 wprintf("</SELECT>\n");
149 *\brief Get time from form
150 * get the time back from the user and convert it into internal structs.
151 * \param t our time element
152 * \param prefix whats that\todo ????
154 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
158 struct icaltimetype t2;
161 localtime_r(&tt, &tm);
163 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
164 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
165 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
166 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
167 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
170 t2 = icaltime_from_timet(tt, 0);
171 memcpy(t, &t2, sizeof(struct icaltimetype));
175 *\brief Get time from form
176 * get the time back from the user and convert it into internal structs.
177 * \param t our time element
178 * \param prefix whats that\todo ????
181 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
184 memset(t, 0, sizeof(struct icaltimetype));
186 sprintf(vname, "%s_month", prefix); t->month = atoi(bstr(vname));
187 sprintf(vname, "%s_day", prefix); t->day = atoi(bstr(vname));
188 sprintf(vname, "%s_year", prefix); t->year = atoi(bstr(vname));
195 * \brief Render PAPSTAT
196 * Render a PARTSTAT parameter as a string (and put it in parentheses)
197 * \param buf the string to put it to
198 * \param attendee the attendee to textify
200 void partstat_as_string(char *buf, icalproperty *attendee) {
201 icalparameter *partstat_param;
202 icalparameter_partstat partstat;
204 strcpy(buf, _("(status unknown)"));
206 partstat_param = icalproperty_get_first_parameter(
208 ICAL_PARTSTAT_PARAMETER
210 if (partstat_param == NULL) {
214 partstat = icalparameter_get_partstat(partstat_param);
216 case ICAL_PARTSTAT_X:
219 case ICAL_PARTSTAT_NEEDSACTION:
220 strcpy(buf, _("(needs action)"));
222 case ICAL_PARTSTAT_ACCEPTED:
223 strcpy(buf, _("(accepted)"));
225 case ICAL_PARTSTAT_DECLINED:
226 strcpy(buf, _("(declined)"));
228 case ICAL_PARTSTAT_TENTATIVE:
229 strcpy(buf, _("(tenative)"));
231 case ICAL_PARTSTAT_DELEGATED:
232 strcpy(buf, _("(delegated)"));
234 case ICAL_PARTSTAT_COMPLETED:
235 strcpy(buf, _("(completed)"));
237 case ICAL_PARTSTAT_INPROCESS:
238 strcpy(buf, _("(in process)"));
240 case ICAL_PARTSTAT_NONE:
241 strcpy(buf, _("(none)"));
249 * Utility function to encapsulate a subcomponent into a full VCALENDAR
250 * \param subcomp the component to encapsulate
251 * \returns the meta object ???
253 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
254 icalcomponent *encaps;
256 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
258 if (subcomp == NULL) {
259 lprintf(3, "ERROR: called with NULL argument!\n");
264 * If we're already looking at a full VCALENDAR component,
265 * don't bother ... just return itself.
267 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
271 /** Encapsulate the VEVENT component into a complete VCALENDAR */
272 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
273 if (encaps == NULL) {
274 lprintf(3, "%s:%d: Error - could not allocate component!\n",
279 /** Set the Product ID */
280 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
282 /** Set the Version Number */
283 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
285 /** Encapsulate the subcomponent inside */
286 /* lprintf(9, "Doing the encapsulation\n"); */
287 icalcomponent_add_component(encaps, subcomp);
289 /** Convert all timestamps to UTC so we don't have to deal with
290 * stupid VTIMEZONE crap.
292 ical_dezonify(encaps);
294 /** Return the object we just created. */