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

class CallForwardTarget_Announcement extends AbstractCallForwardTarget {

	public function __construct($parent) {
		
		$this->mParent = $parent;
		
		$this->setCallForwardType("announcement");
		$this->setTitle(__("PHONESETTINGSCALLFORWARD_TARGET_ANNONCEMENT"));
				
		$property = new CallForwardTargetProperty();
		$property->setPropertyName("voicemailfile");
		$property->setPropertyTitle("Ansagedatei: ");
		$property->setPropertyTypeName("select");
		
	        $cap = new CallForwardTargetPropertyCapability();
                $cap->setName("");
                $cap->setTitle(__("PHONESETTINGSCALLFORWARD_TARGET_ANNOUNCEMENT_SYSTEM_STANDARD"));
                $property->addPropertyCapability($cap);

		$recordings = $this->getAvialableSystemRecordings();
	
		
		foreach ($recordings as $recording) {
			$cap = new CallForwardTargetPropertyCapability();
			$cap->setName($recording->getFile());
			$cap->setTitle($recording->getTitle());
			$cap->setMType($recording->getMType()); // for sorting Audiofiles in option-groups 
			$property->addPropertyCapability($cap);	
		}
						
		$this->addPropertyType($property);
	
	}
		
	public function getHumanReadableDescription() {
	
		$name = __("PHONESETTINGSCALLFORWARD_TARGET_ANNOUNCEMENT_SYSTEM_STANDARD");
		$recordings = $this->getAvialableSystemRecordings();
		if(is_array($recordings)) {
			foreach ($recordings as $recording) {
               	        	if ($recording->getFile() == $this->getProperty("voicemailfile")) {
					$name = $recording->getTitle();
					break;
				}
               		}
		}
		return CHtml::encode($name);
	}
	
	
	public function getAvialableSystemRecordings() {
		return $this->mParent->getAvialableSystemRecordings();
	}
	
        public function getDialedExtension() {
                return $this->mParent->getDialedExtension();
        }


	public function getDialplanTargetNumber() {
		return "vm*".$this->getDialedExtension();
	}
	

	public function getExtraDialplanVars() {
		$retarray = array();
		$retarray["_announcementfile"] = "/usr/share/phonalisa/sys-rec/".$this->getProperty("voicemailfile");
		return $retarray;
	}
	
	
	
}
