<?php
if (!session('tr_lang')) {
    session('tr_lang', 'en');
}
?>

<!DOCTYPE HTML>
<html>
    <head>
        <title>translator v.0.3</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <meta charset="utf-8">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
        <script src="/adg/style/js/ajax.js"></script>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    </head>

    <style>
        .search_form {
            padding: 0 5px;
        }

        .search_form, .search_form .input-group {
            width: 100%;
        }

        .sidebar {
            position: fixed;
            top: 51px;
            bottom: 0;
            left: 0;
            z-index: 1000;
            display: block;
            padding: 20px;
            overflow-x: hidden;
            overflow-y: auto;
            background-color: #f5f5f5;
            border-right: 1px solid #eee;
        }

        .work_area label, .work_area input[type=submit] {
            margin-top: 10px;
        }

        .main {
            padding-top: 51px;
        }

        .array_item {
            cursor: pointer;
        }

        .array_item_anchor_fix {
            position: relative;
        }

        .array_item_anchor_fix div {
            visibility: hidden;
            top: -51px;
            position: absolute;
        }
    </style>

    <body>

    <?php require_once (ROOT . '/adg/blocks_admin/translate_menu.php'); ?>

    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 sidebar">
                <div class="work_area">
                    <form class="" name="set_form" id="set_form" method="post" action="translator.php">
                        <fieldset>
                            <div class="alert alert-success" role="alert" id="alert_success" style="display: none;"></div>
                            <div class="alert alert-danger" role="alert" id="alert_danger" style="display: none;"></div>
                            <?php echo flash_show('translator'); ?>
                            <?php echo form_init(); ?>
                            <input id="last" type="hidden" name="from" value="/translate/set.php">
                            <label for="lang" style="margin-top: 0;">
                                Язык:
                            </label>
                            <select class="form-control" name="lang" id="lang">
                                <?php foreach ($list_languages as $key => $value) {
                                    if ($key != 'ru') { ?>
                                        <option value="<?php echo escape($key); ?>" <?php if (session('tr_lang') == $key) { echo 'selected'; } ?>>
                                            <?php echo strtoupper($key); ?>
                                        </option>
                                        <?php if (is_null(session('tr_lang'))) {
                                            session('tr_lang', $key);
                                        } ?>
                                    <?php } ?>
                                <?php } ?>
                            </select>

                            <label for="origin">
                                Оригинал:
                            </label>
                            <textarea
                                    required
                                    class="form-control"
                                    name="origin"
                                    id="origin"
                                    placeholder="Введите текст ..."
                                    cols="30" rows="10"><?php echo escape(post('origin')); ?></textarea>

                            <label for="translation">
                                Перевод:
                            </label>
                            <textarea
                                    required
                                    class="form-control"
                                    name="translation"
                                    id="translation"
                                    placeholder="Введите новый вариант перевода ..."
                                    cols="30" rows="10"><?php echo escape(post('translation')); ?></textarea>

                            <input class="btn btn-default pull-right" type="submit" value="Добавить запись" id="translate_button">
                        </fieldset>
                    </form>

                    <label for="current">
                        Текущий вариант перевода:
                    </label>
                    <textarea
                            readonly
                            class="form-control"
                            name="current"
                            id="current"
                            cols="30" rows="10"></textarea>

                </div>
            </div>
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 col-xs-offset-3 col-xs-offset-3 col-xs-offset-3 col-xs-offset-3 main">
                <div id="reload_table">

                </div>
            </div>
        </div>
    </div>

    <script>

        $('#reload_table').load('/adg/templates/translator_reload_table.php', '#reload_table');

        $("textarea").focus(function() {
            $(this).select();
        });

        $(document).ready(function() {

            $('#lang').on('change', function() {
                var lang = $(this).val();
                $('#reload_table').load('/adg/templates/translator_reload_table.php?lang='+lang, '#reload_table');
            });

            $('#translate_button').on('click', function(event) {
                var $form = $("#set_form").closest('form');
                q_makeAjaxRequest(
                    '/ajax/adg/translator.php',
                    'post',
                    $form.serialize()
                    //q_callback(),
                );
                return false;
            })
        })
    </script>

    </body>
</html>