<? include('checkcookie.php'); ?>
<h3>Просмотр и редактирование псевдодинамических ссылок</h3>
<br>

<?
if (isset($_POST["id"]))
{
	$id=$_POST["id"];
	$url=$_POST["url"];
	$desc=$_POST["desc"];
	
	mysql_query("update tb_psevdolinks set url='$url', description='$desc' where id='$id'");
	echo "<font color=\"#00dd00\"><b>Изменения сохранены.</b></font><br><br>";
}

if (isset($_GET["id"]))
{
	$id=$_GET["id"];
	$option=$_GET["option"];

	if ($option=="delete")
	{
		mysql_query("DELETE FROM tb_psevdolinks WHERE id='$id'");
		echo "<font color=\"#dd0000\"><b>Псевдодинамическая ссылка удалена.</b></font><br><br>";
	}

	if ($option=="edit")
	{
		$url=$_POST["url"];
		$desc=$_POST["desc"];
		

		?>
		<form method="post" action="adminmain.php?p=psevdoview&option=save">
			<b>URL сайта:</b>&nbsp;<input type="text" name="url" size="150" maxlength="150" value="<?=$url ?>"><br>
			<b>Текст ссылки:</b>&nbsp;<input type="text" name="desc" size="150" maxlength="150" value="<?=$desc ?>"><br>
			<br>
			<input type="hidden" value="<?=$id ?>" name="id">
			<input type="submit" value="Сохранить">
		</form>
		<?
	}
}
?>

<table cellspacing="0" cellpadding="0">
<tr>
<th>URL сайта</th>
<th>Текст ссылки</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?
$res = mysql_query("SELECT * FROM tb_psevdolinks ORDER BY id ASC");
while ($row = mysql_fetch_array($res)) { 

echo "
<tr>
<td><a href=\"". $row["url"] ."\" target=\"_blank\">". $row["url"] ."</a></td>
<td>". $row["description"] ."</td>";
echo "<td>";
?>
<form method="post" action="adminmain.php?p=psevdoview&id=<?= $row["id"] ?>&option=edit">
<input type="hidden" name="url" value="<?=$row["url"] ?>">
<input type="hidden" name="desc" value="<?=$row["description"] ?>">
<input type="submit" value="Редактировать" class="button">
</form>
</td>
<td>
<form method="post" action="adminmain.php?p=psevdoview&id=<?= $row["id"] ?>&option=delete">
<input type="submit" value="Удалить" class="button">
</form>
</td>
</tr>

<?

}

?>
</table>