From: Steve Sutton Date: Wed, 25 Jul 2018 19:45:20 +0000 (-0400) Subject: Fix some update issues with fields and add option for tab name. X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d5dd421c8ccb4b09b8f68f11b6e04b38bc48371f;p=WP-Plugins%2Fglm-member-db-fields.git Fix some update issues with fields and add option for tab name. Adding an option for naming the member custom field tab. Fix update of fields for the checkboxes. --- diff --git a/models/admin/management/fields.php b/models/admin/management/fields.php index 93c7862..8a6e9ef 100644 --- a/models/admin/management/fields.php +++ b/models/admin/management/fields.php @@ -124,6 +124,12 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields $custom_fields = false; $haveCustomFields = false; $where = ' TRUE '; + $glm_field_tab_name = get_option( 'glm_field_tab_name' ); + + // If tab name option is empty then set it. + if ( !$glm_field_tab_name ) { + update_option( 'glm_field_tab_name', 'Custom Fields', true ); + } if (isset($_REQUEST['option2'])) { $option = $_REQUEST['option2']; @@ -147,6 +153,13 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields switch ($option) { + case 'updateTabNameOption': + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + $tab_name = filter_var( $_REQUEST['glm_field_tab_name'] ); + update_option( 'glm_field_tab_name', $tab_name, true ); + $glm_field_tab_name = get_option( 'glm_field_tab_name' ); + break; + case 'deleteOption': // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; $option_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ); @@ -164,39 +177,38 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ); $field_id = filter_var( $_REQUEST['field_id'], FILTER_VALIDATE_INT ); $option_text = filter_var( $_REQUEST['option_text'] ); - $option_default = filter_var( $_REQUEST['option_default'], FILTER_VALIDATE_BOOLEAN ); + // $option_default = filter_var( $_REQUEST['option_default'], FILTER_VALIDATE_BOOLEAN ); if ( $field_id ) { $option_data = array( 'field_id' => $field_id, 'option_text' => $option_text, - 'option_default' => $option_default, ); if ( $id ) { $this->wpdb->update( GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_options', $option_data, array( 'id' => $id ), - array( '%d', '%s', '%d' ), + array( '%d', '%s' ), array( '%d' ) ); } else { $this->wpdb->insert( GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_options', $option_data, - array( '%d', '%s', '%d' ) + array( '%d', '%s' ) ); $id = $this->wpdb->insert_id; } } // If the default is selected then set all but this option to false for option_default - if ( $option_default && $id ) { - $this->wpdb->query( - "UPDATE " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_options - SET option_default = 0 - WHERE field_id = $field_id - AND id != $id" - ); - } + // if ( $option_default && $id ) { + // $this->wpdb->query( + // "UPDATE " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_options + // SET option_default = 0 + // WHERE field_id = $field_id + // AND id != $id" + // ); + // } break; case 'updateNewGroup': @@ -295,6 +307,15 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields 'field_order' => $field_order, 'admin_search' => $admin_search, 'required' => $required, + ), + array( + '%d', // gid + '%s', // uid + '%s', // field_name + '%s', // field_type + '%d', // field_order + '%s', // admin_search + '%s', // required ) ); // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; @@ -304,8 +325,33 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields break; case 'update': + $gid = filter_var( $_REQUEST['gid'], FILTER_VALIDATE_INT ); + $field_name = filter_var( $_REQUEST['field_name'] ); + $admin_search = filter_var( $_REQUEST['admin_search'], FILTER_VALIDATE_BOOLEAN ); + $required = filter_var( $_REQUEST['required'], FILTER_VALIDATE_BOOLEAN ); + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + // echo '
$id: ' . print_r( $id, true ) . '
'; if ($id > 0) { - $this->updateEntry($id); + // $this->updateEntry($id); + $this->wpdb->update( + GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_fields', + array( + 'gid' => $gid, + 'uid' => $uid, + 'field_name' => $field_name, + 'admin_search' => $admin_search, + 'required' => $required, + ), + array( 'id' => $id ), + array( + '%d', // gid + '%s', // uid + '%s', // field_name + '%s', // admin_search + '%s', // required + ), + array( '%d' ) + ); } break; @@ -404,6 +450,7 @@ class GlmMembersAdmin_management_fields extends GlmDataFieldsCustomFields 'uid' => $uid, 'glm_action' => $glm_action, 'groups' => $groups, + 'glm_field_tab_name' => $glm_field_tab_name, ); // echo "
Template data:" . print_r($template_data, true) . "
"; diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 54a79a5..5eaeb01 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -89,7 +89,12 @@ add_filter( 'glm-members-customfields-data', function( $content, $uid, $id ){ * Filter to Return a tab link for multi-page sub-tabs. */ add_filter( 'glm-member-db-custom-fields-nav', function( $content, $tableName ){ - $tabLabel = ( $tableName == 'contact-info' ) ? 'Directory Info' : 'Custom Fields'; + $tab_name = get_option( 'glm_field_tab_name' ); + if ( $tab_name ) { + $tabLabel = $tab_name; + } else { + $tabLabel = ( $tableName == 'contact-info' ) ? 'Directory Info' : 'Custom Fields'; + } $out = '' . $tabLabel . ''; return $out; },10,2); diff --git a/views/admin/entity/fields.html b/views/admin/entity/fields.html index f6173a2..9e11ed8 100644 --- a/views/admin/entity/fields.html +++ b/views/admin/entity/fields.html @@ -43,7 +43,10 @@ {/if} diff --git a/views/admin/management/fields.html b/views/admin/management/fields.html index 194e1ad..e63216a 100644 --- a/views/admin/management/fields.html +++ b/views/admin/management/fields.html @@ -42,13 +42,6 @@ Option Name: - - Selected by Default - - - - - Cancel @@ -135,7 +128,7 @@ {* Updates / Errors *} -
+ {if $settingsUpdated}

Settings Updated

{/if} {if $settingsUpdateError}Settings Update Error{/if}

Custom Fields

@@ -143,6 +136,26 @@
+{* Manage name for custom field tab *} +{if $uid == 'glm-member-db'} +
+ + + + + + + + + +
Tab Name + + + +
+
+{/if} + {* custom fields table *}
{if $groups} @@ -203,7 +216,6 @@ Option Name - Default
Add Option
@@ -213,7 +225,6 @@ {foreach $field.options as $option} {$option.option_text} - {if $option.option_default}Yes{else}No{/if}
Delete
@@ -222,7 +233,6 @@ data-id="{$option.id}" data-field-id="{$option.field_id}" data-option-name="{$option.option_text|escape:'html'}" - data-option-default="{$option.option_default}" >Edit
@@ -390,7 +400,7 @@ jQuery(document).ready(function($) { $('#editFieldName').val(''); $('#editFieldType').val(''); // Set the field type to not be disabled - $('#editFieldType').prop('disabled', false); + //$('#editFieldType').prop('isabled', false); $('#editAdminSearch').prop('checked', false); $('#editRequired').prop('checked', false); @@ -407,7 +417,7 @@ jQuery(document).ready(function($) { $('#editFieldID').val(fieldID); $('#editFieldName').val(fieldName.trim()); $('#editFieldType').val(fieldType); - $('#editFieldType').prop('disabled', true); + //$('#editFieldType').prop('disabled', true); $('#editGroupID').val(groupID); $('#editFieldOption2').val('update'); $('#editFieldSubmit').val('Update Field'); @@ -431,11 +441,9 @@ jQuery(document).ready(function($) { var f_id = $('#optionId'); var f_field_id = $('#fieldId'); var f_option_name = $('#optionName'); - var f_option_default = $('#optionDefault'); f_id.val(''); f_field_id.val(''); f_option_name.val(''); - f_option_default.prop('checked', false); // if there's a data id attr var optionId = $(this).attr('data-id'); @@ -447,9 +455,6 @@ jQuery(document).ready(function($) { f_id.val( $(this).attr('data-id') ); f_field_id.val( $(this).attr('data-field-id') ); f_option_name.val( $(this).attr('data-option-name') ); - if ( $(this).attr('data-option-default') === '1' ) { - f_option_default.prop('checked', true); - } } $('#cfOptionDialog').dialog('open');