Updating the settings for amenities
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jun 2016 17:10:40 +0000 (13:10 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 14 Jun 2016 17:10:40 +0000 (13:10 -0400)
Updating the view file and processing for getting the amenities into
groups.
WIP: Does not bring old groups into the edit form yet.

classes/data/dataAmenities.php
classes/data/dataGroups.php [new file with mode: 0644]
models/admin/settings/amenities.php
setup/validActions.php
views/admin/settings/amenities.html

index 8c9f2bd..60ace16 100644 (file)
@@ -84,11 +84,11 @@ class GlmDataAmenities extends GlmDataAbstract
      * @return void
      * @access public
      */
-    function __construct ($wpdb, $config)
+    function __construct ( $wpdb, $config )
     {
 
         // If this class is not being extended along with existing $wpdb and $config
-        if (!$this->wpdb) {
+        if ( !$this->wpdb ) {
 
             // Save WordPress Database object
             $this->wpdb = $wpdb;
@@ -109,62 +109,97 @@ class GlmDataAmenities extends GlmDataAbstract
         $this->fields = array(
 
                 'id' => array(
-                        'field' => 'id',
-                        'type' => 'integer',
-                        'view_only' => true,
-                        'use' => 'a'
+                    'field'     => 'id',
+                    'type'      => 'integer',
+                    'view_only' => true,
+                    'use'       => 'a',
                 ),
 
                 // Facility Type
-                'ref_type' => array (
-                        'field' => 'ref_type',
-                        'type' => 'list',
-                        'list' => $this->config['ref_type'],
-                        'required' => true,
-                        'use' => 'a'
+                'ref_type'     => array (
+                    'field'    => 'ref_type',
+                    'type'     => 'list',
+                    'list'     => $this->config['ref_type'],
+                    'required' => true,
+                    'use'      => 'a',
                 ),
 
                 // Name
                 'name' => array(
-                        'field' => 'name',
-                        'type' => 'text',
-                        'required' => true,
-                        'unique' => true,
-                        'use' => 'a'
+                    'field'    => 'name',
+                    'type'     => 'text',
+                    'required' => true,
+                    'unique'   => true,
+                    'use'      => 'a',
                 ),
 
                 // Uses Value
                 'uses_value' => array(
-                        'field' => 'uses_value',
-                        'type' => 'checkbox',
-                        'use' => 'a'
+                    'field' => 'uses_value',
+                    'type'  => 'checkbox',
+                    'use'   => 'a',
                 ),
 
                 // Description
                 'descr' => array(
-                        'field' => 'descr',
-                        'type' => 'text',
-                        'use' => 'a'
+                    'field' => 'descr',
+                    'type'  => 'text',
+                    'use'   => 'a',
                 ),
 
                 // Short Description
                 'short_descr' => array(
-                        'field' => 'short_descr',
-                        'type' => 'text',
-                        'use' => 'a'
-                )
+                    '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);
+        if ( is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
+            glmMembersAdmin::addNotice( $this->fields, 'DataBlock', 'Table Fields: '.$this->table );
         }
 
     }
 
+    /**
+     * 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( $result_data, $action )
+    {
+        switch ( $action ) {
+            case 'l':
+            case 'g':
+                $sql = "
+                SELECT *
+                  FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "grouped_amenities
+                 WHERE amenity_id = " . $result_data['id'];
+                $result_data['groups']      = $this->wpdb->get_results( $sql, ARRAY_A );
+                $result_data['groups_json'] = json_encode($result_data['groups']);
+                break;
+            case 'i':
+                echo '<pre>INSERT: $result_data: ' . print_r($result_data, true) . '</pre>';
+                echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+                break;
+            case 'd':
+                break;
+        }
+        return $result_data;
+    }
 
-    /*
+    /**
      * Get the amenitities for a particular reference and destination
      *
      * @param integer $ref Reference Type (i.e. member, member_info, location, ...)
@@ -172,15 +207,18 @@ class GlmDataAmenities extends GlmDataAbstract
      *
      * @return array Array of amenities
      */
-    public function getAmenityRef($ref_type = false, $ref_dest = false) {
+    public function getAmenityRef( $ref_type = false, $ref_dest = false ) {
 
         // Check input for sanity - Refernce type first
-        if ($ref_type == false || ($ref_type-0) <= 0 || !in_array($ref_type, $this->config['ref_type_numb'])) {
+        if ( $ref_type === false
+            || ( $ref_type - 0 ) <= 0
+            || !in_array( $ref_type, $this->config['ref_type_numb'] ) 
+        ) {
             return false;
         }
 
         // Now check for positive integer for destination (record ID)
-        if ($ref_dest == false || ($ref_dest-0) <= 0) {
+        if ( $ref_dest == false || ( $ref_dest - 0 ) <= 0 ) {
             return false;
         }
 
@@ -195,13 +233,13 @@ class GlmDataAmenities extends GlmDataAbstract
           ORDER BY A.name
         ;";
 
-        $amenList = $this->wpdb->get_results($sql, ARRAY_A);
+        $amenList = $this->wpdb->get_results( $sql, ARRAY_A );
 
         return $amenList;
 
     }
 
-    /*
+    /**
      * Get the amenitities for a particular reference and destination
      *
      * @param integer $ref Reference Type (i.e. member, member_info, location, ...)
@@ -209,49 +247,49 @@ class GlmDataAmenities extends GlmDataAbstract
      *
      * @return array Array of amenities
      */
-    public function updateAmenityRef($ref_type = false, $ref_dest = false, $amenities = false) {
+    public function updateAmenityRef( $ref_type = false, $ref_dest = false, $amenities = false ) {
 
         // Check input for sanity - Refernce type first
-        if ($ref_type == false || ($ref_type-0) <= 0 || !in_array($ref_type, $this->config['ref_type_numb'])) {
+        if ( $ref_type == false 
+            || ( $ref_type - 0 ) <= 0 
+            || !in_array( $ref_type, $this->config['ref_type_numb'] ) ) {
             return false;
         }
 
         // Now check for positive integer for destination (record ID)
-        if ($ref_dest == false || ($ref_dest-0) <= 0) {
+        if ( $ref_dest == false || ( $ref_dest - 0 ) <= 0 ) {
             return false;
         }
 
         // Start by deleting all amenities for this destination
         $sql = "
-                DELETE FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref
-                        WHERE ref_type = $ref_type
-                        AND ref_dest = $ref_dest
-                        ;";
-        $this->wpdb->query($sql);
+        DELETE 
+          FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref
+         WHERE ref_type = $ref_type
+           AND ref_dest = $ref_dest";
+        $this->wpdb->query( $sql );
 
         // If no amenities supplied, return now with no list
-        if ($amenities == false) {
+        if ( $amenities == false ) {
             return false;
         }
 
         // Since we seem to have a list, add all of these
-        foreach ($amenities as $a) {
+        foreach ( $amenities as $a ) {
 
             $sql = "
-                INSERT INTO ".GLM_MEMBERS_PLUGIN_DB_PREFIX."amenity_ref
+                INSERT INTO " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "amenity_ref
                     ( amenity, ref_type, ref_dest)
                 VALUES
                     ( $a, $ref_type, $ref_dest )
             ;";
-            $this->wpdb->query($sql);
+            $this->wpdb->query( $sql );
 
         }
 
-        $amen = $this->getAmenityRef($ref_type, $ref_dest);
+        $amen = $this->getAmenityRef( $ref_type, $ref_dest );
         return $amen;
 
     }
 
 }
-
-?>
\ No newline at end of file
diff --git a/classes/data/dataGroups.php b/classes/data/dataGroups.php
new file mode 100644 (file)
index 0000000..63958bf
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+
+/**
+ * GLM Member-DB WordPress Plugin
+ * Groups 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 $
+ */
+
+/**
+ * EventManagementDataGroups 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 GlmDataGroups 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 . 'amenity_groups';
+
+        /*
+         * 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'
+                ),
+        );
+
+        if ( is_admin() && GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
+            glmMembersAdmin::addNotice( $this->fields, 'DataBlock', 'Table Fields: '.$this->table );
+        }
+    }
+}
index 9c15449..cc917dc 100644 (file)
@@ -14,7 +14,8 @@
  */
 
 // Load Amenities data abstract
-require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataAmenities.php');
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataAmenities.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataGroups.php';
 
 /*
  * This class performs the work for the default action of the "Members" menu
@@ -48,7 +49,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
      * @return object Class object
      *
      */
-    public function __construct ($wpdb, $config)
+    public function __construct ( $wpdb, $config )
     {
 
         // Save WordPress Database object
@@ -58,7 +59,7 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
         $this->config = $config;
 
         // Run constructor for members data class
-        parent::__construct(false, false);
+        parent::__construct( false, false );
 
     }
 
@@ -96,143 +97,158 @@ class GlmMembersAdmin_settings_amenities extends GlmDataAmenities
      * produce output.
      *
      */
-    public function modelAction ($actionData = false)
+    public function modelAction ( $actionData = false )
     {
 
-        $success = true;
+        $success       = true;
         $haveAmenities = false;
-        $amenities = false;
-        $error = false;
-
-
-        $newAmenity = $this->newEntry();
+        $haveGroups    = false;
+        $amenities     = false;
+        $error         = false;
+        $newAmenity    = $this->newEntry();
 
         // Check if a category ID is supplied
         $id = 0;
-        if (isset($_REQUEST['id'])) {
-            $id = $_REQUEST['id']-0;
+        if ( isset( $_REQUEST['id'] ) ) {
+            $id = $_REQUEST['id'] - 0;
         }
 
-        // If there's an action option
-        if (isset($_REQUEST['option'])) {
-
-            switch($_REQUEST['option']) {
+        $groupData = new GlmDataGroups( $this->wpdb, $this->config );
 
+        // 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);
+                    if ( $id > 0 ) {
+                        $this->updateEntry( $id );
+                    }
+                    echo '<pre>$id: ' . print_r($id, true) . '</pre>';
+                    echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
+                    // Delete the current entries for the grouped amenities
+                    $this->wpdb->delete(
+                        GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities',
+                        array( 'amenity_id' => $id ),
+                        array( '%d' )
+                    );
+                    if ( isset( $_REQUEST['grouped']['group'] ) ) {
+                        foreach ( $_REQUEST['grouped']['group'] as $group_id => $group_value ) {
+                            if ( $group_value == 1 ) {
+                                $this->wpdb->insert(
+                                    GLM_MEMBERS_PLUGIN_DB_PREFIX . 'grouped_amenities',
+                                    array(
+                                        'group_id'   => $group_id,
+                                        'amenity_id' => $id,
+                                        'searchable' => $_REQUEST['grouped']['searchable'][$group_id]
+                                    ),
+                                    array(
+                                        '%d',
+                                        '%d',
+                                        '%s'
+                                    )
+                                );
+                            }
+                        }
                     }
                     break;
 
                 case 'delete':
-                    if ($id > 0) {
-                        $this->deleteEntry($id, true);
+                    if ( $id > 0 ) {
+                        $this->deleteEntry( $id, true );
                     }
                     break;
 
-            }
-
-        }
-
-
-/*
-        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
-            glmMembersAdmin::addNotice($newAmenity, 'DataBlock', 'New Amenity Data');
-        }
-
-        if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'addNew') {
-
-            $amenities = $this->insertEntry();
-
-            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                glmMembersAdmin::addNotice('&nbsp;&nbsp;New Entry Added ', 'Process');
-            }
-        }
-
-        if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'delete' && isset($_REQUEST['amenityID'])) {
+                case 'addNewGroup':
+                    $groupData->insertEntry();
+                    break;
 
-            $id = $_REQUEST['amenityID']-0;
-            if ($id > 0) {
-                $this->deleteEntry($id, true);
-            }
+                case 'updateGroup':
+                    if ( $id > 0 ) {
+                        $groupData->updateEntry( $id );
+                    } 
+                    break;
 
-            if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
-                glmMembersAdmin::addNotice('&nbsp;&nbsp;Entry Deleted: id = '.$id, 'Process');
+                case 'deleteGroup':
+                    if ( $id > 0 ) {
+                        $groupData->deleteEntry( $id );
+                    } 
+                    break;
             }
-
-        }
-
-        // Check if a amenity ID is supplied
-        if (isset($_REQUEST['amenity_id'])) {
-            // Make sure it's a number
-            $amenityID = $_REQUEST['amenity_id']-0;
-        }
-
-        // Check for action option
-        $option = false;
-        if (isset($_REQUEST['option']) && trim($_REQUEST['option']) != '') {
-            $option = $_REQUEST['option'];
         }
-*/
 
         // Get a current list of amenities
         $amenities = $this->getList();
+        echo '<pre>$amenities: ' . print_r($amenities, true) . '</pre>';
 
-        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
-            glmMembersAdmin::addNotice($amenities, 'DataBlock', 'Amenities Data');
+        if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
+            glmMembersAdmin::addNotice( $amenities, 'DataBlock', 'Amenities Data' );
         }
 
         // If we have list entries - even if it's an empty list
         $success = true;
         $haveAmenities = false;
-        if ($amenities !== false) {
+        if ( $amenities !== false ) {
 
             $success = true;
 
             // If we have any entries
-            if (count($amenities) > 0) {
+            if ( count( $amenities ) > 0 ) {
                 $haveAmenities = true;
             }
         }
 
+        $groups = $groupData->getList();
+
+        if ( GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE ) {
+            glmMembersAdmin::addNotice( $groups, 'DataBlock', 'Amenity Groups Data' );
+        }
+
+        if ( $groups !== false ) {
+            $success = true;
+
+            // If we have any entries.
+            if ( count( $groups ) > 0 ) {
+                $haveGroups = 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
+                'status'           => $success,
+                'menuItemRedirect' => 'error',
+                'modelRedirect'    => 'index',
+                'view'             => 'admin/error/index.html',
+                'data'             => false,
             );
         }
 
         if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
-            glmMembersAdmin::addNotice($amenities, 'DataBlock', 'Amenities Data');
+            glmMembersAdmin::addNotice( $amenities, 'DataBlock', 'Amenities Data' );
         }
 
         // Compile template data
         $templateData = array(
             'haveAmenities' => $haveAmenities,
-            'amenities' => $amenities,
-            'newAmenity' => $newAmenity
+            'haveGroups'    => $haveGroups,
+            'amenities'     => $amenities,
+            'groups'        => $groups,
+            'newAmenity'    => $newAmenity,
         );
 
         // Return status, suggested view, and data to controller
         return array(
-            'status' => $success,
+            'status'           => $success,
             'menuItemRedirect' => false,
-            'modelRedirect' => false,
-            'view' => 'admin/settings/amenities.html',
-            'data' => $templateData
+            'modelRedirect'    => false,
+            'view'             => 'admin/settings/amenities.html',
+            'data'             => $templateData,
         );
 
     }
 
 
 }
-
-?>
\ No newline at end of file
index 651e954..8e4dee8 100644 (file)
 $glmMembersValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-                'imageUpload' => 'glm-member-db'
+            'imageUpload' => 'glm-member-db',
         ),
         'dashboardWidget' => array(
-                'index' => 'glm-member-db'
+            'index' => 'glm-member-db',
         ),
         'members' => array(
-                'index' => 'glm-member-db',            // member list
-                'list' => 'glm-member-db',
-                'reports' => 'glm-member-db',
-                'other' => 'glm-member-db'
+            'index'   => 'glm-member-db',            // member list
+            'list'    => 'glm-member-db',
+            'reports' => 'glm-member-db',
+            'other'   => 'glm-member-db',
         ),
         'member' => array(
-                'index' => 'glm-member-db',            // Member Dashboard
-                'memberInfo' => 'glm-member-db',
-                'memberEdit' => 'glm-member-db',
-                'locations' => 'glm-member-db'
+            'index'      => 'glm-member-db',            // Member Dashboard
+            'memberInfo' => 'glm-member-db',
+            'memberEdit' => 'glm-member-db',
+            'locations'  => 'glm-member-db',
         )
         ,
         'settings' => array(
-                'index' => 'glm-member-db',            // Member Types
-                'categories' => 'glm-member-db',
-                'cities' => 'glm-member-db',
-                'regions' => 'glm-member-db',
-                'amenities' => 'glm-member-db'
+            'index'      => 'glm-member-db',            // Member Types
+            'categories' => 'glm-member-db',
+            'cities'     => 'glm-member-db',
+            'regions'    => 'glm-member-db',
+            'amenities'  => 'glm-member-db',
         ),
         'management' => array(
-                'index' => 'glm-member-db',            // General Options
-                'terms' => 'glm-member-db',
-                'development' => 'glm-member-db',
-                'theme' => 'glm-member-db',
-                'import' => 'glm-member-db',
-                'addons' => 'glm-member-db',
-                'hooks' => 'glm-member-db'
+            'index'       => 'glm-member-db',            // General Options
+            'terms'       => 'glm-member-db',
+            'development' => 'glm-member-db',
+            'theme'       => 'glm-member-db',
+            'import'      => 'glm-member-db',
+            'addons'      => 'glm-member-db',
+            'hooks'       => 'glm-member-db',
         ),
         'shortcodes' => array(
-                'index' => 'glm-member-db'
+            'index' => 'glm-member-db'
         ),
         'error' => array(
-                'index' => 'glm-member-db',
-                'badAction' => 'glm-member-db'
+            'index'     => 'glm-member-db',
+            'badAction' => 'glm-member-db',
         )
     ),
     'frontActions' => array(
         'members' => array(
-            'list' => 'glm-member-db',
-            'detail' => 'glm-member-db'
+            'list'   => 'glm-member-db',
+            'detail' => 'glm-member-db',
         ),
         'error' => array(
-            'index' => 'glm-member-db',
-            'badAction' => 'glm-member-db'
+            'index'     => 'glm-member-db',
+            'badAction' => 'glm-member-db',
         )
     )
 );
 
-?>
\ No newline at end of file
+?>
index 8ba15e7..008dc86 100644 (file)
 {include file='admin/settings/header.html'}
 
-    <!-- Add Amenities Button and Dialog Box -->
-    <div id="newAmenityButton" class="button button-primary glm-right">Add an Amenity</div>
-    <div id="newAmenityDialog" class="glm-dialog-box" title="Enter a New Amenity">
-        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-            <input type="hidden" name="glm_action" value="amenities">
-            <input type="hidden" name="option" value="addNew">
+<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+    <a id="glm-amenities-list" data-show-table="glm-table-amenities" class="glm-settings-tab nav-tab nav-tab-active">Amenities List</a>
+    <a id="glm-groups-list" data-show-table="glm-table-groups" class="glm-settings-tab nav-tab">Groups</a>
+</h2>
 
-<!-- This is only temporary until we reinstate the "Used With" selection below -->
-<input type="hidden" name="ref_type" value="20">
+<table id="glm-table-amenities" class="glm-admin-table glm-settings-table{if $option=''} glm-hidden{/if}">
+    <tr><td colspan="2">
+        <!-- Add Amenities Button and Dialog Box -->
+        <div id="newAmenityButton" class="button button-primary glm-right">Add an Amenity</div>
+        <div id="newAmenityDialog" class="glm-dialog-box" title="Enter a New Amenity">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="amenities">
+                <input type="hidden" name="option" value="addNew">
 
-            <table class="glm-admin-table">
-                <tr>
-                    <th class="glm-required">Amenity Name:</th>
-                    <td>
-                        <input type="text" name="name" class="glm-form-text-input">
-                    </td>
-                </tr>
-<!--                 
-                <tr>
-                    <th class="glm-required">Used With:</th>
-                    <td>
-                        <select name="ref_type">
-                            <option value=""></option>
-    {foreach from=$newAmenity.fieldData.ref_type.list item=v}
-                            <option value="{$v.value}">{$v.name}</option>
-    {/foreach}
-                        </select>
-                    </td>
-                </tr>
--->                
-<!--
-                <tr>
-                    <th>Uses a value:</th>
-                    <td><input type="checkbox" name="uses_value"></td>
-                </tr>
- -->                
-                <tr>
-                    <th>Description:</th>
-                    <td>
-                        <textarea name="descr" class="glm-form-textarea"></textarea>
-                    </td>
-                </tr>
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <input type="hidden" name="ref_type" value="20">
+
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Amenity 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>
+                    <tr>
+                        <td colspan="2">
+                            <table style="width: 100%;">
+                                {foreach $groups as $group}
+                                    <tr>
+                                        <td>
+                                            <label>
+                                                <input type="hidden" name="grouped[group][{$group.id}]" value="0">
+                                                <input type="checkbox" name="grouped[group][{$group.id}]" value="1">
+                                            {$group.name}
+                                            </label>
+                                        </td>
+                                        <td>
+                                            <label>
+                                                <input type="hidden" name="grouped[searchable][{$group.id}]" value="0">
+                                                <input type="checkbox" name="grouped[searchable][{$group.id}]" value="1">
+                                            Searchable
+                                            </label>
+                                        </td>
+                                    </tr>
+                                {/foreach}
+                            </table>
+                        </td>
+                    </tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="newAmenityCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Add new Amenity" class="button button-primary">
+                
+            </form>
+        </div>
+
+        <!-- Delete Amenities Button -->
+        <div id="deleteAmenityDialog" class="glm-dialog-box" title="Delete Amenity">
+            <center>
+                <p>Are you sure you want to delete this amenity?</p>
+                <p><div id="deleteAmenityConfirm" class="button button-primary">Yes, delete this amenity</div></p>
+                <p><div id="deleteAmenityCancel" class="button button-primary">Cancel</div></p>
+            </center>
+        </div>
+
+        <!-- Edit Amenities Dialog Box -->
+        <div id="editAmenityDialog" class="glm-dialog-box" title="Edit this Amenity">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="amenities">
+                <input type="hidden" name="option" value="update">
+                <input id="editAmenityID" type="hidden" name="id" value="">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <input type="hidden" name="ref_type" value="20">
+
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Amenity Name:</th>
+                        <td>
+                            <input id="editAmenityName" type="text" name="name" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                    <tr>
+                        <th>Description:</th>
+                        <td>
+                            <textarea id="editAmenityDescr" name="descr" class="glm-form-textarea"></textarea>
+                        </td>
+                    </tr>
+                    <tr>
+                        <th>Short Description:</th>
+                        <td>
+                            <input id="editAmenityShortDescr" type="text" name="short_descr" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                    <tr>
+                        <td colspan="2">
+                            <table style="width: 100%;">
+                                {foreach $groups as $group}
+                                    <tr>
+                                        <td>
+                                            <label>
+                                                <input type="hidden" name="grouped[group][{$group.id}]" value="0">
+                                                <input type="checkbox" name="grouped[group][{$group.id}]" value="1">
+                                            {$group.name}
+                                            </label>
+                                        </td>
+                                        <td>
+                                            <label>
+                                                <input type="hidden" name="grouped[searchable][{$group.id}]" value="0">
+                                                <input type="checkbox" name="grouped[searchable][{$group.id}]" value="1">
+                                            Searchable
+                                            </label>
+                                        </td>
+                                    </tr>
+                                {/foreach}
+                            </table>
+                        </td>
+                    </tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="editAmenityCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Update this Amenity">
+                
+            </form>
+        </div>
+                    
+    
+        <h2>Amenities</h2>
+
+        <table class="wp-list-table widefat fixed posts glm-admin-table">
+            <thead>
                 <tr>
-                    <th>Short Description:</th>
-                    <td>
-                        <input type="text" name="short_descr" class="glm-form-text-input">
-                    </td>
+                    <th>Amenity</th>
+                    <th>Used With</th>
+                    <th>Description</th>
+                    <th>Short Description</th>
+                    <th>Uses Value</th>
+                    <th>&nbsp;</th>
                 </tr>
-            </table>
-            <p><span class="glm-required">*</span> Required</p>
-            <a id="newAmenityCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Add new Amenity" class="button button-primary">
+            </thead>
+            <tbody>
+            {if $haveAmenities}
+                {assign var="i" value="0"}
+                {foreach $amenities as $t}
+                    {if $i++ is odd by 1}
+                        <tr>
+                    {else}
+                        <tr class="alternate">
+                    {/if}
+                            <td>
+                                <a class="editAmenity" data-amenityID="{$t.id}" data-refTypeID="{$t.ref_type.value}" data-amenityUsesValue="{$t.uses_value.value}">{$t.name}</a>
+                            </td>
+                            <td id="editAmenityRefType_{$t.id}">
+                                {$t.ref_type.name}
+                            </td>
+                            <td id="editAmenityDescr_{$t.id}">
+                                {$t.descr}
+                            </td>
+                            <td id="editAmenityShortDescr_{$t.id}">
+                                {$t.short_descr}
+                            </td>
+                            <td id="editAmenityGroups_{$t.id}" data-groupjson='{$t.groups_json}'>
+                                {foreach $t.groups as $group}
+                                    
+                                {/foreach}
+                            </td>
+                            <td>
+                                <div class="deleteAmenityButton button button-secondary glm-button-small glm-right" data-amenityID="{$t.id}">Delete</div>
+                            </td>
+                        </tr>
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="2">(no amenities listed)</td></tr>
+            {/if}
+            </tbody>
+        </table>
+    </tr>
+</table>
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+        
+        $("#newAmenityDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#editAmenityDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#deleteAmenityDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+
+        $('#newAmenityButton').click( function() {
+            $("#newAmenityDialog").dialog("open");
+        });
+        $('.editAmenity').click( function() {
+            var amenityID = $(this).attr('data-amenityID');
+            var amenityName = $(this).text();
+            var amenityRefTypeID = $(this).attr('data-refTypeID');
+            var amenityUsesValue = parseInt($(this).attr('data-amenityUsesValue'));
+            var amenityDescr = $('#editAmenityDescr_' + amenityID).html();
+            var amenityShortDescr = $('#editAmenityShortDescr_' + amenityID).html();
+            $('#editAmenityID').val(amenityID);
+            $('#editAmenityName').val(amenityName.trim());
+            $('#editAmenityRef').val(amenityRefTypeID);
+            $('#editAmenityUsesValue').prop('checked', amenityUsesValue);
+            $('#editAmenityDescr').val(amenityDescr.trim());
+            $('#editAmenityShortDescr').val(amenityShortDescr.trim());
+            $("#editAmenityDialog").dialog("open");
+        });
+        $('#editAmenityCancel').click( function() {
+            $("#editAmenityDialog").dialog("close");
+        });
+        $('#newAmenityCancel').click( function() {
+            $("#newAmenityDialog").dialog("close");
+        });
+
+        var id = false;
+        $('.deleteAmenityButton').click( function() {
+            id = $(this).attr('data-amenityID');
+            $("#deleteAmenityDialog").dialog("open");
+        });
+        $('#deleteAmenityConfirm').click( function() {
+            $("#deleteAmenityDialog").dialog("close");
+            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=amenities&option=delete&id=" + id;
+        });
+        $('#deleteAmenityCancel').click( function() {
+            $("#deleteAmenityDialog").dialog("close");
+        });
+
+        /*
+         * Edit area tabs
+         */
+        $('.glm-settings-tab').click( function() {
+
+            // Clear tabl highlights and hide all tables
+            $('.glm-settings-tab').removeClass('nav-tab-active');
+            $('.glm-settings-table').addClass('glm-hidden');
             
-        </form>
-    </div>
-
-    <!-- Delete Amenities Button -->
-    <div id="deleteAmenityDialog" class="glm-dialog-box" title="Delete Amenity">
-        <center>
-            <p>Are you sure you want to delete this amenity?</p>
-            <p><div id="deleteAmenityConfirm" class="button button-primary">Yes, delete this amenity</div></p>
-            <p><div id="deleteAmenityCancel" class="button button-primary">Cancel</div></p>
-        </center>
-    </div>
-
-    <!-- Edit Amenities Dialog Box -->
-    <div id="editAmenityDialog" class="glm-dialog-box" title="Edit this Amenity">
-        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-            <input type="hidden" name="glm_action" value="amenities">
-            <input type="hidden" name="option" value="update">
-            <input id="editAmenityID" type="hidden" name="id" value="">
-
-<!-- This is only temporary until we reinstate the "Used With" selection below -->
-<input type="hidden" name="ref_type" value="20">
-
-            <table class="glm-admin-table">
-                <tr>
-                    <th class="glm-required">Amenity Name:</th>
-                    <td>
-                        <input id="editAmenityName" type="text" name="name" class="glm-form-text-input">
-                    </td>
-                </tr>
-<!--                 
-                <tr>
-                    <th class="glm-required">Used With:</th>
-                    <td>
-                        <select id="editAmenityRef" name="ref_type">
-                            <option value=""></option>
-    {foreach from=$newAmenity.fieldData.ref_type.list item=v}
-                            <option value="{$v.value}">{$v.name}</option>
-    {/foreach}
-                        </select>
-                    </td>
-                </tr>
--->                
-<!-- 
-                <tr>
-                    <th>Uses a value:</th>
-                    <td><input id="editAmenityUsesValue" type="checkbox" name="uses_value"></td>
-                </tr>
--->
-                <tr>
-                    <th>Description:</th>
-                    <td>
-                        <textarea id="editAmenityDescr" name="descr" class="glm-form-textarea"></textarea>
-                    </td>
-                </tr>
+            // Highlight selected tab
+            $(this).addClass('nav-tab-active');
+            
+            // Show selected table
+            var table = $(this).attr('data-show-table');
+            $('#' + table).removeClass('glm-hidden');
+            
+            if (table == 'glm-table-address') {
+                initMap();
+            }
+            
+        });
+
+    });
+</script>
+<table id="glm-table-groups" class="glm-admin-table glm-settings-table{if $option!='groups'} glm-hidden{/if}">
+    <tr>
+        <td colspan="2">
+        <!-- Add Group Button and Dialog Box -->
+        <div id="newGroupButton" class="button button-primary glm-right">Add a Group</div>
+        <div id="newGroupDialog" class="glm-dialog-box" title="Enter a New Group">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="amenities">
+                <input type="hidden" name="option" value="addNewGroup">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <input type="hidden" name="ref_type" value="20">
+
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Group Name:</th>
+                        <td>
+                            <input type="text" name="name" class="glm-form-text-input">
+                        </td>
+                    </tr>
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="newGroupCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Add new Group" class="button button-primary">
+                
+            </form>
+        </div>
+
+        <!-- Delete Group Button -->
+        <div id="deleteGroupDialog" class="glm-dialog-box" title="Delete Group">
+            <center>
+                <p>Are you sure you want to delete this group?</p>
+                <p><div id="deleteGroupConfirm" class="button button-primary">Yes, delete this group</div></p>
+                <p><div id="deleteGroupCancel" class="button button-primary">Cancel</div></p>
+            </center>
+        </div>
+
+        <!-- Edit Amenities Dialog Box -->
+        <div id="editGroupDialog" class="glm-dialog-box" title="Edit this Group">
+            <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+                <input type="hidden" name="glm_action" value="amenities">
+                <input type="hidden" name="option" value="updateGroup">
+                <input id="editGroupID" type="hidden" name="id" value="">
+
+                <!-- This is only temporary until we reinstate the "Used With" selection below -->
+                <input type="hidden" name="ref_type" value="20">
+                <table class="glm-admin-table">
+                    <tr>
+                        <th class="glm-required">Group Name:</th>
+                        <td>
+                            <input id="editGroupName" type="text" name="name" class="glm-form-text-input">
+                        </td>
+                    </tr>
+
+                </table>
+                <p><span class="glm-required">*</span> Required</p>
+                <a id="editGroupCancel" class="button button-primary glm-right">Cancel</a>
+                <input type="submit" value="Update this Group">
+                
+            </form>
+        </div>
+
+        <h2>Groups</h2>
+        <table class="wp-list-table widefat fixed posts glm-admin-table">
+            <thead>
                 <tr>
-                    <th>Short Description:</th>
-                    <td>
-                        <input id="editAmenityShortDescr" type="text" name="short_descr" class="glm-form-text-input">
-                    </td>
+                    <th>Group</th>
+                    <th>&nbsp;</th>
                 </tr>
-            </table>
-            <p><span class="glm-required">*</span> Required</p>
-            <a id="editAmenityCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Update this Amenity">
-            
-        </form>
-    </div>
-                    
+            </thead>
+            <tbody>
+            {if $haveGroups}
+                {assign var="i" value="0"}
+                {foreach $groups as $t}
+                    {if $i++ is odd by 1} 
+                        <tr>
+                    {else}
+                        <tr class="alternate">
+                    {/if}
+                            <td>
+                                <a class="editGroup" data-groupID="{$t.id}" data-refTypeID="{$t.ref_type.value}">{$t.name}</a>
+                            </td>
+                            <td>
+                                <div class="deleteGroupButton button button-secondary glm-button-small glm-right" data-groupID="{$t.id}">Delete</div>
+                            </td>
+                        </tr>
+                {/foreach}
+            {else}
+                <tr class="alternate"><td colspan="2">(no groups listed)</td></tr>
+            {/if}
+            </tbody>
+        </table>
+
+    </tr>
+</table>
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+        
+        $("#newGroupDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#editGroupDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+        $("#deleteGroupDialog").dialog({
+            autoOpen: false,
+            minWidth: 400,
+            dialogClass: "glm-dialog-no-close"
+        });
+
+        $('#newGroupButton').click( function() {
+            $("#newGroupDialog").dialog("open");
+        });
+        $('.editGroup').click( function() {
+            var groupID = $(this).attr('data-groupID');
+            var groupName = $(this).text();
+            $('#editGroupID').val(groupID);
+            $('#editGroupName').val(groupName.trim());
+            $("#editGroupDialog").dialog("open");
+        });
+        $('#editGroupCancel').click( function() {
+            $("#editGroupDialog").dialog("close");
+        });
+        $('#newGroupCancel').click( function() {
+            $("#newGroupDialog").dialog("close");
+        });
+
+        var id = false;
+        $('.deleteGroupButton').click( function() {
+            id = $(this).attr('data-groupID');
+            $("#deleteGroupDialog").dialog("open");
+        });
+        $('#deleteGroupConfirm').click( function() {
+            $("#deleteGroupDialog").dialog("close");
+            window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=amenities&option=deleteGroup&id=" + id + "&option=groups";
+        });
+        $('#deleteGroupCancel').click( function() {
+            $("#deleteGroupDialog").dialog("close");
+        });
+
+    });
+</script>
     
-    <h2>Amenities</h2>
-
-    <table class="wp-list-table widefat fixed posts glm-admin-table"">
-        <thead>
-            <tr>
-                <th>Amenity</th>
-                <th>Used With</th>
-                <th>Uses Value</th>
-                <th>Description</th>
-                <th>Short Description</th>
-                <th>&nbsp;</th>
-            </tr>
-        </thead>
-        <tbody>
-{if $haveAmenities}
-    {assign var="i" value="0"}
-    {foreach $amenities as $t}
-        {if $i++ is odd by 1} 
-            <tr>
-        {else}
-            <tr class="alternate">
-        {/if}
-                <td>
-                    <a class="editAmenity" data-amenityID="{$t.id}" data-refTypeID="{$t.ref_type.value}" data-amenityUsesValue="{$t.uses_value.value}">{$t.name}</a>
-                </td>
-                <td id="editAmenityRefType_{$t.id}">
-                    {$t.ref_type.name}
-                </td>
-                <td id="editAmenityUsesValue_{$t.id}" >
-                    {$t.uses_value.name}
-                </td>
-                <td id="editAmenityDescr_{$t.id}">
-                    {$t.descr}
-                </td>
-                <td id="editAmenityShortDescr_{$t.id}">
-                    {$t.short_descr}
-                </td>
-                <td>
-                    <div class="deleteAmenityButton button button-secondary glm-button-small glm-right" data-amenityID="{$t.id}">Delete</div>
-                </td>
-            </tr>
-    {/foreach}
-{else}
-            <tr class="alternate"><td colspan="2">(no amenities listed)</td></tr>
-{/if}
-        </tbody>
-    </table>
-
-    <script type="text/javascript">
-        jQuery(document).ready(function($) {
-               
-            $("#newAmenityDialog").dialog({
-               autoOpen: false,
-               minWidth: 400,
-                dialogClass: "glm-dialog-no-close"
-            });
-            $("#editAmenityDialog").dialog({
-                autoOpen: false,
-                minWidth: 400,
-                dialogClass: "glm-dialog-no-close"
-            });
-            $("#deleteAmenityDialog").dialog({
-                autoOpen: false,
-                minWidth: 400,
-                dialogClass: "glm-dialog-no-close"
-            });
-
-            $('#newAmenityButton').click( function() {
-                $("#newAmenityDialog").dialog("open");
-            });
-            $('.editAmenity').click( function() {
-                var amenityID = $(this).attr('data-amenityID');
-                var amenityName = $(this).text();
-                var amenityRefTypeID = $(this).attr('data-refTypeID');
-                var amenityUsesValue = parseInt($(this).attr('data-amenityUsesValue'));
-                var amenityDescr = $('#editAmenityDescr_' + amenityID).html();
-                var amenityShortDescr = $('#editAmenityShortDescr_' + amenityID).html();                
-                $('#editAmenityID').val(amenityID);
-                $('#editAmenityName').val(amenityName.trim());
-                $('#editAmenityRef').val(amenityRefTypeID);
-                $('#editAmenityUsesValue').prop('checked', amenityUsesValue);
-                $('#editAmenityDescr').val(amenityDescr.trim());
-                $('#editAmenityShortDescr').val(amenityShortDescr.trim());
-                $("#editAmenityDialog").dialog("open");
-            });
-            $('#editAmenityCancel').click( function() {
-                $("#editAmenityDialog").dialog("close");
-            });
-            $('#newAmenityCancel').click( function() {
-                $("#newAmenityDialog").dialog("close");
-            });
-
-            var id = false;
-            $('.deleteAmenityButton').click( function() {
-                id = $(this).attr('data-amenityID');
-                $("#deleteAmenityDialog").dialog("open");
-            });
-            $('#deleteAmenityConfirm').click( function() {
-                $("#deleteAmenityDialog").dialog("close");
-                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=amenities&option=delete&id=" + id;
-            });
-            $('#deleteAmenityCancel').click( function() {
-                $("#deleteAmenityDialog").dialog("close");
-            });
-
-        });
-    </script>
             
 {include file='admin/footer.html'}