<?php
	$id = (isset($_GET['id']) ? intval($_GET['id']) : 0 );
	$d = profile :: getUser($id);

	admin :: access(array('a'=>1));

	$level = admin :: getLevel($d);


	if(isset($_POST['cfms'])) {
		if(isset($_POST['access']) && $_POST['access'] == ACCESS) {
			$money = intval($_POST['money']);
			$money = ($money >= 0 ? $money : $d['line']);

			$first_name = system :: check(system :: text($_POST['first_name']));
			$last_name = system :: check(system :: text($_POST['last_name']));

			DB :: $pdo -> query("UPDATE `users` SET `info_first_name` = ?, `info_last_name` = ?, `line` = ? WHERE `id` = ? LIMIT 1;", [$first_name,$last_name,$money,$d['id']]);
			system :: redirect("Изменения сохранены.", "{$thisLink}?act=user/edit&id={$d['id']}");
		}
	}


	$title = $l = "Панель управления - Редактирование информации";
$lBack ="/admin/?act=user/info&amp;id=".$d['id']."";

require (CORE."head.php");
	echo "<div class=\"app-block\">";
	echo system :: touch(profile :: getLink($d),"
			<div class=\"post-l emotion-show\" data-emotions=\"".system::textOut($d['emotions'])."\">
				".profile :: userAvatar($d,0)."
			</div>
			<div class=\"post-c\">
				<div class=\"_name\">".profile :: getFullName($d, true)."</div>
				<div class=\"_gray\">Время на сайте: ".profile :: onlineTime($d['online_time'])."</div>
				<div class=\"_gray\">Дата регистрации: ".system :: times($d['first_time'])."</div>
				<div class=\"_gray\">Блокировок: ".$d['count_blocks']."</div>
			</div>
			"); 
?>	
		<div class="list">
		<div class="sw-block_"><div class="sw-cont sw-3">
			<div class="sw-item"><a href="/admin/?act=user/edit&amp;id=<?=$d['id']?>" class="sw-c sw-act">Редактирование</a></div>
			<div class="sw-item"><a href="/admin/?act=user/level&amp;id=<?=$d['id']?>" class="sw-c">Должность</a></div>
			<div class="sw-item"><a href="/admin/?act=user/function&amp;id=<?=$d['id']?>" class="sw-c">Функции</a></div>
		</div></div>
		</div>

<?php
	$levels = admin :: getLevel($d);
	$l = "";
	foreach ($config['LEVELS'] as $k => $v) {
		if($k == 'a' && $levels['a'] != 0) {
			$r = $v[$levels['a']];
		} else if($levels[$k] != 0) {
			$r = $v;
		}
		if(isset($r)) { $l .= "<div>".$r."</div>"; }
		unset($r);
	}
	if($l != ""){ echo "<div class=\"list _bg-blue\"  style=\"color:#43734f;\">{$l}</div>"; }
	?>
	<form method="post" action="">
		<div class="list">
			<label>
			<span class="_gray _dbl">Имя:</span>
			<input type="text" name="first_name" value="<?=$d['info_first_name']?>" class="main-input _w-100" /></label>
		</div>
		<div class="list">
			<label>
			<span class="_gray _dbl">Фамилия:</span>
			<input type="text" name="last_name" value="<?=$d['info_last_name']?>" class="main-input _w-100" /></label>
		</div>
		<div class="list">
			<label>
			<span class="_gray _dbl">Монет:</span>
			<input type="text" name="money" value="<?=$d['line']?>" class="main-input _w-100" /></label>
		</div>
		<input type="hidden" name="access" value="<?=ACCESS?>">
		<div class="_center list">
			<input type="submit" class="main-btn _w-100" name="cfms" value="Сохранить">
		</div>
	</form>
	<?php
	echo system :: back("/admin/?act=user/info&amp;id={$d['id']}","Информация", true);
	echo "</div>";
	require (CORE."foot.php");