Размер файла: 3.66Kb
<?php
include 'sys/db.php';
include 'sys/conf.php';
include 'sys/start.php';
include 'sys/functions.php';
$config_title_name = "Мои друзья";
include 'style/head.php';
$friendtest = mysql_fetch_array(mysql_query("SELECT * FROM `friends` WHERE `user`='$user[id]' AND `friend`='$user_info[id]'"));
if(isset($user['login'])){
$act = isset($_GET['act']) ? $_GET['act'] : '';
switch($act){
default:
echo "<div class=title>Мои друзья</div>";
echo "<div class=content>\n";
if ($_GET['isset']==there) {echo "Ошибка добавления в друзья!<hr>\n";}
if ($_GET['isset']==yes) {echo "Пользователь успешно добавлен в друзья!<hr>\n";}
if ($_GET['isset']==yesdel) {echo "Пользователь успешно удален из друзей!<hr>\n";}
function pages($start, $total, $page, $onpage){
if ($start != 0) echo '<a href="'.$page.'?start='.($start - $onpage).'"><-Назад</a> ';
else echo '<-Назад';
echo ' | ';
if ($total > $start + $onpage)
echo ' <a href="'.$page.'?start='.($start + $onpage).'">Далее-></a>';
else echo 'Далее->';}
$total = mysql_result(mysql_query("SELECT COUNT(*)FROM `friends` WHERE `user` = '$user[id]' "),0);
$start = isset($_GET['start']) ? abs((int)$_GET['start']) : 0;
if($start > $total) $start = 0;
if ($total < $start + 10) $end = $total;
else $end = $start + 10;
$friends = mysql_query("SELECT * FROM `friends` WHERE `user` = '$user[id]' ORDER BY `id` DESC LIMIT $start, 10");
if(mysql_num_rows($friends) != 0){
while($fr = mysql_fetch_array($friends)){
$frend = mysql_query("SELECT login,gender FROM `users` WHERE `id` = '$fr[friend]'");
if($freuser = mysql_fetch_array($frend)){
echo "<div class=box>";
if ($freuser['gender']==1)echo "<img src='img/man.gif' alt=''> ";
elseif ($freuser['gender']==2)echo "<img src='img/woman.gif' alt=''> ";
echo "<a href='anketa.php?id=".$fr['friend']."'>".$freuser['login']."</a> ";
if ($authortime > time()-600) {
echo " <img src='img/on.gif' alt=''>";
}else{
echo " <img src='img/off.gif' alt=''>";}
echo "</div>\n";
echo "<a href='mail.php?add=".$fr['friend']."'>Написать</a> |
<a href='?act=del&id=".$fr['id']."'>Удалить</a> |
<a href='ignore.php?act=add&id=".$fr['friend']."'>Игнор</a>\n";
}}
}else{ echo "<br><img src='img/error.gif' alt=''> У вас нет друзей!<br><br>\n";}
echo "</div>\n";
echo "<div class=stat>\n";
pages($start, $total, 'friends.php', 10);
echo "</div>\n";
echo "<div class=stat><a href='index.php'>Прихожая</a>\n";
echo "</div>\n";
break;
case('add'):
$id = intval($_GET['id']);
if ($id != '0') {
$testing = mysql_fetch_array(mysql_query("SELECT * FROM `friends` WHERE `user`='$user[id]' AND `friend`='$id'"));
if($testing != '0'){header ("Location: ?isset=there"); exit;}
$time = time();
$testing = mysql_fetch_array(mysql_query("SELECT * FROM `ignore` WHERE `user`='$user[id]' AND `ignor`='$id'"));
if($testing != '0'){mysql_query("DELETE FROM `ignore` WHERE id='$testing[id]'");}
mysql_query ("INSERT INTO `friends` (user,friend,time) VALUES ('$user[id]','$id','$time')");
header ("Location: friends.php?isset=yes"); exit;
}else{ header ("Location: friends.php?isset=there"); exit;}
break;
case('del'):
$id = intval($_GET['id']);
if ($id != '0') {
$delete = mysql_query("SELECT * FROM `friends` WHERE `id` = '$id'");
if($del = mysql_fetch_array($delete)){
if ($user[id] == $del[user]){
mysql_query("DELETE FROM `friends` WHERE id='$id'");
}else{ header ("Location: friends.php?isset=there"); exit;}
}
header ("Location: friends.php?isset=yesdel"); exit;
}else{ header ("Location: friends.php?isset=there"); exit;}
break;
}
}else{ header ("Location: index.php"); exit;}
include 'style/foot.php';
?>