<?php
require_once 'class.abstractcallforwardcriteria.php';
/*
Translation tags in this Class : 
  PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL
  PHONESETTINGSCALLFORWARD_JABBERSTATE_IS
  PHONESETTINGSCALLFORWARD_JABBERSTATE_ONLINE
  PHONESETTINGSCALLFORWARD_JABBERSTATE_AWAY
  PHONESETTINGSCALLFORWARD_JABBERSTATE_DND
  PHONESETTINGSCALLFORWARD_JABBERSTATE_OFFLINE
  
*/
class CallForwardCriteriaJabberStatus extends AbstractCallForwardCriteria {

	public function __construct($parent){
		$this->setCriteriaName("JabberStatus");
		$this->setCriteriaTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL"));
		$property = new CallForwardCriteriaProperty();
		$property->setPropertyName("jabberstatus");
		$property->setPropertyTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_IS"));
		$property->setPropertyTypeName("select");

		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName("online");
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_ONLINE"));
		$property->addPropertyCapability($cap);

		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName("away");
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_AWAY"));
		$property->addPropertyCapability($cap);

		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName("dnd");
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_DND"));
		$property->addPropertyCapability($cap);

		$cap = new CallForwardCriteriaPropertyCapability();
		$cap->setName("offline");
		$cap->setTitle(__("PHONESETTINGSCALLFORWARD_JABBERSTATE_OFFLINE"));
		$property->addPropertyCapability($cap);

		$this->addPropertyType($property);
	}

	public function getCriteriaDescription() {
		$type = $this->getProperty("jabberstatus","");
		switch ($type) {
			case "online" :
				return __('PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL'). ": " . __('PHONESETTINGSCALLFORWARD_JABBERSTATE_ONLINE');
				break;
			case "away" :
			    return __('PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL'). ": " . __('PHONESETTINGSCALLFORWARD_JABBERSTATE_AWAY');
				break;
			case "dnd" :
			    return __('PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL'). ": " . __('PHONESETTINGSCALLFORWARD_JABBERSTATE_DND');
				break;
			case "offline" :
				return __('PHONESETTINGSCALLFORWARD_JABBERSTATE_GENERAL'). ": " . __('PHONESETTINGSCALLFORWARD_JABBERSTATE_OFFLINE');
				break;
		}
	}

	public function checkIfMatched($variables) {

		//is the jabberstatus set?
		$currentState = @$variables['jabberstatus'];
		if ($currentState == "") {
			return false;
		}

		if ($this->getProperty("jabberstatus","") == $currentState) {
			//current state matches.
			return true;
		}

		return false;
	}

}
