Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
    /**
3
     * @package   php_share
4
     * @author    Lars Tiefland <tiefland@weban.de>
5
     * @copyright 2009 Webagentur Niewerth
6
     * @license   propietary http://www.weban.de
7
     * @version   $Rev: 853 $
8
     * @filesource
9
     *
10
     */
11
 
12
    // SVN: $Id: functions.common.php 853 2011-11-18 08:14:02Z tiefland $
13
 
14
    require_once "errorHandler.php";
15
 
16
    /**
17
     *
18
     * Text_Password-Paket einbinden
19
     *
20
     */
21
    require_once "Text/Password.php";
22
 
23
    /**
24
     *
25
     *  Log-Paket einbinden
26
     *
27
     */
28
    require_once "Log.php";
29
 
30
    /**
31
     *
32
     * Trnaslation2-Paket einbinden
33
     *
34
     */
35
    require_once "Translation2.php";
36
 
37
    /**
38
     *
39
     * Config-Paket einbinden
40
     *
41
     */
42
    require_once "Config.php";
43
 
44
    /**
45
     *
46
     * MDB2-Paket einbinden
47
     *
48
     */
49
    require_once "MDB2.php";
50
 
51
    /**
52
     *
53
     * Smarty einbinden
54
     *
55
     */
56
    require_once "Weban_Smarty.class.php";
57
 
58
    /**
59
     *
60
     * Konstante __USE_MDB2__ definieren, falls dies noch nicht passiert ist
61
     *
62
     */
63
    if ( !defined( "__USE_MDB2__" ) )
64
    {
65
        define( "__USE_MDB2__", false );
66
    }
67
 
68
    /**
69
     *
70
     * Konstante USE_TRANSLATION2 definieren, falls dies noch nicht passiert ist
71
     *
72
     */
73
    if ( !defined( "USE_TRANSLATION2" ) )
74
    {
75
        define( "USE_TRANSLATION2", false );
76
    }
77
 
78
    /**
79
     *
80
     * Konstante USE_SMARTY definieren, falls dies noch nicht passiert ist
81
     *
82
     */
83
    if ( !defined( "USE_SMARTY" ) )
84
    {
85
        define( "USE_SMARTY", false );
86
    }
87
 
88
    /**
89
     *
90
     * Konstante USE_SMARTY_PAGINATE definieren, falls dies noch nicht passiert ist
91
     *
92
     */
93
    if ( !defined( "USE_SMARTY_PAGINATE" ) )
94
    {
95
        define( "USE_SMAETY_PAGINATE", false );
96
    }
97
 
98
    /**
99
     *
100
     * Konstante USE_LOGGING definieren, falls dies noch nicht passiert ist
101
     *
102
     */
103
    if ( !defined( "USE_LOGGING" ) )
104
    {
105
        define( "USE_LOGGING", false );
106
    }
107
 
108
    /**
109
     *
110
     * @package   php_share
111
     * @author    Lars Tiefland <tiefland@weban.de>
112
     * @copyright 2009 Webagentur Niewerth
113
     */
114
 
115
    /**
116
     * getIsoCode()
117
     *
118
     * gibt den 2- oder 3-stelligen ISO-Code eines landes zurück
119
     *
120
     * @param string $Land Land dessen ISO-Code zurügkgegeben werden soll
121
     * @param string $len Länge des ISO-Codes (2- oder 3-stellig)
122
     *
123
     * @return string
124
     */
125
    function getIsoCode( $Land = 'Deutschland', $len = 2 )
126
    {
127
        $sql = "select
128
                    `iso-" . $len . "` as iso_code
129
                from
130
                    content_management.countries
131
                where
132
                    `name-ger` ='" . $Land . "'";
133
 
134
        if ( $q = mysql_query( $sql ) )
135
        {
136
            if ( $r = mysql_fetch_assoc( $q ) )
137
            {
138
                return $r["iso_code"];
139
            }
140
        }
141
        /*
142
        switch ( $len )
143
        {
144
        case 2:
145
        default:
146
 
147
        $codes = array( 'Deutschland' => 'DE', 'Niederlande' => 'NL',
148
        'Österreich' => 'AT', 'Dänemark' => 'DK', 'Schweiz' =>
149
        'CH', 'Schweden' => 'SE', 'Finnland' => 'FI', 'Belgien' => 'BE',
150
        'Luxemburg' => 'LU',
151
 
152
        '' => 'DE'
153
        );
154
        break;
155
        case 3:
156
        $codes = array( 'Deutschland' => 'DEU', 'Niederlande' =>
157
        'NLD', 'Österreich' => 'AUT', 'Dänemark' => 'DNK',
158
        'Schweiz' => 'CHE', 'Schweden' => 'SWE', 'Finnland' =>
159
        'FIN', '' => 'DEU' );
160
        break;
161
        }*/
162
        return false;
163
    }
164
 
165
    /**
166
     * translate_laender()
167
     *
168
     * setzt englische Ländernamen in deutsche um
169
     *
170
     * @param mixed $land englischer Name des Landes
171
     * @return string deutscher Name des Landes
172
     */
173
    function translate_laender( $land )
174
    {
175
        $laender = array( "Germany" => "Deutschland", "Netherlands" =>
176
            "Niederlande", "Austria" => "Österreich", "Belgium" => "Belgien",
177
            "Luxembourg" => "Luxemburg", "Denmark" => "Dänemark", "Switzerland" =>
178
            "Schweiz", "France" => "Frankreich", "United Kingdom" =>
179
            "Großbritanien", "Italy" => "Italien", "Spain" => "Spanien",
180
            "Portugal" => "Portugal", "Sweden" => "Schweden", "Finland" =>
181
            "Finnland", "Norway" => "Norwegen", "Ireland" => "Irland", "Greece" =>
182
            "Griechenland", "Estonia" => "Estland", "Latvia" => "Lettland",
183
            "Malta" => "Malta", "Lithuania" => "Litauen", "Poland" => "Polen",
184
            "Slovenia" => "Slowenien", "Slovakia (Slovak Republic)" =>
185
            "Tschechien/Slowakei", "Czech Republic" => "Tschechien/Slowakei",
186
            "Turkey" => "Türkei", "Hungary" => "Ungarn", "Cyprus" => "Zypern",
187
            "Canada" => "Kanada", "United States" => "USA", );
188
        $t_land = $laender[$land];
189
        if ( !$t_land )
190
        {
191
            $t_land = $land;
192
        }
193
    }
194
 
195
    /**
196
     * getShopInfo()
197
     *
198
     * ermittelt die infos zum angegebenen Shop
199
     *
200
     * @param integer $shop_id ID des Shops dessen Infos gelesen werden sollen
201
     * @return array Infos zum Shop
202
     */
203
    function getShopInfo( $shop_id )
204
    {
205
        $sql = "
206
            SELECT
207
                *
208
            FROM
209
                shops
210
            WHERE
211
                ID=$shop_id
212
        ";
213
        $res = mysql_query( $sql );
214
        $row = mysql_fetch_assoc( $res );
215
        return $row;
216
    }
217
 
218
    /**
219
     * getBestellartInfo()
220
     *
221
     * liest die angegebene Bestellart aus und gibt den Datensatz zurück
222
     * (oder fals im Fehlerfall)
223
     *
224
     * @param mixed $bestellart Bestellart, die ausgelesen werden soll
225
     * @return mixed
226
     */
227
    function getBestellartInfo( $bestellart )
228
    {
229
        $sql = "
230
            SELECT
231
                *
232
            FROM
233
                bestellart
234
            WHERE
235
                ID=$bestellart
236
        ";
237
        $res = mysql_query( $sql );
238
        if ( !$res )
239
        {
240
            return false;
241
        }
242
        $row = mysql_fetch_assoc( $res );
243
        return $row;
244
    }
245
 
246
    /**
247
     * serverCheck()
248
     *
249
     * anhand des Servernamens wird ein Zusatzwert für die INI-Datei zurückgegeben
250
     *
251
     * @param string $serverName
252
     * @return string
253
     */
254
    function serverCheck( $serverName = 'server3' )
255
    {
256
        if ( eregi( "\.local", $_SERVER['SERVER_NAME'] ) || $serverName == $_SERVER['SERVER_NAME'] ||
257
            $serverName == $_SERVER['HOSTNAME'] )
258
        {
259
            $extra = 'local.';
260
        } elseif ( eregi( "^dev", $_SERVER["SERVER_NAME"] ) )
261
        {
262
            $extra = 'dev.';
263
        }
264
        else
265
        {
266
            $extra = '';
267
        }
268
        isWeban();
269
        return $extra;
270
    }
271
 
272
    /**
273
     * getConfig()
274
     *
275
     * liest Konfigrationsdateien für den Shop ein, der folgendermaßen anzugeben ist:
276
     * 1. Konstante "__SITE__" ist auf den Kunden zu setzen (z. B. "mediaran.de")
277
     * 2. Konstante "__SHOP__" ist auf den Shop zu setzen (z. B. "mediakomeet.de")
278
     * und gibt diese zurück
279
     *
280
     * bedient sich der Funktion server_check() um den genauen Dateinamen zu ermitteln
281
     *
282
     * @param string $type Typ der zu lesenden Konfigurationsdatei(en))
283
     * @return array
284
     */
285
    function getConfig( $type = "INI" )
286
    {
287
        if ( !defined( "__SHOP__" ) || !defined( "__SITE__" ) )
288
        {
289
            trigger_error( "Konstante(n) __SITE__ und / oder __SHOP__ wurde(n) NICHT definiert",
290
                E_USER_ERROR );
291
        }
292
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
293
 
294
        $cfg = new Config();
295
        switch ( $type )
296
        {
297
            case "INI":
298
                $ext = "ini.php";
299
                $p_type = "IniCommented";
300
                break;
301
            case "XML":
302
                $ext = "xml";
303
                $p_type = "XML";
304
                break;
305
            default:
306
                trigger_error( "Unbekannter Typ $type!", E_USER_ERROR );
307
                break;
308
        }
309
        $cfg_file = __CFG_PATH__ . "/config.de." . serverCheck() . $ext;
310
        if ( !file_exists( $cfg_file ) )
311
        {
312
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " .
313
                __SITE__ . " -> " . __SHOP__ . " finden!", E_USER_ERROR );
314
        }
315
        $cfg = $cfg->parseconfig( $cfg_file, $p_type, array( "name" => "config" ) );
316
        $cfg = $cfg->toArray();
317
        $ini = ( $type == "INI" ) ? $cfg["root"] : $cfg["root"]["config"];
318
 
319
        if ( $_SERVER["SERVER_NAME"] && USE_SMARTY === false )
320
        {
321
            $cfg = new Config();
322
 
323
            $t_file = __CFG_PATH__ . "/template_" . strtolower( $ini["language"] ) .
324
                ".$ext";
325
            if ( !file_exists( $t_file ) )
326
            {
327
                $t_file = __CFG_PATH__ . "/template_de.$ext";
328
                if ( !file_exists( $t_file ) )
329
                {
330
                    $t_file = __CFG_PATH__ . "/template.$ext";
331
                    if ( !file_exists( $t_file ) )
332
                    {
333
                        trigger_error( "Konnte keine Konfigurationsdatei für das Templatesystem finden!",
334
                            E_USER_ERROR );
335
                    }
336
                }
337
            }
338
            $cfg = $cfg->parseconfig( $t_file, $p_type, array( "name" =>
339
                "config" ) );
340
            $cfg = $cfg->toArray();
341
            $ini["TEMPLATE"] = ( $type == "INI" ) ? $cfg["root"] : $cfg["root"]["config"];
342
        }
343
        return $ini;
344
    }
345
 
346
    /**
347
     * getVersandEigenschaften()
348
     *
349
     * liest Versandeigenschaften aus der Datenbank des Redaktionssystems
350
     * für die in der Konstante __SITE__ definierte Domain (z. B. mediaran.de) aus
351
     * und gibt sie zurück
352
     *
353
     * Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden
354
     *
355
     * @return array
356
     */
357
    function getVersandEigenschaften( $domain = __SITE__ )
358
    {
359
        $eigenschaften = array();
360
        if ( !defined( "__SITE__" ) )
361
        {
362
            trigger_error( "Konstante __SITE__ wurde NICHT definiert!",
363
                E_USER_ERROR );
364
        }
365
        $sql = "
366
            SELECT
367
                ID AS id
368
            FROM
369
                properties
370
            WHERE
371
                interner_Name LIKE 'Eigenschaft%'
372
            AND
373
                tools=1
374
        ";
375
 
376
        //if ( __USE_MDB2__ )
377
 
378
        {
379
            if ( !$GLOBALS["db_red"] instanceof MDB2_Driver_Common )
380
            {
381
                _createDBRed();
382
            }
383
            $res = $GLOBALS["db_red"]->query( $sql );
384
            if ( PEAR::isError( $res ) )
385
            {
386
                trigger_error( "SQL fehlerhaft!\n" . $res->getUserInfo() . "\n",
387
                    E_USER_ERROR );
388
            }
389
            $rows = $res->fetchAll();
390
            foreach ( $rows as $row )
391
            {
392
                $sql2 = "
393
                    SELECT
394
                        wp.*,
395
                        p.interner_name
396
                    FROM
397
                        webs_properties AS wp
398
                    JOIN
399
                        webs AS w
400
                    ON
401
                        w.ID=wp.webs
402
                    JOIN
403
                        properties AS p
404
                    ON
405
                        p.id=wp.properties
406
                    WHERE
407
                        domain='" . $domain . "'
408
                    AND
409
                        properties=" . $row["id"] . "
410
                    AND
411
                        wp.Bezeichnung LIKE '%;logistik';
412
                ";
413
                $res2 = $GLOBALS["db_red"]->query( $sql2 );
414
                if ( PEAR::isError( $res2 ) )
415
                {
416
                    trigger_error( "SQL fehlerhaft!\n" . $res2->getUserInfo() .
417
                        "\n", E_USER_ERROR );
418
                }
419
                $row2 = $res2->FetchRow();
420
                if ( is_array( $row2 ) )
421
                {
422
                    list( $name, $nr ) = explode( "_", $row2["interner_name"] );
423
                    $eigenschaften[] = $nr;
424
                }
425
            }
426
        }
427
        /*else
428
        {
429
        $conn = mysql_connect( "redaktion.weban.de", "admin",
430
        "EW-ad-1055" );
431
        if ( !$conn )
432
        {
433
        trigger_error( "Keine Verbindung zur Datenbank möglich!\n",
434
        E_USER_ERROR );
435
        }
436
        $res = mysql_select_db( "content_management" );
437
        if ( !$res )
438
        {
439
        trigger_error( "Keine Verbindung zur Datenbank möglich!\n" .
440
        mysql_error() . "\n", E_USER_ERROR );
441
        }
442
        $res = mysql_query( $sql );
443
        if ( !$res )
444
        {
445
        trigger_error( "SQL fehlerhaft!\n" . mysql_error() . "\n$sql\n",
446
        E_USER_ERROR );
447
        }
448
        while ( $row = mysql_fetch_assoc( $res ) )
449
        {
450
        $sql2 = "
451
        SELECT
452
        wp.*,
453
        p.interner_name
454
        FROM
455
        webs_properties AS wp
456
        JOIN
457
        webs AS w
458
        ON
459
        w.ID=wp.webs
460
        JOIN
461
        properties AS p
462
        ON
463
        p.id=wp.properties
464
        WHERE
465
        domain='" . __SITE__ . "'
466
        AND
467
        properties=" . $row["id"] . "
468
        AND
469
        wp.Bezeichnung LIKE '%;logistik';
470
        ";
471
        $res2 = mysql_query( $sql2 );
472
        if ( !$res2 )
473
        {
474
        trigger_error( "SQL fehlerhaft!\n" . mysql_error() . "\n$sql2\n",
475
        E_USER_ERROR );
476
        }
477
        $row2 = mysql_fetch_assoc( $res2 );
478
        if ( is_array( $row2 ) )
479
        {
480
        list( $name, $nr ) = explode( "_", $row2["interner_name"] );
481
        $eigenschaften[] = $nr;
482
        }
483
        }
484
        mysql_close( $conn );
485
        }*/
486
        return $eigenschaften;
487
    }
488
 
489
 
490
    /**
491
     * dbConnect()
492
     *
493
     * stellt eine Verbindung zur Datenbank des Online-Shops her
494
     *
495
     * Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden
496
 
497
     * @param mixed $ini Hier wird der Inhalt der Ini-Datei des Shops übergeben.
498
     *
499
     * @return mixed
500
     */
501
    function dbConnect( $ini = null )
502
    {
503
        if ( is_null( $ini ) )
504
        {
505
            $ini = $GLOBALS["INI"];
506
        }
507
        if ( !is_array( $ini ) )
508
        {
509
            $ini = $_SESSION["INI"];
510
        }
511
        if ( __USE_MDB2__ )
512
        {
513
            $php5 = version_compare( phpversion(), "5.0", ">=" );
514
            $type = $ini["dbConnect"]["type"];
515
            if ( !$type )
516
            {
517
                if ( $php5 )
518
                {
519
                    $type = "mysqli";
520
                }
521
                else
522
                {
523
                    $type = "mysql";
524
                }
525
            }
526
            $opts = array( "persistent" => true, "portability" =>
527
                MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^
528
                MDB2_PORTABILITY_FIX_CASE );
529
            if ( $ini["uses_order_db"] )
530
            {
531
                $order_dsn = array( "phptype" => $type, "username" => $ini["dbConnect"]["order_username"],
532
                    "password" => $ini["dbConnect"]["order_password"],
533
                    "hostspec" => $ini["dbConnect"]["order_server"], "database" =>
534
                    $ini["dbConnect"]["order_db"], "new_link" => true, );
535
                $GLOBALS["order_db"] = MDB2::connect( $order_dsn, $opts );
536
                if ( PEAR::isError( $GLOBALS["order_db"] ) )
537
                {
538
                    trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n" .
539
                        var_dump( $order_dsn ), E_USER_ERROR );
540
                }
541
                $GLOBALS["order_db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );
542
            }
543
            $dsn = array( "phptype" => $type, "username" => $ini["dbConnect"]["username"],
544
                "password" => $ini["dbConnect"]["password"], "hostspec" => $ini["dbConnect"]["server"],
545
                "database" => $ini["dbConnect"]["database"], "new_link" => true, );
546
            $GLOBALS["db"] = MDB2::connect( $dsn, $opts );
547
            if ( PEAR::isError( $GLOBALS["db"] ) )
548
            {
549
                trigger_error( "Keine Verbindung zur Datenbank möglich!\n",
550
                    E_USER_ERROR );
551
            }
552
            $GLOBALS["db"]->setfetchMode( MDB2_FETCHMODE_ASSOC );
553
            if ( !isset( $GLOBALS["order_db"] ) )
554
            {
555
                $GLOBALS["order_db"] = $GLOBALS["db"];
556
            }
557
        }
558
        else
559
        {
560
            if ( $ini["uses_order_db"] )
561
            {
562
                if ( !$ini["dbConnect"]["order_username"] )
563
                {
564
                    $ini["dbConnect"]["order_username"] = $ini["dbConnect"]["username"];
565
                }
566
                if ( !$ini["dbConnect"]["order_password"] )
567
                {
568
                    $ini["dbConnect"]["order_password"] = $ini["dbConnect"]["password"];
569
                }
570
                if ( !$ini["dbConnect"]["order_server"] )
571
                {
572
                    $ini["dbConnect"]["order_server"] = $ini["dbConnect"]["server"];
573
                }
574
                if ( !$GLOBALS["order_dbh"] = mysql_pconnect( $ini["dbConnect"]["order_server"],
575
                    $ini["dbConnect"]["order_username"], $ini["dbConnect"]["order_password"] ) )
576
                {
577
                    trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n",
578
                        E_USER_ERROR );
579
                }
580
                else
581
                {
582
                    if ( !mysql_select_db( $ini["dbConnect"]["order_db"], $GLOBALS["order_dbh"] ) )
583
                    {
584
                        trigger_error( "Keine Verbindung zur Bestelldatenbank möglich!\n",
585
                            E_USER_ERROR );
586
                    }
587
                }
588
            }
589
            if ( !$GLOBALS["dbh"] = mysql_pconnect( $ini["dbConnect"]["server"],
590
                $ini["dbConnect"]["username"], $ini["dbConnect"]["password"] ) )
591
            {
592
                //return array( mysql_errno(), mysql_error() );
593
                trigger_error( "Keine Verbindung zur Datenbank möglich!\n",
594
                    E_USER_ERROR );
595
            }
596
            else
597
            {
598
                if ( !mysql_select_db( $ini["dbConnect"]["database"], $GLOBALS["dbh"] ) )
599
                {
600
                    trigger_error( "Keine Verbindung zur Datenbank möglich!\n",
601
                        E_USER_ERROR );
602
                }
603
                else
604
                {
605
                    if ( !isset( $GLOBALS["order_dbh"] ) )
606
                    {
607
                        $GLOBALS["order_dbh"] = $GLOBALS["dbh"];
608
                    }
609
                    return true;
610
                }
611
            }
612
        }
613
    }
614
 
615
 
616
    /**
617
     * str2url()
618
     *
619
     * Wandelt einen String so um, daß er als URL verwendet werden kann
620
     * @param mixed $txt Zu verareitender Text
621
     * @return string URL-konformer Text
622
     */
623
    function str2url( $txt )
624
    {
625
        //$txt = strtolower( $txt );
626
        $txt = str_replace( "<br>", "", $txt );
627
        $txt = str_replace( "€", "EUR", $txt );
628
        $txt = str_replace( "®", "", $txt );
629
        $txt = str_replace( "–", "", $txt );
630
        $txt = preg_replace( "/[\(\)\"”´`',\/\.&\<\>#\s;\*„“]/", "-", $txt );
631
        $txt = str_replace( "²", "2", $txt );
632
        $txt = str_replace( "³", "3", $txt );
633
        $txt = str_replace( "°", "", $txt );
634
        $txt = str_replace( "*", "", $txt );
635
        $txt = str_replace( "Ä", "Ae", $txt );
636
        $txt = str_replace( "ä", "ae", $txt );
637
        $txt = str_replace( "Ö", "Oe", $txt );
638
        $txt = str_replace( "ö", "oe", $txt );
639
        $txt = str_replace( "Ü", "Ue", $txt );
640
        $txt = str_replace( "ü", "ue", $txt );
641
        $txt = str_replace( "á", "a", $txt );
642
        $txt = str_replace( "à", "a", $txt );
643
        $txt = str_replace( "â", "a", $txt );
644
        $txt = str_replace( "é", "e", $txt );
645
        $txt = str_replace( "è", "e", $txt );
646
        $txt = str_replace( "ê", "e", $txt );
647
        $txt = str_replace( "ë", "e", $txt );
648
        $txt = str_replace( "í", "i", $txt );
649
        $txt = str_replace( "ì", "i", $txt );
650
        $txt = str_replace( "î", "i", $txt );
651
        $txt = str_replace( "ï", "i", $txt );
652
        $txt = str_replace( "ó", "o", $txt );
653
        $txt = str_replace( "ò", "o", $txt );
654
        $txt = str_replace( "ô", "o", $txt );
655
        $txt = str_replace( "õ", "o", $txt );
656
        $txt = str_replace( " ", "-", $txt );
657
        $txt = str_replace( "%", "", $txt );
658
        $txt = str_replace( "ß", "ss", $txt );
659
        $txt = preg_replace( "/-{2,}/", "-", $txt );
660
        $txt = preg_replace( "/-$/", "", $txt );
661
        return $txt;
662
    }
663
 
664
    /**
665
     * getPath_new()
666
     * ermittelt den Pfad für einen Artikel oder eine Kategorie
667
     *
668
     * @param mixed $root
669
     * @return array
670
     */
671
    function getPath_new( $root )
672
    {
673
        $father = $root;
674
        while ( $father != -1 )
675
        {
676
            $sql = "
677
                SELECT
678
                    *
679
                FROM
680
                    directory
681
                WHERE
682
                    ID=$father
683
                AND
684
                    language='" . $_SESSION["INI"]["language"] . "'
685
                AND
686
                    status=0
687
            ";
688
            $res = mysql_query( $sql );
689
            $row = mysql_fetch_assoc( $res );
690
            $father = $row["Father"];
691
            foreach ( array( "", "2", "3" ) as $i )
692
            {
693
                if ( $zeile["bild_url" . $i] )
694
                {
695
                    $zeile["bild_url" . $i . "_beurer"] = $_SESSION['INI']['itemContainerKorrektur']["imagePath" .
696
                        $i] . $zeile["bild_url" . $i];
697
                    $zeile["bild_url" . $i] = "<img src=" . $_SESSION['INI']['itemContainerKorrektur']["imagePath" .
698
                        $i] . $zeile["bild_url" . $i] . " >";
699
                }
700
                else
701
                {
702
                    $zeile["bild_url" . $i] = "";
703
                }
704
            }
705
            $path[] = $row;
706
        }
707
        return $path;
708
    }
709
 
710
    /**
711
     * Weban_Log()
712
     *
713
     * Schreibt eine Nachricht in das von createLogger() erzeugte Log-Objekt
714
     *
715
     * @param mixed $message Zu protokollierende Nachricht
716
     * @param mixed $priority Priorität der Nachricht
717
     * @return void
718
     */
719
    function Weban_Log( $message, $priority = E_USER_NOTICE )
720
    {
721
        $log_message = preg_replace( "/[\r\n]/", " ", $message );
722
        $log_message = preg_replace( "/\s{2,}/", " ", $log_message );
723
        $GLOBALS["log"]->log( $log_message, $priority );
724
        if ( IS_WEBAN )
725
        {
726
            if ( function_exists( "xdebug_enable" ) )
727
            {
728
                xdebug_enable();
729
            }
730
            trigger_error( $message, $priority );
731
        }
732
        switch ( $priority )
733
        {
734
            case E_USER_ERROR:
735
                if ( !IS_WEBAN )
736
                {
737
                    header( "HTTP/1.1 500", true, 500 );
738
                }
739
                break;
740
        }
741
    }
742
 
743
    /**
744
     * createLogger()
745
     *
746
     * erzeugt ein Log-Objekt
747
     *
748
     * Die folgenden Konstanten müssen definiert sein:
749
     *
750
     * LOG_FILE enthält das Logfile in das geschrieben werden soll
751
     * __SHOP__ definiert den Identifier für das Log
752
     *
753
     * @return void
754
     */
755
    function createLogger()
756
    {
757
        $conf = array
758
        (
759
            "append" => true,
760
            "lineformat" => "%{timestamp}\t%{ident}\t%%{priority}\t%{message}\t%{file}\t%{line}\t%{function}\t%{class}",
761
        );
762
        $GLOBALS["log"] = Log::singleton( 'file', LOG_FILE, __SHOP__, $conf );
763
    }
764
 
765
 
766
    /**
767
     * directoryIsEmpty()
768
     *
769
     * Die Funktion testet, ob eine Kategorie leer ist.
770
     * Dazu ruft die Funktion sich rekursiv auf, um alle Unterkategorien mit einzubeziehen,
771
     * da Kategorien tief verschachtelt sein können und eventuell erst auf der untersten
772
     * Ebene Artikel enthalten.
773
     *
774
     * @param mixed $start ID der Kategorie, die getestet werden soll
775
     * @return boolen
776
     */
777
    function directoryIsEmpty( $start )
778
    {
779
        static $total_items;
780
        $tree = getNavTree( $start, true );
781
        if ( $tree["Father"] == $_GET["navigation"] )
782
        {
783
            $total_items = 0;
784
        }
785
        $ret = getItems( $start );
786
        $total_items += $ret["total"];
787
        if ( is_array( $tree["childNodes"] ) )
788
        {
789
            foreach ( $tree["childNodes"] as $child )
790
            {
791
                $ret = directoryIsEmpty( $child["ID"] );
792
                $total_items += $ret["total"];
793
            }
794
        }
795
        $empty = ( $total_items ) ? false : true;
796
        return $empty;
797
    }
798
 
799
    /**
800
     * createTranslation2()
801
     *
802
     * ertellt ein Translation2-Objekt
803
     *
804
     * @param mixed $ini
805
     * @return void
806
     */
807
    function createTranslation2( $ini = null )
808
    {
809
        if ( is_null( $ini ) )
810
        {
811
            $ini = $GLOBALS["INI"];
812
        }
813
        if ( !is_array( $ini ) )
814
        {
815
            $ini = $_SESSION["INI"];
816
        }
817
        //if ( __USE_MDB2__ )
818
 
819
        {
820
            $dsn = array( "phptype" => "mysqli", "username" => $ini["dbConnect"]["username"],
821
                "password" => $ini["dbConnect"]["password"], "hostspec" => $ini["dbConnect"]["server"],
822
                "database" => $ini["dbConnect"]["database"], "new_link" => true, );
823
            $params = array( 'langs_avail_table' => 'i18n_langs', 'lang_id_col' =>
824
                'id', 'lang_name_col' => 'name', 'lang_meta_col' => 'meta',
825
                'lang_errmsg_col' => 'error_text', 'lang_encoding_col' =>
826
                'encoding', 'strings_default_table' => 'i18n_%s',
827
                //'%s' will be replaced by the lang code
828
                'string_id_col' => 'id', 'string_page_id_col' => 'page_id',
829
                'string_page_id_col_length' => 255, // db field size
830
                'string_text_col' => 'string' );
831
            $GLOBALS["lang"] = Translation2::factory( "mdb2", $dsn, $params );
832
            if ( PEAR::isError( $GLOBALS["lang"] ) )
833
            {
834
                trigger_error( "Keine Verbindung zur Datenbank möglich!\n",
835
                    E_USER_ERROR );
836
            }
837
        }
838
        if ( !isset( $_SESSION["sprache"] ) )
839
        {
840
            $_SESSION["sprache"] = strtolower( $ini["language"] );
841
        }
842
 
843
        require_once "module/shop/language/index.php";
844
    }
845
 
846
    /**
847
     * createSmarty()
848
     *
849
     * erstellt ein Smarty-Objekt (abgeleitet von der Klasse Weban_Smarty, damit
850
     * auch die Plugins im Unterverzeichnis "weban" zur Verfügung stehen)
851
     *
852
     * @return void
853
     */
854
    function createSmarty()
855
    {
856
        $GLOBALS["ui"] = new Weban_Smarty();
857
        if ( USE_SMARTY_PAGINATE === true )
858
        {
859
            require_once "smarty/SmartyPaginate.class.php";
860
            if ( !$_GET["start"] )
861
            {
862
                SmartyPaginate::reset();
863
            }
864
            SmartyPaginate::setURLVar( 'start' );
865
            SmartyPaginate::setLimit( 20 );
866
            SmartyPaginate::connect();
867
            if ( USE_TRANSLATION2 === true )
868
            {
869
                $prev_text = $GLOBALS["langstrings"]["pagination"]["prev"];
870
                $next_text = $GLOBALS["langstrings"]["pagination"]["next"];
871
                $last_text = $GLOBALS["langstrings"]["pagination"]["last"];
872
                $first_text = $GLOBALS["langstrings"]["pagination"]["first"];
873
            }
874
            else
875
            {
876
                $prev_text = "zur&uuml;ck";
877
                $next_text = "weiter";
878
                $last_text = "letzte Seite";
879
                $first_text = "erste Seite";
880
            }
881
            SmartyPaginate::setPrevText( "&#171; $prev_text" );
882
            SmartyPaginate::setNextText( "$next_text &#187;" );
883
            SmartyPaginate::setLastText( "$last_text &#187;&#187;" );
884
            SmartyPaginate::setFirstText( "&#171;&#171; $first_text" );
885
            $qs = $_SERVER["QUERY_STRING"];
886
            $pos = strpos( $qs, "&start=" );
887
            if ( $pos !== false )
888
            {
889
                $qs = substr( $qs, 0, $pos );
890
            }
891
            else
892
            {
893
                $pos = strpos( $qs, "start=" );
894
                if ( $pos !== false )
895
                {
896
                    $qs = substr( $qs, 0, $pos );
897
                }
898
            }
899
            if ( $qs )
900
            {
901
                $extra = "?" . $qs;
902
            }
903
            SmartyPaginate::setURL( $_SERVER['PHP_SELF'] . $extra );
904
            SmartyPaginate::connect();
905
        }
906
        $GLOBALS["ui"]->setTemplatedir( array( "templates/default/" ) );
907
        $GLOBALS["ui"]->setCompileDir( "templates_c/default/" );
908
        $GLOBALS["ui"]->setCacheDir( "cache/default/" );
909
    }
910
    /**
911
     * init_shop()
912
     *
913
     * initialisiert den Shop mit all seinen Parametern (z. B. Smarty und Translation2)
914
     *
915
     * @param string $type Typ der zu nutzenden Konfiguration (Default: INI)
916
     * @return void
917
     */
918
    function init_shop( $type = "INI", $domain = __SITE__ )
919
    {
920
        $GLOBALS["INI"] = getConfig( $type );
921
 
922
        $GLOBALS["Eigenschaften"] = getVersandEigenschaften( $domain );
923
 
924
        $GLOBALS["web_rechte"] = getWebRechte( $domain );
925
 
926
        $GLOBALS["gesprerte_felder"] = array();
927
        if ( isset( $GLOBALS["web_rechte"]["online_shop"]["artikel"]["artikel_klonen"] ) )
928
        {
929
            $GLOBALS["gesperrte_felder"] = explode( ";", $GLOBALS["web_rechte"]["online_shop"]["artikel"]["artikel_klonen"] );
930
        }
931
 
932
        dbConnect();
933
        if ( USE_TRANSLATION2 === true )
934
        {
935
            createTranslation2();
936
        }
937
        if ( USE_SMARTY === true )
938
        {
939
            createSmarty();
940
        }
941
        if ( USE_LOGGING === true )
942
        {
943
            define( "LOG_PATH", "/etc/shop_logs/" . __SITE__ . "/" . __SHOP__ .
944
                "/" );
945
            if ( !defined( "LOG_FILE" ) )
946
            {
947
                define( "LOG_FILE", LOG_PATH . $domain . "_error.log" );
948
            }
949
            createLogger();
950
            PEAR::setErrorHandling( PEAR_ERROR_CALLBACK, "errorHandlerGlobal" );
951
        }
952
    }
953
 
954
    function getWebRechte( $site = __SITE__ )
955
    {
956
        if ( !$GLOBALS["db_red"] instanceof MDB2_Driver_Common )
957
        {
958
            _createDBRed();
959
        }
960
        $web_rechte = array();
961
        $query = "SELECT
962
                m.interner_name m_name,
963
                t.button_name t_name,
964
                p.interner_name p_name,
965
                wp.Bezeichnung wp_name
966
            FROM
967
                content_management.webs w,
968
                content_management.webs_properties wp,
969
                content_management.properties p,
970
                content_management.tools t,
971
                content_management.modules m
972
            WHERE
973
                w.domain='$site'
974
            AND
975
                wp.webs=w.ID
976
            AND
977
                wp.properties=p.ID
978
            AND
979
                p.tools = t.ID
980
            AND
981
                t.modules = m.ID
982
            ORDER BY
983
                p.Rang
984
        ";
985
        /*$result = mysql_query( $query ) or die( mysql_errno() . ": " .
986
        mysql_error() . "<hr>$query<hr>" );
987
        while ( $zeile = mysql_fetch_assoc( $result ) )*/
988
        $res = $GLOBALS["db_red"]->query( $query );
989
        while ( $zeile = $res->fetchRow() )
990
        {
991
            if ( !$zeile["wp_name"] )
992
            {
993
                $zeile["wp_name"] = "";
994
            }
995
            $zeile["wp_name"] = explode( "|", $zeile["wp_name"] );
996
 
997
            if ( count( $zeile["wp_name"] ) == 1 )
998
            {
999
                $zeile["wp_name"] = $zeile["wp_name"][0];
1000
            }
1001
 
1002
            $web_rechte[$zeile["m_name"]][$zeile["t_name"]][$zeile["p_name"]] =
1003
                $zeile["wp_name"];
1004
        }
1005
 
1006
        foreach ( array_keys( $web_rechte ) as $a )
1007
        {
1008
            foreach ( array_keys( $web_rechte[$a] ) as $b )
1009
            {
1010
                foreach ( array_keys( $web_rechte[$a][$b] ) as $c )
1011
                {
1012
                    if ( is_array( $web_rechte[$a][$b][$c] ) )
1013
                    {
1014
                        $web_rechte[$a][$b][$c] = $web_rechte[$a][$b][$c][array_search( $GLOBALS["INI"]["language"],
1015
                            array_keys( $web_rechte["online_shop"]["language"] ) )];
1016
                        if ( $web_rechte[$a][$b][$c] == "./." )
1017
                        {
1018
                            unset( $web_rechte[$a][$b][$c] );
1019
                        }
1020
                    }
1021
                }
1022
            }
1023
        }
1024
        unset( $query );
1025
        unset( $result );
1026
        unset( $zeile );
1027
        return $web_rechte;
1028
    }
1029
 
1030
    function _createDBRed()
1031
    {
1032
        $opts = array( "persistent" => true, "portability" =>
1033
            MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL );
1034
        $dsn_red = array( "phptype" => "mysqli", "username" => "admin",
1035
            "password" => "EW-ad-1055", "hostspec" => "localhost", "database" =>
1036
            "content_management", "new_link" => true, );
1037
        $GLOBALS["db_red"] = MDB2::connect( $dsn_red, $opts );
1038
        if ( PEAR::isError( $GLOBALS["db_red"] ) )
1039
        {
1040
            trigger_error( "Keine Verbindung zur Datenbank möglich!\n" . $GLOBALS["db_red"]->
1041
                getUserInfo(), E_USER_ERROR );
1042
        }
1043
        $GLOBALS["db_red"]->setfetchMode( MDB2_FETCHMODE_ASSOC );
1044
    }
1045
 
1046
    function getAHersteller()
1047
    {
1048
        $ret = array( "0" => "--- Bitte w&auml;hlen ---" );
1049
        $sql = "SELECT DISTINCT
1050
                id,
1051
                name
1052
            FROM
1053
                Herstellerkatalog
1054
            ORDER BY
1055
                name
1056
        ";
1057
        if ( USE_MDB2 === true )
1058
        {
1059
            $res = $GLOBALS["db"]->Query( $sql );
1060
            while ( $row = $res->FetchRow() )
1061
            {
1062
                $ret[$row["id"]] = $row["name"];
1063
            }
1064
        }
1065
        else
1066
        {
1067
            $res = mysql_Query( $sql );
1068
            while ( $row = mysql_fetch_assoc( $res ) )
1069
            {
1070
                $ret[$row["id"]] = $row["name"];
1071
            }
1072
        }
1073
        return $ret;
1074
    }
1075
 
1076
    function getAType( $hersteller )
1077
    {
1078
        $ret = array( "0" => "--- Bitte w&auml;hlen ---" );
1079
        $sql = "SELECT DISTINCT
1080
                namenserweiterung
1081
            FROM
1082
                artikel
1083
            WHERE
1084
                hersteller=$hersteller
1085
        ";
1086
        if ( USE_MDB2 === true )
1087
        {
1088
            $res = $GLOBALS["db"]->Query( $sql );
1089
            while ( $row = $res->FetchRow() )
1090
            {
1091
                $ret[urlencode( $row["namenserweiterung"] )] = $row["namenserweiterung"];
1092
            }
1093
        }
1094
        else
1095
        {
1096
            $res = mysql_Query( $sql );
1097
            while ( $row = mysql_fetch_assoc( $res ) )
1098
            {
1099
                $ret[urlencode( $row["namenserweiterung"] )] = $row["namenserweiterung"];
1100
            }
1101
        }
1102
        return $ret;
1103
    }
1104
 
1105
    function getAModel( $hersteller, $type )
1106
    {
1107
        $ret = array( "0" => "--- Bitte w&auml;hlen ---" );
1108
        $sql = "SELECT DISTINCT
1109
                kurzbezeichnung,
1110
                id
1111
            FROM
1112
                artikel
1113
            WHERE
1114
                hersteller=$hersteller
1115
            AND
1116
                namenserweiterung='$type'
1117
        ";
1118
        if ( USE_MDB2 === true )
1119
        {
1120
            $res = $GLOBALS["db"]->Query( $sql );
1121
            while ( $row = $res->FetchRow() )
1122
            {
1123
                $ret[$row["id"]] = $row["kurzbezeichnung"];
1124
            }
1125
        }
1126
        else
1127
        {
1128
            $res = mysql_Query( $sql );
1129
            while ( $row = mysql_fetch_assoc( $res ) )
1130
            {
1131
                $ret[$row["id"]] = $row["kurzbezeichnung"];
1132
            }
1133
        }
1134
        return $ret;
1135
    }
1136
 
1137
    function IPtoCountry( $IP )
1138
    {
1139
        $land = "Unbekannt";
1140
        $IP = sprintf( "%u", IP2Long( $IP ) );
1141
        $sql = "SELECT
1142
                name
1143
            FROM
1144
                content_management.IPtoCountry
1145
            WHERE
1146
                IP_from <= $IP
1147
            AND
1148
                IP_to >= $IP
1149
            LIMIT 1
1150
        ";
1151
        if ( $IP !== false )
1152
        {
1153
            $result = mysql_query( $sql, $GLOBALS["dbh"] );
1154
 
1155
            if ( mysql_num_rows( $result ) )
1156
            {
1157
                $row = mysql_fetch_object( $result );
1158
                $land = $row->name;
1159
            }
1160
 
1161
        }
1162
        return $land;
1163
    }
1164
 
1165
    function getGutschein()
1166
    {
1167
        if ( $GLOBALS["INI"]["modules"]["gutschein"] == 1 )
1168
        {
1169
            $sql = "SELECT
1170
                    *
1171
                FROM
1172
                    artikel
1173
                WHERE
1174
                    Father = -5
1175
            ";
1176
            $res = mysql_query( $sql );
1177
            while ( $row = mysql_fetch_assoc( $res ) )
1178
            {
1179
                $buffer[] = itemKorrektur( $row );
1180
                $total++;
1181
            }
1182
            return $buffer;
1183
        }
1184
    }
1185
 
1186
    function list_orders()
1187
    {
1188
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1189
        {
1190
            $db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1191
        }
1192
        $table = $db . "Bestellung b";
1193
        $p_table = $db . "bestellung_paketnummern bp";
1194
        $sql = "SELECT
1195
                b.ID,
1196
        ";
1197
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bezahlstatus"]["bezahlstatus"] ) )
1198
        {
1199
            $sql .= "
1200
                    b.bezahlt,
1201
                ";
1202
        }
1203
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1204
        {
1205
            $sql .= "
1206
                    c.locale,
1207
                ";
1208
        }
1209
        $sql .= "
1210
                b.erstellt_am,
1211
                b.gesamtsumme_buffer
1212
            FROM
1213
        ";
1214
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1215
        {
1216
            $sql .= "
1217
                    currencies c,
1218
                ";
1219
        }
1220
        $sql .= "
1221
                $table
1222
            WHERE
1223
                login=" . $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] . "
1224
        ";
1225
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1226
        {
1227
            $sql .= "
1228
                    AND
1229
                        c.id=b.currency
1230
                ";
1231
        }
1232
        $sql .= "
1233
            ORDER BY
1234
                erstellt_am DESC
1235
        ";
1236
 
1237
        $res = mysql_query( $sql );
1238
        if ( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["tracking"] )
1239
        {
1240
            list( $beschreibung, $link ) = explode( ";", $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["tracking"] );
1241
        }
1242
        while ( $row = mysql_fetch_assoc( $res ) )
1243
        {
1244
            $sql_p = "SELECT
1245
                    *
1246
                FROM
1247
                    $p_table
1248
                WHERE
1249
                    Bestellung=" . $row["ID"] . "
1250
            ";
1251
 
1252
            $res_p = mysql_query( $sql_p );
1253
            while ( $row_p = mysql_fetch_assoc( $res_p ) )
1254
            {
1255
                $row["tracking"][] = $link . $row_p["paketnummer"];
1256
                $row["versanddatum"][] = $row_p["datum"];
1257
            }
1258
            $rows[] = $row;
1259
        }
1260
        return $rows;
1261
    }
1262
 
1263
 
1264
 
1265
    function list_addresses()
1266
    {
1267
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1268
        {
1269
            $db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1270
        }
1271
        $table = $db . "adresse a";
1272
        $c_table = $db . "countries c";
1273
        $sql = "SELECT
1274
                a.*,
1275
                c.id as country,
1276
                c.country as land,
1277
                CONCAT(s.name,' (',s.short,')') as state_name
1278
            FROM
1279
                $table
1280
            JOIN
1281
                $c_table
1282
            ON
1283
                c.id=a.land
1284
            LEFT OUTER JOIN
1285
                states s
1286
            ON
1287
                s.id=a.state
1288
            WHERE
1289
                logins_id=" . $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] . "
1290
        ";
1291
        $res = mysql_query( $sql );
1292
        while ( $row = mysql_fetch_assoc( $res ) )
1293
        {
1294
            foreach ( $row as $feld => $wert )
1295
            {
1296
                $row[$feld] = utf8_encode( $wert );
1297
            }
1298
            $data[] = $row;
1299
        }
1300
        return $data;
1301
    }
1302
    function get_address( $id )
1303
    {
1304
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1305
        {
1306
            $db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1307
        }
1308
        $table = $db . "adresse a";
1309
        $c_table = $db . "countries c";
1310
        $sql = "SELECT
1311
                a.*,
1312
                c.id as country,
1313
                c.country as land
1314
            FROM
1315
                $table
1316
            JOIN
1317
                $c_table
1318
            ON
1319
                c.id=a.land
1320
            WHERE
1321
                a.id=$id
1322
        ";
1323
        $res = mysql_query( $sql );
1324
        $row = mysql_fetch_assoc( $res );
1325
        foreach ( $row as $feld => $wert )
1326
        {
1327
            $row[$feld] = utf8_encode( $wert );
1328
            $row["state_name"] = getStateById( $row["state"] );
1329
        }
1330
        return $row;
1331
    }
1332
    function change_pw()
1333
    {
1334
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1335
        {
1336
            $table = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1337
        }
1338
        $table .= "Logins";
1339
        $sql = "
1340
            UPDATE
1341
                $table
1342
            SET
1343
                passwd='" . md5( $_POST["new_pw"] ) . "'
1344
            WHERE
1345
                ID='" . mysql_real_escape_string( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) .
1346
            "'
1347
        ";
1348
        $res = mysql_query( $sql );
1349
        if ( !$res )
1350
        {
1351
            $msg = "Passwort wurde erfolgreich geändert!";
1352
        }
1353
        else
1354
        {
1355
            $msg = "Konnte Passwort nicht ändern!<br>Bitte versuchen Sie es später noch einmal!";
1356
        }
1357
        return $msg;
1358
    }
1359
 
1360
    function view_order( $id )
1361
    {
1362
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1363
        {
1364
            $db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1365
        }
1366
        $ab_table = $db . "artikel_to_Bestellung ab";
1367
        $b_table = $db . "Bestellung b";
1368
        $a_table = "artikel a";
1369
        $sql = "SELECT
1370
                b.ID,
1371
                b.erstellt_am,
1372
                b.letzte_aenderung_am,
1373
        ";
1374
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1375
        {
1376
            $sql .= "
1377
                    c.locale,
1378
                ";
1379
        }
1380
        $sql .= "
1381
                b.letzte_aenderung_von
1382
            FROM
1383
                $b_table,
1384
        ";
1385
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1386
        {
1387
            $sql .= "
1388
                        currencies c,
1389
                ";
1390
        }
1391
        $sql .= "
1392
                $ab_table
1393
            JOIN
1394
                $a_table
1395
            ON
1396
                a.ID=ab.artikel
1397
            WHERE
1398
                b.ID = $id
1399
            AND
1400
                ab.Bestellung=b.ID
1401
        ";
1402
        if ( isset( $GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["waehrung"] ) )
1403
        {
1404
            $sql .= "
1405
            AND
1406
                c.id=b.currency
1407
        ";
1408
        }
1409
        $res = mysql_query( $sql );
1410
        $row = mysql_fetch_assoc( $res );
1411
        $sql = "SELECT
1412
                ab.*,
1413
                a.kennung,
1414
                a.kurzbezeichnung,
1415
                a.Father,
1416
                Menge * Preis_pro_Stueck AS gesamtpreis
1417
            FROM
1418
                $ab_table
1419
            JOIN
1420
                $a_table
1421
            ON
1422
                a.ID=ab.artikel
1423
            WHERE
1424
                ab.Bestellung=$id
1425
        ";
1426
        $res = mysql_query( $sql );
1427
        while ( $ab_row = mysql_fetch_assoc( $res ) )
1428
        {
1429
            if ( $ab_row["Father"] == -3 )
1430
            {
1431
                $item = getItem( $ab_row["artikel"], false, true );
1432
            }
1433
            else
1434
            {
1435
                $item = getItem( $ab_row["artikel"] );
1436
            }
1437
            $ab_row["Bezeichnung"] = trim( $ab_row["Bezeichnung"] );
1438
            $ab_row["itemLink"] = $item["itemLink"];
1439
            $ab_row["father"] = $item["Father"];
1440
            $row["items"][] = $ab_row;
1441
        }
1442
        return $row;
1443
    }
1444
 
1445
    function admin_debug( $var )
1446
    {
1447
        if ( IS_WEBAN === true )
1448
        {
1449
            echo "<br />Admin-Debug:";
1450
            if ( php_sapi_name() == "cli" )
1451
            {
1452
                echo "\r\n";
1453
            }
1454
            else
1455
            {
1456
                echo "<br>";
1457
            }
1458
            var_dump( $var );
1459
        }
1460
    }
1461
 
1462
    /**
1463
     * gen_password()
1464
     *
1465
     * generiert ein Passwort für das Kundenlogin
1466
     *
1467
     * @param integer $length
1468
     * @param string $type
1469
     * @param string $chars
1470
     * @return string das generierte Passwort
1471
     */
1472
    function gen_password( $length = 8, $type = "unpronounceable", $chars = "" )
1473
    {
1474
        $pw = Text_Password::create( $length, $type, $chars );
1475
        return $pw;
1476
    }
1477
 
1478
    function check_user_list()
1479
    {
1480
        $ids = "";
1481
        $id_arr = array();
1482
        if ( $GLOBALS["INI"]["uses_order_db"] == 1 )
1483
        {
1484
            $db = $GLOBALS["INI"]["dbConnect"]["order_db"] . ".";
1485
        }
1486
        $table = $db . "Logins_to_Verteiler";
1487
        $l_table = $db . "Logins";
1488
        //$ret = true;
1489
        if ( $GLOBALS["INI"]["modules"]["login"] == 1 && $_SESSION["SHOP"]["Login"] )
1490
        {
1491
            $ids = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
1492
        }
1493
        else
1494
        {
1495
            $sql = "SELECT
1496
                    id
1497
                FROM
1498
                    $l_table
1499
                WHERE
1500
                    E_Mail='" . $_SESSION["SHOP"]["buy"]["Persdata"]["email"] .
1501
                "'
1502
            ";
1503
            $res = mysql_query( $sql );
1504
            if ( $res )
1505
            {
1506
                while ( $row = mysql_fetch_assoc( $res ) )
1507
                {
1508
                    $id_arr[] = $row["id"];
1509
                }
1510
                $ids = implode( ",", $id_arr );
1511
            }
1512
        }
1513
        if ( $ids )
1514
        {
1515
            $sql = "SELECT
1516
                    *
1517
                FROM
1518
                    $table
1519
                WHERE
1520
                    Logins IN (" . $ids . ")
1521
                AND
1522
                    Verteiler = " . $GLOBALS["INI"]["modules"]["mailverteiler_id"] .
1523
                "
1524
            ";
1525
            $res = mysql_query( $sql );
1526
            if ( $res )
1527
            {
1528
                $ret = !mysql_num_rows( $res );
1529
            }
1530
        }
1531
        else
1532
        {
1533
            $ret = true;
1534
        }
1535
        return $ret;
1536
    }
1537
 
1538
    function getPagesCommon()
1539
    {
1540
        $sql = "SELECT DISTINCT
1541
                page_id
1542
            FROM
1543
                i18n_de
1544
        ";
1545
        if ( __USE_MDB2__ === true )
1546
        {
1547
            $res = $GLOBALS["db"]->query( $sql );
1548
            while ( $row = $res->FetchRow() )
1549
            {
1550
                $pages[] = $row["page_id"];
1551
            }
1552
        }
1553
        else
1554
        {
1555
            $res = mysql_query( $sql );
1556
            while ( $row = mysql_fetch_assoc( $res ) )
1557
            {
1558
                $pages[] = $row["page_id"];
1559
            }
1560
        }
1561
        return $pages;
1562
    }
1563
 
1564
    function getCurrencies( $format = "name" )
1565
    {
1566
        if ( $format == "array" )
1567
        {
1568
            $column = "name, full_name, locale";
1569
        }
1570
        else
1571
        {
1572
            $column = "id, $format";
1573
        }
1574
        $sql = "SELECT
1575
                $column
1576
            FROM
1577
                currencies
1578
        ";
1579
        $res = mysql_query( $sql );
1580
        while ( $row = mysql_fetch_assoc( $res ) )
1581
        {
1582
            if ( $format == "array" )
1583
            {
1584
                $ret[] = $row;
1585
            }
1586
            else
1587
            {
1588
                $ret[$row["id"]] = $row[$format];
1589
            }
1590
        }
1591
        return $ret;
1592
    }
1593
 
1594
    function getLandData()
1595
    {
1596
        $sql = "SELECT
1597
                *
1598
            FROM
1599
                countries
1600
            WHERE
1601
                id=" . $_SESSION["country"] . "
1602
        ";
1603
        $res = mysql_query( $sql );
1604
        $row = mysql_fetch_assoc( $res );
1605
        return $row;
1606
    }
1607
 
1608
    /**
1609
     * getStateById()
1610
     *
1611
     * @param mixed $id
1612
     * @return
1613
     */
1614
    function getStateById( $id )
1615
    {
1616
        $sql = "SELECT
1617
                *
1618
            FROM
1619
                states
1620
            WHERE
1621
                id=$id
1622
        ";
1623
 
1624
        if ( $q = mysql_query( $sql ) )
1625
        {
1626
            if ( $r = mysql_fetch_assoc( $q ) )
1627
            {
1628
                return utf8_encode( $r['name'] . " (" . $r["short"] . ")" );
1629
            }
1630
        }
1631
        return false;
1632
    }
1633
 
1634
    /**
1635
     * getEULabel()
1636
     *
1637
     * liest die nach dem neuen Verfahren gespeicherten EU-Energielabels aus
1638
     *
1639
     * @param mixed $item Artikelnummer für die das Energielabel gelesen werden soll
1640
     * @return
1641
     */
1642
    function getEULabel( $item )
1643
    {
1644
        $sql = "SELECT
1645
                aa.wert,
1646
                a.name,
1647
                a.type,
1648
                a.eu_label_id,
1649
                a.einheit,
1650
                da.wertebereich
1651
            FROM
1652
                artikel_to_auspraegung aa
1653
            LEFT JOIN
1654
                auspraegung a
1655
            ON
1656
                a.id=aa.auspraegung
1657
            LEFT JOIN
1658
                directory_to_auspraegung da
1659
            ON
1660
                da.auspraegung=a.id
1661
            WHERE
1662
                artikel=$item
1663
            AND
1664
                eu_label_id IS NOT NULL
1665
        ";
1666
        $res = mysql_query( $sql );
1667
        while ( $row = mysql_fetch_assoc( $res ) )
1668
        {
1669
            $row["wertebereich"] = unserialize( $row["wertebereich"] );
1670
            $erg[] = $row;
1671
        }
1672
        return $erg;
1673
    }
1674
 
1675
    function getAuspraegungInfos( $a_id )
1676
    {
1677
        $sql = "SELECT
1678
                *
1679
            FROM
1680
                directory_to_auspraegung
1681
            WHERE
1682
                auspraegung=$a_id
1683
        ";
1684
        $res = mysql_query( $sql );
1685
        $row = mysql_fetch_assoc( $res );
1686
        if ( $row["wertebereich"] )
1687
        {
1688
            $row["wertebereich"] = unserialize( $row["wertebereich"] );
1689
        }
1690
        return $row;
1691
    }
1692
 
1693
    function table_exists( $table, $db )
1694
    {
1695
        $tables = mysql_list_tables( $db );
1696
        while ( list( $temp ) = mysql_fetch_array( $tables ) )
1697
        {
1698
            if ( $temp == $table )
1699
            {
1700
                return true;
1701
            }
1702
        }
1703
        return false;
1704
    }
1705
 
1706
    require_once "weban/weban_utils.class.php";
1707
?>