<?php
/***************************************************************************
 *                            viewtopic_quickreply.php
 *                            -------------------
 *   begin                : Tuesday, Apr 5, 2004
 *   copyright            : (C) 2004 Hayk Chamyan
 *   email                : hayk@mail.ru
 *
 *   $Header: viewtopic_quickreply.php, 8, 09.07.2005 01:12:27, Hayk Chamyan$
 *
 *
 ***************************************************************************/

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

$submit = $refresh = FALSE;
$hidden_form_fields = '<input type="hidden" name="mode" value="reply" />';
$hidden_form_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';

//
// Set toggles for various options
//
if ( !$board_config['allow_html'] )
{
	$html_on = 0;
}
else
{
	$html_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_html']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_html'] : $userdata['user_allowhtml'] );
}

if ( !$board_config['allow_bbcode'] )
{
	$bbcode_on = 0;
}
else
{
	$bbcode_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_bbcode']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_bbcode'] : $userdata['user_allowbbcode'] );
}

if ( !$board_config['allow_smilies'] )
{
	$smilies_on = 0;
}
else
{
	$smilies_on = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['disable_smilies']) ) ? 0 : TRUE ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? $board_config['allow_smilies'] : $userdata['user_allowsmile'] );
}

if ( ($submit || $refresh) && $is_auth['auth_read'])
{
	$notify_user = ( !empty($HTTP_POST_VARS['notify']) ) ? TRUE : 0;
}
else
{
	if ( $userdata['session_logged_in'] && $is_auth['auth_read'] )
	{
		$sql = "SELECT topic_id
			FROM " . TOPICS_WATCH_TABLE . "
			WHERE topic_id = $topic_id
				AND user_id = " . $userdata['user_id'];
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain topic watch information', '', __LINE__, __FILE__, $sql);
		}

		$notify_user = ( $db->sql_fetchrow($result) ) ? TRUE : $userdata['user_notify'];
		$db->sql_freeresult($result);
	}
	else
	{
		$notify_user = ( $userdata['session_logged_in'] && $is_auth['auth_read'] ) ? $userdata['user_notify'] : 0;
	}
}

$attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig'] );

$user_sig = ( $userdata['user_sig'] != '' ) ? $userdata['user_sig'] : '';

if ( (($userdata['user_quickreply_mode']==1) && ($userdata['user_id'] != ANONYMOUS)) || (($board_config['anonymous_sqr_mode']==1) && ($userdata['user_id'] == ANONYMOUS)) )
{
	$template->assign_block_vars('switch_advanced_qr', array());

	//
	// Signature toggle selection
	//
	if( $user_sig != '' )
	{
		$template->assign_block_vars('switch_advanced_qr.switch_signature_checkbox', array());
	}

	//
	// HTML toggle selection
	//
	if ( $board_config['allow_html'] )
	{
		$html_status = $lang['HTML_is_ON'];
		$template->assign_block_vars('switch_advanced_qr.switch_html_checkbox', array());
	}
	else
	{
		$html_status = $lang['HTML_is_OFF'];
	}

	//
	// BBCode toggle selection
	//
	if ( $board_config['allow_bbcode'] )
	{
		$bbcode_status = $lang['BBCode_is_ON'];
		$template->assign_block_vars('switch_advanced_qr.switch_bbcode_checkbox', array());
	}
	else
	{
		$bbcode_status = $lang['BBCode_is_OFF'];
	}

	//
	// Smilies toggle selection
	//
	if ( $board_config['allow_smilies'] )
	{
		$smilies_status = $lang['Smilies_are_ON'];
		$template->assign_block_vars('switch_advanced_qr.switch_smilies_checkbox', array());
	}
	else
	{
		$smilies_status = $lang['Smilies_are_OFF'];
	}

	//
	// Notify checkbox - only show if user is logged in
	//
	if ( $userdata['session_logged_in'] && $is_auth['auth_read'] )
	{
		if ( $mode != 'editpost' || ( $mode == 'editpost' && $post_info['poster_id'] != ANONYMOUS ) )
		{
			$template->assign_block_vars('switch_advanced_qr.switch_notify_checkbox', array());
		}
	}

	// Generate smilies listing for page output
	generate_smilies('inline', PAGE_POSTING);

	$template->assign_vars(array(

		'HTML_STATUS' => $html_status,
		'BBCODE_STATUS' => sprintf($bbcode_status, '<a href="' . append_sid("faq.$phpEx?mode=bbcode") . '" target="_phpbbcode">', '</a>'),
		'SMILIES_STATUS' => $smilies_status,
		'L_OPTIONS' => $lang['Options'],
		'L_DISABLE_HTML' => $lang['Disable_HTML_post'],
		'L_DISABLE_BBCODE' => $lang['Disable_BBCode_post'],
		'L_DISABLE_SMILIES' => $lang['Disable_Smilies_post'],
		'L_ATTACH_SIGNATURE' => $lang['Attach_signature'],
		'L_NOTIFY_ON_REPLY' => $lang['Notify'],

		// javascript
		'L_BBCODE_B_HELP' => $lang['bbcode_b_help'],
		'L_BBCODE_I_HELP' => $lang['bbcode_i_help'],
		'L_BBCODE_U_HELP' => $lang['bbcode_u_help'],
		'L_BBCODE_Q_HELP' => $lang['bbcode_q_help'],
		'L_BBCODE_C_HELP' => $lang['bbcode_c_help'],
		'L_BBCODE_L_HELP' => $lang['bbcode_l_help'],
		'L_BBCODE_O_HELP' => $lang['bbcode_o_help'],
		'L_BBCODE_P_HELP' => $lang['bbcode_p_help'],
		'L_BBCODE_W_HELP' => $lang['bbcode_w_help'],
		'L_BBCODE_A_HELP' => $lang['bbcode_a_help'],
		'L_BBCODE_S_HELP' => $lang['bbcode_s_help'],
		'L_BBCODE_F_HELP' => $lang['bbcode_f_help'],

		'L_FONT_COLOR' => $lang['Font_color'],
		'L_COLOR_DEFAULT' => $lang['color_default'],
		'L_COLOR_DARK_RED' => $lang['color_dark_red'],
		'L_COLOR_RED' => $lang['color_red'],
		'L_COLOR_ORANGE' => $lang['color_orange'],
		'L_COLOR_BROWN' => $lang['color_brown'],
		'L_COLOR_YELLOW' => $lang['color_yellow'],
		'L_COLOR_GREEN' => $lang['color_green'],
		'L_COLOR_OLIVE' => $lang['color_olive'],
		'L_COLOR_CYAN' => $lang['color_cyan'],
		'L_COLOR_BLUE' => $lang['color_blue'],
		'L_COLOR_DARK_BLUE' => $lang['color_dark_blue'],
		'L_COLOR_INDIGO' => $lang['color_indigo'],
		'L_COLOR_VIOLET' => $lang['color_violet'],
		'L_COLOR_WHITE' => $lang['color_white'],
		'L_COLOR_BLACK' => $lang['color_black'],

		'L_FONT_SIZE' => $lang['Font_size'],
		'L_FONT_TINY' => $lang['font_tiny'],
		'L_FONT_SMALL' => $lang['font_small'],
		'L_FONT_NORMAL' => $lang['font_normal'],
		'L_FONT_LARGE' => $lang['font_large'],
		'L_FONT_HUGE' => $lang['font_huge'],

		'L_BBCODE_CLOSE_TAGS' => $lang['Close_Tags'],
		'L_STYLES_TIP' => $lang['Styles_tip'],

		'S_HTML_CHECKED' => ( !$html_on ) ? 'checked="checked"' : '',
		'S_BBCODE_CHECKED' => ( !$bbcode_on ) ? 'checked="checked"' : '',
		'S_SMILIES_CHECKED' => ( !$smilies_on ) ? 'checked="checked"' : '',
		'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? 'checked="checked"' : '',
		'S_NOTIFY_CHECKED' => ( $notify_user ) ? 'checked="checked"' : '')
	);

}
else
{
	if ( !$html_on )
	{
		$hidden_form_fields .= '<input type="hidden" name="disable_html" value="on" />';
	}
	if ( !$bbcode_on )
	{
		$hidden_form_fields .= '<input type="hidden" name="disable_bbcode" value="on" />';
	}
	if ( !$smilies_on )
	{
		$hidden_form_fields .= '<input type="hidden" name="disable_smilies" value="on" />';
	}
	if ( $attach_sig )
	{
		$hidden_form_fields .= '<input type="hidden" name="attach_sig" value="on" />';
	}
	if ( $notify_user )
	{
		$hidden_form_fields .= '<input type="hidden" name="notify" value="on" />';
	}
}

if( !$userdata['session_logged_in'] || ( $mode == 'editpost' && $post_info['poster_id'] == ANONYMOUS ) )
{
	$template->assign_block_vars('switch_username_select', array());
}

//
// Output the data to the template
//
if ( (($userdata['user_open_quickreply']==1) && ($userdata['user_id'] != ANONYMOUS)) || (($board_config['anonymous_open_sqr']==1) && ($userdata['user_id'] == ANONYMOUS)) )
{
	$template->assign_block_vars('switch_open_qr_yes', array());
}
else
{
	$template->assign_block_vars('switch_open_qr_no', array());
}

$template->assign_vars(array(
	'U_POST_SQR_TOPIC' => 'javascript:sqr_show_hide();',
	'SQR_IMG' => $images['quickreply'],
	'L_POST_SQR_TOPIC' => $lang['Show_hide_quick_reply_form'],

	'L_EMPTY_MESSAGE' => $lang['Empty_message'],
	'L_QUICK_REPLY' => $lang['Quick_Reply'],
	'L_USERNAME' => $lang['Username'],
	'L_SUBJECT' => $lang['Subject'],
	'L_MESSAGE_BODY' => $lang['Message_body'],
	'L_PREVIEW' => $lang['Preview'],
	'L_SUBMIT' => $lang['Submit'],
	'S_POST_ACTION' => append_sid("posting.$phpEx"),
	'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields)
);

$template->assign_var_from_handle('QRBODY', 'qrbody');

?>
