OSDN Git Service

Small bug fix. :P
[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-2009 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: sql.php - Last Update: 12/16/2009 SVN 415 - Author: cooldude2k $
15 */
16 /* Some ini setting changes uncomment if you need them. 
17    Display PHP Errors */
18 //ini_set("display_errors", true); 
19 //ini_set("display_startup_errors", true);
20 error_reporting(E_ALL ^ E_NOTICE);
21 //ini_set("error_prepend_string","<span style='color: ff0000;'>");
22 //ini_set("error_append_string","</span>");
23 /* Get rid of session id in urls */
24 //ini_set("session.use_trans_sid", false);
25 //ini_set("session.use_cookies", true);
26 //ini_set("session.use_only_cookies", true);
27 //ini_set("url_rewriter.tags","");
28 set_time_limit(30); ignore_user_abort(true);
29 /* Change session garbage collection settings */
30 //ini_set("session.gc_probability", 1);
31 //ini_set("session.gc_divisor", 100);
32 //ini_set("session.gc_maxlifetime", 1440);
33 $File3Name = basename($_SERVER['SCRIPT_NAME']);
34 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
35         header('Location: index.php');
36         exit(); }
37 require('settings.php');
38 $Settings['bid'] = base64_encode(urlencode($Settings['idburl']));
39 if(!isset($Settings['showverinfo'])) { 
40         $Settings['showverinfo'] = "on"; }
41 if($Settings['fixpathinfo']=="off") {
42         $Settings['fixpathinfo'] = null; }
43 if($Settings['fixbasedir']=="off") {
44         $Settings['fixbasedir'] = null; }
45 if($Settings['fixcookiedir']=="off") {
46         $Settings['fixcookiedir'] = null; }
47 if($Settings['idburl']=="localhost") { 
48 header("Content-Type: text/plain; charset=UTF-8");
49 echo "500 Error: URL is malformed. Try reinstalling iDB."; die(); }
50 if($Settings['fixbasedir']=="on") {
51 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
52 $PathsTest = parse_url($Settings['idburl']);
53 $Settings['fixbasedir'] = $PathsTest['path']."/"; 
54 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
55 if($Settings['fixcookiedir']=="on") {
56 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
57 $PathsTest = parse_url($Settings['idburl']);
58 $Settings['fixcookiedir'] = $PathsTest['path']."/"; 
59 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
60 if(!isset($Settings['charset'])) {
61         $Settings['charset'] = "ISO-8859-15"; }
62 if(isset($Settings['charset'])) {
63 if($Settings['charset']!="ISO-8859-15"&&$Settings['charset']!="ISO-8859-1"&&
64         $Settings['charset']!="UTF-8"&&$Settings['charset']!="CP866"&&
65         $Settings['charset']!="Windows-1251"&&$Settings['charset']!="Windows-1252"&&
66         $Settings['charset']!="KOI8-R"&&$Settings['charset']!="BIG5"&&
67         $Settings['charset']!="GB2312"&&$Settings['charset']!="BIG5-HKSCS"&&
68         $Settings['charset']!="Shift_JIS"&&$Settings['charset']!="EUC-JP") {
69         $Settings['charset'] = "ISO-8859-15"; } }
70         $chkcharset = $Settings['charset'];
71 @ini_set('default_charset', $Settings['charset']);
72 //session_save_path($SettDir['inc']."temp/");
73 if(!isset($Settings['sqldb'])) { 
74 if(file_exists("install.php")) { header('Location: install.php'); die(); } 
75 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
76 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
77 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
78 if($Settings['fixpathinfo']=="on") {
79         $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
80         putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
81 // Check to see if variables are set
82 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
83 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
84 if(!isset($SettDir['sql'])) { $SettDir['sql'] = "inc/misc/sql/"; }
85 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
86 if(!isset($SettDir['sqldumper'])) { $SettDir['sqldumper'] = "inc/admin/sqldumper/"; }
87 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
88 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
89 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
90 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = "off"; }
91 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
92 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { 
93         $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
94 if(!isset($_SERVER["HTTP_ACCEPT"])) { $_SERVER["HTTP_ACCEPT"] = null; }
95 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
96 if(!isset($_GET['page'])) { $_GET['page'] = null; }
97 if(!isset($_GET['act'])) { $_GET['act'] = null; }
98 if(!isset($_POST['act'])) { $_POST['act'] = null; }
99 if(!isset($_GET['modact'])) { $_GET['modact'] = null; }
100 if(!isset($_POST['modact'])) { $_POST['modact'] = null; }
101 if(!isset($_GET['id'])) { $_GET['id'] = null; }
102 if(!isset($_GET['debug'])) { $_GET['debug'] = "off"; }
103 if(!isset($_GET['post'])) { $_GET['post'] = null; }
104 if(!isset($_POST['License'])) { $_POST['License'] = null; }
105 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
106 require_once($SettDir['misc'].'utf8.php');
107 require_once($SettDir['inc'].'filename.php');
108 $iDBVerName = "iDB|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
109 /* This way checks iDB version by sending the iDBVerName to the iDB Version Checker.*/
110 $Settings['vercheck'] = 1;
111 /* This way checks iDB version by sending the board url to the iDB Version Checker.*/
112 $Settings['vercheck'] = 2;
113 if($Settings['vercheck']!=1&&
114         $Settings['vercheck']!=2) {
115         $Settings['vercheck'] = 2; }
116 if($Settings['vercheck']===2) {
117 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8"); ?>
118 <charset><?php echo $Settings['charset']; ?></charset> 
119 <title><?php echo $Settings['board_name']; ?></title> 
120 <?php echo "<name>".$iDBVerName."</name>"; die(); } }
121 if($Settings['vercheck']===1) {
122 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
123 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); die(); } }
124 if(!isset($Settings['use_hashtype'])) {
125         $Settings['use_hashtype'] = "sha256"; }
126 if(!function_exists('hash')||!function_exists('hash_algos')) {
127 if($Settings['use_hashtype']!="md5"&&
128    $Settings['use_hashtype']!="sha1"&&
129    $Settings['use_hashtype']!="sha256") {
130         $Settings['use_hashtype'] = "sha256"; } }
131 if(function_exists('hash')&&function_exists('hash_algos')) {
132 if(!in_array($Settings['use_hashtype'],hash_algos())) {
133         $Settings['use_hashtype'] = "sha256"; }
134 if($Settings['use_hashtype']!="md2"&&
135    $Settings['use_hashtype']!="md4"&&
136    $Settings['use_hashtype']!="md5"&&
137    $Settings['use_hashtype']!="sha1"&&
138    $Settings['use_hashtype']!="sha256"&&
139    $Settings['use_hashtype']!="sha386"&&
140    $Settings['use_hashtype']!="sha512") {
141         $Settings['use_hashtype'] = "sha256"; } }
142 // Check to see if variables are set
143 require_once($SettDir['misc'].'setcheck.php');
144 require_once($SettDir['inc'].'function.php');
145 if($Settings['enable_pathinfo']=="on") { 
146         mrstring(); /* Change Path info to Get Vars :P */ }
147 // Check to see if variables are set
148 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
149 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
150 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
151 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
152 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
153 $cookieDomain = null; $cookieSecure = false;
154 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
155 $URLsTest = parse_url($Settings['idburl']); 
156 $cookieDomain = $URLsTest['host'];
157 if($Settings['enable_https']=="on") {
158  if($URLsTest['scheme']=="https") { $cookieSecure = true; }
159  if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
160 ini_set("default_charset",$Settings['charset']);
161 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
162 $File2Name = $_SERVER['SCRIPT_NAME'];
163 $File3Name=str_replace($File1Name, null, $File2Name);
164 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
165         require($SettDir['inc'].'forbidden.php');
166         exit(); }
167 //error_reporting(E_ERROR);
168 // Check if gzip is on and if user's browser can accept gzip pages
169 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
170         $Settings['use_gzip'] = 'off'; }
171 if($Settings['use_gzip']=="on") {
172 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { 
173         $GZipEncode['Type'] = "gzip"; } else { 
174         if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { 
175         $GZipEncode['Type'] = "deflate"; } else { 
176                 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } }
177 if($Settings['use_gzip']=="gzip") {
178 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
179         $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
180 if($Settings['use_gzip']=="deflate") {
181 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
182         $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
183 if($Settings['clean_ob']=="on") {
184 /* Check for other output handlers/buffers are open
185    and close and get the contents in an array */
186 $numob = count(ob_list_handlers()); $iob = 0; 
187 while ($iob < $numob) { 
188         $old_ob_var[$iob] = ob_get_clean(); 
189         ++$iob; } } ob_start();
190 if($Settings['use_gzip']=="on") { 
191 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
192         if($GZipEncode['Type']=="gzip") {
193         header("Content-Encoding: gzip"); }
194         if($GZipEncode['Type']=="deflate") {
195         header("Content-Encoding: deflate"); } }
196 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
197 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
198 // Some http stuff
199 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
200 $SQLCollate = "latin1_general_ci";
201 $SQLCharset = "latin1"; 
202 if($Settings['charset']=="ISO-8859-1") {
203         $SQLCollate = "latin1_general_ci";
204         $SQLCharset = "latin1"; }
205 if($Settings['charset']=="ISO-8859-15") {
206         $SQLCollate = "latin1_general_ci";
207         $SQLCharset = "latin1"; }
208 if($Settings['charset']=="UTF-8") {
209         $SQLCollate = "utf8_unicode_ci";
210         $SQLCharset = "utf8"; }
211 sql_set_charset($SQLCharset,$SQLStat);
212 if($SQLStat===false) {
213 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
214 ob_clean(); echo "Sorry could not connect to mysql database.\nContact the board admin about error. Error log below.";
215 echo "\n".sql_errorno($SQLStat);
216 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
217 $sqltable = $Settings['sqltable'];
218 function sqlsession_open( $save_path, $session_name ) {
219 global $sess_save_path;
220 $sess_save_path = $save_path;
221 return true; }
222 function sqlsession_close() {
223 return true; }
224 function sqlsession_read($id) {
225 global $sqltable,$SQLStat,$SQLSType;
226 $data = "";
227 $time = GMTimeStamp();
228 $sqlr = sql_pre_query("SELECT \"session_data\" FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id,$time));
229 $rs = sql_query($sqlr,$SQLStat);
230 $a = sql_num_rows($rs);
231 if($a > 0) {
232 $row = sql_fetch_assoc($rs);
233 $data = $row['session_data'];
234 if($SQLSType=="sqlite") {
235 $data = $row["\"session_data\""]; } }
236 return $data; }
237 $SQLSType = $Settings['sqltype'];
238 function sqlsession_write($id,$data) {
239 global $sqltable,$SQLStat,$SQLSType;
240 $time = GMTimeStamp();
241 if($SQLSType=="mysql"||
242         $SQLSType=="mysqli") {
243 $sqlw = sql_pre_query("REPLACE \"".$sqltable."sessions\" VALUES('$id','$data', $time)", array($id,$data,$time));
244 $rs = sql_query($sqlw,$SQLStat); }
245 if($SQLSType=="pgsql"||
246         $SQLSType=="sqlite") {
247 $sqlr = sql_pre_query("SELECT \"session_data\" FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id,$time));
248 $rs = sql_query($sqlr,$SQLStat);
249 $a = sql_num_rows($rs);
250 if($a>0) {
251 $sqlw = sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id));
252 $rs = sql_query($sqlw,$SQLStat); }
253 if($a<1) {
254 $sqlw = sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"expires\") VALUES\n".
255 "('%s', '%s', %i)", array($id,$time,$data)); 
256 $rs = sql_query($sqlw,$SQLStat); } }
257 return true; }
258 function sqlsession_destroy($id) {
259 global $sqltable,$SQLStat;
260 $sqld = sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id));
261 sql_query($sqld,$SQLStat);
262 return true; }
263 function sqlsession_gc($maxlifetime) {
264 global $sqltable,$SQLStat;
265 $time = GMTimeStamp() - $maxlifetime;
266 //$sqlg = sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null));
267 $sqlg = sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time));
268 sql_query($sqlg,$SQLStat);
269 return true; }
270 session_set_save_handler("sqlsession_open", "sqlsession_close", "sqlsession_read", "sqlsession_write", "sqlsession_destroy", "sqlsession_gc");
271 if($cookieDomain==null) {
272 session_set_cookie_params(0, $cbasedir); }
273 if($cookieDomain!=null) {
274 if($cookieSecure===true) {
275 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
276 if($cookieSecure===false) {
277 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
278 session_cache_limiter("private, no-cache, must-revalidate");
279 header("Cache-Control: private, no-cache, must-revalidate");
280 header("Pragma: private, no-cache, must-revalidate");
281 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
282 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
283 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
284 session_name($Settings['sqltable']."sess");
285 session_start();
286 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
287 output_reset_rewrite_vars();
288 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
289         $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
290 if($_GET['act']=="bsd") {
291 header("Content-Type: text/plain; charset=".$Settings['charset']);
292 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
293 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
294 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
295 header("Content-Type: text/plain; charset=".$Settings['charset']);
296 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
297 if($_GET['act']=="js"||$_GET['act']=="javascript") {
298 header("Content-Script-Type: text/javascript");
299 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
300 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
301 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
302 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
303 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
304 require($SettDir['inc'].'javascript.php');
305 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
306 if($Settings['use_captcha']=="on") {
307 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
308         if($Settings['captcha_clean']=="on") { ob_clean(); }
309         require($SettDir['inc']."captcha.php");
310         $aFonts = array('inc/fonts/VeraBd.ttf', 'inc/fonts/VeraBI.ttf', 'inc/fonts/VeraIt.ttf', 'inc/fonts/Vera.ttf');
311         $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
312         $RNumSize = rand(7,17); $i=0; $RandNum = null;
313         while ($i <= $RNumSize) {
314         $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
315         $RandNum=strtoupper($RandNum);
316         $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
317         $oPhpCaptcha->UseColour(true);
318         $oPhpCaptcha->Create(); session_write_close(); die(); } }
319 if(!isset($_SESSION['CheckCookie'])) {
320 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
321 require($SettDir['inc'].'prelogin.php'); } }
322 require($SettDir['inc'].'groupsetup.php');
323 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
324 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
325 ob_clean(); if(!isset($Settings['offline_text'])) {
326 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
327 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; }
328 //echo "\n".sql_errorno($SQLStat);
329 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
330 $dayconv = array('second' => 1, 'minute' => 60, 'hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2630880, 'year' => 31570560, 'decade' => 15705600);
331 //Time Zone Set
332 if(!isset($_SESSION['UserTimeZone'])) { 
333         if(isset($Settings['DefaultTimeZone'])) { 
334         $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
335         if(!isset($Settings['DefaultTimeZone'])) { 
336         $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
337 $checktime = explode(":",$_SESSION['UserTimeZone']);
338 if(count($checktime)!=2) {
339         if(!isset($checktime[0])) { $checktime[0] = "0"; }
340         if(!isset($checktime[1])) { $checktime[1] = "00"; }
341         $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
342 if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
343 if($checktime[0]>12) { $checktime[0] = "12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
344 if($checktime[0]<-12) { $checktime[0] = "-12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
345 if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
346 if($checktime[1]>59) { $checktime[1] = "59"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
347 if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
348 $checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
349 if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
350 if($_SESSION['UserDST']==null) {
351 if($Settings['DefaultDST']=="off") { 
352         $_SESSION['UserDST'] = "off"; }
353 if($Settings['DefaultDST']=="on") { 
354         $_SESSION['UserDST'] = "on"; } }
355 // Guest Stuff
356 if(isset($_SESSION['MemberName'])||
357    isset($_COOKIE['MemberName'])) {
358         $_SESSION['GuestName'] = null;
359         $_COOKIE['GuestName'] = null; }
360 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
361 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
362         $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
363 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
364 // Skin Stuff
365 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
366 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
367 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
368 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
369 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
370 if(!isset($_GET['style'])) { $_GET['style'] = null; }
371 if(!isset($_POST['style'])) { $_POST['style'] = null; }
372 if(!isset($_GET['css'])) { $_GET['css'] = null; }
373 if(!isset($_POST['css'])) { $_POST['css'] = null; }
374 if($_GET['theme']==null) {
375         if($_POST['theme']!=null) {
376                 $_GET['theme'] = $_POST['theme']; }
377         if($_POST['skin']!=null) {
378                 $_GET['theme'] = $_POST['skin']; }
379         if($_POST['style']!=null) {
380                 $_GET['theme'] = $_POST['style']; }
381         if($_POST['css']!=null) {
382                 $_GET['theme'] = $_POST['css']; }
383         if($_GET['skin']!=null) {
384                 $_GET['theme'] = $_GET['skin']; }
385         if($_GET['style']!=null) {
386                 $_GET['theme'] = $_GET['style']; }
387         if($_GET['css']!=null) {
388                 $_GET['theme'] = $_GET['css']; } }
389 if($_GET['theme']!=null) {
390 $_GET['theme'] = chack_themes($_GET['theme']);
391 if($_GET['theme']=="../"||$_GET['theme']=="./") {
392 $_GET['theme']="iDB"; $_SESSION['Theme']="iDB"; }
393 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
394 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
395 $NewDay=GMTimeStamp();
396 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
397 sql_query($qnewskin,$SQLStat); }
398 /* The file Theme Exists */ }
399 else { $_GET['theme'] = $Settings['DefaultTheme']; 
400 $_SESSION['Theme'] = $Settings['DefaultTheme'];
401 /* The file Theme Dose Not Exists */ } }
402 if($_GET['theme']==null) { 
403 if($_SESSION['Theme']!=null) {
404 $OldTheme = $_SESSION['Theme'];
405 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
406 if($OldTheme!=$_SESSION['Theme']) { 
407 $NewDay=GMTimeStamp();
408 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
409 sql_query($qnewskin,$SQLStat); }
410 $_GET['theme']=$_SESSION['Theme']; }
411 if($_SESSION['Theme']==null) {
412 $_SESSION['Theme']=$Settings['DefaultTheme'];
413 $_GET['theme']=$Settings['DefaultTheme']; } }
414 $PreSkin['skindir1'] = $_SESSION['Theme'];
415 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
416 require($SettDir['themes'].$_GET['theme']."/settings.php");
417 $_SESSION['Theme'] = $_GET['theme'];
418 if(!isset($ThemeSet['TableStyle'])) {
419         $ThemeSet['TableStyle'] = "table"; }
420 if(isset($ThemeSet['TableStyle'])) {
421 if($ThemeSet['TableStyle']!="div"&&
422         $ThemeSet['TableStyle']!="table") {
423         $ThemeSet['TableStyle'] = "table"; } }
424 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
425 if($_SESSION['DBName']==null) {
426         $_SESSION['DBName'] = $Settings['sqldb']; }
427 if($_SESSION['DBName']!=null) {
428         if($_SESSION['DBName']!=$Settings['sqldb']) {
429 redirect("location",$basedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }
430 ?>