OSDN Git Service

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