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


//This class holds one representaion of a Users callForward, includes all defined callforwards and the active one
class UserCallForward {

	private $mActive = "none";
	private $mDefinedCallforwards = array();
	private $mSimpleCallForward = null;
	private $mUser = null;

	public function __construct(User $user){
		$this->mUser = $user;
	}

	public function setActive($active) {
		$this->mActive = $active;
	}

	public function getAcitve() {
		return $this->mActive;
	}

	public function getDefinedSimpleCallforward() {

		if($this->mSimpleCallForward == null) {
			$this->mSimpleCallForward = new CallForward($this);
			$this->mSimpleCallForward->setType("simple");
			$target = CallForwardingFactory::getCallNewCallForwardTargetByName("number", $this->mSimpleCallForward);
			$this->mSimpleCallForward->setCallForwardTarget($target);
		}
		return $this->mSimpleCallForward;
	}

	public function setDefinedSimpleCallForward(CallForward $forward) {
		$this->mSimpleCallForward = $forward;
		if($this->mSimpleCallForward != NULL) {
			$this->mSimpleCallForward->setParent($this);
		}
	}

	public function getDefinedAdvancedCallforwards() {
		return $this->mDefinedCallforwards;
	}

	public function setDefinedAdvancedCallForwards(Array $forwards) {

		foreach($forwards as $forward) {
			$forward->setParent($this);
			$this->mDefinedCallforwards[] = $forward;
		}

		if (count($this->mDefinedCallforwards) == 0) {
			//add sample advanced callforward
			$tmp = new CallForward($this);
			$tmp->setId(0);
			$tmp->setPosition(0);
			$tmp->setType("advanced");
			$target = CallForwardingFactory::getCallNewCallForwardTargetByName("number", $tmp);
			$target->setProperty("number", "");
			$tmp->setCallForwardTarget($target);
				
                        $criteria = CallForwardingFactory::getDefaultCriteria($this);
			//$criteria = CallForwardingFactory::getCallNewCallForwardCriteriaByName("PhoneStatus", $this);
			//$criteria->setProperty("phonestatus","offline");
			$tmp->addCriteria($criteria);

			$this->mDefinedCallforwards[] = $tmp;
		}
	}

	public function getAvialableSystemRecordings() {

		$recordings = array();
		$files = $this->mUser->getAudioFiles();
		
		foreach($files as $file) {
			$rec = new SystemRecording();
			$rec->setFile($file->id);
			$rec->setId($file->id);
			$rec->setOwner($file->user_id);
			$rec->setTitle($file->name);
			$rec->setMType(__(AudioFileType::getAudioFileTypesAsString($file->type)));
			$recordings[] = $rec;
		}

		return $recordings;
	}

	public function getAvialableAddressBooks() { //FIXME RENAME TO TYPE!!!
		

		return $this->mUser->getAddressbooks();
	}
	
	public function getAvialableGroups() {
		return $this->mUser->getUserGroups();
	}
	
	public function getAvialableCalendars() {
		
		$calendars = $this->mUser->getCalendars(); 
		return $calendars;
	}
	

	public function getDialedExtension() {
		return $this->mUser->getExtension();
	}

}


