2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000-2004 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OGo
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
2008-06-19 20:31:18 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
|
|
|
#import <NGCards/iCalFreeBusy.h>
|
2007-05-09 21:30:06 +02:00
|
|
|
#import <NGCards/iCalPerson.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SOGo/LDAPUserManager.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
|
2007-09-15 00:49:49 +02:00
|
|
|
#import "SOGoAppointmentFolder.h"
|
2008-06-19 20:31:18 +02:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2007-09-15 00:49:49 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
#import "SOGoFreeBusyObject.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-19 20:31:18 +02:00
|
|
|
static unsigned int freebusyRangeStart = 0;
|
|
|
|
static unsigned int freebusyRangeEnd = 0;
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@interface SOGoFreeBusyObject (PrivateAPI)
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
|
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoFreeBusyObject
|
|
|
|
|
2008-06-19 20:31:18 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSArray *freebusyDateRange;
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
freebusyDateRange = [ud arrayForKey: @"SOGoFreeBusyDefaultInterval"];
|
|
|
|
if (freebusyDateRange && [freebusyDateRange count] > 1)
|
|
|
|
{
|
|
|
|
freebusyRangeStart = [[freebusyDateRange objectAtIndex: 0] unsignedIntValue];
|
|
|
|
freebusyRangeEnd = [[freebusyDateRange objectAtIndex: 1] unsignedIntValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
freebusyRangeStart = 7;
|
|
|
|
freebusyRangeEnd = 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) contentAsString
|
|
|
|
{
|
2007-01-13 00:21:13 +01:00
|
|
|
NSCalendarDate *today, *startDate, *endDate;
|
2007-04-11 21:08:58 +02:00
|
|
|
NSTimeZone *timeZone;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-01-13 00:21:13 +01:00
|
|
|
today = [[NSCalendarDate calendarDate] beginOfDay];
|
2007-04-11 21:08:58 +02:00
|
|
|
timeZone = [[context activeUser] timeZone];
|
|
|
|
[today setTimeZone: timeZone];
|
2007-01-13 00:21:13 +01:00
|
|
|
|
2008-06-19 20:31:18 +02:00
|
|
|
startDate = [today dateByAddingYears: 0 months: 0 days: -freebusyRangeStart
|
2007-01-13 00:21:13 +01:00
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
2008-06-19 20:31:18 +02:00
|
|
|
endDate = [startDate dateByAddingYears: 0 months: 0 days: freebusyRangeEnd
|
2007-01-13 00:21:13 +01:00
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
2007-04-11 21:08:58 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
return [self contentAsStringFrom: startDate to: endDate];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) contentAsStringFrom: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
NSArray *infos;
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
infos = [self fetchFreeBusyInfosFrom:_startDate to:_endDate];
|
2008-06-19 20:31:18 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self iCalStringForFreeBusyInfos:infos from:_startDate to:_endDate];
|
|
|
|
}
|
|
|
|
|
2008-06-19 20:31:18 +02:00
|
|
|
- (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) startDate
|
|
|
|
to: (NSCalendarDate *) endDate
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2007-09-15 00:49:49 +02:00
|
|
|
SOGoAppointmentFolder *calFolder;
|
2007-05-16 18:44:29 +02:00
|
|
|
// SoSecurityManager *sm;
|
2008-06-19 20:31:18 +02:00
|
|
|
NSArray *folders;
|
|
|
|
NSMutableArray *infos;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
infos = [NSMutableArray array];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
2008-06-19 20:31:18 +02:00
|
|
|
folders = [[container lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO] subFolders];
|
|
|
|
max = [folders count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
calFolder = [folders objectAtIndex: count];
|
|
|
|
if (![calFolder isSubscription])
|
|
|
|
[infos addObjectsFromArray: [calFolder fetchFreeBusyInfosFrom: startDate
|
|
|
|
to: endDate]];
|
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
return infos;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
- (NSString *) iCalString
|
|
|
|
{
|
|
|
|
// for UI-X appointment viewer
|
|
|
|
return [self contentAsString];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Private API */
|
2006-10-26 02:09:03 +02:00
|
|
|
- (iCalFreeBusyType) _fbTypeForEventStatus: (NSNumber *) eventStatus
|
|
|
|
{
|
|
|
|
unsigned int status;
|
|
|
|
iCalFreeBusyType fbType;
|
|
|
|
|
|
|
|
status = [eventStatus unsignedIntValue];
|
|
|
|
if (status == 0)
|
|
|
|
fbType = iCalFBBusyTentative;
|
|
|
|
else if (status == 1)
|
|
|
|
fbType = iCalFBBusy;
|
|
|
|
else
|
|
|
|
fbType = iCalFBFree;
|
|
|
|
|
|
|
|
return fbType;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 20:25:51 +02:00
|
|
|
- (iCalPerson *) iCalPersonWithUID: (NSString *) uid
|
|
|
|
{
|
|
|
|
iCalPerson *person;
|
|
|
|
LDAPUserManager *um;
|
|
|
|
NSDictionary *contactInfos;
|
|
|
|
|
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
contactInfos = [um contactInfosForUserWithUIDorEmail: uid];
|
|
|
|
|
|
|
|
person = [iCalPerson new];
|
|
|
|
[person autorelease];
|
|
|
|
[person setCn: [contactInfos objectForKey: @"cn"]];
|
|
|
|
[person setEmail: [contactInfos objectForKey: @"c_email"]];
|
|
|
|
|
|
|
|
return person;
|
|
|
|
}
|
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (NSString *) iCalStringForFreeBusyInfos: (NSArray *) _infos
|
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2006-10-26 02:09:03 +02:00
|
|
|
NSString *uid;
|
|
|
|
NSEnumerator *events;
|
|
|
|
iCalCalendar *calendar;
|
|
|
|
iCalFreeBusy *freebusy;
|
|
|
|
NSDictionary *info;
|
|
|
|
iCalFreeBusyType type;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-12 16:49:54 +01:00
|
|
|
uid = [container ownerInContext: context];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
|
|
|
calendar = [iCalCalendar groupWithTag: @"vcalendar"];
|
|
|
|
[calendar setProdID: @"//Inverse groupe conseil/SOGo 0.9"];
|
|
|
|
[calendar setVersion: @"2.0"];
|
|
|
|
|
|
|
|
freebusy = [iCalFreeBusy groupWithTag: @"vfreebusy"];
|
2007-05-09 21:31:57 +02:00
|
|
|
[freebusy addToAttendees: [self iCalPersonWithUID: uid]];
|
2006-10-26 02:09:03 +02:00
|
|
|
[freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]];
|
|
|
|
[freebusy setStartDate: _startDate];
|
|
|
|
[freebusy setEndDate: _endDate];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* ORGANIZER - strictly required but missing for now */
|
|
|
|
|
|
|
|
/* ATTENDEE */
|
2007-05-09 20:25:51 +02:00
|
|
|
// person = [self iCalPersonWithUid: uid];
|
2006-10-26 02:09:03 +02:00
|
|
|
// [person setTag: @"ATTENDEE"];
|
|
|
|
// [ms appendString: [person versitString]];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
/* FREEBUSY */
|
|
|
|
events = [_infos objectEnumerator];
|
2008-06-19 20:31:18 +02:00
|
|
|
while ((info = [events nextObject]))
|
|
|
|
if ([[info objectForKey: @"c_isopaque"] boolValue])
|
|
|
|
{
|
|
|
|
type = [self _fbTypeForEventStatus: [info objectForKey: @"c_status"]];
|
|
|
|
[freebusy addFreeBusyFrom: [info objectForKey: @"startDate"]
|
|
|
|
to: [info objectForKey: @"endDate"]
|
|
|
|
type: type];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
[calendar setUniqueChild: freebusy];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
return [calendar versitString];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* deliver content without need for view method */
|
|
|
|
|
2006-10-26 02:09:03 +02:00
|
|
|
- (id) GETAction: (id)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOResponse *r;
|
|
|
|
NSData *contentData;
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
contentData = [[self contentAsString]
|
|
|
|
dataUsingEncoding: NSUTF8StringEncoding];
|
2006-10-26 02:09:03 +02:00
|
|
|
|
|
|
|
r = [(WOContext *) _ctx response];
|
|
|
|
[r setHeader: @"text/calendar" forKey: @"content-type"];
|
|
|
|
[r setContent: contentData];
|
|
|
|
[r setStatus: 200];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-04 21:57:36 +01:00
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2007-06-01 08:13:44 +02:00
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"text/calendar";
|
|
|
|
}
|
|
|
|
|
2007-11-07 16:58:43 +01:00
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end
|