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 * \brief display and edit date/time
21 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
22 * handle the display and editing of date/time properties in web pages. The
23 * first one converts an icaltimetype into valid HTML markup -- a series of form
24 * fields for editing the date and time. When the user submits the form, the
25 * results can be fed back into the second function, which turns it back into
26 * an icaltimetype. The "prefix" string required by both functions is prepended
27 * to all field names. This allows a form to contain more than one date/time
28 * property (for example, a start and end time) by ensuring the field names are
29 * unique within the form.
31 * \todo NOTE: These functions assume that the icaltimetype being edited is in UTC, and
32 * will convert to/from local time for editing. "local" in this case is assumed
33 * to be the time zone in which the WebCit server is running. A future improvement
34 * might be to allow the user to specify his/her timezone.
35 * \param t the time we want to parse
36 * \param prefix ???? \todo
40 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
47 int all_day_event = 0;
51 time_format = get_time_format_cached ();
54 localtime_r(&now, &tm_now);
55 this_year = tm_now.tm_year + 1900;
57 if (t == NULL) return;
58 if (t->is_date) all_day_event = 1;
59 tt = icaltime_as_timet(*t);
64 localtime_r(&tt, &tm);
67 wprintf("<input type=\"text\" name=\"");
71 wprintf("\" value=\"");
72 wc_strftime(timebuf, 32, "%d/%m/%Y", &tm);
75 wprintf("<script type=\"text/javascript\">");
76 wprintf("attachDatePicker('");
81 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
82 for (i=0; i<=23; ++i) {
84 if (time_format == WC_TIMEFORMAT_24) {
85 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
86 ((tm.tm_hour == i) ? "SELECTED" : ""),
91 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
92 ((tm.tm_hour == i) ? "SELECTED" : ""),
98 wprintf("</SELECT>\n");
100 wprintf(_("Minute: "));
101 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
102 for (i=0; i<=59; ++i) {
103 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
104 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
105 ((tm.tm_min == i) ? "SELECTED" : ""),
110 wprintf("</SELECT>\n");
114 *\brief Get time from form
115 * get the time back from the user and convert it into internal structs.
116 * \param t our time element
117 * \param prefix whats that\todo ????
119 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
123 /* Stuff tm with some zero values */
132 struct icaltimetype t2;
135 strptime((char*)BSTR(prefix), "%d/%m/%Y", &tm);
136 sprintf(vname, "%s_hour", prefix); hour = IBSTR(vname);
137 sprintf(vname, "%s_minute", prefix); minute = IBSTR(vname);
140 strftime(&datebuf[0], 32, "%Y%m%dT%H%M%S", &tm);
141 t2 = icaltime_from_string(datebuf);
142 memcpy(t, &t2, sizeof(struct icaltimetype));
147 *\brief Get time from form
148 * get the time back from the user and convert it into internal structs.
149 * \param t our time element
150 * \param prefix whats that\todo ????
153 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
155 /* Stuff tm with some zero values */
162 struct icaltimetype t2;
163 strptime((char *)BSTR(prefix), "%d/%m/%Y", &tm);
165 t2 = icaltime_from_timet(tm_t, 1);
166 memcpy(t, &t2, sizeof(struct icaltimetype));
171 * \brief Render PAPSTAT
172 * Render a PARTSTAT parameter as a string (and put it in parentheses)
173 * \param buf the string to put it to
174 * \param attendee the attendee to textify
176 void partstat_as_string(char *buf, icalproperty *attendee) {
177 icalparameter *partstat_param;
178 icalparameter_partstat partstat;
180 strcpy(buf, _("(status unknown)"));
182 partstat_param = icalproperty_get_first_parameter(
184 ICAL_PARTSTAT_PARAMETER
186 if (partstat_param == NULL) {
190 partstat = icalparameter_get_partstat(partstat_param);
192 case ICAL_PARTSTAT_X:
195 case ICAL_PARTSTAT_NEEDSACTION:
196 strcpy(buf, _("(needs action)"));
198 case ICAL_PARTSTAT_ACCEPTED:
199 strcpy(buf, _("(accepted)"));
201 case ICAL_PARTSTAT_DECLINED:
202 strcpy(buf, _("(declined)"));
204 case ICAL_PARTSTAT_TENTATIVE:
205 strcpy(buf, _("(tenative)"));
207 case ICAL_PARTSTAT_DELEGATED:
208 strcpy(buf, _("(delegated)"));
210 case ICAL_PARTSTAT_COMPLETED:
211 strcpy(buf, _("(completed)"));
213 case ICAL_PARTSTAT_INPROCESS:
214 strcpy(buf, _("(in process)"));
216 case ICAL_PARTSTAT_NONE:
217 strcpy(buf, _("(none)"));
225 * Utility function to encapsulate a subcomponent into a full VCALENDAR
226 * \param subcomp the component to encapsulate
227 * \returns the meta object ???
229 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
230 icalcomponent *encaps;
232 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
234 if (subcomp == NULL) {
235 lprintf(3, "ERROR: called with NULL argument!\n");
240 * If we're already looking at a full VCALENDAR component,
241 * don't bother ... just return itself.
243 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
247 /** Encapsulate the VEVENT component into a complete VCALENDAR */
248 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
249 if (encaps == NULL) {
250 lprintf(3, "%s:%d: Error - could not allocate component!\n",
255 /** Set the Product ID */
256 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
258 /** Set the Version Number */
259 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
261 /** Encapsulate the subcomponent inside */
262 /* lprintf(9, "Doing the encapsulation\n"); */
263 icalcomponent_add_component(encaps, subcomp);
265 /** Convert all timestamps to UTC so we don't have to deal with
266 * stupid VTIMEZONE crap.
268 ical_dezonify(encaps);
270 /** Return the object we just created. */