function amr_display_final_list($linessaved, $icols, $cols, $page, $rowsperpage, $totalitems, $caption, $search, $ulist, $c, $filtercol, $sortedbynow, $options = array())
 {
     global $aopt, $amain, $amrusers_fieldfiltering, $amr_current_list, $amr_search_result_count, $ahtm;
     // the display html structure to use
     global $amr_refreshed_heading;
     $amr_current_list = $ulist;
     $html = $hhtml = $fhtml = '';
     $filterhtml = '';
     $filterhtml_separate = '';
     $apply_filter_html = '';
     $filter_submit_html = '';
     $summary = '';
     $explain_filter = '';
     $adminoptions = array('show_search' => true, 'show_perpage' => true, 'show_pagination' => true, 'show_headings' => true, 'show_csv' => true, 'show_refresh' => true, 'show_totals' => false);
     if (!is_admin()) {
         // set public options to overrwite admin
         foreach ($adminoptions as $i => $opt) {
             if (isset($options[$i])) {
                 $adminoptions[$i] = $options[$i];
             } else {
                 $adminoptions[$i] = '';
             }
         }
     }
     //if (WP_DEBUG) var_dump($adminoptions);
     if (!empty($_REQUEST['headings']) or !empty($_REQUEST['filtering'])) {
         $adminoptions['show_search'] = false;
         $adminoptions['show_csv'] = false;
         $adminoptions['show_refresh'] = false;
         $adminoptions['show_perpage'] = false;
         $adminoptions['show_headings'] = false;
         $adminoptions['show_totals'] = false;
         $adminoptions['show_pagination'] = true;
         $amain['filter_html_type'][$amr_current_list] = 'none';
         // if editingheadings, then no showingfilter
     }
     if (is_admin() or !isset($amain['html_type'][$amr_current_list])) {
         // must be after the check above, so will force table in admin
         $ahtm = amr_get_html_to_use('table');
     } else {
         $ahtm = amr_get_html_to_use($amain['html_type'][$amr_current_list]);
     }
     if (empty($linessaved)) {
         $saveditems = 0;
     } else {
         $saveditems = count($linessaved);
     }
     if (is_array($caption)) {
         $caption = '<h3 class="caption">' . implode(', ', esc_attr($caption)) . '</h3>';
     }
     // now fix the icols and cols for any special functioning--------------------------
     if (isset($icols[0]) and $icols[0] == 'ID') {
         /* we only saved the ID so that we can access extra info on display - we don't want to always display it */
         unset($icols[0]);
         unset($cols[0]);
     }
     $icols = array_unique($icols);
     // since may end up with two indices, eg if filtering and grouping by same value
     foreach ($icols as $i => $col) {
         if ($col == 'index') {
             // we only saved the index so that we can access extra info on display - we don't want to display it
             if (!isset($aopt['list'][$amr_current_list]['selected']['index'])) {
                 unset($icols[$i]);
                 unset($cols[$i]);
             }
         } else {
             if (!isset($cols[$i])) {
                 unset($icols[$i]);
             }
         }
     }
     // end fix icols and cols
     if (!empty($search)) {
         $searchselectnow = sprintf(__('%s Users found.', 'amr-users'), $amr_search_result_count);
         $searchselectnow .= sprintf(__('Searching for "%s" in list', 'amr-users'), $search);
     }
     // reset count if searching
     if (isset($amain['sortable'][$amr_current_list])) {
         $sortable = $amain['sortable'][$amr_current_list];
     } else {
         $sortable = false;
     }
     if (!empty($adminoptions['show_headings'])) {
         //admin always has
         if (is_admin()) {
             if (!empty($amr_refreshed_heading)) {
                 $summary = $amr_refreshed_heading;
             } else {
                 $summary = $c->get_cache_summary(amr_rptid($ulist));
             }
         }
         if (!empty($sortedbynow)) {
             $summary = str_replace('<li class="sort">', $sortedbynow, $summary);
         }
         if (!empty($searchselectnow)) {
             $summary = str_replace('<li class="selected">', '<li class="searched">' . $searchselectnow . '</li><li class="selected">', $summary);
         }
         if (!empty($filtercol)) {
             $text = implode(', ', $filtercol);
             $summary = str_replace('<li class="selected">', '<li class="selected">' . __('Selected users with: ', 'amr-users') . esc_attr($text) . '</li><li class="selected">', $summary);
         }
     }
     if (!empty($linessaved) and is_admin() and current_user_can('remove_users') and (empty($_REQUEST['filtering']) and empty($_REQUEST['headings']))) {
         // ym ***
         if (function_exists('amr_ym_bulk_update')) {
             $name = 'ps';
         } else {
             $name = 'users';
         }
         array_unshift($icols, 'checkbox');
         array_unshift($cols, '<input type="checkbox">');
         foreach ($linessaved as $il => $line) {
             if (!empty($line['ID'])) {
                 $linessaved[$il]['checkbox'] = '<input ' . 'type="checkbox" value="' . $line['ID'] . '" name="' . $name . '[]" />';
             } else {
                 $linessaved[$il]['checkbox'] = '&nbsp;';
             }
         }
     }
     //
     //$sortedbynow is set if maually resorted
     if (!isset($amain['html_type'][$amr_current_list]) or !isset($amain['filter_html_type']) or isset($amain['filter_html_type'][$amr_current_list]) and $amain['filter_html_type'][$amr_current_list] == "intableheader") {
         if (function_exists('amr_show_filters')) {
             // for pseudo compatability if unmatched versions
             $filterhtml = amr_show_filters($cols, $icols, $ulist, $filtercol);
             // will have tr and th
         }
     } elseif (!empty($amain['filter_html_type'][$amr_current_list]) and $amain['filter_html_type'][$amr_current_list] == "above") {
         if (function_exists('amr_show_filters_alt')) {
             $filterhtml_separate = amr_show_filters_alt($cols, $icols, $ulist, $filtercol);
         }
     }
     if (!empty($filterhtml) or !empty($filterhtml_separate)) {
         $apply_filter_html = amr_show_apply_filter_button($ulist);
     }
     $apply_filter_html = apply_filters('amr_users_apply_filter_html', $apply_filter_html);
     if (amr_users_can_edit('headings')) {
         $hhtml = amr_allow_update_headings($cols, $icols, $ulist, $sortable);
     } elseif (is_admin() and amr_users_can_edit('filtering')) {
         // in admin  and plus function available etc
         $explain_filter = amr_explain_filtering();
         $hhtml = amr_offer_filtering($cols, $icols, $ulist);
         $filter_submit_html = amr_manage_filtering_submit();
         //will only show if relevant
     } else {
         if (!empty($adminoptions['show_headings'])) {
             $hhtml = amr_list_headings($cols, $icols, $ulist, $sortable, $ahtm);
         }
     }
     // footer
     $fhtml = $ahtm['tfoot'] . $ahtm['tr'] . '>';
     if (stristr($ahtm['th'], '<th')) {
         // if table
         $fhtml .= $ahtm['th'] . ' colspan="' . count($icols) . '">' . amr_users_give_credit();
     } else {
         $fhtml .= $ahtm['th'] . '>';
     }
     $fhtml .= $ahtm['thc'] . $ahtm['trc'] . $ahtm['tfootc'];
     /* setup the html for the table headings */
     if (!empty($linessaved)) {
         $html .= amr_display_a_page($linessaved, $icols, $cols, $ahtm);
     }
     //
     if (!empty($adminoptions['show_search'])) {
         $sformtext = alist_searchform($ulist);
     } else {
         $sformtext = '';
     }
     //
     if (!empty($adminoptions['show_csv'])) {
         $csvtext = amr_users_get_csv_link($ulist, 'csv');
     } else {
         $csvtext = '';
     }
     //
     if (!empty($adminoptions['show_refresh'])) {
         $refreshtext = amr_users_get_refresh_link($ulist);
     } else {
         $refreshtext = '';
     }
     //
     if (!empty($adminoptions['show_perpage'])) {
         $pformtext = alist_per_pageform($ulist);
     } else {
         $pformtext = '';
     }
     if (!empty($amr_search_result_count)) {
         if ($rowsperpage > $amr_search_result_count) {
             $rowsperpage = $amr_search_result_count;
         }
         $totalitems = $amr_search_result_count;
     }
     if (function_exists('amr_custom_navigation')) {
         $custom_nav = amr_custom_navigation($ulist);
     } else {
         $custom_nav = '';
     }
     $moretext = '';
     if (!empty($adminoptions['show_pagination'])) {
         // allows on to just show latest x
         $pagetext = amr_pagetext($page, $totalitems, $rowsperpage);
     } else {
         $pagetext = '';
     }
     if (!empty($filterhtml) or !empty($hhtml)) {
         $hhtml = $ahtm['thead'] . $filterhtml . $hhtml . $ahtm['theadc'];
     }
     if (!empty($adminoptions['show_totals'])) {
         $total_text = PHP_EOL . '<div id="user_totals">' . sprintf(_n('%1s record', '%1s records', $totalitems, 'amr-users'), $totalitems) . '</div>';
     } else {
         $total_text = '';
     }
     $html = amr_manage_headings_submit() . $filter_submit_html . $sformtext . $explain_filter . $filterhtml_separate . $apply_filter_html . $custom_nav . $total_text . $pagetext . PHP_EOL . '<div id="userslist' . $ulist . '"><!-- user list-->' . PHP_EOL . $ahtm['table'] . $caption . $hhtml . $fhtml . PHP_EOL . $ahtm['tbody'] . $html . $ahtm['tbodyc'] . '<!-- end user list body-->' . PHP_EOL . $ahtm['tablec'] . '<!-- end user list table-->' . PHP_EOL . PHP_EOL . '</div><!-- end user list-->' . PHP_EOL . '<div class="userlistfooter">' . $pagetext . $csvtext . $refreshtext . $pformtext . '</div>';
     if (is_admin()) {
         $html = PHP_EOL . '<div class="wrap" >' . $html . '</div>' . PHP_EOL;
     }
     $html = $summary . $html;
     return $html;
 }
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();
}