<?php

define('_IN_JOHNCMS', 1);

$headmod = 'manager';
$textl = 'Bank';
require_once ("../incfiles/core.php");
require_once ("../incfiles/head.php");

        if (!$user_id) {
            echo display_error('Faqat ro`yhatdan o`tganlar uchun');
            exit;
        }
$user=$datauser; //Все данные о пользователе

echo '<b><font color="red">Almashtirish punkti</font></b><br/>'; //Название 


$action=htmlspecialchars(trim($_GET['action']));

////////////////////////////////////////////////////////////////
// Всё что ниже до brake; это форма и приветствие там 
//ничего изменять не надо                                      
///////////////////////////////////////////////////////////////

switch ($action){

default:
echo 'Salom, menejer '.$user['name'].'!<br/>';
echo 'Sizda <b>'.$user['balans'].'</b> sayt ballari bor!<br/>';
$budj = mysql_fetch_array(mysql_query("SELECT `budj` FROM `fman_clubs` WHERE `user_id`='".$user_id."'"));
echo 'Jamoadagi mablag`: <b>'.$budj['budj'].'</b><br/>';  
echo 'Ballarni 1 ball = 1000$ kursi bo`yicha mablag`ga almashtirish <br/>';
echo '<form action="bank.php?action=change" method="post">';
echo 'Qancha ballarni almashtirishni hohlaysiz:<br/>';
echo '<input name="num" type="text" value=""/><br/>';
echo '<input type="submit" value="Almashtirish"/>';
echo '</form>';
break;

case 'change':
$num=(int)$_POST['num'];
if(!$num || $num<1){echo 'Bo`sh ko`rsatkichlar!';break;};
if($user['balans']<$num){echo 'Sizda shuncha ball yo`q!';break;};
$baks=$num*1000;
$ball=$num; 
mysql_query("UPDATE `users` SET `balans`=`balans`-'$ball' WHERE `id`='".$user_id."'");
mysql_query("UPDATE `fman_clubs` SET `budj`=`budj`+'$baks' WHERE `user_id`='".$user_id."'");
echo 'Ijobiy! siz '.$ball.' ballni '.$baks.'$ ga jamoa mablag`iga almashtirdingiz';
break;

case 'money_balans':


echo 'Salom, menejer '.$user['name'].'!<br/>';
echo 'Sizda <b>'.$user['balans'].'</b> sayt ballari bor!<br/>';
$budj = mysql_fetch_array(mysql_query("SELECT `budj` FROM `fman_clubs` WHERE `user_id`='" . $user_id . "'"));
echo 'Jamoadagi mablag`: <b>'.$budj['budj'].'</b><br/>';  
echo 'Mablag`ni 2000$ = 1 ball kursi bo`yicha ballarga almashtirish<br/>';
echo '<form action="bank.php?action=change1" method="post">';
echo 'Qancha mablag`ni almashtirishni hohlaysiz:<br/>';
echo '<input name="num" type="text" value=""/><br/>';
echo '<input type="submit" value="Almashtirish"/>';
echo '</form>';
break;


case 'change1':

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

if(!$num || $num<1){echo 'Bo`sh ko`rsatkichlar!';break;};
$budj = mysql_fetch_array(mysql_query("SELECT `budj` FROM `fman_clubs` WHERE `user_id`='" . $user_id . "'"));
if($budj['budj']<$num){echo 'Sizda bunday mablag` yo`q!';break;};

$baks=$num/2000;  
mysql_query("UPDATE `users` SET `balans`=`balans`+'$baks' WHERE `id`='".$user_id."'");
mysql_query("UPDATE `fman_clubs` SET `budj`=`budj`-'$num' WHERE `id`='".$user_id."'");
echo 'Ijobiy!';
break;

};
echo '<div class="msg"><a href="index.php">Menejerga</a></div>';


require_once ("../incfiles/end.php");   
?>