OSDN Git Service

Another big update to iDB.
[idb/iDB.git.git] / inc / groupsetup.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-2015 iDB Support - http://idb.berlios.de/
12     Copyright 2004-2015 Game Maker 2k - http://gamemaker2k.org/
13
14     $FileInfo: groupsetup.php - Last Update: 08/18/2015 SVN 797 - Author: cooldude2k $
15 */
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="groupsetup.php"||$File3Name=="/groupsetup.php") {
18         require('index.php');
19         exit(); }
20 //Set members temp location
21 $_SESSION['ViewingPage'] = url_maker(null,"no+ext","act=view","&","=",$prexqstr['index'],$exqstr['index']);
22 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
23 $_SESSION['ViewingFile'] = $exfile['index'].$Settings['file_ext']; }
24 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
25 $_SESSION['ViewingFile'] = $exfile['index']; }
26 $_SESSION['PreViewingTitle'] = "Viewing";
27 $_SESSION['ViewingTitle'] = "Board index";
28 $_SESSION['ExtraData'] = "currentact:view; currentcategoryid:0; currentforumid:0; currenttopicid:0; currentmessageid:0; currenteventid:0; currentmemberid:0;";
29 /*$ggidquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"Name\"='%s' LIMIT 1", array($Settings['GuestGroup']));
30 $ggidresult=sql_query($ggidquery,$SQLStat);
31 $Settings['GuestGroupID']=sql_result($ggidresult,0,"id");*/
32 // Check to make sure MemberInfo is right
33 $MyPostCountChk = null; $MyKarmaCount = null;
34 if(!isset($_SESSION['UserID'])) { $_SESSION['UserID'] = 0; }
35 if($_SESSION['UserID']!=0&&$_SESSION['UserID']!=null) { $BanError = null;
36 $kgbquerychkusr = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."members\" WHERE \"Name\"='%s' AND \"UserPassword\"='%s' AND \"id\"=%i LIMIT 1", array($_SESSION['MemberName'],$_SESSION['UserPass'],$_SESSION['UserID'])); 
37 $resultchkusr=sql_query($kgbquerychkusr,$SQLStat);
38 $numchkusr=sql_num_rows($resultchkusr);
39 if($numchkusr==1) {
40 $ChkUsrID=sql_result($resultchkusr,0,"id");
41 $ChkUsrName=sql_result($resultchkusr,0,"Name");
42 $ChkUsrGroup=sql_result($resultchkusr,0,"GroupID");
43 $ChkUsrGroupID=$ChkUsrGroup;
44 $ChkUsrLevel=sql_result($resultchkusr,0,"LevelID");
45 $ChkUsrLevelID=$ChkUsrLevel;
46 $ChkUsrPass=sql_result($resultchkusr,0,"UserPassword");
47 $ChkUsrTimeZone=sql_result($resultchkusr,0,"TimeZone");
48 $ChkUsrDateFormat=sql_result($resultchkusr,0,"DateFormat");
49 $ChkUsrTimeFormat=sql_result($resultchkusr,0,"TimeFormat");
50 $ChkUsrTheme=sql_result($resultchkusr,0,"UseTheme");
51 $ChkUsrLastPostTime=sql_result($resultchkusr,0,"LastPostTime");
52 $MyPostCountChk=sql_result($resultchkusr,0,"PostCount");
53 $MyKarmaCount=sql_result($resultchkusr,0,"Karma");
54 $MyKarmaUpdate=sql_result($resultchkusr,0,"KarmaUpdate");
55 $MyRepliesPerPage=sql_result($resultchkusr,0,"RepliesPerPage");
56 $Settings['max_posts'] = $MyRepliesPerPage;
57 $MyTopicsPerPage=sql_result($resultchkusr,0,"TopicsPerPage");
58 $Settings['max_topics'] = $MyTopicsPerPage;
59 $MyMessagesPerPage=sql_result($resultchkusr,0,"MessagesPerPage");
60 $Settings['max_memlist'] = $MyMessagesPerPage;
61 $Settings['max_pmlist'] = $MyMessagesPerPage;
62 $svrquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"id\"=%i LIMIT 1", array($ChkUsrGroup));
63 $svrgresultkgb=sql_query($svrquery,$SQLStat);
64 $ChkUsrGroup=sql_result($svrgresultkgb,0,"Name"); 
65 $ChkUsrBanTime=sql_result($resultchkusr,0,"BanTime");
66 $ChkUsrGMTime = $utccurtime->getTimestamp();
67 if($ChkUsrBanTime!=0&&$ChkUsrBanTime!=null) {
68 if($ChkUsrBanTime>=$ChkUsrGMTime) { $BanError = "yes"; }
69 if($ChkUsrBanTime<0) { $BanError = "yes"; } }
70 if($BanError!="yes") {
71 $_SESSION['Theme']=$ChkUsrTheme;
72 $_SESSION['MemberName']=$ChkUsrName;
73 $_SESSION['UserID']=$ChkUsrID;
74 $_SESSION['UserIP']=$_SERVER['REMOTE_ADDR'];
75 $_SESSION['UserTimeZone']=$ChkUsrTimeZone;
76 $usertz = new DateTimeZone($_SESSION['UserTimeZone']);
77 $usercurtime->setTimestamp($defcurtime->getTimestamp());
78 $usercurtime->setTimezone($usertz);
79 $_SESSION['iDBDateFormat']=$ChkUsrDateFormat;
80 $_SESSION['iDBTimeFormat']=$ChkUsrTimeFormat;
81 $_SESSION['UserGroup']=$ChkUsrGroup;
82 $_SESSION['UserGroupID']=$ChkUsrGroupID;
83 $_SESSION['UserPass']=$ChkUsrPass;
84 $_SESSION['LastPostTime'] = $ChkUsrLastPostTime; } }
85 if($numchkusr<=0||$numchkusr>1||$BanError=="yes") { session_unset();
86 if($cookieDomain==null) {
87 setcookie("MemberName", null, $utccurtime->getTimestamp() - 3600, $cbasedir);
88 setcookie("UserID", null, $utccurtime->getTimestamp() - 3600, $cbasedir);
89 setcookie("SessPass", null, $utccurtime->getTimestamp() - 3600, $cbasedir);
90 setcookie(session_name(), "", $utccurtime->getTimestamp() - 3600, $cbasedir); }
91 if($cookieDomain!=null) {
92 if($cookieSecure===true) {
93 setcookie("MemberName", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain, 1);
94 setcookie("UserID", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain, 1);
95 setcookie("SessPass", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain, 1);
96 setcookie(session_name(), "", $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain, 1); }
97 if($cookieSecure===false) {
98 setcookie("MemberName", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain);
99 setcookie("UserID", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain);
100 setcookie("SessPass", null, $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain);
101 setcookie(session_name(), "", $utccurtime->getTimestamp() - 3600, $cbasedir, $cookieDomain); } }
102 unset($_COOKIE[session_name()]);
103 $_SESSION = array(); session_unset(); session_destroy();
104 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=login",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); sql_free_result($resultchkusr); sql_free_result($svrgresultkgb);
105 ob_clean(); header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 302;
106 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
107 sql_free_result($resultchkusr); sql_free_result($svrgresultkgb); }
108 if($_SESSION['UserID']==0||$_SESSION['UserID']==null) {
109 $_SESSION['UserIP']=$_SERVER['REMOTE_ADDR'];
110 $_SESSION['MemberName'] = null;
111 $_SESSION['UserGroup'] = $Settings['GuestGroup']; 
112 $gidquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"Name\"='%s' LIMIT 1", array($Settings['GuestGroup']));
113 $gidresult=sql_query($gidquery,$SQLStat);
114 $_SESSION['UserGroupID']=sql_result($gidresult,0,"id"); 
115 sql_free_result($gidresult); }
116 if($_SESSION['MemberName']==null) { $_SESSION['UserID'] = "0";
117 $_SESSION['UserIP']=$_SERVER['REMOTE_ADDR'];
118 $_SESSION['UserGroup'] = $Settings['GuestGroup']; 
119 $gidquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"Name\"='%s' LIMIT 1", array($Settings['GuestGroup']));
120 $gidresult=sql_query($gidquery,$SQLStat);
121 $_SESSION['UserGroupID']=sql_result($gidresult,0,"id"); 
122 sql_free_result($gidresult); }
123 if($_SESSION['UserID']!=0&&$_SESSION['UserID']!=null) {
124 $levquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."levels\" WHERE \"id\"=%i LIMIT 1", array($ChkUsrLevelID));
125 $levresult=sql_query($levquery,$SQLStat);
126 $levnum=sql_num_rows($levresult);
127 if($levnum<=0) { $GruError = true; sql_free_result($levresult);
128 header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 503;
129 ob_clean(); echo "Sorry could not find level data in database.\nContact the board admin about error."; 
130 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
131 if($levnum>=1) {
132 $LevelInfo['ID']=sql_result($levresult,0,"id");
133 if(!is_numeric($LevelInfo['ID'])) { $GruError = true; }
134 $LevelInfo['Name']=sql_result($levresult,0,"Name");
135 $LevelInfo['PromoteTo']=sql_result($levresult,0,"PromoteTo");
136 $LevelInfo['PromotePosts']=sql_result($levresult,0,"PromotePosts");
137 if(!is_numeric($LevelInfo['PromotePosts'])) { 
138         $LevelInfo['PromotePosts'] = 0; $LevelInfo['PromoteTo'] = 0; }
139 $LevelInfo['PromoteKarma']=sql_result($levresult,0,"PromoteKarma");
140 if(!is_numeric($LevelInfo['PromoteKarma'])) { 
141         $LevelInfo['PromoteKarma'] = 0; $LevelInfo['PromoteTo'] = 0; } }
142 // Member Group Setup
143 if(!isset($_SESSION['UserGroup'])) { $_SESSION['UserGroup'] = null; }
144 if($_SESSION['UserGroup']==null) { 
145 $_SESSION['UserGroup']=$Settings['GuestGroup']; } $GruError = null;
146 $gruquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"Name\"='%s' LIMIT 1", array($_SESSION['UserGroup']));
147 $gruresult=sql_query($gruquery,$SQLStat);
148 $grunum=sql_num_rows($gruresult);
149 if($grunum<=0) { $GruError = true; sql_free_result($gruresult);
150 header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 503;
151 ob_clean(); echo "Sorry could not find group data in database.\nContact the board admin about error."; 
152 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
153 if($_SESSION['UserID']!=0) {
154 $memprequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."mempermissions\" WHERE \"id\"=%i LIMIT 1", array($_SESSION['UserID'])); }
155 if($_SESSION['UserID']==0) {
156 $memprequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."mempermissions\" WHERE \"id\"=%i LIMIT 1", array(-1)); }
157 $mempreresult=sql_query($memprequery,$SQLStat);
158 $memprenum=sql_num_rows($mempreresult);
159 if($grunum>=1) {
160 $GroupInfo['ID']=sql_result($gruresult,0,"id");
161 if(!is_numeric($GroupInfo['ID'])) { $GruError = true; }
162 $GroupInfo['Name']=sql_result($gruresult,0,"Name");
163 $GroupInfo['PermissionID']=sql_result($mempreresult,0,"PermissionID");
164 if(!is_numeric($GroupInfo['PermissionID'])||$GroupInfo['PermissionID']=="0") {
165 $GroupInfo['PermissionID']=sql_result($gruresult,0,"PermissionID");
166 if(!is_numeric($GroupInfo['PermissionID'])) { $GruError = true; } }
167 $GroupInfo['NamePrefix']=sql_result($gruresult,0,"NamePrefix");
168 $GroupInfo['NameSuffix']=sql_result($gruresult,0,"NameSuffix");
169 $GroupInfo['CanViewBoard']=sql_result($mempreresult,0,"CanViewBoard");
170 if($GroupInfo['CanViewBoard']!="yes"&&$GroupInfo['CanViewBoard']!="no"&&$GroupInfo['CanViewBoard']!="group") {
171                 $GruError = true; }
172 if($GroupInfo['CanViewBoard']=="group") {
173 $GroupInfo['CanViewBoard']=sql_result($gruresult,0,"CanViewBoard");
174 if($GroupInfo['CanViewBoard']!="yes"&&$GroupInfo['CanViewBoard']!="no") {
175                 $GruError = true; } }
176 $GroupInfo['CanViewOffLine']=sql_result($mempreresult,0,"CanViewOffLine");
177 if($GroupInfo['CanViewOffLine']!="yes"&&$GroupInfo['CanViewOffLine']!="no"&&$GroupInfo['CanViewOffLine']!="group") {
178                 $GruError = true; }
179 if($GroupInfo['CanViewOffLine']=="group") {
180 $GroupInfo['CanViewOffLine']=sql_result($gruresult,0,"CanViewOffLine");
181 if($GroupInfo['CanViewOffLine']!="yes"&&$GroupInfo['CanViewOffLine']!="no") {
182                 $GruError = true; } }
183 $GroupInfo['FloodControl']=sql_result($mempreresult,0,"FloodControl");
184 if(!is_numeric($GroupInfo['FloodControl'])) { $GroupInfo['FloodControl'] = 30; }
185 if($GroupInfo['FloodControl']==-1) {
186 $GroupInfo['FloodControl']=sql_result($gruresult,0,"FloodControl");
187 if(!is_numeric($GroupInfo['FloodControl'])) { $GroupInfo['FloodControl'] = 30; } }
188 $GroupInfo['SearchFlood']=sql_result($mempreresult,0,"SearchFlood");
189 if(!is_numeric($GroupInfo['SearchFlood'])) { $GroupInfo['SearchFlood'] = 30; }
190 if($GroupInfo['SearchFlood']==-1) {
191 $GroupInfo['SearchFlood']=sql_result($gruresult,0,"SearchFlood");
192 if(!is_numeric($GroupInfo['SearchFlood'])) { $GroupInfo['SearchFlood'] = 30; } }
193 $GroupInfo['CanEditProfile']=sql_result($mempreresult,0,"CanEditProfile");
194 if($GroupInfo['CanEditProfile']!="yes"&&$GroupInfo['CanEditProfile']!="no"&&$GroupInfo['CanEditProfile']!="group") {
195                 $GruError = true; }
196 if($GroupInfo['CanEditProfile']=="group") {
197 $GroupInfo['CanEditProfile']=sql_result($gruresult,0,"CanEditProfile");
198 if($GroupInfo['CanEditProfile']!="yes"&&$GroupInfo['CanEditProfile']!="no") {
199                 $GruError = true; } }
200 $GroupInfo['CanAddEvents']=sql_result($mempreresult,0,"CanAddEvents");
201 if($GroupInfo['CanAddEvents']!="yes"&&$GroupInfo['CanAddEvents']!="no"&&$GroupInfo['CanAddEvents']!="group") {
202                 $GruError = true; }
203 if($GroupInfo['CanAddEvents']=="group") {
204 $GroupInfo['CanAddEvents']=sql_result($gruresult,0,"CanAddEvents");
205 if($GroupInfo['CanAddEvents']!="yes"&&$GroupInfo['CanAddEvents']!="no") {
206                 $GruError = true; } }
207 $GroupInfo['CanPM']=sql_result($mempreresult,0,"CanPM");
208 if($GroupInfo['CanPM']!="yes"&&$GroupInfo['CanPM']!="no"&&$GroupInfo['CanPM']!="group") {
209                 $GruError = true; }
210 if($GroupInfo['CanPM']=="group") {
211 $GroupInfo['CanPM']=sql_result($gruresult,0,"CanPM");
212 if($GroupInfo['CanPM']!="yes"&&$GroupInfo['CanPM']!="no") {
213                 $GruError = true; } }
214 $GroupInfo['CanSearch']=sql_result($mempreresult,0,"CanSearch");
215 if($GroupInfo['CanSearch']!="yes"&&$GroupInfo['CanSearch']!="no"&&$GroupInfo['CanSearch']!="group") {
216                 $GruError = true; }
217 if($GroupInfo['CanSearch']=="group") {
218 $GroupInfo['CanSearch']=sql_result($gruresult,0,"CanSearch");
219 if($GroupInfo['CanSearch']!="yes"&&$GroupInfo['CanSearch']!="no") {
220                 $GruError = true; } }
221 $GroupInfo['CanExecPHP']=sql_result($mempreresult,0,"CanExecPHP");
222 if($GroupInfo['CanExecPHP']!="yes"&&$GroupInfo['CanExecPHP']!="no"&&$GroupInfo['CanExecPHP']!="group") {
223         $GroupInfo['CanExecPHP'] = "no"; }
224 if($GroupInfo['CanExecPHP']=="group") {
225 $GroupInfo['CanExecPHP']=sql_result($gruresult,0,"CanExecPHP");
226 if($GroupInfo['CanExecPHP']!="yes"&&$GroupInfo['CanExecPHP']!="no") {
227         $GroupInfo['CanExecPHP'] = "no"; } }
228 $GroupInfo['CanDoHTML']=sql_result($mempreresult,0,"CanDoHTML");
229 if($GroupInfo['CanDoHTML']!="yes"&&$GroupInfo['CanDoHTML']!="no"&&$GroupInfo['CanDoHTML']!="group") {
230         $GroupInfo['CanDoHTML'] = "no"; }
231 if($GroupInfo['CanDoHTML']=="group") {
232 $GroupInfo['CanDoHTML']=sql_result($gruresult,0,"CanDoHTML");
233 if($GroupInfo['CanDoHTML']!="yes"&&$GroupInfo['CanDoHTML']!="no") {
234         $GroupInfo['CanDoHTML'] = "no"; } }
235 $GroupInfo['CanUseBBags']=sql_result($mempreresult,0,"CanUseBBags");
236 if($GroupInfo['CanUseBBags']!="yes"&&$GroupInfo['CanUseBBags']!="no"&&$GroupInfo['CanUseBBags']!="group") {
237         $GroupInfo['CanUseBBags'] = "no"; }
238 if($GroupInfo['CanUseBBags']=="group") {
239 $GroupInfo['CanUseBBags']=sql_result($gruresult,0,"CanUseBBags");
240 if($GroupInfo['CanUseBBags']!="yes"&&$GroupInfo['CanUseBBags']!="no") {
241         $GroupInfo['CanUseBBags'] = "no"; } }
242 $GroupInfo['PromoteTo']=sql_result($gruresult,0,"PromoteTo");
243 $GroupInfo['PromotePosts']=sql_result($gruresult,0,"PromotePosts");
244 if(!is_numeric($GroupInfo['PromotePosts'])) { 
245         $GroupInfo['PromotePosts'] = 0; $GroupInfo['PromoteTo'] = 0; }
246 $GroupInfo['PromoteKarma']=sql_result($gruresult,0,"PromoteKarma");
247 if(!is_numeric($GroupInfo['PromoteKarma'])) { 
248         $GroupInfo['PromoteKarma'] = 0; $GroupInfo['PromoteTo'] = 0; }
249 if(!isset($Settings['KarmaBoostDays'])) {
250         $Settings['KarmaBoostDays'] = null; }
251 $Settings['OldKarmaBoostDays'] = $Settings['KarmaBoostDays'];
252 if(!isset($Settings['KBoostPercent'])) {
253         $Settings['KBoostPercent'] = "6|10"; }
254 //Update karma and group upgrade on post count or karma count.
255 if($_SESSION['UserID']!=0) { $BoostTotal = null;
256 $KarmaExp = explode("&",$Settings['KarmaBoostDays']);
257 $KarmaNow = $usercurtime->format("md");
258 $kupdate = false;
259 if(in_array($KarmaNow,$KarmaExp)) {
260 $KarmaNum = count($KarmaExp); 
261 $Karmai = 0;
262 while ($Karmai < $KarmaNum) {
263 if($KarmaExp[$Karmai]==$KarmaNow) { 
264 $Settings['KarmaBoostDays'] = $KarmaExp[$Karmai]; 
265 $kupdate = true; break 1; }
266 ++$Karmai; } }
267 if($kupdate===false) {
268 $Settings['KarmaBoostDays'] = $KarmaExp[0]; }
269 $NewKarmaUpdate = $usercurtime->format("Ymd");
270 $ThisYearUpdate = $usercurtime->format("Y");
271 if($MyKarmaUpdate<$NewKarmaUpdate&&$MyPostCountChk>0) { 
272         $KarmaBoostDay = $Settings['KarmaBoostDays'];
273         $KBoostPercent = explode("|",$Settings['KBoostPercent']);
274         if(count($KBoostPercent)<1) { 
275         $KBoostPercent[0] = rand(1,4); }
276         if(!is_numeric($KBoostPercent[0])) {
277         $KBoostPercent[0] = 6; }
278         if(count($KBoostPercent)==1) { 
279         $KBoostPercent[1] = $KBoostPercent[0] + rand(3,6); }
280         if(!is_numeric($KBoostPercent[1])) {
281         $KBoostPercent[0] = 10; }
282         $KBoostPercent = rand($KBoostPercent[0],$KBoostPercent[1]);
283         if($ThisYearUpdate.$KarmaBoostDay==$NewKarmaUpdate&&
284         is_numeric($KarmaBoostDay)) {
285         $KBoostPercent = $KBoostPercent / 100;
286         $BoostTotal = $MyKarmaCount * $KBoostPercent;
287         $BoostTotal = round($BoostTotal,0); }
288         if($BoostTotal!=null) {
289         $MyKarmaCount = $MyKarmaCount + $BoostTotal; }
290         if($BoostTotal==null) {
291         $MyKarmaCount = $MyKarmaCount + 1; }
292         $querykarmaup = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"Karma\"=%i,\"KarmaUpdate\"=%i WHERE \"id\"=%i", array($MyKarmaCount,$NewKarmaUpdate,$_SESSION['UserID']));
293         sql_query($querykarmaup,$SQLStat); }
294         $Settings['KarmaBoostDays'] = $Settings['OldKarmaBoostDays'];
295 if($LevelInfo['PromoteTo']!=0&&$MyPostCountChk>=$LevelInfo['PromotePosts']) {
296         $sql_level_check = sql_query(sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."levels\" WHERE \"id\"=%i LIMIT 1", array($LevelInfo['PromoteTo'])),$SQLStat);
297         $level_check = sql_num_rows($sql_level_check);
298         sql_free_result($sql_level_check);
299         if($level_check > 0) {
300         $queryupgrade = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"LevelID\"=%i WHERE \"id\"=%i", array($LevelInfo['PromoteTo'],$_SESSION['UserID']));
301         sql_query($queryupgrade,$SQLStat); } }
302 if($LevelInfo['PromotePosts']==0&&$LevelInfo['PromoteTo']!=0&&$MyKarmaCount>=$LevelInfo['PromoteKarma']) {
303         $sql_level_check = sql_query(sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."levels\" WHERE \"id\"=%i LIMIT 1", array($LevelInfo['PromoteTo'])),$SQLStat);
304         $level_check = sql_num_rows($sql_level_check);
305         sql_free_result($sql_level_check);
306         if($level_check > 0) {
307         $queryupgrade = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"LevelID\"=%i WHERE \"id\"=%i", array($LevelInfo['PromoteTo'],$_SESSION['UserID']));
308         sql_query($queryupgrade,$SQLStat); } }
309 if($GroupInfo['PromoteTo']!=0&&$MyPostCountChk>=$GroupInfo['PromotePosts']) {
310         $sql_group_check = sql_query(sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"id\"=%i LIMIT 1", array($GroupInfo['PromoteTo'])),$SQLStat);
311         $group_check = sql_num_rows($sql_group_check);
312         sql_free_result($sql_group_check);
313         if($group_check > 0) {
314         $queryupgrade = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"GroupID\"=%i WHERE \"id\"=%i", array($GroupInfo['PromoteTo'],$_SESSION['UserID']));
315         sql_query($queryupgrade,$SQLStat); } }
316 if($GroupInfo['PromotePosts']==0&&$GroupInfo['PromoteTo']!=0&&$MyKarmaCount>=$GroupInfo['PromoteKarma']) {
317         $sql_group_check = sql_query(sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."groups\" WHERE \"id\"=%i LIMIT 1", array($GroupInfo['PromoteTo'])),$SQLStat);
318         $group_check = sql_num_rows($sql_group_check);
319         sql_free_result($sql_group_check);
320         if($group_check > 0) {
321         $queryupgrade = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"GroupID\"=%i WHERE \"id\"=%i", array($GroupInfo['PromoteTo'],$_SESSION['UserID']));
322         sql_query($queryupgrade,$SQLStat); } } }
323 $GroupInfo['HasModCP']=sql_result($mempreresult,0,"HasModCP");
324 if($GroupInfo['HasModCP']!="yes"&&$GroupInfo['HasModCP']!="no"&&$GroupInfo['HasModCP']!="group") {
325         $GroupInfo['HasModCP'] = "no"; }
326 if($GroupInfo['HasModCP']=="group") {
327 $GroupInfo['HasModCP']=sql_result($gruresult,0,"HasModCP");
328 if($GroupInfo['HasModCP']!="yes"&&$GroupInfo['HasModCP']!="no") {
329         $GroupInfo['HasModCP'] = "no"; } }
330 $GroupInfo['HasAdminCP']=sql_result($mempreresult,0,"HasAdminCP");
331 if($GroupInfo['HasAdminCP']!="yes"&&$GroupInfo['HasAdminCP']!="no"&&$GroupInfo['HasAdminCP']!="group") {
332         $GroupInfo['HasAdminCP'] = "no"; }
333 if($GroupInfo['HasAdminCP']=="group") {
334 $GroupInfo['HasAdminCP']=sql_result($gruresult,0,"HasAdminCP");
335 if($GroupInfo['HasAdminCP']!="yes"&&$GroupInfo['HasAdminCP']!="no") {
336         $GroupInfo['HasAdminCP'] = "no"; } }
337 $GroupInfo['CanViewIPAddress']=sql_result($mempreresult,0,"CanViewIPAddress");
338 if($GroupInfo['CanViewIPAddress']!="yes"&&$GroupInfo['CanViewIPAddress']!="no"&&$GroupInfo['CanViewIPAddress']!="group") {
339         $GroupInfo['CanViewIPAddress'] = "no"; }
340 if($GroupInfo['CanViewIPAddress']=="group") {
341 $GroupInfo['CanViewIPAddress']=sql_result($gruresult,0,"CanViewIPAddress");
342 if($GroupInfo['CanViewIPAddress']!="yes"&&$GroupInfo['CanViewIPAddress']!="no") {
343         $GroupInfo['CanViewIPAddress'] = "no"; } }
344 $GroupInfo['CanViewUserAgent']=sql_result($mempreresult,0,"CanViewUserAgent");
345 if($GroupInfo['CanViewUserAgent']!="yes"&&$GroupInfo['CanViewUserAgent']!="no"&&$GroupInfo['CanViewUserAgent']!="group") {
346         $GroupInfo['CanViewUserAgent'] = "no"; }
347 if($GroupInfo['CanViewUserAgent']=="group") {
348 $GroupInfo['CanViewUserAgent']=sql_result($gruresult,0,"CanViewUserAgent");
349 if($GroupInfo['CanViewUserAgent']!="yes"&&$GroupInfo['CanViewUserAgent']!="no") {
350         $GroupInfo['CanViewUserAgent'] = "no"; } }
351 $GroupInfo['ViewDBInfo']=sql_result($mempreresult,0,"ViewDBInfo");
352 if($GroupInfo['ViewDBInfo']!="yes"&&$GroupInfo['ViewDBInfo']!="no"&&$GroupInfo['ViewDBInfo']!="group") {
353         $GroupInfo['ViewDBInfo'] = "no"; }
354 if($GroupInfo['ViewDBInfo']=="group") {
355 $GroupInfo['ViewDBInfo']=sql_result($gruresult,0,"ViewDBInfo"); 
356 if($GroupInfo['ViewDBInfo']!="yes"&&$GroupInfo['ViewDBInfo']!="no") {
357         $GroupInfo['ViewDBInfo'] = "no"; } }
358 if($GruError==true) {
359 header("Content-Type: text/plain; charset=".$Settings['charset']); 
360 sql_free_result($gruresult); sql_free_result($levresult); sql_free_result($mempreresult); $urlstatus = 503;
361 ob_clean(); echo "Sorry could not load all group data in database.\nContact the board admin about error."; 
362 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
363 sql_free_result($gruresult); sql_free_result($levresult);
364 if($GroupInfo['CanViewBoard']=="no") { 
365 header("Content-Type: text/plain; charset=".$Settings['charset']); 
366 ob_clean(); echo "Sorry you can not view the board."; $urlstatus = 503;
367 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
368 // Member Group Permissions Setup
369 $perquery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."permissions\" WHERE \"PermissionID\"=%i ORDER BY \"ForumID\" ASC", array($GroupInfo['PermissionID']));
370 $peresult=sql_query($perquery,$SQLStat);
371 $pernum=sql_num_rows($peresult);
372 $peri=0; $PerError = null;
373 if($pernum<0) { $PerError = true; sql_free_result($peresult);
374 header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 503;
375 ob_clean(); echo "Sorry could not find permission data in database.\nContact the board admin about error."; 
376 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
377 $ForumIgnoreList1 = null; $ForumIgnoreList2 = null;
378 $ForumIgnoreList3 = null; $ForumIgnoreList4 = null;
379 $ForumIgnoreList5 = null; $ForumIgnoreList6 = null;
380 $ModForumIgnoreList1 = null; $ModForumIgnoreList2 = null;
381 $ModForumIgnoreList3 = null; $ModForumIgnoreList4 = null;
382 if($pernum>=1) { while ($peri < $pernum) {
383 $PerForumID=sql_result($peresult,$peri,"ForumID");
384 if(!is_numeric($PerForumID)) { $PerError = true; }
385 $PermissionInfo['ID'][$PerForumID]=sql_result($peresult,$peri,"id");
386 if(!is_numeric($PermissionInfo['ID'][$PerForumID])) { $PerError = true; }
387 $PermissionInfo['PermissionID'][$PerForumID]=sql_result($peresult,$peri,"PermissionID");
388 if(!is_numeric($PermissionInfo['PermissionID'][$PerForumID])) { $PerError = true; }
389 $PermissionInfo['Name'][$PerForumID]=sql_result($peresult,$peri,"Name");
390 $PermissionInfo['ForumID'][$PerForumID]=sql_result($peresult,$peri,"ForumID");
391 if(!is_numeric($PermissionInfo['ForumID'][$PerForumID])) { $PerError = true; }
392 $PermissionInfo['CanViewForum'][$PerForumID]=sql_result($peresult,$peri,"CanViewForum");
393 if($PermissionInfo['CanViewForum'][$PerForumID]!="yes"&&$PermissionInfo['CanViewForum'][$PerForumID]!="no") {
394                 $PerError = true; }
395 if($PermissionInfo['CanViewForum'][$PerForumID]=="no") {
396 if(strlen($ForumIgnoreList1)>1) { $ForumIgnoreList1 .= " AND \"id\"<>".$PerForumID; }
397 if(strlen($ForumIgnoreList1)<1) { $ForumIgnoreList1 = " \"id\"<>".$PerForumID; }
398 if(strlen($ForumIgnoreList2)>1) { $ForumIgnoreList2 .= " AND \"id\"<>".$PerForumID; }
399 if(strlen($ForumIgnoreList2)<1) { $ForumIgnoreList2 = " AND \"id\"<>".$PerForumID; }
400 if(strlen($ForumIgnoreList3)>1) { $ForumIgnoreList3 .= " AND \"ForumID\"<>".$PerForumID; }
401 if(strlen($ForumIgnoreList3)<1) { $ForumIgnoreList3 = " WHERE \"ForumID\"<>".$PerForumID; }
402 if(strlen($ForumIgnoreList4)>1) { $ForumIgnoreList4 .= " AND \"ForumID\"<>".$PerForumID; }
403 if(strlen($ForumIgnoreList4)<1) { $ForumIgnoreList4 = " AND \"ForumID\"<>".$PerForumID; }
404 if(strlen($ForumIgnoreList5)>1) { $ForumIgnoreList5 .= " AND \"OldForumID\"<>".$PerForumID; }
405 if(strlen($ForumIgnoreList5)<1) { $ForumIgnoreList5 = " WHERE \"OldForumID\"<>".$PerForumID; }
406 if(strlen($ForumIgnoreList6)>1) { $ForumIgnoreList6 .= " AND \"OldForumID\"<>".$PerForumID; }
407 if(strlen($ForumIgnoreList6)<1) { $ForumIgnoreList6 = " AND \"OldForumID\"<>".$PerForumID; } }
408 $PermissionInfo['CanMakePolls'][$PerForumID]=sql_result($peresult,$peri,"CanMakePolls");
409 if($PermissionInfo['CanMakePolls'][$PerForumID]!="yes"&&$PermissionInfo['CanMakePolls'][$PerForumID]!="no") {
410                 $PerError = true; }
411 $PermissionInfo['CanMakeTopics'][$PerForumID]=sql_result($peresult,$peri,"CanMakeTopics");
412 if($PermissionInfo['CanMakeTopics'][$PerForumID]!="yes"&&$PermissionInfo['CanMakeTopics'][$PerForumID]!="no") {
413                 $PerError = true; }
414 $PermissionInfo['CanMakeReplys'][$PerForumID]=sql_result($peresult,$peri,"CanMakeReplys");
415 if($PermissionInfo['CanMakeReplys'][$PerForumID]!="yes"&&$PermissionInfo['CanMakeReplys'][$PerForumID]!="no") {
416                 $PerError = true; }
417 $PermissionInfo['CanMakeReplysClose'][$PerForumID]=sql_result($peresult,$peri,"CanMakeReplysCT");
418 if($PermissionInfo['CanMakeReplysClose'][$PerForumID]!="yes"&&$PermissionInfo['CanMakeReplysClose'][$PerForumID]!="no") {
419                 $PerError = true; }
420 $PermissionInfo['CanEditTopics'][$PerForumID]=sql_result($peresult,$peri,"CanEditTopics");
421 if($PermissionInfo['CanEditTopics'][$PerForumID]!="yes"&&$PermissionInfo['CanEditTopics'][$PerForumID]!="no") {
422         $PermissionInfo['CanEditTopics'][$PerForumID] = "no"; }
423 $PermissionInfo['CanEditTopicsClose'][$PerForumID]=sql_result($peresult,$peri,"CanEditTopicsCT");
424 if($PermissionInfo['CanEditTopicsClose'][$PerForumID]!="yes"&&$PermissionInfo['CanEditTopicsClose'][$PerForumID]!="no") {
425         $PermissionInfo['CanEditTopicsClose'][$PerForumID] = "no"; }
426 $PermissionInfo['CanEditReplys'][$PerForumID]=sql_result($peresult,$peri,"CanEditReplys");
427 if($PermissionInfo['CanEditReplys'][$PerForumID]!="yes"&&$PermissionInfo['CanEditReplys'][$PerForumID]!="no") {
428         $PermissionInfo['CanEditReplys'][$PerForumID] = "no"; }
429 $PermissionInfo['CanEditReplysClose'][$PerForumID]=sql_result($peresult,$peri,"CanEditReplysCT");
430 if($PermissionInfo['CanEditReplysClose'][$PerForumID]!="yes"&&$PermissionInfo['CanEditReplysClose'][$PerForumID]!="no") {
431         $PermissionInfo['CanEditReplysClose'][$PerForumID] = "no"; }
432 $PermissionInfo['CanDeleteTopics'][$PerForumID]=sql_result($peresult,$peri,"CanDeleteTopics");
433 if($PermissionInfo['CanDeleteTopics'][$PerForumID]!="yes"&&$PermissionInfo['CanDeleteTopics'][$PerForumID]!="no") {
434         $PermissionInfo['CanDeleteTopics'][$PerForumID] = "no"; }
435 $PermissionInfo['CanDeleteTopicsClose'][$PerForumID]=sql_result($peresult,$peri,"CanDeleteTopicsCT");
436 if($PermissionInfo['CanDeleteTopicsClose'][$PerForumID]!="yes"&&$PermissionInfo['CanDeleteTopicsClose'][$PerForumID]!="no") {
437         $PermissionInfo['CanDeleteTopicsClose'][$PerForumID] = "no"; }
438 $PermissionInfo['CanDeleteReplys'][$PerForumID]=sql_result($peresult,$peri,"CanDeleteReplys");
439 if($PermissionInfo['CanDeleteReplys'][$PerForumID]!="yes"&&$PermissionInfo['CanDeleteReplys'][$PerForumID]!="no") {
440         $PermissionInfo['CanDeleteReplys'][$PerForumID] = "no"; }
441 $PermissionInfo['CanDeleteReplysClose'][$PerForumID]=sql_result($peresult,$peri,"CanDeleteReplysCT");
442 if($PermissionInfo['CanDeleteReplysClose'][$PerForumID]!="yes"&&$PermissionInfo['CanDeleteReplysClose'][$PerForumID]!="no") {
443         $PermissionInfo['CanDeleteReplysClose'][$PerForumID] = "no"; }
444 $PermissionInfo['CanCloseTopics'][$PerForumID]=sql_result($peresult,$peri,"CanCloseTopics");
445 if($PermissionInfo['CanCloseTopics'][$PerForumID]!="yes"&&$PermissionInfo['CanCloseTopics'][$PerForumID]!="no") {
446         $PermissionInfo['CanCloseTopics'][$PerForumID] = "no"; }
447 $PermissionInfo['CanPinTopics'][$PerForumID]=sql_result($peresult,$peri,"CanPinTopics");
448 if($PermissionInfo['CanPinTopics'][$PerForumID]!="yes"&&$PermissionInfo['CanPinTopics'][$PerForumID]!="no") {
449         $PermissionInfo['CanPinTopics'][$PerForumID] = "no"; }
450 $PermissionInfo['CanDoHTML'][$PerForumID]=sql_result($peresult,$peri,"CanDoHTML");
451 if($PermissionInfo['CanDoHTML'][$PerForumID]!="yes"&&$PermissionInfo['CanDoHTML'][$PerForumID]!="no") {
452         $PermissionInfo['CanDoHTML'][$PerForumID] = "no"; }
453 $PermissionInfo['CanUseBBags'][$PerForumID]=sql_result($peresult,$peri,"CanUseBBags");
454 if($PermissionInfo['CanUseBBags'][$PerForumID]!="yes"&&$PermissionInfo['CanUseBBags'][$PerForumID]!="no") {
455         $PermissionInfo['CanUseBBags'][$PerForumID] = "no"; }
456 $PermissionInfo['CanModForum'][$PerForumID]=sql_result($peresult,$peri,"CanModForum");
457 if($PermissionInfo['CanModForum'][$PerForumID]!="yes"&&$PermissionInfo['CanModForum'][$PerForumID]!="no") {
458         $PermissionInfo['CanModForum'][$PerForumID] = "no"; }
459 if($PermissionInfo['CanModForum'][$PerForumID]=="no") {
460 if(strlen($ModForumIgnoreList1)>1) { $ModForumIgnoreList1 .= " AND \"id\"<>".$PerForumID; }
461 if(strlen($ModForumIgnoreList1)<1) { $ModForumIgnoreList1 = " \"id\"<>".$PerForumID; }
462 if(strlen($ModForumIgnoreList2)>1) { $ModForumIgnoreList2 .= " AND \"id\"<>".$PerForumID; }
463 if(strlen($ModForumIgnoreList2)<1) { $ModForumIgnoreList2 = " AND \"id\"<>".$PerForumID; }
464 if(strlen($ModForumIgnoreList3)>1) { $ModForumIgnoreList3 .= " AND \"ForumID\"<>".$PerForumID; }
465 if(strlen($ModForumIgnoreList3)<1) { $ModForumIgnoreList3 = " WHERE \"ForumID\"<>".$PerForumID; }
466 if(strlen($ModForumIgnoreList4)>1) { $ModForumIgnoreList4 .= " AND \"ForumID\"<>".$PerForumID; }
467 if(strlen($ModForumIgnoreList4)<1) { $ModForumIgnoreList4 = " AND \"ForumID\"<>".$PerForumID; } }
468 if($PerError===true) { $peri = $pernum; }
469 ++$peri; } if($PerError===true) {
470 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult); $urlstatus = 503;
471 ob_clean(); echo "Sorry could not load all permission data in database.\nContact the board admin about error."; 
472 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
473 sql_free_result($peresult);
474 $per2query = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."catpermissions\" WHERE \"PermissionID\"=%i ORDER BY \"CategoryID\" ASC", array($GroupInfo['PermissionID']));
475 $per2esult=sql_query($per2query,$SQLStat);
476 $per2num=sql_num_rows($per2esult);
477 $per2i=0; $Per2Error = null;
478 if($per2num<=0) { $Per2Error = true; sql_free_result($per2esult);
479 header("Content-Type: text/plain; charset=".$Settings['charset']); $urlstatus = 503;
480 ob_clean(); echo "Sorry could not find permission data in database.\nContact the board admin about error."; 
481 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
482 $CatIgnoreList1 = null; $CatIgnoreList2 = null;
483 $CatIgnoreList3 = null; $CatIgnoreList4 = null;
484 $CatIgnoreList5 = null; $CatIgnoreList6 = null;
485 if($per2num>=1) { while ($per2i < $per2num) {
486 $PerCatID=sql_result($per2esult,$per2i,"CategoryID");
487 if(!is_numeric($PerCatID)) { $Per2Error = true; }
488 $CatPermissionInfo['ID'][$PerCatID]=sql_result($per2esult,$per2i,"id");
489 if(!is_numeric($CatPermissionInfo['ID'][$PerCatID])) { $Per2Error = true; }
490 $CatPermissionInfo['PermissionID'][$PerCatID]=sql_result($per2esult,$per2i,"PermissionID");
491 if(!is_numeric($CatPermissionInfo['PermissionID'][$PerCatID])) { $Per2Error = true; }
492 $CatPermissionInfo['Name'][$PerCatID]=sql_result($per2esult,$per2i,"Name");
493 $CatPermissionInfo['CategoryID'][$PerCatID]=sql_result($per2esult,$per2i,"CategoryID");
494 if(!is_numeric($CatPermissionInfo['CategoryID'][$PerCatID])) { $Per2Error = true; }
495 $CatPermissionInfo['CanViewCategory'][$PerCatID]=sql_result($per2esult,$per2i,"CanViewCategory");
496 if($CatPermissionInfo['CanViewCategory'][$PerCatID]!="yes"&&$CatPermissionInfo['CanViewCategory'][$PerCatID]!="no") { $Per2Error = true; }
497 if($CatPermissionInfo['CanViewCategory'][$PerCatID]=="no") {
498 if(strlen($CatIgnoreList1)>1) { $CatIgnoreList1 .= " AND \"id\"<>".$PerCatID; }
499 if(strlen($CatIgnoreList1)<1) { $CatIgnoreList1 = " \"id\"<>".$PerCatID; }
500 if(strlen($CatIgnoreList2)>1) { $CatIgnoreList2 .= " AND \"id\"<>".$PerCatID; }
501 if(strlen($CatIgnoreList2)<1) { $CatIgnoreList2 = " AND \"id\"<>".$PerCatID; }
502 if(strlen($CatIgnoreList3)>1) { $CatIgnoreList3 .= " AND \"CategoryID\"<>".$PerCatID; }
503 if(strlen($CatIgnoreList3)<1) { $CatIgnoreList3 = " WHERE \"CategoryID\"<>".$PerCatID; }
504 if(strlen($CatIgnoreList4)>1) { $CatIgnoreList4 .= " AND \"CategoryID\"<>".$PerCatID; }
505 if(strlen($CatIgnoreList4)<1) { $CatIgnoreList4 = " AND \"CategoryID\"<>".$PerCatID; }
506 if(strlen($CatIgnoreList5)>1) { $CatIgnoreList5 .= " AND \"OldCategoryID\"<>".$PerCatID; }
507 if(strlen($CatIgnoreList5)<1) { $CatIgnoreList5 = " WHERE \"OldCategoryID\"<>".$PerCatID; }
508 if(strlen($CatIgnoreList6)>1) { $CatIgnoreList6 .= " AND \"OldCategoryID\"<>".$PerCatID; }
509 if(strlen($CatIgnoreList6)<1) { $CatIgnoreList6 = " AND \"OldCategoryID\"<>".$PerCatID; } }
510 if($Per2Error===true) { $per2i = $per2num; }
511 ++$per2i; } if($Per2Error===true) {
512 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($per2esult); $urlstatus = 503;
513 ob_clean(); echo "Sorry could not load all permission data in database.\nContact the board admin about error."; 
514 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
515 sql_free_result($per2esult);
516 ?>