<?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_notif_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_notif') AND !$vbulletin->options['dbtech_vbsuper_pm_notif_allow_disable'])
	{
		eval(standard_error($vbulletin->options['dbtech_vbsuper_pm_cantuse_notif_warning']));
	}

// ############################### start display options ###############################
	if (!$vbulletin->options['dbtech_vbsuper_pm_notif_active'])
	{
		eval(standard_error(fetch_error('dbtech_vbsuper_pm_notif_disabled')));
	}
	else
	{	
		if ($_REQUEST['action'] == 'get_notif')
		{
			// Navigation bits
			$navbits[''] = $vbphrase['dbtech_vbsuper_pm_notif_nav_link'];
							
				//Get users notif active status 
    			$pm_notif = $db->query_first("
					SELECT dbtech_vbsuper_pm_notif_active
					FROM " . TABLE_PREFIX . "userfield
					WHERE userid = '" . $user_id . "'
				");

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

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

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

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

		$vbulletin->url = 'vbsuper_pm.php?' . $vbulletin->session->vars['sessionurl'] . 'do=notif&action=get_notif';
		print_standard_redirect(array('redirect_dbtech_vbsuper_pm_updatethanks_notif_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                                                        * >>
<< ********************************************************************* >>
\*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
?>