<?
include_once(_DIR_EXT.'/esmo_gateway/i_personal_import.php') ;
include_once(_DIR_EXT.'/HTML/c_page_XML_AJAX.php') ;
class c_page_ajax extends c_page_XML_AJAX
{

    function hand_value_from_QR_code()
    {
        if ($GLOBALS['LS_autonom_term_server_protocol'] or $GLOBALS['LS_autonom_term_server_protocol'] === 0) $protocol = $GLOBALS['LS_autonom_term_server_protocol'];
        elseif (_MAIN_PROTOCOL == 'https://') $protocol = 1;
        else $protocol = 0;
        $server_name = ($GLOBALS['LS_autonom_term_server_ip'])? $GLOBALS['LS_autonom_term_server_ip']:'';
        $port = ($GLOBALS['LS_autonom_term_server_port'])? $GLOBALS['LS_autonom_term_server_port']:'';
        ?>
        <div>
            <form method="POST">
                <table class="settings">
                    <tr><td class="name">Протокол</td>       <td><label><input type="radio" name="protocol" value="1" <?if ($protocol == 1) echo 'checked';?>> https</label><label><input type="radio" name="protocol" value="0" <?if ($protocol == 0) echo 'checked';?>> http</label></td></tr>
                    <tr><td class="name">Адрес сервера</td>  <td><input type="text" name="server_name" value="<?echo $server_name?>"></td></tr>
                    <tr><td class="name">Порт</td>           <td><input type="text" name="port" value="<?echo $port?>"></td></tr>
                </table><br>
                <div class="panel_buttons"><input type="submit" class="v2" cmd="autonomous_terminals/save_value_from_QR_code" value="Сохранить">&nbsp;&nbsp;&nbsp;<button class="cancel">Отмена</button></div>
            </form>
        </div>
        <style>
            table.settings {font-size: 18px;line-height: 30px;}
            table.settings td.name {padding-right: 16px;}
            table.settings td label {padding-right: 16px;}
            div.panel_buttons {text-align: center;}
            div.panel_buttons button, div.panel_buttons input[type="submit"] {background: #2da5da;color: white;border: 0px;font-size: 14px;height: 30px;padding: 0 30px;}
        </style>
        <?
        $this->add_element('show_modal_window','HTML',array('title'=>'Параметры для QR кода')) ;
    }

    function save_value_from_QR_code()
    {
        AUTONOMOUS_TERMINALS()->update_data_from_QR_code($_POST);
        $this->add_element('update_page',1) ;
    }

    function create_new_terminal()
    {
        $terminal_id = $_POST['terminals_id'];
        $terminal_type = $_POST['terminals_type'];
        $result = AUTONOMOUS_TERMINALS()->create_new_terminal($terminal_id,$terminal_type);

        if ($result['error']) {
            $html = '<p class="red">'.$result['error'].'</p>';
            $html.='<div class="center"><button class="cancel">Закрыть</button></div>';
            echo $html;
            $this->add_element('show_modal_window',HTML,array('title'=>'Ошибка добавления терминала '.$_POST['terminals_id']));
        } else {
            reboot_engine();
            ACCOUNTS()->update_member_info(MEMBER());
            $this->update_page = 1;
        }
    }

}