OSDN Git Service

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