4 * Miscellaneous functions which handle calendar components.
13 "12am", "1am", "2am", "3am", "4am", "5am", "6am",
14 "7am", "8am", "9am", "10am", "11am", "12pm",
15 "1pm", "2pm", "3pm", "4pm", "5pm", "6pm",
16 "7pm", "8pm", "9pm", "10pm", "11pm"
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 * 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.
36 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
43 int all_day_event = 0;
47 time_format = get_time_format_cached ();
50 localtime_r(&now, &tm_now);
51 this_year = tm_now.tm_year + 1900;
53 if (t == NULL) return;
54 if (t->is_date) all_day_event = 1;
55 tt = icaltime_as_timet(*t);
60 localtime_r(&tt, &tm);
63 wprintf("<input type=\"text\" name=\"");
67 wprintf("\" value=\"");
68 wc_strftime(timebuf, 32, "%Y-%m-%d", &tm);
71 wprintf("<script type=\"text/javascript\">");
72 wprintf("attachDatePicker('");
74 wprintf("', '%s');\n", get_selected_language());
77 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
78 for (i=0; i<=23; ++i) {
80 if (time_format == WC_TIMEFORMAT_24) {
81 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
82 ((tm.tm_hour == i) ? "SELECTED" : ""),
87 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
88 ((tm.tm_hour == i) ? "SELECTED" : ""),
94 wprintf("</SELECT>\n");
96 wprintf(_("Minute: "));
97 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
98 for (i=0; i<=59; ++i) {
99 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
100 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
101 ((tm.tm_min == i) ? "SELECTED" : ""),
106 wprintf("</SELECT>\n");
111 * get the time back from the user and convert it into internal structs.
113 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
117 /* Stuff tm with some zero values */
126 struct icaltimetype t2;
129 strptime((char*)BSTR(prefix), "%Y-%m-%d", &tm);
130 sprintf(vname, "%s_hour", prefix); hour = IBSTR(vname);
131 sprintf(vname, "%s_minute", prefix); minute = IBSTR(vname);
134 strftime(&datebuf[0], 32, "%Y%m%dT%H%M%S", &tm);
135 t2 = icaltime_from_string(datebuf);
136 memcpy(t, &t2, sizeof(struct icaltimetype));
142 * get the time back from the user and convert it into internal structs.
144 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
146 /* Stuff tm with some zero values */
153 struct icaltimetype t2;
154 strptime((char *)BSTR(prefix), "%Y-%m-%d", &tm);
156 t2 = icaltime_from_timet(tm_t, 1);
157 memcpy(t, &t2, sizeof(struct icaltimetype));
162 * \brief Render PARTSTAT
163 * Render a PARTSTAT parameter as a string (and put it in parentheses)
164 * \param buf the string to put it to
165 * \param attendee the attendee to textify
167 void partstat_as_string(char *buf, icalproperty *attendee) {
168 icalparameter *partstat_param;
169 icalparameter_partstat partstat;
171 strcpy(buf, _("(status unknown)"));
173 partstat_param = icalproperty_get_first_parameter(
175 ICAL_PARTSTAT_PARAMETER
177 if (partstat_param == NULL) {
181 partstat = icalparameter_get_partstat(partstat_param);
183 case ICAL_PARTSTAT_X:
186 case ICAL_PARTSTAT_NEEDSACTION:
187 strcpy(buf, _("(needs action)"));
189 case ICAL_PARTSTAT_ACCEPTED:
190 strcpy(buf, _("(accepted)"));
192 case ICAL_PARTSTAT_DECLINED:
193 strcpy(buf, _("(declined)"));
195 case ICAL_PARTSTAT_TENTATIVE:
196 strcpy(buf, _("(tenative)"));
198 case ICAL_PARTSTAT_DELEGATED:
199 strcpy(buf, _("(delegated)"));
201 case ICAL_PARTSTAT_COMPLETED:
202 strcpy(buf, _("(completed)"));
204 case ICAL_PARTSTAT_INPROCESS:
205 strcpy(buf, _("(in process)"));
207 case ICAL_PARTSTAT_NONE:
208 strcpy(buf, _("(none)"));
215 * Utility function to encapsulate a subcomponent into a full VCALENDAR
217 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
218 icalcomponent *encaps;
220 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
222 if (subcomp == NULL) {
223 lprintf(3, "ERROR: called with NULL argument!\n");
228 * If we're already looking at a full VCALENDAR component,
229 * don't bother ... just return itself.
231 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
235 /* Encapsulate the VEVENT component into a complete VCALENDAR */
236 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
237 if (encaps == NULL) {
238 lprintf(3, "%s:%d: Error - could not allocate component!\n",
243 /* Set the Product ID */
244 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
246 /* Set the Version Number */
247 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
249 /* Encapsulate the subcomponent inside */
250 /* lprintf(9, "Doing the encapsulation\n"); */
251 icalcomponent_add_component(encaps, subcomp);
253 /* Convert all timestamps to UTC so we don't have to deal with
254 * stupid VTIMEZONE crap.
256 ical_dezonify(encaps);
258 /* Return the object we just created. */