Subversion-Projekte lars-tiefland.laravel_shop

Revision

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