File size: 3.78Kb
<?php
require '../inc/func.php';
switch(isset($_GET['act']) ? $_GET['act'] :'add')
{
case 'add':
bk_head('Add');
require '../inc/head.php';
echo '<div class="list1"><div class="tt"> Add smile</div>';
if(!isset($_GET['image']) or !isset($_GET['text']) or empty($_GET['image']) or empty($_GET['text']))
{
echo '<form action="?" method="get">
Tên: <small>(Tên của file ảnh,eg: yao.png)</small><br/>
<input type="text" name="image"/><br/>
Nội Dung:<small>(Bbcode để dùng,eg: :yao:)</small><br/>
<input type="text" name="text"/><br/>
<input type="hidden" name="act" value="add"/>
<input type="submit" value="Thêm"/>
</form>';
}
else
{
$image = bk_check($_GET['image']);
$text = bk_check($_GET['text']);
mysql_query("insert into `smiles` values('','$image','$text')");
if(!mysql_error())
{
err ('Thành công!');
}
else
{
err ('Lỗi!');
}
}
echo '</div>';
break;
case 'edit':
bk_head('Edit');
require '../inc/head.php';
echo '<div class="list1"><div class="tt"> Edit smile</div>';
if(!isset($_GET['id']))
{
$query = mysql_query('select * from `smiles`');
echo '<form action="?" method="get">
Chọn:<br/>
<select name="id">
';
while($result = mysql_fetch_assoc($query))
{
echo '<option value="'.$result['id'].'">'.$result['id'].') '.htmlspecialchars(stripslashes($result['text'])).'</option>
';
}
echo '</select><br/>
<input type="hidden" name="act" value="edit"/>
<input type="submit" value="Edit"/>
</form>';
}
else
{
$id = num($_GET['id']);
$query = mysql_query('select * from `smiles` where `id`='.$id);
if(!mysql_num_rows($query)) {
err ('Lỗi!');
echo '</div>';
bk_foot();
exit;
}
if(!isset($_GET['image']) or !isset($_GET['text']) or empty($_GET['image']) or empty($_GET['text']))
{
$result = mysql_fetch_assoc($query);
echo '<form action="?" method="get">
Tên: <small>(Tên file ảnh,eg: yao.png)</small><br/>
<input type="text" name="image" value="'.bk_check($result['image']).'"/><br/>
Bbcode: (Bbcode để sử dụng,eg: :yao:)<br/>
<input type="text" name="text" value="'.bk_check($result['text']).'"/><br/>
<input type="hidden" name="act" value="edit"/>
<input type="hidden" name="id" value="'.$id.'"/>
<input type="submit" value="Save"/>
</form>';
}
else
{
$image = bk_check($_GET['image']);
$text = bk_check($_GET['text']);
mysql_query("update `smiles` set `image`='$image', `text`='$text' where `id`='$id'");
if(!mysql_error())
{
err ('Thành công!');
}
else
{
echo 'Lỗi';
}
}
}
echo '</div>';
break;
case 'delete':
bk_head('Delete');
require '../inc/head.php';
echo '<div class="list1"><div class="tt"> Delete smile</div>';
if(!isset($_GET['id']))
{
$query = mysql_query('select * from `smiles`');
echo '<form action="?" method="get">
Chọn:<br/>
<select name="id">
';
while($result = mysql_fetch_assoc($query))
{
echo '<option value="'.$result['id'].'">'.$result['id'].') '.bk_check($result['text']).'</option>
';
}
echo '</select><br/>
<input type="hidden" name="act" value="delete"/>
<input type="submit" value="Xóa"/>
</form>';
}
else
{
$id = num($_GET['id']);
$query = mysql_query('select * from `smiles` where `id`='.$id);
if(!mysql_num_rows($query)) {
err ('Lỗi!');
echo '</div>';
bk_foot();
exit;
}
if(!isset($_GET['delete']))
{
$result = mysql_fetch_assoc($query);
echo '<div class="shadow">Are you sure? <img src="../smiles/'.bk_check($result['image']).'" alt=""/> - '.bk_check($result['text']).' ?
<br /><a href="?id='.$id.'&act=delete&delete">OK</a> |
<a href="?act=delete">NO</a></div>';
}
else
{
mysql_query('delete from `smiles` where `id`='.$id);
if(!mysql_error())
{
err ('Thành công!');
}
else
{
echo 'Lỗi';
}
}
}
echo '</div>';
break;
}
bk_foot();
?>