2007-03-22 18:38:32 +01:00
|
|
|
/* SOGoUserHomePage.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-03-26 15:42:11 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2007-03-26 15:41:04 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2007-05-10 16:59:17 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-07-22 22:14:47 +02:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-10-26 15:58:15 +02:00
|
|
|
#import <Foundation/NSTimeZone.h>
|
2007-07-22 22:14:47 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-03-26 15:41:04 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-12-05 22:05:04 +01:00
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2007-09-04 17:02:03 +02:00
|
|
|
#import <NGObjWeb/WOCookie.h>
|
2007-03-22 18:38:32 +01:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-03-26 15:41:04 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSCalendarDate+misc.h>
|
2007-07-22 22:14:47 +02:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-03-26 15:41:04 +02:00
|
|
|
|
|
|
|
#import <Appointments/SOGoFreeBusyObject.h>
|
2007-09-04 17:41:59 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoWebAuthenticator.h>
|
2007-09-04 17:02:03 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2007-12-05 22:05:04 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUserFolder.h>
|
2007-09-04 17:02:03 +02:00
|
|
|
#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
|
2006-09-08 17:21:35 +02:00
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-23 16:11:26 +02:00
|
|
|
static NSString *defaultModule = nil;
|
2007-07-22 22:14:47 +02:00
|
|
|
|
2006-09-08 17:21:35 +02:00
|
|
|
@interface SOGoUserHomePage : UIxComponent
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SOGoUserHomePage
|
|
|
|
|
2007-07-22 22:14:47 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
2007-07-23 16:11:26 +02:00
|
|
|
if (!defaultModule)
|
2007-07-22 22:14:47 +02:00
|
|
|
{
|
2007-07-23 16:11:26 +02:00
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
defaultModule = [ud stringForKey: @"SOGoUIxDefaultModule"];
|
2007-07-22 22:14:47 +02:00
|
|
|
if (defaultModule)
|
|
|
|
{
|
|
|
|
if (!([defaultModule isEqualToString: @"Calendar"]
|
|
|
|
|| [defaultModule isEqualToString: @"Contacts"]
|
|
|
|
|| [defaultModule isEqualToString: @"Mail"]))
|
|
|
|
{
|
|
|
|
[self logWithFormat: @"default module '%@' not accepted (must be"
|
|
|
|
@"'Calendar', 'Contacts' or Mail)", defaultModule];
|
|
|
|
defaultModule = @"Calendar";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
defaultModule = @"Calendar";
|
|
|
|
[self logWithFormat: @"default module set to '%@'", defaultModule];
|
|
|
|
[defaultModule retain];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:38:32 +01:00
|
|
|
- (id <WOActionResults>) defaultAction
|
2006-10-26 02:16:56 +02:00
|
|
|
{
|
2007-07-22 22:14:47 +02:00
|
|
|
SOGoUserFolder *co;
|
|
|
|
NSURL *moduleURL;
|
2006-10-26 02:16:56 +02:00
|
|
|
|
2007-07-22 22:14:47 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
moduleURL = [NSURL URLWithString: defaultModule
|
|
|
|
relativeToURL: [co soURL]];
|
2006-10-26 02:16:56 +02:00
|
|
|
|
2007-07-22 22:14:47 +02:00
|
|
|
return [self redirectToLocation: [moduleURL absoluteString]];
|
2006-10-26 02:16:56 +02:00
|
|
|
}
|
|
|
|
|
2007-03-26 15:41:04 +02:00
|
|
|
- (void) _fillFreeBusyItems: (NSMutableArray *) items
|
|
|
|
withRecords: (NSEnumerator *) records
|
|
|
|
fromStartDate: (NSCalendarDate *) startDate
|
|
|
|
toEndDate: (NSCalendarDate *) endDate
|
|
|
|
{
|
|
|
|
NSDictionary *record;
|
|
|
|
int count, startInterval, endInterval, value;
|
|
|
|
NSNumber *status;
|
|
|
|
NSCalendarDate *currentDate;
|
|
|
|
|
2007-11-27 18:19:24 +01:00
|
|
|
while ((record = [records nextObject]))
|
2007-03-26 15:41:04 +02:00
|
|
|
{
|
2007-08-28 23:42:28 +02:00
|
|
|
status = [record objectForKey: @"c_status"];
|
2007-03-26 15:41:04 +02:00
|
|
|
|
2007-08-28 23:42:28 +02:00
|
|
|
value = [[record objectForKey: @"c_startdate"] intValue];
|
2007-03-26 15:41:04 +02:00
|
|
|
currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value];
|
|
|
|
if ([currentDate earlierDate: startDate] == currentDate)
|
|
|
|
startInterval = 0;
|
|
|
|
else
|
|
|
|
startInterval
|
|
|
|
= ([currentDate timeIntervalSinceDate: startDate] / 900);
|
|
|
|
|
2007-08-28 23:42:28 +02:00
|
|
|
value = [[record objectForKey: @"c_enddate"] intValue];
|
2007-03-26 15:41:04 +02:00
|
|
|
currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value];
|
|
|
|
if ([currentDate earlierDate: endDate] == endDate)
|
|
|
|
endInterval = [items count] - 1;
|
|
|
|
else
|
|
|
|
endInterval = ([currentDate timeIntervalSinceDate: startDate] / 900);
|
|
|
|
|
|
|
|
for (count = startInterval; count < endInterval; count++)
|
|
|
|
[items replaceObjectAtIndex: count withObject: status];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _freeBusyAsTextFromStartDate: (NSCalendarDate *) startDate
|
|
|
|
toEndDate: (NSCalendarDate *) endDate
|
|
|
|
forFreeBusy: (SOGoFreeBusyObject *) fb
|
|
|
|
{
|
|
|
|
NSEnumerator *records;
|
|
|
|
NSMutableArray *freeBusyItems;
|
|
|
|
NSTimeInterval interval;
|
|
|
|
int count, intervals;
|
|
|
|
|
|
|
|
interval = [endDate timeIntervalSinceDate: startDate] + 60;
|
|
|
|
intervals = interval / 900; /* slices of 15 minutes */
|
|
|
|
freeBusyItems = [NSMutableArray arrayWithCapacity: intervals];
|
|
|
|
for (count = 1; count < intervals; count++)
|
|
|
|
[freeBusyItems addObject: @"0"];
|
|
|
|
|
|
|
|
records = [[fb fetchFreeBusyInfosFrom: startDate to: endDate] objectEnumerator];
|
|
|
|
[self _fillFreeBusyItems: freeBusyItems withRecords: records
|
|
|
|
fromStartDate: startDate toEndDate: endDate];
|
|
|
|
|
|
|
|
return [freeBusyItems componentsJoinedByString: @","];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _freeBusyAsText
|
|
|
|
{
|
|
|
|
SOGoFreeBusyObject *co;
|
|
|
|
NSCalendarDate *startDate, *endDate;
|
|
|
|
NSString *queryDay, *additionalDays;
|
|
|
|
NSTimeZone *uTZ;
|
2007-04-11 21:08:58 +02:00
|
|
|
SOGoUser *user;
|
2007-03-26 15:41:04 +02:00
|
|
|
|
|
|
|
co = [self clientObject];
|
2007-04-11 21:08:58 +02:00
|
|
|
user = [context activeUser];
|
|
|
|
uTZ = [user timeZone];
|
2007-03-26 15:41:04 +02:00
|
|
|
|
|
|
|
queryDay = [self queryParameterForKey: @"sday"];
|
|
|
|
if ([queryDay length])
|
|
|
|
startDate = [NSCalendarDate dateFromShortDateString: queryDay
|
|
|
|
andShortTimeString: @"0000"
|
|
|
|
inTimeZone: uTZ];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startDate = [NSCalendarDate calendarDate];
|
|
|
|
[startDate setTimeZone: uTZ];
|
|
|
|
startDate = [startDate hour: 0 minute: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
queryDay = [self queryParameterForKey: @"eday"];
|
|
|
|
if ([queryDay length])
|
|
|
|
endDate = [NSCalendarDate dateFromShortDateString: queryDay
|
|
|
|
andShortTimeString: @"2359"
|
|
|
|
inTimeZone: uTZ];
|
|
|
|
else
|
|
|
|
endDate = [startDate hour: 23 minute: 59];
|
|
|
|
|
|
|
|
additionalDays = [self queryParameterForKey: @"additional"];
|
|
|
|
if ([additionalDays length] > 0)
|
|
|
|
endDate = [endDate dateByAddingYears: 0 months: 0
|
|
|
|
days: [additionalDays intValue]
|
|
|
|
hours: 0 minutes: 0 seconds: 0];
|
|
|
|
|
|
|
|
return [self _freeBusyAsTextFromStartDate: startDate toEndDate: endDate
|
|
|
|
forFreeBusy: co];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) readFreeBusyAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 200];
|
2007-05-15 05:23:35 +02:00
|
|
|
// [response setHeader: @"text/plain; charset=iso-8859-1"
|
|
|
|
// forKey: @"Content-Type"];
|
2007-03-26 15:41:04 +02:00
|
|
|
[response appendContentString: [self _freeBusyAsText]];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-09-04 17:02:03 +02:00
|
|
|
- (id <WOActionResults>) logoffAction
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
WOCookie *cookie;
|
2007-09-04 17:41:59 +02:00
|
|
|
SOGoWebAuthenticator *auth;
|
2007-09-04 17:02:03 +02:00
|
|
|
id container;
|
2007-09-07 00:19:05 +02:00
|
|
|
NSCalendarDate *date;
|
2007-09-04 17:02:03 +02:00
|
|
|
|
|
|
|
container = [[self clientObject] container];
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 302];
|
|
|
|
[response setHeader: [container baseURLInContext: context]
|
|
|
|
forKey: @"location"];
|
|
|
|
auth = [[self clientObject] authenticatorInContext: context];
|
2007-10-26 15:58:15 +02:00
|
|
|
|
|
|
|
date = [NSCalendarDate calendarDate];
|
|
|
|
[date setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
|
|
|
|
2007-09-04 17:02:03 +02:00
|
|
|
cookie = [WOCookie cookieWithName: [auth cookieNameInContext: context]
|
2007-09-07 00:19:05 +02:00
|
|
|
value: @"discard"];
|
2007-09-05 00:04:07 +02:00
|
|
|
[cookie setPath: @"/"];
|
2007-09-07 00:19:05 +02:00
|
|
|
[cookie setExpires: [date yesterday]];
|
2007-09-04 17:02:03 +02:00
|
|
|
[response addCookie: cookie];
|
2007-10-26 15:58:15 +02:00
|
|
|
|
|
|
|
[response setHeader: [date rfc822DateString] forKey: @"Last-Modified"];
|
|
|
|
[response setHeader: @"no-store, no-cache, must-revalidate, max-age=0"
|
|
|
|
forKey: @"Cache-Control"];
|
2007-09-18 00:42:55 +02:00
|
|
|
[response setHeader: @"post-check=0, pre-check=0" forKey: @"Cache-Control"];
|
|
|
|
[response setHeader: @"no-cache" forKey: @"Pragma"];
|
2007-09-04 17:02:03 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-12-05 22:05:04 +01:00
|
|
|
- (NSString *) _foldersStringForFolders: (NSEnumerator *) folders
|
|
|
|
{
|
|
|
|
NSMutableString *foldersString;
|
|
|
|
NSDictionary *currentFolder;
|
|
|
|
|
|
|
|
foldersString = [NSMutableString new];
|
|
|
|
[foldersString autorelease];
|
|
|
|
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
while (currentFolder)
|
|
|
|
{
|
|
|
|
[foldersString appendFormat: @";%@:%@:%@",
|
|
|
|
[currentFolder objectForKey: @"displayName"],
|
|
|
|
[currentFolder objectForKey: @"name"],
|
|
|
|
[currentFolder objectForKey: @"type"]];
|
|
|
|
currentFolder = [folders nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return foldersString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) _foldersResponseForResults: (NSDictionary *) results
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
NSString *uid, *foldersString;
|
|
|
|
NSMutableString *responseString;
|
|
|
|
NSDictionary *contact;
|
|
|
|
NSEnumerator *contacts;
|
|
|
|
NSArray *folders;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
[response setStatus: 200];
|
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"Content-Type"];
|
|
|
|
|
|
|
|
responseString = [NSMutableString new];
|
|
|
|
contacts = [[results allKeys] objectEnumerator];
|
|
|
|
while ((contact = [contacts nextObject]))
|
|
|
|
{
|
|
|
|
uid = [contact objectForKey: @"c_uid"];
|
|
|
|
folders = [results objectForKey: contact];
|
|
|
|
foldersString
|
|
|
|
= [self _foldersStringForFolders: [folders objectEnumerator]];
|
|
|
|
[responseString appendFormat: @"%@:%@:%@%@\n", uid,
|
|
|
|
[contact objectForKey: @"cn"],
|
|
|
|
[contact objectForKey: @"c_email"],
|
|
|
|
foldersString];
|
|
|
|
}
|
|
|
|
[response appendContentString: responseString];
|
|
|
|
[responseString release];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id <WOActionResults>) foldersSearchAction
|
|
|
|
{
|
|
|
|
NSString *contact, *folderType;
|
|
|
|
NSDictionary *folders;
|
|
|
|
id <WOActionResults> result;
|
|
|
|
|
|
|
|
contact = [self queryParameterForKey: @"search"];
|
|
|
|
if ([contact length])
|
|
|
|
{
|
|
|
|
folderType = [self queryParameterForKey: @"type"];
|
|
|
|
if ([folderType length])
|
|
|
|
{
|
|
|
|
folders = [[self clientObject] foldersOfType: folderType
|
|
|
|
matchingUID: contact];
|
|
|
|
result = [self _foldersResponseForResults: folders];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'type' parameter"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'search' parameter"];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-22 18:38:32 +01:00
|
|
|
@end
|