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\">\n");
76 wprintf(" var dpck = new DatePicker({\n ");
77 wprintf("relative: '");
79 wprintf("',\n language: 'en',\n");
80 wprintf("disableFutureDate: false\n});</script>");
82 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
83 for (i=0; i<=23; ++i) {
85 if (time_format == WC_TIMEFORMAT_24) {
86 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
87 ((tm.tm_hour == i) ? "SELECTED" : ""),
92 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
93 ((tm.tm_hour == i) ? "SELECTED" : ""),
99 wprintf("</SELECT>\n");
101 wprintf(_("Minute: "));
102 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
103 for (i=0; i<=59; ++i) {
104 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
105 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
106 ((tm.tm_min == i) ? "SELECTED" : ""),
111 wprintf("</SELECT>\n");
115 *\brief Get time from form
116 * get the time back from the user and convert it into internal structs.
117 * \param t our time element
118 * \param prefix whats that\todo ????
120 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
124 /* Stuff tm with some zero values */
133 struct icaltimetype t2;
136 strptime((char*)BSTR(prefix), "%d/%m/%Y", &tm);
137 sprintf(vname, "%s_hour", prefix); hour = IBSTR(vname);
138 sprintf(vname, "%s_minute", prefix); minute = IBSTR(vname);
141 strftime(&datebuf[0], 32, "%Y%m%dT%H%M%S", &tm);
142 t2 = icaltime_from_string(datebuf);
143 memcpy(t, &t2, sizeof(struct icaltimetype));
148 *\brief Get time from form
149 * get the time back from the user and convert it into internal structs.
150 * \param t our time element
151 * \param prefix whats that\todo ????
154 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
156 /* Stuff tm with some zero values */
163 struct icaltimetype t2;
164 strptime((char *)BSTR(prefix), "%d/%m/%Y", &tm);
166 t2 = icaltime_from_timet(tm_t, 1);
167 memcpy(t, &t2, sizeof(struct icaltimetype));
172 * \brief Render PAPSTAT
173 * Render a PARTSTAT parameter as a string (and put it in parentheses)
174 * \param buf the string to put it to
175 * \param attendee the attendee to textify
177 void partstat_as_string(char *buf, icalproperty *attendee) {
178 icalparameter *partstat_param;
179 icalparameter_partstat partstat;
181 strcpy(buf, _("(status unknown)"));
183 partstat_param = icalproperty_get_first_parameter(
185 ICAL_PARTSTAT_PARAMETER
187 if (partstat_param == NULL) {
191 partstat = icalparameter_get_partstat(partstat_param);
193 case ICAL_PARTSTAT_X:
196 case ICAL_PARTSTAT_NEEDSACTION:
197 strcpy(buf, _("(needs action)"));
199 case ICAL_PARTSTAT_ACCEPTED:
200 strcpy(buf, _("(accepted)"));
202 case ICAL_PARTSTAT_DECLINED:
203 strcpy(buf, _("(declined)"));
205 case ICAL_PARTSTAT_TENTATIVE:
206 strcpy(buf, _("(tenative)"));
208 case ICAL_PARTSTAT_DELEGATED:
209 strcpy(buf, _("(delegated)"));
211 case ICAL_PARTSTAT_COMPLETED:
212 strcpy(buf, _("(completed)"));
214 case ICAL_PARTSTAT_INPROCESS:
215 strcpy(buf, _("(in process)"));
217 case ICAL_PARTSTAT_NONE:
218 strcpy(buf, _("(none)"));
226 * Utility function to encapsulate a subcomponent into a full VCALENDAR
227 * \param subcomp the component to encapsulate
228 * \returns the meta object ???
230 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
231 icalcomponent *encaps;
233 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
235 if (subcomp == NULL) {
236 lprintf(3, "ERROR: called with NULL argument!\n");
241 * If we're already looking at a full VCALENDAR component,
242 * don't bother ... just return itself.
244 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
248 /** Encapsulate the VEVENT component into a complete VCALENDAR */
249 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
250 if (encaps == NULL) {
251 lprintf(3, "%s:%d: Error - could not allocate component!\n",
256 /** Set the Product ID */
257 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
259 /** Set the Version Number */
260 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
262 /** Encapsulate the subcomponent inside */
263 /* lprintf(9, "Doing the encapsulation\n"); */
264 icalcomponent_add_component(encaps, subcomp);
266 /** Convert all timestamps to UTC so we don't have to deal with
267 * stupid VTIMEZONE crap.
269 ical_dezonify(encaps);
271 /** Return the object we just created. */