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

[%
    helper.name = c.loc('Subscriber');
    helper.messages = messages;

    helper.edit_preference = edit_preference;
    helper.preference = preference;
    helper.preference_meta = preference_meta;
    helper.preference_values = preference_values;
    helper.pref_groups = pref_groups;
    helper.form = form;
    helper.base_uri = c.uri_for(subscriber.id,'preferences');
    helper.rewrite_rule_sets = rwr_sets;
    helper.header_rule_sets = hdr_sets;
    helper.ncos_sets = ncos_sets;
    helper.ncos_levels = ncos_levels;
    helper.emergency_mapping_containers = emergency_mapping_containers;
    helper.sound_sets = sound_sets;
    helper.contract_sound_sets = contract_sound_sets;
    helper.aip_grp_rs = aip_grp_rs;
    helper.man_aip_grp_rs = man_aip_grp_rs;
    helper.skip_head = 1;

    PROCESS "helpers/modal.tt";
%]

<div class="row">
    <span>
    <a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
    </span>
</div>
[% back_created = 1 %]

[% IF helper.messages -%]
<div class="row">
    [% FOREACH m IN helper.messages -%]
        <div class="alert alert-[% m.type %]">[% m.text %]</div>
    [% END -%]
</div>
[% END -%]

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

<div class="accordion" id="preference_groups">


    [% IF
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.callforward.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        c.user.roles == "admin" || c.user.roles == "reseller" ||
        c.user.roles == "ccareadmin" || c.user.roles == "ccare" -%]

<script>
function destinationDynamicFields(selectedValue, inputNumber){
    if($.isNumeric( inputNumber )){
      inputNumber = inputNumber.toString();
    }else if(!inputNumber){
      inputNumber = '';
    }
    var name = inputNumber + '.announcement_id';
    $(":input[name$='" + name + "']").closest('.ngcp-destination').css("display","none");
    $(":input[name$='" + name + "']").closest('.ngcp-destination-' + selectedValue ).css("display","block");
}
function inputNumberFromName(name){
    var inputNumber = name;
    var inputNumbers = inputNumber.match(/\.(\d+)\./);
    if(inputNumbers){
      inputNumber = inputNumbers[1];
    }else{
      inputNumber = '';
    }
    return inputNumber;
}

$( document ).ready(function() {
    $("input:radio[name$='.destination']:checked").each(function(index, item){
      destinationDynamicFields( $(this).val(), inputNumberFromName($(this).attr('name')) );
    });
    $("input:radio[name$='.destination']").on('click',function(){
      destinationDynamicFields($(this).val(), inputNumberFromName($(this).attr('name')) );
    });
    $('.controls').on('click','input:radio',function(){
      if($(this).attr("checked")){
        destinationDynamicFields($(this).val(), inputNumberFromName($(this).attr('name')) );
      }
    });
});

</script>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_cf">[% c.loc('Call Forwards') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_cf">
            <div class="accordion-inner">

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_cf">
                    <thead>
                        <tr>
                            <th>[% c.loc('Type') %]</th>
                            <th>[% c.loc('Answer Timeout') %]</th>
                            <th>[% c.loc('Timeset') %]</th>
                            <th>[% c.loc('Sources') %]</th>
                            <th>[% c.loc('To (B-Numbers)') %]</th>
                            <th>[% c.loc('New Destinations') %]</th>
                            <th>[% c.loc('Enabled') %]</th>
                            <th>[% c.loc('PSTN 302 Redirection') %]</th>

                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                    [% FOR cf IN [ { type = "cfu", desc = c.loc("Call Forward Unconditional") },
                                   { type = "cfb", desc = c.loc("Call Forward Busy") },
                                   { type = "cft", desc = c.loc("Call Forward Timeout") },
                                   { type = "cfna", desc = c.loc("Call Forward Unavailable") },
                                   { type = "cfs", desc = c.loc("Call Forward SMS") },
                                   { type = "cfr", desc = c.loc("Call Forward on Response") },
                                   { type = "cfo", desc = c.loc("Call Forward on Overflow") } ] -%]
                        [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" -%]
                          [% NEXT IF special_prefs.check && !special_prefs.callforward.${cf.type} -%]
                        [% END -%]
                        <tr class="sw_action_row">
                            <td>[% cf.desc %]</td> <!--- Type -->
                            <td> <!--- Answer Timeout (only cft) -->
                                [% cf_ringtimeout _ 's' IF cf.type == "cft" && cf_destinations.${cf.type}.size && cf_ringtimeout.defined %]
                            </td>
                            <td> <!--- Timeset -->
                                [% idx = 0 -%]
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% jdx = 0 -%]
                                    [% UNLESS maps.tset_name.defined -%]
                                        always
                                        [% jdx = jdx + 1 %]
                                    [% ELSE -%]
                                        [% escaped_tset_name = maps.tset_name | html -%]
                                        [% escaped_tset_name -%]
                                        [% tset_unique_id = cf.type _ idx _ jdx _ maps.id -%]
                                        <a href="#" data-toggle="modal" data-target="#[% tset_unique_id %]" class="pull-right"><i class="icon-question-sign"></i></a>
                                        [% modal_header_dynamic(m.header = c.loc('Timeset "[_1]" Details', escaped_tset_name), m.id=tset_unique_id) %]
                                        <div class="modal-body">
                                        [% FOR p IN maps.periods -%]
                                            [% p.as_string | html %]<br/>
                                        [% END -%]
                                        </div>
                                        [% modal_footer() %]
                                    [% END %]
                                    [% idx = idx + 1 -%]
                                    <br/>
                                [% END -%]
                            </td>
                            <td> <!--- Sources -->
                                [% idx = 0 -%]
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% jdx = 0 -%]
                                    [% UNLESS maps.sset_name.defined -%]
                                        <!-- empty or no source_set -->
                                        [% c.loc('all sources'); %]
                                        [% jdx = jdx + 1 %]
                                    [% ELSE -%]
                                        [% maps.sset_name | html -%] ([% maps.sset_mode -%])
                                        [% sset_unique_id = cf.type _ idx _ jdx _ maps.id _ 's' -%]
                                        <a href="#" data-toggle="modal" data-target="#[% sset_unique_id %]" class="pull-right"><i class="icon-question-sign"></i></a>
                                        [% modal_header_dynamic(m.header = c.loc('Sourceset "[_1]" Details', maps.sset_name), m.id=sset_unique_id) %]
                                        <div class="modal-body">
                                        [% FOR s IN maps.sources -%]
                                            [% s.as_string | html %]<br/>
                                        [% END -%]
                                        </div>
                                        [% modal_footer() %]
                                    [% END %]
                                    [% idx = idx + 1 -%]
                                    <br/>
                                [% END -%]
                            </td>
                            <td> <!--- B Number (To) -->

                                [% idx = 0 -%]
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% jdx = 0 -%]
                                    [% UNLESS maps.bset_name.defined -%]
                                        <!-- empty or no bnumber_set -->
                                        [% c.loc('any number'); %]
                                        [% jdx = jdx + 1 %]
                                    [% ELSE -%]
                                        [% escaped_bset_name = maps.bset_name | html -%]
                                        [% escaped_bset_name -%] ([% maps.bset_mode -%])
                                        [% bset_unique_id = cf.type _ idx _ '-' _ jdx _ '-' _ maps.id _ 'b' -%]
                                        <a href="#" data-toggle="modal" data-target="#[% bset_unique_id %]" class="pull-right"><i class="icon-question-sign"></i></a>
                                        [% modal_header_dynamic(m.header = c.loc('B-Number Set "[_1]" Details', escaped_bset_name), m.id=bset_unique_id) %]
                                        <div class="modal-body">
                                        [% FOR s IN maps.bnumbers -%]
                                            [% s.as_string | html %]<br/>
                                        [% END -%]
                                        </div>
                                        [% modal_footer() %]
                                    [% END %]
                                    [% idx = idx + 1 -%]
                                    <br/>
                                [% END -%]

                            </td>
                            <td> <!--- New Destinations (C-Number) -->
                                [% BLOCK print_destination;
                                    escaped_dest = d.as_string | html;
                                    c.loc('[_1] for [_2]s', escaped_dest _' <span class="pull-right">', d.timeout) _ '</span>';
                                END; -%]
                                [% idx = 0 -%]
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% IF maps.dset_name.search('^quickset_') && maps.destinations.size == 1 %]
                                        [% PROCESS print_destination d=maps.destinations.0; -%]
                                    [% ELSE %]
                                        [% jdx = 0 -%]
                                        [% escaped_dset_name = maps.dset_name | html -%]
                                        [% escaped_dset_name -%]

                                        [% dset_unique_id = cf.type _ "dset" _ idx _ jdx _ maps.id -%]
                                        <a href="#" data-toggle="modal" data-target="#[% dset_unique_id %]" class="pull-right"><i class="icon-question-sign"></i></a>
                                        [% modal_header_dynamic(m.header = c.loc('Destination Set "[_1]" Details', escaped_dset_name), m.id=dset_unique_id) %]
                                        <div class="modal-body">
                                            [% FOR d IN maps.destinations -%]
                                                [% PROCESS print_destination d=d; %]<br/>
                                                [% jdx = jdx + 1 -%]
                                            [% END -%]
                                        </div>
                                        [% modal_footer() %]

                                        [% idx = idx + 1 -%]
                                    [% END %]
                                    <br/>
                                [% END -%]
                            </td>
                            <td>
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% maps.enabled %]
                                    <br/>
                                [% END -%]
                            </td>
                            <td>
                                [% FOR maps IN cf_destinations.${cf.type} -%]
                                    [% maps.use_redirection %]
                                    <br/>
                                [% END -%]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% 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-primary btn-small" href="[% c.uri_for_action("/subscriber/preferences_callforward", [c.req.captures.0], cf.type) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% IF cf_destinations.${cf.type}.size -%]
                                    <a class="btn btn-secondary btn-small" data-confirm="Delete" href="[% c.uri_for_action("/subscriber/preferences_callforward_delete", [c.req.captures.0], cf.type) %]"><i class="icon-trash"></i> [% c.loc('Delete') %]</a>
                                    [% END -%]
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                    [% END -%]
                    </tbody>
                </table>

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

    [% IF
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.voice_mail.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        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="#preference_groups" href="#collapse_vm">[% c.loc('Voicemail and Voicebox') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_vm">
            <div class="accordion-inner">

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_vm">
                    <thead>
                        <tr>
                            <th>[% c.loc('Name') %]</th>
                            <th>[% c.loc('Value') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="sw_action_row">
                            <td>[% c.loc('PIN') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voicemail_user.password | html %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                         ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                           c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'pin') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Email') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voicemail_user.email | html %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'email') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Delete after sending Email') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voicemail_user.get_column('delete') %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]

                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'delete') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Attach WAV in Email') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voicemail_user.attach %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'attach') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        [% IF c.config.features.sms -%]
                        <tr class="sw_action_row">
                            <td>[% c.loc('SMS Number') %]</td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voicemail_user.pager | html %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'pager') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        [% END -%]
                        [% FOREACH  vm_recording_type IN vm_recordings_types -%]
                        <tr class="sw_action_row">
                            <td>[% c.loc('Voicemail greeting ') %] "[%vm_recording_type.type%]"</td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                [% IF  vm_recording_type.greeting_exists %]
                                <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'voicemailgreeting', 'download', vm_recording_type.type  ) %]"><i class="icon-edit"></i> [% c.loc('Download') %]</a>
                                [%END%]
                            </div>
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    [% IF  vm_recording_type.greeting_exists %]
                                    <a class="btn btn-secondary btn-small" data-confirm="Delete" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'voicemailgreeting','delete', vm_recording_type.type ) %]">
                                        <i class="icon-trash"></i> [% c.loc('Delete') %]
                                    [% END %]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_voicebox", [c.req.captures.0], 'voicemailgreeting','edit', vm_recording_type.type ) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        [% END -%]



                    </tbody>
                </table>

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

    [% IF c.license('fax') && c.config.features.faxserver  && (
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.fax_server.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        c.user.roles == "admin" || c.user.roles == "reseller" ||
        c.user.roles == "ccareadmin" || c.user.roles == "ccare"
    ) -%]
    <div class="accordion-group" id="fax_features">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_fax">[% c.loc('Fax Features') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_fax">
            <div class="accordion-inner">
                <!-- fax2mail and sendfax -->
                <h4>[% c.loc('Fax2Mail and Sendfax') %]</h4>
                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_fax">
                    <thead>
                        <tr>
                            <th>[% c.loc('Name') %]</th>
                            <th>[% c.loc('Value') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        [%
                            faxpref = subscriber.provisioning_voip_subscriber.voip_fax_preference;
                            faxdests = subscriber.provisioning_voip_subscriber.voip_fax_destinations.all;
                        -%]
                        <tr class="sw_action_row">
                            <td>[% c.loc('Name in Fax Header for Sendfax') %]</td>
                            <td>
                                [% faxpref.name | html %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'name') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Active') %]</td>
                            <td>
                                [% faxpref.active ? c.loc('yes') : c.loc('no') %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'active') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Destinations') %]</td>
                            <td>
                                [% FOR faxdest IN faxdests -%]
                                    [% FILTER html -%]
                                    [% c.loc('[_1] as [_2]', faxdest.destination, faxdest.filetype) %]<br/>
                                    [% END -%]
                                [% END -%]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'destinations') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('T38') %]</td>
                            <td>
                                [% faxpref.t38 ? c.loc('yes') : c.loc('no') %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 't38') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('ECM') %]</td>
                            <td>
                                [% faxpref.ecm ? c.loc('yes') : c.loc('no') %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_fax", [c.req.captures.0], 'ecm') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                    </tbody>
                </table>
                <!-- mail2fax -->
                <h4>[% c.loc('Mail2Fax') %]</h4>
                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_mail_to_fax">
                    <thead>
                        <tr>
                            <th>[% c.loc('Name') %]</th>
                            <th>[% c.loc('Value') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        [%
                            mtf_pref = subscriber.provisioning_voip_subscriber.voip_mail_to_fax_preference;
                            mtf_secret_renew_notify = subscriber.provisioning_voip_subscriber.voip_mail_to_fax_secrets_renew_notify.all;
                            mtf_acl = subscriber.provisioning_voip_subscriber.voip_mail_to_fax_acls.all;
                        -%]
                        <tr class="sw_action_row">
                            <td>[% c.loc('Active') %]</td>
                            <td>
                                [% mtf_pref.active ? c.loc('yes') : c.loc('no') %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_mail_to_fax", [c.req.captures.0], 'active') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Secret Key (empty=disabled)') %]</td>
                            <td>
                                [% mtf_pref.secret_key | html %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_mail_to_fax", [c.req.captures.0], 'secret_key') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Secret Key Renew') %]</td>
                            <td>
                                [% c.loc("[_1]", mtf_pref.secret_key_renew) %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_mail_to_fax", [c.req.captures.0], 'secret_key_renew') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Last Secret Key Modify Time') %]</td>
                            <td>
                                [% mtf_pref.last_secret_key_modify %]
                            </td>
                            <td class="ngcp-actions-column">
                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('Secret Key Renew Notify') %]</td>
                            <td>
                                [% FOR notify_email IN mtf_secret_renew_notify -%]
                                    [% notify_email.destination | html %]<br/>
                                [% END -%]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_mail_to_fax", [c.req.captures.0], 'secret_renew_notify') %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        <tr class="sw_action_row">
                            <td>[% c.loc('ACL') %]</td>
                            <td>
                                [% FOR acl IN mtf_acl -%]
                                    [% acl.use_regex ? c.loc('regex') : '' %]  [% c.loc('from_email') | html %]  <u>[% acl.from_email ? acl.from_email : c.loc('any') | html %]</u>  [% c.loc('and') %]  [% c.loc('received_from') | html %]  <u>[% acl.received_from ? acl.received_from : c.loc('any') | html %]</u>  [% c.loc('to') | html %]  <u>[% acl.destination ? acl.destination : c.loc('any') | html %]</u>  [% c.loc('destination') | html %]<br/>
                                [% END -%]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_mail_to_fax", [c.req.captures.0], 'acl') %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    [% END -%]
    [% IF c.license('pbx') && c.config.features.cloudpbx && subscriber.contract.product.class == 'pbxaccount' && (
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.auto_attendant.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        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="#preference_groups" href="#collapse_aa">[% c.loc('Auto Attendant Slots') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_aa">
            <div class="accordion-inner">

                [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                      ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                        c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action('/subscriber/edit_autoattendant', [c.req.captures.0]) %]">
                    <i class="icon-star"></i> [% c.loc('Edit Slots') %]
                </a>
                [% END -%]
[%
    helper.messages = '';
    helper.name = c.loc('Autoattendant');
    helper.identifier = 'autoattendant';
    helper.column_sort = 'choice';
    helper.dt_columns = aa_dt_columns;
    helper.length_change = 1;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_autoattendant', [c.req.captures.0]);

    helper.top_buttons = [];
    helper.dt_buttons = [];

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Delete'), uri = "preferences/autoattendant/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
        ];
    END;

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

    [% IF
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.speed_dial.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        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="#preference_groups" href="#collapse_speed">[% c.loc('Speed Dial') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_speed">
            <div class="accordion-inner">

                [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                      ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                        c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action('/subscriber/create_speeddial', [c.req.captures.0]) %]"><i class="icon-star"></i> [% c.loc('Create Slot') %]</a>
                [% END -%]
[%
    helper.messages = '';
    helper.name = c.loc('Speeddial');
    helper.identifier = 'subs_speeddial';
    helper.column_sort = 'slot';
    helper.dt_columns = sd_dt_columns;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_speeddial', [c.req.captures.0]);

    helper.top_buttons = [];
    helper.dt_buttons = [];

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "preferences/speeddial/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = "preferences/speeddial/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
        ];
    END;

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

    [% IF
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && special_prefs.check && special_prefs.reminder.active) ||
        ((c.user.roles == "subscriber" || c.user.roles == "subscriberadmin") && !special_prefs.check) ||
        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="#preference_groups" href="#collapse_rm">[% c.loc('Reminder') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_rm">
            <div class="accordion-inner">

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_rm">
                    <thead>
                        <tr>
                            <th>[% c.loc('Time') %]</th>
                            <th>[% c.loc('Recurrence') %]</th>
                            <th>[% c.loc('Active') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="sw_action_row">
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voip_reminder.get_column('time') %]
                            </td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voip_reminder.recur %]
                            </td>
                            <td>
                                [% subscriber.provisioning_voip_subscriber.voip_reminder.active %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                                          ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_reminder", [c.req.captures.0]) %]">
                                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                                    </a>
                                    [% IF subscriber.provisioning_voip_subscriber.voip_reminder -%]
                                    <a class="btn btn-secondary btn-small" data-confirm="Delete" href="[% c.uri_for_action("/subscriber/delete_reminder", [c.req.captures.0]) %]">
                                        <i class="icon-trash"></i> [% c.loc('Delete') %]
                                    </a>
                                    [% END -%]
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                    </tbody>
                </table>

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

    [% IF c.config.features.callingcard && (
        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="#preference_groups" href="#collapse_ccmap">[% c.loc('Callthrough CLIs') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_ccmap">
            <div class="accordion-inner">

                [% IF c.user.roles == "subscriber" || c.user.roles == "subscriberadmin" ||
                      ((c.user.roles == "admin" || c.user.roles == "reseller" ||
                        c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1) -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action('/subscriber/edit_ccmapping', [c.req.captures.0]) %]">
                    <i class="icon-star"></i> [% c.loc('Edit Callthrough CLIs') %]
                </a>
                [% END -%]
[%
    helper.messages = '';
    helper.name = c.loc('foobar');
    helper.identifier = 'ccmapentries';
    helper.column_sort = undef;
    helper.dt_columns = ccmap_dt_columns;
    helper.length_change = 1;
    helper.ajax_uri = c.uri_for_action('/subscriber/ajax_ccmappings', [c.req.captures.0]);

    helper.top_buttons = [];
    helper.dt_buttons = [];

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Delete'), uri = "/subscriber/"_ c.req.captures.0 _"/preferences/ccmappings/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
        ];
    END;

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


[% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_ts">[% c.loc('Trusted Sources') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_ts">
            <div class="accordion-inner">

                [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                       c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action("/subscriber/create_trusted", [c.req.captures.0]) %]">
                    <i class="icon-star"></i> [% c.loc('Create') %]
                </a>
                [% END -%]
                <div class="ngcp-separator"></div>

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_ts">
                    <thead>
                        <tr>
                            <th>[% c.loc('Source IP') %]</th>
                            <th>[% c.loc('Protocol') %]</th>
                            <th>[% c.loc('From-Pattern') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        [% FOR trusted IN subscriber.provisioning_voip_subscriber.voip_trusted_sources.all -%]
                        <tr class="sw_action_row">
                            <td>
                                [% trusted.src_ip %]
                            </td>
                            <td>
                                [% trusted.protocol %]
                            </td>
                            <td>
                                [% trusted.from_pattern %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_trusted", [c.req.captures.0, trusted.id]) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    <a class="btn btn-secondary btn-small" href="[% c.uri_for_action("/subscriber/delete_trusted", [c.req.captures.0, trusted.id]) %]" data-confirm="Delete"><i class="icon-trash"></i> [% c.loc('Delete') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        [% END %]
                    </tbody>
                </table>

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

[% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_upnr">[% c.loc('UPN Rewrite') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_upnr">
            <div class="accordion-inner">

                [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                       c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action("/subscriber/create_upn_rewrite", [c.req.captures.0]) %]">
                    <i class="icon-star"></i> [% c.loc('Create') %]
                </a>
                [% END -%]
                <div class="ngcp-separator"></div>

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_upnr">
                    <thead>
                        <tr>
                            <th>[% c.loc('#') %]</th>
                            <th>[% c.loc('New CLI') %]</th>
                            <th>[% c.loc('Patterns') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        [% FOR set IN upn_rw_sets -%]
                        <tr class="sw_action_row">
                            <td>
                                [% set.id %]
                            </td>
                            <td>
                                [% set.new_cli %]
                            </td>
                            <td>
                                [%
                                    FOR s IN set.upn_rewrite_sources.all;
                                        s.pattern _ "<br/>";
                                    END;
                                %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                                           c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_upn_rewrite", [c.req.captures.0, set.id]) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    <a class="btn btn-secondary btn-small" href="[% c.uri_for_action("/subscriber/delete_upn_rewrite", [c.req.captures.0, set.id]) %]" data-confirm="Delete"><i class="icon-trash"></i> [% c.loc('Delete') %]</a>
                                    [% END -%]
                                </div>

                            </td>
                        </tr>
                        [% END %]
                    </tbody>
                </table>

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

[% IF c.config.general.ngcp_type != 'spce' -%]
[% IF c.license('header_manipulation') -%]
[% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_hdr">[% c.loc('Header Manipulations') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_hdr">
            <div class="accordion-inner">


[%
    helper.name = c.loc('Header Manipulations');
    helper.identifier = 'header_rules';
    helper.length_change = 1;
    helper.dt_columns = hm_rule_dt_columns;
    helper.ajax_uri = c.uri_for_action('/subscriber/header_rules_ajax', [c.req.captures.0]);

    IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
        c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1;
        FILTER null;
            backuritmp=c.req.uri;
            backuritmp.query_param_delete('back');
            backuritmp.query_param_delete('move');
            backuritmp.query_param_delete('where');
        END;
        helper.top_buttons = [
            { name = c.loc('Create Header Rule'), uri = c.uri_for_action('/subscriber/header_rules_create', [c.req.captures.0]), icon = 'icon-star' },
        ];
        helper.dt_buttons = [
            { uri = "/subscriber/" _ subscriber.id _ "/preferences/header/?move='+full.id+'&where=up", class = 'btn-small btn-primary', icon = 'icon-arrow-up' },
            { uri = "/subscriber/" _ subscriber.id _ "/preferences/header/?move='+full.id+'&where=down", class = 'btn-small btn-primary', icon = 'icon-arrow-down' },
            { name = c.loc('Edit'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Conditions'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/conditions", class = 'btn-small btn-tertiary', icon = 'icon-glass' },
            { name = c.loc('Actions'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/actions", class = 'btn-small btn-tertiary', icon = 'icon-play' },
            { name = c.loc('Delete'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
        ];
    ELSE;
        helper.top_buttons = [
        ];
        helper.dt_buttons = [
            { name = c.loc('Conditions'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/conditions", class = 'btn-small btn-tertiary', icon = 'icon-glass' },
            { name = c.loc('Actions'), uri = "/subscriber/" _ subscriber.id _ "/preferences/header/'+full.id+'/actions", class = 'btn-small btn-tertiary', icon = 'icon-play' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
%]

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

[% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse_lm">[% c.loc('Location Mappings') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_lm">
            <div class="accordion-inner">

                [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                       c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                <a class="btn btn-tertiary btn-large" href="[% c.uri_for_action("/subscriber/create_location_map", [c.req.captures.0]) %]">
                    <i class="icon-star"></i> [% c.loc('Create') %]
                </a>
                [% END -%]
                <div class="ngcp-separator"></div>

                <table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table_lm">
                    <thead>
                        <tr>
                            <th>[% c.loc('Location SIP-URI') %]</th>
                            <th>[% c.loc('Caller Pattern') %]</th>
                            <th>[% c.loc('Callee Pattern') %]</th>
                            <th>[% c.loc('Mode') %]</th>
                            <th>[% c.loc('To Username') %]</th>
                            <th>[% c.loc('External ID') %]</th>
                            <th>[% c.loc('Enabled') %]</th>
                            [% # one for actions -%]
                            <th class="ngcp-actions-column"></th>
                        </tr>
                    </thead>
                    <tbody>
                        [% FOR location_map IN subscriber.provisioning_voip_subscriber.location_mappings.all -%]
                        <tr class="sw_action_row">
                            <td>
                                [% location_map.location %]
                            </td>
                            <td>
                                [% location_map.caller_pattern %]
                            </td>
                            <td>
                                [% location_map.callee_pattern %]
                            </td>
                            <td>
                                [% location_map.mode %]
                            </td>
                            <td>
                                [% location_map.to_username %]
                            </td>
                            <td>
                                [% location_map.external_id %]
                            </td>
                            <td>
                                [% location_map.enabled %]
                            </td>
                            <td class="ngcp-actions-column">
                                <div class="sw_actions">
                                    [% IF (c.user.roles == "admin" || c.user.roles == "reseller" ||
                                            c.user.roles == "ccareadmin" || c.user.roles == "ccare") && c.user.read_only != 1 -%]
                                    <a class="btn btn-primary btn-small" href="[% c.uri_for_action("/subscriber/edit_location_map", [c.req.captures.0, location_map.id]) %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                                    <a class="btn btn-secondary btn-small" href="[% c.uri_for_action("/subscriber/delete_location_map", [c.req.captures.0, location_map.id]) %]" data-confirm="Delete"><i class="icon-trash"></i> [% c.loc('Delete') %]</a>
                                    [% END -%]
                                </div>
                            </td>
                        </tr>
                        [% END %]
                    </tbody>
                </table>

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

[%
    PROCESS 'helpers/pref_table.tt';
%]

[% IF edit_cf_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = cf_description);
-%]

[% IF cf_form.has_for_js -%]
[% cf_form.render_repeatable_js %]
[% END -%]
[% cf_form.render %]

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% ELSIF edit_cfset_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = cf_description);
-%]

    <div class="modal-body">
    <div class="row" style="margin-left: 10px">
        <a class="btn btn-primary btn-medium" href="[% c.uri_for_action('/subscriber/preferences_callforward_destinationset_create', [c.req.captures.0], cf_type) %]"><i class="icon-star"></i>[% c.loc('Create New') %]</a>
    </div>
    <div class="ngcp-separator"></div>
    [% IF cf_sets.size -%]
    <table class="table table-bordered table-striped table-highlight table-hover">
        <thead>
            <tr>
                <th>[% c.loc('Name') %]</th>
                <th>[% c.loc('Values') %]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        [% FOREACH set IN cf_sets -%]
            <tr class="sw_action_row">
                <td>[% set.name | html %]</td>
                <td>
                    [% FOREACH d IN set.destinations -%]
                        [% escaped_cf = d.as_string | html -%]
                        [% c.loc('[_1]<span class="pull-right">for [_2]s</span>', escaped_cf, d.timeout) %]<br/>
                    [% END -%]
                </td>
                <td class="ngcp-actions-column">
                    <div class="sw_actions pull-right">
                        <a class="btn btn-small btn-primary" href="[% c.uri_for_action('/subscriber/preferences_callforward_destinationset_edit', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-edit"></i> [% c.loc('Edit') %]
                        </a>
                        <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% c.uri_for_action('/subscriber/preferences_callforward_destinationset_delete', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-trash"></i> [% c.loc('Delete') %]
                        </a>
                    </div>
                </td>
            </tr>
        [% END -%]
        </tbody>
    </table>
    [% END -%]
    </div>

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% ELSIF edit_timeset_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = cf_description);
-%]

    <div class="modal-body">
    <div class="row" style="margin-left: 10px">
        <a class="btn btn-primary btn-medium" href="[% c.uri_for_action('/subscriber/preferences_callforward_timeset_create', [c.req.captures.0], cf_type) %]"><i class="icon-star"></i>[% c.loc('Create New') %]</a>
    </div>
    <div class="ngcp-separator"></div>
    [% IF cf_sets.size -%]
    <table class="table table-bordered table-striped table-highlight table-hover">
        <thead>
            <tr>
                <th>[% c.loc('Name') %]</th>
                <th>[% c.loc('Values') %]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        [% FOREACH set IN cf_sets -%]
            <tr class="sw_action_row">
                <td>[% set.name | html %]</td>
                <td>
                    [% FOREACH p IN set.periods -%]
                        [% p.as_string | html %]<br/>
                    [% END -%]
                </td>
                <td class="ngcp-actions-column">
                    <div class="sw_actions pull-right">
                        <a class="btn btn-small btn-primary" href="[% c.uri_for_action('/subscriber/preferences_callforward_timeset_edit', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-edit"></i> [% c.loc('Edit') %]
                        </a>
                        <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% c.uri_for_action('/subscriber/preferences_callforward_timeset_delete', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-trash"></i> [% c.loc('Delete') %]
                        </a>
                    </div>
                </td>
            </tr>
        [% END -%]
        </tbody>
    </table>
    [% END -%]
    </div>

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% ELSIF edit_sourceset_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = c.loc("Source Sets"));
-%]

    <div class="modal-body">
    <div class="row" style="margin-left: 10px">
        <a class="btn btn-primary btn-medium" href="[% c.uri_for_action('/subscriber/preferences_callforward_sourceset_create', [c.req.captures.0], cf_type) %]"><i class="icon-star"></i>[% c.loc('Create New') %]</a>
    </div>
    <div class="ngcp-separator"></div>
    [% IF cf_source_sets.size -%]
    <table class="table table-bordered table-striped table-highlight table-hover">
        <thead>
            <tr>
                <th>[% c.loc('Name') %]</th>
                <th>[% c.loc('Mode') %]</th>
                <th>[% c.loc('Values') %]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        [% FOREACH set IN cf_source_sets -%]
            <tr class="sw_action_row">
                <td>[% set.name | html %]</td>
                <td>[% set.mode %]</td>
                <td>
                    [% FOREACH source IN set.sources -%]
                        [% source.as_string | html %]<br/>
                    [% END -%]
                </td>
                <td class="ngcp-actions-column">
                    <div class="sw_actions pull-right">
                        <a class="btn btn-small btn-primary" href="[% c.uri_for_action('/subscriber/preferences_callforward_sourceset_edit', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-edit"></i> [% c.loc('Edit') %]
                        </a>
                        <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% c.uri_for_action('/subscriber/preferences_callforward_sourceset_delete', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-trash"></i> [% c.loc('Delete') %]
                        </a>
                    </div>
                </td>
            </tr>
        [% END -%]
        </tbody>
    </table>
    [% END -%]
    </div>

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% ELSIF edit_bnumberset_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = c.loc("B-Number Sets"));
-%]

    <div class="modal-body">
    <div class="row" style="margin-left: 10px">
        <a class="btn btn-primary btn-medium" href="[% c.uri_for_action('/subscriber/preferences_callforward_bnumberset_create', [c.req.captures.0], cf_type) %]"><i class="icon-star"></i>[% c.loc('Create New') %]</a>
    </div>
    <div class="ngcp-separator"></div>
    [% IF cf_bnumber_sets.size -%]
    <table class="table table-bordered table-striped table-highlight table-hover">
        <thead>
            <tr>
                <th>[% c.loc('Name') %]</th>
                <th>[% c.loc('Mode') %]</th>
                <th>[% c.loc('Values') %]</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        [% FOREACH set IN cf_bnumber_sets -%]
            <tr class="sw_action_row">
                <td>[% set.name | html %]</td>
                <td>[% set.mode %]</td>
                <td>
                    [% FOREACH number IN set.bnumbers -%]
                        [% number.as_string | html %]<br/>
                    [% END -%]
                </td>
                <td class="ngcp-actions-column">
                    <div class="sw_actions pull-right">
                        <a class="btn btn-small btn-primary" href="[% c.uri_for_action('/subscriber/preferences_callforward_bnumberset_edit', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-edit"></i> [% c.loc('Edit') %]
                        </a>
                        <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% c.uri_for_action('/subscriber/preferences_callforward_bnumberset_delete', [ c.req.captures.0, set.id ], cf_type) %]">
                            <i class="icon-trash"></i> [% c.loc('Delete') %]
                        </a>
                    </div>
                </td>
            </tr>
        [% END -%]
        </tbody>
    </table>
    [% END -%]
    </div>

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% ELSIF edit_ccmap_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = 'Callthrough CLIs');
-%]

    [% IF ccmap_form.has_for_js -%]
    [% ccmap_form.render_repeatable_js %]
    [% END -%]
    [% ccmap_form.render %]

[%
    modal_footer();
    modal_script(m.close_target = close_target ? close_target : c.uri_for_action('/subscriber/preferences', [c.req.captures.0]));
-%]
[% END -%]

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