<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
head([]);
//
//
$id = num($_GET['id']);
		$users = DB::$dbs->queryFetch('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', [$id]);
		if(empty($users['id'])): header('location: /profile/'.$user['id']); exit; endif;
//
//
echo logs();
//
//
//
if(isset($_GET['go_gift']) && $users['id'] != $user['id']){
//
//
if(isset($_GET['form'])){ 
// 
$gift = num($_POST['gift']); 
$text = text($_POST['text']); 
// 
$err = false; 
// 
if(mb_strlen($text) > 150){ 
err2("Слишком длинное сообщение"); 
$err = true; 
} 
//
//
$g_g = array('','10','10','10','20','20','20','30','30','30','40','40','40','60','60','60','90','90','90');
//
//
$gold = $g_g[$gift];
//
//
if($user['gold'] < $gold){ 
err2("У вас недостаточно золота"); 
$err = true; 
} 
//
// 
if($err == false){ 
//
//
$text_n = 'Вам отправили [url='.$sites.'/gift/?id='.$users['id'].'][color=#32cd32]подарок[/color][/url]';
DB::$dbs->query('INSERT INTO `notification` SET `text` = ?,`time` = ?,`id_user` = ?',array($text_n,time(),$users['id']));
//
//
DB::$dbs->query("INSERT INTO `gift` SET `time` = ?, `id_gift` = ?, `id_user` = ?, `id_ank` = ?, `text` = ?", array(time(),$gift,$user['id'],$users['id'],$text));
//
//
DB::$dbs->query('UPDATE `users` SET `gold` = `gold` - ? WHERE `id` = ? LIMIT 1', array($gold,$user['id']));
DB::$dbs->query('UPDATE `users` SET `notif` = ? WHERE `id` = ? LIMIT 1', array(1,$users['id']));
//
//
ok2("Подарок отправен"); 
header("location: ?id=".$users['id']); 
exit(); 
} 
header("location: ?id=".$users['id']."&go_gift"); 
exit(); 
} 
//
//
?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Отправить подарок - <a href="/profile/<?=$users['id'];?>"><u><?=$users['name'];?></u></a></span>
		        </center>
		        <div class="menu-us">
		            <center>Выберите подарок<div class="stats2"></div></center>
		        <form action = '?id=<?=$users['id'];?>&go_gift&form' method = 'post'>
		            
		            
		            
		            		      	    <table style="width:100%">
		            		      	        
<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/1.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 10 
<br>
<input type="radio" name="gift" value="1" checked="checked" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/2.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 10 
<br>
<input type="radio" name="gift" value="2" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/3.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 10 
<br>
<input type="radio" name="gift" value="3" />
</center>
</td>
</tr>


<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/4.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 20 
<br>
<input type="radio" name="gift" value="4" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/5.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 20 
<br>
<input type="radio" name="gift" value="5" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/6.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 20 
<br>
<input type="radio" name="gift" value="6" />
</center>
</td>
</tr>

<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/7.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 30 
<br>
<input type="radio" name="gift" value="7" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/8.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 30 
<br>
<input type="radio" name="gift" value="8" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/9.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 30 
<br>
<input type="radio" name="gift" value="9" />
</center>
</td>
</tr>

<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/10.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 40 
<br>
<input type="radio" name="gift" value="10" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/11.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 40 
<br>
<input type="radio" name="gift" value="11" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/12.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 40 
<br>
<input type="radio" name="gift" value="12" />
</center>
</td>
</tr>

<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/13.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 60 
<br>
<input type="radio" name="gift" value="13" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/14.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 60 
<br>
<input type="radio" name="gift" value="14" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/15.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 60 
<br>
<input type="radio" name="gift" value="15" />
</center>
</td>
</tr>

<tr>
<td style="width:33%">
<center>
<img src="/css/img/gift/16.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 90 
<br>
<input type="radio" name="gift" value="16" />
</center>
</td>
	
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/17.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 90 
<br>
<input type="radio" name="gift" value="17" />
</center>
</td>
		                
<td style="width:33%">
<center>
<img src="/css/img/gift/18.png" class="" width="60" height="60">
<br><img src="/css/img/gold.png"> 90 
<br>
<input type="radio" name="gift" value="18" />
</center>
</td>
</tr>

		            
		            </table>

		             
<textarea class="mail" name = 'text' id='message' placeholder='Сообщение не обязательно' maxlength = '5000'></textarea> 
<br>
		        </div>
		       <div class="stats2"></div>
		       <input type="submit" name="" class="butmin" value="Отправить"> 
</form> 

		        </div>
		        </div>
<?
//
//
foot([]);
exit();
}
//
//
//
                $coll = DB::$dbs->querySingle('SELECT COUNT(id) FROM `gift` WHERE `id_ank` = "'.$users['id'].'"');
		$num = 10;
		$total = intval(($coll - 1) / $num) + 1;
		$page = isset($_GET['page'])?intval($_GET['page']):1;
		if(empty($page) or $page < 0) $page = 1;
		if($page > $total) $page = $total;
		$start = $page * $num - $num; 

$sql = DB::$dbs->query("SELECT `id`,`id_user`,`id_ank`,`text`,`id_gift` FROM `gift` WHERE `id_ank` = '".$users['id']."' ORDER BY `time` DESC LIMIT $start, $num")->fetchAll(PDO::FETCH_BOTH);
		?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Подарки игрока - <a href="/profile/<?=$users['id'];?>"><u><?=$users['name'];?></u></a></span>
		        </center>

		<?
				if($coll == 0){
		?>
						   <div class="menu-not">У игрока еще нет подарков</div>  

		<?
		}
			foreach ($sql as $sqlls => $im): ?>

<div class="menu-us">
<div class="imgL">
<img src="/css/img/gift/<?=$im['id_gift'];?>.png" class="" width="40" height="40">
</div>
<font color="#999999">
<?=user_info($im['id_user']);?>
</font>
<br>
<font color="#777777">
<?=$im['text'];?>
</font>
<br>
</div>


			<?php endforeach;
			?>
			</div>
			<?
			echo page('?id='.$users['id'].'&',$page,$total); ?>


			</div>
<?
//
//
foot([]);
//
//
?>