Updates for referred by and db changes
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 23 May 2018 19:40:02 +0000 (15:40 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 23 May 2018 19:40:02 +0000 (15:40 -0400)
new db table for lead to referred by.
changes for notes delete add.

16 files changed:
classes/data/dataReferredBy.php [new file with mode: 0644]
css/admin.css [new file with mode: 0644]
index.php
models/admin/ajax/travelNotes.php
models/admin/settings/referredBy.php [new file with mode: 0644]
models/admin/travel/index.php
setup/adminTabs.php
setup/databaseScripts/create_database_V0.0.1.sql [deleted file]
setup/databaseScripts/create_database_V0.0.2.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.2.sql [new file with mode: 0644]
setup/validActions.php
views/admin/ajax/notes/list.html
views/admin/settings/referredBy.html [new file with mode: 0644]
views/admin/travel/edit.html
views/admin/travel/index.html

diff --git a/classes/data/dataReferredBy.php b/classes/data/dataReferredBy.php
new file mode 100644 (file)
index 0000000..ce1d611
--- /dev/null
@@ -0,0 +1,430 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Events
+ *
+ * PHP version 5.3
+ *
+ * @category Data
+ * @package  GLM Member-DB
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * GlmDataEvent class
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package GLM Member DB
+ * @author  Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *          @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott
+ *          Exp $
+ */
+class GlmDataReferredBy extends GlmDataAbstract
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Data Table Name
+     *
+     * @var $table
+     * @access public
+     */
+    public $table;
+    /**
+     * Field definitions
+     *
+     * 'type' is type of field as defined by the application
+     * text Regular text field
+     * pointer Pointer to an entry in another table
+     * 'filters' is the filter name for a particular filter ID in PHP filter
+     * functions
+     * See PHP filter_id()
+     *
+     * 'use' is when to use the field
+     * l = List
+     * g = Get
+     * n = New
+     * i = Insert
+     * e = Edit
+     * u = Update
+     * d = Delete
+     * a = All
+     *
+     * @var $ini
+     * @access public
+     */
+    public $fields = false;
+    /**
+     * MemberInfo DB object
+     *
+     * @var $MemberInfo
+     * @access public
+     */
+    public $MemberInfo;
+
+    /**
+     * Constructor
+     *
+     * @param object $d database connection
+     * @param array $config Configuration array
+     * @param bool $limitedEdit Flag to say indicate limited edit requested
+     *
+     * @return void
+     * @access public
+     */
+    public function __construct($wpdb, $config, $limitedEdit = false)
+    {
+
+        // If this class is not being extended along with existing $wpdb and $config
+        if (!$this->wpdb) {
+
+            // Save WordPress Database object
+            $this->wpdb = $wpdb;
+
+            // Save plugin configuration object
+            $this->config = $config;
+
+        }
+
+        /*
+         * Table Name
+         */
+        $this->table = GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'referredby';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field' => 'id',
+                'type' => 'integer',
+                'view_only' => true,
+                'use' => 'a'
+            ),
+
+            // Name
+            'name' => array(
+                'field' => 'name',
+                'type' => 'text',
+                'required' => true,
+                'unique' => true,
+                'use' => 'a'
+            ),
+
+            // Parent - for adding, deleting and editing, has selection tabels
+            'parent' => array(
+                'field' => 'parent',
+                'type' => 'pointer',
+                    'p_table' => GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'referredby',
+                    'p_field' => 'name',
+                    'p_orderby' => 'name',
+                    'p_blank' => true,
+                'force_list' => true,
+                'required' => false,
+                'use' => 'a'
+            )
+
+        );
+
+    }
+
+    /**
+     * Entry Post Processing Call-Back Method
+     *
+     * Perform post-processing for all result entries.
+     *
+     * In this case we're using it to append an array of category
+     * data to each member result and also sort by member name.
+     *
+     * @param array $r Array of field result data for a single entry
+     * @param string $a Action being performed (l, i, g, ...)
+     *
+     * @return object Class object
+     *
+     */
+    public function entryPostProcessing($r, $a)
+    {
+        return $r;
+    }
+
+
+   /**
+     * Add a category using supplied parameters
+     *
+     * @param string $name Category Name
+     * @param mixed $parent Existing Parent ID or name of parent to add
+     *
+     * @return integer ID of new category or false if failed
+     *
+     * @access public
+     */
+
+    public function addCategory($name, $parent) {
+
+        $categoryID = false;
+        $parentID = false;
+
+        // Filter new category name
+        $name = filter_var($name);
+        if ($name == false || trim($name) == '') {
+            return false;
+        }
+
+        // Determine parent supplied as an ID
+
+        $parentInt = $parent - 0;
+        if (is_int($parent) && $parentInt > 0) {
+
+            // If it's not positive, then fail
+            if ($parent <= 0) {
+                return false;
+            }
+
+            // Check that parent exists
+            $sql = "
+                SELECT COUNT(id) AS count
+                  FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+                 WHERE id = $parent
+            ;";
+            $test = $this->wpdb->get_row($sql, ARRAY_A);
+
+            // Should be only one entry if the parent category exists
+            if ($test['count'] != 1) {
+                return false;
+            }
+
+            $parentID = $parent;
+
+        // Else check to see if parent was supplied as a name
+        } elseif ($parent != '') {
+
+            $parent = filter_var($parent);
+
+            // If the name didn't pass the filer then fail
+            if ($parent == false) {
+                return false;
+            }
+
+            // Check if the name already exists
+            $sql = "
+                SELECT id
+                  FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+                 WHERE name = '$parent'
+            ;";
+            $parentCategory = $this->wpdb->get_row($sql, ARRAY_A);
+
+            // If we found the parent ID
+            if ($parentCategory['id']) {
+
+                // Set that as the parent ID for the new category
+                $parentID = $parentCategory['id'];
+
+            // Otherwise, try to add the parent category
+            } else {
+
+                // Add the parent as a new category
+                $sql = "
+                    INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+                           ( name, parent )
+                    VALUES
+                           ( '".addslashes($parent)."', 0 )
+                ;";
+                $this->wpdb->query($sql);
+                $parentID = $this->wpdb->insert_id;
+
+                // Check if it didn't store properly
+                if (!$parentID) {
+                    return false;
+                }
+
+            }
+
+        // Otherwise the categroy being added has no parent
+        } else {
+            $parentID = 0;
+        }
+
+        // Check if the new category name/parent already exists
+        $sql = "
+            SELECT id
+              FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+             WHERE name = '$name'
+               AND parent = $parentID
+        ;";
+        $existing = $this->wpdb->get_row($sql, ARRAY_A);
+
+        if ($existing['id']) {
+
+            $categoryID = $existing['id'];
+
+        } else {
+
+            // Try to add the new category
+            $sql = "
+                INSERT INTO ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+                       ( name, parent )
+                VALUES
+                       ( '".addslashes($name)."', $parentID )
+            ;";
+            $this->wpdb->query($sql);
+            $categoryID = $this->wpdb->insert_id;
+
+        }
+
+        return $categoryID;
+
+    }
+
+    /**
+     * Get categories list sorted by parent/child then alpha
+     *
+     * @return array Array of categories
+     * @param boolean $forEdit If true include list of options for each parent field
+     *
+     * @access public
+     */
+
+    public function getListSortedParentChild($forEdit = true) {
+
+        $categories = $this->getList();
+        $categoriesSorted = $this->sortParentChild($categories);
+
+        if (!$forEdit) {
+            while (list($k, $v) = each($categoriesSorted)) {
+                $categoriesSorted[$k]['parent_id'] = $v['parent']['value'];
+                $categoriesSorted[$k]['parent'] = $v['parent']['name'];
+            }
+        }
+
+        return $categoriesSorted;
+
+    }
+
+    /**
+     * getCategoriesWithCurrentEvents
+     *
+     * Returns a list of categories ordered by name that have an event with
+     * current event times.
+     *
+     * @access public
+     * @return void
+     */
+    public function getCategoriesWithCurrentEvents()
+    {
+        $where = " T.id IN (
+        SELECT category
+          FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories
+         WHERE event IN (
+                SELECT event
+                  FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+                 WHERE active
+                   AND start_time >= NOW()
+            )
+            AND event IN (
+               SELECT id
+                 FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events
+                WHERE status = 10
+            )
+        ) ";
+        $order = "T.name";
+        return $this->getList($where, $order);
+    }
+
+    /**
+     * Check other requirements
+     *
+     * When deleteing categories, check for references in sub-categories and set them to no parent.
+     *
+     */
+    function checkOther($r, $a)
+    {
+        // Required
+        parent::checkOther($r, $a);
+
+        // If there's a valid category ID
+        if (isset($r['id']) && $r['id'] > 0) {
+
+            // Set any parent references with this ID to 0
+            $sql = "
+                UPDATE ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX."categories
+                   SET parent = 0
+                 WHERE parent = ".$r['id']."
+            ;";
+            $this->wpdb->query($sql);
+
+        }
+
+        return $r;
+    }
+
+    /**
+     * Sort a database result array (from DataAbstract.php) by parent, child relationships
+     *
+     * @param array $array Array to be sorted
+     * @param string $name Name of array element that represents the text to sort on
+     * @param string $parent Name of the array element that represents the parent ID to sort on
+     *
+     * @return array Sorted array
+     */
+    public static function sortParentChild($array, $name = 'name', $parent = 'parent')
+    {
+
+        if (!is_array($array) || count($array) == 0) {
+            return false;
+        }
+
+        // Do a sort by custom function with it included in the call
+        // This lets me directly use $name and $parent in the sort function
+        uasort($array, function ($a, $b) use ($name, $parent) {
+            // If there's a parent, append the name of this entry to the parent
+            // The '~~~' simply keeps appended strings from any chance of a match with something else
+            if ($a[$parent]['value']) {
+                $aVal = $a[$parent]['name'].'~~~'.$a['name'];
+            } else {
+                // Otheriwse just use the name.
+                $aVal = $a['name'].'~~~';
+            }
+
+            // Same for b value
+            if ($b[$parent]['value']) {
+                $bVal = $b[$parent]['name'].'~~~'.$b['name'];
+            } else {
+                $bVal = $b['name'].'~~~';
+            }
+
+            if ($aVal > $bVal) {
+                return 1;
+            }
+
+            if ($aVal < $bVal) {
+                return -1;
+            }
+
+            return 0;
+
+        });
+
+        return $array;
+    }
+
+}
diff --git a/css/admin.css b/css/admin.css
new file mode 100644 (file)
index 0000000..e11a094
--- /dev/null
@@ -0,0 +1,35 @@
+.glm-travel-edit {
+    max-width: 600px;
+}
+
+.glm-travel-edit .tsLog {
+       margin: 10px 0;
+       border-top: 1px dotted #369;
+       border: 1px solid #eee;
+       height: 1%;
+       overflow: hidden;
+}
+.glm-travel-edit .tsLog h2 {
+       font-family: Georgia, arial, sans-serif;
+       font-size: 16px;
+       padding: 5px 10px;
+       background: #eee;
+       font-weight: normal;
+       margin: 0 0 1em 0 ;
+}
+.glm-travel-edit .tsLog p {
+       margin: 0 10px;
+}
+.glm-travel-edit .tlDelete {
+       display: block;
+       float: right;
+       width: 16px;
+       height: 16px;
+       background: url(../assets/cancel.png) no-repeat;
+       text-indent: -9000px;
+       margin: 10px;
+}
+
+#addLog textarea {
+    width: 500px;
+}
index 11455c0..743e580 100644 (file)
--- 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.1');
+define('GLM_MEMBERS_TRAVEL_PLUGIN_DB_VERSION', '0.0.2');
 
 // 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');
index 693be80..db556ec 100644 (file)
@@ -85,7 +85,7 @@ class GlmMembersAdmin_ajax_travelNotes extends GlmDataTravelNotes
         case 'list':
         default:
             $lead_id = filter_var( $_REQUEST['lead_id'], FILTER_VALIDATE_INT );
-            $notes  = $this->getList( "T.lead = $lead_id" );
+            $notes  = $this->getList( "T.lead = $lead_id", "T.created DESC" );
 
             $view = 'list.html';
             break;
diff --git a/models/admin/settings/referredBy.php b/models/admin/settings/referredBy.php
new file mode 100644 (file)
index 0000000..5436dc9
--- /dev/null
@@ -0,0 +1,193 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Event Categories List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Event Categories data abstract
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH.'/data/dataReferredBy.php';
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_settings_referredBy extends GlmDataReferredBy
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    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);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller 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.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $success        = true;
+        $haveReferredBy = false;
+        $referredby     = false;
+        $error          = false;
+
+        // Check if a category ID is supplied
+        $id = 0;
+        if (isset($_REQUEST['id'])) {
+            $id = $_REQUEST['id']-0;
+        }
+
+        // If there's an action option
+        if (isset($_REQUEST['option'])) {
+
+            switch($_REQUEST['option']) {
+
+                case 'addNew':
+                    $this->insertEntry();
+                    break;
+
+                case 'update':
+                    if ($id > 0) {
+                        $this->updateEntry($id);
+                    }
+                    break;
+
+                case 'delete':
+                    if ($id > 0) {
+                        $this->deleteEntry($id, true);
+
+                        // Also delete from member info
+                        $this->wpdb->delete(
+                            GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'referredby',
+                            array(
+                                'category' => $id
+                            )
+                        );
+                    }
+                    break;
+
+            }
+
+        }
+
+        // Get a current list of referredby
+        $referredby = $this->getList();
+
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveReferredBy = false;
+        if ($referredby !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($referredby) > 0) {
+                $haveReferredBy = true;
+            }
+        }
+
+        // If we had a fatal error, redirect to the error page
+        if ($error) {
+            return array(
+                'status' => $success,
+                'menuItemRedirect' => 'error',
+                'modelRedirect'    => 'index',
+                'view'             => 'admin/error/index.html',
+                'data'             => false
+            );
+        }
+
+        // Sort results by hierarchy (Parent/Child and Alpha)
+        $referredby = $this->sortParentChild($referredby);
+
+        // Compile template data
+        $templateData = array(
+            'haveReferredBy' => $haveReferredBy,
+            'referredby'     => $referredby
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/settings/referredBy.html',
+            'data'             => $templateData
+        );
+
+    }
+
+
+}
index 819d733..fb3e0b0 100644 (file)
@@ -363,14 +363,12 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
 
         switch ( $option ) {
         case 'addLog':
-            echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-
             $this->wpdb->insert(
                 GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'lead_notes',
                 array(
                     'lead'    => $this->entryId,
-                    'created' => date( 'Y-m-d' ),
-                    'updated' => date( 'Y-m-d' ),
+                    'created' => date( 'Y-m-d H:i:s' ),
+                    'updated' => date( 'Y-m-d H:i:s' ),
                     'notes'   => filter_var( $_REQUEST['new_log'], FILTER_SANITIZE_STRING )
                 ),
                 array(
@@ -381,6 +379,32 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
                 )
             );
 
+            // return array(
+            //     'status'           => true,
+            //     'modelRedirect'    => 'index',
+            //     // 'menuItemRedirect' => 'index',
+            //     'data'             => array(
+            //         'option' => 'edit',
+            //         'id'     => $this->entryId,
+            //     )
+            // );
+
+            $entry = $this->editEntry( $this->entryId );
+            $view = 'edit.html';
+            break;
+        case 'deleteLog':
+            if ( isset( $_REQUEST['id'] )
+                && isset( $_REQUEST['note_id'] )
+                && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT )
+                && $note_id = filter_var( $_REQUEST['note_id'], FILTER_VALIDATE_INT )
+            ) {
+                $this->wpdb->delete(
+                    GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX . 'lead_notes',
+                    array( 'lead' => $id, 'id'   => $note_id ),
+                    array( '%d', '%d' )
+                );
+            }
+
             $entry = $this->editEntry( $this->entryId );
             $view = 'edit.html';
             break;
index f506281..015bc89 100644 (file)
  *
  */
 
+if (current_user_can('glm_members_members')) {
+
+    add_filter('glm-member-db-add-tab-for-settings',
+        function($addOnTabs) {
+            $newTabs = array(
+                array(
+                    'text'   => 'Referred By',
+                    'menu'   => 'settings',
+                    'action' => 'referredBy'
+                ),
+
+            );
+            $addOnTabs = array_merge($addOnTabs, $newTabs);
+            return $addOnTabs;
+        }
+    );
+
+}
diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql
deleted file mode 100644 (file)
index a4cf815..0000000
+++ /dev/null
@@ -1,84 +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
-    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 Groups
-CREATE TABLE {prefix}referredby_groups (
-    id INT NOT NULL AUTO_INCREMENT,
-    name TEXT NOT NULL,                 -- Group Name
-    PRIMARY KEY (id)
-);
-
-----
-
--- ReferredBy
-CREATE TABLE {prefix}referredby (
-    id INT NOT NULL AUTO_INCREMENT,
-    groupid INT NOT NULL,               -- Group Id
-    name TINYTEXT NOT NULL,             -- Name
-    pos INT NOT NULL DEFAULT 0,         -- Position number
-    PRIMARY KEY (id),
-    INDEX(groupid)
-);
-
-----
-
--- 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
-    name TINYTEXT,                      -- Name of Contact
-    email TINYTEXT,                     -- Email of Contact
-    phone TINYTEXT,                     -- Phone of Contact
-    PRIMARY KEY (id),
-    INDEX(lead)
-);
diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..01c3e97
--- /dev/null
@@ -0,0 +1,86 @@
+-- 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
+    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
+    name TINYTEXT,                      -- Name of Contact
+    email TINYTEXT,                     -- Email of Contact
+    phone TINYTEXT,                     -- Phone of Contact
+    PRIMARY KEY (id),
+    INDEX(lead)
+);
index 1a972c5..e102a64 100644 (file)
@@ -26,6 +26,7 @@
  * exist with that version.
  */
 $glmMembersTravelDbVersions = array(
-    '0.0.1' => array('version' => '0.0.1', 'tables' => 5, 'date' => '05/18/18'),
+    '0.0.1' => array('version' => '0.0.1', 'tables' => 4, 'date' => '05/18/18'),
+    '0.0.2' => array('version' => '0.0.2', 'tables' => 5, 'date' => '05/23/18'),
 );
 
diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..df8e32d
--- /dev/null
@@ -0,0 +1,17 @@
+-- Gaslight Media Members Database  - Events Add-On
+-- File Created: 05/23/2018
+-- 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 dashes
+
+-- 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)
+);
index 89159c2..744dc39 100644 (file)
@@ -64,6 +64,9 @@ $glmMembersTravelAddOnValidActions = array(
             'travelInterest' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
             'travelNotes'    => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
         ),
+        'settings' => array(
+            'referredBy' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+        ),
         'travel' => array(
             'index' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
         )
index f1fb609..210fc8d 100644 (file)
@@ -3,13 +3,14 @@
     <input type="hidden" name="id" value="{$lead_id}" />
     <input type="hidden" name="page" value="{$editPage}" />
     <input type="hidden" name="option" value="addLog" />
-    <textarea name="new_log"></textarea>
+    <textarea name="new_log" cols="30" rows="5"></textarea>
     <input type="submit" class="button" value="New Note Entry" />
 </form>
 
 {foreach $notes as $n}
     <div class="tsLog">
         <h2>{$n.updated.datetime}</h2>
-        {$n.notes|nl2br}
+        <p>{$n.notes|nl2br}</p>
+        <a class="tlDelete" href="{$adminUrl}?page={$editPage}&option=deleteLog&id={$lead_id}&note_id={$n.id}#ui-id-6" title="Delete this entry">Delete</a>
     </div>
 {/foreach}
diff --git a/views/admin/settings/referredBy.html b/views/admin/settings/referredBy.html
new file mode 100644 (file)
index 0000000..89a3fc7
--- /dev/null
@@ -0,0 +1,179 @@
+{include file='admin/settings/header.html'}
+
+    <!-- Add ReferredBy Button and Dialog Box -->
+    <div id="newReferredByButton" class="button button-primary glm-right">Add a Referred By</div>
+    <div id="newReferredByDialog" class="glm-dialog-box" title="Enter a New Referred By">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="referredBy">
+            <input type="hidden" name="option" value="addNew">
+
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Referred By Name:</th>
+                    <td>
+                        <input type="text" name="name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Parent Referred By:</th>
+                    <td>
+                        <select name="parent">
+                            <option value="0">(none)</option>
+                                {if $haveReferredBy}
+                                    {foreach $referredby as $t}
+                                        {if !$t.parent.value} <!-- don't show child referredby -->
+                                            <option value="{$t.id}">{$t.name}</option>
+                                        {/if}
+                                    {/foreach}
+                                {/if}
+                        </select>
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="newReferredByCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Add new Referred By" class="button button-primary">
+        </form>
+    </div>
+
+    <!-- Delete ReferredBy Button and Dialog Box -->
+    <div id="deleteReferredByDialog" class="glm-dialog-box" title="Delete Referred By">
+        <center>
+            <p>Are you sure you want to delete this referred by?</p>
+            <p><div id="deleteReferredByConfirm" class="button button-primary">Yes, delete this referred by</div></p>
+            <p><div id="deleteReferredByCancel" class="button button-primary">Cancel</div></p>
+        </center>
+    </div>
+
+    <!-- Edit ReferredBy Dialog Box -->
+    <div id="editReferredByDialog" class="glm-dialog-box" title="Edit this Referred By">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="referredBy">
+            <input type="hidden" name="option" value="update">
+            <input id="editReferredByID" type="hidden" name="id" value="">
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Referred By Name:</th>
+                    <td>
+                        <input id="editReferredByName" type="text" name="name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Parent Referred By:</th>
+                    <td>
+                        <select id="editReferredByParent" name="parent">
+                            <option value="0">(none)</option>
+            {if $haveReferredBy}
+                {foreach $referredby as $t}
+                    {if !$t.parent.value} <!-- don't show child referredby -->
+                            <option value="{$t.id}">{$t.name}</option>
+                    {/if}
+                {/foreach}
+            {/if}
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Description:</th>
+                    <td>
+                        <textarea id="editReferredByDescr" name="descr" class="glm-form-textarea"></textarea>
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="editReferredByCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Update this Referred By">
+        </form>
+    </div>
+
+    <h2>Referred By</h2>
+
+    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+        <thead>
+            <tr>
+                <th>ID</th>
+                <th>Referred By</th>
+                <th>&nbsp;</th>
+            </tr>
+        </thead>
+        <tbody>
+{if $haveReferredBy}
+    {assign var="i" value="0"}
+    {foreach $referredby as $t}
+        {if $i++ is odd by 1}
+            <tr>
+        {else}
+            <tr class="alternate">
+        {/if}
+                <td>{$t.id}</td>
+                <td>
+                    <div{if $t.parent.value} class="glm-indent"{/if}>
+                        <a class="editReferredBy" data-referredByID="{$t.id}" data-referredByParent="{$t.parent.value}">{$t.name}</a>
+                    </div>
+                </td>
+                <td>
+                    <div class="deleteReferredByButton button button-secondary glm-button-small glm-right" data-referredByID="{$t.id}">Delete</div>
+                </td>
+            </tr>
+    {/foreach}
+{else}
+            <tr class="alternate"><td colspan="2">(no referred by listed)</td></tr>
+{/if}
+        </tbody>
+    </table>
+
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+
+            $("#newReferredByDialog").dialog({
+               autoOpen: false,
+               minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#editReferredByDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#deleteReferredByDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+
+            $('#newReferredByButton').click( function() {
+                $("#newReferredByDialog").dialog("open");
+            });
+            $('.editReferredBy').click( function() {
+                var catID = $(this).attr('data-referredByID');
+                var catName = $(this).text();
+                var catParent = $(this).attr('data-referredByParent');
+                $('#editReferredByID').val(catID);
+                $('#editReferredByName').val(catName.trim());
+                $('#editReferredByParent').val(catParent);
+                $("#editReferredByDialog").dialog("open");
+            });
+            $('#editReferredByCancel').click( function() {
+                $("#editReferredByDialog").dialog("close");
+            });
+            $('#newReferredByCancel').click( function() {
+                $("#newReferredByDialog").dialog("close");
+            });
+
+            var id = false;
+            $('.deleteReferredByButton').click( function() {
+                id = $(this).attr('data-referredByID');
+                $("#deleteReferredByDialog").dialog("open");
+            });
+            $('#deleteReferredByConfirm').click( function() {
+                $("#deleteReferredByDialog").dialog("close");
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=referredBy&option=delete&id=" + id;
+            });
+            $('#deleteReferredByCancel').click( function() {
+                $("#deleteReferredByDialog").dialog("close");
+            });
+
+        });
+    </script>
+
+{include file='admin/footer.html'}
index d788d19..782369b 100644 (file)
 </div>
 {/if}
 
-<div id="tabs" style="max-width: 600px;">
+<div id="tabs" class="glm-travel-edit">
 
     <ul>
         <li><a href="#tabs-1">Lead</a></li>
         {if isset($lead.fieldData) && isset($lead.fieldData.id)}
             <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelContacts&lead_id={$lead.fieldData.id}">Contacts</a></li>
-            <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelInterests&lead_id={$lead.fieldData.id}">Interest</a></li>
+            <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelInterests&lead_id={$lead.fieldData.id}">Referred By</a></li>
             <li><a href="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=travelNotes&lead_id={$lead.fieldData.id}">Notes</a></li>
         {/if}
     </ul>
index e746ccf..fd3a043 100644 (file)
@@ -6,12 +6,12 @@
 <table class="wp-list-table widefat fixed posts glm-admin-table">
     <thead>
         <tr>
-            <th>Edit</th>
-            <th>Company</th>
-            <th>First Name</th>
-            <th>Last Name</th>
-            <th>Updated</th>
-            <th>Status</th>
+            <th width="20"> Edit </th>
+            <th> Company </th>
+            <th> First Name </th>
+            <th> Last Name </th>
+            <th> Updated </th>
+            <th> Status </th>
         </tr>
     </thead>
     <tbody>