<?php

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

class XmlPhoneLoginApp extends AbstractTiptel30xxXmlPhoneLoginApp
{

    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();

        $attributes = array(
            'type' => 'string',
            'Password' => 'no',
            'displayMode' => 'normal'
        );
        $screenAttributes = $this->getScreenAttributes($attributes);

        $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->printScreen();
    }

    public function renderLoginPIN()
    {
        $URI = $this->getEnterPinURL();
        $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'), "5", true);
    }

    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, $removeBtns = false)
    {
        $screenAttributes = $this->getScreenAttributes();
        $screenAttributes["Timeout"] = $timeout;
        $screen = new XmlScreen("TextScreen", $screenAttributes);
        $screen->setTitle('');
        $screen->addText($text);
        if ($removeBtns) {
            $screen->removeDefaultButtons();
        }
        $screen->printScreen();
    }
}
