'use' => 'a'
),
+ // admin_search flag
+ 'admin_search' => array (
+ 'field' => 'admin_search',
+ 'type' => 'checkbox',
+ 'default' => false,
+ 'use' => 'a'
+ ),
+
);
}
* version from this plugin.
*/
define('GLM_MEMBERS_FIELDS_PLUGIN_VERSION', '0.0.1');
-define('GLM_MEMBERS_FIELDS_PLUGIN_DB_VERSION', '0.0.2');
+define('GLM_MEMBERS_FIELDS_PLUGIN_DB_VERSION', '0.0.3');
// This is the minimum version of the GLM Members DB plugin require for this plugin.
define('GLM_MEMBERS_FIELDS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');
$parts = array();
$customFields = $this->wpdb->get_results(
"SELECT *
- FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields",
+ FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE admin_search = 1",
ARRAY_A
);
if ( isset( $customFields ) && count( $customFields ) > 0 ) {
foreach ( $customFields as $key => $field ) {
switch ( $field['field_type'] ) {
- case 'text':
case 'textarea':
+ break;
+ case 'text':
+ // convert name to lower case and replace spaces with _
+ $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
+ $parts[$field['id']] = '<b>' . $field['field_name'] . ':</b> <input type="text" size="10" name="' . $field_name . '"';
+ if ( isset( $_REQUEST[$field_name] ) && $fieldValue = filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
+ $parts[$field['id']] .= ' value="' . $fieldValue . '"';
+ }
+ $parts[$field['id']] .= '></b>';
break;
case 'checkbox':
// Get all custom fields
$customFields = $this->wpdb->get_results(
"SELECT *
- FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields",
+ FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE admin_search = 1",
ARRAY_A
);
if ( isset( $customFields ) && count( $customFields ) > 0 ) {
foreach ( $customFields as $key => $field ) {
switch ( $field['field_type'] ) {
- case 'text':
case 'textarea':
+ break;
+ case 'text':
+ // convert name to lower case and replace spaces with _
+ $field_name = preg_replace( '/[ -]/', '_', strtolower( $field['field_name'] ) );
+ if ( isset( $_REQUEST[$field_name] ) && $fieldValue = filter_var( $_REQUEST[$field_name], FILTER_SANITIZE_STRING ) ) {
+ $queryParts[] = " T.id IN (
+ SELECT mi.member
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info mi, " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data cfd
+ WHERE cfd.ref_dest = mi.id
+ AND cfd.field_data like '%" . esc_sql( $fieldValue ) . "%'
+ AND cfd.field_id = (SELECT id
+ FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+ WHERE field_name = '" . esc_sql( $field['field_name'] ) . "'))";
+ }
break;
case 'checkbox':
+++ /dev/null
--- Gaslight Media Members Database - Fields Add-On
--- File Created: 2017-03-27
--- Database Version: 0.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,
- 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),
- INDEX(field_name(20))
-);
-
-----
-
--- Data Table
-CREATE TABLE {prefix}custom_field_data (
- id INT NOT NULL AUTO_INCREMENT,
- 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).
- INDEX(field_id),
- INDEX(ref_dest)
-);
--- /dev/null
+-- Gaslight Media Members Database - Fields Add-On
+-- File Created: 2017-03-27
+-- Database Version: 0.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,
+ 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
+ admin_search BOOLEAN NOT NULL DEFAULT '0', -- If the field is added to member list filters.
+ PRIMARY KEY (id),
+ INDEX(field_name(20))
+);
+
+----
+
+-- Data Table
+CREATE TABLE {prefix}custom_field_data (
+ id INT NOT NULL AUTO_INCREMENT,
+ 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).
+ INDEX(field_id),
+ INDEX(ref_dest)
+);
$glmMembersFieldsDbVersions = array(
'0.0.1' => array('version' => '0.0.1', 'tables' => 2, 'date' => '03/27/2017'),
'0.0.2' => array('version' => '0.0.2', 'tables' => 2, 'date' => '04/14/2017'),
+ '0.0.3' => array('version' => '0.0.3', 'tables' => 2, 'date' => '04/24/2017'),
);
-- 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 dashses
+-- all queries must be separated by a line with four dashes
CREATE INDEX field_name ON {prefix}custom_fields(field_name(20));
--- /dev/null
+-- Gaslit Media Members Database
+-- File Created: 2017-04-14
+-- Database Version: 0.0.2
+-- 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_fields ADD COLUMN admin_search BOOLEAN DEFAULT '0';
</td>
</tr>
<tr>
- <th>Field Type:</th>
+ <th class="glm-required">Field Type:</th>
<td>
<select name="field_type">
{foreach $field_types as $val => $label}
</select>
</td>
</tr>
+ <tr>
+ <th>Admin Searchable</th>
+ <td>
+ <input type="hidden" name="admin_search" value="0" />
+ <input type="checkbox" name="admin_search" value="1" />
+ (text or checkbox only)
+ </td>
+ </tr>
</table>
<p><span class="glm-required">*</span> Required</p>
<a id="newFieldCancel" class="button button-primary glm-right">Cancel</a>
</td>
</tr>
<tr>
- <th>Field Type:</th>
+ <th class="glm-required">Field Type:</th>
<td>
<select id="editFieldType" name="field_type">
{foreach $field_types as $val => $label}
</select>
</td>
</tr>
+ <tr>
+ <th>Admin Searchable</th>
+ <td>
+ <input type="hidden" name="admin_search" value="0" />
+ <input type="checkbox" id="editAdminSearch" name="admin_search" value="1" />
+ (text or checkbox only)
+ </td>
+ </tr>
</table>
<p><span class="glm-required">*</span> Required</p>
<a id="editFieldCancel" class="button button-primary glm-right">Cancel</a>
<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>
+ <a class="editField" data-fieldID="{$t.id}" data-fieldType="{$t.field_type.name|escape:'html'}" data-adminSearch="{$t.admin_search.value}">{$t.field_name}</a>
</div>
</td>
<td id="editFieldType_{$t.id}">
$("#newFieldDialog").dialog("open");
});
$('.editField').click( function() {
- var fieldID = $(this).attr('data-fieldID');
- var fieldName = $(this).text();
- var fieldType = $(this).attr('data-fieldType');
+ var fieldID = $(this).attr('data-fieldID');
+ var fieldName = $(this).text();
+ var fieldType = $(this).attr('data-fieldType');
+ var adminSearch = $(this).attr('data-adminSearch');
$('#editFieldID').val(fieldID);
$('#editFieldName').val(fieldName.trim());
$('#editFieldType').val(fieldType);
+ console.log(adminSearch);
+ if (adminSearch === '1') {
+ console.log('setting the checked to true');
+ $('#editAdminSearch').prop('checked', true);
+ } else {
+ console.log('setting the checked to false');
+ $('#editAdminSearch').prop('checked', false);
+ }
$("#editFieldDialog").dialog("open");
});
$('#editFieldCancel').click( function() {