Subversion-Projekte lars-tiefland.laravel_shop

Revision

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