* @release frontHooks.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';
/*
* Place Misc Hooks and Filters here. If this file exists, it will be included
// Inject things into gravity forms fields - This intercepts all GravityForms before displaying them
add_filter( 'gform_pre_render', function( $form ) {
+ $inputs = $choices = array();
foreach ( $form['fields'] as $k => $v ) {
- //echo '<pre>$v[inputName]: ' . print_r($v['inputName'], true) . '</pre>';
- if ( $v['inputName'] == 'glm_interest' ) {
- $form['fields'][$k]['choices'] = array(
- 0 => array(
- 'text' => 'Skiing',
- 'value' => 'Skiing',
- 'isSelected' => false,
- 'price' => ''
- ),
- 1 => array(
- 'text' => 'Boating',
- 'value' => 'Boating',
- 'isSelected' => false,
- 'price' => ''
- ),
- 2 => array(
- 'text' => 'Hiking',
- 'value' => 'Hiking',
- 'isSelected' => false,
- 'price' => ''
- ),
- 3 => array(
- 'text' => 'Biking',
- 'value' => 'Biking',
- 'isSelected' => false,
- 'price' => ''
- )
- );
+ if ( $v['type'] == 'leads' ) {
+ $groupData = new GlmDataInterestGroups( $this->wpdb, $this->config );
+ $groups = $groupData->getList();
+ $interestsData = new GlmDataInterests( $this->wpdb, $this->config );
+ $interests = $interestsData->getList( null, 'title' );
+ //echo '<pre>$interests: ' . print_r($interests, true) . '</pre>';
+ if ( $interests ) {
+ foreach ( $interests as $interest ) {
+ $inputs[] = array(
+ 'id' => $v['id'] . '.' . $interest['id'],
+ 'label' => $interest['title']
+ );
+ $choices[] = array(
+ 'text' => $interest['title'],
+ 'value' => $interest['title'],
+ 'isSelected' => false,
+ 'price' => ''
+ );
+ }
+ }
+ $form['fields'][$k]['inputs'] = $inputs;
+ $form['fields'][$k]['choices'] = $choices;
}
}
- //echo '<pre>$form: ' . print_r($form, true) . '</pre>';
- //echo '<pre>$form: ' . print_r($form, true) . '</pre>';
- /*
- $newCheckbox = new GF_Field_Checkbox();
- $newCheckbox->adminLabel = 'glm_assoc_interest';
- $newCheckbox->label = 'Interest Fields';
- $newCheckbox->inputName = 'glm_assoc_interest';
- $newCheckbox->inputs = array(
- array(
- 'id' => '5.1',
- 'label' => 'Skiing'
- ),
- array(
- 'id' => '5.2',
- 'label' => 'Boating'
- ),
- array(
- 'id' => '5.3',
- 'label' => 'Hiking'
- ),
+ return $form;
+});
+add_action( 'gform_after_submission', function( $entry, $form ){
+ //echo '<pre>$entry: ' . print_r($entry, true) . '</pre>';
+ $mapped_keys = array(
+ 'fname',
+ 'lname',
+ 'org',
+ 'addr1',
+ 'addr2',
+ 'city',
+ 'state',
+ 'zip',
+ 'country',
+ 'email',
+ 'phone',
+ 'phone2',
+ 'fax',
);
- $newCheckbox->choices = array(
- array(
- 'text' => 'Skiing',
- 'value' => '1',
- 'isSelected' => false,
- 'price' => ''
+ // have to go through the $form array to see what field we need from post
+ $glm_leads_entry = array();
+ if ( $form['fields'] ) {
+ foreach ( $form['fields'] as $field ) {
+ switch ( $field['type'] ) {
+ case 'website':
+ case 'phone':
+ case 'email':
+ case 'text':
+ if ( in_array( $field['inputName'], $mapped_keys ) ) {
+ $glm_leads_entry[$field['inputName']] = $_POST['input_' . $field['id']];
+ }
+ break;
+ case 'name':
+ case 'address':
+ if ( $field->inputs ) {
+ foreach ( $field->inputs as $input ) {
+ if ( in_array( $input['name'], $mapped_keys ) ) {
+ $glm_leads_entry[$input['name']] = $_POST['input_' . str_replace( '.', '_', $input['id'] )];
+ }
+ }
+ }
+ break;
+ case 'leads':
+ $leads_fields = array();
+ foreach ( $_POST as $key => $value ) {
+ if ( preg_match( '/input_' . $field['id'] . '_(\d*)/', $key, $matches ) ) {
+ // grab the final digit
+ $leads_fields[$matches[1]] = $value;
+ }
+ }
+ //$glm_leads_entry['leads'] = $leads_fields;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ // we need to have email field
+ if ( !isset( $glm_leads_entry['email'] ) ) {
+ return;
+ }
+ // create the lead
+ // check first to see if the lead exists by matching email address
+ $result = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads
+ WHERE email = %s",
+ $glm_leads_entry['email']
),
+ ARRAY_A
+ );
+ if ( $result['id'] ) {
+ $lead_id = $result['id'];
+ // will need to update the mail_ok or member fields
+ } else {
+ // this will need mail_ok and members to be setup also
+ $result = $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'leads', // table
+ array(
+ 'email' => $glm_leads_entry['email']
+ ), // data
+ array( '%s' ) // data format
+ );
+ if ( $result === false ) {
+ die( 'lead error given' );
+ }
+ $lead_id = $this->wpdb->insert_id;
+ }
+ if ( !$lead_id ) {
+ return;
+ }
+ // create the lead entry
+ $lead_entry = $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry', // table
array(
- 'text' => 'Boating',
- 'value' => '2',
- 'isSelected' => false,
- 'price' => ''
- ),
+ 'source_id' => $entry['form_id'],
+ 'lead_id' => $lead_id,
+ 'fname' => ( isset( $glm_leads_entry['fname'] ) ) ? $glm_leads_entry['fname'] : '',
+ 'lname' => ( isset( $glm_leads_entry['lname'] ) ) ? $glm_leads_entry['lname'] : '',
+ 'lname' => ( isset( $glm_leads_entry['lname'] ) ) ? $glm_leads_entry['lname'] : '',
+ 'addr1' => ( isset( $glm_leads_entry['addr1'] ) ) ? $glm_leads_entry['addr1'] : '',
+ 'org' => ( isset( $glm_leads_entry['org'] ) ) ? $glm_leads_entry['org'] : '',
+ 'city' => ( isset( $glm_leads_entry['city'] ) ) ? $glm_leads_entry['city'] : '',
+ 'state' => ( isset( $glm_leads_entry['state'] ) ) ? $glm_leads_entry['state'] : '',
+ 'zip' => ( isset( $glm_leads_entry['zip'] ) ) ? $glm_leads_entry['zip'] : '',
+ 'country' => ( isset( $glm_leads_entry['country'] ) ) ? $glm_leads_entry['country'] : '',
+ 'phone' => ( isset( $glm_leads_entry['phone'] ) ) ? $glm_leads_entry['phone'] : '',
+ 'phone2' => ( isset( $glm_leads_entry['phone2'] ) ) ? $glm_leads_entry['phone2'] : '',
+ 'fax' => ( isset( $glm_leads_entry['fax'] ) ) ? $glm_leads_entry['fax'] : '',
+ 'user_trace_info' => $entry['ip'],
+ 'date_submitted' => $entry['date_created']
+ ), // data
array(
- 'text' => 'Hiking',
- 'value' => '3',
- 'isSelected' => false,
- 'price' => ''
- )
+ '%d',
+ '%d',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ '%s',
+ ) // data format
);
- */
- //echo '<pre>$newCheckbox: ' . print_r($newCheckbox, true) . '</pre>';
- //$form['fields'][] = $newCheckbox;
-
- return $form;
-});
-add_action( 'gform_after_submission', function( $entry, $form ){
- echo '<pre>$entry: ' . print_r($entry, true) . '</pre>';
- echo '<pre>$form: ' . print_r($form, true) . '</pre>';
- exit;
-}, 10, 2);
-//add_action( 'gform_pre_submission', function ( $form ) {
- // echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>';
+ if ( $lead_entry === false ) {
+ die( 'lead_entry error given' );
+ }
+ $lead_entry_id = $this->wpdb->insert_id;
+ // 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_id => $interest_val ) {
+ $this->wpdb->insert(
+ GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests', // table
+ array(
+ 'interest_id' => $interest_id,
+ 'lead_entry_id' => $lead_entry_id
+ ), // data
+ array( '%d', '%d' ) // data format
+ );
+ }
+ }
+ //echo '<pre>$glm_leads_entry: ' . print_r($glm_leads_entry, true) . '</pre>';
+ //echo '<pre>$_POST: ' . print_r($_POST, true) . '</pre>';
//echo '<pre>$form: ' . print_r($form, true) . '</pre>';
- // exit;
-//});
+ //exit;
+}, 10, 2);