<?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> |
| Helli Kleinhans |
| Christian Unger |
| Gregor Wollner |
+----------------------------------------------------------------------+ */
/**
* Script das die nötige Umgebung für die Layouts zusammenstellt
*
* @autor Helmut Kleinhans
* @autor Marek Kadziela
* @autor Stefan Rottensteiner
* @version $Revision: 1.55 $
*/
error_reporting(0);
// caching ...
if(!is_object($GLOBALS['DC_ENV']))
{
include_once('../../../config/base.php');
$GLOBALS['DC_ENV'] = new dcenv();
}
// Switch off debugger by npf_debug = no
if($GLOBALS['npf_debug'] == 'no')
$GLOBALS['DC_ENV']->debug_level = '';
// Start der Laufzeitmessung wenn erwünscht
if (!empty($GLOBALS['DC_ENV']->debug_level))
$GLOBALS['php_runtime_start'] = microtime();
// cache einstellungen einlesen
$session_file = $DC_ENV->cachepath.'sessions/sess_'.$_COOKIE[ $GLOBALS['DC_ENV']->cookiename ];
if (empty($npf_cache) && file_exists($session_file))
{
if (function_exists('file_get_contents'))
$session_data = file_get_contents($session_file);
else
$session_data = implode('',file($session_file));
if (strpos($session_data, 's:10:"INIT_CACHE";a:1:{i:0;s:2:"no";}')!==false)
$GLOBALS['npf_cache'] = $npf_cache = 'no';
if (strpos($session_data, 's:10:"INIT_CACHE";s:2:"no"')!==false)
$GLOBALS['npf_cache'] = $npf_cache = 'no';
if (strpos($session_data, 's:10:"INIT_CACHE";a:1:{i:0;s:3:"yes";}')!==false)
$GLOBALS['npf_cache'] = $npf_cache = 'yes';
if (strpos($session_data, 's:10:"INIT_CACHE";s:3:"yes"')!==false)
$GLOBALS['npf_cache'] = $npf_cache = 'yes';
}
else
{
$session_data = '';
$data = array();
}
if(empty($GLOBALS['npf_cache']) && empty($npf_cache)) $GLOBALS['npf_cache'] = $npf_cache = strtolower($GLOBALS['DC_ENV']->allow_cache);
if($GLOBALS['npf_cache'] == 'yes' && intval($GLOBALS['DC_ENV']->cache_life_time) > 0) $GLOBALS['npf_cache'] = $npf_cache = $GLOBALS['DC_ENV']->cache_life_time;
if (empty($npf_cache) && !empty($GLOBALS['INIT_CACHE'])) $GLOBALS['npf_cache'] = $npf_cache = $GLOBALS['INIT_CACHE'];
$GLOBALS['npf_cache_auto'] = (!empty($GLOBALS['npf_cache']) && strtolower($GLOBALS['npf_cache']) != 'no' && $GLOBALS['DC_ENV']->auto_cache_note == 'yes') ? 'yes' : 'no';
$GLOBALS['npf_cache_server_mode'] = (!empty($GLOBALS['DC_ENV']->cache_server_mode)) ? strtolower($GLOBALS['DC_ENV']->cache_server_mode) : '';
// ... caching
$na_layout_cache_key = false;
$na_layout_cache_file_name = '';
if (!function_exists('nal_calculateCacheKey'))
{
function nal_calculateCacheKey($session_data = false)
{
$app_cache_to_check = array_unique(array_merge($GLOBALS['npf_cache_params']['app_cache_to_check'], explode(',', $GLOBALS['DC_ENV']->cache_reference_session)));
if(!empty($app_cache_to_check))
{
$session_file = $GLOBALS['DC_ENV']->cachepath.'sessions/sess_'.$_COOKIE[ $GLOBALS['DC_ENV']->cookiename ];
if (file_exists( $session_file))
{
if (empty($session_data) || !is_string($session_data))
{
if (function_exists('file_get_contents'))
$session_data = file_get_contents( $session_file);
else
$session_data = implode('',file($session_file));
}
if(!empty($session_data) && is_string($session_data))
{
$data = substr($session_data,strpos($session_data,'NAPRO_APPLICATION_CACHE')+24);
$data = substr($data,0,strpos($data,'NA_PRO_CACHE'));
$data = unserialize($data);
}
$session_data = array();
if(!empty($data) && is_array($data))
{
foreach($app_cache_to_check as $idx=>$name)
{
if (isset($data[ $name])) $session_data[$name] = $data[$name];
}
}
}
else
{
$session_data = array();
}
}
else
{
$session_data = array();
}
$na_layout_cache_key = array_merge($_POST,$_GET,$session_data);
if (isset($na_layout_cache_key['npf_cache']))
unset($na_layout_cache_key['npf_cache']);
ksort($na_layout_cache_key);
$na_layout_cache_key = serialize($na_layout_cache_key);
return $na_layout_cache_key;
}
}
if(!empty($npf_cache) && ($npf_cache == 'yes' || $npf_cache=='update' || intval($npf_cache) > 0))
{
$cache_mlay_id = (empty($mlay_id) ? '' : $mlay_id );
$cache_mdoc_id = (empty($mdoc_id) ? '' : $mdoc_id );
clearstatcache();
unset($_POST['npf_cache']);
unset($_GET['npf_cache']);
unset($_REQUEST['npf_cache']);
$na_layout_cache_key = nal_calculateCacheKey($session_data);
$na_layout_cache_name = $cache_mlay_id.'_'.$cache_mdoc_id.'_'.md5($na_layout_cache_key);
$na_layout_cache_file_name = $GLOBALS['DC_ENV']->cachepath.'/layouts/'.$na_layout_cache_name.'.lyc';
if($npf_cache != 'yes' && $npf_cache != 'update')
{
if(file_exists($na_layout_cache_file_name))
{
$ftime = filemtime($na_layout_cache_file_name);
$stime = date('U', time());
$npf_cache = ( $stime-$ftime < $npf_cache ? 'yes' : 'update' );
unset($ftime);
unset($stime);
}
else
{
$npf_cache = 'update';
}
}
}
else
{
$na_layout_cache_key = nal_calculateCacheKey($session_data);
}
unset( $data);
unset( $session_data);
if( $npf_cache == 'yes' && $GLOBALS['npf_cache_server_mode'] != 'cms' && file_exists($na_layout_cache_file_name))
{
readfile($na_layout_cache_file_name);
echo('<!-- CACHE-FILE: '.basename($na_layout_cache_file_name).' -->');
die();
}
include_once('../../include/init.inc');
includeNaPro('string,array,cache');
if(!empty($npf_cache) && ($npf_cache == 'yes' || $npf_cache=='update' || intval($npf_cache) > 0))
{
$sql_check4cache = $sql_world->select('SELECT user_id FROM users',0,1,2);
if(empty($sql_check4cache[0]))
{
$GLOBALS['npf_cache'] = $npf_cache = 'no';
}
}
// Switch off debugger by npf_debug = no
if($GLOBALS['npf_debug'] == 'no')
{
$GLOBALS['DC_ENV']->debug_level = '';
$_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level_temp'] = $_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'];
$_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'] = '';
}
if ( !empty($GLOBALS['DC_ENV']->debug_level) ||
$GLOBALS['DC_ENV']->debug_level == '0' ||
!empty($_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level']) ||
$_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'] == '0' )
{
$GLOBALS['NAPRO_DEBUGGER']['php_runtime_start'] = microtime();
}
$DC_ENV->page_id = md5($na_layout_cache_key);
$DC_ENV->layout_chache_id = $na_layout_cache_key;
$buffer ='';
$elements ='';
/**
* Classe um Variablen und Werte zwischen verschiedenen NPF_Funktione auszutauschen
*
* @version 1.1
* @access public
*
*/
class runtime
{
/**
* @var array $npf_functions
*/
var $npf_functions = array();
/**
* @var array $npf_functions
*/
var $npf_def_file = 'npf_functions.dat';
/**
* @var array $env
*/
var $env = array();
/**
* @var array $ptr
*/
var $ptr = array();
/**
* @var array $stack
*/
var $stack = array();
/**
* @var array $stack
*/
var $stackPosition = array();
/**
* @var string $default_inc_location
*/
var $default_inc_location = 'parse';
function runtime($filename='')
{
if (empty($filename)) $filename = $GLOBALS['DC_ENV']->cachepath.'npf_functions.dat';
$this->npf_def_file = $filename;
}
/**
* Bereitet die Parameter für Netautor-Funktionen auf und lädt
* die entsprechende Funktionsbibliothek nach
*
* @param string $name Name der Funktion
* @param array $params Array mit den 'so-far'-Parametern
* @param array $values Array mit den aktuellen Values
*
*/
function rt_comp_params($name,&$params,&$values)
{
if (!isset($this->npf_functions[$name])) return;
$def = $this->npf_functions[$name];
$seperators = array();
// Wertbehaftete Parameter testen
if(!empty($def['params']))
{
foreach($def['params'] as $param_name => $param_def)
{
// **** Flag-Parameter testen
if ($param_def['flag'])
{
if (!isset($params[$param_name]))
{
$params[$param_name] = (empty($param_def['default'])?false:true);
}
else
{
if (!is_bool($params[$param_name]))
$params[$param_name] = ( ($params[$param_name]=='0' || strtolower(trim($params[$param_name]))=='no' ) ? false: true );
}
continue;
}
// **** Value-Parameter testen
// * Seperator setzten
//if (!strpos($param_name,'.seperator') && empty($params[ $param_name.'.seperator' ])) $params[ $param_name.'.seperator' ]=',';
// * Gegen default testen
if (!isset($params[$param_name]) || empty($params[$param_name]))
{
$params[$param_name]=$param_def['default'];
continue;
}
else
{
// * MagicReplacer
switch($param_def['magic'])
{
case 2: // KEINE ERSETZUNGEN VORNEHMEN
break;
case 1: // ERSETZTEN UND ÜBRIGLASSEN
$params[$param_name]=magicReplacer($params[$param_name],$values,'%',false);
break;
case 0: // ERSETZEN UND DURCH LEERESTRING ERSETZTEN
default:
$params[$param_name]=magicReplacer($params[$param_name],$values,'%',true);
break;
}
}
/* QuoteEngine */
switch($param_def['quote'])
{
// return normal params not as array
case 1: $params[$param_name] =eval_param($params[$param_name],false,','); break;
//return normal params as $params[name][0]
case 2: $params[$param_name] =eval_param($params[$param_name],true,','); break;
// return as Uppercased - space-loss- array
case 3:
// assumption:
// if $params[$param_name] is an array, it HAS to be : ['TOPIC']=>0,['TOPIC_2']=>1 etc. /
if (is_array($params[$param_name])) $params[$param_name]=implode(',',array_flip($params[$param_name]));
$params[$param_name] =eval_param(strtoupper(trim(str_replace(' ','',$params[$param_name]))),false,',');
if (!is_array($params[$param_name])) $params[$param_name] = array($params[$param_name]);
$params[$param_name] = array_flip($params[$param_name]);
break;
}
}
}
if (!function_exists($def['function']) && empty($def['location']) )
{
include_once($def['include']);
}
elseif(!function_exists($def['function']))
{
includeNaPro($def['filename'],TRUE,$def['location']);
}
if (!empty($params['source_tag_name']) && strtolower($params['source_tag_name']) != $name)
{
$this->rt_comp_params(strtolower($params['source_tag_name']),$params,$values);
}
}
/**
* Setzt ein NA-Runtime-Variable
*
* @param string $name Name der Variable
* @param string $wert Wert der Variable
* @access public
* @return void
*/
function rt_set_env($name,$wert)
{
$this->env[$name] = $wert;
}
/**
* Setzt ein NA-Runtime-Pointer
*
* @param string $name Name des Pointers
* @param object $wert Pointer auf ein Object oder eine Variable
* @access public
* @return void
*/
function rt_set_pointer($name,&$wert)
{
$this->ptr[$name] = &$wert;
}
function rt_push_pointer($name,&$wert)
{
$this->stackPosition[$name] = intval($this->stackPosition[$name])+1;
$this->stack[$name][ $this->stackPosition[$name] ] = &$wert;
$this->rt_set_pointer( $name, $wert);
//echo "[PUSH {$name} @ {$this->stackPosition[$name]}]";
}
function &rt_pop_pointer($name)
{
//echo "[POP {$name} from {$this->stackPosition[$name]}]";
$wert = &$this->stack[$name][ $this->stackPosition[$name] ];
$this->stackPosition[$name] = $this->stackPosition[$name] -1;
if ( $this->stackPosition[$name] >0 )
{
$this->ptr[$name] = &$this->stack[$name][ $this->stackPosition[$name] ];
}
else
{
//$this->ptr[$name] = null;
}
return $wert;
}
/**
* Returns NA-Runtime-variable
*
* @param string $name Name of variable
* @return string Value or false
*/
function rt_get_env($name) {
return ( isset($this->env[$name]) ? $this->env[$name] : false );
}
function rt_pipe_values($pipe_filter,&$source)
{
if (!is_array($pipe_filter)) $pipe_filter=explode(',',$pipe_filter);
if (empty($pipe_filter)) return array();
$result = array();
reset($pipe_filter);
foreach ($pipe_filter as $pipe_index => $pipe_name)
{
$pipe_name = trim($pipe_name);
if ($pipe_name=='*') { return $source;}
if (($pos = strpos(strtolower($pipe_name),' as ')))
{
$new_pipe_name = substr($pipe_name,$pos+4);
$pipe_name = substr($pipe_name,0,$pos);
}
else
{
$new_pipe_name=$pipe_name;
}
if (!empty($pipe_name) && !empty($new_pipe_name))
{
if ($new_pipe_name[0]=='&')
{
$result[$new_pipe_name]=&$source[$pipe_name];
}
else
{
$result[$new_pipe_name]=$source[$pipe_name];
}
}
}
return $result;
}
function &getValueContext($keyword,&$values)
{
$keyword = strtoupper(trim($keyword));
switch ($keyword){
case 'GLOBAL':
case 'GLOBALS':
$target = &$GLOBALS;
break;
case 'PARENT':
if(empty($this->ptr['parent_values'])) $this->ptr['parent_values'] = array();
$target = &$this->ptr['parent_values'];
break;
case 'FEATURE':
$target = &$GLOBALS['USER']->FEATURE['value'];
break;
case 'USER':
$target = &$GLOBALS['USER'];
break;
case 'SERVER': $target = $_SERVER; break;
case 'REQUEST': $target = $_REQUEST; break;
case 'POST':
case 'GET': $target = &$GLOBALS['HTTP_'.$keyword.'_VARS'];
break;
case 'SESSION':
if (!isset($GLOBALS['NAPRO_APPLICATION_CACHE'])){
$GLOBALS['NAPRO_APPLICATION_CACHE'] = array();
session_register('NAPRO_APPLICATION_CACHE');
}
$target = &$GLOBALS['NAPRO_APPLICATION_CACHE'];
break;
case 'THIS':
case 'VALUES':
default:
$target = &$values;
break;
}
return $target;
}
/**
* Do standard functionality 'store' for functions
*
* @param $values [array] Current values
* @param $store_values [array] Values to be stored in $store_element
* @param $store_element string Target of $values
* @param $store_context string Target context
*/
function rt_store(&$values,$store_values,$params='') {
/* Store this values ...*/
$a_store_select = explode(',',(empty($params['store.select']) ? implode(',',array_keys($store_values)) :trim($params['store.select'])));
/* into this context ... */
$a_store_context= explode(',',(empty($params['store.context']) ? 'THIS' : trim(strtoupper($params['store.context']))));
/* into this values ... */
$a_store_element= explode(',',(empty($params['store.element']) ? '' : trim($params['store.element'])));
/* with this operation mode (MERGE,REPLACE)*/
$store_mode = (empty($params['store.mode'])? 'REPLACE' : strtoupper(trim($params['store.mode'])));
$last_context = $a_store_context[0];
$last_element = $a_store_element[0];
foreach ($a_store_select as $index => $store_select) {
/* Determine target-pointer*/
$store_context = trim(strtoupper((empty($a_store_context[$index]) ? $last_context : $a_store_context[$index])));
$target = &$this->getValueContext($store_context,$values);
$store_element = (empty($a_store_element[$index])?$last_element:$a_store_element[$index]);
/* Expand target-pointer if needed */
if (!empty($store_element) && ($store_element != $store_select)) {
if ($store_mode != 'MERGE' && (!isset($target[ $store_element ]) || !array($target[ $store_element ]))) $target[ $store_element ]= array();
$target = &$target[ $store_element ];
}
if ($store_mode=='MERGE') $target = &$target[];
$last_context = $store_context;
$last_lastelment = $store_element;
if ($store_mode=='MERGE' ){
$target[$store_select] = array_merge($target[$store_select],$store_values[ $store_select ]);
//$target = array_merge($target[$store_select],$store_values[ $store_select ]);
}
else {
$target[ $store_select ] = $store_values[ $store_select ];
//$target = $store_values[ $store_select ];
}
}
}
function rt_restore(&$values,$params){
$result = array();
$restore_element = $params['restore.element'];
$restore_select = (empty($params['restore.select'])?'':explode(',',$params['restore.select']));
$restore_context = (empty($params['restore.context'])?'THIS': $params['restore.context']);
$source = $this->getValueContext($restore_context,$values);
if (empty($restore_element)) {
$result = $source;
}
else {
$result = (is_object($source)? $source->$$restore_element: $source[$restore_element]);
}
if (!empty($restore_select)) {
$restore_select = array_flip($restore_select);
$temp = array();
foreach($result as $key => $value ) {
if (isset($restore_select[ $key ])) $temp[ $key ] = $value;
}
$result =$temp;
}
return $result;
}
/**
* Do standard functionality for Parameter DependOn
*
* @param $params [array] Current params
* @param $values [array] Current values
* @param $DC_ENV [array] Current DC_ENV
* @return true/false
*/
function rt_depend_on(&$params, &$values, &$DC_ENV )
{
/* For some historical reasons */
if (!empty($params['dependon']) && empty($params['dependon.element']))
{
$params['dependon.element'] = $params['dependon'];
unset($params['dependon']);
}
if (empty($params['dependon.element'])) return true;
$is_fullfilled = true;
/* Prepare parameters */
$array_element = explode(',',$params['dependon.element']);
if (empty($params['dependon.context'])){
$array_context = array();
}
else{
if (is_array($params['dependon.context'])) {
$array_context = array_flip( $params['dependon.context'] );
}
else {
$array_context = explode(',', strtoupper(trim(str_replace(' ','',$params['dependon.context']))));
}
}
$array_operator= explode(',',(empty($params['dependon.operator']) ?'':$params['dependon.operator']));
$array_value = explode(',',(empty($params['dependon.value']) ?'':$params['dependon.value']));
$code = array();
/* Loop through all elements */
foreach ($array_element as $index => $dep_element){
/* Shortcut , historical compabitility */
$erg = array();
if (preg_match('/([!=<>]{1,2})/iS',$dep_element,$erg)){
$pos = strpos($dep_element,$erg[1]);
$name = trim(substr($dep_element,0,$pos));
$wert = trim(substr($dep_element,$pos+strlen($erg[1])+1));
$code[]=' ($values["'.$name.'"][0] '.$erg[1].' '.$wert.')';
continue;
}
/* Prepare search context */
$dep_context = (empty($array_context[$index])?'THIS':trim($array_context[$index]));
$pos = false;
/* New standard way*/
if (strpos($dep_element,'[')) {
$pos = strpos($dep_element,'[');
$dep_element = '['.substr($dep_element,0,$pos).']'.substr($dep_element,$pos);
}
else {
/* all values are supposed to be within arrays, except in the user-object */
if ($dep_context != 'USER') $dep_element = "['$dep_element']";
}
switch ($dep_context){
case 'GLOBALS':
case 'GLOBAL': $dep_element='$GLOBALS'.$dep_element; break;
case 'PARENT': $dep_element='$this->ptr[\'parent_values\']'; break;
case 'FEATURE': $dep_element='$GLOBALS[\'USER\']->FEATURE[\'value\']'.$dep_element; break;
case 'USER':
/* some name-mapping to be "in line" with the npf_user-functions */
$dep_element = strtoupper($dep_element);
switch ($dep_element){
case 'USER_ID' : $dep_element='ID'; break;
case 'USER_NAME' : $dep_element='NAME'; break;
case 'USER_REMARK' : $dep_element='REMARK'; break;
case 'USER_EMAIL' : $dep_element='EMAIL'; break;
case 'USER_LOGIN' : $dep_element='LOGIN'; break;
case 'USER_LINK_TO' :
case 'LINK_TO' : $dep_element='INGROUPS'; break;
}
$dep_element='$GLOBALS[\'USER\']->'.$dep_element; break;
case 'SESSION': $dep_element='$GLOBALS[\'NAPRO_APPLICATION_CACHE\']'.$dep_element;break;
case 'THIS' :
default : $dep_element='$values'.$dep_element; break;
}
/* Prepare operator */
$dep_operator = (empty($array_operator[$index])?'NONEMPTY':trim(strtoupper($array_operator[$index])));
/* Prepare value */
if (isset($array_value[$index])) {
$dep_value = (strlen(strval($array_value[$index]))==0? '' : strval($array_value[$index]));
}
else {
$dep_value = '';
}
$dep_value = str_replace("'","\\'",$dep_value);
/**
Create a code line for this dependency check
Extend if ,[] was not given , operator was not LK and context was not USER
Map EQ/NE without comparisation value to EMPTY/NONEMPTY
*/
if ($dep_operator=='EQ' && strlen($dep_value)==0) $dep_operator='EMPTY';
if ($dep_operator=='NE' && strlen($dep_value)==0) $dep_operator='NONEMPTY';
if ( $pos ===false && (strpos($dep_operator,'EMPTY')===false ) && $dep_operator !='LK' && $dep_context!='USER') {
$dep_element = "(is_array($dep_element) ? $dep_element".'[0]'.": $dep_element )";
}
switch ($dep_operator){
case 'NONEMPTY' :$code[]= ($pos != false || $dep_context=='USER' ? "(!empty($dep_element))": "(is_array($dep_element) ? !empty($dep_element".'[0]'.") : !empty($dep_element) )" ); break;
case 'EMPTY' :$code[]= ($pos != false || $dep_context=='USER' ? "(empty($dep_element))" : "(is_array($dep_element) ? empty($dep_element".'[0]'.") : empty($dep_element) )" ); break;
case 'EQ': $code[]= "($dep_element == '$dep_value')"; break;
case 'NE': $code[]= "($dep_element != '$dep_value')"; break;
case 'LT': $code[]= "($dep_element < '$dep_value')"; break;
case 'GT': $code[]= "($dep_element > '$dep_value')"; break;
case 'LE': $code[]= "($dep_element <= '$dep_value')"; break;
case 'GE': $code[]= "($dep_element >= '$dep_value')"; break;
case 'LK': $code[]= "( is_array($dep_element) ? in_array ('$dep_value',$dep_element) : strpos($dep_element,'$dep_value')>=0 )"; break;
}
}
/* Create code for eval command */
$code = implode (' && ',$code);
if (empty($code)) return true;
$code = '$fullfilled = ('.$code.');';
$old_error_reporting = error_reporting(1);
eval($code);
// echo("\n<br> NPF- Dependency : \n$code\n (Result : ".($fullfilled? 'yes':'no').")<br>\n");
error_reporting($old_error_reporting);
return $fullfilled;
}
}
/**
* Erstellt aus einem Array eine schöne Liste mit HTML-Parametern
*
* @param array $Params Array mit den Werten ('name' => 'Wert')
* @param array $Delimiter Zeichen für Werte, zb. ' " :
* @param array $Forbidden String mit Leerzeichenseparierten Namen die
* in $Params vorkommen aber nicht beachter werden dürfen
*
* @return string String mit den Parametern
*/
function params2list( &$Params, $Delimiter="'", $Forbidden='' )
{
$result ='';
$trenner = array( ':' => array(':' ,';'),
'"' => array('="' ,'"'),
' ' => array('= ' ,'' ),
"'" => array("='" ,"'"));
list($prefix,$postfix) = (!empty($trenner[$Delimiter]) ? $trenner[$Delimiter] : $trenner["'"] );
$Forbidden = ' '.strtolower($Forbidden).' ';
foreach($Params as $name => $value)
{
if(strpos($name,'.') || strpos($Forbidden,' '.strtolower($name).' ') !== false ) continue;
if (!is_null($value))
{
if (is_bool($value))
{
if ($value == true) $result.=' '.$name;
}
else
{
$result.=' '.$name.$prefix.$value.$postfix;
}
continue;
}
$result.=' '.$name;
}
return $result;
}
/***********************************************************************
Prüft, ob ein bestimmter Parameter gesetzt ist oder nicht
Parameter
$params Parameter-Array
$name ParameterName
$Value Ist $Value leer, so wird nur auf Vorhandensein
des Parameters getestet, sonst auf diesen Wert
$DoUnset Boolean Flag, ob der Parameter gelöscht werden soll
Result
Werte des gewünschten Parameters
***********************************************************************/
function evalParam(&$params,$name,$Value='',$DoUnset=true)
{
if (!isset($params[$name])) return false;
if (empty($Value))
{
$flag = (empty($params[$name]))?true:$params[$name];
}
else
{
$flag = (strtolower(trim($params[$name])) == strtolower($Value));
}
if ($DoUnset) unset($params[$name]);
return $flag;
}
/***********************************************************************
Dient dazu um die Plus und Minus Werte zu prüfen und eventuell ein neues Feld in einem
multiplen Bereich bzw. multiplen Feld einzufügen
Parameter
$values Das Array mit den Werten
$plusminus Das Array mit möglichen Plus-Minus Anweisungen
$mode PLUS oder MINUS ?
$pre ?
Result
?
***********************************************************************/
function step_down(&$values,&$plusminus,$mode,&$pre)
{
// $pre is needet to extend areas (bereiche) it holds the values without the last key
if(is_array($plusminus))
{
reset ($plusminus);
$key = key ($plusminus);
$key = (empty($key)?'0':$key);
step_down ($values[$key],$plusminus[$key],$mode,$values);
}
else
{
if($mode=='plus')
{
reset($values);
// check if the value is a area (breich) or if it is a multiple field
if(is_array($values[key($values)]))
{
array_push($pre,'');
}
else
{
array_push($values,'');
}
}
else
{
if(is_array($values[key($values)]))
{
array_pop($pre);
}
else
{
array_pop($values);
}
}
}
}
if(empty($mlay_id))
{ // if empty layout_id
if(!empty($mdoc_id) && empty($status))
{ // ... try to read from document
$erg= $sql_world->select('SELECT mdocs.mdoc_mlay_id FROM mdocs WHERE mdoc_id='.$mdoc_id,0,1,2);
if (empty($erg[0]['mdoc_mlay_id']))
{ // .. or try to read from database
$erg= $sql_world->select('SELECT mlayouts.mlay_id,mdocs.mdoc_mlay_id FROM mdocs,mlayouts WHERE mdocs.mdoc_id='.$mdoc_id.' AND mdocs.mdoc_mn_naid = mlayouts.mlay_mn_naid AND mlay_default=1',0,1,2);
if (!empty($erg[0]['mlay_id'])) $mlay_id= intval($erg[0]['mlay_id']);
}
else
{
$mlay_id= intval($erg[0]['mdoc_mlay_id']);
}
}
if (empty($mlay_id))
{
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>/digiconcept/netautor/error</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="Description" content="Netautor Professional Application Server - Error">
<meta name="robots" content="nofollow">
<link rel="stylesheet" type="text/css" href="include/netautor.css">
</head>
<body bgcolor="White" >
<br>
<center>
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: Red; text-align: center;"><?php echo $GLOBALS['LOCALE']->dgettext('system','parse_no_layout_id'); ?></span>
</center>
</body>
</html><?php
die();
}
}
// Layout notfalls übersetzten
$file = $DC_ENV->layoutspath.'/'.$mlay_id.'.lay';
if (!file_exists($file) || !filesize($file))
{
$erg = $sql_world->select('SELECT * FROM mlayouts WHERE mlay_id='.$mlay_id,0,1,2);
if (empty($erg[0]))
{?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>/digiconcept/netautor/error</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="Description" content="Netautor Professional Application Server - Error">
<meta name="robots" content="nofollow">
<link rel="stylesheet" type="text/css" href="include/netautor.css">
</head>
<body bgcolor="White" >
<br>
<center>
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: Red; text-align: center;"><?php echo $GLOBALS['LOCALE']->dgettext('system','parse_layout_not_found',array($mlay_id)); ?></span>
</center>
</body>
</html><?php
die();
}
includeNaPro('nal_compiler');
$analyse = array();
$result = nal_create_file($erg[0],$analyse);
if ($result)
{
}
else
{?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>/digiconcept/netautor/error</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta name="Description" content="Netautor Professional Application Server - Error">
<meta name="robots" content="nofollow">
<link rel="stylesheet" type="text/css" href="include/netautor.css">
</head>
<body bgcolor="White" >
<br>
<center>
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: Red; text-align: center;"><?php echo $GLOBALS['LOCALE']->dgettext('system','parse_cannot_compile',array($mlay_id)); ?></span>
</center>
</body>
</html><?php
die();
}
}
$values = parse_post_get_array( '1','xmlval_','1' );
$original_values = $values;
// List of possible commands. Some of the are additionally stored with _x to capture the image-submits
$commands = array(
'npf_search' =>'npf_search' ,'npf_search_x' =>'npf_search',
'npf_delete' =>'npf_delete' ,'npf_delete_x' =>'npf_delete',
'npf_update' =>'npf_update' ,'npf_update_x' =>'npf_update',
'npf_update_multi' =>'npf_update_multi','npf_update_multi_x' =>'npf_update_multi',
'npf_update_exact' =>'npf_update_exact','npf_update_exact_x' =>'npf_update_exact',
'npf_create' =>'npf_create' ,'npf_create_x' =>'npf_create',
'npf_clear' =>'npf_clear' ,'npf_clear_x' =>'npf_clear',
'npf_duplicate' =>'npf_duplicate' ,'npf_duplicate_x' =>'npf_duplicate',
'status' =>'status' ,'mdoc_id' =>'mdoc_id',
'mdoc_log_id' =>'mdoc_log_id',
'mdoc_mlay_id' =>'mdoc_mlay_id' ,'mdoc_mdoc_id' =>'mdoc_mdoc_id',
'mlay_id' =>'mlay_id' ,'params' =>'params',
'npf_set_pos' =>'npf_set_pos' ,'npf_counter' =>'npf_counter',
'npf_export' =>'npf_export' ,'npf_export_x' =>'npf_export',
'npf_update_multi_x'=>'npf_update_multi',
'npf_perms_users' =>'npf_perms_users','npf_perms_groups' =>'npf_perms_groups',
'npf_perms' =>'npf_perms' ,'npf_restore' =>'npf_restore',
'npf_restore_x' =>'npf_restore' ,'npf_create_schema' =>'npf_create_schema' );
foreach($commands as $name => $wert)
{
if(!isset($$name) ) continue;
@$denied = intval($GLOBALS['USER']->get_feature_value("deny_{$wert}"));
if ($denied)
{ /* Are there any forbidden commands? */
if(isset($$name))
unset($$name);
if(isset($_REQUEST[ $name]))
unset($_REQUEST[ $name]);
if(isset($_GET[ $name]))
unset($_GET[ $name]);
if(isset($_POST[ $name]))
unset($_POST[ $name]);
if(isset($GLOBALS[$name]))
unset($GLOBALS[$name]);
continue;
}
$values[$wert] = $$name;
}
// Raufzähler berechnen
if(!empty($values['plus'])) foreach ($values['plus'] as $plus_name => $plus_wert) { step_down($values[$plus_name],$plus_wert,'plus',$values[$plus_name]); }
// Runterzähler berechnen
if(!empty($values['minus']))foreach ($values['minus'] as $minus_name => $minus_wert){ step_down($values[$minus_name],$minus_wert,'minus',$values[$minus_name]);}
// Laufzeitumgebung initialisiern
$npf_runtime = new runtime();
includeNaPro('db_fields');
// Template inkludieren
include_once($file);
// Ein altes Dokument laden?
if (!empty($values['mdoc_log_id']))
{
includeNaPro('npf_versions', false, 'npf_lib');
// Daten des alten Dokumentes laden
$_erg = array();
$_params = array('log_id' => $values['mdoc_log_id'] );
npf_doclog_read($_params,$_erg,$elements,$npf_runtime,$DC_ENV,$sql_world);
$_result = $npf_runtime->rt_get_env('npf_action_restore');
if ( !empty($_result) )
{
// Wenn das Laden erfolgreich war, dann die Daten in die aktuellen $values einspielen
$values = array_merge($values,$_erg);
$values['status'] = 'read';
}
// Nach Möglichkeit alle Spuren löschen
$GLOBALS['mdoc_restore_log_id'] = $values['mdoc_log_id'];
unset( $_params);
unset( $_erg);
unset( $_result);
unset( $values['mdoc_log_id']);
unset( $_REQUEST['mdoc_log_id']);
unset( $_POST['mdoc_log_id']);
unset( $_GET['mdoc_log_id']);
unset( $GLOBALS['mdoc_log_id']);
}
// Nötigenfalls Dokument bearbeiten
if( !empty($values['npf_delete']) ||
!empty($values['npf_update']) ||
!empty($values['npf_create']) ||
!empty($values['npf_delete_all']) ||
!empty($values['npf_update_multi']) ||
!empty($values['npf_update_exact']) ||
!empty($values['npf_search']) ||
!empty($values['npf_restore'])
)
{
includeNaPro('mdoc');
$npf_runtime->rt_set_env('mlay_id',$mlay_id);
$work_status= mdoc_work($sql_world,$values,$elements,$npf_runtime);
}
// Nötigenfalls Dokument einlesen
unset($mdoc_id);
if(intval($values['mdoc_id'])>0 && empty($values['status']) )
{
includeNaPro('mdoc');
$erg=mdoc_read( $sql_world, $values['mdoc_id']);
if (is_array($erg)) $values = array_merge($values,$erg);
$values['status']='read';
}
$to_exec = 'show_lay_'.$mlay_id;
$params ='';
error_reporting(5);
$to_exec($params,$values,$elements,$npf_runtime,$DC_ENV,$sql_world);
if(!empty($npf_cache) && ( $npf_cache=='yes' || $npf_cache=='update'))
{
if( $GLOBALS['npf_cache_server_mode'] != 'cms' ) echo '<!-- CACHED : '.date('d.m.Y H:i:s').' -->';
$contents = ob_get_contents();
ob_end_clean();
// caching ...
if( $GLOBALS['npf_cache_server_mode'] != 'cms' )
{
$fp = fopen( $na_layout_cache_file_name, 'w' );
if($fp)
{
fwrite( $fp, $contents ,strlen($contents));
fclose( $fp );
}
else
{
if(!file_exists(dirname($na_layout_cache_file_name)))
{
includeNaPro('file');
File_MkDir(dirname($na_layout_cache_file_name));
}
}
}
// ...caching
$GLOBALS['npf_cache_note']['mlay_id'][$cache_mlay_id]=$cache_mlay_id;
$GLOBALS['npf_cache_note']['mdoc_id'][$cache_doc_id ]=$cache_doc_id;
if(!empty($GLOBALS['npf_cache_note']))
{
if(!empty($GLOBALS['write_sql_conf']))
{
$object = 'sql_'.$GLOBALS['write_sql_conf']['vendor'];
includeNaPro($object);
$sql_temp = new $object($NA_SYSTEM,$GLOBALS['write_sql_conf']);
}
else
{
$sql_temp = &$sql_world;
}
// caching ...
/*
$mcache['mc_key'] = $na_layout_cache_name;
$mcache['mc_mlay_id'] = '|'.implode('|',$GLOBALS['npf_cache_note']['mlay_id'] ).'|';
$mcache['mc_mdoc_id'] = '|'.implode('|',$GLOBALS['npf_cache_note']['mdoc_id'] ).'|';
$mcache['mc_note'] = '|'.implode('|',$GLOBALS['npf_cache_note']['note'] ).'|';
$sql_temp->exec("DELETE FROM mc_cache WHERE mc_key = '$na_layout_cache_name'");
$sql_temp->bind_insert('mcache',$mcache);
*/
// da die cache einträge manchmal länger als 255 zeichen sind werden sie hier geteilt
// und paketweise ins mcache geschrieben
$mcache_rows = 1;
$temp_row = 1;
$mcache[$temp_row]['mc_mlay_id'] = '|';
foreach($GLOBALS['npf_cache_note']['mlay_id'] as $idx => $cn_mlay_id)
{
if(strlen($mcache[$temp_row]['mc_mlay_id'].'|'.$cn_mlay_id.'|') > 255)
{
$temp_row++;
if($temp_row > $mcache_rows) $mcache_rows = $temp_row;
$mcache[$temp_row]['mc_mlay_id'] = '|';
}
$mcache[$temp_row]['mc_mlay_id'] .= $cn_mlay_id.'|';
}
$temp_row = 1;
$mcache[$temp_row]['mc_mdoc_id'] = '|';
foreach($GLOBALS['npf_cache_note']['mdoc_id'] as $idx => $cn_mdoc_id)
{
if(strlen($mcache[$temp_row]['mc_mdoc_id'].'|'.$cn_mdoc_id.'|') > 255)
{
$temp_row++;
if($temp_row > $mcache_rows) $mcache_rows = $temp_row;
$mcache[$temp_row]['mc_mdoc_id'] = '|';
}
$mcache[$temp_row]['mc_mdoc_id'] .= $cn_mdoc_id.'|';
}
$temp_row = 1;
$mcache[$temp_row]['mc_note'] = '|';
foreach($GLOBALS['npf_cache_note']['note'] as $idx => $cn_note)
{
if(strlen($mcache[$temp_row]['mc_note'].'|'.$cn_note.'|') > 255)
{
$temp_row++;
if($temp_row > $mcache_rows) $mcache_rows = $temp_row;
$mcache[$temp_row]['mc_note'] = '|';
}
$mcache[$temp_row]['mc_note'] .= $cn_note.'|';
}
$sql_temp->exec("DELETE FROM mc_cache WHERE mc_key = '$na_layout_cache_name'");
for($r=1; $r<=$mcache_rows; $r++)
{
$mcache[$r]['mc_key'] = $na_layout_cache_name;
$sql_temp->bind_insert('mcache',$mcache[$r]);
}
// ... caching
}
echo ($contents);
}
if ( !empty($GLOBALS['DC_ENV']->debug_level) || $GLOBALS['DC_ENV']->debug_level == '0' ||
!empty($_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level']) ||
$_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'] == '0' )
{
$GLOBALS['NAPRO_DEBUGGER']['php_runtime_end'] = microtime();
list($m_start,$start) = explode(' ',trim($GLOBALS['NAPRO_DEBUGGER']['php_runtime_start']));
list($m_ende,$ende) = explode(' ',trim($GLOBALS['NAPRO_DEBUGGER']['php_runtime_end']));
$start = doubleval($start) + doubleval($m_start);
$ende = doubleval($ende) + doubleval($m_ende);
echo('PHP Runtime: '.($ende - $start).' sec.');
}
// Restore debugger by npf_debug = no
if($GLOBALS['npf_debug'] == 'no')
{
$_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level'] = $_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level_temp'];
unset($_SESSION['NA_PRO_CACHE']['NAPRO_DEBUGGER']['debug_level_temp']);
}
?>