2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <NGCards/iCalCalendar.h>
23 #import <NGCards/iCalFreeBusy.h>
24 #import <NGCards/iCalPerson.h>
28 #import <SOGo/LDAPUserManager.h>
29 #import <SOGo/SOGoPermissions.h>
31 #import "SOGoFreeBusyObject.h"
33 @interface SOGoFreeBusyObject (PrivateAPI)
34 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
35 from: (NSCalendarDate *) _startDate
36 to: (NSCalendarDate *) _endDate;
39 @implementation SOGoFreeBusyObject
41 - (NSString *) iCalString
43 // for UI-X appointment viewer
44 return [self contentAsString];
47 - (NSString *) contentAsString
49 NSCalendarDate *today, *startDate, *endDate;
52 today = [[NSCalendarDate calendarDate] beginOfDay];
53 timeZone = [[context activeUser] timeZone];
54 [today setTimeZone: timeZone];
56 startDate = [today dateByAddingYears: 0 months: 0 days: -14
57 hours: 0 minutes: 0 seconds: 0];
58 endDate = [startDate dateByAddingYears: 0 months: 1 days: 0
59 hours: 0 minutes: 0 seconds: 0];
61 return [self contentAsStringFrom: startDate to: endDate];
64 - (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
65 to: (NSCalendarDate *) _endDate
69 infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
70 return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
73 - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
74 to: (NSCalendarDate *) _endDate
77 // SoSecurityManager *sm;
80 calFolder = [container lookupName: @"Calendar" inContext: nil acquire: NO];
81 // sm = [SoSecurityManager sharedSecurityManager];
82 // if (![sm validatePermission: SOGoPerm_FreeBusyLookup
83 // onObject: calFolder
84 // inContext: context])
85 infos = [calFolder fetchFreeBusyInfosFrom: _startDate
89 // infos = [NSArray new];
90 // [infos autorelease];
97 - (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
100 iCalFreeBusyType fbType;
102 status = [eventStatus unsignedIntValue];
104 fbType = iCalFBBusyTentative;
105 else if (status == 1)
113 - (iCalPerson *) iCalPersonWithUID: (NSString *) uid
117 NSDictionary *contactInfos;
119 um = [LDAPUserManager sharedUserManager];
120 contactInfos = [um contactInfosForUserWithUIDorEmail: uid];
122 person = [iCalPerson new];
123 [person autorelease];
124 [person setCn: [contactInfos objectForKey: @"cn"]];
125 [person setEmail: [contactInfos objectForKey: @"c_email"]];
130 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
131 from: (NSCalendarDate *) _startDate
132 to: (NSCalendarDate *) _endDate
135 NSEnumerator *events;
136 iCalCalendar *calendar;
137 iCalFreeBusy *freebusy;
139 iCalFreeBusyType type;
141 uid = [[self container] login];
143 calendar = [iCalCalendar groupWithTag: @"vcalendar"];
144 [calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
145 [calendar setVersion: @"2.0"];
147 freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
148 [freebusy addToAttendees: [self iCalPersonWithUID: uid]];
149 [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
150 [freebusy setStartDate: _startDate];
151 [freebusy setEndDate: _endDate];
153 /* ORGANIZER - strictly required but missing for now */
156 // person = [self iCalPersonWithUid: uid];
157 // [person setTag: @"ATTENDEE"];
158 // [ms appendString: [person versitString]];
161 events = [_infos objectEnumerator];
162 info = [events nextObject];
165 if ([[info objectForKey: @"isopaque"] boolValue])
167 type = [self _fbTypeForEventStatus: [info objectForKey: @"status"]];
168 [freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
169 to: [info objectForKey: @"endDate"]
172 info = [events nextObject];
175 [calendar setUniqueChild: freebusy];
177 return [calendar versitString];
180 /* deliver content without need for view method */
182 - (id) GETAction: (id)_ctx
187 contentData = [[self contentAsString] dataUsingEncoding: NSUTF8StringEncoding];
189 r = [(WOContext *) _ctx response];
190 [r setHeader: @"text/calendar" forKey: @"content-type"];
191 [r setContent: contentData];
197 - (NSString *) davContentType
199 return @"text/calendar";