Subversion-Projekte lars-tiefland.ci

Revision

Revision 2011 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

// $Id: weban_helper.php 2117 2017-11-11 20:56:38Z lars $

if (!defined("CONTINUE_ON_ERROR")) {
    define("CONTINUE_ON_ERROR", false);
}
if (!defined("CRON")) {
    if (php_sapi_name() == "cli") {
        define("CRON", true);
    } else {
        define("CRON", false);
    }
}

if (!defined("EOL")) {
    if (php_sapi_name() == "cli") {
        define("EOL", "\n");
    } else {
        define("EOL", "<br>");
    }
}
$GLOBALS['ci'] = &get_instance();
$GLOBALS['order_db'] = $GLOBALS['ci']->load->database('order_db', true);
$GLOBALS['db_red'] = $GLOBALS['ci']->load->database('db_red', true);
$GLOBALS['ci']->load->model('artikel_model', 'artikel');
$domain = "faltradxxs.de";
$GLOBALS["Eigenschaften"] = getVersandEigenschaften($domain);
$GLOBALS["web_rechte"] = getWebRechte($domain);
isWeban();

$GLOBALS["zahlsysteme"] = array(
    "kreditkarte",
    "paypal",
    "sofortueberweisung",
    "frei",
    "finanzierung",
    "billsafe",
    "billsafe_hire",
    "amazon",
    "PayPalExpress",
    "Ratenzahlung",
    "PayPalPlus",
    "paymill",
    );

//Excellence Käuferschutz
$GLOBALS["tsItems"] = array(
    "TS080501_500_30_EUR" => array(
        "max" => 500,
        "preis" => 0.82353,
        ),
    "TS080501_1500_30_EUR" => array(
        "max" => 1500,
        "preis" => 2.47059,
        ),
    "TS080501_2500_30_EUR" => array(
        "max" => 2500,
        "preis" => 4.11765,
        ),
    "TS080501_5000_30_EUR" => array(
        "max" => 5000,
        "preis" => 8.23530,
        ),
    "TS080501_1000_30_EUR" => array(
        "max" => 1000,
        "preis" => 16.47060,
        ),
    "TS080501_20000_30_EUR" => array(
        "max" => 20000,
        "preis" => 31.94120,
        ),
    );

$GLOBALS["tsMethods"] = array(
    "paypal" => "PAYPAL",
    "PayPalPlus" => "PAYPAL",
    "billsafe" => "INVOICE",
    "nachnahme" => "CASH_ON_DELIVERY",
    "kreditkarte" => "CREDIT_CARD",
    "selbstabholung" => "CASH_ON_PICKUP",
    "sofortueberweisung" => "DIECT_E_BANKING",
    "vorkasse" => "PREPAYMENT",
    );
//Excellence Käuferschutz - ENDE

/**
 * @author Lars Tiefland
 * @copyright 2016
 */

function getVersandLaender()
{
    // ME: Länder raus, und die bit-Schiebeoperation ungestört durchzählen lasssen
    // LT: für Smarty umgebaut
    $forbiddenLands = array();
    if (table_exists("bestelladresse", $GLOBALS["INI"]["dbConnect"]["order_db"]) &&
        $GLOBALS["INI"]["modules"]["adresssystem"] == "neu") {
        $old = false;
        if (table_exists("shippinggroups")) {
            $cTable = "countries";
            $cField = "`name-ger";
            $coTable = "cotinents";
            $coField = "name_de";
            if (table_exists("countries")) {
                $cField = "country";
                $cTable = $GLOBALS["INI"]["dbConnect"]["database"] . "." . $cTable;
                $coTable = "";
                $coField = "continent";
            }
            $sql = "SELECT
                        c.id,
                        c.shipping,
                        " . $coField . " AS continent,
                        c." . $cField . " AS country 
                    FROM
                        " . $cTable . " c
                    JOIN
                        " . $GLOBALS["INI"]["dbConnect"]["database"] .
                ".shippinggroups sg
                    ON
                        sg.id = c.shipping
                ";
            if ($coTable) {
                $sql .= "
                        JOIN
                            " . $coTable . "
                        ON
                            co.id=c.continent
                    ";
            }
        } else {
            $old = true;
            $sql = "SELECT
                                        id,
                                        weban_lcode,
                                        `name-ger` AS country
                                FROM
                                        content_management.countries
                                WHERE
                                        weban_lcode!=''
                        ";
        }
        $res = $GLOBALS["db_red"]->query($sql);
        while ($row = $res->unbuffered_row('array')) {
            $land_name = $row["country"];
            if (!in_array($land_name, $forbiddenLands)) {
                if ($old === true) {
                    $land = $row["weban_lcode"];
                    $gewicht = 0;
                    $preis = 0;
                    if (isset($_SESSION['SHOP']['SUMME']) && $_SESSION['SHOP']['SUMME']) {
                        $preis = $_SESSION['SHOP']['SUMME'];
                    }
                    // gibt es für dieses Land Versandoptionen?
                    $sql = "SELECT 
                                ID 
                            FROM
                                artikel 
                            WHERE 
                                Lieferstatus & " . $land . " = " . $land . " 
                            AND
                                Father=-3 
                            AND 
                                status = " . $GLOBALS['INI']['shops_ID'] . "
                        ";

                    if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"])) {
                        $sql .= "
                                AND
                                (
                                    (" . $gewicht .
                            " between preis_neu1 and preis_neu2)
                                )
                                AND
                                (
                                    (" . $preis .
                            " BETWEEN preis_neu3 AND preis_neu4)
                                    OR
                                    (preis_neu3=preis_neu4)
                                )                            
                            ";
                    }
                    if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"])) {
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
                            if (Eigenschaft($nr) == true) {
                                $sql .= " AND Eigenschaft_$nr = 1 ";
                            } else {
                                $sql .= "
                                        AND
                                        (
                                            (Eigenschaft_$nr = 0)
                                            OR
                                            (Eigenschaft_$nr IS NULL)
                                        )
                                    ";
                            }
                        }
                    }


                    $q = $GLOBALS['ci']->db->query($sql);
                    if ($q) {
                        $n = $q->row_array();
                        if ($n) {
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["db_is_utf8"] !=
                                1) {
                                $land_name = utf8_encode($land_name);
                            }
                            $laender[$row["id"]] = $land_name;
                        }
                    }
                } else {
                    $continent = $row["continent"];
                    $sql = "SELECT 
                                ID 
                            FROM
                                artikel 
                            WHERE 
                                kennung =  " . $row["shipping"] . "
                            AND
                                Father=-3 
                            AND 
                                status = " . $GLOBALS['INI']['shops_ID'] . "
                        ";

                    if (count($_SESSION["SHOP"]["BASKET"])) {
                        $sql .= "
                                AND
                                (
                                    (" . $gewicht .
                            " between preis_neu1 and preis_neu2)
                                )
                                AND
                                (
                                    (" . $preis .
                            " BETWEEN preis_neu3 AND preis_neu4)
                                    OR
                                    (preis_neu3=preis_neu4)
                                )                            
                            ";
                    }
                    if (count($_SESSION["SHOP"]["BASKET"])) {
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
                            if (Eigenschaft($nr) == true) {
                                $sql .= " AND Eigenschaft_$nr = 1 ";
                            } else {
                                $sql .= "
                                        AND
                                        (
                                            (Eigenschaft_$nr = 0)
                                            OR
                                            (Eigenschaft_$nr IS NULL)
                                        )
                                    ";
                            }
                        }
                    }


                    $q = mysql_query($sql);
                    if ($q) {
                        $n = mysql_num_rows($q);
                        if ($n) {
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["order_db_is_utf8"] !=
                                1) {
                                $land_name = utf8_encode($land_name);
                                $continent = utf8_encode($continent);
                            }
                            $laender[$continent][$row["id"]] = $land_name;
                        }
                    }
                }
            }
        }
    } else {
        for ($i = 0; $i < 64; $i++) {

            $land = 1 << $i;

            $land_name = getCountryById($land);

            if ($land_name) {

                if (!in_array($land_name, $forbiddenLands)) {
                    $gewicht = getBasketGewicht();
                    $preis = getBasketSumme();

                    // gibt es für dieses Land Versandoptionen?
                    $sql = "SELECT 
                                ID 
                            FROM
                                artikel 
                            WHERE 
                                Lieferstatus & " . $land . " = " . $land . " 
                            AND
                                Father=-3 
                            AND 
                                status = " . $GLOBALS['INI']['shops_ID'] . "
                        ";

                    if (count($_SESSION["SHOP"]["BASKET"])) {
                        $sql .= "
                                AND
                                (
                                    (" . $gewicht .
                            " between preis_neu1 and preis_neu2)
                                )
                                AND
                                (
                                    (" . $preis .
                            " BETWEEN preis_neu3 AND preis_neu4)
                                    OR
                                    (preis_neu3=preis_neu4)
                                )                            
                            ";
                    }
                    if (count($_SESSION["SHOP"]["BASKET"])) {
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
                            if (Eigenschaft($nr) == true) {
                                $sql .= " AND Eigenschaft_$nr = 1 ";
                            } else {
                                $sql .= "
                                        AND
                                        (
                                            (Eigenschaft_$nr = 0)
                                            OR
                                            (Eigenschaft_$nr IS NULL)
                                        )
                                    ";
                            }
                        }
                    }


                    $q = mysql_query($sql);
                    if ($q) {
                        $n = mysql_num_rows($q);
                        if ($n) {
                            $shopsNoEncode = array(
                                "ababum.de",
                                "etoh24.de",
                                );
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && !in_array(__SHOP__, $shopsNoEncode)) {
                                $land_name = utf8_encode($land_name);
                            }
                            $laender[$land] = ($land_name);
                        }
                    }
                }
            }
        }
    }
    if (is_array($laender)) {
        $laender = array_unique($laender);
    } else {
        $laender = array();
    }

    return $laender;
}


function table_exists($table, $db = null, $c = null)
{
    $ini = $GLOBALS['INI'];
    if ($db) {
        $db = trim($db, '.');
    }
    if (!$c) {
        $conn = $GLOBALS['order_db'];
    } else {
        $conn = $c;
    }
    if (!$db || $db == $ini["dbConnect"]["database"]) {
        $db = $ini["dbConnect"]["database"];
        if (!$c) {
            $conn = $GLOBALS['ci']->db;
        } else {
            $conn = $c;
        }
    }
    $sql = "SELECT
            engine
        FROM
            information_schema.TABLES
        WHERE
            table_name='" . $table . "'
        AND
            table_schema='" . $db . "'
    ";
    $res = $conn->query($sql);
    if ($res->num_rows()) {
        return true;
    }
    return false;
}

function column_exists($table, $column, $db = null, $c = null)
{
    $ini = $GLOBALS['INI'];
    if ($db) {
        $db = trim($db, '.');
    }
    if (!$c) {
        $conn = $GLOBALS['order_db'];
    } else {
        $conn = $c;
    }
    if (!$db || $db == $ini["dbConnect"]["database"]) {
        $db = $ini["dbConnect"]["database"];
        if (!$c) {
            $conn = $GLOBALS['ci']->db;
        } else {
            $conn = $c;
        }
    }

    $t_exists = table_exists($table, $db, $conn);
    if ($t_exists) {
        $sql = "SELECT
                    data_type
                FROM
                    information_schema.COLUMNS
                WHERE
                    column_name='" . $column . "'
                AND
                    table_name='" . $table . "'
                AND
                    table_schema='" . $db . "'
            ";

        $res = $conn->query($sql);
        if ($res->num_rows()) {
            return true;
        }
        return false;
    }
    return false;
}

/**
 * getColumnInfo()
 * 
 * Holt Informationen zu einer Spalte (inklusive dem f?r diese Spalte definierten Fremdschl?ssel)
 * 
 * @param mixed $table
 * @param mixed $column
 * @param mixed $db
 * @param mixed $c
 * @return
 */
function getColumnInfo($table, $column, $db = null, $c = null)
{
    global $remoteServer_dbh, $localhost_dbh;
    if (!is_array($_SESSION["INI"])) {
        $ini = $GLOBALS["INI"];
    } else {
        $ini = $_SESSION["INI"];
    }
    if ($db) {
        $db = trim($db, '.');
    }
    if (!$c) {
        if (__USE_MDB2__ === true) {
            $conn = $GLOBALS["order_db"];
        } elseif (is_resource($GLOBALS["order_dbh"])) {
            $conn = $GLOBALS["order_dbh"];
        } elseif (is_resource($remoteServer_dbh)) {
            $conn = $remoteServer_dbh;
        }
    } else {
        $conn = $c;
    }
    if (!$db || $db == $ini["dbConnect"]["database"]) {
        $db = $ini["dbConnect"]["database"];
        if (!$c) {
            if (__USE_MDB2__ === true) {
                $conn = $GLOBALS["db"];
            } elseif (is_resource($GLOBALS["dbh"])) {
                $conn = $GLOBALS["dbh"];
            } elseif (is_resource($localhost_dbh)) {
                $conn = $localhost_dbh;
            }
        } else {
            $conn = $c;
        }
    }


    if (column_exists($table, $column, $db, $conn)) {
        //Hole Informationen zur Spalte
        $sql = "SELECT
                    *
                FROM
                    information_schema.COLUMNS
                WHERE
                    column_name='" . $column . "'
                AND
                    table_name='" . $table . "'
                AND
                    table_schema='" . $db . "'
            ";

        if (__USE_MDB2__ === true) {
            $res = $conn->query($sql);
            if ($res->numRows()) {
                $row = $res->fetchRow();
            }
        } else {
            $res = mysql_query($sql, $conn);
            if (mysql_num_rows($res)) {
                $row = mysql_fetch_assoc($res);
            }
        }
        $t = getTableInfo($table, $db, $conn);
        $row["engine"] = $t["ENGINE"];
        if ($row["engine"] == "InnoDB") {
            //Hole Informationen zu einem definierten Fremdschl?ssel
            $sql = "SELECT
                        REFERENCED_TABLE_SCHEMA,
                        REFERENCED_TABLE_NAME,
                        REFERENCED_COLUMN_NAME,
                        CONSTRAINT_NAME
                    FROM
                        information_schema.KEY_COLUMN_USAGE
                    WHERE
                        column_name='" . $column . "'
                    AND
                        table_name='" . $table . "'
                    AND
                        table_schema='" . $db . "'
                ";
            if (__USE_MDB2__ === true) {
                $res = $conn->query($sql);
                if ($res->numRows()) {
                    $row_k = $res->fetchRow();
                }
            } else {
                $res = mysql_query($sql, $conn);
                if (mysql_num_rows($res)) {
                    $row_k = mysql_fetch_assoc($res);
                }
            }
            if (is_array($row_k)) {
                $row = array_merge($row, $row_k);
            }
        }
    }
    return $row;

}

/**
 * getTableInfo()
 * 
 * Liest Informationen zu einer Tabelle
 * 
 * @param mixed $table
 * @param mixed $db
 * @param mixed $c
 * @return
 */
function getTableInfo($table, $db = null, $c = null)
{
    global $remoteServer_dbh, $localhost_dbh;
    if (!is_array($_SESSION["INI"])) {
        $ini = $GLOBALS["INI"];
    } else {
        $ini = $_SESSION["INI"];
    }
    if ($db) {
        $db = trim($db, '.');
    }
    if (!$c) {
        if (__USE_MDB2__ === true) {
            $conn = $GLOBALS["order_db"];
        } elseif (is_resource($GLOBALS["order_dbh"])) {
            $conn = $GLOBALS["order_dbh"];
        } elseif (is_resource($remoteServer_dbh)) {
            $conn = $remoteServer_dbh;
        }
    } else {
        $conn = $c;
    }
    if (!$db || $db == $ini["dbConnect"]["database"]) {
        $db = $ini["dbConnect"]["database"];
        if (!$c) {
            if (__USE_MDB2__ === true) {
                $conn = $GLOBALS["db"];
            } elseif (is_resource($GLOBALS["dbh"])) {
                $conn = $GLOBALS["dbh"];
            } elseif (is_resource($localhost_dbh)) {
                $conn = $localhost_dbh;
            }
        } else {
            $conn = $c;
        }
    }

    if (table_exists($table, $db, $conn)) {
        //Hole Informationen zur Tabelle
        $sql = "SELECT
                    *
                FROM
                    information_schema.TABLES
                WHERE
                    table_name='" . $table . "'
                AND
                    table_schema='" . $db . "'
            ";

        if (__USE_MDB2__ === true) {
            $res = $conn->query($sql);
            if ($res->numRows()) {
                $row = $res->fetchRow();
            }
        } else {
            $res = mysql_query($sql, $conn);
            if (mysql_num_rows($res)) {
                $row = mysql_fetch_assoc($res);
            }
        }
    }
    return $row;
}

/**
 * createDBField()
 * 
 * legt eine neue Spalte $name in der durch $table bestimmten Tabelle an
 * $config ist ein Array mit folgenden Schl?sseln
 *   type ==> Typ der Spalte (z. B. varchar)
 *   length ==> L?nge der Spalte (z. B. 255)
 *   extra ==> zus?tliche Optionen f?r das Feld (z. B. UNSIGNED bei Zahlen)
 *   nullable ==> kann Feld den Wert NULL enthalten?
 *   default ==> Wert, der in der Spalte gespeichert wird, wenn kein Wert
 *               ?bergeben wird
 *   index ==> Soll ein Index angelegt werden und wenn ja, welcher?
 *             Beispiele: index, unique
 *   after ==> Bestimmt hinter welcher Spalte die neue angelegt wird
 *             Wenn kein Wert angegeben wird, wird die Spalte am Ende der Tabelle
 *             angelegt  
 * 
 * @param string $name
 * @param string $table
 * @param resource $conn
 * @param array $config
 * @return void
 */
function createDBField($name, $table, $conn, $config)
{
    $typ = $config["type"];
    if ($config["length"]) {
        $typ .= "(" . $config["length"] . ")";
    }
    if ($config["extra"]) {
        $typ .= " " . $config["extra"];
    }
    if ($config["nullable"] == 1) {
        $typ .= " NULL DEFAULT NULL";
    } else {
        $default = '';
        if ($config["default"]) {
            $default = $config["default"];
        }
        $typ .= " NOT NULL DEFAULT '" . $default . "'";
    }
    if ($config["after"]) {
        $typ .= " AFTER " . $config["after"];
    }
    if ($config["index"]) {
        $typ .= ", ADD " . $config["index"] . "(" . $name . ")";
    }
    $sql = "
            ALTER TABLE
                " . $table . "
            ADD
                " . $name . " " . $typ . "
        ";
    $conn->exec($sql);
}
function Eigenschaft($NR)
{
    if (is_array($_SESSION['SHOP']['BASKET']) && count($_SESSION['SHOP']['BASKET']) >
        0) {
        foreach ($_SESSION['SHOP']['BASKET'] as $v) {
            $test = explode("_", $v["ID"]);
            if (count($test) == 1) {
                $idArray[] = $v["ID"];
            }
        }
        $query = "
                SELECT distinct
                    Eigenschaft_$NR
                FROM
                    artikel
                WHERE
                    (ID =" . implode(" or ID =", $idArray) . ")
                AND
                    Language = '" . $GLOBALS["INI"]['language'] . "'
                AND
                    Eigenschaft_$NR=1
            ";

        $result = $GLOBALS['ci']->db->query($query);
        if ($result->num_rows() > 0) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

/**
 * 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__)
{

    $sql = "SELECT
                id
            FROM
                properties
            WHERE
                interner_Name LIKE 'Eigenschaft%'
            AND
                tools=1
        ";

    $res = $GLOBALS["db_red"]->query($sql);
    $rows = $res->result_array();
    foreach ($rows as $row) {
        $sql2 = "SELECT
                    wp.*,
                    p.interner_name
                FROM
                    webs_properties AS wp
                JOIN
                    webs AS w
                ON
                    w.ID=wp.webs
                JOIN
                    properties AS p
                ON
                    p.id=wp.properties
                WHERE
                    domain='" . $domain . "'
                AND
                    properties=" . $row["id"] . "
                AND
                    wp.Bezeichnung LIKE '%;logistik';
            ";
        $res2 = $GLOBALS["db_red"]->query($sql2);
        $row2 = $res2->row_array();
        if (is_array($row2)) {
            list($name, $nr) = explode("_", $row2["interner_name"]);
            $eigenschaften[] = $nr;
        }
    }
    return $eigenschaften;
}

function getWebRechte($site = __SITE__)
{
    $web_rechte = array();
    $query = "SELECT
                m.interner_name m_name,
                t.button_name t_name,
                p.interner_name p_name,
                wp.Bezeichnung wp_name
            FROM
                content_management.webs w,
                content_management.webs_properties wp,
                content_management.properties p,
                content_management.tools t,
                content_management.modules m
            WHERE
                w.domain='$site'
            AND
                wp.webs=w.ID
            AND
                wp.properties=p.ID
            AND
                p.tools = t.ID
            AND
                t.modules = m.ID
            ORDER BY
                p.Rang
        ";
    $res = $GLOBALS["db_red"]->query($query);
    while ($zeile = $res->unbuffered_row('array')) {
        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 getZahlarten()
{
    $zahlarten[] = "- Bezahlarten -";
    $sql = "
                SELECT
                        z.*
                FROM
                        zahlungsarten z
                JOIN
                        artikel a
                ON
                        a.short_line_1=z.interner_name
                ORDER BY
                        name
        ";
    $res = $GLOBALS['ci']->db->query($sql);
    while ($row = $res->unbuffered_row('array')) {
        $ini_name = $row["interner_name"];
        if ($row["interner_name"] == "sofortueberweisung") {
            $ini_name = "ueberweisung";
        }
        if (isset($GLOBALS['INI'][$ini_name]) && $GLOBALS["INI"][$ini_name]["aktiv"] ==
            1 && ((isset($_SESSION['zahlarten'][$ini_name]) && $_SESSION["zahlarten"][$ini_name]
            !== false) || !isset($_SESSION['zahlarten'][$ini_name])) || !in_array($row["interner_name"],
            $GLOBALS["zahlsysteme"])) {
            $zahlarten[$row['interner_name']] = $row['name'];
        }
    }
    return $zahlarten;
}

function getWebanLCode($land)
{
    $sql = "SELECT
                weban_lcode
            FROM
                countries
            WHERE
                `name-ger` = '" . $land . "'
            OR
                `name-en` = '" . $land . "'
            OR
                `iso-2` = '" . $land . "'
            OR
                `iso-3` = '" . $land . "'
            OR
                `id` = '" . $land . "'
        ";
    $res = $GLOBALS["db_red"]->query($sql);
    $row = $res->row_array();
    $id = $row['weban_lcode'];
    return $id;
}

function get_versandkosten($land = null, $mode = '')
{
    if (is_null($land)) {
        $land = 47;
    }
    $lCode = getWebanLCode($land);
    $gewicht = get_gewicht();
    $preis = $_SESSION['SHOP']['SUMME'];
    $shopID = $GLOBALS["INI"]['shops_ID'];
    if (isset($_SESSION["KundengruppeShopID"]) && $_SESSION["KundengruppeShopID"] !=
        "") {
        $shopID = $_SESSION["KundengruppeShopID"];
    }
    $sql_Z_extra = "";
    if (column_exists("zahlungsarten", "express", $GLOBALS["INI"]["dbConnect"]["database"],
        $GLOBALS['ci']->db)) {
        $sql_Z_extra = "express,";
    }

    $sql = "
                SELECT
                        a.ID,
                        Father,
                        kurzbezeichnung as kurz,
                        langbezeichnung    as lang,
                        beschreibung as beschr,
                        preis1 as preis,
                        preis2 as aufschlag,
                        short_line_1 as rufname,
                        versand_abschlag,
                        1 as Versand,
                        preis_neu1,
                        preis_neu2,
                        preis_neu3,
                        preis_neu4,
                        Eigenschaft_1,
                        Eigenschaft_2,
                        Eigenschaft_3,
                        Eigenschaft_4,
                        Eigenschaft_5,
                        " . $sql_Z_extra . "
                        z.name AS z_name
                FROM
                        artikel a
                JOIN
                        zahlungsarten z
                ON
                        z.interner_name=a.short_line_1
                WHERE
                        father=-3
                AND
                        language='" . $GLOBALS['INI']['language'] . "'
                AND
                        lieferstatus & " . $lCode . "=" . $lCode . "
                AND
                (
                        (" . $gewicht . " between preis_neu1 and preis_neu2)
                )
                AND
                (
                        (" . $preis . " BETWEEN preis_neu3 AND preis_neu4)
                        OR
                        (preis_neu3=preis_neu4)
                )
        ";
    if ($mode != 'Versanduebersicht') {
        foreach ($GLOBALS["Eigenschaften"] as $nr) {
            if (Eigenschaft($nr) == true) {
                $sql .= "
                                        AND
                                                Eigenschaft_$nr = 1
                                ";
            } else {
                $sql .= "
                                        AND
                                        (
                                                (Eigenschaft_$nr = 0)
                                                OR
                                                (Eigenschaft_$nr IS NULL)
                                        )
                                ";
            }
        }
    }
    $sql .= "
                ORDER BY
                        short_line_1,
                        rang
        ";
    $res = $GLOBALS['ci']->db->query($sql);
    $items = $res->result_array();
    return $items;
}

/**
 * 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)
{
    $iso = "DE";
    $sql = "SELECT
                `iso-" . $len . "` as iso_code
            FROM
                countries
            WHERE
                `name-ger` ='" . $Land . "'
            OR
                `name-en` = '" . $Land . "'
            OR
                `id` = '" . $Land . "'
        ";
    $res = $GLOBALS["db_red"]->query($sql);
    $row = $res->row_array();
    $iso = $row["iso_code"];
    return $iso;
}

if (isset($GLOBALS['INI']['steuern']['use_countries_tax'])) {
    $GLOBALS['steuern'] = getSteuerinfo();
}

/**
 * Liefert zu den angegebenen LänderIds aus der Ini-Variable steuern->use_countries-tax die verfügbaren Steuersätze
 *      *
 * @return array $steuern mit den Steuerinfos ermittelt
 *
 */
function getSteuerinfo()
{
    $steuern = array();
    //default LandID für Deutschland
    $landID = 47;
    //Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
    if (isset($GLOBALS["INI"]["steuern"]["default_countryID"])) {
        $landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
    }

    $countryIDs = (isset($GLOBALS['INI']['steuern']['use_countries_tax'])) ? $GLOBALS['INI']['steuern']['use_countries_tax'] :
        $landID;

    $sql = "SELECT
                        *
                FROM
                        countries_tax
                WHERE
                        countries_id IN (" . $countryIDs . ")
        ";
    $res = $GLOBALS["db_red"]->query($sql);
    while ($r = $res->unbuffered_row('array')) {
        $steuern[$r['countries_id']][$r['taxes_id']] = $r['tax_percent'];
    }
    return $steuern;
}

function get_gewicht()
{
    $gewicht = 0;
    foreach ($_SESSION['SHOP']['BASKET'] as $bItem) {
        $artikel = $GLOBALS['ci']->artikel->get_artikel($bItem['ID'], true);
        $gewicht += $artikel['gewicht'];
    }
    return $gewicht;
}

/**
 *
 * definiert die Konstante IS_WEBAN
 * diese wird auf "true" gesetzt, wenn ein Zugriff über mindestens einen der 
 * folgende Wege erfolgt:
 * 
 * 1. über die öffentliche IP der Firma
 * 2. Mit dem Benutzernamen "admin"
 * 3. aus dem lokalen Netz der Firma
 *
 */

function isWeban()
{
    $webanIP = "89.245.130.99";
    if (!defined("IS_WEBAN")) {
        if ((isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == $webanIP) || (isset
            ($_SERVER["PHP_AUTH_USER"]) && $_SERVER["PHP_AUTH_USER"] == "admin") || (isset($_SERVER["REMOTE_ADDR"]) &&
            preg_match("/192\.168\.0/", $_SERVER["REMOTE_ADDR"])) || CRON === true) {
            define("IS_WEBAN", true);
        } else {
            define("IS_WEBAN", false);
        }
    }
}
function admin_debug($var, $die = false)
{
    if (IS_WEBAN === true) {
        echo EOL . "Admin-Debug:" . EOL;
        var_dump($var);
        if ($die === true) {
            die();
        }
    } else {
        //mail( "ltiefland@gmail.com", "Fehler auf " . __SHOP__, var_export( $var, true ) );
    }
}

function getBasketGewicht()
{
    $gewicht = 0;
    foreach ($_SESSION["SHOP"]["BASKET"] as $bItem) {
        $gewicht += $bItem["gewicht"];
    }
    return $gewicht;
}

function getDokDomain()
{
    global $webs, $site_full, $site;
    $prot = "http";
    if ( $webs["use_ssl"] == 1 )
    {
        $prot = "https";
    }
    $dokDomain = $prot . "://www." . $site_full;
    if ( $site == $site_full && $webs["dok_domain"] )
    {
        $dokDomain = $prot . "://" . $webs["dok_domain"];
    }
    return $dokDomain;
}
?>