Subversion-Projekte lars-tiefland.ci

Revision

Revision 1386 | Revision 1424 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
755 lars 1
<?php
2
 
3
// $Id: weban_helper.php 713 2016-09-29 17:39:30Z lars $
824 lars 4
setlocale(LC_TIME, "de_DE.UTF-8");
755 lars 5
$GLOBALS['ci'] = &get_instance();
6
$GLOBALS['order_db'] = $GLOBALS['ci']->load->database('order_db', TRUE);
7
$GLOBALS['db_red'] = $GLOBALS['ci']->load->database('db_red', TRUE);
812 lars 8
//$GLOBALS['ci']->load->model('artikel_model', 'artikel');
755 lars 9
 
10
$GLOBALS["zahlsysteme"] = array(
11
	"kreditkarte",
12
	"paypal",
13
	"sofortueberweisung",
14
	"frei",
15
	"finanzierung",
16
	"billsafe",
17
	"billsafe_hire",
18
	"amazon",
19
	"PayPalExpress",
20
	"Ratenzahlung",
21
	"PayPalPlus",
22
	"paymill",
23
	);
24
 
25
//Excellence Käuferschutz
26
$GLOBALS["tsItems"] = array(
27
	"TS080501_500_30_EUR" => array(
28
		"max" => 500,
29
		"preis" => 0.82353,
30
		),
31
	"TS080501_1500_30_EUR" => array(
32
		"max" => 1500,
33
		"preis" => 2.47059,
34
		),
35
	"TS080501_2500_30_EUR" => array(
36
		"max" => 2500,
37
		"preis" => 4.11765,
38
		),
39
	"TS080501_5000_30_EUR" => array(
40
		"max" => 5000,
41
		"preis" => 8.23530,
42
		),
43
	"TS080501_1000_30_EUR" => array(
44
		"max" => 1000,
45
		"preis" => 16.47060,
46
		),
47
	"TS080501_20000_30_EUR" => array(
48
		"max" => 20000,
49
		"preis" => 31.94120,
50
		),
51
	);
52
 
53
$GLOBALS["tsMethods"] = array(
54
	"paypal" => "PAYPAL",
55
	"PayPalPlus" => "PAYPAL",
56
	"billsafe" => "INVOICE",
57
	"nachnahme" => "CASH_ON_DELIVERY",
58
	"kreditkarte" => "CREDIT_CARD",
59
	"selbstabholung" => "CASH_ON_PICKUP",
60
	"sofortueberweisung" => "DIECT_E_BANKING",
61
	"vorkasse" => "PREPAYMENT",
62
	);
63
//Excellence Käuferschutz - ENDE
64
 
65
/**
66
 * @author Lars Tiefland
67
 * @copyright 2016
68
 */
69
 
70
function getVersandLaender()
71
{
72
	// ME: Länder raus, und die bit-Schiebeoperation ungestört durchzählen lasssen
73
	// LT: für Smarty umgebaut
74
	$domain = "faltradxxs.de";
75
	$GLOBALS["Eigenschaften"] = getVersandEigenschaften($domain);
76
	$GLOBALS["web_rechte"] = getWebRechte($domain);
77
	$forbiddenLands = array();
78
	if (table_exists("bestelladresse", $GLOBALS["INI"]["dbConnect"]["order_db"]) &&
79
		$GLOBALS["INI"]["modules"]["adresssystem"] == "neu")
80
	{
81
		$old = false;
82
		if (table_exists("shippinggroups"))
83
		{
84
			$cTable = "countries";
85
			$cField = "`name-ger";
86
			$coTable = "cotinents";
87
			$coField = "name_de";
88
			if (table_exists("countries"))
89
			{
90
				$cField = "country";
91
				$cTable = $GLOBALS["INI"]["dbConnect"]["database"].".".$cTable;
92
				$coTable = "";
93
				$coField = "continent";
94
			}
95
			$sql = "SELECT
96
                        c.id,
97
                        c.shipping,
98
                        ".$coField." AS continent,
99
                        c.".$cField." AS country
100
                    FROM
101
                        ".$cTable." c
102
                    JOIN
103
                        ".$GLOBALS["INI"]["dbConnect"]["database"].
104
				".shippinggroups sg
105
                    ON
106
                        sg.id = c.shipping
107
                ";
108
			if ($coTable)
109
			{
110
				$sql .= "
111
                        JOIN
112
                            ".$coTable."
113
                        ON
114
                            co.id=c.continent
115
                    ";
116
			}
117
		}
118
		else
119
		{
120
			$old = true;
121
			$sql = "SELECT
122
					id,
123
					weban_lcode,
124
					`name-ger` AS country
125
				FROM
126
					content_management.countries
127
				WHERE
128
					weban_lcode!=''
129
			";
130
		}
131
		$res = $GLOBALS["db_red"]->query($sql);
132
		while ($row = $res->unbuffered_row('array'))
133
		{
134
			$land_name = $row["country"];
135
			if (!in_array($land_name, $forbiddenLands))
136
			{
137
				if ($old === true)
138
				{
139
					$land = $row["weban_lcode"];
140
					$gewicht = 0;
141
					$preis = 0;
142
					if (isset($_SESSION['SHOP']['SUMME']) && $_SESSION['SHOP']['SUMME'])
143
					{
144
						$preis = $_SESSION['SHOP']['SUMME'];
145
					}
146
					// gibt es für dieses Land Versandoptionen?
147
					$sql = "SELECT
148
                                ID
149
                            FROM
150
                                artikel
151
                            WHERE
152
                                Lieferstatus & ".$land." = ".$land."
153
                            AND
154
                                Father=-3
155
                            AND
156
                                status = ".$GLOBALS['INI']['shops_ID']."
157
                        ";
158
 
159
					if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"]))
160
					{
161
						$sql .= "
162
                                AND
163
                                (
164
                                    (".$gewicht.
165
							" between preis_neu1 and preis_neu2)
166
                                )
167
                                AND
168
                                (
169
                                    (".$preis.
170
							" BETWEEN preis_neu3 AND preis_neu4)
171
                                    OR
172
                                    (preis_neu3=preis_neu4)
173
                                )
174
                            ";
175
					}
176
					if (isset($_SESSION['SHOP']['BASKET']) && count($_SESSION["SHOP"]["BASKET"]))
177
					{
178
						foreach ($GLOBALS["Eigenschaften"] as $nr)
179
						{
180
							if (Eigenschaft($nr) == true)
181
							{
182
								$sql .= " AND Eigenschaft_$nr = 1 ";
183
							}
184
							else
185
							{
186
								$sql .= "
187
                                        AND
188
                                        (
189
                                            (Eigenschaft_$nr = 0)
190
                                            OR
191
                                            (Eigenschaft_$nr IS NULL)
192
                                        )
193
                                    ";
194
							}
195
						}
196
					}
197
 
198
 
199
					$q = $GLOBALS['ci']->db->query($sql);
200
					if ($q)
201
					{
202
						$n = $q->row_array();
203
						if ($n)
204
						{
205
							if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["db_is_utf8"] !=
206
								1)
207
							{
208
								$land_name = utf8_encode($land_name);
209
							}
210
							$laender[$row["id"]] = $land_name;
211
						}
212
					}
213
				}
214
				else
215
				{
216
					$continent = $row["continent"];
217
					$sql = "SELECT
218
                                ID
219
                            FROM
220
                                artikel
221
                            WHERE
222
                                kennung =  ".$row["shipping"]."
223
                            AND
224
                                Father=-3
225
                            AND
226
                                status = ".$GLOBALS['INI']['shops_ID']."
227
                        ";
228
 
229
					if (count($_SESSION["SHOP"]["BASKET"]))
230
					{
231
						$sql .= "
232
                                AND
233
                                (
234
                                    (".$gewicht.
235
							" between preis_neu1 and preis_neu2)
236
                                )
237
                                AND
238
                                (
239
                                    (".$preis.
240
							" BETWEEN preis_neu3 AND preis_neu4)
241
                                    OR
242
                                    (preis_neu3=preis_neu4)
243
                                )
244
                            ";
245
					}
246
					if (count($_SESSION["SHOP"]["BASKET"]))
247
					{
248
						foreach ($GLOBALS["Eigenschaften"] as $nr)
249
						{
250
							if (Eigenschaft($nr) == true)
251
							{
252
								$sql .= " AND Eigenschaft_$nr = 1 ";
253
							}
254
							else
255
							{
256
								$sql .= "
257
                                        AND
258
                                        (
259
                                            (Eigenschaft_$nr = 0)
260
                                            OR
261
                                            (Eigenschaft_$nr IS NULL)
262
                                        )
263
                                    ";
264
							}
265
						}
266
					}
267
 
268
 
269
					$q = mysql_query($sql);
270
					if ($q)
271
					{
272
						$n = mysql_num_rows($q);
273
						if ($n)
274
						{
275
							if ($GLOBALS["INI"]["charset"] == "utf-8" && $GLOBALS["INI"]["dbConnect"]["order_db_is_utf8"] !=
276
								1)
277
							{
278
								$land_name = utf8_encode($land_name);
279
								$continent = utf8_encode($continent);
280
							}
281
							$laender[$continent][$row["id"]] = $land_name;
282
						}
283
					}
284
				}
285
			}
286
		}
287
	}
288
	else
289
	{
290
		for ($i = 0; $i < 64; $i++)
291
		{
292
 
293
			$land = 1 << $i;
294
 
295
			$land_name = getCountryById($land);
296
 
297
			if ($land_name)
298
			{
299
 
300
				if (!in_array($land_name, $forbiddenLands))
301
				{
302
					$gewicht = getBasketGewicht();
303
					$preis = getBasketSumme();
304
 
305
					// gibt es für dieses Land Versandoptionen?
306
					$sql = "SELECT
307
                                ID
308
                            FROM
309
                                artikel
310
                            WHERE
311
                                Lieferstatus & ".$land." = ".$land."
312
                            AND
313
                                Father=-3
314
                            AND
315
                                status = ".$GLOBALS['INI']['shops_ID']."
316
                        ";
317
 
318
					if (count($_SESSION["SHOP"]["BASKET"]))
319
					{
320
						$sql .= "
321
                                AND
322
                                (
323
                                    (".$gewicht.
324
							" between preis_neu1 and preis_neu2)
325
                                )
326
                                AND
327
                                (
328
                                    (".$preis.
329
							" BETWEEN preis_neu3 AND preis_neu4)
330
                                    OR
331
                                    (preis_neu3=preis_neu4)
332
                                )
333
                            ";
334
					}
335
					if (count($_SESSION["SHOP"]["BASKET"]))
336
					{
337
						foreach ($GLOBALS["Eigenschaften"] as $nr)
338
						{
339
							if (Eigenschaft($nr) == true)
340
							{
341
								$sql .= " AND Eigenschaft_$nr = 1 ";
342
							}
343
							else
344
							{
345
								$sql .= "
346
                                        AND
347
                                        (
348
                                            (Eigenschaft_$nr = 0)
349
                                            OR
350
                                            (Eigenschaft_$nr IS NULL)
351
                                        )
352
                                    ";
353
							}
354
						}
355
					}
356
 
357
 
358
					$q = mysql_query($sql);
359
					if ($q)
360
					{
361
						$n = mysql_num_rows($q);
362
						if ($n)
363
						{
364
							$shopsNoEncode = array(
365
								"ababum.de",
366
								"etoh24.de",
367
								);
368
							if ($GLOBALS["INI"]["charset"] == "utf-8" && !in_array(__SHOP__, $shopsNoEncode))
369
							{
370
								$land_name = utf8_encode($land_name);
371
							}
372
							$laender[$land] = ($land_name);
373
						}
374
					}
375
				}
376
			}
377
		}
378
	}
379
	if (is_array($laender))
380
	{
381
		$laender = array_unique($laender);
382
	}
383
	else
384
	{
385
		$laender = array();
386
	}
387
 
388
	return $laender;
389
}
390
 
391
 
392
function table_exists($table, $db = null, $c = null)
393
{
394
	$ini = $GLOBALS['INI'];
395
	if ($db)
396
	{
397
		$db = trim($db, '.');
398
	}
399
	if (!$c)
400
	{
401
		$conn = $GLOBALS['order_db'];
402
	}
403
	else
404
	{
405
		$conn = $c;
406
	}
407
	if (!$db || $db == $ini["dbConnect"]["database"])
408
	{
409
		$db = $ini["dbConnect"]["database"];
410
		if (!$c)
411
		{
412
			$conn = $GLOBALS['ci']->db;
413
		}
414
		else
415
		{
416
			$conn = $c;
417
		}
418
	}
419
	$sql = "SELECT
420
            engine
421
        FROM
422
            information_schema.TABLES
423
        WHERE
424
            table_name='".$table."'
425
        AND
426
            table_schema='".$db."'
427
    ";
428
	$res = $conn->query($sql);
429
	if ($res->num_rows())
430
	{
431
		return true;
432
	}
433
	return false;
434
}
435
 
436
function column_exists($table, $column, $db = null, $c = null)
437
{
438
	$ini = $GLOBALS['INI'];
439
	if ($db)
440
	{
441
		$db = trim($db, '.');
442
	}
443
	if (!$c)
444
	{
445
		$conn = $GLOBALS['order_db'];
446
	}
447
	else
448
	{
449
		$conn = $c;
450
	}
451
	if (!$db || $db == $ini["dbConnect"]["database"])
452
	{
453
		$db = $ini["dbConnect"]["database"];
454
		if (!$c)
455
		{
456
			$conn = $GLOBALS['ci']->db;
457
		}
458
		else
459
		{
460
			$conn = $c;
461
		}
462
	}
463
 
464
	$t_exists = table_exists($table, $db, $conn);
465
	if ($t_exists)
466
	{
467
		$sql = "SELECT
468
                    data_type
469
                FROM
470
                    information_schema.COLUMNS
471
                WHERE
472
                    column_name='".$column."'
473
                AND
474
                    table_name='".$table."'
475
                AND
476
                    table_schema='".$db."'
477
            ";
478
 
479
		$res = $conn->query($sql);
480
		if ($res->num_rows())
481
		{
482
			return true;
483
		}
484
		return false;
485
	}
486
	return false;
487
}
488
 
489
/**
490
 * getColumnInfo()
491
 *
492
 * Holt Informationen zu einer Spalte (inklusive dem f?r diese Spalte definierten Fremdschl?ssel)
493
 *
494
 * @param mixed $table
495
 * @param mixed $column
496
 * @param mixed $db
497
 * @param mixed $c
498
 * @return
499
 */
500
function getColumnInfo($table, $column, $db = null, $c = null)
501
{
502
	global $remoteServer_dbh, $localhost_dbh;
503
	if (!is_array($_SESSION["INI"]))
504
	{
505
		$ini = $GLOBALS["INI"];
506
	}
507
	else
508
	{
509
		$ini = $_SESSION["INI"];
510
	}
511
	if ($db)
512
	{
513
		$db = trim($db, '.');
514
	}
515
	if (!$c)
516
	{
517
		if (__USE_MDB2__ === true)
518
		{
519
			$conn = $GLOBALS["order_db"];
520
		}
521
		elseif (is_resource($GLOBALS["order_dbh"]))
522
		{
523
			$conn = $GLOBALS["order_dbh"];
524
		}
525
		elseif (is_resource($remoteServer_dbh))
526
		{
527
			$conn = $remoteServer_dbh;
528
		}
529
	}
530
	else
531
	{
532
		$conn = $c;
533
	}
534
	if (!$db || $db == $ini["dbConnect"]["database"])
535
	{
536
		$db = $ini["dbConnect"]["database"];
537
		if (!$c)
538
		{
539
			if (__USE_MDB2__ === true)
540
			{
541
				$conn = $GLOBALS["db"];
542
			}
543
			elseif (is_resource($GLOBALS["dbh"]))
544
			{
545
				$conn = $GLOBALS["dbh"];
546
			}
547
			elseif (is_resource($localhost_dbh))
548
			{
549
				$conn = $localhost_dbh;
550
			}
551
		}
552
		else
553
		{
554
			$conn = $c;
555
		}
556
	}
557
 
558
 
559
	if (column_exists($table, $column, $db, $conn))
560
	{
561
		//Hole Informationen zur Spalte
562
		$sql = "SELECT
563
                    *
564
                FROM
565
                    information_schema.COLUMNS
566
                WHERE
567
                    column_name='".$column."'
568
                AND
569
                    table_name='".$table."'
570
                AND
571
                    table_schema='".$db."'
572
            ";
573
 
574
		if (__USE_MDB2__ === true)
575
		{
576
			$res = $conn->query($sql);
577
			if ($res->numRows())
578
			{
579
				$row = $res->fetchRow();
580
			}
581
		}
582
		else
583
		{
584
			$res = mysql_query($sql, $conn);
585
			if (mysql_num_rows($res))
586
			{
587
				$row = mysql_fetch_assoc($res);
588
			}
589
		}
590
		$t = getTableInfo($table, $db, $conn);
591
		$row["engine"] = $t["ENGINE"];
592
		if ($row["engine"] == "InnoDB")
593
		{
594
			//Hole Informationen zu einem definierten Fremdschl?ssel
595
			$sql = "SELECT
596
                        REFERENCED_TABLE_SCHEMA,
597
                        REFERENCED_TABLE_NAME,
598
                        REFERENCED_COLUMN_NAME,
599
                        CONSTRAINT_NAME
600
                    FROM
601
                        information_schema.KEY_COLUMN_USAGE
602
                    WHERE
603
                        column_name='".$column."'
604
                    AND
605
                        table_name='".$table."'
606
                    AND
607
                        table_schema='".$db."'
608
                ";
609
			if (__USE_MDB2__ === true)
610
			{
611
				$res = $conn->query($sql);
612
				if ($res->numRows())
613
				{
614
					$row_k = $res->fetchRow();
615
				}
616
			}
617
			else
618
			{
619
				$res = mysql_query($sql, $conn);
620
				if (mysql_num_rows($res))
621
				{
622
					$row_k = mysql_fetch_assoc($res);
623
				}
624
			}
625
			if (is_array($row_k))
626
			{
627
				$row = array_merge($row, $row_k);
628
			}
629
		}
630
	}
631
	return $row;
632
 
633
}
634
 
635
/**
636
 * getTableInfo()
637
 *
638
 * Liest Informationen zu einer Tabelle
639
 *
640
 * @param mixed $table
641
 * @param mixed $db
642
 * @param mixed $c
643
 * @return
644
 */
645
function getTableInfo($table, $db = null, $c = null)
646
{
647
	global $remoteServer_dbh, $localhost_dbh;
648
	if (!is_array($_SESSION["INI"]))
649
	{
650
		$ini = $GLOBALS["INI"];
651
	}
652
	else
653
	{
654
		$ini = $_SESSION["INI"];
655
	}
656
	if ($db)
657
	{
658
		$db = trim($db, '.');
659
	}
660
	if (!$c)
661
	{
662
		if (__USE_MDB2__ === true)
663
		{
664
			$conn = $GLOBALS["order_db"];
665
		}
666
		elseif (is_resource($GLOBALS["order_dbh"]))
667
		{
668
			$conn = $GLOBALS["order_dbh"];
669
		}
670
		elseif (is_resource($remoteServer_dbh))
671
		{
672
			$conn = $remoteServer_dbh;
673
		}
674
	}
675
	else
676
	{
677
		$conn = $c;
678
	}
679
	if (!$db || $db == $ini["dbConnect"]["database"])
680
	{
681
		$db = $ini["dbConnect"]["database"];
682
		if (!$c)
683
		{
684
			if (__USE_MDB2__ === true)
685
			{
686
				$conn = $GLOBALS["db"];
687
			}
688
			elseif (is_resource($GLOBALS["dbh"]))
689
			{
690
				$conn = $GLOBALS["dbh"];
691
			}
692
			elseif (is_resource($localhost_dbh))
693
			{
694
				$conn = $localhost_dbh;
695
			}
696
		}
697
		else
698
		{
699
			$conn = $c;
700
		}
701
	}
702
 
703
	if (table_exists($table, $db, $conn))
704
	{
705
		//Hole Informationen zur Tabelle
706
		$sql = "SELECT
707
                    *
708
                FROM
709
                    information_schema.TABLES
710
                WHERE
711
                    table_name='".$table."'
712
                AND
713
                    table_schema='".$db."'
714
            ";
715
 
716
		if (__USE_MDB2__ === true)
717
		{
718
			$res = $conn->query($sql);
719
			if ($res->numRows())
720
			{
721
				$row = $res->fetchRow();
722
			}
723
		}
724
		else
725
		{
726
			$res = mysql_query($sql, $conn);
727
			if (mysql_num_rows($res))
728
			{
729
				$row = mysql_fetch_assoc($res);
730
			}
731
		}
732
	}
733
	return $row;
734
}
735
 
736
/**
737
 * createDBField()
738
 *
739
 * legt eine neue Spalte $name in der durch $table bestimmten Tabelle an
740
 * $config ist ein Array mit folgenden Schl?sseln
741
 *   type ==> Typ der Spalte (z. B. varchar)
742
 *   length ==> L?nge der Spalte (z. B. 255)
743
 *   extra ==> zus?tliche Optionen f?r das Feld (z. B. UNSIGNED bei Zahlen)
744
 *   nullable ==> kann Feld den Wert NULL enthalten?
745
 *   default ==> Wert, der in der Spalte gespeichert wird, wenn kein Wert
746
 *               ?bergeben wird
747
 *   index ==> Soll ein Index angelegt werden und wenn ja, welcher?
748
 *             Beispiele: index, unique
749
 *   after ==> Bestimmt hinter welcher Spalte die neue angelegt wird
750
 *             Wenn kein Wert angegeben wird, wird die Spalte am Ende der Tabelle
751
 *             angelegt
752
 *
753
 * @param string $name
754
 * @param string $table
755
 * @param resource $conn
756
 * @param array $config
757
 * @return void
758
 */
759
function createDBField($name, $table, $conn, $config)
760
{
761
	$typ = $config["type"];
762
	if ($config["length"])
763
	{
764
		$typ .= "(".$config["length"].")";
765
	}
766
	if ($config["extra"])
767
	{
768
		$typ .= " ".$config["extra"];
769
	}
770
	if ($config["nullable"] == 1)
771
	{
772
		$typ .= " NULL DEFAULT NULL";
773
	}
774
	else
775
	{
776
		$default = '';
777
		if ($config["default"])
778
		{
779
			$default = $config["default"];
780
		}
781
		$typ .= " NOT NULL DEFAULT '".$default."'";
782
	}
783
	if ($config["after"])
784
	{
785
		$typ .= " AFTER ".$config["after"];
786
	}
787
	if ($config["index"])
788
	{
789
		$typ .= ", ADD ".$config["index"]."(".$name.")";
790
	}
791
	$sql = "
792
            ALTER TABLE
793
                ".$table."
794
            ADD
795
                ".$name." ".$typ."
796
        ";
797
	$conn->exec($sql);
798
}
799
function Eigenschaft($NR)
800
{
801
	if (is_array($_SESSION['SHOP']['BASKET']) && count($_SESSION['SHOP']['BASKET']) >
802
		0)
803
	{
804
		foreach ($_SESSION['SHOP']['BASKET'] as $v)
805
		{
806
			$test = explode("_", $v["ID"]);
807
			if (count($test) == 1)
808
			{
809
				$idArray[] = $v["ID"];
810
			}
811
		}
812
		$query = "
813
                SELECT distinct
814
                    Eigenschaft_$NR
815
                FROM
816
                    artikel
817
                WHERE
818
                    (ID =".implode(" or ID =", $idArray).")
819
                AND
820
                    Language = '".$GLOBALS["INI"]['language']."'
821
                AND
822
                    Eigenschaft_$NR=1
823
            ";
824
 
825
		$result = $GLOBALS['ci']->db->query($query);
826
		if ($result->num_rows() > 0)
827
		{
828
			return true;
829
		}
830
		else
831
		{
832
			return false;
833
		}
834
	}
835
	else
836
	{
837
		return false;
838
	}
839
}
840
 
841
/**
842
 * getVersandEigenschaften()
843
 *
844
 * liest Versandeigenschaften aus der Datenbank des Redaktionssystems
845
 * für die in der Konstante __SITE__ definierte Domain (z. B. mediaran.de) aus
846
 * und gibt sie zurück
847
 *
848
 * Über die Konstante __USE_MDB2__ kann die Datenbankschnittstelle bestimmt werden
849
 *
850
 * @return array
851
 */
852
function getVersandEigenschaften($domain = __SITE__)
853
{
854
 
855
	$sql = "SELECT
856
                id
857
            FROM
858
                properties
859
            WHERE
860
                interner_Name LIKE 'Eigenschaft%'
861
            AND
862
                tools=1
863
        ";
864
 
865
	$res = $GLOBALS["db_red"]->query($sql);
866
	$rows = $res->result_array();
867
	foreach ($rows as $row)
868
	{
869
		$sql2 = "SELECT
870
                    wp.*,
871
                    p.interner_name
872
                FROM
873
                    webs_properties AS wp
874
                JOIN
875
                    webs AS w
876
                ON
877
                    w.ID=wp.webs
878
                JOIN
879
                    properties AS p
880
                ON
881
                    p.id=wp.properties
882
                WHERE
883
                    domain='".$domain."'
884
                AND
885
                    properties=".$row["id"]."
886
                AND
887
                    wp.Bezeichnung LIKE '%;logistik';
888
            ";
889
		$res2 = $GLOBALS["db_red"]->query($sql2);
890
		$row2 = $res2->row_array();
891
		if (is_array($row2))
892
		{
893
			list($name, $nr) = explode("_", $row2["interner_name"]);
894
			$eigenschaften[] = $nr;
895
		}
896
	}
897
	return $eigenschaften;
898
}
899
 
900
function getWebRechte($site = __SITE__)
901
{
902
	$web_rechte = array();
903
	$query = "SELECT
904
                m.interner_name m_name,
905
                t.button_name t_name,
906
                p.interner_name p_name,
907
                wp.Bezeichnung wp_name
908
            FROM
909
                content_management.webs w,
910
                content_management.webs_properties wp,
911
                content_management.properties p,
912
                content_management.tools t,
913
                content_management.modules m
914
            WHERE
915
                w.domain='$site'
916
            AND
917
                wp.webs=w.ID
918
            AND
919
                wp.properties=p.ID
920
            AND
921
                p.tools = t.ID
922
            AND
923
                t.modules = m.ID
924
            ORDER BY
925
                p.Rang
926
        ";
927
	$res = $GLOBALS["db_red"]->query($query);
928
	while ($zeile = $res->unbuffered_row('array'))
929
	{
930
		if (!$zeile["wp_name"])
931
		{
932
			$zeile["wp_name"] = "";
933
		}
934
		$zeile["wp_name"] = explode("|", $zeile["wp_name"]);
935
 
936
		if (count($zeile["wp_name"]) == 1)
937
		{
938
			$zeile["wp_name"] = $zeile["wp_name"][0];
939
		}
940
 
941
		$web_rechte[$zeile["m_name"]][$zeile["t_name"]][$zeile["p_name"]] = $zeile["wp_name"];
942
	}
943
 
944
	foreach (array_keys($web_rechte) as $a)
945
	{
946
		foreach (array_keys($web_rechte[$a]) as $b)
947
		{
948
			foreach (array_keys($web_rechte[$a][$b]) as $c)
949
			{
950
				if (is_array($web_rechte[$a][$b][$c]))
951
				{
952
					$web_rechte[$a][$b][$c] = $web_rechte[$a][$b][$c][array_search($GLOBALS["INI"]["language"],
953
						array_keys($web_rechte["online_shop"]["language"]))];
954
					if ($web_rechte[$a][$b][$c] == "./.")
955
					{
956
						unset($web_rechte[$a][$b][$c]);
957
					}
958
				}
959
			}
960
		}
961
	}
962
	unset($query);
963
	unset($result);
964
	unset($zeile);
965
	return $web_rechte;
966
}
967
 
968
function getZahlarten()
969
{
970
	$zahlarten[] = "- Bezahlarten -";
971
	$sql = "
972
		SELECT
973
			z.*
974
		FROM
975
			zahlungsarten z
976
		JOIN
977
			artikel a
978
		ON
979
			a.short_line_1=z.interner_name
980
		ORDER BY
981
			name
982
	";
983
	$res = $GLOBALS['ci']->db->query($sql);
984
	while ($row = $res->unbuffered_row('array'))
985
	{
986
		$ini_name = $row["interner_name"];
987
		if ($row["interner_name"] == "sofortueberweisung")
988
		{
989
			$ini_name = "ueberweisung";
990
		}
991
		if (isset($GLOBALS['INI'][$ini_name]) && $GLOBALS["INI"][$ini_name]["aktiv"] ==
992
			1 && ((isset($_SESSION['zahlarten'][$ini_name]) && $_SESSION["zahlarten"][$ini_name]
993
			!== false) || !isset($_SESSION['zahlarten'][$ini_name])) || !in_array($row["interner_name"],
994
			$GLOBALS["zahlsysteme"]))
995
		{
996
			$zahlarten[$row['interner_name']] = $row['name'];
997
		}
998
	}
999
	return $zahlarten;
1000
}
1001
 
1002
function getWebanLCode($land)
1003
{
1004
	$sql = "SELECT
1005
                weban_lcode
1006
            FROM
1007
                countries
1008
            WHERE
1009
                `name-ger` = '".$land."'
1010
            OR
1011
                `name-en` = '".$land."'
1012
            OR
1013
                `iso-2` = '".$land."'
1014
            OR
1015
                `iso-3` = '".$land."'
1016
            OR
1017
                `id` = '".$land."'
1018
        ";
1019
	$res = $GLOBALS["db_red"]->query($sql);
1020
	$row = $res->row_array();
1021
	$id = $row['weban_lcode'];
1022
	return $id;
1023
}
1024
 
1025
function get_versandkosten($land = null, $mode = '')
1026
{
1027
	if (is_null($land))
1028
	{
1029
		$land = 47;
1030
	}
1031
	$lCode = getWebanLCode($land);
1032
	$gewicht = get_gewicht();
1033
	$preis = $_SESSION['SHOP']['SUMME'];
1034
	$shopID = $GLOBALS["INI"]['shops_ID'];
1035
	if (isset($_SESSION["KundengruppeShopID"]) && $_SESSION["KundengruppeShopID"] !=
1036
		"")
1037
	{
1038
		$shopID = $_SESSION["KundengruppeShopID"];
1039
	}
1040
	$sql_Z_extra = "";
1041
	if (column_exists("zahlungsarten", "express", $GLOBALS["INI"]["dbConnect"]["database"],
1042
		$GLOBALS['ci']->db))
1043
	{
1044
		$sql_Z_extra = "express,";
1045
	}
1046
 
1047
	$sql = "
1048
		SELECT
1049
			a.ID,
1050
			Father,
1051
			kurzbezeichnung as kurz,
1052
			langbezeichnung    as lang,
1053
			beschreibung as beschr,
1054
			preis1 as preis,
1055
			preis2 as aufschlag,
1056
			short_line_1 as rufname,
1057
			versand_abschlag,
1058
			1 as Versand,
1059
			preis_neu1,
1060
			preis_neu2,
1061
			preis_neu3,
1062
			preis_neu4,
1063
			Eigenschaft_1,
1064
			Eigenschaft_2,
1065
			Eigenschaft_3,
1066
			Eigenschaft_4,
1067
			Eigenschaft_5,
1068
			".$sql_Z_extra."
1069
			z.name AS z_name
1070
		FROM
1071
			artikel a
1072
		JOIN
1073
			zahlungsarten z
1074
		ON
1075
			z.interner_name=a.short_line_1
1076
		WHERE
1077
			father=-3
1078
		AND
1079
			language='".$GLOBALS['INI']['language']."'
1080
		AND
1081
			lieferstatus & ".$lCode."=".$lCode."
1082
		AND
1083
		(
1084
			(".$gewicht." between preis_neu1 and preis_neu2)
1085
		)
1086
		AND
1087
		(
1088
			(".$preis." BETWEEN preis_neu3 AND preis_neu4)
1089
			OR
1090
			(preis_neu3=preis_neu4)
1091
		)
1092
	";
1093
	if ($mode != 'Versanduebersicht')
1094
	{
1095
		foreach ($GLOBALS["Eigenschaften"] as $nr)
1096
		{
1097
			if (Eigenschaft($nr) == true)
1098
			{
1099
				$sql .= "
1100
					AND
1101
						Eigenschaft_$nr = 1
1102
				";
1103
			}
1104
			else
1105
			{
1106
				$sql .= "
1107
					AND
1108
					(
1109
						(Eigenschaft_$nr = 0)
1110
						OR
1111
						(Eigenschaft_$nr IS NULL)
1112
					)
1113
				";
1114
			}
1115
		}
1116
	}
1117
	$sql .= "
1118
		ORDER BY
1119
			short_line_1,
1120
			rang
1121
	";
1122
	$res = $GLOBALS['ci']->db->query($sql);
1123
	$items = $res->result_array();
1124
	return $items;
1125
}
1126
 
1127
/**
1128
 * getIsoCode()
1129
 *
1130
 * gibt den 2- oder 3-stelligen ISO-Code eines landes zurück
1131
 *
1132
 * @param string $Land Land dessen ISO-Code zurügkgegeben werden soll
1133
 * @param string $len Länge des ISO-Codes (2- oder 3-stellig)
1134
 *
1135
 * @return string
1136
 */
1137
function getIsoCode($Land = 'Deutschland', $len = 2)
1138
{
1139
	$iso = "DE";
1140
	$sql = "SELECT
1141
                `iso-".$len."` as iso_code
1142
            FROM
1143
                countries
1144
            WHERE
1145
                `name-ger` ='".$Land."'
1146
            OR
1147
                `name-en` = '".$Land."'
1148
            OR
1149
                `id` = '".$Land."'
1150
        ";
1151
	$res = $GLOBALS["db_red"]->query($sql);
1152
	$row = $res->row_array();
1153
	$iso = $row["iso_code"];
1154
	return $iso;
1155
}
1156
 
1157
if (isset($GLOBALS['INI']['steuern']['use_countries_tax']))
1158
{
1159
	$GLOBALS['steuern'] = getSteuerinfo();
1160
}
1161
 
1162
/**
1163
 * Liefert zu den angegebenen LänderIds aus der Ini-Variable steuern->use_countries-tax die verfügbaren Steuersätze
1164
 *      *
1165
 * @return array $steuern mit den Steuerinfos ermittelt
1166
 *
1167
 */
1168
function getSteuerinfo()
1169
{
1170
	$steuern = array();
1171
	//default LandID für Deutschland
1172
	$landID = 47;
1173
	//Wenn das Flag gesetzt ist, dann nimm diesen wert, damit auch "ausländische Shops" den richtigen MwSt angezeigt bekommen
1174
	if (isset($GLOBALS["INI"]["steuern"]["default_countryID"]))
1175
	{
1176
		$landID = $GLOBALS["INI"]["steuern"]["default_countryID"];
1177
	}
1178
 
1179
	$countryIDs = (isset($GLOBALS['INI']['steuern']['use_countries_tax'])) ? $GLOBALS['INI']['steuern']['use_countries_tax'] :
1180
		$landID;
1181
 
1182
	$sql = "SELECT
1183
			*
1184
		FROM
1185
			countries_tax
1186
		WHERE
1187
			countries_id IN (".$countryIDs.")
1188
	";
1189
	$res = $GLOBALS["db_red"]->query($sql);
1190
	while ($r = $res->unbuffered_row('array'))
1191
	{
1192
		$steuern[$r['countries_id']][$r['taxes_id']] = $r['tax_percent'];
1193
	}
1194
	return $steuern;
1195
}
1196
 
1197
function get_gewicht()
1198
{
1199
	$gewicht = 0;
1200
	foreach ($_SESSION['SHOP']['BASKET'] AS $bItem)
1201
	{
1202
		$artikel = $GLOBALS['ci']->artikel->get_artikel($bItem['ID'], true);
1203
		$gewicht += $artikel['gewicht'];
1204
	}
1205
	return $gewicht;
1206
}
1207
 
1378 lars 1208
function select_tpl($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue = false,
1209
	$required = false, $onChange = null)
1210
{
1211
 
1212
	if ($required == false)
1213
	{
1214
		array_unshift($options, array($optionValueKey => false, $optionLabelKey =>
1215
				"----------- alle -----------"));
1216
	}
1217
 
1218
	$ret = '<select name="'.$formTagName.
1219
		'" onChange="$onChange" class="filterStatistik">';
1220
	foreach ($options as $option)
1221
	{
1222
		$ret .= '<option value="'.$option[$optionValueKey].'"';
1223
		if ($option[$optionValueKey] == $preSelectValue)
1224
		{
1225
			$ret .= ' selected="selected"';
1226
		}
1227
		$ret .= '>'.$option[$optionLabelKey].'</option>';
1228
 
1229
	}
1230
	$ret .= '</select>';
1231
	return $ret;
1232
}
1233
 
1234
function select($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue = false,
1235
	$required = false, $onChange = null)
1236
{
1237
	echo select_tpl($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue,
1238
		$required, $onChange);
1239
}
1240
 
1241
function getShops($shop_id = null, $filter = false, $start = 0, $ende = 0, $start_v =
1242
	0, $ende_v = 0)
1243
{
1244
 
1245
	$buffer = array();
1246
	$where = "";
1247
 
1248
	if (isset($_SESSION["datenquellen"]["shops"]) && count($_SESSION["datenquellen"]["shops"]) >
1249
		0)
1250
	{
1251
		$where = " WHERE id IN ( ".implode(",", $_SESSION["datenquellen"]["shops"]).
1252
			" )";
1253
	}
1254
 
1255
	$query = "
1256
            SELECT  *
1257
            FROM    shops
1258
        ";
1259
	$query .= (!empty($shop_id)) ? " WHERE ID = ".$shop_id : $where;
1260
 
1380 lars 1261
	$result = $GLOBALS["order_db"]->query($query);
1262
	while ($zeile = $result->unbuffered_row('array'))
1378 lars 1263
	{
1264
		$buffer[] = $zeile;
1265
	}
1266
	if ($filter)
1267
	{
1396 lars 1268
 
1378 lars 1269
		//Shops filtern
1270
		foreach ($buffer as $id => $shop)
1271
		{
1380 lars 1272
			/*
1378 lars 1273
			if (get_umsatz($start, $ende, $shop["ID"], 0) > 0.0 || get_umsatz($start_v, $ende_v,
1396 lars 1274
			$shop["ID"], 0) > 0.0)
1380 lars 1275
			{*/
1396 lars 1276
			$shops[] = $shop;
1380 lars 1277
			//}
1378 lars 1278
		}
1279
	}
1280
	else
1281
	{
1282
		$shops = $buffer;
1283
	}
1284
	unset($buffer);
1285
	return $shops;
1286
}
1287
 
1288
function getLogistikerFilter()
1289
{
1290
	$logistiker[0] = "alle";
1291
 
1292
	$sql = "SELECT
1293
			id,
1294
			name
1295
		FROM
1296
			logistiker
1297
  	";
1298
	$result = $GLOBALS["order_db"]->query($sql);
1299
 
1300
	while ($row = $result->unbuffered_row('array'))
1301
	{
1302
		$logistiker[$row["id"]] = $row["name"];
1303
	}
1304
 
1305
	return $logistiker;
1306
}
1307
function getBestelllaender()
1308
{
1309
	$laender[0] = "alle";
1310
	$laender[1] = "Ausland";
1311
 
1384 lars 1312
	if (isset($GLOBALS["web_rechte"]["Warenwirtschaft"]["bestellung"]["adressbuch"]))
1378 lars 1313
	{
1314
 
1315
		$countryTable = "countries co";
1316
 
1384 lars 1317
		if ($GLOBALS["web_rechte"]["online_shop"]["language"]["standardsprache"] == "UK")
1378 lars 1318
		{
1319
			$coFeld = "co.`name-en` AS liefer_Land";
1320
		}
1321
		else
1322
		{
1323
			$coFeld = "co.`name-ger` AS liefer_Land";
1324
		}
1325
		$query = "SELECT
1326
				".$coFeld."
1327
    		FROM
1328
				".$countryTable."
1329
    	";
1330
		$result = $GLOBALS["db_red"]->query($query);
1331
 
1386 lars 1332
		while ($row = $result->unbuffered_row('array'))
1378 lars 1333
		{
1334
			$laender[] = $row["liefer_Land"];
1335
		}
1336
	}
1337
	else
1338
	{
1339
		$Laender = array(
1340
			"Deutschland",
1341
			"Niederlande",
1342
			"Österreich",
1343
			"Belgien",
1344
			"Luxemburg",
1345
			"Dänemark",
1346
			"Schweiz",
1347
			"Frankreich",
1348
			"Großbritannien",
1349
			"Italien",
1350
			"Spanien",
1351
			"Portugal",
1352
			"Schweden",
1353
			"Finnland",
1354
			"Norwegen",
1355
			"Irland",
1356
			"Griechenland",
1357
			"Estland",
1358
			"Lettland",
1359
			"Malta",
1360
			"Litauen",
1361
			"Polen",
1362
			"Slowenien",
1363
			"Slowakei",
1364
			"Tschechien",
1365
			"Türkei",
1366
			"Ungarn",
1367
			"Zypern",
1368
			"Kanada",
1369
			"USA",
1370
			"Kroatien",
1371
			"Bulgarien",
1372
			"Rumänien",
1373
			"Südafrika",
1374
			"Japan",
1375
			"China",
1376
			"Singapur",
1377
			"Dubai (VAE)",
1378
			);
1379
		$laender = array_merge($laender, $Laender);
1380
	}
1381
 
1382
	return $laender;
1383
}
1384
 
1385
function getBestellarten()
1386
{
1387
	global $user_rechte;
1388
	$bestellarten = false;
1385 lars 1389
	if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["bestellart"]))
1378 lars 1390
	{
1391
 
1392
		if (isset($_SESSION["datenquellen"]["bestellarten"]) && count($_SESSION["datenquellen"]["bestellarten"]) >
1393
			0)
1394
		{
1395
			$where = implode(",", $_SESSION["datenquellen"]["bestellarten"]);
1396
			$sql = "SELECT * FROM bestellart WHERE id IN ( ".$where." )";
1397
		}
1398
		else
1399
		{
1400
 
1401
			$sql = "SELECT * FROM bestellart";
1402
		}
1403
		$query = $GLOBALS["order_db"]->query($sql);
1404
		if (!$query)
1405
		{
1406
			return false;
1407
		}
1408
 
1409
		while ($db = $query->unbuffered_row('array'))
1410
		{
1411
			$bestellarten[$db["id"]] = $db;
1412
		}
1413
	}
1414
	return $bestellarten;
1415
}
1416
 
1417
function getZahlungsarten()
1418
{
1419
	global $user_rechte;
1420
	$zahlungsarten = false;
1385 lars 1421
	if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["zahlungsart"]))
1378 lars 1422
	{
1423
		$sql = "SELECT * FROM zahlungsarten";
1424
		$query = $GLOBALS["order_db"]->query($sql);
1425
		if (!$query)
1426
		{
1427
			return false;
1428
		}
1429
		while ($r = $query->unbuffered_row('array'))
1430
		{
1431
			$zahlungsarten[$r['id']] = $r['name'];
1432
		}
1433
	}
1434
	return $zahlungsarten;
1435
}
1436
 
1437
function getDates()
1438
{
1439
	$start = strtotime(date("Y-m-01"));
1440
	$buffer[] = array(
1441
		"datum" => strftime("%Y-%m"),
1442
		"datumText" => strftime("%B %G"),
1443
		);
1444
	for ($i = 1; $i <= 25; $i++)
1445
	{
1446
		$buffer[] = array(
1447
			"datum" => strftime("%Y-%m", strtotime("-$i months", $start)),
1448
			"datumText" => strftime("%B %Y", strtotime("-$i months", $start)),
1449
			);
1450
	}
1451
	if (strftime("%w") != 1)
1452
	{
1453
		$start = strtotime("last monday");
1454
	}
1455
	else
1456
	{
1457
		$start = time();
1458
	}
1459
	$buffer[] = array(
1460
		"datum" => strftime("%Y", $start),
1461
		"datumText" => strftime("Jahr %Y", $start),
1462
		);
1463
	$buffer[] = array(
1464
		"datum" => strftime("%Y", strtotime("-1 year", $start)),
1465
		"datumText" => strftime("Jahr %Y", strtotime("-1 year", $start)),
1466
		);
1467
	$buffer[] = array(
1468
		"datum" => strftime("%Y", strtotime("-2 year", $start)),
1469
		"datumText" => strftime("Jahr %Y", strtotime("-2 year", $start)),
1470
		);
1471
	$buffer[] = array(
1472
		"datum" => strftime("%G-%m-%dW", $start),
1473
		"datumText" => strftime("Woche %V %G", $start),
1474
		);
1475
	$buffer[] = array(
1476
		"datum" => strftime("%G-%m-%dW", strtotime("-1 week", $start)),
1477
		"datumText" => strftime("Woche %V %G", strtotime("-1 week", $start)),
1478
		);
1479
	for ($i = 2; $i <= 5; $i++)
1480
	{
1481
		$buffer[] = array(
1482
			"datum" => strftime("%G-%m-%dW", strtotime("-$i weeks", $start)),
1483
			"datumText" => strftime("Woche %V %G", strtotime("-$i weeks", $start)),
1484
			);
1485
	}
1486
	return $buffer;
1487
}
1488
 
1489
function getWeeks($year = 2008, $maxReverse = 6)
1490
{
1491
	$paramYear = $year;
1492
	$scalar = 0;
1493
	$weekNow = date("W", time());
1494
	$monthNow = date("n", time());
1495
	$dateArray = array();
1496
	$monthArray = array();
1497
 
1498
	$countedWeek = $weekNow;
1499
	$countedMonth = $monthNow;
1500
 
1501
	for ($i = $weekNow; $i > ($weekNow - $maxReverse); $i--)
1502
	{
1503
		$dateArray[$scalar]['week'] = $countedWeek;
1504
		$dateArray[$scalar]['year'] = $year;
1505
		$dateArray[$scalar]['date_string'] = "kw,".$countedWeek.",".$year;
1506
		$dateArray[$scalar]['human_string'] = "$countedWeek/$year";
1507
 
1508
		if ($countedWeek == 1)
1509
		{
1510
			$year -= 1;
1511
			$countedWeek = 1;
1512
		}
1513
		else
1514
		{
1515
			$countedWeek--;
1516
		}
1517
 
1518
		$scalar++;
1519
	}
1520
 
1521
	$year = $paramYear;
1522
 
1523
	for ($i = $monthNow; $i > ($monthNow - $maxReverse); $i--)
1524
	{
1525
		$dateArray[$scalar]['month'] = $countedMonth;
1526
		$dateArray[$scalar]['year'] = $paramYear;
1527
		$dateArray[$scalar]['date_string'] = "mon,".$countedMonth.",".$year;
1528
		$dateArray[$scalar]['human_string'] = date("M", mktime(0, 0, 0, $countedMonth, 1,
1529
			$year))." $year";
1530
 
1531
		if ($countedMonth == 1)
1532
		{
1533
			$year -= 1;
1534
			$countedMonth = 12;
1535
		}
1536
		else
1537
		{
1538
			$countedMonth--;
1539
		}
1540
 
1541
		$scalar++;
1542
	}
1543
	return $dateArray;
1544
}
1545
 
1396 lars 1546
function parseEnumSet($table, $col)
1547
{
1548
	$sql = "SELECT
1549
			DATA_TYPE,
1550
			COLUMN_TYPE,
1551
			COLUMN_DEFAULT
1552
		FROM
1553
			information_schema.COLUMNS
1554
		WHERE
1555
			TABLE_SCHEMA='".$GLOBALS["webs"]["datenbank"]."'
1556
		AND
1557
			TABLE_NAME='".$table."'
1558
		AND
1559
			COLUMN_NAME='".$col."'
1560
        ";
1561
	$res = $GLOBALS["ci"]->db->query($sql);
1562
	$row = $res->row_array();
1563
	$werte = str_replace(array(
1564
		$row["DATA_TYPE"]."(",
1565
		")",
1566
		"'",
1567
		), "", $row["COLUMN_TYPE"]);
1568
	$werte = explode(",", $werte);
1569
	$ret = array(
1570
		"werte" => $werte,
1571
		"typ" => $row["DATA_TYPE"],
1572
		"default" => $row["COLUMN_DEFAULT"],
1573
		);
1574
	return $ret;
1575
}
1576
 
755 lars 1577
?>