OSDN Git Service

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