<?php
require_once ('../inc/header.php');
$action = isset ($_GET['action']) ? $_GET['action'] : '';
$post_id = isset ($_GET['post_id']) ? $_GET['post_id'] : '';
$post_id = get_post($post_id, 'id');
if ($action == 'delete') {
if (!get_post($post_id, 'id')) {
header('location:post.php');
}
if (isset ($_POST['confirm'])) {
mysql_query("delete from post where id='$post_id'");
mysql_query("delete from comment where post_id='$post_id'");
$_SESSION['success_notif']='Artikel berhasil dihapus.';
header('location:post.php');
exit;
}
rt('tm');
echo '<div class="list-head">Hapus posting?</div>' .
'<div class="content"><center>' . get_post($post_id, 'title') . '<br/><br />' .
'<form action="?action=delete&post_id=' . $post_id . '" method="post">' .
'<input type="submit" value=" Ya " name="confirm"/> <a href="post.php">Tidak</a>' .
'</form></center></div>';
rb('b');
} else {
$title = isset ($_POST['title']) ? mysql_real_escape_string($_POST['title']) : '';
$description = isset ($_POST['description']) ? mysql_real_escape_string($_POST['description']) : '';
$content = isset ($_POST['content']) ? mysql_real_escape_string($_POST['content']) : '';
$category = isset ($_POST['category']) ? mysql_real_escape_string($_POST['category']) : '1';
$nocomment = isset ($_POST['nocomment']) ? mysql_real_escape_string($_POST['nocomment']) : '0';
$draft = isset ($_POST['draft']) ? $_POST['draft'] : '0';
if ($action == 'new') {
if (isset ($_POST['submit'])) {
if (empty ($title)) {
show_warning('Mohon masukkan judul');
}
if (empty ($content)) {
show_warning('Mohon masukkan posting');
}
$res_author = mysql_fetch_assoc(mysql_query("select id from user where username='$username'"));
if (strlen ($description) > 155) {
show_warning('Description Maksimal 155 Karakter');
} else {
if (!empty ($title) && !empty ($content)) {
mysql_query("insert into post set " .
"title='$title'," .
"description='$description'," .
"content='$content'," .
"permalink='" . create_permalink(rus_lat($title)) . "'," .
"author='" . $res_author['id'] . "'," .
"createtime='" . time() . "'," .
"modtime='" . time() . "'," .
"category='$category'," .
"draft='$draft'," .
"nocomment='$nocomment'");
$post_id = mysql_insert_id();
show_notif('Posting berhasil di dibuat. ' .
($draft == 1 ? '(Disimpan sebagai draft)' : '<a href="' .
get_post($post_id, 'permalink') . '">Lihat</a>'));
$action = 'edit';
$title = get_post($post_id, 'title');
$description = get_post($post_id, 'description');
$content = get_post($post_id, 'content');
}
}
}
} else
if ($action == 'edit') {
if (!get_post($post_id, 'id')) {
header('location:post.php');
}
if (!isset ($_POST['submit'])) {
$title = get_post($post_id, 'title');
$description = get_post($post_id, 'description');
$content = get_post($post_id, 'content');
$category = get_post($post_id, 'category');
$nocomment = get_post($post_id, 'nocomment');
$draft = get_post($post_id, 'draft');
} else {
if (empty ($title)) {
show_warning('Mohon masukkan judul');
}
if (empty ($content)) {
show_warning('Mohon masukkan posting');
}
if (strlen ($description) > 155) {
show_warning('Description Maksimal 155 Karakter');
} else {
if (!empty ($title) && !empty ($content)) {
mysql_query("update post set " .
"title='$title'," .
"description='$description'," .
"content='$content'," .
"category='$category'," .
"modtime='" . time() . "'," .
"nocomment='$nocomment'," .
"draft='$draft' where id='$post_id'");
show_notif('Posting berhasil diperbarui. ' .
($draft == 1 ? '(Disimpan sebagai draft)' : '<a href="' .
get_post($post_id, 'permalink') . '">Lihat</a>'));
$title = get_post($post_id, 'title');
$description = get_post($post_id, 'description');
$content = get_post($post_id, 'content');
$category = get_post($post_id, 'category');
$nocomment = get_post($post_id, 'nocomment');
$draft = get_post($post_id, 'draft');
}
}
}
}
rt('tm');
echo '<div class="list-head">' . ($action == 'new' ? 'Posting baru' : 'Edit posting') . '</div><div class="content">' .
'<form method="post" action="?action=' . ($action == 'edit' ? 'edit&post_id=' . $post_id : 'new') . '">' .
'Judul:<br /><input type="text" name="title" value="' . $title . '"/><br />' .
'Description Singkat (Maksimal 155 Karakter):<br /><input type="text" name="description" value="' . $description . '" maxlength="155" /><hr />';
$sql = mysql_query("select * from category");
echo 'Kategori:<br /><select name="category">';
while ($res_category = mysql_fetch_assoc($sql)) {
echo '<option value="' . $res_category['id'] . '"' . ($category == $res_category['name'] ? ' selected="selected"' : '') . '>' . $res_category['name'] . '</option>';
}
echo '</select> • <a href="category.php">Kelola kategori</a><hr />' .
'Posting:<br /><textarea rows="10" name="content">' . $content . '</textarea><hr />' .
'<input type="checkbox" name="nocomment" value="1"' . ($nocomment == 1 ? ' checked="checked"' : '') . '/> Matikan komentar<hr />' .
'<input type="checkbox" name="draft" value="1"' . ($draft == 1 ? ' checked="checked"' : '') . '/> Simpan sebagai draft<hr/>' .
'<table><tr><td><input type="submit" value="' . ($action == 'new' ? 'Buat' : 'Perbarui') . '" name="submit"/></form></td>' .
($action == 'edit' ? '<td><form action="?action=delete&post_id=' . get_post($post_id, 'id') . '" method="post">' .
'<input type="submit" value="Hapus"/></form></td>' : '') . '</tr></table></div>';
rb('b');
rt('t');
if ($action == 'edit')
echo '<div class="list-nobullet-top"><a href="?action=new"><img src="' . get_setting('blogurl') . '/images/add.png"> Tulis baru</a></div><hr/>';
echo '<div class="list-nobullet-top"><a href="post.php"><img src="' . get_setting('blogurl') . '/images/post.png"> Kelola artikel</a></div>';
rb('b');
}
require_once ('../inc/footer.php');
?>