<?
if (!defined('SITE')) die();

if(isset($_POST['login']))
{
	if($_POST['login'] != "" && $_POST['password'] != "")
	{
		$_POST['login'] = str_replace("'", "`", $_POST['login']);
		$_POST['password'] = str_replace("'", "`", $_POST['password']);
		$_POST['login']  = htmlspecialchars(stripslashes($_POST['login'])); 
		$_POST['password'] = htmlspecialchars(stripslashes($_POST['password']));
		$_SESSION['login'] = $_POST['login'];
		$_SESSION['password'] = $_POST['password'];
		$change = mysql_query("UPDATE jshop_admin SET login = '".$_POST['login']."', password = '".md5($_POST['password'])."'");
	}
}

if(isset($_GET['op']) && $_GET['op'] == "edit")
{
	$profile = mysql_query("SELECT * FROM jshop_admin");
	if(mysql_numrows($profile) == 1)
	{
		$profile = mysql_fetch_array($profile);
				
		$profile['login'] = str_replace('"', '&quot;', $profile['login']);
		$profile['login']  = htmlspecialchars(stripslashes($profile['login']));

		$profile['password'] = str_replace('"', '&quot;', $profile['password']);
		$profile['password']  = htmlspecialchars(stripslashes($profile['password']));


	echo "<form method=post action=\"".$h."/admin/profile/\">";
	echo "<table align=center cellpadding=0 cellspacing=0><tr><td bgcolor=#E5E5E5><table width=100% cellpadding=1 cellspacing=1>";
	echo "<tr bgcolor=#F8F8F8><td colspan=10 align=center><div class=table_item><b>Редактировать</b></div></td></tr>";
	echo "<tr bgcolor=#FFFFFF><td><div class=table_item>Логин</div></td><td><div class=table_item><input size=50 name=login type=text value=\"". $profile['login'] ."\"></div></td></tr>
	<tr bgcolor=#FFFFFF><td><div class=table_item>Пароль</div></td><td><div class=table_item><input size=50 name=password type=text></div></td></tr>
	</table></td></tr></table>
	<center><br><br><input type=submit value=\"Изменить\"></center>
	</form>";
	}
	else echo "<center>Ошибка при чтении профиля!</center>";
}
else 
{
	$profile = mysql_query("SELECT * FROM jshop_admin");
	if(mysql_numrows($profile) == 1)
	{
		$profile = mysql_fetch_array($profile);

		echo "<table align=center cellpadding=0 cellspacing=10><tr><td bgcolor=#E5E5E5><table width=100% cellpadding=1 cellspacing=1><tr bgcolor=#F8F8F8><td colspan=10 align=center><div class=table_item><b>Профиль Администратора</b></div></td></tr><tr bgcolor=#FFFFFF><td><div class=table_item>Логин</div></td><td><div class=table_item>".$profile['login']."</div></td></tr><tr bgcolor=#FFFFFF><td><div class=table_item>Пароль</div></td><td><div class=table_item>********</div></td></tr><tr bgcolor=#FFFFFF><td colspan=2><div class=table_item><a href=\"".$h."/admin/profile/edit/\">Изменить данные</a></div></td></tr></table></td></tr></table>";
	}
	else echo "<center>Ошибка при чтении профиля!</center>";
}
?>