Файл: friends by SBeka/friend.php
Строк: 107
<?php
define('_IN_JOHNCMS', 1);
$headmod = 'anketa';
require_once('../incfiles/core.php');
require_once('../incfiles/head.php');
if (!$user_id) {
require_once('../incfiles/head.php');
echo display_error('Только для зарегистрированных посетителей');
require_once('../incfiles/end.php');
exit;
}
switch ($_GET['act']){
///////////////////////////////////////////////////////////////////////////////////
case 'zay_no':
$zayNoCount = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `friend_id`='".$user_id."' AND `zay`='no';"),0);
if ($zayNoCount != 0) {
$zayNo = mysql_query("SELECT * FROM `friends` WHERE `friend_id`='".$user_id."' AND `zay`='no';");
echo '<div class="info">Вам предлагают дружбу:</div>';
while ($zayNoArray = mysql_fetch_array($zayNo)) {
$friendInfo = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='".$zayNoArray['user_id']."';"));
echo '<div class="menu"><center><a href="anketa.php?id='.$friendInfo['id'].'">'.$friendInfo['name'].'</a><br/> <small>'.$zayNoArray['date'].'</small><hr/><a class="button" href="friend.php?act=actionYes&id='.$zayNoArray['id'].'">Принять</a> <a class="redton" href="friend.php?act=actionNo&id='.$zayNoArray['id'].'">Отклонить</a>
</center><br/></div>';
}
} else {echo '<div class="menu"><div class="warning">Вам не никто предлагал дружбу</div><a href="../index.php">Назад</a></div>';}
break;
///////////////////////////////////////////////////////////////////////////////////
case 'actionYes':
$id = $_GET['id'];
if (!empty($id)) {
$friendsArray = mysql_fetch_array(mysql_query("SELECT * FROM `friends` WHERE `id`='".$id."' ;"));
$friendsInsert = mysql_query("INSERT INTO `friends` (`id`, `user_id`, `friend_id`, `zay`, `date`) VALUES (NULL, '".$friendsArray['friend_id']."', '".$friendsArray['user_id']."', 'yes', '".date('d.m.y | H.i.s')."');");
mysql_query("UPDATE `friends` SET `zay` = 'yes' WHERE `id` = '".$id."';");
header('Location: friend.php?act=zay_no');
} else {header('Location: ../index.php');}
break;
///////////////////////////////////////////////////////////////////////////////////
case 'sendPr':
$id = $_GET['id'];
if (!empty($id)) {
mysql_query("INSERT INTO `friends` (`id`, `user_id`, `friend_id`, `zay`, `date`) VALUES (NULL, '".$user_id."', '".$id."', 'no', '".date('d.m.y | H.i.s')."');");
echo '<div class="menu"><div class="warning">Заявка на дружбу успешно отправлен!</div><a href="anketa.php?id='.$id.'">Назад</a></div>';
} else {header('Location: ../index.php');}
break;
///////////////////////////////////////////////////////////////////////////////////
case 'actionNo':
$id = $_GET['id'];
if (!empty($id)) {
mysql_query("DELETE FROM `friends` WHERE `id` = '".$id."' LIMIT 1 ;");
header('Location: anketa.php?id='.$user_id.'');
} else {header('Location: ../index.php');}
break;
///////////////////////////////////////////////////////////////////////////////////
case 'all_fr':
$id = $_GET['id'];
if (!empty($id)) {
$userInfo2 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='".$id."';"));
$sqlFriends = mysql_query("SELECT * FROM `friends` WHERE `user_id`='".$id."' AND `zay`='yes' ORDER BY date DESC ;");
echo '<div class="info">Друзья пользователя <strong>'.$userInfo2['name'].'</strong></div>';
echo '<div class="menu">';
while ($friendsArray = mysql_fetch_array($sqlFriends)) {
$userInfo = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='".$friendsArray['friend_id']."';"));
echo '<table width="100%">
<tr>
<td width="15%">';
if (file_exists(('../files/photo/' . $userInfo['id'] . '.jpg'))){
echo'<div style="text-align:center"><p><img style="border-radius:5px;" src="../files/photo/' . $userInfo['id'] . '.jpg" width="80px" height="80px"/></p></div>';
}else{
echo'<div style="text-align:center"><p><img style="border-radius:5px;" src="../files/photo/nophoto.jpg" width="80px" height="80px"/></p></div>';}
echo '</td>
<td width="85%">';
echo '<b><a href="anketa.php?id='.$friendsArray['friend_id'].'">'.$userInfo['name'].'</a></b>';
echo '<hr/><a href="pradd.php?act=write&adr='.$userInfo['id'].'">Отправить сообшение</a></td>
</tr>
</table><hr/>';}
echo '</div>';
} else {header('Location: ../index.php');}
break;
default :
break;
}
require_once('../incfiles/end.php');
?>