<?php
/*

# CloudFW Register Functions
# Author: Orkun Gürsel - contact@orkungursel.com - support@cloudfw.net

*/

function cloudfw_get_form_vars($id, $vars = array()){
	foreach((array)$vars as $var){
		$out[] = $id.'_'.$var;
	}
	return $out;
};



function cloudfw_PV($data = array()) {
	$out = cloudfw_PV_foreach($data);
	return $out;
}


function cloudfw_PV_foreach($skin = array()) {
	
		if (is_array($skin)){
			
		foreach ((array)$skin as $element => $attributes) {
			
			if (is_array($attributes)){
				
				foreach ($attributes as $attribute => $value) {
					
					$var = cloudfw_PV_make_attribute($element,$attribute,$value);
					if ($var) $out_attr[$attribute] = $var;
					
				} // foreach: attributes
					
			} // is_array: attributes
			
			if ($out_attr) $out[$element] = $out_attr;
			$out_attr = NULL;
		
		} // foreach: element
		
	}
	
	if ($out) return $out; else return false;
	
}

function cloudfw_PV_make_attribute( $element = NULL, $attribute = NULL, $value = NULL ) {
		
	//if (!$value && $value !== "0") return false;
	$keys = @key($value);
	
	if (is_array($value) && $keys=="pattern_" ) {
			
		$form = $value["pattern_"];
		unset($value["pattern_"]);
					
			foreach($value as $number => $sub_value) {
				$var = $_POST[cloudfw_PV_make_form_name($element,$attribute.'_'.$number)];
				if (!is_array($var)) $var = stripslashes($var);
				if($var) $out[$number] = $var;
			}
						
	if (!empty($out)) return $out; else return false;
						
	}else{
		
		switch ($attribute) {
			case 'ID':
				return false;
			break;
			default:
				$var = $_POST[cloudfw_PV_make_form_name($element,$attribute)];
				if (!is_array($var)) $var = stripslashes($var);
				if($var) $out = $var;
				
			break;	
			}
	
	if (!empty($out)) return $out; else return false;
	
	}
	
	
}



?>