<?php

	class classFilter
	{
		static function validateMail($email) { 
			 $regexp='/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/';
			 return preg_match($regexp, trim($email));
		}
		
		static function validateNumber($no)
		{
			 $regexp="/[^0-9-. ]/";
			 if(preg_match($regexp,$no))
			 {
				 return 0;
			 }
			 else
			 {
				 return 1;
			 }
		}
		
		static function validateCreditCardNumber($type,$cc_num)
		{
			if($type=="MasterCard")
			{
				$pattern = "/^([51|52|53|54|55]{2})([0-9]{14})$/";//Mastercard
			}
			elseif($type=="Visa")
			{
				$pattern = "/^([4]{1})([0-9]{12,15})$/";//Visa
			}
			
			if(preg_match($pattern,$cc_num)) 
			{
				return 1;
			} 
			else 
			{
				return 0;
			}
		}
		
		static function filter_payment_data($array) {
			$filters = array
				(
					"merchant_spp_user_account"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"sku"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"item_id"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"item_title"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"item_price"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"quantity"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"delivery_address"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"delivery_shipping_amount"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"total_amount"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"return_url_on_success"=> array
						(
							"filter"=>FILTER_VALIDATE_URL
						),
					"return_url_on_failure"=> array
						(
							"filter"=>FILTER_VALIDATE_URL
						),
					"type_of_transaction"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"return_policy"=> array
						(
							"filter"=>FILTER_SANITIZE_STRING
						),
					"subcat_id"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"site_deduction_amount"=> array
						(
							"filter"=>FILTER_VALIDATE_INT
						),
					"site_user_email"=> array
						(
							"filter"=>FILTER_VALIDATE_EMAIL
						)
				);
			
			
			return filter_var_array($array,$filters);
		}
		
		static function validateTitle($accountTitle = NULL) {
			if(!is_null($accountTitle) AND !empty($accountTitle) AND $accountTitle != '')
			{
				if(preg_match('/[^A-Za-z0-9\?\.\,\_\:\-\"\@\*\(\)\&\#\$\! ]/',addslashes(strip_tags($accountTitle))))
				{
					
					return 0;
				}
				else
				{
					return 1;
				}
			}
			else
			{
				return 0;
			}
		}
		
		static function validateKeywords($string = NULL) {
			if(!is_null($string) AND !empty($string) AND $string != '')
			{
				if(preg_match('/[^a-zA-Z0-9\- ,]/',addslashes(strip_tags($string)))) 
				{
					
					return 0;
				}
				else
				{
					return 1;
				}
			}
			else
			{
				return 0;
			}
		}
		
		static function addMySlashes($variable) {
			if(get_magic_quotes_gpc() == 0)
			{
				$variable = addslashes($variable);
			}
			return $variable;
		}
		
		static function removeMySlashes($variable) {
			if(get_magic_quotes_gpc() == 0)
			{
				$variable = stripslashes($variable);
			}
			return $variable;
		}
		
		static function validateEmail($email) {
			if(!filter_var($email, FILTER_VALIDATE_EMAIL))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateInteger($integer) {
			if(!filter_var(trim($integer),FILTER_VALIDATE_INT))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validatePregInteger($integer) {
			if(preg_match('/[^\d]/',$integer))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateStringWithoutSpecialCharacters($string) {
			if(preg_match('/[^A-Za-z ]/',$string))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateStringWithoutSpaces($string) {
			if(preg_match('/[^A-Za-z]/',$string))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateName($string) {
			if(preg_match('/[^A-Za-z-_ ]/',$string))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateUniqueName($uniqueName) {
			if(preg_match('/[^A-Za-z0-9-_.]/',$uniqueName))  
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateURL($url) {
			if(!filter_var($url,FILTER_VALIDATE_URL))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		
		static function validateBlogURL($blogURL) {
			if(preg_match('/[^A-Za-z-_.]/',$blogURL))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		static function validateDate($date) {
			if(!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date))
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
	}
?>