<?php

include dirname(__FILE__) . '/../../../lib/AbstractXmlPhoneLoginApp.php';
require_once "lib/XmlMenuScreen.php";
require_once "lib/XmlFormattedTextScreen.php";
require_once "lib/XmlInputScreen.php";

class XmlPhoneLoginApp extends AbstractXMLPhoneLoginApp
{
    private $screen = null;
    
    private function getScreenAttributes($changeAttribute = array())
    {
        $screenAttributes = array();
        $screenAttributes["defaultIndex"] = "";
        $screenAttributes["style"] = "radio";
        $screenAttributes["Beep"] = "no";
        $screenAttributes["cancelAction"] = "";
        $screenAttributes["wrapList"] = "yes";
        $screenAttributes["Timeout"] = "30";
        $screenAttributes["LockIn"] = "no";

        if (!empty($changeAttribute)) {
            foreach ($changeAttribute as $key => $value) {
                $screenAttributes[$key] = $value;
            }
        }
        return $screenAttributes;
    }

    public function renderLoginExtension()
    {
        $URI = $this->appURL();
        
        $screenAttributes = $this->getScreenAttributes();

        $screen = new XmlInputScreen($screenAttributes);
        $screen->setTitle(__('XML_LOGIN_APP_LOGIN_SCREEN'));
        $screen->xw->writeElement("URL", $URI);  
        $screen->addInputField("string", "no", "yes", __("XML_LOGIN_APP_EXTENSION") . ':', "extension", "", "");
        $screen->xw->endElement();
        
        $screen->addButton("1", __("XML_GLOBAL_EXIT_BTN"), "SoftKey:Exit");
        $screen->addButton("2", __("XML_LOGIN_APP_ABC"), "SoftKey:ChangeMode");
        $screen->addButton("3", __("XML_GLOBAL_DELETE_BTN"), "SoftKey:BackSpace");
        $screen->addButton("4", __("XML_LOGIN_APP_SEND"), "SoftKey:Submit");
        
        $screen->printScreen();
        
    }

    public function renderLoginPIN()
    {
        $URI = $this->appURL();
        $URI.="?extension=" . $_REQUEST["extension"];
        $screenAttributes = $this->getScreenAttributes();

        $screen = new XmlInputScreen($screenAttributes);

        $screen->setTitle(__('XML_LOGIN_APP_LOGIN_SCREEN'));      
        $screen->xw->writeElement("URL", $URI);     
        $screen->addInputField("string", "yes", "yes", __("XML_LOGIN_APP_PIN") . ':', "pin", "", "");
        $screen->xw->endElement();
        
        $screen->addButton("1", __("XML_GLOBAL_EXIT_BTN"), "SoftKey:Exit");
        $screen->addButton("2", __("XML_LOGIN_APP_ABC"), "SoftKey:ChangeMode");
        $screen->addButton("3", __("XML_GLOBAL_DELETE_BTN"), "SoftKey:BackSpace");
        $screen->addButton("4", __("XML_LOGIN_APP_SEND"), "SoftKey:Submit");
        
        $screen->printScreen();
    }
        
    public function renderSucces()
    {
        $this->renderAppTextScreens(__('XML_LOGIN_APP_ENTRY_SUCCESFUL'),"10");
    }

    public function renderNoExtensionFound()
    {
        $this->renderAppTextScreens(__('XML_LOGIN_APP_WRONG_EXTENSION'),"5");
    }

    public function renderWrongPIN()
    {
        $this->renderAppTextScreens(__('XML_LOGIN_APP_WRONG_PIN'),"5");
    }

    public function renderNoSipFound()
    {
        $this->renderAppTextScreens(__('XML_LOGIN_APP_NO_SIP'),"5");
    }
    
    public function renderAppTextScreens($text, $timeout)
    {
        $screenAttributes = $this->getScreenAttributes();
        $screenAttributes["Timeout"] = $timeout;

        $screen = new XmlFormattedTextScreen($screenAttributes);

        $screen->setLine($text);
        
        $screen->removeDefaultButtons();

        $screen->printScreen();
    
    }
}
