barabula
Гуру форума
- Регистрация
- 21 Май 2009
- Сообщения
- 474
- Реакции
- 80
- Автор темы
- #1
Люди кто шарит в этом хорошо, помогите плизз проверить код на уязвимости.
P.S. Модераторые если написал не туда, перенесите тему.
PHP:
<?php
require_once( "../../inc_common.php" );
include( $engine_path."users_get_list.php" );
if ( !$exists )
{
$error_text = "{$w_no_user}";
include( $file_path."designes/".$design."/error_page.php" );
exit( );
}
if ( !$is_regist_complete )
{
header( "Location: ".$chat_url.( "registration_form.php?session=".$session."&user_name=" ).urlencode( $user_name ) );
exit( );
}
include( "../../inc_user_class.php" );
include( $ld_engine_path."users_get_object.php" );
include( "config.php" );
$is_regist_old = $is_regist;
if ( !mysql_connect( $mysql_server, $mysql_username, $mysql_password ) )
{
exit( "<font color=#EF0202><b>Ошибка подключение к MySQL. Проверьте параметры</b></font>" );
}
if ( !mysql_select_db( $mysql_db ) )
{
exit( "<font color=#EF0202><b>Ошибка MySQL. Невозможно выбрать базу данных.</b></font>" );
}
mysql_query( "SET NAMES cp1251" );
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$frcount = mysql_num_rows( $result );
set_variable( "fid" );
$fid = intval( $fid );
set_variable( "act" );
set_variable( "filter" );
set_variable( "res" );
switch ( $act )
{
case "add" :
if ( $fid == 0 )
{
$code = 1;
include( "error.php" );
exit( );
}
if ( $fid == $is_regist )
{
$code = 2;
include( "error.php" );
exit( );
}
$is_regist_old = $is_regist;
$is_regist = $fid;
$friend = $current_user->nickname;
include( $ld_engine_path."users_get_object.php" );
$friend_nickname = $current_user->nickname;
$is_regist = $is_regist_old;
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$is_regist."\") and (`fid`=\"".$fid."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) == 0 )
{
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) == 0 )
{
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\") and (`fid`=\"".$fid."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) == 0 )
{
$sql = "INSERT INTO `".$mysql_prefix."friendrequests` SET `is_regist`=\"".$is_regist."\", `fid`=\"".$fid."\", `friend_name`=\"".$friend_nickname."\", `friend`=\"".$friend."\"";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
if ( $send_board )
{
include_once( $file_path."inc_user_class.php" );
include( $ld_engine_path."users_get_object.php" );
$send_to_id = $fid;
$subject = $current_user->nickname." желает вас добавить в друзья";
$message = "<b>".$current_user->nickname."</b> желает вас добавить в друзья<br> Для одобрения или отклонения заявки пройдите в раздел <br><b>\"Мои друзья\"</b>";
$message .= "<br><br>С уважением,<br>Администрация ".$w_title;
include( $ld_engine_path."hidden_board_post_message.php" );
include( $file_path."designes/".$design."/board_post.php" );
}
if ( $_GET['up'] == "pc" )
{
header( "Location: ".$current_design."profile_content.php?session=".$session."&user_id=".$fid."&res=1#fr" );
}
else
{
header( "Location: friends.php?session=".$session."&filter=general&uid=".$_GET['uid']."&res=1" );
}
}
else
{
$code = 3;
include( "error.php" );
}
}
else
{
$code = 4;
include( "error.php" );
}
}
else
{
$code = 4;
include( "error.php" );
}
break;
case "delete" :
if ( $fid == 0 )
{
$code = 1;
include( "error.php" );
exit( );
}
if ( $fid == $is_regist )
{
$code = 2;
include( "error.php" );
exit( );
}
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) !== 0 )
{
$sql = "DELETE FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$sql = "DELETE FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\") and (`fid`=\"".$fid."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
if ( $_GET['up'] == "pc" )
{
header( "Location: ".$current_design."profile_content.php?session=".$session."&user_id=".$fid."&res=2#fr" );
}
else
{
header( "Location: friends.php?session=".$session."&filter=general&uid=".$_GET['uid']."&res=2" );
}
}
else
{
$code = 5;
include( "error.php" );
}
break;
case "approval" :
if ( $fid == 0 )
{
$code = 1;
include( "error.php" );
exit( );
}
if ( $fid == $is_regist )
{
$code = 2;
include( "error.php" );
exit( );
}
$is_regist_old = $is_regist;
$is_regist = $fid;
$friend = $current_user->nickname;
include( $ld_engine_path."users_get_object.php" );
$friend_nickname = $current_user->nickname;
$is_regist = $is_regist_old;
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) !== 0 )
{
$sql = "INSERT INTO `".$mysql_prefix."friends` SET `is_regist`=\"".$is_regist."\", `fid`=\"".$fid."\", `friend_name`=\"".$friend_nickname."\", `friend`=\"".$friend."\"";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$sql = "INSERT INTO `".$mysql_prefix."friends` SET `is_regist`=\"".$fid."\", `fid`=\"".$is_regist."\", `friend_name`=\"".$friend."\", `friend`=\"".$friend_nickname."\"";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$sql = "DELETE FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
header( "Location: friends.php?session=".$session."&filter=requests&res=1" );
}
else
{
$code = 5;
include( "error.php" );
}
break;
case "decline" :
if ( $fid == 0 )
{
$code = 1;
include( "error.php" );
exit( );
}
if ( $fid == $is_regist )
{
$code = 2;
include( "error.php" );
exit( );
}
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row = mysql_fetch_assoc( $result );
if ( count( $row['id'] ) !== 0 )
{
$sql = "DELETE FROM `".$mysql_prefix."friendrequests` WHERE (`is_regist`=\"".$fid."\") and (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
header( "Location: friends.php?session=".$session."&filter=requests&res=2" );
}
else
{
$code = 5;
include( "error.php" );
}
}
switch ( $filter )
{
case "general" :
set_variable( "uid" );
$uid = intval( $uid );
if ( $uid )
{
$is_regist = $uid;
include( $ld_engine_path."users_get_object.php" );
}
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$fcount = mysql_num_rows( $result );
$itext = "друзей";
$z = strlen( $fcount );
$c = str_split( $fcount );
$c = $c[$z - 1];
if ( $c == 1 )
{
$itext = "друг";
}
if ( $c == 2 || $c == 3 || $c == 4 )
{
$itext = "друга";
}
if ( $fcount == 11 || $fcount == 12 || $fcount == 13 || $fcount == 14 )
{
$itext = "друзей";
}
include( "header.php" );
if ( $res == 1 )
{
echo "\t\t<table width=\"100%\" border=\"1\" bordercolor=\"6EAFF7\" bgcolor=\"#D6EAFF\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t<tr><td> <b>Друг добавлен в ваш список друзей</b></td></tr></table><br>";
}
if ( $res == 2 )
{
echo "\t<table width=\"100%\" border=\"1\" bordercolor=\"FC8787\" bgcolor=\"#FFD6D6\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t<tr><td> <b>Друг удален из вашего списка друзей</b></td></tr></table><br>";
}
if ( $res == 3 )
{
echo "\t<table width=\"100%\" border=\"1\" bordercolor=\"FFF265\" bgcolor=\"#FFF8AC\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t<tr><td> <b>Заявка на добавление в друзья подана</b></td></tr></table><br>";
}
echo "\t\t<b><font color=\"#FF783D\">У ";
if ( $uid )
{
echo $current_user->nickname;
}
else
{
echo "Вас";
}
echo " ";
echo $fcount;
echo " ";
echo $itext;
echo "</font></b>\t\r\n\t\t<table width=\"100%\" border=\"1\" bordercolor=\"DAE2E8\" bgcolor=\"#F7F7F7\" cellspacing=\"4\" cellpadding=\"4\">\r\n\t\t";
while ( ( $row = mysql_fetch_assoc( $result ) ) !== FALSE )
{
echo "\t\t<tr><td bgcolor=\"#FFFFFF\">\r\n\t\t\t<table width=\"100%\"><tr><td width=\"100\" align=\"center\">\r\n\t\t\t";
if ( file_exists( $file_path."photos/".floor( $row['fid'] / 2000 )."/".$row['fid'].".big.jpg" ) )
{
$photo = $chat_url."photos/".floor( $row['fid'] / 2000 )."/".$row['fid'].".big.jpg";
}
else
{
$photo = "img/nophoto.jpg";
}
echo "\t\t\t\t\t\t<a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\">\r\n\t\t\t\t<img src=\"";
echo $photo;
echo "\" width=\"80\" border=\"0\"></a>\r\n\t\t\t<td align=\"left\" valign=\"top\" width=\"70%\">Ник: <a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">";
echo $row['friend_name'];
echo "</a>\r\n\t\t\t\t</td>\r\n\t\t\t<td width=\"250\" align=\"left\" valign=\"top\">\r\n\t\t\t\t<table border=\"1\" width=\"200\" bordercolor=\"DAE2E8\" bgcolor=\"#FBFBFB\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t\t\t\t<tr><td> <a href=\"";
echo $chat_url;
echo "board_send.php?session=";
echo $session;
echo "&send_to_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Отправить сообщение</a></td></tr>\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&filter=general&uid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Друзья ";
echo $row['friend_name'];
echo "</a></td></tr>\r\n\t\t\t\t\t";
if ( $row['fid'] !== $is_regist_old )
{
$sql2 = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist_old."\") and (`fid`=\"".$row['fid']."\")";
if ( !( $result2 = mysql_query( $sql2 ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql2 );
}
$checkf = mysql_num_rows( $result2 );
if ( $checkf == 0 )
{
echo "\t\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=add&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Добавить в друзья</a></td></tr>\r\n\t\t\t\t\t";
}
else
{
echo "\t\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=delete&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Убрать из друзей</a></td></tr>";
}
}
echo "\t\t\t\t\t</table>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr></table>\r\n\t\t</td></tr>\r\n\t\t";
}
echo "\t\t</table>\r\n\t\t\t";
include( "header_end.php" );
break;
case "requests" :
$sql = "SELECT * FROM `".$mysql_prefix."friendrequests` WHERE (`fid`=\"".$is_regist."\")";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$fcount = mysql_num_rows( $result );
if ( $fcount == 0 )
{
header( "Location: friends.php?session=".$session."&filter=general" );
}
$itext = "заявок";
$z = strlen( $fcount );
$c = str_split( $fcount );
$c = $c[$z - 1];
if ( $c == 1 )
{
$itext = "заявка";
}
if ( $c == 2 || $c == 3 || $c == 4 )
{
$itext = "заявки";
}
if ( $fcount == 11 || $fcount == 12 || $fcount == 13 || $fcount == 14 )
{
$itext = "заявок";
}
include( "header.php" );
echo "\t\t<b><font color=\"#FF783D\">У Вас ";
echo $fcount;
echo " ";
echo $itext;
echo "</font></b>\t\r\n\t\t\t";
if ( $res == 1 )
{
echo "\t\t\t<table width=\"100%\" border=\"1\" bordercolor=\"71B4F9\" bgcolor=\"#D6EAFF\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t<tr><td> <b>Заявка одобрена</b></td></tr></table><br>";
}
if ( $res == 2 )
{
echo "\t\t\t<table width=\"100%\" border=\"1\" bordercolor=\"FC8787\" bgcolor=\"#FFD6D6\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t<tr><td> <b>Заявка отклонена</b></td></tr></table><br>";
}
echo "\t<table width=\"100%\" border=\"1\" bordercolor=\"DAE2E8\" bgcolor=\"#F7F7F7\" cellspacing=\"4\" cellpadding=\"4\">\r\n\t\t";
if ( !( $result = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
while ( ( $row = mysql_fetch_assoc( $result ) ) !== FALSE )
{
echo "\t\t<tr><td bgcolor=\"#FFFFFF\">\r\n\t\t\t<table width=\"100%\"><tr><td width=\"100\" align=\"center\">\r\n\t\t\t";
$photo = "img/nophoto.jpg";
if ( file_exists( $file_path."photos/".floor( $row['is_regist'] / 2000 )."/".$row['is_regist'].".big.jpg" ) )
{
$photo = $chat_url."photos/".floor( $row['is_regist'] / 2000 )."/".$row['is_regist'].".big.jpg";
}
echo "\t\t\t\t\t\t<a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['is_regist'];
echo "\">\r\n\t\t\t\t<img src=\"";
echo $photo;
echo "\" width=\"80\" border=\"0\"></a>\r\n\t\t\t<td align=\"left\" valign=\"top\" width=\"70%\">Ник: <a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['is_regist'];
echo "\" class=\"jsnavi2\">";
echo $row['friend'];
echo "</a>\r\n\t\t\t\t</td>\r\n\t\t\t<td width=\"250\" align=\"left\" valign=\"top\">\r\n\t\t\t\t<table border=\"1\" width=\"200\" bordercolor=\"DAE2E8\" bgcolor=\"#FBFBFB\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=approval&fid=";
echo $row['is_regist'];
echo "\" class=\"jsnavi2\"><b>Добавить в друзья</b></a></td></tr>\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=decline&fid=";
echo $row['is_regist'];
echo "\" class=\"jsnavi2\"><b>Отклонить заявку</b></a></td></tr>\r\n\t\t\t\t\t</table>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr></table>\r\n\t\t</td></tr>\r\n\t\t";
}
echo "\t\t</table>\r\n\t\t\t";
include( "header_end.php" );
break;
case "online" :
set_variable( "uid" );
$uid = intval( $uid );
$fr = 0;
include( $ld_engine_path."rooms_get_list.php" );
include( $engine_path."users_get_list.php" );
$IsModer = 0;
if ( $is_regist )
{
include( "inc_user_class.php" );
include( $ld_engine_path."users_get_object.php" );
if ( 0 < $current_user->user_class )
{
$IsModer = 1;
}
else
{
$IsModer = 0;
}
}
$usr_test = array( );
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\")";
if ( !( $friends_online = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$fr = 0;
if ( 0 < count( $users ) )
{
$in_room = array( );
$kk = 0;
for ( ; $kk < count( $room_ids ); ++$kk )
{
$i = 0;
for ( ; $i < count( $users ); ++$i )
{
$usr_test = explode( "\t", $users[$i] );
$who_nickname = $usr_test[USER_NICKNAME];
$who_room = $usr_test[USER_ROOM];
if ( $who_room == $room_ids[$kk] )
{
$usr_test[USER_INVISIBLE] = intval( trim( $usr_test[USER_INVISIBLE] ) );
if ( $usr_test[USER_INVISIBLE] )
{
if ( $IsModer )
{
$in_room[] = $who_nickname;
}
}
else
{
$in_room[] = $who_nickname;
}
}
}
$rooms[$room_ids[$kk]]['in_room'] = $in_room;
}
while ( ( $row = mysql_fetch_assoc( $friends_online ) ) !== FALSE )
{
$fexists = in_array( $row['friend_name'], $in_room );
if ( $fexists )
{
++$fr;
}
}
}
else if ( $uid )
{
$is_regist = $uid;
include( $ld_engine_path."users_get_object.php" );
}
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\")";
if ( !( $friends_online = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$fcount = $fr;
$itext = "друзей";
$z = strlen( $fcount );
$c = str_split( $fcount );
$c = $c[$z - 1];
if ( $c == 1 )
{
$itext = "друг";
}
if ( $c == 2 || $c == 3 || $c == 4 )
{
$itext = "друга";
}
if ( $fcount == 11 || $fcount == 12 || $fcount == 13 || $fcount == 14 )
{
$itext = "друзей";
}
include( "header.php" );
echo "\t\t<b><font color=\"#FF783D\">У ";
if ( $uid )
{
echo $current_user->nickname;
}
else
{
echo "Вас";
}
echo " ";
echo $fcount;
echo " ";
echo $itext;
echo " online</font></b>\t\r\n\t\t\t\t<table width=\"100%\" border=\"1\" bordercolor=\"DAE2E8\" bgcolor=\"#F7F7F7\" cellspacing=\"4\" cellpadding=\"4\">\r\n\t\t\t";
while ( ( $row = mysql_fetch_assoc( $friends_online ) ) !== FALSE )
{
$fexists = in_array( $row['friend_name'], $in_room );
if ( $fexists )
{
$photo = $chat_url."powmod/friends/img/nophoto.jpg";
if ( file_exists( $file_path."photos/".floor( $row['fid'] / 2000 )."/".$row['fid'].".big.jpg" ) )
{
$photo = $chat_url."photos/".floor( $row['fid'] / 2000 )."/".$row['fid'].".big.jpg";
}
echo "\t\t\t \t\t<tr><td bgcolor=\"#FFFFFF\">\r\n\t\t\t<table width=\"100%\"><tr><td width=\"100\" align=\"center\">\r\n\t\t\t\t\t\t<a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\">\r\n\t\t\t\t<img src=\"";
echo $photo;
echo "\" width=\"80\" border=\"0\"></a>\r\n\t\t\t<td align=\"left\" valign=\"top\" width=\"70%\">Ник: <a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">";
echo $row['friend_name'];
echo "</a>\r\n\t\t\t\t</td>\r\n\t\t\t<td width=\"250\" align=\"left\" valign=\"top\">\r\n\t\t\t\t<table border=\"1\" width=\"200\" bordercolor=\"DAE2E8\" bgcolor=\"#FBFBFB\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t\t\t\t<tr><td> <a href=\"";
echo $chat_url;
echo "board_send.php?session=";
echo $session;
echo "&send_to_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Отправить сообщение</a></td></tr>\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&filter=general&uid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Друзья ";
echo $row['friend_name'];
echo "</a></td></tr>\r\n\t\t\t\t\t";
if ( $row['fid'] !== $is_regist_old )
{
$sql2 = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist_old."\") and (`fid`=\"".$row['fid']."\")";
if ( !( $result2 = mysql_query( $sql2 ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql2 );
}
$checkf = mysql_num_rows( $result2 );
if ( $checkf == 0 )
{
echo "\t\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=add&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Добавить в друзья</a></td></tr>\r\n\t\t\t\t\t";
}
else
{
echo "\t\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=delete&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Убрать из друзей</a></td></tr>";
}
}
echo "\t\t\t\t\t</table>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr></table>\r\n\t\t</td></tr>\r\n\t\t\t\t\t\t";
}
}
echo " </table>\r\n\t\t\t\t";
include( "header_end.php" );
break;
case "approval" :
set_variable( "uid" );
$uid = intval( $uid );
if ( $uid )
{
$is_regist_old = $is_regist;
$is_regist = $uid;
include( $ld_engine_path."users_get_object.php" );
}
else
{
echo "stop";
exit( );
}
$approval_friend = array( );
$approval_friend_id = array( );
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist."\")";
if ( !( $result_b = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
while ( ( $row_b = mysql_fetch_assoc( $result_b ) ) !== FALSE )
{
$sql = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist_old."\") and (`friend_name`=\"".$row_b['friend_name']."\")";
if ( !( $result_a = mysql_query( $sql ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql );
}
$row_a = mysql_fetch_assoc( $result_a );
if ( $row_a['friend_name'] )
{
array_push( &$approval_friend, $row_a['friend_name'] );
array_push( &$approval_friend_id, $row_a['fid'] );
}
}
$fcount = count( $approval_friend );
$itext = "друзей";
$itext_a = "общих";
$z = strlen( $fcount );
$c = str_split( $fcount );
$c = $c[$z - 1];
if ( $c == 1 )
{
$itext = "друг";
$itext_a = "общий";
}
if ( $c == 2 || $c == 3 || $c == 4 )
{
$itext = "друга";
}
if ( $fcount == 11 || $fcount == 12 || $fcount == 13 || $fcount == 14 )
{
$itext = "друзей";
}
$i = 0;
include( "header.php" );
echo "\t\t<b><font color=\"#FF783D\">У Вас с ";
echo $current_user->nickname;
echo " ";
echo $fcount;
echo " ";
echo $itext_a;
echo " ";
echo $itext;
echo " </font></b>\t\r\n\t\t\t\t<table width=\"100%\" border=\"1\" bordercolor=\"DAE2E8\" bgcolor=\"#F7F7F7\" cellspacing=\"4\" cellpadding=\"4\">\r\n\t\t\t";
foreach ( $approval_friend as $value )
{
++$i;
$row['friend_name'] = $value;
$row['fid'] = $approval_friend_id[$i - 1];
$photo = $chat_url."powmod/friends/img/nophoto.jpg";
if ( file_exists( $file_path."photos/".floor( $approval_friend_id[$i - 1] / 2000 )."/".$approval_friend_id[$i - 1].".big.jpg" ) )
{
$photo = $chat_url."photos/".floor( $approval_friend_id[$i - 1] / 2000 )."/".$approval_friend_id[$i - 1].".big.jpg";
}
echo "\t\t\t\t\t<tr><td bgcolor=\"#FFFFFF\">\r\n\t\t\t<table width=\"100%\"><tr><td width=\"100\" align=\"center\">\r\n\t\t\t\t\t\t<a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\">\r\n\t\t\t\t<img src=\"";
echo $photo;
echo "\" width=\"80\" border=\"0\"></a>\r\n\t\t\t<td align=\"left\" valign=\"top\" width=\"70%\">Ник: <a href=\"";
echo $chat_url;
echo "fullinfo.php?session=";
echo $session;
echo "&user_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">";
echo $row['friend_name'];
echo "</a>\r\n\t\t\t\t</td>\r\n\t\t\t<td width=\"250\" align=\"left\" valign=\"top\">\r\n\t\t\t\t<table border=\"1\" width=\"200\" bordercolor=\"DAE2E8\" bgcolor=\"#FBFBFB\" cellspacing=\"1\" cellpadding=\"1\">\r\n\t\t\t\t\t<tr><td> <a href=\"";
echo $chat_url;
echo "board_send.php?session=";
echo $session;
echo "&send_to_id=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Отправить сообщение</a></td></tr>\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&filter=general&uid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Друзья ";
echo $row['friend_name'];
echo "</a></td></tr>\r\n\t\t\t\t\t";
if ( $row['fid'] !== $is_regist_old )
{
$sql2 = "SELECT * FROM `".$mysql_prefix."friends` WHERE (`is_regist`=\"".$is_regist_old."\") and (`fid`=\"".$row['fid']."\")";
if ( !( $result2 = mysql_query( $sql2 ) ) )
{
exit( "Error: ".mysql_error." with query ".$sql2 );
}
$checkf = mysql_num_rows( $result2 );
if ( $checkf == 0 )
{
echo "\t\r\n\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=add&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Добавить в друзья</a></td></tr>\r\n\t\t\t\t\t";
}
else
{
echo "\t\t\t\t\t\t<tr><td> <a href=\"friends.php?session=";
echo $session;
echo "&act=delete&uid=";
echo $is_regist;
echo "&fid=";
echo $row['fid'];
echo "\" class=\"jsnavi2\">Убрать из друзей</a></td></tr>";
}
}
echo "\t\t\t\t\t</table>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t</tr></table>\r\n\t\t</td></tr>\r\n\t\t";
}
echo "\t\t</table>\r\n\t\t\t";
include( "header_end.php" );
}
mysql_close( );
?>
PHP:
<?
include($file_path."powmod/friends/config.php");
//Connect Mysql
mysql_connect($mysql_server,$mysql_username, $mysql_password) or die("<font color=#EF0202><b>Ошибка подключение к MySQL. Проверьте параметры</b></font>");
mysql_select_db($mysql_db) or die("<font color=#EF0202><b>Ошибка MySQL. Невозможно выбрать базу данных.</b></font>");
mysql_query('SET NAMES cp1251');
$sql = 'SELECT * FROM `'.$mysql_prefix.'friendrequests` WHERE (`fid`="'.$is_regist_old.'")';
$result = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
$frcount = mysql_num_rows($result);
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`fid`="'.$is_regist.'")';
$result_b = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
$frcheck = mysql_num_rows($result_b);
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`fid`="'.$is_regist.'") and (`is_regist`="'.$is_regist_old.'")';
$result_f = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
$frchecks = mysql_num_rows($result_f);
if($_GET['res']==2) {?>
<a name="fr"></a>
<table width="50%" border="1" bordercolor="FC8787" bgcolor="#FFD6D6" cellspacing="1" cellpadding="1">
<tr><td> <b>Друг удален из вашего списка друзей</b></td></tr></table><br><? }
if($_GET['res']==1) {?>
<a name="fr"></a>
<table width="50%" border="1" bordercolor="FFF265" bgcolor="#FFF8AC" cellspacing="1" cellpadding="1">
<tr><td> <b>Заявка на добавление в друзья подана</b></td></tr></table><br>
<? }
if($is_regist_old!=$is_regist) {
if($frchecks!==0) {?>
<? } else {?>
<? }
}?>
<br><br>
<table><tr>
<?php
include($ld_engine_path."rooms_get_list.php");
include($engine_path."users_get_list.php");
$is_regist=$user_id;
$usr_test = array();
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`is_regist`="'.$is_regist.'")';
$friends_online = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
$fr = 0;
if (count($users)>0) {
$in_room = array();
for($kk=0;$kk<count($room_ids);$kk++){
for ($i=0;$i<count($users);$i++){
$usr_test = explode("\t", $users[$i]);
$who_nickname = $usr_test[USER_NICKNAME];
$who_room = $usr_test[USER_ROOM];
if ($who_room == $room_ids[$kk]) {
$usr_test[USER_INVISIBLE] = intval(trim($usr_test[USER_INVISIBLE]));
if($usr_test[USER_INVISIBLE]) {
if($IsModer) $in_room[] = $who_nickname;
}
else $in_room[] = $who_nickname;
}
}
$rooms[$room_ids[$kk]]["in_room"] = $in_room;
}
while (($row = mysql_fetch_assoc($friends_online)) !== false ) {
$fexists=in_array($row['friend_name'], $in_room);
if($fexists) { $fr++; }
}
}
if ($fr>0) {
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`is_regist`="'.$is_regist.'") ORDER by id DESC';
$friends_online = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);?>
<td valign="top">
<table width="200" height="20" cellspacing="0" cellpadding="0">
<td width="16" align="center" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><img src="<? echo $chat_url;?>powmod/friends/img/br.gif"></td>
<td width="200" align="left" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><font color="#45688E"><b>Друзья онлайн</b>(<? echo $fr;?>)</td>
<td width="36" align="right" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><a href="<? echo $chat_url;?>powmod/friends/friends.php?session=<? echo $session;?>&filter=online&uid=<? echo $is_regist;?>" target="_blank">Все</a> </td></tr>
<tr><td colspan="3">
<table align="center"><tr>
<?
$i = 0;
while (($row = mysql_fetch_assoc($friends_online)) !== false ) {
$fexists=in_array($row['friend_name'], $in_room);
if($fexists) {
$i++;
$photo=$chat_url."powmod/friends/img/nophoto.jpg";
if(file_exists($file_path."photos/".floor($row['fid']/2000)."/".$row['fid'].".big.jpg")){
$photo=$chat_url."photos/".floor($row['fid']/2000)."/".$row['fid'].".big.jpg";}
?>
<td align="center" valign="bottom"><a href="<? $chat_url;?>/fullinfo.php?session=<? echo $session;?>&user_id=<? echo $row['fid'];?>" target="_blank"><img src="<? echo $photo;?>" width="65" border="0"><br><? echo $row['friend_name'];?></a></td>
<? if($i==3) echo "</tr><tr>"; }
if($i==6) break;
}
?>
</tr></table>
</td></tr>
</table></td>
<?}
if($frcheck>0) {
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`is_regist`="'.$is_regist.'") ORDER by id DESC LIMIT 6';
$friends = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);?>
<tr>
<td valign="top">
<table width="200" height="20" cellspacing="0" cellpadding="0">
<td width="16" align="center" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><img src="<? echo $chat_url;?>powmod/friends/img/br.gif"></td>
<td width="200" align="left" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><font color="#45688E"><b>Друзья</b>(<? echo $frcheck;?>)</td>
<td width="36" align="right" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><a href="<? echo $chat_url;?>powmod/friends/friends.php?session=<? echo $session;?>&filter=general&uid=<? echo $is_regist;?>" target="_blank">Все</a> </td></tr>
<tr><td colspan="3">
<table align="center"><tr>
<?
$i = 0;
while (($row = mysql_fetch_assoc($friends)) !== false ) {
$i++;
$photo=$chat_url."powmod/friends/img/nophoto.jpg";
if(file_exists($file_path."photos/".floor($row['fid']/2000)."/".$row['fid'].".big.jpg")){
$photo=$chat_url."photos/".floor($row['fid']/2000)."/".$row['fid'].".big.jpg";}
?>
<td align="center" valign="bottom"><a href="<? $chat_url;?>/fullinfo.php?session=<? echo $session;?>&user_id=<? echo $row['fid'];?>" target="_blank"><img src="<? echo $photo;?>" width="65" border="0"><br><? echo $row['friend_name'];?></a></td>
<? if($i==3) echo "</tr><tr>"; }?>
</tr></table>
</td></tr>
</table></td>
<?}
if($is_regist!=$is_regist_old) {
$approval_friend=array();
$approval_friend_id=array();
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`is_regist`="'.$is_regist.'")';
$result_b = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
while (($row_b = mysql_fetch_assoc($result_b)) !== false ) {
$sql = 'SELECT * FROM `'.$mysql_prefix.'friends` WHERE (`is_regist`="'.$is_regist_old.'") and (`friend_name`="'.$row_b['friend_name'].'")';
$result_a = mysql_query($sql) or die ("Error: ".mysql_error." with query ".$sql);
$row_a = mysql_fetch_assoc($result_a);
if($row_a['friend_name']) {
array_push($approval_friend, $row_a['friend_name']);
array_push($approval_friend_id, $row_a['fid']);
}
}
if(count($approval_friend)>0) {?>
<tr>
<td valign="top">
<table width="200" height="20" cellspacing="0" cellpadding="0">
<td width="16" align="center" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><img src="<? echo $chat_url;?>powmod/friends/img/br.gif"></td>
<td width="200" align="left" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><font color="#45688E"><b>Общие друзья</b>(<? echo count($approval_friend);?>)</td>
<td width="36" align="right" valign="center" background="<? echo $chat_url;?>powmod/friends/img/br.gif"><a href="<? echo $chat_url;?>powmod/friends/friends.php?session=<? echo $session;?>&filter=approval&uid=<? echo $is_regist;?>" target="_blank">Все</a> </td></tr>
<tr><td colspan="3">
<table align="center"><tr>
<?
$i = 0;
foreach($approval_friend as $value) {
$i++;
$photo=$chat_url."powmod/friends/img/nophoto.jpg";
if(file_exists($file_path."photos/".floor($approval_friend_id[$i-1]/2000)."/".$approval_friend_id[$i-1].".big.jpg")){
$photo=$chat_url."photos/".floor($approval_friend_id[$i-1]/2000)."/".$approval_friend_id[$i-1].".big.jpg";}
?>
<td align="center" valign="bottom"><a href="<? $chat_url;?>/fullinfo.php?session=<? echo $session;?>&user_id=<? echo $approval_friend_id[$i-1];?>" target="_blank"><img src="<? echo $photo;?>" width="65" border="0"><br><? echo $value;?></a></td>
<? if($i==3) echo "</tr><tr>";
if ($i==6) break; }?>
</tr></table>
</td></tr>
</table></td>
<?}
} ?>
</tr></table><br>
<? mysql_close(); ?>