Fixed problem with script being included when there's no parent form ID, and working...
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 18 Dec 2017 21:33:42 +0000 (16:33 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 18 Dec 2017 21:33:42 +0000 (16:33 -0500)
classes/customFieldSupport.php
classes/data/dataCustomFieldsData.php
index.php
models/admin/ajax/customFields.php
models/front/customFields/formDisplay.php
setup/commonHooks.php
setup/databaseScripts/create_database_V1.0.2.sql [deleted file]
setup/databaseScripts/create_database_V1.0.3.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V1.0.3.sql [new file with mode: 0644]

index 458e491..86879cc 100644 (file)
@@ -312,6 +312,7 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
                 $res = $this->wpdb->insert(
                     GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
                     array(
+                        'fid'           => $formId,
                         'field_id'      => $field['id'],
                         'record_id'     => $recordId,
                         'text_data'     => ($fType=='text'||$fType=='textarea'||$fType=='picklist' ? $field['submitted'] : ''),
@@ -320,6 +321,7 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
                         'float_data'    => ($fType=='float' ? $field['submitted'] : false),
                     ),
                     array(
+                        '%s',
                         '%d',
                         '%d',
                         '%s',
index 55691d4..ed91f98 100644 (file)
@@ -121,6 +121,15 @@ class GlmDataFieldsCustomFieldsData extends GlmDataAbstract
                 'view_only' => true,
                 'use'       => 'a'
             ),
+            
+            // Form ID
+            'fid' => array(
+                'field'    => 'fid',
+                'type'     => 'text',
+                'required' => true,
+                'use'      => 'a'
+            ),
+            
             // Entity ID (event, member, package)
             'record_id' => array (
                 'field'     => 'record_id',
@@ -128,6 +137,7 @@ class GlmDataFieldsCustomFieldsData extends GlmDataAbstract
                 'view_only' => false,
                 'use'       => 'a'
             ),
+            
             // Event ID
             'field_id' => array(
                 'field'    => 'field_id',
@@ -141,7 +151,7 @@ class GlmDataFieldsCustomFieldsData extends GlmDataAbstract
                 'type'     => 'text',
                 'required' => true,
                 'use'      => 'a'
-            ),
+            )
 
         );
 
index ae3b290..c790cc3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -38,7 +38,7 @@
  *  version from this plugin.
  */
 define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_VERSION', '1.0.0');
-define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.2');
+define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_VERSION', '1.0.3');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');
index 3d65f98..9e7a50b 100644 (file)
@@ -114,6 +114,18 @@ class GlmMembersAdmin_ajax_customFields extends GlmDataFieldsCustomFields
 
                 // Delete this custom field
                 $this->deleteEntry($fieldId, true);
+                
+                // Delete any field options
+                $this->wpdb->query(
+                    $this->wpdb->prepare(
+                        "
+                        DELETE FROM ".GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX."custom_field_options
+                                WHERE field_id = %d
+                               ",
+                        $fieldId
+                    )
+                );
+                
                 echo true;
 
                 break;
index 3b87906..e0344ef 100644 (file)
@@ -109,6 +109,7 @@ class GlmMembersFront_customFields_formDisplay extends GlmDataFieldsCustomFields
         $view       = 'displayForm.html';
         $parentFormId   = $actionData['request']['parent-form-id'];
 
+trigger_error('Form Display Submit Data '.print_r($actionData,1),E_USER_NOTICE);        
         if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) {
             trigger_error('Shortcode Called: glm-members-customfields-form-display', E_USER_NOTICE);
         }
@@ -128,6 +129,18 @@ class GlmMembersFront_customFields_formDisplay extends GlmDataFieldsCustomFields
                 foreach ($formFields as $fieldKey => $fieldVal) {
                     $formFields[$fieldKey]['field_fail'] = '';
                 }
+                
+                // If there's a record ID
+                $recordId = ($actionData['request']['record-id'] - 0);
+                if ($recordId > 0) {
+trigger_error('recordId = '.$recordId,E_USER_NOTICE);                    
+                    // Try to get any stored data
+                    $CustomFieldData = new GlmDataFieldsCustomFieldsData($this->wpdb, $this->config);
+                    $customFieldData = $CustomFieldData->getList("fid = '$formId' AND field_id = $recordId");
+trigger_error('Field Data = '.print_r($customFieldData,1), E_USER_NOTICE);                    
+                    
+                    
+                }
 
             }
 
index 8924960..8eefe69 100644 (file)
@@ -127,7 +127,7 @@ add_filter( 'glm-members-customfields-form-display', function( $content, $fid, $
     }
 
     // Call form display shortcode to do this work
-    $content .= do_shortcode('[glm-members-customfields-form-display fid='.$fid.' record-id='.$recordId.' parent-form-id='.$parentFormId.' form-data='.$formData.']');
+    $content .= do_shortcode('[glm-members-customfields-form-display fid="'.$fid.'" record-id="'.$recordId.'" parent-form-id="'.$parentFormId.'" form-data="'.$formData.'"]');
 
     return $content;
 
diff --git a/setup/databaseScripts/create_database_V1.0.2.sql b/setup/databaseScripts/create_database_V1.0.2.sql
deleted file mode 100644 (file)
index c8c92c0..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
--- Gaslight Media Members Database - Custom Fields Add-On
--- File Created: 2017-03-27
--- Database Version: 1.0.2
--- Database Creation Script
---
--- This file is called to create a new set of tables for this
--- add-on for the most recent database version for this add-on.
---
--- There should only be one such file in this directory
---
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
-
--- Field Setup Table
-CREATE TABLE {prefix}custom_fields (
-  id INT NOT NULL AUTO_INCREMENT,
-  fid TEXT NOT NULL DEFAULT '',                 -- Unique ID for this form (group of these fields)
-  field_name TINYTEXT NOT NULL DEFAULT '',      -- Field reference name
-  field_prompt TINYTEXT NOT NULL DEFAULT '',    -- Prompt to display on form to user
-  field_type TINYTEXT NOT NULL DEFAULT '',      -- Field Type
-  field_order SMALLINT NOT NULL DEFAULT 0,      -- Order for Field
-  required BOOLEAN NOT NULL DEFAULT '0',        -- If the field is required.
-  PRIMARY KEY (id),
-  INDEX (field_name(40))
-);
-
-----
-
--- Data Table
-CREATE TABLE {prefix}custom_field_data (
-  id INT NOT NULL AUTO_INCREMENT,
-  field_id INT NOT NULL DEFAULT 0,                  -- Pointer to ID of field in custom_fields table
-  record_id INT NOT NULL DEFAULT 0,                 -- id for this submission of this form
-  text_data TEXT NOT NULL DEFAULT '',               -- Data for a text field
-  checkbox_data BOOLEAN NOT NULL DEFAULT false,     -- Data for a boolean field
-  integer_data INTEGER NOT NULL DEFAULT 0,          -- Data for an integer field
-  float_data FLOAT NOT NULL DEFAULT '0.00',         -- Data for a float field
-  PRIMARY KEY (id),
-  INDEX (field_id),
-  INDEX (record_id)
-);
-
-----
-
--- Picklist Field Options
-CREATE TABLE {prefix}custom_field_options (
-  id INT NOT NULL AUTO_INCREMENT,
-  field_id INT NOT NULL DEFAULT 0,                  -- Pointer to ID of fields in custom_fields table
-  option_text TINYTEXT NOT NULL DEFAULT '',         -- Option's Displayed text
-  option_value TINYTEXT NOT NULL DEFAULT '',        -- Option's value
-  option_cost FLOAT NOT NULL DEFAULT '0.00',        -- A cost added when this option is selected
-  option_default BOOLEAN NOT NULL DEFAULT false,    -- Flag indicating that this option is the default
-  PRIMARY KEY (id),
-  INDEX (field_id)
-);
diff --git a/setup/databaseScripts/create_database_V1.0.3.sql b/setup/databaseScripts/create_database_V1.0.3.sql
new file mode 100644 (file)
index 0000000..f458b07
--- /dev/null
@@ -0,0 +1,58 @@
+-- Gaslight Media Members Database - Custom Fields Add-On
+-- File Created: 2017-03-27
+-- Database Version: 1.0.2
+-- Database Creation Script
+--
+-- This file is called to create a new set of tables for this
+-- add-on for the most recent database version for this add-on.
+--
+-- There should only be one such file in this directory
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+
+-- Field Setup Table
+CREATE TABLE {prefix}custom_fields (
+  id INT NOT NULL AUTO_INCREMENT,
+  fid TEXT NOT NULL DEFAULT '',                 -- Unique ID for this form (group of these fields)
+  field_name TINYTEXT NOT NULL DEFAULT '',      -- Field reference name
+  field_prompt TINYTEXT NOT NULL DEFAULT '',    -- Prompt to display on form to user
+  field_type TINYTEXT NOT NULL DEFAULT '',      -- Field Type
+  field_order SMALLINT NOT NULL DEFAULT 0,      -- Order for Field
+  required BOOLEAN NOT NULL DEFAULT '0',        -- If the field is required.
+  PRIMARY KEY (id),
+  INDEX (field_name(40))
+);
+
+----
+
+-- Data Table
+CREATE TABLE {prefix}custom_field_data (
+  id INT NOT NULL AUTO_INCREMENT,
+  fid TEXT NOT NULL DEFAULT '',                     -- Form ID
+  field_id INT NOT NULL DEFAULT 0,                  -- Pointer to ID of field in custom_fields table
+  record_id INT NOT NULL DEFAULT 0,                 -- id for this submission of this form
+  text_data TEXT NOT NULL DEFAULT '',               -- Data for a text field
+  checkbox_data BOOLEAN NOT NULL DEFAULT false,     -- Data for a boolean field
+  integer_data INTEGER NOT NULL DEFAULT 0,          -- Data for an integer field
+  float_data FLOAT NOT NULL DEFAULT '0.00',         -- Data for a float field
+  PRIMARY KEY (id),
+  INDEX (fid(30)),
+  INDEX (field_id),
+  INDEX (record_id)
+);
+
+----
+
+-- Picklist Field Options
+CREATE TABLE {prefix}custom_field_options (
+  id INT NOT NULL AUTO_INCREMENT,
+  field_id INT NOT NULL DEFAULT 0,                  -- Pointer to ID of fields in custom_fields table
+  option_text TINYTEXT NOT NULL DEFAULT '',         -- Option's Displayed text
+  option_value TINYTEXT NOT NULL DEFAULT '',        -- Option's value
+  option_cost FLOAT NOT NULL DEFAULT '0.00',        -- A cost added when this option is selected
+  option_default BOOLEAN NOT NULL DEFAULT false,    -- Flag indicating that this option is the default
+  PRIMARY KEY (id),
+  INDEX (field_id)
+);
index 510cfbb..2c04b30 100644 (file)
@@ -16,6 +16,7 @@
 $glmMembersCustomFieldsDbVersions = array(
     '1.0.0' => array('version' => '1.0.0', 'tables' => 2, 'date' => '12/01/2017'),
     '1.0.1' => array('version' => '1.0.1', 'tables' => 2, 'date' => '12/05/2017'),
-    '1.0.2' => array('version' => '1.0.2', 'tables' => 3, 'date' => '12/15/2017')
+    '1.0.2' => array('version' => '1.0.2', 'tables' => 3, 'date' => '12/15/2017'),
+    '1.0.3' => array('version' => '1.0.3', 'tables' => 3, 'date' => '12/18/2017')
 );
 
diff --git a/setup/databaseScripts/update_database_V1.0.3.sql b/setup/databaseScripts/update_database_V1.0.3.sql
new file mode 100644 (file)
index 0000000..191576a
--- /dev/null
@@ -0,0 +1,13 @@
+-- Gaslight Media Members Database  - Custom Fields Add-On
+-- File Created: 08/30/16 09:47:15
+-- Database Version: 1.0.1
+-- Database Update From Previous Version Script
+--
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+ALTER TABLE {prefix}custom_field_data ADD COLUMN fid TINYTEXT;
+
+----
+
+CREATE INDEX fid ON {prefix}custom_field_data (record_id(30)));
\ No newline at end of file