OSDN Git Service

Small bug fix to avatar table for opera. ^_^
[idb/iDB.git.git] / mysql.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-2007 Cool Dude 2k - http://intdb.sourceforge.net/
12     Copyright 2004-2007 Game Maker 2k - http://upload.idb.s1.jcink.com/
13
14     $FileInfo: mysql.php - Last Update: 10/05/2007 SVN 115 - Author: cooldude2k $
15 */
16 //@ini_set("display_errors", true); 
17 //@ini_set("display_startup_errors", true);
18 @error_reporting(E_ALL ^ E_NOTICE);
19 @ini_set('session.use_trans_sid', false);
20 @set_time_limit(30); @ignore_user_abort(true);
21 $File3Name = basename($_SERVER['SCRIPT_NAME']);
22 if ($File3Name=="mysql.php"||$File3Name=="/mysql.php") {
23         @header('Location: index.php');
24         exit(); }
25 if(@ini_get("register_globals")) { require('settings.php');
26 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
27         require_once($SettDir['misc'].'killglobals.php'); }
28 require('settings.php');
29 if($Settings['fixbasedir']==true) {
30 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
31 $PathsTest = parse_url($Settings['idburl']);
32 $Settings['fixbasedir'] = $PathsTest['path']."/"; 
33 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
34 if($Settings['fixcookiedir']==true) {
35 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
36 $PathsTest = parse_url($Settings['idburl']);
37 $Settings['fixcookiedir'] = $PathsTest['path']."/"; 
38 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
39 //@session_save_path($SettDir['inc']."temp/");
40 if(!isset($Settings['sqldb'])) { 
41 if(file_exists("install.php")) { @header('Location: install.php'); die(); } 
42 if(!file_exists("install.php")) { @header("Content-Type: text/plain; charset=UTF8");
43 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
44 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
45 @ini_set("error_prepend_string","<span style='color: ff0000;'>");
46 @ini_set("error_append_string","</span>");
47 if($Settings['fixpathinfo']==true) {
48         $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
49         @putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
50 // Check to see if variables are set
51 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
52 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
53 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
54 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
55 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
56 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
57 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = false; }
58 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
59 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { 
60         $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
61 if(!isset($_SERVER["HTTP_ACCEPT"])) { $_SERVER["HTTP_ACCEPT"] = null; }
62 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
63 if(!isset($_GET['page'])) { $_GET['page'] = null; }
64 if(!isset($_GET['act'])) { $_GET['act'] = null; }
65 if(!isset($_POST['act'])) { $_POST['act'] = null; }
66 if(!isset($_GET['id'])) { $_GET['id'] = null; }
67 if(!isset($_GET['debug'])) { $_GET['debug'] = false; }
68 if(!isset($_GET['post'])) { $_GET['post'] = null; }
69 if(!isset($_POST['License'])) { $_POST['License'] = null; }
70 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
71 require_once($SettDir['inc'].'filename.php');
72 require_once($SettDir['inc'].'function.php');
73 if($Settings['enable_pathinfo']==true) { 
74         mrstring(); /* Change Path info to Get Vars :P */ }
75 // Check to see if variables are set
76 require_once($SettDir['misc'].'setcheck.php');
77 if($Settings['enable_https']==true&&$_SERVER['HTTPS']=="on") {
78 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
79 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
80 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
81 $cookieDomain = null; $cookieSecure = false;
82 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
83 $URLsTest = parse_url($Settings['idburl']); 
84 $cookieDomain = $URLsTest['host'];
85 if($Settings['enable_https']==true) {
86  if($URLsTest['scheme']=="https") { $cookieSecure = true; }
87  if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
88 @ini_set("default_charset",$Settings['charset']);
89 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
90 $File2Name = $_SERVER['SCRIPT_NAME'];
91 $File3Name=str_replace($File1Name, null, $File2Name);
92 if ($File3Name=="mysql.php"||$File3Name=="/mysql.php") {
93         require($SettDir['inc'].'forbidden.php');
94         exit(); }
95 //error_reporting(E_ERROR);
96 // Check if gzip is on and if user's browser can accept gzip pages
97 if($Settings['use_gzip']=="on") {
98 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { 
99         $GZipEncode['Type'] = "gzip"; } else { 
100         if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { 
101         $GZipEncode['Type'] = "deflate"; } else { 
102                 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } }
103 if($Settings['use_gzip']=="gzip") {
104 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
105         $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
106 if($Settings['use_gzip']=="deflate") {
107 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
108         $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
109 if($Settings['clean_ob']==true) {
110 /* Check for other output handlers/buffers are open
111    and close and get the contents in an array */
112 $numob = count(ob_list_handlers()); $iob = 0; 
113 while ($iob < $numob) { 
114         $old_ob_var[$iob] = @ob_get_clean(); 
115         ++$iob; } } @ob_start();
116 if($Settings['use_gzip']=="on") { 
117 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
118         if($GZipEncode['Type']=="gzip") {
119         @header("Content-Encoding: gzip"); }
120         if($GZipEncode['Type']=="deflate") {
121         @header("Content-Encoding: deflate"); } }
122 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
123 @header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
124 // Some http stuff
125 if($cookieDomain==null) {
126 @session_set_cookie_params(0, $cbasedir); }
127 if($cookieDomain!=null) {
128 if($cookieSecure==true) {
129 @session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
130 if($cookieSecure==false) {
131 @session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
132 @session_cache_limiter("private, must-revalidate");
133 @header("Cache-Control: private, must-revalidate"); // IE 6 Fix
134 @header("Pragma: private, must-revalidate");
135 @header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
136 @header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
137 @header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
138 @session_name($Settings['sqltable']."sess");
139 @session_start();
140 //@header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
141 @output_reset_rewrite_vars();
142 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL") { $_GET['act']="bsd"; }
143 if($_GET['act']=="bsd"||$_GET['act']=="bsd") {
144 @header("Content-Type: text/plain; charset=".$Settings['charset']);
145 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
146 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
147 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
148 @header("Content-Type: text/plain; charset=".$Settings['charset']);
149 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
150 if($_GET['act']=="js"||$_GET['act']=="javascript") {
151 @header("Content-Script-Type: text/javascript");
152 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
153 @header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
154 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
155 @header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
156 @header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
157 require($SettDir['inc'].'javascript.php');
158 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
159 $SQLStat = @ConnectMysql($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
160 if($SQLStat==false) {
161 @header("Content-Type: text/plain; charset=".$Settings['charset']); @mysql_free_result($peresult);
162 ob_clean(); echo "Sorry could not connect to mysql database.\nContact the board admin about error. Error log berlow.";
163 echo "\n".mysql_errno().": ".mysql_error();
164 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
165 if(isset($_SESSION['CheckCookie'])) {
166 if($_SESSION['CheckCookie']!="done") {
167 if($_COOKIE['SessPass']!=null&&
168 $_COOKIE['MemberName']!=null) {
169 require($SettDir['inc'].'prelogin.php'); } } }
170 require($SettDir['inc'].'groupsetup.php');
171 if($Settings['board_offline']==true) {
172 @header("Content-Type: text/plain; charset=".$Settings['charset']); @mysql_free_result($peresult);
173 ob_clean(); echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp.";
174 echo "\n".mysql_errno().": ".mysql_error();
175 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); @mysql_close(); die(); }
176 $dayconv = array('second' => 1, 'minute' => 60, 'hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2630880, 'year' => 31570560, 'decade' => 15705600);
177 //Time Zone Set
178 if(!isset($_SESSION['UserTimeZone'])) { 
179         if(isset($Settings['DefaultTimeZone'])) { 
180         $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
181         if(!isset($Settings['DefaultTimeZone'])) { 
182         $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
183 $checktime = explode(":",$_SESSION['UserTimeZone']);
184 if(count($checktime)!=2) {
185         if(!isset($checktime[0])) { $checktime[0] = "0"; }
186         if(!isset($checktime[1])) { $checktime[1] = "00"; }
187         $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
188 if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
189 if($checktime[0]>12) { $checktime[0] = "12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
190 if($checktime[0]<-12) { $checktime[0] = "-12"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
191 if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
192 if($checktime[1]>59) { $checktime[1] = "59"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
193 if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
194 $checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
195 if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
196 if($_SESSION['UserDST']==null) {
197 if($Settings['DefaultDST']=="off") { 
198         $_SESSION['UserDST'] = "off"; }
199 if($Settings['DefaultDST']=="on") { 
200         $_SESSION['UserDST'] = "on"; } }
201 // Skin Stuff
202 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
203 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
204 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
205 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
206 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
207 if(!isset($_GET['style'])) { $_GET['style'] = null; }
208 if(!isset($_POST['style'])) { $_POST['style'] = null; }
209 if(!isset($_GET['css'])) { $_GET['css'] = null; }
210 if(!isset($_POST['css'])) { $_POST['css'] = null; }
211 if($_GET['theme']==null) {
212         if($_POST['theme']!=null) {
213                 $_GET['theme'] = $_POST['theme']; }
214         if($_POST['skin']!=null) {
215                 $_GET['theme'] = $_POST['skin']; }
216         if($_POST['style']!=null) {
217                 $_GET['theme'] = $_POST['style']; }
218         if($_POST['css']!=null) {
219                 $_GET['theme'] = $_POST['css']; }
220         if($_GET['skin']!=null) {
221                 $_GET['theme'] = $_GET['skin']; }
222         if($_GET['style']!=null) {
223                 $_GET['theme'] = $_GET['style']; }
224         if($_GET['css']!=null) {
225                 $_GET['theme'] = $_GET['css']; } }
226 if($_GET['theme']!=null) {
227 $_GET['theme']=preg_replace("/(.*?)\.\/(.*?)/", "iDB", $_GET['theme']);
228 if($_GET['theme']=="../"||$_GET['theme']=="./") {
229 $_GET['theme']="iDB"; $_SESSION['Theme']="iDB"; }
230 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
231 $_SESSION['Theme'] = $_GET['theme'];
232 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
233 $NewDay=GMTimeStamp();
234 $qnewskin = query("update `".$Settings['sqltable']."members` set `UseTheme`='%s',`LastActive`='%s' WHERE `id`=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
235 mysql_query($qnewskin); }
236 /* The file Theme Exists */ }
237 else { $_GET['theme'] = $Settings['DefaultTheme']; 
238 $_SESSION['Theme'] = $Settings['DefaultTheme'];
239 /* The file Theme Dose Not Exists */ } }
240 if($_GET['theme']==null) { 
241 if($_SESSION['Theme']!=null) {
242 $_GET['theme']=$_SESSION['Theme']; }
243 if($_SESSION['Theme']==null) {
244 $_SESSION['Theme']=$Settings['DefaultTheme'];
245 $_GET['theme']=$Settings['DefaultTheme']; } }
246 $PreSkin['skindir1'] = $_SESSION['Theme'];
247 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
248 require($SettDir['themes'].$_GET['theme']."/settings.php");
249 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
250 if($_SESSION['DBName']==null) {
251         $_SESSION['DBName'] = $Settings['sqldb']; }
252 if($_SESSION['DBName']!=null) {
253         if($_SESSION['DBName']!=$Settings['sqldb']) {
254 @redirect("location",$basedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }
255 ?>