View file libs/new.stat.php

File size: 2.53Kb
<?


define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
if($_GET['id']){$id=$_GET['id'];}
registrat();
$lib = mysql_fetch_array(mysql_query("SELECT * FROM `libs` WHERE `id` = '$id'"));
$shcmsengine['title'] = 'Библиотека - '.$lib['name'].' - Добавить статью';
include_once'../template/head.php';

if($_POST['submit']){$submit = $_POST['submit'];}
if(isset($submit))
{
if($_POST['name']){$name = $_POST['name'];}
if($_POST['text']){$text = $_POST['text'];}


if(empty($name))
{echo '<div class="errors">Введите названия статьи</div>';
header("Refresh: 1; url=new.stat.php?id=$id");
include_once'../template/foot.php';
exit;}

$lib_prov = mysql_query("SELECT * FROM `libs_stat` WHERE `name`='" . mysql_real_escape_string($name) . "';");
        if (mysql_fetch_array($lib_prov) != 0) {
            echo  '<div class="errors">Статья с такой названией уже есть в библиотеке</div>';
			header("Refresh: 1; url=?id=".$id."");
			include_once'../template/foot.php';
 exit();      
	  }

if(strlen($name) <1 || strlen($name) > 100)
{echo '<div class="errors">Название должно быть не больше 60 символов</div>';
header("Refresh: 1; url=new.stat.php?id=$id");
include_once'../template/foot.php';
exit;}
if(empty($text))
{echo '<div class="errors">Введите текст статьи</div>';
header("Refresh: 1; url=new.stat.php?id=$id");
include_once'../template/foot.php';
exit;}



$libs = mysql_query("INSERT INTO `libs_stat` (`dir`,`name`,`text`,`time`,`user_id`) VALUES ('$id','$name','".my_esc($text)."','".time()."','$user_id')");
if($libs == true){echo '<div class="actshcms">Статья успешно добавлена</div>';
header("Refresh: 1; url=/libs/list.php?id=$id");
include_once'../template/foot.php';
exit;}
else
{errors('Возникла ошибка при добавлении статьи');
header("Refresh: 1; url=new.stat.php?id=$id");
include_once'../template/foot.php';
exit;}

}



echo '<form action="?id='.$id.'" method="post" name="form">';
echo '<strong>Названия статьи:</strong><br/><input type="text" name="name"><br/>';
echo '<strong>Текст статьи:</strong><br/><textarea id="text" name="text"></textarea><br/>';
				echo '<input  type="submit" name="submit" value="Добавить"> ';
				echo '<input  type="submit" name="refresh" value="Обновить">';
echo '</form>';




include_once'../template/foot.php';
?>