<?php 

/***************************************************************************
 *
 *      Update to 2.0.15 by Alf (07.05.2005) 22:02
 *
 *	Title: xphpBBi - phpBB Complete Integration project 
 *	Description: Project to turn the phpBB forums into a fully functioning
 *		Xoops2 Module. Based on the phpBB 2.0.11 port from BBpixel.com - 
 *		(PBBoard v1.22).
 *	Credits: Xoops2 Module Development Team - Koudanshi - phpBB Group
 *	Thanks: To Koudanshi for a great start in his port, and phpBB Group for
 *		such a great forum software.
 *	License: GNU/GPL version 2 or later.
 ****************************************************************************/

/***************************************************************************
 *                              quick_reply.php
 *                            -------------------
 *   begin                : Tuesday, Aug 20, 2002
 *   copyright            : RustyDragon 
 *   original work by     : Smartor <smartor_xp@hotmail.com>
 *   contact              : <dev@RustyDragon.com>, http://www.RustyDragon.com
 *   $Id: quick_reply.php,v 1.4.1.1 2002/11/18 13:35:54 RustyDragon Exp $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/


//
// BEGIN OUTPUT
//

$phpbb_root_path = "./";

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
}

$template->set_filenames(array(
        'quick_reply_output' => 'quick_reply.tpl')
);
        

if ( !(((!$is_auth['auth_reply']) or 
($forum_topic_data['forum_status'] == FORUM_LOCKED) or 
($forum_topic_data['topic_status'] == TOPIC_LOCKED)) and ($userdata['user_level'] != ADMIN)))
{
        $bbcode_uid = $postrow[$total_posts - 1]['bbcode_uid'];
        $last_poster = $postrow[$total_posts - 1]['uname'];
        $last_msg = $postrow[$total_posts - 1]['post_text'];
        $last_msg = str_replace(":1:$bbcode_uid", '', $last_msg);
        $last_msg = str_replace(":$bbcode_uid", '', $last_msg);        
        $last_msg = str_replace("'", '&#39;', $last_msg);
        $last_msg = "[quote=\"$last_poster\"]" . $last_msg . '[/quote]';
        $attach_sig = (( is_object($xoopsUser) ) ? $userdata['attachsig'] : 0)?"checked='checked'":'';
        $notify_user = (( is_object($xoopsUser) ) ? $userdata['user_notify'] : 0)?"checked='checked'":'';
        
        $template->assign_block_vars('quick_reply', array(
                'POST_ACTION' => append_sid("posting.php"),
                'TOPIC_ID' => $topic_id,
                'SID' => $userdata['sess_id'],
                'LAST_MESSAGE' => $last_msg)
        );

        if( is_object($xoopsUser) )
        {
                $template->assign_block_vars('quick_reply.user_logged_in', array(
                        'ATTACH_SIGNATURE' => $attach_sig,
                        'NOTIFY_ON_REPLY' => $notify_user)
                );
        }else
        {
                $template->assign_block_vars('quick_reply.user_logged_out', array());
        }

        generate_smilies();

        $template->assign_vars(array(
                'U_MORE_SMILIES' => append_sid("posting.php?mode=smilies"),
                'L_USERNAME' => $lang['Username'],
                'L_PREVIEW' => $lang['Preview'],
                'L_OPTIONS' => $lang['Options'],
                'L_SUBMIT' => $lang['Submit'],
		'L_SENDING' => $lang['Sending'], 
                'L_CANCEL' => $lang['Cancel'],
                'L_ATTACH_SIGNATURE' => $lang['Attach_signature'], 
		'L_EMOTICONS' => $lang['Emoticons'], 
                'L_NOTIFY_ON_REPLY' => $lang['Notify'],
                'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
                'L_ALL_SMILIES' => $lang['Quick_Reply_smilies'],
                'L_QUOTE_SELECTED' => $lang['QuoteSelelected'],
                'L_NO_TEXT_SELECTED' => $lang['QuoteSelelectedEmpty'],
                'L_EMPTY_MESSAGE' => $lang['Empty_message'],
                'L_QUOTE_LAST_MESSAGE' => $lang['Quick_quote'],
                'L_QUICK_REPLY' => $lang['Quick_Reply'],
                'L_PREVIEW' => $lang['Preview'],
                'L_SUBMIT' => $lang['Submit'])
);
}
$template->assign_var_from_handle('QUICKREPLY_OUTPUT', 'quick_reply_output');

function generate_smilies()
{
        global $db, $board_config, $template;

        $max_smilies_first = 4;
        $max_smilies_second = 8;
        $max_smilies_third = 12;
        $max_smilies_fourth = 16;
        $max_smilies_five = 20;


        switch ( SQL_LAYER )
        {
                case 'mssql':
                        $sql = 'SELECT TOP ' . $max_smilies_first . ' min(emotion) AS emotion,
                        min(code) AS code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY [smile_url]';
	                break;
                default:
                        $sql = 'SELECT emotion, code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY smile_url
                        ORDER BY id LIMIT ' . $max_smilies_first;
      	          break;
        }
        if (!$result = $db->sql_query($sql))
        {
                message_die(GENERAL_ERROR, "Couldn't retrieve smilies list", '', __LINE__, __FILE__, $sql);
        }
        $smilies_count_first = $db->sql_numrows($result);
        $smilies_data_first = $db->sql_fetchrowset($result);

        for ($i = 0; $i < $smilies_count_first; $i++)
        {
		$template->assign_block_vars('quick_reply.smilies_first_row', array(
            	'CODE' => $smilies_data_first[$i]['code'],
            	'URL' => $board_config['smilies_path'] . '/' . $smilies_data_first[$i]['smile_url'],
                  'DESC' => $smilies_data_first[$i]['emotion'])
	      );
        }

        switch ( SQL_LAYER )
        {
                case 'mssql':
                        $sql = 'SELECT TOP ' . $max_smilies_second . ' min(emotion) AS emotion,
                        min(code) AS code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY [smile_url]';
	                break;
                default:
                        $sql = 'SELECT emotion, code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY smile_url
                        ORDER BY id LIMIT ' . $max_smilies_second;
      	          break;
        }
        if (!$result = $db->sql_query($sql))
        {
                message_die(GENERAL_ERROR, "Couldn't retrieve smilies list", '', __LINE__, __FILE__, $sql);
        }
        $smilies_count_second = $db->sql_numrows($result);
        $smilies_data_second = $db->sql_fetchrowset($result);

        for ($i = $max_smilies_first; $i < $smilies_count_second; $i++)
        {
		$template->assign_block_vars('quick_reply.smilies_second_row', array(
            	'CODE' => $smilies_data_second[$i]['code'],
            	'URL' => $board_config['smilies_path'] . '/' . $smilies_data_second[$i]['smile_url'],
                  'DESC' => $smilies_data_second[$i]['emotion'])
	      );
        }

        switch ( SQL_LAYER )
        {
                case 'mssql':
                        $sql = 'SELECT TOP ' . $max_smilies_third . ' min(emotion) AS emotion,
                        min(code) AS code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY [smile_url]';
	                break;
                default:
                        $sql = 'SELECT emotion, code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY smile_url
                        ORDER BY id LIMIT ' . $max_smilies_third;
      	          break;
        }
        if (!$result = $db->sql_query($sql))
        {
                message_die(GENERAL_ERROR, "Couldn't retrieve smilies list", '', __LINE__, __FILE__, $sql);
        }
        $smilies_count_third = $db->sql_numrows($result);
        $smilies_data_third = $db->sql_fetchrowset($result);

        for ($i = $max_smilies_second; $i < $smilies_count_third; $i++)
        {
		$template->assign_block_vars('quick_reply.smilies_third_row', array(
            	'CODE' => $smilies_data_third[$i]['code'],
            	'URL' => $board_config['smilies_path'] . '/' . $smilies_data_third[$i]['smile_url'],
                  'DESC' => $smilies_data_third[$i]['emotion'])
	      );
        }

        switch ( SQL_LAYER )
        {
                case 'mssql':
                        $sql = 'SELECT TOP ' . $max_smilies_fourth . ' min(emotion) AS emotion,
                        min(code) AS code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY [smile_url]';
	                break;
                default:
                        $sql = 'SELECT emotion, code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY smile_url
                        ORDER BY id LIMIT ' . $max_smilies_fourth;
      	          break;
        }
        if (!$result = $db->sql_query($sql))
        {
                message_die(GENERAL_ERROR, "Couldn't retrieve smilies list", '', __LINE__, __FILE__, $sql);
        }
        $smilies_count_fourth = $db->sql_numrows($result);
        $smilies_data_fourth = $db->sql_fetchrowset($result);

        for ($i = $max_smilies_third; $i < $smilies_count_fourth; $i++)
        {
		$template->assign_block_vars('quick_reply.smilies_fourth_row', array(
            	'CODE' => $smilies_data_fourth[$i]['code'],
            	'URL' => $board_config['smilies_path'] . '/' . $smilies_data_fourth[$i]['smile_url'],
                  'DESC' => $smilies_data_fourth[$i]['emotion'])
	      );
        }

        switch ( SQL_LAYER )
        {
                case 'mssql':
                        $sql = 'SELECT TOP ' . $max_smilies_five . ' min(emotion) AS emotion,
                        min(code) AS code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY [smile_url]';
	                break;
                default:
                        $sql = 'SELECT emotion, code, smile_url
                        FROM ' . SMILIES_TABLE . ' 
                        GROUP BY smile_url
                        ORDER BY id LIMIT ' . $max_smilies_five;
      	          break;
        }
        if (!$result = $db->sql_query($sql))
        {
                message_die(GENERAL_ERROR, "Couldn't retrieve smilies list", '', __LINE__, __FILE__, $sql);
        }
        $smilies_count_five = $db->sql_numrows($result);
        $smilies_data_five = $db->sql_fetchrowset($result);

        for ($i = $max_smilies_fourth; $i < $smilies_count_five; $i++)
        {
		$template->assign_block_vars('quick_reply.smilies_five_row', array(
            	'CODE' => $smilies_data_five[$i]['code'],
            	'URL' => $board_config['smilies_path'] . '/' . $smilies_data_five[$i]['smile_url'],
                  'DESC' => $smilies_data_five[$i]['emotion'])
	      );
        }
}
?>
