Subversion-Projekte lars-tiefland.ci

Revision

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