View file element_town_treas.php

File size: 12.72Kb
<?php
require_once './element_options/element_options.php';
if (!$user) { header('Location: /'); exit; }

	if (!$id) {
	$title = 'Город не найден';
	$error1 = '<span class="small">Выбранный Вами город не существует, либо был удален</span>';
	require_once 'element_error_page.php';
	exit;
	}
	
	if ($id != $user['lost_town'] AND $user['lost_privilege'] != 3) {
	$title = 'Доступ закрыт';
	$error1 = '<span class="small">Администрация ограничила доступ к этой странице</span>';
	require_once 'element_error_page.php';
	exit;
	}
	
	$cache_town = cache_town($id);
	
	if (!$cache_town) {
	$title = 'Город не найден';
	$error1 = '<span class="small">Выбранный Вами город не существует, либо был удален</span>';
	require_once 'element_error_page.php';
	exit;
	}
	
	
	$title = 'Казна "'.$cache_town['lost_name'].'"';
	require_once './element_include/element_head.php';
	require_once './element_include/element_header_user_true.php';
	
	if ($go == 'add') {
	$treas_gold = (isset($_POST['treas_gold']) AND is_numeric($_POST['treas_gold'])) ? (int)$_POST['treas_gold'] : 0;
	$treas_crist = (isset($_POST['treas_crist']) AND is_numeric($_POST['treas_crist'])) ? (int)$_POST['treas_crist'] : 0;
	$treas_iridiy = (isset($_POST['treas_iridiy']) AND is_numeric($_POST['treas_iridiy'])) ? (int)$_POST['treas_iridiy'] : 0;
	
	if ($treas_gold == 0 AND $treas_crist == 0 AND $treas_crist == 0) $error = '<div class="red">Поля введены неверно</div>';
	if ($user['lost_money_gold'] < $treas_gold) $error = '<div class="red">Вам не хватает <img src="/images/icons/gold.png"><span class="bold">'.nmb_2(($treas_gold - $user['lost_money_gold'])).'</span> золота</div>';
	if ($user['lost_resourse_cristalls'] < $treas_crist) $error .= '<div class="red">Вам не хватает <img src="/images/icons/cristall.png"> <span class="bold">'.nmb_2(($treas_crist - $user['lost_resourse_cristalls'])).'</span> кристаллов</div>';
	if ($user['lost_resourse_irridyi'] < $treas_iridiy) $error .= '<div class="red">Вам не хватает <img src="/images/icons/irridyi.png"> <span class="bold">'.nmb_2(($treas_iridiy - $user['lost_resourse_irridyi'])).'</span> ирридия</div>';
	
	// http://m.xsolla.com/?id_project=11062&pid=27&out=100&currency=RUR&v1=1&local=ru
	// http://m.xsolla.com/?id_project=11062&pid=27&out=100&currency=RUR&v1=1&local=ru
	
	if ($treas_gold < 0 OR $treas_crist < 0 OR $treas_iridiy < 0) $error = '<div class="red">Поля введены неверно</div>';
	
		if (!isset($error)) {
			$treas_user = mysql_fetch_array(mysql_query("SELECT * FROM `element_town_treas` WHERE `lost_town` = '$id' AND `lost_user` = '$user[lost_id]' LIMIT 1"));
			
			if ($treas_user) {
			$treas_user['lost_gold'] = $treas_user['lost_gold'] + $treas_gold;
			$treas_user['lost_crist'] = $treas_user['lost_crist'] + $treas_crist;
			$treas_user['lost_irridiy'] = $treas_user['lost_irridiy'] + $treas_iridiy;
			
			$cache_town['lost_treas_gold'] = $cache_town['lost_treas_gold'] + $treas_gold;
			$cache_town['lost_treas_crist'] = $cache_town['lost_treas_crist'] + $treas_crist;
			$cache_town['lost_treas_iridiy'] = $cache_town['lost_treas_iridiy'] + $treas_iridiy;
			
			mysql_query("UPDATE `element_town_treas` SET `lost_gold` = '$treas_user[lost_gold]',
														 `lost_crist` = '$treas_user[lost_crist]',
														 `lost_irridiy` = '$treas_user[lost_irridiy]'
														  WHERE `lost_town` = '$id' AND `lost_user` = '$user[lost_id]' LIMIT 1");
			writecache('element_town_id_'.$id,$cache_town);
			
			$statistika_user = 'Время: '.rdate("Y год, d M H:i", time()).'<br/>
				Сдача ресурсов в казну города: <img src="/images/icons/gold.png">'.$treas_gold.' золота, <img src="/images/icons/cristall.png"> '.$treas_crist.' кристаллов, <img src="/images/icons/irridyi.png"> '.$treas_iridiy.' ирридия';
				
			
			update_money_exp($user, 0, -$treas_crist, -$treas_iridiy, -$treas_gold);
			user_list_update($user['lost_id']);	
			town_list_update($id);
			header('Location: /town/treas?id='.$id.'&go=result&g='.$treas_gold.'&c='.$treas_crist.'&i='.$treas_iridiy);
			exit;
			} else {
			$cache_town['lost_treas_gold'] = $cache_town['lost_treas_gold'] + $treas_gold;
			$cache_town['lost_treas_crist'] = $cache_town['lost_treas_crist'] + $treas_crist;
			$cache_town['lost_treas_iridiy'] = $cache_town['lost_treas_iridiy'] + $treas_iridiy;
			
			mysql_query("INSERT INTO `element_town_treas` SET `lost_town` = '$id',
															  `lost_user` = '$user[lost_id]',
															  `lost_gold` = '$treas_gold',
															  `lost_crist` = '$treas_crist',
														      `lost_irridiy` = '$treas_iridiy'");
			writecache('element_town_id_'.$id,$cache_town);
			
			$statistika_user = 'Время: '.rdate("Y год, d M H:i", time()).'<br/>
				Сдача ресурсов в казну города: <img src="/images/icons/gold.png">'.$treas_gold.' золота, <img src="/images/icons/cristall.png"> '.$treas_crist.' кристаллов, <img src="/images/icons/irridyi.png"> '.$treas_iridiy.' ирридия';
				
			
			update_money_exp($user, 0, -$treas_crist, -$treas_iridiy, -$treas_gold);
			user_list_update($user['lost_id']);	
			town_list_update($id);
			header('Location: /town/treas?id='.$id.'&go=result&g='.$treas_gold.'&c='.$treas_crist.'&i='.$treas_iridiy);
			exit;
			}
		
		} else echo '<div class="nfl small p5 mb5 small cntr mlra">'.$error.'</div>';
	}
	
	if ($go == 'result') {
	$gold = (isset($_GET['g']) AND is_numeric($_GET['g'])) ? (int)$_GET['g'] : 0;
	$cris = (isset($_GET['c']) AND is_numeric($_GET['c'])) ? (int)$_GET['c'] : 0;
	$irid = (isset($_GET['i']) AND is_numeric($_GET['i'])) ? (int)$_GET['i'] : 0;
		
		if ($gold > 0 OR $cris > 0 OR $irid > 0) {
		echo '<div class="nfl small p5 mb5 small cntr mlra">';
		echo '<span class="lngreen">Вы пополнили казну города на: ';
		echo ($gold > 0) ? '<img src="/images/icons/gold.png">'.$gold.' ' : '';
		echo ($cris > 0) ? '<img src="/images/icons/cristall.png"> '.$cris.' ' : '';
		echo ($irid > 0) ? '<img src="/images/icons/irridyi.png"> '.$irid.' ' : '';
		echo '</span></div>';
		}
	
	}
	
	
	echo '<div class="nfl p5 mb5 mlra small">';	
	echo '<div class="yellow1 mb5 cntr"><a href="/town?id='.$id.'">Вернуться в город</a></div>';
	
		echo '<div class="white mb5 mt5 cntr">';
		echo 'Казна города: <img src="/images/icons/gold.png"><span class="yellow1">'.nmb_2($cache_town['lost_treas_gold']).'</span>, ';
		echo '<img src="/images/icons/cristall.png"> <span class="yellow1">'.nmb_2($cache_town['lost_treas_crist']).'</span>, ';
		echo '<img src="/images/icons/irridyi.png"> <span class="yellow1">'.nmb_2($cache_town['lost_treas_iridiy']).'</span>';
		echo '</div><div class="line"></div>';
	
		if ($go == 'rating_gold') {
		$query = mysql_query("SELECT `lost_user`,`lost_gold` FROM `element_town_treas` WHERE `lost_town` = '$id' AND `lost_gold` > '0' ORDER BY `lost_gold` DESC");
		$i = 0;
		echo '<div class="mt5 yellow1 mb5 cntr">Статистика по золоту<br/><a href="/town/treas?id='.$id.'&go=rating_crist">Статистика по кристаллам</a><br/><a href="/town/treas?id='.$id.'&go=rating_irridiy">Статистика по ирридию</a></div>';
		
			while($myrrow = mysql_fetch_array($query)) {
			$i++;
			$cache_user = cache_user($myrrow['lost_user']);
			$odd = ($i % 2) ? ' odd' : '';
			echo '
			<div class="ml5 mr5">
				<a class="bl p5 small block'.$odd.'" href="/user?id='.$myrrow['lost_user'].'">
				<span class="white small fr"><img src="/images/icons/gold.png">'.nmb_2($myrrow['lost_gold']).'</span>
					'.$i.'. '.ikonka_user($cache_user['lost_race'], ((!empty($online[$myrrow['lost_user']])) ? 'online' : 'offline')).' <span class="yellow1">'.$cache_user['lost_login'].'</span>	
				</a>
			</div>
			';
			
			}
			if ($i == 0) echo '<div class="mt5 yellow1 mb5 cntr">Статистика казны города, по золоту пуста!</div>';
		
		echo '</div>';
		require_once './element_include/element_foot_user_true.php';
		exit;
		}
		
		if ($go == 'rating_crist') {
		$query = mysql_query("SELECT `lost_user`,`lost_crist` FROM `element_town_treas` WHERE `lost_town` = '$id' AND `lost_crist` > '0' ORDER BY `lost_crist` DESC");
		$i = 0;
		echo '<div class="mt5 yellow1 mb5 cntr">Статистика по кристаллам<br/><a href="/town/treas?id='.$id.'&go=rating_gold">Статистика по золоту</a><br/><a href="/town/treas?id='.$id.'&go=rating_irridiy">Статистика по ирридию</a></div>';
		
			while($myrrow = mysql_fetch_array($query)) {
			$i++;
			$cache_user = cache_user($myrrow['lost_user']);
			$odd = ($i % 2) ? ' odd' : '';
			echo '
			<div class="ml5 mr5">
				<a class="bl p5 small block'.$odd.'" href="/user?id='.$myrrow['lost_user'].'">
				<span class="white small fr"><img src="/images/icons/cristall.png">'.nmb_2($myrrow['lost_crist']).'</span>
					'.$i.'. '.ikonka_user($cache_user['lost_race'], ((!empty($online[$myrrow['lost_user']])) ? 'online' : 'offline')).' <span class="yellow1">'.$cache_user['lost_login'].'</span>	
				</a>
			</div>
			';
			
			}
			if ($i == 0) echo '<div class="mt5 yellow1 mb5 cntr">Статистика казны города, по кристаллам пуста!</div>';
		
		echo '</div>';
		require_once './element_include/element_foot_user_true.php';
		exit;
		}
	
		if ($go == 'rating_irridiy') {
		$query = mysql_query("SELECT `lost_user`,`lost_irridiy` FROM `element_town_treas` WHERE `lost_town` = '$id' AND `lost_irridiy` > '0' ORDER BY `lost_irridiy` DESC");
		$i = 0;
		echo '<div class="mt5 yellow1 mb5 cntr">Статистика по ирридию<br/><a href="/town/treas?id='.$id.'&go=rating_gold">Статистика по золоту</a><br/><a href="/town/treas?id='.$id.'&go=rating_crist">Статистика по кристаллам</a></div>';
		
			while($myrrow = mysql_fetch_array($query)) {
			$i++;
			$cache_user = cache_user($myrrow['lost_user']);
			$odd = ($i % 2) ? ' odd' : '';
			echo '
			<div class="ml5 mr5">
				<a class="bl p5 small block'.$odd.'" href="/user?id='.$myrrow['lost_user'].'">
				<span class="white small fr"><img src="/images/icons/irridyi.png">'.nmb_2($myrrow['lost_irridiy']).'</span>
					'.$i.'. '.ikonka_user($cache_user['lost_race'], ((!empty($online[$myrrow['lost_user']])) ? 'online' : 'offline')).' <span class="yellow1">'.$cache_user['lost_login'].'</span>	
				</a>
			</div>
			';
			
			}
			if ($i == 0) echo '<div class="mt5 yellow1 mb5 cntr">Статистика казны города, по ирридию пуста!</div>';
		
		echo '</div>';
		require_once './element_include/element_foot_user_true.php';
		exit;
		}
	
	
		echo '<div class="white mb5 mt5 cntr">';
		echo '<form method="post" action="/town/treas?id='.$id.'&go=add">
			  <label class="bl mb5 ccc">
				Пополнить казну:<br/>
			    <img src="/images/icons/gold.png"> 
				<input class="fdark w50" type="text" name="treas_gold" value="0" size="20" maxlength="32">
			  </label>';
		echo '<label class="bl mb5 ccc"><img src="/images/icons/cristall.png"> 
				<input class="fdark w50" type="text" name="treas_crist" value="0" size="20" maxlength="32">
			  </label>';
		echo '<label class="bl mb5 ccc"><img src="/images/icons/irridyi.png"> 
				<input class="fdark w50" type="text" name="treas_iridiy" value="0" size="20" maxlength="32">
			  </label>';
		echo '<span class="button w40"><input type="submit" class="ttl" name="submit" value="Пополнить"/></span></form>';
		echo '</div>';
		
		echo '<div class="white mb5 mt5 cntr">';
		echo '<div class="ml5 mr5">
				<a class="bl p5 block odd" href="/town/treas?id='.$id.'&go=rating_gold">
					<span class="small">Рейтинг по золоту</span>
				</a>
			  </div>';
		echo '<div class="ml5 mr5">
				<a class="bl p5 block" href="/town/treas?id='.$id.'&go=rating_crist">
					<span class="small">Рейтинг по кристаллам</span>
				</a>
			  </div>';
		echo '<div class="ml5 mr5">
				<a class="bl p5 block odd" href="/town/treas?id='.$id.'&go=rating_irridiy">
					<span class="small">Рейтинг по ирридию</span>
				</a>
			  </div>';
		echo '</div><div class="line"></div>';
		
		echo '<div class="moderator mt5 small cntr">';
		echo '<span>* Ограничений на пополнение казны города нету</span>';
		echo '</div>';
		
	echo '</div>';

	require_once './element_include/element_foot_user_true.php';
?>