<?

/**
*
* @package ppkBB3cker
* @version $Id: bar.php 1.000 2009-04-02 11:33:00 PPK $
* @copyright (c) 2008, 2009 PPK
* http://ppkbb3cker.rx22.ru, http://protoneutron.narod.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);

require($phpbb_root_path.'config.'.$phpEx);

if($dbms!='mysql')
{
	err('Only mysql supported');
}

$c=@mysql_connect($dbhost, $dbuser, $dbpasswd);
if(!$c)
{
	err('Error connecting database: '.mysql_error());
}

$s=@mysql_select_db($dbname, $c);
if(!$s)
{
	err('Error selecting database: '.mysql_error());
}

define('CONFIG_TABLE',				$table_prefix . 'config');
define('SMILIES_TABLE',				$table_prefix . 'smilies');

my_sql_query("SET NAMES 'utf8'");

$config=array();
$sql="SELECT config_name, config_value FROM ".CONFIG_TABLE." WHERE config_name='smilies_path'";
$result=my_sql_query($sql);
while($row=mysql_fetch_row($result))
{
	$config[$row[0]]=$row[1];
}
mysql_free_result($result);

$forum_id=intval(@$_GET['f']);
$forum_id < 0 ? $forum_id=0 : '';
$lang='ru';
$css_link='chat/stylesheet.css';
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<?=$phpbb_root_path.$css_link?>.chat.css" type="text/css">
<script language="JavaScript">
<!--
function inserttext(str)
{
	if(str!='')
	{
		parent.form.document.post_form.chat_message.value += str;
	}
	else
	{
		parent.form.document.post_form.chat_message.value = '';
	}
	parent.form.document.post_form.chat_message.focus();
}
-->
</script>
</head>
<body>
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td align="center" nowrap="nowrap">
<?
if($forum_id)
{
	echo chat_generate_smilies('inline', $forum_id);
}

?>
	</td>
</tr>
</table>
</body>
</html>
<?
mysql_close();

exit();

//############################################################

function my_sql_query($query)
{
	global $startsqlcount, $c;
	$startsqlcount+=1;

	return mysql_query($query);
}

//From includes/functions_posting.php
function chat_generate_smilies($mode, $forum_id)
{
	global $config, $phpEx, $phpbb_root_path, $dbms;

	$display_link = false;
	$chat_smilies='
	<table width="25%" cellpadding="2" cellspacing="0" border="0">
		<tr>';
	/*if ($mode == 'inline')
	{
		$sql = 'SELECT smiley_id
			FROM ' . SMILIES_TABLE . '
			WHERE display_on_posting = 0';
		$result=my_sql_query($sql);

		if ($row = mysql_fetch_row($result))
		{
			$display_link = true;
		}
		mysql_free_result($result);
	}*/

	$last_url = '';

	$sql = 'SELECT *
		FROM ' . SMILIES_TABLE .'
		ORDER BY smiley_order';
	$result = my_sql_query($sql);

	$smilies = array();
	while($row=mysql_fetch_array($result))
	{
		if (empty($smilies[$row['smiley_url']]))
		{
			$smilies[$row['smiley_url']] = $row;
		}
	}
	mysql_free_result($result);

	if (sizeof($smilies))
	{
		foreach ($smilies as $row)
		{
			$chat_smilies.='<td><a href="#" onClick="javascript:inserttext(\' '.$row['code'].' \');"><img alt="'.$row['emotion'].'" title="'.$row['emotion'].'" width="'.$row['smiley_width'].'" height="'.$row['smiley_height'].'" src="'.$phpbb_root_path . $config['smilies_path'] . '/' . $row['smiley_url'].'" border="0" /></a></td>';
		}
	}
	$smilies.='
		<tr>
	</table>';
	return $chat_smilies;

}

function err($str)
{
	echo $str;
	exit();
}
?>
