<?php
	/***
	   * interface author codewriter
	   
	   * validation interface
	   * don't change or edit
	***/
include_once("_config_.php");

//require_once("interfaces/commoninterface.php");
// validation class
class FormValidation //implements InputValidationInterface
{	
	protected $_data;
	protected $_needle;
	protected $_in;

		// make conn	
		private function connt(){
			$conf = new config();
			return $conf->_conni();
		}

	public function data($data) 
	{
		$this->_data = $data;
		return $this->_data;
	}


	public function validate($value, $needle)
	{
		$this->_needle = $needle;
		
		if($this->_needle == 'str') {
			//if(preg_match('/^([a-zA-Z0-9,.&%!$£_+-\s\']){3,1000}$/',  $this->data($value)))
			if($this->data($value) != '')
			{
				return TRUE;
			}else{
				return FALSE;
			}
		}elseif($this->_needle == 'em') {
		
			if(preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $this->data($value)))
			{
				return TRUE;
			}else{
				return FALSE;
			}
		
		}elseif($this->_needle == 'int') {
		
			if(preg_match('/^([0-9+.,$%]){1,11}$/', $this->data($value)))
			{
				return TRUE;
			}else{
				return FALSE;
			}
			
		}elseif($this->_needle == 'url') {
		
			if(preg_match('/^(http|https):\/\/[a-z0-9_]+([\-\.]{1}[a-z_0-9]+)*\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\/.*)?$/i', $this->data($value)))
			{
				return TRUE;
			}else{
				return TRUE;
				// set return FALSE of validation required
			}
		
		} // end needle
			
			
	} // end method validate
	
	public function iValid($input, $message, $validType)
	{
		
			if($this->validate($input, $validType) == TRUE) 
			{ 
			echo "<div id='success_alert'>Value Accepted</div>";
			return addslashes(mysqli_real_escape_string($this->connt(), $input));
			 
			}else{
			echo "<div id='err_alert'>".$this->isExist($message)."</div>";  
			return '';
			
			}
	
	}
	
	public function isExist($in)
	{
		if($in != ''){
		$this->_in = $in;
		return $this->_in;
		}else{
		throw new Exception('Input/Message Variable Must Be Define/Added');
		}
	}
	
	

	
} // end class Formvalidation 

?>