Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 832 | Revision 848 | 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();
847 lars 58
    if ( isset( $_GET["killSession"] ) )
59
    {
60
        unset( $_SESSION );
61
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
62
    }
710 lars 63
    $GLOBALS["steuern"] = array();
64
    //default LandID für Deutschland
65
    $landID = 47;
66
    //Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
67
    if ( isset( $GLOBALS["INI"]["steuern"]["default_countryID"] ) )
68
    {
69
        $landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
70
    }
71
 
72
    $countryIDs = ( isset( $GLOBALS['INI']['steuern']['use_countries_tax'] ) ) ? $GLOBALS['INI']['steuern']['use_countries_tax'] : $landID;
73
 
723 lars 74
    $sql = "SELECT
75
            *
76
        FROM
77
            countries_tax
78
        WHERE
79
            country_id IN (" . $countryIDs . ")
80
    ";
81
    $rows = DB::connection( "cms" )->select( $sql );
710 lars 82
    foreach ( $rows as $r )
83
    {
711 lars 84
        $GLOBALS["steuern"][$r->country_id][$r->taxes_id] = $r->tax_percent;
85
        $GLOBALS["steuern"][$r->country_id][null] = $GLOBALS["steuern"][$r->country_id][0];
710 lars 86
    }
697 lars 87
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
88
    {
730 lars 89
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
697 lars 90
    }
700 lars 91
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 92
    {
93
        $items = $_SESSION["SHOP"]["BASKET"];
94
        unset( $_SESSION["SHOP"]["BASKET"] );
730 lars 95
        $_SESSION["SHOP"]["BASKET"] = new BasketController();
699 lars 96
        $_SESSION["SHOP"]["BASKET"]->items = $items;
697 lars 97
    }
340 lars 98
    $sql = "
99
        SELECT
100
            *
101
        FROM
102
            i18n_de
103
    ";
405 lars 104
    if ( Schema::hasTable( 'i18n_de' ) )
105
    {
106
        $langstrings = DB::select( $sql );
107
    }
108
    else
109
    {
110
        $langstrings = DB::connection( "old" )->select( $sql );
111
    }
340 lars 112
    foreach ( $langstrings as $langstring )
113
    {
355 lars 114
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 115
    }
355 lars 116
 
367 lars 117
    function parseCMSPage( $url ): array
355 lars 118
    {
375 lars 119
        $menu = "";
120
        $content = "";
365 lars 121
        $dom = new Dom;
366 lars 122
        try
123
        {
124
            $dom->loadFromUrl( $url );
375 lars 125
            $menu = $dom->getElementById( 'menu' )->innerHtml;
126
            $menu = str_replace( "/typo3", "/cms", $menu );
127
            $content = $dom->getElementById( 'content' )->innerHtml;
128
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
129
            $content = str_replace( "ce-textpic", "", $content );
366 lars 130
        }
375 lars 131
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 132
        {
133
        }
355 lars 134
        return array( "menu" => $menu, "content" => $content, );
135
    }
136
 
333 lars 137
    function getConfig()
138
    {
139
        define( '__SITE__', env( 'site' ) );
140
        define( '__SHOP__', env( 'shop' ) );
141
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 142
 
333 lars 143
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
144
        if ( !file_exists( $cfg_file ) )
145
        {
146
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
147
        }
148
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
149
        $ini = json_decode( json_encode( $xml ), true );
150
        foreach ( $ini as $key => $wert )
151
        {
152
            if ( $wert == array() )
153
            {
355 lars 154
                $ini[$key] = "";
333 lars 155
            }
156
            elseif ( is_array( $wert ) )
157
            {
158
                foreach ( $wert as $key2 => $wert2 )
159
                {
160
                    if ( $wert2 == array() )
161
                    {
355 lars 162
                        $ini[$key][$key2] = "";
333 lars 163
                    }
176 lars 164
                }
165
            }
166
        }
167
 
333 lars 168
        $v_file = __CFG_PATH__ . "/versand.xml";
169
        if ( file_exists( $v_file ) )
170
        {
171
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 172
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
173
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 174
            {
175
                if ( $wert == array() )
176
                {
355 lars 177
                    $ini["shipping"][$key] = "";
333 lars 178
                }
179
                elseif ( is_array( $wert ) )
180
                {
181
                    foreach ( $wert as $key2 => $wert2 )
182
                    {
183
                        if ( $wert2 == array() )
184
                        {
355 lars 185
                            $ini["shipping"][$key][$key2] = "";
333 lars 186
                        }
176 lars 187
                    }
188
                }
189
            }
190
        }
333 lars 191
        return $ini;
177 lars 192
    }
193
 
355 lars 194
    $GLOBALS["INI"] = getConfig();
195
    $GLOBALS["menu"] = array();
333 lars 196
    $nav = new Directory();
355 lars 197
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 198
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
199
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 200
    /* Mobile Weiche */
355 lars 201
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 202
    {
375 lars 203
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 204
        {
88 lars 205
 
355 lars 206
            $_SESSION['isMobile'] = false;
207
            $GLOBALS['isMobile'] = false;
88 lars 208
 
333 lars 209
            if (
375 lars 210
                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 211
            )
212
            {
88 lars 213
 
355 lars 214
                $_SESSION['isMobile'] = true;
215
                $GLOBALS['isMobile'] = true;
333 lars 216
            }
217
 
88 lars 218
        }
219
    }
405 lars 220
    Route::get( "/addItemToBasket", function ()
385 lars 221
    {
697 lars 222
        $_SESSION["SHOP"]["BASKET"]->addItem();
671 lars 223
        return view( 'header_wk', [
678 lars 224
            "nav"         => $GLOBALS["menu"],
225
            "ini"         => $GLOBALS["INI"],
226
            "langstrings" => $GLOBALS["langstrings"],
671 lars 227
        ] );
405 lars 228
    } );
745 lars 229
    Route::get( "/editItem/{id}/{menge}", function ()
230
    {
231
        $_SESSION["SHOP"]["BASKET"]->editItem();
765 lars 232
        return redirect( "/basket.html" );
745 lars 233
    } )->where( [ "id" => "[0-9a-f]{40}", "menge" => "[0-9]+" ] );
234
    Route::get( "/delItem/{id}", function ()
235
    {
236
        $_SESSION["SHOP"]["BASKET"]->delItem();
765 lars 237
        return redirect( "/basket.html" );
745 lars 238
    } )->where( "id", "[0-9a-f]{40}" );
766 lars 239
    Route::post( "/login", [ UserController::class, "login" ] );
809 lars 240
    Route::post( "/logout", [ UserController::class, "logout" ] );
814 lars 241
    Route::post( "/send_pw", [ UserController::class, "forgot_pw" ] );
777 lars 242
    Route::get( "/favoriten", function ()
243
    {
244
        return view( 'login_center', [
245
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
246
            "nav"               => $GLOBALS["menu"],
247
            "ini"               => $GLOBALS["INI"],
248
            "langstrings"       => $GLOBALS["langstrings"],
249
        ] );
250
    } );
776 lars 251
    Route::get( "/forgot_pw", function ()
252
    {
253
        return view( 'login_center', [
254
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
255
            "nav"               => $GLOBALS["menu"],
256
            "ini"               => $GLOBALS["INI"],
257
            "langstrings"       => $GLOBALS["langstrings"],
258
        ] );
259
    } );
765 lars 260
    Route::get( "/login", function ()
762 lars 261
    {
262
        return view( 'login_center', [
263
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
264
            "nav"               => $GLOBALS["menu"],
265
            "ini"               => $GLOBALS["INI"],
266
            "langstrings"       => $GLOBALS["langstrings"],
267
        ] );
765 lars 268
    } );
775 lars 269
    Route::get( "/register", function ()
270
    {
271
        return view( 'login_center', [
272
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
273
            "nav"               => $GLOBALS["menu"],
274
            "ini"               => $GLOBALS["INI"],
275
            "langstrings"       => $GLOBALS["langstrings"],
276
        ] );
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', [
368 lars 315
            "serviceContent"    => $content,
316
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
317
            "nav"               => $GLOBALS["menu"],
318
            "ini"               => $GLOBALS["INI"],
319
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 320
        ] );
321
    } );
377 lars 322
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 323
    {
405 lars 324
        return view( 'buy_' . $id, [
376 lars 325
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
326
            "nav"               => $GLOBALS["menu"],
327
            "ini"               => $GLOBALS["INI"],
328
            "langstrings"       => $GLOBALS["langstrings"],
686 lars 329
            "Laender"           => getRechnungsLaender(),
685 lars 330
            "defaultLandID"     => 47,
376 lars 331
        ] );
678 lars 332
    } )->where( 'id', '[1-4][ab]{0,1}' );
730 lars 333
    Route::post( "/bestellen_seite_{id}.html", [ BuyController::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
349 lars 334
    Route::get( "basket.html", function ()
335
    {
678 lars 336
 
349 lars 337
        return view( 'basket', [
368 lars 338
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
339
            "nav"               => $GLOBALS["menu"],
340
            "ini"               => $GLOBALS["INI"],
341
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 342
        ] );
343
    } );
333 lars 344
    Route::get( "/directory/{id}", function ( $id )
345
    {
346
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
347
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
348
            0,
349
            99
650 lars 350
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 351
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 352
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 353
        $subdir["subdirs"] = $dirs;
354
        $subdir["items"] = $items;
628 lars 355
        $template = 'subdir';
634 lars 356
        $artstaemmeItems = array();
631 lars 357
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 358
        {
675 lars 359
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
634 lars 360
            foreach ( $dirs as $dir )
361
            {
362
                if ( $dir->articlemaster == 1 )
363
                {
636 lars 364
                    $artstaemmeItems[$dir->id] = $dir;
673 lars 365
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 366
                }
367
            }
628 lars 368
        }
369
        return view( $template, [
368 lars 370
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
371
            "subdir"            => $subdir,
372
            "nav"               => $GLOBALS["menu"],
373
            "ini"               => $GLOBALS["INI"],
374
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 375
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 376
        ] );
377
    } );
378
    Route::get( "{item:slug}.html", function ( Item $item )
379
    {
646 lars 380
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 381
        return view( 'item', [
368 lars 382
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
383
            "item"              => $item,
384
            "nav"               => $GLOBALS["menu"],
385
            "ini"               => $GLOBALS["INI"],
386
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 387
        ] );
388
    } );
389
    Route::get( '/', function ()
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
    }