<?php

class ModelExtensionAccountCombine extends Model {

	private $_field_usage = false;
	private $_field_display = array('c' => false, 'r' => false);
	
	public function use_fields() {
		if($this->config->get('module_tracking_input_status') && $this->config->get('module_tracking_input_require_code')) return true;
		$fields = $this->config->get('module_account_combine_fields');
		foreach($this->config->get('module_account_combine__fields') as $f) {
			if($fields[$f] != 'n') return true;
		}
		return false;
	}

	public function field_usage() {
		if($this->_field_usage === false) {
			$this->_field_usage = array('n' => array(), 'r' => array(), 'y' => array());
			$fields = $this->config->get('module_account_combine_fields');
			foreach($this->config->get('module_account_combine__fields') as $f) {
				$this->_field_usage[$fields[$f]][] = $f;
			}
		}
		return $this->_field_usage;
	}
	

	public function field_display($section = 'r') {
		if($section !== 'r') $section = 'c';
		if($this->_field_display[$section] === false) {
			$c = $this->config->get('module_account_combine_' . $section . 'form');
			$this->_field_display[$section]['agreement'] = !!$c['agreement'];
			foreach($c as $k => $v) {
				if(substr($k, 0, 5) === 'show_') $this->_field_display[$section][substr($k, 5)] = !!$v;
			}
		}
	     	return  $this->_field_display[$section];
	}


	public function show_fields() {
		if($this->config->get('module_tracking_input_choose_code')) return true;
		$c = $this->config->get('module_account_combine_rform');
		if($c['agreement']) return true;
		foreach($c as $k => $v) {
			if(substr($k, 0, 5) === 'show_' && $v) return true;
		}
		return false;
	}
	
	public function require_fields() {
		$this->field_usage();
		return $this->_field_usage['r'];
	}	
	
	
}

