/**
  * Prepare all the items to be displayed
  *
  * @access public
  * @return void
  */
 public function prepare_items()
 {
     $columns = $this->get_columns();
     $sortable = $this->get_sortable_columns();
     $hidden = array();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // Get the audit data.
     $audit_posts_model = new MSA_Audit_Posts_Model();
     $per_page = $this->get_items_per_page('posts_per_page', 50);
     $current_page = $this->get_pagenum();
     $args = array('per_page' => $per_page, 'current_page' => $current_page);
     /**
      * Search term
      */
     if (isset($_POST['s']) && check_admin_referer('msa-all-audit-posts-table')) {
         // Input var okay.
         $args['s'] = sanitize_text_field(wp_unslash($_POST['s']));
         // Input var okay.
     }
     /**
      * Get Posts
      */
     $audit = -1;
     if (isset($_GET['audit'])) {
         // Input var okay.
         $audit = sanitize_text_field(wp_unslash($_GET['audit']));
         // Input var okay.
     }
     $posts = $audit_posts_model->get_data($audit, $args);
     foreach ($posts as $post) {
         $this->items[] = array('score' => $post['score'], 'post' => $post['post'], 'data' => $post['data']);
     }
     /**
      * Filter Posts
      */
     $this->items = msa_filter_posts($this->items);
     /**
      * Sort Posts
      */
     if (count($this->items) > 0) {
         usort($this->items, array(&$this, 'usort_reorder'));
     }
     $total_items = count($this->items);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
     if (is_array($this->items) && count($this->items) > 0) {
         $this->items = array_slice($this->items, ($current_page - 1) * $per_page, $per_page);
     }
 }
	</div>

<?php 
} else {
    if (isset($_GET['audit']) && check_admin_referer('msa-single-audit')) {
        // Input var okay.
        $audit_id = sanitize_text_field(wp_unslash($_GET['audit']));
        // Input var okay.
        // Get the Audit.
        $audit_model = new MSA_Audits_Model();
        $audit = $audit_model->get_data_from_id($audit_id);
        $form_fields = json_decode($audit['args']['form_fields'], true);
        // Get the posts for an audit.
        $audit_posts_model = new MSA_Audit_Posts_Model();
        $posts = $audit_posts_model->get_data($audit_id);
        // Get all the current filters.
        $current_filters = '';
        $conditions = msa_get_conditions();
        $attributes = msa_get_attributes();
        foreach ($conditions as $key => $condition) {
            if (isset($condition['filter']['name']) && isset($_GET[$condition['filter']['name']])) {
                // Input var okay.
                $current_filters .= '&' . $condition['filter']['name'] . '=' . sanitize_text_field(wp_unslash($_GET[$condition['filter']['name']]));
                // Input var okay.
            }
        }
        foreach ($attributes as $key => $attribute) {
            if (isset($attribute['filter']['name']) && isset($_GET[$attribute['filter']['name']])) {
                // Input var okay.
                $current_filters .= '&' . $attribute['filter']['name'] . '=' . sanitize_text_field(wp_unslash($_GET[$attribute['filter']['name']]));