Mercurial > hg > fapweb
annotate ajax.php @ 14:e36c4d2b09c4
Fix settings to work, clean up the code, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 06 Dec 2012 16:13:08 +0200 |
parents | 4c5f651aa107 |
children | 6da681d1f62a |
rev | line source |
---|---|
0 | 1 <? |
2 require "mconfig.inc.php"; | |
3 require "msite.inc.php"; | |
4 | |
5 // Check if we are allowed to execute | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
6 if (!stCheckHTTPS() || !stAdmSessionAuth()) |
0 | 7 { |
8 header("Status: 404 Not Found"); | |
9 exit; | |
10 } | |
11 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
12 stSetupCacheControl(); |
0 | 13 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
14 // Initiate SQL database connection |
0 | 15 if (!stConnectSQLDB()) |
16 die("Could not connect to SQL database."); | |
17 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
18 // Fetch non-"hardcoded" settings from SQL database |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
19 stReloadSettings(); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
20 |
0 | 21 |
22 function setStatus($val, $msg) | |
23 { | |
24 global $statusSet; | |
25 if (!$statusSet) | |
26 { | |
27 header("Status: ".$val." ".$msg); | |
28 } | |
29 $statusSet = TRUE; | |
30 } | |
31 | |
32 | |
33 function execSQLCond($sql, $okmsg) | |
34 { | |
35 if (($res = stExecSQL($sql)) !== FALSE) | |
36 { | |
37 if ($okmsg != "") | |
38 setStatus(200, $okmsg); | |
39 return $res; | |
40 } | |
41 else | |
42 { | |
43 setStatus(900, "Error in SQL execution."); | |
44 return FALSE; | |
45 } | |
46 } | |
47 | |
48 | |
49 // XMLHttp responses | |
50 $action = "ERROR"; | |
51 if (stChkRequestItem("action") && stChkRequestItem("type")) | |
52 { | |
53 $action = $_REQUEST["action"]; | |
54 $type = $_REQUEST["type"]; | |
55 } | |
56 | |
57 | |
58 switch ($action) | |
59 { | |
60 case "dump": | |
61 if (($res = execSQLCond( | |
62 "SELECT * FROM attendees WHERE email NOT NULL AND email != '' ORDER BY regtime DESC", | |
63 "Dump OK.")) !== FALSE) | |
64 { | |
65 $out1 = array(); | |
66 $out2 = array(); | |
67 | |
68 foreach ($res as $item) | |
69 { | |
70 $out1[] = $item["name"]." <".$item["email"].">"; | |
71 $out2[] = $item["email"]; | |
72 } | |
73 | |
74 echo "<br /><hr />". | |
75 implode(", ", $out1)."<br /><hr /><br />". | |
76 implode("<br />", $out1)."<br /><hr /><br />". | |
77 implode(", ", $out2)."<br /><hr /><br />". | |
78 implode("<br />", $out2)."<br /><hr />"; | |
79 | |
80 } | |
81 break; | |
82 | |
83 case "get": | |
84 switch ($type) | |
85 { | |
86 case "news": | |
87 $sql = "SELECT * FROM news ORDER BY utime DESC"; | |
88 break; | |
89 | |
90 case "attendees": | |
91 $sql = "SELECT * FROM attendees ORDER BY regtime DESC"; | |
92 break; | |
93 | |
94 case "compos": | |
95 $sql = "SELECT * FROM compos ORDER BY id DESC"; | |
96 break; | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
97 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
98 case "settings": |
14
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
99 $prefix = "st"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
100 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
101 echo |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
102 "<table>\n"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
103 foreach (stExecSQL("SELECT * FROM settings WHERE vtype<>".VT_TEXT) as $item) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
104 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
105 echo |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
106 " <tr>\n". |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
107 " <td>"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
108 $id = $item["key"]; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
109 switch ($item["vtype"]) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
110 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
111 case VT_INT: |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
112 echo stGetFormTextInput(10, 10, "", $id, $prefix, $item["vint"]); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
113 break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
114 case VT_STR: |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
115 echo stGetFormTextInput(40, 128, "", $id, $prefix, $item["vstr"]); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
116 break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
117 case VT_BOOL: |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
118 echo stGetFormCheckBoxInput("", $id, $prefix, $item["vint"], ""); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
119 break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
120 } |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
121 echo "</td>\n". |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
122 " <td>".$item["desc"]."</td>\n". |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
123 " </tr>\n"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
124 } |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
125 echo "</table>\n"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
126 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
127 foreach (stExecSQL("SELECT * FROM settings WHERE vtype=".VT_TEXT) as $item) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
128 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
129 echo "<h2>".chentities($item["desc"])."</h2>\n". |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
130 stGetFormTextArea(10, 60, "", $item["key"], $prefix, $item["vtext"]). |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
131 "\n<br />\n"; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
132 } |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
133 break; |
0 | 134 |
135 case "entries": | |
136 stGetCompoList(TRUE); | |
137 | |
138 foreach ($compos as $id => $compo) | |
139 { | |
140 echo | |
141 "<form>\n". | |
142 " <table class=\"misc\">\n". | |
143 " <tr>\n". | |
144 " <th colspan=\"3\">".chentities($compo["name"])."</th>\n". | |
145 " </tr>\n". | |
146 " <tr>\n". | |
147 " <th>Title</th>\n". | |
148 " <th>Author</th>\n". | |
149 " <th>Actions</th>\n". | |
150 " </tr>\n"; | |
151 | |
152 $prefix = "en"; | |
153 foreach ($compo["entries"] as $eid => $entry) | |
154 { | |
155 echo | |
156 " <tr id=\"entry".$eid."\">\n". | |
157 " <td>".stGetFormTextInput(40, 64, "name", $eid, "en", $entry["name"])."</td>\n". | |
158 " <td>".stGetFormTextInput(40, 64, "author", $eid, "en", $entry["author"])."</td>\n". | |
159 " <td>". | |
160 stGetFormButtonInput("update", $eid, $prefix, " Update ", "updateEntry(".$eid.")"). | |
161 stGetFormButtonInput("delete", $eid, $prefix, " Delete ", "deleteEntry(".$eid.")"). | |
162 "</td>\n". | |
163 " </tr>\n"; | |
164 } | |
165 $prefix = "ne"; | |
166 echo | |
167 " <tr>\n". | |
168 " <td>".stGetFormTextInput(40, 64, "name", $id, "ne", "")."</td>\n". | |
169 " <td>".stGetFormTextInput(40, 64, "author", $id, "ne", "")."</td>\n". | |
170 " <td>".stGetFormButtonInput("add", $id, $prefix, " Add new ", "addEntry(".$id.")")."</td>\n". | |
171 " </tr>\n". | |
172 " </table>\n". | |
173 "</form>\n"; | |
174 } | |
175 break; | |
176 | |
177 case "voters": | |
178 $sql = "SELECT * FROM voters ORDER BY id ASC"; | |
179 } | |
180 | |
181 if (isset($sql) && ($res = execSQLCond($sql, "")) !== FALSE) | |
182 { | |
183 if ($type == "news") | |
184 { | |
185 foreach ($res as $item) | |
186 { | |
187 $id = $item["id"]; | |
188 stPrintNewsItem($item, | |
189 "<br />". | |
190 " <button class=\"button\" id=\"ndel".$id. | |
191 "\" type=\"button\" onclick=\"deleteNews(".$id. | |
192 ")\">Delete</button>\n" | |
193 ); | |
194 } | |
195 } | |
196 else | |
197 if ($type == "attendees") | |
198 { | |
199 echo | |
200 "<table class=\"attendees\">\n". | |
201 " <tr>\n". | |
202 " <th>Name</th>\n". | |
203 " <th class=\"groups\">Group(s)</th>\n". | |
204 " <th class=\"regtime\">Registered</th>\n". | |
205 " <th class=\"oneliner\">Oneliner</th>\n". | |
206 " <th class=\"email\">E-mail</th>\n". | |
207 " <th>Actions</th>\n". | |
208 " </tr>\n"; | |
209 $row = 0; | |
210 foreach ($res as $item) | |
211 stPrintAttendee($item, $row++, TRUE); | |
212 echo "</table>\n"; | |
213 } | |
214 else | |
215 if ($type == "compos") | |
216 { | |
217 foreach ($res as $item) | |
218 { | |
219 $id = $item["id"]; | |
220 $prefix = "co"; | |
221 echo | |
222 "<div id=\"compo".$id."\">\n". | |
223 "<h2>#".$id." - ".chentities($item["name"])."</h2>\n". | |
224 stGetFormTextInput(40, 64, "name", $id, $prefix, $item["name"])."\n". | |
225 stGetFormCheckBoxInput("enabled", $id, $prefix, $item["enabled"], "Enabled")."<br />\n". | |
226 stGetFormTextArea(5, 60, "description", $id, $prefix, $item["description"])."\n<br />\n". | |
227 stGetFormButtonInput("update", $id, $prefix, " Update ", "updateCompo(".$id.")")."\n". | |
228 "</div>\n". | |
229 "<hr />\n"; | |
230 } | |
231 } | |
232 else | |
233 if ($type == "voters") | |
234 { | |
235 echo | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
236 "<table class=\"voters\">\n". |
0 | 237 " <tr>\n". |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
238 " <th class=\"vid\">#</th>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
239 " <th class=\"vkey\">Vote key</th>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
240 " <th class=\"vname\">Name</th>\n". |
14
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
241 " <th class=\"vactive\">Active</th>\n". |
0 | 242 " </tr>\n"; |
243 $row = 0; | |
244 foreach ($res as $item) | |
245 { | |
246 $id = $item["id"]; | |
247 $prefix = "vo"; | |
248 echo | |
249 " <tr>\n". | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
250 " <tr class=\"".($item["enabled"] ? "vactive " : ""). |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
251 ($row % 2 == 1 ? "rodd" : "reven")."\" id=\"voter".$id."\">\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
252 " <td class=\"vid\">".sprintf("%04d", $id)."</td>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
253 " <td class=\"vkey\">".chentities($item["key"])."</td>\n". |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
254 " <td class=\"vname\">".stGetFormTextInput(40, 64, "name", $id, $prefix, $item["name"], |
0 | 255 "onBlur=\"updateVoter(".$id.")\" autocomplete=\"off\"")."</td>\n". |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
256 " <td class=\"vactive\">".stGetFormCheckBoxInput("enabled", $id, $prefix, $item["enabled"], "", |
0 | 257 "onClick=\"updateVoter(".$id.")\"")."</td>\n". |
258 " </tr>\n"; | |
259 $row++; | |
260 } | |
261 echo "</table>\n"; | |
262 } | |
263 } | |
264 break; | |
265 | |
266 case "delete": | |
267 if (stChkRequestItem("id")) | |
268 { | |
269 $id = intval(stGetRequestItem("id")); | |
270 | |
271 if ($type == "news") | |
272 $sql = stPrepareSQL("DELETE FROM news WHERE id=%d AND persist=0", $id); | |
273 else | |
274 if ($type == "attendees") | |
275 $sql = stPrepareSQL("DELETE FROM attendees WHERE id=%d", $id); | |
276 else | |
277 if ($type == "entries") | |
278 $sql = stPrepareSQL("DELETE FROM entries WHERE id=%d", $id); | |
279 | |
280 execSQLCond($sql, "OK, ".$type." item ".$id." deleted."); | |
281 } | |
282 else | |
283 setStatus(901, "No ID specified."); | |
284 break; | |
285 | |
286 case "add": | |
287 if ($type == "news" && stChkRequestItem("text") && stChkRequestItem("author") && stChkRequestItem("title")) | |
288 { | |
289 $sql = stPrepareSQL( | |
290 "INSERT INTO news (utime,title,text,author) VALUES (%d,%S,%Q,%S)", | |
291 time(), "title", "text", "author"); | |
292 | |
293 execSQLCond($sql, "OK, news item added."); | |
294 } | |
295 else | |
296 if ($type == "compo" && stChkRequestItem("name") && stChkRequestItem("description")) | |
297 { | |
298 $sql = stPrepareSQL( | |
299 "INSERT INTO compos (name,description,enabled) VALUES (%S,%Q,0)", | |
300 "name", "description", 0); | |
301 | |
302 execSQLCond($sql, "OK, compo added."); | |
303 } | |
304 else | |
305 if ($type == "entry" && stChkRequestItem("name") && stChkRequestItem("author") && stChkRequestItem("compo_id")) | |
306 { | |
307 $sql = stPrepareSQL( | |
308 "INSERT INTO entries (name,author,compo_id) VALUES (%S,%Q,%D)", | |
309 "name", "author", "compo_id"); | |
310 | |
311 execSQLCond($sql, "OK, entry added."); | |
312 } | |
313 else | |
314 setStatus(902, "No data."); | |
315 break; | |
316 | |
317 case "update": | |
318 if ($type == "attendees" && stChkRequestItem("id") && | |
319 stChkRequestItem("email") && stChkRequestItem("oneliner")) | |
320 { | |
321 $sql = stPrepareSQLUpdate("attendees", | |
322 "WHERE id=".intval(stGetRequestItem("id")), | |
323 array( | |
324 "email" => "S", | |
325 "oneliner" => "S", | |
326 )); | |
327 | |
328 execSQLCond($sql, "OK, attendee updated."); | |
329 } | |
330 else | |
331 if ($type == "news" && stChkRequestItem("id") && | |
332 stChkRequestItem("text") && stChkRequestItem("author") && | |
333 stChkRequestItem("title")) | |
334 { | |
335 $sql = stPrepareSQLUpdate("news", | |
336 "WHERE id=".intval(stGetRequestItem("id")), | |
337 array( | |
338 "title" => "S", | |
339 "text" => "Q", | |
340 "author" => "S" | |
341 )); | |
342 | |
343 execSQLCond($sql, "OK, news item updated."); | |
344 } | |
345 else | |
346 if ($type == "compo" && stChkRequestItem("id") && | |
347 stChkRequestItem("name") && stChkRequestItem("description") && | |
348 stChkRequestItem("enabled")) | |
349 { | |
350 $sql = stPrepareSQLUpdate("compos", | |
351 "WHERE id=".intval(stGetRequestItem("id")), | |
352 array( | |
353 "name" => "S", | |
354 "description" => "Q", | |
355 "enabled" => "B", | |
356 )); | |
357 | |
358 execSQLCond($sql, "OK, compo updated."); | |
359 } | |
360 else | |
361 if ($type == "voter" && stChkRequestItem("id") && | |
362 stChkRequestItem("name") && stChkRequestItem("enabled")) | |
363 { | |
364 $sql = stPrepareSQLUpdate("voters", | |
365 "WHERE id=".intval(stGetRequestItem("id")), | |
366 array( | |
367 "name" => "S", | |
368 "enabled" => "B", | |
369 )); | |
370 | |
371 execSQLCond($sql, "OK, voter updated."); | |
372 } | |
373 else | |
374 if ($type == "entry" && stChkRequestItem("id") && | |
3
916623924bd5
More work on the party management and voting system.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
375 stChkRequestItem("name") && stChkRequestItem("author")) |
0 | 376 { |
377 $sql = stPrepareSQLUpdate("entries", | |
378 "WHERE id=".intval(stGetRequestItem("id"). | |
379 " AND compo_id=".intval(stGetRequestItem("compo_id"))), | |
380 array( | |
381 "name" => "S", | |
382 "author" => "S", | |
383 )); | |
384 | |
385 execSQLCond($sql, "OK, voter updated."); | |
386 } | |
387 else | |
14
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
388 if ($type == "settings") |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
389 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
390 foreach (stExecSQL("SELECT * FROM settings") as $item) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
391 if (stChkRequestItem($item["key"])) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
392 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
393 $val = stGetRequestItem($item["key"]); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
394 switch ($item["vtype"]) |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
395 { |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
396 case VT_INT: $vsql = stPrepareSQL("vint=%d", $val); break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
397 case VT_BOOL: $vsql = stPrepareSQL("vint=%d", $val ? 1 : 0); break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
398 case VT_STR: $vsql = stPrepareSQL("vstr=%s", $val); break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
399 case VT_TEXT: $vsql = stPrepareSQL("vtext=%s", $val); break; |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
400 } |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
401 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
402 $sql = "UPDATE settings SET ".$vsql." WHERE key=".$db->quote($item["key"]); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
403 execSQLCond($sql, "OK, setting updated."); |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
404 } |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
405 } |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
406 else |
0 | 407 setStatus(902, "No data."); |
408 break; | |
409 | |
410 default: | |
411 setStatus(404, "Not Found"); | |
412 break; | |
413 } | |
414 | |
415 ?> |