[% 
    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>
        <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 == '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.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>
                [% 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" -%]
                        <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 = subscriber.provisioning_voip_subscriber.webpassword, 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 subscriber.provisioning_voip_subscriber.voip_pbx_groups.count;
                                group_subs = subscriber.provisioning_voip_subscriber.voip_pbx_groups.all;
                                group_str = '';
                                FOR group IN group_subs;
                                    group_str = group_str _ group.group.username;
                                    IF !loop.last;
                                        group_str = group_str _ '<br/>';
                                    END;
                                END;
                                elements.push({ value = group_str, desc = c.loc('PBX Groups') });
                            END;
                            IF c.user.roles == "admin" || c.user.roles == "reseller";
                                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;
                            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 %]</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 %]<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('Serial Hunt Timeout') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.pbx_hunt_timeout %]
                            </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 showCallDetails(callId){
    var divId = 'call_details';
    var uri = '[%c.uri_for_action('/subscriber/ajax_call_details', [c.req.captures.0, 'call_id'])%]';
    uri=uri.replace('call_id', callId);
    fetch_into(
        'call_details_container',
        uri,
        '',
        function(){ 
            $('#'+divId).draggable({
                handle: '.modal-header',
                cursor: 'crosshair',
            }).css('display','block').find($('.mod_close')).click(function(event) {
                $('#'+divId).css('display','none');
            });
        }
    );
}
</script>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#subscriber_data" href="#collapse_calls">[% c.loc('Call History') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_calls">
            <div class="accordion-inner">

[%PROCESS 'subscriber/call_details_wrapper.tt' %]  
[%
    helper.name = 'Calls';
    helper.dt_columns = calls_dt_columns;
    helper.column_sort = 'start_time';
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_calls', [c.req.captures.0]);
    helper.show_footer = 1;

    IF (c.user.roles == "admin" || c.user.roles == "reseller");
        IF c.config.features.callflow;
    helper.dt_buttons = [
        { name = c.loc('Call Flow'), uri = "/callflow/'+encodeURIComponent(full.call_id)+'/callmap", class = 'btn-small btn-primary', icon = 'icon-random' },
    ];
        END;
    details_button = { name = c.loc('Call Details'), uri = "javascript:showCallDetails(\\''+encodeURIComponent(full.id)+'\\');void(0);" , class = 'btn-small btn-primary', icon = 'icon-edit' };
    helper.dt_buttons.push( details_button );
    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_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]);

    
    UNLESS (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>


    <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.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 = 'origtime';
    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.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 -%]
    <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)+'/callmap", class = 'btn-small btn-primary', icon = 'icon-random' },
    ];
   

    PROCESS 'helpers/datatables.tt';
%]
            </div>
        </div>
    </div>
[% 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);
    translate_form(form).render;
    modal_footer();
    modal_script(m.close_target = close_target);
-%]
[% END -%]


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