function amr_meta_handle_export_request()
{
    global $amain;
    check_admin_referer('amr-meta');
    $ulist = (int) $_REQUEST['csv'];
    $tofile = amr_is_tofile($ulist);
    $capability = apply_filters('amr-users-export-csv', 'list_users', $ulist);
    amr_meta_main_admin_header(__('Export a user list', 'amr-users'), $capability);
    // pass capability
    amr_meta_admin_headings($plugin_page = '');
    // does the nonce check  and formstartetc
    if (isset($_REQUEST['csvfiltered'])) {
        echo amr_generate_csv($ulist, true, true, 'txt', "'", chr(9), chr(13) . chr(10), $tofile);
    } else {
        echo amr_generate_csv($ulist, true, false, 'csv', '"', ',', chr(13) . chr(10), $tofile);
    }
    echo ausers_form_end();
    return;
}
function amr_meta_handle_export_request()
{
    global $amain;
    $ulist = (int) $_REQUEST['csv'];
    if (empty($amain['public'][$ulist])) {
        check_admin_referer('amr-meta');
        $tofile = false;
    } else {
        $tofile = true;
    }
    amr_meta_main_admin_header(__('Export a user list', 'amr-users'));
    amr_meta_admin_headings($plugin_page = '');
    // does the nonce check  and formstartetc
    if (isset($_REQUEST['csvfiltered'])) {
        echo amr_generate_csv($ulist, true, true, 'txt', "'", chr(9), chr(13) . chr(10), $tofile);
    } else {
        echo amr_generate_csv($ulist, true, false, 'csv', '"', ',', chr(13) . chr(10), $tofile);
    }
    echo ausers_form_end();
    return;
}
function amrmeta_configure_page()
{
    global $aopt;
    global $amr_nicenames;
    global $pluginpage;
    global $amain;
    ameta_options();
    // should handle emptiness etc
    if (isset($_POST['addnew']) and isset($_POST['copylist'])) {
        $copyfrom = intval($_REQUEST['copylist']);
        $amain['names'][] = __('New list copy of ') . $amain['names'][$copyfrom];
        $aopt['list'][] = $aopt['list'][$copyfrom];
        $ulist = array_pop(array_keys($amain['names']));
        $amain['names'][$ulist] .= ' #' . $ulist;
        ausers_update_option('amr-users', $aopt);
        ausers_update_option('amr-users-main', $amain);
        amr_users_message('Added list: ' . $ulist);
        $_REQUEST['ulist'] = $ulist;
    } else {
        if (!empty($_REQUEST['ulist'])) {
            $ulist = (int) $_REQUEST['ulist'];
        } else {
            $ulist = '1';
        }
    }
    amr_meta_main_admin_header('Configure a user list');
    amr_meta_admin_headings($plugin_page = '');
    // does the nonce check  and formstartetc
    //	else
    if (isset($_REQUEST['rebuild'])) {
        /* can only do one list at a time in realtime */
        amr_rebuild_in_realtime_with_info($ulist);
        echo ausers_form_end();
        return;
    } elseif (!empty($_REQUEST['rebuildback'])) {
        /*  */
        amr_request_cache_with_feedback();
        echo ausers_form_end();
        return;
    } elseif (!empty($_REQUEST['rebuildwarning'])) {
        /*  */
        amr_rebuildwarning($ulist);
        echo ausers_form_end();
        return;
    } elseif (isset($_REQUEST['custom_navigation'])) {
        if (function_exists('amrmeta_custom_navigation_page')) {
            amrmeta_custom_navigation_page($ulist);
            echo ausers_form_end();
            return;
        } else {
            echo 'Function not active';
        }
    } elseif (isset($_REQUEST['grouping'])) {
        if (function_exists('amr_grouping_admin_form')) {
            amr_grouping_admin_form($ulist);
            echo ausers_form_end();
            return;
        } else {
            _e('Grouping Function not active', 'amr-users');
        }
    } elseif (amr_users_can_edit('filtering')) {
        amrmeta_filtering_page($ulist);
    } elseif (isset($_POST['action']) and $_POST['action'] == "save") {
        if (isset($_POST['updateoverview'])) {
            amrmeta_validate_overview();
        } elseif (isset($_POST['update'])) {
            if (!amrmeta_validate_listfields($ulist)) {
                amr_users_message(__('List Fields Validation failed', 'amr-users'));
            }
        } elseif (isset($_POST['configure'])) {
            // ulist already set above, so will just configure
        }
    }
    list_configurable_lists();
    // to allow selection of which to configure
    amrmeta_listfields($ulist);
    echo ausers_form_end();
}
function amrmeta_admin_header()
{
    global $ausersadminurl;
    amr_meta_main_admin_header('User Lists');
    echo '<ul class="subsubsub">';
    $t = __('General', 'amr-users');
    echo PHP_EOL . '<li><a  href="' . $ausersadminurl . '" title="' . $t . '" >' . $t . '</a>|</li>';
    $t = __('Test your db', 'amr-users');
    echo PHP_EOL . '<li><a  href="' . wp_nonce_url(add_query_arg('am_page', 'testyourdb', $ausersadminurl), 'amr-meta') . '" title="' . $t . '" >' . $t . '</a>|</li>';
    $t = __('Overview', 'amr-users');
    echo PHP_EOL . '<li>&nbsp;<span class="step">1.</span><a  href="' . wp_nonce_url(add_query_arg('am_page', 'overview', $ausersadminurl), 'amr-meta') . '" title="' . $t . '" >' . $t . '</a>|</li>';
    $t = __('Nice Names', 'amr-users');
    echo '<li>&nbsp;<span class="step">' . '2.</span><a ' . a_currentclass('nicenames') . ' href="' . wp_nonce_url(add_query_arg('am_page', 'nicenames', $ausersadminurl), 'amr-meta') . '" title="' . $t . '" >' . $t . '</a>|&nbsp;<span class="step">' . '3.</span></li></ul>';
    $t = __('Rebuild Cache in Background', 'amr-users');
    list_configurable_lists();
    echo '<ul class="subsubsub"><li>&nbsp;<span class="step">4.</span>' . au_buildcachebackground_link() . '|</li>';
    echo '<li>&nbsp;<span class="step">5.</span>' . au_cachelog_link() . '|</li>';
    echo '<li>&nbsp;<span class="step">6.</span>' . au_cachestatus_link() . '</li>';
    echo '</ul>';
    return;
}