5 * \defgroup MiscCal 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"
19 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
22 * \brief display and edit date/time
23 * The display_icaltimetype_as_webform() and icaltime_from_webform() functions
24 * handle the display and editing of date/time properties in web pages. The
25 * first one converts an icaltimetype into valid HTML markup -- a series of form
26 * fields for editing the date and time. When the user submits the form, the
27 * results can be fed back into the second function, which turns it back into
28 * an icaltimetype. The "prefix" string required by both functions is prepended
29 * to all field names. This allows a form to contain more than one date/time
30 * property (for example, a start and end time) by ensuring the field names are
31 * unique within the form.
33 * \todo NOTE: These functions assume that the icaltimetype being edited is in UTC, and
34 * will convert to/from local time for editing. "local" in this case is assumed
35 * to be the time zone in which the WebCit server is running. A future improvement
36 * might be to allow the user to specify his/her timezone.
37 * \param t the time we want to parse
38 * \param prefix ???? \todo
42 void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix) {
50 int all_day_event = 0;
51 char calhourformat[16];
53 get_preference("calhourformat", calhourformat, sizeof calhourformat);
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 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
73 ((tm.tm_mon == i) ? "SELECTED" : ""),
78 wprintf("</SELECT>\n");
81 wprintf("<SELECT NAME=\"%s_day\" SIZE=\"1\">\n", prefix);
82 for (i=1; i<=31; ++i) {
83 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
84 ((tm.tm_mday == i) ? "SELECTED" : ""),
88 wprintf("</SELECT>\n");
91 wprintf("<SELECT NAME=\"%s_year\" SIZE=\"1\">\n", prefix);
92 if ((this_year - t->year) > span) {
93 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
96 for (i=(this_year-span); i<=(this_year+span); ++i) {
97 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
98 ((t->year == i) ? "SELECTED" : ""),
102 if ((t->year - this_year) > span) {
103 wprintf("<OPTION SELECTED VALUE=\"%d\">%d</OPTION>\n",
106 wprintf("</SELECT>\n");
108 wprintf(_("Hour: "));
109 wprintf("<SELECT NAME=\"%s_hour\" SIZE=\"1\">\n", prefix);
110 for (i=0; i<=23; ++i) {
112 if (!strcasecmp(calhourformat, "24")) {
113 wprintf("<OPTION %s VALUE=\"%d\">%d</OPTION>\n",
114 ((tm.tm_hour == i) ? "SELECTED" : ""),
119 wprintf("<OPTION %s VALUE=\"%d\">%s</OPTION>\n",
120 ((tm.tm_hour == i) ? "SELECTED" : ""),
126 wprintf("</SELECT>\n");
128 wprintf(_("Minute: "));
129 wprintf("<SELECT NAME=\"%s_minute\" SIZE=\"1\">\n", prefix);
130 for (i=0; i<=59; ++i) {
131 if ( (i % 5 == 0) || (tm.tm_min == i) ) {
132 wprintf("<OPTION %s VALUE=\"%d\">:%02d</OPTION>\n",
133 ((tm.tm_min == i) ? "SELECTED" : ""),
138 wprintf("</SELECT>\n");
142 *\brief Get time from form
143 * get the time back from the user and convert it into internal structs.
144 * \param t our time element
145 * \param prefix whats that\todo ????
147 void icaltime_from_webform(struct icaltimetype *t, char *prefix) {
151 struct icaltimetype t2;
154 localtime_r(&tt, &tm);
156 sprintf(vname, "%s_month", prefix); tm.tm_mon = atoi(bstr(vname)) - 1;
157 sprintf(vname, "%s_day", prefix); tm.tm_mday = atoi(bstr(vname));
158 sprintf(vname, "%s_year", prefix); tm.tm_year = atoi(bstr(vname)) - 1900;
159 sprintf(vname, "%s_hour", prefix); tm.tm_hour = atoi(bstr(vname));
160 sprintf(vname, "%s_minute", prefix); tm.tm_min = atoi(bstr(vname));
163 t2 = icaltime_from_timet(tt, 0);
164 memcpy(t, &t2, sizeof(struct icaltimetype));
168 *\brief Get time from form
169 * get the time back from the user and convert it into internal structs.
170 * \param t our time element
171 * \param prefix whats that\todo ????
174 void icaltime_from_webform_dateonly(struct icaltimetype *t, char *prefix) {
177 memset(t, 0, sizeof(struct icaltimetype));
179 sprintf(vname, "%s_month", prefix); t->month = atoi(bstr(vname));
180 sprintf(vname, "%s_day", prefix); t->day = atoi(bstr(vname));
181 sprintf(vname, "%s_year", prefix); t->year = atoi(bstr(vname));
188 * \brief Render PAPSTAT
189 * Render a PARTSTAT parameter as a string (and put it in parentheses)
190 * \param buf the string to put it to
191 * \param attendee the attendee to textify
193 void partstat_as_string(char *buf, icalproperty *attendee) {
194 icalparameter *partstat_param;
195 icalparameter_partstat partstat;
197 strcpy(buf, _("(status unknown)"));
199 partstat_param = icalproperty_get_first_parameter(
201 ICAL_PARTSTAT_PARAMETER
203 if (partstat_param == NULL) {
207 partstat = icalparameter_get_partstat(partstat_param);
209 case ICAL_PARTSTAT_X:
212 case ICAL_PARTSTAT_NEEDSACTION:
213 strcpy(buf, _("(needs action)"));
215 case ICAL_PARTSTAT_ACCEPTED:
216 strcpy(buf, _("(accepted)"));
218 case ICAL_PARTSTAT_DECLINED:
219 strcpy(buf, _("(declined)"));
221 case ICAL_PARTSTAT_TENTATIVE:
222 strcpy(buf, _("(tenative)"));
224 case ICAL_PARTSTAT_DELEGATED:
225 strcpy(buf, _("(delegated)"));
227 case ICAL_PARTSTAT_COMPLETED:
228 strcpy(buf, _("(completed)"));
230 case ICAL_PARTSTAT_INPROCESS:
231 strcpy(buf, _("(in process)"));
233 case ICAL_PARTSTAT_NONE:
234 strcpy(buf, _("(none)"));
242 * Utility function to encapsulate a subcomponent into a full VCALENDAR
243 * \param subcomp the component to encapsulate
244 * \returns the meta object ???
246 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
247 icalcomponent *encaps;
249 /* lprintf(9, "ical_encapsulate_subcomponent() called\n"); */
251 if (subcomp == NULL) {
252 lprintf(3, "ERROR: called with NULL argument!\n");
257 * If we're already looking at a full VCALENDAR component,
258 * don't bother ... just return itself.
260 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
264 /** Encapsulate the VEVENT component into a complete VCALENDAR */
265 encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
266 if (encaps == NULL) {
267 lprintf(3, "%s:%d: Error - could not allocate component!\n",
272 /** Set the Product ID */
273 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
275 /** Set the Version Number */
276 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
278 /** Encapsulate the subcomponent inside */
279 /* lprintf(9, "Doing the encapsulation\n"); */
280 icalcomponent_add_component(encaps, subcomp);
282 /** Convert all timestamps to UTC so we don't have to deal with
283 * stupid VTIMEZONE crap.
285 ical_dezonify(encaps);
287 /** Return the object we just created. */