Subversion-Projekte lars-tiefland.laravel_shop

Revision

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