* @release leadss.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
* @link http://dev.gaslightmedia.com/
*/
+require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterests.php';
require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterestGroups.php';
/**
switch( $option2 ) {
+ case 'importmemberleads':
+ $result .= '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ // $this->importMemberCategories();
+ $result .= $this->importMemberLeads();
+ break;
case 'importleads':
$result .= '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
$result .= $this->importLeads();
);
}
+ public function setupFormInterests()
+ {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'gf_interests',
+ array(
+ 'interest_id' => $interest_id,
+ 'gf_field_id' => $gf_field_id,
+ 'form_id' => $form_id
+ ),
+ array( '%d', '%s', '%d' )
+ );
+ }
+
+ public function importMemberCategories()
+ {
+ // Create Leads Category group_name
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'interest_groups',
+ array( 'title' => 'Lead Categories' ),
+ array( '%s' )
+ );
+ $terms = get_terms( 'member-lead-cat' );
+
+ foreach ( $terms as $term ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'interests',
+ array( 'title' => $term->name, 'group_id' => 1 ),
+ array( '%s', '%d' )
+ );
+ }
+ }
+
+ public function resetData()
+ {
+ $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" );
+ $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests" );
+ }
+
+ public function importMemberLeads()
+ {
+ $limit = 10;
+ $start = ( isset( $_REQUEST['start'] ) ) ? (int)filter_var( $_REQUEST['start'] ) : 0;
+ if ( $start === 0 ) {
+ $this->resetData();
+ }
+ // Grab the interest.
+ $Interest = new GlmDataInterests( $this->wpdb, $this->config );
+ $intData = $Interest->getList();
+ $interests = array();
+ if ( $intData ) {
+ foreach ( $intData as $interest ) {
+ // $interests[$interest['id']] = htmlspecialchars_decode( $interest['title'] );
+ $interests[$interest['id']] = $interest['title'];
+ }
+ }
+ $newEntries = 0;
+ // echo '<pre>$interests: ' . print_r( $interests, true ) . '</pre>';
+ // exit;
+ $source_id = 1; // Source id for the form
+
+ // get the total number of posts
+ $total_number = $this->wpdb->get_var(
+ "SELECT count(ID)
+ FROM " . $this->wpdb->prefix . "posts
+ WHERE post_type = 'member_lead'
+ AND post_status = 'publish'"
+ );
+ $completed = false;
+
+ $query =
+ "SELECT p.ID,p.post_title, pm1.meta_value AS 'fname', pm2.meta_value AS 'lname',
+ pm3.meta_value AS 'email', pm4.meta_value AS 'phone', pm5.meta_value AS 'address',
+ pm7.meta_value AS 'city', pm8.meta_value AS 'state', pm9.meta_value AS 'zip', p.post_date AS create_date, p.post_status
+ FROM wp_p6qnh6_posts p
+ INNER JOIN wp_p6qnh6_postmeta AS pm1 ON pm1.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm2 ON pm2.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm3 ON pm3.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm4 ON pm4.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm5 ON pm5.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm7 ON pm7.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm8 ON pm8.post_id = p.ID
+ INNER JOIN wp_p6qnh6_postmeta AS pm9 ON pm9.post_id = p.ID
+ WHERE pm1.meta_key = 'First Name'
+ AND pm2.meta_key = 'Last Name'
+ AND pm3.meta_key = 'Email'
+ AND pm4.meta_key = 'Phone'
+ AND pm5.meta_key = 'Address Line 1'
+ AND pm7.meta_key = 'City'
+ AND pm8.meta_key = 'State'
+ AND pm9.meta_key = 'Zip Code'
+ AND p.post_type = 'member_lead'
+ AND p.post_status = 'publish'";
+ $query .= " LIMIT $limit OFFSET $start";
+
+ $results = $this->wpdb->get_results( $query, ARRAY_A );
+ $return = '';
+ $return = '<pre>$results: ' . print_r( $results, true ) . '</pre>';
+ foreach ( $results as $contact ) {
+ $lead_categories = array();
+
+ // Check to see if a lead with this email address exists.
+ $lead_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE email = %s",
+ $contact['email']
+ )
+ );
+ // If the lead doesn't exists create it.
+ if ( !$lead_id ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX. 'leads',
+ array(
+ 'email' => $contact['email'],
+ 'mail_ok' => 1,
+ 'member_ok' => 1,
+ 'created' => $contact['create_date'],
+ ),
+ array( '%s', '%s', '%s', '%s' )
+ );
+ $lead_id = $this->wpdb->insert_id;
+ }
+ if ( $lead_id ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX. 'lead_entry',
+ array(
+ 'source_id' => $source_id,
+ 'lead_id' => $lead_id,
+ 'fname' => $contact['fname'],
+ 'lname' => $contact['lname'],
+ 'addr1' => $contact['address'],
+ 'city' => $contact['city'],
+ 'state' => $contact['state'],
+ 'zip' => $contact['zip'],
+ 'phone' => $contact['phone'],
+ 'fax' => $contact['fax'],
+ 'date_submitted' => $contact['create_date'],
+ ),
+ array(
+ '%d', // source id
+ '%d', // lead id
+ '%s', // first name
+ '%s', // last name
+ '%s', // address
+ '%s', // city
+ '%s', // state
+ '%s', // zip
+ '%s', // phone
+ '%s', // fax
+ '%s', // create date
+ )
+ );
+ $lead_entry_id = $this->wpdb->insert_id;
+ // echo '<pre>$lead_entry_id: ' . print_r( $lead_entry_id, true ) . '</pre>';
+ if ( $lead_entry_id ) {
+ $newEntries++;
+ // Get this row's terms
+ $terms = wp_get_post_terms(
+ $contact['ID'],
+ 'member-lead-cat'
+ );
+ $return .= '<pre>$terms: ' . print_r( $terms, true ) . '</pre>';
+ foreach ( $terms as $term ) {
+ $lead_categories[$term->term_id] = $term->name;
+ $int_key = array_search( $term->name, $interests );
+ // echo '<pre>';
+ // var_dump($int_key);
+ // echo '</pre>';
+ if ( $int_key !== false ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests',
+ array(
+ 'interest_id' => $int_key,
+ 'lead_entry_id' => $lead_entry_id
+ ),
+ array( '%d', '%d' )
+ );
+ }
+ }
+ // $return .= '<pre>$lead_categories: ' . print_r( $lead_categories, true ) . '</pre>';
+ }
+ }
+ }
+ $next = $start + $limit;
+ $return = "<p>Added $newEntries. </p>";
+ $next_url = 'admin.php?page=glm-members-admin-menu-management'
+ . '&glm_action=leads&option=import&option2=importmemberleads&start=' . $next;
+ $return .= '<a href="' . $next_url . '">Next</a>';
+ if ( $next > $total_number ) {
+ $completed = true;
+ }
+ if ( !$completed ) {
+ $return .= "<script> window.location.href = '" . $next_url. "'; </script>";
+ }
+ return $return;
+ }
+
/**
* importLeads
*
}
}
}
+ // echo '<pre>$gf_interests: ' . print_r( $gf_interests, true ) . '</pre>';
+ // echo '<pre>$_POST: ' . print_r( $_POST, true ) . '</pre>';
// have to go through the $form array to see what field we need from post
$glm_leads_entry = array();
if ( $form['fields'] ) {
}
}
}
+ // echo '<pre>$leads_fields: ' . print_r( $leads_fields, true ) . '</pre>';
// we need to have email field
if ( !isset( $glm_leads_entry['email'] ) || !$glm_leads_entry['email'] ) {
return;
$ints[$interest['id']] = htmlspecialchars_decode( $interest['title'] );
}
}
+ // echo '<pre>$ints: ' . print_r( $ints, true ) . '</pre>';
// Create the lead to interest entries.
// Using $leads_fields.
// First delete any they current have.
if ( is_array( $leads_fields) && !empty( $leads_fields ) ) {
foreach ( $leads_fields as $interest_val ) {
+ // echo '<pre>$interest_val: ' . print_r( $interest_val, true ) . '</pre>';
+
+ // for one type if checkboxes
+ // Here we have the interest id as interest_val
$int_key = array_search( $interest_val, array_keys( $ints ) );
if ( $int_key !== false ) {
$isGood = $this->wpdb->insert(
if ( !$isGood ) {
die( 'We did not get lead_interests id' );
}
+ // Here we now have the interest_val as pointer to
+ // the ints array, so we need the array key
+ } else {
+ // if lead type
+ $int_key = array_search( $interest_val, $ints );
+ if ( $int_key !== false ) {
+ $isGood = $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests',
+ array(
+ 'interest_id' => $int_key,
+ 'lead_entry_id' => $lead_entry_id
+ ),
+ array( '%d', '%d' )
+ );
+ if ( !$isGood ) {
+ die( 'We did not get lead_interests id' );
+ }
+ }
}
}
}