Subversion-Projekte lars-tiefland.ci

Revision

Revision 2137 | 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
 
1424 lars 1312
	$countryTable = "countries co";
1313
 
1314
	if ($GLOBALS["web_rechte"]["online_shop"]["language"]["standardsprache"] == "UK")
1378 lars 1315
	{
1424 lars 1316
		$coFeld = "co.`name-en` AS liefer_Land";
1378 lars 1317
	}
1318
	else
1319
	{
1424 lars 1320
		$coFeld = "co.`name-ger` AS liefer_Land";
1378 lars 1321
	}
1424 lars 1322
	$query = "SELECT
1323
			".$coFeld.",
1426 lars 1324
			co.id,
1424 lars 1325
			con.name_de kontinent
1326
		FROM
1327
			".$countryTable."
1328
		JOIN
1329
			continents con
1330
		ON
1331
			con.id=co.continent
1429 lars 1332
		WHERE
1333
			weban_lcode > 0
1427 lars 1334
		ORDER BY
1436 lars 1335
			weban_lcode
1424 lars 1336
	";
1337
	$result = $GLOBALS["db_red"]->query($query);
1378 lars 1338
 
1424 lars 1339
	while ($row = $result->unbuffered_row('array'))
1340
	{
1425 lars 1341
		$laender[$row["kontinent"]][$row["id"]] = $row["liefer_Land"];
1424 lars 1342
	}
1378 lars 1343
	return $laender;
1344
}
1345
 
1346
function getBestellarten()
1347
{
1348
	global $user_rechte;
1349
	$bestellarten = false;
1385 lars 1350
	if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["bestellart"]))
1378 lars 1351
	{
1352
 
1353
		if (isset($_SESSION["datenquellen"]["bestellarten"]) && count($_SESSION["datenquellen"]["bestellarten"]) >
1354
			0)
1355
		{
1356
			$where = implode(",", $_SESSION["datenquellen"]["bestellarten"]);
1357
			$sql = "SELECT * FROM bestellart WHERE id IN ( ".$where." )";
1358
		}
1359
		else
1360
		{
1361
 
1362
			$sql = "SELECT * FROM bestellart";
1363
		}
1364
		$query = $GLOBALS["order_db"]->query($sql);
1365
		if (!$query)
1366
		{
1367
			return false;
1368
		}
1369
 
1370
		while ($db = $query->unbuffered_row('array'))
1371
		{
1372
			$bestellarten[$db["id"]] = $db;
1373
		}
1374
	}
1375
	return $bestellarten;
1376
}
1377
 
1378
function getZahlungsarten()
1379
{
1380
	global $user_rechte;
1381
	$zahlungsarten = false;
1385 lars 1382
	if (isset($GLOBALS["user_rechte"]["Warenwirtschaft"]["bestellung"]["zahlungsart"]))
1378 lars 1383
	{
1384
		$sql = "SELECT * FROM zahlungsarten";
1385
		$query = $GLOBALS["order_db"]->query($sql);
1386
		if (!$query)
1387
		{
1388
			return false;
1389
		}
1390
		while ($r = $query->unbuffered_row('array'))
1391
		{
1392
			$zahlungsarten[$r['id']] = $r['name'];
1393
		}
1394
	}
1395
	return $zahlungsarten;
1396
}
1397
 
1398
function getDates()
1399
{
1400
	$start = strtotime(date("Y-m-01"));
1401
	$buffer[] = array(
1402
		"datum" => strftime("%Y-%m"),
1403
		"datumText" => strftime("%B %G"),
1404
		);
1405
	for ($i = 1; $i <= 25; $i++)
1406
	{
1407
		$buffer[] = array(
1408
			"datum" => strftime("%Y-%m", strtotime("-$i months", $start)),
1409
			"datumText" => strftime("%B %Y", strtotime("-$i months", $start)),
1410
			);
1411
	}
1412
	if (strftime("%w") != 1)
1413
	{
1414
		$start = strtotime("last monday");
1415
	}
1416
	else
1417
	{
1418
		$start = time();
1419
	}
1420
	$buffer[] = array(
1421
		"datum" => strftime("%Y", $start),
1422
		"datumText" => strftime("Jahr %Y", $start),
1423
		);
1424
	$buffer[] = array(
1425
		"datum" => strftime("%Y", strtotime("-1 year", $start)),
1426
		"datumText" => strftime("Jahr %Y", strtotime("-1 year", $start)),
1427
		);
1428
	$buffer[] = array(
1429
		"datum" => strftime("%Y", strtotime("-2 year", $start)),
1430
		"datumText" => strftime("Jahr %Y", strtotime("-2 year", $start)),
1431
		);
1432
	$buffer[] = array(
1433
		"datum" => strftime("%G-%m-%dW", $start),
1434
		"datumText" => strftime("Woche %V %G", $start),
1435
		);
1436
	$buffer[] = array(
1437
		"datum" => strftime("%G-%m-%dW", strtotime("-1 week", $start)),
1438
		"datumText" => strftime("Woche %V %G", strtotime("-1 week", $start)),
1439
		);
1440
	for ($i = 2; $i <= 5; $i++)
1441
	{
1442
		$buffer[] = array(
1443
			"datum" => strftime("%G-%m-%dW", strtotime("-$i weeks", $start)),
1444
			"datumText" => strftime("Woche %V %G", strtotime("-$i weeks", $start)),
1445
			);
1446
	}
1447
	return $buffer;
1448
}
1449
 
1450
function getWeeks($year = 2008, $maxReverse = 6)
1451
{
1452
	$paramYear = $year;
1453
	$scalar = 0;
1454
	$weekNow = date("W", time());
1455
	$monthNow = date("n", time());
1456
	$dateArray = array();
1457
	$monthArray = array();
1458
 
1459
	$countedWeek = $weekNow;
1460
	$countedMonth = $monthNow;
1461
 
1462
	for ($i = $weekNow; $i > ($weekNow - $maxReverse); $i--)
1463
	{
1464
		$dateArray[$scalar]['week'] = $countedWeek;
1465
		$dateArray[$scalar]['year'] = $year;
1466
		$dateArray[$scalar]['date_string'] = "kw,".$countedWeek.",".$year;
1467
		$dateArray[$scalar]['human_string'] = "$countedWeek/$year";
1468
 
1469
		if ($countedWeek == 1)
1470
		{
1471
			$year -= 1;
1472
			$countedWeek = 1;
1473
		}
1474
		else
1475
		{
1476
			$countedWeek--;
1477
		}
1478
 
1479
		$scalar++;
1480
	}
1481
 
1482
	$year = $paramYear;
1483
 
1484
	for ($i = $monthNow; $i > ($monthNow - $maxReverse); $i--)
1485
	{
1486
		$dateArray[$scalar]['month'] = $countedMonth;
1487
		$dateArray[$scalar]['year'] = $paramYear;
1488
		$dateArray[$scalar]['date_string'] = "mon,".$countedMonth.",".$year;
1489
		$dateArray[$scalar]['human_string'] = date("M", mktime(0, 0, 0, $countedMonth, 1,
1490
			$year))." $year";
1491
 
1492
		if ($countedMonth == 1)
1493
		{
1494
			$year -= 1;
1495
			$countedMonth = 12;
1496
		}
1497
		else
1498
		{
1499
			$countedMonth--;
1500
		}
1501
 
1502
		$scalar++;
1503
	}
1504
	return $dateArray;
1505
}
1506
 
1396 lars 1507
function parseEnumSet($table, $col)
1508
{
1509
	$sql = "SELECT
1510
			DATA_TYPE,
1511
			COLUMN_TYPE,
1512
			COLUMN_DEFAULT
1513
		FROM
1514
			information_schema.COLUMNS
1515
		WHERE
1516
			TABLE_SCHEMA='".$GLOBALS["webs"]["datenbank"]."'
1517
		AND
1518
			TABLE_NAME='".$table."'
1519
		AND
1520
			COLUMN_NAME='".$col."'
1521
        ";
1522
	$res = $GLOBALS["ci"]->db->query($sql);
1523
	$row = $res->row_array();
1524
	$werte = str_replace(array(
1525
		$row["DATA_TYPE"]."(",
1526
		")",
1527
		"'",
1528
		), "", $row["COLUMN_TYPE"]);
1529
	$werte = explode(",", $werte);
1530
	$ret = array(
1531
		"werte" => $werte,
1532
		"typ" => $row["DATA_TYPE"],
1533
		"default" => $row["COLUMN_DEFAULT"],
1534
		);
1535
	return $ret;
1536
}
1537
 
2118 lars 1538
function getDokDomain()
1539
{
1540
    $prot = "http";
2125 lars 1541
    if ( $GLOBALS["webs"]["use_ssl"] == 1 )
2118 lars 1542
    {
1543
        $prot = "https";
1544
    }
2138 lars 1545
    $dokDomain = $prot . "://ci.starfleethq.de/";
2125 lars 1546
    if ( $GLOBALS["site"] == $GLOBALS["site_full"] && $GLOBALS["webs"]["dok_domain"] )
2118 lars 1547
    {
2125 lars 1548
        $dokDomain = $prot . "://" . $GLOBALS["webs"]["dok_domain"];
2118 lars 1549
    }
1550
    return $dokDomain;
1551
}
755 lars 1552
?>