4 * Miscellaneous functions which handle calendar components.
12 "12am", "1am", "2am", "3am", "4am", "5am", "6am",
13 "7am", "8am", "9am", "10am", "11am", "12pm",
14 "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
15 "7pm", "8pm", "9pm", "10pm", "11pm"
19 * \brief display and edit date/time
20 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
21 * handle the display and editing of date/time properties in web pages. The
22 * first one converts an icaltimetype into valid HTML markup -- a series of form
23 * fields for editing the date and time. When the user submits the form, the
24 * results can be fed back into the second function, which turns it back into
25 * an icaltimetype. The "prefix" string required by both functions is prepended
26 * to all field names. This allows a form to contain more than one date/time
27 * property (for example, a start and end time) by ensuring the field names are
28 * unique within the form.
30 * \todo NOTE: These functions assume that the icaltimetype being edited is in UTC, and
31 * will convert to/from local time for editing. "local" in this case is assumed
32 * to be the time zone in which the WebCit server is running. A future improvement
33 * might be to allow the user to specify his/her timezone.
34 * \param t the time we want to parse
35 * \param prefix ???? \todo
39 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
47 int all_day_event = 0;
48 time_t monthselect_time;
49 struct tm monthselect_tm;
50 char monthselect_str[32];
53 time_format = get_time_format_cached ();
56 localtime_r(&now, &tm_now);
57 this_year = tm_now.tm_year + 1900;
59 if (t == NULL) return;
60 if (t->is_date) all_day_event = 1;
61 tt = icaltime_as_timet(*t);
66 localtime_r(&tt, &tm);
69 wprintf(_("Month: "));
70 wprintf("<SELECT NAME=\"%s_month\" SIZE=\"1\">\n", prefix);
71 for (i=0; i<=11; ++i) {
72 monthselect_time = 1137997451 + (i * 2592000);
73 localtime_r(&monthselect_time, &monthselect_tm);
74 wc_strftime(monthselect_str, sizeof monthselect_str, "%B", &monthselect_tm);
75 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
76 ((tm.tm_mon == i) ? "SELECTED" : ""),
81 wprintf("</SELECT>\n");
84 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
85 for (i=1; i<=31; ++i) {
86 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
87 ((tm.tm_mday == i) ? "SELECTED" : ""),
91 wprintf("</SELECT>\n");
94 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
95 if ((this_year - t->year) > span) {
96 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
99 for (i=(this_year-span); i<=(this_year+span); ++i) {
100 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
101 ((t->year == i) ? "SELECTED" : ""),
105 if ((t->year - this_year) > span) {
106 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
109 wprintf("</SELECT>\n");
111 wprintf(_("Hour: "));
112 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
113 for (i=0; i<=23; ++i) {
115 if (time_format == WC_TIMEFORMAT_24) {
116 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
117 ((tm.tm_hour == i) ? "SELECTED" : ""),
122 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
123 ((tm.tm_hour == i) ? "SELECTED" : ""),
129 wprintf("</SELECT>\n");
131 wprintf(_("Minute: "));
132 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
133 for (i=0; i<=59; ++i) {
134 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
135 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
136 ((tm.tm_min == i) ? "SELECTED" : ""),
141 wprintf("</SELECT>\n");
145 *\brief Get time from form
146 * get the time back from the user and convert it into internal structs.
147 * \param t our time element
148 * \param prefix whats that\todo ????
150 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
152 struct icaltimetype t2;
154 int month, mday, year, hour, minute;
156 sprintf(vname, "%s_month", prefix); month = atoi(bstr(vname));
157 sprintf(vname, "%s_day", prefix); mday = atoi(bstr(vname));
158 sprintf(vname, "%s_year", prefix); year = atoi(bstr(vname));
159 sprintf(vname, "%s_hour", prefix); hour = atoi(bstr(vname));
160 sprintf(vname, "%s_minute", prefix); minute = atoi(bstr(vname));
162 sprintf(timestr, "%04d%02d%02dT%02d%02d00", year, month, mday, hour, minute);
163 t2 = icaltime_from_string(timestr);
164 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. */