Subversion-Projekte lars-tiefland.laravel_shop

Revision

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

<?php

    use App\Http\Controllers\BasketController;
    use App\Http\Controllers\BuyController;
    use App\Http\Controllers\ShippingController;
    use App\Http\Controllers\UserController;
    use Illuminate\Support\Facades\DB;
    use Illuminate\Support\Facades\Schema;
    use PHPHtmlParser\Dom;
    use App\Models\Action;
    use App\Models\Item;
    use App\Models\Directory;
    use Illuminate\Support\Facades\Route;
    use PHPHtmlParser\Exceptions\ChildNotFoundException;
    use PHPHtmlParser\Exceptions\CircularException;
    use PHPHtmlParser\Exceptions\CurlException;
    use PHPHtmlParser\Exceptions\NotLoadedException;
    use PHPHtmlParser\Exceptions\StrictException;

    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
     */

    $GLOBALS["INI"] = getConfig();
    $GLOBALS["zahlsysteme"] = [
        "kreditkarte",
        "paypal",
        "sofortueberweisung",
        "frei",
        "finanzierung",
        "billsafe",
        "billsafe_hire",
        "amazon",
        "PayPalExpress",
        "Ratenzahlung",
        "PayPalPlus",
        "paymill",
        "klarna",
        "paydirekt",
        "payever",
        "billie",
        "easycredit",
        "crefopay",
        "crefopayKK",
        "PayPalCheckout",
    ];

    if ( php_sapi_name() == "cli" )
    {
        return;
    }
    session_start();
    if ( isset( $_GET["killSession"] ) )
    {
        unset( $_SESSION );
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
    }
    $GLOBALS["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
            content_management.countries_tax
        WHERE
            country_id IN (" . $countryIDs . ")
    ";
    $rows = DB::connection( "cms" )->select( $sql );
    foreach ( $rows as $r )
    {
        $GLOBALS["steuern"][$r->country_id][$r->taxes_id] = $r->tax_percent;
        $GLOBALS["steuern"][$r->country_id][null] = $GLOBALS["steuern"][$r->country_id][0];
    }
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
    {
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
    }
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
    {
        $items = $_SESSION["SHOP"]["BASKET"];
        unset( $_SESSION["SHOP"]["BASKET"] );
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
        $_SESSION["SHOP"]["BASKET"]->items = $items;
    }
    $sql = "
        SELECT
            *
        FROM
            i18n_de
    ";
    if ( Schema::hasTable( 'i18n_de' ) )
    {
        $langstrings = DB::select( $sql );
    }
    else
    {
        $langstrings = DB::connection( "old" )->select( $sql );
    }
    foreach ( $langstrings as $langstring )
    {
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
    }

    function parseCMSPage( $url ): array
    {
        $menu = "";
        $content = "";
        $dom = new Dom;
        try
        {
            $dom->loadFromUrl( $url );
            $menu = $dom->getElementById( 'menu' )->innerHtml;
            $menu = str_replace( "/typo3", "/cms", $menu );
            $content = $dom->getElementById( 'content' )->innerHtml;
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
            $content = str_replace( "ce-textpic", "", $content );
        }
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
        {
        }
        return array( "menu" => $menu, "content" => $content, );
    }

    function getConfig()
    {
        define( '__SITE__', env( 'site' ) );
        define( '__SHOP__', env( 'shop' ) );
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );

        $cfg_file = __CFG_PATH__ . "/config.de.xml";
        if ( !file_exists( $cfg_file ) )
        {
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
        }
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
        $ini = json_decode( json_encode( $xml ), true );
        foreach ( $ini as $key => $wert )
        {
            if ( $wert == array() )
            {
                $ini[$key] = "";
            }
            elseif ( is_array( $wert ) )
            {
                foreach ( $wert as $key2 => $wert2 )
                {
                    if ( $wert2 == array() )
                    {
                        $ini[$key][$key2] = "";
                    }
                }
            }
        }

        $v_file = __CFG_PATH__ . "/versand.xml";
        if ( file_exists( $v_file ) )
        {
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
            foreach ( $ini["shipping"] as $key => $wert )
            {
                if ( $wert == array() )
                {
                    $ini["shipping"][$key] = "";
                }
                elseif ( is_array( $wert ) )
                {
                    foreach ( $wert as $key2 => $wert2 )
                    {
                        if ( $wert2 == array() )
                        {
                            $ini["shipping"][$key][$key2] = "";
                        }
                    }
                }
            }
        }
        return $ini;
    }

    if ( !isset( $_SESSION["navigation"]["position"] ) )
    {
        $_SESSION["navigation"]["position"] = null;
    }
    $nav = new Directory();
    $menu = $nav->nav_menu();
    $shopPosition = $nav->shopPosition();
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
    $data = [
        "nav"               => $menu,
        "serviceCenterMenu" => $sc["menu"],
        "shopPosition"      => $shopPosition,
        "langstrings"       => $GLOBALS["langstrings"],
        "ini"               => $GLOBALS["INI"],
    ];
    \View::share( $data );

    /* Mobile Weiche */
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
    {
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
        {

            $_SESSION['isMobile'] = false;
            $GLOBALS['isMobile'] = false;

            $pattern = "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i";
            if ( preg_match( $pattern, $_SERVER["HTTP_USER_AGENT"] ) )
            {

                $_SESSION['isMobile'] = true;
                $GLOBALS['isMobile'] = true;
            }

        }
    }
    Route::get( "/addItemToBasket", function ()
    {
        $_SESSION["SHOP"]["BASKET"]->addItem();
        return view( 'header_wk' );
    } );
    Route::get( "/editItem/{id}/{menge}", function ()
    {
        $_SESSION["SHOP"]["BASKET"]->editItem();
        return redirect( "/basket.html" );
    } )->where( [ "id" => "[0-9a-f]{40}", "menge" => "[0-9]+" ] );
    Route::get( "/delItem/{id}", function ()
    {
        $_SESSION["SHOP"]["BASKET"]->delItem();
        return redirect( "/basket.html" );
    } )->where( "id", "[0-9a-f]{40}" );
    Route::post( "/login", [ UserController::class, "login" ] );
    Route::post( "/logout", [ UserController::class, "logout" ] );
    Route::post( "/send_pw", [ UserController::class, "forgot_pw" ] );
    Route::get( "/favoriten", function ()
    {
        return view( 'login_center' );
    } );
    Route::get( "/forgot_pw", function ()
    {
        return view( 'login_center' );
    } );
    Route::get( "/login", function ()
    {
        return view( 'login_center' );
    } );
    Route::get( "/register", function ()
    {
        return view( 'login_center' );
    } );
    Route::get( "/update_versand", [ ShippingController::class, "updateShipping" ] );
    Route::get( "/checkLand.php", function ()
    {
        $_SESSION['SHOP']["BASKET"]->getShippingCountries();
        $valid = 1;
        if ( !in_array( $_GET["land"], array_keys( $_SESSION["SHOP"]["BASKET"]->shippingCountries ) ) )
        {
            $valid = 0;
        }
        echo $valid;
        return $valid;
    } );
    Route::get( '/setSessionVars', function ()
    {
        foreach ( $_GET as $key => $value )
        {
            if ( $value == "false" )
            {
                unset( $_SESSION[$key] );
            }
            else
            {
                $_SESSION[$key] = $value;
            }
        }
    } );
    Route::post( "/setSessionVars", function ()
    {
        foreach ( $_POST as $key => $value )
        {
            if ( $value == "false" )
            {
                unset( $_SESSION[$key] );
            }
            else
            {
                $_SESSION[$key] = $value;
            }
        }
    } );
    Route::post( "/updateSession", function ()
    {
    } );
    Route::get( "/cms/{slug}", function ( $slug )
    {
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
        $arr = parseCMSPage( $url );
        $content = $arr["content"];
        return view( 'service_center_content', [
            "serviceContent" => $content,
        ] );
    } );
    Route::get( "/bestellen_seite_{step}.html", function ( $step )
    {
        return view( 'buy_' . $step, [
            "pagetype"      => "Bestellvorgang1",
            "Laender"       => getRechnungsLaender(),
            "defaultLandID" => 47,
        ] );
    } )->where( 'step', '[1-4][ab]{0,1}' );
    Route::post( "/bestellen_seite_{step}.html", [ BuyController::class, 'step1' ] )->where( 'step', '[1-4][ab]{0,1}' );
    Route::get( "basket.html", function ()
    {

        return view( 'basket' );
    } );
    Route::get( "{item:slug}.html", function ( Item $item )
    {
        //$item->load( 'price', 'medium.medium', 'manufacturer' );
        return view( 'item', [
            "item" => $item,
        ] );
    } );
    Route::get( "/directory/{id}", function ( $id )
    {
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
        $_SESSION["navigation"]["position"] = $dirId;
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
            0,
            99
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
        $subdir = Directory::with( 'medium.medium', 'template.template', 'manufacturer' )->find( $dirId );
        $subdir["subdirs"] = $dirs->reject( function ( $value )
        {
            return $value->articlemaster == 1;
        } );
        $subdir["items"] = $items;
        $template = 'subdir';
        if ( $subdir->articlemaster == 1 )
        {
            $template = 'artstamm';
        }
        $artstaemmeItems = array();
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
        {
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
        }
        foreach ( $dirs as $dir )
        {
            if ( $dir->articlemaster == 1 )
            {
                $preise = array();
                $items = Item::with( 'price' )->where( "directory_id", $dir->id )->whereIn( "status", [ 0, 2 ] )->get();
                $dir->anz = count( $items );
                foreach ( $items as $item )
                {
                    $preise[] = $item->price[0]->preis;
                }
                if ( $preise )
                {
                    $startPrice = min( $preise );
                    $dir->mehrerePreise = count( array_unique( $preise ) ) > 1;
                    $dir->startpreis_tpl = $startPrice;
                }
                $subdir["items"] = $dirs->filter( function ( $value )
                {
                    return $value->articlemaster == 1 && $value->anz > 0;
                } );
                /*$artstaemmeItems[$dir->id] = $dir;
                $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();*/
            }
        }
        return view( $template, [
            "subdir"          => $subdir,
            "artstaemmeItems" => $artstaemmeItems,
        ] );
    } );
    Route::get( '/', function ()
    {
        $date = date( "Y-m-d" );
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
        return view( 'startpage', [
            "pagetype" => "Startseite",
            "aktion"   => $aktion,
        ] );
    } );


    function getRechnungsLaender(): array
    {
        $arr = array();
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM content_management.countries WHERE `rank` > 0 ORDER BY `rank`' );
        foreach ( $laender as $land )
        {
            $arr[$land->id] = $land->name_de;
        }
        return $arr;
    }

    //require_once __DIR__.'/admin.php';