Subversion-Projekte lars-tiefland.ci

Revision

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

<?php

/**
 * @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->fetchRow() )
            {
                $land_name = $row["country"];
                if ( !in_array( $land_name, $forbiddenLands ) )
                {
                    if ( $old === true )
                    {
                        $land = $row["weban_lcode"];
                        $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 )
                            {
                                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;
    }


?>