Subversion-Projekte lars-tiefland.ci

Revision

Revision 1385 | Revision 1424 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

// $Id: weban_helper.php 713 2016-09-29 17:39:30Z lars $
setlocale(LC_TIME, "de_DE.UTF-8");
$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');

$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
        $domain = "faltradxxs.de";
        $GLOBALS["Eigenschaften"] = getVersandEigenschaften($domain);
        $GLOBALS["web_rechte"] = getWebRechte($domain);
        $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;
}

function select_tpl($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue = false,
        $required = false, $onChange = null)
{

        if ($required == false)
        {
                array_unshift($options, array($optionValueKey => false, $optionLabelKey =>
                                "----------- alle -----------"));
        }

        $ret = '<select name="'.$formTagName.
                '" onChange="$onChange" class="filterStatistik">';
        foreach ($options as $option)
        {
                $ret .= '<option value="'.$option[$optionValueKey].'"';
                if ($option[$optionValueKey] == $preSelectValue)
                {
                        $ret .= ' selected="selected"';
                }
                $ret .= '>'.$option[$optionLabelKey].'</option>';

        }
        $ret .= '</select>';
        return $ret;
}

function select($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue = false,
        $required = false, $onChange = null)
{
        echo select_tpl($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue,
                $required, $onChange);
}

function getShops($shop_id = null, $filter = false, $start = 0, $ende = 0, $start_v =
        0, $ende_v = 0)
{

        $buffer = array();
        $where = "";

        if (isset($_SESSION["datenquellen"]["shops"]) && count($_SESSION["datenquellen"]["shops"]) >
                0)
        {
                $where = " WHERE id IN ( ".implode(",", $_SESSION["datenquellen"]["shops"]).
                        " )";
        }

        $query = "
            SELECT  *
            FROM    shops
        ";
        $query .= (!empty($shop_id)) ? " WHERE ID = ".$shop_id : $where;

        $result = $GLOBALS["order_db"]->query($query);
        while ($zeile = $result->unbuffered_row('array'))
        {
                $buffer[] = $zeile;
        }
        if ($filter)
        {
                
                //Shops filtern
                foreach ($buffer as $id => $shop)
                {
                        /*
                        if (get_umsatz($start, $ende, $shop["ID"], 0) > 0.0 || get_umsatz($start_v, $ende_v,
                                $shop["ID"], 0) > 0.0)
                        {*/
                                $shops[] = $shop;
                        //}
                }
        }
        else
        {
                $shops = $buffer;
        }
        unset($buffer);
        return $shops;
}

function getLogistikerFilter()
{
        $logistiker[0] = "alle";

        $sql = "SELECT
                        id,
                        name
                FROM
                        logistiker
        ";
        $result = $GLOBALS["order_db"]->query($sql);

        while ($row = $result->unbuffered_row('array'))
        {
                $logistiker[$row["id"]] = $row["name"];
        }

        return $logistiker;
}
function getBestelllaender()
{
        $laender[0] = "alle";
        $laender[1] = "Ausland";

        if (isset($GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["adressbuch"]))
        {

                $countryTable = "countries co";

                if ($GLOBALS["web_rechte"]["online_shop"]["language"]["standardsprache"] == "UK")
                {
                        $coFeld = "co.`name-en` AS liefer_Land";
                }
                else
                {
                        $coFeld = "co.`name-ger` AS liefer_Land";
                }
                $query = "SELECT 
                                ".$coFeld."
                FROM
                                ".$countryTable."
        ";
                $result = $GLOBALS["db_red"]->query($query);

                while ($row = $result->unbuffered_row('array'))
                {
                        $laender[] = $row["liefer_Land"];
                }
        }
        else
        {
                $Laender = array(
                        "Deutschland",
                        "Niederlande",
                        "Österreich",
                        "Belgien",
                        "Luxemburg",
                        "Dänemark",
                        "Schweiz",
                        "Frankreich",
                        "Großbritannien",
                        "Italien",
                        "Spanien",
                        "Portugal",
                        "Schweden",
                        "Finnland",
                        "Norwegen",
                        "Irland",
                        "Griechenland",
                        "Estland",
                        "Lettland",
                        "Malta",
                        "Litauen",
                        "Polen",
                        "Slowenien",
                        "Slowakei",
                        "Tschechien",
                        "Türkei",
                        "Ungarn",
                        "Zypern",
                        "Kanada",
                        "USA",
                        "Kroatien",
                        "Bulgarien",
                        "Rumänien",
                        "Südafrika",
                        "Japan",
                        "China",
                        "Singapur",
                        "Dubai (VAE)",
                        );
                $laender = array_merge($laender, $Laender);
        }

        return $laender;
}

function getBestellarten()
{
        global $user_rechte;
        $bestellarten = false;
        if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["bestellart"]))
        {

                if (isset($_SESSION["datenquellen"]["bestellarten"]) && count($_SESSION["datenquellen"]["bestellarten"]) >
                        0)
                {
                        $where = implode(",", $_SESSION["datenquellen"]["bestellarten"]);
                        $sql = "SELECT * FROM bestellart WHERE id IN ( ".$where." )";
                }
                else
                {

                        $sql = "SELECT * FROM bestellart";
                }
                $query = $GLOBALS["order_db"]->query($sql);
                if (!$query)
                {
                        return false;
                }

                while ($db = $query->unbuffered_row('array'))
                {
                        $bestellarten[$db["id"]] = $db;
                }
        }
        return $bestellarten;
}

function getZahlungsarten()
{
        global $user_rechte;
        $zahlungsarten = false;
        if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["zahlungsart"]))
        {
                $sql = "SELECT * FROM zahlungsarten";
                $query = $GLOBALS["order_db"]->query($sql);
                if (!$query)
                {
                        return false;
                }
                while ($r = $query->unbuffered_row('array'))
                {
                        $zahlungsarten[$r['id']] = $r['name'];
                }
        }
        return $zahlungsarten;
}

function getDates()
{
        $start = strtotime(date("Y-m-01"));
        $buffer[] = array(
                "datum" => strftime("%Y-%m"),
                "datumText" => strftime("%B %G"),
                );
        for ($i = 1; $i <= 25; $i++)
        {
                $buffer[] = array(
                        "datum" => strftime("%Y-%m", strtotime("-$i months", $start)),
                        "datumText" => strftime("%B %Y", strtotime("-$i months", $start)),
                        );
        }
        if (strftime("%w") != 1)
        {
                $start = strtotime("last monday");
        }
        else
        {
                $start = time();
        }
        $buffer[] = array(
                "datum" => strftime("%Y", $start),
                "datumText" => strftime("Jahr %Y", $start),
                );
        $buffer[] = array(
                "datum" => strftime("%Y", strtotime("-1 year", $start)),
                "datumText" => strftime("Jahr %Y", strtotime("-1 year", $start)),
                );
        $buffer[] = array(
                "datum" => strftime("%Y", strtotime("-2 year", $start)),
                "datumText" => strftime("Jahr %Y", strtotime("-2 year", $start)),
                );
        $buffer[] = array(
                "datum" => strftime("%G-%m-%dW", $start),
                "datumText" => strftime("Woche %V %G", $start),
                );
        $buffer[] = array(
                "datum" => strftime("%G-%m-%dW", strtotime("-1 week", $start)),
                "datumText" => strftime("Woche %V %G", strtotime("-1 week", $start)),
                );
        for ($i = 2; $i <= 5; $i++)
        {
                $buffer[] = array(
                        "datum" => strftime("%G-%m-%dW", strtotime("-$i weeks", $start)),
                        "datumText" => strftime("Woche %V %G", strtotime("-$i weeks", $start)),
                        );
        }
        return $buffer;
}

function getWeeks($year = 2008, $maxReverse = 6)
{
        $paramYear = $year;
        $scalar = 0;
        $weekNow = date("W", time());
        $monthNow = date("n", time());
        $dateArray = array();
        $monthArray = array();

        $countedWeek = $weekNow;
        $countedMonth = $monthNow;

        for ($i = $weekNow; $i > ($weekNow - $maxReverse); $i--)
        {
                $dateArray[$scalar]['week'] = $countedWeek;
                $dateArray[$scalar]['year'] = $year;
                $dateArray[$scalar]['date_string'] = "kw,".$countedWeek.",".$year;
                $dateArray[$scalar]['human_string'] = "$countedWeek/$year";

                if ($countedWeek == 1)
                {
                        $year -= 1;
                        $countedWeek = 1;
                }
                else
                {
                        $countedWeek--;
                }

                $scalar++;
        }

        $year = $paramYear;

        for ($i = $monthNow; $i > ($monthNow - $maxReverse); $i--)
        {
                $dateArray[$scalar]['month'] = $countedMonth;
                $dateArray[$scalar]['year'] = $paramYear;
                $dateArray[$scalar]['date_string'] = "mon,".$countedMonth.",".$year;
                $dateArray[$scalar]['human_string'] = date("M", mktime(0, 0, 0, $countedMonth, 1,
                        $year))." $year";

                if ($countedMonth == 1)
                {
                        $year -= 1;
                        $countedMonth = 12;
                }
                else
                {
                        $countedMonth--;
                }

                $scalar++;
        }
        return $dateArray;
}

?>