<?php

include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
$set['title']='Действия';
include_once '../sys/inc/thead.php';
title();
err();

echo "<div class='textmes'>\n";
if(isset($user))
{
$int = intval(abs($_GET['id']));

if($int != null)
{
	$result = mysql_query("SELECT count(*) AS total FROM user WHERE id=$int");
    $total = mysql_fetch_array($result);
    $total = $total['total'];
	if($total == 0)
	{
		echo 'Такого пользователя не существует!';
		exit;
	}
}

if($int == null)
	{
		echo 'Такого пользователя не существует!';
		exit;
	}
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id`= $int LIMIT 1"));

echo 'Действия с : <a href="/info.php?id='.$ank['id'].'"><b><font color="red">'.$ank['nick'].'</font></b></a><br/>';

if ($ank['id']!=$user['id']) {

$k_dei=mysql_result(mysql_query("SELECT count(*) FROM `mod_dei_sp`"),0);
if($k_dei==0){echo '<select><option>Действий нет!</option></select><br/>';
}else{
$q=mysql_query("SELECT * FROM `mod_dei_sp` ORDER BY `price` ASC");
echo 'У вас <b><font color="green">'.$user['balls'].'</font></b> баллов.<font color="#FF00FF"> В скобках указана цена действия в баллах !</font><br/>';

echo'<form action="?id='.$ank['id'].'&amp;act=ok" method="post" name="form" >'; echo '<select name="go" />';
while($row=mysql_fetch_assoc($q)){
echo'<option value="'.$row['id'].'" >'.$row['name'].' ('.$row['price'].')</option>';
};
echo'</select><br/>';
echo '<input class="subbutton" type="submit" value="OK" />';
echo '</form>'; }; };  echo "</div>\n";
$act=htmlspecialchars(trim($_GET['act']));

switch ($act){

default:
$k_post=mysql_result(mysql_query("SELECT count(*) FROM `mod_dei_go` WHERE `uid`='".$ank['id']."' "),0);

echo "<table class='post'>";
$onpage=10;
$k_page=k_page($k_post,$onpage);
$page=page($k_page);
$start=$onpage*$page-$onpage;
if($k_post==0){echo 'С данным пользователем еще не совершали никаких действий!';break;};
$q=mysql_query("SELECT * FROM `mod_dei_go`  WHERE `uid`='".$ank['id']."' ORDER BY `id` DESC LIMIT $start, $onpage");



while($row=mysql_fetch_assoc($q)){
$id_dei=mysql_fetch_array(mysql_query("SELECT * FROM `mod_dei_sp` WHERE `id` = $row[id_dei] LIMIT 1"));
$a_n_k=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $row[go_uid] LIMIT 1"));
if($a_n_k['pol']==1)$pol=''.$id_dei['pol_m'].''; else $pol=''.$id_dei['pol_w'].'';
echo "<tr></div><td class='linechat'>";
echo '<img src="img/'.$id_dei['id'].'_'.$id_dei['img'].'"></img> <a href="/info.php?id='.$a_n_k['id'].'">'.$a_n_k['nick'].'</a> ';
if ($ank['balls']>=1000 && $ank['balls']<=4999){echo " <img src='/img/medal_bronze.gif' alt=''/>";
}else
if ($ank['balls']>=5000 && $ank['balls']<=9999){echo " <img src='/img/medal_bronze.gif' alt=''/> <img src='/img/medal_silver.gif' alt=''/>";
}else{
if ($ank['balls']>=10000)echo " <img src='/img/medal_bronze.gif' alt=''/> <img src='/img/medal_silver.gif' alt=''/> <img src='/img/medal_gold.gif' alt=''/>";}


if ($a_n_k['brak']!=NULL)echo "<img src='/style/icons/rings.gif' alt='' class='icon'/> \n";
if ($a_n_k['braks']!=NULL)echo "<img src='/style/icons/rings.gif' alt='' class='icon'/> \n";
if ($a_n_k['stran']==0)echo "\n";
if ($a_n_k['stran']==1)echo "<img src='/style/strana/ru.png'>\n";
if ($a_n_k['stran']==2)echo "<img src='/style/strana/ua.png'>\n";
if ($a_n_k['stran']==3)echo "<img src='/style/strana/by.png'>\n";
if ($a_n_k['stran']==4)echo "<img src='/style/strana/az.png'>\n";
if ($a_n_k['stran']==5)echo "<img src='/style/strana/kz.png'>\n";
if ($a_n_k['stran']==6)echo "<img src='/style/strana/uz.png'>\n";
if ($a_n_k['stran']==7)echo "<img src='/style/strana/england.png'>\n";
if ($a_n_k['stran']==8)echo "<img src='/style/strana/de.png'>\n";
echo '<br/><font color="#FF69B4"> '.$pol.'</font><br/><span style="float:right"><font color="#458B74"> '.date("d.m.y в H:i:s ",$row['date']).'';
echo "</font></span></td></tr>";
};
echo "</table>";

if ($k_page>1)str('?id='.$ank['id'].'&amp;',$k_page,$page);
break;
case 'ok' :

$go=(int)$_POST['go'];

if(!$go || $go<0){echo 'Пустые параметры!';break;};
$x=mysql_query("SELECT * FROM `mod_dei_sp` WHERE `id`='$go'");
if(!mysql_num_rows($x)){echo 'Такого действия не существует!';break;};
$x=mysql_fetch_assoc($x);
if($user['balls']<$x['price']){
echo' Недостаточно баллов!<br/>';
}else{
if($ank['id']==$user['id']){
echo'Себе делать действия запрещено!<br/>';
}else{
mysql_query("UPDATE `user` SET `balls`=`balls`-'".$x['price']."' WHERE `id`='".$user['id']."'");
if($user['pol']==1)$pol=''.$x['pol_m'].''; else $pol=''.$x['pol_w'].'';
mysql_query("INSERT INTO `mod_dei_go` (`uid`,`name`,`go_uid`,`date`,`id_dei`)VALUES('".$ank['id']."','".$pol."','".$user['id']."','".time()."','".$x['id']."')");

$pm_id='0';
if($user['pol']==1)$pol=''.$x['pol_m'].''; else $pol=''.$x['pol_w'].'';
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$ank[id]', ' [url=/info.php?id=$user[id]]$user[nick][/url] $pol ', '$time')");
header ("Location: /dei/?id=".$ank['id']."");
}; };
break;
};
echo '<div class="textmes"><img src="/style/back.gif" alt=""/> <a href="/info.php?id='.$ank['id'].'">Страничка</a></div>';
}
else echo '<div class="msg">Действия доступны только для авторизованых пользователей!</div>';
include_once '../sys/inc/tfoot.php';
?>