<?php
require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick'])))  {
  ?>
  <script type="text/javascript">
  document.location.href = "reg.php";
  </script>
  <?php
  exit();
}

$user_id = $_SESSION['id'];
$user=abs(intval($_GET['user']));
$query_dfr1 = "Select monet from users where id='$user_id'";
$result_dfr1 = mysqli_query($dbc, $query_dfr1) or die ('Ошибка передачи запроса к БД');
$row_dfr1 = mysqli_fetch_array($result_dfr1);
$query_dfr2 = "Select nick from users where id='$user'";
$result_dfr2 = mysqli_query($dbc, $query_dfr2) or die ('Ошибка передачи запроса к БД');
$row_dfr2 = mysqli_fetch_array($result_dfr2);
if($user==$user_id){
header("Location: user.php?id=".$user_id."");
exit();
}

if(isset($_GET['gift'])){
if($user_id==$user){
header("Location: prezents.php?user=".$user."&err=1");
exit();
}
if($row_dfr1['monet']<'10'){
header("Location: prezents.php?user=".$user."&err=2");
exit();
}

$gift=abs(intval($_GET['gift']));
$query_us11 = "Select * from prezents where id ='$gift' order by id DESC";
$result_us11 = mysqli_query($dbc, $query_us11) or die ('Ошибка передачи запроса к БД');
$row_us11 = mysqli_fetch_array($result_us11);
$img_gif = $row_us11['img'];
$say = $_POST['msg'];
$query_add_ch = "insert into prezents_us (`user`, `komy`, `time`, `img`, `komment`) values ('$user_id', '$user', NOW(), '$img_gif', '$say')";
$result_add_ch = mysqli_query($dbc, $query_add_ch) or die ('Ошибка передачи запроса к БД');
$query1111 = "update users set podarok=podarok+'1' where id = '$user' ";
$result1111 = mysqli_query($dbc, $query1111) or die ('Ошибка передачи запроса к БД3');
$query = "update users set monet=monet-'10' where id = '$user_id' ";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД4');
header("Location: prezents.php?user=".$user."");
exit();
}
$page_title = 'Подарить подарок';
require_once('conf/head.php');
require_once('conf/top.php');
?><div class="name1"><center>Подарить подарок игроку <a style="text-decoration:none" href="/user.php?id=<?=$user;?>"><?=$row_dfr2['nick'];?></a></center></div><?
if($_GET['err']=='1'){?><span class="red">Нельзя отправлять подарки самому себе!</span><?php }
if($_GET['err']=='2'){?><span class="red">У вас не достаточно баксов!</span><?php }?>
<div style="border: 2px solid #303030; border-radius: 6px; background: #202020 url(../img/dark22.png);">
<?php
if(isset($_GET['tip'])){
    $query_us = "Select * from prezents where tip ='$_GET[tip]' order by id DESC";
$result_us = mysqli_query($dbc, $query_us) or die ('Ошибка передачи запроса к БД');
$row_us1 = mysqli_num_rows($result_us);
?>
<div class="cat_top radius_right">
<div class="cat_up radius">Всего [<?=$row_us1;?>]</div>
</div>
<div class="cat_bottom radius_down">

<?

while ($row_us = mysqli_fetch_array($result_us)) {?>
	<p>
<img  src="/mail_podarki/gifts/<?php echo $row_us['img']; ?>.png"> 
<a href="?user=<?=$user;?>&tip=<?=$_GET['tip'];?>&id=<?=$row_us['id'];?>" style=" display: inline-block;
 vertical-align: middle;
 background-color: #333;
 background-image: -webkit-linear-gradient(top,#555,#333);
 background-image: -moz-linear-gradient(top,#555,#333);
 background-image: -ms-linear-gradient(top,#555,#333);
 background-image: -o-linear-gradient(top,#555,#333);
 background-image: linear-gradient(top,#555,#333);
 border: 0px solid gainsboro;
 border: 0px solid rgba(0, 0, 0, 0.1);
 border-radius: 3px;
 color: #bcbcbc; text-shadow: 1px 0px 0px #222;
 cursor: pointer;
 font-size: 10px; 
 font-weight: bold; 
width:90px;

  line-height: 15px; 
 margin: 2px;
 padding:5 5px; 
 text-align: center;
 text-decoration:none">Подарить</a>
</form>  <span style="float: right;"><font color="gold"><i>10<img src="/img/ico/coin.png" width="12" height="12"/> баксов</i></font></span>
</a></p>

<?
if($_GET['id']==$row_us['id']){
?><p><center>Коментарий к подарку</center></p>
<form enctype="multipart/form-data" method="post" action="prezents.php?user=<?php echo $user; ?>&gift=<?php echo $row_us['id']; ?>" name="message">
<textarea rows="2" style="width:98%; height:60px;" cols="35px" name="msg" autofocus required></textarea>
<div class="knopka">
<center><input type="submit" class="input" value="Отправить" name="addad" accesskey="ы"/></center>
</div>
</form> 
<?
}
?>
<div class="line red"></div>
<?php }
?></div><?
}
?><div class="menu" style="border:0px">
<table width='100%' border='0' cellpadding='1' cellspacing='1'>
<tr>
<td width="10%" style="border: 1px solid #000000; background: #111">
<center><img src="/mail_podarki/gifts/25.png" width="25px" /></center>
</td> 
<td width="90%" style="border: 1px solid #000000; background: #212121 url(/style/img/line.png);">
<a href="?user=<?=$user;?>&tip=0" class="linkw"> Романтика</a>
</td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1'>
<tr>
<td width="10%" style="border: 1px solid #000000; background: #111">
<center><img src="/mail_podarki/gifts/11.png" width="25px" /></center>
</td> 
<td width="90%" style="border: 1px solid #000000; background: #212121 url(/style/img/line.png);">
<a href="?user=<?=$user;?>&tip=1" class="linkw"> Дружба</a>
</td>
</tr>
</table>
<table  width='100%' border='0' cellpadding='1' cellspacing='1'>
<tr>
<td width="10%" style="border: 1px solid #000000; background: #111" >
<center><img src="/mail_podarki/gifts/20.png" width="25px" /></center>
</td> 
<td width="90%" style="border: 1px solid #000000; background: #212121 url(/style/img/line.png);">
<a href="?user=<?=$user;?>&tip=2" class="linkw"> Праздники</a>
</td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1'>
<tr>
<td width="10%" style="border: 1px solid #000000; background:#111">
<center><img src="/mail_podarki/gifts/51.png" width="25px" /></center>
</td> 
<td width="90%" style="border: 1px solid #000000; background: #212121 url(/style/img/line.png);">
<a href="?user=<?=$user;?>&tip=3" class="linkw"> Спорт</a>
</td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1'>
<tr>
<td width="10%" style="border: 1px solid #000000; background:#111">
<center><img src="/mail_podarki/gifts/55.png" width="25px" /></center>
</td> 
<td width="90%" style="border: 1px solid #000000; background: #212121 url(/style/img/line.png);">
<a href="?user=<?=$user;?>&tip=4" class="linkw"> Новый год</a>
</td>
</tr>
</table></div>
<?
require_once('conf/navig.php');
require_once('conf/foot.php');
?>
</div>
</body>
</html>