From: Steve Sutton Date: Mon, 13 Aug 2018 17:35:42 +0000 (-0400) Subject: Setup the tables for reports and search form X-Git-Tag: v1.0.0^2~12 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=62f28cc53b2e86377350f9851d9c98f4a6ab0998;p=WP-Plugins%2Fglm-member-db-travel.git Setup the tables for reports and search form Setting up new table for the member lead reports. Setup a search form and new admin menu for the reporting. --- diff --git a/index.php b/index.php index 9f14c7a..74f0124 100644 --- a/index.php +++ b/index.php @@ -44,7 +44,7 @@ if (!defined('ABSPATH')) { * version from this plugin. */ define('GLM_MEMBERS_TRAVEL_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_TRAVEL_PLUGIN_DB_VERSION', '0.0.4'); +define('GLM_MEMBERS_TRAVEL_PLUGIN_DB_VERSION', '0.0.5'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_TRAVEL_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/travel/members.php b/models/admin/travel/members.php index 7b7ca9a..d533fa5 100644 --- a/models/admin/travel/members.php +++ b/models/admin/travel/members.php @@ -152,6 +152,8 @@ class GlmMembersAdmin_travel_members extends GlmDataTravelLeads // See if they have a saved search to use. if ( isset( $wpUser ) && $wpUser ) { + $user = $this->config['loggedInUser']; + // echo '
$user: ' . print_r( $user, true ) . '
'; $result = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * @@ -213,7 +215,6 @@ class GlmMembersAdmin_travel_members extends GlmDataTravelLeads ) ); } -// echo '
$search_params: ' . print_r( $search_params, true ) . '
'; // If we have wpUser then save searches for them. if ( $wpUser['ID'] ) { @@ -238,6 +239,19 @@ class GlmMembersAdmin_travel_members extends GlmDataTravelLeads array( '%s', '%s', '%d', '%s' ) ); } + // Every Time a user request a search store a report. + // They need to have a logged in contact. + // Need to get the member id. + if ( $searching && isset( $this->config['loggedInUser']['contactUser']['ref_dest'] ) ) { + if ( $member_id = filter_var( $this->config['loggedInUser']['contactUser']['ref_dest'], FILTER_VALIDATE_INT ) ) { + $this->wpdb->insert( + GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'search_reports', + array( 'member_id' => $member_id, 'search_date' => date( 'Y-m-d H:i:s' ) ), + array( '%d', '%s' ) + ); + } + } + } // build the $where part diff --git a/models/admin/travel/reports.php b/models/admin/travel/reports.php new file mode 100644 index 0000000..9352551 --- /dev/null +++ b/models/admin/travel/reports.php @@ -0,0 +1,169 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Leads data abstract +require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH.'/data/dataLeads.php'; +require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataContacts.php'; +require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataNotes.php'; + +class GlmMembersAdmin_travel_reports //extends GlmDataTravelLeads +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + public $entryId = false; + /* + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull 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 the data class + * + * Note, the third parameter is a flag that indicates to the + * data class that it should flag a group of fields as 'view_only'. + */ + // parent::__construct(false, false, true); + + + } + + public function modelAction($actionData = false) + { + $where = ' true '; + $option = false; + $hasSearch = false; + + // Get any provided option + if ( isset( $_REQUEST['option'] ) ) { + $option = $_REQUEST['option']; + } + + // Only get active leads. + // $where_parts = array( 'T.status = ' . $this->config['lead_status_numb']['Active'] ); + + switch ( $option ) { + default: + + $list = array(); + + if ( isset( $_REQUEST['report_month'] ) && $monthYear = filter_var( $_REQUEST['report_month'] ) ) { + + if ($monthYear) { + list($month, $year) = explode("|", $monthYear); + } else { + $month = date('n'); + $year = date('Y'); + } + + $stime = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year)); + $etime = date('Y-m-d', mktime(0, 0, 0, $month +1, -1, $year)); + + // echo '
$stime: ' . print_r( $stime, true ) . '
'; + // echo '
$etime: ' . print_r( $etime, true ) . '
'; + + $list = $this->wpdb->get_results( + "SELECT R.search_date,R.member_id,M.name + FROM " . GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . "search_reports R + LEFT OUTER JOIN " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members M + ON (M.id = R.member_id) + WHERE R.search_date BETWEEN '$stime' AND '$etime'", + ARRAY_A + ); + + // echo '
$list: ' . print_r( $list, true ) . '
'; + } + + // Get paging results + $view = 'reports.html'; + + break; + } + + $months = $this->wpdb->get_results( + "SELECT MONTH(search_date) as month, YEAR(search_date) as year + FROM " . GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . "search_reports + GROUP BY month, year", + ARRAY_A + ); + + // Add Month name to $months + if ( isset( $months ) && !empty( $months ) ) { + foreach ( $months as $key => $row ) { + $months[$key]['full_month'] = date( 'F', mktime( 0, 0, 0, $row['month'], $row['year']) ); + } + } + + // Common things to place into the $templateData array + $templateData = array( + 'hasSearch' => $hasSearch, + 'list' => $list, + 'months' => $months, + ); + + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'admin/travel/' . $view, + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminMenus.php b/setup/adminMenus.php index 4836ab1..9c6688e 100644 --- a/setup/adminMenus.php +++ b/setup/adminMenus.php @@ -59,19 +59,23 @@ add_submenu_page( 'glm-members-admin-menu-glm-travel', function(){$this->controller('travel');} ); +add_submenu_page( + 'glm-members-admin-menu-members', + 'Reports', + '    Reports', + 'glm_members_members', + 'glm-members-admin-menu-glm-travel-reports', + function() {$this->controller('travel', 'reports');} +); // If a contact is logged in (ownEntity isn't false), add Contact Profile menu item if ( isset( $this->config['loggedInUser']['contactUser'] ) && $this->config['loggedInUser']['contactUser'] ) { - // Check for the option GLM_MEMBERS_LEADS_PLUGIN_MEMBER_ACCESS_OPTION - // $memberCanAccessLeads = get_option( GLM_MEMBERS_LEADS_PLUGIN_MEMBER_ACCESS_OPTION ); - // if ( $memberCanAccessLeads ) { - add_submenu_page( - $mainMenuSlug, - 'Travel Leads', - 'Travel Leads', - 'glm_members_edit_my_entity', - 'glm-members-admin-menu-glm-travel', - function() {$this->controller('travel', 'members');} - ); - // } + add_submenu_page( + $mainMenuSlug, + 'Travel Leads', + 'Travel Leads', + 'glm_members_edit_my_entity', + 'glm-members-admin-menu-glm-travel', + function() {$this->controller('travel', 'members');} + ); } diff --git a/setup/databaseScripts/create_database_V0.0.3.sql b/setup/databaseScripts/create_database_V0.0.3.sql deleted file mode 100644 index a4d075e..0000000 --- a/setup/databaseScripts/create_database_V0.0.3.sql +++ /dev/null @@ -1,100 +0,0 @@ --- Gaslight Media Travel Leads Module --- File Created: 05/18/2018 --- 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 --- --- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES **** --- - --- Leads -CREATE TABLE {prefix}leads ( - id INT NOT NULL AUTO_INCREMENT, - status INT NOT NULL DEFAULT 0, -- Lead Status (active, inactive) - create_date DATE NOT NULL, -- Date contact was created - updated DATETIME NOT NULL, -- Updated Timestamp - title TEXT NULL, -- Title of Lead - fname TEXT NULL, -- First Name - lname TEXT NULL, -- Last Name - email TINYTEXT NULL, -- Email - company TEXT NULL, -- Company Name - address TEXT NULL, -- Address - address2 TEXT NULL, -- Address 2 - city TEXT NULL, -- City - state TEXT NULL, -- State - zip TEXT NULL, -- ZIP - phone TEXT NULL, -- Phone - fax TEXT NULL, -- Fax - mail_ok BOOLEAN DEFAULT false, -- Mail OK (boolean) - website TEXT NULL, -- Website URL - PRIMARY KEY (id), - INDEX(create_date), - INDEX(email(20)), - INDEX(fname(20)), - INDEX(lname(20)) -); - ----- - --- ReferredBy -CREATE TABLE {prefix}referredby ( - id INT NOT NULL AUTO_INCREMENT, - parent INT NOT NULL, -- Pointer to the parent referredby id - name TINYTEXT NOT NULL, -- Name - PRIMARY KEY (id), - INDEX(parent) -); - ----- - --- Referred By to Leads -CREATE TABLE {prefix}leads_referredby ( - id INT NOT NULL AUTO_INCREMENT, - lead INT NOT NULL, -- Reference to lead table - referredby INT NOT NULL, -- Reference to referred by table - PRIMARY KEY (id), - INDEX(lead), - INDEX(referredby) -); - ----- - --- Lead Notes -CREATE TABLE {prefix}lead_notes ( - id INT NOT NULL AUTO_INCREMENT, - lead INT NOT NULL, -- Reference to lead table - created DATETIME NOT NULL, -- Created Timestamp - updated DATETIME NOT NULL, -- Updated Timestamp - notes TEXT, -- Note Entry - PRIMARY KEY (id), - INDEX(lead) -); - ----- - --- Lead Contacts -CREATE TABLE {prefix}lead_contacts ( - id INT NOT NULL AUTO_INCREMENT, - lead INT NOT NULL, -- Reference to lead table - updated DATETIME NOT NULL, -- Updated Timestamp - title TINYTEXT NULL, -- Title of Contact - name TINYTEXT, -- Name of Contact - email TINYTEXT, -- Email of Contact - phone TINYTEXT, -- Phone of Contact - PRIMARY KEY (id), - INDEX(lead) -); - ----- - --- Lead Searches -CREATE TABLE {prefix}searches ( - id INT NOT NULL AUTO_INCREMENT, - user_id INT NOT NULL, -- The wordpress user id - updated DATETIME NOT NULL, -- Last Update Date Time - title TINYTEXT NULL, -- Title for this search configuration - search TEXT NULL, -- Serialized array of search parameters - PRIMARY KEY (id) -); diff --git a/setup/databaseScripts/create_database_V0.0.5.sql b/setup/databaseScripts/create_database_V0.0.5.sql new file mode 100644 index 0000000..863163c --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.5.sql @@ -0,0 +1,110 @@ +-- Gaslight Media Travel Leads Module +-- File Created: 05/18/2018 +-- Database Version: 0.0.5 +-- Database Creation Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes +-- +-- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES **** +-- + +-- Leads +CREATE TABLE {prefix}leads ( + id INT NOT NULL AUTO_INCREMENT, + status INT NOT NULL DEFAULT 0, -- Lead Status (active, inactive) + create_date DATE NOT NULL, -- Date contact was created + updated DATETIME NOT NULL, -- Updated Timestamp + title TEXT NULL, -- Title of Lead + fname TEXT NULL, -- First Name + lname TEXT NULL, -- Last Name + email TINYTEXT NULL, -- Email + company TEXT NULL, -- Company Name + address TEXT NULL, -- Address + address2 TEXT NULL, -- Address 2 + city TEXT NULL, -- City + state TEXT NULL, -- State + zip TEXT NULL, -- ZIP + phone TEXT NULL, -- Phone + fax TEXT NULL, -- Fax + mail_ok BOOLEAN DEFAULT false, -- Mail OK (boolean) + website TEXT NULL, -- Website URL + PRIMARY KEY (id), + INDEX(create_date), + INDEX(email(20)), + INDEX(fname(20)), + INDEX(lname(20)) +); + +---- + +-- ReferredBy +CREATE TABLE {prefix}referredby ( + id INT NOT NULL AUTO_INCREMENT, + parent INT NOT NULL, -- Pointer to the parent referredby id + name TINYTEXT NOT NULL, -- Name + PRIMARY KEY (id), + INDEX(parent) +); + +---- + +-- Referred By to Leads +CREATE TABLE {prefix}leads_referredby ( + id INT NOT NULL AUTO_INCREMENT, + lead INT NOT NULL, -- Reference to lead table + referredby INT NOT NULL, -- Reference to referred by table + PRIMARY KEY (id), + INDEX(lead), + INDEX(referredby) +); + +---- + +-- Lead Notes +CREATE TABLE {prefix}lead_notes ( + id INT NOT NULL AUTO_INCREMENT, + lead INT NOT NULL, -- Reference to lead table + created DATETIME NOT NULL, -- Created Timestamp + updated DATETIME NOT NULL, -- Updated Timestamp + notes TEXT, -- Note Entry + PRIMARY KEY (id), + INDEX(lead) +); + +---- + +-- Lead Contacts +CREATE TABLE {prefix}lead_contacts ( + id INT NOT NULL AUTO_INCREMENT, + lead INT NOT NULL, -- Reference to lead table + updated DATETIME NOT NULL, -- Updated Timestamp + title TINYTEXT NULL, -- Title of Contact + name TINYTEXT, -- Name of Contact + email TINYTEXT, -- Email of Contact + phone TINYTEXT, -- Phone of Contact + PRIMARY KEY (id), + INDEX(lead) +); + +---- + +-- Lead Searches +CREATE TABLE {prefix}searches ( + id INT NOT NULL AUTO_INCREMENT, + user_id INT NOT NULL, -- The wordpress user id + updated DATETIME NOT NULL, -- Last Update Date Time + title TINYTEXT NULL, -- Title for this search configuration + search TEXT NULL, -- Serialized array of search parameters + PRIMARY KEY (id) +); + +---- + +-- Member Downloads +CREATE TABLE {prefix}search_reports ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, -- Member Id + search_date DATETIME NOT NULL, -- date time of the search + PRIMARY KEY (id) +); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index afded64..8d6c6d8 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -30,5 +30,6 @@ $glmMembersTravelDbVersions = array( '0.0.2' => array('version' => '0.0.2', 'tables' => 5, 'date' => '05/23/18'), '0.0.3' => array('version' => '0.0.3', 'tables' => 6, 'date' => '05/31/18'), '0.0.4' => array('version' => '0.0.4', 'tables' => 6, 'date' => '06/07/18'), + '0.0.5' => array('version' => '0.0.5', 'tables' => 7, 'date' => '08/13/18'), ); diff --git a/setup/databaseScripts/update_database_V0.0.4.sql b/setup/databaseScripts/update_database_V0.0.4.sql index 01d7d66..9221cf9 100644 --- a/setup/databaseScripts/update_database_V0.0.4.sql +++ b/setup/databaseScripts/update_database_V0.0.4.sql @@ -1,6 +1,6 @@ -- Gaslight Media Members Database - Events Add-On -- File Created: 05/31/2018 --- Database Version: 0.0.3 +-- Database Version: 0.0.4 -- Database Update From Previous Version Script -- -- To permit each query below to be executed separately, diff --git a/setup/databaseScripts/update_database_V0.0.5.sql b/setup/databaseScripts/update_database_V0.0.5.sql new file mode 100644 index 0000000..74f1ed2 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.5.sql @@ -0,0 +1,15 @@ +-- Gaslight Media Members Database - Events Add-On +-- File Created: 08/13/2018 +-- Database Version: 0.0.5 +-- 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 dashes + +-- Member Downloads +CREATE TABLE {prefix}search_reports ( + id INT NOT NULL AUTO_INCREMENT, + member_id INT NOT NULL, -- Member Id + search_date DATETIME NOT NULL, -- date time of the search + PRIMARY KEY (id) +); diff --git a/setup/validActions.php b/setup/validActions.php index abd089f..a25949b 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -64,8 +64,8 @@ $glmMembersTravelAddOnValidActions = array( 'travelReferredby' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, 'travelSearch' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, 'travelNotes' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, - 'leadCsvExport' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, - 'leadPdfExport' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, + 'leadCsvExport' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, + 'leadPdfExport' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, ), 'settings' => array( 'referredBy' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, @@ -73,6 +73,7 @@ $glmMembersTravelAddOnValidActions = array( 'travel' => array( 'index' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, 'members' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, + 'reports' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, ), 'import' =>array( 'travel' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG, diff --git a/views/admin/travel/reports.html b/views/admin/travel/reports.html new file mode 100644 index 0000000..3389b0e --- /dev/null +++ b/views/admin/travel/reports.html @@ -0,0 +1,84 @@ +{include file='admin/travel/header.html'} + + + +
+ +
+ + +
+ Show Summary for Month + + +
+
+ +{if $list} + + + + + + + + + {foreach $list as $row} + + + + + {/foreach} + +
Member Name Download Date
+ + {$row.name} + + {$row.search_date|date_format:"%m/%d/%Y"}
+{/if} + +
+ +{include file='admin/travel/footer.html'}