{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% block meta_title %}{% trans 'System settings' %}{% endblock %}
{% set active_menu = 'system' %}
{% set params = admin.system_get_params %}
{% block content %}

<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-company">{% trans 'Company' %}</a></li>
        <li><a href="#tab-invoice">{% trans 'Invoice' %}</a></li>
        <li><a href="#tab-order">{% trans 'Order' %}</a></li>
        <li><a href="#tab-ftp">{% trans 'FTP layer' %}</a></li>
        <li><a href="#tab-cron">{% trans 'Scheduled tasks' %}</a></li>
        <li><a href="#tab-license">{% trans 'License' %}</a></li>
    </ul>

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

            <div class="help">
                <h3>{% trans 'Company details' %}</h3>
            </div>

            <form method="post" action="admin/system/update_params" class="mainForm api-form" data-api-msg="Company updated">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Name' %}</label>
                        <div class="formRight">
                            <input type="text" name="company_name" value="{{params.company_name}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{% trans 'Email' %}</label>
                        <div class="formRight">
                            <input type="text" name="company_email" value="{{params.company_email}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{% trans 'Phone' %}</label>
                        <div class="formRight">
                            <input type="text" name="company_tel" value="{{params.company_tel}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{% trans 'Address' %}</label>
                        <div class="formRight">
                            <input type="text" name="company_address_1" value="{{params.company_address_1}}" placeholder="Address line 1"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem noborder">
                        <div class="formRight">
                            <input type="text" name="company_address_2" value="{{params.company_address_2}}" placeholder="Address line 2"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem noborder">
                        <div class="formRight">
                            <input type="text" name="company_address_3" value="{{params.company_address_3}}" placeholder="Address line 3"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label class="topLabel">{% trans 'Logo URL' %}</label>
                        <div class="formBottom">
                            <input type="text" name="company_logo" value="{{params.company_logo}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                       <label class="topLabel">{% trans 'Company number, chamber of commerce number' %}</label>
                        <div class="formBottom">
                            <input type="text" name="company_number" value="{{params.company_number}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label class="topLabel">{% trans 'VAT number' %}</label>
                        <div class="formBottom">
                            <input type="text" name="company_vat_number" value="{{params.company_vat_number}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label class="topLabel">{% trans 'Bank Account number' %}</label>
                        <div class="formBottom">
                            <input type="text" name="company_account_number" value="{{params.company_account_number}}"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label class="topLabel">{% trans 'Signature' %}</label>
                        <div class="formBottom">
                            <textarea name="company_signature" rows="5" cols="5">{{params.company_signature}}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>

                <input type="submit" value="{% trans 'Update settings' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>

            <form method="post" action="admin/system/update_params" class="mainForm api-form" data-api-msg="Company updated">
                <fieldset>
                    <legend>{% trans 'Company terms of service, legal regulation' %}</legend>
                    <textarea name="company_tos" rows="5" cols="5" class="bb-textarea">{{params.company_tos}}</textarea>
                </fieldset>

                <fieldset>
                    <legend>{% trans 'Company privacy policy' %}</legend>
                    <textarea name="company_privacy_policy" rows="5" cols="5" class="bb-textarea">{{params.company_privacy_policy}}</textarea>
                </fieldset>

                <fieldset>
                    <legend>{% trans 'Notes' %}</legend>
                    <textarea name="company_note" rows="5" cols="5" class="bb-textarea">{{params.company_note}}</textarea>
                </fieldset>

                <fieldset>
                    <input type="submit" value="{% trans 'Update settings' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

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

            <div class="help">
                <h3>{% trans 'Orders settings' %}</h3>
            </div>
                
            {% set order_params = admin.extension_config_get({"ext":"mod_order"}) %}
            <form method="post" action="admin/extension/config_save" class="mainForm api-form" data-api-msg="Settings updated">
                <fieldset>
                <div class="rowElem">
                    <label>{% trans 'Expiration date' %}</label>
                    <div class="formRight">
                        <input type="radio" name="order_renewal_logic" value="from_expiration_date" {% if order_params.order_renewal_logic == "from_expiration_date" or not params.order_renewal_logic %}checked="checked"{% endif %}/><label>Next date is counted from last order expiration date</label>
                        <div class="clear"></div>
                        <input type="radio" name="order_renewal_logic" value="from_today" {% if order_params.order_renewal_logic == "from_today" %}checked="checked"{% endif %}/><label>Next date is counted from renewal (payment) date</label>
                        <div class="clear"></div>
                        <input type="radio" name="order_renewal_logic" value="from_greater" {% if order_params.order_renewal_logic == "from_greater" %}checked="checked"{% endif %}/><label>Next date is counted from last expiration date or renewal date whichever is greater</label>
                    </div>
                    <div class="fix"></div>
                </div>
                    
                <input type="hidden" name="ext" value="mod_order" />
                <input type="submit" value="{% trans 'Update settings' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>
        
        <div id="tab-invoice" class="tab_content nopadding">

                <div class="help">
                    <h3>{% trans 'Invoice settings' %}</h3>
                </div>

            <form method="post" action="admin/system/update_params" class="mainForm api-form" data-api-msg="Settings updated">
                <fieldset>
                <div class="rowElem noborder">
                    <label>{% trans 'Number of days to generate new invoice before order expiration' %}</label>
                    <div class="formRight">
                        <input type="text" name="invoice_issue_days_before_expire" value="{{params.invoice_issue_days_before_expire}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label>{% trans 'Invoice due days' %}</label>
                    <div class="formRight">
                        <input type="text" name="invoice_due_days" value="{{params.invoice_due_days}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label>{% trans 'Auto invoice approval' %}</label>
                    <div class="formRight">
                        <input type="radio" name="invoice_auto_approval" value="1" {% if params.invoice_auto_approval == "1" %}checked="checked"{% endif %}/><label>{% trans 'Yes' %}</label>
                        <input type="radio" name="invoice_auto_approval" value="0" {% if params.invoice_auto_approval == "0" %}checked="checked"{% endif %}/><label>{% trans 'No' %}</label>
                    </div>
                    <div class="fix"></div>
                </div>
                </fieldset>

                <fieldset>
                    <legend>{% trans 'Proforma Invoicing / Sequential Invoice Numbering' %}</legend>
                <div class="rowElem">
                    <label>{% trans 'Proforma invoice prefix/series' %}</label>
                    <div class="formRight">
                        <input type="text" name="invoice_series" value="{{params.invoice_series}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label>{% trans 'Paid invoice prefix/series' %}</label>
                    <div class="formRight">
                        <input type="text" name="invoice_series_paid" value="{{params.invoice_series_paid}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label>{% trans 'Next paid invoice number' %}</label>
                    <div class="formRight">
                        <input type="text" name="invoice_starting_number" value="{{params.invoice_starting_number}}"/>
                    </div>
                    <div class="fix"></div>
                </div>
                </fieldset>
                
                <fieldset>
                    <legend>{% trans 'Refunds settings' %}</legend>
                <div class="rowElem">
                    <label>{% trans 'Refunds logic' %}</label>
                    <div class="formRight">
                        <input type="radio" name="invoice_refund_logic" value="negative_invoice" {% if params.invoice_refund_logic == "1" %}checked="checked"{% endif %}/><label>Negative invoice. Generate refund invoice continuing paid invoices numbering</label>
                        <div class="clear"></div>
                        <input type="radio" name="invoice_refund_logic" value="credit_note" {% if params.invoice_refund_logic == "credit_note" %}checked="checked"{% endif %}/><label>Credit note. Generate credit note with unique numbering</label>
                        <div class="clear"></div>
                        <input type="radio" name="invoice_refund_logic" value="manual" {% if params.invoice_refund_logic == "manual" %}checked="checked"{% endif %}/><label>Manual. No actions performed</label>
                    </div>
                    <div class="fix"></div>
                </div>
                </fieldset>

                <fieldset>
                    <legend>{% trans 'Add funds settings' %}</legend>
                <div class="rowElem">
                    <label>{% trans 'Minimum amount for add funds invoice' %}</label>
                    <div class="formRight">
                        <input type="text" name="funds_min_amount" value="{{params.funds_min_amount}}" placeholder="{% trans 'Unlimited' %}"/>
                    </div>
                    <div class="fix"></div>
                </div>
                    
                <div class="rowElem">
                    <label>{% trans 'Maximum amount for add funds invoice' %}</label>
                    <div class="formRight">
                        <input type="text" name="funds_max_amount" value="{{params.funds_max_amount}}" placeholder="{% trans 'Unlimited' %}"/>
                    </div>
                    <div class="fix"></div>
                </div>
                    
                <input type="submit" value="{% trans 'Update settings' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div id="tab-ftp" class="tab_content nopadding">
            <div class="help">
                <h3>{% trans 'FTP layer for BoxBilling' %}</h3>
                <p>{% trans 'FTP is used to manage BoxBilling modules and updates.' %}</p>
            </div>

            <form method="post" action="admin/system/update_params" class="mainForm api-form" data-api-msg="{% trans 'FTP settings updated' %}">
                <fieldset>
                <div class="rowElem">
                    <label class="topLabel">{% trans %}<strong>FTP Hostname</strong> - can be a numerical URL 127.0.0.1 is the default address for a locally hosted server, it might be this, it might be the full URL as my example above with the File Transfer Protocol (FTP) prefix, it might be the http:// protocol it might be SFTP (secure FTP) even secure http (https). Your host will be able to advise you on the correct format.{% endtrans %}</label>
                    <div class="formBottom">
                        <input type="text" name="ftp_host" value="{{params.ftp_host|default('localhost')}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label class="topLabel">{% trans %}<strong>FTP port</strong> - is nearly always 21 unless the host has changed this they will have notified you of this. Secure FTP generally uses port 22.{% endtrans %}</label>
                    <div class="formBottom">
                        <input type="text" name="ftp_port" value="{{params.ftp_port|default(21)}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label class="topLabel">{% trans %}<strong>FTP user</strong> - In most cases, this is the specific user name your host has set up for you to access your Web site via FTP- It is the name you use in your FTP client. This could be an alphanumeric, it could be your name, even your e-mail address, If you don't know this speak to your host. You may have the facility on your Web account to set up additional FTP users if that is the case (and it's more secure) you are recommended to do this{% endtrans %}</label>
                    <div class="formBottom">
                        <input type="text" name="ftp_user" value="{{params.ftp_user}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label class="topLabel">{% trans %}<strong>FTP password</strong> - this is the password you enter in your FTP client.{% endtrans %}</label>
                    <div class="formBottom">
                        <input type="password" name="ftp_password" value="{{params.ftp_password}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <div class="rowElem">
                    <label class="topLabel">{% trans %}<strong>FTP root</strong> - This is generally the directory in which BoxBilling is installed. This setting is very important to be setup correctly as it very specifically depends on the Host server settings. In can be just / BUT it might be htdocs/boxbilling, public_html/, /public_html/boxbilling or other. It is a variable that BoxBilling has absolutely no control over. You will need to clarify this with your host.{% endtrans %}</label>
                    <div class="formBottom">
                        <input type="text" name="ftp_root" value="{{params.ftp_root}}"/>
                    </div>
                    <div class="fix"></div>
                </div>

                <input type="submit" value="{% trans 'Update settings' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div id="tab-cron" class="tab_content nopadding">
            
            <div class="help">
                <h3>{% trans 'Setup scheduled tasks to be executed once a day' %}</h3>
                <p>{% trans 'Scheduled tasks must be enabled immediately after installation. Cron is responsible for sending your clients reminder about payments, domain renewal notices and many more.' %}</p>
            </div>

            {% set cron = admin.cron_info %}
            <table class="tableStatic wide">
                <tbody>
                    <tr class="noborder">
                        <td>{% trans 'Timezone' %}</td>
                        <td align="right">{{ "now"|date('e') }}</td>
                    </tr>
                    
                    <tr>
                        <td>{% trans 'Time on server' %}</td>
                        <td align="right">{{ "now"|date('Y-m-d H:i:s') }}</td>
                    </tr>
                    <tr>
                        <td>{% trans 'Last time scheduled tasks were executed' %}</td>
                        <td align="right">
                            {% if cron.last_cron_exec %}
                                {{ cron.last_cron_exec|date('Y-m-d H:i:s') }}
                                ({{cron.last_cron_exec|timeago }} ago)
                            {% else %}
                                {% trans 'Scheduled tasks were never executed' %}
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <td>{% trans 'Unix crontab setup:' %}</td>
                        <td align="right"><pre>*/5 * * * * php {{ cron.cron_path}}</pre></td>
                    </tr>
                    <tr>
                        <td>{% trans 'Execute scheduled tasks from browser' %}</td>
                        <td align="right"><pre>{{ cron.cron_url}}</pre></td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">
                            <div class="aligncenter">
                            <a href="{{ cron.cron_url}}" title="" class="btn55 mr10" target="_blank"><img src="images/icons/middlenav/airplane.png" alt=""><span>{% trans 'Execute now' %}</span></a>
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </div>

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

            <div class="help">
                <h3>{% trans 'License' %}</h3>
                <p>{% trans 'After purchase you have received an e-mail with license key. Update license key to unlock all features of BoxBilling' %}</p>
                <p>{% trans 'To change license key, change <em>BB_LICENSE</em> value in <em>bb-config.php</em> file' %}</p>
            </div>

            {% set env = admin.system_env %}
            {% set license = admin.system_license_info %}
            <table class="tableStatic wide">
                <tbody>
                    <tr class="noborder">
                        <td>{% trans 'Licensed to' %}</td>
                        <td align="right">{{ license.licensed_to }}</td>
                    </tr>
                    <tr>
                        <td>{% trans 'Key' %}</td>
                        <td align="right">{{ license.key }}</td>
                    </tr>

                    {% if license.expires_at %}
                    <tr>
                        <td>{% trans 'Expires at' %}</td>
                        <td align="right">{{ license.expires_at|date('Y-m-d') }}</td>
                    </tr>
                    {% endif %}
                    
                    <tr>
                        <td>{% trans 'IP' %}</td>
                        <td align="right">{{ env.ip }}</td>
                    </tr>
                </tbody>
            </table>
        </div>

    </div>
    
</div>
{% endblock %}

{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}