Subversion-Projekte lars-tiefland.laravel_shop

Revision

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