<?php

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

define('STOP_STYLE',true);

$CALL_SYSTEM			=	array();
$CALL_SYSTEM['LANG'] 	= 	true;
$CALL_SYSTEM['VISITOR'] 	= 	true;

include('common.php');

define('CLASS_NAME','PowerBBChangeLangMOD');

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

		$PowerBB->_GET['id'] = $PowerBB->functions->CleanVariable($PowerBB->_GET['id'],'intval');

		if (empty($PowerBB->_GET['id']))
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}

		if ($PowerBB->_GET['change'])
		{
			$LangArr 				= 	array();
			$LangArr['field']		=	array();

			$LangArr['field']['lang'] = $PowerBB->_GET['id'];

			if ($PowerBB->_CONF['member_permission'])
			{
				$LangArr['where'] = array('id',$PowerBB->_CONF['member_row']['id']);

				$change = $PowerBB->member->UpdateMember($LangArr);
			}
			else
			{
				$Lang_id = $PowerBB->_GET['id'];
				if ($PowerBB->visitor->IsVisitor(array('where' => array('ip',$PowerBB->_CONF['ip']))))
				{
					$UpdatevisitorArr 							= 	array();
					$UpdatevisitorArr['field']['lang_id'] 	= 	$Lang_id;
			        $UpdatevisitorArr['where'] 		    	= 	array('ip',$PowerBB->_CONF['ip']);

					$Update = $PowerBB->visitor->UpdateVisitor($UpdatevisitorArr);

                    $PowerBB->functions->redirect('index.php');
				}
			  else
			    {
					$VisitorLangArr 				= 	array();
					$VisitorLangArr['field']		=	array();

					$VisitorLangArr['field']['ip'] 		= 	$PowerBB->_CONF['ip'];
					$VisitorLangArr['field']['lang_id'] 	= 	$Lang_id;

					$InsertBan = $PowerBB->visitor->InsertVisitor($VisitorLangArr);

					$PowerBB->functions->redirect('index.php');
               }
			}

			if ($change)
			{
				$PowerBB->functions->msg($PowerBB->_CONF['template']['lang']['Language_changed_successfully']);
				$PowerBB->functions->redirect('index.php');
			}
		}
		else
		{
			$PowerBB->functions->error($PowerBB->_CONF['template']['lang']['path_not_true']);
		}
	}
}

?>
