OSDN Git Service

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