*/
public $events = array();
public $image_owner;
+ public $db_host;
+ public $db_name;
+ public $db_user;
+ public $db_password;
+ public $redirectUrl;
+ public $next;
+ public $limit = 50;
+ public $completed = false;
/**
* Constructor
'mLeadAccess' => $memberCanAccessLeads,
'settingsUpdated' => $settingsUpdated,
'settingsUpdateError' => $settingsUpdateError,
+ 'db_host' => $this->db_host,
+ 'db_name' => $this->db_name,
+ 'db_user' => $this->db_user,
+ 'db_password' => $this->db_password,
+ 'redirectUrl' => $this->redirectUrl,
+ 'next' => $this->next,
);
// Return status, suggested view, and data to controller
*/
public function importLeads()
{
+ // Set start to 1
+ $start = 0;
+
+ if ( isset( $_REQUEST['start'] ) ) {
+ $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+ }
+
+ if ( $start == 0 ) {
+ // clear the leads tables
+ $this->wpdb->query( 'DELETE FROM ' . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'leads' );
+ $this->wpdb->query( 'DELETE FROM ' . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry' );
+ }
+
+ // counters
$new_leads = 0;
$updated_leads = 0;
+
+ // data arrays
$interests = array();
$new_interests = array();
$interests_map = array();
// Connect to the postgresql database
- $db_host = filter_var( $_REQUEST['db_host'], FILTER_SANITIZE_STRING );
- $db_name = filter_var( $_REQUEST['db_name'], FILTER_SANITIZE_STRING );
- $db_user = filter_var( $_REQUEST['db_user'], FILTER_SANITIZE_STRING );
- $db_password = filter_var( $_REQUEST['db_password'], FILTER_SANITIZE_STRING );
- $this->connectPostgresDb( $db_host, $db_name, $db_user, $db_password );
+ $this->db_host = filter_var( $_REQUEST['db_host'], FILTER_SANITIZE_STRING );
+ $this->db_name = filter_var( $_REQUEST['db_name'], FILTER_SANITIZE_STRING );
+ $this->db_user = filter_var( $_REQUEST['db_user'], FILTER_SANITIZE_STRING );
+ $this->db_password = filter_var( $_REQUEST['db_password'], FILTER_SANITIZE_STRING );
+ $this->connectPostgresDb( $this->db_host, $this->db_name, $this->db_user, $this->db_password );
// Get list of contact interest
// From old database
}
// Get contacts
- $sql = "
- SELECT *
+ $statsSql = "SELECT count(*)";
+ $sql = "SELECT *";
+ $baseSql = "
FROM contacts.contact
WHERE email != ''
AND email is not null
- AND create_date >= '2014-01-01'
- AND contact_type not like '%3'";
- $contacts = $this->dbh->query( $sql )->fetchAll( PDO::FETCH_ASSOC );
+ AND create_date >= '09/01/2018'";
+ $statsSql .= $baseSql;
+ $sql .= $baseSql . " LIMIT " . $this->limit . " OFFSET $start";
+ $contactStats = $this->dbh->query( $statsSql )->fetchColumn();
+ $contacts = $this->dbh->query( $sql )->fetchAll( PDO::FETCH_ASSOC );
+ $totalFetched = count( $contacts );
+
+ if ( $totalFetched ) {
+ $this->next = $start + $totalFetched;
+ } else {
+ $this->completed = true;
+ }
+
+
foreach ( $contacts as $contact ) {
// Check to see if a lead with this email address exists.
$lead_id = $this->wpdb->get_var(
}
}
- return '<pre>
+ $return = '<pre>
New leads: ' . $new_leads . '
- Updated Leads: ' . $updated_leads . '</pre>';
+ Updated Leads: ' . $updated_leads . '
+ Total Contacts: ' . $contactStats . '
+ Total Fetched: ' . $totalFetched . '
+ </pre>';
+
+ return $return;
}
public function importInterests()
<a id="glm-leads-sources" data-show-table="glm-table-sources" class="glm-settings-tab nav-tab {if $option2 == ''} nav-tab-active{/if}">Settings / Source List</a>
<a id="glm-leads-import" data-show-table="glm-table-import" class="glm-settings-tab nav-tab">Gravity Forms</a>
<a id="glm-leads-importleads" data-show-table="glm-table-setupInterests" class="glm-settings-tab nav-tab{if $result && $option2 == 'setupInterests'} nav-tab-active{/if}">Setup Interests</a>
- <a id="glm-leads-importleads" data-show-table="glm-table-importleads" class="glm-settings-tab nav-tab{if $result && $option2 == 'importleads'} nav-tab-active{/if}">Import Leads</a>
+ <a id="glm-leads-importleads" data-show-table="glm-table-importleads" class="glm-settings-tab nav-tab{if $result && $option2 == 'importleads'} nav-tab-active{/if}" >Import Leads</a>
{* <a id="glm-leads-importmemberleads" data-show-table="glm-table-importmemberleads" class="glm-settings-tab nav-tab{if $result && $option2 == 'importmemberleads'} nav-tab-active{/if}">Import Member Leads</a> *}
{* <a id="glm-leads-redozip" data-show-table="glm-table-redozip" class="glm-settings-tab nav-tab{if $option2 == 'redozip'} nav-tab-active{/if}">Redo Zip</a> *}
</h2>
</table>
</form>
-<form action="{$thisUrl}?page={$thisPage}&glm_action=leads&option=import&option2=importleads" method="post">
+<form id="leadImportForm" action="{$thisUrl}?page={$thisPage}&glm_action=leads&option=import&option2=importleads" method="post">
<input type="hidden" name="glm_action" value="leads" />
<input type="hidden" name="option" value="import" />
<input type="hidden" name="option2" value="importleads" />
+ {if $db_host}<input type="hidden" name="db_host" value="{$db_host}" />{/if}
+ {if $db_name}<input type="hidden" name="db_name" value="{$db_name}" />{/if}
+ {if $db_user}<input type="hidden" name="db_user" value="{$db_user}" />{/if}
+ {if $db_password}<input type="hidden" name="db_password" value="{$db_password}" />{/if}
+ {if $next}<input type="hidden" name="start" value="{$next}" />{/if}
<table id="glm-table-importleads" class="glm-admin-table glm-settings-table{if $option2 != 'importleads'} glm-hidden{/if}">
{if !$result}
<tr>
<tr>
<td>{$result}</td>
</tr>
+ <tr>
+ <td colspan="2"><input type="submit" value="Next 50" /></td>
+ </tr>
{/if}
</table>
</form>
<script>
jQuery(document).ready(function($){
+
/*
* Edit area tabs
*/
});
- // Flash certain elements for a short time after display
- $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+ {if isset( $next ) && $next}
+ $('#leadImportForm').submit();
+ {/if}
+
+ // Flash certain elements for a short time after display
+ $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
});
</script>