10 $rResult =
getResult(
"SELECT `keys`.`ID` AS `ID`, `keys`.`Default` AS `Default`, `values`.`Value` AS `Value` FROM `" . MODULE_DB_PREFIX .
"MembershipsSettings` AS `keys` LEFT JOIN `" . MODULE_DB_PREFIX .
"Memberships` AS `values` ON `keys`.`ID`=`values`.`Setting` AND `values`.`Membership`='" . $sMembership .
"'");
11 $sContents =
'<membership id="' . $sMembership .
'" ';
12 $iCount = $rResult->rowCount();
13 for($i=0; $i<$iCount; $i++) {
14 $aSetting = $rResult->fetch();
15 $sValue = !isset($aSetting[
'Value']) || $aSetting[
'Value'] ==
"" ? $aSetting[
'Default'] : $aSetting[
'Value'];
16 $sContents .=
'v' . $aSetting[
'ID'] .
'="' . $sValue .
'" ';
25 $aSettingTmpls = array(
26 3 =>
'<setting id="#1#" name="#2#"><![CDATA[#3#]]></setting>',
27 6 =>
'<setting id="#1#" name="#2#" type="#3#" default="#4#" range="#5#"><![CDATA[#6#]]></setting>'
30 $rResult =
getResult(
"SELECT * FROM `" . MODULE_DB_PREFIX .
"MembershipsSettings`");
32 $iCount = $rResult->rowCount();
33 for($i=0; $i<$iCount; $i++) {
34 $aSetting = $rResult->fetch();
35 if($bAdmin) $sSettings .=
parseXml($aSettingTmpls, $aSetting[
'ID'], $aSetting[
'Name'], $aSetting[
'Type'], $aSetting[
'Default'], $aSetting[
'Range'], $aSetting[
'Caption']);
36 else $sSettings .=
parseXml($aSettingTmpls, $aSetting[
'ID'], $aSetting[
'Name'], $aSetting[
'Error']);
49 $iCurrentTime =
time();
52 getResult(
"REPLACE `" . MODULE_DB_PREFIX .
"CurrentUsers` SET `ID`='" .
$aUser[
'id'] .
"', `Nick`='" .
$sNick .
"', `Sex`='" .
$aUser[
'sex'] .
"', `Age`='" .
$aUser[
'age'] .
"', `Desc`='" . $sDescription .
"', `Photo`='" .
$aUser[
'photo'] .
"', `Profile`='" .
$aUser[
'profile'] .
"', `Start`='" . $iCurrentTime .
"', `When`='" . $iCurrentTime .
"', `Status`='" . USER_STATUS_NEW .
"'");
53 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"RoomsUsers` WHERE `User`='" .
$aUser[
'id'] .
"'");
55 $rFiles =
getResult(
"SELECT `ID` FROM `" . MODULE_DB_PREFIX .
"Messages` WHERE `Recipient`='" .
$aUser[
'id'] .
"' AND `Type`='file'");
56 while($aFile = $rFiles->fetch())
removeFile($aFile[
'ID']);
73 return getValue(
"SELECT `Banned` FROM `" . MODULE_DB_PREFIX .
"Profiles` WHERE `ID` = '" .
$sId .
"' LIMIT 1") == TRUE_VAL;
81 $sUserId =
getValue(
"SELECT `ID` FROM `" . MODULE_DB_PREFIX .
"Profiles` WHERE `ID` = '" .
$sId .
"' LIMIT 1");
82 $sSql =
empty($sUserId)
83 ?
"INSERT INTO `" . MODULE_DB_PREFIX .
"Profiles`(`ID`, `Banned`, `Type`) VALUES('" .
$sId .
"', '" . $sBan .
"', '" . CHAT_TYPE_FULL .
"')"
84 :
"UPDATE `" . MODULE_DB_PREFIX .
"Profiles` SET `Banned`='" . $sBan .
"' WHERE `ID`='" .
$sId .
"'";
98 $iCurrentTime =
time();
100 $iDeleteTime = $iUpdateInterval * 6;
104 $rResult =
getResult(
"SELECT * FROM `" . MODULE_DB_PREFIX .
"Rooms` WHERE IF('" .
$sId .
"'='0', 1, `OwnerID`<>'" .
$sId .
"') AND (`When` >= (" . ($iCurrentTime - $iUpdateInterval) .
") OR (`Status`='" . ROOM_STATUS_DELETE .
"' AND `When` >= " . ($iCurrentTime - $iDeleteTime) .
")) ORDER BY `When`");
105 while($aRoom = $rResult->fetch())
106 switch($aRoom[
'Status']) {
107 case ROOM_STATUS_DELETE:
110 case ROOM_STATUS_NORMAL:
112 $sRooms .=
parseXml(
$aXmlTemplates[
'room'], $aRoom[
'ID'], ROOM_STATUS_NORMAL, $aRoom[
'OwnerID'],
empty($aRoom[
'Password']) ? FALSE_VAL : TRUE_VAL, stripslashes($aRoom[
'Name']), stripslashes($aRoom[
'Desc']));
118 $sSql =
"SELECT `r`.`ID` AS `RoomID`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . ROOM_STATUS_NORMAL .
"',`ru`.`User`,'') SEPARATOR ',') AS `In`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . ROOM_STATUS_DELETE .
"',`ru`.`User`,'') SEPARATOR ',') AS `Out` FROM `" . MODULE_DB_PREFIX .
"Rooms` AS `r` INNER JOIN `" . MODULE_DB_PREFIX .
"RoomsUsers` AS `ru` WHERE `r`.`ID`=`ru`.`Room` AND `r`.`Status`='" . ROOM_STATUS_NORMAL .
"' AND `ru`.`When`>=" . ($iCurrentTime - $iUpdateInterval) .
" GROUP BY `r`.`ID`";
120 while($aRoom = $rResult->fetch())
126 $iCurrentTime -= $iRunTime;
127 $rResult =
getResult(
"SELECT `ID` FROM `" . MODULE_DB_PREFIX .
"RoomsUsers`");
128 if($rResult->rowCount() == 0)
getResult(
"TRUNCATE TABLE `" . MODULE_DB_PREFIX .
"RoomsUsers`");
129 $iRoomsCount =
getValue(
"SELECT COUNT(`ID`) FROM `" . MODULE_DB_PREFIX .
"Rooms` WHERE `Status`='" . ROOM_STATUS_NORMAL .
"'");
131 if(
empty($iRoomsCount))
132 getResult(
"INSERT INTO `" . MODULE_DB_PREFIX .
"Rooms` (`Name`, `OwnerID`, `Desc`, `When`, `Status`) VALUES ('Lobby', '0', 'Welcome to our chat!', '0', 'normal')");
134 $sSql =
"SELECT `r`.`ID` AS `RoomID`, `r`.*, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . ROOM_STATUS_NORMAL .
"' AND `ru`.`User`<>'" .
$sId .
"',`ru`.`User`,'') SEPARATOR ',') AS `In`, GROUP_CONCAT(DISTINCT IF(`ru`.`Status`='" . ROOM_STATUS_NORMAL .
"' AND `ru`.`User`<>'" .
$sId .
"',(" . $iCurrentTime .
"-`ru`.`When`),'') SEPARATOR ',') AS `InTime` FROM `" . MODULE_DB_PREFIX .
"Rooms` AS `r` LEFT JOIN `" . MODULE_DB_PREFIX .
"RoomsUsers` AS `ru` ON `r`.`ID`=`ru`.`Room` GROUP BY `r`.`ID` ORDER BY `r`.`ID` LIMIT " .
getSettingValue(
$sModule,
"maxRoomsNumber");
136 while($aRoom = $rResult->fetch())
137 $sRooms .=
parseXml(
$aXmlTemplates[
'room'], $aRoom[
'RoomID'], $aRoom[
'OwnerID'],
empty($aRoom[
'Password']) ? FALSE_VAL : TRUE_VAL, stripslashes($aRoom[
'Name']), stripslashes($aRoom[
'Desc']), $aRoom[
'In'], $aRoom[
'InTime']);
148 $iCurrentTime =
time();
151 $aCurRoom =
getArray(
"SELECT * FROM `" . MODULE_DB_PREFIX .
"Rooms` WHERE `Name`='" .
$sTitle .
"'");
152 $sStatus = $bTemp ? ROOM_STATUS_DELETE : ROOM_STATUS_NORMAL;
153 if(!
empty($aCurRoom[
'ID']) && $sUserId == $aCurRoom[
'OwnerID']) {
154 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"Rooms` SET `Name`='" .
$sTitle .
"', `Password`='" .
$sPassword .
"', `Desc`='" .
$sDesc .
"', `OwnerID`='" . $sUserId .
"', `When`='" . $iCurrentTime .
"', `Status`='" .
$sStatus .
"' WHERE `ID`='" . $aCurRoom[
'ID'] .
"'");
155 return $aCurRoom[
'ID'];
156 }
else if(
empty($aCurRoom[
'ID'])) {
157 getResult(
"INSERT INTO `" . MODULE_DB_PREFIX .
"Rooms` (`ID`, `Name`, `Password`, `Desc`, `OwnerID`, `When`, `Status`) VALUES ('" .
$iRoomId .
"', '" .
$sTitle .
"', '" .
$sPassword .
"', '" .
$sDesc .
"', '" . $sUserId .
"', '" . $iCurrentTime .
"', '" .
$sStatus .
"')");
163 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"Rooms` SET `Name`='" .
$sTitle .
"', `Password`='" .
$sPassword .
"', `Desc`='" .
$sDesc .
"', `When`='" . $iCurrentTime .
"', `Status`='" . ROOM_STATUS_NORMAL .
"' WHERE `ID`='" .
$iRoomId .
"'");
167 $sSql =
"UPDATE `" . MODULE_DB_PREFIX .
"Rooms` SET `When`='" . $iCurrentTime .
"', `Status`='" . ROOM_STATUS_DELETE .
"' WHERE `ID` = '" .
$iRoomId .
"'";
172 $sId =
getValue(
"SELECT `ID` FROM `" . MODULE_DB_PREFIX .
"RoomsUsers` WHERE `Room`='" .
$iRoomId .
"' AND `User`='" . $sUserId .
"' LIMIT 1");
173 if(
empty(
$sId))
getResult(
"INSERT INTO `" . MODULE_DB_PREFIX .
"RoomsUsers`(`Room`, `User`, `When`) VALUES('" .
$iRoomId .
"', '" . $sUserId .
"', '" . $iCurrentTime .
"')");
174 else getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"RoomsUsers` SET `When`='" . $iCurrentTime .
"', `Status`='" . ROOM_STATUS_NORMAL .
"' WHERE `ID`='" .
$sId .
"'");
178 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"RoomsUsers` SET `When`='" . $iCurrentTime .
"', `Status`='" . ROOM_STATUS_DELETE .
"' WHERE `Room`='" .
$iRoomId .
"' AND `User`='" . $sUserId .
"' LIMIT 1");
183 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"Rooms` WHERE `Status`='" . ROOM_STATUS_DELETE .
"' AND `When`<" . ($iCurrentTime - 24*60*60));
199 $iIdleTime = $iUpdateInterval * 3;
200 $iDeleteTime = $iUpdateInterval * 6;
202 $iCurrentTime =
time();
204 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"CurrentUsers` SET `Status`='" . USER_STATUS_OLD .
"', `When`='" . $iCurrentTime .
"' WHERE `ID`='" .
$sId .
"' AND `Status`<>'" . USER_STATUS_KICK .
"' AND (`Status` NOT IN('" . USER_STATUS_NEW .
"', '" . USER_STATUS_TYPE .
"', '" . USER_STATUS_ONLINE .
"') || (" . $iCurrentTime .
"-`When`)>" . $iUpdateInterval .
") LIMIT 1");
207 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"CurrentUsers` SET `When`=" . $iCurrentTime .
", `Status`='" . USER_STATUS_IDLE .
"' WHERE `Status`<>'" . USER_STATUS_IDLE .
"' AND `When`<=(" . ($iCurrentTime - $iIdleTime) .
")");
208 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"RoomsUsers` WHERE `Status`='" . ROOM_STATUS_DELETE .
"' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) .
")");
210 $rFiles =
getResult(
"SELECT `files`.`ID` AS `FileID` FROM `" . MODULE_DB_PREFIX .
"Messages` AS `files` INNER JOIN `" . MODULE_DB_PREFIX .
"CurrentUsers` AS `users` WHERE `files`.`Recipient`=`users`.`ID` AND `files`.`Type`='file' AND `users`.`Status`='" . USER_STATUS_IDLE .
"' AND `users`.`When`<=" . ($iCurrentTime - $iDeleteTime));
211 while($aFile = $rFiles->fetch())
removeFile($aFile[
'FileID']);
214 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"CurrentUsers`, `" . MODULE_DB_PREFIX .
"RoomsUsers` USING `" . MODULE_DB_PREFIX .
"CurrentUsers`, `" . MODULE_DB_PREFIX .
"RoomsUsers` WHERE `" . MODULE_DB_PREFIX .
"CurrentUsers`.`ID`=`" . MODULE_DB_PREFIX .
"RoomsUsers`.`User` AND `" . MODULE_DB_PREFIX .
"CurrentUsers`.`Status`='" . USER_STATUS_IDLE .
"' AND `" . MODULE_DB_PREFIX .
"CurrentUsers`.`When`<=" . ($iCurrentTime - $iDeleteTime));
216 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"Rooms`, `" . MODULE_DB_PREFIX .
"RoomsUsers` USING `" . MODULE_DB_PREFIX .
"Rooms`,`" . MODULE_DB_PREFIX .
"RoomsUsers` WHERE `" . MODULE_DB_PREFIX .
"Rooms`.`ID`=`" . MODULE_DB_PREFIX .
"RoomsUsers`.`Room` AND `" . MODULE_DB_PREFIX .
"Rooms`.`Status`='" . ROOM_STATUS_DELETE .
"' AND `" . MODULE_DB_PREFIX .
"Rooms`.`When`<=(" . ($iCurrentTime - $iDeleteTime) .
")");
221 $sIds = count($aIds)>0 ?
" AND `OwnerID` NOT IN (" . implode(
',', $aIds) .
")" :
"";
222 $rResult =
getResult(
"SELECT DISTINCT(`Room`) FROM `" . MODULE_DB_PREFIX .
"RoomsUsers`");
223 $aFullRooms = array();
224 $iCount = $rResult->rowCount();
225 for($i=0; $i<$iCount; $i++) {
226 $aFullRoom = $rResult->fetch();
227 $aFullRooms[] = $aFullRoom[
'Room'];
229 $sFullRooms = count($aFullRooms)>0 ?
"`ID` NOT IN(" . implode(
',', $aFullRooms) .
") AND " :
"";
230 getResult(
"UPDATE `" . MODULE_DB_PREFIX .
"Rooms` SET `Status`='" . ROOM_STATUS_DELETE .
"', `When`=" . $iCurrentTime .
" WHERE " . $sFullRooms .
"`OwnerID`<>0" . $sIds);
234 getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"Messages` WHERE `Type`='text' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) .
")");
238 $rRes =
getResult(
"SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`Status` AS `Status`, ccu.`Online` AS `Online`, rp.`Type` AS `Type` FROM `" . MODULE_DB_PREFIX .
"Profiles` AS rp, `" . MODULE_DB_PREFIX .
"CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` ORDER BY ccu.`When`");
239 while(
$aUser = $rRes->fetch()) {
240 if(
$aUser[
'ID'] ==
$sId && !(
$aUser[
'Status'] == USER_STATUS_KICK ||
$aUser[
'Status'] == USER_STATUS_TYPE))
continue;
241 switch(
$aUser[
'Status']) {
242 case USER_STATUS_NEW:
243 $sContent .=
parseXml(
$aXmlTemplates[
'user'],
$aUser[
'ID'],
$aUser[
'Status'],
$aUser[
'Nick'],
$aUser[
'Sex'],
$aUser[
'Age'], stripslashes(
$aUser[
'Desc']),
$aUser[
'Photo'],
$aUser[
'Profile'],
$aUser[
'Type'],
$aUser[
'Online']);
245 case USER_STATUS_TYPE:
248 case USER_STATUS_ONLINE:
251 case USER_STATUS_IDLE:
252 case USER_STATUS_KICK:
261 $iCurrentTime -= $iRunTime;
262 $rRes =
getResult(
"SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`Online` AS `Online`, rp.`Type` AS `Type`, (" . $iCurrentTime .
"-`ccu`.`Start`) AS `Time` FROM `" . MODULE_DB_PREFIX .
"Profiles` AS rp, `" . MODULE_DB_PREFIX .
"CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` AND ccu.`Status` NOT IN ('" . USER_STATUS_IDLE .
"', '" . USER_STATUS_KICK .
"') AND rp.`Banned`='" . FALSE_VAL .
"' ORDER BY ccu.`When`");
263 while(
$aUser = $rRes->fetch())
264 $sContent .=
parseXml(
$aXmlTemplates[
'user'],
$aUser[
'ID'], USER_STATUS_NEW,
$aUser[
'Nick'],
$aUser[
'Sex'],
$aUser[
'Age'], stripslashes(
$aUser[
'Desc']),
$aUser[
'Photo'],
$aUser[
'Profile'],
$aUser[
'Type'],
$aUser[
'Online'],
$aUser[
'Time']);
273 @
getResult(
"DELETE FROM `" . MODULE_DB_PREFIX .
"Messages` WHERE `ID`='" . $sFileId .
"'");