CODE
<? $page_title = 'Редактирование статей';
include('header.php');
setlocale (LC_ALL, 'ru_RU.cp1251');
session_start();
if (!$_SESSION[login]) {
echo "Нужно <a href='login.php'>Войти</a>";
include ('footer.php');
} elseif(!in_array($_SESSION['userdata']['boat'], arrayarray("журналист", "редактор")))
{
echo "<a href='./login.php'>Доступ запрещен</a>";
include ('footer.php');
}
else
include ('connection.php');
if (isset($_POST['update'])) {
include('bbcode.php');
$id = htmlspecialchars(strip_tags($_POST['id']));
$text = $_POST['text'];
$title = htmlspecialchars(strip_tags($_POST['title']));
$text = nl2br($text);
$textcomp = mysql_escape_string(bbcode(stripslashes($_POST['text'])));
if (!get_magic_quotes_gpc()) {
$title = addslashes($title);
$text = addslashes($text);
}
$result = mysql_query("UPDATE articles SET time = CURDATE(), title='$title', entry='$text', category='$category', textcomp = '$textcomp' WHERE id='$id'") or print ("Заклинания не работают.<br />" . mysql_error());
header("Location: articles.php?id=" .$id);
}
if (isset($_POST['delete'])) {
$id = (int)$_POST['id'];
$result = mysql_query("DELETE FROM articles WHERE id='$id'") or print ("Не могу удалить статью.<br />" . mysql_error());
if ($result != false) {
echo "<p><div id='contenido'>";
print "Удалено!";
echo "</div></p>";
include ('footer.php');
}
}
if (!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])) {
die ("Такой статьи не существует");
}
else {
$id = (int)$_GET['id'];
}
$result = mysql_query("SELECT * FROM articles WHERE id = '$id'") or print ("Заклинания не действуют.<br />".sql."<br />".mysql_error());
while ($row = mysql_fetch_array($result)) {
$old_title = $row['title'];
$old_text = $row['entry'];
$old_title = str_replace('"','\'',$old_title);
$category = (int)$_POST['category'];
$old_text = str_replace('<br />', '', $old_text);
echo "<p><div id='contenido'>";
echo "<hr></div></p>";
?>
<form name ='post' method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php
$result2 = mysql_query("SELECT * FROM article_categ");
echo '<p><strong><label for="category">Новая категория:</label></strong> <select name="category" id="category">';
while($row2 = mysql_fetch_array($result2)) { ?>
<option value="<?php echo $row2['category_id']; ?>" <?php if ($row['category'] == $row2['category_id']) echo ' selected="selected"'; ?>><?php echo $row2['category_name']; ?></option>
<?php
}
?>
</select></p>
<p><strong><label for="title">Название:</label></strong> <input type="text" name="title" id="title" value="<?php echo $old_title; ?>" size="40" /> </p>
<p><script language="JavaScript" SRC="bbcode.js" type="text/javascript"></SCRIPT><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<div id="bbcodes"><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<input type="button" accesskey="b" name="addbbcode0" value="B" onClick="bbstyle(0)" title="Жирный текст: [b]текст[/b] (alt+b)">
<input type="button" accesskey="i" name="addbbcode2" value="I" onClick="bbstyle(2)" title="Наклонный текст: [i]текст[/i] (alt+i)">
<input type="button" accesskey="u" name="addbbcode4" value="U" onClick="bbstyle(4)" title="Подчёркнутый текст: [u]текст[/u] (alt+u)">
<input type="button" accesskey="s" name="addbbcode6" value="S" onClick="bbstyle(6)" title="Зачёркнутый текст: [s]текст[/s] (alt+s)">
<input type="button" accesskey="c" name="addbbcode8" value="C" onClick="bbstyle(8)" title="Выровнять текст по центру: [center]текст[/center] (alt+c)">
<input type="button" accesskey="r" name="addbbcode10" value="R" onClick="bbstyle(10)" title="Выровнять текст по правому краю: [right]текст[/right] (alt+r)">
<input type="button" accesskey="h" name="addbbcode12" value=" H " onClick="bbstyle(12)" title="Заглавие: [h]текст[/h] (alt+h)">
<input type="button" accesskey="p" name="addbbcode14" value="IMG" onClick="bbstyle(14)" title="Вставить картинку: [img]http://image_url[/img] (alt+p)">
<input type="button" accesskey="w" name="addbbcode16" value="URL" onClick="bbstyle(16)" title="Вставить ссылку: [url]http://url[/url] или [url=http://url]текст ссылки[/url] (alt+w)">
<input type="button" accesskey="o" name="addbbcode18" value="OT" onClick="bbstyle(18)" title="Off-topic (alt+w)">
<br><a href="java script:bbstyle(-1)" title="Закрыть все открытые теги bbCode">Закрыть теги</a><br></div>
<textarea name=text rows="10" cols="70"><?php echo $old_text; ?>
</textarea><br></p>
<p><input type="submit" name="update" id="update" value="Обновить"> <input type="submit" name="delete" id="delete" value="Удалить"></p>
</form>
<?php
include('footer.php');
mysql_close();
}
?>
include('header.php');
setlocale (LC_ALL, 'ru_RU.cp1251');
session_start();
if (!$_SESSION[login]) {
echo "Нужно <a href='login.php'>Войти</a>";
include ('footer.php');
} elseif(!in_array($_SESSION['userdata']['boat'], arrayarray("журналист", "редактор")))
{
echo "<a href='./login.php'>Доступ запрещен</a>";
include ('footer.php');
}
else
include ('connection.php');
if (isset($_POST['update'])) {
include('bbcode.php');
$id = htmlspecialchars(strip_tags($_POST['id']));
$text = $_POST['text'];
$title = htmlspecialchars(strip_tags($_POST['title']));
$text = nl2br($text);
$textcomp = mysql_escape_string(bbcode(stripslashes($_POST['text'])));
if (!get_magic_quotes_gpc()) {
$title = addslashes($title);
$text = addslashes($text);
}
$result = mysql_query("UPDATE articles SET time = CURDATE(), title='$title', entry='$text', category='$category', textcomp = '$textcomp' WHERE id='$id'") or print ("Заклинания не работают.<br />" . mysql_error());
header("Location: articles.php?id=" .$id);
}
if (isset($_POST['delete'])) {
$id = (int)$_POST['id'];
$result = mysql_query("DELETE FROM articles WHERE id='$id'") or print ("Не могу удалить статью.<br />" . mysql_error());
if ($result != false) {
echo "<p><div id='contenido'>";
print "Удалено!";
echo "</div></p>";
include ('footer.php');
}
}
if (!isset($_GET['id']) || empty($_GET['id']) || !is_numeric($_GET['id'])) {
die ("Такой статьи не существует");
}
else {
$id = (int)$_GET['id'];
}
$result = mysql_query("SELECT * FROM articles WHERE id = '$id'") or print ("Заклинания не действуют.<br />".sql."<br />".mysql_error());
while ($row = mysql_fetch_array($result)) {
$old_title = $row['title'];
$old_text = $row['entry'];
$old_title = str_replace('"','\'',$old_title);
$category = (int)$_POST['category'];
$old_text = str_replace('<br />', '', $old_text);
echo "<p><div id='contenido'>";
echo "<hr></div></p>";
?>
<form name ='post' method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<?php
$result2 = mysql_query("SELECT * FROM article_categ");
echo '<p><strong><label for="category">Новая категория:</label></strong> <select name="category" id="category">';
while($row2 = mysql_fetch_array($result2)) { ?>
<option value="<?php echo $row2['category_id']; ?>" <?php if ($row['category'] == $row2['category_id']) echo ' selected="selected"'; ?>><?php echo $row2['category_name']; ?></option>
<?php
}
?>
</select></p>
<p><strong><label for="title">Название:</label></strong> <input type="text" name="title" id="title" value="<?php echo $old_title; ?>" size="40" /> </p>
<p><script language="JavaScript" SRC="bbcode.js" type="text/javascript"></SCRIPT><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<div id="bbcodes"><meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<input type="button" accesskey="b" name="addbbcode0" value="B" onClick="bbstyle(0)" title="Жирный текст: [b]текст[/b] (alt+b)">
<input type="button" accesskey="i" name="addbbcode2" value="I" onClick="bbstyle(2)" title="Наклонный текст: [i]текст[/i] (alt+i)">
<input type="button" accesskey="u" name="addbbcode4" value="U" onClick="bbstyle(4)" title="Подчёркнутый текст: [u]текст[/u] (alt+u)">
<input type="button" accesskey="s" name="addbbcode6" value="S" onClick="bbstyle(6)" title="Зачёркнутый текст: [s]текст[/s] (alt+s)">
<input type="button" accesskey="c" name="addbbcode8" value="C" onClick="bbstyle(8)" title="Выровнять текст по центру: [center]текст[/center] (alt+c)">
<input type="button" accesskey="r" name="addbbcode10" value="R" onClick="bbstyle(10)" title="Выровнять текст по правому краю: [right]текст[/right] (alt+r)">
<input type="button" accesskey="h" name="addbbcode12" value=" H " onClick="bbstyle(12)" title="Заглавие: [h]текст[/h] (alt+h)">
<input type="button" accesskey="p" name="addbbcode14" value="IMG" onClick="bbstyle(14)" title="Вставить картинку: [img]http://image_url[/img] (alt+p)">
<input type="button" accesskey="w" name="addbbcode16" value="URL" onClick="bbstyle(16)" title="Вставить ссылку: [url]http://url[/url] или [url=http://url]текст ссылки[/url] (alt+w)">
<input type="button" accesskey="o" name="addbbcode18" value="OT" onClick="bbstyle(18)" title="Off-topic (alt+w)">
<br><a href="java script:bbstyle(-1)" title="Закрыть все открытые теги bbCode">Закрыть теги</a><br></div>
<textarea name=text rows="10" cols="70"><?php echo $old_text; ?>
</textarea><br></p>
<p><input type="submit" name="update" id="update" value="Обновить"> <input type="submit" name="delete" id="delete" value="Удалить"></p>
</form>
<?php
include('footer.php');
mysql_close();
}
?>
Please, could somebody help me