<?php

require_once 'core/system.php';

include 'core/func_smiles.php'; 


date_default_timezone_set('Europe/Moscow'); 





head('Подарки');



reg(); 

    $ney = int($_SESSION['bumm']); 
$rowi = $dbc->query("SELECT * FROM `users` WHERE `id`='".$ney."' LIMIT 1")->fetch_assoc(); 
   // if(!$rowi){  header("location:index.php");}

if(!empty($_GET['add'])){ 

    $vibor = int($_GET['add']); 

$gift= $dbc->query("SELECT * FROM `present` WHERE `id`='".$vibor."' LIMIT 1")->fetch_assoc(); 

if($user['gold']<$gift['gold']){ $_SESSION['message']="Недостаточно Золота"; header("location:?");exit;}
        
    $text = protect($_POST['text']);




$dbc->query("INSERT INTO `journal` SET `user_id`='".$ney."', `text`='<a href=\"pers.php?ank=".$user['id']."\">".$user['login']."</a> Прислал вам подарок, <br><a id=\"link_button\" href=\"user_gift.php?id=".$user['id']."\">Посмотреть</a>',




    `time`='".time()."'");
$dbc->query("UPDATE `users` SET `journal`=`journal`+1 WHERE `id`='".$ney."'"); 



$dbc->query("UPDATE `users` SET `gold`=`gold`-'".$gift['gold']."' WHERE `id`='".$user['id']."'");  
$dbc->query("INSERT INTO `present_us` SET
        `user_id`='".$ney."',
        `text`='".$text."',
        `time`='".time()."',
`name` ='".$gift['name']."'
,
`img` ='".$gift['img']."',
`kto` ='".$user['id']."'
"); 
}
if(isset($_GET['new'])){




$pres =$dbc->query("SELECT * FROM `present` WHERE `tip`=1");



while($present = $pres->fetch_assoc()){ 




?><div class="sblue-panel"><div class="panel-inner-3"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="37" style="vertical-align: top;"><img width="52"height="52" src="img/gift/<?=$present['img']?>.jpg" alt="."border="0" >







</td><td><div><center><?=$present['name']?> <img src="img/money/money.png"><?=$present['gold']?></center></div><span class="nowrap"></span> <span class="nowrap"></span><span class="clearer"></span></td><td width="60"><a href="/gif.php?go=<?=$present['id']?><??>&amp;pres" class="gr-btn center"><span>Подарить</span></a></td></td></tr></table></div></div><?



}




}
if(isset($_GET['pres']) and !empty($_GET['go'])){ 




    $pr_id = int($_GET['go']); 




$podarok = $dbc->query("SELECT * FROM `present` WHERE `id`='".$pr_id."' LIMIT 1")->fetch_assoc();


if(!$podarok){
        header("Location: gif.php");
        exit;
        } 

$komu = $dbc->query("SELECT * FROM `users` WHERE `id`=".$ney." LIMIT 1")->fetch_assoc();









?><div class="sblue-panel"><div class="panel-inner-3"><center>

Подарок Для :<img src="img/class/<?=$komu['storona']?>/<?=$komu['pers']?>/pers.png" width="14" height="14" alt="*"><b><a href="pers.php?ank=<?=$komu['id']?>"><?=$komu['login']?></b></a></br>


<img src="img/gift/<?=$podarok['img']?>.jpg"></br> Стоимость <img src="img/money/money.png"><?=$podarok['gold']?>









<script language='JavaScript' type='text/javascript'> 
function sml(html) { 
var e = document.getElementById('text'); 
if (e != null) { 
e.value += ' ' + html + ' '; 
e.focus(); 
} 
} 
function smiles() { 
var e = document.getElementById('smiles'); 
if (e != null) { 
if (e.style.display == 'block') e.style.display = 'none'; 
else e.style.display = 'block'; 
} 
} 
</script> 
<form action="gif.php?add=<?=$podarok['id']?>" method="post"> 


<textarea rows="2" cols="30" class="b-textarea" name="text" id="text" maxlength="256">
</textarea> 

<button id="submitSent" type="submit" class="gr- btn">Отправить</button> <a href="#" onclick="smiles();return false">Смайлы</a></div></div></center> <?



$smile_q = $dbc->query("SELECT * FROM `smiles` ORDER BY `id` ASC LIMIT 33"); 



 
?><div id="smiles" style="display:none;overflow: auto;max-height: 65px;"><? 


    while($smile = $smile_q->fetch_assoc()){ 
?><img onclick="sml('<?=$smile['value']?>')" src="/img/smiles/<?=$smile['img']?>" alt="<?=$smile['value']?>" /> 




<?
}



?></div><?



}
foot();
