Subversion-Projekte lars-tiefland.laravel_shop

Revision

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