<?php
require_once 'class.abstractcallforwardcriteria.php';

final class CallForwardCriteriaCallNightCircutState {
	const Enabled         = 0x00000000;
	const Disabled        = 0x00000001;
	
	private function __construct(){
	}
	
	public static function toMySQLEnum($type) {
		if($type == CallForwardCriteriaCallNightCircutState::Enabled) {
			return "enabled";
		} else {
			return "disabled";
		}
	}
	
	public static function fromMySQLEnum($type) {
		if ($type == "enabled" ) {
			return CallForwardCriteriaCallNightCircutState::Enabled;
		} else {
			return CallForwardCriteriaCallNightCircutState::Disabled;
		}
	}
	
}

class CallForwardCriteriaCallNightCircut extends AbstractCallForwardCriteria {
	
	private $mCallForwardCriteriaCallNightCircutState = CallForwardCriteriaCallNightCircutState::Enabled;
	
	public function __construct($parent){
		
		$this->mParent = $parent;
		
		$this->setCriteriaName("NightCircutState");
		$this->setCriteriaTitle(__("PHONESETTINGSCALLFORWARD_IN_NIGHTCIRCUTSTATE_GENERAL"));
		$property = new CallForwardCriteriaProperty();
		$property->setPropertyName("NightCircutState");
		$property->setPropertyTitle(__("PHONESETTINGSCALLFORWARD_IN_NIGHTCIRCUTSTATE_GENERAL"));
		$property->setPropertyTypeName("select");
		
		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName(CallForwardCriteriaCallNightCircutState::toMySQLEnum(CallForwardCriteriaCallNightCircutState::Enabled));
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_CALLSOURCE_NIGHTCIRCUTSTATE_GENERAL_ENABLED"));
		$property->addPropertyCapability($cap);
		
		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName(CallForwardCriteriaCallNightCircutState::toMySQLEnum(CallForwardCriteriaCallNightCircutState::Disabled));
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_CALLSOURCE_NIGHTCIRCUTSTATE_GENERAL_DISABLED"));
		$property->addPropertyCapability($cap);
						
		$this->addPropertyType($property);
		
		$groupList =$this->getAvialableGroups();
		if (count($groupList)) {
			$property = new CallForwardCriteriaProperty();
			$property->setPropertyName("groupId");
			$property->setPropertyTitle(__("PHONESETTINGSCALLFORWARD_GROUP"));
			$property->setPropertyTypeName("select");
			foreach ($groupList as $group) {
				$cap = new CallForwardCriteriaPropertyCapability();
				$cap->setName($group->id);
				$cap->setTitle($group->name);
				$property->addPropertyCapability($cap);
			}
			$this->addPropertyType($property);
		}
		
		
	}
	
	public function getAvialableGroups() {
	
		return $this->mParent->getAvialableGroups();
	}
	
	public function getMatchedStatus() {
		return CallForwardCriteriaCallNightCircutState::fromMySQLEnum($this->getProperty("NightCircutState"));
	}
	
	public function getCriteriaDescription() {

		$group_choosen = $this->getProperty("groupId","");
		$group = null;
		foreach ($this->getAvialableGroups() as $group) {
			if ($group_choosen== $group->id) {
				break;
			} else {
				$group = NULL;
			}
		}
	
		$type = $this->getMatchedStatus();
		switch ($type) {
			case CallForwardCriteriaCallNightCircutState::Enabled :
				return __('PHONESETTINGSCALLFORWARD_IN_NIGHTCIRCUTSTATE_GENERAL') . " " . __("PHONESETTINGSCALLFORWARD_CALLSOURCE_NIGHTCIRCUTSTATE_GENERAL_ENABLED") .' '.__("PHONESETTINGSCALLFORWARD_GROUP").' "'.  CHtml::encode($group->name).'".'; //FIXME ADD ADDRESSBOOK!
				break;
			case CallForwardCriteriaCallNightCircutState::Disabled :
				return __('PHONESETTINGSCALLFORWARD_IN_NIGHTCIRCUTSTATE_GENERAL') . " " . __("PHONESETTINGSCALLFORWARD_CALLSOURCE_NIGHTCIRCUTSTATE_GENERAL_DISABLED").' '.__("PHONESETTINGSCALLFORWARD_GROUP").' "'.  CHtml::encode($group->name).'".';
				break;
		}

	}

	public function checkIfMatched($variables) {
		return false;
	}
	
	
}