| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare API loader * 4 * This file was originaly written by Dan Kuykendall and Joseph Engo * 5 * Copyright (C) 2000, 2001 Dan Kuykendall * 6 * -------------------------------------------------------------------------* 7 * Rewritten by RalfBecker@outdoor-training.de to store the eGW enviroment * 8 * (egw-object and egw_info-array) in a php-session and restore it from * 9 * there instead of creating it completly new on each page-request. * 10 * The enviroment gets now created by the egw-class * 11 * -------------------------------------------------------------------------* 12 * This library is part of the eGroupWare API http://www.egroupware.org * 13 * ------------------------------------------------------------------------ * 14 * This program is free software; you can redistribute it and/or modify it * 15 * under the terms of the GNU General Public License as published by the * 16 * Free Software Foundation; either version 2 of the License, or (at your * 17 * option) any later version. * 18 \**************************************************************************/ 19 20 /* $Id: functions.inc.php 23187 2007-01-03 08:06:47Z ralfbecker $ */ 21 22 error_reporting(E_ALL & ~E_NOTICE); 23 magic_quotes_runtime(false); 24 25 if (!function_exists('version_compare'))//version_compare() is only available in PHP4.1+ 26 { 27 echo 'eGroupWare requires PHP 4.1 or greater.<br>'; 28 echo 'Please contact your System Administrator'; 29 exit; 30 } 31 32 if (!defined('EGW_API_INC')) define('EGW_API_INC',PHPGW_API_INC); // this is to support the header upgrade 33 34 /* Make sure the header.inc.php is current. */ 35 if (!isset($GLOBALS['egw_domain']) || $GLOBALS['egw_info']['server']['versions']['header'] < $GLOBALS['egw_info']['server']['versions']['current_header']) 36 { 37 echo '<center><b>You need to update your header.inc.php file to version '. 38 $GLOBALS['egw_info']['server']['versions']['current_header']. 39 ' by running <a href="setup/manageheader.php">setup/headeradmin</a>.</b></center>'; 40 exit; 41 } 42 43 /* Make sure the developer is following the rules. */ 44 if (!isset($GLOBALS['egw_info']['flags']['currentapp'])) 45 { 46 echo "<p><b>!!! YOU DO NOT HAVE YOUR \$GLOBALS['egw_info']['flags']['currentapp'] SET !!!<br>\n"; 47 echo '!!! PLEASE CORRECT THIS SITUATION !!!</b></p>'; 48 } 49 50 include_once (EGW_API_INC.'/common_functions.inc.php'); 51 52 // check if we can restore the eGW enviroment from the php-session 53 if ($GLOBALS['egw_info']['server']['sessions_type'] == 'php4-restore' && $_REQUEST['sessionid']) 54 { 55 session_name('sessionid'); 56 session_start(); 57 58 if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login' && $GLOBALS['egw_info']['flags']['currentapp'] != 'logout') 59 { 60 if (is_array($_SESSION['egw_info_cache']) && is_array($_SESSION['egw_included_files']) && $_SESSION['egw_object_cache']) 61 { 62 // marking the context as restored from the session, used by session->verify to not read the date from the db again 63 $GLOBALS['egw_info']['flags']['restored_from_session'] = true; 64 65 // restoring the egw_info-array 66 $flags = $GLOBALS['egw_info']['flags']; 67 $GLOBALS['egw_info'] = $_SESSION['egw_info_cache']; 68 $GLOBALS['egw_info']['flags'] = $flags; 69 unset($flags); 70 71 // including the necessary class-definitions 72 foreach($_SESSION['egw_included_files'] as $file) 73 { 74 //echo "<p>about to include $file</p>\n"; 75 include_once($file); 76 } 77 $GLOBALS['egw'] = unserialize($_SESSION['egw_object_cache']); 78 79 $GLOBALS['egw']->wakeup2(); // adapt the restored egw-object/enviroment to this request (eg. changed current app) 80 81 //printf("<p style=\"position: absolute; right: 0px; top: 0px;\">egw-enviroment restored in %d ms</p>\n",1000*(perfgetmicrotime()-$GLOBALS['egw_info']['flags']['page_start_time'])); 82 83 return; // exit this file, as the rest of the file creates a new egw-object and -enviroment 84 } 85 //echo "<p>could not restore egw_info and the egw-object!!!</p>\n"; 86 } 87 else // destroy the session-cache if called by login or logout 88 { 89 unset($_SESSION['egw_info_cache']); 90 unset($_SESSION['egw_included_files']); 91 unset($_SESSION['egw_object_cache']); 92 } 93 } 94 95 print_debug('sane environment','messageonly','api'); 96 97 /****************************************************************************\ 98 * Multi-Domain support * 99 \****************************************************************************/ 100 101 if (!isset($GLOBALS['egw_info']['server']['default_domain']) || // allow to overwrite the default domain 102 !isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']])) 103 { 104 if(isset($GLOBALS['egw_domain'][$_SERVER['SERVER_NAME']])) 105 { 106 $GLOBALS['egw_info']['server']['default_domain'] = $_SERVER['SERVER_NAME']; 107 } 108 else 109 { 110 reset($GLOBALS['egw_domain']); 111 list($GLOBALS['egw_info']['server']['default_domain']) = each($GLOBALS['egw_domain']); 112 } 113 } 114 if (isset($_POST['login'])) // on login 115 { 116 $GLOBALS['login'] = $_POST['login']; 117 if (strstr($GLOBALS['login'],'@') === False || count($GLOBALS['egw_domain']) == 1) 118 { 119 $GLOBALS['login'] .= '@' . get_var('logindomain',array('POST'),$GLOBALS['egw_info']['server']['default_domain']); 120 } 121 $parts = explode('@',$GLOBALS['login']); 122 $GLOBALS['egw_info']['user']['domain'] = array_pop($parts); 123 } 124 else // on "normal" pageview 125 { 126 $GLOBALS['egw_info']['user']['domain'] = get_var('domain',array('GET','COOKIE'),false); 127 } 128 if (@isset($GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']])) 129 { 130 $GLOBALS['egw_info']['server']['db_host'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_host']; 131 $GLOBALS['egw_info']['server']['db_port'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_port']; 132 $GLOBALS['egw_info']['server']['db_name'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_name']; 133 $GLOBALS['egw_info']['server']['db_user'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_user']; 134 $GLOBALS['egw_info']['server']['db_pass'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_pass']; 135 $GLOBALS['egw_info']['server']['db_type'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['user']['domain']]['db_type']; 136 } 137 else 138 { 139 $GLOBALS['egw_info']['server']['db_host'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_host']; 140 $GLOBALS['egw_info']['server']['db_port'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_port']; 141 $GLOBALS['egw_info']['server']['db_name'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_name']; 142 $GLOBALS['egw_info']['server']['db_user'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_user']; 143 $GLOBALS['egw_info']['server']['db_pass'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_pass']; 144 $GLOBALS['egw_info']['server']['db_type'] = $GLOBALS['egw_domain'][$GLOBALS['egw_info']['server']['default_domain']]['db_type']; 145 } 146 print_debug('domain',@$GLOBALS['egw_info']['user']['domain'],'api'); 147 148 // the egw-object instanciates all sub-classes (eg. $GLOBALS['egw']->db) and the egw_info array 149 $GLOBALS['egw'] =& CreateObject('phpgwapi.egw',array_keys($GLOBALS['egw_domain'])); 150 151 if ($GLOBALS['egw_info']['flags']['currentapp'] != 'login') 152 { 153 if (!$GLOBALS['egw_info']['server']['show_domain_selectbox']) 154 { 155 unset ($GLOBALS['egw_domain']); // we kill this for security reasons 156 } 157 //printf("<p style=\"position: absolute; right: 0px; top: 0px;\">egw-enviroment new created in %d ms</p>\n",1000*(perfgetmicrotime()-$GLOBALS['egw_info']['flags']['page_start_time'])); 158 } 159 160 // saving the the egw_info array and the egw-object in the session 161 if ($GLOBALS['egw_info']['server']['sessions_type'] == 'php4-restore' && $GLOBALS['egw_info']['flags']['currentapp'] != 'login') 162 { 163 $_SESSION['egw_info_cache'] = $GLOBALS['egw_info']; 164 unset($_SESSION['egw_info_cache']['flags']); // dont save the flags, they change on each request 165 166 // exclude 1: caller, 2: the header.inc.php, 3: phpgwapi/setup/setup.inc.php, 4: phpgwapi/inc/functions.inc.php (this file) 167 $_SESSION['egw_included_files'] = array(); 168 foreach(array_slice(get_included_files(),4) as $file) 169 { 170 if (!strstr($file,'phpgwapi')) 171 { 172 continue; 173 } 174 175 switch(basename($file)) 176 { 177 case 'head.inc.php': // needs EGW_TEMPLATE_DIR and is included anyway by common::egw_header() 178 case 'functions.inc.php': // not needed/wanted at all 179 break; 180 default: 181 $_SESSION['egw_included_files'][] = $file; 182 } 183 } 184 $_SESSION['egw_object_cache'] = serialize($GLOBALS['egw']); 185 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |