Author: ralfbecker
New Revision: 55853
URL: http://svn.stylite.de/viewvc/egroupware?rev=55853&view=rev
Log:
move egw and applications class to api including (common_)functions.inc.php
Added:
trunk/egroupware/api/src/Egw/
trunk/egroupware/api/src/Egw.php
- copied, changed from r55817, trunk/phpgwapi/inc/class.egw.inc.php
trunk/egroupware/api/src/Egw/Applications.php
- copied, changed from r55840, trunk/phpgwapi/inc/class.applications.inc.php
trunk/egroupware/api/src/Egw/Base.php
- copied, changed from r55817, trunk/phpgwapi/inc/class.egw.inc.php
trunk/egroupware/api/src/autoload.php
- copied, changed from r55840, trunk/phpgwapi/inc/common_functions.inc.php
trunk/egroupware/api/src/loader/
trunk/egroupware/api/src/loader.php
- copied, changed from r55817, trunk/phpgwapi/inc/functions.inc.php
trunk/egroupware/api/src/loader/common.php
- copied, changed from r55840, trunk/phpgwapi/inc/common_functions.inc.php
trunk/egroupware/api/src/loader/exception.php
- copied, changed from r55840, trunk/phpgwapi/inc/common_functions.inc.php
trunk/egroupware/api/src/loader/security.php
- copied, changed from r55840, trunk/phpgwapi/inc/common_functions.inc.php
trunk/phpgwapi/inc/deprecated_functions.inc.php
- copied, changed from r55840, trunk/phpgwapi/inc/common_functions.inc.php
Modified:
trunk/egroupware/header.inc.php.template
trunk/phpgwapi/inc/class.applications.inc.php
trunk/phpgwapi/inc/class.egw.inc.php
trunk/phpgwapi/inc/common_functions.inc.php
trunk/phpgwapi/inc/functions.inc.php
— trunk/phpgwapi/inc/class.egw.inc.php (original)
+++ trunk/egroupware/api/src/Egw.php Tue Apr 26 16:38:08 2016
@@ -1,6 +1,6 @@
<?php
/**
- * eGroupWare API - Applications
+ * EGroupware API - Applications
*
* @link http://www.egroupware.org
* This file was originaly written by Dan Kuykendall and Joseph Engo
@@ -12,7 +12,12 @@
* @version $Id$
*/
-use EGroupware\Api;
+namespace EGroupware\Api;
+
+// explicitly list old, non-namespaced classes
+// they are only used, if phpgwapi is installed
+use accounts;
+use egw_session;
/**
* New written class to create the eGW enviroment AND restore it from a php-session
@@ -22,16 +27,16 @@
* there instead of creating it completly new on each page-request.
* The enviroment gets now created by the egw-class
*
- * 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.
+ * Extending Egw\Base which uses now a getter method to create the usual subobject on demand,
+ * to allow a quicker header include on sites not using php4-restore.
* This also makes a lot of application code, like the following, unnecessary:
- * if (!is_object($GLOBALS['egw']->datetime)
+ * if (!is_object($GLOBALS['egw']->ldap)
* {
- * $GLOBALS['egw']->datetime = CreateObject('phpgwapi.datetime');
+ * $GLOBALS['egw']->ldap = Api\Ldap::factory();
* }
- * You can now simply use $GLOBALS['egw']->datetime, and the egw class instanciates it for you on demand.
+ * You can now simply use $GLOBALS['egw']->ldap, and the egw class instanciates it for you on demand.
*/
-class egw extends egw_minimal
+class Egw extends Egw\Base
{
/**
* Turn on debug mode. Will output additional data for debugging purposes.
@@ -42,21 +47,9 @@
/**
* Instance of the account object
*
- * @var accounts
+ * @var Accounts
*/
var $accounts;
- /**
- * Instace of the common object
- *
- * @var common
- */
- var $common;
- /**
- * Instace of the hooks object
- *
- * @var hooks
- */
- var $hooks;
/**
* Constructor: Instantiates the sub-classes
@@ -67,8 +60,6 @@
function __construct($domain_names=null)
{
$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);
}
@@ -83,27 +74,27 @@
{
// create the DB-object
// as SiteMgr, Wiki, KnowledgeBase and probably more still use eg next_record(), we stick with Db\Deprecated for now
- $this->db = new Api\Db\Deprecated($GLOBALS['egw_info']['server']);
+ $this->db = new Db\Deprecated($GLOBALS['egw_info']['server']);
if ($this->debug)
{
$this->db->Debug = 1;
}
- $this->db->set_app(Api\Db::API_APPNAME);
+ $this->db->set_app(Db::API_APPNAME);
// check if eGW is already setup, if not redirect to setup/
try {
$this->db->connect();
- $num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
- }
- catch(Api\Db\Exception\Connection $e) {
+ $num_config = $this->db->select(Config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
+ }
+ catch(Db\Exception\Connection $e) {
// ignore exception, get handled below
}
- catch(Api\Db\Exception\InvalidSql $e1) {
+ catch(Db\Exception\InvalidSql $e1) {
unset($e1); // not used
try {
$phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
}
- catch (Api\Db\Exception\InvalidSql $e2) {
+ catch (Db\Exception\InvalidSql $e2) {
unset($e2); // not used
// ignor error, get handled below
}
@@ -117,13 +108,13 @@
}
if ($e)
{
- throw new Api\Db\Exception\Setup('Connection with '.$e->getMessage()."\n\n".
+ throw new Db\Exception\Setup('Connection with '.$e->getMessage()."\n\n".
'Maybe you not created a database for EGroupware yet.',999);
}
- throw new Api\Db\Exception\Setup('It appears that you have not created the database tables for EGroupware.',999);
- }
- // Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in config::read)
- foreach($this->db->select(config::TABLE,'config_name,config_value',array(
+ throw new Db\Exception\Setup('It appears that you have not created the database tables for EGroupware.',999);
+ }
+ // Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in Config::read)
+ foreach($this->db->select(Config::TABLE,'config_name,config_value',array(
'config_app' => 'phpgwapi',
'config_name' => array('system_charset','install_id','temp_dir'),
),__LINE__,__FILE__) as $row)
@@ -135,7 +126,7 @@
$this->db->Link_ID->SetCharSet($GLOBALS['egw_info']['server']['system_charset']);
}
// load up the $GLOBALS['egw_info']['server'] array
- $GLOBALS['egw_info']['server'] += config::read('phpgwapi');
+ $GLOBALS['egw_info']['server'] += Config::read('phpgwapi');
// 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
@@ -145,7 +136,7 @@
try
{
$tz = new DateTimeZone(date_default_timezone_get());
- config::save_value('server_timezone',$GLOBALS['egw_info']['server']['server_timezone'] = $tz->getName(),'phpgwapi');
+ 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)
@@ -156,23 +147,33 @@
}
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
+ // if phpgwapi exists we prefer accounts and egw_session, as they have some deprecated methods
+ if (file_exists(EGW_SERVER_ROOT.'/phpgwapi'))
+ {
+ $this->accounts = new accounts();
+ /* 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)
+ {
+ $this->session = new egw_session($domain_names);
+ }
+ }
+ else
+ {
+ $this->accounts = new Accounts();
+ /* 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)
+ {
+ $this->session = new Session($domain_names);
+ }
+ }
// setup the other subclasses
- // translation class is here only for backward compatibility, as all it's methods can be called static now
- $this->translation = new translation();
- $this->common = new common();
- $this->accounts = new accounts();
- $this->acl = new acl();
- // we instanciate the hooks object here manually, to cache it's hooks in the session
- $this->hooks = new hooks();
- /* 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)
- {
- $this->session = new egw_session($domain_names);
- }
- $this->preferences = new preferences();
- $this->applications = new applications();
+ $this->acl = new Acl();
+ $this->preferences = new Preferences();
+ $this->applications = new Egw\Applications();
if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && $GLOBALS['egw_info']['flags']['currentapp'] != 'logout')
{
@@ -230,7 +231,7 @@
$this->template->set_root(EGW_APP_TPL);
}
// init the translation class, necessary as own wakeup would run before our's
- translation::init(isset($GLOBALS['egw_info']['flags']['load_translations']) ? $GLOBALS['egw_info']['flags']['load_translations'] : true);
+ Translation::init(isset($GLOBALS['egw_info']['flags']['load_translations']) ? $GLOBALS['egw_info']['flags']['load_translations'] : true);
$this->unset_datetime();
@@ -261,17 +262,22 @@
// output the header unless the developer turned it off
if (!@$GLOBALS['egw_info']['flags']['noheader'])
{
- common::egw_header();
+ echo $GLOBALS['egw']->framework->header();
+
+ if (!$GLOBALS['egw_info']['flags']['nonavbar'])
+ {
+ echo $GLOBALS['egw']->framework->navbar();
+ }
}
// 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']))
+ file_exists(EGW_APP_INC . '/functions.inc.php') && !isset($_GET['menuaction']))
{
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']))
+ file_exists(EGW_APP_INC . '/header.inc.php') && !isset($_GET['menuaction']))
{
include(EGW_APP_INC . '/header.inc.php');
}
@@ -331,7 +337,7 @@
{
$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 (Session::get_sessionid()) $redirect .= 'cd=10&';
}
if ($relpath) $redirect .= 'phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : ''));
self::redirect_link($redirect);
@@ -343,9 +349,9 @@
*
* If the user has no rights for the app (eg. called via URL) he get a permission denied page (this function does NOT return)
*
- * @throws Api\Exception\Redirect for anonymous user accessing something he has no rights to
- * @throws Api\Exception\NoPermission\Admin
- * @throws Api\Exception\NoPermission\App
+ * @throws Exception\Redirect for anonymous user accessing something he has no rights to
+ * @throws Exception\NoPermission\Admin
+ * @throws Exception\NoPermission\App
*/
function check_app_rights()
{
@@ -361,17 +367,17 @@
if ($this->session->session_flags == 'A')
{
// need to destroy a basic auth session here, because it will only be available on current url
- if (($sessionid = egw_session::get_sessionid(true)))
+ if (($sessionid = Session::get_sessionid(true)))
{
$GLOBALS['egw']->session->destroy($sessionid);
}
- throw new Api\Exception\Redirect(egw::link('/logout.php'));
+ throw new Exception\Redirect(egw::link('/logout.php'));
}
if ($currentapp == 'admin' || $GLOBALS['egw_info']['flags']['admin_only'])
{
- throw new Api\Exception\NoPermission\Admin();
+ throw new Exception\NoPermission\Admin();
}
- throw new Api\Exception\NoPermission\App($currentapp);
+ throw new Exception\NoPermission\App($currentapp);
}
}
}
@@ -479,17 +485,17 @@
*/
static function redirect($url, $link_app=null)
{
- Api\Framework::redirect($url, $link_app);
+ Framework::redirect($url, $link_app);
}
/**
* Shortcut to translation class
*
- * This function is a basic wrapper to translation::translate()
+ * This function is a basic wrapper to Translation::translate()
*
* @deprecated only used in the old timetracker
* @param string The key for the phrase
- * @see translation::translate()
+ * @see Translation::translate()
*/
static function lang($key,$args=null)
{
@@ -498,7 +504,7 @@
$args = func_get_args();
array_shift($args);
}
- return translation::translate($key,$args);
+ return Translation::translate($key,$args);
}
/**
@@ -535,9 +541,9 @@
define('EGW_SHUTDOWN',True);
// send json response BEFORE flushing output
- if (egw_json_request::isJSONRequest())
- {
- egw_json_response::sendResult();
+ if (Json\Request::isJSONRequest())
+ {
+ Json\Response::sendResult();
}
// run all on_shutdown callbacks with session in their name (eg. egw_link::save_session_cache), do NOT stop on exceptions
@@ -549,7 +555,7 @@
if (!is_array($callback) || strpos($callback[1], 'session') === false) continue;
call_user_func_array($callback, $data);
}
- catch (Exception $ex) {
+ catch (\Exception $ex) {
_egw_log_exception($ex);
}
unset(self::$shutdown_callbacks[$n]);
@@ -579,113 +585,17 @@
$callback = array_shift($data);
call_user_func_array($callback, $data);
}
- catch (Exception $ex) {
+ catch (\Exception $ex) {
_egw_log_exception($ex);
}
}
// call the asyncservice check_run function if it is not explicitly set to cron-only
if (!$GLOBALS['egw_info']['server']['asyncservice']) // is default
{
- ExecMethod('phpgwapi.asyncservice.check_run','fallback');
+ $async = new Asyncservice();
+ $async->fallback();
}
$this->db->disconnect();
}
}
}
-
-/**
- * Minimal eGW object used in setup, does not instanciate anything by default
- *
- */
-class egw_minimal
-{
- /**
- * Instance of the db-object
- *
- * @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;
-
- /**
- * Classes which get instanciated in a different name
- *
- * @var array
- */
- static $sub_objects = array(
- 'log' => 'errorlog',
-// 'js' => 'javascript',
- 'link' => 'bolink', // depricated use static egw_link methods
- 'datetime' => 'egw_datetime',
- 'framework' => true, // special handling in __get()
- 'template' => 'Template',
- 'session' => 'egw_session', // otherwise $GLOBALS['egw']->session->appsession() fails
- // classes moved to new api dir
- 'ldap' => true,
- 'auth' => 'EGroupware\\Api\\Auth',
- );
-
- /**
- * 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);
- }
-
- /**
- * Magic function to return a sub-object
- *
- * @param string $name
- * @return mixed
- */
- function __get($name)
- {
- //error_log(__METHOD__."($name)".function_backtrace());
-
- if ($name == 'js') $name = 'framework'; // javascript class is integrated now into framework
-
- if (isset($this->$name))
- {
- return $this->$name;
- }
-
- if (!isset(self::$sub_objects[$name]) && !class_exists($name))
- {
- if ($name != 'ADOdb') error_log(__METHOD__.": There's NO $name object! ".function_backtrace());
- return null;
- }
- switch($name)
- {
- case 'framework':
- return $this->framework = egw_framework::factory();
- case 'template': // need to be instancated for the current app
- if (!($tpl_dir = common::get_tpl_dir($this->currentapp)))
- {
- return null;
- }
- return $this->template = new Template($tpl_dir);
- case 'ldap':
- return $this->ldap = Api\Ldap::factory(false);
- default:
- $class = isset(self::$sub_objects[$name]) ? self::$sub_objects[$name] : $name;
- break;
- }
- return $this->$name = new $class();
- }
-}
Copied: trunk/egroupware/api/src/Egw/Applications.php (from r55840, trunk/phpgwapi/inc/class.applications.inc.php)
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/src/Egw/Applications.php?p2=trunk/egroupware/api/src/Egw/Applications.php&p1=trunk/phpgwapi/inc/class.applications.inc.php&r1=55840&r2=55853&rev=55853&view=diff
==============================================================================
--- trunk/phpgwapi/inc/class.applications.inc.php (original)
+++ trunk/egroupware/api/src/Egw/Applications.php Tue Apr 26 16:38:08 2016
@@ -1,21 +1,22 @@
<?php
/**
- * eGroupWare API - Applications
+ * EGroupware API - Applications
*
* @link http://www.egroupware.org
* @author Mark Peters
* Copyright (C) 2001 Mark Peters
* @license http://opensource.org/licenses/lgpl-license.php LGPL - GNU Lesser General Public License
* @package api
+ * @subpackage egw
* @version $Id$
*/
+namespace EGroupware\Api\Egw;
+
/**
- * functions for managing and installing apps
- *
- * Author: skeeter
+ * Application (sub-)object of Egw-object used to load $GLOBALS['egw_info'](['user'])['apps']
*/
-class applications
+class Applications
{
var $account_id;
var $data = Array();
@@ -50,14 +51,10 @@
$this->account_id = get_account_id($account_id);
}
- /**************************************************************************\
- * These are the standard $this->account_id specific functions *
- \**************************************************************************/
-
/**
- * read from repository
+ * Get applications of user
*
- * private should only be called from withing this class
+ * Used to populate $GLOBALS['egw_info']['user']['apps'] in Api\Session
*/
function read_repository()
{
@@ -71,7 +68,7 @@
return False;
}
$apps = $GLOBALS['egw']->acl->get_user_applications($this->account_id);
- foreach($GLOBALS['egw_info']['apps'] as $app => $data)
+ foreach(array_keys($GLOBALS['egw_info']['apps']) as $app)
{
if (isset($apps[$app]) && $apps[$app])
{
@@ -80,124 +77,6 @@
}
return $this->data;
}
-
- /**
- * read from the repository
- *
- * pubic function that is used to determine what apps a user has rights to
- */
- function read()
- {
- if (!count($this->data))
- {
- $this->read_repository();
- }
- return $this->data;
- }
- /**
- * add an app to a user profile
- *
- * @discussion
- * @param $apps array containing apps to add for a user
- */
- function add($apps)
- {
- if(is_array($apps))
- {
- foreach($apps as $app)
- {
- $this->data[$app] =& $GLOBALS['egw_info']['apps'][$app];
- }
- }
- elseif(gettype($apps))
- {
- $this->data[$apps] =& $GLOBALS['egw_info']['apps'][$apps];
- }
- return $this->data;
- }
- /**
- * delete an app from a user profile
- *
- * @discussion
- * @param $appname appname to remove
- */
- function delete($appname)
- {
- if($this->data[$appname])
- {
- unset($this->data[$appname]);
- }
- return $this->data;
- }
- /**
- * update the array(?)
- *
- * @discussion
- * @param $data update the repository array(?)
- */
- function update_data($data)
- {
- $this->data = $data;
- return $this->data;
- }
- /**
- * save the repository
- *
- * @discussion
- */
- function save_repository()
- {
- $GLOBALS['egw']->acl->delete_repository("%%", 'run', $this->account_id);
- foreach($this->data as $app => $data)
- {
- if(!$this->is_system_enabled($app))
- {
- continue;
- }
- $GLOBALS['egw']->acl->add_repository($app,'run',$this->account_id,1);
- }
- return $this->data;
- }
-
- /**************************************************************************\
- * These are the non-standard $this->account_id specific functions *
- \**************************************************************************/
-
- function app_perms()
- {
- if (!count($this->data))
- {
- $this->read_repository();
- }
- foreach ($this->data as $app => $data)
- {
- $apps[] = $this->data[$app]['name'];
- }
- return $apps;
- }
-
- function read_account_specific()
- {
- if (!is_array($GLOBALS['egw_info']['apps']))
- {
- $this->read_installed_apps();
- }
- if (($app_list = $GLOBALS['egw']->acl->get_app_list_for_id('run',1,$this->account_id)))
- {
- foreach($app_list as $app)
- {
- if ($this->is_system_enabled($app))
- {
- $this->data[$app] =& $GLOBALS['egw_info']['apps'][$app];
- }
- }
- }
- return $this->data;
- }
-
- /**************************************************************************\
- * These are the generic functions. Not specific to $this->account_id *
- \**************************************************************************/
/**
* populate array with a list of installed apps
@@ -227,46 +106,4 @@
);
}
}
-
- /**
- * check if an app is enabled
- *
- * @param $appname name of the app to check for
- */
- function is_system_enabled($appname)
- {
- if(!is_array($GLOBALS['egw_info']['apps']))
- {
- $this->read_installed_apps();
- }
- if ($GLOBALS['egw_info']['apps'][$appname]['enabled'])
- {
- return True;
- }
- else
- {
- return False;
- }
- }
-
- function id2name($id)
- {
- foreach($GLOBALS['egw_info']['apps'] as $appname => $app)
- {
- if((int)$app['id'] == (int)$id)
- {
- return $appname;
- }
- }
- return '';
- }
-
- function name2id($appname)
- {
- if(is_array($GLOBALS['egw_info']['apps'][$appname]))
- {
- return $GLOBALS['egw_info']['apps'][$appname]['id'];
- }
- return 0;
- }
}
Copied: trunk/egroupware/api/src/Egw/Base.php (from r55817, trunk/phpgwapi/inc/class.egw.inc.php)
URL: http://svn.stylite.de/viewvc/egroupware/trunk/egroupware/api/src/Egw/Base.php?p2=trunk/egroupware/api/src/Egw/Base.php&p1=trunk/phpgwapi/inc/class.egw.inc.php&r1=55817&r2=55853&rev=55853&view=diff
==============================================================================
--- trunk/phpgwapi/inc/class.egw.inc.php (original)
+++ trunk/egroupware/api/src/Egw/Base.php Tue Apr 26 16:38:08 2016
@@ -1,6 +1,6 @@
<?php
/**
- * eGroupWare API - Applications
+ * EGroupware API - Applications
*
* @link http://www.egroupware.org
* This file was originaly written by Dan Kuykendall and Joseph Engo
@@ -9,600 +9,35 @@
* @author RalfBecker@outdoor-training.de
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package api
+ * @subpackage egw
* @version $Id$
*/
+namespace EGroupware\Api\Egw;
+
use EGroupware\Api;
-/**
- * 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
- *
- * 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.
- */
-class egw extends egw_minimal
-{
- /**
- * 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;
- /**
- * Instace of the hooks object
- *
- * @var hooks
- */
- var $hooks;
-
- /**
- * Constructor: Instantiates the sub-classes
- *
- * @author RalfBecker@outdoor-training.de
- * @param array $domain_names array with valid egw-domain names
- */
- function __construct($domain_names=null)
- {
- $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);
- }
-
- /**
- * 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
- // as SiteMgr, Wiki, KnowledgeBase and probably more still use eg next_record(), we stick with Db\Deprecated for now
- $this->db = new Api\Db\Deprecated($GLOBALS['egw_info']['server']);
- if ($this->debug)
- {
- $this->db->Debug = 1;
- }
- $this->db->set_app(Api\Db::API_APPNAME);
-
- // check if eGW is already setup, if not redirect to setup/
- try {
- $this->db->connect();
- $num_config = $this->db->select(config::TABLE,'COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
- }
- catch(Api\Db\Exception\Connection $e) {
- // ignore exception, get handled below
- }
- catch(Api\Db\Exception\InvalidSql $e1) {
- unset($e1); // not used
- try {
- $phpgw_config = $this->db->select('phpgw_config','COUNT(config_name)',false,__LINE__,__FILE__)->fetchColumn();
- }
- catch (Api\Db\Exception\InvalidSql $e2) {
- unset($e2); // not used
- // ignor error, get handled below
- }
- }
- if (!$num_config)
- {
- // we check for the old table too, to not scare updating users ;-)
- if ($phpgw_config)
- {
- throw new Exception('You need to update EGroupware before you can continue using it.',999);
- }
- if ($e)
- {
- throw new Api\Db\Exception\Setup('Connection with '.$e->getMessage()."\n\n".
- 'Maybe you not created a database for EGroupware yet.',999);
- }
- throw new Api\Db\Exception\Setup('It appears that you have not created the database tables for EGroupware.',999);
- }
- // Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in config::read)
- foreach($this->db->select(config::TABLE,'config_name,config_value',array(
- 'config_app' => 'phpgwapi',
- 'config_name' => array('system_charset','install_id','temp_dir'),
- ),__LINE__,__FILE__) as $row)
- {
- $GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value'];
- }
- if ($GLOBALS['egw_info']['server']['system_charset'] && $GLOBALS['egw_info']['server']['system_charset'] != 'utf-8')
- {
- $this->db->Link_ID->SetCharSet($GLOBALS['egw_info']['server']['system_charset']);
- }
- // load up the $GLOBALS['egw_info']['server'] array
- $GLOBALS['egw_info']['server'] += config::read('phpgwapi');
-
- // 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
- if (empty($GLOBALS['egw_info']['server']['server_timezone']) ||
- $GLOBALS['egw_info']['server']['server_timezone'] == 'System/Localtime') // treat invalid tz like empty!
- {
- 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!");
- }
- }
- date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
-
- // setup the other subclasses
- // translation class is here only for backward compatibility, as all it's methods can be called static now
- $this->translation = new translation();
- $this->common = new common();
- $this->accounts = new accounts();
- $this->acl = new acl();
- // we instanciate the hooks object here manually, to cache it's hooks in the session
- $this->hooks = new hooks();
- /* 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)
- {
- $this->session = new egw_session($domain_names);
- }
- $this->preferences = new preferences();
- $this->applications = new applications();
-
- 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
-
- $this->define_egw_constants();
-
- $this->check_app_rights();
-
- $this->load_optional_classes();
- }
- else // set the defines for login, in case it's more then just login
- {
- $this->define_egw_constants();
- }
- }
-
- /**
- * __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;
-
- if ($GLOBALS['egw_info']['server']['system_charset'])
- {
- $this->db->Link_ID->SetCharSet($GLOBALS['egw_info']['server']['system_charset']);
- }
- // 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']);
- }
-
- $this->define_egw_constants();
- }
-
- /**
- * wakeup2 function 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))
- {
- $this->template->set_root(EGW_APP_TPL);
- }
- // init the translation class, necessary as own wakeup would run before our's
- translation::init(isset($GLOBALS['egw_info']['flags']['load_translations']) ? $GLOBALS['egw_info']['flags']['load_translations'] : true);
-
- $this->unset_datetime();
-
- // verify the session
- $GLOBALS['egw']->verify_session();
- $GLOBALS['egw']->check_app_rights();
-
- $this->load_optional_classes();
- }
-
- /**
- * Unsetting datetime object, so time gets updated
- */
- function unset_datetime()
- {
- unset($this->datetime);
- }
-
- /**
- * 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'])
- {
- common::egw_header();
- }
-
- // 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']))
- {
- 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()
- {
- if($GLOBALS['egw_info']['server']['enforce_ssl'] === 'redirect' && !$_SERVER['HTTPS'])
- {
- Header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
- exit;
- }
- // check if we have a session, if not try to automatic create one
- if ($this->session->verify()) return true;
-
- $account = null;
- 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
- {
- $sessionid = $this->session->create($account);
-