<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

define( 'PAGE_ID', 'article_mgt' );

if ( !checkAdminPermission( PAGE_ID ) ) {

	header( 'location: not_authorize.php' );
	exit;
}


$err = 0 ;

if ( $_POST['txttitle'] == '' ) {

	$err = NO_HDR;

} elseif ( trim($_POST['txttext']) == '' || strlen(trim($_POST['txttext'])) <= 0 ) {

	$err = NO_TEXT;

}

if ( $err != 0 ) {

	$_SESSION['txttext'] = $_POST['txttext'];

	$_SESSION['txttitle'] = $_POST['txttitle'];

	$_SESSION['artcldate'] = strtotime( $_POST['txtDay'] . ' ' . $_POST['txtMonth'] . ' ' . $_POST['txtYear'] );

	header( 'location: articleins.php?edit=' . $id . '&errid=' . $err );

	exit;

}

$_SESSION['txttext'] = '';
$_SESSION['artcldate'] = '';
$_SESSION['txttitle'] = '';

$title = eregi_replace('</?[a-z][a-z0-9]*[^<>]*>', '', $title );

$osDB->query( 'INSERT INTO ! (  dat, title, text ) VALUES ( ?, ?, ? )', array( ARTICLES_TABLE, strtotime( $_POST['txtDay'] . ' ' . $_POST['txtMonth'] . ' ' . $_POST['txtYear'] ), $_POST['txttitle'], trim($_POST['txttext']) ) );

header( 'location: managearticle.php' );

exit;

?>