<?php

define('_IN_JOHNCMS', 1);



$headmod = 'perevod';

$textl = 'Ball ulashish';

require_once ("../incfiles/core.php");

require_once ("../incfiles/head.php");



switch($act)

{

	default:

	if(empty($_GET['id']))

	{

		echo '<form method="POST" action="perevod.php?act=ok">';

		echo '<div class="gmenu">';

		echo 'Hozirda hisobingizda: <b>'.$datauser['balans'].'</b> ball mavjud!<br/>';

		echo 'Foydalanuvchini tanlash usulini tanlang:<br/>';

		echo ' 1: <input type="radio"  value="1" name="pos" checked="checked"/>';

		echo '<div class="fmenu">Foydalanuvchini tanlang:<br/>';

		echo '<select name="users">';

		echo '<option value="">---------------</option>';

		$sql = mysql_query("select `id`,`name` from `users`");

		while($res = mysql_fetch_array($sql))

		{

			echo '<option value="'.$res['id'].'">'.$res['name'].'</option>';

		}

		echo '</select></div>';

		echo ' 2: <input type="radio"  value="2" name="pos" />';

		echo '<div class="fmenu">Foydalanuvchi ID sini yoki NIK ini kiriting :<br/><input name="user"/></div>';

		echo 'Necha ball ulashmoqchisiz:<br/><input name="bal"/></div>';

		echo '<div class="menu"><input value="Ulashish" type="submit" name="submit"/></div></form>';

	}else{

		$sql = mysql_query("select `id`,`name` from `users` WHERE `id` = '".$id."' LIMIT 1;");

		if(mysql_num_rows($sql)!=="0")

		{

			$user = mysql_fetch_array($sql);

			echo '<form method="POST" action="perevod.php?act=ok&amp;id='.$user['id'].'">';

			echo 'Siz  <b>'.$user['name'].'</b> nomli foydalanuvchiga ball ulashmoqchisiz!<br/>';

			echo 'Ulashilinadigan ball miqdori:<br/><input name="bal"/><br/>';

			echo '<input value="Ulashish" type="submit" name="submit"/></form>';

		}

	}

	break;

	case "ok";

	if(empty($_GET['id']))

	{

		if(!empty($_POST['submit']))

		{

			if($_POST['pos'] == "1")

			{

                $user = isset($_POST['users'])?abs(intval($_POST['users'])):false;

			}elseif($_POST['pos'] == "2")

			{

                $user = isset($_POST['user'])?check($_POST['user']):false;

			}

			$ball = isset($_POST['bal'])?abs(intval($_POST['bal'])):false;

			$count = mysql_result(mysql_query("select COUNT(*) from `users` WHERE `id` = '".$user."' or `name` = '".$user."'"),0);

			if($count > 0 )

			{

				$arr = mysql_fetch_array(mysql_query("select `name`,`balans` from `users` WHERE `id` = '".$user."'  or `name` = '".$user."' LIMIT 1"));

				$q = mysql_fetch_array(mysql_query("select `name`,`balans` from `users` WHERE `id` = '".$user_id."' LIMIT 1"));

				if($q['balans'] >= 1 && $ball < $q['balans'])

				{

				 if($arr['name'] !== $q['name'])

				 {

                  if($ball > 1 && $ball < $q['balans'])

				  {

				$min_bal = intval($q['balans'] - $ball);

				$plus_bal = intval($arr['balans'] + $ball);

				mysql_query("update `users` set `balans` = '".$min_bal."' where `id` = '".$user_id."' LIMIT 1");

				mysql_query("update `users` set `balans` = '".$plus_bal."' where `id` = '".$user."'  or `name` = '".$user."' LIMIT 1");

				echo '<p>'.$ball.' ball, '.$arr['name'].' nomli foydalanuvchiga o`tdi!<br/>';

				echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

                  }else{

                    echo '<p>O`tkazishda xatolik!</p>';

                  }

				}else{

                    echo '<p>O`tkazishda xatolik!</p>';

				}

				}else{

					echo '<p>O`tkazishda xatolik!</p>';

				}

			}else{

				echo '<p><bFoydalanuvchi topilmadi</b><br/>';

				echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

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

				exit;

			}

		}else{

            echo '<p><b>Xatolik!!!</b><br/>';

		    echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

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

			exit;

		}

	}else{

        if(!empty($_POST['submit']))

		{

			$ball = isset($_POST['bal'])?abs(intval($_POST['bal'])):false;

			$count = mysql_result(mysql_query("select COUNT(*) from `users` WHERE `id` = '".$id."'"),0);

			if($count > 0 )

			{

				$arr = mysql_fetch_array(mysql_query("select `name`,`balans` from `users` WHERE `id` = '".$id."' LIMIT 1"));

				$q = mysql_fetch_array(mysql_query("select `name`,`balans` from `users` WHERE `id` = '".$user_id."' LIMIT 1"));

				if($q['balans'] >= 1 && $ball < $q['balans'])

				{

                 if($arr['name'] !== $q['name'])

				 {

				  if($ball > 1 && $ball < $q['balans'])

				  {

				$min_bal = intval($q['balans'] - $ball);

				$plus_bal = intval($arr['balans'] + $ball);

				mysql_query("update `users` set `balans` = '".$min_bal."' where `id` = '".$user_id."' LIMIT 1");

				mysql_query("update `users` set `balans` = '".$plus_bal."' where `id` = '".$id."' LIMIT 1");

				echo '<p>'.$ball.' ball, '.$arr['name'].' nomli foydalanuvchiga o`tkazildi!<br/>';

				echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

				  }else{

                    echo '<p>O`tkazishda xatolik!</p>';

				  }

				 }else{

                    echo '<p>O`tkazishda xatolik!</p>';

				}

				}else{

					echo '<p>O`tkazishda xatolik!</p>';

				}

			}else{

				echo '<p><b>Foydalanuvchi topilmadi!</b><br/>';

				echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

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

				exit;

			}

		}else{

            echo '<p><b>Xatolik!!!</b><br/>';

		    echo '<a href="perevod.php?r='.mt_rand(0000,9999).'">Ortga</a></p>';

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

			exit;

		}

	}

	break;

}



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

?>