--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Leads Database
+ * CSV Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @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;
+
+}
<?php
/**
- * Gaslight Media Members Database
- * Admin Member User Profile
+ * Gaslight Media Member Leads Database
+ * Leads search, list, edit page
*
* PHP version 5.5
*
public function modelAction($actionData = false)
{
- $option = false;
+ $option = false;
$user_can_edit_leads = false;
+ $wpUser = $this->config['loggedInUser']['wpUser'];
+ $search_id = false;
// Get any provided option
if ( isset( $_REQUEST['option'] ) ) {
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();
);
break;
+ case 'download':
+ echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+ exit;
+ break;
+
default:
if ( $groups ) {
foreach ( $groups as $group ) {