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 <Foundation/NSCalendarDate.h>
23 #import <Foundation/NSDictionary.h>
24 #import <Foundation/NSEnumerator.h>
25 #import <Foundation/NSValue.h>
27 #import <NGObjWeb/WOContext+SoObjects.h>
28 #import <NGObjWeb/WOResponse.h>
29 #import <NGExtensions/NSCalendarDate+misc.h>
30 #import <NGCards/iCalCalendar.h>
31 #import <NGCards/iCalFreeBusy.h>
32 #import <NGCards/iCalPerson.h>
34 #import <SOGo/LDAPUserManager.h>
35 #import <SOGo/SOGoUser.h>
36 #import <SOGo/SOGoPermissions.h>
38 #import "SOGoFreeBusyObject.h"
40 @interface SOGoFreeBusyObject (PrivateAPI)
41 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
42 from: (NSCalendarDate *) _startDate
43 to: (NSCalendarDate *) _endDate;
46 @implementation SOGoFreeBusyObject
48 - (NSString *) iCalString
50 // for UI-X appointment viewer
51 return [self contentAsString];
54 - (NSString *) contentAsString
56 NSCalendarDate *today, *startDate, *endDate;
59 today = [[NSCalendarDate calendarDate] beginOfDay];
60 timeZone = [[context activeUser] timeZone];
61 [today setTimeZone: timeZone];
63 startDate = [today dateByAddingYears: 0 months: 0 days: -14
64 hours: 0 minutes: 0 seconds: 0];
65 endDate = [startDate dateByAddingYears: 0 months: 1 days: 0
66 hours: 0 minutes: 0 seconds: 0];
68 return [self contentAsStringFrom: startDate to: endDate];
71 - (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
72 to: (NSCalendarDate *) _endDate
76 infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
77 return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
80 - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
81 to: (NSCalendarDate *) _endDate
84 // SoSecurityManager *sm;
87 calFolder = [container lookupName: @"Calendar" inContext: nil acquire: NO];
88 // sm = [SoSecurityManager sharedSecurityManager];
89 // if (![sm validatePermission: SOGoPerm_FreeBusyLookup
90 // onObject: calFolder
91 // inContext: context])
92 infos = [calFolder fetchFreeBusyInfosFrom: _startDate
96 // infos = [NSArray new];
97 // [infos autorelease];
104 - (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
107 iCalFreeBusyType fbType;
109 status = [eventStatus unsignedIntValue];
111 fbType = iCalFBBusyTentative;
112 else if (status == 1)
120 - (iCalPerson *) iCalPersonWithUID: (NSString *) uid
124 NSDictionary *contactInfos;
126 um = [LDAPUserManager sharedUserManager];
127 contactInfos = [um contactInfosForUserWithUIDorEmail: uid];
129 person = [iCalPerson new];
130 [person autorelease];
131 [person setCn: [contactInfos objectForKey: @"cn"]];
132 [person setEmail: [contactInfos objectForKey: @"c_email"]];
137 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
138 from: (NSCalendarDate *) _startDate
139 to: (NSCalendarDate *) _endDate
142 NSEnumerator *events;
143 iCalCalendar *calendar;
144 iCalFreeBusy *freebusy;
146 iCalFreeBusyType type;
148 uid = [[self container] login];
150 calendar = [iCalCalendar groupWithTag: @"vcalendar"];
151 [calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
152 [calendar setVersion: @"2.0"];
154 freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
155 [freebusy addToAttendees: [self iCalPersonWithUID: uid]];
156 [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
157 [freebusy setStartDate: _startDate];
158 [freebusy setEndDate: _endDate];
160 /* ORGANIZER - strictly required but missing for now */
163 // person = [self iCalPersonWithUid: uid];
164 // [person setTag: @"ATTENDEE"];
165 // [ms appendString: [person versitString]];
168 events = [_infos objectEnumerator];
169 info = [events nextObject];
172 if ([[info objectForKey: @"isopaque"] boolValue])
174 type = [self _fbTypeForEventStatus: [info objectForKey: @"status"]];
175 [freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
176 to: [info objectForKey: @"endDate"]
179 info = [events nextObject];
182 [calendar setUniqueChild: freebusy];
184 return [calendar versitString];
187 /* deliver content without need for view method */
189 - (id) GETAction: (id)_ctx
194 contentData = [[self contentAsString] dataUsingEncoding: NSUTF8StringEncoding];
196 r = [(WOContext *) _ctx response];
197 [r setHeader: @"text/calendar" forKey: @"content-type"];
198 [r setContent: contentData];
204 - (NSString *) davContentType
206 return @"text/calendar";