<?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_blocker_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'] == 'get_blocker') AND !is_member_of($vbulletin->userinfo, explode(',', $vbulletin->options['dbtech_vbsuper_pm_auto_blocker_allowed'])))
	{
		eval(standard_error($vbulletin->options['dbtech_vbsuper_pm_cantuse_blocker']));
	}

// ############################### start display options ###############################
	if (!$vbulletin->options['dbtech_vbsuper_pm_auto_blocker_active'])
	{
		eval(standard_error(fetch_error('dbtech_vbsuper_pm_blocker_disabled')));
	}
	else
	{	
		if ($_REQUEST['action'] == 'get_blocker')
		{
			// Navigation bits
			$navbits[''] = $vbphrase['dbtech_vbsuper_pm_auto_block_usercp_navbit'];
	
			$pm_auto_blocker = $db->query_first("
				SELECT dbtech_vbsuper_pm_blocked, dbtech_vbsuper_pm_blocked_active
				FROM " . TABLE_PREFIX . "userfield
				WHERE userid = '" . $user_id . "'
			");

			$pm_auto_blocker['dbtech_vbsuper_pm_blocked'] = iif(empty($pm_auto_blocker['dbtech_vbsuper_pm_blocked']), ' ', $pm_auto_blocker['dbtech_vbsuper_pm_blocked']);
			$pm_auto_blocker['dbtech_vbsuper_pm_blocked_active'] = iif(empty($pm_auto_blocker['dbtech_vbsuper_pm_blocked_active']), '0', $pm_auto_blocker['dbtech_vbsuper_pm_blocked_active']);

			$page_templater = vB_Template::create('dbtech_vbsuper_pm_blocker_options');
			$page_templater->register('pm_auto_blocker', $pm_auto_blocker);
			$template_hook['usercp_options_other'] .= $page_templater->render();		
				
		}		

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

		if (count($vbulletin->GPC['pm_auto_blocker']))
		{
			// Make sure blocker is active
			$vbulletin->GPC['pm_auto_blocker']['dbtech_vbsuper_pm_blocked_active'] = iif(
				in_array($vbulletin->GPC['pm_auto_blocker']['dbtech_vbsuper_pm_blocked_active'], array('0', '1')),
				$vbulletin->GPC['pm_auto_blocker']['dbtech_vbsuper_pm_blocked_active'],
				'0'
			);

				$vbulletin->db->query_write(" 
		UPDATE " . TABLE_PREFIX . "userfield SET 
			dbtech_vbsuper_pm_blocked = '".$db->escape_string($vbulletin->GPC['pm_auto_blocker']['dbtech_vbsuper_pm_blocked'])."',
			dbtech_vbsuper_pm_blocked_active = '" . intval($vbulletin->GPC['pm_auto_blocker']['dbtech_vbsuper_pm_blocked_active']) . "'
			WHERE userid = '" . $user_id . "'
		");
		}
		
		$vbulletin->url = 'vbsuper_pm.php?' . $vbulletin->session->vars['sessionurl'] . 'do=blocker&action=get_blocker';
		print_standard_redirect(array('redirect_dbtech_vbsuper_pm_updatethanks_blocker',$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                                                        * >>
<< ********************************************************************* >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
?>