<?php
include("header.php");
if(!$_GET['do'])
{
//If $do is empty we load the default page listing all smilies
//We select all smilie_id from the database and initialize smilie objects...
$query = "SELECT smilie_id FROM tblSmilie";
$result = $db->doQuery($query);
while($row = $result->getArray())
{
$smilie = new Smilie($db, $row['smilie_id']);
$smilies[] = array('id' => $smilie->getId(),
'file' => $smilie->getFile(),
'code' =>$smilie->getCode());
}
$template->assign('smilies', $smilies);
}
if($_GET['do'] == "add")
{
if($_POST['submit'])
{
if($file = add_img("../img/smilies/"))
{
$code = $_POST['code'];
$file = "smilies/" . $file;
$query = "INSERT INTO tblSmilie (smilie_code, smilie_file)
VALUES('$code', '$file')";
if(!$result = $db->doQuery($query))
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['add_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_smilies'] . "</a></p>";
}
}
else
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
//Send to the template
$template->assign('confirm_message', $confirm_message);
}
else
{
//Seems like there is nothing to do here...
}
}
if($_GET['do'] == "edit")
{
if($_POST['submit'])
{
$smilie = new Smilie($db, $_POST['id']);
$smilie->setCode($_POST['code']);
if(!$smilie->edit())
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['edit_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_smilies'] . "</a></p>";
}
$template->assign('confirm_message', $confirm_message);
}
else
{
//Lets read the smilie first
$smilie = new Smilie($db, $_GET['id']);
//Now lets create a proper array before sending this to the template...
$smilie_arr = array('code' => $smilie->getCode());
//Now we assign it to the template
$template->assign('smilie', $smilie_arr);
}
}
if($_GET['do'] == "delete")
{
//This is the delete routine
//Delete the smilie from the table and display confirmation
$smilie = new Smilie($db, $_GET['id']);
if(!$smilie->delete())
{
$confirm_message = $lang['db_problem'] . "<br><br>" . $db->getError();
}
else
{
$confirm_message = "<p>" . $lang['delete_success'] . "</p><p><a href=\"$PHP_SELF\">" . $lang['manage_smilies'] . "</a></p>";
}
//Send to the template
$template->assign('confirm_message', $confirm_message);
}
//Lets display the template
$template->display($config['theme'].'/admin/smilie.tpl');
include("footer.php");
?>