From: Steve Sutton Date: Fri, 15 Jul 2016 17:46:43 +0000 (-0400) Subject: Add Lead Entry Form done X-Git-Tag: v1.0.0^2~21 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=0617ecc0ab9414c6dae79f1a07091c05a5ba9929;p=WP-Plugins%2Fglm-member-db-leads.git Add Lead Entry Form done Also have put in success messages for the update insert parts. And hide the search form when searching and add button to toggle the form. --- diff --git a/models/admin/leads/index.php b/models/admin/leads/index.php index 213e8e1..ec7447c 100644 --- a/models/admin/leads/index.php +++ b/models/admin/leads/index.php @@ -100,6 +100,11 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry $haveLeads = false; $leadCount = 0; $addingLead = false; + $searching = false; + $updating = false; + $updating_error = false; + $inserting = false; + $inserting_error = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -147,6 +152,9 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry } if ( ( isset( $search ) && $search ) || isset( $search_params ) && $search_params ) { + if ( isset( $search ) && $search ) { + $searching = true; + } // Filter the $_POST variables from the search form. // Verify mm/dd/YYYY date format for the from and to dates. if ( !isset( $search_params ) ) { @@ -307,30 +315,36 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry $paging = false; } - //$leads = $this->getList( $where, $order ); - $listResult = $this->getSimpleEntriesList( $where, $order, true, 'id', $start, $limit ); - - // Get paging results - $numbDisplayed = $listResult['returned']; - $lastDisplayed = $listResult['last']; - if ($start == 1) { - $prevStart = false; - } else { - $prevStart = $start - $limit; - if ($start < 1) { - $start = 1; + + switch ( $option ) { + case 'csv': + $leads = $this->getList( $where, $order ); + break; + default: + $listResult = $this->getSimpleEntriesList( $where, $order, true, 'id', $start, $limit ); + // Get paging results + $numbDisplayed = $listResult['returned']; + $lastDisplayed = $listResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($listResult['returned'] == $limit) { + $nextStart = $start + $limit; } - } - if ($listResult['returned'] == $limit) { - $nextStart = $start + $limit; - } - // since we're doing paging, we have to break out just the member data - $leads = $listResult['list']; - unset($listResult); + // since we're doing paging, we have to break out just the member data + $leads = $listResult['list']; + unset($listResult); - // If we have list entries - even if it's an empty list - $success = true; + // If we have list entries - even if it's an empty list + break; + } + $success = true; $haveLeads = false; if ($leads !== false) { @@ -342,6 +356,8 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry } } + + } else { $leads = false; } @@ -441,6 +457,7 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry break; case 'update': + $updating = true; if ( $this->config['loggedInUser']['contactUser'] ) { break; } @@ -463,7 +480,6 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry ), array( '%d', '%d' ) ); - var_dump( $this->wpdb->insert_id ); } } @@ -473,15 +489,12 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry } // Get the record for this Entry. $entry = $this->editEntry( $this->entryId ); + //echo '
$entry: ' . print_r($entry, true) . '
'; // get the field from the leads table $leadData = new GlmDataLeads( $this->wpdb, $this->config ); $lead = $leadData->getEntry( $entry['fieldData']['lead_id']['value'] ); - if ( $lead ) { - $entry['fieldData']['mail_ok'] = $lead['mail_ok']; - $entry['fieldData']['member_ok'] = $lead['member_ok']; - } - //echo '
$entry: ' . print_r($entry, true) . '
'; + //echo '
$lead: ' . print_r($lead, true) . '
'; // Use the edit view file. $view = 'edit.html'; @@ -523,12 +536,149 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry } // Compile template data $templateData = array( - 'addingLead' => $addingLead, - 'entry' => $entry, - 'lead_interests' => $lead_interests, + 'addingLead' => $addingLead, + 'entry' => $entry, + 'lead' => $lead, + 'lead_interests' => $lead_interests, ); break; + case 'insert': + $inserting = true; + if ( $this->config['loggedInUser']['contactUser'] ) { + break; + } + $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ); + $mail_ok = filter_var( $_REQUEST['mail_ok'], FILTER_VALIDATE_BOOLEAN ); + $member_ok = filter_var( $_REQUEST['member_ok'], FILTER_VALIDATE_BOOLEAN ); + if ( !$email ) { + die( 'Fatal Error: Email did not validate' ); + } + // Check to see if this email is already in leads table + $lead = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads + WHERE email = %s", + $email + ), + ARRAY_A + ); + if ( !$lead ) { + // Insert new email address as new lead + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'leads', + array( + 'email' => $email, + 'mail_ok' => $mail_ok, + 'member_ok' => $member_ok, + 'created' => current_time( 'mysql', false ), + ), + array( '%s', '%s', '%s', '%s' ) + ); + // get leads id + $lead_id = $this->wpdb->insert_id; + } else { + $lead_id = $lead['id']; + echo '
$lead: ' . print_r($lead, true) . '
'; + } + if ( !isset( $lead_id ) && !$lead_id ) { + die( 'Fatal Error: Cannot generate lead_id for new leads record' ); + } + /* Source + * If there's no admin source then create one. + */ + $source_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "sources + WHERE title = %s", + 'Admin' + ) + ); + if ( !$source_id ) { + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'sources', + array( + 'title' => 'Admin', + 'enabled' => 1 + ), + array( '%s', '%s' ) + ); + $source_id = $this->wpdb->insert_id; + } + if ( !$source_id ) { + die( 'Fatal Error: Cannot generate source_id for new source record' ); + } + /* + * Now that we have a source_id and lead_id we can + * insert the entry record. + */ + $fname = filter_var( $_REQUEST['fname'], FILTER_SANITIZE_STRING ); + $lname = filter_var( $_REQUEST['lname'], FILTER_SANITIZE_STRING ); + $addr1 = filter_var( $_REQUEST['addr1'], FILTER_SANITIZE_STRING ); + $addr2 = filter_var( $_REQUEST['addr2'], FILTER_SANITIZE_STRING ); + $city = filter_var( $_REQUEST['city'], FILTER_SANITIZE_STRING ); + $state = filter_var( $_REQUEST['state'], FILTER_SANITIZE_STRING ); + $zip = filter_var( $_REQUEST['zip'], FILTER_SANITIZE_STRING ); + $country = filter_var( $_REQUEST['country'], FILTER_SANITIZE_STRING ); + $phone = filter_var( $_REQUEST['phone'], FILTER_SANITIZE_STRING ); + $phone2 = filter_var( $_REQUEST['phone2'], FILTER_SANITIZE_STRING ); + $fax = filter_var( $_REQUEST['fax'], FILTER_SANITIZE_STRING ); + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_entry', + array( + 'date_submitted' => current_time( 'mysql', false ) , + 'user_trace_info' => $_SERVER['REMOTE_ADDR'], + 'lead_id' => $lead_id, + 'source_id' => $source_id, + 'fname' => $fname, + 'lname' => $lname, + 'addr1' => $addr1, + 'addr2' => $addr2, + 'city' => $city, + 'state' => $state, + 'zip' => $zip, + 'country' => $country, + 'phone' => $phone, + 'phone2' => $phone2, + 'fax' => $fax, + ), + array( + '%s', + '%s', + '%d', + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + ) + ); + // Get the Entry id + $entry_id = $this->wpdb->insert_id; + + // Add the interests to lead_interests + if ( isset( $_POST['interests'] ) && !empty( $_POST['interests'] ) ) { + foreach ( $_POST['interests'] as $interest_id => $new_interest ) { + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests", + array( + 'lead_entry_id' => $entry_id, + 'interest_id' => $interest_id + ), + array( '%d', '%d' ) + ); + } + } + case 'add': if ( $this->config['loggedInUser']['contactUser'] ) { break; @@ -621,6 +771,11 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry $templateData['start'] = $start; $templateData['limit'] = $limit; $templateData['paging'] = $paging; + $templateData['searching'] = $searching; + $templateData['updating'] = $updating; + $templateData['updating_error'] = $updating_error; + $templateData['inserting'] = $inserting; + $templateData['inserting_error'] = $inserting_error; // Return status, any suggested view, and any data to controller diff --git a/views/admin/leads/edit.html b/views/admin/leads/edit.html index 88ad0aa..f78701f 100644 --- a/views/admin/leads/edit.html +++ b/views/admin/leads/edit.html @@ -1,19 +1,72 @@ {include file='admin/leads/header.html'} +{if $updating}Lead Entry Updated{/if} +{if $updating_error}Lead Entry Update Error{/if} +{if $inserting}Lead Entry Added{/if} +{if $inserting_error}Lead Entry Add Error{/if} + {if $entry.status}
- {if !$addingLead} - + + + {else} + {/if} + - - + + + + + + + + + {if !$addingLead} + + + + {/if} @@ -62,14 +115,6 @@ - - - - - - - -
EmailLead
+ + + + + + + + + + + + + +
Email + {if $addingLead} + + {else} + {$lead.email} + {/if} +
Mail Ok? + {if $addingLead} + + {else} + {$lead.mail_ok.name} + {/if} +
Member Ok? + {if $addingLead} + + {else} + {$lead.member_ok.name} + {/if} +
+ +
Entry
Date Submitted{$entry.fieldData.date_submitted|date_format}
Company Fax
Mail Ok?
Member Ok?
{foreach $grouped_interests as $group_name => $group} @@ -96,4 +141,10 @@ {/if} + {include file='admin/footer.html'} diff --git a/views/admin/leads/index.html b/views/admin/leads/index.html index 961eb30..22f893c 100644 --- a/views/admin/leads/index.html +++ b/views/admin/leads/index.html @@ -4,16 +4,22 @@ #lead-search-form td { padding: 5px; } + #lead-search-form.hide { + display: none; + } {if $user_can_edit_leads} Add New Lead {/if} +{if $searching} + +{/if}
- +
- + {/foreach} {/if} @@ -136,6 +142,9 @@ jQuery(document).ready(function($){ $('#glm-form-from_date').datepicker(); $('#glm-form-to_date').datepicker(); + $('#search-form-toggle').click(function(){ + $('#lead-search-form').toggleClass('hide'); + }); });
@@ -118,7 +124,7 @@ {$lead.source_id.name} {$lead.org} {$lead.date_submitted} {$lead.date_submitted|date_format}