Update custom fields for saving custom field data
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Mar 2017 17:53:43 +0000 (13:53 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Mar 2017 17:53:43 +0000 (13:53 -0400)
Custom field plugin now will create custom fields with three types:
text, textarea, and checkbox.
All field data stores into text fields.

13 files changed:
classes/customFieldPluginSupport.php [new file with mode: 0644]
classes/data/dataCustomFields.php [new file with mode: 0644]
config/plugin.ini
index.php
models/admin/management/fields.php [new file with mode: 0644]
models/admin/memberinfo/fields.php [new file with mode: 0644]
setup/adminHooks.php
setup/adminTabs.php
setup/databaseScripts/create_database_V0.0.1.sql
setup/databaseScripts/dbVersions.php [new file with mode: 0644]
setup/validActions.php
views/admin/management/fields.html [new file with mode: 0644]
views/admin/memberinfo/fields.html [new file with mode: 0644]

diff --git a/classes/customFieldPluginSupport.php b/classes/customFieldPluginSupport.php
new file mode 100644 (file)
index 0000000..590deab
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Plugin Support Functions for the Custom Fields plugin
+ *
+ */
+/**
+ * customFieldsSaveMemberInfoFields
+ *
+ * Save the data for the Member Info custom fields.
+ * Uses the $_REQUEST variable glm_custom_field.
+ *
+ * @param mixed $memberId Id for the member info record
+ *
+ * @access public
+ * @return void
+ */
+function customFieldsSaveMemberInfoFields( $memberId )
+{
+    global $wpdb;
+    // If no data for custom field then return
+    if ( !isset( $_REQUEST['glm_custom_field'] ) ) {
+        return false;
+    }
+    // See if this memberInfo has current field data
+    $currentCustomFields = customFieldsGetMemberInfoFields( $memberId );
+    // Insert the custom field record
+    $fieldDataFormat = array(
+        '%d',
+        '%d',
+        '%s'
+    );
+    // Loop through the glm_custom_field array
+    foreach ( $_REQUEST['glm_custom_field'] as $fieldId => $fieldValue ) {
+        $fieldData =array(
+            'ref_dest'   => $memberId,
+            'field_id'   => $fieldId,
+            'field_data' => $fieldValue
+        );
+        if ( !isset($currentCustomFields[$fieldId]) ) {
+            // Insert Entries
+            $wpdb->insert(
+                GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
+                $fieldData,
+                $fieldDataFormat
+            );
+        } else {
+            // Update Entries
+            $wpdb->update(
+                GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data",
+                $fieldData,
+                array(
+                    'ref_dest' => $memberId,
+                    'field_id' => $fieldId
+                ),
+                $fieldDataFormat,
+                '%d'
+            );
+        }
+    }
+}
+
+/**
+ * customFieldsGetMemberInfoFields
+ *
+ * Pull the member info custom field data.
+ * This will be used more for admin side.
+ *
+ * @param mixed $memberId Id for the member info record
+ *
+ * @access public
+ * @return void
+ */
+function customFieldsGetMemberInfoFields( $memberId )
+{
+    global $wpdb;
+    $data = array();
+    $sql = "
+    SELECT *
+      FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data
+     WHERE ref_dest = %d";
+    $fieldData = $wpdb->get_results( $wpdb->prepare( $sql, $memberId ), ARRAY_A );
+    if ( $fieldData ) {
+        foreach ( $fieldData as $key => $val ) {
+            $data[$val['field_id']] = $val['field_data'];
+        }
+        return $data;
+    } else {
+        return false;
+    }
+}
diff --git a/classes/data/dataCustomFields.php b/classes/data/dataCustomFields.php
new file mode 100644 (file)
index 0000000..c2746ea
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+/**
+ * GLM Member-DB WordPress Add-On Plugin
+ * Data Class Fields
+ *
+ * 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: dataFields.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 GlmDataFieldsCustomFields 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_FIELDS_PLUGIN_DB_PREFIX . 'custom_fields';
+
+        /*
+         * Table Data Fields
+         */
+
+        $this->fields = array (
+
+            'id' => array (
+                'field'     => 'id',
+                'type'      => 'integer',
+                'view_only' => true,
+                'use'       => 'a'
+            ),
+
+            // Event ID
+            'field_name' => array(
+                'field'    => 'field_name',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+
+            // Category ID
+            'field_type' => array(
+                'field'    => 'field_type',
+                'type'     => 'list',
+                'list'     => $this->config['custom_field_types'],
+                'required' => true,
+                '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;
+    }
+
+}
index 9222f7e..e6f76cb 100644 (file)
@@ -2,7 +2,10 @@
 ; Main Configuration File
 ; {descrName}
 ;
-; Place any static configuration parameters here.  
+; Place any static configuration parameters here.
 ;
 
-[common]
+[custom_field_types]
+text = 'text'
+textarea = 'textarea'
+checkbox = 'checkbox'
index 8fe3212..da5b91b 100644 (file)
--- a/index.php
+++ b/index.php
@@ -31,7 +31,7 @@
  *  Updates to checkDatabase() in glmPluginSupport.php must be
  *  made together with the DB_VERSION below. ONLY bump the DB
  *  version when there's a change in the database!! Use the
- *  version nunmber of that release for the DB version.
+ *  version number of that release for the DB version.
  *
  *  We check the plugin version stored in the WordPress option below
  *  so that we're sure the other add-ons see an up to date
@@ -147,7 +147,6 @@ if (is_file(GLM_MEMBERS_FIELDS_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) {
 $glmMembersFieldsManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A );
 unset($glmMembersFieldsManagementSettings['id']);
 */
-
 function glmMembersFieldsRegisterAddOn($addOns) {
 
     // Add this add-on to the add-ons array
@@ -157,8 +156,7 @@ function glmMembersFieldsRegisterAddOn($addOns) {
         'short_name' => GLM_MEMBERS_FIELDS_PLUGIN_SHORT_NAME,
         'slug' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
         'actions' => $GLOBALS['glmMembersFieldsAddOnValidActions'],
-        'config' => array(
-        ),
+        'config' => parse_ini_file(GLM_MEMBERS_FIELDS_PLUGIN_PATH.'/config/plugin.ini', true),
         'shortcodes' => $GLOBALS['glmMembersFieldsShortcodes'],
         'shortcodesDescription' => $GLOBALS['glmMembersFieldsShortcodesDescription']
     );
diff --git a/models/admin/management/fields.php b/models/admin/management/fields.php
new file mode 100644 (file)
index 0000000..4dce64c
--- /dev/null
@@ -0,0 +1,204 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author     Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ *            Exp $
+ */
+class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * dbh Postgres database connection
+     *
+     * @var mixed
+     * @access public
+     */
+    public $dbh;
+    /**
+     * settings used for the schema and tablenames
+     *
+     * @var mixed
+     * @access public
+     */
+    public $settings = array();
+    /**
+     * categories
+     *
+     * @var bool
+     * @access public
+     */
+    public $categories = array();
+    public $oldCatMap = array();
+    /**
+     * fields
+     *
+     * @var bool
+     * @access public
+     */
+    public $fields = array();
+    public $image_owner;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct(false, false);
+
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+
+        $option                = false;
+        $settings_updated      = false;
+        $settings_update_error = false;
+        $custom_fields         = false;
+        $haveCustomFields      = false;
+
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Check if a field ID is supplied
+        $id = 0;
+        if (isset($_REQUEST['id'])) {
+            $id = $_REQUEST['id']-0;
+        }
+
+        switch ($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;
+
+            default:
+                // Make sure option is set if default
+                $option = 'list';
+
+                // Determine if current user can edit configurations
+                if (!current_user_can('glm_members_management')) {
+                    return array(
+                        'status'           => false,
+                        'menuItemRedirect' => 'error',
+                        'modelRedirect'    => 'index',
+                        'view'             => 'admin/error/index.html',
+                        'data'             => array(
+                            'reason' => 'User does not have rights to make configuration changes.'
+                        )
+                    );
+                }
+
+                break;
+
+        }
+
+        // Get list of Custom Fields
+        $custom_fields = $this->getList();
+        if ( isset($custom_fields) && $custom_fields && count( $custom_fields ) > 0 ) {
+            $haveCustomFields = true;
+        }
+
+        // Compile template data
+        $template_data = array(
+            'option'              => $option,
+            'settingsUpdated'     => $settings_updated,
+            'settingsUpdateError' => $settings_update_error,
+            'custom_fields'       => $custom_fields,
+            'field_types'         => $this->config['custom_field_types'],
+            'haveCustomFields'    => $haveCustomFields,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/management/fields.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+}
diff --git a/models/admin/memberinfo/fields.php b/models/admin/memberinfo/fields.php
new file mode 100644 (file)
index 0000000..0b72856
--- /dev/null
@@ -0,0 +1,192 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Fields Add-on - Management Fields Tab
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author     Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  fields.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Management Fields data abstract
+require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH.'/data/dataCustomFields.php';
+
+/**
+ * GlmMembersAdmin_management_fields
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author    Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ *            @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott
+ *            Exp $
+ */
+class GlmMembersAdmin_memberinfo_fields extends GlmDataFieldsCustomFields
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * dbh Postgres database connection
+     *
+     * @var mixed
+     * @access public
+     */
+    public $dbh;
+    /**
+     * settings used for the schema and tablenames
+     *
+     * @var mixed
+     * @access public
+     */
+    public $settings = array();
+    /**
+     * categories
+     *
+     * @var bool
+     * @access public
+     */
+    public $categories = array();
+    public $oldCatMap = array();
+    /**
+     * fields
+     *
+     * @var bool
+     * @access public
+     */
+    public $fields = array();
+    public $image_owner;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct(false, false);
+
+    }
+
+    /**
+     * modelAction
+     *
+     * @param bool $actionData
+     * @access public
+     * @return void
+     */
+    public function modelAction($actionData = false)
+    {
+        $option           = false;
+        $customFields     = false;
+        $haveCustomFields = false;
+        $customFieldData  = false;
+
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Check if a field ID is supplied
+        $id = 0;
+        if (isset($_REQUEST['id'])) {
+            $id = $_REQUEST['id']-0;
+        }
+        $memberId = 0;
+        if (isset($actionData)) {
+            $memberId = $actionData-0;
+        }
+
+        switch ($option) {
+
+            default:
+                // Make sure option is set if default
+                $option = 'list';
+
+                // Determine if current user can edit configurations
+                if (!current_user_can('glm_members_management')) {
+                    return array(
+                        'status'           => false,
+                        'menuItemRedirect' => 'error',
+                        'modelRedirect'    => 'index',
+                        'view'             => 'admin/error/index.html',
+                        'data'             => array(
+                            'reason' => 'User does not have rights to make configuration changes.'
+                        )
+                    );
+                }
+
+                break;
+
+        }
+
+        // Get list of Custom Fields
+        $customFields = $this->getList();
+        if ( isset($customFields) && $customFields && count( $customFields ) > 0 ) {
+            $haveCustomFields = true;
+        }
+
+        require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
+        $customFieldsData = customFieldsGetMemberInfoFields( $memberId );
+
+        // Compile template data
+        $template_data = array(
+            'prefix'           => 'glm_custom_field',
+            'customFields'     => $customFields,
+            'customFieldsData' => $customFieldsData,
+            'fieldTypes'       => $this->config['custom_field_types'],
+            'haveCustomFields' => $haveCustomFields,
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => true,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/memberinfo/fields.html',
+            'data'             => $template_data
+        );
+
+
+    }
+
+}
index 6de6790..22bcca9 100644 (file)
  *
  *  Also note that parameters will be in the context of the main admin controller constructor.
   */
+add_filter( 'glm-member-db-member-info-custom-nav', function( $memberId ){
+    $out = '<a id="glm-member-info-custom-fields" data-show-table="glm-table-custom-fields" class="glm-member-info-tab nav-tab">Custom Fields</a>';
+    return $out;
+});
+
+add_filter( 'glm-member-db-member-info-custom-tab', function( $memberId ){
+    $content = $this->controller( 'memberinfo', 'fields', $memberId );
+    return $content;
+});
+add_action(
+    'glm-member-db-member-info-save-custom-fields',
+    function( $memberInfoId ){
+        require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php';
+        // this will save the member data
+        customFieldsSaveMemberInfoFields( $memberInfoId );
+    },
+    1,
+    1
+);
index 65d5654..0860651 100644 (file)
  * );
  *
  */
+// If user can manage all members
+if (current_user_can('glm_members_members')) {
+    add_filter('glm-member-db-add-tab-for-management',
+        function($addOnTabs) {
+            $newTabs = array(
+                array(
+                    'text' => 'Custom Fields',
+                    'menu' => 'fields',
+                    'action' => 'fields',
+                    'option' => 'list'
+                ),
 
+            );
+            $addOnTabs = array_merge($addOnTabs, $newTabs);
+            return $addOnTabs;
+        }
+    );
+}
index d345d94..1e14758 100644 (file)
@@ -1,5 +1,5 @@
--- Gaslight Media Members Database - Events Add-On
--- File Created: 2017-02-07
+-- Gaslight Media Members Database - Fields Add-On
+-- File Created: 2017-03-27
 -- Database Version: 0.0.1
 -- Database Creation Script
 --
 
 
 -- Field Setup Table
-CREATE TABLE {prefix}field_setup (
+CREATE TABLE {prefix}custom_fields (
   id INT NOT NULL AUTO_INCREMENT,
   field_name TINYTEXT NOT NULL DEFAULT '',      -- Field Name
+  field_type TINYTEXT NOT NULL DEFAULT '',      -- Field Type
   field_order SMALLINT NOT NULL DEFAULT 0,      -- Order for Field
   PRIMARY KEY (id)
 );
@@ -23,9 +24,10 @@ CREATE TABLE {prefix}field_setup (
 ----
 
 -- Data Table
-CREATE TABLE {prefix}field_data (
+CREATE TABLE {prefix}custom_field_data (
   id INT NOT NULL AUTO_INCREMENT,
-  ref_dest INT NOT NULL DEFAULT 0,              -- Member Id
+  field_id INT NOT NULL DEFAULT 0,              -- Field Id
+  ref_dest INT NOT NULL DEFAULT 0,              -- Member Info Id
   field_data TEXT NOT NULL DEFAULT '',          -- Data for the field
   PRIMARY KEY (id)
 );
diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php
new file mode 100644 (file)
index 0000000..6c5508f
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Events DB Versions
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+$glmMembersFieldsDbVersions = array(
+    '0.0.1' => array('version' => '0.0.1', 'tables' => 2, 'date' => '03/27/2017'),
+);
+
index 79d0569..180782d 100644 (file)
 
 $glmMembersFieldsAddOnValidActions = array(
     'adminActions' => array(
+        'memberinfo' => array(
+            'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
+        ),
+        'management' => array(
+            'fields' => GLM_MEMBERS_FIELDS_PLUGIN_SLUG,
+        ),
     ),
     'frontActions' => array(
     )
 );
-
-?>
\ No newline at end of file
diff --git a/views/admin/management/fields.html b/views/admin/management/fields.html
new file mode 100644 (file)
index 0000000..e958477
--- /dev/null
@@ -0,0 +1,194 @@
+{include file='admin/management/header.html'}
+
+    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+        <a id="glm-settings" data-show-table="glm-table-settings" class="glm-settings-tab nav-tab{if $option=='settings'} nav-tab-active{/if}">Custom Fields</a>
+    </h2>
+
+    <!-- Add Custom Field Button and Dialog Box -->
+    <div id="newFieldButton" class="button button-primary glm-right">Add a Custom Field</div>
+    <div id="newFieldDialog" class="glm-dialog-box" title="Enter a New Custom Field">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="fields">
+            <input type="hidden" name="option" value="addNew">
+
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Field Name:</th>
+                    <td>
+                        <input type="text" name="field_name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Field Type:</th>
+                    <td>
+                        <select name="field_type">
+                            {foreach $field_types as $val => $label}
+                                <option value="{$val}">{$label}</option>
+                            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="newFieldCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Add new Custom Field" class="button button-primary">
+        </form>
+    </div>
+
+    <!-- Delete Field Button and Dialog Box -->
+    <div id="deleteFieldDialog" class="glm-dialog-box" title="Delete Field">
+        <center>
+            <p>Are you sure you want to delete this field?</p>
+            <p><div id="deleteFieldConfirm" class="button button-primary">Yes, delete this field</div></p>
+            <p><div id="deleteFieldCancel" class="button button-primary">Cancel</div></p>
+        </center>
+    </div>
+
+    <!-- Edit Field Dialog Box -->
+    <div id="editFieldDialog" class="glm-dialog-box" title="Edit this Field">
+        <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
+            <input type="hidden" name="glm_action" value="fields">
+            <input type="hidden" name="option" value="update">
+            <input id="editFieldID" type="hidden" name="id" value="">
+            <table class="glm-admin-table">
+                <tr>
+                    <th class="glm-required">Field Name:</th>
+                    <td>
+                        <input id="editFieldName" type="text" name="field_name" class="glm-form-text-input">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Field Type:</th>
+                    <td>
+                        <select id="editFieldType" name="field_type">
+                            {foreach $field_types as $val => $label}
+                                <option value="{$val}">{$label}</option>
+                            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+            </table>
+            <p><span class="glm-required">*</span> Required</p>
+            <a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Update this Field">
+        </form>
+    </div>
+    <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
+        <tr>
+            <td colspan="2">
+                {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
+                {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+                <h2>Custom Fields</h2>
+            </td>
+        </tr>
+    </table>
+    <table id="glm-table-settings" class="glm-admin-table glm-settings-table">
+        <thead>
+            <tr>
+                <th>ID</th>
+                <th>Field</th>
+                <th>Type</th>
+                <th>&nbsp;</th>
+            </tr>
+        </thead>
+        <tbody>
+            {if $haveCustomFields}
+                {assign var="i" value="0"}
+                {foreach $custom_fields as $t}
+                    {if $i++ is odd by 1}
+                        <tr>
+                    {else}
+                        <tr class="alternate">
+                    {/if}
+                <td>{$t.id}</td>
+                <td>
+                    <div>
+                        <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}">{$t.field_name}</a>
+                    </div>
+                </td>
+                <td id="editFieldType_{$t.id}">
+                    {$t.field_type.name}
+                </td>
+                <td>
+                    <div class="deleteFieldButton button button-secondary glm-button-small glm-right" data-fieldID="{$t.id}">Delete</div>
+                </td>
+            </tr>
+            {/foreach}
+        {else}
+            <tr class="alternate"><td colspan="2">(no custom fields listed)</td></tr>
+        {/if}
+        </tbody>
+    </table>
+    <!-- Tests -->
+
+<script type="text/javascript">
+jQuery(document).ready(function($) {
+
+    /*
+     * Edit area tabs
+     */
+    $('.glm-settings-tab').click( function() {
+
+        // Clear table highlights and hide all tables
+        $('.glm-settings-tab').removeClass('nav-tab-active');
+        $('.glm-settings-table').addClass('glm-hidden');
+
+        // Highlight selected tab
+        $(this).addClass('nav-tab-active');
+
+        // Show selected table
+        var table = $(this).attr('data-show-table');
+        $('#' + table).removeClass('glm-hidden');
+
+    });
+    $("#newFieldDialog").dialog({
+        autoOpen: false,
+        minWidth: 400,
+        dialogClass: "glm-dialog-no-close"
+    });
+    $("#editFieldDialog").dialog({
+        autoOpen: false,
+        minWidth: 400,
+        dialogClass: "glm-dialog-no-close"
+    });
+    $("#deleteFieldDialog").dialog({
+        autoOpen: false,
+        minWidth: 400,
+        dialogClass: "glm-dialog-no-close"
+    });
+    $('#newFieldButton').click( function() {
+        $("#newFieldDialog").dialog("open");
+    });
+    $('.editField').click( function() {
+        var fieldID = $(this).attr('data-fieldID');
+        var fieldName = $(this).text();
+        var fieldType = $(this).attr('data-fieldType');
+        $('#editFieldID').val(fieldID);
+        $('#editFieldName').val(fieldName.trim());
+        $('#editFieldType').val(fieldType);
+        $("#editFieldDialog").dialog("open");
+    });
+    $('#editFieldCancel').click( function() {
+        $("#editFieldDialog").dialog("close");
+    });
+    $('#newFieldCancel').click( function() {
+        $("#newFieldDialog").dialog("close");
+    });
+
+    var id = false;
+    $('.deleteFieldButton').click( function() {
+        id = $(this).attr('data-fieldID');
+        $("#deleteFieldDialog").dialog("open");
+    });
+    $('#deleteFieldConfirm').click( function() {
+        $("#deleteFieldDialog").dialog("close");
+        window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=fields&option=delete&id=" + id;
+    });
+    $('#deleteFieldCancel').click( function() {
+        $("#deleteFieldDialog").dialog("close");
+    });
+
+    // Flash certain elements for a short time after display
+    $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+});
+</script>
diff --git a/views/admin/memberinfo/fields.html b/views/admin/memberinfo/fields.html
new file mode 100644 (file)
index 0000000..db2e959
--- /dev/null
@@ -0,0 +1,17 @@
+<table id="glm-table-custom-fields" class="glm-admin-table glm-hidden glm-member-info-table">
+    {foreach $customFields as $field}
+        <tr >
+            <th>{$field.field_name}</th>
+            <td>
+                {if $field.field_type.name == 'text'}
+                <input type="text" name="{$prefix}[{$field.id}]" value="{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]}{/if}">
+                {elseif $field.field_type.name == 'textarea'}
+                    <textarea name="{$prefix}[{$field.id}]">{if isset($customFieldsData[$field.id])}{$customFieldsData[$field.id]}{/if}</textarea>
+                {elseif $field.field_type.name == 'checkbox'}
+                <input type="hidden" name="{$prefix}[{$field.id}]" value="No" {if !isset($customFieldsData[$field.id]) || $customFieldsData[$field.id] == 'No'}checked{/if}>
+                <input type="checkbox" name="{$prefix}[{$field.id}]" value="Yes" {if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == 'Yes'}checked{/if}>
+                {/if}
+            </td>
+        </tr>
+    {/foreach}
+</table>