{% extends "layout_default.phtml" %}

{% import "macro_functions.phtml" as mf %}

{% block meta_title %}Domain management{% endblock %}

{% set active_menu = 'system' %}

{% block content %}
<div class="widget simpleTabs">
    <ul class="tabs">
        <li><a href="#tab-tlds">{{ 'Top level domains'|trans }}</a></li>
        <li><a href="#tab-new-tld">{{ 'New top level domain'|trans }}</a></li>
        <li><a href="#tab-registrars">{{ 'Registrars'|trans }}</a></li>
        <li><a href="#tab-new-registrar">{{ 'New domain registrar'|trans }}</a></li>
        <li><a href="#tab-nameservers">{{ 'Nameservers'|trans }}</a></li>
    </ul>

    <div class="tabs_container">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-tlds">

<div class="help">
    <h5>{{ 'Manage TLDs'|trans }}</h5>
    <p>{{ 'Setup domain pricing and allowed operations. Assign specific domain registrars for each Top Level Domain (TLD)'|trans }}</p>
</div>

<table class="tableStatic wide">
    <thead>
        <tr class="noborder">
            <td>{{ 'TLD'|trans }}</td>
            <td>{{ 'Registration'|trans }}</td>
            <td>{{ 'Renew'|trans }}</td>
            <td>{{ 'Transfer'|trans }} </td>
            <td>{{ 'Operations'|trans }}</td>
            <td>{{ 'Registrar'|trans }}</td>
            <td style="width:13%">&nbsp;</td>
        </tr>
    </thead>

    <tbody>
        {% for tld in admin.servicedomain_tld_get_list({"per_page":99}).list %}
        <tr>
            <td>{{ tld.tld }}</td>
            <td>{{ mf.currency_format(tld.price_registration) }}</td>
            <td>{{ mf.currency_format(tld.price_renew) }}</td>
            <td>{{ mf.currency_format(tld.price_transfer) }}</td>
            <td>
             {{ 'Allow register:'|trans }} {% if tld.allow_register %}{{ 'Yes'|trans }}{% else %}{{ 'No'|trans }}{% endif %}<br/>
             {{ 'Allow transfer:'|trans }} {% if tld.allow_transfer %}{{ 'Yes'|trans }}{% else %}{{ 'No'|trans }}{% endif %}<br/>
             {{ 'Active:'|trans }} {% if tld.active %}{{ 'Yes'|trans }}{% else %}{{ 'No'|trans }}{% endif %}
            </td>
            <td><a class="" href="{{ 'servicedomain/registrar'|alink }}/{{ tld.registrar.id }}">{{ tld.registrar.title }}</a></td>
            <td class="actions">
                <a class="btn14 mr5" href="{{ 'servicedomain/tld'|alink }}/{{ tld.tld|slice(1) }}"><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-reload="1" href="{{ 'api/admin/servicedomain/tld_delete'|link({'tld' : tld.tld}) }}"><img src="images/icons/dark/trash.png" alt=""></a>
            </td>
        </tr>
        {% endfor %}
     </tbody>

</table>
</div>

        <div class="tab_content nopadding" id="tab-new-tld">

            <div class="help">
                <h5>{{ 'Add new top level domain'|trans }}</h5>
                <p>{{ 'Setup new TLD prices and properties'|trans }}</p>
            </div>

            <form method="post" action="{{ 'api/admin/servicedomain/tld_create'|link }}" class="mainForm save api-form" data-api-reload="1">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{{ 'Tld'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="tld" value="." required="required" class="dirTop" title="Must start with a dot">
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Registrar'|trans }}:</label>
                        <div class="formRight">
                            <select name="tld_registrar_id" required="required">
                                {% for id,title in admin.servicedomain_registrar_get_pairs %}
                                <option value="{{id}}">{{ title }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Registration price'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="price_registration" value="" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Renewal price'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="price_renew" value="" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Transfer price'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="price_transfer" value="" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Minimum years of registration'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="min_years" value="1" required="required">
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Allow registration'|trans }}:</label>
                        <div class="formRight">
                            <input type="radio" name="allow_register" value="1"checked="checked"/><label>{{ 'Yes'|trans }}</label>
                            <input type="radio" name="allow_register" value="0"/><label>{{ 'No'|trans }}</label>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Allow transfer'|trans }}:</label>
                        <div class="formRight">
                            <input type="radio" name="allow_transfer" value="1" checked="checked"/><label>{{ 'Yes'|trans }}</label>
                            <input type="radio" name="allow_transfer" value="0"/><label>{{ 'No'|trans }}</label>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{{ 'Active'|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>

                    <input type="submit" value="{{ 'Add'|trans }}" class="greyishBtn submitForm" />
                </fieldset>
            </form>

        </div>

        <div class="tab_content nopadding" id="tab-registrars">

        <div class="help">
            <h5>{{ 'Domain registrars'|trans }}</h5>
            <p>{{ 'Manage domain registrars'|trans }}</p>
        </div>

        <table class="tableStatic wide">
            <thead>
                <tr class="noborder">
                    <th>{{ 'Title'|trans }}</th>
                    <th style="width:18%">&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                {% for registrar in admin.servicedomain_registrar_get_list.list %}
                <tr>
                    <td>{{ registrar.title }}</td>
                    <td>
                        <a class="btn14 mr5" href="{{ 'servicedomain/registrar/'|alink }}/{{ registrar.id }}"><img src="images/icons/dark/pencil.png" alt=""></a>
                        <a class="bb-button btn14 api-link" href="{{ 'api/admin/servicedomain/registrar_copy'|link({'id' : registrar.id}) }}" data-api-reload="1" title="Install"><img src="images/icons/dark/baloons.png" alt=""></a>
                        <a class="bb-button btn14 api-link" href="{{ 'api/admin/servicedomain/registrar_delete'|link({'id' : registrar.id}) }}" data-api-confirm="Are you sure?" data-api-reload="1"><img src="images/icons/dark/trash.png" alt=""></a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>

            </div>

        <div class="tab_content nopadding" id="tab-nameservers">

        <div class="help">
            <h5>{{ 'Nameservers'|trans }}</h5>
            <p>{{ 'Setup default nameservers that will be used for new domain registrations if client have not provided his own nameservers in order form'|trans }}</p>
        </div>

        <form method="post" action="{{ 'api/admin/system/update_params'|link }}" class="mainForm api-form" data-api-msg="Nameservers updated">
        <fieldset>
            <div class="rowElem noborder">
                <label>{{ 'Nameserver 1'|trans }}:</label>
                <div class="formRight noborder">
                    <input type="text" name="nameserver_1" value="{{ admin.system_param({'key':'nameserver_1'}) }}">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Nameserver 2'|trans }}:</label>
                <div class="formRight noborder">
                    <input type="text" name="nameserver_2" value="{{ admin.system_param({'key':'nameserver_2'}) }}">
                </div>
                <div class="fix"></div>
            </div>
            <div class="rowElem">
                <label>{{ 'Nameserver 3'|trans }}:</label>
                <div class="formRight noborder">
                    <input type="text" name="nameserver_3" value="{{ admin.system_param({'key':'nameserver_3'}) }}">
                </div>
                <div class="fix"></div>
            </div>

            <div class="rowElem">
                <label>{{ 'Nameserver 4'|trans }}:</label>
                <div class="formRight noborder">
                    <input type="text" name="nameserver_4" value="{{ admin.system_param({'key':'nameserver_4'}) }}">
                </div>
                <div class="fix"></div>
            </div>
            <input type="submit" value="{{ 'Update nameservers'|trans }}" class="greyishBtn submitForm" />
        </fieldset>
        </form>
        </div>

        <div class="tab_content nopadding" id="tab-new-registrar">
            {% include "partial_extensions.phtml" with { 'type': 'domain-registrar', 'header': 'List of domain registrars on extensions site' } only %}
            <div class="body">
                <h1 class="pt10">{{ 'Adding new domain registrar'|trans }}</h1>
                <p>{{ 'Follow instructions below to install new domain registrar.'|trans }}</p>

                <div class="pt20 list arrowGrey">
                    <ul>
                        <li>{{ 'Check domain registrar you are looking for is available at'|trans }} <a href="http://extensions.boxbilling.org/" target="_blank">BoxBilling extensions site</a></li>
                        <li>{{ 'Download domain registrar file and place to'|trans }} <strong>{{ constant('BB_PATH_LIBRARY') }}/Registrar/Adapter</strong></li>
                        <li>{{ 'Reload this page to see newly detected domain registrar'|trans }}</li>
                        <li>{{ 'Click on install button. Now you will be able to create top level domains with new domain registrar'|trans }}</li>
                        <li>{{ 'For developers. Read'|trans }} <a href="http://docs.boxbilling.org/en/latest/reference/extension.html#domain-registrar" target="_blank">{{ 'BoxBilling documentation'|trans }}</a> {{ 'to learn how to create your own domain registrar.'|trans }}</li>
                    </ul>
                </div>

            </div>

            {% if admin.servicedomain_registrar_get_available|length > 0 %}
            <table class="tableStatic wide">
            <thead>
                <tr>
                    <td>{{ 'Code'|trans }}</td>
                    <td style="width: 5%">{{ 'Install'|trans }}</td>
                </tr>
            </thead>

            <tbody>
            {% for code in admin.servicedomain_registrar_get_available %}
            <tr>
                <td>{{ code }}</td>
                <td class="actions">
                    <a class="bb-button btn14 api-link" href="{{ 'api/admin/servicedomain/registrar_install'|link({'code' : code}) }}" data-api-msg="Domain registrar installed" title="Install"><img src="images/icons/dark/cog.png" alt=""></a>
                </td>
            </tr>
            </tbody>

            {% else %}
            <tbody>
                <tr>
                    <td colspan="5">
                        {{ 'All payment gateways installed'|trans }}
                    </td>
                </tr>
            </tbody>
            {% endfor %}
        </table>
        {% endif %}
        </div>
    </div>
</div>
{% endblock %}
