Subversion-Projekte lars-tiefland.laravel_shop

Revision

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