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

{% set title = 'Users'|trans ~ ': ' ~ 'list of users'|trans %}


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

        <script src="{{app.request_context.baseUrl}}/plugins/datatables/extensions/FixedHeader/js/dataTables.fixedHeader.js"></script>
        <link  href="{{app.request_context.baseUrl}}/plugins/datatables/extensions/FixedHeader/css/fixedHeader.dataTables.css" rel="stylesheet">

{% endblock %}
{% block footer %}
        
        {{ parent() }}
        <script type="text/javascript" defer>
            {% include (app.twig_theme ~ "/Users/users_list/users_list.js.twig") %}
        </script>

{% endblock %}


{% block content %}
    <div id="iptv_list">
        <div class="row  filters-actions-pannel">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                {% if attribute(app, 'filters_set') is defined %}
                    {% for filter in app.filters_set %}
                        {% if filter.default == '1' %}
                            {% if filter.values_set|length != 0 %}
                                {{ main_macro.get_filter_value_set_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 1) }}
                            {% elseif filter.type == 'STRING' %}
                                {{ main_macro.get_filter_string_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 1) }}
                            {% elseif filter.type == 'DATETIME' %}
                                {{ main_macro.get_filter_datetime_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 1) }}
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                {% endif %}
                <div class="col-sm-2 col-xs-2">
                    {% if attribute(app, 'filters_template') is defined %}
                        {{ main_macros.get_dropdown_attribute(app['filters_template'], 'filter_param', 'Add parametr'|trans, 6, 1, 'true') }}
                    {% endif %}
                </div>
                <a id="add_button" href="{{app.request_context.baseUrl}}/{{app.controller_alias}}/add-users" class="btn btn-action pull-right" {% if not app.resellerUserLimit %}style="display: none;"{% endif %}><i class="fa fa-plus"></i>{{ 'Add user'|trans }}</a>
                <span id="limit_message" class="btn btn-default pull-right" {% if app.resellerUserLimit %}style="display: none;"{% endif %}>{{ 'Limit of number of the users has been reached'|trans }}</span>
                <a id="form_filter_button" href="{{app.request_context.baseUrl}}/{{app.controller_alias}}/save-filter" class="btn btn-success green pull-right no_context_menu" data-filter_set_id="{% if attribute(app, 'filter_set') is defined %}{{ app.filter_set.id }}{% endif %}">{{ 'Save filter'|trans }}</a>
                <a id="apply_filter_button" href="#" class="btn btn-default pull-right no_context_menu">{{ 'Apply filter'|trans }}</a>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" id="filter_block">
                {% if attribute(app, 'filters_set') is defined %}
                    {% for filter in app.filters_set %}
                        {% if filter.default == '0' %}
                            {% if filter.values_set|length != 0 %}
                                {{ main_macro.get_filter_value_set_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 0) }}
                            {% elseif filter.type == 'STRING' %}
                                {{ main_macro.get_filter_string_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 0) }}
                            {% elseif filter.type == 'DATETIME' %}
                                {{ main_macro.get_filter_datetime_input(filter.text_id, filter.title, 'value', 'title', filter.values_set, 0) }}
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                {% endif %}
            </div>
        </div>

        <div class="row">
            <div class="box">
                {% if attribute(app, 'dropdownAttribute') is defined %}
                    {{ main_macro.get_dropdown_attribute(app['dropdownAttribute']) }}
                {% endif %}
                <div class="box-content">
                    <div class="box-content no-padding">
                        <div class="dataTables_processing"></div>
                        <table class="table  table-hover table-datatable" id="datatable-1">
                            {% if attribute(app, 'dropdownAttribute') is defined %}
                                {{ main_macro.get_datatable_head(app['dropdownAttribute']) }}
                            {% endif %}
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="modalbox_ad">
        <div class="devoops-modal">
            <div class="devoops-modal-header">
                <div class="modal-header-name">
                    <span>{{ 'New event'|trans }}</span>
                </div>
                <div class="box-icons">
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
            </div>
            <div class="devoops-modal-inner">
                <div class="box">
                    <div class="box-content">
                        <form class="form-horizontal" role="form">
                            <div class="form-group" style="display: none;">
                                <label class="col-sm-3 control-label col-sm-offset-1">Адресат</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="user_list_type" id="s2_user_list_type">
                                            <option value="to_single" selected="selected">{{ 'Single'|trans }}</option>
                                        </select>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Selecting a destination. Example one, all, on the list, on the template, the group.'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-list-type="by_user_list">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'List of MAC-addresses'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <input type="hidden" name="file_name" id="file_name">
                                    <!-- The file upload form used as target for the file upload widget -->
                                    <div id="fileupload" class="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>{{ 'File'|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">{{ 'The file must contain pre-compiled list of MAC-addresses in the txt extension or another text format'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-list-type="by_group">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Group'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="group_id" id="s2_group_id">
                                            {% for item in app.consoleGroup %}
                                                <option value="{{ item.id }}">{{ item.name }}</option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Select a group of users that will be sent a message'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-list-type="by_pattern">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Template'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="pattern" id="s2_pattern">
                                            <option value="MAG100">MAG100</option>
                                            <option value="MAG200">MAG200</option>
                                            <option value="MAG250">MAG250</option>
                                            <option value="MAG255">MAG255</option>
                                            <option value="MAG256">MAG256</option>
                                            <option value="MAG257">MAG257</option>
                                            <option value="MAG270">MAG270</option>
                                            <option value="MAG275">MAG275</option>
                                            <option value="MAG351">MAG351</option>
                                            <option value="MAG352">MAG352</option>
                                            <option value="AuraHD0">AuraHD0</option>
                                            <option value="AuraHD1">AuraHD1</option>
                                            <option value="AuraHD9">AuraHD9</option>
                                        </select>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Select a template for the type of STB'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-list-type="to_single">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'MAC-address'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-8 col-sm-shifted">
                                        <input class="form-control" type="text" title="" value="{% if attribute(app, 'currentUser') is defined %}{{ app.currentUser.mac }}{% endif %}" name="mac">
                                        <div>&nbsp;</div>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Enter the MAC-address of the user'|trans }}я</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Actions'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" name="event" id="s2_event">
                                            <option value=""></option>
                                            <option value="send_msg">{{ 'Sending a message'|trans }}</option>
                                            <option value="reboot">{{ 'Reboot'|trans }}</option>
                                            <option value="reload_portal">{{ 'Restart the portal'|trans }}</option>
                                            <option value="update_channels">{{ 'Update channel list'|trans }}</option>
                                            <option value="play_channel">{{ 'Playback channel'|trans }}</option>
                                            <option value="play_radio_channel">{{ 'Playback radio channel'|trans }}</option>
                                            <option value="mount_all_storages">{{ 'Mount all storages'|trans }}</option>
                                            <option value="cut_off">{{ 'Switch off'|trans }}</option>
                                            <option value="update_image">{{ 'Image update'|trans }}</option>
                                        </select>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Select one of the actions'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="play_channel;play_radio_channel">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Channel'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-8 col-sm-shifted">
                                        <input class="form-control" type="text" title="" value="" name="channel">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="send_msg">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Restart'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" value="1" name="reboot_after_ok">
                                                <i class="fa fa-square-o small"></i>
                                            </label>
                                        </div>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Restart STB by pressing the "OK"'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label col-sm-offset-1">TTL</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <input class="form-control" type="text" title="" value="" name="ttl" id="ttl">
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                        <span class="small txt-default">{{ 'Term relevance of action, is measured in seconds'|trans }}</span>
                                    </span>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="send_msg">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Message header'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-10">
                                        <input class="form-control" type="text" title="" value="" name="header" id="msg_header">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="send_msg">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Message text'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-10">
                                        <textarea class="form-control" rows="4" title="" value="" name="msg" id="msg_textarea"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="send_msg">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Message templates'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" data-validation=required name="" id="s2_msg_pattern">
                                            <option value="0" data-filter-descriprion=""></option>
                                            {% if attribute(app,'messagesTemplates') is defined and app['messagesTemplates']|length > 0 %}
                                                {% for item in app['messagesTemplates'] %}
                                                    <option value="{{ item['id'] }}" data-template-header="{{ item['header'] }}">{{ item['title'] }}</option>
                                                {% endfor %}
                                            {% endif %}
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="send_msg" id="add_post_function_container">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Add post-function'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" value="1" name="add_post_function" id="add_post_function">
                                                <i class="fa fa-square-o small"></i>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="post_function_type" id="post_function_type">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Post-function'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" data-validation=required name="post_function" id="s2_post_function">
                                            <option value="send_msg_with_video">{{ 'Send message whith video'|trans }}</option>
                                            {#<option value="run_application">{{ 'Run application'|trans }}</option>#}
                                        </select>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-12">
                                    <span class="small txt-default">{{ 'The function to be executed when pressing the "OK" button'|trans }}</span>
                                </span>
                                </div>
                            </div>
                            <div class="form-group" data-event-type="post_function_video_url" id="send_msg_with_video">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'VIDEO URL'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-12">
                                        <input class="form-control" type="text" title="" value="" name="param1">
                                    </div>
                                </div>
                            </div>
                            {#<div class="form-group" data-event-type="post_function_run_application" id="run_application">
                                <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Application'|trans }}</label>
                                <div class="col-xs-10 col-sm-8">
                                    <div class=" col-xs-10 col-sm-6">
                                        <select class="populate placeholder" data-validation=required name="param1" id="s2_applications">
                                            <option value="youtube">{{ 'YouTube'|trans }}</option>
                                            <option value="itv">{{ 'TV'|trans }}</option>
                                            <option value="radio">{{ 'Radio'|trans }}</option>
                                        </select>
                                    </div>
                                </div>
                            </div>#}
                        </form>
                    </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>
        </div>
    </div>
                                    



    {% if attribute(app, 'messagesTemplates') is defined and app.messagesTemplates|length> 0%}
        {% for item in app.messagesTemplates %}
            <script type="text/template" id="msg_textarea_pattern_{{ item.id }}">
                {{ item.body }}
            </script>
        {% endfor %}
    {% endif %}

    <script type="text/template" id="save_filter_template">
        <div class="box-content">
            <form class="form-horizontal" role="form" action="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/save-filter">
                <div class="form-group">
                    <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Filter name'|trans }}</label>
                    <div class="col-xs-10 col-sm-8">
                        <span class="col-xs-12 col-sm-10">
                            <input type="hidden" class="own_fields" name="filter_set[id]" value="">
                            <input type="hidden" class="own_fields" name="filter_set[admin_id]" value="">
                            <input type="hidden" class="own_fields" name="filter_set[filter_set]" value="">
                            <input type="text" class="own_fields form-control" name="filter_set[title]" value="">
                        </span>
                    </div>
                </div>
                <div class="form-group form-group-checkbox">
                    <label class="col-sm-3 control-label col-sm-offset-1">{{ 'For all'|trans }}</label>
                    <div class="col-xs-10 col-sm-8">
                        <span class="col-xs-12 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" class="own_fields" name="filter_set[for_all]">
                                    <i class="fa fa-square-o small"></i>
                                </label>
                            </div>
                        </span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Description'|trans }}</label>
                    <div class="col-xs-10 col-sm-8">
                        <span class="col-xs-12 col-sm-10">
                            <textarea class="own_fields form-control" name="filter_set[description]"></textarea>
                        </span>
                    </div>
                </div>
            </form>
        </div>
    </script>

    {% if attribute(app, 'reseller') is defined and not app['reseller'] %}
    <script type="text/template" id="move_user_to_reseller_template">
        <div class="box-content">
            <form class="form-horizontal" role="form" action="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/move-user-to-reseller">
                <div class="form-group">
                    <label class="col-sm-3 control-label col-sm-offset-1">{{ 'Reseller name'|trans }}</label>
                    <div class="col-xs-10 col-sm-8">
                        <span class="col-xs-12 col-sm-10">
                            <input type="hidden" class="own_fields" name="id" value="">
                            <input type="hidden" class="own_fields" name="source_id" value="">
                            <select class="own_fields" name="target_id" id="target_reseller">
                                {% autoescape false %}
                                    {% if attribute(app, 'allResellers') is defined %}
                                        {% for row in app.allResellers %}
                                            <option value="{{ row.id }}" >{{ row.name ? row.name : '&nbsp;' }}</option>
                                        {% endfor %}
                                    {% endif %}
                                {% endautoescape %}
                            </select>
                        </span>
                    </div>
                </div>
            </form>
        </div>
    </script>
    {% endif %}

    {% if attribute(app, 'enableBilling') is defined and app.enableBilling %}
    <script type="text/template" id="expire_date_template">
        <form class='form-horizontal' role='form' action='{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/set-expire-billing-date'>
            <input type='hidden' class='own_fields' name='setaction' value='set'>
            <input type='hidden' class='own_fields' name='userid' value=''>
            <input type='text' readonly='readonly' class='datepicker col-sm-11 own_fields' style='margin-left: 15px;' data-date-format='dd-mm-yy' name='expire_date' id='expire_date_datepicker'>
        </form>
    </script>
    {% endif %}

    <script type="text/template" id="modal_form_button_template">
        <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>
    </script>

{% endblock %}