[%
    IF subscriber.provisioning_voip_subscriber.is_pbx_group;
        site_config.title = c.loc('PBX Group [_1]@[_2]', subscriber.username, subscriber.domain.domain);
    ELSE;
        site_config.title = c.loc('Subscriber [_1]@[_2]', subscriber.username, subscriber.domain.domain);
    END;
-%]


<div class="row">
    <span class="pull-left" style="margin:0 5px 0 5px;">
        <a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
        <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/subscriber/preferences', [ subscriber.id ]) %]"><i class="icon-list"></i> [% c.loc('Preferences') %]</a>
        [% IF c.user.roles != "ccareadmin" && c.user.roles != "ccare" -%]
        <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/subscriber/calllist', [subscriber.id]) %]"><i class="icon-list"></i> [% c.loc('Calls history') %]</a>
        [% END -%]
        <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/customer/details', [ subscriber.contract_id ]) %]"><i class="icon-user"></i> [% c.loc('Customer') %]</a>
    </span>
</div>
[% back_created = 1 -%]

<div class="row">
    [% FOREACH m IN messages -%]
        <div class="alert alert-[% m.type %]">[% m.text %]</div>
    [% END -%]
    [% IF subscriber && subscriber.status != "active" -%]
        <div class="alert">[% c.loc('Subscriber status is <b>[_1]</b>', subscriber.status) %]</div>
    [% END -%]
    [% IF prov_lock_string && prov_lock_string != "none" -%]
        <div class="alert">[% c.loc('Subscriber is locked for <b>[_1]</b>', prov_lock_string) %]</div>
    [% END -%]
</div>

<div class="ngcp-separator"></div>

<div class="accordion" id="subscriber_data">
    [% IF c.user.roles == 'admin' || c.user.roles == 'reseller' ||
          c.user.roles == 'ccareadmin' || c.user.roles == 'ccare' ||
          c.user.roles == 'subscriberadmin' -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_master">[% c.loc('Master Data') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_master">
            <div class="accordion-inner">

                [% UNLESS (c.user.roles == "admin" || c.user.roles == "reseller" ||
                           c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only -%]
                    [%
                        IF subscriber.provisioning_voip_subscriber.is_pbx_group;
                            href = c.uri_for_action('/customer/pbx_group_edit', [ contract.id, subscriber.id ]);
                        ELSE;
                            href = c.uri_for_action('/subscriber/edit_master', [ subscriber.id ]);
                        END;
                    -%]
                    <a class="btn btn-primary btn-large" href="[% href %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                    [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                           c.user.roles == "ccareadmin" || c.user.roles == "ccare") -%]
                        [% IF c.config.general.csc_js_enable == 0 || c.config.general.csc_js_enable == 2 -%]
                            <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/subscriber/login_to_csc', [ subscriber.id ]) %]" target="_blank"><i class="icon-user"></i> [% c.loc('Login to CSC') %]</a>
                        [% END -%]
                        [% IF c.config.general.csc_js_enable == 1 || c.config.general.csc_js_enable == 2 -%]
                            <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/subscriber/login_to_csc_v2', [ subscriber.id ]) %]" target="_blank"><i class="icon-user"></i> [% c.loc('Login to New CSC') %]</a>
                        [% END -%]
                    [% END -%]
                [% END -%]
                [% IF subscriber.contract.passreset_email_template -%]
                    <a class="btn btn-secondary btn-large" href="[% c.uri_for_action('/subscriber/reset_webpassword', [subscriber.id]) %]" data-confirm="Reset"><i class="icon-repeat"></i> [% c.loc('Reset Web Password') %]</a>
                [% END -%]

                <div class="ngcp-separator"></div>

                <table class="table table-bordered table-striped table-highlight table-hover" id="subscribers_table">
                    <thead>
                        <tr>
                            <th>[% c.loc('Setting') %]</th>
                            <th>[% c.loc('Values') %]</th>
                        </tr>
                    </thead>
                    <tbody>
                        [% IF c.user.roles == "admin" || c.user.roles == "reseller"  || c.user.roles == "ccareadmin" || c.user.roles == "ccare" -%]
                        <tr class="sw_action_row">
                            <td>[% c.loc('Customer #') %]</td>
                            <td>[% subscriber.contract.id %]</td>
                        </tr>
                        [% END -%]
                        [%
                            elements = [];

                            elements.push({ value = subscriber.status, desc = c.loc('Status') });
                            IF subscriber.contact;
                                elements.push({ value = subscriber.contact.email, desc = c.loc('Email Address') });
                            END;
                            elements.push({ value = subscriber.provisioning_voip_subscriber.webusername, desc = c.loc('Web Username') });
                            IF (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.show_passwords;
                                elements.push({ value = '******', desc = c.loc('Web Password') });
                            END;
                            elements.push({ value = subscriber.username _ '@' _ subscriber.domain.domain, desc = c.loc('SIP URI') });
                            IF (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.show_passwords;
                                elements.push({ value = subscriber.provisioning_voip_subscriber.password, desc = c.loc('SIP Password') });
                            END;
                            IF c.user.roles == "admin" || c.user.roles == "reseller" || c.user.roles == "ccareadmin" || c.user.roles == "ccare";
                                elements.push({ value = subscriber.provisioning_voip_subscriber.admin ? 'yes' : 'no', desc = c.loc('Administrative') });
                                elements.push({ value = subscriber.external_id, desc = c.loc('External #')});
                                elements.push({ value = subscriber.uuid, desc = c.loc('UUID') });
                            END;
                            IF subscriber.timezone.name;
                                elements.push({ value = subscriber.timezone.name, desc = c.loc('Timezone') });
                            ELSE;
                                elements.push({ value = c.config.contact.timezone, desc = c.loc('Timezone') });
                            END;
                            elements.push({ value = subscriber.primary_number.cc _ ' ' _ subscriber.primary_number.ac _ ' ' _ subscriber.primary_number.sn, desc = c.loc('Primary Number') });

                        -%]
                        [% FOR elem IN elements -%]
                            <tr>
                                <td>[% elem.desc %]</td>
                                <td>[% elem.value | html %]</td>
                            </tr>
                        [% END -%]
                        <tr>
                            <td>[% c.loc('Alias Numbers') %]</td>
                            <td>
                                [% FOR num IN subscriber.voip_numbers.all -%]
                                    [% NEXT IF num.id == subscriber.primary_number.id -%]
                                    [% num.cc %] [% num.ac %] [% num.sn %] [% IF num.voip_dbalias.is_devid %]<span class="icon-phone"></span>[% END %]<br/>
                                [% END -%]
                            </td>
                        </tr>
                        [% IF subscriber.provisioning_voip_subscriber.pbx_extension -%]
                        <tr>
                            <td>[% c.loc('Extension') %]</td>
                            <td>[% subscriber.provisioning_voip_subscriber.pbx_extension %]</td>
                        </tr>
                        [% END -%]
                        [% UNLESS subscriber.provisioning_voip_subscriber.is_pbx_group -%]
                        <tr>
                            <td>[% c.loc('Subscriber Profile Set') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voip_subscriber_profile_set.name %]
                            </td>
                        </tr>
                        <tr>
                            <td>[% c.loc('Subscriber Profile') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voip_subscriber_profile.name %]
                            </td>
                        </tr>
                        [% END -%]
                        [% IF subscriber.provisioning_voip_subscriber.is_pbx_group -%]
                        <tr>
                            <td>[% c.loc('Hunt Policy') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.pbx_hunt_policy %]
                            </td>
                        </tr>
                        <tr>
                            <td>[% c.loc('Hunt Timeout') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.pbx_hunt_timeout %]
                            </td>
                        </tr>
                        <tr>
                            <td>[% c.loc('Cancel Mode') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.pbx_hunt_cancel_mode %]
                            </td>
                        </tr>
                        [% END -%]
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    [% END -%]

    [% IF
        ((c.user.roles == 'admin' || c.user.roles == 'reseller') && c.user.call_data) ||
        c.user.roles == 'subscriberadmin'
    -%]


<script type="text/javascript" src="/js/background.js"></script>
<script>
function process_pbx_items(moveId,direction){
    var uri = '[%c.uri_for_action('/subscriber/order_pbx_items', [subscriber.id], 'move'=> 'moveId', 'where' => 'direction')%]';
    uri=uri.replace('moveId', moveId);
    uri=uri.replace('direction', direction);
    fetch_into(
        'pbx_group_items',
        uri,
        '',
        function(){
            mainWrapperInit();
        }
    );
}
</script>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_pbx_group_items">[%IF subscriber.provisioning_voip_subscriber.is_pbx_group; c.loc('Group members'); ELSE; c.loc('Groups'); END%]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_pbx_group_items">
            <div class="accordion-inner" id="pbx_group_items">
[%PROCESS 'subscriber/pbx_group_items.tt' %]
            </div>
        </div>
    </div>

    [% END -%]


    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_voicemail">[% c.loc('Voice Mails') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_voicemail">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Voicemails');
    helper.identifier = 'voicemails';
    helper.column_sort = 'origtime';
    helper.dt_columns = vm_dt_columns;

    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_voicemails', [c.req.captures.0]);


    IF (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.read_only;
    helper.dt_buttons = [
        { name = c.loc('Play'), uri = "details/voicemail/'+full.id+'/play", class = 'btn-small btn-tertiary', icon = 'icon-play' },
    ];
    ELSE;
    helper.dt_buttons = [
        { name = c.loc('Play'), uri = "details/voicemail/'+full.id+'/play", class = 'btn-small btn-tertiary', icon = 'icon-play' },
        { name = c.loc('Delete'), uri = "details/voicemail/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
    ];
    END;


    PROCESS 'helpers/datatables.tt';
%]
            </div>
        </div>
    </div>

[% IF c.user.roles != "ccareadmin" && c.user.roles != "ccare" -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_recordings">[% c.loc('Call Recordings') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_recordings">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Call Recordings');
    helper.identifier = 'recordings';
    helper.column_sort = 'id';
    helper.dt_columns = rec_dt_columns;

    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_recordings', [c.req.captures.0]);


    IF ((c.user.roles == "admin" || c.user.roles == "reseller") && !c.user.read_only) || c.user.roles == "subscriber" || c.user.roles == "subscriberadmin";
    helper.dt_buttons = [
        { name = c.loc('Call Details'), uri = "/subscriber/" _ subscriber.id _ "/calls?callid=' + encodeURIComponent(full.call_id_url) + '", class = 'btn-small btn-tertiary', icon = 'icon-search' },
        { name = c.loc('Recorded Files'), uri = "details/recording/'+full.id+'/streams", class = 'btn-small btn-tertiary', icon = 'icon-play' },
#we will confirm deletion in the form
        { name = c.loc('Delete recording'), uri = "details/recording/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
    ];
    ELSE;
    helper.dt_buttons = [
        { name = c.loc('Call Details'), uri = "/subscriber/" _ subscriber.id _ "/calls?callid=' + encodeURIComponent(full.call_id_url) + '", class = 'btn-small btn-tertiary', icon = 'icon-search' },
        { name = c.loc('Files'), uri = "details/recording/'+full.id+'/streams", class = 'btn-small btn-tertiary', icon = 'icon-play' },
    ];
    END;


    PROCESS 'helpers/datatables.tt';
%]
            </div>
        </div>
    </div>
[% END -%]




    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_regdev">[% c.loc('Registered Devices') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_regdev">
            <div class="accordion-inner">

            [% UNLESS (c.user.roles == "admin" || c.user.roles == "reseller" ||
                       c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only -%]
            <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action('/subscriber/create_registered', [c.req.captures.0]) %]"><i class="icon-star"></i> [% c.loc('Create Permanent Registration') %]</a>
            [% END -%]
[%
    helper.name = c.loc('Registered Devices');
    helper.identifier = 'registered_devices';
    helper.column_sort = 'q';
    helper.column_sort_order = 'desc';

    helper.dt_columns = reg_dt_columns;

    helper.close_target = close_target;
    helper.create_flag = reg_create_flag;
    helper.edit_flag = reg_edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_registered', [c.req.captures.0]);

    UNLESS (c.user.roles == "admin" || c.user.roles == "reseller" ||
            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only;
    helper.dt_buttons = [
        { name = c.loc('Delete'), uri = "details/registered/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
    ];
    END;


    PROCESS 'helpers/datatables.tt';
%]
            </div>
        </div>
    </div>

[% IF c.config.features.callflow && c.user.call_data && c.user.roles != "ccareadmin" && c.user.roles != "ccare" -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_cap">[% c.loc('Captured Dialogs') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_cap">
            <div class="accordion-inner">

[%
    helper.name = c.loc('Captured Dialogs');
    helper.identifier = 'captured_dialogs';
    #helper.column_sort = 'origtime';
    helper.dt_columns = capture_dt_columns;

    helper.close_target = close_target;
    helper.create_flag = 0;
    helper.edit_flag = 0;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_captured_calls', [c.req.captures.0]);

    helper.dt_buttons = [
        { name = c.loc('Call Flow'), uri = "callflow/'+encodeURIComponent(full.call_id_url)+'/callmap", class = 'btn-small btn-primary', icon = 'icon-random' },
    ];


    PROCESS 'helpers/datatables.tt';
%]
            </div>
        </div>
    </div>
[% END -%]

    [% IF c.config.general.ngcp_type != 'spce' -%]
    [% IF c.license('phonebook') -%]
    [% IF (c.user.roles == "subscriberadmin" && product.class == "pbxaccount") ||
           c.user.roles == "admin" || c.user.roles == "reseller" || c.user.roles == "ccareadmin" || c.user.roles == "ccare" -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_phonebook">[% c.loc('Phonebook') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_phonebook">
            <div class="accordion-inner">

[%
    helper.name = c.loc('Phonebook');
    helper.identifier = 'phonebook';
    helper.create_flag = phonebook_create_flag;
    helper.edit_flag = phonebook_edit_flag;
    helper.form_object = form;
    helper.messages = messages;
    helper.length_change = 1;
    helper.dt_columns = phonebook_dt_columns;
    helper.ajax_uri = c.uri_for_action('/subscriber/phonebook_ajax', [ c.req.captures.0 ]);
    helper.tmpuri = c.uri_for_action('/subscriber/phonebook_root', [ c.req.captures.0 ]);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = helper.tmpuri _ "/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = helper.tmpuri _ "/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-remove' },
        ];
        helper.top_buttons = [
            { name = c.loc('Create Phonebook Entry'), uri = c.uri_for_action('/subscriber/phonebook_create', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
            { name = c.loc('Download CSV'), uri = c.uri_for_action('/subscriber/phonebook_download_csv', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
            { name = c.loc('Upload CSV'), uri = c.uri_for_action('/subscriber/phonebook_upload_csv', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
%]

            </div>
        </div>
    </div>
    [% END -%]
    [% END -%]
    [% END -%]

</div>

[% IF edit_flag == 1 -%]
<!-- edit master data -->
[%
    IF form.has_for_js;
        form.render_repeatable_js;
    END;
    PROCESS "helpers/modal.tt";
    modal_header(m.create_flag=0,
                 m.name = description);
    form.render;
    modal_footer();
    modal_script(m.close_target = close_target);
-%]

<script src="/js/libs/ngcp-pwdgen.js"></script>
[% END -%]


[% # vim: set tabstop=4 syntax=html expandtab: -%]
