Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 703 | Revision 710 | 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();
697 lars 34
    if ( !isset( $_SESSION["SHOP"]["BASKET"] ) )
35
    {
36
        $_SESSION["SHOP"]["BASKET"] = new Basket();
37
    }
700 lars 38
    elseif ( is_array( $_SESSION["SHOP"]["BASKET"] ) )
697 lars 39
    {
40
        $items = $_SESSION["SHOP"]["BASKET"];
41
        unset( $_SESSION["SHOP"]["BASKET"] );
42
        $_SESSION["SHOP"]["BASKET"] = new Basket();
699 lars 43
        $_SESSION["SHOP"]["BASKET"]->items = $items;
697 lars 44
    }
340 lars 45
    $sql = "
46
        SELECT
47
            *
48
        FROM
49
            i18n_de
50
    ";
405 lars 51
    if ( Schema::hasTable( 'i18n_de' ) )
52
    {
53
        $langstrings = DB::select( $sql );
54
    }
55
    else
56
    {
57
        $langstrings = DB::connection( "old" )->select( $sql );
58
    }
340 lars 59
    foreach ( $langstrings as $langstring )
60
    {
355 lars 61
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 62
    }
355 lars 63
 
367 lars 64
    function parseCMSPage( $url ): array
355 lars 65
    {
375 lars 66
        $menu = "";
67
        $content = "";
365 lars 68
        $dom = new Dom;
366 lars 69
        try
70
        {
71
            $dom->loadFromUrl( $url );
375 lars 72
            $menu = $dom->getElementById( 'menu' )->innerHtml;
73
            $menu = str_replace( "/typo3", "/cms", $menu );
74
            $content = $dom->getElementById( 'content' )->innerHtml;
75
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
76
            $content = str_replace( "ce-textpic", "", $content );
366 lars 77
        }
375 lars 78
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 79
        {
80
        }
355 lars 81
        return array( "menu" => $menu, "content" => $content, );
82
    }
83
 
333 lars 84
    function getConfig()
85
    {
86
        define( '__SITE__', env( 'site' ) );
87
        define( '__SHOP__', env( 'shop' ) );
88
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 89
 
333 lars 90
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
91
        if ( !file_exists( $cfg_file ) )
92
        {
93
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
94
        }
95
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
96
        $ini = json_decode( json_encode( $xml ), true );
97
        foreach ( $ini as $key => $wert )
98
        {
99
            if ( $wert == array() )
100
            {
355 lars 101
                $ini[$key] = "";
333 lars 102
            }
103
            elseif ( is_array( $wert ) )
104
            {
105
                foreach ( $wert as $key2 => $wert2 )
106
                {
107
                    if ( $wert2 == array() )
108
                    {
355 lars 109
                        $ini[$key][$key2] = "";
333 lars 110
                    }
176 lars 111
                }
112
            }
113
        }
114
 
333 lars 115
        $v_file = __CFG_PATH__ . "/versand.xml";
116
        if ( file_exists( $v_file ) )
117
        {
118
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 119
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
120
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 121
            {
122
                if ( $wert == array() )
123
                {
355 lars 124
                    $ini["shipping"][$key] = "";
333 lars 125
                }
126
                elseif ( is_array( $wert ) )
127
                {
128
                    foreach ( $wert as $key2 => $wert2 )
129
                    {
130
                        if ( $wert2 == array() )
131
                        {
355 lars 132
                            $ini["shipping"][$key][$key2] = "";
333 lars 133
                        }
176 lars 134
                    }
135
                }
136
            }
137
        }
333 lars 138
        return $ini;
177 lars 139
    }
140
 
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
    }