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 "SOGoAppointmentFolder.h"
40 #import "SOGoFreeBusyObject.h"
42 @interface SOGoFreeBusyObject (PrivateAPI)
43 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
44 from: (NSCalendarDate *) _startDate
45 to: (NSCalendarDate *) _endDate;
48 @implementation SOGoFreeBusyObject
50 - (NSString *) contentAsString
52 NSCalendarDate *today, *startDate, *endDate;
55 today = [[NSCalendarDate calendarDate] beginOfDay];
56 timeZone = [[context activeUser] timeZone];
57 [today setTimeZone: timeZone];
59 startDate = [today dateByAddingYears: 0 months: 0 days: -14
60 hours: 0 minutes: 0 seconds: 0];
61 endDate = [startDate dateByAddingYears: 0 months: 1 days: 0
62 hours: 0 minutes: 0 seconds: 0];
64 return [self contentAsStringFrom: startDate to: endDate];
67 - (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
68 to: (NSCalendarDate *) _endDate
72 infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
73 return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
76 - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
77 to: (NSCalendarDate *) _endDate
79 SOGoAppointmentFolder *calFolder;
80 // SoSecurityManager *sm;
83 calFolder = [[container lookupName: @"Calendar" inContext: nil acquire: NO]
84 lookupName: @"personal" inContext: nil acquire: NO];
85 // sm = [SoSecurityManager sharedSecurityManager];
86 // if (![sm validatePermission: SOGoPerm_FreeBusyLookup
87 // onObject: calFolder
88 // inContext: context])
89 infos = [calFolder fetchFreeBusyInfosFrom: _startDate
93 // infos = [NSArray new];
94 // [infos autorelease];
100 - (NSString *) iCalString
102 // for UI-X appointment viewer
103 return [self contentAsString];
107 - (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
110 iCalFreeBusyType fbType;
112 status = [eventStatus unsignedIntValue];
114 fbType = iCalFBBusyTentative;
115 else if (status == 1)
123 - (iCalPerson *) iCalPersonWithUID: (NSString *) uid
127 NSDictionary *contactInfos;
129 um = [LDAPUserManager sharedUserManager];
130 contactInfos = [um contactInfosForUserWithUIDorEmail: uid];
132 person = [iCalPerson new];
133 [person autorelease];
134 [person setCn: [contactInfos objectForKey: @"cn"]];
135 [person setEmail: [contactInfos objectForKey: @"c_email"]];
140 - (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
141 from: (NSCalendarDate *) _startDate
142 to: (NSCalendarDate *) _endDate
145 NSEnumerator *events;
146 iCalCalendar *calendar;
147 iCalFreeBusy *freebusy;
149 iCalFreeBusyType type;
151 uid = [[self container] login];
153 calendar = [iCalCalendar groupWithTag: @"vcalendar"];
154 [calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
155 [calendar setVersion: @"2.0"];
157 freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
158 [freebusy addToAttendees: [self iCalPersonWithUID: uid]];
159 [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
160 [freebusy setStartDate: _startDate];
161 [freebusy setEndDate: _endDate];
163 /* ORGANIZER - strictly required but missing for now */
166 // person = [self iCalPersonWithUid: uid];
167 // [person setTag: @"ATTENDEE"];
168 // [ms appendString: [person versitString]];
171 events = [_infos objectEnumerator];
172 info = [events nextObject];
175 if ([[info objectForKey: @"c_isopaque"] boolValue])
177 type = [self _fbTypeForEventStatus: [info objectForKey: @"c_status"]];
178 [freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
179 to: [info objectForKey: @"endDate"]
182 info = [events nextObject];
185 [calendar setUniqueChild: freebusy];
187 return [calendar versitString];
190 /* deliver content without need for view method */
192 - (id) GETAction: (id)_ctx
197 contentData = [[self contentAsString]
198 dataUsingEncoding: NSUTF8StringEncoding];
200 r = [(WOContext *) _ctx response];
201 [r setHeader: @"text/calendar" forKey: @"content-type"];
202 [r setContent: contentData];
208 - (NSString *) davContentType
210 return @"text/calendar";
213 - (NSArray *) aclsForUser: (NSString *) uid