OSDN Git Service

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