Ejemplo n.º 1
0
 /**
  * initializes and outputs the list for the backend
  */
 public static function initialize()
 {
     self::_setup_i18n();
     self::$options = Participants_Db::$plugin_options;
     get_currentuserinfo();
     // set up the user settings transient
     global $user_ID;
     self::$user_settings = Participants_Db::$prefix . self::$user_settings . '-' . $user_ID;
     self::set_list_limit();
     self::$registration_page_url = get_bloginfo('url') . '/' . (isset(self::$options['registration_page']) ? self::$options['registration_page'] : '');
     self::setup_display_columns();
     self::$sortables = Participants_Db::get_sortables();
     // set up the basic values
     $default_values = array('search_field' => self::get_admin_user_setting('search_field', 'none'), 'value' => '', 'operator' => self::get_admin_user_setting('search_op', 'LIKE'), 'sortBy' => self::get_admin_user_setting('sort_by', self::$options['admin_default_sort']), 'ascdesc' => self::get_admin_user_setting('sort_order', self::$options['admin_default_sort_order']), 'submit-button' => '');
     // merge the defaults with the $_REQUEST array so if there are any new values coming in, they're included
     self::$filter = shortcode_atts($default_values, $_REQUEST);
     self::set_admin_user_setting('search_field', self::$filter['search_field']);
     self::set_admin_user_setting('search_op', self::$filter['operator']);
     self::set_admin_user_setting('sort_by', self::$filter['sortBy']);
     self::set_admin_user_setting('sort_order', self::$filter['ascdesc']);
     //error_log(__METHOD__.' request:'.print_r($_REQUEST,1).' filter:'.print_r(self::$filter,1));
     // process delete and items-per-page form submissions
     self::_process_general();
     self::_process_search(self::$filter['submit-button']);
     if (WP_DEBUG) {
         error_log(__METHOD__ . ' list query= ' . self::$list_query);
     }
     // get the $wpdb object
     global $wpdb;
     // get the number of records returned
     self::$num_records = $wpdb->get_var(str_replace('*', 'COUNT(*)', self::$list_query));
     // set the pagination object
     self::$pagination = new PDb_Pagination(array('link' => self::prepare_page_link($_SERVER['REQUEST_URI']), 'page' => isset($_GET[self::$list_page]) ? $_GET[self::$list_page] : '1', 'size' => self::$page_list_limit, 'total_records' => self::$num_records, 'add_variables' => http_build_query(self::$filter) . '#pdb-list-admin'));
     // get the records for this page, adding the pagination limit clause
     self::$participants = $wpdb->get_results(self::$list_query . ' ' . self::$pagination->getLimitSql(), ARRAY_A);
     // ok, setup finished, start outputting the form
     // add the top part of the page for the admin
     self::_admin_top();
     // print the sorting/filtering forms
     self::_sort_filter_forms();
     // add the delete and items-per-page controls for the backend
     self::_general_list_form_top();
     // print the main table
     self::_main_table();
     // output the pagination controls
     echo '<div class="pdb-list">' . self::$pagination->links() . '</div>';
     // print the CSV export form (admin users only)
     if (current_user_can(Participants_Db::$plugin_options['plugin_admin_capability'])) {
         self::_print_export_form();
     }
     // print the plugin footer
     Participants_Db::plugin_footer();
 }
 /**
  * initializes and outputs the list for the backend
  */
 public static function initialize()
 {
     self::_setup_i18n();
     wp_localize_script(Participants_Db::$prefix . 'list-admin', 'list_adminL10n', array('delete' => self::$i18n['delete_checked'], 'cancel' => self::$i18n['change'], "record" => __("Do you really want to delete the selected record?", 'participants-database'), "records" => __("Do you really want to delete the selected records?", 'participants-database')));
     wp_enqueue_script(Participants_Db::$prefix . 'list-admin');
     wp_enqueue_script(Participants_Db::$prefix . 'debounce');
     get_currentuserinfo();
     // set up the user settings transient
     global $user_ID;
     self::$user_settings = Participants_Db::$prefix . self::$user_settings . '-' . $user_ID;
     self::$filter_transient = Participants_Db::$prefix . self::$filter_transient . '-' . $user_ID;
     self::set_list_limit();
     self::$registration_page_url = get_bloginfo('url') . '/' . Participants_Db::plugin_setting('registration_page', '');
     self::setup_display_columns();
     self::$sortables = Participants_Db::get_field_list(false, false, 'alpha');
     //    self::$sortables = Participants_Db::get_sortables(false, 'alpha');
     // set up the basic values
     self::$default_filter = array('search' => array(0 => array('search_field' => 'none', 'value' => '', 'operator' => 'LIKE', 'logic' => 'AND')), 'sortBy' => Participants_Db::plugin_setting('admin_default_sort'), 'ascdesc' => Participants_Db::plugin_setting('admin_default_sort_order'), 'list_filter_count' => 1);
     // merge the defaults with the $_REQUEST array so if there are any new values coming in, they're included
     self::_update_filter();
     // error_log(__METHOD__.' filter:'.print_r(self::$filter,1));
     // process delete and items-per-page form submissions
     self::_process_general();
     self::_process_search();
     if (WP_DEBUG) {
         error_log(__METHOD__ . ' list query= ' . self::$list_query);
     }
     /*
      * save the query in a transient so it can be used by the export CSV functionality
      */
     if (Participants_Db::current_user_has_plugin_role('admin', 'csv export')) {
         global $current_user;
         set_transient(Participants_Db::$prefix . 'admin_list_query' . $current_user->ID, self::$list_query, 3600 * 24);
     }
     // get the $wpdb object
     global $wpdb;
     // get the number of records returned
     self::$num_records = $wpdb->get_var(str_replace('*', 'COUNT(*)', self::$list_query));
     // set the pagination object
     $current_page = filter_input(INPUT_GET, self::$list_page, FILTER_VALIDATE_INT, array('options' => array('default' => 1, 'min_range' => 1)));
     self::$pagination = new PDb_Pagination(array('link' => self::prepare_page_link($_SERVER['REQUEST_URI']) . '&' . self::$list_page . '=%1$s', 'page' => $current_page, 'size' => self::$page_list_limit, 'total_records' => self::$num_records, 'add_variables' => '#pdb-list-admin'));
     // get the records for this page, adding the pagination limit clause
     self::$participants = $wpdb->get_results(self::$list_query . ' ' . self::$pagination->getLimitSql(), ARRAY_A);
     // ok, setup finished, start outputting the form
     // add the top part of the page for the admin
     self::_admin_top();
     // print the sorting/filtering forms
     self::_sort_filter_forms();
     // add the delete and items-per-page controls for the backend
     self::_general_list_form_top();
     // print the main table
     self::_main_table();
     // output the pagination controls
     echo '<div class="pdb-list">' . self::$pagination->links() . '</div>';
     // print the CSV export form (authorized users only)
     $csv_role = Participants_Db::plugin_setting_is_true('editor_allowed_csv_export') ? 'editor' : 'admin';
     if (Participants_Db::current_user_has_plugin_role($csv_role, 'csv export')) {
         self::_print_export_form();
     }
     // print the plugin footer
     Participants_Db::plugin_footer();
 }