{% extends app['twig_theme'] ~ '/layout.twig' %}
{% import  app['twig_theme'] ~ '/macro/iptw_macro.twig' as main_macro %}

{% set title = ('IPTV channels'|trans ~ ': ' ~ (app.channelEdit ? ('edit channel "'|trans ~ app.editChannelName ~ '"') | trans : 'add'|trans)) | trans %}
{% set active_alias = 'iptv-list' %}


{% block footer_js %}
    
        {{ parent() }}
        {% include app.twig_theme ~ "/basic_templates/scripts-select2.twig" %}
        {% include app.twig_theme ~ "/basic_templates/file-uploader-scripts.twig" %}

{% endblock %}
{% block footer %}

        {{ parent() }}
        <script type="text/javascript" src="./js/jquery.tmpl.min.js" defer=""></script>
        <script type="text/javascript" src="./plugins/scrollTo/jquery.scrollTo.min.js" defer=""></script>
        <script type="text/javascript" defer="">
           
            {% include (app.twig_theme ~ "/TvChannels/add_channel/add_channel.js.twig") %}

        </script>
        
{% endblock %}


{% block content %}
    
    {% if attribute(app, 'not_found') is defined and app.not_found %}
    <div class="row ">
        <div class="box">
            <div class="box-content">
                <h3 class="text-danger">{{ 'Requested channel not found'|trans }}. {{ 'Add a channel'|trans }}?</h3>
            </div>
        </div>
    </div>
    {% endif %}

    <div id="add_channel">
        {{ form_start(app['form'], {'method': 'POST', 'action': (app.request_context.baseUrl ~ '/' ~ app.controller_alias  ~ '/' ~ app.action_alias), 'attr': {'class': 'form-horizontal', 'role': 'form', 'id': 'form_' }}) }}
        <div class="bg-danger">
            <div class="bg-danger">
                {{ form_errors(app['form']) }}
            </div>
        </div>
        <div class="row">
            <div class="box">
                <h4 class="section-header"><span>{{ 'Basic'|trans }}</span></h4>
                {#
                <a class="collapse-link">
                    <div class="box-header">
                        <div class="box-name">
                            <div class="row">
                                <div class="col-xs-10 col-sm-2">
                                    <span>{{ 'Basic'|trans }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="box-icons">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                    </div>
                </a>
                #}
                <div class="box-content" id="add_channel_base">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Channel number'|trans }}<span class="icon-required">*</span></label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].id) }}
                                {{ form_widget(app['form'].number, {'attr': {'class': 'form-control ignore',
                                    'data-validation':'required, number, server',
                                    'data-validation-allowing':'range[1;99999]',
                                    'data-validation-postpone': '200',
                                    'data-validation-url': app.request_context.baseUrl ~ '/'~ app.controller_alias ~'/check-channel-number',
                                    'data-validation-param-name': 'number'
                                }}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].number) }}
                                    {% if attribute(app, 'error_local') is defined and attribute(app['error_local'], 'number') is defined %}<span> {{ app['error_local']['number'] }}</span> {% endif %}
                                </div>
                            </div>
                            {#
                            <span class="help-inline col-xs-12 col-sm-12">
                                <span class="small txt-default">{{ 'Number in channel list must contain only numbers from 0 to 999'|trans }}</span>
                            </span>
                            #}
                            <i class="i-hint"
                                title="{{ 'Number in channel list must contain only numbers from 1 to 999' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Channel name'|trans }}<span class="icon-required">*</span></label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].name, {'attr': {'class': 'form-control',
                                    'data-validation':'required, server',
                                    'data-validation-postpone': '200',
                                    'data-validation-url': app.request_context.baseUrl ~ '/'~ app.controller_alias ~'/check-channel-name',
                                    'data-validation-param-name': 'name'
                                }}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].name) }}
                                    {% if attribute(app, 'error_local') is defined and attribute(app['error_local'], 'name') is defined %}<span> {{ app['error_local']['name'] }}</span> {% endif %}
                                </div>
                            </div>
                            <i class="i-hint"
                                title="{{ 'You can use Latin letters, digits and symbols from the list ! @ # $ % ^ & * ( ) _ - + : ; , .' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Genre'|trans }}<span class="icon-required">*</span></label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].tv_genre_id, {'attr': {'class': 'populate placeholder'} }) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].tv_genre_id) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Languages'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].languages, {'attr': {'class': 'populate placeholder'} }) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].languages) }}
                                </div>
                            </div>
                            <div class="no-padding-left col-xs-10 col-sm-6">
                                <button id="lang_autocheck" class="btn btn-success {% if not(attribute(app['form'], 'cmd') is defined) or app['form']['cmd']|length < 1 %}disabled{% endif %}">{{ 'Autofill'|trans }}</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Volume correction'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-3">
                                {{ form_widget(app['form'].volume_correction, {'attr': {'class': 'populate placeholder'} }) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].volume_correction) }}
                                </div>
                            </div>
                            <i class="i-hint"
                                title="{{ 'Sets compulsory volume level for this channel' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Channel logo'|trans }}:</label>
                        <div class="col-xs-10 col-sm-8">
                            <div class="pull-left" id="cover_container">
                                {{form_widget(app['form'].logo) }}
                                <img class="channel-logo" src="{% if app['form'].logo.vars.value %}{{ app.baseHost }}{{app['form'].logo.vars.value }}?ver={{ random(100000) }}{% endif %}" alt="" style="max-width: 100%;">
                                <div class="col-xs-2 col-sm-1 no-padding" id="deletelogolink">
                                    <a class="no_context_menu" href="{{app.request_context.baseUrl}}/{{app.controller_alias}}/delete-logo" data-logo_id="{% if app['form'].id.vars.value %}{{app['form'].id.vars.value}}{% endif %}">{{ 'Delete logo'|trans }}</a>
                                </div>
                            </div>

                            <!-- The file upload form used as target for the file upload widget -->
                            <div id="fileupload" class="clear-left pull-left">
                                <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
                                <div class="fileupload-buttonbar">
                                    <div class="fileupload-buttons">
                                        <!-- The fileinput-button span is used to style the file input field as button -->
                                        <span class="fileinput-button btn btn-success">
                                            <span>{{ 'Add a picture'|trans }}</span>
                                            <input type="file" name="files" style="opacity: 0;">
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <span class="help-inline col-xs-12 col-sm-12">
                                <span class="small txt-default">{{ 'Recommended format – png, no smaller than 96*96 pixels, maximum size of the file – 1 MB.'|trans }}</span>
                            </span>
                        </div>
                    </div>
                    {% if attribute(app, 'enable_tariff_plans') is defined and not app['enable_tariff_plans']%}
                    <div class="form-group form-group-checkbox">
                        <label class="col-sm-2 control-label">{{ 'Basic channel'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-10">
                                <div class="checkbox-inline">
                                    <label>
                                        {{ form_widget(app['form'].base_ch) }}
                                        <i class="fa fa-square-o small"></i>
                                    </label>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'The base channel is available for user by default.' |trans }} {{'Not base channel may be available by subscription in user profile.' |trans}}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].base_ch) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endif %}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Streaming links'|trans }}<span class="icon-required">*</span></label>
                        <div class="col-xs-10 col-sm-8">
                            <div class=" col-xs-10 col-sm-12">
                                <table class="table table-datatable dataTable  table-hover" id="cmd_data" data-validation = 'cmd_validate'>
                                    <thead>
                                    <tr>
                                        <th>{{ 'Address'|trans }}</th>
                                        <th>{{ 'Filter'|trans }}</th>
                                        <th>{{ 'Priority'|trans }}</th>
                                        <th>{{ 'Temporary HTTP–link'|trans }}</th>
                                        <th>{{ 'Monitoring'|trans }}</th>
                                        <th>{{ 'Monitoring status'|trans }}</th>
                                        <th>{{ 'Loading balance'|trans }}</th>
                                        <th></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <!-- Start: list_row -->
                                    {% if attribute(app['form'], 'cmd') is defined and app['form']['cmd']|length >= 1 %}
                                        {% for key in app['form'].cmd|keys %}
                                            {% if attribute(app['form']['cmd'][key].vars, 'value') is defined %}
                                                <tr>
                                                    <td>
                                                        {{ main_macro.input_hidden(app['form']['link_id'], 'link_id', key, 0) }}
                                                        {{ main_macro.input_hidden(app['form']['cmd'], 'cmd', key, 1) }}
                                                    </td>
                                                    <td>
                                                        {{ main_macro.input_hidden(app['form']['user_agent_filter'], 'user_agent_filter', key, 1) }}
                                                    </td>
                                                    <td>
                                                        {{ main_macro.input_hidden(app['form']['priority'], 'priority', key, 1) }}
                                                    </td>
                                                    <td>
                                                        <div class="col-sm-12">
                                                            {{ main_macro.input_checkbox(app['form']['use_http_tmp_link'], 'use_http_tmp_link', key) }}
                                                            {% if attribute(app, 'httpTmpLink') is defined and app['httpTmpLink'] %}
                                                                {% for row in app['httpTmpLink'] %}
                                                                    {% if not(row.value == 'use_http_tmp_link') %}
                                                                        {{ main_macro.input_hidden(app['form'][row.value], row.value, key, 0) }}
                                                                    {% endif %}
                                                                {% endfor %}
                                                            {% endif %}
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="col-sm-12">
                                                            {{ main_macro.input_checkbox(app['form']['enable_monitoring'], 'enable_monitoring', key) }}
                                                            {{ main_macro.input_hidden(app['form']['enable_balancer_monitoring'], 'enable_balancer_monitoring', key, 0) }}
                                                            {{ main_macro.input_hidden(app['form']['monitoring_url'], 'monitoring_url', key, 0) }}
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="col-sm-12">
                                                            {% if attribute(app['form']['monitoring_status'], key) is defined and attribute(app['form']['enable_monitoring'], key) is defined %}
                                                                {{ main_macro.set_monitoring_status(app['form']['monitoring_status'], key, app['form']['enable_monitoring'][key].vars.data) }}
                                                            {% else %}
                                                                <div>
                                                                    <label> - </label>
                                                                </div>
                                                            {% endif %}
                                                            {% if attribute(app['form']['monitoring_status'], key) is defined %}
                                                                {{ main_macro.input_hidden(app['form']['monitoring_status'], 'monitoring_status', key, 0) }}
                                                            {% endif %}
                                                            {% if attribute(app['form']['enable_monitoring'], key) is defined %}
                                                                {{ main_macro.input_hidden(app['form']['enable_monitoring'], 'enable_monitoring', key, 0) }}
                                                            {% endif %}
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="col-sm-12">
                                                            {{ main_macro.input_checkbox(app['form']['use_load_balancing'], 'use_load_balancing', key) }}
                                                            {{ main_macro.input_hidden(app['form']['stream_server'], 'stream_server', key, 0) }}
                                                        </div>
                                                    </td>
                                                    <td class="action-menu">
                                                        <div class="col-xs-3 col-sm-8">
                                                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                                                <i class="pull-right fa fa-cog"></i>
                                                            </a>
                                                            <ul class="dropdown-menu pull-right">
                                                                <li>
                                                                    <a href="#" class="channel_url_change_data">
                                                                        <span>{{ 'Edit'|trans }}</span>
                                                                    </a>
                                                                </li>
                                                                <li>
                                                                    <a href="#" class="channel_url_remove_data">
                                                                        <span>{{ 'Delete'|trans }}</span>
                                                                    </a>
                                                                </li>
                                                            </ul>
                                                        </div>
                                                    </td>
                                                </tr>
                                            {% endif %}
                                        {% endfor %}
                                    {% endif %}
                                    <tr>
                                        <td>
                                            <label data-field="form[cmd]"></label>
                                            <input type="hidden" disabled="disabled" name="form[cmd][0]" id="form_cmd_0">
                                        </td>
                                        <td>
                                            <label data-field="form[user_agent_filter]"></label>
                                            <input type="hidden" disabled="disabled" name="form[user_agent_filter][0]" id="form_user_agent_filter_0">
                                        </td>
                                        <td>
                                            <label data-field="form[priority]"></label>
                                            <input type="hidden" disabled="disabled" name="form[priority][0]" id="form_priority_0">
                                        </td>
                                        <td>
                                            <div class="col-sm-12">
                                                <div class="toggle-switch toggle-switch-success">
                                                    <label>
                                                        <input type="checkbox" value="1" disabled="disabled" name="form[use_http_tmp_link][0]" id="form_use_http_tmp_link_0">
                                                        <div class="toggle-switch-inner"></div>
                                                        <div class="toggle-switch-switch"></div>
                                                    </label>
                                                </div>
                                                {% if attribute(app, 'httpTmpLink') is defined and app['httpTmpLink'] %}
                                                    {% for row in app['httpTmpLink'] %}
                                                        {% if not(row.value == 'use_http_tmp_link') %}
                                                        <input type="hidden" disabled="disabled" name="form[{{ row.value }}][0]" id="form_{{ row.value }}_0">
                                                        {% endif %}
                                                    {% endfor %}
                                                {% endif %}
                                            </div>
                                        </td>
                                        <td>
                                            <div class="col-sm-12">
                                                <div class="toggle-switch toggle-switch-success">
                                                    <label>
                                                        <input type="checkbox" value="1" disabled="disabled" name="form[enable_monitoring][0]" id="form_enable_monitoring_0">
                                                        <div class="toggle-switch-inner"></div>
                                                        <div class="toggle-switch-switch"></div>
                                                    </label>
                                                    <input type="hidden" disabled="disabled" name="form[enable_balancer_monitoring][0]" id="form_enable_balancer_monitoring_0">
                                                    <input type="hidden" disabled="disabled" name="form[monitoring_url][0]" id="form_monitoring_url_0">
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="col-sm-12">
                                                <div >
                                                    <label>-</label>
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                            <div class="col-sm-12">
                                                <div class="toggle-switch toggle-switch-success">
                                                    <label>
                                                        <input type="checkbox" value="1" disabled="disabled" name="form[use_load_balancing][0]" id="form_use_load_balancing_0">
                                                        <div class="toggle-switch-inner"></div>
                                                        <div class="toggle-switch-switch"></div>
                                                    </label>
                                                    <input type="hidden" disabled="disabled" name="form[stream_server][0]" id="form_stream_server_0">
                                                </div>
                                            </div>
                                        </td>
                                        <td class="action-menu">
                                            <div class="col-xs-3 col-sm-8">
                                                <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                                                    <i class="pull-right fa fa-cog"></i>
                                                </a>
                                                <ul class="dropdown-menu pull-right">
                                                    <li>
                                                        <a class="channel_url_change_data" href="#">
                                                            <span>{{ 'Edit'|trans }}</span>
                                                        </a>
                                                    </li>
                                                    <li>
                                                        <a class="channel_url_remove_data" href="#">
                                                            <span>{{ 'Delete'|trans }}</span>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                    </tr>
                                    <!-- End: list_row -->
                                    </tbody>
                                </table>
                                <input type="hidden" name="cmd_validate" data-validation = 'cmd_validate'>
                            </div>
                            {% if attribute(app, 'error_local') is defined and attribute(app['error_local'], 'cmd') is defined %}
                                <div class=" col-xs-10 col-sm-12 cmd_error">
                                    <div class="bg-danger lead">
                                        <span> {{ app['error_local']['cmd'] }}</span>
                                    </div>
                                </div>
                            {% endif %}
                            <div class="pull-left">
                                <a class="btn btn-success btn-block" id="add_broadcasting_link"><span>{{ 'Add link'|trans }}</span></a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box">
                <h4 class="section-header"><span>{{ 'TV archive'|trans }}</span></h4>
                {#
                <a class="collapse-link">
                    <div class="box-header">
                        <div class="box-name">
                            <div class="row">
                                <div class="col-xs-10 col-sm-2">
                                    <span>{{ 'TV archive'|trans }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="box-icons">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                        <div class="no-move"></div>
                    </div>
                </a>
                #}
                <div class="box-content" id="add_channel_storage_save">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'TV archive type'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-3">
                                {{ form_widget(app['form'].tv_archive_type, {'attr': {'class': 'form-control populate placeholder', 'placeholder': 'Disabled'|trans} }) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].tv_archive_type) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Archive servers'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].storage_names, {'attr': {'class': 'populate placeholder', 'data-validation': 'required', 'data-validation-depends-on' : 'form[tv_archive_type]', 'data-validation-error-msg': "Select the storage for recording" | trans}}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].storage_names) }}
                                </div>
                                {{ form_widget(app['form'].wowza_storage_names, {'attr': {'class': 'populate placeholder', 'data-validation': 'required', 'data-validation-depends-on' : 'form[tv_archive_type]', 'data-validation-error-msg': "Select the storage for recording" | trans}}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].wowza_storage_names) }}
                                </div>
                                {{ form_widget(app['form'].flussonic_storage_names, {'attr': {'class': 'populate placeholder', 'data-validation': 'required', 'data-validation-depends-on' : 'form[tv_archive_type]', 'data-validation-error-msg': "Select the storage for recording" | trans}}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].flussonic_storage_names) }}
                                </div>
                                {{ form_widget(app['form'].nimble_storage_names, {'attr': {'class': 'populate placeholder', 'data-validation': 'required', 'data-validation-depends-on' : 'form[tv_archive_type]', 'data-validation-error-msg': "Select the storage for recording" | trans}}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].nimble_storage_names) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'TV archive address'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].mc_cmd, {'attr': {'class': 'form-control', 'data-validation': 'required custom', 'data-validation-regexp': '^(http|udp|rtp)\\:\\/\\/', 'data-validation-error-msg-custom': "Valid protocols are http://, rtp:// and udp://." | trans, 'data-validation-error-msg-required': "Input source URL" | trans, 'data-validation-depends-on' : 'form[tv_archive_type]' }}) }} {#, form[allow_pvr]#}
                                {# multiple fields in data-validation-depends-on is made manualy in javascript file #}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].mc_cmd) }}
                                    {% if attribute(app, 'error_local') is defined and attribute(app['error_local'], 'mc_cmd') is defined %}<span> {{ app['error_local']['mc_cmd'] }}</span> {% endif %}
                                </div>
                            </div>
                            <i class="i-hint"
                                title="{{ 'Channel\'s URL for TV archive or nPVR recording' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'TV archive length'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].tv_archive_duration, {'attr': {'class': 'form-control populate placeholder', 'data-validation':'required number', 'data-validation-error-msg-required': "Setup TV archive duration" | trans, 'data-validation-allowing':'range[0;999]', 'data-validation-error-msg-number': "Allowed values from 0 to 999"|trans, 'data-validation-depends-on' : 'form[tv_archive_type]' }}) }}
                                {# multiple fields in data-validation-depends-on is made manualy in javascript file #}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].tv_archive_duration) }}
                                </div>
                            </div>
                            <i class="i-hint"
                                title="{{ 'TV archive length' |trans }}. {{ 'Measured in hours' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                    <div class="form-group form-group-checkbox">
                        <label class="col-sm-2 control-label">{{ 'Allow nPVR'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-10">
                                <div class="checkbox-inline">
                                    <label>
                                        {{ form_widget(app['form'].allow_pvr) }}
                                        <i class="fa fa-square-o small"></i>
                                    </label>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'Allow the user to record selected programs on the server repository' |trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].allow_pvr) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'nPVR servers'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].pvr_storage_names, {'attr': {'class': 'populate placeholder', 'data-validation': 'required', 'data-validation-depends-on' : 'form[allow_pvr]', 'data-validation-error-msg': "Select the storage for recording" | trans }}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].pvr_storage_names) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box">
                <h4 class="section-header"><span>{{ 'EPG'|trans }}</span></h4>
                {#
                <a class="collapse-link">
                    <div class="box-header">
                        <div class="box-name">
                            <div class="row">
                                <div class="col-xs-10 col-sm-2">
                                    <span>{{ 'EPG'|trans }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="box-icons">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                        <div class="no-move"></div>
                    </div>
                </a>
                #}
                <div class="box-content" id="add_channel_EPG">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'XMLTV ID'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].xmltv_id, {'attr': {'class': 'form-control' }}) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].xmltv_id) }}
                                </div>
                            </div>
                            {% autoescape false %}
                            <i class="i-hint"
                                title="{{ 'XMLTV ID of channel in EPG file. If the EPG source has the prefix state it in &lt;your_prefix&gt;ID format' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                            {% endautoescape %}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{{ 'Time correction for EPG'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-6">
                                {{ form_widget(app['form'].correct_time, {'attr': {'class': 'form-control', 'data-validation':'number', 'data-validation-allowing':'range[-720;840],negative', 'data-validation-error-msg': "Allowed values from -720 to 840" | trans, 'data-validation-depends-on' : 'form[xmltv_id]'} }) }}
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].correct_time) }}
                                </div>
                            </div>
                            <i class="i-hint"
                                title="{{ 'Measured in minutes' |trans }}" >
                                <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                            </i>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box">
                <h4 class="section-header"><span>{{ 'Parental control'|trans }}</span></h4>
                {#
                <a class="collapse-link">
                    <div class="box-header">
                        <div class="box-name">
                            <div class="row">
                                <div class="col-xs-10 col-sm-2">
                                    <span>{{ 'Parental control'|trans }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="box-icons">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                        <div class="no-move"></div>
                    </div>
                </a>
                #}
                <div class="box-content" id="add_channel_safety">
                    <div class="form-group form-group-checkbox">
                        <label class="col-sm-2 control-label">{{ 'Age restriction'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-10">
                                <div class="checkbox-inline">
                                    <label>
                                        {{ form_widget(app['form'].censored) }}
                                        <i class="fa fa-square-o small"></i>
                                    </label>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'Sets the password restriction on the channel Default password 0000' |trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].censored) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box">
                <h4 class="section-header"><span>{{ 'USB recordings'|trans }}</span></h4>
                {#
                <a class="collapse-link">
                    <div class="box-header">
                        <div class="box-name">
                            <div class="row">
                                <div class="col-xs-10 col-sm-2">
                                    <span>{{ 'USB recordings'|trans }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="box-icons">
                            <i class="fa fa-chevron-down"></i>
                        </div>
                        <div class="no-move"></div>
                    </div>
                </a>
                #}
                <div class="box-content" id="add_channel_usb_store">
                    <div class="form-group form-group-checkbox">
                        <label class="col-sm-2 control-label">{{ 'TimeShift via USB devices'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-10">
                                <div class="checkbox-inline">
                                    <label>
                                        {{ form_widget(app['form'].allow_local_timeshift) }}
                                        <i class="fa fa-square-o small"></i>
                                    </label>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'User can perform TimeShift function using Flash drive.'|trans }} {{ 'TimeShift only works with solutions rtp and ffrt.'|trans}}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].allow_local_timeshift) }}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-checkbox">
                        <label class="col-sm-2 control-label">{{ 'PVR to the USB-driver'|trans }}</label>
                        <div class="col-xs-10 col-sm-6">
                            <div class=" col-xs-10 col-sm-10">
                                <div class="checkbox-inline">
                                    <label>
                                        {{ form_widget(app['form'].allow_local_pvr) }}
                                        <i class="fa fa-square-o small"></i>
                                    </label>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'User can record selected shows and programs to the Flash drive.'|trans }} {{ 'Can record only the channels, which is broadcasted in the transport stream (mpeg-ts),  from multicast and also from http-server.'|trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                                <div class="bg-danger">
                                    {{ form_errors(app['form'].allow_local_pvr) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-buttons col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="box">
                <div class="box-content">
                    <div class="row">
                        <div class="pull-right">
                            {{ form_widget(app['form'].save, { 'label': 'Save'|trans , attr: {'class': 'btn btn-success   pull-right' }}) }}
                            <a href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/iptv-list" class="btn btn-default  pull-right">{{ 'Cancel'|trans }}</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div style="display: none;">
        {{ form_rest(app['form']) }}
    </div>
        {{ form_end(app['form']) }}
    

    <div id="modalbox_ad">
        <div class="devoops-modal channel-form">
            <div class="devoops-modal-header">
                <div class="modal-header-name">
                    <span>{{ 'Add streaming link'|trans }}</span>
                </div>
                <div class="box-icons">
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <form class="form-horizontal" role="form" id="add_channel_link_form">
                <div class="devoops-modal-inner">
                    <div class="box">
                        <a class="collapse-link">
                            <div class="box-header">
                                <div class="box-name">
                                    <div class="row">
                                        <div class="col-xs-10 col-sm-4">
                                            <span>{{ 'Basic'|trans }}</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="box-icons">
                                    <i class="fa fa-chevron-down"></i>
                                </div>
                                <div class="no-move"></div>
                            </div>
                        </a>
                        <div class="box-content" id="add_channel_url_base">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Channel URL'|trans }}<span class="icon-required">*</span></label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12 no-padding-right">
                                        <input class="form-control" type="text" name="form[cmd][]" value=""
                                        data-validation = "required, custom, cmd_duplicated"
                                        data-validation-regexp = "^(\w+\s)?\w+\:\/\/.+$"
                                        data-validation-error-msg-cmd_duplicated="{{'This URL already exists'|trans }}" >
                                    </div>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'Format: solution+URL Example ffrt http://5.39.70.216/live/88.ts' |trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Filter'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12 no-padding-right">
                                        <input class="form-control" type="text" title="" value="" name="form[user_agent_filter][]"
                                        data-validation = "cmd_filter_user_agent" data-validation-optional="true"
                                        data-validation-error-msg="{{'Incorrect filter value'|trans }}">
                                    </div>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'Filter by user-agent. Ability to set the filter by the connection type (WiFi, Ethernet), by STB model (MAG250, MAG275, ...), by country (UA, RU, ...). Field is case sensitive' |trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Priority'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="form[priority][]" id="s2_priority">
                                            <option value="0">0</option>
                                            <option value="1">1</option>
                                            <option value="2">2</option>
                                            <option value="3">3</option>
                                            <option value="4">4</option>
                                            <option value="5">5</option>
                                        </select>
                                    </div>
                                    <i class="i-hint"
                                        title="{{ 'Priority for channel URL, 0 – the highest priority' |trans }}" >
                                        <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                    </i>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Temporary URL'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="form[use_http_tmp_link][]" id="s2_use_http_tmp_link">
                                            <option value="">&nbsp;</option>
                                            {% if attribute(app, 'httpTmpLink') is defined %}
                                                {% for row in app['httpTmpLink'] %}
                                                    <option value="{{ row.value }}" data-check-module={% if row.check_module and not app['mcrypt_enabled'] %}0{% else %}1{% endif %}>{{ row.label }}</option>
                                                {% endfor %}
                                            {% endif %}
                                        </select>
                                    </div>
                                    <i class="i-hint"
                                        title="{{ 'Protect channel from unauthorized access' |trans }}" >
                                        <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                    </i>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="box">
                        <a class="collapse-link">
                            <div class="box-header">
                                <div class="box-name">
                                    <div class="row">
                                        <div class="col-xs-10 col-sm-4">
                                            <span>{{ 'Monitoring'|trans }}</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="box-icons">
                                    <i class="fa fa-chevron-up"></i>
                                </div>
                                <div class="no-move"></div>
                            </div>
                        </a>
                        <div class="box-content" id="add_channel_link_monitoring">
                            <div class="form-group form-group-checkbox">
                                <label class="col-sm-3 control-label">{{ 'Enable monitoring'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12">
                                        <div class="checkbox-inline">
                                            <label>
                                                <input type="checkbox" name="form[enable_monitoring][]">
                                                <i class="fa fa-square-o small"></i>
                                            </label>
                                        </div>
                                        <i class="i-hint"
                                            title="{{ 'URL availability check' |trans }}" >
                                            <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                        </i>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Channel URL for monitoring'|trans }}<span class="icon-required">*</span></label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12 no-padding-right">
                                        <input class="form-control" type="text" title="" value="" name="form[monitoring_url][]" data-validation = 'required, custom' data-validation-regexp = '^\w+\:\/\/.+$'>
                                    </div>
                                </div>
                                <i class="i-hint"
                                    title="{{ 'Format: URL (without solution). Example: http://lpOfStream/test.js' |trans }}" >
                                    <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                </i>
                            </div>
                        </div>
                    </div>
                    <div class="box">
                        <a class="collapse-link">
                            <div class="box-header">
                                <div class="box-name">
                                    <div class="row">
                                        <div class="col-xs-10 col-sm-4">
                                            <span>{{ 'Load balancing'|trans }}</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="box-icons">
                                    <i class="fa fa-chevron-up"></i>
                                </div>
                                <div class="no-move"></div>
                            </div>
                        </a>
                        <div class="box-content" id="add_channel_load_balancing">
                            <div class="form-group form-group-checkbox">
                                <label class="col-sm-3 control-label">{{ 'Enable load balancing'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12">
                                        <div class="checkbox-inline">
                                            <label>
                                                <input type="checkbox" name="form[use_load_balancing][]" id="use_load_balancing_chk">
                                                <i class="fa fa-square-o small"></i>
                                            </label>
                                        </div>
                                        <i class="i-hint"
                                            title="{{ 'Switching between streaming servers depending on the load' |trans }}" >
                                            <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                        </i>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{ 'Streaming servers'|trans }}<span class="icon-required">*</span></label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-10">
                                        <select class="populate placeholder" multiple name="form[stream_server][]" id="s2_stream_server" data-validation = "required" disabled="disabled">
                                            {% if app['streamServers'] %}
                                                {% for s_item in app.streamServers %}
                                                    <option value="{{ s_item.id }}">{{ s_item.name }}</option>
                                                {% endfor %}
                                            {% endif %}
                                        </select>
                                    </div>
                                    <i class="i-hint"
                                        title="{{ 'Servers which are going to be balanced' |trans }}" >
                                        <img class="i-hint-sign" src="{{app.request_context.baseUrl}}/img/field-hint-sign.svg" />
                                    </i>
                                </div>
                            </div>
                            <div class="form-group form-group-checkbox">
                                <label class="col-sm-3 control-label">{{ 'Balancer monitoring'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12">
                                        <div class="checkbox-inline">
                                            <label>
                                                <input type="checkbox" name="form[enable_balancer_monitoring][]">
                                                <i class="fa fa-square-o small"></i>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="devoops-modal-bottom">
                    <div class="col-xs-12">
                        <button type="submit" class="btn btn-success col-sm-2 pull-right" >{{ 'Save'|trans }}</button>
                        <button type="reset"  class="btn btn-default col-sm-2 pull-right" >{{ 'Cancel'|trans }}</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script type="text/template" id="cmd_autocheck_lang_tmpl">
        <div class="form-group">
            <label class="col-sm-2 control-label">{{ 'Select link'|trans }}</label>
            <input type="hidden" id="ch_id" name="ch_id" value="${ch_id}">
            <div class="col-xs-10 col-sm-10">
                <select id="cmd_autocheck_lang" name="cmd_autocheck_lang" required="required" class="form-control populate placeholder">
                    {{ '{{each links}}'}}
                    <option value="${$value}">${$value}</option>
                    {{ '{{/each}}' }}
                </select>
            </div>
        </div>
        <div class="form-group">
            <div id="cmd_lang_result" class="col-xs-12 col-sm-12" style="min-height: 138px;">
            </div>
        </div>
    </script>

    <script type="text/template" id="modal_form_buttons">
        <div class="pull-right no-padding">&nbsp;</div>
        <div class="pull-right no-padding">
            <button id="cmd_autocheck_btn" type="submit" class="btn btn-success pull-right">{{ 'Check'|trans }}</button>
            <button type="reset" class="btn btn-default pull-right" >{{ 'Cancel'|trans }}</button>
        </div>
    </script>
{% endblock %}
