<?php
class XmlScreen {
	
	public $xw;
	
	public function __construct ($type="YealinkIPPhoneTextScreen", $attributes = array()) {
		
		$this->xw = new xmlWriter();
		$this->xw->openMemory();
		$this->xw->setIndent(TRUE);
		$this->xw->startDocument('1.0', 'UTF-8'); // start document
		
		$this->xw->startElement($type);
		foreach($attributes as $key => $value) {
			$this->xw->writeAttribute($key, $value);
		}
		
	}
	
	private function finishDocument() {
		
		$this->addButton("1","", $URI="");
		$this->addButton("2","", $URI="");
		$this->addButton("3","", $URI="");
		$this->addButton("4","", $URI="");
		
		$this->xw->endElement(); // close node <book>
		$this->xw->endDocument(); // end document
	}
	
	public function printScreen() {
		$this->finishDocument();
		echo $this->xw->outputMemory();	
	}
	
	
	public function setTitle($title, $wrap="yes") {
	
		$this->xw->startElement('Title');  // <title> with content
		$this->xw->writeAttribute("wrap", $wrap);
		$this->xw->text($title);
		$this->xw->endElement();
		
	}
	
	public function addText($text) {
		$this->xw->writeElement("Text", $text);
	}
	
	public function addButton($index, $label, $URI="SoftKey:Select") {
		
		$this->xw->startElement("SoftKey");
		$this->xw->writeAttribute("index", $index);
		$this->xw->writeElement("Label", $label);
		$this->xw->writeElement("URI", $URI);
		$this->xw->endElement();
		
	}	
	
}