Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 711 | Revision 730 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
385 lars 3
    use App\Http\Controllers\Basket;
678 lars 4
    use App\Http\Controllers\Buy;
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
    {
60
        $_SESSION["SHOP"]["BASKET"] = new Basket();
61
    }
700 lars 62
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 63
    {
64
        $items = $_SESSION["SHOP"]["BASKET"];
65
        unset( $_SESSION["SHOP"]["BASKET"] );
66
        $_SESSION["SHOP"]["BASKET"] = new Basket();
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
    } );
658 lars 200
    Route::get( '/setSessionVars', function ()
201
    {
202
        foreach ( $_GET as $key => $value )
203
        {
204
            if ( $value == "false" )
205
            {
206
                unset( $_SESSION[$key] );
207
            }
208
            else
209
            {
210
                $_SESSION[$key] = $value;
211
            }
212
        }
213
    } );
355 lars 214
    Route::get( "/cms/{slug}", function ( $slug )
215
    {
359 lars 216
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 217
        $arr = parseCMSPage( $url );
355 lars 218
        $content = $arr["content"];
361 lars 219
        return view( 'service_center_content', [
368 lars 220
            "serviceContent"    => $content,
221
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
222
            "nav"               => $GLOBALS["menu"],
223
            "ini"               => $GLOBALS["INI"],
224
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 225
        ] );
226
    } );
377 lars 227
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 228
    {
405 lars 229
        return view( 'buy_' . $id, [
376 lars 230
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
231
            "nav"               => $GLOBALS["menu"],
232
            "ini"               => $GLOBALS["INI"],
233
            "langstrings"       => $GLOBALS["langstrings"],
686 lars 234
            "Laender"           => getRechnungsLaender(),
685 lars 235
            "defaultLandID"     => 47,
376 lars 236
        ] );
678 lars 237
    } )->where( 'id', '[1-4][ab]{0,1}' );
238
    Route::post( "/bestellen_seite_{id}.html", [ Buy::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
349 lars 239
    Route::get( "basket.html", function ()
240
    {
678 lars 241
 
349 lars 242
        return view( 'basket', [
368 lars 243
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
244
            "nav"               => $GLOBALS["menu"],
245
            "ini"               => $GLOBALS["INI"],
246
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 247
        ] );
248
    } );
333 lars 249
    Route::get( "/directory/{id}", function ( $id )
250
    {
251
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
252
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
253
            0,
254
            99
650 lars 255
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 256
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 257
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 258
        $subdir["subdirs"] = $dirs;
259
        $subdir["items"] = $items;
628 lars 260
        $template = 'subdir';
634 lars 261
        $artstaemmeItems = array();
631 lars 262
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 263
        {
675 lars 264
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
634 lars 265
            foreach ( $dirs as $dir )
266
            {
267
                if ( $dir->articlemaster == 1 )
268
                {
636 lars 269
                    $artstaemmeItems[$dir->id] = $dir;
673 lars 270
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 271
                }
272
            }
628 lars 273
        }
274
        return view( $template, [
368 lars 275
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
276
            "subdir"            => $subdir,
277
            "nav"               => $GLOBALS["menu"],
278
            "ini"               => $GLOBALS["INI"],
279
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 280
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 281
        ] );
282
    } );
283
    Route::get( "{item:slug}.html", function ( Item $item )
284
    {
646 lars 285
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 286
        return view( 'item', [
368 lars 287
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
288
            "item"              => $item,
289
            "nav"               => $GLOBALS["menu"],
290
            "ini"               => $GLOBALS["INI"],
291
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 292
        ] );
293
    } );
294
    Route::get( '/', function ()
295
    {
723 lars 296
        if ( isset( $_GET["killSession"] ) )
297
        {
298
            unset( $_SESSION );
299
            $_SESSION["SHOP"]["BASKET"] = new Basket();
300
        }
405 lars 301
        $date = date( "Y-m-d" );
302
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 303
        return view( 'startpage', [
368 lars 304
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
305
            "pagetype"          => "Startseite",
306
            "aktion"            => $aktion,
307
            "nav"               => $GLOBALS["menu"],
308
            "ini"               => $GLOBALS["INI"],
309
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 310
        ] );
311
    } );
685 lars 312
 
313
 
703 lars 314
    function getRechnungsLaender(): array
685 lars 315
    {
687 lars 316
        $arr = array();
693 lars 317
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM countries WHERE rank > 0 ORDER BY rank' );
687 lars 318
        foreach ( $laender as $land )
319
        {
320
            $arr[$land->id] = $land->name_de;
321
        }
322
        return $arr;
685 lars 323
    }