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 char calhourformat[16];
54 get_preference("calhourformat", calhourformat, sizeof calhourformat);
57 localtime_r(&now, &tm_now);
58 this_year = tm_now.tm_year + 1900;
60 if (t == NULL) return;
61 if (t->is_date) all_day_event = 1;
62 tt = icaltime_as_timet(*t);
67 localtime_r(&tt, &tm);
70 wprintf(_("Month: "));
71 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
72 for (i=0; i<=11; ++i) {
73 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
74 ((tm.tm_mon == i) ? "SELECTED" : ""),
79 wprintf("</SELECT>\n");
82 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
83 for (i=1; i<=31; ++i) {
84 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
85 ((tm.tm_mday == i) ? "SELECTED" : ""),
89 wprintf("</SELECT>\n");
92 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
93 if ((this_year - t->year) > span) {
94 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
97 for (i=(this_year-span); i<=(this_year+span); ++i) {
98 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
99 ((t->year == i) ? "SELECTED" : ""),
103 if ((t->year - this_year) > span) {
104 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
107 wprintf("</SELECT>\n");
109 wprintf(_("Hour: "));
110 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
111 for (i=0; i<=23; ++i) {
113 if (!strcasecmp(calhourformat, "24")) {
114 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
115 ((tm.tm_hour == i) ? "SELECTED" : ""),
120 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
121 ((tm.tm_hour == i) ? "SELECTED" : ""),
127 wprintf("</SELECT>\n");
129 wprintf(_("Minute: "));
130 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
131 for (i=0; i<=59; ++i) {
132 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
133 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
134 ((tm.tm_min == i) ? "SELECTED" : ""),
139 wprintf("</SELECT>\n");
143 *\brief Get time from form
144 * get the time back from the user and convert it into internal structs.
145 * \param t our time element
146 * \param prefix whats that\todo ????
148 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
152 struct icaltimetype t2;
155 localtime_r(&tt, &tm);
157 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
158 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
159 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
160 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
161 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
164 t2 = icaltime_from_timet(tt, 0);
165 memcpy(t, &t2, sizeof(struct icaltimetype));
169 *\brief Get time from form
170 * get the time back from the user and convert it into internal structs.
171 * \param t our time element
172 * \param prefix whats that\todo ????
175 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
178 memset(t, 0, sizeof(struct icaltimetype));
180 sprintf(vname, "%s_month", prefix); t->month = atoi(bstr(vname));
181 sprintf(vname, "%s_day", prefix); t->day = atoi(bstr(vname));
182 sprintf(vname, "%s_year", prefix); t->year = atoi(bstr(vname));
189 * \brief Render PAPSTAT
190 * Render a PARTSTAT parameter as a string (and put it in parentheses)
191 * \param buf the string to put it to
192 * \param attendee the attendee to textify
194 void partstat_as_string(char *buf, icalproperty *attendee) {
195 icalparameter *partstat_param;
196 icalparameter_partstat partstat;
198 strcpy(buf, _("(status unknown)"));
200 partstat_param = icalproperty_get_first_parameter(
202 ICAL_PARTSTAT_PARAMETER
204 if (partstat_param == NULL) {
208 partstat = icalparameter_get_partstat(partstat_param);
210 case ICAL_PARTSTAT_X:
213 case ICAL_PARTSTAT_NEEDSACTION:
214 strcpy(buf, _("(needs action)"));
216 case ICAL_PARTSTAT_ACCEPTED:
217 strcpy(buf, _("(accepted)"));
219 case ICAL_PARTSTAT_DECLINED:
220 strcpy(buf, _("(declined)"));
222 case ICAL_PARTSTAT_TENTATIVE:
223 strcpy(buf, _("(tenative)"));
225 case ICAL_PARTSTAT_DELEGATED:
226 strcpy(buf, _("(delegated)"));
228 case ICAL_PARTSTAT_COMPLETED:
229 strcpy(buf, _("(completed)"));
231 case ICAL_PARTSTAT_INPROCESS:
232 strcpy(buf, _("(in process)"));
234 case ICAL_PARTSTAT_NONE:
235 strcpy(buf, _("(none)"));
243 * Utility function to encapsulate a subcomponent into a full VCALENDAR
244 * \param subcomp the component to encapsulate
245 * \returns the meta object ???
247 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
248 icalcomponent *encaps;
250 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
252 if (subcomp == NULL) {
253 lprintf(3, "ERROR: called with NULL argument!\n");
258 * If we're already looking at a full VCALENDAR component,
259 * don't bother ... just return itself.
261 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
265 /** Encapsulate the VEVENT component into a complete VCALENDAR */
266 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
267 if (encaps == NULL) {
268 lprintf(3, "%s:%d: Error - could not allocate component!\n",
273 /** Set the Product ID */
274 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
276 /** Set the Version Number */
277 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
279 /** Encapsulate the subcomponent inside */
280 /* lprintf(9, "Doing the encapsulation\n"); */
281 icalcomponent_add_component(encaps, subcomp);
283 /** Convert all timestamps to UTC so we don't have to deal with
284 * stupid VTIMEZONE crap.
286 ical_dezonify(encaps);
288 /** Return the object we just created. */