Mercurial > hg > fapweb
annotate msite.inc.php @ 50:184a4188555c
Move CLI helper functions to createdb.php, as they are now only used there.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 05 Oct 2013 04:14:21 +0300 |
parents | 238c73840b61 |
children | 7bdf89601ba0 |
rev | line source |
---|---|
0 | 1 <? |
2 // | |
9
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
3 // FAPWEB - Demo Party Website System System |
33 | 4 // Generic and miscellaneous site support code |
9
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
5 // (C) Copyright 2012 Matti 'ccr' Hamalainen <ccr@tnsp.org> |
0 | 6 // |
9
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
7 |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
8 // Globals and definitions |
0 | 9 $errorSet = FALSE; |
10 $errorMsg = ""; | |
11 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
12 define("VT_STR", 1); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
13 define("VT_INT", 2); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
14 define("VT_BOOL", 3); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
15 define("VT_TEXT", 4); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
16 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
17 |
32 | 18 if (function_exists("ini_set")) |
19 { | |
20 // Use cookies to store the session ID on the client side | |
21 @ini_set("session.use_only_cookies", 1); | |
22 | |
23 // Disable transparent Session ID support | |
24 @ini_set("session.use_trans_sid", 0); | |
25 } | |
26 | |
27 | |
0 | 28 function stError($msg) |
29 { | |
30 global $errorSet, $errorMsg; | |
31 $errorSet = TRUE; | |
32 $errorMsg .= "<li>".$msg."</li>\n"; | |
33 } | |
34 | |
35 | |
36 function stCheckHTTPS() | |
37 { | |
38 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
39 } | |
40 | |
41 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
42 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
43 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
44 header("Cache-Control: must-revalidate, no-store, private"); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
45 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
49 function stReloadSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
50 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
51 global $siteSettings; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
52 $res = stExecSQL("SELECT * FROM settings"); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
53 if ($res !== FALSE) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
54 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
55 foreach ($res as $row) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
56 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
57 switch ($row["vtype"]) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
58 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
59 case VT_INT: $val = intval($row["vint"]); break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
60 case VT_BOOL: $val = intval($row["vint"]) ? true : false; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
61 case VT_STR: $val = $row["vstr"]; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
62 case VT_TEXT: $val = $row["vtext"]; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
63 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
64 $siteSettings[$row["key"]] = $val; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
65 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
66 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
67 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
68 die("Error fetching site settings."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
69 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
70 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
71 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 function stGetSetting($name) |
0 | 73 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
74 global $siteSettings; |
0 | 75 if (isset($siteSettings[$name])) |
76 return $siteSettings[$name]; | |
77 else | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
78 die("No config value for '".$name."'.\n"); |
0 | 79 } |
80 | |
81 | |
82 function stChkSetting($name) | |
83 { | |
84 global $siteSettings; | |
85 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
86 } | |
87 | |
88 | |
89 function dhentities($str) | |
90 { | |
91 return str_replace(array("<",">"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
92 } | |
93 | |
94 | |
95 function chentities($str) | |
96 { | |
97 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
98 } | |
99 | |
100 | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
101 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
102 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
103 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
104 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
105 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
106 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
107 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
108 |
0 | 109 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
110 { | |
111 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
112 "<input ".$extra." type=\"checkbox\" ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
113 ($checked ? "checked=\"checked\" " : "")." />". |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
114 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : ""); |
0 | 115 } |
116 | |
117 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
118 function stGetFormRadioButtonInput($name, $id, $prefix, $value, $checked, $label, $extra = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
119 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
120 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
121 "<input ".$extra." type=\"radio\" ".stGetIDName($name, $id, $prefix). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
122 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
123 ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : ""); |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
124 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
125 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
126 |
0 | 127 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
128 { | |
129 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
130 "<input type=\"button\" ".stGetIDName($name, $id, $prefix). |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
131 "value=\" ".chentities($label)." \" ". |
0 | 132 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
133 } | |
134 | |
135 | |
136 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") | |
137 { | |
138 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
139 "<textarea ".$extra." ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
140 "rows=\"".$rows."\" cols=\"".$cols."\">". |
0 | 141 (isset($value) ? chentities($value) : ""). |
142 "</textarea>"; | |
143 } | |
144 | |
145 | |
146 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
147 { | |
148 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
149 "<input ".$extra." type=\"text\" ".stGetIDName($name, $id, $prefix). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
150 "size=\"".$size."\" maxlength=\"".$len."\"". |
0 | 151 (isset($value) ? " value=\"".chentities($value)."\"" : ""). |
152 " />"; | |
153 } | |
154 | |
155 | |
156 function stGetFormPasswordInput($name, $id, $prefix) | |
157 { | |
158 return | |
13 | 159 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." />"; |
0 | 160 } |
161 | |
162 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
163 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
164 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
165 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
166 "<input type=\"submit\" name=\"".$name. |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
167 "\" value=\" ".chentities($label)." \" ". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
168 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
169 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
170 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
171 |
0 | 172 function stGetFormHiddenInput($name, $value) |
173 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
174 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
175 "<input type=\"hidden\" name=\"".$name. |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
176 "\" value=\"".chentities($value)."\" />"; |
0 | 177 } |
178 | |
179 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
180 function stGetFormStart($name, $action = "", $method = "post") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
181 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
182 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
183 "<form name=\"".$name."\" action=\"". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
184 ($action != "" ? $action : $name). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
185 "\" method=\"".$method."\">\n"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
186 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
187 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
188 |
0 | 189 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "") |
190 { | |
191 return | |
192 "<td class=\"".$name."\">". | |
193 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)). | |
194 "</td>"; | |
195 } | |
196 | |
197 | |
198 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") | |
199 { | |
200 echo " <tr><th>".chentities($text1)."</th><td>". | |
15
ea0f98a0bed8
Fix some issues and bugs caused by recent changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
201 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). |
0 | 202 "</td><td>".chentities($text2)."</td></tr>\n"; |
203 } | |
204 | |
205 | |
206 function stPrintFormHiddenInput($name, $value) | |
207 { | |
208 echo " ".stGetFormHiddenInput($name, $value)."\n"; | |
209 } | |
210 | |
211 | |
212 function stChkDataItem($name) | |
213 { | |
214 return !isset($_REQUEST[$name]) || strlen(trim($_REQUEST[$name])) < 1; | |
215 } | |
216 | |
217 | |
218 function stChkRequestItem($name) | |
219 { | |
220 return isset($_REQUEST[$name]); | |
221 } | |
222 | |
223 | |
224 function stGetRequestItem($name, $default = "") | |
225 { | |
226 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; | |
227 } | |
228 | |
229 | |
230 function stGetDRequestItem($name, $default = "") | |
231 { | |
232 return trim(urldecode(stGetRequestItem($name, $default))); | |
233 } | |
234 | |
235 | |
236 function stLogSQLError($sql) | |
237 { | |
238 global $db; | |
239 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\""); | |
240 } | |
241 | |
242 | |
243 function stConnectSQLDB() | |
244 { | |
245 global $db; | |
246 try { | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
247 $db = new PDO(stGetSetting("sqlDB")); |
0 | 248 } |
249 catch (PDOException $e) { | |
250 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
251 return FALSE; | |
252 } | |
253 return TRUE; | |
254 } | |
255 | |
256 | |
257 function stGetSQLParam($type, $value) | |
258 { | |
259 global $db; | |
260 switch ($type) | |
261 { | |
262 case "d": | |
263 return intval($value); | |
264 | |
265 case "s": | |
266 return $db->quote($value); | |
267 | |
268 case "D": | |
269 return intval(stGetRequestItem($value)); | |
270 | |
271 case "S": | |
272 return $db->quote(stGetDRequestItem($value)); | |
273 | |
274 case "Q": | |
275 return $db->quote(stripslashes(stGetDRequestItem($value))); | |
276 | |
277 case "B": | |
278 return intval(stGetRequestItem($value)) ? 1 : 0; | |
279 } | |
280 } | |
281 | |
282 | |
283 function stPrepareSQL() | |
284 { | |
285 $argc = func_num_args(); | |
286 $argv = func_get_args(); | |
287 if ($argc < 1) | |
288 { | |
289 error_log("Invalid stPrepareSQL() call, no arguments!"); | |
290 return FALSE; | |
291 } | |
292 | |
293 $fmt = $argv[0]; | |
294 $len = strlen($fmt); | |
295 $sql = ""; | |
296 $argn = 1; | |
297 $pos = 0; | |
298 while ($pos < $len) | |
299 { | |
300 if ($fmt[$pos] == "%") | |
301 { | |
302 if ($argn < $argc) | |
303 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]); | |
304 else | |
305 { | |
306 error_log("Invalid SQL statement format string '".$fmt. | |
307 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
308 return FALSE; | |
309 } | |
310 } | |
311 else | |
312 $sql .= $fmt[$pos]; | |
313 $pos++; | |
314 } | |
315 | |
316 return $sql; | |
317 } | |
318 | |
319 | |
320 function stPrepareSQLUpdate($table, $cond, $pairs) | |
321 { | |
322 $sql = array(); | |
323 foreach ($pairs as $name => $attr) | |
324 { | |
325 $sql[] = $name."=".stGetSQLParam($attr, $name); | |
326 } | |
327 return | |
328 "UPDATE ".$table." SET ".implode(",", $sql). | |
329 ($cond != "" ? " ".$cond : ""); | |
330 } | |
331 | |
332 | |
333 function stExecSQL($sql) | |
334 { | |
335 global $db; | |
336 if (($res = $db->query($sql)) !== FALSE) | |
337 return $res; | |
338 else | |
339 { | |
340 stLogSQLError($sql); | |
341 stError("Oh noes! SQL error #23!"); | |
342 return FALSE; | |
343 } | |
344 } | |
345 | |
346 | |
347 function stFetchSQL($sql) | |
348 { | |
349 global $db; | |
350 if (($res = $db->query($sql)) !== FALSE) | |
351 { | |
352 return $res->fetch(); | |
353 } | |
354 else | |
355 { | |
356 stLogSQLError($sql); | |
357 stError("Oh noes! SQL error #31!"); | |
358 return FALSE; | |
359 } | |
360 } | |
361 | |
362 | |
363 function stFetchSQLColumn($sql, $column = 0) | |
364 { | |
365 global $db; | |
366 if (($res = $db->query($sql)) !== FALSE) | |
367 { | |
368 return $res->fetchColumn($column); | |
369 } | |
370 else | |
371 { | |
372 stLogSQLError($sql); | |
373 stError("Oh noes! SQL error #81!"); | |
374 return FALSE; | |
375 } | |
376 } | |
377 | |
378 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
379 // |
37 | 380 // Site-specific common functions .. these should be elsewhere |
381 // | |
382 function stPrintAttendee($item, $row, $edit, $eclass = "") | |
383 { | |
384 $id = $item["id"]; | |
385 $prefix = "at"; | |
386 echo " ". | |
387 "<tr class=\"".($row % 2 == 1 ? "rodd" : "reven").$eclass."\" id=\"attendee".$id."\">". | |
388 stGetTDEditTextItem(FALSE, 20, 40, "name", $id, $prefix, $item["name"]). | |
389 stGetTDEditTextItem(FALSE, 20, 40, "groups", $id, $prefix, $item["groups"]). | |
390 "<td class=\"regtime\">".date("d M Y / H:i", $item["regtime"])."</td>". | |
391 stGetTDEditTextItem($edit, 30, 64, "oneliner", $id, $prefix, $item["oneliner"], "autocomplete=\"off\""); | |
392 | |
393 if ($edit) | |
394 { | |
395 echo | |
396 stGetTDEditTextItem($edit, 20, 40, "email", $id, $prefix, $item["email"], "autocomplete=\"off\""). | |
397 "<td>". | |
398 "<button class=\"button\" id=\"atupd".$id."\" type=\"button\" onclick=\"updateAttendee(".$id.")\">Update</button>". | |
399 "<button class=\"button\" id=\"atdel".$id."\" type=\"button\" onclick=\"deleteAttendee(".$id.")\">Delete</button>". | |
400 "</td>"; | |
401 } | |
402 | |
403 echo "</tr>\n"; | |
404 } | |
405 | |
406 | |
407 function stPrintNewsItem($item, $edit = "") | |
408 { | |
409 echo | |
410 "<div class=\"newsitem\" id=\"news".$item["id"]."\">\n". | |
411 " <h2>".chentities($item["title"])."</h2>\n". | |
412 " <div class=\"text\">".dhentities($item["text"])."</div>\n". | |
413 " <div class=\"sig\">-- ".chentities($item["author"])."<br />". | |
414 date("d M Y / H:i", $item["utime"]). | |
415 $edit."</div>\n". | |
416 "</div>\n"; | |
417 } | |
418 | |
419 | |
420 function stGetCompoList($fvisible, $fvoting = FALSE) | |
421 { | |
422 global $compos; | |
423 | |
424 // Get entries and competitions into an array structure | |
425 $sql = "SELECT * FROM compos"; | |
426 if ($fvisible || $fvoting) | |
427 { | |
428 $sql .= " WHERE ".implode(" AND ", array($fvisible ? "visible<>0" : "", $fvoting ? "voting<>0" : "")); | |
429 } | |
430 foreach (stExecSQL($sql) as $compo) | |
431 { | |
432 $id = $compo["id"]; | |
433 | |
434 $compos[$compo["id"]] = array( | |
435 "name" => $compo["name"], | |
436 "entries" => array() | |
437 ); | |
438 | |
439 $sql = stPrepareSQL("SELECT * FROM entries WHERE compo_id=%d", $id); | |
440 foreach (stExecSQL($sql) as $entry) | |
441 { | |
442 $compos[$id]["entries"][$entry["id"]] = $entry; | |
443 } | |
444 } | |
445 } | |
446 | |
447 | |
0 | 448 ?> |