annotate msitegen.inc.php @ 810:2a23243a6cc4

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