Subversion-Projekte lars-tiefland.laravel_shop

Revision

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

<?php

    use App\Http\Controllers\Basket;
    use App\Http\Controllers\Buy;
    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!
    |
     */

    if ( php_sapi_name() == "cli" )
    {
        return;
    }
    session_start();
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
    {
        $_SESSION["SHOP"]["BASKET"] = new Basket();
    }
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
    {
        $items = $_SESSION["SHOP"]["BASKET"];
        unset( $_SESSION["SHOP"]["BASKET"] );
        $_SESSION["SHOP"]["BASKET"] = new Basket();
        $_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;
    }

    $GLOBALS["INI"] = getConfig();
    $GLOBALS["menu"] = array();
    $nav = new Directory();
    $GLOBALS["menu"] = $nav->nav_menu();
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
    /* 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;

            if (
                preg_match( "/(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", $_SERVER["HTTP_USER_AGENT"] )
            )
            {

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

        }
    }
    Route::get( "/addItemToBasket", function ()
    {
        $_SESSION["SHOP"]["BASKET"]->addItem();
        return view( 'header_wk', [
            "nav"         => $GLOBALS["menu"],
            "ini"         => $GLOBALS["INI"],
            "langstrings" => $GLOBALS["langstrings"],
        ] );
    } );
    Route::get( '/setSessionVars', function ()
    {
        foreach ( $_GET as $key => $value )
        {
            if ( $value == "false" )
            {
                unset( $_SESSION[$key] );
            }
            else
            {
                $_SESSION[$key] = $value;
            }
        }
    } );
    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,
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
        ] );
    } );
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
    {
        return view( 'buy_' . $id, [
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
            "Laender"           => getRechnungsLaender(),
            "defaultLandID"     => 47,
        ] );
    } )->where( 'id', '[1-4][ab]{0,1}' );
    Route::post( "/bestellen_seite_{id}.html", [ Buy::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
    Route::get( "basket.html", function ()
    {

        return view( 'basket', [
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
        ] );
    } );
    Route::get( "/directory/{id}", function ( $id )
    {
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
        $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' )->find( $dirId );
        $subdir["subdirs"] = $dirs;
        $subdir["items"] = $items;
        $template = 'subdir';
        $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 )
                {
                    $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, [
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "subdir"            => $subdir,
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
            "artstaemmeItems"   => $artstaemmeItems,
        ] );
    } );
    Route::get( "{item:slug}.html", function ( Item $item )
    {
        $item->load( 'price', 'medium.medium', 'manufacturer' );
        return view( 'item', [
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "item"              => $item,
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
        ] );
    } );
    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', [
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
            "pagetype"          => "Startseite",
            "aktion"            => $aktion,
            "nav"               => $GLOBALS["menu"],
            "ini"               => $GLOBALS["INI"],
            "langstrings"       => $GLOBALS["langstrings"],
        ] );
    } );


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