annotate msitegen.inc.php @ 486:e0fa6bb432d7

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