<?php
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*\
<< ******************************************************************** >>
<< * ---------------------------------------------------------------- * >>
<< * Copyright ©2011-2012 Ozzy47                                      * >>
<< * All Rights Reserved. 											  * >>
<< * This file may not be redistributed in whole or significant part. * >>
<< * ---------------------------------------------------------------- * >>
<< * You are not allowed to use this on your server unless the files  * >>
<< * you downloaded were done so with permission.					  * >>
<< * ---------------------------------------------------------------- * >>
<< ******************************************************************** >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/

//Check to see if the entire system is active in General Settings
if (!$vbulletin->options['dbtech_vbsuper_pm_system_enabled'])
{
	eval(standard_error(fetch_error('dbtech_vbsuper_pm_post_quote_disabled')));
}
		
// ######################### REQUIRE BACK-END ############################
require_once(DIR . '/includes/functions_user.php');

// #################### DEFINE IMPORTANT CONSTANTS #######################
$user_id = $vbulletin->userinfo['userid'];

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

	if (($_REQUEST['action'] == 'post_quote') AND !is_member_of($vbulletin->userinfo, explode(',', $vbulletin->options['dbtech_vbsuper_pm_post_quote_allowed'])))
	{
		eval(standard_error($vbulletin->options['dbtech_vbsuper_pm_cantuse_post_quote_warning']));
	}

// ############################### start display options ###############################
	if (!$vbulletin->options['dbtech_vbsuper_pm_post_quote_active'])
	{
		eval(standard_error(fetch_error('dbtech_vbsuper_pm_post_quote_disabled')));
	}
	else
	{	
		if ($_REQUEST['action'] == 'get_post_quote')
		{
			// Navigation bits
			$navbits[''] = $vbphrase['dbtech_vbsuper_pm_post_quote_nav_link'];
							
				//Get users post quote active status 
    			$pm_quote_post = $db->query_first("
					SELECT dbtech_vbsuper_pm_quote_post_active
					FROM " . TABLE_PREFIX . "userfield
					WHERE userid = '" . $user_id . "'
				");

			$pm_quote_post['dbtech_vbsuper_pm_quote_post_active'] = iif(empty($pm_quote_post['dbtech_vbsuper_pm_quote_post_active']), '0', $pm_quote_post['dbtech_vbsuper_pm_quote_post_active']);
			$page_templater = vB_Template::create('dbtech_vbsuper_pm_post_quote_options');
			$page_templater->register('pm_quote_post', $pm_quote_post);
			$template_hook['usercp_options_other'] .= $page_templater->render();		
				
		}		

// ############################### start save options ##################################
	if ($_POST['action'] == 'save_post_quote')
	{	
		$vbulletin->input->clean_array_gpc('p', array(
			'pm_quote_post' => TYPE_ARRAY_NOHTML
			
		));			

		if (count($vbulletin->GPC['pm_quote_post']))
		{
			// Make sure post quote is active
				$vbulletin->GPC['pm_quote_post']['dbtech_vbsuper_pm_quote_post_active'] = iif(
				in_array($vbulletin->GPC['pm_quote_post']['dbtech_vbsuper_pm_quote_post_active'], array('0', '1')),
				$vbulletin->GPC['pm_quote_post']['dbtech_vbsuper_pm_quote_post_active'],
				'0'
			);

			$vbulletin->db->query_write(" 
				UPDATE " . TABLE_PREFIX . "userfield SET 
				dbtech_vbsuper_pm_quote_post_active = '" . intval($vbulletin->GPC['pm_quote_post']['dbtech_vbsuper_pm_quote_post_active']) . "'
				WHERE userid = '" . $user_id . "'
			");		
						
		}

		$vbulletin->url = 'vbsuper_pm.php?' . $vbulletin->session->vars['sessionurl'] . 'do=post_quote&amp;action=get_post_quote';
		print_standard_redirect(array('redirect_dbtech_vbsuper_pm_updatethanks_post_quote_msg',$vbulletin->userinfo['username']), true, true);
	}

	$navbar = render_navbar_template(construct_navbits($navbits));	
	construct_usercp_nav('dbtech_vbsuper_pm_' . $_REQUEST['action']);

	$templater = vB_Template::create('USERCP_SHELL');
		$templater->register_page_templates();
		$templater->register('cpnav', $cpnav);
		if (method_exists($page_templater, 'render'))
		{
			// Only run this if there's anything to render
			$templater->register('HTML', $page_templater->render());
		}
		$templater->register('clientscripts', $clientscripts);
		$templater->register('navbar', $navbar);
		$templater->register('navclass', $navclass);
		$templater->register('onload', $onload);
		$templater->register('pagetitle', $pagetitle);
		$templater->register('template_hook', $template_hook);
	print_output($templater->render());
	}		

/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*\
<< ********************************************************************* >>
<< * Created: 09:30, Fri June 8th 2012                                 * >>
<< * VER: 1.0.0                                                        * >>
<< ********************************************************************* >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
?>