OSDN Git Service

Another small update to 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/21/2010 SVN 445 - 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"><xsl:value-of select="vname"/></span>
160       </div>
161       <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
162         <span style="font-style:italic">
163           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>
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 xml_doc_start("1.0",$Settings['charset']);
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']).'"?>'."\n"; ?>
175
176 <!DOCTYPE versioninfo [
177 <!ELEMENT versioninfo (version*)>
178 <!ELEMENT version (charset,title,name)>
179 <!ELEMENT charset (#PCDATA)>
180 <!ELEMENT title (#PCDATA)>
181 <!ELEMENT name (#PCDATA)>
182 <!ELEMENT vname (#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 <vname>iDB Version Checker</vname>
192 </version>
193
194 </versioninfo>
195 <?php die(); } }
196 if($Settings['vercheck']===1) {
197 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
198 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); die(); } }
199 if($Settings['enable_pathinfo']=="on") { 
200         mrstring(); /* Change Path info to Get Vars :P */ }
201 // Check to see if variables are set
202 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
203 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
204 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
205 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
206 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
207 $cookieDomain = null; $cookieSecure = false;
208 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
209 $URLsTest = parse_url($Settings['idburl']); 
210 $cookieDomain = $URLsTest['host'];
211 if($cookieDomain=="localhost") { $cookieDomain = false; }
212 if($Settings['enable_https']=="on") {
213  if($URLsTest['scheme']=="https") { $cookieSecure = true; }
214  if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
215 @ini_set("default_charset",$Settings['charset']);
216 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
217 $File2Name = $_SERVER['SCRIPT_NAME'];
218 $File3Name=str_replace($File1Name, null, $File2Name);
219 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
220         require($SettDir['inc'].'forbidden.php');
221         exit(); }
222 //error_reporting(E_ERROR);
223 // Check if gzip is on and if user's browser can accept gzip pages
224 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
225         $Settings['use_gzip'] = 'off'; }
226 if($Settings['use_gzip']=="on") {
227 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { 
228         $GZipEncode['Type'] = "gzip"; } else { 
229         if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { 
230         $GZipEncode['Type'] = "deflate"; } else { 
231                 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } }
232 if($Settings['use_gzip']=="gzip") {
233 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
234         $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
235 if($Settings['use_gzip']=="deflate") {
236 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
237         $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
238 if($Settings['clean_ob']=="on") {
239 /* Check for other output handlers/buffers are open
240    and close and get the contents in an array */
241 $numob = count(ob_list_handlers()); $iob = 0; 
242 while ($iob < $numob) { 
243         $old_ob_var[$iob] = ob_get_clean(); 
244         ++$iob; } } ob_start();
245 if($Settings['use_gzip']=="on") { 
246 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
247         if($GZipEncode['Type']=="gzip") {
248         header("Content-Encoding: gzip"); }
249         if($GZipEncode['Type']=="deflate") {
250         header("Content-Encoding: deflate"); } }
251 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
252 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
253 // Some http stuff
254 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
255 $SQLCollate = "latin1_general_ci";
256 $SQLCharset = "latin1"; 
257 if($Settings['charset']=="ISO-8859-1") {
258         $SQLCollate = "latin1_general_ci";
259         $SQLCharset = "latin1"; }
260 if($Settings['charset']=="ISO-8859-15") {
261         $SQLCollate = "latin1_general_ci";
262         $SQLCharset = "latin1"; }
263 if($Settings['charset']=="UTF-8") {
264         $SQLCollate = "utf8_unicode_ci";
265         $SQLCharset = "utf8"; }
266 sql_set_charset($SQLCharset,$SQLStat);
267 if($SQLStat===false) {
268 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
269 ob_clean(); echo "Sorry could not connect to mysql database.\nContact the board admin about error. Error log below.";
270 echo "\n".sql_errorno($SQLStat);
271 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
272 $sqltable = $Settings['sqltable'];
273 function sqlsession_open( $save_path, $session_name ) {
274 global $sess_save_path;
275 $sess_save_path = $save_path;
276 return true; }
277 function sqlsession_close() {
278 return true; }
279 function sqlsession_read($id) {
280 global $sqltable,$SQLStat,$SQLSType;
281 $data = "";
282 $time = GMTimeStamp();
283 $sqlr = sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id,$time));
284 $rs = sql_query($sqlr,$SQLStat);
285 $a = sql_num_rows($rs);
286 if($a > 0) {
287 $row = sql_fetch_assoc($rs);
288 $data = $row['session_data']; }
289 return $data; }
290 $SQLSType = $Settings['sqltype'];
291 function sqlsession_write($id,$data) {
292 global $sqltable,$SQLStat,$SQLSType;
293 $time = GMTimeStamp();
294 if($SQLSType=="mysql"||
295         $SQLSType=="mysqli") {
296 $sqlw = sql_pre_query("REPLACE \"".$sqltable."sessions\" VALUES('$id','$data', $time)", array($id,$data,$time));
297 $rs = sql_query($sqlw,$SQLStat); }
298 if($SQLSType=="pgsql"||
299         $SQLSType=="sqlite") {
300 $sqlr = sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id,$time));
301 $rs = sql_query($sqlr,$SQLStat);
302 $a = sql_num_rows($rs);
303 if($a>0) {
304 $sqlw = sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id));
305 $rs = sql_query($sqlw,$SQLStat); }
306 if($a<1) {
307 $sqlw = sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"expires\") VALUES\n".
308 "('%s', '%s', %i)", array($id,$time,$data)); 
309 $rs = sql_query($sqlw,$SQLStat); } }
310 return true; }
311 function sqlsession_destroy($id) {
312 global $sqltable,$SQLStat;
313 $sqld = sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id));
314 sql_query($sqld,$SQLStat);
315 return true; }
316 function sqlsession_gc($maxlifetime) {
317 global $sqltable,$SQLStat;
318 $time = GMTimeStamp() - $maxlifetime;
319 //$sqlg = sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null));
320 $sqlg = sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time));
321 sql_query($sqlg,$SQLStat);
322 return true; }
323 session_set_save_handler("sqlsession_open", "sqlsession_close", "sqlsession_read", "sqlsession_write", "sqlsession_destroy", "sqlsession_gc");
324 if($cookieDomain==null) {
325 session_set_cookie_params(0, $cbasedir); }
326 if($cookieDomain!=null) {
327 if($cookieSecure===true) {
328 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
329 if($cookieSecure===false) {
330 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
331 session_cache_limiter("private, no-cache, must-revalidate");
332 header("Cache-Control: private, no-cache, must-revalidate");
333 header("Pragma: private, no-cache, must-revalidate");
334 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
335 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
336 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
337 session_name($Settings['sqltable']."sess");
338 session_start();
339 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
340 output_reset_rewrite_vars();
341 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
342         $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
343 if($_GET['act']=="bsd") {
344 header("Content-Type: text/plain; charset=".$Settings['charset']);
345 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
346 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
347 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
348 header("Content-Type: text/plain; charset=".$Settings['charset']);
349 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
350 if($_GET['act']=="js"||$_GET['act']=="javascript") {
351 header("Content-Script-Type: text/javascript");
352 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
353 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
354 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
355 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
356 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
357 require($SettDir['inc'].'javascript.php');
358 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
359 if($Settings['use_captcha']=="on") {
360 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
361         if($Settings['captcha_clean']=="on") { ob_clean(); }
362         require($SettDir['inc']."captcha.php");
363         $aFonts = array('inc/fonts/VeraBd.ttf', 'inc/fonts/VeraBI.ttf', 'inc/fonts/VeraIt.ttf', 'inc/fonts/Vera.ttf');
364         $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
365         $RNumSize = rand(7,17); $i=0; $RandNum = null;
366         while ($i <= $RNumSize) {
367         $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
368         $RandNum=strtoupper($RandNum);
369         $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
370         $oPhpCaptcha->UseColour(true);
371         $oPhpCaptcha->Create(); session_write_close(); die(); } }
372 if(!isset($_SESSION['CheckCookie'])) {
373 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
374 require($SettDir['inc'].'prelogin.php'); } }
375 require($SettDir['inc'].'groupsetup.php');
376 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
377 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
378 ob_clean(); if(!isset($Settings['offline_text'])) {
379 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
380 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; }
381 //echo "\n".sql_errorno($SQLStat);
382 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
383 $dayconv = array('second' => 1, 'minute' => 60, 'hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2630880, 'year' => 31570560, 'decade' => 15705600);
384 //Time Zone Set
385 if(!isset($_SESSION['UserTimeZone'])) { 
386         if(isset($Settings['DefaultTimeZone'])) { 
387         $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
388         if(!isset($Settings['DefaultTimeZone'])) { 
389         $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
390 $checktime = explode(":",$_SESSION['UserTimeZone']);
391 if(count($checktime)!=2) {
392         if(!isset($checktime[0])) { $checktime[0] = "0"; }
393         if(!isset($checktime[1])) { $checktime[1] = "00"; }
394         $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
395 if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
396 if($checktime[0]>12) { $checktime[0] = "12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
397 if($checktime[0]<-12) { $checktime[0] = "-12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
398 if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
399 if($checktime[1]>59) { $checktime[1] = "59"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
400 if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
401 $checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
402 if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
403 if($_SESSION['UserDST']==null) {
404 if($Settings['DefaultDST']=="off") { 
405         $_SESSION['UserDST'] = "off"; }
406 if($Settings['DefaultDST']=="on") { 
407         $_SESSION['UserDST'] = "on"; } }
408 // Guest Stuff
409 if(isset($_SESSION['MemberName'])||
410    isset($_COOKIE['MemberName'])) {
411         $_SESSION['GuestName'] = null;
412         $_COOKIE['GuestName'] = null; }
413 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
414 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
415         $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
416 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
417 // Skin Stuff
418 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
419 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
420 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
421 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
422 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
423 if(!isset($_GET['style'])) { $_GET['style'] = null; }
424 if(!isset($_POST['style'])) { $_POST['style'] = null; }
425 if(!isset($_GET['css'])) { $_GET['css'] = null; }
426 if(!isset($_POST['css'])) { $_POST['css'] = null; }
427 if($_GET['theme']==null) {
428         if($_POST['theme']!=null) {
429                 $_GET['theme'] = $_POST['theme']; }
430         if($_POST['skin']!=null) {
431                 $_GET['theme'] = $_POST['skin']; }
432         if($_POST['style']!=null) {
433                 $_GET['theme'] = $_POST['style']; }
434         if($_POST['css']!=null) {
435                 $_GET['theme'] = $_POST['css']; }
436         if($_GET['skin']!=null) {
437                 $_GET['theme'] = $_GET['skin']; }
438         if($_GET['style']!=null) {
439                 $_GET['theme'] = $_GET['style']; }
440         if($_GET['css']!=null) {
441                 $_GET['theme'] = $_GET['css']; } }
442 if($_GET['theme']!=null) {
443 $_GET['theme'] = chack_themes($_GET['theme']);
444 if($_GET['theme']=="../"||$_GET['theme']=="./") {
445 $_GET['theme']="iDB"; $_SESSION['Theme']="iDB"; }
446 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
447 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
448 $NewDay=GMTimeStamp();
449 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
450 sql_query($qnewskin,$SQLStat); }
451 /* The file Theme Exists */ }
452 else { $_GET['theme'] = $Settings['DefaultTheme']; 
453 $_SESSION['Theme'] = $Settings['DefaultTheme'];
454 /* The file Theme Dose Not Exists */ } }
455 if($_GET['theme']==null) { 
456 if($_SESSION['Theme']!=null) {
457 $OldTheme = $_SESSION['Theme'];
458 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
459 if($OldTheme!=$_SESSION['Theme']) { 
460 $NewDay=GMTimeStamp();
461 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
462 sql_query($qnewskin,$SQLStat); }
463 $_GET['theme']=$_SESSION['Theme']; }
464 if($_SESSION['Theme']==null) {
465 $_SESSION['Theme']=$Settings['DefaultTheme'];
466 $_GET['theme']=$Settings['DefaultTheme']; } }
467 $PreSkin['skindir1'] = $_SESSION['Theme'];
468 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
469 require($SettDir['themes'].$_GET['theme']."/settings.php");
470 $_SESSION['Theme'] = $_GET['theme'];
471 if(!isset($ThemeSet['TableStyle'])) {
472         $ThemeSet['TableStyle'] = "table"; }
473 if(isset($ThemeSet['TableStyle'])) {
474 if($ThemeSet['TableStyle']!="div"&&
475         $ThemeSet['TableStyle']!="table") {
476         $ThemeSet['TableStyle'] = "table"; } }
477 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
478 if($_SESSION['DBName']==null) {
479         $_SESSION['DBName'] = $Settings['sqldb']; }
480 if($_SESSION['DBName']!=null) {
481         if($_SESSION['DBName']!=$Settings['sqldb']) {
482 redirect("location",$basedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }
483 ?>