Subversion-Projekte lars-tiefland.ci

Revision

Revision 2011 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
528 lars 1
<?php
2
 
3
// $Id: weban_helper.php 2117 2017-11-11 20:56:38Z lars $
4
 
2117 lars 5
if (!defined("CONTINUE_ON_ERROR")) {
6
    define("CONTINUE_ON_ERROR", false);
2004 lars 7
}
2117 lars 8
if (!defined("CRON")) {
9
    if (php_sapi_name() == "cli") {
10
        define("CRON", true);
11
    } else {
12
        define("CRON", false);
13
    }
2004 lars 14
}
2003 lars 15
 
2117 lars 16
if (!defined("EOL")) {
17
    if (php_sapi_name() == "cli") {
18
        define("EOL", "\n");
19
    } else {
20
        define("EOL", "<br>");
21
    }
2004 lars 22
}
696 lars 23
$GLOBALS['ci'] = &get_instance();
2117 lars 24
$GLOBALS['order_db'] = $GLOBALS['ci']->load->database('order_db', true);
25
$GLOBALS['db_red'] = $GLOBALS['ci']->load->database('db_red', true);
711 lars 26
$GLOBALS['ci']->load->model('artikel_model', 'artikel');
2003 lars 27
$domain = "faltradxxs.de";
28
$GLOBALS["Eigenschaften"] = getVersandEigenschaften($domain);
29
$GLOBALS["web_rechte"] = getWebRechte($domain);
30
isWeban();
694 lars 31
 
528 lars 32
$GLOBALS["zahlsysteme"] = array(
2117 lars 33
    "kreditkarte",
34
    "paypal",
35
    "sofortueberweisung",
36
    "frei",
37
    "finanzierung",
38
    "billsafe",
39
    "billsafe_hire",
40
    "amazon",
41
    "PayPalExpress",
42
    "Ratenzahlung",
43
    "PayPalPlus",
44
    "paymill",
45
    );
528 lars 46
 
47
//Excellence Käuferschutz
48
$GLOBALS["tsItems"] = array(
2117 lars 49
    "TS080501_500_30_EUR" => array(
50
        "max" => 500,
51
        "preis" => 0.82353,
52
        ),
53
    "TS080501_1500_30_EUR" => array(
54
        "max" => 1500,
55
        "preis" => 2.47059,
56
        ),
57
    "TS080501_2500_30_EUR" => array(
58
        "max" => 2500,
59
        "preis" => 4.11765,
60
        ),
61
    "TS080501_5000_30_EUR" => array(
62
        "max" => 5000,
63
        "preis" => 8.23530,
64
        ),
65
    "TS080501_1000_30_EUR" => array(
66
        "max" => 1000,
67
        "preis" => 16.47060,
68
        ),
69
    "TS080501_20000_30_EUR" => array(
70
        "max" => 20000,
71
        "preis" => 31.94120,
72
        ),
73
    );
528 lars 74
 
75
$GLOBALS["tsMethods"] = array(
2117 lars 76
    "paypal" => "PAYPAL",
77
    "PayPalPlus" => "PAYPAL",
78
    "billsafe" => "INVOICE",
79
    "nachnahme" => "CASH_ON_DELIVERY",
80
    "kreditkarte" => "CREDIT_CARD",
81
    "selbstabholung" => "CASH_ON_PICKUP",
82
    "sofortueberweisung" => "DIECT_E_BANKING",
83
    "vorkasse" => "PREPAYMENT",
84
    );
528 lars 85
//Excellence Käuferschutz - ENDE
86
 
87
/**
88
 * @author Lars Tiefland
89
 * @copyright 2016
90
 */
91
 
92
function getVersandLaender()
93
{
2117 lars 94
    // ME: Länder raus, und die bit-Schiebeoperation ungestört durchzählen lasssen
95
    // LT: für Smarty umgebaut
96
    $forbiddenLands = array();
97
    if (table_exists("bestelladresse", $GLOBALS["INI"]["dbConnect"]["order_db"]) &&
98
        $GLOBALS["INI"]["modules"]["adresssystem"] == "neu") {
99
        $old = false;
100
        if (table_exists("shippinggroups")) {
101
            $cTable = "countries";
102
            $cField = "`name-ger";
103
            $coTable = "cotinents";
104
            $coField = "name_de";
105
            if (table_exists("countries")) {
106
                $cField = "country";
107
                $cTable = $GLOBALS["INI"]["dbConnect"]["database"] . "." . $cTable;
108
                $coTable = "";
109
                $coField = "continent";
110
            }
111
            $sql = "SELECT
528 lars 112
                        c.id,
113
                        c.shipping,
2117 lars 114
                        " . $coField . " AS continent,
115
                        c." . $cField . " AS country
528 lars 116
                    FROM
2117 lars 117
                        " . $cTable . " c
528 lars 118
                    JOIN
2117 lars 119
                        " . $GLOBALS["INI"]["dbConnect"]["database"] .
120
                ".shippinggroups sg
528 lars 121
                    ON
122
                        sg.id = c.shipping
123
                ";
2117 lars 124
            if ($coTable) {
125
                $sql .= "
528 lars 126
                        JOIN
2117 lars 127
                            " . $coTable . "
528 lars 128
                        ON
129
                            co.id=c.continent
130
                    ";
2117 lars 131
            }
132
        } else {
133
            $old = true;
134
            $sql = "SELECT
528 lars 135
					id,
136
					weban_lcode,
137
					`name-ger` AS country
138
				FROM
139
					content_management.countries
140
				WHERE
141
					weban_lcode!=''
142
			";
2117 lars 143
        }
144
        $res = $GLOBALS["db_red"]->query($sql);
145
        while ($row = $res->unbuffered_row('array')) {
146
            $land_name = $row["country"];
147
            if (!in_array($land_name, $forbiddenLands)) {
148
                if ($old === true) {
149
                    $land = $row["weban_lcode"];
150
                    $gewicht = 0;
151
                    $preis = 0;
152
                    if (isset($_SESSION['SHOP']['SUMME']) && $_SESSION['SHOP']['SUMME']) {
153
                        $preis = $_SESSION['SHOP']['SUMME'];
154
                    }
155
                    // gibt es für dieses Land Versandoptionen?
156
                    $sql = "SELECT
528 lars 157
                                ID
158
                            FROM
159
                                artikel
160
                            WHERE
2117 lars 161
                                Lieferstatus & " . $land . " = " . $land . "
528 lars 162
                            AND
163
                                Father=-3
164
                            AND
2117 lars 165
                                status = " . $GLOBALS['INI']['shops_ID'] . "
528 lars 166
                        ";
167
 
2117 lars 168
                    if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"])) {
169
                        $sql .= "
528 lars 170
                                AND
171
                                (
2117 lars 172
                                    (" . $gewicht .
173
                            " between preis_neu1 and preis_neu2)
528 lars 174
                                )
175
                                AND
176
                                (
2117 lars 177
                                    (" . $preis .
178
                            " BETWEEN preis_neu3 AND preis_neu4)
528 lars 179
                                    OR
180
                                    (preis_neu3=preis_neu4)
181
                                )
182
                            ";
2117 lars 183
                    }
184
                    if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"])) {
185
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
186
                            if (Eigenschaft($nr) == true) {
187
                                $sql .= " AND Eigenschaft_$nr = 1 ";
188
                            } else {
189
                                $sql .= "
528 lars 190
                                        AND
191
                                        (
192
                                            (Eigenschaft_$nr = 0)
193
                                            OR
194
                                            (Eigenschaft_$nr IS NULL)
195
                                        )
196
                                    ";
2117 lars 197
                            }
198
                        }
199
                    }
528 lars 200
 
201
 
2117 lars 202
                    $q = $GLOBALS['ci']->db->query($sql);
203
                    if ($q) {
204
                        $n = $q->row_array();
205
                        if ($n) {
206
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["db_is_utf8"] !=
207
                                1) {
208
                                $land_name = utf8_encode($land_name);
209
                            }
210
                            $laender[$row["id"]] = $land_name;
211
                        }
212
                    }
213
                } else {
214
                    $continent = $row["continent"];
215
                    $sql = "SELECT
528 lars 216
                                ID
217
                            FROM
218
                                artikel
219
                            WHERE
2117 lars 220
                                kennung =  " . $row["shipping"] . "
528 lars 221
                            AND
222
                                Father=-3
223
                            AND
2117 lars 224
                                status = " . $GLOBALS['INI']['shops_ID'] . "
528 lars 225
                        ";
226
 
2117 lars 227
                    if (count($_SESSION["SHOP"]["BASKET"])) {
228
                        $sql .= "
528 lars 229
                                AND
230
                                (
2117 lars 231
                                    (" . $gewicht .
232
                            " between preis_neu1 and preis_neu2)
528 lars 233
                                )
234
                                AND
235
                                (
2117 lars 236
                                    (" . $preis .
237
                            " BETWEEN preis_neu3 AND preis_neu4)
528 lars 238
                                    OR
239
                                    (preis_neu3=preis_neu4)
240
                                )
241
                            ";
2117 lars 242
                    }
243
                    if (count($_SESSION["SHOP"]["BASKET"])) {
244
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
245
                            if (Eigenschaft($nr) == true) {
246
                                $sql .= " AND Eigenschaft_$nr = 1 ";
247
                            } else {
248
                                $sql .= "
528 lars 249
                                        AND
250
                                        (
251
                                            (Eigenschaft_$nr = 0)
252
                                            OR
253
                                            (Eigenschaft_$nr IS NULL)
254
                                        )
255
                                    ";
2117 lars 256
                            }
257
                        }
258
                    }
528 lars 259
 
260
 
2117 lars 261
                    $q = mysql_query($sql);
262
                    if ($q) {
263
                        $n = mysql_num_rows($q);
264
                        if ($n) {
265
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["order_db_is_utf8"] !=
266
                                1) {
267
                                $land_name = utf8_encode($land_name);
268
                                $continent = utf8_encode($continent);
269
                            }
270
                            $laender[$continent][$row["id"]] = $land_name;
271
                        }
272
                    }
273
                }
274
            }
275
        }
276
    } else {
277
        for ($i = 0; $i < 64; $i++) {
528 lars 278
 
2117 lars 279
            $land = 1 << $i;
528 lars 280
 
2117 lars 281
            $land_name = getCountryById($land);
528 lars 282
 
2117 lars 283
            if ($land_name) {
528 lars 284
 
2117 lars 285
                if (!in_array($land_name, $forbiddenLands)) {
286
                    $gewicht = getBasketGewicht();
287
                    $preis = getBasketSumme();
528 lars 288
 
2117 lars 289
                    // gibt es für dieses Land Versandoptionen?
290
                    $sql = "SELECT
528 lars 291
                                ID
292
                            FROM
293
                                artikel
294
                            WHERE
2117 lars 295
                                Lieferstatus & " . $land . " = " . $land . "
528 lars 296
                            AND
297
                                Father=-3
298
                            AND
2117 lars 299
                                status = " . $GLOBALS['INI']['shops_ID'] . "
528 lars 300
                        ";
301
 
2117 lars 302
                    if (count($_SESSION["SHOP"]["BASKET"])) {
303
                        $sql .= "
528 lars 304
                                AND
305
                                (
2117 lars 306
                                    (" . $gewicht .
307
                            " between preis_neu1 and preis_neu2)
528 lars 308
                                )
309
                                AND
310
                                (
2117 lars 311
                                    (" . $preis .
312
                            " BETWEEN preis_neu3 AND preis_neu4)
528 lars 313
                                    OR
314
                                    (preis_neu3=preis_neu4)
315
                                )
316
                            ";
2117 lars 317
                    }
318
                    if (count($_SESSION["SHOP"]["BASKET"])) {
319
                        foreach ($GLOBALS["Eigenschaften"] as $nr) {
320
                            if (Eigenschaft($nr) == true) {
321
                                $sql .= " AND Eigenschaft_$nr = 1 ";
322
                            } else {
323
                                $sql .= "
528 lars 324
                                        AND
325
                                        (
326
                                            (Eigenschaft_$nr = 0)
327
                                            OR
328
                                            (Eigenschaft_$nr IS NULL)
329
                                        )
330
                                    ";
2117 lars 331
                            }
332
                        }
333
                    }
528 lars 334
 
335
 
2117 lars 336
                    $q = mysql_query($sql);
337
                    if ($q) {
338
                        $n = mysql_num_rows($q);
339
                        if ($n) {
340
                            $shopsNoEncode = array(
341
                                "ababum.de",
342
                                "etoh24.de",
343
                                );
344
                            if ($GLOBALS["INI"]["charset"] == "utf-8" && !in_array(__SHOP__, $shopsNoEncode)) {
345
                                $land_name = utf8_encode($land_name);
346
                            }
347
                            $laender[$land] = ($land_name);
348
                        }
349
                    }
350
                }
351
            }
352
        }
353
    }
354
    if (is_array($laender)) {
355
        $laender = array_unique($laender);
356
    } else {
357
        $laender = array();
358
    }
528 lars 359
 
2117 lars 360
    return $laender;
528 lars 361
}
362
 
363
 
364
function table_exists($table, $db = null, $c = null)
365
{
2117 lars 366
    $ini = $GLOBALS['INI'];
367
    if ($db) {
368
        $db = trim($db, '.');
369
    }
370
    if (!$c) {
371
        $conn = $GLOBALS['order_db'];
372
    } else {
373
        $conn = $c;
374
    }
375
    if (!$db || $db == $ini["dbConnect"]["database"]) {
376
        $db = $ini["dbConnect"]["database"];
377
        if (!$c) {
378
            $conn = $GLOBALS['ci']->db;
379
        } else {
380
            $conn = $c;
381
        }
382
    }
383
    $sql = "SELECT
528 lars 384
            engine
385
        FROM
386
            information_schema.TABLES
387
        WHERE
2117 lars 388
            table_name='" . $table . "'
528 lars 389
        AND
2117 lars 390
            table_schema='" . $db . "'
528 lars 391
    ";
2117 lars 392
    $res = $conn->query($sql);
393
    if ($res->num_rows()) {
394
        return true;
395
    }
396
    return false;
528 lars 397
}
398
 
399
function column_exists($table, $column, $db = null, $c = null)
400
{
2117 lars 401
    $ini = $GLOBALS['INI'];
402
    if ($db) {
403
        $db = trim($db, '.');
404
    }
405
    if (!$c) {
406
        $conn = $GLOBALS['order_db'];
407
    } else {
408
        $conn = $c;
409
    }
410
    if (!$db || $db == $ini["dbConnect"]["database"]) {
411
        $db = $ini["dbConnect"]["database"];
412
        if (!$c) {
413
            $conn = $GLOBALS['ci']->db;
414
        } else {
415
            $conn = $c;
416
        }
417
    }
528 lars 418
 
2117 lars 419
    $t_exists = table_exists($table, $db, $conn);
420
    if ($t_exists) {
421
        $sql = "SELECT
528 lars 422
                    data_type
423
                FROM
424
                    information_schema.COLUMNS
425
                WHERE
2117 lars 426
                    column_name='" . $column . "'
528 lars 427
                AND
2117 lars 428
                    table_name='" . $table . "'
528 lars 429
                AND
2117 lars 430
                    table_schema='" . $db . "'
528 lars 431
            ";
432
 
2117 lars 433
        $res = $conn->query($sql);
434
        if ($res->num_rows()) {
435
            return true;
436
        }
437
        return false;
438
    }
439
    return false;
528 lars 440
}
441
 
442
/**
443
 * getColumnInfo()
444
 *
445
 * Holt Informationen zu einer Spalte (inklusive dem f?r diese Spalte definierten Fremdschl?ssel)
446
 *
447
 * @param mixed $table
448
 * @param mixed $column
449
 * @param mixed $db
450
 * @param mixed $c
451
 * @return
452
 */
453
function getColumnInfo($table, $column, $db = null, $c = null)
454
{
2117 lars 455
    global $remoteServer_dbh, $localhost_dbh;
456
    if (!is_array($_SESSION["INI"])) {
457
        $ini = $GLOBALS["INI"];
458
    } else {
459
        $ini = $_SESSION["INI"];
460
    }
461
    if ($db) {
462
        $db = trim($db, '.');
463
    }
464
    if (!$c) {
465
        if (__USE_MDB2__ === true) {
466
            $conn = $GLOBALS["order_db"];
467
        } elseif (is_resource($GLOBALS["order_dbh"])) {
468
            $conn = $GLOBALS["order_dbh"];
469
        } elseif (is_resource($remoteServer_dbh)) {
470
            $conn = $remoteServer_dbh;
471
        }
472
    } else {
473
        $conn = $c;
474
    }
475
    if (!$db || $db == $ini["dbConnect"]["database"]) {
476
        $db = $ini["dbConnect"]["database"];
477
        if (!$c) {
478
            if (__USE_MDB2__ === true) {
479
                $conn = $GLOBALS["db"];
480
            } elseif (is_resource($GLOBALS["dbh"])) {
481
                $conn = $GLOBALS["dbh"];
482
            } elseif (is_resource($localhost_dbh)) {
483
                $conn = $localhost_dbh;
484
            }
485
        } else {
486
            $conn = $c;
487
        }
488
    }
528 lars 489
 
490
 
2117 lars 491
    if (column_exists($table, $column, $db, $conn)) {
492
        //Hole Informationen zur Spalte
493
        $sql = "SELECT
528 lars 494
                    *
495
                FROM
496
                    information_schema.COLUMNS
497
                WHERE
2117 lars 498
                    column_name='" . $column . "'
528 lars 499
                AND
2117 lars 500
                    table_name='" . $table . "'
528 lars 501
                AND
2117 lars 502
                    table_schema='" . $db . "'
528 lars 503
            ";
504
 
2117 lars 505
        if (__USE_MDB2__ === true) {
506
            $res = $conn->query($sql);
507
            if ($res->numRows()) {
508
                $row = $res->fetchRow();
509
            }
510
        } else {
511
            $res = mysql_query($sql, $conn);
512
            if (mysql_num_rows($res)) {
513
                $row = mysql_fetch_assoc($res);
514
            }
515
        }
516
        $t = getTableInfo($table, $db, $conn);
517
        $row["engine"] = $t["ENGINE"];
518
        if ($row["engine"] == "InnoDB") {
519
            //Hole Informationen zu einem definierten Fremdschl?ssel
520
            $sql = "SELECT
528 lars 521
                        REFERENCED_TABLE_SCHEMA,
522
                        REFERENCED_TABLE_NAME,
523
                        REFERENCED_COLUMN_NAME,
524
                        CONSTRAINT_NAME
525
                    FROM
526
                        information_schema.KEY_COLUMN_USAGE
527
                    WHERE
2117 lars 528
                        column_name='" . $column . "'
528 lars 529
                    AND
2117 lars 530
                        table_name='" . $table . "'
528 lars 531
                    AND
2117 lars 532
                        table_schema='" . $db . "'
528 lars 533
                ";
2117 lars 534
            if (__USE_MDB2__ === true) {
535
                $res = $conn->query($sql);
536
                if ($res->numRows()) {
537
                    $row_k = $res->fetchRow();
538
                }
539
            } else {
540
                $res = mysql_query($sql, $conn);
541
                if (mysql_num_rows($res)) {
542
                    $row_k = mysql_fetch_assoc($res);
543
                }
544
            }
545
            if (is_array($row_k)) {
546
                $row = array_merge($row, $row_k);
547
            }
548
        }
549
    }
550
    return $row;
528 lars 551
 
552
}
553
 
554
/**
555
 * getTableInfo()
556
 *
557
 * Liest Informationen zu einer Tabelle
558
 *
559
 * @param mixed $table
560
 * @param mixed $db
561
 * @param mixed $c
562
 * @return
563
 */
564
function getTableInfo($table, $db = null, $c = null)
565
{
2117 lars 566
    global $remoteServer_dbh, $localhost_dbh;
567
    if (!is_array($_SESSION["INI"])) {
568
        $ini = $GLOBALS["INI"];
569
    } else {
570
        $ini = $_SESSION["INI"];
571
    }
572
    if ($db) {
573
        $db = trim($db, '.');
574
    }
575
    if (!$c) {
576
        if (__USE_MDB2__ === true) {
577
            $conn = $GLOBALS["order_db"];
578
        } elseif (is_resource($GLOBALS["order_dbh"])) {
579
            $conn = $GLOBALS["order_dbh"];
580
        } elseif (is_resource($remoteServer_dbh)) {
581
            $conn = $remoteServer_dbh;
582
        }
583
    } else {
584
        $conn = $c;
585
    }
586
    if (!$db || $db == $ini["dbConnect"]["database"]) {
587
        $db = $ini["dbConnect"]["database"];
588
        if (!$c) {
589
            if (__USE_MDB2__ === true) {
590
                $conn = $GLOBALS["db"];
591
            } elseif (is_resource($GLOBALS["dbh"])) {
592
                $conn = $GLOBALS["dbh"];
593
            } elseif (is_resource($localhost_dbh)) {
594
                $conn = $localhost_dbh;
595
            }
596
        } else {
597
            $conn = $c;
598
        }
599
    }
528 lars 600
 
2117 lars 601
    if (table_exists($table, $db, $conn)) {
602
        //Hole Informationen zur Tabelle
603
        $sql = "SELECT
528 lars 604
                    *
605
                FROM
606
                    information_schema.TABLES
607
                WHERE
2117 lars 608
                    table_name='" . $table . "'
528 lars 609
                AND
2117 lars 610
                    table_schema='" . $db . "'
528 lars 611
            ";
612
 
2117 lars 613
        if (__USE_MDB2__ === true) {
614
            $res = $conn->query($sql);
615
            if ($res->numRows()) {
616
                $row = $res->fetchRow();
617
            }
618
        } else {
619
            $res = mysql_query($sql, $conn);
620
            if (mysql_num_rows($res)) {
621
                $row = mysql_fetch_assoc($res);
622
            }
623
        }
624
    }
625
    return $row;
528 lars 626
}
627
 
628
/**
629
 * createDBField()
630
 *
631
 * legt eine neue Spalte $name in der durch $table bestimmten Tabelle an
632
 * $config ist ein Array mit folgenden Schl?sseln
633
 *   type ==> Typ der Spalte (z. B. varchar)
634
 *   length ==> L?nge der Spalte (z. B. 255)
635
 *   extra ==> zus?tliche Optionen f?r das Feld (z. B. UNSIGNED bei Zahlen)
636
 *   nullable ==> kann Feld den Wert NULL enthalten?
637
 *   default ==> Wert, der in der Spalte gespeichert wird, wenn kein Wert
638
 *               ?bergeben wird
639
 *   index ==> Soll ein Index angelegt werden und wenn ja, welcher?
640
 *             Beispiele: index, unique
641
 *   after ==> Bestimmt hinter welcher Spalte die neue angelegt wird
642
 *             Wenn kein Wert angegeben wird, wird die Spalte am Ende der Tabelle
643
 *             angelegt
644
 *
645
 * @param string $name
646
 * @param string $table
647
 * @param resource $conn
648
 * @param array $config
649
 * @return void
650
 */
651
function createDBField($name, $table, $conn, $config)
652
{
2117 lars 653
    $typ = $config["type"];
654
    if ($config["length"]) {
655
        $typ .= "(" . $config["length"] . ")";
656
    }
657
    if ($config["extra"]) {
658
        $typ .= " " . $config["extra"];
659
    }
660
    if ($config["nullable"] == 1) {
661
        $typ .= " NULL DEFAULT NULL";
662
    } else {
663
        $default = '';
664
        if ($config["default"]) {
665
            $default = $config["default"];
666
        }
667
        $typ .= " NOT NULL DEFAULT '" . $default . "'";
668
    }
669
    if ($config["after"]) {
670
        $typ .= " AFTER " . $config["after"];
671
    }
672
    if ($config["index"]) {
673
        $typ .= ", ADD " . $config["index"] . "(" . $name . ")";
674
    }
675
    $sql = "
528 lars 676
            ALTER TABLE
2117 lars 677
                " . $table . "
528 lars 678
            ADD
2117 lars 679
                " . $name . " " . $typ . "
528 lars 680
        ";
2117 lars 681
    $conn->exec($sql);
528 lars 682
}
683
function Eigenschaft($NR)
684
{
2117 lars 685
    if (is_array($_SESSION['SHOP']['BASKET']) && count($_SESSION['SHOP']['BASKET']) >
686
        0) {
687
        foreach ($_SESSION['SHOP']['BASKET'] as $v) {
688
            $test = explode("_", $v["ID"]);
689
            if (count($test) == 1) {
690
                $idArray[] = $v["ID"];
691
            }
692
        }
693
        $query = "
528 lars 694
                SELECT distinct
695
                    Eigenschaft_$NR
696
                FROM
697
                    artikel
698
                WHERE
2117 lars 699
                    (ID =" . implode(" or ID =", $idArray) . ")
528 lars 700
                AND
2117 lars 701
                    Language = '" . $GLOBALS["INI"]['language'] . "'
528 lars 702
                AND
703
                    Eigenschaft_$NR=1
704
            ";
705
 
2117 lars 706
        $result = $GLOBALS['ci']->db->query($query);
707
        if ($result->num_rows() > 0) {
708
            return true;
709
        } else {
710
            return false;
711
        }
712
    } else {
713
        return false;
714
    }
528 lars 715
}
716
 
717
/**
718
 * getVersandEigenschaften()
719
 *
720
 * liest Versandeigenschaften aus der Datenbank des Redaktionssystems
721
 * für die in der Konstante __SITE__ definierte Domain (z. B. mediaran.de) aus
722
 * und gibt sie zurück
723
 *
724
 * Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden
725
 *
726
 * @return array
727
 */
728
function getVersandEigenschaften($domain = __SITE__)
729
{
730
 
2117 lars 731
    $sql = "SELECT
528 lars 732
                id
733
            FROM
734
                properties
735
            WHERE
736
                interner_Name LIKE 'Eigenschaft%'
737
            AND
738
                tools=1
739
        ";
740
 
2117 lars 741
    $res = $GLOBALS["db_red"]->query($sql);
742
    $rows = $res->result_array();
743
    foreach ($rows as $row) {
744
        $sql2 = "SELECT
528 lars 745
                    wp.*,
746
                    p.interner_name
747
                FROM
748
                    webs_properties AS wp
749
                JOIN
750
                    webs AS w
751
                ON
752
                    w.ID=wp.webs
753
                JOIN
754
                    properties AS p
755
                ON
756
                    p.id=wp.properties
757
                WHERE
2117 lars 758
                    domain='" . $domain . "'
528 lars 759
                AND
2117 lars 760
                    properties=" . $row["id"] . "
528 lars 761
                AND
762
                    wp.Bezeichnung LIKE '%;logistik';
763
            ";
2117 lars 764
        $res2 = $GLOBALS["db_red"]->query($sql2);
765
        $row2 = $res2->row_array();
766
        if (is_array($row2)) {
767
            list($name, $nr) = explode("_", $row2["interner_name"]);
768
            $eigenschaften[] = $nr;
769
        }
770
    }
771
    return $eigenschaften;
528 lars 772
}
773
 
774
function getWebRechte($site = __SITE__)
775
{
2117 lars 776
    $web_rechte = array();
777
    $query = "SELECT
528 lars 778
                m.interner_name m_name,
779
                t.button_name t_name,
780
                p.interner_name p_name,
781
                wp.Bezeichnung wp_name
782
            FROM
783
                content_management.webs w,
784
                content_management.webs_properties wp,
785
                content_management.properties p,
786
                content_management.tools t,
787
                content_management.modules m
788
            WHERE
789
                w.domain='$site'
790
            AND
791
                wp.webs=w.ID
792
            AND
793
                wp.properties=p.ID
794
            AND
795
                p.tools = t.ID
796
            AND
797
                t.modules = m.ID
798
            ORDER BY
799
                p.Rang
800
        ";
2117 lars 801
    $res = $GLOBALS["db_red"]->query($query);
802
    while ($zeile = $res->unbuffered_row('array')) {
803
        if (!$zeile["wp_name"]) {
804
            $zeile["wp_name"] = "";
805
        }
806
        $zeile["wp_name"] = explode("|", $zeile["wp_name"]);
528 lars 807
 
2117 lars 808
        if (count($zeile["wp_name"]) == 1) {
809
            $zeile["wp_name"] = $zeile["wp_name"][0];
810
        }
528 lars 811
 
2117 lars 812
        $web_rechte[$zeile["m_name"]][$zeile["t_name"]][$zeile["p_name"]] = $zeile["wp_name"];
813
    }
528 lars 814
 
2117 lars 815
    foreach (array_keys($web_rechte) as $a) {
816
        foreach (array_keys($web_rechte[$a]) as $b) {
817
            foreach (array_keys($web_rechte[$a][$b]) as $c) {
818
                if (is_array($web_rechte[$a][$b][$c])) {
819
                    $web_rechte[$a][$b][$c] = $web_rechte[$a][$b][$c][array_search($GLOBALS["INI"]["language"],
820
                        array_keys($web_rechte["online_shop"]["language"]))];
821
                    if ($web_rechte[$a][$b][$c] == "./.") {
822
                        unset($web_rechte[$a][$b][$c]);
823
                    }
824
                }
825
            }
826
        }
827
    }
828
    unset($query);
829
    unset($result);
830
    unset($zeile);
831
    return $web_rechte;
528 lars 832
}
833
 
834
function getZahlarten()
835
{
2117 lars 836
    $zahlarten[] = "- Bezahlarten -";
837
    $sql = "
528 lars 838
		SELECT
839
			z.*
840
		FROM
841
			zahlungsarten z
842
		JOIN
843
			artikel a
844
		ON
845
			a.short_line_1=z.interner_name
846
		ORDER BY
847
			name
848
	";
2117 lars 849
    $res = $GLOBALS['ci']->db->query($sql);
850
    while ($row = $res->unbuffered_row('array')) {
851
        $ini_name = $row["interner_name"];
852
        if ($row["interner_name"] == "sofortueberweisung") {
853
            $ini_name = "ueberweisung";
854
        }
855
        if (isset($GLOBALS['INI'][$ini_name]) && $GLOBALS["INI"][$ini_name]["aktiv"] ==
856
            1 && ((isset($_SESSION['zahlarten'][$ini_name]) && $_SESSION["zahlarten"][$ini_name]
857
            !== false) || !isset($_SESSION['zahlarten'][$ini_name])) || !in_array($row["interner_name"],
858
            $GLOBALS["zahlsysteme"])) {
859
            $zahlarten[$row['interner_name']] = $row['name'];
860
        }
861
    }
862
    return $zahlarten;
528 lars 863
}
864
 
865
function getWebanLCode($land)
866
{
2117 lars 867
    $sql = "SELECT
528 lars 868
                weban_lcode
869
            FROM
870
                countries
871
            WHERE
2117 lars 872
                `name-ger` = '" . $land . "'
528 lars 873
            OR
2117 lars 874
                `name-en` = '" . $land . "'
528 lars 875
            OR
2117 lars 876
                `iso-2` = '" . $land . "'
528 lars 877
            OR
2117 lars 878
                `iso-3` = '" . $land . "'
528 lars 879
            OR
2117 lars 880
                `id` = '" . $land . "'
528 lars 881
        ";
2117 lars 882
    $res = $GLOBALS["db_red"]->query($sql);
883
    $row = $res->row_array();
884
    $id = $row['weban_lcode'];
885
    return $id;
528 lars 886
}
887
 
888
function get_versandkosten($land = null, $mode = '')
889
{
2117 lars 890
    if (is_null($land)) {
891
        $land = 47;
892
    }
893
    $lCode = getWebanLCode($land);
894
    $gewicht = get_gewicht();
895
    $preis = $_SESSION['SHOP']['SUMME'];
896
    $shopID = $GLOBALS["INI"]['shops_ID'];
897
    if (isset($_SESSION["KundengruppeShopID"]) && $_SESSION["KundengruppeShopID"] !=
898
        "") {
899
        $shopID = $_SESSION["KundengruppeShopID"];
900
    }
901
    $sql_Z_extra = "";
902
    if (column_exists("zahlungsarten", "express", $GLOBALS["INI"]["dbConnect"]["database"],
903
        $GLOBALS['ci']->db)) {
904
        $sql_Z_extra = "express,";
905
    }
528 lars 906
 
2117 lars 907
    $sql = "
671 lars 908
		SELECT
909
			a.ID,
910
			Father,
911
			kurzbezeichnung as kurz,
912
			langbezeichnung    as lang,
913
			beschreibung as beschr,
914
			preis1 as preis,
915
			preis2 as aufschlag,
916
			short_line_1 as rufname,
917
			versand_abschlag,
918
			1 as Versand,
919
			preis_neu1,
920
			preis_neu2,
921
			preis_neu3,
922
			preis_neu4,
923
			Eigenschaft_1,
924
			Eigenschaft_2,
925
			Eigenschaft_3,
926
			Eigenschaft_4,
927
			Eigenschaft_5,
2117 lars 928
			" . $sql_Z_extra . "
671 lars 929
			z.name AS z_name
930
		FROM
931
			artikel a
932
		JOIN
933
			zahlungsarten z
934
		ON
935
			z.interner_name=a.short_line_1
936
		WHERE
937
			father=-3
938
		AND
2117 lars 939
			language='" . $GLOBALS['INI']['language'] . "'
671 lars 940
		AND
2117 lars 941
			lieferstatus & " . $lCode . "=" . $lCode . "
710 lars 942
		AND
943
		(
2117 lars 944
			(" . $gewicht . " between preis_neu1 and preis_neu2)
710 lars 945
		)
946
		AND
947
		(
2117 lars 948
			(" . $preis . " BETWEEN preis_neu3 AND preis_neu4)
710 lars 949
			OR
950
			(preis_neu3=preis_neu4)
951
		)
671 lars 952
	";
2117 lars 953
    if ($mode != 'Versanduebersicht') {
954
        foreach ($GLOBALS["Eigenschaften"] as $nr) {
955
            if (Eigenschaft($nr) == true) {
956
                $sql .= "
671 lars 957
					AND
958
						Eigenschaft_$nr = 1
959
				";
2117 lars 960
            } else {
961
                $sql .= "
671 lars 962
					AND
963
					(
964
						(Eigenschaft_$nr = 0)
965
						OR
966
						(Eigenschaft_$nr IS NULL)
967
					)
968
				";
2117 lars 969
            }
970
        }
971
    }
972
    $sql .= "
671 lars 973
		ORDER BY
974
			short_line_1,
975
			rang
976
	";
2117 lars 977
    $res = $GLOBALS['ci']->db->query($sql);
978
    $items = $res->result_array();
979
    return $items;
528 lars 980
}
981
 
678 lars 982
/**
983
 * getIsoCode()
984
 *
985
 * gibt den 2- oder 3-stelligen ISO-Code eines landes zurück
986
 *
987
 * @param string $Land Land dessen ISO-Code zurügkgegeben werden soll
988
 * @param string $len Länge des ISO-Codes (2- oder 3-stellig)
989
 *
990
 * @return string
991
 */
992
function getIsoCode($Land = 'Deutschland', $len = 2)
993
{
2117 lars 994
    $iso = "DE";
995
    $sql = "SELECT
996
                `iso-" . $len . "` as iso_code
678 lars 997
            FROM
713 lars 998
                countries
678 lars 999
            WHERE
2117 lars 1000
                `name-ger` ='" . $Land . "'
678 lars 1001
            OR
2117 lars 1002
                `name-en` = '" . $Land . "'
678 lars 1003
            OR
2117 lars 1004
                `id` = '" . $Land . "'
678 lars 1005
        ";
2117 lars 1006
    $res = $GLOBALS["db_red"]->query($sql);
1007
    $row = $res->row_array();
1008
    $iso = $row["iso_code"];
1009
    return $iso;
678 lars 1010
}
1011
 
2117 lars 1012
if (isset($GLOBALS['INI']['steuern']['use_countries_tax'])) {
1013
    $GLOBALS['steuern'] = getSteuerinfo();
692 lars 1014
}
1015
 
1016
/**
1017
 * Liefert zu den angegebenen LänderIds aus der Ini-Variable steuern->use_countries-tax die verfügbaren Steuersätze
1018
 *      *
1019
 * @return array $steuern mit den Steuerinfos ermittelt
1020
 *
1021
 */
1022
function getSteuerinfo()
1023
{
2117 lars 1024
    $steuern = array();
1025
    //default LandID für Deutschland
1026
    $landID = 47;
1027
    //Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
1028
    if (isset($GLOBALS["INI"]["steuern"]["default_countryID"])) {
1029
        $landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
1030
    }
692 lars 1031
 
2117 lars 1032
    $countryIDs = (isset($GLOBALS['INI']['steuern']['use_countries_tax'])) ? $GLOBALS['INI']['steuern']['use_countries_tax'] :
1033
        $landID;
692 lars 1034
 
2117 lars 1035
    $sql = "SELECT
692 lars 1036
			*
1037
		FROM
1038
			countries_tax
1039
		WHERE
2117 lars 1040
			countries_id IN (" . $countryIDs . ")
692 lars 1041
	";
2117 lars 1042
    $res = $GLOBALS["db_red"]->query($sql);
1043
    while ($r = $res->unbuffered_row('array')) {
1044
        $steuern[$r['countries_id']][$r['taxes_id']] = $r['tax_percent'];
1045
    }
1046
    return $steuern;
692 lars 1047
}
1048
 
711 lars 1049
function get_gewicht()
1050
{
2117 lars 1051
    $gewicht = 0;
1052
    foreach ($_SESSION['SHOP']['BASKET'] as $bItem) {
1053
        $artikel = $GLOBALS['ci']->artikel->get_artikel($bItem['ID'], true);
1054
        $gewicht += $artikel['gewicht'];
1055
    }
1056
    return $gewicht;
711 lars 1057
}
1058
 
2004 lars 1059
/**
1060
 *
1061
 * definiert die Konstante IS_WEBAN
1062
 * diese wird auf "true" gesetzt, wenn ein Zugriff über mindestens einen der
1063
 * folgende Wege erfolgt:
1064
 *
1065
 * 1. über die öffentliche IP der Firma
1066
 * 2. Mit dem Benutzernamen "admin"
1067
 * 3. aus dem lokalen Netz der Firma
1068
 *
1069
 */
2003 lars 1070
 
2004 lars 1071
function isWeban()
1072
{
2117 lars 1073
    $webanIP = "89.245.130.99";
1074
    if (!defined("IS_WEBAN")) {
1075
        if ((isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == $webanIP) || (isset
1076
            ($_SERVER["PHP_AUTH_USER"]) && $_SERVER["PHP_AUTH_USER"] == "admin") || (isset($_SERVER["REMOTE_ADDR"]) &&
1077
            preg_match("/192\.168\.0/", $_SERVER["REMOTE_ADDR"])) || CRON === true) {
1078
            define("IS_WEBAN", true);
1079
        } else {
1080
            define("IS_WEBAN", false);
1081
        }
1082
    }
2004 lars 1083
}
1084
function admin_debug($var, $die = false)
1085
{
2117 lars 1086
    if (IS_WEBAN === true) {
1087
        echo EOL . "Admin-Debug:" . EOL;
1088
        var_dump($var);
1089
        if ($die === true) {
1090
            die();
1091
        }
1092
    } else {
1093
        //mail( "ltiefland@gmail.com", "Fehler auf " . __SHOP__, var_export( $var, true ) );
1094
    }
2004 lars 1095
}
1096
 
2010 lars 1097
function getBasketGewicht()
1098
{
2117 lars 1099
    $gewicht = 0;
1100
    foreach ($_SESSION["SHOP"]["BASKET"] as $bItem) {
1101
        $gewicht += $bItem["gewicht"];
1102
    }
1103
    return $gewicht;
2010 lars 1104
}
1105
 
2117 lars 1106
function getDokDomain()
1107
{
1108
    global $webs, $site_full, $site;
1109
    $prot = "http";
1110
    if ( $webs["use_ssl"] == 1 )
1111
    {
1112
        $prot = "https";
1113
    }
1114
    $dokDomain = $prot . "://www." . $site_full;
1115
    if ( $site == $site_full && $webs["dok_domain"] )
1116
    {
1117
        $dokDomain = $prot . "://" . $webs["dok_domain"];
1118
    }
1119
    return $dokDomain;
1120
}
2003 lars 1121
?>