From 3deca1bd9f435febbb0402b3c504f3a33b17efc2 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 11 Jul 2016 16:55:16 -0400 Subject: [PATCH] Adding edit entry screen to admin leads Working still on the interest edit part. I have the other fields saving their info. Using just the data abstract for the edit entry form. --- classes/data/dataInterests.php | 2 +- classes/data/dataLeadEntry.php | 4 +- models/admin/leads/index.php | 132 ++++++++++++++++++++++++++++----- setup/validActions.php | 10 +-- views/admin/leads/edit.html | 79 ++++++++++++++++++++ views/admin/leads/index.html | 4 +- 6 files changed, 202 insertions(+), 29 deletions(-) create mode 100644 views/admin/leads/edit.html diff --git a/classes/data/dataInterests.php b/classes/data/dataInterests.php index 640e37a..b4c5693 100644 --- a/classes/data/dataInterests.php +++ b/classes/data/dataInterests.php @@ -140,7 +140,7 @@ class GlmDataInterests extends GlmDataAbstract } - /* + /** * Entry Post Processing Call-Back Method * * Perform post-processing for all result entries. diff --git a/classes/data/dataLeadEntry.php b/classes/data/dataLeadEntry.php index 428f2fa..ef34334 100644 --- a/classes/data/dataLeadEntry.php +++ b/classes/data/dataLeadEntry.php @@ -228,6 +228,7 @@ class GlmDataLeadEntry extends GlmDataAbstract 'type' => 'text', 'required' => false, 'unique' => false, + 'view_only' => true, 'use' => 'a', ), @@ -236,6 +237,7 @@ class GlmDataLeadEntry extends GlmDataAbstract 'type' => 'text', 'required' => false, 'unique' => false, + 'view_only' => true, 'use' => 'a', ), @@ -243,7 +245,7 @@ class GlmDataLeadEntry extends GlmDataAbstract } - /* + /** * 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 d70b5c8..bbea9af 100644 --- a/models/admin/leads/index.php +++ b/models/admin/leads/index.php @@ -36,6 +36,7 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry */ public $config; + public $entryId = false; /* * Constructor * @@ -83,6 +84,24 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry public function modelAction($actionData = false) { + $option = false; + + // Get any provided option + if ( isset( $_REQUEST['option'] ) ) { + $option = $_REQUEST['option']; + } + + // Get event ID if supplied + if (isset($_REQUEST['entry'])) { + + // Make sure it's numeric + $this->entryId = ( $_REQUEST['entry'] - 0 ); + + if ( $this->entryId <= 0 ) { + $this->entryId = false; + } + + } // Check for a search being done. if ( isset( $_REQUEST['search'] ) ) { $search = filter_var( $_REQUEST['search'], FILTER_VALIDATE_BOOLEAN); @@ -149,7 +168,9 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry $where_parts[] = "T.date_submitted BETWEEN STR_TO_DATE('{$search_params['from_date']}', '%m/%d/%Y') " . "AND STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')"; } else if ( $search_params['from_date'] ) { + $where_parts[] = "T.date_submitted >= STR_TO_DATE('{$search_params['from_date']}', '%m/%d/%Y')"; } else if ( $search_params['to_date'] ) { + $where_parts[] = "T.date_submitted <= STR_TO_DATE('{$search_params['to_date']}', '%m/%d/%Y')"; } $where = implode( ' AND ', $where_parts ); //echo '
$where: ' . print_r( $where, true ) . '
'; @@ -166,42 +187,113 @@ class GlmMembersAdmin_leads_index extends GlmDataLeadEntry ); } + $interests = array(); $groupData = new GlmDataInterestGroups( $this->wpdb, $this->config ); $groups = $groupData->getList(); $grouped_interests = array(); - 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' ); + switch ( $option ) { + case 'update': + $entry = $this->updateEntry( $this->entryId ); + + // Update the Entries Interests. First remove them. + $this->wpdb->delete( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests", + array( 'lead_entry_id' => $this->entryId ), + array( '%d' ) + ); + // then add the ones needed. + 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' => $this->entryId, + 'interest_id' => $interest_id + ), + array( '%d', '%d' ) + ); + } } - if ( $grouped_interests ) { - foreach ( $grouped_interests as $group_name => &$interests ) { - foreach ( $interests as $key => &$interest ) { - $grouped_interests[$group_name][$key]['selected'] - = ( isset( $search_params['interests'][$key] ) && $search_params['interests'][$key] ) ? 1 : 0; + echo '
$_POST: ' . print_r($_POST, true) . '
'; + + case 'edit': + $entry = $this->editEntry( $this->entryId ); + + $view = 'edit.html'; + + $lead_ints = array(); + $sql = " + SELECT * + FROM " . GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . "lead_interests + WHERE lead_entry_id = " . $this->entryId; + $lead_interests = $this->wpdb->get_results( $sql, ARRAY_A ); + if ( $lead_interests ) { + foreach ( $lead_interests as $interest ) { + $lead_ints[] = $interest['id']; + } + } + 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'] + = ( isset( $lead_ints[$key] ) ) ? 1 : 0; + } + } + } + } + // Compile template data + $templateData = array( + 'entry' => $entry, + 'lead_interests' => $lead_interests, + 'grouped_interests' => $grouped_interests, + ); + break; + + default: + 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'] + = ( isset( $search_params['interests'][$key] ) && $search_params['interests'][$key] ) ? 1 : 0; + } } } } + $view = 'index.html'; + // Compile template data + $templateData = array( + 'search_params' => $search_params, + 'request' => print_r( $_REQUEST, true ), + 'leads' => $leads, + 'grouped_interests' => $grouped_interests, + ); + break; } - // Compile template data - $templateData = array( - 'search_params' => $search_params, - 'request' => print_r( $_REQUEST, true ), - 'leads' => $leads, - 'grouped_interests' => $grouped_interests, - ); // Return status, any suggested view, and any data to controller return array( 'status' => true, 'modelRedirect' => false, - 'view' => 'admin/leads/index.html', + 'view' => 'admin/leads/' . $view, 'data' => $templateData ); diff --git a/setup/validActions.php b/setup/validActions.php index bb4a1be..33b89fb 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -33,15 +33,15 @@ $glmMembersLeadsAddOnValidActions = array( 'adminActions' => array( 'leads' => array( - 'index' => GLM_MEMBERS_LEADS_PLUGIN_SLUG + 'index' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, + 'edit' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, ), 'management' => array( - 'leads' => GLM_MEMBERS_LEADS_PLUGIN_SLUG + 'leads' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, ), 'settings' => array( - 'leads' => GLM_MEMBERS_LEADS_PLUGIN_SLUG - ) + 'leads' => GLM_MEMBERS_LEADS_PLUGIN_SLUG, + ), ), ); -?> \ No newline at end of file diff --git a/views/admin/leads/edit.html b/views/admin/leads/edit.html new file mode 100644 index 0000000..e900b77 --- /dev/null +++ b/views/admin/leads/edit.html @@ -0,0 +1,79 @@ +{include file='admin/leads/header.html'} + +{if $entry.status} +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Company
First Name
Last Name
Address 1
Address 2
City
State
ZIP
Country
Phone
Phone 2
Fax
+ {foreach $grouped_interests as $group_name => $group} +
+ {$group_name} + {foreach $group as $interest} +
+ +
+ {/foreach} +
+ {/foreach} +
+
+{/if} + +{include file='admin/footer.html'} diff --git a/views/admin/leads/index.html b/views/admin/leads/index.html index f2e5d42..ee944bf 100644 --- a/views/admin/leads/index.html +++ b/views/admin/leads/index.html @@ -41,14 +41,14 @@ {if $leads} - + {foreach $leads as $lead} + - {/foreach} -- 2.17.1
Company ContactCompany Submitted
{$lead.fname} {$lead.lname} {$lead.org} {$lead.fname} {$lead.lname} {$lead.date_submitted}