<?php

//require_once 'PhoneModelFactory.php' ;
include dirname(__FILE__).'/../../../lib/AbstractXMLPhonebookApp.php'; 
require_once "lib/XmlMenuScreen.php";

class XmlPhonebookApp extends AbstractXMLPhonebookApp
{
	private $screen = null;

	
	public function renderPhoneBooks($books) {
		
		$URI = $this->getPhonebookURI();
		
		$screenAttributes = array();
		$screenAttributes["defaultIndex"] = "";
		$screenAttributes["style"] = "radio";
		$screenAttributes["Beep"] = "yes";
		$screenAttributes["cancelAction"] = "";
		$screenAttributes["wrapList"] = "yes";
		$screenAttributes["Timeout"] = "30";
		$screenAttributes["LockIn"] = "no";

		$screen = new XmlMenuScreen($screenAttributes);

		$screen->setTitle("Phonebook(s)");	
		
		foreach($books as $book) {
			$screen->addMenuItem($book->title, $URI, "pbid=".$book->id);
		}
		
		$screen->addButton("1","Exit", "Key:CANCEL");
		$screen->addButton("3","Search", $this->getSearchScreenURI());
		$screen->addButton("4", "Select");
		
		$screen->printScreen();

	}
	
	public function renderPhoneAdresses($bookName, $addresses) {
	
		$URI = $this->getAddressesURI();
		
		$screenAttributes = array();
		$screenAttributes["defaultIndex"] = "";
		$screenAttributes["style"] = "radio";
		$screenAttributes["Beep"] = "yes";
		$screenAttributes["cancelAction"] = "";
		$screenAttributes["wrapList"] = "yes";
		$screenAttributes["Timeout"] = "30";
		$screenAttributes["LockIn"] = "no";
		
		$screen = new XmlMenuScreen($screenAttributes);

		$screen->setTitle($bookName);

		foreach($addresses as $address) {
			$screen->addMenuItem($address->phoneContactNames(), $URI, "addressid=".$address->id);
		}
		
		$screen->addButton("1", "Exit", $this->appURL());
		$screen->addButton("2", "Prev", "SoftKey:Exit");
		$screen->addButton("3", "Next", $this->getNextPageURI());
		$screen->addButton("4", "Select");
		
		$screen->printScreen();

	}

	public function renderPhoneAddress($address) {
		
		$URI = $this->getAddressesURI();

		$screenAttributes = array();
		$screenAttributes["defaultIndex"] = "";
		$screenAttributes["style"] = "radio";
		$screenAttributes["Beep"] = "yes";
		$screenAttributes["cancelAction"] = "";
		$screenAttributes["wrapList"] = "yes";
		$screenAttributes["Timeout"] = "30";
		$screenAttributes["LockIn"] = "no";
	
		$screen = new XmlMenuScreen($screenAttributes);
	
		$screen->setTitle($address->phoneContactNames());
	
		foreach ($address->phoneNumbers() as $name => $number) {
			$screen->addMenuItem($name, "", "", $number);
		}
		
		$screen->addButton("1","Back", "SoftKey:Exit");
		$screen->addButton("4","Dial", "SoftKey:Dial");
		
		$screen->printScreen();
	
	}
	
	public function renderSearchResult($bookName, $addresses) {
	
		$URI = $this->getSearchResultURI();

		$screenAttributes = array();
		$screenAttributes["defaultIndex"] = "";
		$screenAttributes["style"] = "number";
		$screenAttributes["Beep"] = "yes";
		$screenAttributes["cancelAction"] = "";
		$screenAttributes["wrapList"] = "yes";
		$screenAttributes["Timeout"] = "30";
		$screenAttributes["LockIn"] = "no";
	
		$screen = new XmlMenuScreen($screenAttributes);
		
		$screen->setTitle ('Search Result for "'.$this->search_request.'"');
		
		foreach($addresses as $address) {
			$screen->addMenuItem($address->phoneContactNames(), $URI, "addressid=".$address->id);
		}
	
		$screen->addButton("1", "Exit", $this->appURL());
		$screen->addButton("2", "Prev", "SoftKey:Exit");
		$screen->addButton("3", "Next", $this->getNextSearchPageURI());
		$screen->addButton("4", "Select");
		
		$screen->printScreen();
	}

	
	public function renderSearch() {
		
		
		require_once "lib/XmlInputScreen.php";
		
		$URI = $this->getSearchURI();
		
		$screenAttributes = array();
		$screenAttributes['type']="string";
		$screenAttributes['Beep']="yes";
		$screenAttributes["cancelAction"] = "";
		$screenAttributes["Password"]="yes";
		$screenAttributes["Timeout"]="30";
		$screenAttributes["LockIn"]="no";
		$screenAttributes["inputLanguage"]="German";
		$screenAttributes["displayMode"]="normal";
		$screenAttributes["defaultIndex"] = "";
		
		$screen = new XmlInputScreen($screenAttributes);
		
		$screen->setTitle("Search Screen");
		
		$screen->xw->writeElement("URL", $URI);
		
		$screen->addInputField("string", "no", "yes", "Search for Name or Company", "search_request", "", "");
		
		$screen->addButton("1", "Exit", "SoftKey:Exit");
		$screen->addButton("2", "ABC", "SoftKey:ChangeMode");
		$screen->addButton("3", "Delete", "SoftKey:BackSpace");
		$screen->addButton("4", "Select","SoftKey:Submit");
		
		$screen->printScreen();
		
	}
		
}