OSDN Git Service

b80babbced7e33f1dd273503d7cefa11f2bf5a81
[idb/iDB.git.git] / sql.php
1 <?php
2 /*
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the Revised BSD License.
5
6     This program is distributed in the hope that it will be useful,
7     but WITHOUT ANY WARRANTY; without even the implied warranty of
8     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9     Revised BSD License for more details.
10
11     Copyright 2004-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12     Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
13
14     $FileInfo: sql.php - Last Update: 4/6/2022 SVN 944 - Author: cooldude2k $
15 */
16 /* Some ini setting changes uncomment if you need them. 
17    Display PHP Errors */
18 $disfunc = @ini_get("disable_functions");
19 $disfunc = @trim($disfunc);
20 $disfunc = @preg_replace("/([\\s+|\\t+|\\n+|\\r+|\\0+|\\x0B+])/i", "", $disfunc);
21 if($disfunc!="ini_set") { $disfunc = explode(",",$disfunc); }
22 if($disfunc=="ini_set") { $disfunc = array("ini_set"); }
23 if(!in_array("ini_set", $disfunc)) {
24 @ini_set("html_errors", false);
25 @ini_set("track_errors", false);
26 @ini_set("display_errors", false);
27 @ini_set("report_memleaks", false);
28 @ini_set("display_startup_errors", false);
29 //@ini_set("error_log","logs/error.log"); 
30 //@ini_set("log_errors","On"); 
31 @ini_set("docref_ext", "");
32 @ini_set("docref_root", "http://php.net/"); }
33 if(!defined("E_DEPRECATED")) { define("E_DEPRECATED", 0); }
34 @error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
35 /* Get rid of session id in urls */
36 if(!in_array("ini_set", $disfunc)) {
37 @ini_set("default_mimetype","text/html"); 
38 @ini_set("zlib.output_compression", false);
39 @ini_set("zlib.output_compression_level", -1);
40 @ini_set("session.use_trans_sid", false);
41 @ini_set("session.use_cookies", true);
42 @ini_set("session.use_only_cookies", true);
43 @ini_set("url_rewriter.tags",""); 
44 @ini_set('zend.ze1_compatibility_mode', 0);
45 @ini_set("ignore_user_abort", 1); }
46 @set_time_limit(30); @ignore_user_abort(true);
47 /* Change session garbage collection settings */
48 if(!in_array("ini_set", $disfunc)) {
49 @ini_set("session.gc_probability", 1);
50 @ini_set("session.gc_divisor", 100);
51 @ini_set("session.gc_maxlifetime", 1440);
52 /* Change session hash type here */
53 @ini_set("session.hash_function", 1);
54 @ini_set("session.hash_bits_per_character", 6); }
55 /* Do not change anything below this line unless you know what you are doing */
56 $File3Name = basename($_SERVER['SCRIPT_NAME']);
57 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
58         header('Location: index.php');
59         exit(); }
60 if(file_exists('settings.php')) {
61         require_once('settings.php'); 
62         if(file_exists('extrasettings.php')) {
63                 require_once('extrasettings.php'); }
64         if(file_exists('extendsettings.php')) {
65                 require_once('extendsettings.php'); }
66 if(!in_array("ini_set", $disfunc)&&$Settings['qstr']!="/"&&$Settings['qstr']!="&") {
67 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
68 ini_set("arg_separator.input",$Settings['qstr']); } }
69 if(!isset($Settings['idburl'])) { $Settings['idburl'] = null; }
70 if(isset($Settings['BoardUUID'])) { $Settings['BoardUUID'] = base64_decode($Settings['BoardUUID']); 
71 header("Board-Unique-ID: ".$Settings['BoardUUID']); }
72 function unparse_url($parsed_url) {
73   $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
74   $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
75   $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
76   $user     = isset($parsed_url['user']) ? $parsed_url['user'] : '';
77   $pass     = isset($parsed_url['pass']) ? ':' . $parsed_url['pass']  : '';
78   $pass     = ($user || $pass) ? "$pass@" : '';
79   $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
80   $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
81   $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
82   return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
83
84 $OrgBoardURL = $Settings['idburl'];
85 $PreBestURL = parse_url($Settings['idburl']);
86 $PreServURL = parse_url((isset($_SERVER['HTTPS']) ? "https" : "http") . "://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
87 if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
88    $PreBestURL['host'] = "localhost";
89    $PreBestURL['path'] = $PreServURL['path'];
90    $Settings['idburl'] = unparse_url($PreBestURL); }
91 if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])!="localpath") {
92    $PreBestURL['host'] = $PreServURL['host'];
93    $Settings['idburl'] = unparse_url($PreBestURL); }
94 if($PreBestURL['host']!="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
95    $PreBestURL['path'] = $PreServURL['path'];
96    $Settings['idburl'] = unparse_url($PreBestURL); }
97 $OrgWebSiteURL = $Settings['weburl'];
98 $PreWestURL = parse_url($Settings['weburl']);
99 if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
100    $PreWestURL['host'] = $PreServURL['host'];
101    $PreWestURL['path'] = $PreServURL['path'];
102    $Settings['weburl'] = unparse_url($PreWestURL); }
103 if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])!="localpath") {
104    $PreWestURL['host'] = $PreServURL['host'];
105    $Settings['weburl'] = unparse_url($PreWestURL); }
106 if($PreWestURL['host']!="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
107    $PreWestURL['path'] = $PreServURL['path'];
108    $Settings['weburl'] = unparse_url($PreWestURL); }
109 if(!isset($Settings['fixbasedir'])) { $Settings['fixbasedir'] = null; }
110 if(!isset($Settings['fixpathinfo'])) { $Settings['fixpathinfo'] = null; }
111 if(!isset($Settings['fixcookiedir'])) { $Settings['fixcookiedir'] = null; }
112 if(!isset($Settings['fixredirectdir'])) { $Settings['fixcookiedir'] = null; }
113 if(!isset($Settings['idb_time_format'])) { $Settings['idb_time_format'] = "g:i A"; }
114 if(!isset($Settings['idb_date_format'])) { $Settings['idb_date_format'] = "F j Y"; }
115 if(!isset($Settings['showverinfo'])) { 
116         $Settings['showverinfo'] = "on"; }
117 if(!isset($Settings['sqldb'])) {
118 header("Content-Type: text/plain; charset=UTF-8");
119 header('Location: install.php?act=Part1'); }
120 if(!isset($Settings['fixpathinfo'])) {
121         $Settings['fixpathinfo'] = "off"; }
122 if($Settings['fixpathinfo']=="off") {
123         $Settings['fixpathinfo'] = null; }
124 if(!isset($Settings['fixbasedir'])) {
125         $Settings['fixbasedir'] = "off"; }
126 if($Settings['fixbasedir']=="off") {
127         $Settings['fixbasedir'] = null; }
128 if(!isset($Settings['fixcookiedir'])) {
129         $Settings['fixcookiedir'] = "off"; }
130 if($Settings['fixcookiedir']=="off") {
131         $Settings['fixcookiedir'] = null; }
132 if(!isset($Settings['fixredirectdir'])) {
133         $Settings['fixredirectdir'] = "off"; }
134 if($Settings['fixredirectdir']=="off") {
135         $Settings['fixredirectdir'] = null; }
136 $OldSettings['fixpathinfo'] = $Settings['fixpathinfo'];
137 $OldSettings['fixbasedir'] = $Settings['fixbasedir'];
138 $OldSettings['fixcookiedir'] = $Settings['fixcookiedir'];
139 $OldSettings['fixredirectdir'] = $Settings['fixredirectdir'];
140 if($Settings['idburl']=="localhost") { 
141 header("Content-Type: text/plain; charset=UTF-8");
142 echo "500 Error: URL is malformed. Try reinstalling iDB."; die(); }
143 if($Settings['fixbasedir']=="on") {
144 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
145 $PathsTest = parse_url($Settings['idburl']);
146 $Settings['fixbasedir'] = $PathsTest['path']."/"; 
147 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
148 if($Settings['fixcookiedir']=="on") {
149 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
150 $PathsTest = parse_url($Settings['idburl']);
151 $Settings['fixcookiedir'] = $PathsTest['path']."/"; 
152 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
153 if($Settings['fixredirectdir']=="on") {
154 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
155 $PathsTest = parse_url($Settings['idburl']);
156 $Settings['fixredirectdir'] = $PathsTest['path']."/"; 
157 $Settings['fixredirectdir'] = str_replace("//", "/", $Settings['fixredirectdir']); } }
158 if(!isset($Settings['charset'])) {
159         $Settings['charset'] = "ISO-8859-15"; }
160 if(isset($Settings['charset'])) {
161 if($Settings['charset']!="ISO-8859-15"&&$Settings['charset']!="ISO-8859-1"&&
162         $Settings['charset']!="UTF-8"&&$Settings['charset']!="CP866"&&
163         $Settings['charset']!="Windows-1251"&&$Settings['charset']!="Windows-1252"&&
164         $Settings['charset']!="KOI8-R"&&$Settings['charset']!="BIG5"&&
165         $Settings['charset']!="GB2312"&&$Settings['charset']!="BIG5-HKSCS"&&
166         $Settings['charset']!="Shift_JIS"&&$Settings['charset']!="EUC-JP") {
167         $Settings['charset'] = "ISO-8859-15"; } }
168         $chkcharset = $Settings['charset'];
169 if(!in_array("ini_set", $disfunc)) {
170 @ini_set('default_charset', $Settings['charset']); }
171 //session_save_path($SettDir['inc']."temp/");
172 if(!isset($Settings['sqldb'])) { 
173 if(file_exists("install.php")) { header('Location: install.php?act=Part1'); die(); } 
174 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
175 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
176 if(isset($Settings['sqldb'])) { 
177         $deftz = new DateTimeZone(date_default_timezone_get());
178         $defcurtime = new DateTime();
179         $defcurtime->setTimezone($deftz);
180         $utctz = new DateTimeZone("UTC");
181         $utccurtime = new DateTime();
182         $utccurtime->setTimestamp($defcurtime->getTimestamp());
183         $utccurtime->setTimezone($utctz);
184         $servtz = new DateTimeZone($Settings['DefaultTimeZone']);
185         $servcurtime = new DateTime();
186         $servcurtime->setTimestamp($defcurtime->getTimestamp());
187         $servcurtime->setTimezone($servtz);
188         $usercurtime = new DateTime();
189         $usercurtime->setTimestamp($defcurtime->getTimestamp()); }
190 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
191 if($Settings['fixpathinfo']=="on") {
192         $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
193         putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
194 // Check to see if variables are set
195 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
196 if(!isset($SettDir['archive'])) { $SettDir['archive'] = "archive/"; }
197 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
198 if(!isset($SettDir['sql'])) { $SettDir['sql'] = "inc/misc/sql/"; }
199 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
200 if(!isset($SettDir['sqldumper'])) { $SettDir['sqldumper'] = "inc/admin/sqldumper/"; }
201 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
202 if(!isset($SettDir['mplayer'])) { $SettDir['mplayer'] = "inc/mplayer/"; }
203 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
204 if(!isset($SettDir['maindir'])||!file_exists($SettDir['maindir'])||!is_dir($SettDir['maindir'])) { 
205         $SettDir['maindir'] = addslashes(str_replace("\\","/",dirname(__FILE__)."/")); }
206 if(isset($SettDir['maindir'])) { @chdir($SettDir['maindir']); }
207 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
208 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = "off"; }
209 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
210 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { 
211         $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
212 if(!isset($_SERVER["HTTP_ACCEPT"])) { $_SERVER["HTTP_ACCEPT"] = null; }
213 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
214 if(!isset($_GET['page'])) { $_GET['page'] = null; }
215 if(!isset($_GET['act'])) { $_GET['act'] = null; }
216 if(!isset($_POST['act'])) { $_POST['act'] = null; }
217 if(!isset($_GET['modact'])) { $_GET['modact'] = null; }
218 if(!isset($_POST['modact'])) { $_POST['modact'] = null; }
219 if(!isset($_GET['id'])) { $_GET['id'] = null; }
220 if(!isset($_GET['debug'])) { $_GET['debug'] = "off"; }
221 if(!isset($_GET['post'])) { $_GET['post'] = null; }
222 if(!isset($_POST['License'])) { $_POST['License'] = null; }
223 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
224 if(!isset($Settings['SQLThemes'])) { $Settings['SQLThemes'] = "off"; }
225 if($Settings['SQLThemes']!="on"&&$Settings['SQLThemes']!="off") { 
226         $Settings['SQLThemes'] = "off"; }
227 require_once($SettDir['misc'].'utf8.php');
228 require_once($SettDir['inc'].'filename.php');
229 if(!isset($Settings['use_hashtype'])) {
230         $Settings['use_hashtype'] = "sha1"; }
231 if(!function_exists('hash')||!function_exists('hash_algos')) {
232 if($Settings['use_hashtype']!="md5"&&
233    $Settings['use_hashtype']!="sha1"&&
234    $Settings['use_hashtype']!="bcrypt") {
235         $Settings['use_hashtype'] = "sha1"; } }
236 if((function_exists('hash')&&function_exists('hash_algos'))||function_exists('password_hash')) {
237 if(!in_array($Settings['use_hashtype'],hash_algos())&&$Settings['use_hashtype']!="bcrypt") {
238         $Settings['use_hashtype'] = "sha1"; }
239 if($Settings['use_hashtype']!="md2"&&
240    $Settings['use_hashtype']!="md4"&&
241    $Settings['use_hashtype']!="md5"&&
242    $Settings['use_hashtype']!="sha1"&&
243    $Settings['use_hashtype']!="sha224"&&
244    $Settings['use_hashtype']!="sha256"&&
245    $Settings['use_hashtype']!="sha384"&&
246    $Settings['use_hashtype']!="sha512"&&
247    $Settings['use_hashtype']!="sha3-224"&&
248    $Settings['use_hashtype']!="sha3-256"&&
249    $Settings['use_hashtype']!="sha3-384"&&
250    $Settings['use_hashtype']!="sha3-512"&&
251    $Settings['use_hashtype']!="ripemd128"&&
252    $Settings['use_hashtype']!="ripemd160"&&
253    $Settings['use_hashtype']!="ripemd256"&&
254    $Settings['use_hashtype']!="ripemd320"&&
255    $Settings['use_hashtype']!="bcrypt") {
256         $Settings['use_hashtype'] = "sha1"; } }
257 // Check to see if variables are set
258 require_once($SettDir['misc'].'setcheck.php');
259 $dayconv = array("year" => 29030400, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
260 require_once($SettDir['inc'].'function.php');
261 $Settings['bid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=versioninfo",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)));
262 $Settings['ubid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=versioninfo",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)));
263 if($Settings['enable_pathinfo']=="on") { 
264         mrstring(); /* Change Path info to Get Vars :P */ }
265 // Check to see if variables are set
266 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
267 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
268 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
269 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
270 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
271 $cookieDomain = null; $cookieSecure = false;
272 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
273 $URLsTest = parse_url($Settings['idburl']); 
274 $cookieDomain = $URLsTest['host'];
275 if($cookieDomain=="localhost") { $cookieDomain = false; }
276 if($Settings['enable_https']=="on") {
277  if($URLsTest['scheme']=="https") { $cookieSecure = true; }
278  if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
279 if(!in_array("ini_set", $disfunc)) {
280 @ini_set('default_charset', $Settings['charset']); }
281 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
282 $File2Name = $_SERVER['SCRIPT_NAME'];
283 /*$File3Name=str_replace($File1Name, null, $File2Name);
284 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
285         header('Location: index.php');
286         exit(); }*/
287 $File3Name = basename($_SERVER['SCRIPT_NAME']);
288 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
289     header('Location: index.php');
290     exit(); }
291 //error_reporting(E_ERROR);
292 // Check if gzip is on and if user's browser can accept gzip pages
293 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
294         $Settings['use_gzip'] = 'off'; }
295 if($Settings['use_gzip']=="on") {
296 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")&&function_exists('brotli_compress')) { 
297         $GZipEncode['Type'] = "brotli"; } else { 
298         if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { 
299                 $GZipEncode['Type'] = "gzip"; } else { 
300                 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { 
301                         $GZipEncode['Type'] = "deflate"; } else { 
302                         $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } } }
303 if($Settings['use_gzip']=="brotli"&&function_exists('brotli_compress')) {
304 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")) { $Settings['use_brotli'] = "on";
305         $GZipEncode['Type'] = "brotli"; } else { $Settings['use_gzip'] = "off"; } }
306 if($Settings['use_gzip']=="brotli"&&!function_exists('brotli_compress')) { $GZipEncode['Type'] = "gzip"; }
307 if($Settings['use_gzip']=="gzip") {
308 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
309         $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
310 if($Settings['use_gzip']=="deflate") {
311 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
312         $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
313 $iWrappers = array(null);
314 function idb_output_handler($buffer) { return $buffer; }
315 function idb_suboutput_handler($buffer) { return $buffer; }
316 if($Settings['clean_ob']=="on") {
317 /* Check for other output handlers/buffers are open
318    and close and get the contents in an array */
319 $numob = count(ob_list_handlers()); $iob = 0; 
320 while ($iob < $numob) { 
321         $old_ob_var[$iob] = ob_get_clean(); 
322         ++$iob; } } ob_start("idb_output_handler");
323 if($Settings['use_gzip']=="on") { 
324 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
325         if($GZipEncode['Type']=="gzip") {
326         header("Content-Encoding: gzip"); }
327         if($GZipEncode['Type']=="deflate") {
328         header("Content-Encoding: deflate"); } }
329 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
330 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
331 // Some http stuff
332 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
333 if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
334         if($Settings['sql_collate']=="ascii_bin"||
335                 $Settings['sql_collate']=="ascii_generel_ci") {
336                 $Settings['sql_charset'] = "ascii"; }
337         if($Settings['sql_collate']=="latin1_bin"||
338                 $Settings['sql_collate']=="latin1_general_ci"||
339                 $Settings['sql_collate']=="latin1_general_cs") {
340                 $Settings['sql_charset'] = "latin1"; }
341         if($Settings['sql_collate']=="utf8_bin"||
342                 $Settings['sql_collate']=="utf8_general_ci"||
343                 $Settings['sql_collate']=="utf8_unicode_ci"||
344                 $Settings['sql_collate']=="utf8mb4_bin"||
345                 $Settings['sql_collate']=="utf8mb4_general_ci"||
346                 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
347                 $Settings['sql_charset'] = "utf8"; } }
348 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
349         if($Settings['sql_charset']=="ascii") {
350         if($Settings['sql_collate']!="ascii_bin"&&
351                 $Settings['sql_collate']!="ascii_generel_ci") {
352                 $Settings['sql_collate'] = "ascii_generel_ci"; } }
353         if($Settings['sql_charset']=="latin1") {
354         if($Settings['sql_collate']!="latin1_bin"&&
355                 $Settings['sql_collate']!="latin1_general_ci"&&
356                 $Settings['sql_collate']!="latin1_general_cs") {
357                 $Settings['sql_collate'] = "latin1_general_ci"; } }
358         if($Settings['sql_charset']=="utf8" || $Settings['sql_charset']=="utf8mb4") {
359         if($Settings['sql_collate']!="utf8_bin"&&
360                 $Settings['sql_collate']!="utf8_general_ci"&&
361                 $Settings['sql_collate']!="utf8_unicode_ci"&&
362                 $Settings['sql_collate']!="utf8mb4_bin"&&
363                 $Settings['sql_collate']!="utf8mb4_general_ci"&&
364                 $Settings['sql_collate']!="utf8mb4_unicode_ci") {
365                 $Settings['sql_collate'] = "utf8mb4_unicode_ci"; } }
366         if($Settings['sql_collate']=="utf8_bin"||
367                 $Settings['sql_collate']=="utf8_general_ci"||
368                 $Settings['sql_collate']=="utf8_unicode_ci") {
369                 $Settings['sql_charset'] = "utf8"; }
370         if($Settings['sql_collate']=="utf8mb4_bin"||
371                 $Settings['sql_collate']=="utf8mb4_general_ci"||
372                 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
373                 $Settings['sql_charset'] = "utf8mb4"; }
374         $SQLCollate = $Settings['sql_collate'];
375         $SQLCharset = $Settings['sql_charset']; }
376 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
377 $SQLCollate = "latin1_general_ci";
378 $SQLCharset = "latin1"; 
379 if($Settings['charset']=="ISO-8859-1") {
380         $SQLCollate = "latin1_general_ci";
381         $SQLCharset = "latin1"; }
382 if($Settings['charset']=="ISO-8859-15") {
383         $SQLCollate = "latin1_general_ci";
384         $SQLCharset = "latin1"; }
385 if($Settings['charset']=="UTF-8") {
386         $SQLCollate = "utf8mb4_unicode_ci";
387         $SQLCharset = "utf8mb4"; } 
388 $Settings['sql_collate'] = $SQLCollate;
389 $Settings['sql_charset'] = $SQLCharset; }
390 sql_set_charset($SQLCharset,$SQLStat);
391 if($SQLStat===false) {
392 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
393 ob_clean(); echo "Sorry could not connect to sql database.\nContact the board admin about error. Error log below.";
394 echo "\n".sql_errorno($SQLStat); $urlstatus = 503;
395 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
396 $sqltable = $Settings['sqltable'];
397 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
398 if(!isset($_SERVER['HTTP_USER_AGENT'])) {
399         $_SERVER['HTTP_USER_AGENT'] = ""; }
400 if(strpos($_SERVER['HTTP_USER_AGENT'], "msie") && 
401         !strpos($_SERVER['HTTP_USER_AGENT'], "opera")){
402         header("X-UA-Compatible: IE=Edge"); }
403 if(strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
404         header("X-UA-Compatible: IE=Edge,chrome=1"); }
405 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
406 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
407 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
408 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
409 $MkIndexFile = $exfile['index']; }
410 $temp_session_data = "ViewingPage|s:9:\"?act=view\";ViewingFile|s:".strlen($MkIndexFile).":\"".$MkIndexFile."\";PreViewingTitle|s:7:\"Viewing\";ViewingTitle|s:11:\"Board index\";UserID|s:1:\"0\";UserIP|s:".strlen($_SERVER['REMOTE_ADDR']).":\"".$_SERVER['REMOTE_ADDR']."\";UserGroup|s:".strlen($Settings['GuestGroup']).":\"".$Settings['GuestGroup']."\";UserGroupID|s:1:\"4\";UserTimeZone|s:".strlen($Settings['DefaultTimeZone']).":\"".$Settings['DefaultTimeZone']."\";";
411 $alt_temp_session_data['ViewingPage'] = "?act=view";
412 $alt_temp_session_data['ViewingFile'] = $MkIndexFile;
413 $alt_temp_session_data['PreViewingTitle'] = "Viewing";
414 $alt_temp_session_data['ViewingTitle'] = "Board index";
415 $alt_temp_session_data['UserID'] = "0";
416 $alt_temp_session_data['UserIP'] = $_SERVER['REMOTE_ADDR'];
417 $alt_temp_session_data['UserGroupID'] = "4";
418 $alt_temp_session_data['UserTimeZone'] = $Settings['DefaultTimeZone'];
419 $alttemp_session_data = serialize($alt_temp_session_data);
420 $alt_temp_session_data = $alttemp_session_data;
421 $alttemp_session_data = null;
422 $SQLSType = $Settings['sqltype'];
423 //Session Open Function
424 function sql_session_open($save_path, $session_name ) {
425 global $sess_save_path;
426 $sess_save_path = $save_path;
427 return true; }
428 //Session Close Function
429 $iDBSessCloseDB = true;
430 function sql_session_close() {
431 global $SQLStat,$iDBSessCloseDB;
432 if($iDBSessCloseDB===true) {
433 sql_disconnect_db($SQLStat); }
434 return true; }
435 //Session Read Function
436 function sql_session_read($id) {
437 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent,$temp_session_data,$alt_temp_session_data;
438 $result = sql_query(sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id)),$SQLStat);
439 if (!sql_num_rows($result)) {
440 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\"<>'%s' AND \"ip_address\"='%s' AND \"user_agent\"='%s'", array($id,$temp_user_ip,$temp_user_agent)),$SQLStat);
441 $utctz = new DateTimeZone("UTC");
442 $utccurtime = new DateTime();
443 $utccurtime->setTimezone($utctz);
444 $time = $utccurtime->getTimestamp();
445 sql_query(sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"ip_address\", \"expires\") VALUES\n".
446 "('%s', '%s', '%s', '%s', '%s', %i)", array($id,$temp_session_data,$alt_temp_session_data,$temp_user_agent,$temp_user_ip,$time)),$SQLStat);
447 return '';
448 } else {
449 $utctz = new DateTimeZone("UTC");
450 $utccurtime = new DateTime();
451 $utccurtime->setTimezone($utctz);
452 $time = $utccurtime->getTimestamp();
453 $predata = sql_num_rows($result);
454 $data = "";
455 if($predata > 0) {
456 $row = sql_fetch_assoc($result);
457 $data = $row['session_data']; }
458 /*sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id)),$SQLStat);*/
459 return $data; } }
460 //Session Write Function
461 function sql_session_write($id,$data) {
462 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent;
463 $utctz = new DateTimeZone("UTC");
464 $utccurtime = new DateTime();
465 $utccurtime->setTimezone($utctz);
466 $time = $utccurtime->getTimestamp();
467 $rs = sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"serialized_data\"='%s',\"user_agent\"='%s',\"ip_address\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,serialize($_SESSION),$temp_user_agent,$temp_user_ip,$time,$id)),$SQLStat);
468 return true; }
469 //Session Destroy Function
470 function sql_session_destroy($id) {
471 global $sqltable,$SQLStat;
472 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id)),$SQLStat);
473 return true; }
474 //Session Garbage Collection Function
475 function sql_session_gc($maxlifetime) {
476 global $sqltable,$SQLStat;
477 $utctz = new DateTimeZone("UTC");
478 $utccurtime = new DateTime();
479 $utccurtime->setTimezone($utctz);
480 $time = $utccurtime->getTimestamp() - $maxlifetime;
481 //sql_query(sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null)),$SQLStat);
482 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time)),$SQLStat);
483 return true; }
484 if (session_id()) { session_destroy(); }
485 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
486 if($cookieDomain==null) {
487 session_set_cookie_params(0, $cbasedir); }
488 if($cookieDomain!=null) {
489 if($cookieSecure===true) {
490 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
491 if($cookieSecure===false) {
492 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
493 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
494 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
495 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
496 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
497 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
498 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
499 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
500 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
501 $exptime = $utccurtime->getTimestamp() - ini_get("session.gc_maxlifetime");
502 sql_query(sql_pre_query("DELETE FROM \"".$Settings['sqltable']."sessions\" WHERE \"expires\" < %i OR \"ip_address\"='%s' AND \"user_agent\"='%s'", array($exptime,$temp_user_ip,$temp_user_agent)),$SQLStat); }
503 if(!isset($_SESSION['CheckCookie'])) {
504 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
505 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
506 session_name($Settings['sqltable']."sess");
507 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
508 session_start([
509     'use_trans_sid' => false,
510     'use_cookies' => true,
511     'use_only_cookies' => true,
512     'gc_probability' => 1,
513     'gc_divisor' => 100,
514     'gc_maxlifetime' => 1440,
515     //'hash_function' => 1,
516     //'hash_bits_per_character' => 6,
517     'name' => $Settings['sqltable']."sess",
518 ]); }
519 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
520 $iDBSessCloseDB = false;
521 $_SESSION['ShowActHidden'] = "no";
522 output_reset_rewrite_vars();
523 require($SettDir['inc'].'prelogin.php'); 
524 session_write_close(); } }
525 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
526 session_name($Settings['sqltable']."sess");
527 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
528 session_start([
529     'use_trans_sid' => false,
530     'use_cookies' => true,
531     'use_only_cookies' => true,
532     'gc_probability' => 1,
533     'gc_divisor' => 100,
534     'gc_maxlifetime' => 1440,
535     //'hash_function' => 1,
536     //'hash_bits_per_character' => 6,
537     'name' => $Settings['sqltable']."sess",
538 ]); }
539 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
540 $iDBSessCloseDB = true;
541 output_reset_rewrite_vars();
542 //@register_shutdown_function("session_write_close");
543 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
544 if(!in_array("ini_set", $disfunc)) {
545 // Set user agent if we can use ini_set and have to do any http requests. :P 
546 $iverstring = "FR 0.0.0 ".$VER2[2]." 0";
547 if($Settings['hideverinfohttp']=="off") {
548         $iverstring = $VER2[1]." ".$VER1[0].".".$VER1[1].".".$VER1[2]." ".$VER2[2]." ".$SubVerN; }
549 if($Settings['hideverinfohttp']=="on") {
550         $iverstring = "FR 0.0.0 ".$VER2[2]." 0"; }
551 $qstrtest = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
552 $qseptest = htmlentities($Settings['qsep'], ENT_QUOTES, $Settings['charset']);
553 $isiteurl = $Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']);
554 @ini_set("user_agent", "Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")"); 
555 if (function_exists("stream_context_create")) {
556 $iopts = array(
557   'http' => array(
558     'method' => "GET",
559     'header' => "Accept-Language: *\r\n".
560                 "User-Agent: Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")\r\n".
561                 "Accept: */*\r\n".
562                 "Connection: keep-alive\r\n".
563                 "Referer: ".$isiteurl."\r\n".
564                 "From: ".$isiteurl."\r\n".
565                 "Via: ".$_SERVER['REMOTE_ADDR']."\r\n".
566                 "Forwarded: ".$_SERVER['REMOTE_ADDR']."\r\n".
567                 "X-Real-IP: ".$_SERVER['REMOTE_ADDR']."\r\n".
568                 "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR']."\r\n".
569                 "X-Forwarded-Host: ".$URLsTest['host']."\r\n".
570                 "X-Forwarded-Proto: ".$URLsTest['scheme']."\r\n".
571                 "Board-Unique-ID: ".$Settings['BoardUUID']."\r\n".
572                 "Client-IP: ".$_SERVER['REMOTE_ADDR']."\r\n"
573   )
574 );
575 $icontext = stream_context_create($iopts); 
576 function file_get_contents_alt($filename,$use_include_path=null,$offset=-1,$maxlen=null) {
577 global $icontext;
578 if($maxlen!==null) {
579 return file_get_contents($filename,$use_include_path,$icontext,$offset,$maxlen); }
580 if($maxlen===null) {
581 return file_get_contents($filename,$use_include_path,$icontext,$offset); } } } }
582 $iDBVerName = $VerCheckName."|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
583 /* 
584 This way checks iDB version by sending the iDBVerName to the iDB Version Checker.
585 $Settings['vercheck'] = 1; 
586 This way checks iDB version by sending the board url to the iDB Version Checker.
587 $Settings['vercheck'] = 2;
588 */
589 if(!isset($Settings['vercheck'])) { 
590         $Settings['vercheck'] = 2; }
591 if($Settings['vercheck']!=1&&
592         $Settings['vercheck']!=2) {
593         $Settings['vercheck'] = 2; }
594 if($Settings['vercheck']===2) {
595 if($_GET['act']=="vercheckxsl") {
596 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
597 header("Content-Type: application/xml; charset=".$Settings['charset']); }
598 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
599 xml_doc_start("1.0",$Settings['charset']);
600 echo "\n"; ?>
601 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
602
603 <xsl:template match="/">
604  <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
605   <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
606    <xsl:for-each select="versioninfo/version">
607     <div style="background-color:teal;color:white;padding:4px">
608      <span style="font-weight:bold"><xsl:value-of select="vname"/></span>
609     </div>
610     <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
611      <span style="font-style:italic">
612           Board Name: <a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><xsl:value-of select="title"/></a></span>
613     </div>
614    </xsl:for-each>
615   </body>
616  </html>
617 </xsl:template>
618
619 </xsl:stylesheet>
620 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } 
621 if($_GET['act']=="versioninfo") {
622 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
623 header("Content-Type: application/xml; charset=".$Settings['charset']); }
624 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
625 xml_doc_start("1.0",$Settings['charset']);
626 echo '<?xml-stylesheet type="text/xsl" href="'.url_maker($exfile['index'],$Settings['file_ext'],"act=vercheckxsl",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']).'"?>'."\n"; ?>
627
628 <!DOCTYPE versioninfo [
629 <!ELEMENT versioninfo (version*)>
630 <!ELEMENT version (charset,title,name,vname)>
631 <!ELEMENT charset (#PCDATA)>
632 <!ELEMENT title (#PCDATA)>
633 <!ELEMENT name (#PCDATA)>
634 <!ELEMENT vname (#PCDATA)>
635 ]>
636
637 <versioninfo>
638
639 <version>
640  <charset><?php echo $Settings['charset']; ?></charset> 
641   <title><?php echo $Settings['board_name']; ?></title> 
642   <?php echo "<name>".$iDBVerName."</name>\n"; ?>
643   <vname><?php echo $VerCheckName; ?> Version Checker</vname>
644 </version>
645
646 </versioninfo>
647 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } } 
648 if($Settings['vercheck']===1) {
649 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
650 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); $urlstatus = 302;
651 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
652 if($_GET['act']=="homepage") { header("Content-Type: text/plain; charset=UTF-8");
653 header("Location: ".$Settings['weburl']); $urlstatus = 302;
654 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
655 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
656         $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
657 if($_GET['act']=="bsd") {
658 header("Content-Type: text/plain; charset=".$Settings['charset']);
659 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
660 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
661 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
662 header("Content-Type: text/plain; charset=".$Settings['charset']);
663 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
664 if($_GET['act']=="js"||$_GET['act']=="javascript") {
665 header("Content-Script-Type: text/javascript");
666 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
667 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
668 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
669 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
670 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
671 require($SettDir['inc'].'javascript.php');
672 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
673 if($Settings['use_captcha']=="on") {
674 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
675         if($Settings['captcha_clean']=="on") { ob_clean(); }
676         require($SettDir['inc']."captcha.php");
677         $aFontDir = dirname(__FILE__)."/inc/fonts/";
678         $aFonts = array($aFontDir.'VeraBd.ttf', $aFontDir.'VeraBI.ttf', $aFontDir.'VeraIt.ttf', $aFontDir.'Vera.ttf');
679         $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
680         $RNumSize = rand(7,17); $i=0; $RandNum = null;
681         while ($i <= $RNumSize) {
682         $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
683         $RandNum=strtoupper($RandNum);
684         $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
685         $oPhpCaptcha->UseColour(true);
686         $oPhpCaptcha->Create(); session_write_close(); die(); } }
687 require($SettDir['inc'].'groupsetup.php');
688 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
689 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
690 ob_clean(); if(!isset($Settings['offline_text'])) {
691 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
692 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; } $urlstatus = 503;
693 //echo "\n".sql_errorno($SQLStat);
694 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
695 //Time Format Set
696 if(!isset($_SESSION['iDBDateFormat'])) { 
697         if(isset($Settings['idb_date_format'])) { 
698         $_SESSION['iDBDateFormat'] = $Settings['idb_date_format'];
699         if(!isset($Settings['idb_date_format'])) { 
700         $_SESSION['iDBDateFormat'] = "g:i A"; } } }
701 if(!isset($_SESSION['iDBTimeFormat'])) { 
702         if(isset($Settings['idb_time_format'])) { 
703         $_SESSION['iDBTimeFormat'] = $Settings['idb_time_format'];
704         if(!isset($Settings['idb_time_format'])) { 
705         $_SESSION['iDBTimeFormat'] = "F j Y"; } } }
706 //Time Zone Set
707 if(!isset($_SESSION['UserTimeZone'])) { 
708         if(isset($Settings['DefaultTimeZone'])) { 
709         $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
710         if(!isset($Settings['DefaultTimeZone'])) { 
711         $_SESSION['UserTimeZone'] = date_default_timezone_get(); } } }
712 $usertz = new DateTimeZone($_SESSION['UserTimeZone']);
713 $usercurtime->setTimestamp($defcurtime->getTimestamp());
714 $usercurtime->setTimezone($usertz);
715 // Guest Stuff
716 if(isset($_SESSION['MemberName'])||
717    isset($_COOKIE['MemberName'])) {
718         $_SESSION['GuestName'] = null;
719         $_COOKIE['GuestName'] = null; }
720 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
721 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
722         $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
723 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
724 // Skin Stuff
725 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
726 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
727 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
728 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
729 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
730 if(!isset($_GET['style'])) { $_GET['style'] = null; }
731 if(!isset($_POST['style'])) { $_POST['style'] = null; }
732 if(!isset($_GET['css'])) { $_GET['css'] = null; }
733 if(!isset($_POST['css'])) { $_POST['css'] = null; }
734 if($_GET['theme']==null) {
735         if($_POST['theme']!=null) {
736                 $_GET['theme'] = $_POST['theme']; }
737         if($_POST['skin']!=null) {
738                 $_GET['theme'] = $_POST['skin']; }
739         if($_POST['style']!=null) {
740                 $_GET['theme'] = $_POST['style']; }
741         if($_POST['css']!=null) {
742                 $_GET['theme'] = $_POST['css']; }
743         if($_GET['skin']!=null) {
744                 $_GET['theme'] = $_GET['skin']; }
745         if($_GET['style']!=null) {
746                 $_GET['theme'] = $_GET['style']; }
747         if($_GET['css']!=null) {
748                 $_GET['theme'] = $_GET['css']; } }
749 if($Settings['SQLThemes']=="off") {
750 if($_GET['theme']!=null) {
751 $_GET['theme'] = chack_themes($_GET['theme']);
752 if($_GET['theme']=="../"||$_GET['theme']=="./") {
753 $_GET['theme']=$Settings['DefaultTheme']; $_SESSION['Theme']=$Settings['DefaultTheme']; }
754 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
755 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
756 $NewDay=$utccurtime->getTimestamp();
757 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
758 sql_query($qnewskin,$SQLStat); }
759 /* The file Theme Exists */ }
760 else { $_GET['theme'] = $Settings['DefaultTheme']; 
761 $_SESSION['Theme'] = $Settings['DefaultTheme'];
762 /* The file Theme Dose Not Exists */ } }
763 if($_GET['theme']==null) { 
764 if($_SESSION['Theme']!=null) {
765 $OldTheme = $_SESSION['Theme'];
766 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
767 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
768 if($OldTheme!=$_SESSION['Theme']) { 
769 $NewDay=$utccurtime->getTimestamp();
770 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
771 sql_query($qnewskin,$SQLStat); } }
772 $_GET['theme']=$_SESSION['Theme']; }
773 if($_SESSION['Theme']==null) {
774 $_SESSION['Theme']=$Settings['DefaultTheme'];
775 $_GET['theme']=$Settings['DefaultTheme']; } }
776 $PreSkin['skindir1'] = $_SESSION['Theme'];
777 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
778 require($SettDir['themes'].$_GET['theme']."/settings.php"); }
779 if($Settings['SQLThemes']=="on") {
780 if($_GET['theme']==null&&$_SESSION['Theme']==null) { 
781         $_GET['theme'] = $Settings['DefaultTheme']; 
782         $_SESSION['Theme'] = $Settings['DefaultTheme']; }
783 if($_GET['theme']!=null) {
784 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme'])); }
785 if($_GET['theme']==null) { 
786 if($_SESSION['Theme']!=null) {
787 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])); } }
788 $themeresult=sql_query($themequery,$SQLStat);
789 $themenum=sql_num_rows($themeresult);
790 if($themenum<=0) {
791 $_GET['theme'] = $Settings['DefaultTheme']; 
792 $_SESSION['Theme'] = $Settings['DefaultTheme']; 
793 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
794 $NewDay=$utccurtime->getTimestamp();
795 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
796 sql_query($qnewskin,$SQLStat); }
797 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
798 $themeresult=sql_query($themequery,$SQLStat);
799 $themenum=sql_num_rows($themeresult); } 
800 else {
801 if($_GET['theme']==null) { 
802 if($_SESSION['Theme']!=null) {
803 $_GET['theme'] = $_SESSION['Theme']; } }
804 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
805 $NewDay=$utccurtime->getTimestamp();
806 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
807 sql_query($qnewskin,$SQLStat); } } 
808 require($SettDir['inc'].'sqlthemes.php');
809 sql_free_result($themeresult); }
810 $_SESSION['Theme'] = $_GET['theme'];
811 function get_theme_values($matches) {
812         global $ThemeSet;
813         $return_text = null;
814         if(isset($ThemeSet[$matches[1]])) { $return_text = $ThemeSet[$matches[1]]; }
815         if(!isset($ThemeSet[$matches[1]])) { $return_text = null; }
816         return $return_text; }
817 foreach($ThemeSet AS $key => $value) {
818     if(isset($ThemeSet[$key])) {
819         $ThemeSet[$key] = preg_replace("/%%/s", "{percent}p", $ThemeSet[$key]);
820         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}T/s", "get_theme_values", $ThemeSet[$key]);
821         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}e/s", "get_env_values", $ThemeSet[$key]);
822         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}i/s", "get_server_values", $ThemeSet[$key]);
823         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}s/s", "get_setting_values", $ThemeSet[$key]);
824         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}t/s", "get_time", $ThemeSet[$key]); 
825         $ThemeSet[$key] = preg_replace("/\{percent\}p/s", "%", $ThemeSet[$key]); } }
826 if(!isset($ThemeSet['TableStyle'])) {
827         $ThemeSet['TableStyle'] = "table"; }
828 if(isset($ThemeSet['TableStyle'])) {
829 if($ThemeSet['TableStyle']!="div"&&
830         $ThemeSet['TableStyle']!="table") {
831         $ThemeSet['TableStyle'] = "table"; } }
832 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
833 if($_SESSION['DBName']==null) {
834         $_SESSION['DBName'] = $Settings['sqldb']; }
835 if($_SESSION['DBName']!=null) {
836         if($_SESSION['DBName']!=$Settings['sqldb']) {
837 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }
838 ?>