OSDN Git Service

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