<?php

class setting{
	var $var;

	function __construct(){
		if($_SERVER['REQUEST_METHOD']=='GET'){
			$this->view();
		}else{
			$this->edit();
		}
	}

	private function edit(){
		global $connect;
		$data['login']=ReplaceContent(trim($_POST['login']));
		$data['password']=ReplaceContent(trim($_POST['password']));
		$data['confpassword']=ReplaceContent(trim($_POST['confpassword']));

		if(!$this->validation($data)){
			return false;
		}else{
			if($data['password']!=='' or $data['confpassword']!==''){
				mysqli_query($connect,'UPDATE config SET login="'.base64_encode($data['login']).'", password="'.md5($data['password'].'ghj%^&gjfhbfdn34&*').'"');
			}else{
				mysqli_query($connect,'UPDATE config SET login="'.base64_encode($data['login']).'"');
			}
		}
		$text=$GLOBALS['lang']['tri5'];
		$location='setting';
		include('./inc/success.php');
	}

	private function validation($data){
		if(strlen($data['login'])<3){
			$this->warning($GLOBALS['lang']['war1']); return false;
		}elseif(strlen($data['password'])<5 and $data['password']!==''){
			$this->warning($GLOBALS['lang']['war2']); return false;
		}elseif($data['password']!==$data['confpassword']){
			$this->warning($GLOBALS['lang']['war3']); return false;
		}
		return true;
	}

	private function warning($text){
	   $location='setting';
	   include('./inc/warning.php');
    }

	private function view(){
		global $connect;
		$MySQL=mysqli_query($connect,'SELECT login FROM config');
		$row=mysqli_fetch_assoc($MySQL);
		include('./inc/forms/setting.php');
	}
}

?>