Subversion-Projekte lars-tiefland.ci

Revision

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