[% USE date %]
[% IF framed -%]

<body>
    <div id="wrapper">
        <h2>[% template.title or site_config.title %]</h2>
        <div id="content">
            [% content %]
        </div>
    </div>
    <script type="text/javascript">
        const errorNode = document.querySelector('#content .alert.alert-error')
        let errorMessage = null
        if (errorNode !== null) {
            errorMessage = errorNode.innerText
        }
        if (parent) {
            parent.postMessage({
                origin: 'ngcp-panel',
                path: location.pathname,
                error: errorMessage
            }, '*')

            $(window).on('beforeunload', function() {
                if (parent) {
                    parent.postMessage({
                        origin: 'ngcp-panel-beforeunload',
                        path: location.pathname
                    }, '*');
                }
            });
        }
    </script>
</body>

[% ELSE -%]

<body>
<div id="wrapper">
    <div id="banner">
        <div class="container">
          <span class="pull-right">
          [% c.loc("This interface is not supported anymore and it will be discontinued in future versions. Please use the new interface for the configuration of the system.") %]
          </span>
        </div>
    </div>
    <div id="topbar">
        <div class="container">

            <a href="javascript:;" id="menu-trigger" class="dropdown-toggle" data-toggle="dropdown" data-target="#">
                <i class="icon-cog"></i>
            </a>

            <div id="top-nav">
                <ul class="pull-right">
                    <li>
                      [% IF c.user -%]
                        [%- IF c.user.roles == 'admin' || c.user.roles == 'reseller' || c.user.roles == 'ccareadmin' || c.user.roles == 'ccare' || c.user.roles == 'lintercept' -%]
                          [% login_name = c.user.login _ ' (' _ c.user.roles _ ')' %]
                        [%- ELSE -%]
                          [% login_name = c.user.webusername _'@'_ c.user.domain.domain %]
                        [%- END -%]
                        <i class="icon-user"></i> [% c.loc("Logged in as [_1]", login_name) %]

                      [%- ELSE -%]
                        <i class="icon-user"></i> [% c.loc("Not logged in") %]
                      [%- END -%]
                    </li>
                    <li>
                        [% IF c.user && c.session.user_tz_name; '(' _ c.session.user_tz.name _ ' ' _ c.loc('time') _ ')'; END; %]
                    </li>
                    <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="icon-globe"></i> [% c.loc('Language') %]
                        <b class="caret"></b>
                    </a>

                    <ul class="dropdown-menu pull-right">
                        <li><a href="?lang=en"><img src="/img/lang/en.png" class="ngcp-lang-flag"/> English</a></li>
                        <li><a href="?lang=de"><img src="/img/lang/de.png" class="ngcp-lang-flag"/> German</a></li>
                        <li><a href="?lang=fr"><img src="/img/lang/fr.png" class="ngcp-lang-flag"/> French</a></li>
                        <li><a href="?lang=it"><img src="/img/lang/it.png" class="ngcp-lang-flag"/> Italian</a></li>
                        <li><a href="?lang=es"><img src="/img/lang/es.png" class="ngcp-lang-flag"/> Spanish</a></li>
                    </ul>
                    </li>
                    <li><a href="[% c.uri_for('/logout') %]">[% c.loc('Logout') %]</a></li>
                </ul>
            </div> <!-- /#top-nav -->
        </div> <!-- /.container -->
    </div> <!-- /#topbar -->

    <div id="header">
        <div class="container">
            <a href="[% c.uri_for('/dashboard') %]" class="brand">[% c.loc("Dashboard") %]</a>
            <a href="javascript:;" class="btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <i class="icon-reorder"></i>
            </a>
            <div class="nav-collapse collapse">
                <ul id="main-nav" class="nav pull-right">

                    <li class="nav-icon">
                        <a href="[% c.uri_for('/') %]">
                            <i class="icon-home"></i>
                            <span>[% c.loc("Home") %]</span>
                        </a>
                    </li>
                    [% FOREACH t IN topmenu -%]
                        [% INCLUDE $t -%]
                    [% END -%]
                </ul> <!-- /.dropdown-menu -->
            </div> <!-- /.nav-collapse -->
        </div> <!-- /.container -->
    </div> <!-- /#header -->
    <div id="masthead">
        <div class="container">
            <div class="masthead-pad">
                <div class="masthead-text">
                    <h2>[% template.title or site_config.title %]</h2>
                </div>
            </div>
        </div>
    </div>
    <div id="content">
        <div class="container">
            [% IF c.config.general.maintenance_mode -%]
                <div class="alert alert-error" style="font-size:150%">
                    <strong>[% c.loc('Maintenance mode is enabled! Please do not perform any changes until maintenance mode has been switched off!') %]</strong>
                </div>
            [% END -%]
            [% content %]
        </div>
    </div>
</div> <!-- /#wrapper -->

<div id="footer">
    <div class="container">
        <div class="row">
            <div class="span6">
                [% IF c.user.roles == 'admin' || c.user.roles == 'reseller'; -%]
                    <a href="[% c.uri_for("/statistics/versions") %]">[% c.config.ngcp_version %]</a>
                [% END; -%]
                © 2013 - [% date.format(date.now, '%Y') -%] <a href="http://www.sipwise.com">Sipwise GmbH</a>, [% c.loc('all rights reserved') %].
            </div>
            [% IF c.config.general.ui_enable -%]
              [% IF c.user.roles == 'admin' || c.user.roles == 'reseller' || c.user.roles == 'ccareadmin' || c.user.roles == 'ccare' || c.user.roles == 'lintercept' -%]
                <div class="nav pull-right">
                  <b><a href="[% c.uri_for_action('/login_to_v2') -%]/?page=[% c.escape_uri(c.req.path) -%]">[% c.loc('GO TO NEW ADMIN PANEL') -%]</a></b>
                </div>
              [% END -%]
            [% END -%]
        </div>
    </div>
</div>
[% END -%] <!-- framed=0 -->

<script src="/js/Theme.js"></script>

<script>
var isIE = /(MSIE|Trident\/|Edge\/)/i.test(navigator.userAgent);
if(isIE){
    $.ajaxSetup({ cache: false });
}
var addConsoleNoOp =  function (window) {
    var names = ["log", "debug", "info", "warn", "error",
        "assert", "dir", "dirxml", "group", "groupEnd", "time",
        "timeEnd", "count", "trace", "profile", "profileEnd"],
        i, l = names.length,
        noOp = function () {};
    window.console = {};
    for (i = 0; i < l; i = i + 1) {
        window.console[names[i]] = noOp;
    }
};
if (!window.console) {
    this.addConsoleNoOp(window);
}


[% IF c.session.aui_adminId && c.session.aui_jwt -%]
    localStorage.setItem('aui_adminId', [% c.session.aui_adminId -%]);
    localStorage.setItem('aui_jwt', '[% c.session.aui_jwt -%]');
    [% c.session.delete('aui_adminId', 'aui_jwt') %]
[% END -%]

var mainWrapperInit = function () {

    $('[rel="tooltip"]').tooltip({'html': false});

    $('.sw_actions').css('visibility','hidden');
    $('.sw_action_row').hover(
                    function() { $(this).find('.sw_actions').css('visibility','visible'); },
                    function() { $(this).find('.sw_actions').css('visibility','hidden'); }
    );

    $(document).on("click", 'a[data-confirm]', function(ev) {
        var href = $(this).attr('href');
        //var onclick = $(this).attr('onclick');
        if (!$('#dataConfirmModal').length) {
            $('body').append(
                '<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true">'+
                '<div class="modal-header">'+
                  '<h3 id="dataConfirmLabel">[% c.escape_js(c.loc('Are you sure?')) %]</h3>'+
                '</div>'+
                '<div class="modal-footer">'+
                  '<button class="btn" data-dismiss="modal" aria-hidden="true" id="dataConfirmCancel">[% c.escape_js(c.loc('Cancel')) %]</button>'+
                  '<a class="btn btn-primary" id="dataConfirmOK">[% c.escape_js(c.loc('OK')) %]</a>'+
                '</div>'+
              '</div>'
            );
        }
        $('#dataConfirmOK').attr('href', href);
        if( href.search(/^javascript:/i ) > -1 ){
            $('#dataConfirmOK').attr('onclick', href);
            $('#dataConfirmOK').attr('data-dismiss', 'modal');
        }
        $('#dataConfirmOK').text($(this).attr('data-confirm'));
        if($('#mod_edit').length) {
            if(!$(this).attr('cancel-hide')){
                $('#mod_edit').modal('hide');
                $(document).on("click", '#dataConfirmCancel', function(ev) {
                    $('#mod_edit').modal('show');
                });
            }
        }
        $('#dataConfirmModal').modal({show:true});
        return false;
    });

    [%
        backuri = c.escape_uri(c.req.uri);
        tmp = backuri.query_param_delete('back');
    -%]
    $('a').each(function() {
        var _text = $(this).text().trim();
        var _href = $(this).attr('href');
        var javascriptLink = 0;
        if(_href && ( _href.search(/^javascript:/i) > -1 ) ){
            javascriptLink = 1;
        }
        if(_text == "Back" ||
           $(this).hasClass('ngcp-error-button') ||
           $(this).hasClass('accordion-toggle') ||
           $(this).hasClass('ngcp-noback-link') ||
           javascriptLink ||
           $(this).parents('#footer').length ||
           $(this).parents('#topbar').length)  {

            return true;
        }
        var backuri = $(this).data('backuri') ? $(this).data('backuri') : '[%- backuri | uri -%]';
        var _back = 'back='+backuri;
        if(_href == null || _href.match(/[&\?]back=/)) {
            // ignore
        } else if(_href.match(/\?/)) {
            $(this).attr('href', _href + '&' + _back);
        } else {
            $(this).attr('href', _href + '?' + _back);
        }
        return true;
    });
};

$( document ).ready(function() {
    Theme.init();
    Theme.createExpandCollapseButton ("[% c.loc('Collapse Groups') %]", "[% c.loc('Expand Groups') %]", [% framed %]);
    mainWrapperInit();
});

</script>


[%PROCESS 'administrator/openvpn_wrapper.tt' %]
[% UNLESS framed -%]
</body>
[% END -%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]
