2001-01-11 10:52:33 +01:00
|
|
|
<?php
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare API - Applications
|
2008-04-20 21:31:51 +02:00
|
|
|
*
|
2008-03-21 21:11:59 +01:00
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* This file was originaly written by Dan Kuykendall and Joseph Engo
|
|
|
|
* Copyright (C) 2000, 2001 Dan Kuykendall
|
|
|
|
* Parts Copyright (C) 2003 Free Software Foundation
|
|
|
|
* @author RalfBecker@outdoor-training.de
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New written class to create the eGW enviroment AND restore it from a php-session
|
|
|
|
*
|
|
|
|
* Rewritten by RalfBecker@outdoor-training.de to store the eGW enviroment
|
|
|
|
* (egw-object and egw_info-array) in a php-session and restore it from
|
|
|
|
* there instead of creating it completly new on each page-request.
|
|
|
|
* The enviroment gets now created by the egw-class
|
2008-04-20 21:31:51 +02:00
|
|
|
*
|
2008-03-21 21:11:59 +01:00
|
|
|
* Use now a php5 getter method to create the usuall subobject on demand, to allow a quicker
|
|
|
|
* header include on sites not useing php4-restore.
|
|
|
|
* This also makes a lot of application code, like the following, unnecessary:
|
|
|
|
* if (!is_object($GLOBALS['egw']->datetime)
|
|
|
|
* {
|
|
|
|
* $GLOBALS['egw']->datetime = CreateObject('phpgwapi.datetime');
|
|
|
|
* }
|
|
|
|
* You can now simply use $GLOBALS['egw']->datetime, and the egw class instanciates it for you on demand.
|
|
|
|
*/
|
2008-03-22 10:29:29 +01:00
|
|
|
class egw extends egw_minimal
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Turn on debug mode. Will output additional data for debugging purposes.
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $debug = 0; // This will turn on debugging information.
|
|
|
|
/**
|
|
|
|
* Instance of the account object
|
|
|
|
*
|
|
|
|
* @var accounts
|
|
|
|
*/
|
|
|
|
var $accounts;
|
|
|
|
/**
|
|
|
|
* Instace of the common object
|
|
|
|
*
|
|
|
|
* @var common
|
|
|
|
*/
|
|
|
|
var $common;
|
2010-01-22 00:31:28 +01:00
|
|
|
/**
|
|
|
|
* Instace of the hooks object
|
|
|
|
*
|
|
|
|
* @var hooks
|
|
|
|
*/
|
|
|
|
var $hooks;
|
2010-03-15 08:51:38 +01:00
|
|
|
|
2008-12-17 21:05:19 +01:00
|
|
|
private $cat_cache;
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2001-05-08 23:20:47 +02:00
|
|
|
/**
|
2008-03-21 21:11:59 +01:00
|
|
|
* Constructor: Instantiates the sub-classes
|
2005-07-17 23:00:49 +02:00
|
|
|
*
|
2008-03-21 21:11:59 +01:00
|
|
|
* @author RalfBecker@outdoor-training.de
|
|
|
|
* @param array $domain_names array with valid egw-domain names
|
2005-07-17 23:00:49 +02:00
|
|
|
*/
|
2008-03-21 21:11:59 +01:00
|
|
|
function __construct($domain_names=null)
|
2001-02-07 21:22:17 +01:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$GLOBALS['egw'] =& $this; // we need to be immediately available there for the other classes we instantiate
|
|
|
|
// for the migration: reference us to the old phpgw object
|
|
|
|
$GLOBALS['phpgw'] =& $this;
|
|
|
|
$this->setup($domain_names,True);
|
|
|
|
}
|
2007-03-29 23:01:11 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* Called every time the constructor is called. Also called by sessions to ensure the correct db,
|
|
|
|
* in which case we do not recreate the session object.
|
|
|
|
* @author RalfBecker@outdoor-training.de (moved to setup() by milos@groupwhere.org
|
|
|
|
* @param array $domain_names array with valid egw-domain names
|
|
|
|
* @param boolean $createsessionobject True to create the session object (default=True)
|
|
|
|
*/
|
|
|
|
function setup($domain_names,$createsessionobject=True)
|
|
|
|
{
|
|
|
|
// create the DB-object
|
2008-08-07 23:12:44 +02:00
|
|
|
$this->db = new egw_db($GLOBALS['egw_info']['server']);
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($this->debug)
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->db->Debug = 1;
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->db->set_app('phpgwapi');
|
|
|
|
|
|
|
|
// check if eGW is already setup, if not redirect to setup/
|
2008-04-01 12:33:54 +02:00
|
|
|
try {
|
2008-08-07 23:12:44 +02:00
|
|
|
$this->db->connect();
|
2009-04-28 21:32:29 +02:00
|
|
|
if (!($num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn()))
|
2008-10-25 07:43:59 +02:00
|
|
|
{
|
2009-04-28 21:32:29 +02:00
|
|
|
$phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
|
2008-10-25 07:43:59 +02:00
|
|
|
}
|
2008-04-01 12:33:54 +02:00
|
|
|
}
|
|
|
|
catch(Exception $e) {
|
|
|
|
//echo "<pre>Connection to DB failed (".$e->getMessage().")!\n".$e->getTraceAsString();
|
|
|
|
}
|
2008-10-25 07:43:59 +02:00
|
|
|
if ($e || !$num_config)
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-10-25 07:43:59 +02:00
|
|
|
$setup_dir = str_replace(array('home/index.php','index.php'),'setup/',$_SERVER['PHP_SELF']);
|
2005-11-05 14:15:33 +01:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
// we check for the old table too, to not scare updating users ;-)
|
2008-10-25 07:43:59 +02:00
|
|
|
if ($phpgw_config)
|
2005-08-14 19:01:30 +02:00
|
|
|
{
|
2008-04-20 21:31:51 +02:00
|
|
|
throw new Exception('<center><b>Fatal Error:</b> You need to <a href="' . $setup_dir .
|
2008-04-01 12:33:54 +02:00
|
|
|
'">update eGroupWare</a> before you can continue using it.</center>',999);
|
2005-08-14 19:01:30 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
else
|
2005-08-14 19:01:30 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
throw new Exception('<center><b>Fatal Error:</b> It appears that you have not created the database tables for '
|
|
|
|
.'eGroupWare. Click <a href="' . $setup_dir . '">here</a> to run setup.</center>',999);
|
2005-08-14 19:01:30 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
// Set the DB's client charset if a system-charset is set
|
|
|
|
$system_charset = $this->db->select(config::TABLE,'config_value',array(
|
|
|
|
'config_app' => 'phpgwapi',
|
|
|
|
'config_name' => 'system_charset',
|
2009-04-28 21:32:29 +02:00
|
|
|
),__LINE__,__FILE__)->fetchColumn();
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($system_charset)
|
|
|
|
{
|
|
|
|
$this->db->Link_ID->SetCharSet($system_charset);
|
|
|
|
}
|
|
|
|
// load up the $GLOBALS['egw_info']['server'] array
|
|
|
|
foreach($this->db->select(config::TABLE,'*',array('config_app' => 'phpgwapi'),__LINE__,__FILE__) as $row)
|
|
|
|
{
|
2009-04-28 21:32:29 +02:00
|
|
|
$GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value'];
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
|
|
|
//$GLOBALS['egw_info']['server'] = config::read('phpgwapi'); would unserialize arrays
|
|
|
|
|
2009-12-03 09:10:48 +01:00
|
|
|
// if no server timezone set, use date_default_timezone_get() to determine it once
|
|
|
|
// it fills to log with deprecated warnings under 5.3 otherwise
|
2010-03-15 08:51:38 +01:00
|
|
|
if (empty($GLOBALS['egw_info']['server']['server_timezone']) ||
|
|
|
|
$GLOBALS['egw_info']['server']['server_timezone'] == 'System/Localtime') // treat invalid tz like empty!
|
2009-11-30 15:40:27 +01:00
|
|
|
{
|
2010-03-15 08:51:38 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$tz = new DateTimeZone(date_default_timezone_get());
|
|
|
|
config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = $tz->getName(),'phpgwapi');
|
|
|
|
error_log(__METHOD__."() stored server_timezone=".$GLOBALS['egw_info']['server']['server_timezone']);
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
|
|
|
// do nothing if new DateTimeZone fails (eg. 'System/Localtime' returned), specially do NOT store it!
|
|
|
|
error_log(__METHOD__."() NO valid 'date.timezone' set in your php.ini!");
|
|
|
|
}
|
2009-11-30 15:40:27 +01:00
|
|
|
}
|
2009-12-03 09:10:48 +01:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
// setup the other subclasses
|
2009-04-20 13:59:39 +02:00
|
|
|
// translation class is here only for backward compatibility, as all it's methods can be called static now
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->translation = new translation();
|
|
|
|
$this->common = new common();
|
|
|
|
$this->accounts = accounts::getInstance();
|
|
|
|
$this->acl = new acl();
|
2010-01-22 00:31:28 +01:00
|
|
|
// we instanciate the hooks object here manually, to cache it's hooks in the session
|
|
|
|
$this->hooks = new hooks();
|
2008-03-21 21:11:59 +01:00
|
|
|
/* Do not create the session object if called by the sessions class. This way
|
|
|
|
* we ensure the correct db based on the user domain.
|
|
|
|
*/
|
|
|
|
if($createsessionobject)
|
|
|
|
{
|
2008-08-07 23:12:44 +02:00
|
|
|
$this->session = new egw_session($domain_names);
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
|
|
|
$this->preferences = new preferences();
|
|
|
|
$this->applications = new applications();
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
register_shutdown_function(array($this, 'shutdown'));
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && $GLOBALS['egw_info']['flags']['currentapp'] != 'logout')
|
|
|
|
{
|
|
|
|
$this->verify_session();
|
|
|
|
$this->applications->read_installed_apps(); // to get translated app-titles, has to be after verify_session
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->define_egw_constants();
|
2006-12-11 00:44:18 +01:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->check_app_rights();
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->load_optional_classes();
|
2009-04-20 13:59:39 +02:00
|
|
|
|
2008-12-17 21:05:19 +01:00
|
|
|
$this->cat_cache =& categories::init_cache();
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
else // set the defines for login, in case it's more then just login
|
2005-07-20 14:31:58 +02:00
|
|
|
{
|
|
|
|
$this->define_egw_constants();
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2005-07-17 23:00:49 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* __wakeup function gets called by php while unserializing the egw-object, eg. reconnects to the DB
|
|
|
|
*
|
|
|
|
* @author RalfBecker@outdoor-training.de
|
|
|
|
*/
|
|
|
|
function __wakeup()
|
|
|
|
{
|
|
|
|
$GLOBALS['egw'] =& $this; // we need to be immediately available there for the other classes we instantiate
|
|
|
|
// for the migration: reference us to the old phpgw object
|
|
|
|
$GLOBALS['phpgw'] =& $this;
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($GLOBALS['egw_info']['server']['system_charset'])
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->db->Link_ID->SetCharSet($GLOBALS['egw_info']['server']['system_charset']);
|
|
|
|
}
|
2009-11-30 15:40:27 +01:00
|
|
|
// restoring server timezone, to avoid warnings under php5.3
|
|
|
|
if (!empty($GLOBALS['egw_info']['server']['server_timezone']))
|
|
|
|
{
|
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
|
|
|
}
|
2009-12-03 09:10:48 +01:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
register_shutdown_function(array($this, 'shutdown'));
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->define_egw_constants();
|
2009-04-20 13:59:39 +02:00
|
|
|
|
2008-12-17 21:05:19 +01:00
|
|
|
categories::init_cache($this->cat_cache);
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2005-07-17 23:00:49 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* wakeup2 funcontion needs to be called after unserializing the egw-object
|
|
|
|
*
|
|
|
|
* It adapts the restored object/enviroment to the changed (current) application / page-request
|
|
|
|
*
|
|
|
|
* @author RalfBecker@outdoor-training.de
|
|
|
|
*/
|
|
|
|
function wakeup2()
|
|
|
|
{
|
|
|
|
// do some application specific stuff, need to be done as we are different (current) app now
|
|
|
|
if (isset($this->template))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->template->set_root(EGW_APP_TPL);
|
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
// init the translation class, necessary as own wakeup would run before our's
|
|
|
|
translation::init();
|
2005-07-17 23:00:49 +02:00
|
|
|
|
2009-10-06 08:45:28 +02:00
|
|
|
$this->unset_datetime();
|
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
// verify the session
|
|
|
|
$GLOBALS['egw']->verify_session();
|
|
|
|
$GLOBALS['egw']->check_app_rights();
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->load_optional_classes();
|
|
|
|
}
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2009-10-06 08:45:28 +02:00
|
|
|
/**
|
|
|
|
* Unsetting datetime object, so time gets updated
|
|
|
|
*/
|
|
|
|
function unset_datetime()
|
|
|
|
{
|
|
|
|
unset($this->datetime);
|
|
|
|
}
|
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* load optional classes by mentioning them in egw_info[flags][enable_CLASS_class] => true
|
|
|
|
*
|
|
|
|
* Also loads the template-class if not egw_info[flags][disable_Template_class] is set
|
|
|
|
*
|
|
|
|
* Maybe the whole thing should be depricated ;-)
|
|
|
|
*/
|
|
|
|
function load_optional_classes()
|
|
|
|
{
|
|
|
|
// output the header unless the developer turned it off
|
|
|
|
if (!@$GLOBALS['egw_info']['flags']['noheader'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->common->egw_header();
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
// Load the (depricated) app include files if they exists
|
|
|
|
if (EGW_APP_INC != "" && ! preg_match ('/phpgwapi/i', EGW_APP_INC) &&
|
|
|
|
file_exists(EGW_APP_INC . '/functions.inc.php') && !isset($_GET['menuaction']))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
include(EGW_APP_INC . '/functions.inc.php');
|
|
|
|
}
|
|
|
|
if (!@$GLOBALS['egw_info']['flags']['noheader'] && !@$GLOBALS['egw_info']['flags']['noappheader'] &&
|
|
|
|
file_exists(EGW_APP_INC . '/header.inc.php') && !isset($_GET['menuaction']))
|
|
|
|
{
|
|
|
|
include(EGW_APP_INC . '/header.inc.php');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verfiy there is a valid session
|
|
|
|
*
|
|
|
|
* One can specify a callback, which gets called if there's no valid session. If the callback returns true, the parameter
|
|
|
|
* containst account-details (in keys login, passwd and passwd_type) to automatic create an (anonymous session)
|
|
|
|
*
|
|
|
|
* It also checks if enforce_ssl is set in the DB and redirects to the https:// version of the site.
|
|
|
|
*
|
|
|
|
* If there is no valid session and none could be automatic created, the function will redirect to login and NOT return
|
|
|
|
*/
|
|
|
|
function verify_session()
|
|
|
|
{
|
2011-05-31 15:33:26 +02:00
|
|
|
if($GLOBALS['egw_info']['server']['enforce_ssl'] === 'redirect' && !$_SERVER['HTTPS'])
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
2011-05-31 15:33:26 +02:00
|
|
|
Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
|
2008-03-21 21:11:59 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
// check if we have a session, if not try to automatic create one
|
|
|
|
if ($this->session->verify()) return true;
|
2006-04-06 20:32:22 +02:00
|
|
|
|
2010-05-05 11:19:37 +02:00
|
|
|
if (($account_callback = $GLOBALS['egw_info']['flags']['autocreate_session_callback']) && is_callable($account_callback) &&
|
|
|
|
($sessionid = call_user_func_array($account_callback,array(&$account))) === true) // $account_call_back returns true, false or a session-id
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
$sessionid = $this->session->create($account);
|
|
|
|
}
|
|
|
|
if (!$sessionid)
|
|
|
|
{
|
|
|
|
//echo "<p>account_callback='$account_callback', account=".print_r($account,true).", sessionid=$sessionid</p>\n"; exit;
|
|
|
|
// we forward to the same place after the re-login
|
|
|
|
if ($GLOBALS['egw_info']['server']['webserver_url'] && $GLOBALS['egw_info']['server']['webserver_url'] != '/')
|
2006-04-06 20:32:22 +02:00
|
|
|
{
|
2010-11-12 10:13:54 +01:00
|
|
|
// we have to use only path component, to cope with domains like http://egroupware.domain.com and /egroupware
|
|
|
|
list(,$relpath) = explode(parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH),
|
|
|
|
parse_url($_SERVER['PHP_SELF'],PHP_URL_PATH),2);
|
2006-04-06 20:32:22 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
else // the webserver-url is empty or just a slash '/' (eGW is installed in the docroot and no domain given)
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
if (preg_match('/^https?:\/\/[^\/]*\/(.*)$/',$relpath=$_SERVER['PHP_SELF'],$matches))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$relpath = $matches[1];
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
// this removes the sessiondata if its saved in the URL
|
|
|
|
$query = preg_replace('/[&]?sessionid(=|%3D)[^&]+&kp3(=|%3D)[^&]+&domain=.*$/','',$_SERVER['QUERY_STRING']);
|
2010-05-11 18:19:26 +02:00
|
|
|
if ($GLOBALS['egw_info']['server']['http_auth_types'])
|
|
|
|
{
|
|
|
|
$redirect = '/phpgwapi/ntlm/index.php?';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$redirect = '/login.php?';
|
|
|
|
// only add "your session could not be verified", if a sessionid is given (cookie or on url)
|
|
|
|
if (egw_session::get_sessionid()) $redirect .= 'cd=10&';
|
|
|
|
}
|
|
|
|
if ($relpath) $redirect .= 'phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : ''));
|
2010-06-07 08:54:07 +02:00
|
|
|
//Header('Location: '.$GLOBALS['egw_info']['server']['webserver_url'].$redirect);
|
|
|
|
// do NOT redirect, but set top.location, as this works in framed template too
|
2011-01-20 15:11:47 +01:00
|
|
|
$redirect = $GLOBALS['egw_info']['server']['webserver_url'].$redirect;
|
|
|
|
|
2011-02-04 15:28:12 +01:00
|
|
|
echo "<html>\n<head>\n<script type='text/javascript'>top.location='$redirect';</script>\n</head>\n";
|
2008-03-21 21:11:59 +01:00
|
|
|
exit;
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* Verify the user has rights for the requested app
|
|
|
|
*
|
|
|
|
* If the user has no rights for the app (eg. called via URL) he get a permission denied page (this function does NOT return)
|
|
|
|
*/
|
|
|
|
function check_app_rights()
|
|
|
|
{
|
|
|
|
$this->currentapp = $GLOBALS['egw_info']['flags']['currentapp']; // some apps change it later
|
|
|
|
|
2011-03-30 09:54:29 +02:00
|
|
|
if ($GLOBALS['egw_info']['flags']['currentapp'] != 'home') // give everyone implicit home rights
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
// This will need to use ACL in the future
|
|
|
|
if (!$GLOBALS['egw_info']['user']['apps'][$currentapp = $GLOBALS['egw_info']['flags']['currentapp']] ||
|
|
|
|
($GLOBALS['egw_info']['flags']['admin_only'] && !$GLOBALS['egw_info']['user']['apps']['admin']))
|
2001-07-26 13:02:10 +02:00
|
|
|
{
|
2010-09-17 11:11:44 +02:00
|
|
|
// present a login page, if anon user has no right for an application
|
|
|
|
if ($this->session->session_flags == 'A')
|
|
|
|
{
|
|
|
|
egw::redirect_link('/logout.php');
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
if ($currentapp == 'admin' || $GLOBALS['egw_info']['flags']['admin_only'])
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
throw new egw_exception_no_permission_admin();
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
throw new egw_exception_no_permission_app($currentapp);
|
2001-02-07 21:22:17 +01:00
|
|
|
}
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2005-07-22 11:05:01 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* create all the defines / constants of the eGW-environment (plus the deprecated phpgw ones)
|
|
|
|
*/
|
|
|
|
function define_egw_constants()
|
|
|
|
{
|
|
|
|
define('SEP',filesystem_separator());
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
define('PHPGW_ACL_GROUP_MANAGERS',32);
|
|
|
|
define('PHPGW_ACL_CUSTOM_1',64);
|
|
|
|
define('PHPGW_ACL_CUSTOM_2',128);
|
|
|
|
define('PHPGW_ACL_CUSTOM_3',256);
|
|
|
|
// A few hacker resistant constants that will be used throught the program
|
|
|
|
define('EGW_TEMPLATE_DIR', $this->common->get_tpl_dir('phpgwapi'));
|
|
|
|
define('EGW_IMAGES_DIR', $this->common->get_image_path('phpgwapi'));
|
|
|
|
define('EGW_IMAGES_FILEDIR', $this->common->get_image_dir('phpgwapi'));
|
|
|
|
define('EGW_APP_ROOT', $this->common->get_app_dir());
|
|
|
|
define('EGW_APP_INC', $this->common->get_inc_dir());
|
|
|
|
define('EGW_APP_TPL', $this->common->get_tpl_dir());
|
|
|
|
define('EGW_IMAGES', $this->common->get_image_path());
|
|
|
|
define('EGW_APP_IMAGES_DIR', $this->common->get_image_dir());
|
|
|
|
// and the old ones
|
|
|
|
define('PHPGW_TEMPLATE_DIR',EGW_TEMPLATE_DIR);
|
|
|
|
define('PHPGW_IMAGES_DIR',EGW_IMAGES_DIR);
|
|
|
|
define('PHPGW_IMAGES_FILEDIR',EGW_IMAGES_FILEDIR);
|
|
|
|
define('PHPGW_APP_ROOT',EGW_APP_ROOT);
|
|
|
|
define('PHPGW_APP_INC',EGW_APP_INC);
|
|
|
|
define('PHPGW_APP_TPL',EGW_APP_TPL);
|
|
|
|
define('PHPGW_IMAGES',EGW_IMAGES);
|
|
|
|
define('PHPGW_APP_IMAGES_DIR',EGW_APP_IMAGES_DIR);
|
|
|
|
}
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* force the session cache to be re-created, because some of it's data changed
|
|
|
|
*
|
|
|
|
* Needs to be called if user-preferences, system-config or enabled apps of the current user have been changed and
|
|
|
|
* the change should have immediate effect
|
|
|
|
*/
|
2008-04-20 21:31:51 +02:00
|
|
|
static function invalidate_session_cache()
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
unset($_SESSION['egw_info_cache']);
|
|
|
|
unset($_SESSION['egw_object_cache']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* run string through htmlspecialchars and stripslashes
|
|
|
|
*
|
|
|
|
* @param string $s
|
|
|
|
* @return string The string with html special characters replaced with entities
|
|
|
|
*/
|
2008-04-20 21:31:51 +02:00
|
|
|
static function strip_html($s)
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
return htmlspecialchars(stripslashes($s));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link url generator
|
|
|
|
*
|
2010-06-02 19:11:48 +02:00
|
|
|
* @param string='' $string The url the link is for
|
|
|
|
* @param string|array $extravars='' Extra params to be passed to the url
|
|
|
|
* @param string $link_app=null if appname or true, some templates generate a special link-handler url
|
2008-03-21 21:11:59 +01:00
|
|
|
* @return string The full url after processing
|
|
|
|
*/
|
2010-06-02 19:11:48 +02:00
|
|
|
static function link($url = '', $extravars = '', $link_app=null)
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
2010-06-02 19:11:48 +02:00
|
|
|
return $GLOBALS['egw']->framework->link($url, $extravars, $link_app);
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects direct to a generated link
|
|
|
|
*
|
|
|
|
* @param string $string The url the link is for
|
|
|
|
* @param string/array $extravars Extra params to be passed to the url
|
|
|
|
* @return string The full url after processing
|
|
|
|
*/
|
2008-04-20 21:31:51 +02:00
|
|
|
static function redirect_link($url = '',$extravars='')
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
2010-06-01 23:38:00 +02:00
|
|
|
return $GLOBALS['egw']->framework->redirect_link($url, $extravars);
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles redirects under iis and apache, it does NOT return (calls exit)
|
|
|
|
*
|
|
|
|
* This function handles redirects under iis and apache it assumes that $phpgw->link() has already been called
|
|
|
|
*
|
|
|
|
* @param string The url ro redirect to
|
|
|
|
*/
|
2008-04-20 21:31:51 +02:00
|
|
|
static function redirect($url = '')
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
/* global $HTTP_ENV_VARS; */
|
|
|
|
|
|
|
|
$iis = @strpos($GLOBALS['HTTP_ENV_VARS']['SERVER_SOFTWARE'], 'IIS', 0);
|
|
|
|
|
|
|
|
if(!$url)
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$url = $_SERVER['PHP_SELF'];
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
if($iis)
|
2005-08-14 19:01:30 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
echo "\n<HTML>\n<HEAD>\n<TITLE>Redirecting to $url</TITLE>";
|
|
|
|
echo "\n<META HTTP-EQUIV=REFRESH CONTENT=\"0; URL=$url\">";
|
|
|
|
echo "\n</HEAD><BODY>";
|
|
|
|
echo "<H3>Please continue to <a href=\"$url\">this page</a></H3>";
|
|
|
|
echo "\n</BODY></HTML>";
|
2005-08-14 19:01:30 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
else
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2009-11-17 15:56:57 +01:00
|
|
|
if (headers_sent($file,$line))
|
|
|
|
{
|
|
|
|
throw new egw_exception_assertion_failed(__METHOD__."('".htmlspecialchars($url)."') can NOT redirect, output already started at $file line $line!");
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
Header("Location: $url");
|
|
|
|
print("\n\n");
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-10-24 20:39:30 +02:00
|
|
|
@ob_flush(); flush();
|
2010-05-05 11:19:37 +02:00
|
|
|
|
|
|
|
// commit session (if existing), to fix timing problems sometimes preventing session creation ("Your session can not be verified")
|
|
|
|
if (isset($GLOBALS['egw']->session)) $GLOBALS['egw']->session->commit_session();
|
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
exit;
|
|
|
|
}
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* Shortcut to translation class
|
|
|
|
*
|
2009-04-20 13:59:39 +02:00
|
|
|
* This function is a basic wrapper to translation::translate()
|
2008-03-21 21:11:59 +01:00
|
|
|
*
|
|
|
|
* @deprecated only used in the old timetracker
|
|
|
|
* @param string The key for the phrase
|
2009-04-20 13:59:39 +02:00
|
|
|
* @see translation::translate()
|
2008-03-21 21:11:59 +01:00
|
|
|
*/
|
2009-04-20 13:59:39 +02:00
|
|
|
static function lang($key,$args=null)
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
|
|
|
if (!is_array($args))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
$args = func_get_args();
|
|
|
|
array_shift($args);
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2009-04-20 13:59:39 +02:00
|
|
|
return translation::translate($key,$args);
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* eGW's shutdown handler
|
|
|
|
*/
|
|
|
|
function shutdown()
|
|
|
|
{
|
|
|
|
if (!defined('EGW_SHUTDOWN'))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
define('EGW_SHUTDOWN',True);
|
2005-08-14 19:01:30 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
if (class_exists('egw_link',false)) // false = no autoload!
|
2005-08-14 19:01:30 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
egw_link::save_session_cache();
|
2005-08-14 19:01:30 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
// call the asyncservice check_run function if it is not explicitly set to cron-only
|
|
|
|
//
|
|
|
|
if (!$GLOBALS['egw_info']['server']['asyncservice']) // is default
|
2005-08-14 19:01:30 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
ExecMethod('phpgwapi.asyncservice.check_run','fallback');
|
2005-08-14 19:01:30 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
$this->db->disconnect();
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2008-03-22 10:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimal eGW object used in setup, does not instanciate anything by default
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class egw_minimal
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Instance of the db-object
|
2008-04-20 21:31:51 +02:00
|
|
|
*
|
2008-03-22 10:29:29 +01:00
|
|
|
* @var egw_db
|
|
|
|
*/
|
|
|
|
var $db;
|
|
|
|
/**
|
|
|
|
* Current app at the instancation of the class
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $currentapp;
|
|
|
|
/**
|
|
|
|
* Global ADOdb object, need to be defined here, to not call magic __get method
|
|
|
|
*
|
|
|
|
* @var ADOConnection
|
|
|
|
*/
|
|
|
|
var $ADOdb;
|
2005-07-17 23:00:49 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* Classes which get instanciated in a different name
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
static $sub_objects = array(
|
|
|
|
'log' => 'errorlog',
|
2010-06-09 17:30:53 +02:00
|
|
|
// 'js' => 'javascript',
|
2008-03-21 21:11:59 +01:00
|
|
|
'link' => 'bolink', // depricated use static egw_link methods
|
|
|
|
'datetime' => 'egw_datetime',
|
2008-08-07 23:12:44 +02:00
|
|
|
// 'session' => 'sessions',
|
|
|
|
'session' => 'egw_session',
|
2008-03-21 21:11:59 +01:00
|
|
|
'framework' => true, // special handling in __get()
|
|
|
|
'template' => 'Template',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Magic function to check if a sub-object is set
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function __isset($name)
|
|
|
|
{
|
|
|
|
//error_log(__METHOD__."($name)");
|
|
|
|
return isset($this->$name);
|
|
|
|
}
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
/**
|
|
|
|
* Magic function to return a sub-object
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function __get($name)
|
|
|
|
{
|
2008-03-21 22:02:00 +01:00
|
|
|
//error_log(__METHOD__."($name)".function_backtrace());
|
2010-10-28 18:24:58 +02:00
|
|
|
|
2010-06-09 17:30:53 +02:00
|
|
|
if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
if (isset($this->$name))
|
2005-07-17 23:00:49 +02:00
|
|
|
{
|
2008-03-21 21:11:59 +01:00
|
|
|
return $this->$name;
|
|
|
|
}
|
2008-04-20 21:31:51 +02:00
|
|
|
|
2008-03-21 21:11:59 +01:00
|
|
|
if (!isset(self::$sub_objects[$name]) && !class_exists($name))
|
|
|
|
{
|
2009-05-30 22:15:31 +02:00
|
|
|
if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace());
|
2008-03-21 21:11:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
switch($name)
|
|
|
|
{
|
|
|
|
case 'framework':
|
|
|
|
// setup the new eGW framework (template sets)
|
|
|
|
$class = $GLOBALS['egw_info']['server']['template_set'].'_framework';
|
2010-06-02 11:20:55 +02:00
|
|
|
if (!class_exists($class)) // first try to autoload the class
|
2008-03-21 21:11:59 +01:00
|
|
|
{
|
2010-06-02 11:20:55 +02:00
|
|
|
require_once($file=EGW_INCLUDE_ROOT.'/phpgwapi/templates/'.$GLOBALS['egw_info']['server']['template_set'].'/class.'.$class.'.inc.php');
|
|
|
|
if (!in_array($file,(array)$_SESSION['egw_required_files']))
|
|
|
|
{
|
|
|
|
$_SESSION['egw_required_files'][] = $file; // automatic load the used framework class, when the object get's restored
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|
2010-10-28 18:24:58 +02:00
|
|
|
// fall back to idots if a template does NOT support current user-agent
|
|
|
|
if ($class != 'idots_framework' && method_exists($class,'is_supported_user_agent') &&
|
|
|
|
!call_user_func(array($class,'is_supported_user_agent')))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['server']['template_set'] = 'idots';
|
|
|
|
return $this->__get('framework');
|
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
break;
|
|
|
|
case 'template': // need to be instancated for the current app
|
2008-08-18 11:00:19 +02:00
|
|
|
if (!($tpl_dir = $GLOBALS['egw']->common->get_tpl_dir($this->currentapp)))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $this->template = new Template($tpl_dir);
|
2008-03-21 21:11:59 +01:00
|
|
|
default:
|
|
|
|
$class = isset(self::$sub_objects[$name]) ? self::$sub_objects[$name] : $name;
|
|
|
|
break;
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
return $this->$name = new $class();
|
2005-07-17 23:00:49 +02:00
|
|
|
}
|
2008-03-21 21:11:59 +01:00
|
|
|
}
|