OSDN Git Service

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