1 |
6daefa8c
|
Petr Lukašík
|
<?php
|
2 |
|
|
require_once("./functions/dictionary.php");
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* Pomocna funkce, vraci do tabulky zformatovany zaznam
|
6 |
|
|
*
|
7 |
|
|
* @param $Record polozka tabulky nactena z db
|
8 |
|
|
* @return do tabulky zformatovany zaznam
|
9 |
|
|
*/
|
10 |
|
|
function get_row_of_table($Record, $od = 1, $do = 2) {
|
11 |
|
|
$navrat .= "<tr class=\"akt\">\n ";
|
12 |
|
|
$navrat .= '<td><input type="checkbox" name="smaz['.$Record[0].']" /></td>'.
|
13 |
|
|
'<td><a href="?nav_id=edit_user&user_id='.$Record[0].'">uprav</a></td>';
|
14 |
|
|
for($j=$od;$j<$do;$j++) {
|
15 |
|
|
$navrat .= "<td>";
|
16 |
|
|
$navrat .= "$Record[$j]";
|
17 |
|
|
$navrat .= " </td>\n";
|
18 |
|
|
}
|
19 |
|
|
$navrat .= "</tr> \n ";
|
20 |
|
|
return $navrat;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
function get_pocet_uzivatel() {
|
24 |
|
|
require_once("./classes/db.php");
|
25 |
|
|
$spojeni = new DB_Sql();
|
26 |
|
|
$dotaz = "SELECT \"IDuser\" FROM \"user\" ";
|
27 |
|
|
$spojeni->query($dotaz);
|
28 |
|
|
return $spojeni->num_rows();
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
function get_razeni($l_order = "IDuser", $l_od = 0, $l_limit = 30) {
|
32 |
|
|
global $order;
|
33 |
|
|
global $od;
|
34 |
|
|
global $limit;
|
35 |
|
|
|
36 |
|
|
$order = $l_order;
|
37 |
|
|
$od = $l_od;
|
38 |
|
|
$limit = $l_limit;
|
39 |
|
|
$pocet_uzivatel = get_pocet_uzivatel();
|
40 |
|
|
$nav = "list_user";
|
41 |
|
|
|
42 |
|
|
$navrat = "<p class=\"akt\"></p>";
|
43 |
|
|
$navrat .= "<table>
|
44 |
|
|
<tr class=\"nadpis_sekce\"><td><form action\"\" method=\"post\" name=\"razeni\">
|
45 |
|
|
Zobrazeno $limit uživatel od $od. (Ve slovniku celkem $pocet_uzivatel)<br />
|
46 |
|
|
Řadit podle
|
47 |
|
|
<select name=\"order\">
|
48 |
|
|
<option value=\"IDuser\">Identifikátor</option>
|
49 |
|
|
<option value=\"name\">jméno</option>
|
50 |
|
|
<option value=\"surname\">příjmení</option>
|
51 |
|
|
<option value=\"city\">město</option>
|
52 |
|
|
<option value=\"email\">email</option>
|
53 |
|
|
<option value=\"nationality\">národnosti</option>
|
54 |
|
|
<option value=\"number_of_usage\">počtu přihlášení</option>
|
55 |
|
|
<option value=\"date_created\">datum vytvoření</option>
|
56 |
|
|
<option value=\"date_last_visit\">datum poslední návštěvy</option>
|
57 |
|
|
<option value=\"privileges\">práva</option>
|
58 |
|
|
<option value=\"nick\">nick</option>
|
59 |
|
|
</select>
|
60 |
|
|
od: <input type=\"text\" name=\"od\" value=\"$od\" size=\"5\" />
|
61 |
|
|
počet: <input type=\"text\" name=\"limit\" value=\"$limit\" size=\"5\" />
|
62 |
|
|
<input type=\"submit\" name=\"serad\" value=\"Zobraz\" /> </form>
|
63 |
|
|
</td></tr>
|
64 |
|
|
<tr class=\"nadpis_sekce\"><td align=\"center\">
|
65 |
|
|
<a href=\"?nav_id=$nav&serad=true&order=$order&od=0&limit=$limit\">
|
66 |
|
|
Na začátek </a> | ";
|
67 |
|
|
if ($od-$limit >= 0)
|
68 |
|
|
$navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
|
69 |
|
|
($od-$limit)."&limit=$limit\">
|
70 |
|
|
Předchozích $limit </a> | ";
|
71 |
|
|
if ($od+$limit < $pocet_uzivatel)
|
72 |
|
|
$navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
|
73 |
|
|
($od+$limit)."&limit=$limit\">
|
74 |
|
|
Dalších $limit </a> | ";
|
75 |
|
|
$navrat .="<a href=\"?nav_id=$nav&serad=true&order=$order&od=".
|
76 |
|
|
($pocet_uzivatel-$limit)."&limit=$limit\">
|
77 |
|
|
Na konec </a></td>
|
78 |
|
|
";
|
79 |
|
|
$navrat .= "</td></tr></table>";
|
80 |
|
|
return $navrat;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
function get_header_of_table() {
|
84 |
|
|
return "<tr class=\"nadpis_sekce\">
|
85 |
|
|
<td>vybrané</td>
|
86 |
|
|
<td> </td>
|
87 |
|
|
<td>jméno</td>
|
88 |
|
|
<td>příjmení</td>
|
89 |
|
|
<td>město</td>
|
90 |
|
|
<td>email</td>
|
91 |
|
|
<td>národnost</td>
|
92 |
|
|
<td>počet přihlášení</td>
|
93 |
|
|
<td>vytvořen</td>
|
94 |
|
|
<td>naposledy přihlášen</td>
|
95 |
|
|
<td>práva</td>
|
96 |
|
|
<td>nick</td>
|
97 |
|
|
</tr>";
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
function get_foot_of_table() {
|
101 |
|
|
return '<tr class="nadpis_sekce"><td><input type="submit" name="delete" value="Smaž"></td><td></td>
|
102 |
|
|
<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
function print_table_of_user($order = "IDuser", $od = 0, $limit = 30) {
|
106 |
|
|
require_once("./classes/db.php");
|
107 |
|
|
$spojeni = new DB_Sql();
|
108 |
|
|
$dotaz = "SELECT * FROM \"user\" ORDER BY \"$order\" OFFSET $od LIMIT $limit";
|
109 |
|
|
$radky = $spojeni->query($dotaz);
|
110 |
|
|
$navrat .= "<h3 class=\"nadpis2\">Výpis uživatelů</h3>";
|
111 |
|
|
$navrat .= get_razeni($order, $od, $limit);
|
112 |
|
|
$navrat .= "<table><form action=\"\" method=\"post\">";
|
113 |
|
|
$navrat .= get_header_of_table();
|
114 |
|
|
while ($spojeni->next_record()) {
|
115 |
|
|
$navrat .= get_row_of_table($spojeni->Record, 1, 11);
|
116 |
|
|
}
|
117 |
|
|
$navrat .= get_foot_of_table();
|
118 |
|
|
$navrat .= '<input type="hidden" name="action" value="delete_user">';
|
119 |
|
|
$navrat .= "</form></table>";
|
120 |
|
|
echo $navrat;
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
function nick_exists($nick) {
|
126 |
|
|
require_once("./classes/db.php");
|
127 |
|
|
$spojeni = new DB_Sql();
|
128 |
|
|
$dotaz = "SELECT * FROM \"user\" WHERE nick LIKE '$nick'";
|
129 |
|
|
$spojeni->query($dotaz);
|
130 |
|
|
if ($spojeni->Errno != 0) {
|
131 |
|
|
print_hlasku($spojeni->$Error);
|
132 |
|
|
return true;
|
133 |
|
|
}
|
134 |
|
|
//echo $nick." / ".$spojeni->num_rows();
|
135 |
|
|
if ($spojeni->num_rows() == 0)
|
136 |
|
|
return false;
|
137 |
|
|
|
138 |
|
|
return true;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
function insert_user($name, $surname, $city, $email, $nationality, $privileges, $nick, $password, $vypisovat = true){
|
142 |
|
|
require_once("./classes/db.php");
|
143 |
|
|
$spojeni = new DB_Sql();
|
144 |
|
|
//$NOW = Date("YmdHis");
|
145 |
|
|
|
146 |
|
|
$dotaz = "INSERT INTO \"user\" (\"name\",
|
147 |
|
|
\"surname\",
|
148 |
|
|
\"city\",
|
149 |
|
|
\"email\",
|
150 |
|
|
\"nationality\",
|
151 |
|
|
\"number_of_usage\",
|
152 |
|
|
\"date_created\",
|
153 |
|
|
\"privileges\",
|
154 |
|
|
\"nick\",
|
155 |
|
|
\"pass\")
|
156 |
|
|
VALUES ('$name',
|
157 |
|
|
'$surname',
|
158 |
|
|
'$city',
|
159 |
|
|
'$email',
|
160 |
|
|
'$nationality',
|
161 |
|
|
'0',
|
162 |
|
|
'NOW',
|
163 |
|
|
'$privileges',
|
164 |
|
|
'$nick',
|
165 |
|
|
'$password')";
|
166 |
|
|
$spojeni->query($dotaz);
|
167 |
|
|
if ($spojeni->Errno != 0) {
|
168 |
|
|
if ($vypisovat) print_hlasku("Bohužel, uživatele '$name $surname' se nepodařilo přidat.");
|
169 |
|
|
return false;
|
170 |
|
|
}
|
171 |
|
|
if ($vypisovat) print_hlasku ("Uživatel '$name $surname' přidán..");
|
172 |
|
|
return true;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
function possible_to_delete_user($user_id) {
|
176 |
|
|
require_once("./classes/db.php");
|
177 |
|
|
$spojeni = new DB_Sql();
|
178 |
|
|
$dotaz = "SELECT * FROM dict WHERE usr LIKE '$user_id'";
|
179 |
|
|
$spojeni->query($dotaz);
|
180 |
|
|
if ($spojeni->Errno != 0) {
|
181 |
|
|
print_hlasku($spojeni->$Error);
|
182 |
|
|
return false;
|
183 |
|
|
}
|
184 |
|
|
//echo $spojeni->num_rows();
|
185 |
|
|
if ($spojeni->num_rows() == 0)
|
186 |
|
|
return true;
|
187 |
|
|
|
188 |
|
|
return false;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
function delete_user($ID) {
|
192 |
|
|
if (!possible_to_delete_user($ID)) {
|
193 |
|
|
print_hlasku("Kontrola integrity hlásí: Nelze smazat");
|
194 |
|
|
return false;
|
195 |
|
|
}
|
196 |
|
|
require_once("./classes/db.php");
|
197 |
|
|
$spojeni = new DB_Sql();
|
198 |
|
|
$dotaz = "DELETE FROM \"user\" WHERE \"IDuser\" = '$ID'";
|
199 |
|
|
$spojeni->query($dotaz);
|
200 |
|
|
if ($spojeni->Errno != 0) {
|
201 |
|
|
return false;
|
202 |
|
|
}
|
203 |
|
|
return true;
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
function update_user($name, $surname, $city, $email, $nationality, $privileges, $nick, $user_id, $password) {
|
207 |
|
|
require_once("./classes/db.php");
|
208 |
|
|
$spojeni = new DB_Sql();
|
209 |
|
|
$dotaz = "UPDATE \"user\" SET \"name\" = '$name',
|
210 |
|
|
\"surname\" = '$surname',
|
211 |
|
|
\"city\" = '$city',
|
212 |
|
|
\"email\" = '$email',
|
213 |
|
|
\"nationality\" = '$nationality',
|
214 |
|
|
\"privileges\" = '$privileges',
|
215 |
|
|
\"nick\" = '$nick'";
|
216 |
|
|
if (!Empty($password)) {
|
217 |
|
|
$dotaz .= ", \"pass\" = '$password'";
|
218 |
|
|
}
|
219 |
|
|
$dotaz .= " WHERE \"IDuser\" = '$user_id'";
|
220 |
|
|
|
221 |
|
|
$spojeni->query($dotaz);
|
222 |
|
|
if ($spojeni->Errno != 0) {
|
223 |
|
|
print_hlasku("Uživatel se nepodařilo upravit.");
|
224 |
|
|
}
|
225 |
|
|
print_hlasku("Uživatel změněn.");
|
226 |
|
|
echo_zpet_do_uzivatel();
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
function get_user($user_id) {
|
230 |
|
|
require_once("./classes/db.php");
|
231 |
|
|
$spojeni = new DB_Sql();
|
232 |
|
|
$dotaz = "SELECT * FROM \"user\" WHERE \"IDuser\" LIKE '$user_id'";
|
233 |
|
|
$radky = $spojeni->query($dotaz);
|
234 |
|
|
|
235 |
|
|
$spojeni->next_record();
|
236 |
|
|
|
237 |
|
|
return $spojeni->Record;
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
function get_privileges_chooser($privileges = 1) {
|
241 |
|
|
$navrat = "<select name=\"privileges\" size=\"1\">\n";
|
242 |
|
|
|
243 |
|
|
$navrat .= " <option value=\"1\"";
|
244 |
|
|
if ($privileges == 1) $navrat .= " selected=\"true\"";
|
245 |
|
|
$navrat .= "> Uživatel </option>\n";
|
246 |
|
|
|
247 |
|
|
$navrat .= " <option value=\"2\"";
|
248 |
|
|
if ($privileges == 2) $navrat .= " selected=\"true\"";
|
249 |
|
|
$navrat .= "> Uživatel (smí i zapisovat) </option>\n";
|
250 |
|
|
|
251 |
|
|
$navrat .= " <option value=\"3\"";
|
252 |
|
|
if ($privileges == 3) $navrat .= " selected=\"true\"";
|
253 |
|
|
$navrat .= "> Administrátor </option>\n";
|
254 |
|
|
|
255 |
|
|
$navrat .= '</select>';
|
256 |
|
|
return $navrat;
|
257 |
|
|
}
|
258 |
|
|
?>
|