Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 710 | Revision 723 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
385 lars 3
    use App\Http\Controllers\Basket;
678 lars 4
    use App\Http\Controllers\Buy;
375 lars 5
    use Illuminate\Support\Facades\DB;
673 lars 6
    use Illuminate\Support\Facades\Schema;
365 lars 7
    use PHPHtmlParser\Dom;
333 lars 8
    use App\Models\Action;
9
    use App\Models\Item;
10
    use App\Models\Directory;
11
    use Illuminate\Support\Facades\Route;
366 lars 12
    use PHPHtmlParser\Exceptions\ChildNotFoundException;
13
    use PHPHtmlParser\Exceptions\CircularException;
14
    use PHPHtmlParser\Exceptions\CurlException;
375 lars 15
    use PHPHtmlParser\Exceptions\NotLoadedException;
366 lars 16
    use PHPHtmlParser\Exceptions\StrictException;
2 lars 17
 
333 lars 18
    /*
19
    |--------------------------------------------------------------------------
20
    | Web Routes
21
    |--------------------------------------------------------------------------
22
    |
23
    | Here is where you can register web routes for your application. These
24
    | routes are loaded by the RouteServiceProvider within a group which
25
    | contains the "web" middleware group. Now create something great!
26
    |
27
     */
2 lars 28
 
624 lars 29
    if ( php_sapi_name() == "cli" )
582 lars 30
    {
31
        return;
32
    }
704 lars 33
    session_start();
710 lars 34
    $GLOBALS["steuern"] = array();
35
    //default LandID für Deutschland
36
    $landID = 47;
37
    //Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
38
    if ( isset( $GLOBALS["INI"]["steuern"]["default_countryID"] ) )
39
    {
40
        $landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
41
    }
42
 
43
    $countryIDs = ( isset( $GLOBALS['INI']['steuern']['use_countries_tax'] ) ) ? $GLOBALS['INI']['steuern']['use_countries_tax'] : $landID;
44
 
45
    $sql = "SELECT *
46
                FROM content_management.countries_tax
47
                WHERE country_id IN (" . $countryIDs . ")
48
        ";
49
    $rows = DB::connection("cms")->select( $sql );
50
    foreach ( $rows as $r )
51
    {
711 lars 52
        $GLOBALS["steuern"][$r->country_id][$r->taxes_id] = $r->tax_percent;
53
        $GLOBALS["steuern"][$r->country_id][null] = $GLOBALS["steuern"][$r->country_id][0];
710 lars 54
    }
697 lars 55
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
56
    {
57
        $_SESSION["SHOP"]["BASKET"] = new Basket();
58
    }
700 lars 59
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 60
    {
61
        $items = $_SESSION["SHOP"]["BASKET"];
62
        unset( $_SESSION["SHOP"]["BASKET"] );
63
        $_SESSION["SHOP"]["BASKET"] = new Basket();
699 lars 64
        $_SESSION["SHOP"]["BASKET"]->items = $items;
697 lars 65
    }
340 lars 66
    $sql = "
67
        SELECT
68
            *
69
        FROM
70
            i18n_de
71
    ";
405 lars 72
    if ( Schema::hasTable( 'i18n_de' ) )
73
    {
74
        $langstrings = DB::select( $sql );
75
    }
76
    else
77
    {
78
        $langstrings = DB::connection( "old" )->select( $sql );
79
    }
340 lars 80
    foreach ( $langstrings as $langstring )
81
    {
355 lars 82
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 83
    }
355 lars 84
 
367 lars 85
    function parseCMSPage( $url ): array
355 lars 86
    {
375 lars 87
        $menu = "";
88
        $content = "";
365 lars 89
        $dom = new Dom;
366 lars 90
        try
91
        {
92
            $dom->loadFromUrl( $url );
375 lars 93
            $menu = $dom->getElementById( 'menu' )->innerHtml;
94
            $menu = str_replace( "/typo3", "/cms", $menu );
95
            $content = $dom->getElementById( 'content' )->innerHtml;
96
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
97
            $content = str_replace( "ce-textpic", "", $content );
366 lars 98
        }
375 lars 99
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 100
        {
101
        }
355 lars 102
        return array( "menu" => $menu, "content" => $content, );
103
    }
104
 
333 lars 105
    function getConfig()
106
    {
107
        define( '__SITE__', env( 'site' ) );
108
        define( '__SHOP__', env( 'shop' ) );
109
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 110
 
333 lars 111
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
112
        if ( !file_exists( $cfg_file ) )
113
        {
114
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
115
        }
116
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
117
        $ini = json_decode( json_encode( $xml ), true );
118
        foreach ( $ini as $key => $wert )
119
        {
120
            if ( $wert == array() )
121
            {
355 lars 122
                $ini[$key] = "";
333 lars 123
            }
124
            elseif ( is_array( $wert ) )
125
            {
126
                foreach ( $wert as $key2 => $wert2 )
127
                {
128
                    if ( $wert2 == array() )
129
                    {
355 lars 130
                        $ini[$key][$key2] = "";
333 lars 131
                    }
176 lars 132
                }
133
            }
134
        }
135
 
333 lars 136
        $v_file = __CFG_PATH__ . "/versand.xml";
137
        if ( file_exists( $v_file ) )
138
        {
139
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 140
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
141
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 142
            {
143
                if ( $wert == array() )
144
                {
355 lars 145
                    $ini["shipping"][$key] = "";
333 lars 146
                }
147
                elseif ( is_array( $wert ) )
148
                {
149
                    foreach ( $wert as $key2 => $wert2 )
150
                    {
151
                        if ( $wert2 == array() )
152
                        {
355 lars 153
                            $ini["shipping"][$key][$key2] = "";
333 lars 154
                        }
176 lars 155
                    }
156
                }
157
            }
158
        }
333 lars 159
        return $ini;
177 lars 160
    }
161
 
355 lars 162
    $GLOBALS["INI"] = getConfig();
163
    $GLOBALS["menu"] = array();
333 lars 164
    $nav = new Directory();
355 lars 165
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 166
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
167
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 168
    /* Mobile Weiche */
355 lars 169
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 170
    {
375 lars 171
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 172
        {
88 lars 173
 
355 lars 174
            $_SESSION['isMobile'] = false;
175
            $GLOBALS['isMobile'] = false;
88 lars 176
 
333 lars 177
            if (
375 lars 178
                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"] )
333 lars 179
            )
180
            {
88 lars 181
 
355 lars 182
                $_SESSION['isMobile'] = true;
183
                $GLOBALS['isMobile'] = true;
333 lars 184
            }
185
 
88 lars 186
        }
187
    }
405 lars 188
    Route::get( "/addItemToBasket", function ()
385 lars 189
    {
697 lars 190
        $_SESSION["SHOP"]["BASKET"]->addItem();
671 lars 191
        return view( 'header_wk', [
678 lars 192
            "nav"         => $GLOBALS["menu"],
193
            "ini"         => $GLOBALS["INI"],
194
            "langstrings" => $GLOBALS["langstrings"],
671 lars 195
        ] );
405 lars 196
    } );
658 lars 197
    Route::get( '/setSessionVars', function ()
198
    {
199
        foreach ( $_GET as $key => $value )
200
        {
201
            if ( $value == "false" )
202
            {
203
                unset( $_SESSION[$key] );
204
            }
205
            else
206
            {
207
                $_SESSION[$key] = $value;
208
            }
209
        }
210
    } );
355 lars 211
    Route::get( "/cms/{slug}", function ( $slug )
212
    {
359 lars 213
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 214
        $arr = parseCMSPage( $url );
355 lars 215
        $content = $arr["content"];
361 lars 216
        return view( 'service_center_content', [
368 lars 217
            "serviceContent"    => $content,
218
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
219
            "nav"               => $GLOBALS["menu"],
220
            "ini"               => $GLOBALS["INI"],
221
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 222
        ] );
223
    } );
377 lars 224
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 225
    {
405 lars 226
        return view( 'buy_' . $id, [
376 lars 227
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
228
            "nav"               => $GLOBALS["menu"],
229
            "ini"               => $GLOBALS["INI"],
230
            "langstrings"       => $GLOBALS["langstrings"],
686 lars 231
            "Laender"           => getRechnungsLaender(),
685 lars 232
            "defaultLandID"     => 47,
376 lars 233
        ] );
678 lars 234
    } )->where( 'id', '[1-4][ab]{0,1}' );
235
    Route::post( "/bestellen_seite_{id}.html", [ Buy::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
349 lars 236
    Route::get( "basket.html", function ()
237
    {
678 lars 238
 
349 lars 239
        return view( 'basket', [
368 lars 240
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
241
            "nav"               => $GLOBALS["menu"],
242
            "ini"               => $GLOBALS["INI"],
243
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 244
        ] );
245
    } );
333 lars 246
    Route::get( "/directory/{id}", function ( $id )
247
    {
248
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
249
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
250
            0,
251
            99
650 lars 252
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 253
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 254
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 255
        $subdir["subdirs"] = $dirs;
256
        $subdir["items"] = $items;
628 lars 257
        $template = 'subdir';
634 lars 258
        $artstaemmeItems = array();
631 lars 259
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 260
        {
675 lars 261
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
634 lars 262
            foreach ( $dirs as $dir )
263
            {
264
                if ( $dir->articlemaster == 1 )
265
                {
636 lars 266
                    $artstaemmeItems[$dir->id] = $dir;
673 lars 267
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 268
                }
269
            }
628 lars 270
        }
271
        return view( $template, [
368 lars 272
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
273
            "subdir"            => $subdir,
274
            "nav"               => $GLOBALS["menu"],
275
            "ini"               => $GLOBALS["INI"],
276
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 277
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 278
        ] );
279
    } );
280
    Route::get( "{item:slug}.html", function ( Item $item )
281
    {
646 lars 282
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 283
        return view( 'item', [
368 lars 284
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
285
            "item"              => $item,
286
            "nav"               => $GLOBALS["menu"],
287
            "ini"               => $GLOBALS["INI"],
288
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 289
        ] );
290
    } );
291
    Route::get( '/', function ()
292
    {
405 lars 293
        $date = date( "Y-m-d" );
294
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 295
        return view( 'startpage', [
368 lars 296
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
297
            "pagetype"          => "Startseite",
298
            "aktion"            => $aktion,
299
            "nav"               => $GLOBALS["menu"],
300
            "ini"               => $GLOBALS["INI"],
301
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 302
        ] );
303
    } );
685 lars 304
 
305
 
703 lars 306
    function getRechnungsLaender(): array
685 lars 307
    {
687 lars 308
        $arr = array();
693 lars 309
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM countries WHERE rank > 0 ORDER BY rank' );
687 lars 310
        foreach ( $laender as $land )
311
        {
312
            $arr[$land->id] = $land->name_de;
313
        }
314
        return $arr;
685 lars 315
    }