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