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