From: Steve Sutton Date: Thu, 14 Jul 2016 20:59:22 +0000 (-0400) Subject: Working more on the add edit form. X-Git-Tag: v1.0.0^2~22 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ed7018bf07b37a4a7d0c3fc47fb5be50f5ae4c3e;p=WP-Plugins%2Fglm-member-db-leads.git Working more on the add edit form. Adding to the edit template the mail_ok and member_ok fields. Getting the info from the main leads record. --- diff --git a/classes/data/dataLeadEntry.php b/classes/data/dataLeadEntry.php index ed7afe1..560685b 100644 --- a/classes/data/dataLeadEntry.php +++ b/classes/data/dataLeadEntry.php @@ -276,4 +276,39 @@ class GlmDataLeadEntry extends GlmDataAbstract return $r; } + /* + * Get a simple members list - Name and ID only + * + * @return array Array of Name and ID for all members + * @access public + */ + public function getSimpleEntriesList( + $where = '', + $order = '', + $fieldVals = true, + $idField = 'id', + $start = false, + $limit = false + ) { + + // Save the current fields array and make a copy + $fSave = $this->fields; + + // Remove what we don't want from the copy and get the list + $this->fields = array( + 'id' => $fSave['id'], + 'fname' => $fSave['fname'], + 'lname' => $fSave['lname'], + 'org' => $fSave['org'], + 'source_id' => $fSave['source_id'], + 'date_submitted' => $fSave['date_submitted'], + ); + + $entryList = $this->getList( $where, $order, $fieldVals, $idField, $start, $limit ); + + // Restore the fields list + $this->fields = $fSave; + + return $entryList; + } } diff --git a/classes/data/dataLeads.php b/classes/data/dataLeads.php index 30ccda3..0257cdc 100644 --- a/classes/data/dataLeads.php +++ b/classes/data/dataLeads.php @@ -123,11 +123,25 @@ class GlmDataLeads extends GlmDataAbstract 'use' => 'a', ), + 'mail_ok' => array( + 'field' => 'mail_ok', + 'type' => 'checkbox', + 'required' => false, + 'use' => 'a', + ), + + 'member_ok' => array( + 'field' => 'member_ok', + 'type' => 'checkbox', + 'required' => false, + 'use' => 'a', + ), + ); } - /* + /** * Entry Post Processing Call-Back Method * * Perform post-processing for all result entries. diff --git a/models/admin/leads/index.php b/models/admin/leads/index.php index 5868108..213e8e1 100644 --- a/models/admin/leads/index.php +++ b/models/admin/leads/index.php @@ -14,6 +14,7 @@ */ // Load Leads data abstract +require_once(GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataLeads.php'); require_once(GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataLeadEntry.php'); require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterests.php'; require_once GLM_MEMBERS_LEADS_PLUGIN_CLASS_PATH.'/data/dataInterestGroups.php'; @@ -84,10 +85,21 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry public function modelAction($actionData = false) { + $where = ' true '; $option = false; $user_can_edit_leads = false; $wpUser = $this->config['loggedInUser']['wpUser']; $search_id = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $haveLeads = false; + $leadCount = 0; + $addingLead = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -156,7 +168,8 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry 'regexp' => '%([0-9]{2})/([0-9]{2})/([0-9]{4})%' ) ), - 'mail_ok' => FILTER_VALIDATE_BOOLEAN, + 'mail_ok' => FILTER_VALIDATE_BOOLEAN, + 'member_ok' => FILTER_VALIDATE_BOOLEAN, 'interests' => array( 'filter' => FILTER_VALIDATE_BOOLEAN, 'flags' => FILTER_FORCE_ARRAY @@ -164,6 +177,13 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry ) ); } + // checking the booleans for empty or false + if ( isset( $_REQUEST['mail_ok'] ) && $_REQUEST['mail_ok'] === '0' ) { + $search_params['mail_ok'] = (int)0; + } + if ( isset( $_REQUEST['member_ok'] ) && $_REQUEST['member_ok'] === '0' ) { + $search_params['member_ok'] = (int)0; + } if ( $wpUser['ID'] ) { $search_data = array( @@ -191,11 +211,19 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry // build the $where part $where_parts = array(); - if ( $search_params['mail_ok'] ) { + if ( isset( $search_params['member_ok'] ) && $search_params['member_ok'] !== false ) { + $member_ok = ( $search_params['member_ok'] === true ) ? 'true' : 'false'; + $where_parts[] = "T.lead_id IN ( + SELECT id + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads + WHERE member_ok = $member_ok)"; + } + if ( isset( $search_params['mail_ok'] ) && $search_params['mail_ok'] !== false ) { + $mail_ok = ( $search_params['mail_ok'] === true ) ? 'true' : 'false'; $where_parts[] = "T.lead_id IN ( SELECT id FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "leads - WHERE mail_ok = true)"; + WHERE mail_ok = $mail_ok)"; } if ( $this->config['loggedInUser']['contactUser'] ) { $where_parts[] = "T.lead_id IN ( @@ -249,9 +277,71 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry $where_parts[] = "T.date_submitted <= STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')"; } if ( isset( $search ) && $search ) { - $where = implode( ' AND ', $where_parts ); + if ( isset( $where_parts ) && !empty( $where_parts ) ) { + $where .= ' AND ' . implode( ' AND ', $where_parts ); + } $order = "T.lname, T.fname"; - $leads = $this->getList( $where, $order ); + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } + } + + // Get count of members listed + $leadCount = $this->getStats($where); + + // If the number of members is less than a page, don't do paging + if ($leadCount <= $limit) { + $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; + } + } + 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); + + // If we have list entries - even if it's an empty list + $success = true; + $haveLeads = false; + if ($leads !== false) { + + $success = true; + + // If we have any entries + if (count($leads) > 0) { + $haveLeads = true; + } + } + } else { $leads = false; } @@ -384,6 +474,15 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry // Get the record for this Entry. $entry = $this->editEntry( $this->entryId ); + // 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) . '
'; + // Use the edit view file. $view = 'edit.html'; @@ -424,6 +523,45 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry } // Compile template data $templateData = array( + 'addingLead' => $addingLead, + 'entry' => $entry, + 'lead_interests' => $lead_interests, + ); + break; + + case 'add': + if ( $this->config['loggedInUser']['contactUser'] ) { + break; + } + $entry = $this->newEntry(); + $addingLead = true; + + $lead_interests = array(); + + // Use the edit view file. + $view = 'edit.html'; + + // Setup the $grouped_interests array for the edit page. + if ( $groups ) { + foreach ( $groups as $group ) { + $intData = new GlmDataInterests( $this->wpdb, $this->config ); + $group_parts = explode( '_', $group['title'] ); + $group_parts = array_map( function($item){ return ucfirst( $item ); }, $group_parts ); + $group_title = implode( ' ', $group_parts ); + $grouped_interests[$group_title] = $intData->getList( "group_id = " . $group['id'], 'title' ); + } + if ( $grouped_interests ) { + foreach ( $grouped_interests as $group_name => $interests ) { + foreach ( $interests as $key => $interest ) { + $grouped_interests[$group_name][$key]['selected'] = 0; + } + } + } + } + + // Compile template data + $templateData = array( + 'addingLead' => $addingLead, 'entry' => $entry, 'lead_interests' => $lead_interests, ); @@ -474,6 +612,16 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry // Common things to place into the $templateData array $templateData['sources'] = $sources; $templateData['grouped_interests'] = $grouped_interests; + $templateData['haveLeads'] = $haveLeads; + $templateData['leadCount'] = $leadCount; + $templateData['numbDisplayed'] = $numbDisplayed; + $templateData['lastDisplayed'] = $lastDisplayed; + $templateData['prevStart'] = $prevStart; + $templateData['nextStart'] = $nextStart; + $templateData['start'] = $start; + $templateData['limit'] = $limit; + $templateData['paging'] = $paging; + // Return status, any suggested view, and any data to controller return array( diff --git a/models/admin/management/leads.php b/models/admin/management/leads.php index 160db77..d0cdea7 100644 --- a/models/admin/management/leads.php +++ b/models/admin/management/leads.php @@ -115,17 +115,16 @@ class GlmMembersAdmin_management_leads // extends GlmDataLeadsManagement */ public function modelAction($actionData = false) { - - $gravity_forms = GFAPI::get_forms(); - - $groupData = new GlmDataInterestGroups( $this->wpdb, $this->config ); - $groups = $groupData->getList(); + // Grab data from the Sources table + $sources = $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "sources", + ARRAY_A + ); // Compile template data $templateData = array( - 'formData' => print_r( $gravity_forms, true ), - 'gravityForms' => $gravity_forms, - 'groups' => $groups, + 'sources' => $sources ); // Return status, suggested view, and data to controller diff --git a/views/admin/leads/edit.html b/views/admin/leads/edit.html index 353f9a4..88ad0aa 100644 --- a/views/admin/leads/edit.html +++ b/views/admin/leads/edit.html @@ -4,9 +4,16 @@
+ {if !$addingLead} + {/if} + + + + + @@ -55,6 +62,14 @@ + + + + + + + + - + +
Email
Company Fax
Mail Ok?
Member Ok?
{foreach $grouped_interests as $group_name => $group} @@ -62,7 +77,9 @@ {$group_name} {foreach $group as $interest}
- +
{/foreach} @@ -70,8 +87,11 @@
+ +
{/if} diff --git a/views/admin/leads/index.html b/views/admin/leads/index.html index 933b566..961eb30 100644 --- a/views/admin/leads/index.html +++ b/views/admin/leads/index.html @@ -5,9 +5,14 @@ padding: 5px; } - +{if $user_can_edit_leads} + Add New Lead +{/if}
+ + + @@ -43,8 +48,26 @@ - + + {if $user_can_edit_leads} + + + + + {/if} {foreach $grouped_interests as $group_name => $group} @@ -61,35 +84,54 @@
+ +
+ +
{$group_name}
-
{if $leads}

Search Results:

-
- Download as CSV File -
- - - - - - - - {foreach $leads as $lead} - - - - - - - {/foreach} + Download as CSV File + +
+

Total found: {$leadCount}  

+ {if $paging} + + + {/if} +
ContactSourceCompanySubmitted
- {if $user_can_edit_leads}{/if} - {$lead.fname} {$lead.lname} - {if $user_can_edit_leads}{/if} - {$lead.source_id.name} {$lead.org} {$lead.date_submitted}
+ + + + + + + + + + {if $haveLeads} + {assign var="i" value="0"} + {foreach $leads as $lead} + {if $i++ is odd by 1}{else}{/if} + + + + + + {/foreach} + {/if} +
ContactSourceCompanySubmitted
+ {if $user_can_edit_leads} + + {/if} + {$lead.fname} {$lead.lname} + {if $user_can_edit_leads}{/if} + {$lead.source_id.name} {$lead.org} {$lead.date_submitted}
+ {if $paging} + + + {/if} {/if} + +