Blame | Letzte Änderung | Log anzeigen | RSS feed
<?php/*** @package php_share* @author Lars Tiefland <tiefland@weban.de>* @copyright 2009 Webagentur Niewerth* @license propietary http://www.weban.de* @version $Rev: 853 $* @filesource**/// SVN: $Id: functions.common.php 853 2011-11-18 08:14:02Z tiefland $require_once "errorHandler.php";/**** Text_Password-Paket einbinden**/require_once "Text/Password.php";/**** Log-Paket einbinden**/require_once "Log.php";/**** Trnaslation2-Paket einbinden**/require_once "Translation2.php";/**** Config-Paket einbinden**/require_once "Config.php";/**** MDB2-Paket einbinden**/require_once "MDB2.php";/**** Smarty einbinden**/require_once "Weban_Smarty.class.php";/**** Konstante __USE_MDB2__ definieren, falls dies noch nicht passiert ist**/if ( !defined( "__USE_MDB2__" ) ){define( "__USE_MDB2__", false );}/**** Konstante USE_TRANSLATION2 definieren, falls dies noch nicht passiert ist**/if ( !defined( "USE_TRANSLATION2" ) ){define( "USE_TRANSLATION2", false );}/**** Konstante USE_SMARTY definieren, falls dies noch nicht passiert ist**/if ( !defined( "USE_SMARTY" ) ){define( "USE_SMARTY", false );}/**** Konstante USE_SMARTY_PAGINATE definieren, falls dies noch nicht passiert ist**/if ( !defined( "USE_SMARTY_PAGINATE" ) ){define( "USE_SMAETY_PAGINATE", false );}/**** Konstante USE_LOGGING definieren, falls dies noch nicht passiert ist**/if ( !defined( "USE_LOGGING" ) ){define( "USE_LOGGING", false );}/**** @package php_share* @author Lars Tiefland <tiefland@weban.de>* @copyright 2009 Webagentur Niewerth*//*** getIsoCode()** gibt den 2- oder 3-stelligen ISO-Code eines landes zurück** @param string $Land Land dessen ISO-Code zurügkgegeben werden soll* @param string $len Länge des ISO-Codes (2- oder 3-stellig)** @return string*/function getIsoCode( $Land = 'Deutschland', $len = 2 ){$sql = "select`iso-" . $len . "` as iso_codefromcontent_management.countrieswhere`name-ger` ='" . $Land . "'";if ( $q = mysql_query( $sql ) ){if ( $r = mysql_fetch_assoc( $q ) ){return $r["iso_code"];}}/*switch ( $len ){case 2:default:$codes = array( 'Deutschland' => 'DE', 'Niederlande' => 'NL','Österreich' => 'AT', 'Dänemark' => 'DK', 'Schweiz' =>'CH', 'Schweden' => 'SE', 'Finnland' => 'FI', 'Belgien' => 'BE','Luxemburg' => 'LU','' => 'DE');break;case 3:$codes = array( 'Deutschland' => 'DEU', 'Niederlande' =>'NLD', 'Österreich' => 'AUT', 'Dänemark' => 'DNK','Schweiz' => 'CHE', 'Schweden' => 'SWE', 'Finnland' =>'FIN', '' => 'DEU' );break;}*/return false;}/*** translate_laender()** setzt englische Ländernamen in deutsche um** @param mixed $land englischer Name des Landes* @return string deutscher Name des Landes*/function translate_laender( $land ){$laender = array( "Germany" => "Deutschland", "Netherlands" =>"Niederlande", "Austria" => "Österreich", "Belgium" => "Belgien","Luxembourg" => "Luxemburg", "Denmark" => "Dänemark", "Switzerland" =>"Schweiz", "France" => "Frankreich", "United Kingdom" =>"Großbritanien", "Italy" => "Italien", "Spain" => "Spanien","Portugal" => "Portugal", "Sweden" => "Schweden", "Finland" =>"Finnland", "Norway" => "Norwegen", "Ireland" => "Irland", "Greece" =>"Griechenland", "Estonia" => "Estland", "Latvia" => "Lettland","Malta" => "Malta", "Lithuania" => "Litauen", "Poland" => "Polen","Slovenia" => "Slowenien", "Slovakia (Slovak Republic)" =>"Tschechien/Slowakei", "Czech Republic" => "Tschechien/Slowakei","Turkey" => "Türkei", "Hungary" => "Ungarn", "Cyprus" => "Zypern","Canada" => "Kanada", "United States" => "USA", );$t_land = $laender[$land];if ( !$t_land ){$t_land = $land;}}/*** getShopInfo()** ermittelt die infos zum angegebenen Shop** @param integer $shop_id ID des Shops dessen Infos gelesen werden sollen* @return array Infos zum Shop*/function getShopInfo( $shop_id ){$sql = "SELECT*FROMshopsWHEREID=$shop_id";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );return $row;}/*** getBestellartInfo()** liest die angegebene Bestellart aus und gibt den Datensatz zurück* (oder fals im Fehlerfall)** @param mixed $bestellart Bestellart, die ausgelesen werden soll* @return mixed*/function getBestellartInfo( $bestellart ){$sql = "SELECT*FROMbestellartWHEREID=$bestellart";$res = mysql_query( $sql );if ( !$res ){return false;}$row = mysql_fetch_assoc( $res );return $row;}/*** serverCheck()** anhand des Servernamens wird ein Zusatzwert für die INI-Datei zurückgegeben** @param string $serverName* @return string*/function serverCheck( $serverName = 'server3' ){if ( eregi( "\.local", $_SERVER['SERVER_NAME'] ) || $serverName == $_SERVER['SERVER_NAME'] ||$serverName == $_SERVER['HOSTNAME'] ){$extra = 'local.';} elseif ( eregi( "^dev", $_SERVER["SERVER_NAME"] ) ){$extra = 'dev.';}else{$extra = '';}isWeban();return $extra;}/*** getConfig()** liest Konfigrationsdateien für den Shop ein, der folgendermaßen anzugeben ist:* 1. Konstante "__SITE__" ist auf den Kunden zu setzen (z. B. "mediaran.de")* 2. Konstante "__SHOP__" ist auf den Shop zu setzen (z. B. "mediakomeet.de")* und gibt diese zurück** bedient sich der Funktion server_check() um den genauen Dateinamen zu ermitteln** @param string $type Typ der zu lesenden Konfigurationsdatei(en))* @return array*/function getConfig( $type = "INI" ){if ( !defined( "__SHOP__" ) || !defined( "__SITE__" ) ){trigger_error( "Konstante(n) __SITE__ und / oder __SHOP__ wurde(n) NICHT definiert",E_USER_ERROR );}define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );$cfg = new Config();switch ( $type ){case "INI":$ext = "ini.php";$p_type = "IniCommented";break;case "XML":$ext = "xml";$p_type = "XML";break;default:trigger_error( "Unbekannter Typ $type!", E_USER_ERROR );break;}$cfg_file = __CFG_PATH__ . "/config.de." . serverCheck() . $ext;if ( !file_exists( $cfg_file ) ){trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " .__SITE__ . " -> " . __SHOP__ . " finden!", E_USER_ERROR );}$cfg = $cfg->parseconfig( $cfg_file, $p_type, array( "name" => "config" ) );$cfg = $cfg->toArray();$ini = ( $type == "INI" ) ? $cfg["root"] : $cfg["root"]["config"];if ( $_SERVER["SERVER_NAME"] && USE_SMARTY === false ){$cfg = new Config();$t_file = __CFG_PATH__ . "/template_" . strtolower( $ini["language"] ) .".$ext";if ( !file_exists( $t_file ) ){$t_file = __CFG_PATH__ . "/template_de.$ext";if ( !file_exists( $t_file ) ){$t_file = __CFG_PATH__ . "/template.$ext";if ( !file_exists( $t_file ) ){trigger_error( "Konnte keine Konfigurationsdatei für das Templatesystem finden!",E_USER_ERROR );}}}$cfg = $cfg->parseconfig( $t_file, $p_type, array( "name" =>"config" ) );$cfg = $cfg->toArray();$ini["TEMPLATE"] = ( $type == "INI" ) ? $cfg["root"] : $cfg["root"]["config"];}return $ini;}/*** getVersandEigenschaften()** liest Versandeigenschaften aus der Datenbank des Redaktionssystems* für die in der Konstante __SITE__ definierte Domain (z. B. mediaran.de) aus* und gibt sie zurück** Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden** @return array*/function getVersandEigenschaften( $domain = __SITE__ ){$eigenschaften = array();if ( !defined( "__SITE__" ) ){trigger_error( "Konstante __SITE__ wurde NICHT definiert!",E_USER_ERROR );}$sql = "SELECTID AS idFROMpropertiesWHEREinterner_Name LIKE 'Eigenschaft%'ANDtools=1";//if ( __USE_MDB2__ ){if ( !$GLOBALS["db_red"] instanceof MDB2_Driver_Common ){_createDBRed();}$res = $GLOBALS["db_red"]->query( $sql );if ( PEAR::isError( $res ) ){trigger_error( "SQL fehlerhaft!\n" . $res->getUserInfo() . "\n",E_USER_ERROR );}$rows = $res->fetchAll();foreach ( $rows as $row ){$sql2 = "SELECTwp.*,p.interner_nameFROMwebs_properties AS wpJOINwebs AS wONw.ID=wp.websJOINproperties AS pONp.id=wp.propertiesWHEREdomain='" . $domain . "'ANDproperties=" . $row["id"] . "ANDwp.Bezeichnung LIKE '%;logistik';";$res2 = $GLOBALS["db_red"]->query( $sql2 );if ( PEAR::isError( $res2 ) ){trigger_error( "SQL fehlerhaft!\n" . $res2->getUserInfo() ."\n", E_USER_ERROR );}$row2 = $res2->FetchRow();if ( is_array( $row2 ) ){list( $name, $nr ) = explode( "_", $row2["interner_name"] );$eigenschaften[] = $nr;}}}/*else{$conn = mysql_connect( "redaktion.weban.de", "admin","EW-ad-1055" );if ( !$conn ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n",E_USER_ERROR );}$res = mysql_select_db( "content_management" );if ( !$res ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n" .mysql_error() . "\n", E_USER_ERROR );}$res = mysql_query( $sql );if ( !$res ){trigger_error( "SQL fehlerhaft!\n" . mysql_error() . "\n$sql\n",E_USER_ERROR );}while ( $row = mysql_fetch_assoc( $res ) ){$sql2 = "SELECTwp.*,p.interner_nameFROMwebs_properties AS wpJOINwebs AS wONw.ID=wp.websJOINproperties AS pONp.id=wp.propertiesWHEREdomain='" . __SITE__ . "'ANDproperties=" . $row["id"] . "ANDwp.Bezeichnung LIKE '%;logistik';";$res2 = mysql_query( $sql2 );if ( !$res2 ){trigger_error( "SQL fehlerhaft!\n" . mysql_error() . "\n$sql2\n",E_USER_ERROR );}$row2 = mysql_fetch_assoc( $res2 );if ( is_array( $row2 ) ){list( $name, $nr ) = explode( "_", $row2["interner_name"] );$eigenschaften[] = $nr;}}mysql_close( $conn );}*/return $eigenschaften;}/*** dbConnect()** stellt eine Verbindung zur Datenbank des Online-Shops her** Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden* @param mixed $ini Hier wird der Inhalt der Ini-Datei des Shops übergeben.** @return mixed*/function dbConnect( $ini = null ){if ( is_null( $ini ) ){$ini = $GLOBALS["INI"];}if ( !is_array( $ini ) ){$ini = $_SESSION["INI"];}if ( __USE_MDB2__ ){$php5 = version_compare( phpversion(), "5.0", ">=" );$type = $ini["dbConnect"]["type"];if ( !$type ){if ( $php5 ){$type = "mysqli";}else{$type = "mysql";}}$opts = array( "persistent" => true, "portability" =>MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^MDB2_PORTABILITY_FIX_CASE );if ( $ini["uses_order_db"] ){$order_dsn = array( "phptype" => $type, "username" => $ini["dbConnect"]["order_username"],"password" => $ini["dbConnect"]["order_password"],"hostspec" => $ini["dbConnect"]["order_server"], "database" =>$ini["dbConnect"]["order_db"], "new_link" => true, );$GLOBALS["order_db"] = MDB2::connect( $order_dsn, $opts );if ( PEAR::isError( $GLOBALS["order_db"] ) ){trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n" .var_dump( $order_dsn ), E_USER_ERROR );}$GLOBALS["order_db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );}$dsn = array( "phptype" => $type, "username" => $ini["dbConnect"]["username"],"password" => $ini["dbConnect"]["password"], "hostspec" => $ini["dbConnect"]["server"],"database" => $ini["dbConnect"]["database"], "new_link" => true, );$GLOBALS["db"] = MDB2::connect( $dsn, $opts );if ( PEAR::isError( $GLOBALS["db"] ) ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n",E_USER_ERROR );}$GLOBALS["db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );if ( !isset( $GLOBALS["order_db"] ) ){$GLOBALS["order_db"] = $GLOBALS["db"];}}else{if ( $ini["uses_order_db"] ){if ( !$ini["dbConnect"]["order_username"] ){$ini["dbConnect"]["order_username"] = $ini["dbConnect"]["username"];}if ( !$ini["dbConnect"]["order_password"] ){$ini["dbConnect"]["order_password"] = $ini["dbConnect"]["password"];}if ( !$ini["dbConnect"]["order_server"] ){$ini["dbConnect"]["order_server"] = $ini["dbConnect"]["server"];}if ( !$GLOBALS["order_dbh"] = mysql_pconnect( $ini["dbConnect"]["order_server"],$ini["dbConnect"]["order_username"], $ini["dbConnect"]["order_password"] ) ){trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n",E_USER_ERROR );}else{if ( !mysql_select_db( $ini["dbConnect"]["order_db"], $GLOBALS["order_dbh"] ) ){trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n",E_USER_ERROR );}}}if ( !$GLOBALS["dbh"] = mysql_pconnect( $ini["dbConnect"]["server"],$ini["dbConnect"]["username"], $ini["dbConnect"]["password"] ) ){//return array( mysql_errno(), mysql_error() );trigger_error( "Keine Verbindung zur Datenbank möglich!\n",E_USER_ERROR );}else{if ( !mysql_select_db( $ini["dbConnect"]["database"], $GLOBALS["dbh"] ) ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n",E_USER_ERROR );}else{if ( !isset( $GLOBALS["order_dbh"] ) ){$GLOBALS["order_dbh"] = $GLOBALS["dbh"];}return true;}}}}/*** str2url()** Wandelt einen String so um, daß er als URL verwendet werden kann* @param mixed $txt Zu verareitender Text* @return string URL-konformer Text*/function str2url( $txt ){//$txt = strtolower( $txt );$txt = str_replace( "<br>", "", $txt );$txt = str_replace( "€", "EUR", $txt );$txt = str_replace( "®", "", $txt );$txt = str_replace( "–", "", $txt );$txt = preg_replace( "/[\(\)\"”´`',\/\.&\<\>#\s;\*„“]/", "-", $txt );$txt = str_replace( "²", "2", $txt );$txt = str_replace( "³", "3", $txt );$txt = str_replace( "°", "", $txt );$txt = str_replace( "*", "", $txt );$txt = str_replace( "Ä", "Ae", $txt );$txt = str_replace( "ä", "ae", $txt );$txt = str_replace( "Ö", "Oe", $txt );$txt = str_replace( "ö", "oe", $txt );$txt = str_replace( "Ü", "Ue", $txt );$txt = str_replace( "ü", "ue", $txt );$txt = str_replace( "á", "a", $txt );$txt = str_replace( "à", "a", $txt );$txt = str_replace( "â", "a", $txt );$txt = str_replace( "é", "e", $txt );$txt = str_replace( "è", "e", $txt );$txt = str_replace( "ê", "e", $txt );$txt = str_replace( "ë", "e", $txt );$txt = str_replace( "í", "i", $txt );$txt = str_replace( "ì", "i", $txt );$txt = str_replace( "î", "i", $txt );$txt = str_replace( "ï", "i", $txt );$txt = str_replace( "ó", "o", $txt );$txt = str_replace( "ò", "o", $txt );$txt = str_replace( "ô", "o", $txt );$txt = str_replace( "õ", "o", $txt );$txt = str_replace( " ", "-", $txt );$txt = str_replace( "%", "", $txt );$txt = str_replace( "ß", "ss", $txt );$txt = preg_replace( "/-{2,}/", "-", $txt );$txt = preg_replace( "/-$/", "", $txt );return $txt;}/*** getPath_new()* ermittelt den Pfad für einen Artikel oder eine Kategorie** @param mixed $root* @return array*/function getPath_new( $root ){$father = $root;while ( $father != -1 ){$sql = "SELECT*FROMdirectoryWHEREID=$fatherANDlanguage='" . $_SESSION["INI"]["language"] . "'ANDstatus=0";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );$father = $row["Father"];foreach ( array( "", "2", "3" ) as $i ){if ( $zeile["bild_url" . $i] ){$zeile["bild_url" . $i . "_beurer"] = $_SESSION['INI']['itemContainerKorrektur']["imagePath" .$i] . $zeile["bild_url" . $i];$zeile["bild_url" . $i] = "<img src=" . $_SESSION['INI']['itemContainerKorrektur']["imagePath" .$i] . $zeile["bild_url" . $i] . " >";}else{$zeile["bild_url" . $i] = "";}}$path[] = $row;}return $path;}/*** Weban_Log()** Schreibt eine Nachricht in das von createLogger() erzeugte Log-Objekt** @param mixed $message Zu protokollierende Nachricht* @param mixed $priority Priorität der Nachricht* @return void*/function Weban_Log( $message, $priority = E_USER_NOTICE ){$log_message = preg_replace( "/[\r\n]/", " ", $message );$log_message = preg_replace( "/\s{2,}/", " ", $log_message );$GLOBALS["log"]->log( $log_message, $priority );if ( IS_WEBAN ){if ( function_exists( "xdebug_enable" ) ){xdebug_enable();}trigger_error( $message, $priority );}switch ( $priority ){case E_USER_ERROR:if ( !IS_WEBAN ){header( "HTTP/1.1 500", true, 500 );}break;}}/*** createLogger()** erzeugt ein Log-Objekt** Die folgenden Konstanten müssen definiert sein:** LOG_FILE enthält das Logfile in das geschrieben werden soll* __SHOP__ definiert den Identifier für das Log** @return void*/function createLogger(){$conf = array("append" => true,"lineformat" => "%{timestamp}\t%{ident}\t%%{priority}\t%{message}\t%{file}\t%{line}\t%{function}\t%{class}",);$GLOBALS["log"] = Log::singleton( 'file', LOG_FILE, __SHOP__, $conf );}/*** directoryIsEmpty()** Die Funktion testet, ob eine Kategorie leer ist.* Dazu ruft die Funktion sich rekursiv auf, um alle Unterkategorien mit einzubeziehen,* da Kategorien tief verschachtelt sein können und eventuell erst auf der untersten* Ebene Artikel enthalten.** @param mixed $start ID der Kategorie, die getestet werden soll* @return boolen*/function directoryIsEmpty( $start ){static $total_items;$tree = getNavTree( $start, true );if ( $tree["Father"] == $_GET["navigation"] ){$total_items = 0;}$ret = getItems( $start );$total_items += $ret["total"];if ( is_array( $tree["childNodes"] ) ){foreach ( $tree["childNodes"] as $child ){$ret = directoryIsEmpty( $child["ID"] );$total_items += $ret["total"];}}$empty = ( $total_items ) ? false : true;return $empty;}/*** createTranslation2()** ertellt ein Translation2-Objekt** @param mixed $ini* @return void*/function createTranslation2( $ini = null ){if ( is_null( $ini ) ){$ini = $GLOBALS["INI"];}if ( !is_array( $ini ) ){$ini = $_SESSION["INI"];}//if ( __USE_MDB2__ ){$dsn = array( "phptype" => "mysqli", "username" => $ini["dbConnect"]["username"],"password" => $ini["dbConnect"]["password"], "hostspec" => $ini["dbConnect"]["server"],"database" => $ini["dbConnect"]["database"], "new_link" => true, );$params = array( 'langs_avail_table' => 'i18n_langs', 'lang_id_col' =>'id', 'lang_name_col' => 'name', 'lang_meta_col' => 'meta','lang_errmsg_col' => 'error_text', 'lang_encoding_col' =>'encoding', 'strings_default_table' => 'i18n_%s',//'%s' will be replaced by the lang code'string_id_col' => 'id', 'string_page_id_col' => 'page_id','string_page_id_col_length' => 255, // db field size'string_text_col' => 'string' );$GLOBALS["lang"] = Translation2::factory( "mdb2", $dsn, $params );if ( PEAR::isError( $GLOBALS["lang"] ) ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n",E_USER_ERROR );}}if ( !isset( $_SESSION["sprache"] ) ){$_SESSION["sprache"] = strtolower( $ini["language"] );}require_once "module/shop/language/index.php";}/*** createSmarty()** erstellt ein Smarty-Objekt (abgeleitet von der Klasse Weban_Smarty, damit* auch die Plugins im Unterverzeichnis "weban" zur Verfügung stehen)** @return void*/function createSmarty(){$GLOBALS["ui"] = new Weban_Smarty();if ( USE_SMARTY_PAGINATE === true ){require_once "smarty/SmartyPaginate.class.php";if ( !$_GET["start"] ){SmartyPaginate::reset();}SmartyPaginate::setURLVar( 'start' );SmartyPaginate::setLimit( 20 );SmartyPaginate::connect();if ( USE_TRANSLATION2 === true ){$prev_text = $GLOBALS["langstrings"]["pagination"]["prev"];$next_text = $GLOBALS["langstrings"]["pagination"]["next"];$last_text = $GLOBALS["langstrings"]["pagination"]["last"];$first_text = $GLOBALS["langstrings"]["pagination"]["first"];}else{$prev_text = "zurück";$next_text = "weiter";$last_text = "letzte Seite";$first_text = "erste Seite";}SmartyPaginate::setPrevText( "« $prev_text" );SmartyPaginate::setNextText( "$next_text »" );SmartyPaginate::setLastText( "$last_text »»" );SmartyPaginate::setFirstText( "«« $first_text" );$qs = $_SERVER["QUERY_STRING"];$pos = strpos( $qs, "&start=" );if ( $pos !== false ){$qs = substr( $qs, 0, $pos );}else{$pos = strpos( $qs, "start=" );if ( $pos !== false ){$qs = substr( $qs, 0, $pos );}}if ( $qs ){$extra = "?" . $qs;}SmartyPaginate::setURL( $_SERVER['PHP_SELF'] . $extra );SmartyPaginate::connect();}$GLOBALS["ui"]->setTemplatedir( array( "templates/default/" ) );$GLOBALS["ui"]->setCompileDir( "templates_c/default/" );$GLOBALS["ui"]->setCacheDir( "cache/default/" );}/*** init_shop()** initialisiert den Shop mit all seinen Parametern (z. B. Smarty und Translation2)** @param string $type Typ der zu nutzenden Konfiguration (Default: INI)* @return void*/function init_shop( $type = "INI", $domain = __SITE__ ){$GLOBALS["INI"] = getConfig( $type );$GLOBALS["Eigenschaften"] = getVersandEigenschaften( $domain );$GLOBALS["web_rechte"] = getWebRechte( $domain );$GLOBALS["gesprerte_felder"] = array();if ( isset( $GLOBALS["web_rechte"]["online_shop"]["artikel"]["artikel_klonen"] ) ){$GLOBALS["gesperrte_felder"] = explode( ";", $GLOBALS["web_rechte"]["online_shop"]["artikel"]["artikel_klonen"] );}dbConnect();if ( USE_TRANSLATION2 === true ){createTranslation2();}if ( USE_SMARTY === true ){createSmarty();}if ( USE_LOGGING === true ){define( "LOG_PATH", "/etc/shop_logs/" . __SITE__ . "/" . __SHOP__ ."/" );if ( !defined( "LOG_FILE" ) ){define( "LOG_FILE", LOG_PATH . $domain . "_error.log" );}createLogger();PEAR::setErrorHandling( PEAR_ERROR_CALLBACK, "errorHandlerGlobal" );}}function getWebRechte( $site = __SITE__ ){if ( !$GLOBALS["db_red"] instanceof MDB2_Driver_Common ){_createDBRed();}$web_rechte = array();$query = "SELECTm.interner_name m_name,t.button_name t_name,p.interner_name p_name,wp.Bezeichnung wp_nameFROMcontent_management.webs w,content_management.webs_properties wp,content_management.properties p,content_management.tools t,content_management.modules mWHEREw.domain='$site'ANDwp.webs=w.IDANDwp.properties=p.IDANDp.tools = t.IDANDt.modules = m.IDORDER BYp.Rang";/*$result = mysql_query( $query ) or die( mysql_errno() . ": " .mysql_error() . "<hr>$query<hr>" );while ( $zeile = mysql_fetch_assoc( $result ) )*/$res = $GLOBALS["db_red"]->query( $query );while ( $zeile = $res->fetchRow() ){if ( !$zeile["wp_name"] ){$zeile["wp_name"] = "";}$zeile["wp_name"] = explode( "|", $zeile["wp_name"] );if ( count( $zeile["wp_name"] ) == 1 ){$zeile["wp_name"] = $zeile["wp_name"][0];}$web_rechte[$zeile["m_name"]][$zeile["t_name"]][$zeile["p_name"]] =$zeile["wp_name"];}foreach ( array_keys( $web_rechte ) as $a ){foreach ( array_keys( $web_rechte[$a] ) as $b ){foreach ( array_keys( $web_rechte[$a][$b] ) as $c ){if ( is_array( $web_rechte[$a][$b][$c] ) ){$web_rechte[$a][$b][$c] = $web_rechte[$a][$b][$c][array_search( $GLOBALS["INI"]["language"],array_keys( $web_rechte["online_shop"]["language"] ) )];if ( $web_rechte[$a][$b][$c] == "./." ){unset( $web_rechte[$a][$b][$c] );}}}}}unset( $query );unset( $result );unset( $zeile );return $web_rechte;}function _createDBRed(){$opts = array( "persistent" => true, "portability" =>MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL );$dsn_red = array( "phptype" => "mysqli", "username" => "admin","password" => "EW-ad-1055", "hostspec" => "localhost", "database" =>"content_management", "new_link" => true, );$GLOBALS["db_red"] = MDB2::connect( $dsn_red, $opts );if ( PEAR::isError( $GLOBALS["db_red"] ) ){trigger_error( "Keine Verbindung zur Datenbank möglich!\n" . $GLOBALS["db_red"]->getUserInfo(), E_USER_ERROR );}$GLOBALS["db_red"]->setfetchMode( MDB2_FETCHMODE_ASSOC );}function getAHersteller(){$ret = array( "0" => "--- Bitte wählen ---" );$sql = "SELECT DISTINCTid,nameFROMHerstellerkatalogORDER BYname";if ( USE_MDB2 === true ){$res = $GLOBALS["db"]->Query( $sql );while ( $row = $res->FetchRow() ){$ret[$row["id"]] = $row["name"];}}else{$res = mysql_Query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$ret[$row["id"]] = $row["name"];}}return $ret;}function getAType( $hersteller ){$ret = array( "0" => "--- Bitte wählen ---" );$sql = "SELECT DISTINCTnamenserweiterungFROMartikelWHEREhersteller=$hersteller";if ( USE_MDB2 === true ){$res = $GLOBALS["db"]->Query( $sql );while ( $row = $res->FetchRow() ){$ret[urlencode( $row["namenserweiterung"] )] = $row["namenserweiterung"];}}else{$res = mysql_Query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$ret[urlencode( $row["namenserweiterung"] )] = $row["namenserweiterung"];}}return $ret;}function getAModel( $hersteller, $type ){$ret = array( "0" => "--- Bitte wählen ---" );$sql = "SELECT DISTINCTkurzbezeichnung,idFROMartikelWHEREhersteller=$herstellerANDnamenserweiterung='$type'";if ( USE_MDB2 === true ){$res = $GLOBALS["db"]->Query( $sql );while ( $row = $res->FetchRow() ){$ret[$row["id"]] = $row["kurzbezeichnung"];}}else{$res = mysql_Query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$ret[$row["id"]] = $row["kurzbezeichnung"];}}return $ret;}function IPtoCountry( $IP ){$land = "Unbekannt";$IP = sprintf( "%u", IP2Long( $IP ) );$sql = "SELECTnameFROMcontent_management.IPtoCountryWHEREIP_from <= $IPANDIP_to >= $IPLIMIT 1";if ( $IP !== false ){$result = mysql_query( $sql, $GLOBALS["dbh"] );if ( mysql_num_rows( $result ) ){$row = mysql_fetch_object( $result );$land = $row->name;}}return $land;}function getGutschein(){if ( $GLOBALS["INI"]["modules"]["gutschein"] == 1 ){$sql = "SELECT*FROMartikelWHEREFather = -5";$res = mysql_query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$buffer[] = itemKorrektur( $row );$total++;}return $buffer;}}function list_orders(){if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$table = $db . "Bestellung b";$p_table = $db . "bestellung_paketnummern bp";$sql = "SELECTb.ID,";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bezahlstatus"]["bezahlstatus"] ) ){$sql .= "b.bezahlt,";}if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "c.locale,";}$sql .= "b.erstellt_am,b.gesamtsumme_bufferFROM";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "currencies c,";}$sql .= "$tableWHERElogin=" . $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] . "";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "ANDc.id=b.currency";}$sql .= "ORDER BYerstellt_am DESC";$res = mysql_query( $sql );if ( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["tracking"] ){list( $beschreibung, $link ) = explode( ";", $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["tracking"] );}while ( $row = mysql_fetch_assoc( $res ) ){$sql_p = "SELECT*FROM$p_tableWHEREBestellung=" . $row["ID"] . "";$res_p = mysql_query( $sql_p );while ( $row_p = mysql_fetch_assoc( $res_p ) ){$row["tracking"][] = $link . $row_p["paketnummer"];$row["versanddatum"][] = $row_p["datum"];}$rows[] = $row;}return $rows;}function list_addresses(){if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$table = $db . "adresse a";$c_table = $db . "countries c";$sql = "SELECTa.*,c.id as country,c.country as land,CONCAT(s.name,' (',s.short,')') as state_nameFROM$tableJOIN$c_tableONc.id=a.landLEFT OUTER JOINstates sONs.id=a.stateWHERElogins_id=" . $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] . "";$res = mysql_query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){foreach ( $row as $feld => $wert ){$row[$feld] = utf8_encode( $wert );}$data[] = $row;}return $data;}function get_address( $id ){if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$table = $db . "adresse a";$c_table = $db . "countries c";$sql = "SELECTa.*,c.id as country,c.country as landFROM$tableJOIN$c_tableONc.id=a.landWHEREa.id=$id";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );foreach ( $row as $feld => $wert ){$row[$feld] = utf8_encode( $wert );$row["state_name"] = getStateById( $row["state"] );}return $row;}function change_pw(){if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$table = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$table .= "Logins";$sql = "UPDATE$tableSETpasswd='" . md5( $_POST["new_pw"] ) . "'WHEREID='" . mysql_real_escape_string( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) ."'";$res = mysql_query( $sql );if ( !$res ){$msg = "Passwort wurde erfolgreich geändert!";}else{$msg = "Konnte Passwort nicht ändern!<br>Bitte versuchen Sie es später noch einmal!";}return $msg;}function view_order( $id ){if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$ab_table = $db . "artikel_to_Bestellung ab";$b_table = $db . "Bestellung b";$a_table = "artikel a";$sql = "SELECTb.ID,b.erstellt_am,b.letzte_aenderung_am,";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "c.locale,";}$sql .= "b.letzte_aenderung_vonFROM$b_table,";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "currencies c,";}$sql .= "$ab_tableJOIN$a_tableONa.ID=ab.artikelWHEREb.ID = $idANDab.Bestellung=b.ID";if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) ){$sql .= "ANDc.id=b.currency";}$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );$sql = "SELECTab.*,a.kennung,a.kurzbezeichnung,a.Father,Menge * Preis_pro_Stueck AS gesamtpreisFROM$ab_tableJOIN$a_tableONa.ID=ab.artikelWHEREab.Bestellung=$id";$res = mysql_query( $sql );while ( $ab_row = mysql_fetch_assoc( $res ) ){if ( $ab_row["Father"] == -3 ){$item = getItem( $ab_row["artikel"], false, true );}else{$item = getItem( $ab_row["artikel"] );}$ab_row["Bezeichnung"] = trim( $ab_row["Bezeichnung"] );$ab_row["itemLink"] = $item["itemLink"];$ab_row["father"] = $item["Father"];$row["items"][] = $ab_row;}return $row;}function admin_debug( $var ){if ( IS_WEBAN === true ){echo "<br />Admin-Debug:";if ( php_sapi_name() == "cli" ){echo "\r\n";}else{echo "<br>";}var_dump( $var );}}/*** gen_password()** generiert ein Passwort für das Kundenlogin** @param integer $length* @param string $type* @param string $chars* @return string das generierte Passwort*/function gen_password( $length = 8, $type = "unpronounceable", $chars = "" ){$pw = Text_Password::create( $length, $type, $chars );return $pw;}function check_user_list(){$ids = "";$id_arr = array();if ( $GLOBALS["INI"]["uses_order_db"] == 1 ){$db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";}$table = $db . "Logins_to_Verteiler";$l_table = $db . "Logins";//$ret = true;if ( $GLOBALS["INI"]["modules"]["login"] == 1 && $_SESSION["SHOP"]["Login"] ){$ids = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];}else{$sql = "SELECTidFROM$l_tableWHEREE_Mail='" . $_SESSION["SHOP"]["buy"]["Persdata"]["email"] ."'";$res = mysql_query( $sql );if ( $res ){while ( $row = mysql_fetch_assoc( $res ) ){$id_arr[] = $row["id"];}$ids = implode( ",", $id_arr );}}if ( $ids ){$sql = "SELECT*FROM$tableWHERELogins IN (" . $ids . ")ANDVerteiler = " . $GLOBALS["INI"]["modules"]["mailverteiler_id"] ."";$res = mysql_query( $sql );if ( $res ){$ret = !mysql_num_rows( $res );}}else{$ret = true;}return $ret;}function getPagesCommon(){$sql = "SELECT DISTINCTpage_idFROMi18n_de";if ( __USE_MDB2__ === true ){$res = $GLOBALS["db"]->query( $sql );while ( $row = $res->FetchRow() ){$pages[] = $row["page_id"];}}else{$res = mysql_query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$pages[] = $row["page_id"];}}return $pages;}function getCurrencies( $format = "name" ){if ( $format == "array" ){$column = "name, full_name, locale";}else{$column = "id, $format";}$sql = "SELECT$columnFROMcurrencies";$res = mysql_query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){if ( $format == "array" ){$ret[] = $row;}else{$ret[$row["id"]] = $row[$format];}}return $ret;}function getLandData(){$sql = "SELECT*FROMcountriesWHEREid=" . $_SESSION["country"] . "";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );return $row;}/*** getStateById()** @param mixed $id* @return*/function getStateById( $id ){$sql = "SELECT*FROMstatesWHEREid=$id";if ( $q = mysql_query( $sql ) ){if ( $r = mysql_fetch_assoc( $q ) ){return utf8_encode( $r['name'] . " (" . $r["short"] . ")" );}}return false;}/*** getEULabel()** liest die nach dem neuen Verfahren gespeicherten EU-Energielabels aus** @param mixed $item Artikelnummer für die das Energielabel gelesen werden soll* @return*/function getEULabel( $item ){$sql = "SELECTaa.wert,a.name,a.type,a.eu_label_id,a.einheit,da.wertebereichFROMartikel_to_auspraegung aaLEFT JOINauspraegung aONa.id=aa.auspraegungLEFT JOINdirectory_to_auspraegung daONda.auspraegung=a.idWHEREartikel=$itemANDeu_label_id IS NOT NULL";$res = mysql_query( $sql );while ( $row = mysql_fetch_assoc( $res ) ){$row["wertebereich"] = unserialize( $row["wertebereich"] );$erg[] = $row;}return $erg;}function getAuspraegungInfos( $a_id ){$sql = "SELECT*FROMdirectory_to_auspraegungWHEREauspraegung=$a_id";$res = mysql_query( $sql );$row = mysql_fetch_assoc( $res );if ( $row["wertebereich"] ){$row["wertebereich"] = unserialize( $row["wertebereich"] );}return $row;}function table_exists( $table, $db ){$tables = mysql_list_tables( $db );while ( list( $temp ) = mysql_fetch_array( $tables ) ){if ( $temp == $table ){return true;}}return false;}require_once "weban/weban_utils.class.php";?>