{% import "macro_functions.phtml" as mf %}
{% extends "layout_default.phtml" %}
{% block meta_title %}{{ 'Hosting plans and servers'|trans }}{% endblock %}
{% set active_menu = 'system' %}

{% block content %}
<div class="widget simpleTabs">
    <ul class="tabs">
        <li><a href="#tab-index">{{ 'Hosting plans and servers'|trans }}</a></li>
        <li><a href="#tab-new-server">{{ 'New server'|trans }}</a></li>
        <li><a href="#tab-new-plan">{{ 'New hosting plan'|trans }}</a></li>
    </ul>

    <div class="tabs_container">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">
            <div class="help">
                <h5>{{ 'Servers'|trans }}</h5>
            </div>

            <table class="tableStatic wide">
                <thead>
                    <tr>
                        <th>{{ 'Name'|trans }}</th>
                        <th>{{ 'IP'|trans }}</th>
                        <th>{{ 'Server manager'|trans }}</th>
                        <th>{{ 'Active'|trans }}</th>
                        <th style="width:22%">&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    {% set servers = admin.servicehosting_server_get_list({"per_page":100}) %}
                    {% for server in servers.list %}
                    <tr>
                        <td>{{server.name}}</td>
                        <td>{{server.ip}}</td>
                        <td>{{ mf.status_name(server.manager) }}</td>
                        <td>{{ mf.q(server.active) }}</td>
                        <td class="actions">
                            <a class="bb-button btn14" href="{{server.cpanel_url}}" target="_blank"><img src="images/icons/dark/cog.png" alt=""></a>
                            <a class="bb-button btn14 api-link" data-api-msg="Connected" href="{{ 'api/admin/servicehosting/server_test_connection'|link({'id' : server.id}) }}" title="Test connection"><img src="images/icons/dark/signal.png" alt=""></a>
                            <a class="bb-button btn14" href="{{ '/servicehosting/server'|alink }}/{{server.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                            <a class="bb-button btn14 bb-rm-tr api-link" data-api-confirm="Are you sure?" data-api-redirect="{{ 'servicehosting'|alink }}" href="{{ 'api/admin/servicehosting/server_delete'|link({'id' : server.id}) }}"><img src="images/icons/dark/trash.png" alt=""></a>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="7">{{ 'The list is empty'|trans }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="7"></td>
                    </tr>
                </tfoot>
            </table>

            <div class="help">
                <h5>{{ 'Hosting plans'|trans }}</h5>
            </div>

            <table class="tableStatic wide">
                <thead>
                    <tr>
                        <td>{{ 'Title'|trans }}</td>
                        <td>{{ 'Addon domains'|trans }}</td>
                        <td>{{ 'Disk space'|trans }}</td>
                        <td>{{ 'Bandwidth'|trans }}</td>
                        <td style="width:13%">&nbsp;</td>
                    </tr>
                </thead>
                
                <tbody>
                    {% set hps = admin.servicehosting_hp_get_list({"per_page":100}) %}
                    {% for hp in hps.list %}
                    <tr>
                        <td>{{hp.name}}</td>
                        <td>{{hp.max_addon}}</td>
                        <td>{{hp.quota}}</td>
                        <td>{{hp.bandwidth}}</td>
                        <td class="actions">
                            <a class="bb-button btn14" href="{{ '/servicehosting/plan'|alink }}/{{hp.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                            <a class="bb-button btn14 bb-rm-tr api-link" data-api-confirm="Are you sure?" data-api-redirect="{{ 'servicehosting'|alink }}" href="{{ 'api/admin/servicehosting/hp_delete'|link({'id' : hp.id}) }}"><img src="images/icons/dark/trash.png" alt=""></a>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="2">{{ 'The list is empty'|trans }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>


        </div>

        <div class="tab_content nopadding" id="tab-new-server">
            <form method="post" action="admin/servicehosting/server_create" class="mainForm api-form" data-api-redirect="{{ 'servicehosting'|alink }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{{ 'Name'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="name" value="" required="required" placeholder="{{ 'Unique name to identify this server'|trans }}">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Hostname'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="hostname" value="" placeholder="{{ 'server1.yourserverdomain.com'|trans }}">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'IP'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="ip" value="" required="required" placeholder="{{ 'Primary IP address of the server used to connect to it like: 123.123.123.123'|trans }}">
                        </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)'|trans }}"></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" checked="checked"/><label>{{ 'Yes'|trans }}</label>
                                <input type="radio" name="active" value="0"/><label>{{ 'No'|trans }}</label>
                            </div>
                        <div class="fix"></div>
                    </div>
                </fieldset>

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

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

                    <div class="rowElem">
                        <label>{{ 'Nameserver 3'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="ns3" value="" placeholder="{{ 'ns3.yourdomain.com'|trans }}">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Nameserver 4'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="ns4" value="" placeholder="{{ 'ns4.yourdomain.com'|trans }}">
                        </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}}">{{ 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="" placeholder="{{ 'Login username to your server: root/reseller'|trans }}">
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{{ 'Password'|trans }}:</label>
                        <div class="formRight">
                            <input type="password" name="password" value="" placeholder="{{ 'Login password to your server'|trans }}">
                        </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"></textarea>
                        </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"/><label>{{ 'Yes'|trans }}</label>
                                <input type="radio" name="secure" value="0" checked="checked"/><label>{{ 'No'|trans }}</label>
                            </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{{ 'Add server'|trans }}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div class="tab_content nopadding" id="tab-new-plan">
            <div class="help">
                <h3>{{ 'Adding new hosting plan'|trans }}</h3>
                <p>{{ 'Depending on server manager used to setup hosting account you may require provide additional parameters in next step. In this step provide basic hosting plan information.'|trans }}</p>
            </div>
            <form method="post" action="{{ 'api/admin/servicehosting/hp_create'|link}}" class="mainForm api-form" data-api-jsonp="onAfterHostingPlanCreate">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{{ 'Name'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="name" value="" required="required" placeholder="{{ 'Unique name to identify this hosting plan'|trans }}">
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{{ 'Disk quota (MB)'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="quota" value="1024" placeholder="">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Bandwidth (MB)'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="bandwidth" value="1024" placeholder="">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <input type="submit" value="{{ 'Create hosting plan'|trans }}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>
    </div>
</div>



{% endblock %}


{% block js%}
<script type="text/javascript">
$(function() {

});

function onAfterHostingPlanCreate(id) {
    bb.redirect("{{ 'servicehosting/plan'|alink}}/"+id);
}
</script>
{% endblock %}