{% extends "layout_default.phtml" %}
{% block meta_title %}Hosting management{% endblock %}
{% set active_menu = 'system' %}

{% block breadcrumbs %}
<ul>
    <li class="firstB"><a href="{{ '/'|alink }}">{{ 'Home'|trans }}</a></li>
    <li><a href="{{ 'servicehosting'|alink }}">{{ 'Hosting plans and servers'|trans }}</a></li>
    <li class="lastB">{{ server.name }}</li>
</ul>
{% endblock %}

{% block content %}
<div class="widget">
    <div class="head">
        <h5>Server management</h5>
    </div>

    <form method="post" action="{{ 'api/admin/servicehosting/server_update'|link }}" id="server-update" class="mainForm save api-form" data-api-msg="Server updated">
        <fieldset>
            <div class="rowElem noborder">
                <label>{{ 'Name'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="name" value="{{ server.name }}" required="required" placeholder="Unique name to identify this server">
                </div>
                <div class="fix"></div>
            </div>
            <div class="rowElem">
                <label>{{ 'Hostname'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="hostname" value="{{ server.hostname }}" placeholder="server1.yourserverdomain.com">
                </div>
                <div class="fix"></div>
            </div>
            <div class="rowElem">
                <label>{{ 'IP'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="ip" value="{{ server.ip }}" required="required" placeholder="Primary IP address of the server used to connect to it like: 123.123.123.123">
                </div>
                <div class="fix"></div>
            </div>
            {#
            <div class="rowElem">
                <label>{{ 'Assigned IP Addresses'|trans }}:</label>
                <div class="formRight">
                    <textarea name="assigned_ips" cols="5" rows="5" placeholder="List the IP Addresses assigned to the server (One per line)">{% for v in server.assigned_ips %}{{ v }}{{constant("PHP_EOL")}}{% endfor %}</textarea>
                </div>
                <div class="fix"></div>
            </div>
            #}
            <div class="rowElem">
                <label>{{ 'Enable/Disable'|trans }}:</label>
                    <div class="formRight">
                        <input type="radio" name="active" value="1" {% if server.active %}checked="checked"{% endif %}/><label>Yes</label>
                        <input type="radio" name="active" value="0" {% if not server.active %}checked="checked"{% endif %}/><label>No</label>
                    </div>
                <div class="fix"></div>
            </div>
        </fieldset>

        <fieldset>
            <legend>Server manager</legend>
            <div class="rowElem">
                <label>{{ 'Server manager'|trans }}:</label>
                <div class="formRight">
                    <select name="manager">
                        {% for code, manager in admin.servicehosting_manager_get_pairs %}
                        <option value="{{code}}" {% if server.manager == code %}selected="selected"{% endif %}>{{ manager.label }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Username'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="username" value="{{ server.username }}" placeholder="Login username to your server: root/reseller">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Password'|trans }}:</label>
                <div class="formRight">
                    <input type="password" name="password" value="{{ server.password }}" placeholder="Login password to your server">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Access Hash (Instead of password for cPanel servers)'|trans }}:</label>
                <div class="formRight">
                    <textarea name="accesshash" cols="5" rows="5">{{ server.accesshash }}</textarea>
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Connection port'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="port" value="{{ server.port }}" placeholder="Custom port. Use blank to use default. Used to connect to API">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Use Secure connection'|trans }}:</label>
                    <div class="formRight">
                        <input type="radio" name="secure" value="1" {% if server.secure %}checked="checked"{% endif %}/><label>Yes</label>
                        <input type="radio" name="secure" value="0" {% if not server.secure %}checked="checked"{% endif %}/><label>No</label>
                    </div>
                <div class="fix"></div>
            </div>

            <input type="button" value="{{ 'Update and test connection'|trans }}" class="greyishBtn submitForm" id="test-connection"/>
        </fieldset>


        <fieldset>
            <legend>Nameservers</legend>
            <div class="rowElem">
                <label>{{ 'Nameserver 1'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="ns1" value="{{ server.ns1 }}" placeholder="ns1.yourdomain.com">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Nameserver 2'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="ns2" value="{{ server.ns2 }}" placeholder="ns2.yourdomain.com">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Nameserver 3'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="ns3" value="{{ server.ns3 }}" placeholder="ns3.yourdomain.com">
                </div>
                <div class="fix"></div>
            </div>
            <div class="rowElem">
                <label>{{ 'Nameserver 4'|trans }}:</label>
                <div class="formRight">
                    <input type="text" name="ns4" value="{{ server.ns4 }}" placeholder="ns4.yourdomain.com">
                </div>
                <div class="fix"></div>
            </div>
            <input type="submit" value="{{ 'Update server'|trans }}" class="greyishBtn submitForm" />
        </fieldset>

        <input type="hidden" name="id" value="{{ server.id }}" />
    </form>
</div>
{% endblock %}

{% block js%}
<script>
    $(function() {
        $('#test-connection').click(function(){
            $('#server-update').submit();
            bb.post('admin/servicehosting/server_test_connection',
                { id: {{ server.id }} },
                function(result) {
                    bb.msg('Successfully connected to server');
                }
            );

            return false;
        });
    });
</script>
{% endblock %}
