From f99f2ef4e884ee158b0cde09db66a2efb90a6361 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 17 Jul 2005 21:00:49 +0000 Subject: [PATCH] 1) eGW enviroment (egw_info-array and egw-object) can now be stored in a php-session and restored from there. It is no longer necessary to create it on every page-request. At the moment you need to log out to activate any changes in the config, preferences or the apps enabled for a user. This can be changed easily by invalidating the cache. 2) New way to create an anoymous session: you can specify a callback function, which gets called if the session could not be verified. The callback can use the DB or instanciate a config object to get the account-date, which it returns. A new session get then created. --- phpgwapi/inc/class.common.inc.php | 4 +- phpgwapi/inc/class.egw.inc.php | 602 ++++++++++++++------ phpgwapi/inc/class.egw_db.inc.php | 3 + phpgwapi/inc/class.sessions.inc.php | 39 +- phpgwapi/inc/class.translation_sql.inc.php | 26 +- phpgwapi/inc/common_functions.inc.php | 26 +- phpgwapi/inc/functions.inc.php | 608 +++++---------------- 7 files changed, 639 insertions(+), 669 deletions(-) diff --git a/phpgwapi/inc/class.common.inc.php b/phpgwapi/inc/class.common.inc.php index d4bb61d340..e044fe2760 100644 --- a/phpgwapi/inc/class.common.inc.php +++ b/phpgwapi/inc/class.common.inc.php @@ -1221,10 +1221,10 @@ header('Content-type: text/html; charset='.$GLOBALS['egw']->translation->charset()); ob_end_flush(); - include(EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['server']['template_set'] + include_once(EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['server']['template_set'] . '/head.inc.php'); $this->navbar(False); - include(EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['server']['template_set'] + include_once(EGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['egw_info']['server']['template_set'] . '/navbar.inc.php'); if (!@$GLOBALS['egw_info']['flags']['nonavbar'] && !@$GLOBALS['egw_info']['flags']['navbar_target']) { diff --git a/phpgwapi/inc/class.egw.inc.php b/phpgwapi/inc/class.egw.inc.php index a0e32e5d25..78bbecef09 100644 --- a/phpgwapi/inc/class.egw.inc.php +++ b/phpgwapi/inc/class.egw.inc.php @@ -1,186 +1,448 @@ * - * and Joseph Engo * - * This is the central class for the eGroupWare API * - * Copyright (C) 2000, 2001 Dan Kuykendall * - * Parts Copyright (C) 2003 Free Software Foundation * - * -------------------------------------------------------------------------* - * This library is part of the eGroupWare API * - * http://www.egroupware.org/api * - * ------------------------------------------------------------------------ * - * 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 * - \**************************************************************************/ +/**************************************************************************\ +* eGroupWare API loader * +* This file was originaly written by Dan Kuykendall and Joseph Engo * +* Copyright (C) 2000, 2001 Dan Kuykendall * +* Parts Copyright (C) 2003 Free Software Foundation * +* -------------------------------------------------------------------------* +* 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 * +* -------------------------------------------------------------------------* +* This library is part of the eGroupWare API http://www.egroupware.org * +* ------------------------------------------------------------------------ * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 2 of the License, or (at your * +* option) any later version. * +\**************************************************************************/ - /* $Id$ */ +/* $Id$ */ + +/** + * New written class to create the eGW enviroment AND restore it from a php-session + * + * @author RalfBecker@outdoor-training.de + * @copyright GPL + * @package api + * @access public + */ +class egw +{ + /** + * Turn on debug mode. Will output additional data for debugging purposes. + * @var string $debug + * @access public + */ + var $debug = 0; // This will turn on debugging information. + /** + * @var egw_db-object $db instance of the db-object + */ + var $db; + var $config_table = 'phpgw_config'; + + /** + * Constructor: Instanciates the sub-classes + * + * @author RalfBecker@outdoor-training.de + * @param array $domain_names array with valid egw-domain names + */ + function egw($domain_names=null) + { + $GLOBALS['egw'] =& $this; // we need to be imediatly avalilible there for the other classes we instanciate + // for the migration: reference us to the old phpgw object + $GLOBALS['phpgw'] =& $this; + + // create the DB-object + $this->db =& CreateObject('phpgwapi.egw_db'); + if ($this->debug) + { + $this->db->Debug = 1; + } + $this->db->set_app('phpgwapi'); + + $this->db->Halt_On_Error = 'no'; + $this->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'] + ); + // check if eGW is already setup, if not redirect to setup/ + $this->db->select($this->config_table,'COUNT(config_name)',false,__LINE__,__FILE__); + if(!$this->db->next_record()) + { + $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); + echo '
Fatal Error: It appears that you have not created the database tables for ' + .'eGroupWare. Click here to run setup.
'; + exit; + } + $this->db->Halt_On_Error = 'yes'; + + // Set the DB's client charset if a system-charset is set + $this->db->select($this->config_table,'config_value',array( + 'config_app' => 'phpgwapi', + 'config_name' => 'system_charset', + ),__LINE__,__FILE__); + if ($this->db->next_record() && $this->db->f(0)) + { + $this->db->Link_ID->SetCharSet($this->db->f(0)); + } + // load up the $GLOBALS['egw_info']['server'] array + $this->db->select($this->config_table,'*',array('config_app' => 'phpgwapi'),__LINE__,__FILE__); + while (($row = $this->db->row(true))) + { + $GLOBALS['egw_info']['server'][$row['config_name']] = stripslashes($row['config_value']); + } + // setup the other subclasses + $this->log =& CreateObject('phpgwapi.errorlog'); + $this->translation =& CreateObject('phpgwapi.translation'); + $this->common =& CreateObject('phpgwapi.common'); + $this->hooks =& CreateObject('phpgwapi.hooks'); + $this->auth =& CreateObject('phpgwapi.auth'); + $this->accounts =& CreateObject('phpgwapi.accounts'); + $this->acl =& CreateObject('phpgwapi.acl'); + $this->session =& CreateObject('phpgwapi.sessions',$domain_names); + $this->preferences =& CreateObject('phpgwapi.preferences'); + $this->applications =& CreateObject('phpgwapi.applications'); + $this->contenthistory =& CreateObject('phpgwapi.contenthistory'); + $this->datetime =& CreateObject('phpgwapi.datetime'); + + include_once(EGW_INCLUDE_ROOT.'/phpgwapi/inc/class.error.inc.php'); + + register_shutdown_function(array($this->common, 'egw_final')); + + 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->load_theme_info(); + + $this->check_app_rights(); + + $this->load_optional_classes(); + } + } + + /** + * __wakeup function gets called by php while unserializing the egw-object, eg. reconnects to the DB + * + * @author RalfBecker@outdoor-training.de + */ + function __wakeup() + { + // for the migration: reference us to the old phpgw object + $GLOBALS['phpgw'] =& $this; + register_shutdown_function(array($this->common, 'egw_final')); + + $this->db->connect(); // we need to re-connect + foreach(array('translation','hooks','auth','accounts','acl','session','preferences','applications','contenthistory','contacts') as $class) + { + if (is_object($this->$class->db)) + { + $this->$class->db->Link_ID =& $this->db->Link_ID; + } + } + + $this->define_egw_constants(); + } + + /** + * 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 (is_object($this->template)) + { + $this->template->set_root(EGW_APP_TPL); + } + $this->translation->add_app($GLOBALS['egw_info']['flags']['currentapp']); + + // verify the session + $GLOBALS['egw']->verify_session(); + $GLOBALS['egw']->check_app_rights(); + + $this->load_optional_classes(); + } + + /** + * 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() + { + // load classes explicitly mentioned + foreach($GLOBALS['egw_info']['flags'] as $enable_class => $enable) + { + if ($enable && substr($enable_class,0,7) == 'enable_') + { + $enable_class = substr($enable_class,7,-6); + $this->$enable_class =& CreateObject('phpgwapi.'.$enable_class); + } + } + + // load the template class, if not turned off + if(!$GLOBALS['egw_info']['flags']['disable_Template_class']) + { + $this->template =& CreateObject('phpgwapi.Template',EGW_APP_TPL); + } + + // output the header unless the developer turned it off + if (!@$GLOBALS['egw_info']['flags']['noheader']) + { + $GLOBALS['egw']->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(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && !$_SERVER['HTTPS']) + { + Header('Location: https://' . $GLOBALS['egw_info']['server']['hostname'] . $GLOBALS['egw_info']['server']['webserver_url'] . $_SERVER['REQUEST_URI']); + exit; + } + $account_callback = $GLOBALS['egw_info']['flags']['autocreate_session_callback']; + + // check if we have a session, if not try to automatic create one + if (!$this->session->verify() && + !($account_callback && function_exists($account_callback) && $account_callback($account) && + ($sessionid = $this->session->create($account)))) + { + //echo "

account_callback='$account_callback', account=".print_r($account,true).", sessionid=$sessionid

\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'] != '/') + { + list(,$relpath) = explode($GLOBALS['egw_info']['server']['webserver_url'],$_SERVER['PHP_SELF'],2); + } + 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]; + } + } + // this removes the sessiondata if its saved in the URL + $query = preg_replace('/[&]?sessionid(=|%3D)[^&]+&kp3(=|%3D)[^&]+&domain=.*$/','',$_SERVER['QUERY_STRING']); + Header('Location: '.$GLOBALS['egw_info']['server']['webserver_url'].'/login.php?cd=10&phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : ''))); + exit; + } + } + + /** + * Verfiy 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() + { + if ($GLOBALS['egw_info']['flags']['currentapp'] != 'about') + { + // This will need to use ACL in the future + if (!$GLOBALS['egw_info']['user']['apps'][$GLOBALS['egw_info']['flags']['currentapp']] || + ($GLOBALS['egw_info']['flags']['admin_only'] && !$GLOBALS['egw_info']['user']['apps']['admin'])) + { + $this->common->egw_header(); + if ($GLOBALS['egw_info']['flags']['noheader']) + { + echo parse_navbar(); + } + + $this->log->write(array('text'=>'W-Permissions, Attempted to access %1','p1'=>$GLOBALS['egw_info']['flags']['currentapp'])); + + echo '

'.lang('Access not permitted').'
'; + $this->common->egw_exit(True); + } + } + } + + /** + * Load old theme info into egw_info[theme] + * + * @deprecated all theming should be done via CSS files of the template + */ + function load_theme_info() + { + global $phpgw_info; // the theme-files use this + // at the moment we still need the theme files, hopefully they are gone soon in favor of CSS + if(@file_exists(EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS['egw_info']['user']['preferences']['common']['theme'] . '.theme')) + { + include(EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS['egw_info']['user']['preferences']['common']['theme'] . '.theme'); + } + elseif(@file_exists(EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme')) + { + include(EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme'); + } + else + { + // Hope we don't get to this point. Better then the user seeing a + // complety back screen and not know whats going on + echo ''; + $this->log->write(array('text'=>'F-Abort, No themes found')); + + exit; + } + } /** - * Parent class for the egwAPI - * Parent class. Has a few functions but is more importantly used as a parent class for everything else. - * @author Dan Kuykendall - * @copyright LGPL - * @package api - * @access public - */ - - class egw + * create all the defines / constants of the eGW-enviroment (plus the depricated phpgw ones) + */ + function define_egw_constants() { - var $accounts; - var $applications; - var $acl; - var $auth; - var $db; - /** - * Turn on debug mode. Will output additional data for debugging purposes. - * @var string $debug - * @access public - */ - var $debug = 0; // This will turn on debugging information. - var $crypto; - var $categories; - var $common; - var $datetime; - var $hooks; - var $network; - var $nextmatchs; - var $preferences; - var $session; - var $send; - var $template; - var $translation; - var $utilities; - var $vfs; - var $calendar; - var $msg; - var $addressbook; - var $todo; + 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); + } - /**************************************************************************\ - * Core functions * - \**************************************************************************/ + /** + * run string through htmlspecialchars and stripslashes + * + * @param string $s + * @return string The string with html special characters replaced with entities + */ + function strip_html($s) + { + return htmlspecialchars(stripslashes($s)); + } - /** - * Strips out html chars - * - * Used as a shortcut for stripping out html special chars. - * - * @access public - * @param $s string The string to have its html special chars stripped out. - * @return string The string with html special characters removed - * @syntax strip_html($string) - * @example $reg_string = strip_html($urlencode_string); - */ - function strip_html($s) + /** + * Link url generator + * + * Used for backwards compatibility and as a shortcut. If no url is passed, it will use PHP_SELF. Wrapper to session->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 + */ + function link($url = '', $extravars = '') + { + return $this->session->link($url, $extravars); + } + + function redirect_link($url = '',$extravars='') + { + $this->redirect($this->session->link($url, $extravars)); + } + + /** + * 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 + */ + function redirect($url = '') + { + /* global $HTTP_ENV_VARS; */ + + $iis = @strpos($GLOBALS['HTTP_ENV_VARS']['SERVER_SOFTWARE'], 'IIS', 0); + + if(!$url) { - return htmlspecialchars(stripslashes($s)); + $url = $_SERVER['PHP_SELF']; } - - /** - * Link url generator - * - * Used for backwards compatibility and as a shortcut. If no url is passed, it will use PHP_SELF. Wrapper to session->link() - * - * @access public - * @param string $string The url the link is for - * @param string $extravars Extra params to be passed to the url - * @return string The full url after processing - * @see session->link() - * @syntax link($string, $extravars) - * @example None yet - */ - function link($url = '', $extravars = '') + if($iis) { - return $this->session->link($url, $extravars); + echo "\n\n\nRedirecting to $url"; + echo "\n"; + echo "\n"; + echo "

Please continue to this page

"; + echo "\n"; } - - function redirect_link($url = '',$extravars='') + else { - $this->redirect($this->session->link($url, $extravars)); + Header("Location: $url"); + print("\n\n"); } + exit; + } - /** - * Repost Prevention Detection - * - * Used as a shortcut. Wrapper to session->is_repost() - * - * @access public - * @param bool $display_error Use common error handler? - not yet implemented - * @return bool True if called previously, else False - call ok - * @see session->is_repost() - * @syntax is_post() - * @example $repost = $GLOBALS['phpgwapi']->is_repost(); - * @author Dave Hall - */ - function is_repost($display_error = False) + /** + * Shortcut to translation class + * + * 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() + */ + function lang($key,$args=null) + { + if (!is_array($args)) { - return $this->session->is_repost($display_error); + $args = func_get_args(); + array_shift($args); } - - /** - * Handles redirects under iis and apache - * - * This function handles redirects under iis and apache it assumes that $phpgw->link() has already been called - * - * @access public - * @param string The url ro redirect to - * @syntax redirect(key as string) - * @example None yet - */ - function redirect($url = '') - { - /* global $HTTP_ENV_VARS; */ - - $iis = @strpos($GLOBALS['HTTP_ENV_VARS']['SERVER_SOFTWARE'], 'IIS', 0); - - if(!$url) - { - $url = $_SERVER['PHP_SELF']; - } - if($iis) - { - echo "\n\n\nRedirecting to $url"; - echo "\n"; - echo "\n"; - echo "

Please continue to this page

"; - echo "\n"; - exit; - } - else - { - Header("Location: $url"); - print("\n\n"); - exit; - } - } - - /** - * Shortcut to translation class - * - * This function is a basic wrapper to translation->translate() - * - * @access public - * @param string The key for the phrase - * @param string the first additional param - * @param string the second additional param - * @param string the thrid additional param - * @param string the fourth additional param - * @see translation->translate() - */ - function lang($key, $m1 = '', $m2 = '', $m3 = '', $m4 = '') - { - /* global $phpgw; */ - return $this->translation->translate($key); - } - } /* end of class */ -?> + return $this->translation->translate($key,$args); + } +} diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index a4fedcf128..3e4b1c17a4 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -301,6 +301,9 @@ $this->Link_ID = &$GLOBALS['egw']->ADOdb; } } + // next ADOdb version: if (!$this->Link_ID->isConnected()) $this->Link_ID->Connect(); + if (!$this->Link_ID->_connectionID) $this->Link_ID->Connect(); + //echo "

".print_r($this->Link_ID->ServerInfo(),true)."

\n"; return $this->Link_ID; } diff --git a/phpgwapi/inc/class.sessions.inc.php b/phpgwapi/inc/class.sessions.inc.php index 20baa1c7b8..5f03aa5318 100644 --- a/phpgwapi/inc/class.sessions.inc.php +++ b/phpgwapi/inc/class.sessions.inc.php @@ -281,6 +281,8 @@ */ function verify($sessionid='',$kp3='') { + $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; + if(empty($sessionid) || !$sessionid) { $sessionid = get_var('sessionid',array('GET','COOKIE')); @@ -323,7 +325,7 @@ $this->iv = $GLOBALS['egw_info']['server']['mcrypt_iv']; $GLOBALS['egw']->crypto->init(array($this->key,$this->iv)); - $this->read_repositories(@$GLOBALS['egw_info']['server']['cache_phpgw_info']); + if ($fill_egw_info_and_repositories) $this->read_repositories(@$GLOBALS['egw_info']['server']['cache_phpgw_info']); if ($this->user['expires'] != -1 && $this->user['expires'] < time()) { @@ -339,13 +341,14 @@ } return False; } - - $GLOBALS['egw_info']['user'] = $this->user; - $GLOBALS['egw_info']['hooks'] = $this->hooks; - - $GLOBALS['egw_info']['user']['session_ip'] = $session['session_ip']; - $GLOBALS['egw_info']['user']['passwd'] = base64_decode($this->appsession('password','phpgwapi')); - + if ($fill_egw_info_and_repositories) + { + $GLOBALS['egw_info']['user'] = $this->user; + $GLOBALS['egw_info']['hooks'] = $this->hooks; + + $GLOBALS['egw_info']['user']['session_ip'] = $session['session_ip']; + $GLOBALS['egw_info']['user']['passwd'] = base64_decode($this->appsession('password','phpgwapi')); + } if ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) { if(is_object($GLOBALS['egw']->log)) @@ -384,11 +387,13 @@ } } - $GLOBALS['egw']->acl->acl($this->account_id); - $GLOBALS['egw']->accounts->accounts($this->account_id); - $GLOBALS['egw']->preferences->preferences($this->account_id); - $GLOBALS['egw']->applications->applications($this->account_id); - + if ($fill_egw_info_and_repositories) + { + $GLOBALS['egw']->acl->acl($this->account_id); + $GLOBALS['egw']->accounts->accounts($this->account_id); + $GLOBALS['egw']->preferences->preferences($this->account_id); + $GLOBALS['egw']->applications->applications($this->account_id); + } if (! $this->account_lid) { if(is_object($GLOBALS['egw']->log)) @@ -488,7 +493,11 @@ $this->clean_sessions(); $this->split_login_domain($login,$this->account_lid,$this->account_domain); - + // add domain to the login, if not already there + if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain) + { + $this->login .= '@'.$this->account_domain; + } $now = time(); //echo "

session::create(login='$login'): lid='$this->account_lid', domain='$this->account_domain'

\n"; @@ -573,7 +582,7 @@ } $GLOBALS['egw']->db->transaction_begin(); - $this->register_session($login,$user_ip,$now,$session_flags); + $this->register_session($this->login,$user_ip,$now,$session_flags); if ($session_flags != 'A') // dont log anonymous sessions { $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); diff --git a/phpgwapi/inc/class.translation_sql.inc.php b/phpgwapi/inc/class.translation_sql.inc.php index 64a7e3e9aa..42d151aae3 100644 --- a/phpgwapi/inc/class.translation_sql.inc.php +++ b/phpgwapi/inc/class.translation_sql.inc.php @@ -45,6 +45,7 @@ var $userlang = 'en'; var $loaded_apps = array(); var $line_rejected = array(); + var $lang_array = array(); /** * Constructor, sets up a copy of the db-object, gets the system-charset and tries to load the mbstring extension @@ -128,7 +129,7 @@ else { // if no translations are loaded (system-startup) use a default, else lang('charset') - $charset = !is_array(@$GLOBALS['lang']) ? 'iso-8859-1' : strtolower($this->translate('charset')); + $charset = !is_array(@$this->lang_arr) ? 'iso-8859-1' : strtolower($this->translate('charset')); } // we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0 // else we get problems for a charset is different from the default utf-8 @@ -144,12 +145,9 @@ */ function init() { - // post-nuke and php-nuke are using $GLOBALS['lang'] too - // but not as array! - // this produces very strange results - if (!is_array(@$GLOBALS['lang'])) + if (!is_array(@$this->lang_arr)) { - $GLOBALS['lang'] = array(); + $this->lang_arr = array(); } if ($GLOBALS['egw_info']['user']['preferences']['common']['lang']) @@ -157,7 +155,7 @@ $this->userlang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; } $this->add_app('common'); - if (!count($GLOBALS['lang'])) + if (!count($this->lang_arr)) { $this->userlang = 'en'; $this->add_app('common'); @@ -175,24 +173,24 @@ */ function translate($key, $vars=false, $not_found='*' ) { - if (!is_array(@$GLOBALS['lang']) || !count($GLOBALS['lang'])) + if (!is_array(@$this->lang_arr) || !count($this->lang_arr)) { $this->init(); } $ret = $key.$not_found; // save key if we dont find a translation - if (isset($GLOBALS['lang'][$key])) + if (isset($this->lang_arr[$key])) { - $ret = $GLOBALS['lang'][$key]; + $ret = $this->lang_arr[$key]; } else { $new_key = strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH))); - if (isset($GLOBALS['lang'][$new_key])) + if (isset($this->lang_arr[$new_key])) { // we save the original key for performance - $ret = $GLOBALS['lang'][$key] = $GLOBALS['lang'][$new_key]; + $ret = $this->lang_arr[$key] = $this->lang_arr[$new_key]; } } if (is_array($vars) && count($vars)) @@ -229,7 +227,7 @@ ),__LINE__,__FILE__); while ($this->db->next_record()) { - $GLOBALS['lang'][strtolower ($this->db->f('message_id'))] = $this->db->f('content'); + $this->lang_arr[strtolower ($this->db->f('message_id'))] = $this->db->f('content'); } $this->loaded_apps[$app] = $lang; } @@ -260,7 +258,7 @@ foreach($phrases as $message_id => $content) { - $GLOBALS['lang'][$message_id] = $this->convert($content,$phrases['charset']); + $this->lang_arr[$message_id] = $this->convert($content,$phrases['charset']); } } $this->loaded_apps['setup'] = $lang; diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index 3ef5bda819..afd461d58d 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -1129,15 +1129,19 @@ if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); - //echo "
".print_r($backtrace,True)."
\n"; + //echo "function_backtrace($remove)
".print_r($backtrace,True)."
\n"; foreach($backtrace as $level) { if ($remove-- < 0) { - $ret[] = (isset($level['class'])?$level['class'].'::':'').$level['function']; + $ret[] = (isset($level['class'])?$level['class'].'::':'').$level['function']. + (!$level['class'] ? '('.str_replace(EGW_SERVER_ROOT,'',$level['args'][0]).')' : ''); } } - return implode(' / ',$ret); + if (is_array($ret)) + { + return implode(' / ',$ret); + } } return $_GET['menuaction'] ? $_GET['menuaction'] : str_replace(EGW_SERVER_ROOT,'',$_SERVER['SCRIPT_FILENAME']); } @@ -1201,4 +1205,20 @@ } '); } + + /** + * function to handle multilanguage support + */ + if (!function_exists('lang')) // setup declares an own version + { + function lang($key,$vars='') + { + if(!is_array($m1)) + { + $vars = func_get_args(); + array_shift($vars); // remove $key + } + return $GLOBALS['egw']->translation->translate($key,$vars); + } + } ?> diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index cc754d3005..92085806e6 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -1,489 +1,167 @@ * - * and Joseph Engo * - * Has a few functions, but primary role is to load the phpgwapi * - * Copyright (C) 2000, 2001 Dan Kuykendall * - * -------------------------------------------------------------------------* - * This library is part of the eGroupWare API * - * http://www.egroupware.org/api * - * ------------------------------------------------------------------------ * - * 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 * - \**************************************************************************/ - - /* $Id$ */ - - /***************************************************************************\ - * If running in PHP3, then force admin to upgrade * - \***************************************************************************/ +/**************************************************************************\ +* eGroupWare API loader * +* This file was originaly written by Dan Kuykendall and Joseph Engo * +* Copyright (C) 2000, 2001 Dan Kuykendall * +* -------------------------------------------------------------------------* +* 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 * +* -------------------------------------------------------------------------* +* This library is part of the eGroupWare API http://www.egroupware.org * +* ------------------------------------------------------------------------ * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU General Public License as published by the * +* Free Software Foundation; either version 2 of the License, or (at your * +* option) any later version. * +\**************************************************************************/ - error_reporting(error_reporting() & ~E_NOTICE); +/* $Id$ */ - if (!function_exists('version_compare'))//version_compare() is only available in PHP4.1+ +error_reporting(E_ALL & ~E_NOTICE); +magic_quotes_runtime(false); + +if (!function_exists('version_compare'))//version_compare() is only available in PHP4.1+ +{ + echo 'eGroupWare requires PHP 4.1 or greater.
'; + echo 'Please contact your System Administrator'; + exit; +} + +if (!defined('EGW_API_INC')) define('EGW_API_INC',PHPGW_API_INC); // this is to support the header upgrade + +/* Make sure the header.inc.php is current. */ +if (!isset($GLOBALS['egw_domain']) || $GLOBALS['egw_info']['server']['versions']['header'] < $GLOBALS['egw_info']['server']['versions']['current_header']) +{ + echo '
You need to port your settings to the new header.inc.php version by running setup/headeradmin.
'; + exit; +} + +/* Make sure the developer is following the rules. */ +if (!isset($GLOBALS['egw_info']['flags']['currentapp'])) +{ + echo "

!!! YOU DO NOT HAVE YOUR \$GLOBALS['egw_info']['flags']['currentapp'] SET !!!
\n"; + echo '!!! PLEASE CORRECT THIS SITUATION !!!

'; +} + +//define('NO_RESTORE',true); // uncomment to see the difference ;-) + +// check if we can restore the eGW enviroment from the php-session +if (!defined('NO_RESTORE') && $GLOBALS['egw_info']['server']['sessions_type'] == 'php4' && $_REQUEST['sessionid'] && + $GLOBALS['egw_info']['flags']['currentapp'] != 'login' && $GLOBALS['egw_info']['flags']['currentapp'] != 'logout') +{ + session_name('sessionid'); + session_start(); + + if (is_array($_SESSION['egw_info_cache']) && is_array($_SESSION['egw_included_files']) && $_SESSION['egw_object_cache']) { - echo 'eGroupWare requires PHP 4.1 or greater.
'; - echo 'Please contact your System Administrator'; - exit; - } - - if (!defined('EGW_API_INC')) define('EGW_API_INC',PHPGW_API_INC); // this is to support the header upgrade - - include(EGW_API_INC.'/common_functions.inc.php'); - - /*! - @function lang - @abstract function to handle multilanguage support - */ - function lang($key,$m1='',$m2='',$m3='',$m4='',$m5='',$m6='',$m7='',$m8='',$m9='',$m10='') - { - if(is_array($m1)) + // marking the context as restored from the session, used by session->verify to not read the date from the db again + $GLOBALS['egw_info']['flags']['restored_from_session'] = true; + + // restoring the egw_info-array + $flags = $GLOBALS['egw_info']['flags']; + $GLOBALS['egw_info'] = $_SESSION['egw_info_cache']; + $GLOBALS['egw_info']['flags'] = $flags; + unset($flags); + + // including the necessary class-definitions + foreach($_SESSION['egw_included_files'] as $file) { - $vars = $m1; + //echo "

about to include $file

\n"; + include_once($file); } - else - { - $vars = array($m1,$m2,$m3,$m4,$m5,$m6,$m7,$m8,$m9,$m10); - } - $value = $GLOBALS['egw']->translation->translate("$key",$vars); - return $value; - } + $GLOBALS['egw'] = unserialize($_SESSION['egw_object_cache']); + + $GLOBALS['egw']->wakeup2(); // adapt the restored egw-object/enviroment to this request (eg. changed current app) + + //printf("

egw-enviroment restored in %d ms

\n",1000*(perfgetmicrotime()-$GLOBALS['egw_info']['flags']['page_start_time'])); - /* Make sure the header.inc.php is current. */ - if (!isset($GLOBALS['egw_domain']) || $GLOBALS['egw_info']['server']['versions']['header'] < $GLOBALS['egw_info']['server']['versions']['current_header']) - { - echo '
You need to port your settings to the new header.inc.php version by running setup/headeradmin.
'; - exit; + return; // exit this file, as the rest of the file creates a new egw-object and -enviroment } + //echo "

could not restore egw_info and the egw-object!!!

\n"; +} +include(EGW_API_INC.'/common_functions.inc.php'); - /* Make sure the developer is following the rules. */ - if (!isset($GLOBALS['egw_info']['flags']['currentapp'])) - { - /* This object does not exist yet. */ - /* $GLOBALS['egw']->log->write(array('text'=>'W-MissingFlags, currentapp flag not set'));*/ +print_debug('sane environment','messageonly','api'); - echo '!!! YOU DO NOT HAVE YOUR $GLOBALS[\'phpgw_info\'][\'flags\'][\'currentapp\'] SET !!!'; - echo '
!!! PLEASE CORRECT THIS SITUATION !!!
'; - } +/****************************************************************************\ +* Multi-Domain support * +\****************************************************************************/ - magic_quotes_runtime(false); - print_debug('sane environment','messageonly','api'); +if (!isset($GLOBALS['egw_info']['server']['default_domain']) || // allow to overwrite the default domain + !isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']])) +{ + reset($GLOBALS['egw_domain']); + list($GLOBALS['egw_info']['server']['default_domain']) = each($GLOBALS['egw_domain']); +} +if (isset($_POST['login'])) // on login +{ + $GLOBALS['login'] = $_POST['login']; + if (strstr($GLOBALS['login'],'@') === False || count($GLOBALS['egw_domain']) == 1) + { + $GLOBALS['login'] .= '@' . get_var('logindomain',array('POST'),$GLOBALS['egw_info']['server']['default_domain']); + } + $parts = explode('@',$GLOBALS['login']); + $GLOBALS['egw_info']['user']['domain'] = array_pop($parts); +} +else // on "normal" pageview +{ + $GLOBALS['egw_info']['user']['domain'] = $_REQUEST['domain']; +} - /****************************************************************************\ - * Multi-Domain support * - \****************************************************************************/ - - if (!isset($GLOBALS['egw_info']['server']['default_domain']) || // allow to overwrite the default domain - !isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']])) - { - reset($GLOBALS['egw_domain']); - list($GLOBALS['egw_info']['server']['default_domain']) = each($GLOBALS['egw_domain']); - } - if (isset($_POST['login'])) // on login - { - $GLOBALS['login'] = $_POST['login']; - if (strstr($GLOBALS['login'],'@') === False || count($GLOBALS['egw_domain']) == 1) - { - $GLOBALS['login'] .= '@' . get_var('logindomain',array('POST'),$GLOBALS['egw_info']['server']['default_domain']); - } - $parts = explode('@',$GLOBALS['login']); - $GLOBALS['egw_info']['user']['domain'] = array_pop($parts); - } - else // on "normal" pageview - { - $GLOBALS['egw_info']['user']['domain'] = get_var('domain', array('GET', 'COOKIE'), FALSE); - } +if (@isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']])) +{ + $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']; +} +else +{ + $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']; +} +print_debug('domain',@$GLOBALS['egw_info']['user']['domain'],'api'); - if (@isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']])) - { - $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']; - } - else - { - $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']; - } +// the egw-object instanciates all sub-classes (eg. $GLOBALS['egw']->db) and the egw_info array +$GLOBALS['egw'] =& CreateObject('phpgwapi.egw',array_keys($GLOBALS['egw_domain'])); - $domain_names = array_keys($GLOBALS['egw_domain']); - if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && ! $GLOBALS['egw_info']['server']['show_domain_selectbox']) +if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login') +{ + if (!$GLOBALS['egw_info']['server']['show_domain_selectbox']) { unset ($GLOBALS['egw_domain']); // we kill this for security reasons } + //printf("

egw-enviroment new created in %d ms

\n",1000*(perfgetmicrotime()-$GLOBALS['egw_info']['flags']['page_start_time'])); +} - print_debug('domain',@$GLOBALS['egw_info']['user']['domain'],'api'); +// saving the the egw_info array and the egw-object in the session +if (!defined('NO_RESTORE') && $GLOBALS['egw_info']['server']['sessions_type'] == 'php4' && $GLOBALS['egw_info']['flags']['currentapp'] != 'login') +{ + $_SESSION['egw_info_cache'] = $GLOBALS['egw_info']; + unset($_SESSION['egw_info_cache']['flags']); // dont save the flags, they change on each request - /****************************************************************************\ - * These lines load up the API, fill up the $phpgw_info array, etc * - \****************************************************************************/ - /* Load main class */ - $GLOBALS['egw'] =& CreateObject('phpgwapi.egw'); - // for the migration - $GLOBALS['phpgw'] =& $GLOBALS['egw']; - /************************************************************************\ - * Load up the main instance of the db class. * - \************************************************************************/ - $GLOBALS['egw']->db =& CreateObject('phpgwapi.egw_db'); - if ($GLOBALS['egw']->debug) + // exclude 1: caller, 2: the header.inc.php, 3: phpgwapi/setup/setup.inc.php, 4: phpgwapi/inc/functions.inc.php (this file) + $_SESSION['egw_included_files'] = array(); + foreach(array_slice(get_included_files(),4) as $file) { - $GLOBALS['egw']->db->Debug = 1; - } - $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'] - ); - @$GLOBALS['egw']->db->query("SELECT COUNT(config_name) FROM phpgw_config"); - if(!@$GLOBALS['egw']->db->next_record()) - { - $setup_dir = str_replace($_SERVER['PHP_SELF'],'index.php','setup/'); - echo '
Fatal Error: It appears that you have not created the database tables for ' - .'eGroupWare. Click here to run setup.
'; - exit; - } - $GLOBALS['egw']->db->Halt_On_Error = 'yes'; + if (!strstr($file,'phpgwapi')) continue; - // Set the DB's client charset if a system-charset is set - $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)) - { - $GLOBALS['egw']->db->Link_ID->SetCharSet($GLOBALS['egw']->db->f(0)); - } - /* Fill phpgw_info["server"] array */ - // An Attempt to speed things up using cache premise - $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()) - { - $GLOBALS['egw']->db->next_record(); - $GLOBALS['egw_info']['server']['cache_phpgw_info'] = stripslashes($GLOBALS['egw']->db->f('config_value')); - } - - $cache_query = "select content from phpgw_app_sessions where" - ." sessionid = '0' and loginid = '0' and app = 'phpgwapi' and location = 'config'"; - - $GLOBALS['egw']->db->query($cache_query,__LINE__,__FILE__); - $server_info_cache = $GLOBALS['egw']->db->num_rows(); - - if(@$GLOBALS['egw_info']['server']['cache_phpgw_info'] && $server_info_cache) - { - $GLOBALS['egw']->db->next_record(); - $GLOBALS['egw_info']['server'] = unserialize(stripslashes($GLOBALS['egw']->db->f('content'))); - } - else - { - $GLOBALS['egw']->db->query("select * from phpgw_config WHERE config_app='phpgwapi'",__LINE__,__FILE__); - while ($GLOBALS['egw']->db->next_record()) + switch(basename($file)) { - $GLOBALS['egw_info']['server'][$GLOBALS['egw']->db->f('config_name')] = stripslashes($GLOBALS['egw']->db->f('config_value')); - } - - if(@isset($GLOBALS['egw_info']['server']['cache_phpgw_info'])) - { - if($server_info_cache) - { - $cache_query = "DELETE FROM phpgw_app_sessions WHERE sessionid='0' and loginid='0' and app='phpgwapi' and location='config'"; - $GLOBALS['egw']->db->query($cache_query,__LINE__,__FILE__); - } - $cache_query = 'INSERT INTO phpgw_app_sessions(sessionid,loginid,app,location,content) VALUES(' - . "'0','0','phpgwapi','config','".addslashes(serialize($GLOBALS['egw_info']['server']))."')"; - $GLOBALS['egw']->db->query($cache_query,__LINE__,__FILE__); - } - } - unset($cache_query); - unset($server_info_cache); - if(@isset($GLOBALS['egw_info']['server']['enforce_ssl']) && !$_SERVER['HTTPS']) - { - Header('Location: https://' . $GLOBALS['egw_info']['server']['hostname'] . $GLOBALS['egw_info']['server']['webserver_url'] . $_SERVER['REQUEST_URI']); - exit; - } - - /****************************************************************************\ - * This is a global constant that should be used * - * instead of / or \ in file paths * - \****************************************************************************/ - define('SEP',filesystem_separator()); - - /************************************************************************\ - * Required classes * - \************************************************************************/ - $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'); - print_debug('main class loaded', 'messageonly','api'); - if (! isset($GLOBALS['egw_info']['flags']['included_classes']['error']) || - ! $GLOBALS['egw_info']['flags']['included_classes']['error']) - { - include(EGW_INCLUDE_ROOT.'/phpgwapi/inc/class.error.inc.php'); - $GLOBALS['egw_info']['flags']['included_classes']['error'] = True; - } - - /*****************************************************************************\ - * ACL defines - moved here to work for xml-rpc/soap, also * - \*****************************************************************************/ - 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); - - /****************************************************************************\ - * Forcing the footer to run when the rest of the script is done. * - \****************************************************************************/ - register_shutdown_function(array($GLOBALS['egw']->common, 'egw_final')); - - /****************************************************************************\ - * Stuff to use if logging in or logging out * - \****************************************************************************/ - if ($GLOBALS['egw_info']['flags']['currentapp'] == 'login' || $GLOBALS['egw_info']['flags']['currentapp'] == 'logout') - { - if ($GLOBALS['egw_info']['flags']['currentapp'] == 'login') - { - if (@$_POST['login'] != '') - { - if (count($GLOBALS['egw_domain']) > 1) - { - list($login) = explode('@',$_POST['login']); - } - else - { - $login = $_POST['login']; - } - print_debug('LID',$login,'app'); - $login_id = $GLOBALS['egw']->accounts->name2id($login); - print_debug('User ID',$login_id,'app'); - $GLOBALS['egw']->accounts->accounts($login_id); - $GLOBALS['egw']->preferences->preferences($login_id); - $GLOBALS['egw']->datetime =& CreateObject('phpgwapi.datetime'); - } - } - /**************************************************************************\ - * Everything from this point on will ONLY happen if * - * the currentapp is not login or logout * - \**************************************************************************/ - } - else - { - if (! $GLOBALS['egw']->session->verify()) - { - // we forward to the same place after the re-login - if ($GLOBALS['egw_info']['server']['webserver_url'] && $GLOBALS['egw_info']['server']['webserver_url'] != '/') - { - list(,$relpath) = explode($GLOBALS['egw_info']['server']['webserver_url'],$_SERVER['PHP_SELF'],2); - } - 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]; - } - } - // this removes the sessiondata if its saved in the URL - $query = preg_replace('/[&]?sessionid(=|%3D)[^&]+&kp3(=|%3D)[^&]+&domain=.*$/','',$_SERVER['QUERY_STRING']); - Header('Location: '.$GLOBALS['egw_info']['server']['webserver_url'].'/login.php?cd=10&phpgw_forward='.urlencode($relpath.(!empty($query) ? '?'.$query : ''))); - exit; - } - - $GLOBALS['egw']->datetime =& CreateObject('phpgwapi.datetime'); - - /* A few hacker resistant constants that will be used throught the program */ - 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()); - - /********* This sets the user variables *********/ - $GLOBALS['egw_info']['user']['private_dir'] = $GLOBALS['egw_info']['server']['files_dir'] - . '/users/'.$GLOBALS['egw_info']['user']['userid']; - - /* This will make sure that a user has the basic default prefs. If not it will add them */ - $GLOBALS['egw']->preferences->verify_basic_settings(); - - /********* Optional classes, which can be disabled for performance increases *********/ - while ($phpgw_class_name = each($GLOBALS['egw_info']['flags'])) - { - 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); - reset($GLOBALS['egw_info']['flags']); - - /*************************************************************************\ - * These lines load up the templates class * - \*************************************************************************/ - if(!@$GLOBALS['egw_info']['flags']['disable_Template_class']) - { - $GLOBALS['egw']->template =& CreateObject('phpgwapi.Template',EGW_APP_TPL); - } - - /*************************************************************************\ - * These lines load up the themes * - \*************************************************************************/ - if (! $GLOBALS['egw_info']['user']['preferences']['common']['theme']) - { - if (@$GLOBALS['egw_info']['server']['template_set'] == 'user_choice') - { - $GLOBALS['egw_info']['user']['preferences']['common']['theme'] = 'default'; - } - else - { - $GLOBALS['egw_info']['user']['preferences']['common']['theme'] = $GLOBALS['egw_info']['server']['template_set']; - } - } - if (@$GLOBALS['egw_info']['server']['force_theme'] == 'user_choice') - { - if (!isset($GLOBALS['egw_info']['user']['preferences']['common']['theme'])) - { - $GLOBALS['egw_info']['user']['preferences']['common']['theme'] = 'default'; - } - } - else - { - if (isset($GLOBALS['egw_info']['server']['force_theme'])) - { - $GLOBALS['egw_info']['user']['preferences']['common']['theme'] = $GLOBALS['egw_info']['server']['force_theme']; - } - } - - if(@file_exists(EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS['egw_info']['user']['preferences']['common']['theme'] . '.theme')) - { - include(EGW_SERVER_ROOT . '/phpgwapi/themes/' . $GLOBALS['egw_info']['user']['preferences']['common']['theme'] . '.theme'); - } - elseif(@file_exists(EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme')) - { - include(EGW_SERVER_ROOT . '/phpgwapi/themes/default.theme'); - } - else - { - /* Hope we don't get to this point. Better then the user seeing a */ - /* complety back screen and not know whats going on */ - echo ''; - $GLOBALS['egw']->log->write(array('text'=>'F-Abort, No themes found')); - - exit; - } - unset($theme_to_load); - - /*************************************************************************\ - * If they are using frames, we need to set some variables * - \*************************************************************************/ - 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')) - { - $GLOBALS['egw_info']['flags']['navbar_target'] = 'phpgw_body'; - } - - /*************************************************************************\ - * Verify that the users session is still active otherwise kick them out * - \*************************************************************************/ - if ($GLOBALS['egw_info']['flags']['currentapp'] != 'about') - { - // This will need to use ACL in the future - if (! $GLOBALS['egw_info']['user']['apps'][$GLOBALS['egw_info']['flags']['currentapp']] || - (@$GLOBALS['egw_info']['flags']['admin_only'] && - ! $GLOBALS['egw_info']['user']['apps']['admin'])) - { - $GLOBALS['egw']->common->phpgw_header(); - if ($GLOBALS['egw_info']['flags']['noheader']) - { - echo parse_navbar(); - } - - $GLOBALS['egw']->log->write(array('text'=>'W-Permissions, Attempted to access %1','p1'=>$GLOBALS['egw_info']['flags']['currentapp'])); - - echo '

'.lang('Access not permitted').'
'; - $GLOBALS['egw']->common->phpgw_exit(True); - } - } - - if(!is_object($GLOBALS['egw']->datetime)) - { - $GLOBALS['egw']->datetime =& CreateObject('phpgwapi.datetime'); - } - $GLOBALS['egw']->applications->read_installed_apps(); // to get translated app-titles - - /*************************************************************************\ - * Load the header unless the developer turns it off * - \*************************************************************************/ - if (!@$GLOBALS['egw_info']['flags']['noheader']) - { - $GLOBALS['egw']->common->phpgw_header(); - } - - /*************************************************************************\ - * Load the app include files if the exists * - \*************************************************************************/ - /* Then the include file */ - 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'); + case 'head.inc.php': // needs EGW_TEMPLATE_DIR and is included anyway by common::egw_header() + case 'functions.inc.php': // not needed/wanted at all + break; + default: + $_SESSION['egw_included_files'][] = $file; } } + $_SESSION['egw_object_cache'] = serialize($GLOBALS['egw']); +}