Subversion-Projekte lars-tiefland.ci

Revision

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