Adding an option for naming the member custom field tab.
Fix update of fields for the checkboxes.
$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'];
switch ($option) {
+ case 'updateTabNameOption':
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
$option_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT );
$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':
'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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
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 '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ // echo '<pre>$id: ' . print_r( $id, true ) . '</pre>';
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;
'uid' => $uid,
'glm_action' => $glm_action,
'groups' => $groups,
+ 'glm_field_tab_name' => $glm_field_tab_name,
);
// echo "<pre>Template data:" . print_r($template_data, true) . "</pre>";
* 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 = '<a id="glm-custom-fields" data-show-table="glm-table-custom-fields" class="glm-' . $tableName . '-tab nav-tab">' . $tabLabel . '</a>';
return $out;
},10,2);
<select name="{$prefix}[{$field.id}]">
<option value=""></option>
{foreach $field.options as $option}
- <option value="{$option.option_text|escape:'html'}"{if isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == $option.option_text} selected{/if}>{$option.option_text}</option>
+ <option value="{$option.option_text|escape:'html'}"
+ {if (isset($customFieldsData[$field.id]) && $customFieldsData[$field.id] == $option.option_text) || $option.option_default}
+ selected
+ {/if}>{$option.option_text}</option>
{/foreach}
</select>
{/if}
<th class="glm-required">Option Name:</th>
<td><input id="optionName" type="text" name="option_text" class="glm-form-text-input" required></td>
</tr>
- <tr>
- <th>Selected by Default</th>
- <td>
- <input type="hidden" name="default" value="0" />
- <input id="optionDefault" type="checkbox" name="option_default" value="1" />
- </td>
- </tr>
</table>
<a id="cfOptionCancel" class="button button-primary glm-right">Cancel</a>
{* Updates / Errors *}
<table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option2!='settings'} glm-hidden{/if}">
<tr>
- <td colspan="2">
+ <td>
{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>
</tr>
</table>
+{* Manage name for custom field tab *}
+{if $uid == 'glm-member-db'}
+ <form id="editFieldForm" action="{$thisUrl}?page={$thisPage}&glm_action={$glm_action}&option=customfields" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="glm_action" value="{$glm_action}" />
+ <input type="hidden" name="option" value="customfields" />
+ <input type="hidden" id="editFieldOption2" name="option2" value="updateTabNameOption" />
+ <table>
+ <tr>
+ <th> Tab Name </th>
+ <td>
+ <input name="glm_field_tab_name" value="{$glm_field_tab_name}" />
+ </td>
+ <th>
+ <input class="button button-secondary glm-button-small" type="submit" value="Update">
+ </th>
+ </tr>
+ </table>
+ </form>
+{/if}
+
{* custom fields table *}
<div id="sortable-groups">
{if $groups}
<thead>
<tr style="background-color: #ddd;">
<th style="text-align: left;"> Option Name </th>
- <th style="text-align: left;"> Default </th>
<th width="10%">
<div class="fieldoption button button-secondary glm-button-small" data-field-id="{$field.id}"> Add Option </div>
</th>
{foreach $field.options as $option}
<tr>
<td style="text-align: left;"> {$option.option_text} </td>
- <td style="text-align: left;"> {if $option.option_default}Yes{else}No{/if} </td>
<td width="10%">
<div class="deleteOptionButton button button-secondary glm-button-small"
data-option-id="{$option.id}">Delete</div>
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</div>
</td>
</tr>
$('#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);
$('#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');
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');
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');