Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 777 | Revision 814 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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