Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 700 | Revision 704 | 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
    }
697 lars 33
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
34
    {
35
        $_SESSION["SHOP"]["BASKET"] = new Basket();
36
    }
700 lars 37
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 38
    {
39
        $items = $_SESSION["SHOP"]["BASKET"];
40
        unset( $_SESSION["SHOP"]["BASKET"] );
41
        $_SESSION["SHOP"]["BASKET"] = new Basket();
699 lars 42
        $_SESSION["SHOP"]["BASKET"]->items = $items;
697 lars 43
    }
340 lars 44
    $sql = "
45
        SELECT
46
            *
47
        FROM
48
            i18n_de
49
    ";
405 lars 50
    if ( Schema::hasTable( 'i18n_de' ) )
51
    {
52
        $langstrings = DB::select( $sql );
53
    }
54
    else
55
    {
56
        $langstrings = DB::connection( "old" )->select( $sql );
57
    }
340 lars 58
    foreach ( $langstrings as $langstring )
59
    {
355 lars 60
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 61
    }
355 lars 62
 
367 lars 63
    function parseCMSPage( $url ): array
355 lars 64
    {
375 lars 65
        $menu = "";
66
        $content = "";
365 lars 67
        $dom = new Dom;
366 lars 68
        try
69
        {
70
            $dom->loadFromUrl( $url );
375 lars 71
            $menu = $dom->getElementById( 'menu' )->innerHtml;
72
            $menu = str_replace( "/typo3", "/cms", $menu );
73
            $content = $dom->getElementById( 'content' )->innerHtml;
74
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
75
            $content = str_replace( "ce-textpic", "", $content );
366 lars 76
        }
375 lars 77
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 78
        {
79
        }
355 lars 80
        return array( "menu" => $menu, "content" => $content, );
81
    }
82
 
333 lars 83
    function getConfig()
84
    {
85
        define( '__SITE__', env( 'site' ) );
86
        define( '__SHOP__', env( 'shop' ) );
87
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 88
 
333 lars 89
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
90
        if ( !file_exists( $cfg_file ) )
91
        {
92
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
93
        }
94
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
95
        $ini = json_decode( json_encode( $xml ), true );
96
        foreach ( $ini as $key => $wert )
97
        {
98
            if ( $wert == array() )
99
            {
355 lars 100
                $ini[$key] = "";
333 lars 101
            }
102
            elseif ( is_array( $wert ) )
103
            {
104
                foreach ( $wert as $key2 => $wert2 )
105
                {
106
                    if ( $wert2 == array() )
107
                    {
355 lars 108
                        $ini[$key][$key2] = "";
333 lars 109
                    }
176 lars 110
                }
111
            }
112
        }
113
 
333 lars 114
        $v_file = __CFG_PATH__ . "/versand.xml";
115
        if ( file_exists( $v_file ) )
116
        {
117
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 118
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
119
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 120
            {
121
                if ( $wert == array() )
122
                {
355 lars 123
                    $ini["shipping"][$key] = "";
333 lars 124
                }
125
                elseif ( is_array( $wert ) )
126
                {
127
                    foreach ( $wert as $key2 => $wert2 )
128
                    {
129
                        if ( $wert2 == array() )
130
                        {
355 lars 131
                            $ini["shipping"][$key][$key2] = "";
333 lars 132
                        }
176 lars 133
                    }
134
                }
135
            }
136
        }
333 lars 137
        return $ini;
177 lars 138
    }
139
 
333 lars 140
    session_start();
355 lars 141
    $GLOBALS["INI"] = getConfig();
142
    $GLOBALS["menu"] = array();
333 lars 143
    $nav = new Directory();
355 lars 144
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 145
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
146
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 147
    /* Mobile Weiche */
355 lars 148
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 149
    {
375 lars 150
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 151
        {
88 lars 152
 
355 lars 153
            $_SESSION['isMobile'] = false;
154
            $GLOBALS['isMobile'] = false;
88 lars 155
 
333 lars 156
            if (
375 lars 157
                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 158
            )
159
            {
88 lars 160
 
355 lars 161
                $_SESSION['isMobile'] = true;
162
                $GLOBALS['isMobile'] = true;
333 lars 163
            }
164
 
88 lars 165
        }
166
    }
405 lars 167
    Route::get( "/addItemToBasket", function ()
385 lars 168
    {
697 lars 169
        $_SESSION["SHOP"]["BASKET"]->addItem();
671 lars 170
        return view( 'header_wk', [
678 lars 171
            "nav"         => $GLOBALS["menu"],
172
            "ini"         => $GLOBALS["INI"],
173
            "langstrings" => $GLOBALS["langstrings"],
671 lars 174
        ] );
405 lars 175
    } );
658 lars 176
    Route::get( '/setSessionVars', function ()
177
    {
178
        foreach ( $_GET as $key => $value )
179
        {
180
            if ( $value == "false" )
181
            {
182
                unset( $_SESSION[$key] );
183
            }
184
            else
185
            {
186
                $_SESSION[$key] = $value;
187
            }
188
        }
189
    } );
355 lars 190
    Route::get( "/cms/{slug}", function ( $slug )
191
    {
359 lars 192
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 193
        $arr = parseCMSPage( $url );
355 lars 194
        $content = $arr["content"];
361 lars 195
        return view( 'service_center_content', [
368 lars 196
            "serviceContent"    => $content,
197
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
198
            "nav"               => $GLOBALS["menu"],
199
            "ini"               => $GLOBALS["INI"],
200
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 201
        ] );
202
    } );
377 lars 203
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 204
    {
405 lars 205
        return view( 'buy_' . $id, [
376 lars 206
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
207
            "nav"               => $GLOBALS["menu"],
208
            "ini"               => $GLOBALS["INI"],
209
            "langstrings"       => $GLOBALS["langstrings"],
686 lars 210
            "Laender"           => getRechnungsLaender(),
685 lars 211
            "defaultLandID"     => 47,
376 lars 212
        ] );
678 lars 213
    } )->where( 'id', '[1-4][ab]{0,1}' );
214
    Route::post( "/bestellen_seite_{id}.html", [ Buy::class, 'step1' ] )->where( 'id', '[1-4][ab]{0,1}' );
349 lars 215
    Route::get( "basket.html", function ()
216
    {
678 lars 217
 
349 lars 218
        return view( 'basket', [
368 lars 219
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
220
            "nav"               => $GLOBALS["menu"],
221
            "ini"               => $GLOBALS["INI"],
222
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 223
        ] );
224
    } );
333 lars 225
    Route::get( "/directory/{id}", function ( $id )
226
    {
227
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
228
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
229
            0,
230
            99
650 lars 231
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 232
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 233
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 234
        $subdir["subdirs"] = $dirs;
235
        $subdir["items"] = $items;
628 lars 236
        $template = 'subdir';
634 lars 237
        $artstaemmeItems = array();
631 lars 238
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 239
        {
675 lars 240
            $template = substr( $subdir->template[0]->template->template_value, strpos( $subdir->template[0]->template->template_value, "=" ) + 1 );
634 lars 241
            foreach ( $dirs as $dir )
242
            {
243
                if ( $dir->articlemaster == 1 )
244
                {
636 lars 245
                    $artstaemmeItems[$dir->id] = $dir;
673 lars 246
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();
634 lars 247
                }
248
            }
628 lars 249
        }
250
        return view( $template, [
368 lars 251
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
252
            "subdir"            => $subdir,
253
            "nav"               => $GLOBALS["menu"],
254
            "ini"               => $GLOBALS["INI"],
255
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 256
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 257
        ] );
258
    } );
259
    Route::get( "{item:slug}.html", function ( Item $item )
260
    {
646 lars 261
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 262
        return view( 'item', [
368 lars 263
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
264
            "item"              => $item,
265
            "nav"               => $GLOBALS["menu"],
266
            "ini"               => $GLOBALS["INI"],
267
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 268
        ] );
269
    } );
270
    Route::get( '/', function ()
271
    {
405 lars 272
        $date = date( "Y-m-d" );
273
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 274
        return view( 'startpage', [
368 lars 275
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
276
            "pagetype"          => "Startseite",
277
            "aktion"            => $aktion,
278
            "nav"               => $GLOBALS["menu"],
279
            "ini"               => $GLOBALS["INI"],
280
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 281
        ] );
282
    } );
685 lars 283
 
284
 
703 lars 285
    function getRechnungsLaender(): array
685 lars 286
    {
687 lars 287
        $arr = array();
693 lars 288
        $laender = DB::connection( 'cms' )->select( 'SELECT id,name_de FROM countries WHERE rank > 0 ORDER BY rank' );
687 lars 289
        foreach ( $laender as $land )
290
        {
291
            $arr[$land->id] = $land->name_de;
292
        }
293
        return $arr;
685 lars 294
    }