Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1576 | Revision 1578 | 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
 
333 lars 196
    $nav = new Directory();
848 lars 197
    $menu = $nav->nav_menu();
368 lars 198
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
852 lars 199
    $data = [
200
        "nav"               => $menu,
201
        "serviceCenterMenu" => $sc["menu"],
202
        "langstrings"       => $GLOBALS["langstrings"],
203
        "ini"               => $GLOBALS["INI"],
204
    ];
205
    \View::share( $data );
848 lars 206
 
333 lars 207
    /* Mobile Weiche */
355 lars 208
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 209
    {
375 lars 210
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 211
        {
88 lars 212
 
355 lars 213
            $_SESSION['isMobile'] = false;
214
            $GLOBALS['isMobile'] = false;
88 lars 215
 
853 lars 216
            $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";
217
            if ( preg_match( $pattern, $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 218
            {
88 lars 219
 
355 lars 220
                $_SESSION['isMobile'] = true;
221
                $GLOBALS['isMobile'] = true;
333 lars 222
            }
223
 
88 lars 224
        }
225
    }
405 lars 226
    Route::get( "/addItemToBasket", function ()
385 lars 227
    {
697 lars 228
        $_SESSION["SHOP"]["BASKET"]->addItem();
848 lars 229
        return view( 'header_wk' );
405 lars 230
    } );
745 lars 231
    Route::get( "/editItem/{id}/{menge}", function ()
232
    {
233
        $_SESSION["SHOP"]["BASKET"]->editItem();
765 lars 234
        return redirect( "/basket.html" );
745 lars 235
    } )->where( [ "id" => "[0-9a-f]{40}", "menge" => "[0-9]+" ] );
236
    Route::get( "/delItem/{id}", function ()
237
    {
238
        $_SESSION["SHOP"]["BASKET"]->delItem();
765 lars 239
        return redirect( "/basket.html" );
745 lars 240
    } )->where( "id", "[0-9a-f]{40}" );
766 lars 241
    Route::post( "/login", [ UserController::class, "login" ] );
809 lars 242
    Route::post( "/logout", [ UserController::class, "logout" ] );
814 lars 243
    Route::post( "/send_pw", [ UserController::class, "forgot_pw" ] );
777 lars 244
    Route::get( "/favoriten", function ()
245
    {
848 lars 246
        return view( 'login_center' );
777 lars 247
    } );
776 lars 248
    Route::get( "/forgot_pw", function ()
249
    {
848 lars 250
        return view( 'login_center' );
776 lars 251
    } );
765 lars 252
    Route::get( "/login", function ()
762 lars 253
    {
848 lars 254
        return view( 'login_center' );
765 lars 255
    } );
775 lars 256
    Route::get( "/register", function ()
257
    {
848 lars 258
        return view( 'login_center' );
775 lars 259
    } );
890 lars 260
    Route::get( "/update_versand", [ ShippingController::class, "updateShipping" ] );
891 lars 261
    Route::get( "/checkLand.php", function ()
890 lars 262
    {
263
        $_SESSION['SHOP']["BASKET"]->getShippingCountries();
264
        $valid = 1;
893 lars 265
        if ( !in_array( $_GET["land"], array_keys( $_SESSION["SHOP"]["BASKET"]->shippingCountries ) ) )
890 lars 266
        {
267
            $valid = 0;
268
        }
899 lars 269
        echo $valid;
890 lars 270
        return $valid;
271
    } );
658 lars 272
    Route::get( '/setSessionVars', function ()
273
    {
274
        foreach ( $_GET as $key => $value )
275
        {
276
            if ( $value == "false" )
277
            {
278
                unset( $_SESSION[$key] );
279
            }
280
            else
281
            {
282
                $_SESSION[$key] = $value;
283
            }
284
        }
285
    } );
765 lars 286
    Route::post( "/setSessionVars", function ()
287
    {
762 lars 288
        foreach ( $_POST as $key => $value )
289
        {
290
            if ( $value == "false" )
291
            {
292
                unset( $_SESSION[$key] );
293
            }
294
            else
295
            {
296
                $_SESSION[$key] = $value;
297
            }
298
        }
765 lars 299
    } );
300
    Route::post( "/updateSession", function ()
756 lars 301
    {
302
    } );
355 lars 303
    Route::get( "/cms/{slug}", function ( $slug )
304
    {
359 lars 305
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 306
        $arr = parseCMSPage( $url );
355 lars 307
        $content = $arr["content"];
361 lars 308
        return view( 'service_center_content', [
848 lars 309
            "serviceContent" => $content,
355 lars 310
        ] );
311
    } );
925 lars 312
    Route::get( "/bestellen_seite_{step}.html", function ( $step )
376 lars 313
    {
925 lars 314
        return view( 'buy_' . $step, [
924 lars 315
            "pagetype"      => "Bestellvorgang1",
848 lars 316
            "Laender"       => getRechnungsLaender(),
317
            "defaultLandID" => 47,
376 lars 318
        ] );
925 lars 319
    } )->where( 'step', '[1-4][ab]{0,1}' );
320
    Route::post( "/bestellen_seite_{step}.html", [ BuyController::class, 'step1' ] )->where( 'step', '[1-4][ab]{0,1}' );
349 lars 321
    Route::get( "basket.html", function ()
322
    {
678 lars 323
 
848 lars 324
        return view( 'basket' );
349 lars 325
    } );
1564 lars 326
    Route::get( "{item:slug}.html", function ( Item $item )
333 lars 327
    {
1564 lars 328
        //$item->load( 'price', 'medium.medium', 'manufacturer' );
329
        return view( 'item', [
330
            "item" => $item,
331
        ] );
332
    } );
1568 lars 333
    Route::get( "/directory/{id}", function ( $id )
1564 lars 334
    {
333 lars 335
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
1476 lars 336
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
337
            0,
338
            99
339
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 340
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
1571 lars 341
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
1572 lars 342
        $subdir["subdirs"] = $dirs->reject( function ( $value, $key )
343
        {
1573 lars 344
            return $value->articlemaster == 1;
1572 lars 345
        } );
355 lars 346
        $subdir["items"] = $items;
628 lars 347
        $template = 'subdir';
634 lars 348
        $artstaemmeItems = array();
631 lars 349
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 350
        {
675 lars 351
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
1569 lars 352
        }
353
        foreach ( $dirs as $dir )
354
        {
355
            if ( $dir->articlemaster == 1 )
634 lars 356
            {
1569 lars 357
                $artstaemmeItems[$dir->id] = $dir;
1576 lars 358
                $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 359
            }
628 lars 360
        }
361
        return view( $template, [
848 lars 362
            "subdir"          => $subdir,
363
            "artstaemmeItems" => $artstaemmeItems,
333 lars 364
        ] );
365
    } );
366
    Route::get( '/', function ()
367
    {
405 lars 368
        $date = date( "Y-m-d" );
369
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 370
        return view( 'startpage', [
848 lars 371
            "pagetype" => "Startseite",
372
            "aktion"   => $aktion,
333 lars 373
        ] );
374
    } );
685 lars 375
 
376
 
703 lars 377
    function getRechnungsLaender(): array
685 lars 378
    {
687 lars 379
        $arr = array();
693 lars 380
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM countries WHERE rank > 0 ORDER BY rank' );
687 lars 381
        foreach ( $laender as $land )
382
        {
383
            $arr[$land->id] = $land->name_de;
384
        }
385
        return $arr;
730 lars 386
    }
964 lars 387
 
1144 lars 388
    //require_once __DIR__.'/admin.php';