Mercurial > hg > fapweb
annotate msitegen.inc.php @ 365:2e0a0d93b8c1
Sanitize secure pages scheme.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 03 Dec 2013 13:13:23 +0200 |
parents | bab3b508be55 |
children | a3caded43f6d |
rev | line source |
---|---|
0 | 1 <? |
2 // | |
160
0980e705dea0
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
3 // FAPWeb Simple Demoparty System |
33 | 4 // Generic and miscellaneous site support code |
160
0980e705dea0
Add some copyright headers.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
5 // (C) Copyright 2012-2013 Tecnic Software productions (TNSP) |
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; |
210 | 10 $errorMsgs = array(); |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
11 $statusSet = 0; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
12 $statusMsg = ""; |
0 | 13 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
14 // Value types |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
15 define("VT_STR", 1); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
16 define("VT_INT", 2); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
17 define("VT_BOOL", 3); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
18 define("VT_TEXT", 4); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
19 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
20 // Validation check types |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
21 define("CHK_TYPE", 1); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
22 define("CHK_ISLT", 2); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
23 define("CHK_ISGT", 3); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
24 define("CHK_ISEQ", 4); |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
25 define("CHK_GTEQ", 5); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
26 define("CHK_LTEQ", 6); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
27 define("CHK_RANGE", 7); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
28 define("CHK_CUSTOM", 8); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
29 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
30 |
173
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
31 function stDebug($msg) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
32 { |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
33 if (stGetSetting("debug")) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
34 error_log($msg); |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
35 } |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
36 |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
37 |
0 | 38 function stError($msg) |
39 { | |
210 | 40 global $errorSet, $errorMsgs; |
0 | 41 $errorSet = TRUE; |
210 | 42 $errorMsgs[] = $msg; |
0 | 43 } |
44 | |
45 | |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
46 function stSetStatus($status, $msg) |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
47 { |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
48 global $statusSet, $statusMsg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
49 $statusMsg = $msg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
50 $statusSet = $status; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
51 } |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
52 |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
53 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
54 function stDumpAJAXStatusErrors() |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
55 { |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
56 global $errorSet, $errorMsgs, $statusSet, $statusMsg; |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
57 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
58 if ($errorSet && !$statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
59 stSetStatus(902, "Error"); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
60 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
61 if ($statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
62 { |
229 | 63 header("HTTP/1.0 ".$statusSet." ".$statusMsg); |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
64 header("Status: ".$statusSet." ".$statusMsg); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
65 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
66 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
67 if ($errorSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
68 { |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
69 echo "<h1>Following errors occured</h1>\n". |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
70 "<ul>\n"; |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
71 foreach ($errorMsgs as $msg) |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
72 echo " <li>".chentities($msg)."</li>\n"; |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
73 echo "</ul>\n"; |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
74 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
75 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
76 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
77 |
0 | 78 function stCheckHTTPS() |
79 { | |
80 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
81 } | |
82 | |
83 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
84 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
85 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
86 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
|
87 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
|
88 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
89 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
91 function stGetSQLSettingData($item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
92 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
93 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
94 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
95 case VT_INT: return intval($item["vint"]); |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
96 case VT_BOOL: return intval($item["vint"]) ? true : false; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
97 case VT_STR: return $item["vstr"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
98 case VT_TEXT: return $item["vtext"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
99 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
100 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
101 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
102 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
103 function stGetSettingSQL($item, $val) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
104 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
105 global $db; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
106 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
107 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
108 case VT_INT: return "vint=".intval($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
109 case VT_BOOL: return "vint=".($val ? "1" : "0"); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
110 case VT_STR: return "vstr=".$db->quote($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
111 case VT_TEXT: return "vtext=".$db->quote($val); break; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
112 default: return FALSE; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
113 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
114 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
115 |
293 | 116 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
117 function stReloadSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
118 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
119 global $siteSettings; |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
120 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
121 if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
122 { |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
123 foreach ($res as $item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
124 $siteSettings[$item["key"]] = stGetSQLSettingData($item); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
125 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
126 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
127 die("Error fetching site settings."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
128 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
129 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
130 |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
131 function stGetSetting($name) |
0 | 132 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
133 global $siteSettings; |
0 | 134 if (isset($siteSettings[$name])) |
135 return $siteSettings[$name]; | |
136 else | |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
137 { |
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
138 error_log("No config value for '".$name."'"); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
139 die("No config value for '".$name."'.\n"); |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
140 } |
0 | 141 } |
142 | |
143 | |
144 function stChkSetting($name) | |
145 { | |
146 global $siteSettings; | |
147 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
148 } | |
149 | |
150 | |
151 function dhentities($str) | |
152 { | |
153 return str_replace(array("<",">"), array("<", ">"), htmlentities($str, ENT_NOQUOTES, "UTF-8")); | |
154 } | |
155 | |
156 | |
157 function chentities($str) | |
158 { | |
159 return htmlentities($str, ENT_NOQUOTES, "UTF-8"); | |
160 } | |
161 | |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
162 function ihentities($str) |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
163 { |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
164 return htmlentities($str, ENT_QUOTES, "UTF-8"); |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
165 } |
0 | 166 |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
167 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
168 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
169 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
170 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
171 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
172 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
173 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
174 |
0 | 175 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
176 { | |
177 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
178 "<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
|
179 ($checked ? "checked=\"checked\" " : "")." />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
180 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
0 | 181 } |
182 | |
183 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
184 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
|
185 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
186 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
187 "<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
|
188 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
189 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
190 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
191 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
192 |
0 | 193 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
194 { | |
195 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
196 "<input type=\"button\" ".stGetIDName($name, $id, $prefix). |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
197 "value=\" ".ihentities($label)." \" ". |
0 | 198 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
199 } | |
200 | |
201 | |
202 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") | |
203 { | |
204 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
205 "<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
|
206 "rows=\"".$rows."\" cols=\"".$cols."\">". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
207 (isset($value) ? ihentities($value) : ""). |
0 | 208 "</textarea>"; |
209 } | |
210 | |
211 | |
212 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
213 { | |
214 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
215 "<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
|
216 "size=\"".$size."\" maxlength=\"".$len."\"". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
217 (isset($value) ? " value=\"".ihentities($value)."\"" : ""). |
0 | 218 " />"; |
219 } | |
220 | |
221 | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
222 function stGetFormPasswordInput($name, $id, $prefix, $extra = "") |
0 | 223 { |
224 return | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
225 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." ".$extra." />"; |
0 | 226 } |
227 | |
228 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
229 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
230 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
231 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
232 "<input type=\"submit\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
233 "\" value=\" ".ihentities($label)." \" ". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
234 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
235 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
236 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
237 |
0 | 238 function stGetFormHiddenInput($name, $value) |
239 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
240 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
241 "<input type=\"hidden\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
242 "\" value=\"".ihentities($value)."\" />"; |
0 | 243 } |
244 | |
245 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
246 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
|
247 { |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
248 $str = |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
249 "<form name=\"".$name."\" action=\"". |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
250 ($action != "" ? $action : $name). |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
251 "\" method=\"".$method."\">\n"; |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
252 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
253 if (($csrfID = stGetSessionItem("csrfID", FALSE)) !== FALSE) |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
254 $str .= stGetFormHiddenInput("csrfID", $csrfID)."\n"; |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
255 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
256 return $str; |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
257 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
258 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
259 |
0 | 260 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "") |
261 { | |
262 return | |
263 "<td class=\"".$name."\">". | |
264 ($edit ? stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra) : chentities($value)). | |
265 "</td>"; | |
266 } | |
267 | |
268 | |
269 function stPrintFormTextInput($text1, $text2, $size, $len, $name, $extra="") | |
270 { | |
271 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
|
272 stGetFormTextInput($size, $len, $name, "", "", stGetRequestItem($name), $extra). |
0 | 273 "</td><td>".chentities($text2)."</td></tr>\n"; |
274 } | |
275 | |
276 | |
277 function stPrintFormHiddenInput($name, $value) | |
278 { | |
279 echo " ".stGetFormHiddenInput($name, $value)."\n"; | |
280 } | |
281 | |
282 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
283 function stErrorStrF($msg, $data) |
0 | 284 { |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
285 stError($msg); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
286 return FALSE; |
0 | 287 } |
288 | |
289 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
290 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
291 // Check and validate one item from $_REQUEST[], based on |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
292 // list of validation conditions. For example: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
293 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
294 // stChkRequestItem("name", FALSE, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
295 // array(CHK_ISGT, VT_STR, 0, "Handle / name not given."), |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
296 // array(CHK_ISGT, VT_STR, 3, "Handle / name too short, should be 3 characters or more."), |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
297 // array(CHK_LTEQ, VT_STR, SET_LEN_USERNAME, "Handle / name is too long, should be less than ".SET_LEN_USERNAME." characters."), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
298 // array(CHK_RANGE, VT_STR, array(3, SET_LEN_USERNAME), "Ulululu!"), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
299 // ^- ranges specified as array of MIN and MAX values (inclusive) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
300 // |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
301 // array(CHK_CUSTOM, VT_STR, function($value) { return FALSE; }, "Error! Error!"), |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
302 // ^- can be any callable/anonymous function etc. |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
303 // ... |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
304 // |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
305 function stChkRequestDataItem($type, $value, $cmp) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
306 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
307 switch ($type) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
308 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
309 case CHK_ISLT : return $value < $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
310 case CHK_ISGT : return $value > $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
311 case CHK_ISEQ : return $value == $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
312 case CHK_LTEQ : return $value <= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
313 case CHK_GTEQ : return $value >= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
314 case CHK_RANGE: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
315 if (!is_array($cmp)) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
316 return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
317 else |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
318 return ($value >= $cmp[0] && $value <= $cmp[1]); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
319 break; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
320 default: return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
321 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
322 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
323 |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
324 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
325 function stChkRequestItem($name, &$sdata) |
0 | 326 { |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
327 if (!isset($_POST[$name])) |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
328 return stErrorStrF("Required data item '".$name."' not set.", $name); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
329 |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
330 $data = trim($_POST[$name]); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
331 $slen = strlen($data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
332 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
333 if ($sdata !== FALSE) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
334 $sdata = $data; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
335 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
336 // Go through list of validation checks |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
337 $argc = func_num_args(); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
338 $argv = func_get_args(); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
339 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
340 for ($argn = 2; $argn < $argc; $argn++) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
341 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
342 // Act according to check type |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
343 $check = $argv[$argn]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
344 switch ($check[0]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
345 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
346 case CHK_TYPE: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
347 // Check type of the data |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
348 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
349 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
350 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
351 if ($slen == 0) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
352 return stErrorStrF($check[2], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
353 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
354 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
355 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
356 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
357 if ($slen == 0 || !is_numeric($data)) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
358 return stErrorStrF($check[2], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
359 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
360 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
361 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
362 |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
363 case CHK_ISLT: case CHK_ISGT: case CHK_ISEQ: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
364 case CHK_GTEQ: case CHK_LTEQ: case CHK_RANGE: |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
365 // Check length or value of the data |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
366 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
367 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
368 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
369 case VT_TEXT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
370 // Strings get their length checked |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
371 if (!stChkRequestDataItem($check[0], $slen, $check[2])) |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
372 return stErrorStrF($check[3], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
373 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
374 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
375 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
376 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
377 // Integer values checked against .. value |
292 | 378 if (!stChkRequestDataItem($check[0], intval($data), $check[2])) |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
379 return stErrorStrF($check[3], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
380 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
381 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
382 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
383 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
384 case CHK_CUSTOM: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
385 // Call a custom function (or closure) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
386 $func = $check[1]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
387 if (!is_callable($func) || !$func($data)) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
388 return stErrorStrF($check[2], $data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
389 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
390 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
391 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
392 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
393 return TRUE; |
0 | 394 } |
395 | |
396 | |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
397 function stGetRequestItem($name, $default = "", $allowGet = FALSE) |
0 | 398 { |
357
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
399 if ($allowGet) |
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
400 return isset($_REQUEST[$name]) ? trim($_REQUEST[$name]) : $default; |
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
401 else |
7e906c827e68
Make default of request items to allow POST only, GET enabled on case by case basis.
Matti Hamalainen <ccr@tnsp.org>
parents:
349
diff
changeset
|
402 return isset($_POST[$name]) ? trim($_POST[$name]) : $default; |
0 | 403 } |
404 | |
405 | |
406 function stGetDRequestItem($name, $default = "") | |
407 { | |
408 return trim(urldecode(stGetRequestItem($name, $default))); | |
409 } | |
410 | |
411 | |
412 function stLogSQLError($sql) | |
413 { | |
414 global $db; | |
415 error_log("SQL error ".implode("; ", $db->errorInfo())." in statement \"".$sql."\""); | |
416 } | |
417 | |
418 | |
419 function stConnectSQLDB() | |
420 { | |
421 global $db; | |
422 try { | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
423 $db = new PDO(stGetSetting("sqlDB")); |
0 | 424 } |
425 catch (PDOException $e) { | |
426 error_log("Could not connect to SQL database: ".$e->getMessage()."."); | |
427 return FALSE; | |
428 } | |
429 return TRUE; | |
430 } | |
431 | |
432 | |
433 function stGetSQLParam($type, $value) | |
434 { | |
435 global $db; | |
436 switch ($type) | |
437 { | |
438 case "d": | |
439 return intval($value); | |
440 | |
441 case "s": | |
442 return $db->quote($value); | |
443 | |
72
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
444 case "b": |
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
445 return intval($value) ? 1 : 0; |
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
71
diff
changeset
|
446 |
0 | 447 case "D": |
448 return intval(stGetRequestItem($value)); | |
449 | |
450 case "S": | |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
451 return $db->quote(stGetRequestItem($value)); |
0 | 452 |
453 case "Q": | |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
454 return $db->quote(stGetRequestItem($value)); |
0 | 455 |
456 case "B": | |
457 return intval(stGetRequestItem($value)) ? 1 : 0; | |
458 } | |
459 } | |
460 | |
461 | |
462 function stPrepareSQL() | |
463 { | |
464 $argc = func_num_args(); | |
465 $argv = func_get_args(); | |
466 if ($argc < 1) | |
467 { | |
468 error_log("Invalid stPrepareSQL() call, no arguments!"); | |
469 return FALSE; | |
470 } | |
87 | 471 |
0 | 472 $fmt = $argv[0]; |
473 $len = strlen($fmt); | |
474 $sql = ""; | |
475 $argn = 1; | |
476 $pos = 0; | |
477 while ($pos < $len) | |
478 { | |
479 if ($fmt[$pos] == "%") | |
480 { | |
481 if ($argn < $argc) | |
482 $sql .= stGetSQLParam($fmt[++$pos], $argv[$argn++]); | |
483 else | |
484 { | |
485 error_log("Invalid SQL statement format string '".$fmt. | |
486 "', not enough parameters specified (".$argn." of ".$argc.")"); | |
487 return FALSE; | |
488 } | |
489 } | |
490 else | |
491 $sql .= $fmt[$pos]; | |
492 $pos++; | |
493 } | |
494 | |
495 return $sql; | |
496 } | |
497 | |
498 | |
499 function stPrepareSQLUpdate($table, $cond, $pairs) | |
500 { | |
501 $sql = array(); | |
502 foreach ($pairs as $name => $attr) | |
503 { | |
504 $sql[] = $name."=".stGetSQLParam($attr, $name); | |
505 } | |
506 return | |
507 "UPDATE ".$table." SET ".implode(",", $sql). | |
508 ($cond != "" ? " ".$cond : ""); | |
509 } | |
510 | |
511 | |
512 function stExecSQL($sql) | |
513 { | |
514 global $db; | |
515 if (($res = $db->query($sql)) !== FALSE) | |
516 return $res; | |
517 else | |
518 { | |
519 stLogSQLError($sql); | |
520 stError("Oh noes! SQL error #23!"); | |
521 return FALSE; | |
522 } | |
523 } | |
524 | |
525 | |
526 function stFetchSQL($sql) | |
527 { | |
528 global $db; | |
529 if (($res = $db->query($sql)) !== FALSE) | |
530 { | |
531 return $res->fetch(); | |
532 } | |
533 else | |
534 { | |
535 stLogSQLError($sql); | |
536 stError("Oh noes! SQL error #31!"); | |
537 return FALSE; | |
538 } | |
539 } | |
540 | |
541 | |
542 function stFetchSQLColumn($sql, $column = 0) | |
543 { | |
544 global $db; | |
545 if (($res = $db->query($sql)) !== FALSE) | |
546 { | |
547 return $res->fetchColumn($column); | |
548 } | |
549 else | |
550 { | |
551 stLogSQLError($sql); | |
552 stError("Oh noes! SQL error #81!"); | |
553 return FALSE; | |
554 } | |
555 } | |
556 | |
557 | |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
558 function stExecSQLCond($sql, $msg = FALSE) |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
559 { |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
560 if (($res = stExecSQL($sql)) !== FALSE) |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
561 { |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
562 if ($msg !== FALSE) |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
563 stSetStatus(200, $msg); |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
564 return $res; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
565 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
566 else |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
567 { |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
568 stSetStatus(902, "Error in SQL execution."); |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
569 return FALSE; |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
570 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
571 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
572 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
573 |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
574 function stStrChop($str, $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
575 { |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
576 if (strlen($str) > $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
577 $s = substr($str, 0, $len - 3)."..."; |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
578 else |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
579 $s = $str; |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
580 return sprintf("%-".$len."s", $s); |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
581 } |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
582 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
583 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
584 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
585 function cmLocaleInit() |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
586 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
587 global $pageCharset; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
588 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
589 if (!isset($pageCharset)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
590 $pageCharset = "UTF-8"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
591 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
592 mb_internal_encoding($pageCharset); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
593 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
594 $tmp = "en_US.".strtolower(str_replace("-", "", $pageCharset)); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
595 setlocale(LC_ALL, $tmp); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
596 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
597 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
598 |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
599 function cmPrintCSSLine($uri, $media = "") |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
600 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
601 echo |
232 | 602 " <link rel=\"stylesheet\" href=\"".$uri. |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
603 "\" type=\"text/css\" ".($media != "" ? "media=\"".$media."\"": "")." />\n"; |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
604 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
605 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
606 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
607 function cmPrintPageHeader($pageTitle, $pageExtra = "", $useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
608 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
609 global $pageCSS, $pageCharset, $pageAuthor, $pageCSSData, $pageUrchin; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
610 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
611 echo |
363 | 612 "<!DOCTYPE html>\n". |
178 | 613 "<html>\n". |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
614 "<head>\n". |
232 | 615 " <meta charset=\"".$pageCharset."\">\n". |
362
38dfe9e0a017
Add meta-equiv for document content type.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
616 " <meta http-equiv=\"Content-type\" content=\"text/html;charset=".$pageCharset."\">\n". |
232 | 617 " <title>".strip_tags($pageTitle)."</title>\n". |
618 $pageExtra; | |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
619 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
620 if (is_array($pageCSS)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
621 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
622 foreach ($pageCSS as $uri => $media) |
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
623 cmPrintCSSLine($uri, $media); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
624 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
625 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
626 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
627 cmPrintCSSLine($pageCSS); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
628 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
629 |
232 | 630 echo |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
631 "</head>\n". |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
632 "<body>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
633 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
634 if (isset($pageUrchin)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
635 require_once $pageUrchin; |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
636 |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
637 echo "<div id=\"messageBox\"></div>\n"; |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
638 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
639 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
640 echo "<div id=\"contents\">\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
641 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
642 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
643 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
644 function cmPrintPageFooter($useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
645 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
646 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
647 echo "</div>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
648 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
649 echo "</body>\n</html>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
650 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
651 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
652 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
653 function cmQM($msg) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
654 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
655 global $pageTranslations, $pageLang; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
656 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
657 if (isset($pageTranslations[$msg]) && isset($pageTranslations[$msg][$pageLang])) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
658 $str = $pageTranslations[$msg][$pageLang]; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
659 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
660 $str = $msg; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
661 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
662 foreach (func_get_args() as $argn => $argv) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
663 $str = preg_replace("/\%".$argn."/", $argv, $str); |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
664 return $str; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
665 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
666 |
0 | 667 ?> |