<?php
/* +----------------------------------------------------------------------+
| Netautor Professional Application Server |
+----------------------------------------------------------------------+
| Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net> |
+----------------------------------------------------------------------+
| This file is subject to license, that is bundled with this package |
| in the file LICENSE.TXT, and is available at through the |
| world-wide-web at http://www.netautor.com/license/ |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| hide@address.com so we can mail you a copy. |
+----------------------------------------------------------------------+
| Authors: Stefan Rottensteiner <hide@address.com> |
| Marek Kadziela <hide@address.com> |
| Gregor Wollner |
| Christian Unger |
| Helli Kleinhans |
+----------------------------------------------------------------------+
| @version $Revision: 1.72 $ |
+----------------------------------------------------------------------+*/
/**
* Main init.
*/
error_reporting(1);
/** ComPat 1
* MAGIC_QUOTES_GPC müssen OFF sein.
*/
$eval_postget = FALSE;
if(ini_get('magic_quotes_gpc')==1)
{
if (!function_exists('recursive_stripslashes'))
{
function recursive_stripslashes(&$var)
{
if (!isset($var) || is_null($var)) return ;
if(is_array($var))
{
foreach( $var as $key=>$val)
recursive_stripslashes($var[$key]);
}
else
{
$var = stripslashes($var);
}
}
}
recursive_stripslashes($_POST);
recursive_stripslashes($_GET);
recursive_stripslashes($_REQUEST);
recursive_stripslashes($GLOBALS['HTTP_POST_VARS']);
recursive_stripslashes($GLOBALS['HTTP_GET_VARS']);
$eval_postget = TRUE;
}
/** ComPat 2
* VARIABLES_ORDER muss auf EPGCS gestellt.sein.
*/
if(strpos(strtoupper(ini_get('variables_order')),'PG') === false || $eval_postget)
{
$_REQUEST = array();
foreach($_POST as $idx=>$wert) $GLOBALS[$idx] = $_POST[$idx];
foreach($_GET as $idx=>$wert) $GLOBALS[$idx] = $_GET[$idx];
$_REQUEST = array_merge( $_POST, $_GET);
}
unset($eval_postget);
/** ComPat 3
* REGISTER_GLOBALS muss auf ON sein
*/
if(!ini_get('register_globals'))
{
@import_request_variables('EPGCS');
}
/** ComPat4
* Definiere Funktion 'html_entity_decode' wenn notwendig.
*/
if (!function_exists('html_entity_decode'))
{
if (!defined('ENT_NOQUOTES')) define('ENT_NOQUOTES' , 0);
if (!defined('ENT_COMPAT')) define('ENT_COMPAT' , 2);
if (!defined('ENT_QUOTES')) define('ENT_QUOTES' , 3);
function html_entity_decode ($string, $opt = ENT_COMPAT, $charset='ISO-8859-1')
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
if ($opt & 1)
$trans_tbl['''] = "'";
if (!($opt & 2))
unset($trans_tbl['"']);
return strtr ($string, $trans_tbl);
}
}
/** ComPat5
* Definiere Funktion 'stripos' wenn notwendig.
*/
if (!function_exists('stripos'))
{
function stripos ($haystack, $needle, $offset=0 )
{
return strpos( strtolower($haystack), strtolower($needle), $offset);
}
}
/** ComPat 6
* Definiere Funktion 'array_unique' wenn notwendig.
*/
if (!function_exists('array_unique'))
{
function array_unique ( $array )
{
return array_flip( array_flip( $array));
}
}
/** ComPat 7
* Definiere Funktion 'file_get_contents' wenn notwendig.
*/
if (!function_exists('file_get_contents'))
{
function file_get_contents ( $filename, $includePath=null, $context=null )
{
$fileContent = file( $filename);
$fileContent = implode('', $fileContent);
return $fileContent;
}
}
/**
* Interne Funktion zur Ausgabe von schwerwiegenden Fehlern.
* @param string $text Fehlertext
* @param boolean continue Script fortsetzen oder nicht
*/
if (!function_exists('napro_internal_error'))
{
function napro_internal_error($text,$continue=true)
{
?>
<div style="border:Red solid 2px; padding: 5px 5px 5px 5px; font-weight: bold; font-size: 11px; font-family: Verdana,Geneva,Arial,Helvetica,sans-serif; color: Black; background-color: #FFFFB0;" >
<span style="color: Red;" >INTERNAL NETAUTOR ERROR<br><br></span>
<?php echo htmlspecialchars($text); ?>
</div>
</body>
</html>
<?php
if (!$continue)
{
ob_flush();
die();
}
}
}
/* Kann niemals von aussen kommen */
if (isset($_REQUEST['sql_conf']))
{
unset($_REQUEST['sql_conf']);
if (isset($GLOBALS['sql_conf']))
unset($GLOBALS['sql_conf']);
}
if(!is_array($GLOBALS['sql_conf']))
{
if(strpos(__FILE__,'napro4') !== false)
{
$basedir= substr(__FILE__,0,strpos(__FILE__,'napro4'));
}
else
{
$basedir= substr($_SERVER['SCRIPT_FILENAME'],0,strpos($_SERVER['SCRIPT_FILENAME'],'napro4'));
}
/**
* In case of unpredictable problems, set here the $basedir manually
*/
// $basedir = '';
$conf_name = $basedir.'/config/base.';
if (file_exists($conf_name.'php'))
{
include_once($conf_name.'php');
}
elseif (file_exists($conf_name.'conf'))
{
if (@copy ($conf_name.'conf',$conf_name.'php'))
{
@unlink($conf_name.'conf');
include_once($conf_name.'php');
}
else
{
napro_internal_error('Cannot find new configuration at "'.$basedir.'config/base.php"', false);
}
}
else
{
napro_internal_error('Cannot find configuration at "'.$basedir.'config/base.php"', false);
}
}
/**
* System class: NaSystem
*/
class NaSystem extends dcenv
{
/**
* Get current sstem os
*/
function getOs()
{
return $this->os;
}
}
// Automatischen Flush deaktivieren
ob_start();
ob_implicit_flush(0);
// Magic-Quotes etc. einstellen
set_magic_quotes_runtime(0);
if (function_exists('ini_set'))
{
ini_set('magic_quotes_gpc',0); // MAGIG_QUOTES_GPC sollten immer OFF sein
ini_set('magic_quotes_runtime',0); // MAGIC_QUOTES_RUNTIME müssen immer OFF sein
ini_set('magic_quotes_sybase',0); // MAGIC_QUOTES_SYBASE müssen immer OFF sein
ini_set('allow_call_time_pass_reference','Off');
ini_set('variables_order','EPGCS');
}
register_shutdown_function('napro_shutdown');
$NA_SYSTEM = new NaSystem();
// Wenn die Konfiguration noch nicht geladen ist, dies jetzt einmalig tun
if( !isset( $GLOBALS['init_inc'] ) )
{
// Neue Klasse für Umgebung
$DC_ENV = new dcenv;
$NAPRO_APPLICATION_CACHE = array();
if(!file_exists($GLOBALS['DC_ENV']->includepath.'functions/'.$sql_conf['vendor'].'.fnc'))
{
napro_internal_error('Invalid SQL driver ['.$sql_conf['vendor'].'].', false);
}
/* Muss gesetzt sein - Zur Feststellung ob wir in der Webroot sind oder nicht */
if (empty($DC_ENV->application_root_sub))
{
$DC_ENV->application_root_sub = str_replace('//','/',substr($DC_ENV->installpath ,0,-(strlen('netautor/napro4/'))));
}
// Libs die mindestens benötigt werden.
includeNaPro( 'users,locale,sql,'.$sql_conf['vendor'] );
$sql_db = 'sql_'.$sql_conf['vendor'];
$sql_world = new $sql_db($NA_SYSTEM,$sql_conf);
if (function_exists('ini_set'))
{
ini_set('session.save_path' ,$DC_ENV->cachepath.'sessions/');
ini_set('session.name' ,$DC_ENV->cookiename);
ini_set('session.use_cookies' ,'1');
}
else
{
session_save_path( $DC_ENV->cachepath.'sessions/');
session_name( $DC_ENV->cookiename);
}
if(empty($GLOBALS['npf_export']))
{
session_start();
/**
* Die Registrierung von SESSION-Variablen hängt von der Einstellung
* REGISTER_GLOBALS ab.
*/
if(ini_get('register_globals'))
{
session_register('LOCALE');
session_register('USER');
session_register('NAPRO_APPLICATION_CACHE');
@session_register('NA_PRO_CACHE');
}
else
{
$GLOBALS['LOCALE'] = & $_SESSION['LOCALE'];
$GLOBALS['USER'] = & $_SESSION['USER'];
$GLOBALS['NAPRO_APPLICATION_CACHE'] = & $_SESSION['NAPRO_APPLICATION_CACHE'];
$GLOBALS['NA_PRO_CACHE'] = & $_SESSION['NA_PRO_CACHE'];
}
}
if (isset($_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']))
{
$DC_ENV->debug_level = $_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'];
}
if( $DC_ENV->login_engine &&
strtolower($GLOBALS['DC_ENV']->login_engine) == 'ldap' )
{
includeNaPro( 'ldap' );
$GLOBALS['LDAP_ENV'] = new ldap();
}
// --- Cookiename zuweisen
$DC_ENV->message = array();
if(empty($USER->NAME))
{
$USER = new users($sql_world); // Neue Klasse für User
if( isset($_COOKIE[ $DC_ENV->cookiename ]) ) // Cookie ok
{
if (empty($_POST['SETUP_CHECK'])){
// Read user data and session data . Skipped while installation !
$query = "SELECT ses_user_id AS user_id,ses_id FROM sessions WHERE ses_cookie='".$_COOKIE[ $DC_ENV->cookiename ]."'";
$erg = $sql_world->select( $query, 0, 1, SQL_FETCH_BOTH);
if( !empty($erg[0]['user_id']) ) // Wenn benutzer_Id valid
{
$sql_world->exec('UPDATE sessions SET ses_access=\''.date('Y-m-d H:i:s').'\',ses_count =ses_count + 1 WHERE ses_id='.$erg[0]['ses_id']);
$USER->users_set($erg[0]['user_id']);
$USER->users_init();
}
else {
$USER->users_set(10);
$USER->users_init();
}
}
else {
$USER->users_set(10);
}
}
else
{
$USER->users_set(10);
$USER->users_init();
}
}
else
{
$cache=TRUE;
//Setzt das SQL-Object nochmals ein da es nach dem holen des USER objects aus der Session in keinem
//brauchbaeren Zustand ist.
$USER->setSQL($sql_world);
}
// --- evaluate language
if (empty($GLOBALS['USER']->FEATURE['value']['language']))
{
/* No language-feature set */
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{ /* Try to set language by browser-defined language */
$langs = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$langs_count = count($langs);
$installed_langs = array ('de'=>true,'en'=>true,'pl'=>true);
for ($i=0;$i<$langs_count;$i++)
{
$temp = strtolower(substr($langs[$i],0,2));
if (!isset($installed_langs[$temp])) continue;
$language = $GLOBALS['USER']->FEATURE['value']['language'] = $temp;
break;
}
}
}
else
{
$language = $GLOBALS['USER']->FEATURE['value']['language'];
}
/* Set ENGLISH as default language */
if (empty($language)) $language ='en';
/* Create localization object*/
$LOCALE = new Locale($language);
// --- set language
//setCurrentLanguage($language,true);
if( strpos($_SERVER['PHP_SELF'],'php.exe') !== false ) // Wenn php.exe im Pfad
{
$PHP_SELF = strstr($_SERVER['PHP_SELF'],'.exe'); // Alles links von .exe wegschneiden
$PHP_SELF = substr($PHP_SELF,4); // .exe auch noch wegschneiden
$_SERVER['PHP_SELF'] = $GLOBALS['PHP_SELF'] = $PHP_SELF;
}
error_reporting(empty($USER->FEATURE['value']['debug-level'])?1:$USER->FEATURE['value']['debug-level']);
$GLOBALS['init_inc'] = true; // Bestätigung, daß init.inc bereits aufgerufen wurde
}
/**
* Includes a Netautor Professional resource - once
* @param string $Includes List of resources
* @param boolean $Debug -- obsolet --
* @param boolean $Area Resources from 'internal','npf_lib', 'external', 'functions'
* @param string $Extension File-Extesion
*/
function includeNaPro($Includes,$Debug=false,$Area='functions',$Extension='fnc')
{
$Includes = explode(',',$Includes);
switch($Area)
{
case 'internal':
case 'npf_lib': $fn_base = $GLOBALS['DC_ENV']->includepath.'npf_lib/'; break;
case 'external': $fn_base = $GLOBALS['DC_ENV']->external_func_path; break;
case 'functions':
default: $fn_base = $GLOBALS['DC_ENV']->includepath.'functions/'; break;
}
foreach ($Includes as $Key => $Value)
{
$Value = strtolower($Value);
if (isset($GLOBALS['NAPRO_INCLUDES'][ $Area.'_'.$Value.'_inc' ])) continue;
$fn = $fn_base.$Value.'.'.$Extension ;
include_once($fn);
$GLOBALS['NAPRO_INCLUDES'][$Area.'_'.$Value.'_inc']=true;
}
return true;
}
/**
* Kleine Funktion um eine simples Debug-Fenster zu befüllen
*
* An Hand eines globalen Schalters wird, wenn nötig, ein kleines Script ausgegeben.
* Für jeden Debug-Punkt wird ein Link zum Window-Open ausgegeben.
* @param string $debugText Der Debug-Text
* @param string $title
*/
function debugNaPro($debugText,$debugTitle='',$debugParam='')
{
if(empty($debugParam['RuntimeInterline1'])) $debugParam['RuntimeInterline1'] = microtime();
if(empty($debugParam['RuntimeInterline2'])) $debugParam['RuntimeInterline2'] = $debugParam['RuntimeInterline1'];
if(empty($debugParam['DebugToken'])) $debugParam['DebugToken'] = 'spot';
list($m_start,$start) = explode(' ',trim($GLOBALS['NAPRO_DEBUGGER']['php_runtime_start']));
$start = doubleval($start) + doubleval($m_start);
list($m_interline1,$interline1) = explode(' ',trim($debugParam['RuntimeInterline1']));
$interline1 = doubleval($interline1) + doubleval($m_interline1);
list($m_interline2,$interline2) = explode(' ',trim($debugParam['RuntimeInterline2']));
$interline2 = doubleval($interline2) + doubleval($m_interline2);
$debugTime1 = $interline1 - $start;
$debugTime2 = $interline2 - $start;
$debugTime0 = $interline2 - $interline1;
$debugText = "PHP Runtime Interim: {$debugTime1}<br>{$debugText}<br>PHP Runtime Interim: {$debugTime2}<br>PHP Runtime Lap: {$debugTime0}";
$debugText = "<b>DEBUG: {$debugTitle} LEVEL {$GLOBALS['DC_ENV']->debug_level}</b> - ".date('d.m.Y H:i:s',time())."<br><hr size='1'>{$debugText}";
$debugText = "<html><title>Netautor Debug Window</title><LINK rel='stylesheet' type='TEXT/CSS' href='{$GLOBALS['DC_ENV']->indexpath}include/netautor.css'><body class='blue' ><code>{$debugText}</code></body></html>";
$debugTitle = '('.round($debugTime1,2).') '.$debugTitle.' ('.round($debugTime2,2).')';
$debugID = md5(microtime());
?>
<script language="JavaScript" type="text/javascript">
<!--
document.debugText<?php echo $debugID;?>= "<?php echo preg_replace('/[\r\n\t]/ium','', str_replace('"','\\"', $debugText) )?>";
//-->
</script>
<a href ="javascript: void 0;"
onClick ="openDebugWindow('<?php echo $debugID;?>');"
title ="[ DEBUG: <?php echo $debugTitle;?> ]" ><img border="0" src="<?php echo $GLOBALS['DC_ENV']->indexpath; ?>grafik/debug_<?php echo($debugParam['DebugToken']); ?>.gif" alt="[ DEBUG <?php echo $debugTitle;?>]" width="18" height="18" ></a>
<?php
if (empty($GLOBALS['NA_PRO_DEBUG_SCRIPT'])):
$GLOBALS['NA_PRO_DEBUG_SCRIPT'] = 1;
?>
<script language="JavaScript" type="text/javascript">
<!--
function openDebugWindow(debugID)
{
eval("var theText = ( document.debugText"+debugID+" ? document.debugText"+debugID+" : '');");
var w = window.open("<?php echo $GLOBALS['DC_ENV']->indexpath?>home/empty.html","NetautorDebug","width=500,height=200,top=100,left=100,screenX=100,screenY=100,menubar=no,locationbar=no,scrollbars=yes,resizable=yes,dependent=yes");
if (w)
{
w.document.open("text/html","replace");
w.document.write(theText);
w.document.close();
w.focus();
}
else
{
alert(theText);
}
}
//-->
</script>
<?php endif; ?>
<?php
}
/**
* Handles output-buffer-zipping.
* Closed.
*/
function na_pro_zip($exit=true)
{
/**
* Funktion wegen "Überalterung" entgültig gelöscht.
*/
if ($exit) die();
}
/**
* Shut down netautor professional
*/
function napro_shutdown()
{
if (isset($GLOBALS['sql_world']) && is_object($GLOBALS['sql_world']))
$GLOBALS['sql_world']->sql_disconnect();
}
?>