<?php
include '../system/bd.php';
include '../system/cook.php';
include ("../system/gzip.php");
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include '../system/head.php';
include '../system/head1.php';
$req = mysql_query("SELECT * FROM `user` WHERE `id` = '$user[id]'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto=="0"){
echo'Ошибка 1';
include 'inc/nogi.php';
exit;
}
$us = mysql_fetch_array($req);
if(empty($us[clan])){
echo' <div class="title">Ошибка</div>
<div class="empty_block item_center"> Вы не состоите в банде! </div>';
echo'<div class="block_link">';
echo"<a href='../index.php'> <img src ='../img/images/arrow.png'> Вернуться</a></div>";
include '../system/foot.php';
exit;}
/////////////

if($us[clan]!="$clans[id]"){

$req = mysql_query("SELECT * FROM `clans` where `id`='$us[clan]' or `leader`='$us[clan]' ");

$req = mysql_query("SELECT * FROM `clans` where `id`='$us[clan]' or `leader`='$us[clan]' ");

$avto=mysql_num_rows($req);
if($avto==1){
$clan1 = mysql_fetch_array($req);
$req = mysql_query("SELECT `id` FROM `user` where `clan`='$clan1[id]'");



////////////////////////////
$kk=mysql_num_rows($req);


echo '' ;

switch($_GET[mod]){
default:

echo"<div class='title'>Казна</div>";
echo ' <div class="bor1"><div class="bor2"><div class="bor3"><div class="bor4"><div class="bor_bg item_center"> ';
echo"<center> 
<img src='../img/icon/gold.png' alt='*'/> ".number_format ($clan1[gold])." 
 <img src='../img/icon/silver.png' alt='*'/> ".number_format ($clan1[silver])."
</center>";
echo ' </div> </div> </div> </div></div>';


echo"<div class='empty_block'>
<img src='/img/icon/gold.png' alt='*'/> Золото: ".number_format ($clan1[gold])." [<a href='?mod=gold'>Пополнить</a>]
<br><img src='/img/icon/silver.png' alt='*'/> Серебро: ".number_format ($clan1[silver])." [<a href='?mod=silver'>Пополнить</a>] </div>";

echo'<div class="block_link">';
echo"<a href='clan.php?mod=adm'> <img src ='../img/images/arrow.png'> Вернуться</a></div>";
break;

case 'gold':
echo"<div class='title'>Казна</div>";
echo"<div class='empty_block item_center'>
<form method='post' action='?mod=gold_ok'>";
echo "Сколько ложим золота?
<br>
<input name='gold' maxlength='15' title='name'> 
<br/>";
echo "<input type='submit' value='Пополнить' class='button'></form> </div>";

echo"<div class='block_link'>
<a href='treasury.php'> 
<img src='../img/foot/index.png'> Вернуться</a></div>";


break;
case 'gold_ok':
if($_POST[gold]<=0){echo'Ошибка!';
header("Location: ?mod=gold");
exit;}
if(eregi("[^0-9]",$_POST[gold])){echo"Ошибка!";
header("Location: ?mod=gold");
exit;}
if($_POST[gold]>$user[gold]){
header("Location: ?mod=gold");
exit;}
$clan1[gold]=$clan1[gold]+$_POST[gold];
$clan_gold=$_POST[gold];

mysql_query("UPDATE `clans` SET `gold` = '$clan1[gold]' WHERE `id` = '$user[clan]' LIMIT 1");

mysql_query("UPDATE `user` SET `gold` = `gold` - '$_POST[gold]' WHERE `id` = '$user[id]' LIMIT 1");


$n='<img src="/pic/main/fermany.png" alt="*"/> фермани';
$n2='<a href=\"infa.php?id='.$account[id].'\">'.$account[login].'</a> пополнил общак на';
$time = date("H:i d.m.y");
mysql_query("INSERT INTO `banda_log` SET `banda`='$usdata[banda]',`msg`='$n2 <b>$_POST[kol]</b> $n <img src=\"pic/main/timeniz.png\">', `time` = '$time' ");

echo"<div class='title'>Казна</div>";
echo"
<div class='empty_block'> 
Казна пополнена на <b>$_POST[gold] 
</b> <img src='../img/icon/gold.png' alt='*'/> золота </div>";

echo"<div class='block_link'>
<a href='treasury.php'> <img src='../img/foot/index.png'> Вернуться </a></div>";

break;

case 'silver':
echo"<div class='title'>Казна</div>";
echo"<div class='empty_block item_center'>
<form method='post' action='?mod=silver_ok'>";
echo "Сколько ложим серебра?
<br>
<input name='silver' maxlength='15' title='name'> 
<br/>";
echo "<input type='submit' value='Пополнить' class='button'></form> </div>";

echo"<div class='block_link'>
<a href='treasury.php'> 
<img src='../img/foot/index.png'> Вернуться</a></div>";


break;
case 'silver_ok':
if($_POST[silver]<=0){echo'Ошибка!';
header("Location: ?mod=silver");
exit;}
if(eregi("[^0-9]",$_POST[silver])){echo"Ошибка!";
header("Location: ?mod=silver");
exit;}
if($_POST[silver]>$user[silver]){
header("Location: ?mod=silver");
exit;}
$clan1[silver]=$clan1[silver]+$_POST[silver];
$clan_gold=$_POST[silver];

mysql_query("UPDATE `clans` SET `silver` = '$clan1[silver]' WHERE `id` = '$user[clan]' LIMIT 1");

mysql_query("UPDATE `user` SET `silver` = `silver` - '$_POST[silver]' WHERE `id` = '$user[id]' LIMIT 1");


$n='<img src="/pic/main/fermany.png" alt="*"/> фермани';
$n2='<a href=\"infa.php?id='.$account[id].'\">'.$account[login].'</a> пополнил общак на';
$time = date("H:i d.m.y");
mysql_query("INSERT INTO `banda_log` SET `banda`='$usdata[banda]',`msg`='$n2 <b>$_POST[kol]</b> $n <img src=\"pic/main/timeniz.png\">', `time` = '$time' ");

echo"<div class='title'>Казна</div>";
echo"
<div class='empty_block'> 
Казна пополнена на <b>$_POST[silver] 
</b> <img src='../img/icon/silver.png' alt='*'/> серебра </div>";

echo"<div class='block_link'>
<a href='treasury.php'> <img src='../img/foot/index.png'> Вернуться </a></div>";

break;
             //////////




}
} else{
echo"Ошибка 3";
include '../system/foot.php';
exit;}
}
//////////////////

}else{
header ("Location: index.php"); exit;
}
include '../system/foot.php';
?>
