2 * Copyright (c) 1996-2012 by the citadel.org team
4 * This program is open source software. You can redistribute it and/or
5 * modify it under the terms of the GNU General Public License, version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
15 extern IcalKindEnumMap icalproperty_kind_map[];
16 extern IcalMethodEnumMap icalproperty_method_map[];
18 HashList *IcalComponentMap = NULL;
19 CtxType CTX_ICAL = CTX_NONE;
20 CtxType CTX_ICALPROPERTY = CTX_NONE;
21 CtxType CTX_ICALMETHOD = CTX_NONE;
22 CtxType CTX_ICALTIME = CTX_NONE;
24 void SortPregetMatter(HashList *Cals)
30 IcalEnumMap *SortMap[10];
33 const char *Next = NULL;
34 const StrBuf *SortVector;
39 SortVector = SBSTR("ICALSortVec");
40 if (SortVector == NULL)
43 for (i = 0; i < 10; i++) SortMap[i] = NULL;
45 while (StrBufExtract_NextToken(SortBy, SortVector, &Next, ':') > 0) {
46 GetHash(IcalComponentMap, SKEY(SortBy), &vSort);
47 Map = (IcalEnumMap*) vSort;
57 switch (SortMap[i - 1]->map) {
64 It = GetNewHashPos(Cals, 0);
65 while (GetNextHashPos(Cals, It, &KLen, &Key, &vCal)) {
67 Cal = (disp_cal*) vCal;
68 Cal->Status = icalcomponent_get_status(Cal->cal);
69 Cal->SortBy = Cal->cal;
72 while ((SortMap[i] != NULL) &&
73 (Cal->SortBy != NULL))
75 /****Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map); */
82 void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP)
84 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
86 icalproperty_kind Kind;
89 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
90 p = icalcomponent_get_first_property(cal, Kind);
92 str = icalproperty_get_comment (p);
93 StrBufAppendTemplateStr(Target, TP, str, 1);
97 void tmplput_CtxICalProperty(StrBuf *Target, WCTemplputParams *TP)
99 icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
102 str = icalproperty_get_comment (p);
103 StrBufAppendTemplateStr(Target, TP, str, 0);
106 int ReleaseIcalSubCtx(StrBuf *Target, WCTemplputParams *TP)
108 WCTemplputParams *TPP = TP;
113 int cond_ICalIsA(StrBuf *Target, WCTemplputParams *TP)
115 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
116 icalcomponent_kind c = GetTemplateTokenNumber(Target, TP, 2, ICAL_NO_COMPONENT);
117 return icalcomponent_isa(cal) == c;
120 int cond_ICalHaveItem(StrBuf *Target, WCTemplputParams *TP)
122 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
124 icalproperty_kind Kind;
126 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
127 p = icalcomponent_get_first_property(cal, Kind);
129 WCTemplputParams *DynamicTP;
131 DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams));
132 StackDynamicContext (TP,
139 TP->Tokens->Params[1]->lvalue);
146 int ReleaseIcalTimeCtx(StrBuf *Target, WCTemplputParams *TP)
148 WCTemplputParams *TPP = TP;
155 int cond_ICalHaveTimeItem(StrBuf *Target, WCTemplputParams *TP)
157 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
159 icalproperty_kind Kind;
161 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY);
162 p = icalcomponent_get_first_property(cal, Kind);
164 struct icaltimetype *t;
165 struct icaltimetype tt;
166 WCTemplputParams *DynamicTP;
168 DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams) +
169 sizeof(struct icaltimetype));
170 t = (struct icaltimetype *) ((char*)DynamicTP) + sizeof(WCTemplputParams);
171 memset(&tt, 0, sizeof(struct icaltimetype));
174 case ICAL_DTSTART_PROPERTY:
175 tt = icalproperty_get_dtstart(p);
177 case ICAL_DTEND_PROPERTY:
178 tt = icalproperty_get_dtend(p);
183 memcpy(t, &tt, sizeof(struct icaltimetype));
185 StackDynamicContext (TP,
192 TP->Tokens->Params[1]->lvalue);
200 int cond_ICalTimeIsDate(StrBuf *Target, WCTemplputParams *TP)
202 struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
206 void tmplput_ICalTime_Date(StrBuf *Target, WCTemplputParams *TP)
211 struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
213 memset(&d_tm, 0, sizeof d_tm);
214 d_tm.tm_year = t->year - 1900;
215 d_tm.tm_mon = t->month - 1;
216 d_tm.tm_mday = t->day;
217 len = wc_strftime(buf, sizeof(buf), "%x", &d_tm);
218 StrBufAppendBufPlain(Target, buf, len, 0);
220 void tmplput_ICalTime_Time(StrBuf *Target, WCTemplputParams *TP)
224 struct icaltimetype *t = (struct icaltimetype *) CTX(CTX_ICALTIME);
227 tt = icaltime_as_timet(*t);
228 len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
229 StrBufAppendBufPlain(Target, buf, len, 0);
232 void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP)
234 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
236 icalproperty_kind Kind;
237 struct icaltimetype t;
241 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
242 p = icalcomponent_get_first_property(cal, Kind);
245 t = icalproperty_get_dtend(p);
246 tt = icaltime_as_timet(t);
247 len = webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
248 StrBufAppendBufPlain(Target, buf, len, 0);
252 void tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP)
254 icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
255 struct icaltimetype t;
260 t = icalproperty_get_dtend(p);
261 tt = icaltime_as_timet(t);
262 len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
263 StrBufAppendBufPlain(Target, buf, len, 0);
268 void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
270 icalproperty_method the_method = ICAL_METHOD_NONE;
271 icalproperty *method = NULL;
274 WCTemplputParams SubTP;
275 WCTemplputParams SuperTP;
276 static int divcount = 0;
278 if (StrLength(Mime->Data) == 0) {
281 if (StrLength(Mime->Data) > 0) {
282 cal = icalcomponent_new_from_string(ChrPtr(Mime->Data));
285 StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item."));
286 StrBufAppendPrintf(Mime->Data, "<br>\n");
290 putlbstr("divname", ++divcount);
291 putbstr("cal_partnum", NewStrBufDup(Mime->PartNum));
292 putlbstr("msgnum", Mime->msgnum);
294 memset(&SubTP, 0, sizeof(WCTemplputParams));
295 memset(&SuperTP, 0, sizeof(WCTemplputParams));
297 /*//ical_dezonify(cal); */
299 /* If the component has subcomponents, recurse through them. */
300 c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
301 c = (c != NULL) ? c : cal;
303 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
304 if (method != NULL) {
305 the_method = icalproperty_get_method(method);
308 SuperTP.Context = &the_method;
309 SuperTP.Filter.ContextType = CTX_ICALMETHOD,
311 StackContext (&SuperTP,
317 FlushStrBuf(Mime->Data);
318 DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP);
320 /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */
322 /* Free the memory we obtained from libical's constructor */
323 StrBufPlain(Mime->ContentType, HKEY("text/html"));
324 StrBufAppendPrintf(WC->trailing_javascript,
325 "eventEditAllDay(); \n"
326 "RecurrenceShowHide(); \n"
327 "EnableOrDisableCheckButton(); \n"
330 UnStackContext(&SubTP);
331 icalcomponent_free(cal);
333 void CreateIcalComponendKindLookup(void)
337 IcalComponentMap = NewHash (1, NULL);
338 while (icalproperty_kind_map[i].NameLen != 0) {
339 RegisterNS(icalproperty_kind_map[i].Name,
340 icalproperty_kind_map[i].NameLen,
346 Put(IcalComponentMap,
347 icalproperty_kind_map[i].Name,
348 icalproperty_kind_map[i].NameLen,
349 &icalproperty_kind_map[i],
350 reference_free_handler);
360 int cond_ICalIsMethod(StrBuf *Target, WCTemplputParams *TP)
362 icalproperty_method *the_method = (icalproperty_method *) CTX(CTX_ICALMETHOD);
363 icalproperty_method which_method;
365 which_method = GetTemplateTokenNumber(Target, TP, 2, ICAL_METHOD_X);
366 return *the_method == which_method;
375 void tmplput_Conflict(StrBuf *Target, WCTemplputParams *TP)
378 HashList* IterateGetAttendees()
381 /* If the component has attendees, iterate through them. * /
382 for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY);
384 p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) {
385 StrBufAppendPrintf(Target, "<dt>");
386 StrBufAppendPrintf(Target, _("Attendee:"));
387 StrBufAppendPrintf(Target, "</dt><dd>");
388 ch = icalproperty_get_attendee(p);
389 if ((ch != NULL) && !strncasecmp(buf, "MAILTO:", 7)) {
391 /** screen name or email address * /
392 safestrncpy(buf, ch + 7, sizeof(buf));
394 StrEscAppend(Target, NULL, buf, 0, 0);
395 StrBufAppendPrintf(Target, " ");
397 /** participant status * /
398 partstat_as_string(buf, p);
399 StrEscAppend(Target, NULL, buf, 0, 0);
401 StrBufAppendPrintf(Target, "</dd>\n");
405 /* If the component has subcomponents, recurse through them. * /
406 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
408 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
409 /* Recursively process subcomponent * /
410 cal_process_object(Target, c, recursion_level+1, msgnum, cal_partnum);
418 InitModule_ICAL_SUBST
421 RegisterCTX(CTX_ICAL);
423 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS_TPL, 1, 501);
424 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS_TPL, 1, 500);
427 CreateIcalComponendKindLookup ();
428 RegisterConditional("COND:ICAL:PROPERTY", 1, cond_ICalHaveItem, CTX_ICAL);
429 RegisterConditional("COND:ICAL:IS:A", 1, cond_ICalIsA, CTX_ICAL);
431 RegisterNamespace("ICAL:SERV:CHECK:CONFLICT", 0, 0, tmplput_Conflict, NULL, CTX_ICAL);
433 RegisterCTX(CTX_ICALPROPERTY);
434 RegisterNamespace("ICAL:ITEM", 1, 2, tmplput_ICalItem, NULL, CTX_ICAL);
435 RegisterNamespace("ICAL:PROPERTY:STR", 0, 1, tmplput_CtxICalProperty, NULL, CTX_ICALPROPERTY);
436 RegisterNamespace("ICAL:PROPERTY:DATE", 0, 1, tmplput_CtxICalPropertyDate, NULL, CTX_ICALPROPERTY);
438 RegisterCTX(CTX_ICALMETHOD);
439 RegisterConditional("COND:ICAL:METHOD", 1, cond_ICalIsMethod, CTX_ICALMETHOD);
442 RegisterCTX(CTX_ICALTIME);
443 RegisterConditional("COND:ICAL:DT:PROPERTY", 1, cond_ICalHaveTimeItem, CTX_ICAL);
444 RegisterConditional("COND:ICAL:DT:ISDATE", 0, cond_ICalTimeIsDate, CTX_ICALTIME);
445 RegisterNamespace("ICAL:DT:DATE", 0, 1, tmplput_ICalTime_Date, NULL, CTX_ICALTIME);
446 RegisterNamespace("ICAL:DT:DATETIME", 0, 1, tmplput_ICalTime_Time, NULL, CTX_ICALTIME);
450 ServerShutdownModule_ICAL
453 DeleteHash(&IcalComponentMap);