Setting up new table for the member lead reports.
Setup a search form and new admin menu for the reporting.
* 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');
// See if they have a saved search to use.
if ( isset( $wpUser ) && $wpUser ) {
+ $user = $this->config['loggedInUser'];
+ // echo '<pre>$user: ' . print_r( $user, true ) . '</pre>';
$result = $this->wpdb->get_row(
$this->wpdb->prepare(
"SELECT *
)
);
}
-// echo '<pre>$search_params: ' . print_r( $search_params, true ) . '</pre>';
// If we have wpUser then save searches for them.
if ( $wpUser['ID'] ) {
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
--- /dev/null
+<?php
+/**
+ * Gaslight Media Member Leads Database
+ * Leads search, list, edit page
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @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 '<pre>$stime: ' . print_r( $stime, true ) . '</pre>';
+ // echo '<pre>$etime: ' . print_r( $etime, true ) . '</pre>';
+
+ $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 '<pre>$list: ' . print_r( $list, true ) . '</pre>';
+ }
+
+ // 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
+ );
+
+ }
+
+}
'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');}
+ );
}
+++ /dev/null
--- 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)
-);
--- /dev/null
+-- 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)
+);
'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'),
);
-- 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,
--- /dev/null
+-- 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)
+);
'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,
'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,
--- /dev/null
+{include file='admin/travel/header.html'}
+
+<style>
+/* Table Grid */
+#dataGrid2 {
+ margin: 0.5em 0 1em 0;
+ background: rgba(255, 255, 255, 0.0);
+ }
+#dataGrid2, #dataGrid2 tr, #dataGrid2 th, #dataGrid2 td {
+ border: 1px solid #999;
+ border-collapse: collapse;
+ }
+#dataGrid2 th, #dataGrid2 td {
+ padding: 10px 20px;
+ }
+#dataGrid2 th {
+ background: #fff;
+ }
+#dataGrid2 tr:nth-child(even) {
+ background: rgba(231, 231, 231, .9);
+ }
+#dataGrid2 tr:nth-child(odd) {
+ background: rgba(248, 248, 248, .9);;
+ }
+#dataGrid2 tr:hover {
+ background: #fff;
+ /* cursor: pointer; */
+ }
+#dataGrid2 tr.nohand:hover{
+ /* cursor: initial !important; */
+}
+#dataGrid2 a {
+ text-decoration: underline;
+ color: black;
+ }
+#dataGrid2 th a {
+ text-decoration: underline;
+ font-family: Georgia, arial, sans-serif;
+ white-space: nowrap;
+ }
+</style>
+
+<div id="travel-admin2">
+
+ <form action="{$thisUrl}">
+ <input type="hidden" name="page" value="glm-members-admin-menu-glm-travel-reports" />
+ <input type="hidden" name="option" value="search" />
+ <div>
+ Show Summary for Month
+ <select name="report_month">
+ {foreach $months as $m}
+ <option value="{$m.month}|{$m.year}">{$m.full_month} {$m.year}</option>
+ {/foreach}
+ </select>
+ <input type="submit" value="Go" />
+ </div>
+ </form>
+
+{if $list}
+ <table id="dataGrid2" class="dataGrid2" style="width: 90%;">
+ <thead>
+ <tr class="nohand">
+ <th> Member Name </th>
+ <th> Download Date </th>
+ </tr>
+ </thead>
+ <tbody>
+ {foreach $list as $row}
+ <tr>
+ <td>
+ <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=index&member={$row.member_id}">
+ {$row.name}
+ </a>
+ </td>
+ <td width="120">{$row.search_date|date_format:"%m/%d/%Y"}</td>
+ </tr>
+ {/foreach}
+ </tbody>
+ </table>
+{/if}
+
+</div>
+
+{include file='admin/travel/footer.html'}