<?php
/*========================================================*\
||########################################################||
||# #||
||# WB News v2.0.0 #||
||# ---------------------------------------------------- #||
||# Copyright (c) 2004-2008 #||
||# Created: 2nd Febuary 2008 #||
||# Filename: theme.php #||
||# #||
||########################################################||
/*========================================================*/
/**
* @author $Author: pmcilwaine $
* @version $Id: edit-emoticon.php,v 1.1.2.5.2.1 2008/07/14 11:02:37 pmcilwaine Exp $
*/
/**
TODO
make sure we use proper menu auth check
make sure we get page menu (not toolbar) from menu
**/
require_once( "global.php" );
$auth->login_if( !$auth->has_perm( "canconfig" ) );
$myform = "edit-emoticon";
if ( !isset($_SESSION["return_page"]) )
{
$_SESSION["return_page"] = MAIN_SERVER . "/admin/emoticons.php";
}
$page = new PageTemplateEngine( BuildPath("admin/main-page.ihtml") );
$tmpl->SetFilename( BuildPath("admin/edit-emoticon.ihtml") );
$params = array(
"entry" => "\t<li>%s</li>\n\t",
"separator" => FALSE,
"class_open" => "open",
"links" => toolbarmenu()
);
$toolbar = include( INCDIR . "/page-menu.php" );
$page->AddParam( "toolbar", $toolbar );
$page->AddParam( "userinfo", $userinfo );
$id = isset($_REQUEST["id"]) ? $DB->escape( $_REQUEST["id"] ) : NULL;
$cond = array();
$cond[] = "\"id\"='$id'";
$cond = join( " AND ", $cond );
$DB->query( "SELECT * FROM " . TBL_EMOTICON . " WHERE $cond" );
$is_new = !$DB->next_record();
$formdata =& $tmpl->AddParam( "formdata", array() );
if ( $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["form"]) && $_POST["form"] == $myform )
{
$err_msg = array();
switch ( Submit() )
{
case "Create":
case "Ok":
$name = sanitize_post( "name" );
$image = sanitize_post( "image" );
if ( "" == $name )
{
$err_msg["name"] = "You must enter a name";
}
if ( "" == $image )
{
$err_msg["image"] = "You must enter a image path";
}
if ( count($err_msg) > 0 )
{
$_SESSION["formdata"] = $_POST;
$_SESSION["err_msg"][$myform] = $err_msg;
redirect( make_url() );
exit;
}
$name = $DB->escape( $name );
$image = $DB->escape( $image );
$query = array();
if ( $is_new )
{
$new_id = $DB->NewID( SEQ_PREFIX . "seq_emoticons" );
$query[] = "INSERT INTO " . TBL_EMOTICON;
$query[] = "(id,name,image)";
$query[] = "VALUES($new_id,'$name','$image')";
}
else
{
$query[] = "UPDATE " . TBL_EMOTICON . " SET";
$query[] = "name='$name',";
$query[] = "image='$image'";
$query[] = "WHERE themeid='$id'";
}
if ( !$DB->query( join( " ", $query ) ) )
{
Message( "Couldn't commit data" );
$_SESSION["formdata"] = $_POST;
$_SESSION["err_msg"][$myform] = $err_msg;
redirect( make_url() );
exit;
}
switch ( Submit() )
{
case "Create":
Message( "Created new emoticon" );
break;
case "Ok":
Message( "Updated emoticon \"$name\"" );
break;
default:
Message( "Unknown action" );
break;
}
redirect( $_SESSION["return_page"] );
exit;
case "Delete":
$DB->query( "DELETE FROM " . TBL_EMOTICON . " WHERE id='$id'");
Message( "Deleted emoticon " . htmlspecialchars( $_POST["name"] ) );
redirect( $_SESSION["return_page"] );
exit;
case "Cancel":
if ( $is_new )
{
Message( "Cancelled creating emotion" );
}
else
{
Message( "Cancelled updating \"" . htmlspecialchars( $_POST["name"] ) . "\"" );
}
redirect( $_SESSION["return_page"] );
exit;
default:
Message( "Unknown action" );
exit;
}
}
$tmpl->AddParam( "caption", !$is_new ? "Edit Emoticon" : "Create Emoticon" );
$formdata["hidden"] = array(
"form" => $myform,
"id" => $id
);
$formdata["name"] = htmlspecialchars( $DB->field("name") );
$formdata["image"] = htmlspecialchars( $DB->field("image") );
if ( $is_new )
{
$tmpl->AddParam( "buttons", "Cancel,Create" );
}
else
{
$tmpl->AddParam( "buttons", "Cancel,Delete,Ok" );
}
if ( isset($_SESSION["formdata"]) )
{
if ( isset($_SESSION["err_msg"][$myform]) )
{
$tmpl->AddParam( "msg", $_SESSION["err_msg"][$myform] );
}
$formdata["name"] = sanitize_post_html( "name", NULL , $_SESSION["formdata"] );
$formdata["image"] = sanitize_post_html( "image", NULL , $_SESSION["formdata"] );
unset( $_SESSION["formdata"], $_SESSION["err_msg"][$myform] );
}
$pagemenu =& $tmpl->AddParam( "pagemenu", array() );
$page->BindParam( "pagemenu", $tmpl );
$params = array(
"entry" => "\t<li>%s</li>\n\t",
"separator" => "\t<li>|</li>\n\t",
"links" => buildmenu( $theme_info["pagemenu_build"] )
);
$params = array_merge( $params, $theme_info["pagemenu"] );
$pagemenu = include( INCDIR . "/page-menu.php" );
$page->ParseContent( $tmpl->GetHTML() );
$page->ShowPage();
?>