| 1 |
lars |
1 |
<?
|
|
|
2 |
function select($formTagName, $options, $optionValueKey, $optionLabelKey, $preSelectValue=false, $required=false)
|
|
|
3 |
{
|
|
|
4 |
if ($required == false)
|
|
|
5 |
{
|
|
|
6 |
array_unshift
|
|
|
7 |
(
|
|
|
8 |
$options,
|
|
|
9 |
array
|
|
|
10 |
(
|
|
|
11 |
$optionValueKey => false,
|
|
|
12 |
$optionLabelKey => "----------- alle -----------"
|
|
|
13 |
)
|
|
|
14 |
);
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
echo "<select name=\"".$formTagName."\">";
|
|
|
18 |
foreach($options as $option)
|
|
|
19 |
{
|
|
|
20 |
echo "<option value=\"".$option[$optionValueKey]."\"";
|
|
|
21 |
if ($option[$optionValueKey] == $preSelectValue)
|
|
|
22 |
{
|
|
|
23 |
echo " selected";
|
|
|
24 |
}
|
|
|
25 |
echo ">".$option[$optionLabelKey]."</option>";
|
|
|
26 |
}
|
|
|
27 |
echo "</select>";
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
function getShops()
|
|
|
31 |
{
|
|
|
32 |
$buffer=array();
|
|
|
33 |
$query="select * from shops";
|
|
|
34 |
$result = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>$query<hr>");
|
|
|
35 |
while($zeile=mysql_fetch_assoc($result))
|
|
|
36 |
{
|
|
|
37 |
$buffer[]=$zeile;
|
|
|
38 |
}
|
|
|
39 |
return $buffer;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
function getDates()
|
|
|
43 |
{
|
|
|
44 |
$buffer=array();
|
|
|
45 |
$query="
|
|
|
46 |
select
|
|
|
47 |
distinct
|
|
|
48 |
date_format(Bestellung.erstellt_am, '%Y-%m') as datum,
|
|
|
49 |
date_format(Bestellung.erstellt_am, '%b %Y') as datumText
|
|
|
50 |
from
|
|
|
51 |
Bestellung
|
|
|
52 |
order by
|
|
|
53 |
Bestellung.erstellt_am desc
|
|
|
54 |
";
|
|
|
55 |
$result = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>$query<hr>");
|
|
|
56 |
while($zeile=mysql_fetch_assoc($result))
|
|
|
57 |
{
|
|
|
58 |
$buffer[]=$zeile;
|
|
|
59 |
}
|
|
|
60 |
$query="
|
|
|
61 |
select
|
|
|
62 |
distinct
|
|
|
63 |
date_format(Bestellung.erstellt_am, '%Y') as datum,
|
|
|
64 |
date_format(Bestellung.erstellt_am, '%Y') as datumText
|
|
|
65 |
from
|
|
|
66 |
Bestellung
|
|
|
67 |
order by
|
|
|
68 |
Bestellung.erstellt_am desc
|
|
|
69 |
";
|
|
|
70 |
$result = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>$query<hr>");
|
|
|
71 |
while($zeile=mysql_fetch_assoc($result))
|
|
|
72 |
{
|
|
|
73 |
$buffer[]=$zeile;
|
|
|
74 |
}
|
|
|
75 |
return $buffer;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
function getWeeks($year=2008, $maxReverse = 32)
|
|
|
79 |
{
|
|
|
80 |
|
|
|
81 |
$scalar = 0;
|
|
|
82 |
$weekNow = date("W");
|
|
|
83 |
$dateArray = array();
|
|
|
84 |
$countedWeek = $weekNow;
|
|
|
85 |
|
|
|
86 |
for($i=$weekNow;$i>($weekNow-$maxReverse);$i--) {
|
|
|
87 |
|
|
|
88 |
$dateArray[$scalar]['week'] = $countedWeek;
|
|
|
89 |
$dateArray[$scalar]['year'] = $year;
|
|
|
90 |
$dateArray[$scalar]['date_string'] = $countedWeek.",".$year;
|
|
|
91 |
$dateArray[$scalar]['human_string'] = "KW: $countedWeek - $year";
|
|
|
92 |
|
|
|
93 |
if ($countedWeek==1) {
|
|
|
94 |
$year -=1;
|
|
|
95 |
$countedWeek=date("W",mktime(0, 0, 0, 12, 25, $year));
|
|
|
96 |
} else {
|
|
|
97 |
$countedWeek--;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
$scalar++;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
return $dateArray;
|
|
|
104 |
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/* ################################################################################ */
|
|
|
108 |
/* Select-Abfrage an die Datenbank senden. */
|
|
|
109 |
/* Methode um Select-Abfragen zentral an die Datenbank zu senden */
|
|
|
110 |
/* NUR Select-Abfragen ! */
|
|
|
111 |
/* Nur sinnvoll in Verbindung mit while-Schleifen. */
|
|
|
112 |
/* Aufrufbeispiel: while($zeile=mysqlSelect("select ....")) {...} */
|
|
|
113 |
/* ################################################################################ */
|
|
|
114 |
function mysqlSelect($query)
|
|
|
115 |
{
|
|
|
116 |
if (!preg_match("/^select/i", trim($query))) // Abbrechen falls query nicht mit "select beginnt"
|
|
|
117 |
{ return false; }
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
static $status; // Statuswerte der jeweiligen queries speichern
|
|
|
121 |
$hash=md5($query);
|
|
|
122 |
if (!$status[$hash])
|
|
|
123 |
{
|
|
|
124 |
$status[$hash]=array
|
|
|
125 |
(
|
|
|
126 |
"result" => "",
|
|
|
127 |
"numRows" => 0,
|
|
|
128 |
"endOfResult" => false
|
|
|
129 |
);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
$result = &$status[$hash]["result"];
|
|
|
133 |
$numRows = &$status[$hash]["numRows"];
|
|
|
134 |
$endOfResult = &$status[$hash]["endOfResult"];
|
|
|
135 |
|
|
|
136 |
if (($numRows == 0) && $endOfResult==false) // Beginn des Aufrufes: EoR = false $numRows=0
|
|
|
137 |
{
|
|
|
138 |
$result = mysql_query ($query) or die (mysql_errno().": ".mysql_error()."<hr>".pre($query,true)."<hr>");
|
|
|
139 |
$numRows = mysql_num_rows($result);
|
|
|
140 |
$endOfResult=false;
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
if ($numRows > 0) // Mittendrinn: numRows > 0
|
|
|
144 |
{
|
|
|
145 |
if ($numRows == 1) { $endOfResult=true; } // letzter durchlauf mit Daten
|
|
|
146 |
$numRows--; //
|
|
|
147 |
return mysql_fetch_assoc($result);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
if (($numRows == 0) && $endOfResult==true) // letzter durchlauf
|
|
|
151 |
{
|
|
|
152 |
$endOfResult=false; // Werte zurücksetzen
|
|
|
153 |
return false; // Ende zurückliefern
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
return false;
|
|
|
157 |
}
|
|
|
158 |
?>
|