Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 874 | Revision 890 | 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
    } );
875 lars 260
    Route::get("/update_versand",[ ShippingController::class, "updateShipping"]);
658 lars 261
    Route::get( '/setSessionVars', function ()
262
    {
263
        foreach ( $_GET as $key => $value )
264
        {
265
            if ( $value == "false" )
266
            {
267
                unset( $_SESSION[$key] );
268
            }
269
            else
270
            {
271
                $_SESSION[$key] = $value;
272
            }
273
        }
274
    } );
765 lars 275
    Route::post( "/setSessionVars", function ()
276
    {
762 lars 277
        foreach ( $_POST as $key => $value )
278
        {
279
            if ( $value == "false" )
280
            {
281
                unset( $_SESSION[$key] );
282
            }
283
            else
284
            {
285
                $_SESSION[$key] = $value;
286
            }
287
        }
765 lars 288
    } );
289
    Route::post( "/updateSession", function ()
756 lars 290
    {
291
    } );
355 lars 292
    Route::get( "/cms/{slug}", function ( $slug )
293
    {
359 lars 294
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 295
        $arr = parseCMSPage( $url );
355 lars 296
        $content = $arr["content"];
361 lars 297
        return view( 'service_center_content', [
848 lars 298
            "serviceContent" => $content,
355 lars 299
        ] );
300
    } );
377 lars 301
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 302
    {
405 lars 303
        return view( 'buy_' . $id, [
848 lars 304
            "Laender"       => getRechnungsLaender(),
305
            "defaultLandID" => 47,
376 lars 306
        ] );
678 lars 307
    } )->where( 'id', '[1-4][ab]{0,1}' );
730 lars 308
    Route::post( "/bestellen_seite_{id}.html", [ BuyController::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
349 lars 309
    Route::get( "basket.html", function ()
310
    {
678 lars 311
 
848 lars 312
        return view( 'basket' );
349 lars 313
    } );
333 lars 314
    Route::get( "/directory/{id}", function ( $id )
315
    {
316
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
317
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
318
            0,
319
            99
650 lars 320
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 321
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 322
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 323
        $subdir["subdirs"] = $dirs;
324
        $subdir["items"] = $items;
628 lars 325
        $template = 'subdir';
634 lars 326
        $artstaemmeItems = array();
631 lars 327
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 328
        {
675 lars 329
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
634 lars 330
            foreach ( $dirs as $dir )
331
            {
332
                if ( $dir->articlemaster == 1 )
333
                {
636 lars 334
                    $artstaemmeItems[$dir->id] = $dir;
673 lars 335
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 336
                }
337
            }
628 lars 338
        }
339
        return view( $template, [
848 lars 340
            "subdir"          => $subdir,
341
            "artstaemmeItems" => $artstaemmeItems,
333 lars 342
        ] );
343
    } );
344
    Route::get( "{item:slug}.html", function ( Item $item )
345
    {
646 lars 346
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 347
        return view( 'item', [
848 lars 348
            "item" => $item,
333 lars 349
        ] );
350
    } );
351
    Route::get( '/', function ()
352
    {
405 lars 353
        $date = date( "Y-m-d" );
354
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 355
        return view( 'startpage', [
848 lars 356
            "pagetype" => "Startseite",
357
            "aktion"   => $aktion,
333 lars 358
        ] );
359
    } );
685 lars 360
 
361
 
703 lars 362
    function getRechnungsLaender(): array
685 lars 363
    {
687 lars 364
        $arr = array();
693 lars 365
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM countries WHERE rank > 0 ORDER BY rank' );
687 lars 366
        foreach ( $laender as $land )
367
        {
368
            $arr[$land->id] = $land->name_de;
369
        }
370
        return $arr;
730 lars 371
    }