Subversion-Projekte lars-tiefland.ci

Revision

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

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