Mercurial > hg > fapweb
annotate msitegen.inc.php @ 1105:0b0094db56da
Improve function stDBPrepareSQLUpdate() by adding new optional last argument
to specify values array.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 16 May 2019 12:42:24 +0300 |
parents | 0a2117349f46 |
children | b3c1c5969a0b |
rev | line source |
---|---|
1071 | 1 <?php |
0 | 2 // |
571
ce11ea112a65
Change the header blurb a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
569
diff
changeset
|
3 // FAPWeb - Simple Web-based Demoparty Management System |
33 | 4 // Generic and miscellaneous site support code |
1072 | 5 // (C) Copyright 2012-2017 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); |
907
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
29 define("CHK_ARRAY_KEY", 9); |
908 | 30 define("CHK_ARRAY_VAL", 10); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
31 |
94
6edd7d623eab
Start adding votekey modes code.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
32 |
173
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
33 function stDebug($msg) |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
34 { |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
35 if (stGetSetting("debug")) |
906 | 36 error_log("FAPWeb[D]: ".$msg); |
173
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
37 } |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
38 |
fef53f6170b5
Move stDebug() to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
39 |
874 | 40 function stLogError($msg) |
861
62b3a69e9030
Add stErrorLog() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
836
diff
changeset
|
41 { |
906 | 42 error_log("FAPWeb[E]: ".$msg); |
861
62b3a69e9030
Add stErrorLog() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
836
diff
changeset
|
43 return FALSE; |
62b3a69e9030
Add stErrorLog() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
836
diff
changeset
|
44 } |
62b3a69e9030
Add stErrorLog() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
836
diff
changeset
|
45 |
62b3a69e9030
Add stErrorLog() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
836
diff
changeset
|
46 |
874 | 47 function stLogSQLError($dbh, $sql) |
48 { | |
906 | 49 return stLogError("SQL error '".implode("; ", $dbh->errorInfo())."' in statement: \"".$sql."\""); |
874 | 50 } |
51 | |
52 | |
0 | 53 function stError($msg) |
54 { | |
210 | 55 global $errorSet, $errorMsgs; |
0 | 56 $errorSet = TRUE; |
210 | 57 $errorMsgs[] = $msg; |
812
8083b39d3bde
Return FALSE from stError() functions, as a convenience.
Matti Hamalainen <ccr@tnsp.org>
parents:
811
diff
changeset
|
58 return FALSE; |
0 | 59 } |
60 | |
61 | |
208
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
62 function stSetStatus($status, $msg) |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
63 { |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
64 global $statusSet, $statusMsg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
65 $statusMsg = $msg; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
66 $statusSet = $status; |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
67 } |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
68 |
8985d2bdb29b
More work on error handling etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
69 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
70 function stDumpAJAXStatusErrors() |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
71 { |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
72 global $errorSet, $errorMsgs, $statusSet, $statusMsg; |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
73 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
74 if ($errorSet && !$statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
75 stSetStatus(902, "Error"); |
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 if ($statusSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
78 { |
229 | 79 header("HTTP/1.0 ".$statusSet." ".$statusMsg); |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
80 header("Status: ".$statusSet." ".$statusMsg); |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
81 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
82 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
83 if ($errorSet) |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
84 { |
559 | 85 echo |
86 "<h1>Following errors occured</h1>\n". | |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
87 "<ul>\n"; |
559 | 88 |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
89 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
|
90 echo " <li>".chentities($msg)."</li>\n"; |
559 | 91 |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
92 echo "</ul>\n"; |
211
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
93 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
94 } |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
95 |
5bae42020034
Factorize some code into msitegen.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
96 |
0 | 97 function stCheckHTTPS() |
98 { | |
99 return isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != "" && $_SERVER["HTTPS"] != "off"); | |
100 } | |
101 | |
102 | |
5
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
103 function stSetupCacheControl() |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
104 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
105 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
|
106 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
|
107 } |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
108 |
76c3b89d7b11
Improve voting, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
109 |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
110 function stGetSQLSettingData($item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
111 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
112 switch ($item["vtype"]) |
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 case VT_INT: return intval($item["vint"]); |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1103
diff
changeset
|
115 case VT_BOOL: return intval($item["vint"]) ? TRUE : FALSE; |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
116 case VT_STR: return $item["vstr"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
117 case VT_TEXT: return $item["vtext"]; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
118 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
119 } |
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 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
122 function stGetSettingSQL($item, $val) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
123 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
124 global $db; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
125 switch ($item["vtype"]) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
126 { |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 default: return FALSE; |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
132 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
133 } |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
134 |
293 | 135 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
136 function stReloadSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
137 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
138 global $siteSettings; |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
139 |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
140 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
|
141 { |
198
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
142 foreach ($res as $item) |
96ab189e5c03
Add some new helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
184
diff
changeset
|
143 $siteSettings[$item["key"]] = stGetSQLSettingData($item); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
144 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
145 else |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
146 die("Error fetching site settings."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
147 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
148 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
149 |
538 | 150 function stGetSetting($name, $default = FALSE) |
0 | 151 { |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
152 global $siteSettings; |
0 | 153 if (isset($siteSettings[$name])) |
154 return $siteSettings[$name]; | |
155 else | |
538 | 156 if ($default !== FALSE) |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
157 return $default; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
158 else |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
159 { |
874 | 160 stLogError("No config value for '".$name."'"); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
161 die("No config value for '".$name."'.\n"); |
291
ce30a9083b40
Add error_log() for missing settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
246
diff
changeset
|
162 } |
0 | 163 } |
164 | |
165 | |
166 function stChkSetting($name) | |
167 { | |
168 global $siteSettings; | |
169 return isset($siteSettings[$name]) && $siteSettings[$name]; | |
170 } | |
171 | |
172 | |
173 function dhentities($str) | |
174 { | |
1102 | 175 return htmlspecialchars($str, ENT_COMPAT, "UTF-8"); |
0 | 176 } |
177 | |
178 | |
179 function chentities($str) | |
180 { | |
1102 | 181 return htmlspecialchars($str, ENT_NOQUOTES, "UTF-8"); |
0 | 182 } |
183 | |
485 | 184 |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
185 function ihentities($str) |
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
186 { |
1102 | 187 return htmlspecialchars($str, ENT_QUOTES, "UTF-8"); |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
188 } |
0 | 189 |
485 | 190 |
676 | 191 // |
192 // Helper functions for form/HTML elements | |
193 // XXX/TODO .. this name/id/prefix mess needs to be cleaned up. | |
194 // | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
195 function stGetIDName($name, $id, $prefix = "") |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
196 { |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
197 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
198 ($id != "" ? "id=\"".$prefix.$name.$id."\" " : ""). |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
199 ($name != "" ? "name=\"".$prefix.$name.$id."\" " : ""); |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
200 } |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
201 |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
202 |
0 | 203 function stGetFormCheckBoxInput($name, $id, $prefix, $checked, $label, $extra = "") |
204 { | |
205 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
206 "<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
|
207 ($checked ? "checked=\"checked\" " : "")." />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
208 ($label != "" ? "<label for=\"".$prefix.$name.$id."\">".$label."</label>" : ""); |
0 | 209 } |
210 | |
211 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
212 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
|
213 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
214 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
215 "<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
|
216 ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />". |
336
49094cfbd674
Fix radio- and checkbutton labels.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
217 ($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
|
218 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
219 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
220 |
0 | 221 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "") |
222 { | |
223 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
224 "<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
|
225 "value=\" ".ihentities($label)." \" ". |
0 | 226 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
227 } | |
228 | |
229 | |
680
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
230 function stGetFormButtonElement($name, $id, $prefix, $label, $onclick = "") |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
231 { |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
232 return |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
233 "<button class=\"button\" ".stGetIDName($name, $id, $prefix)." type=\"button\"". |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
234 ($onclick != "" ? " onClick=\"".$onclick."\"" : "")."> ".chentities($label)." </button>"; |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
235 } |
c9b96a7b9dc4
Add new helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
676
diff
changeset
|
236 |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
237 |
0 | 238 function stGetFormTextArea($rows, $cols, $name, $id, $prefix, $value, $extra = "") |
239 { | |
240 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
241 "<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
|
242 "rows=\"".$rows."\" cols=\"".$cols."\">". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
243 (isset($value) ? ihentities($value) : ""). |
0 | 244 "</textarea>"; |
245 } | |
246 | |
247 | |
248 function stGetFormTextInput($size, $len, $name, $id, $prefix, $value, $extra = "") | |
249 { | |
250 return | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
251 "<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
|
252 "size=\"".$size."\" maxlength=\"".$len."\"". |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
253 (isset($value) ? " value=\"".ihentities($value)."\"" : ""). |
0 | 254 " />"; |
255 } | |
256 | |
257 | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
258 function stGetFormPasswordInput($name, $id, $prefix, $extra = "") |
0 | 259 { |
260 return | |
246
cb34e3fafb33
Add extra parameter to stGetFormPasswordInput().
Matti Hamalainen <ccr@tnsp.org>
parents:
244
diff
changeset
|
261 "<input type=\"password\" ".stGetIDName($name, $id, $prefix)." ".$extra." />"; |
0 | 262 } |
263 | |
264 | |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
265 function stGetFormSubmitInput($name, $label, $onclick = "") |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
266 { |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
267 return |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
268 "<input type=\"submit\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
269 "\" value=\" ".ihentities($label)." \" ". |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
270 ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />"; |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
271 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
272 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
273 |
0 | 274 function stGetFormHiddenInput($name, $value) |
275 { | |
12
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
276 return |
358534308c61
Clean up some of the html item generation code.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
277 "<input type=\"hidden\" name=\"".$name. |
297
fdcd78675d1c
Possibly fix input quotation and escaping issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
278 "\" value=\"".ihentities($value)."\" />"; |
0 | 279 } |
280 | |
281 | |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
282 function stGetFormStart($name, $action = FALSE, $method = FALSE, $extra = FALSE) |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
283 { |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
284 $str = |
771
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
285 "<form name=\"".$name."\"". |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
286 ($action !== FALSE ? " action=\"".$action."\"" : ""). |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
287 " method=\"".($method !== FALSE ? $method : "post")."\"". |
cd8a29647c09
Change the API of stGetFormStart().
Matti Hamalainen <ccr@tnsp.org>
parents:
760
diff
changeset
|
288 ($extra !== FALSE ? " ".$extra : "").">\n"; |
359
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
289 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
290 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
|
291 $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
|
292 |
f7a806d5060f
Add preliminary code for CSRF prevention via unique hash tokens. Not fully
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
293 return $str; |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
294 } |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
295 |
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
296 |
675 | 297 function stGetFormOptionListStart($id, $indent, $outer, $size = 10, $onChange = "") |
0 | 298 { |
299 return | |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
300 ($outer ? $indent."<div id=\"".$id."\">\n" : ""). |
638
79bbd09114c5
Allow selection list size to be zero.
Matti Hamalainen <ccr@tnsp.org>
parents:
637
diff
changeset
|
301 $indent."<select class=\"selectBox\" id=\"".$id."Sel\"". |
79bbd09114c5
Allow selection list size to be zero.
Matti Hamalainen <ccr@tnsp.org>
parents:
637
diff
changeset
|
302 ($size > 0 ? " size=\"".$size."\"" : ""). |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
303 ($onChange != "" ? " onChange=\"".$onChange."\"" : "").">\n"; |
0 | 304 } |
305 | |
306 | |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
307 function stGetFormOptionListItem($indent, $value, $active, $name) |
0 | 308 { |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
309 return |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
310 $indent."<option value=\"".$value."\"". |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
311 ($active ? " selected=\"selected\"" : ""). |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
312 ">".str_replace(" ", " ", chentities($name))."</option>\n"; |
0 | 313 } |
314 | |
315 | |
675 | 316 function stGetFormOptionListEnd($indent, $outer) |
0 | 317 { |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
318 return |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
319 $indent."</select>\n". |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
320 ($outer ? $indent."</div>\n" : ""); |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
321 } |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
322 |
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
323 |
752
c714140541d5
Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents:
747
diff
changeset
|
324 function stGetFormOptionListFromArray($id, $indent, $outer, $data, $active, $size = 10, $arrIndex = 0, $onChange = "") |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
325 { |
675 | 326 $str = stGetFormOptionListStart($id, $indent, $outer, $size, $onChange); |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
327 |
639
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
328 foreach ($data as $key => $value) |
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
329 { |
747
330e6d79c5dc
Change stGetFormOptionList* function APIs a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
680
diff
changeset
|
330 $str .= stGetFormOptionListItem($indent." ", $key, |
642 | 331 ($key == $active), |
752
c714140541d5
Add more data to previewTypeList array and implement array index argument in
Matti Hamalainen <ccr@tnsp.org>
parents:
747
diff
changeset
|
332 is_array($value) ? $value[$arrIndex] : $value); |
639
26ec29d2e728
Elements of arrays passed to selection list can be arrays themselves, the
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
333 } |
637
a376521c7bd1
Move some code around, for more appropriate placement in the modules.
Matti Hamalainen <ccr@tnsp.org>
parents:
619
diff
changeset
|
334 |
675 | 335 return $str.stGetFormOptionListEnd($indent, $outer); |
0 | 336 } |
337 | |
338 | |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
339 function stErrorStrF($fmt) |
0 | 340 { |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
341 $argc = func_num_args(); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
342 $argv = func_get_args(); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
343 |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
344 $len = strlen($fmt); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
345 $str = ""; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
346 $argn = 1; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
347 for ($pos = 0; $pos < $len; $pos++) |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
348 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
349 if ($fmt[$pos] == "%") |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
350 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
351 $pos++; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
352 if ($fmt[$pos] == "%") |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
353 $str .= "%"; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
354 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
355 { |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
356 $n = intval($fmt[$pos]); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
357 if ($n >= 1 && $n < $argc) |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
358 $str .= $argv[$n]; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
359 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
360 { |
874 | 361 stLogError("Invalid stErrorStrF() format string, arg #".$n. |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
362 " referenced, but only has ".$argc." arguments: '".$fmt."'\n"); |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
363 return FALSE; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
364 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
365 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
366 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
367 else |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
368 $str .= $fmt[$pos]; |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
369 } |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
370 |
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
371 stError($str); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
372 return FALSE; |
0 | 373 } |
374 | |
375 | |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
376 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
377 // 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
|
378 // 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
|
379 // |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
380 // stChkRequestItem("name", FALSE, |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
381 // 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
|
382 // 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
|
383 // 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
|
384 // 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
|
385 // ^- 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
|
386 // |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
387 // 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
|
388 // ^- can be any callable/anonymous function etc. |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
389 // ... |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
390 // |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
391 function stChkRequestDataItem($type, $value, $cmp) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
392 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
393 switch ($type) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
394 { |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
395 case CHK_ISLT : return $value < $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
396 case CHK_ISGT : return $value > $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
397 case CHK_ISEQ : return $value == $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
398 case CHK_LTEQ : return $value <= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
399 case CHK_GTEQ : return $value >= $cmp; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
400 case CHK_RANGE: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
401 if (!is_array($cmp)) |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
402 return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
403 else |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
404 return ($value >= $cmp[0] && $value <= $cmp[1]); |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
405 break; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
406 default: return FALSE; |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
407 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
408 } |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
409 |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
410 |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
411 function stDoCheckRequestItem($name, &$sdata, $nindex, $argc, $argv) |
0 | 412 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
413 if (stGetSetting("debug")) |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
414 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
415 if (!isset($_REQUEST[$name])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
416 return stErrorStrF("Required data item '%1' not set.", $name); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
417 |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
418 $data = trim($_REQUEST[$name]); |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
419 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
420 else |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
421 { |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
422 if (!isset($_POST[$name])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
423 return stErrorStrF("Required data item '%1' not set.", $name); |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
424 |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
425 $data = trim($_POST[$name]); |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
426 } |
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
427 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
428 $slen = strlen($data); |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
429 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
430 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
431 // Go through list of validation checks |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
432 for ($argn = $nindex; $argn < $argc; $argn++) |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
433 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
434 // 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
|
435 $check = $argv[$argn]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
436 switch ($check[0]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
437 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
438 case CHK_TYPE: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
439 // 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
|
440 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
441 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
442 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
443 if ($slen == 0) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
444 return stErrorStrF($check[2], $slen); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
445 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
446 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
447 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
448 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
449 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
|
450 return stErrorStrF($check[2], $data); |
813
c635887048aa
Apply intval() to data when checking type.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
451 else |
c635887048aa
Apply intval() to data when checking type.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
452 $data = intval($data); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
453 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
454 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
455 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
456 |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
457 case CHK_ISLT: case CHK_ISGT: case CHK_ISEQ: |
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
458 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
|
459 // 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
|
460 switch ($check[1]) |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
461 { |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
462 case VT_STR: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
463 case VT_TEXT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
464 // Strings get their length checked |
244
70c424d025d6
Improve input validation helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
465 if (!stChkRequestDataItem($check[0], $slen, $check[2])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
466 return stErrorStrF($check[3], $slen, $check[2]); |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
467 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
468 |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
469 case VT_INT: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
470 case VT_BOOL: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
471 // Integer values checked against .. value |
292 | 472 if (!stChkRequestDataItem($check[0], intval($data), $check[2])) |
793
ff6e6c6200a4
Add improved error message formatting to stChkRequestItem*() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
771
diff
changeset
|
473 return stErrorStrF($check[3], 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
|
474 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
475 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
476 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
477 |
907
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
478 case CHK_ARRAY_KEY: |
896
52737f6192bb
More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
874
diff
changeset
|
479 if (!isset($check[1][$data])) |
52737f6192bb
More work on preview handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
874
diff
changeset
|
480 return stErrorStrF($check[2], $data); |
810
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
481 break; |
2a23243a6cc4
Add new check type for stChkRequestItem*(), CHK_ARRAY.
Matti Hamalainen <ccr@tnsp.org>
parents:
803
diff
changeset
|
482 |
907
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
483 case CHK_ARRAY_VAL: |
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
484 if (!in_array($data, $check[1], TRUE)) |
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
485 return stErrorStrF($check[2], $data); |
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
486 break; |
affd8bd8c910
Add new check type(s) CHK_ARRAY_KEY and CHK_ARRAY_VAL, remove CHK_ARRAY as
Matti Hamalainen <ccr@tnsp.org>
parents:
906
diff
changeset
|
487 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
488 case CHK_CUSTOM: |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
489 // 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
|
490 $func = $check[1]; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
491 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
|
492 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
|
493 break; |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
494 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
495 } |
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
496 |
436
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
497 if ($sdata !== FALSE) |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
498 $sdata = $data; |
4ce10edceedf
Only assign data if it has been completely validated.
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
499 |
184
1b30c2107e5b
Add function for validating input with different definable conditions. Use
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
500 return TRUE; |
0 | 501 } |
502 | |
503 | |
670
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
504 function stChkRequestItem($name, &$sdata) |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
505 { |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
506 return stDoCheckRequestItem($name, $sdata, 2, func_num_args(), func_get_args()); |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
507 } |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
508 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
509 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
510 function stChkRequestItemFail($name, &$sdata, &$sfail) |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
511 { |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
512 $sres = stDoCheckRequestItem($name, $sdata, 3, func_num_args(), func_get_args()); |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
513 if ($sres !== TRUE) $sfail = FALSE; |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
514 return $sres; |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
515 } |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
516 |
8a091dc8d608
Add new utility function stChkRequestItemFail().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
517 |
1003
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
518 function stTrimIfString($val) |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
519 { |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
520 if (is_string($val)) |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
521 return trim($val); |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
522 else |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
523 return $val; |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
524 } |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
525 |
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
526 |
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
|
527 function stGetRequestItem($name, $default = "", $allowGet = FALSE) |
0 | 528 { |
369
a3caded43f6d
Add possibility of always using GET requests when debug mode is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
529 if ($allowGet || stGetSetting("debug")) |
1003
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
530 return isset($_REQUEST[$name]) ? stTrimIfString($_REQUEST[$name]) : $default; |
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
|
531 else |
1003
668fd0ea4e08
Add check for request items that might not be strings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
532 return isset($_POST[$name]) ? stTrimIfString($_POST[$name]) : $default; |
0 | 533 } |
534 | |
535 | |
486 | 536 function stConnectSQLDBSpec($dbspec) |
537 { | |
538 try { | |
539 $dbh = new PDO($dbspec); | |
540 } | |
541 catch (PDOException $e) { | |
874 | 542 stLogError("Could not connect to SQL database: ".$e->getMessage()."."); |
486 | 543 return FALSE; |
544 } | |
545 return $dbh; | |
546 } | |
547 | |
548 | |
1102 | 549 function stDBGetSQLParam($dbh, $type, $value) |
550 { | |
551 switch ($type) | |
552 { | |
553 case "d": return intval($value); | |
554 case "s": return $dbh->quote($value); | |
555 case "b": return intval($value) ? 1 : 0; | |
556 case "D": return intval(stGetRequestItem($value)); | |
557 case "S": return $dbh->quote(stGetRequestItem($value)); | |
558 case "Q": return $dbh->quote(stGetRequestItem($value)); | |
559 case "B": return intval(stGetRequestItem($value)) ? 1 : 0; | |
560 } | |
561 } | |
562 | |
563 | |
0 | 564 function stConnectSQLDB() |
565 { | |
566 global $db; | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
567 try { |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
568 $db = new PDO(stGetSetting("sqlDB"), |
538 | 569 stGetSetting("sqlUsername", NULL), |
570 stGetSetting("sqlPassword", NULL), | |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
571 stGetSetting("sqlOptions", array())); |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
572 } |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
573 catch (PDOException $e) { |
874 | 574 stLogError("Could not connect to SQL database: ".$e->getMessage()."."); |
537
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
575 return FALSE; |
12726b4be750
Make database connection settings better.
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
576 } |
486 | 577 $db = stConnectSQLDBSpec(stGetSetting("sqlDB")); |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1103
diff
changeset
|
578 return ($db !== FALSE); |
0 | 579 } |
580 | |
581 | |
1105
0b0094db56da
Improve function stDBPrepareSQLUpdate() by adding new optional last argument
Matti Hamalainen <ccr@tnsp.org>
parents:
1104
diff
changeset
|
582 function stDBPrepareSQLUpdate($dbh, $table, $cond, $pairs, $values = NULL) |
0 | 583 { |
1105
0b0094db56da
Improve function stDBPrepareSQLUpdate() by adding new optional last argument
Matti Hamalainen <ccr@tnsp.org>
parents:
1104
diff
changeset
|
584 $sql = []; |
487 | 585 foreach ($pairs as $name => $attr) |
0 | 586 { |
1105
0b0094db56da
Improve function stDBPrepareSQLUpdate() by adding new optional last argument
Matti Hamalainen <ccr@tnsp.org>
parents:
1104
diff
changeset
|
587 $sql[] = $name."=".stDBGetSQLParam($dbh, |
0b0094db56da
Improve function stDBPrepareSQLUpdate() by adding new optional last argument
Matti Hamalainen <ccr@tnsp.org>
parents:
1104
diff
changeset
|
588 $attr, $values !== NULL ? $values[$name] : $name); |
0 | 589 } |
487 | 590 return |
591 "UPDATE ".$table." SET ".implode(",", $sql). | |
592 ($cond != "" ? " ".$cond : ""); | |
0 | 593 } |
594 | |
595 | |
487 | 596 function stDBPrepareSQL($dbh) |
0 | 597 { |
598 $argc = func_num_args(); | |
599 $argv = func_get_args(); | |
87 | 600 |
487 | 601 $fmt = $argv[1]; |
0 | 602 $len = strlen($fmt); |
603 $sql = ""; | |
487 | 604 $argn = 2; |
605 for ($pos = 0; $pos < $len; $pos++) | |
0 | 606 { |
607 if ($fmt[$pos] == "%") | |
608 { | |
609 if ($argn < $argc) | |
501 | 610 $sql .= stDBGetSQLParam($dbh, $fmt[++$pos], $argv[$argn++]); |
0 | 611 else |
612 { | |
874 | 613 stLogError("Invalid SQL statement format string '".$fmt. |
0 | 614 "', not enough parameters specified (".$argn." of ".$argc.")"); |
615 return FALSE; | |
616 } | |
617 } | |
618 else | |
619 $sql .= $fmt[$pos]; | |
620 } | |
485 | 621 |
0 | 622 return $sql; |
623 } | |
624 | |
625 | |
487 | 626 function stPrepareSQL() |
0 | 627 { |
487 | 628 global $db; |
629 $argc = func_num_args(); | |
630 $argv = func_get_args(); | |
631 | |
632 $fmt = $argv[0]; | |
633 $len = strlen($fmt); | |
634 $sql = ""; | |
635 $argn = 1; | |
636 for ($pos = 0; $pos < $len; $pos++) | |
0 | 637 { |
487 | 638 if ($fmt[$pos] == "%") |
639 { | |
640 if ($argn < $argc) | |
492 | 641 $sql .= stDBGetSQLParam($db, $fmt[++$pos], $argv[$argn++]); |
487 | 642 else |
643 { | |
874 | 644 stLogError("Invalid SQL statement format string '".$fmt. |
487 | 645 "', not enough parameters specified (".$argn." of ".$argc.")"); |
646 return FALSE; | |
647 } | |
648 } | |
649 else | |
650 $sql .= $fmt[$pos]; | |
0 | 651 } |
487 | 652 |
653 return $sql; | |
0 | 654 } |
655 | |
656 | |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
657 function stDBExecSQLInsert($dbh, $sql) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
658 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
659 switch ($dbh->getAttribute(PDO::ATTR_DRIVER_NAME)) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
660 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
661 case "pgsql": |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1103
diff
changeset
|
662 if (($res = stDBFetchSQLColumn($dbh, $sql." RETURNING id")) !== FALSE) |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
663 return $res; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
664 else |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
665 return FALSE; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
666 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
667 default: |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1103
diff
changeset
|
668 if (stDBExecSQL($dbh, $sql) !== FALSE) |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
669 return $dbh->lastInsertId(); |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
670 else |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
671 return FALSE; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
672 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
673 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
674 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
675 |
487 | 676 function stDBExecSQL($dbh, $sql) |
0 | 677 { |
487 | 678 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 679 return $res; |
680 else | |
681 { | |
501 | 682 stLogSQLError($dbh, $sql); |
0 | 683 stError("Oh noes! SQL error #23!"); |
684 return FALSE; | |
685 } | |
686 } | |
687 | |
688 | |
487 | 689 function stDBFetchSQL($dbh, $sql) |
0 | 690 { |
487 | 691 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 692 return $res->fetch(); |
693 else | |
694 { | |
501 | 695 stLogSQLError($dbh, $sql); |
0 | 696 stError("Oh noes! SQL error #31!"); |
697 return FALSE; | |
698 } | |
699 } | |
700 | |
701 | |
487 | 702 function stDBFetchSQLColumn($dbh, $sql, $column = 0) |
0 | 703 { |
487 | 704 if (($res = $dbh->query($sql)) !== FALSE) |
0 | 705 return $res->fetchColumn($column); |
706 else | |
707 { | |
501 | 708 stLogSQLError($dbh, $sql); |
0 | 709 stError("Oh noes! SQL error #81!"); |
710 return FALSE; | |
711 } | |
712 } | |
713 | |
714 | |
487 | 715 function stPrepareSQLUpdate($table, $cond, $pairs) |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
716 { |
487 | 717 global $db; |
718 return stDBPrepareSQLUpdate($db, $table, $cond, $pairs); | |
719 } | |
720 | |
721 | |
547
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
722 function stExecSQLInsert($sql) |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
723 { |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
724 global $db; |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
725 return stDBExecSQLInsert($db, $sql); |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
726 } |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
727 |
1fceb6f57c90
Add helper functions for SQL INSERT that return the last insert id, to work
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
728 |
492 | 729 function stExecSQL($sql) |
487 | 730 { |
731 global $db; | |
732 return stDBExecSQL($db, $sql); | |
733 } | |
734 | |
735 | |
492 | 736 function stFetchSQL($sql) |
487 | 737 { |
738 global $db; | |
739 return stDBFetchSQL($db, $sql); | |
740 } | |
741 | |
742 | |
743 function stFetchSQLColumn($sql, $column = 0) | |
744 { | |
745 global $db; | |
746 return stDBFetchSQLColumn($db, $sql, $column); | |
66
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
747 } |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
748 |
230aacc22cb4
Move some functions to site lib.
Matti Hamalainen <ccr@tnsp.org>
parents:
65
diff
changeset
|
749 |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
750 function stDBBeginTransaction($dbh = FALSE) |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
751 { |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
752 global $db; |
579 | 753 return stDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "BEGIN TRANSACTION"); |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
754 } |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
755 |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
756 |
607
e78d90ca4f4a
Use default database handle for transaction commits if none provided.
Matti Hamalainen <ccr@tnsp.org>
parents:
579
diff
changeset
|
757 function stDBCommitTransaction($dbh = FALSE) |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
758 { |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
759 global $db; |
579 | 760 return stDBExecSQL(($dbh !== FALSE) ? $dbh : $db, "COMMIT"); |
578
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
761 } |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
762 |
4227095a1384
Add functions for beginning and committing SQL transactions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
577
diff
changeset
|
763 |
577
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
764 function stDBGetTableSchema($dbh, $data) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
765 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
766 $res = array(); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
767 $driver = $dbh->getAttribute(PDO::ATTR_DRIVER_NAME); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
768 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
769 foreach ($data as $col) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
770 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
771 $tmp = array(); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
772 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
773 switch ($driver) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
774 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
775 case "pgsql": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
776 foreach ($col as $elem) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
777 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
778 // For Postgres, use SERIAL for autoincrement |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
779 if ($elem == "AUTOINCREMENT") |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
780 $tmp[1] = "SERIAL"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
781 else |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
782 $tmp[] = $elem; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
783 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
784 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
785 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
786 case "mysql": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
787 foreach ($col as $elem) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
788 { |
1102 | 789 if ($elem == "AUTOINCREMENT") |
577
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
790 $tmp[] = "AUTO_INCREMENT"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
791 else |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
792 $tmp[] = $elem; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
793 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
794 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
795 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
796 case "sqlite": |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
797 $tmp = $col; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
798 break; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
799 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
800 default: |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
801 die("Don't know how to handle PDO driver '".$driver."' yet.\n"); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
802 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
803 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
804 $res[] = implode(" ", $tmp); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
805 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
806 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
807 return implode(", ", $res); |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
808 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
809 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
810 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
811 function stDBCreateOneTable($dbh, $name, $schema) |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
812 { |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
813 // echo "CREATE TABLE ".$name ." (".$schema.")\n"; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
814 return (stDBExecSQL($dbh, "CREATE TABLE ".$name." (".$schema.")") !== FALSE) ? TRUE : FALSE; |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
815 } |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
816 |
ba521a7e7653
Move two DB helper functions from managedb to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
575
diff
changeset
|
817 |
803
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
818 function stSubStrCmp($str, $cmp, $send = FALSE) |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
819 { |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
820 if ($send) |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
821 return substr($str, -strlen($cmp)) == $cmp; |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
822 else |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
823 return substr($str, 0, strlen($cmp)) == $cmp; |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
824 } |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
825 |
ddb30c989b47
Add new helper function stSubStrCmp() for comparing substrings.
Matti Hamalainen <ccr@tnsp.org>
parents:
793
diff
changeset
|
826 |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
827 function stStrChop($str, $len) |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
828 { |
1102 | 829 return (strlen($str) > $len) ? substr($str, 0, $len - 3)."..." : $str; |
558
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
830 } |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
831 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
832 |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
833 function stStrChopPad($str, $len) |
09a11dd385c7
Add new function stStrChopPad() that replaces stStrChop(), but stStrChop()
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
834 { |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
835 $tmp = stStrChop($str, $len); |
1102 | 836 for ($i = strlen($tmp); $i < $len; $i++) |
569
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
837 $tmp .= " "; |
9e8637631089
Fix stStrChop() and stStrChopPad() UTF-8 handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
838 return $tmp; |
135
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
839 } |
eecac02579c4
Move stChop() to site module and rename it to stStrChop().
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
840 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
841 |
1017
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
842 $stStrAtimeData = |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
843 [ |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
844 [ 30*24*60*60, "month" , "months" ], |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
845 [ 7*24*60*60, "week" , "weeks" ], |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
846 [ 24*60*60, "day" , "days" ], |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
847 [ 60*60, "hour" , "hours" ], |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
848 [ 60, "minute" , "minutes" ], |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
849 ]; |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
850 |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
851 |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
852 function stStrAtime($val) |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
853 { |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
854 global $stStrAtimeData; |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
855 |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
856 $res = []; |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
857 foreach ($stStrAtimeData as $data) |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
858 if ($val >= $data[0]) |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
859 { |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
860 $tmp = $val / $data[0]; |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
861 $val = $val % $data[0]; |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
862 $res[] = $tmp." ".($tmp > 1 ? $data[2] : $data[1]); |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
863 } |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
864 return implode(", ", $res); |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
865 } |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
866 |
438457153ced
Add new utility function stStrAtime().
Matti Hamalainen <ccr@tnsp.org>
parents:
1006
diff
changeset
|
867 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
868 function cmPrintCSSLine($filename, $media = FALSE) |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
869 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
870 echo |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
871 " <link rel=\"stylesheet\" href=\"".$filename. |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
872 "\" type=\"text/css\" ".($media !== FALSE ? "media=\"".$media."\"": "")." />\n"; |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
873 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
874 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
875 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
876 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
|
877 { |
575
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
878 global $pageCSS, $pageCSSIndex, $pageCharset, $pageAuthor, $pageCSSData, $pageUrchin; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
879 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
880 if (!isset($pageCSS)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
881 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
882 if (!isset($pageCSSData)) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
883 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
884 $pageCSSData = array( |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
885 "cookie" => "docscss", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
886 "prefix" => "/css/docs", |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
887 ); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
888 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
889 |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
890 if (isset($_GET["css"])) |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
891 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
892 $pageCSSIndex = intval($_GET["css"]); |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
893 setcookie($pageCSSData["cookie"], $pageCSSIndex, time() + 365*24*60*60, "/"); // expire in a year |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
894 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
895 else |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
896 { |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
897 $pageCSSIndex = isset($_COOKIE[$pageCSSData["cookie"]]) ? intval($_COOKIE[$pageCSSData["cookie"]]) : 1; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
898 } |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
899 $pageCSS = $pageCSSData["prefix"].$pageCSSIndex.".css"; |
1ec34a220df3
Another merge from generic custom site branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
574
diff
changeset
|
900 } |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
901 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
902 echo |
363 | 903 "<!DOCTYPE html>\n". |
178 | 904 "<html>\n". |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
905 "<head>\n". |
232 | 906 " <meta charset=\"".$pageCharset."\">\n". |
907 " <title>".strip_tags($pageTitle)."</title>\n". | |
908 $pageExtra; | |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
909 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
910 if (is_array($pageCSS)) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
911 { |
180
a3f0f2a3551a
Split stylesheets into separate files for different platforms and also split
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
912 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
|
913 cmPrintCSSLine($uri, $media); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
914 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
915 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
916 { |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
917 cmPrintCSSLine($pageCSS, FALSE); |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
918 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
919 |
232 | 920 echo |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
921 "</head>\n". |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
922 "<body>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
923 |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
924 if (isset($pageUrchin) && file_exists($pageUrchin)) |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
925 require_once $pageUrchin; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
926 else |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
927 if (file_exists("urchin.inc.php")) |
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
928 require_once "urchin.inc.php"; |
349
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
929 |
61c4dda0ec03
New message/confirmation boxes code done in JS + CSS instead of relying on
Matti Hamalainen <ccr@tnsp.org>
parents:
336
diff
changeset
|
930 echo "<div id=\"messageBox\"></div>\n"; |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
931 |
174
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
932 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
933 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
|
934 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
935 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
936 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
937 function cmPrintPageFooter($useContents = TRUE) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
938 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
939 if ($useContents) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
940 echo "</div>\n"; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
941 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
942 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
|
943 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
944 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
945 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
946 function cmQM($msg) |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
947 { |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
948 global $pageTranslations, $pageLang; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
949 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
950 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
|
951 $str = $pageTranslations[$msg][$pageLang]; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
952 else |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
953 $str = $msg; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
954 |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
955 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
|
956 $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
|
957 return $str; |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
958 } |
63c840590476
Move common code from mcommon.inc.php to msitegen module.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
959 |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
960 |
1069
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
961 function stCommonAJAX($backend, $failover) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
962 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
963 ?> |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
964 function jsSendPOSTRequest(params, success, failure) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
965 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
966 <?php |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
967 if (($csrfID = stGetSessionItem("csrfID", FALSE)) !== FALSE) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
968 echo " params += \"&csrfID=".$csrfID."\";\n"; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
969 else |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
970 echo "// No CSRF?\n"; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
971 ?> |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
972 var req = jsCreateXMLRequest(); |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1103
diff
changeset
|
973 req.open("POST", "<?php echo $backend ?>", TRUE); |
1069
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
974 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
975 req.setRequestHeader("Content-length", params.length); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
976 req.setRequestHeader("Connection", "close"); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
977 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
978 req.onreadystatechange = function() |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
979 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
980 if (req.readyState == 4) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
981 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
982 switch (req.status) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
983 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
984 case 404: |
1071 | 985 window.location = "<?php echo $failover ?>"; |
1069
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
986 break; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
987 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
988 case 902: |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
989 jsStatusMsg(req.statusText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
990 jsMessageBox(req.responseText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
991 break; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
992 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
993 case 903: |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
994 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
995 var nitem = document.getElementById("messageBox"); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
996 if (nitem) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
997 { |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
998 nitem.innerHTML = "<div class='messageBoxInner'>"+ req.responseText + |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
999 "<div class='messageBoxControls'>"+ |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1000 "</div></div>"; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1001 nitem.style.display = "block"; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1002 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1003 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1004 break; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1005 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1006 case 200: |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1007 if (success) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1008 success(req.responseText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1009 jsStatusMsg(req.statusText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1010 break; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1011 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1012 default: |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1013 if (failure) |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1014 failure(req.status, req.statusText, req.responseText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1015 else |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1016 jsStatusMsg("["+req.status+" - "+req.statusText+"] "+ req.responseText); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1017 break; |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1018 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1019 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1020 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1021 req.send(params); |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1022 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1023 |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1024 <?php |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1025 } |
5f92fa5e683a
Refactor how the "AJAX" stuff works.
Matti Hamalainen <ccr@tnsp.org>
parents:
1027
diff
changeset
|
1026 |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1027 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1028 // CLI related helper functions |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1029 // |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1030 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1031 // Check if we are running from commandline or not |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1032 function stCheckCLIExec($fail = TRUE) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1033 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1034 if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1035 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1036 if ($fail) |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1037 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1038 header("Status: 404 Not Found"); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1039 die(); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1040 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1041 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1042 return TRUE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1043 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1044 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1045 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1046 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1047 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1048 |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1049 function stCArg($index, $clip = FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1050 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1051 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1052 if ($index < $argc) |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1053 { |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1054 $str = $argv[$index]; |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1055 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1056 } |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1057 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1058 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1059 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1060 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1061 |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1062 function stCArgLC($index, $clip = FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1063 { |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1064 global $argc, $argv; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1065 if ($index < $argc) |
1006
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1066 { |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1067 $str = strtolower($argv[$index]); |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1068 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; |
cb23b23a2d8b
Improve commandline parsing, fix some potential bug situations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1003
diff
changeset
|
1069 } |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1070 else |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1071 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1072 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1073 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1074 |
1027
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1075 function stYesNoPrompt($msg, $default = FALSE) |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1076 { |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1077 echo $msg." [".($default ? "Y/n" : "y/N")."]? "; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1078 $sprompt = strtolower(trim(fgets(STDIN))); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1079 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1080 if ($default) |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1081 return ($sprompt == "n"); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1082 else |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1083 return ($sprompt == "y"); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1084 } |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1085 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1086 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1087 function stInputPrompt($msg, $default = FALSE, $validate = null) |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1088 { |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1089 $valid = FALSE; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1090 while (!$valid) |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1091 { |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1092 echo $msg."\n".($default !== FALSE ? "[".$default."]" : "")."> "; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1093 $sprompt = trim(fgets(STDIN)); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1094 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1095 if ($sprompt == "") |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1096 $sprompt = ($default !== FALSE ? $default : ""); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1097 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1098 $valid = !is_callable($validate) || call_user_func($validate, $sprompt); |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1099 } |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1100 return $sprompt; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1101 } |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1102 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1103 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1104 function stValidateNotEmpty($val) |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1105 { |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1106 if ($val == "") |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1107 { |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1108 echo "The value can't be empty.\n"; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1109 return FALSE; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1110 } |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1111 else |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1112 return TRUE; |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1113 } |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1114 |
0603012e99b7
Add CLI helper functions stYesNoPrompt() and stInputPrompt().
Matti Hamalainen <ccr@tnsp.org>
parents:
1017
diff
changeset
|
1115 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1116 function stGetDBMeta($dbh, $name) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1117 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1118 if (($item = stDBFetchSQL($dbh, "SELECT * FROM dbmeta WHERE key=".$dbh->quote($name))) === FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1119 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1120 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1121 return stGetSQLSettingData($item); |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1122 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1123 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1124 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1125 function stSetDBMeta($dbh, $name, $value) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1126 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1127 if (($item = stDBFetchSQL($dbh, "SELECT * FROM dbmeta WHERE key=".$dbh->quote($name))) === FALSE) |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1128 return FALSE; |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1129 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1130 $sql = "UPDATE dbmeta SET ".stGetSettingSQL($item, $value)." WHERE key=".$dbh->quote($name); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
1131 return stDBExecSQL($dbh, $sql); |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1132 } |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1133 |
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
1134 |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1135 // |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1136 // Global locale initialization |
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1137 // |
562 | 1138 if (!isset($localeInited) || !$localeInited) |
1139 { | |
1140 $localeInited = TRUE; | |
574
463189fc05ed
Some changes from custom site system branch.
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
1141 $pageCharset = "UTF-8"; |
561
6b4cbd590d35
More locale initialization refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1142 |
562 | 1143 $tmp = "en_US.".strtolower(str_replace("-", "", $pageCharset)); |
1144 setlocale(LC_ALL, $tmp); | |
1145 } | |
0 | 1146 ?> |