<?php

(!defined('IN_PowerBB')) ? die() : '';

$CALL_SYSTEM					=	array();
$CALL_SYSTEM['PM'] 				= 	true;
$CALL_SYSTEM['ICONS'] 			= 	true;
$CALL_SYSTEM['TOOLBOX'] 		= 	true;
$CALL_SYSTEM['FILESEXTENSION'] 	= 	true;
$CALL_SYSTEM['ATTACH'] 			= 	true;

define('JAVASCRIPT_PowerCode',true);

include('common.php');

define('CLASS_NAME','PowerBBPrivateMassegeMOD');

class PowerBBPrivateMassegeMOD
{
	function run()
	{
		global $PowerBB;

		if (!$PowerBB->_CONF['info_row']['pm_feature'])
		{
            $PowerBB->functions->ShowHeader();
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['no_pm']);
		}

		/** Can't use the private massege system **/
		if (!$PowerBB->_CONF['rows']['group_info']['use_pm'])
		{
            $PowerBB->functions->ShowHeader();
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Cant_use_pm']);
		}
		/** **/

		/** Visitor can't use the private massege system **/
		if (!$PowerBB->_CONF['member_permission'])
		{
            $PowerBB->functions->ShowHeader();
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Cant_see_pm']);
		}
		/** **/

		if ($PowerBB->_GET['setting'])
		{
			if ($PowerBB->_GET['index'])
			{
				$this->_SettingIndex();
			}
			elseif ($PowerBB->_GET['start'])
			{
				$this->_SettingStart();
			}
		}
		else
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}

		$PowerBB->functions->GetFooter();
	}

	function _SettingIndex()
	{
		global $PowerBB;

		$PowerBB->functions->ShowHeader();

		$PowerBB->template->display('pm_setting');
	}

	function _SettingStart()
	{
		global $PowerBB;

		$PowerBB->functions->ShowHeader();

		if ($PowerBB->_POST['autoreply']
			and (!isset($PowerBB->_POST['title']) or !isset($PowerBB->_POST['msg'])))
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['Please_fill_in_all_the_information']);
		}

		$PowerBB->_POST['title'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['title'],'sql');
		$PowerBB->_POST['msg']   = 	$PowerBB->functions->CleanVariable($PowerBB->_POST['msg'] ,'sql');
		$PowerBB->_POST['autoreply'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['autoreply'],'sql');
		$PowerBB->_POST['pm_senders_msg'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['pm_senders_msg'],'sql');
		$PowerBB->_POST['pm_senders'] 	= 	$PowerBB->functions->CleanVariable($PowerBB->_POST['pm_senders'],'sql');


		$UpdateArr 				= 	array();
		$UpdateArr['field']		=	array();

		$UpdateArr['field']['autoreply'] 		= 	$PowerBB->_POST['autoreply'];
		$UpdateArr['field']['autoreply_title'] 	= 	$PowerBB->_POST['title'];
		$UpdateArr['field']['autoreply_msg'] 	= 	$PowerBB->_POST['msg'];
		$UpdateArr['field']['pm_senders'] 		= 	$PowerBB->_POST['pm_senders'];
		$UpdateArr['field']['pm_senders_msg'] 	= 	$PowerBB->_POST['pm_senders_msg'];
		$UpdateArr['where']						=	array('id',$PowerBB->_CONF['member_row']['id']);

		$update = $PowerBB->member->UpdateMember($UpdateArr);

		if ($update)
		{
		    	$PowerBB->functions->msg($PowerBB->_CONF['template']['lang']['Data_has_been_updated_successfully']);
			$PowerBB->functions->redirect('index.php?page=pm_setting&amp;setting=1&amp;index=1');
		}
	}
}

?>
