From e7fc0cf064ece69ec0c250f368bb9aa5f55bb4c9 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 12 Jul 2016 16:54:11 -0400 Subject: [PATCH] Start working on the ajax for lead downloads. Should be setup much like the other ajax stuff I setup on events. --- models/admin/ajax/csvExport.php | 59 +++++++++++++++++++ models/admin/leads/index.php | 100 ++++++++++++++++++++++++-------- setup/validActions.php | 3 + views/admin/leads/index.html | 3 +- 4 files changed, 139 insertions(+), 26 deletions(-) create mode 100644 models/admin/ajax/csvExport.php diff --git a/models/admin/ajax/csvExport.php b/models/admin/ajax/csvExport.php new file mode 100644 index 0000000..8ef85d5 --- /dev/null +++ b/models/admin/ajax/csvExport.php @@ -0,0 +1,59 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_LEADS_PLUGIN_PATH . '/models/admin/leads/index.php'; +/** + * Steve Note... + * + * You can get to this using the following URL. + * + * {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=csvExport&mystuff=THIS + * + * You should be able to do this as POST or GET and should be able to add and read additional parameters. + * I added a "mystuff" parameter to the URL above and it does output from the code in the + * modelAction() function below. + * + * To add another model under models/admin/ajax all you need to do is create it and add it to the + * setup/validActions.php file. + * + */ + +// Load Members data abstract +// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php'); + +/** + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_csvExport extends GlmMembersAdmin_leads_index +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + +} diff --git a/models/admin/leads/index.php b/models/admin/leads/index.php index 9f03991..8dc961d 100644 --- a/models/admin/leads/index.php +++ b/models/admin/leads/index.php @@ -1,7 +1,7 @@ config['loggedInUser']['wpUser']; + $search_id = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -107,33 +109,76 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry if ( isset( $_REQUEST['search'] ) ) { $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN); } + // See if they have a saved search to use. + $result = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "searches + WHERE user_id = %d", + $wpUser['ID'] + ), + ARRAY_A + ); + if ( $result ) { + $search_id = $result['id']; + if ( !isset( $_REQUEST['search'] ) ) { + $search_params = unserialize( $result['search'] ); + $search = true; + } + } if ( isset( $search ) && $search ) { // Filter the $_POST variables from the search form. - // Verlify mm/dd/YYYY date format for the from and to dates. - $search_params = filter_var_array( - $_POST, - array( - 'company' => FILTER_SANITIZE_STRING, - 'contact' => FILTER_SANITIZE_STRING, - 'from_date' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array( - 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' - ) - ), - 'to_date' => array( - 'filter' => FILTER_VALIDATE_REGEXP, - 'options' => array( - 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' + // Verify mm/dd/YYYY date format for the from and to dates. + if ( !isset( $search_params ) ) { + $search_params = filter_var_array( + $_POST, + array( + 'company' => FILTER_SANITIZE_STRING, + 'contact' => FILTER_SANITIZE_STRING, + 'from_date' => array( + 'filter' => FILTER_VALIDATE_REGEXP, + 'options' => array( + 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' + ) + ), + 'to_date' => array( + 'filter' => FILTER_VALIDATE_REGEXP, + 'options' => array( + 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' + ) + ), + 'interests' => array( + 'filter' => FILTER_VALIDATE_BOOLEAN, + 'flags' => FILTER_FORCE_ARRAY ) - ), - 'interests' => array( - 'filter' => FILTER_VALIDATE_BOOLEAN, - 'flags' => FILTER_FORCE_ARRAY ) - ) - ); + ); + } + + if ( $wpUser['ID'] ) { + $search_data = array( + 'title' => '', + 'search' => serialize( $search_params ), + 'user_id' => $wpUser['ID'], + 'date_created' => date( 'Y-m-d' ) + ); + if ( $search_id ) { + $this->wpdb->update( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'searches', + $search_data, + array( 'id' => $search_id ), + array( '%s', '%s', '%d', '%s' ), + array( '%d' ) + ); + } else { + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'searches', + $search_data, + array( '%s', '%s', '%d', '%s' ) + ); + } + } // build the $where part $where_parts = array(); @@ -288,6 +333,11 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry ); break; + case 'download': + echo '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; + exit; + break; + default: if ( $groups ) { foreach ( $groups as $group ) { diff --git a/setup/validActions.php b/setup/validActions.php index 33b89fb..ccba4e7 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -32,6 +32,9 @@ $glmMembersLeadsAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'csvExport' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, + ), 'leads' => array( 'index' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, 'edit' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, diff --git a/views/admin/leads/index.html b/views/admin/leads/index.html index 98ea4db..fe4eb14 100644 --- a/views/admin/leads/index.html +++ b/views/admin/leads/index.html @@ -39,8 +39,9 @@ {if $leads} +

Search Results:

- + Download
-- 2.17.1