Adding uptra feature for importing cleaned leads.
New management option for letting members only view cleaned leads.
define('GLM_MEMBERS_LEADS_PLUGIN_SLUG', 'glm-member-db-leads');
define('GLM_MEMBERS_LEADS_PLUGIN_IMPORT_OPTION', 'glm_member_db_leads_import_option');
define('GLM_MEMBERS_LEADS_PLUGIN_MEMBER_ACCESS_OPTION', 'glm_member_db_leads_member_access');
+define('GLM_MEMBERS_LEADS_PLUGIN_CLEANED_LEADS', 'glm_member_db_leads_cleaned');
// Database table prefixes - change if using add-on tables
global $wpdb;
* version from this plugin.
*/
define('GLM_MEMBERS_LEADS_PLUGIN_VERSION', '1.1.3');
-define('GLM_MEMBERS_LEADS_PLUGIN_DB_VERSION', '0.0.7');
+define('GLM_MEMBERS_LEADS_PLUGIN_DB_VERSION', '0.0.8');
// This is the minimum version of the GLM Members DB plugin require for this plugin.
define('GLM_MEMBERS_LEADS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.11.0');
class GlmMembersAdmin_leads_index extends GlmDataLeadEntry
{
+ const CSV_CHARS_PER_LINE = 6000;
/**
* WordPress Database Object
*
public $config;
public $entryId = false;
+
+ public $imported = 0;
+
+ public $updated = 0;
+ /**
+ * Default headers
+ */
+ public $defaultHeaders = array(
+ 'contact_id',
+ 'fname',
+ 'lname',
+ 'company',
+ 'address',
+ 'address2',
+ 'city',
+ 'state',
+ 'zip',
+ 'phone',
+ 'fax',
+ 'email',
+ );
/*
* Constructor
*
$updating_error = false;
$inserting = false;
$inserting_error = false;
+ $processingLeads = false;
+ $message = '';
+ $mLeadCleanedAccess = get_option( GLM_MEMBERS_LEADS_PLUGIN_CLEANED_LEADS );
// Get any provided option
if ( isset( $_REQUEST['option'] ) ) {
$grouped_interests = array();
switch ( $option ) {
+
+ case 'import':
+ $view = 'import.html';
+
+ // Initialize Variables for counts
+ $verifyHeaders = false;
+ $imported = 0;
+ $updated = 0;
+
+ if ( isset( $_FILES ) ) {
+ // $message .= '<pre>$_FILES: ' . print_r( $_FILES, true ) . '</pre>';
+ // Set variable for the upload directory
+ $wpUploadDir = wp_get_upload_dir();
+
+ // Set the $uploadPath for import files
+ $uploadPath = $wpUploadDir['basedir'] . '/' . 'glm-member-leads';
+
+ // If the folder for the upload import files doesn't exists create one.
+ if ( !is_dir( $uploadPath ) ) {
+ // Get old umask
+ $oldMask = umask( 0 );
+ // Set folder permission
+ mkdir( $uploadPath, 0770 );
+ // reset old umask
+ umask( $oldMask );
+ }
+
+ // read file data
+ $fileHasHeaders = false;
+ if ( !$_FILES['file']['error'] ) {
+ $fileName = $_FILES['file']['name'];
+ if ( move_uploaded_file( $_FILES['file']['tmp_name'], $uploadPath . '/' . $fileName ) ) {
+ $headers = $this->readCSVFileHeaders( $uploadPath . '/' . $fileName );
+ // Need to test if the first line is a header line
+ if ( is_array( $headers ) && !empty( $headers ) ) {
+ if ( isset( $headers[0] ) && $headers[0] ) {
+ if ( $headers[0] === 'contact_id' ) {
+ $fileHasHeaders = true;
+ }
+ }
+ } else {
+ // Error
+ }
+ if ( $fileHasHeaders ) {
+ // $message .= '<pre>$headers: ' . print_r( $headers, true ) . '</pre>';
+ $leads = $this->readCsvContacts( $uploadPath . '/' . $fileName, $headers );
+ } else {
+ // $message .= '<pre>$headers: ' . print_r( $this->defaultHeaders, true ) . '</pre>';
+ $leads = $this->readCsvContacts( $uploadPath . '/' . $fileName, $this->defaultHeaders, true );
+ }
+
+ // Set processingLeads to true
+ $processingLeads = true;
+ $this->processLeads( $leads );
+
+ if ( $leads ) {
+ // $message .= '<pre>$leads: ' . print_r( $leads, true ) . '</pre>';
+ $message .= '<p>Total Imported: ' . $this->imported . '</p>';
+ $message .= '<p>Total Updated: ' . $this->updated . '</p>';
+ }
+ }
+ }
+ }
+ $templateData = array(
+ 'user_can_edit_leads' => $user_can_edit_leads,
+ 'processing_leads' => $processingLeads,
+ 'message' => $message,
+ );
+ break;
+
case 'csv':
// Initialize.
$out = array();
foreach ( $interest_field_data as $int_field ) {
$interest_fields[$int_field['id']] = html_entity_decode( $int_field['title'] );
}
- // echo '<pre>$interest_fields: ' . print_r( $interest_fields, true ) . '</pre>';
// Generate the output for the csv file
if ( isset( $leads ) && is_array( $leads ) && !empty( $leads ) ) {
$lead['source_id']
)
);
- $out = array(
- 'fname' => $lead['fname'],
- 'lname' => $lead['lname'],
- 'email' => $lead['email'],
- 'addr1' => $lead['addr1'],
- 'addr2' => $lead['addr2'],
- 'city' => $lead['city'],
- 'state' => $lead['state'],
- 'zip' => $lead['zip'],
- 'country' => $lead['country'],
- 'phone' => $lead['phone'],
- 'phone2' => $lead['phone2'],
- 'fax' => $lead['fax'],
- 'date_submitted' => $lead['date_submitted'],
- 'source' => $source_name,
- );
+ $out = array();
+ if ( $user_can_edit_leads && $mLeadCleanedAccess ) {
+ $out['contact_id'] = $lead['id'];
+ $out['fname'] = $lead['fname'];
+ $out['lname'] = $lead['lname'];
+ $out['company'] = $lead['org'];
+ $out['address'] = $lead['addr1'];
+ $out['address2'] = $lead['addr2'];
+ $out['city'] = $lead['city'];
+ $out['state'] = $lead['state'];
+ $out['zip'] = $lead['zip'];
+ $out['phone'] = $lead['phone'];
+ $out['fax'] = $lead['fax'];
+ $out['email'] = $lead['email'];
+ $out['create_date'] = $lead['date_submitted'];
+ $out['contact_type'] = $source_name;
+ } else {
+ $out['fname'] = $lead['fname'];
+ $out['lname'] = $lead['lname'];
+ $out['email'] = $lead['email'];
+ $out['addr1'] = $lead['addr1'];
+ $out['addr2'] = $lead['addr2'];
+ $out['city'] = $lead['city'];
+ $out['state'] = $lead['state'];
+ $out['zip'] = $lead['zip'];
+ $out['country'] = $lead['country'];
+ $out['phone'] = $lead['phone'];
+ $out['phone2'] = $lead['phone2'];
+ $out['fax'] = $lead['fax'];
+ $out['date_submitted'] = $lead['date_submitted'];
+ $out['source'] = $source_name;
+ }
+
// Add fields for all interest fields
if ( $interest_field_data ) {
foreach ( $interest_fields as $int_field_id => $int_field_title ) {
$out["$int_field_title"] = '';
}
}
- // Add fields for group names
- // if ( $groups ) {
- // foreach ( $groups as $group ) {
- // $out[$group['title']] = '';
- // }
- // }
if ( !$user_can_edit_leads ) {
unset(
$out['source']
foreach ( $interest_fields as $int_field_id => $int_field_title ) {
$out["$int_field_title"] = ( $interest_by_groups["$int_field_title"] ) ? $int_field_title : '';
}
- // if ( $interest_by_groups ) {
- // foreach ( $interest_by_groups as $group_name => $group_interest ) {
- // $out[$group_name] = implode( ';', $group_interest );
- // }
- // }
}
// First line should be the header line
if ( $lead_counter === 0 ) {
'leads' => $leads,
);
break;
- }
+ } // end of switch $option
// Fetch the sources
$sources = $this->wpdb->get_results(
}
// Common things to place into the $templateData array
+ $templateData['option'] = $option;
$templateData['sources'] = $sources;
$templateData['grouped_interests'] = $grouped_interests;
$templateData['haveLeads'] = $haveLeads;
$templateData['updating_error'] = $updating_error;
$templateData['inserting'] = $inserting;
$templateData['inserting_error'] = $inserting_error;
+ $templateData['leadCleanedAccess'] = $mLeadCleanedAccess;
$templateData['prev']
= ( isset( $_REQUEST['prevStart'] ) )
? $_REQUEST['prevStart']
}
+ /**
+ * Read in contacts from a csv file
+ *
+ * Header line as follows. Data follows immediately below this line. this
+ * line and all above it are ignored.
+ *
+ * 'member_id','member_name','member_login','member_passwd','contact_email'
+ *
+ * @param string $csv Temporary file name of csv file upload
+ *
+ * @return array Array of data from CSV file or an error message
+ */
+ public function readCsvContacts( $csv, $headers, $skip = false )
+ {
+ $contacts = array();
+ $startImport = false;
+ if ( $skip === true ) {
+ $startImport = true;
+ }
+
+ // Try to open file
+ if ( ( $handle = fopen( $csv, "r" ) ) !== false ) {
+
+ $firstContact = true;
+
+ // For each line in the file
+ while ( ( $c = fgetcsv( $handle, SELF::CSV_CHARS_PER_LINE, "," ) ) !== false ) {
+
+ if ( $skip == true && $firstContact === true ) {
+ // Pad the header array
+ $headers = array_pad( $headers, count($c), '' );
+ }
+ $firstContact = false;
+
+ // If we're past the header, the first item is numeric, and we have at least 5 fields
+ if( $startImport && ( $c[0]-0 ) > 0 && count( $c ) >= 5 ) {
+ // Add this line of data to Contacts
+ $contacts[] = array_combine( $headers, $c );
+ }
+
+ // If we find the header, assume all data is below that
+ if ( $c[0] == 'contact_id' && $c[1] == 'fname' && $skip === false ) {
+ $startImport = true;
+ }
+
+ }
+
+ fclose( $handle );
+
+ } else {
+ return "No file submitted.";
+ }
+
+ // If we never found the header
+ if ( !$startImport ) {
+ return "Required header not found in file.";
+ }
+
+ // If we found no data below the header
+ if ( count( $contacts ) == 0 ) {
+ return "Header found but no data followed";
+ }
+
+ return $contacts;
+ }
+
+ /**
+ * readCSVFileHeaders
+ *
+ * Read the cvs file. Just the first line is read.
+ *
+ * @param mixed $fileName Name of the file (path)
+
+ * @access public
+ * @return array
+ */
+ public function readCSVFileHeaders( $fileName )
+ {
+ $fileHeaders = array();
+ if ( ( $fp = fopen( $fileName, 'r' ) ) !== false ) {
+ // get first line to use as headers
+ $fileHeaders = fgetcsv( $fp, SELF::CSV_CHARS_PER_LINE, ',' );
+ fclose( $fp );
+ }
+
+ return array_map( 'strtolower', $fileHeaders );
+ }
+
+ /**
+ * processLeads
+ *
+ * Do imports and updates to lead_entry records
+ *
+ * @param mixed $data Array of lead data
+ *
+ * @access public
+ * @return string
+ */
+ public function processLeads( $data )
+ {
+ // email cannot be in this array.
+ $validFields = array(
+ 'fname' => 'fname',
+ 'lname' => 'lname',
+ 'company' => 'org',
+ 'address' => 'addr1',
+ 'address2' => 'addr2',
+ 'city' => 'city',
+ 'state' => 'state',
+ 'zip' => 'zip',
+ 'phone' => 'phone',
+ 'fax' => 'fax',
+ );
+ if ( isset( $data ) && is_array( $data ) && !empty( $data ) ) {
+ foreach ( $data as $key => $val ) {
+ $leadData = array();
+ // find lead entry
+ $leadId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_entry
+ WHERE id = %d",
+ $val['contact_id']
+ )
+ );
+ foreach ( $validFields as $field => $fieldName ) {
+ if ( isset( $val[$field] ) ) {
+ $leadData[$fieldName] = $val[$field];
+ $leadFormat[] = '%s';
+ }
+ }
+ // echo '<pre>$leadData: ' . print_r( $leadData, true ) . '</pre>';
+ // echo '<pre>$leadId: ' . print_r( $leadId, true ) . '</pre>';
+ // return false;
+ if ( isset( $leadData ) && !empty( $leadData ) ) {
+ $leadData['cleaned'] = true;
+ $leadFormat[] = '%s';
+ if ( $leadId ) {
+ // Check that email matches
+ $email = $this->getEmailByEntryId( $leadId );
+ // echo '<pre>$email: ' . print_r( $email, true ) . '</pre>';
+ if ( isset( $val['email'] )
+ && $val['email']
+ && $val['email'] != $email
+ ) {
+ // If it doesn't match then find lead id for that email or add one
+ $this->addNewLead( $val['email'], $leadData, $leadFormat );
+ $this->imported++;
+ } else {
+ // Update this entry
+ $this->wpdb->update(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry',
+ $leadData,
+ array( 'id' => $val['contact_id'] ),
+ $leadFormat,
+ array( '%d' )
+ );
+ $this->updated++;
+ }
+ } else {
+ $this->addNewLead( $val['email'], $leadData, $leadFormat );
+ $this->imported++;
+ }
+ }
+ } // end foreach $data
+ } // end if $data
+ }
+
+ public function getLeadIdByEmail( $email )
+ {
+ if ( !isset( $email ) && !$email ) {
+ return false;
+ }
+ $leadId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE email = %s",
+ $email
+ )
+ );
+ return $leadId;
+ }
+
+ public function getEmailByEntryId( $entryId )
+ {
+ if ( !isset( $entryId ) && !$entryId ) {
+ return false;
+ }
+ $email = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT email
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE id = (SELECT lead_id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_entry
+ WHERE id = %d)",
+ $entryId
+ )
+ );
+ return $email;
+ }
+
+ public function getAdminSourceId()
+ {
+ static $sourceId;
+ if ( $sourceId ) {
+ return $sourceId;
+ }
+ $sourceId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "sources
+ WHERE title = %s",
+ 'Admin'
+ )
+ );
+ return $sourceId;
+ }
+
+ public function addNewLead( $email, $data, $format )
+ {
+ if ( !isset( $email ) && !$email ) {
+ return false;
+ }
+ $leadId = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE email = %s",
+ $email
+ )
+ );
+ if ( !$leadId ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'leads',
+ array(
+ 'email' => $email,
+ 'created' => date( 'Y-m-d H:i' ),
+ 'mail_ok' => true,
+ 'member_ok' => true,
+ ),
+ array(
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ )
+ );
+ $leadId = $this->insert_id;
+ }
+ if ( $leadId ) {
+ $data['lead_id'] = $leadId;
+ $format[] = '%d';
+ $data['source_id'] = $this->getAdminSourceId();
+ $data['cleaned_imported'] = true;
+ $format[] = '%s';
+ $data['date_submitted'] = date( 'Y-m-d' );
+ $format[] = '%s';
+
+ // Insert this entry
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry',
+ $data,
+ $format
+ );
+
+ }
+ return $leadId;
+ }
}
if ( isset( $_REQUEST['member_can_access_leads'] ) ) {
$memberCanAccessLeads = filter_var( $_REQUEST['member_can_access_leads'], FILTER_VALIDATE_BOOLEAN );
}
+ if ( isset( $_REQUEST['member_only_cleaned_leads'] ) ) {
+ $mLeadCleanedAccess = filter_var( $_REQUEST['member_only_cleaned_leads'], FILTER_VALIDATE_BOOLEAN );
+ }
update_option( GLM_MEMBERS_LEADS_PLUGIN_MEMBER_ACCESS_OPTION, $memberCanAccessLeads );
+ update_option( GLM_MEMBERS_LEADS_PLUGIN_CLEANED_LEADS, $mLeadCleanedAccess );
$settingsUpdated = true;
break;
default:
}
$memberCanAccessLeads = get_option( GLM_MEMBERS_LEADS_PLUGIN_MEMBER_ACCESS_OPTION );
+ $mLeadCleanedAccess = get_option( GLM_MEMBERS_LEADS_PLUGIN_CLEANED_LEADS );
switch( $option2 ) {
'offset' => $offset,
'next_offset' => $next_offset,
'mLeadAccess' => $memberCanAccessLeads,
+ 'mLeadCleanedAccess' => $mLeadCleanedAccess,
'settingsUpdated' => $settingsUpdated,
'settingsUpdateError' => $settingsUpdateError,
'db_host' => $this->db_host,
+++ /dev/null
--- Gaslight Media Members Database - Leads
--- File Created: 16/07/19 16:16:16
--- Database Version: 0.0.3
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- Leads
-CREATE TABLE {prefix}leads (
- id INT NOT NULL AUTO_INCREMENT,
- email TINYTEXT NULL, -- Email address of lead
- mail_ok BOOLEAN NULL, -- OK to send them E-Mail
- member_ok BOOLEAN NULL, -- OK to have members contact lead
- created DATETIME NULL, -- Timestamp lead was first added
- PRIMARY KEY (id),
- INDEX (email(20))
-);
-
-----
-
--- Sources - info on form or method via which lead can be submitted
-CREATE TABLE {prefix}sources (
- id INT NOT NULL AUTO_INCREMENT,
- title TINYTEXT NULL, -- Title/Name of source for reference
- code TINYTEXT NULL, -- Code supplied by form to indicate source
- form_id INT NULL,
- enabled BOOLEAN NULL,
- PRIMARY KEY (id),
- INDEX (code(20))
-);
-
-----
-
--- Lead Entry - Information on a single submission of lead information
-CREATE TABLE {prefix}lead_entry (
- id INT NOT NULL AUTO_INCREMENT,
- source_id SMALLINT NULL, -- Pointer to sources entry - Form used to submit lead data
- lead_id INTEGER NULL, -- Pointer to lead - all submissions for same E-Mail address point to same leads entry
- gf_entry_id INTEGER NULL, -- Reference to Gravity Form Entry
- fname TINYTEXT NULL, -- First Name
- lname TINYTEXT NULL, -- Last Name
- org TINYTEXT NULL, -- Organization name
- addr1 TINYTEXT NULL, -- Address line 1
- addr2 TINYTEXT NULL, -- Address line 2
- city TINYTEXT NULL, -- City name
- state TINYTEXT NULL, -- State/Province - as submitted by Gravityforms or whatever (not state code)
- zip TINYTEXT NULL, -- ZIP/Postal code
- country TINYTEXT NULL, -- Country name - as submitted by form (not country code)
- phone TINYTEXT NULL, -- Primary phone #
- phone2 TINYTEXT NULL, -- Alternate phone #
- fax TINYTEXT NULL, -- Fax #
- how_heard SMALLINT NULL, -- Pointer to how_heard table entry
- visit_date DATE NULL, -- Anticipated date of visit
- date_submitted DATE NULL, -- Date this information was submitted
- user_trace_info TINYTEXT NULL, -- User IP address and other identifying network info (pos referrer)
- PRIMARY KEY (id),
- INDEX (source_id),
- INDEX (lead_id),
- INDEX (fname(20)),
- INDEX (lname(20)),
- INDEX (visit_date),
- INDEX (date_submitted)
-);
-
-----
-
--- Interest Groups
-CREATE TABLE {prefix}interest_groups (
- id INT NOT NULL AUTO_INCREMENT,
- title TINYTEXT NULL, -- Group name
- members BOOLEAN DEFAULT '0',
- PRIMARY KEY (id)
-);
-
-----
-
--- Interests - Used to build Interest fields in forms - Forms use ID as value
-CREATE TABLE {prefix}interests (
- id INT NOT NULL AUTO_INCREMENT,
- title TINYTEXT NULL, -- Title
- group_id SMALLINT NULL, -- Pointer to interest group
- PRIMARY KEY (id),
- INDEX (group_id)
-);
-
-----
-
--- GF Interests - Used to relate the Gravity Form field id for interests
-CREATE TABLE {prefix}gf_interests (
- id INT NOT NULL AUTO_INCREMENT,
- interest_id INTEGER NULL, -- Id for the interests
- gf_field_id TINYTEXT NULL, -- The field id from gravity forms for this interest
- form_id INT NULL, -- The Gravity Form Id
- PRIMARY KEY (id),
- INDEX (gf_field_id(6)),
- INDEX (interest_id),
- INDEX (form_id)
-);
-
-----
-
--- Lead Interests - many to one links to lead-entry table
-CREATE TABLE {prefix}lead_interests (
- id INT NOT NULL AUTO_INCREMENT,
- interest_id SMALLINT NULL, -- Pointer to Interest table
- lead_entry_id INTEGER NULL, -- Pointer to lead_entry table
- PRIMARY KEY (id),
- INDEX (interest_id),
- INDEX (lead_entry_id)
-);
-
-----
-
--- lead_searches - Memorized search configurations
-CREATE TABLE {prefix}searches (
- id INT NOT NULL AUTO_INCREMENT,
- user_id INT NOT NULL, -- The wordpress user id
- title TINYTEXT NULL, -- Title for this search configuration
- search TEXT NULL, -- Serialized array of search parameters
- date_created DATE NULL, -- Date the search type was created
- PRIMARY KEY (id)
-);
-
-----
-
--- Lead Stats Data - Totals of lead stats - Preserved for 2 years
-CREATE TABLE {prefix}lead_stats (
- id INT NOT NULL AUTO_INCREMENT,
- stat_type TINYTEXT NULL, -- Type of stat Daily, Weekly, Monthly...
- stat_date DATE NULL, -- Date for which these stats are accumulated
- leads_count INTEGER NULL, -- Number of leads
- PRIMARY KEY (id),
- INDEX (stat_type(10)),
- INDEX (stat_date)
-);
--- /dev/null
+-- Gaslight Media Members Database - Leads
+-- File Created: 16/07/19 16:16:16
+-- Database Version: 0.0.3
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- Leads
+CREATE TABLE {prefix}leads (
+ id INT NOT NULL AUTO_INCREMENT,
+ email TINYTEXT NULL, -- Email address of lead
+ mail_ok BOOLEAN NULL, -- OK to send them E-Mail
+ member_ok BOOLEAN NULL, -- OK to have members contact lead
+ created DATETIME NULL, -- Timestamp lead was first added
+ PRIMARY KEY (id),
+ INDEX (email(20))
+);
+
+----
+
+-- Sources - info on form or method via which lead can be submitted
+CREATE TABLE {prefix}sources (
+ id INT NOT NULL AUTO_INCREMENT,
+ title TINYTEXT NULL, -- Title/Name of source for reference
+ code TINYTEXT NULL, -- Code supplied by form to indicate source
+ form_id INT NULL,
+ enabled BOOLEAN NULL,
+ PRIMARY KEY (id),
+ INDEX (code(20))
+);
+
+----
+
+-- Lead Entry - Information on a single submission of lead information
+CREATE TABLE {prefix}lead_entry (
+ id INT NOT NULL AUTO_INCREMENT,
+ source_id SMALLINT NULL, -- Pointer to sources entry - Form used to submit lead data
+ lead_id INTEGER NULL, -- Pointer to lead - all submissions for same E-Mail address point to same leads entry
+ gf_entry_id INTEGER NULL, -- Reference to Gravity Form Entry
+ fname TINYTEXT NULL, -- First Name
+ lname TINYTEXT NULL, -- Last Name
+ org TINYTEXT NULL, -- Organization name
+ addr1 TINYTEXT NULL, -- Address line 1
+ addr2 TINYTEXT NULL, -- Address line 2
+ city TINYTEXT NULL, -- City name
+ state TINYTEXT NULL, -- State/Province - as submitted by Gravityforms or whatever (not state code)
+ zip TINYTEXT NULL, -- ZIP/Postal code
+ country TINYTEXT NULL, -- Country name - as submitted by form (not country code)
+ phone TINYTEXT NULL, -- Primary phone #
+ phone2 TINYTEXT NULL, -- Alternate phone #
+ fax TINYTEXT NULL, -- Fax #
+ how_heard SMALLINT NULL, -- Pointer to how_heard table entry
+ visit_date DATE NULL, -- Anticipated date of visit
+ date_submitted DATE NULL, -- Date this information was submitted
+ user_trace_info TINYTEXT NULL, -- User IP address and other identifying network info (pos referrer)
+ cleaned BOOLEAN NULL, -- Cleaned lead
+ cleaned_imported BOOLEAN NULL, -- Cleaned lead - Imported
+ PRIMARY KEY (id),
+ INDEX (source_id),
+ INDEX (lead_id),
+ INDEX (fname(20)),
+ INDEX (lname(20)),
+ INDEX (visit_date),
+ INDEX (date_submitted)
+);
+
+----
+
+-- Interest Groups
+CREATE TABLE {prefix}interest_groups (
+ id INT NOT NULL AUTO_INCREMENT,
+ title TINYTEXT NULL, -- Group name
+ members BOOLEAN DEFAULT '0',
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Interests - Used to build Interest fields in forms - Forms use ID as value
+CREATE TABLE {prefix}interests (
+ id INT NOT NULL AUTO_INCREMENT,
+ title TINYTEXT NULL, -- Title
+ group_id SMALLINT NULL, -- Pointer to interest group
+ PRIMARY KEY (id),
+ INDEX (group_id)
+);
+
+----
+
+-- GF Interests - Used to relate the Gravity Form field id for interests
+CREATE TABLE {prefix}gf_interests (
+ id INT NOT NULL AUTO_INCREMENT,
+ interest_id INTEGER NULL, -- Id for the interests
+ gf_field_id TINYTEXT NULL, -- The field id from gravity forms for this interest
+ form_id INT NULL, -- The Gravity Form Id
+ PRIMARY KEY (id),
+ INDEX (gf_field_id(6)),
+ INDEX (interest_id),
+ INDEX (form_id)
+);
+
+----
+
+-- Lead Interests - many to one links to lead-entry table
+CREATE TABLE {prefix}lead_interests (
+ id INT NOT NULL AUTO_INCREMENT,
+ interest_id SMALLINT NULL, -- Pointer to Interest table
+ lead_entry_id INTEGER NULL, -- Pointer to lead_entry table
+ PRIMARY KEY (id),
+ INDEX (interest_id),
+ INDEX (lead_entry_id)
+);
+
+----
+
+-- lead_searches - Memorized search configurations
+CREATE TABLE {prefix}searches (
+ id INT NOT NULL AUTO_INCREMENT,
+ user_id INT NOT NULL, -- The wordpress user id
+ title TINYTEXT NULL, -- Title for this search configuration
+ search TEXT NULL, -- Serialized array of search parameters
+ date_created DATE NULL, -- Date the search type was created
+ PRIMARY KEY (id)
+);
+
+----
+
+-- Lead Stats Data - Totals of lead stats - Preserved for 2 years
+CREATE TABLE {prefix}lead_stats (
+ id INT NOT NULL AUTO_INCREMENT,
+ stat_type TINYTEXT NULL, -- Type of stat Daily, Weekly, Monthly...
+ stat_date DATE NULL, -- Date for which these stats are accumulated
+ leads_count INTEGER NULL, -- Number of leads
+ PRIMARY KEY (id),
+ INDEX (stat_type(10)),
+ INDEX (stat_date)
+);
'0.0.5' => array('version' => '0.0.5', 'tables' => 10, 'date' => '7/22/2016'),
'0.0.6' => array('version' => '0.0.6', 'tables' => 11, 'date' => '7/22/2016'),
'0.0.7' => array('version' => '0.0.7', 'tables' => 9, 'date' => '7/26/2016'),
+ '0.0.8' => array('version' => '0.0.8', 'tables' => 9, 'date' => '5/10/2019'),
);
--- Gaslight Media Members Database - Events Add-On
+-- Gaslight Media Members Database - Leads Add-On
-- File Created: 16/07/19 16:16:16
-- Database Version: 0.0.3
-- Database Update From Previous Version Script
--- /dev/null
+-- Gaslight Media Members Database - Leads Add-On
+-- File Created: 05/10/19
+-- Database Version: 0.0.8
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+ALTER TABLE {prefix}lead_entry ADD COLUMN cleaned BOOLEAN NULL;
+
+----
+
+ALTER TABLE {prefix}lead_entry ADD COLUMN cleaned_imported BOOLEAN NULL;
<div class="wrap">
<h2>All Leads</h2>
<h2 class="nav-tab-wrapper">
- <a href="{$thisUrl}?page={$thisPage}&glm_action=index" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">Dashboard</a>
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=index" class="nav-tab{if $thisAction==index && $option != 'import'} nav-tab-active{/if}">Dashboard</a>
+ {if $user_can_edit_leads && $leadCleanedAccess}
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=index&option=import" class="nav-tab{if $option == 'import'} nav-tab-active{/if}">Import</a>
+ {/if}
</h2>
<div id="glm-admin-content-container">
-
-
\ No newline at end of file
+
--- /dev/null
+{include file='admin/leads/header.html'}
+
+{if !$processing_leads}
+ <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="{$thisAction}" />
+ <input type="hidden" name="page" value="{$thisPage}" />
+ <input type="hidden" name="option" value="{$option}" />
+ <table width="500">
+ <tr>
+ <td>
+ <p>The following script will work with the file that was downloaded from this site.
+ After the file has been Cleaned (Updated), it can be uploaded. This will only update the following fields.
+ </p>
+ <ol>
+ <li>First Name</li>
+ <li>Last Name</li>
+ <li>Email</li>
+ <li>Address 1</li>
+ <li>Address 2</li>
+ <li>City</li>
+ <li>State</li>
+ <li>ZIP</li>
+ <li>Country</li>
+ <li>Phone</li>
+ <li>Phone 2</li>
+ <li>Fax</li>
+ </ol>
+ <p>The recordid field is used to properly update the correct contact.</p>
+ <p>Your results will be displayed once the file has been uploaded and database is updated.</p>
+ <p style="font-weight:bold">Sample header of file to be imported</p>
+ <p>recordid,fname,lname,email,addr1,addr2,city,state,zip,country,phone,phone2,fax</p>
+ <p style="font-weight:bold">You can have more fields but these are required in the file</p>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <input type="file" name="file">
+ <input type="submit" name="submit" value="Upload File">
+ </td>
+ </tr>
+ </table>
+ </form>
+{else}
+ {$message}
+{/if}
+
+{include file='admin/footer.html'}
<input type="hidden" name="limit" value="{$limit}" />
<table style="width: 800px;" id="lead-search-form"{if $searching} class="hide"{/if}>
{if $user_can_edit_leads}
- <tr>
- <td style="text-align: right;"><label for="glm-form-source_id">Source</label></td>
- <td>
- {if $sources}
- <select id="glm-form-source_id" name="source_id">
- <option value=""></option>
- {foreach $sources as $source}
- <option value="{$source.id}" {if $source.selected} selected{/if}>{$source.title}</option>
- {/foreach}
- </select>
- {/if}
- </td>
- </tr>
- <tr>
- <td style="text-align: right;"><label for="glm-form-contact">Name</label></td>
- <td><input type="text" id="glm-form-contact" name="contact" value="{$search_params.contact}"></td>
- </tr>
+ <tr>
+ <td style="text-align: right;"><label for="glm-form-source_id">Source</label></td>
+ <td>
+ {if $sources}
+ <select id="glm-form-source_id" name="source_id">
+ <option value=""></option>
+ {foreach $sources as $source}
+ <option value="{$source.id}" {if $source.selected} selected{/if}>{$source.title}</option>
+ {/foreach}
+ </select>
+ {/if}
+ </td>
+ </tr>
+ <tr>
+ <td style="text-align: right;"><label for="glm-form-contact">Name</label></td>
+ <td><input type="text" id="glm-form-contact" name="contact" value="{$search_params.contact}"></td>
+ </tr>
{/if}
<tr>
<th colspan="2">Date Range</th>
<td><input type="text" id="glm-form-to_date" name="to_date" value="{$search_params.to_date}"></td>
</tr>
{if $user_can_edit_leads}
- <tr>
- <td style="text-align: right;"><label>Mail Ok</label></td>
- <td>
- <select id="glm-form-mail_ok" name="mail_ok">
- <option value="">Choose</option>
- <option value="1" {if $search_params.mail_ok == '1'}selected{/if}>Yes</option>
- <option value="0" {if $search_params.mail_ok === 0}selected{/if}>No</option>
- </select>
- </td>
- </tr>
+ <tr>
+ <td style="text-align: right;"><label>Mail Ok</label></td>
+ <td>
+ <select id="glm-form-mail_ok" name="mail_ok">
+ <option value="">Choose</option>
+ <option value="1" {if $search_params.mail_ok == '1'}selected{/if}>Yes</option>
+ <option value="0" {if $search_params.mail_ok === 0}selected{/if}>No</option>
+ </select>
+ </td>
+ </tr>
<tr>
<td style="text-align: right;"><label>Member Ok</label></td>
<td>
<td colspan="2">
<strong style="width: 100%; text-align: left;display: block;">{$group_name}</strong>
{foreach $group as $interest}
- <label style="display: block;width: 30%; float: left;">
- <input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}
- </label>
- {/foreach}
+ <label style="display: block;width: 30%; float: left;">
+ <input type="checkbox" name="interests[{$interest.id}]" {if $interest.selected} checked{/if}>{$interest.title}
+ </label>
+ {/foreach}
</td>
</tr>
{/foreach}
<br clear="all">
<p><b>Total found:</b> {$leadCount} </p>
- {if $paging}
- <input type="Submit" name="pageSelect" value="Previous {$limit} Leads" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
- <input type="Submit" name="pageSelect" value="Next {$limit} Leads" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
- {/if}
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} Leads" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} Leads" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
<table class="wp-list-table striped glm-admin-table">
<thead>
<tr>
<th>Contact</th>
- {if $user_can_edit_leads}
- <th>Source</th>
- {/if}
+ {if $user_can_edit_leads}
+ <th>Source</th>
+ {/if}
<th>Submitted</th>
</tr>
</thead>
{/if}
<tbody>
</table>
- {if $paging}
- <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
- <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
- {/if}
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
{else if $searching}
<strong>Sorry, Nothing matches your search.</strong>
{/if}
</label>
</td>
</tr>
+ <tr>
+ <th>Members only allowed Cleaned leads:</th>
+ <td>
+ <input type="hidden" name="member_only_cleaned_leads" value="0">
+ <label>
+ <input type="checkbox" name="member_only_cleaned_leads" value="1" {if $mLeadCleanedAccess}checked{/if} /> Yes
+ </label>
+ </td>
+ </tr>
<tr>
<td colspan="2"><input type="submit" value="Update" /></td>
</tr>