2001-01-11 20:41:38 +01:00
< ? php
2003-08-28 16:31:11 +02:00
/************************************************************************** \
2004-05-05 14:06:13 +02:00
* eGroupWare API - phpgwapi loader *
2003-08-28 16:31:11 +02:00
* This file written by Dan Kuykendall < seek3r @ phpgroupware . org > *
* and Joseph Engo < jengo @ phpgroupware . org > *
* Has a few functions , but primary role is to load the phpgwapi *
* Copyright ( C ) 2000 , 2001 Dan Kuykendall *
* -------------------------------------------------------------------------*
2004-05-05 14:06:13 +02:00
* This library is part of the eGroupWare API *
* http :// www . egroupware . org / api *
2003-08-28 16:31:11 +02:00
* ------------------------------------------------------------------------ *
* This library 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.1 of the License , *
* or any later version . *
* This library 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 this library ; if not , write to the Free Software Foundation , *
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA *
\ **************************************************************************/
2001-09-06 10:27:22 +02:00
/* $Id$ */
2003-05-18 21:18:58 +02:00
2003-12-19 11:46:37 +01:00
/*************************************************************************** \
* If running in PHP3 , then force admin to upgrade *
\ ***************************************************************************/
2001-08-16 08:32:22 +02:00
2004-03-09 22:05:28 +01:00
error_reporting ( error_reporting () & ~ E_NOTICE );
2003-08-28 16:31:11 +02:00
if ( ! function_exists ( 'version_compare' )) //version_compare() is only available in PHP4.1+
2001-09-06 10:27:22 +02:00
{
2004-01-26 04:34:17 +01:00
echo 'eGroupWare requires PHP 4.1 or greater.<br>' ;
2003-05-18 21:18:58 +02:00
echo 'Please contact your System Administrator' ;
exit ;
2001-09-06 10:27:22 +02:00
}
2001-08-16 08:32:22 +02:00
2002-03-01 13:31:50 +01:00
include ( PHPGW_API_INC . '/common_functions.inc.php' );
2003-08-28 16:31:11 +02:00
2001-08-08 16:03:20 +02:00
/*!
@ function lang
@ abstract function to handle multilanguage support
2001-09-06 10:27:22 +02:00
*/
2001-08-08 16:03:20 +02:00
function lang ( $key , $m1 = '' , $m2 = '' , $m3 = '' , $m4 = '' , $m5 = '' , $m6 = '' , $m7 = '' , $m8 = '' , $m9 = '' , $m10 = '' )
{
2001-09-06 21:23:56 +02:00
if ( is_array ( $m1 ))
2001-08-08 02:13:00 +02:00
{
2001-08-08 16:03:20 +02:00
$vars = $m1 ;
2001-08-08 02:13:00 +02:00
}
else
{
2001-08-08 16:03:20 +02:00
$vars = array ( $m1 , $m2 , $m3 , $m4 , $m5 , $m6 , $m7 , $m8 , $m9 , $m10 );
2001-08-08 02:13:00 +02:00
}
2005-03-03 11:47:28 +01:00
$value = $GLOBALS [ 'egw' ] -> translation -> translate ( " $key " , $vars );
2001-08-08 16:03:20 +02:00
return $value ;
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
2001-09-06 10:27:22 +02:00
/* Make sure the header.inc.php is current. */
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'versions' ][ 'header' ] < $GLOBALS [ 'egw_info' ][ 'server' ][ 'versions' ][ 'current_header' ])
2001-08-08 16:03:20 +02:00
{
2004-06-28 09:06:29 +02:00
echo '<center><b>You need to port your settings to the new header.inc.php version by running <a href="setup/manageheader.php">setup/headeradmin</a>.</b></center>' ;
2001-08-08 16:03:20 +02:00
exit ;
}
2001-09-06 10:27:22 +02:00
/* Make sure the developer is following the rules. */
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ]))
2001-08-08 02:13:00 +02:00
{
2003-08-28 16:31:11 +02:00
/* This object does not exist yet. */
2005-03-03 11:47:28 +01:00
/* $GLOBALS['egw']->log->write(array('text'=>'W-MissingFlags, currentapp flag not set'));*/
2003-08-28 16:31:11 +02:00
echo '<b>!!! YOU DO NOT HAVE YOUR $GLOBALS[\'phpgw_info\'][\'flags\'][\'currentapp\'] SET !!!' ;
echo '<br>!!! PLEASE CORRECT THIS SITUATION !!!</b>' ;
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
magic_quotes_runtime ( false );
2003-08-28 16:31:11 +02:00
print_debug ( 'sane environment' , 'messageonly' , 'api' );
2001-08-08 16:03:20 +02:00
/**************************************************************************** \
* Multi - Domain support *
\ ****************************************************************************/
2003-05-18 21:18:58 +02:00
2001-08-08 16:03:20 +02:00
/* make them fix their header */
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_domain' ]))
2001-08-08 02:13:00 +02:00
{
2001-08-08 16:03:20 +02:00
echo '<center><b>The administrator must upgrade the header.inc.php file before you can continue.</b></center>' ;
exit ;
2001-08-08 02:13:00 +02:00
}
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]) || // allow to overwrite the default domain
! isset ( $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]]))
2004-02-04 01:33:37 +01:00
{
2005-03-03 11:47:28 +01:00
reset ( $GLOBALS [ 'egw_domain' ]);
list ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]) = each ( $GLOBALS [ 'egw_domain' ]);
2004-02-04 01:33:37 +01:00
}
2003-05-18 21:18:58 +02:00
if ( isset ( $_POST [ 'login' ])) // on login
2001-08-08 16:03:20 +02:00
{
2003-05-18 21:18:58 +02:00
$GLOBALS [ 'login' ] = $_POST [ 'login' ];
2005-03-03 11:47:28 +01:00
if ( strstr ( $GLOBALS [ 'login' ], '@' ) === False || count ( $GLOBALS [ 'egw_domain' ]) == 1 )
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'login' ] .= '@' . get_var ( 'logindomain' , array ( 'POST' ), $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]);
2001-08-08 02:13:00 +02:00
}
2003-11-14 00:15:55 +01:00
$parts = explode ( '@' , $GLOBALS [ 'login' ]);
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ] = array_pop ( $parts );
2001-08-08 02:13:00 +02:00
}
2003-05-18 21:18:58 +02:00
else // on "normal" pageview
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ] = get_var ( 'domain' , array ( 'GET' , 'COOKIE' ), FALSE );
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
2005-03-03 11:47:28 +01:00
if ( @ isset ( $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]]))
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_host' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_host' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_port' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_port' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_name' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_name' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_user' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_user' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_pass' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_pass' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_type' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ]][ 'db_type' ];
2001-08-08 02:13:00 +02:00
}
else
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_host' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_host' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_port' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_port' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_name' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_name' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_user' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_user' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_pass' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_pass' ];
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_type' ] = $GLOBALS [ 'egw_domain' ][ $GLOBALS [ 'egw_info' ][ 'server' ][ 'default_domain' ]][ 'db_type' ];
2001-08-08 02:13:00 +02:00
}
2001-08-07 18:02:55 +02:00
2005-03-03 11:47:28 +01:00
$domain_names = array_keys ( $GLOBALS [ 'egw_domain' ]);
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] != 'login' && ! $GLOBALS [ 'egw_info' ][ 'server' ][ 'show_domain_selectbox' ])
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
unset ( $GLOBALS [ 'egw_domain' ]); // we kill this for security reasons
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
2005-03-03 11:47:28 +01:00
print_debug ( 'domain' , @ $GLOBALS [ 'egw_info' ][ 'user' ][ 'domain' ], 'api' );
2001-08-08 16:03:20 +02:00
2003-08-28 16:31:11 +02:00
/**************************************************************************** \
* These lines load up the API , fill up the $phpgw_info array , etc *
\ ****************************************************************************/
2001-08-08 16:03:20 +02:00
/* Load main class */
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] = CreateObject ( 'phpgwapi.egw' );
// for the migration
$GLOBALS [ 'phpgw' ] =& $GLOBALS [ 'egw' ];
2003-08-28 16:31:11 +02:00
/************************************************************************ \
* Load up the main instance of the db class . *
\ ************************************************************************/
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db = CreateObject ( 'phpgwapi.db' );
if ( $GLOBALS [ 'egw' ] -> debug )
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> Debug = 1 ;
2001-08-08 02:13:00 +02:00
}
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> Halt_On_Error = 'no' ;
$GLOBALS [ 'egw' ] -> db -> connect (
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_name' ],
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_host' ],
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_port' ],
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_user' ],
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_pass' ],
$GLOBALS [ 'egw_info' ][ 'server' ][ 'db_type' ]
2004-04-02 09:36:11 +02:00
);
2005-03-03 11:47:28 +01:00
@ $GLOBALS [ 'egw' ] -> db -> query ( " SELECT COUNT(config_name) FROM phpgw_config " );
if ( !@ $GLOBALS [ 'egw' ] -> db -> next_record ())
2001-08-08 02:13:00 +02:00
{
2003-12-10 12:34:39 +01:00
$setup_dir = str_replace ( $_SERVER [ 'PHP_SELF' ], 'index.php' , 'setup/' );
2001-08-08 16:03:20 +02:00
echo '<center><b>Fatal Error:</b> It appears that you have not created the database tables for '
2003-12-19 11:46:37 +01:00
. 'eGroupWare. Click <a href="' . $setup_dir . '">here</a> to run setup.</center>' ;
2001-08-08 16:03:20 +02:00
exit ;
2001-08-08 02:13:00 +02:00
}
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> Halt_On_Error = 'yes' ;
2001-08-08 16:03:20 +02:00
2004-11-21 10:44:02 +01:00
// Set the DB's client charset if a system-charset is set
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( " select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='system_charset' " , __LINE__ , __FILE__ );
if ( $GLOBALS [ 'egw' ] -> db -> next_record () && $GLOBALS [ 'egw' ] -> db -> f ( 0 ))
2004-11-21 10:44:02 +01:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> Link_ID -> SetCharSet ( $GLOBALS [ 'egw' ] -> db -> f ( 0 ));
2004-11-21 10:44:02 +01:00
}
2003-12-19 11:46:37 +01:00
/* Fill phpgw_info["server"] array */
// An Attempt to speed things up using cache premise
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( " select config_value from phpgw_config WHERE config_app='phpgwapi' and config_name='cache_phpgw_info' " , __LINE__ , __FILE__ );
if ( $GLOBALS [ 'egw' ] -> db -> num_rows ())
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> next_record ();
$GLOBALS [ 'egw_info' ][ 'server' ][ 'cache_phpgw_info' ] = stripslashes ( $GLOBALS [ 'egw' ] -> db -> f ( 'config_value' ));
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
$cache_query = " select content from phpgw_app_sessions where "
. " sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config' " ;
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( $cache_query , __LINE__ , __FILE__ );
$server_info_cache = $GLOBALS [ 'egw' ] -> db -> num_rows ();
2001-08-08 16:03:20 +02:00
2005-03-03 11:47:28 +01:00
if ( @ $GLOBALS [ 'egw_info' ][ 'server' ][ 'cache_phpgw_info' ] && $server_info_cache )
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> next_record ();
$GLOBALS [ 'egw_info' ][ 'server' ] = unserialize ( stripslashes ( $GLOBALS [ 'egw' ] -> db -> f ( 'content' )));
2001-08-08 02:13:00 +02:00
}
else
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( " select * from phpgw_config WHERE config_app='phpgwapi' " , __LINE__ , __FILE__ );
while ( $GLOBALS [ 'egw' ] -> db -> next_record ())
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'server' ][ $GLOBALS [ 'egw' ] -> db -> f ( 'config_name' )] = stripslashes ( $GLOBALS [ 'egw' ] -> db -> f ( 'config_value' ));
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
2005-03-03 11:47:28 +01:00
if ( @ isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'cache_phpgw_info' ]))
2001-08-08 02:13:00 +02:00
{
2001-08-08 16:03:20 +02:00
if ( $server_info_cache )
{
2002-01-13 05:06:40 +01:00
$cache_query = " DELETE FROM phpgw_app_sessions WHERE sessionid='0' and loginid='0' and app='phpgwapi' and location='config' " ;
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> db -> query ( $cache_query , __LINE__ , __FILE__ );
2001-08-08 16:03:20 +02:00
}
2002-01-13 05:06:40 +01:00
$cache_query = 'INSERT INTO phpgw_app_sessions(sessionid,loginid,app,location,content) VALUES('
2005-03-03 11:47:28 +01:00
. " '0','0','phpgwapi','config',' " . addslashes ( serialize ( $GLOBALS [ 'egw_info' ][ 'server' ])) . " ') " ;
$GLOBALS [ 'egw' ] -> db -> query ( $cache_query , __LINE__ , __FILE__ );
2001-08-08 02:13:00 +02:00
}
}
2001-08-08 16:03:20 +02:00
unset ( $cache_query );
unset ( $server_info_cache );
2005-03-03 11:47:28 +01:00
if ( @ isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'enforce_ssl' ]) && ! $_SERVER [ 'HTTPS' ])
2003-05-18 21:18:58 +02:00
{
2005-03-03 11:47:28 +01:00
Header ( 'Location: https://' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'hostname' ] . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . $_SERVER [ 'REQUEST_URI' ]);
2003-05-18 21:18:58 +02:00
exit ;
}
2003-10-19 20:05:27 +02:00
/**************************************************************************** \
* This is a global constant that should be used *
* instead of / or \ in file paths *
\ ****************************************************************************/
define ( 'SEP' , filesystem_separator ());
2001-09-06 10:27:22 +02:00
/************************************************************************ \
* Required classes *
\ ************************************************************************/
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log = CreateObject ( 'phpgwapi.errorlog' );
$GLOBALS [ 'egw' ] -> translation = CreateObject ( 'phpgwapi.translation' );
$GLOBALS [ 'egw' ] -> common = CreateObject ( 'phpgwapi.common' );
$GLOBALS [ 'egw' ] -> hooks = CreateObject ( 'phpgwapi.hooks' );
$GLOBALS [ 'egw' ] -> auth = CreateObject ( 'phpgwapi.auth' );
$GLOBALS [ 'egw' ] -> accounts = CreateObject ( 'phpgwapi.accounts' );
$GLOBALS [ 'egw' ] -> acl = CreateObject ( 'phpgwapi.acl' );
$GLOBALS [ 'egw' ] -> session = CreateObject ( 'phpgwapi.sessions' , $domain_names );
$GLOBALS [ 'egw' ] -> preferences = CreateObject ( 'phpgwapi.preferences' );
$GLOBALS [ 'egw' ] -> applications = CreateObject ( 'phpgwapi.applications' );
$GLOBALS [ 'egw' ] -> contenthistory = CreateObject ( 'phpgwapi.contenthistory' );
2002-02-14 08:29:26 +01:00
print_debug ( 'main class loaded' , 'messageonly' , 'api' );
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'included_classes' ][ 'error' ]) ||
! $GLOBALS [ 'egw_info' ][ 'flags' ][ 'included_classes' ][ 'error' ])
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
include ( EGW_INCLUDE_ROOT . '/phpgwapi/inc/class.error.inc.php' );
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'included_classes' ][ 'error' ] = True ;
2001-08-08 16:03:20 +02:00
}
2001-08-23 06:32:15 +02:00
/***************************************************************************** \
* ACL defines - moved here to work for xml - rpc / soap , also *
\ *****************************************************************************/
2005-03-03 11:47:28 +01:00
define ( 'EGW_ACL_READ' , 1 );
define ( 'EGW_ACL_ADD' , 2 );
define ( 'EGW_ACL_EDIT' , 4 );
define ( 'EGW_ACL_DELETE' , 8 );
define ( 'EGW_ACL_PRIVATE' , 16 );
define ( 'EGW_ACL_GROUP_MANAGERS' , 32 );
define ( 'EGW_ACL_CUSTOM_1' , 64 );
define ( 'EGW_ACL_CUSTOM_2' , 128 );
define ( 'EGW_ACL_CUSTOM_3' , 256 );
// and the old ones
2001-08-23 06:32:15 +02:00
define ( 'PHPGW_ACL_READ' , 1 );
define ( 'PHPGW_ACL_ADD' , 2 );
define ( 'PHPGW_ACL_EDIT' , 4 );
define ( 'PHPGW_ACL_DELETE' , 8 );
define ( 'PHPGW_ACL_PRIVATE' , 16 );
2002-01-10 19:18:44 +01:00
define ( 'PHPGW_ACL_GROUP_MANAGERS' , 32 );
2003-08-28 16:31:11 +02:00
define ( 'PHPGW_ACL_CUSTOM_1' , 64 );
define ( 'PHPGW_ACL_CUSTOM_2' , 128 );
define ( 'PHPGW_ACL_CUSTOM_3' , 256 );
2001-08-23 06:32:15 +02:00
2002-09-28 17:20:20 +02:00
/**************************************************************************** \
* Forcing the footer to run when the rest of the script is done . *
\ ****************************************************************************/
2005-03-03 11:47:28 +01:00
register_shutdown_function ( array ( $GLOBALS [ 'egw' ] -> common , 'egw_final' ));
2002-10-26 22:33:04 +02:00
2001-09-06 10:27:22 +02:00
/**************************************************************************** \
* Stuff to use if logging in or logging out *
\ ****************************************************************************/
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'login' || $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'logout' )
2001-08-08 16:03:20 +02:00
{
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] == 'login' )
2001-08-08 02:13:00 +02:00
{
2003-05-18 21:18:58 +02:00
if ( @ $_POST [ 'login' ] != '' )
2001-08-08 16:03:20 +02:00
{
2005-03-03 11:47:28 +01:00
if ( count ( $GLOBALS [ 'egw_domain' ]) > 1 )
2003-11-14 00:15:55 +01:00
{
list ( $login ) = explode ( '@' , $_POST [ 'login' ]);
}
else
{
$login = $_POST [ 'login' ];
}
2003-05-18 21:18:58 +02:00
print_debug ( 'LID' , $login , 'app' );
2005-03-03 11:47:28 +01:00
$login_id = $GLOBALS [ 'egw' ] -> accounts -> name2id ( $login );
2003-05-18 21:18:58 +02:00
print_debug ( 'User ID' , $login_id , 'app' );
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> accounts -> accounts ( $login_id );
$GLOBALS [ 'egw' ] -> preferences -> preferences ( $login_id );
$GLOBALS [ 'egw' ] -> datetime = CreateObject ( 'phpgwapi.datetime' );
2001-08-08 16:03:20 +02:00
}
2001-08-08 02:13:00 +02:00
}
2001-09-06 10:27:22 +02:00
/************************************************************************** \
* Everything from this point on will ONLY happen if *
* the currentapp is not login or logout *
\ **************************************************************************/
2001-08-08 02:13:00 +02:00
}
2001-08-08 16:03:20 +02:00
else
2001-08-08 02:13:00 +02:00
{
2005-03-03 11:47:28 +01:00
if ( ! $GLOBALS [ 'egw' ] -> session -> verify ())
2001-08-08 16:03:20 +02:00
{
2004-07-03 14:38:01 +02:00
// we forward to the same place after the re-login
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] && $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] != '/' )
2004-07-03 14:38:01 +02:00
{
2005-03-03 11:47:28 +01:00
list (, $relpath ) = explode ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ], $_SERVER [ 'PHP_SELF' ], 2 );
2004-07-03 14:38:01 +02:00
}
else // the webserver-url is empty or just a slash '/' (eGW is installed in the docroot and no domain given)
{
if ( preg_match ( '/^https?:\/\/[^\/]*\/(.*)$/' , $relpath = $_SERVER [ 'PHP_SELF' ], $matches ))
{
$relpath = $matches [ 1 ];
}
}
2004-05-03 15:52:09 +02:00
// this removes the sessiondata if its saved in the URL
2004-11-03 06:01:36 +01:00
$query = preg_replace ( '/[&]?sessionid(=|%3D)[^&]+&kp3(=|%3D)[^&]+&domain=.*$/' , '' , $_SERVER [ 'QUERY_STRING' ]);
2005-03-03 11:47:28 +01:00
Header ( 'Location: ' . $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ] . '/login.php?cd=10&phpgw_forward=' . urlencode ( $relpath . ( ! empty ( $query ) ? '?' . $query : '' )));
2004-05-03 15:52:09 +02:00
exit ;
2001-08-08 16:03:20 +02:00
}
2001-08-07 18:02:55 +02:00
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> datetime = CreateObject ( 'phpgwapi.datetime' );
2002-04-30 05:35:52 +02:00
2003-08-28 16:31:11 +02:00
/* A few hacker resistant constants that will be used throught the program */
2005-03-03 11:47:28 +01:00
define ( 'EGW_TEMPLATE_DIR' , $GLOBALS [ 'egw' ] -> common -> get_tpl_dir ( 'phpgwapi' ));
define ( 'EGW_IMAGES_DIR' , $GLOBALS [ 'egw' ] -> common -> get_image_path ( 'phpgwapi' ));
define ( 'EGW_IMAGES_FILEDIR' , $GLOBALS [ 'egw' ] -> common -> get_image_dir ( 'phpgwapi' ));
define ( 'EGW_APP_ROOT' , $GLOBALS [ 'egw' ] -> common -> get_app_dir ());
define ( 'EGW_APP_INC' , $GLOBALS [ 'egw' ] -> common -> get_inc_dir ());
define ( 'EGW_APP_TPL' , $GLOBALS [ 'egw' ] -> common -> get_tpl_dir ());
define ( 'EGW_IMAGES' , $GLOBALS [ 'egw' ] -> common -> get_image_path ());
define ( 'EGW_APP_IMAGES_DIR' , $GLOBALS [ 'egw' ] -> common -> get_image_dir ());
// and the old ones
define ( 'PHPGW_TEMPLATE_DIR' , $GLOBALS [ 'egw' ] -> common -> get_tpl_dir ( 'phpgwapi' ));
define ( 'PHPGW_IMAGES_DIR' , $GLOBALS [ 'egw' ] -> common -> get_image_path ( 'phpgwapi' ));
define ( 'PHPGW_IMAGES_FILEDIR' , $GLOBALS [ 'egw' ] -> common -> get_image_dir ( 'phpgwapi' ));
define ( 'PHPGW_APP_ROOT' , $GLOBALS [ 'egw' ] -> common -> get_app_dir ());
define ( 'PHPGW_APP_INC' , $GLOBALS [ 'egw' ] -> common -> get_inc_dir ());
define ( 'PHPGW_APP_TPL' , $GLOBALS [ 'egw' ] -> common -> get_tpl_dir ());
define ( 'PHPGW_IMAGES' , $GLOBALS [ 'egw' ] -> common -> get_image_path ());
define ( 'PHPGW_APP_IMAGES_DIR' , $GLOBALS [ 'egw' ] -> common -> get_image_dir ());
2002-10-25 05:04:28 +02:00
2003-08-28 16:31:11 +02:00
/********* This sets the user variables *********/
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'private_dir' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'files_dir' ]
. '/users/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'userid' ];
2002-10-25 05:04:28 +02:00
/* This will make sure that a user has the basic default prefs. If not it will add them */
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> preferences -> verify_basic_settings ();
2002-10-25 05:04:28 +02:00
/********* Optional classes, which can be disabled for performance increases *********/
2005-03-03 11:47:28 +01:00
while ( $phpgw_class_name = each ( $GLOBALS [ 'egw_info' ][ 'flags' ]))
2002-10-25 05:04:28 +02:00
{
if ( ereg ( 'enable_' , $phpgw_class_name [ 0 ]))
{
$enable_class = str_replace ( 'enable_' , '' , $phpgw_class_name [ 0 ]);
$enable_class = str_replace ( '_class' , '' , $enable_class );
eval ( '$GLOBALS["phpgw"]->' . $enable_class . ' = createobject(\'phpgwapi.' . $enable_class . '\');' );
}
}
unset ( $enable_class );
2005-03-03 11:47:28 +01:00
reset ( $GLOBALS [ 'egw_info' ][ 'flags' ]);
2002-10-25 05:04:28 +02:00
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* These lines load up the templates class *
\ *************************************************************************/
2005-03-03 11:47:28 +01:00
if ( !@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'disable_Template_class' ])
2002-10-25 05:04:28 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> template = CreateObject ( 'phpgwapi.Template' , PHPGW_APP_TPL );
2002-10-25 05:04:28 +02:00
}
2002-11-02 23:25:14 +01:00
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* These lines load up the themes *
\ *************************************************************************/
2005-03-03 11:47:28 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ])
2002-10-25 05:04:28 +02:00
{
2005-03-03 11:47:28 +01:00
if ( @ $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ] == 'user_choice' )
2002-10-25 05:04:28 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] = 'default' ;
2002-10-25 05:04:28 +02:00
}
2003-08-28 16:31:11 +02:00
else
2002-10-25 05:04:28 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'template_set' ];
2002-10-25 05:04:28 +02:00
}
2003-08-28 16:31:11 +02:00
}
2005-03-03 11:47:28 +01:00
if ( @ $GLOBALS [ 'egw_info' ][ 'server' ][ 'force_theme' ] == 'user_choice' )
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
if ( ! isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ]))
2002-10-25 05:04:28 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] = 'default' ;
2002-10-25 05:04:28 +02:00
}
}
2003-08-28 16:31:11 +02:00
else
2002-05-30 11:47:09 +02:00
{
2005-03-03 11:47:28 +01:00
if ( isset ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'force_theme' ]))
2003-08-28 16:31:11 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] = $GLOBALS [ 'egw_info' ][ 'server' ][ 'force_theme' ];
2003-08-28 16:31:11 +02:00
}
2002-05-30 11:47:09 +02:00
}
2005-03-03 11:47:28 +01:00
if ( @ file_exists ( EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] . '.theme' ))
2002-05-30 11:47:09 +02:00
{
2005-03-03 11:47:28 +01:00
include ( EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'theme' ] . '.theme' );
2002-05-30 11:47:09 +02:00
}
2005-03-03 11:47:28 +01:00
elseif ( @ file_exists ( EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme' ))
2002-05-30 11:47:09 +02:00
{
2005-03-03 11:47:28 +01:00
include ( EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme' );
2002-05-30 11:47:09 +02:00
}
else
{
2003-08-28 16:31:11 +02:00
/* Hope we don't get to this point. Better then the user seeing a */
/* complety back screen and not know whats going on */
echo '<body bgcolor="FFFFFF">' ;
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log -> write ( array ( 'text' => 'F-Abort, No themes found' ));
2001-08-08 16:03:20 +02:00
2003-08-28 16:31:11 +02:00
exit ;
2001-08-08 02:13:00 +02:00
}
2003-08-28 16:31:11 +02:00
unset ( $theme_to_load );
2001-08-07 18:02:55 +02:00
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* If they are using frames , we need to set some variables *
\ *************************************************************************/
2005-03-03 11:47:28 +01:00
if ((( isset ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'useframes' ]) &&
$GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'useframes' ]) &&
$GLOBALS [ 'egw_info' ][ 'server' ][ 'useframes' ] == 'allowed' ) ||
( $GLOBALS [ 'egw_info' ][ 'server' ][ 'useframes' ] == 'always' ))
2002-05-24 12:38:03 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'navbar_target' ] = 'phpgw_body' ;
2002-05-30 23:13:07 +02:00
}
2001-08-08 16:03:20 +02:00
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* Verify that the users session is still active otherwise kick them out *
\ *************************************************************************/
2005-03-03 11:47:28 +01:00
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] != 'home' &&
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ] != 'about' )
2002-05-23 23:28:59 +02:00
{
2003-08-28 16:31:11 +02:00
// This will need to use ACL in the future
2005-03-03 11:47:28 +01:00
if ( ! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ]] ||
( @ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'admin_only' ] &&
! $GLOBALS [ 'egw_info' ][ 'user' ][ 'apps' ][ 'admin' ]))
2002-05-30 11:47:09 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> common -> phpgw_header ();
if ( $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ])
2003-08-28 16:31:11 +02:00
{
echo parse_navbar ();
}
2002-10-25 05:04:28 +02:00
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> log -> write ( array ( 'text' => 'W-Permissions, Attempted to access %1' , 'p1' => $GLOBALS [ 'egw_info' ][ 'flags' ][ 'currentapp' ]));
2002-10-25 05:04:28 +02:00
2003-08-28 16:31:11 +02:00
echo '<p><center><b>' . lang ( 'Access not permitted' ) . '</b></center>' ;
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> common -> phpgw_exit ( True );
2001-08-08 16:03:20 +02:00
}
2001-08-08 02:13:00 +02:00
}
2002-10-25 05:04:28 +02:00
2005-03-03 11:47:28 +01:00
if ( ! is_object ( $GLOBALS [ 'egw' ] -> datetime ))
2002-05-30 11:47:09 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> datetime = CreateObject ( 'phpgwapi.datetime' );
2002-05-30 11:47:09 +02:00
}
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> applications -> read_installed_apps (); // to get translated app-titles
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* Load the header unless the developer turns it off *
\ *************************************************************************/
2005-03-03 11:47:28 +01:00
if ( !@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ])
2001-08-08 16:03:20 +02:00
{
2005-03-03 11:47:28 +01:00
$GLOBALS [ 'egw' ] -> common -> phpgw_header ();
2001-08-08 16:03:20 +02:00
}
2002-10-25 05:04:28 +02:00
2003-08-28 16:31:11 +02:00
/************************************************************************* \
* Load the app include files if the exists *
\ *************************************************************************/
/* Then the include file */
2004-06-11 12:36:14 +02:00
if ( PHPGW_APP_INC != " " &&
! preg_match ( " /phpgwapi/i " , PHPGW_APP_INC ) &&
file_exists ( PHPGW_APP_INC . '/functions.inc.php' ) &&
! isset ( $_GET [ 'menuaction' ]))
2001-08-08 16:03:20 +02:00
{
2003-08-28 16:31:11 +02:00
include ( PHPGW_APP_INC . '/functions.inc.php' );
}
2005-03-03 11:47:28 +01:00
if ( !@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noheader' ] &&
!@ $GLOBALS [ 'egw_info' ][ 'flags' ][ 'noappheader' ] &&
2004-01-26 04:34:17 +01:00
file_exists ( PHPGW_APP_INC . '/header.inc.php' ) && ! isset ( $_GET [ 'menuaction' ]))
2003-08-28 16:31:11 +02:00
{
include ( PHPGW_APP_INC . '/header.inc.php' );
}
}