Subversion-Projekte lars-tiefland.laravel_shop

Revision

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