Add Counties
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 30 Mar 2017 20:42:22 +0000 (16:42 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 4 Apr 2017 20:32:05 +0000 (16:32 -0400)
Adding Counties table.
Adding Counties into Settings.
Adding County to member info record.

classes/data/dataCounties.php [new file with mode: 0644]
classes/data/dataMemberInfo.php
models/admin/settings/counties.php [new file with mode: 0644]
setup/validActions.php
views/admin/settings/counties.html [new file with mode: 0644]
views/admin/settings/header.html

diff --git a/classes/data/dataCounties.php b/classes/data/dataCounties.php
new file mode 100644 (file)
index 0000000..767b81f
--- /dev/null
@@ -0,0 +1,191 @@
+<?php
+
+/**
+ * GLM Member-DB WordPress Plugin
+ * Counties data class
+ *
+ * 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: dataMemberType.php,v 1.0 2011/01/25 19:31:47 cscott Exp $
+ */
+
+/**
+ * EventManagementDataCounties class
+ *
+ * PHP version 5
+ *
+ * @category Data
+ * @package EventManagement
+ * @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 GlmDataCounties extends GlmDataAbstract
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Field definitions
+     *
+     * @var $ini
+     * @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;
+
+    /**
+     * Constructor
+     *
+     * @param object $d
+     *            database connection
+     *
+     * @return void
+     * @access public
+     */
+    function __construct ($wpdb, $config)
+    {
+
+        // 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_PLUGIN_DB_PREFIX . 'counties';
+
+        /*
+         * 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'
+            ),
+
+            // Description
+            'descr' => array(
+                'field' => 'descr',
+                'type' => 'text',
+                'use' => 'a'
+            ),
+
+            // Short Description
+            'short_descr' => array(
+                'field' => 'short_descr',
+                'type' => 'text',
+                'use' => 'a'
+            )
+
+
+        );
+
+        if (is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($this->fields, 'DataBlock', 'Table Fields: '.$this->table);
+        }
+
+    }
+
+
+    /**
+     * Get counties list sorted by alpha
+     *
+     * @param boolean $forActiveMembers Return only counties that are referenced in active members
+     *
+     * @return array Array of categories
+     * @access public
+     */
+
+    public function getListForSearch($forActiveMembers = false) {
+
+        $where = '';
+
+        // If we only want counties for active and visible members
+        if ($forActiveMembers) {
+            $where = "T.id in (
+                SELECT DISTINCT(MI.county)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI,
+                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M
+                 WHERE MI.status = ".$this->config['status_numb']['Active']."
+                   AND M.id = MI.member
+                   AND M.access IN (
+                          ".$this->config['access_numb']['NoAccess'].",
+                          ".$this->config['access_numb']['Moderated'].",
+                          ".$this->config['access_numb']['Full']."
+                       )
+                )
+            ";
+        }
+
+        // Get a list of all counties (optionally for active members only)
+        $counties = $this->getList($where);
+
+        return $counties;
+
+    }
+
+
+}
+
+?>
index 339e0a4..1d1220f 100644 (file)
@@ -299,6 +299,18 @@ class GlmDataMemberInfo extends GlmDataAbstract
                 'use' => 'a'
             ),
 
+            // County
+            'county' => array(
+                'field' => 'county',
+                'type' => 'pointer',
+                    'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'counties',
+                    'p_field' => 'name',
+                    'p_orderby' => 'name',
+                    'p_blank' => true,
+                //  'force_list' => true,
+                'use' => 'a'
+            ),
+
             // Phone
             'phone' => array(
                 'field'    => 'phone',
@@ -770,6 +782,7 @@ class GlmDataMemberInfo extends GlmDataAbstract
                 'email'         => $f['email'],
                 'url'           => $f['url'],
                 'region'        => $f['region'],
+                'county'        => $f['county'],
                 'cc_type'       => $f['cc_type'],
                 'logo'          => $f['logo'],
                 'descr'         => $f['descr'],
diff --git a/models/admin/settings/counties.php b/models/admin/settings/counties.php
new file mode 100644 (file)
index 0000000..a13267e
--- /dev/null
@@ -0,0 +1,195 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin Counties 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 Member Types data abstract
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.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_counties extends GlmDataCounties
+{
+
+    /**
+     * 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 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.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $success        = true;
+        $haveCounties    = false;
+        $counties        = false;
+        $error          = false;
+        $enable_members = $this->config['settings']['enable_members'];
+
+        // Check for county id
+        $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);
+                    }
+                    break;
+
+            }
+
+        }
+
+        // Get a current list of members
+        $counties = $this->getList('', 'name');
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($counties, 'DataBlock', 'County Data');
+        }
+
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveCounties = false;
+        if ($counties !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($counties) > 0) {
+                $haveCounties = 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
+            );
+        }
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
+            glmMembersAdmin::addNotice($counties, 'DataBlock', 'Counties Data');
+        }
+
+        // Compile template data
+        $templateData = array(
+            'enable_members' => $enable_members,
+            'haveCounties'    => $haveCounties,
+            'counties'        => $counties
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/settings/counties.html',
+            'data'             => $templateData
+        );
+
+    }
+
+
+}
+
+?>
index 4ba560d..eab646d 100644 (file)
@@ -65,6 +65,7 @@ $glmMembersValidActions = array(
             'categories' => 'glm-member-db',
             'cities'     => 'glm-member-db',
             'regions'    => 'glm-member-db',
+            'counties'   => 'glm-member-db',
             'amenities'  => 'glm-member-db',
         ),
         'management' => array(
diff --git a/views/admin/settings/counties.html b/views/admin/settings/counties.html
new file mode 100644 (file)
index 0000000..5222b27
--- /dev/null
@@ -0,0 +1,174 @@
+{include file='admin/settings/header.html'}
+
+    <!-- Add Counties Button and Dialog Box -->
+    <div id="newCountyButton" class="button button-primary glm-right">Add a County</div>
+    <div id="newCountyDialog" class="glm-dialog-box" title="Enter a New County">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="counties">
+            <input type="hidden" name="option" value="addNew">
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">County Name:</th>
+                    <td>
+                        <input type="text" name="name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Description:</th>
+                    <td>
+                        <textarea name="descr" class="glm-form-textarea"></textarea>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Short Description:</th>
+                    <td>
+                        <input type="text" name="short_descr" class="glm-form-text-input">
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="newCountyCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Add new County" class="button button-primary">
+        </form>
+    </div>
+
+    <!-- Add Counties Button -->
+    <div id="deleteCountyDialog" class="glm-dialog-box" title="Delete County">
+        <center>
+            <p>Are you sure you want to delete this county?</p>
+            <p><div id="deleteCountyConfirm" class="button button-primary">Yes, delete this county</div></p>
+            <p><div id="deleteCountyCancel" class="button button-primary">Cancel</div></p>
+        </center>
+    </div>
+
+    <!-- Edit Counties Dialog Box -->
+    <div id="editCountyDialog" class="glm-dialog-box" title="Edit this County">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="counties">
+            <input type="hidden" name="option" value="update">
+            <input id="editCountyID" type="hidden" name="id" value="">
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">County Name:</th>
+                    <td>
+                        <input id="editCountyName" type="text" name="name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Description:</th>
+                    <td>
+                        <textarea id="editCountyDescr" name="descr" class="glm-form-textarea"></textarea>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Short Description:</th>
+                    <td>
+                        <input id="editCountyShortDescr" type="text" name="short_descr" class="glm-form-text-input">
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="editCountyCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Update this County">
+        </form>
+    </div>
+
+    <h2>Counties</h2>
+
+    <table class="wp-list-table widefat fixed posts glm-admin-table"">
+        <thead>
+            <tr>
+                <th>ID</th>
+                <th>County</th>
+                <th>Description</th>
+                <th>Short Description</th>
+                <th>&nbsp;</th>
+            </tr>
+        </thead>
+        <tbody>
+{if $haveCounties}
+    {assign var="i" value="0"}
+    {foreach $counties as $t}
+        {if $i++ is odd by 1}
+            <tr>
+        {else}
+            <tr class="alternate">
+        {/if}
+                <td>{$t.id}</td>
+                <td>
+                    <a class="editCounty" data-countyID="{$t.id}">{$t.name}</a>
+                </td>
+                <td id="editCountyDescr_{$t.id}">
+                    {$t.descr}
+                </td>
+                <td id="editCountyShortDescr_{$t.id}">
+                    {$t.short_descr}
+                </td>
+                <td>
+                    <div class="deleteCountyButton button button-secondary glm-button-small glm-right" data-countyID="{$t.id}">Delete</div>
+                </td>
+            </tr>
+    {/foreach}
+{else}
+            <tr class="alternate"><td colspan="2">(no counties listed)</td></tr>
+{/if}
+        </tbody>
+    </table>
+
+    <script type="text/javascript">
+        jQuery(document).ready(function($) {
+
+            $("#newCountyDialog").dialog({
+               autoOpen: false,
+               minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#editCountyDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $("#deleteCountyDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+
+            $('#newCountyButton').click( function() {
+                $("#newCountyDialog").dialog("open");
+            });
+            $('.editCounty').click( function() {
+                var countyID = $(this).attr('data-countyID');
+                var countyName = $(this).text();
+                var countyDescr = $('#editCountyDescr_' + countyID).html();
+                var countyShortDescr = $('#editCountyShortDescr_' + countyID).html();
+                $('#editCountyID').val(countyID);
+                $('#editCountyName').val(countyName.trim());
+                $('#editCountyDescr').val(countyDescr.trim());
+                $('#editCountyShortDescr').val(countyShortDescr.trim());
+                $("#editCountyDialog").dialog("open");
+            });
+            $('#editCountyCancel').click( function() {
+                $("#editCountyDialog").dialog("close");
+            });
+            $('#newCountyCancel').click( function() {
+                $("#newCountyDialog").dialog("close");
+            });
+
+            var id = false;
+            $('.deleteCountyButton').click( function() {
+                id = $(this).attr('data-countyID');
+                $("#deleteCountyDialog").dialog("open");
+            });
+            $('#deleteCountyConfirm').click( function() {
+                $("#deleteCountyDialog").dialog("close");
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=counties&option=delete&id=" + id;
+            });
+            $('#deleteCountyCancel').click( function() {
+                $("#deleteCountyDialog").dialog("close");
+            });
+
+        });
+    </script>
+
+{include file='admin/footer.html'}
index a0bfe90..95ccbe8 100644 (file)
@@ -11,6 +11,7 @@
         <a href="{$thisUrl}?page={$thisPage}&glm_action=cities" class="nav-tab{if $thisAction==cities} nav-tab-active{/if}">Cities</a>
         {if $enable_members}
         <a href="{$thisUrl}?page={$thisPage}&glm_action=regions" class="nav-tab{if $thisAction==regions} nav-tab-active{/if}">Regions</a>
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=counties" class="nav-tab{if $thisAction==counties} nav-tab-active{/if}">Counties</a>
         {/if}
 {foreach $addOnTabs as $a}
         <a href="{$thisUrl}?page={$thisPage}&glm_action={$a.action}" class="nav-tab{if $thisAction==$a.action} nav-tab-active{/if}">{$a.text}</a>