From: Steve Sutton Date: Thu, 15 Nov 2018 19:26:36 +0000 (-0500) Subject: Setup gravity form for send trip planner. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=df20ba94db44c2c1f1027a904354fa3e2ccedb9d;p=WP-Plugins%2Fglm-member-db-itinerary.git Setup gravity form for send trip planner. Add new setting for the trip planner. Add send_itinerary_form_id for setting the gravity form id. Will be used for submitting the form to the members. --- diff --git a/classes/data/dataSettings.php b/classes/data/dataSettings.php index 9743658..170b89b 100644 --- a/classes/data/dataSettings.php +++ b/classes/data/dataSettings.php @@ -122,6 +122,13 @@ class GlmDataItinerarySettings extends GlmDataAbstract 'use' => 'a', ), + // Form id for Trip Planner Form + 'send_itinerary_form_id' => array( + 'field' => 'send_itinerary_form_id', + 'type' => 'integer', + 'use' => 'a', + ), + // Page id for Trip Planner Page 'itinerary_page' => array( 'field' => 'itinerary_page', diff --git a/index.php b/index.php index 6ef8eb8..c18d816 100644 --- a/index.php +++ b/index.php @@ -44,7 +44,7 @@ if (!defined('ABSPATH')) { * version from this plugin. */ define('GLM_MEMBERS_ITINERARY_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_ITINERARY_PLUGIN_DB_VERSION', '0.0.1'); +define('GLM_MEMBERS_ITINERARY_PLUGIN_DB_VERSION', '0.0.2'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_ITINERARY_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/js/front.js b/js/front.js index 7df88c3..cca2642 100644 --- a/js/front.js +++ b/js/front.js @@ -52,3 +52,26 @@ jQuery('.glm-itinerary-delete').on('click', function(e){ } return false; }); +jQuery('.glm-itinerary-request-delete').on('click', function(e){ + e.preventDefault(); + var member_id = jQuery(this).data('id'); + var base_url = jQuery(this).data('baseurl'); + var button = jQuery(this); + if ( member_id ) { + jQuery.ajax({ + url: base_url + '/wp-admin/admin-ajax.php', + cache: false, + data: { + action: 'glm_members_admin_ajax', + glm_action: 'itineraryList', + member_id: member_id, + del: true + }, + success: function(){ + window.location.href = glm_itinerary_page_url + '?option=moreinfo'; + // button.parent('td').parent('tr.glm-itinerary-request-item').remove(); + } + }); + } + return false; +}); diff --git a/models/front/itinerary/list.php b/models/front/itinerary/list.php index ef0a1c6..0024d03 100755 --- a/models/front/itinerary/list.php +++ b/models/front/itinerary/list.php @@ -16,6 +16,45 @@ */ class GlmMembersFront_itinerary_list // extends GlmMembersFront_events_baseAction { + /** + * Constructor + * + * This constructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successful and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + // parent::__construct(false, false); + + } + /** * modelAction * @@ -26,9 +65,16 @@ class GlmMembersFront_itinerary_list // extends GlmMembersFront_events_baseActio */ public function modelAction( $actionData = false ) { - $status = true; - $view = 'list.html'; - $members = array(); + $status = true; + $view = 'list.html'; + $members = array(); + $option = 'list'; + $form_contents = ''; + $userLoggedIn = false; + $membersWithEmails = + $memberEmails = + $states = + $membersNoEmails = array(); if ( isset( $_SESSION['travel-list'] ) ) { foreach ( $_SESSION['travel-list'] as $item ) { @@ -36,10 +82,124 @@ class GlmMembersFront_itinerary_list // extends GlmMembersFront_events_baseActio } } + // echo '
$_SESSION: ' . print_r( $_SESSION, true ) . '
'; + + if ( isset( $_REQUEST['option'] ) ) { + $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ); + } + + if ( isset( $_SESSION['itinerary-auth'] ) && filter_var( $_SESSION['itinerary-auth'], FILTER_VALIDATE_INT ) ) { + $userLoggedIn = true; + } + + switch ( $option ) { + case 'addAccount': + // Add the account + // Unless email already exists + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + $password = md5( filter_var( $_REQUEST['password'], FILTER_SANITIZE_STRING ) ); + $this->wpdb->insert( + GLM_MEMBERS_ITINERARY_PLUGIN_DB_PREFIX . 'user', + array( + '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 ), + 'email' => filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ), + 'password' => $password, + ), + array( + '%s', // fname + '%s', // lname + '%s', // addr1 + '%s', // addr2 + '%s', // city + '%s', // state + '%s', // zip + '%s', // email + '%s', // password + ) + ); + $view = 'create.html'; + break; + case 'create': + // Get list of states + $states = $this->config['states']; + // echo '
$states: ' . print_r( $states, true ) . '
'; + $view = 'create.html'; + break; + case 'login': + $email = filter_var( $_REQUEST['username'], FILTER_VALIDATE_EMAIL ); + $password = filter_var( $_REQUEST['password'] ); + $user_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_ITINERARY_PLUGIN_DB_PREFIX . "user + WHERE email = %s + AND password = md5(%s)", + $email, + $password + ) + ); + if ( $user_id ) { + // Success login + $_SESSION['itinerary-auth'] = $user_id; + $userLoggedIn = true; + } + global $wp; + $tripPlannerPage = get_permalink( $this->config['settings']['itinerary_page'] ); + // Redirect to trip planner page + // if ( $tripPlannerPage ) { + // wp_redirect( $tripPlannerPage ); + // exit; + // } + // $view = 'login.html'; + break; + case 'forgot': + $view = 'forgot.html'; + break; + case 'moreinfo': + // Need to create two list one with emails and one without. + foreach ( $members as $member ) { + if ( $member['email'] && filter_var( $member['email'], FILTER_VALIDATE_EMAIL ) ) { + $membersWithEmails[] = $member; + $memberEmwails[] = $member['email']; + } else if ( $member['phone'] ) { + $membersNoEmails[] = $member; + } + } + if ( count( $membersNoEmails ) == 0 && count( $membersWithEmails ) == 0 ) { + $view = 'list.html'; + } else { + $view = 'moreinfo.html'; + } + if ( count( $membersWithEmails ) > 0 ) { + $_GET['member_emails'] = implode( ',', $memberEmwails ); + $form_id = $this->config['settings']['send_itinerary_form_id']; + if ( isset( $form_id ) && filter_var( $form_id, FILTER_VALIDATE_INT ) ) { + $form_contents = do_shortcode( '[gravityform id="' . $form_id . '" title="false" description="false"]' ); + } + } else { + $form_contents = ''; + } + break; + case 'list': + $view = 'list.html'; + default: + break; + } $templateData = array( - 'baseurl' => get_bloginfo( 'url' ), - 'members' => $members, + 'baseurl' => get_bloginfo( 'url' ), + 'members' => $members, + 'membersWithEmails' => $membersWithEmails, + 'membersNoEmails' => $membersNoEmails, + 'formContents' => $form_contents, + 'states' => $states, + 'userLoggedIn' => $userLoggedIn, ); error_reporting(E_ALL ^ E_NOTICE); diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql deleted file mode 100644 index 1127253..0000000 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ /dev/null @@ -1,57 +0,0 @@ --- Gaslight Media Staff Add On --- File Created: 2018-10-24 --- Database Version: 0.0.1 --- Database Creation Script --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashes - --- Itinerary Session -CREATE TABLE {prefix}session ( - id INT NOT NULL AUTO_INCREMENT, - ref_type INT NOT NULL, -- Reference Type (see plugin.ini for ref_types) - ref_dest INT NOT NULL, -- Id from the Reference - contact_type INT NOT NULL, -- Contact Type (see plugin.ini for contact_types) - contact_dest INT NOT NULL, -- Id of the Contact Type - page_url TEXT NOT NULL, -- Page url when this was added. - PRIMARY KEY (id), - INDEX(ref_dest), - INDEX(contact_dest) -); - ----- - --- Itinerary User -CREATE TABLE {prefix}user ( - id INT NOT NULL AUTO_INCREMENT, - fname TINYTEXT NULL, - lname TINYTEXT NULL, - addr1 TINYTEXT NULL, - addr2 TINYTEXT NULL, - city TINYTEXT NULL, - state TINYTEXT NULL, - zip TINYTEXT NULL, - email TINYTEXT NULL, - phone TINYTEXT NULL, - fax TINYTEXT NULL, - password TINYTEXT NULL, - PRIMARY KEY (id), - INDEX(email(20)) -); - ----- - --- Management -CREATE TABLE {prefix}management ( - id INT NOT NULL AUTO_INCREMENT, - itinerary_page INT NULL, - itinerary_page_content TEXT NULL, - add_label TINYTEXT NULL, - view_label TINYTEXT NULL, - PRIMARY KEY (id) -); - ----- - --- Add record to management table -INSERT INTO {prefix}management (id, add_label, view_label) VALUES (1, 'Add to Trip Planner', 'View Trip Planner'); diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql new file mode 100644 index 0000000..e0d170d --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.2.sql @@ -0,0 +1,58 @@ +-- Gaslight Media Staff Add On +-- File Created: 2018-10-24 +-- Database Version: 0.0.1 +-- Database Creation Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Itinerary Session +CREATE TABLE {prefix}session ( + id INT NOT NULL AUTO_INCREMENT, + ref_type INT NOT NULL, -- Reference Type (see plugin.ini for ref_types) + ref_dest INT NOT NULL, -- Id from the Reference + contact_type INT NOT NULL, -- Contact Type (see plugin.ini for contact_types) + contact_dest INT NOT NULL, -- Id of the Contact Type + page_url TEXT NOT NULL, -- Page url when this was added. + PRIMARY KEY (id), + INDEX(ref_dest), + INDEX(contact_dest) +); + +---- + +-- Itinerary User +CREATE TABLE {prefix}user ( + id INT NOT NULL AUTO_INCREMENT, + fname TINYTEXT NULL, + lname TINYTEXT NULL, + addr1 TINYTEXT NULL, + addr2 TINYTEXT NULL, + city TINYTEXT NULL, + state TINYTEXT NULL, + zip TINYTEXT NULL, + email TINYTEXT NULL, + phone TINYTEXT NULL, + fax TINYTEXT NULL, + password TINYTEXT NULL, + PRIMARY KEY (id), + INDEX(email(20)) +); + +---- + +-- Management +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + send_itinerary_form_id INT NULL, + itinerary_page INT NULL, + itinerary_page_content TEXT NULL, + add_label TINYTEXT NULL, + view_label TINYTEXT NULL, + PRIMARY KEY (id) +); + +---- + +-- Add record to management table +INSERT INTO {prefix}management (id, add_label, view_label) VALUES (1, 'Add to Trip Planner', 'View Trip Planner'); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 3246374..4ecc20c 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -15,5 +15,6 @@ $glmMembersItineraryDbVersions = array( '0.0.1' => array('version' => '0.0.1', 'tables' => 3, 'date' => '10/31/2018'), + '0.0.2' => array('version' => '0.0.2', 'tables' => 3, 'date' => '11/13/2018'), ); diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql new file mode 100644 index 0000000..6e15699 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.2.sql @@ -0,0 +1,12 @@ +-- Gaslight Media Members Database - Itinerary Add-On +-- File Created: 2018-11-13 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + + +-- Add Form Id for Itinerary +ALTER TABLE {prefix}management ADD COLUMN send_itinerary_form_id INT NULL; + diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 65a1ef9..7bd5f2f 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -61,3 +61,11 @@ add_action( 'init', function(){ session_start(); } }); + +$form_id = ( isset( $config['settings']['send_itinerary_form_id'] ) ) ? $config['settings']['send_itinerary_form_id']: null; +if ( isset( $form_id ) && filter_var( $form_id, FILTER_VALIDATE_INT ) ) { + // Send Trip Planner Form action after submission + add_action( 'gform_after_submission_' . $form_id, function(){ + unset( $_SESSION['travel-list'] ); + }, 10, 2); +} diff --git a/views/admin/settings/itinerary.html b/views/admin/settings/itinerary.html index 5439ff9..aa27f3c 100644 --- a/views/admin/settings/itinerary.html +++ b/views/admin/settings/itinerary.html @@ -18,6 +18,14 @@ + + + + +
Gravity Form Id For Trip Planner Form + + {if $itinerarySettings.fieldFail.send_itinerary_form_id}

{$itinerarySettings.fieldFail.send_itinerary_form_id}

{/if}
+
Trip Planner Page Id diff --git a/views/front/itinerary/create.html b/views/front/itinerary/create.html new file mode 100644 index 0000000..8a57b98 --- /dev/null +++ b/views/front/itinerary/create.html @@ -0,0 +1,83 @@ +{* Create Account Form *} + + + + + + + + +

Create an Account to Save your Trip Planner

+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ + diff --git a/views/front/itinerary/list.html b/views/front/itinerary/list.html index b873816..8fc5294 100644 --- a/views/front/itinerary/list.html +++ b/views/front/itinerary/list.html @@ -1,50 +1,61 @@ {* Trip Planner (Itinerary) List page *} +{if $members} +{/if}

{$settings.itinerary_page_content}

-
+ {if !$userLoggedIn} + +

Sign In:

- - - + + + - Forgot your Password? + Forgot your Password?

If you do not have an account

-
+ Create Account
By creating an account, you'll be able to save your list for later.
+ {else} +
+

Logged in as ...

+
+ {/if} + {if $members} + {/if}

-
-
-
- {if $members} +
+
+
+ {foreach $members as $data}
{$data.member_name} @@ -70,7 +81,6 @@
{/foreach} -{/if} +{/if} diff --git a/views/front/itinerary/moreinfo.html b/views/front/itinerary/moreinfo.html new file mode 100644 index 0000000..bebad0f --- /dev/null +++ b/views/front/itinerary/moreinfo.html @@ -0,0 +1,61 @@ +

Your Trip Planner List

+ +

Below is the list of businesses you have added to your Trip Planner. The +form below will be sent to each individual business listing that has an email +address listed with their business listing. For those businesses with no +email address, we have included their phone numbers for you to call directly +and request additional information.

+

These business listings have no current email address on file. To receive +additional information please call the phone numbers listed next to each +business name.

+ +{if count($membersNoEmails) > 0} +

Request Information by Phone From:

+

These business listings have no current email address on file. To receive + additional information please call the phone numbers listed next to each + business name.

+ + {foreach $membersNoEmails as $data} + + + + + + {/foreach} +
+ {if !$data.has_no_profile}{/if} + {$data.member_name} + {if !$data.has_no_profile}{/if} + + {apply_filters('glm_associate_phone_filter', $data.phone)} + +
+{/if} + +{if count($membersWithEmails) > 0} +

Request Information by Email From:

+

This list of businesses will receive the following information form directly + to their email account.

+ + {foreach $membersWithEmails as $data} + + + + + {/foreach} +
+ {if !$data.has_no_profile}{/if} + {$data.member_name} + {if !$data.has_no_profile}{/if} + + +
+ + {$formContents} + +{/if} + + +