-/*
- Copyright (C) 2004-2005 SKYRIX Software AG
-
- This file is part of OpenGroupware.org.
-
- 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.
-*/
-
+/* 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.
+ */
+
+#import <Foundation/NSArray.h>
+#import <Foundation/NSCalendarDate.h>
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSURL.h>
+#import <Foundation/NSUserDefaults.h>
+#import <Foundation/NSValue.h>
+#import <NGObjWeb/WOCookie.h>
+#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
-#import <SoObjects/Appointments/SOGoFreeBusyObject.h>
-#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
#import <NGExtensions/NSCalendarDate+misc.h>
+#import <NGExtensions/NSObject+Logs.h>
+#import <Appointments/SOGoFreeBusyObject.h>
+#import <SoObjects/SOGo/SOGoWebAuthenticator.h>
+#import <SoObjects/SOGo/SOGoUser.h>
+#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
#import <SOGoUI/UIxComponent.h>
-#import <Scheduler/UIxComponent+Agenor.h>
-@interface SOGoUserHomePage : UIxComponent
-{
- id item;
-}
+static NSString *defaultModule = nil;
-- (NSString *)ownPath;
-- (NSString *)userFolderPath;
-- (NSString *)relativePathToUserFolderSubPath:(NSString *)_sub;
+@interface SOGoUserHomePage : UIxComponent
-- (NSString *)relativeCalendarPath;
-- (NSString *)relativeContactsPath;
-- (NSString *)relativeMailPath;
-
@end
-#include <SOGo/AgenorUserManager.h>
-#include <SOGo/WOContext+Agenor.h>
-#include <SOGo/SOGoUser.h>
-#include "common.h"
-
@implementation SOGoUserHomePage
-static NSArray *internetAccessStates = nil;
-
-+ (void)initialize {
- static BOOL didInit = NO;
-
- if (didInit) return;
- didInit = YES;
-
- internetAccessStates = [[NSArray alloc] initWithObjects:@"0", @"1", nil];
-}
-
-- (void)dealloc {
- [self->item release];
- [super dealloc];
-}
-
-/* lookup */
-
-- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
- // Note: we do no acquisition
- id obj;
-
- /* first check attributes directly bound to the object */
- if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
- return obj;
-
- return nil;
-}
-
-/* accessors */
-
-- (void)setItem:(id)_item {
- ASSIGN(self->item, _item);
-}
-- (id)item {
- return self->item;
-}
-
-- (NSArray *)internetAccessStates {
- return internetAccessStates;
-}
-
-- (NSString *)internetAccessState {
- NSUserDefaults *ud;
- NSNumber *value;
-
- ud = [[[self context] activeUser] userDefaults];
- value = [ud objectForKey:@"allowinternet"];
- return [NSString stringWithFormat:@"%d", [value boolValue]];
-}
-- (void)setInternetAccessState:(NSString *)_internetAccessState {
++ (void) initialize
+{
NSUserDefaults *ud;
-
- ud = [[[self context] activeUser] userDefaults];
- [ud setObject:_internetAccessState forKey:@"allowinternet"];
- [ud synchronize];
-}
-
-- (NSString *)itemInternetAccessStateText {
- NSString *key;
-
- key = [NSString stringWithFormat:@"internetAccessState_%@", self->item];
- return key;
-}
-
-/* paths */
-
-- (NSString *)ownPath {
- NSString *uri;
- NSRange r;
-
- uri = [[[self context] request] uri];
-
- /* first: cut off query parameters */
-
- r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
- if (r.length > 0)
- uri = [uri substringToIndex:r.location];
- return uri;
-}
-
-- (NSString *)userFolderPath {
- WOContext *ctx;
- NSArray *traversalObjects;
- NSString *url;
-
- ctx = [self context];
- traversalObjects = [ctx objectTraversalStack];
- url = [[traversalObjects objectAtIndex:1]
- baseURLInContext:ctx];
- return [[NSURL URLWithString:url] path];
-}
-
-- (NSString *)relativePathToUserFolderSubPath:(NSString *)_sub {
- NSString *dst, *rel;
-
- dst = [[self userFolderPath] stringByAppendingPathComponent:_sub];
- rel = [dst urlPathRelativeToPath:[self ownPath]];
- return rel;
-}
-
-- (NSString *)relativeCalendarPath {
- return [self relativePathToUserFolderSubPath:@"Calendar/"];
-}
-
-- (NSString *)relativeContactsPath {
- return [self relativePathToUserFolderSubPath:@"Contacts/"];
-}
-
-- (NSString *)relativeMailPath {
- return [NSString stringWithFormat: @"%@%@/view",
- [self relativePathToUserFolderSubPath:@"Mail/"],
- [self emailForUser]];
-}
-
-/* objects */
-- (id)calendarFolder {
- return [[self clientObject] lookupName:@"Calendar"
- inContext:[self context]
- acquire:NO];
-}
-
-/* checking access */
-
-- (BOOL)canAccess {
- WOContext *ctx;
- NSString *owner;
-
- ctx = [self context];
- owner = [[self clientObject] ownerInContext:ctx];
- return [owner isEqualToString:[[ctx activeUser] login]];
-}
-
-- (BOOL)isNotAllowedToChangeInternetAccess {
- // TODO: should be a SOGoUser method
- AgenorUserManager *um;
- WOContext *ctx;
- NSString *uid;
-
- ctx = [self context];
- /* do not allow changes when access is from Internet */
- if (![ctx isAccessFromIntranet])
- return YES;
- um = [AgenorUserManager sharedUserManager];
- uid = [[ctx activeUser] login];
- return [um isUserAllowedToChangeSOGoInternetAccess:uid] ? NO : YES;
-}
-
-- (BOOL)isVacationMessageEnabledForInternet {
- // TODO: should be a SOGoUser method
- AgenorUserManager *um;
- NSString *uid;
-
- um = [AgenorUserManager sharedUserManager];
- uid = [[[self context] activeUser] login];
- return [um isInternetAutoresponderEnabledForUser:uid];
-}
-
-- (BOOL)isVacationMessageEnabledForIntranet {
- // TODO: should be a SOGoUser method
- AgenorUserManager *um;
- NSString *uid;
-
- um = [AgenorUserManager sharedUserManager];
- uid = [[[self context] activeUser] login];
- return [um isIntranetAutoresponderEnabledForUser:uid];
+ if (!defaultModule)
+ {
+ ud = [NSUserDefaults standardUserDefaults];
+ defaultModule = [ud stringForKey: @"SOGoUIxDefaultModule"];
+ 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];
+ }
}
-/* actions */
-
-#if 0
-- (id)defaultAction {
- return [self redirectToLocation:[self relativeCalendarPath]];
-}
-#endif
+- (id <WOActionResults>) defaultAction
+{
+ SOGoUserFolder *co;
+ NSURL *moduleURL;
-/* this is triggered by an XMLHTTPRequest */
-- (id)saveInternetAccessStateAction {
- NSString *state;
-
- if ([self isNotAllowedToChangeInternetAccess])
- return [NSException exceptionWithHTTPStatus:403 /* Forbidden */];
+ co = [self clientObject];
+ moduleURL = [NSURL URLWithString: defaultModule
+ relativeToURL: [co soURL]];
- state = [[[self context] request] formValueForKey:@"allowinternet"];
- [self setInternetAccessState:state];
- return [NSException exceptionWithHTTPStatus:200 /* OK */];
+ return [self redirectToLocation: [moduleURL absoluteString]];
}
- (void) _fillFreeBusyItems: (NSMutableArray *) items
int count, startInterval, endInterval, value;
NSNumber *status;
NSCalendarDate *currentDate;
-
+
record = [records nextObject];
while (record)
{
- status = [record objectForKey: @"status"];
-
- value = [[record objectForKey: @"startdate"] intValue];
+ status = [record objectForKey: @"c_status"];
+
+ value = [[record objectForKey: @"c_startdate"] intValue];
currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value];
if ([currentDate earlierDate: startDate] == currentDate)
startInterval = 0;
startInterval
= ([currentDate timeIntervalSinceDate: startDate] / 900);
- value = [[record objectForKey: @"enddate"] intValue];
+ value = [[record objectForKey: @"c_enddate"] intValue];
currentDate = [NSCalendarDate dateWithTimeIntervalSince1970: value];
if ([currentDate earlierDate: endDate] == endDate)
endInterval = [items count] - 1;
record = [records nextObject];
}
}
-
+
- (NSString *) _freeBusyAsTextFromStartDate: (NSCalendarDate *) startDate
toEndDate: (NSCalendarDate *) endDate
forFreeBusy: (SOGoFreeBusyObject *) fb
NSCalendarDate *startDate, *endDate;
NSString *queryDay, *additionalDays;
NSTimeZone *uTZ;
+ SOGoUser *user;
co = [self clientObject];
- uTZ = [co userTimeZone];
+ user = [context activeUser];
+ uTZ = [user timeZone];
queryDay = [self queryParameterForKey: @"sday"];
if ([queryDay length])
response = [context response];
[response setStatus: 200];
- [response setHeader: @"text/plain; charset=iso-8859-1"
- forKey: @"Content-Type"];
+// [response setHeader: @"text/plain; charset=iso-8859-1"
+// forKey: @"Content-Type"];
[response appendContentString: [self _freeBusyAsText]];
return response;
}
-@end /* SOGoUserHomePage */
+- (id <WOActionResults>) logoffAction
+{
+ WOResponse *response;
+ WOCookie *cookie;
+ SOGoWebAuthenticator *auth;
+ id container;
+ NSCalendarDate *date;
+
+ container = [[self clientObject] container];
+
+ response = [context response];
+ [response setStatus: 302];
+ [response setHeader: [container baseURLInContext: context]
+ forKey: @"location"];
+ auth = [[self clientObject] authenticatorInContext: context];
+ cookie = [WOCookie cookieWithName: [auth cookieNameInContext: context]
+ value: @"discard"];
+ [cookie setPath: @"/"];
+ date = [NSCalendarDate calendarDate];
+ [cookie setExpires: [date yesterday]];
+ [response addCookie: cookie];
+
+ [response setHeader: date forKey: @"Last-Modified"];
+ [response setHeader: @"no-store, no-cache, must-revalidate, max-age=0" forKey: @"Cache-Control"];
+ [response setHeader: @"post-check=0, pre-check=0" forKey: @"Cache-Control"];
+ [response setHeader: @"no-cache" forKey: @"Pragma"];
+
+ return response;
+}
+
+@end