<?PHP

/* ====================
Seditio - Website engine
Copyright Neocrome
http://www.neocrome.net
[BEGIN_SED]
File=admin.smilies.inc.php
Version=101
Updated=2006-mar-15
Type=Core.admin
Author=Neocrome
Description=Administration panel
[END_SED]
==================== */

if ( !defined('SED_CODE') || !defined('SED_ADMIN') ) { die('Wrong URL.'); }

list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = sed_auth('admin', 'a');
sed_block($usr['isadmin']);

$adminpath[] = array ("admin.php?m=other", $L['Other']);
$adminpath[] = array ("admin.php?m=smilies", $L['Smilies']);

if ($a=='update')
	{
	$s = sed_import('s', 'P', 'ARR');
	foreach($s as $i => $k)
		{
		$sql = sed_sql_query("UPDATE $db_smilies SET smilie_code='".sed_sql_prep($s[$i]['code'])."', smilie_image='".$s[$i]['image']."', smilie_text='".$s[$i]['text']."' WHERE smilie_id='$i'");
		}
	sed_cache_clear('sed_smilies');
	header("Location: admin.php?m=smilies");
	exit;
	}
elseif ($a=='add')
	{
	$nsmiliecode = sed_sql_prep(sed_import('nsmiliecode', 'P', 'STX'));
	$nsmilieimage = sed_sql_prep(sed_import('nsmilieimage', 'P', 'STX'));
	$nsmilietext = sed_sql_prep(sed_import('nsmilietext', 'P', 'STX'));
	$sql = sed_sql_query("INSERT INTO $db_smilies (smilie_code, smilie_image, smilie_text) VALUES ('$nsmiliecode','$nsmilieimage','$nsmilietext')");
	sed_cache_clear('sed_smilies');
	header("Location: admin.php?m=smilies");
	exit;
	}
elseif ($a=='delete')
	{
	sed_check_xg();
	$id = sed_import('id', 'G', 'INT');
	$sql = sed_sql_query("DELETE FROM $db_smilies WHERE smilie_id='$id'");
	sed_cache_clear('sed_smilies');
	header("Location: admin.php?m=smilies");
	exit;
	}

$sql = sed_sql_query("SELECT * FROM $db_smilies ORDER by smilie_id");

$adminmain .= "<h4>".$L['editdeleteentries']." :</h4>";
$adminmain .= "<form id=\"savesmilies\" action=\"admin.php?m=smilies&amp;a=update\" method=\"post\">";
$adminmain .= "<table class=\"cells\"><tr>";
$adminmain .= "<td class=\"coltop\" style=\"width:40px;\">".$L['Delete']."</td>";
$adminmain .= "<td class=\"coltop\" style=\"width:48px;\">".$L['Preview']."</td>";
$adminmain .= "<td class=\"coltop\" style=\"width:64px;\">".$L['Size']."</td>";
$adminmain .= "<td class=\"coltop\">".$L['Code']."</td>";
$adminmain .= "<td class=\"coltop\">".$L['ImageURL']."</td>";
$adminmain .= "<td class=\"coltop\">".$L['Text']."</td>";
$adminmain .= "</tr>";

while ($row = sed_sql_fetcharray($sql))
	{
	$smilie_id = $row['smilie_id'];
	$smilie_code = $row['smilie_code'];
	$smilie_image = $row['smilie_image'];
	$smilie_text = $row['smilie_text'];

	if (file_exists($smilie_image))
		{
		$smilie_preview = "<img src=\"".$smilie_image."\" alt=\"".$smilie_text."\" />";
		$smilie_img = @getimagesize($smilie_image);
		if ($smilie_img)
			{ $smilie_size = $smilie_img[0]."x".$smilie_img[1]." &nbsp;"; }
		else
			{ $smilie_size = "?"; }
		}
	else
		{
		$smilie_preview = "?";
		$smilie_size = "?";
		}

	$adminmain .= "<tr><td style=\"text-align:center;\">[<a href=\"admin.php?m=smilies&amp;a=delete&amp;id=".$smilie_id."&amp;".sed_xg()."\">x</a>]";
	$adminmain .= "<td style=\"text-align:center;\">".$smilie_preview."</td>";
	$adminmain .= "<td style=\"text-align:center;\">".$smilie_size."</td>";
	$adminmain .= "<td><input type=\"text\" class=\"text\" name=\"s[$smilie_id][code]\" value=\"".$smilie_code."\" size=\"12\" maxlength=\"16\" /></td>";
	$adminmain .= "<td><input type=\"text\" class=\"text\" name=\"s[$smilie_id][image]\" value=\"".$smilie_image."\" size=\"32\" maxlength=\"128\" /></td>";
	$adminmain .= "<td><input type=\"text\" class=\"text\" name=\"s[$smilie_id][text]\" value=\"".$smilie_text."\" size=\"12\" maxlength=\"64\" /></td></tr>";
	}

$adminmain .= "<tr><td colspan=\"6\"><input type=\"submit\" class=\"submit\" value=\"".$L['Update']."\" /></td></tr>";
$adminmain .= "</table></form>";

$adminmain .= "<h4>".$L['addnewentry']." :</h4>";
$adminmain .= "<form id=\"addsmilie\" action=\"admin.php?m=smilies&amp;a=add\" method=\"post\">";
$adminmain .= "<table class=\"cells\">";
$adminmain .= "<tr><td>".$L['Code']." :</td><td><input type=\"text\" class=\"text\" name=\"nsmiliecode\" value=\"\" size=\"40\" maxlength=\"16\" /> ".$L['adm_required']."</td></tr>";
$adminmain .= "<tr><td>".$L['ImageURL']." :</td><td><input type=\"text\" class=\"text\" name=\"nsmilieimage\" value=\"system/smilies/.gif\" size=\"40\" maxlength=\"128\" /> ".$L['adm_required']."</td></tr>";
$adminmain .= "<tr><td>".$L['Text']." :</td><td><input type=\"text\" class=\"text\" name=\"nsmilietext\" value=\"\" size=\"40\" maxlength=\"16\" /> ".$L['adm_required']."</td></tr>";
$adminmain .= "<tr><td><input type=\"submit\" class=\"submit\" value=\"".$L['Add']."\" colspan=\"2\" /></td></tr></table></form>";

?>