adding admin search template and model files to manage the header search
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 26 Oct 2018 12:15:47 +0000 (08:15 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 26 Oct 2018 12:15:47 +0000 (08:15 -0400)
models/admin/adminSearch/index.php [deleted file]
models/admin/manageMembers/index.php [new file with mode: 0644]
models/admin/manageMembers/manage.php [deleted file]
models/admin/manageMembers/search.php [new file with mode: 0644]
setup/adminHooks.php
setup/adminMenus.php
setup/validActions.php
views/admin/manageMembers/adminSearch/searchHeader.html [new file with mode: 0644]
views/admin/manageMembers/index.html [new file with mode: 0644]
views/admin/manageMembers/manage.html [deleted file]

diff --git a/models/admin/adminSearch/index.php b/models/admin/adminSearch/index.php
deleted file mode 100644 (file)
index ba4b501..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-<?php
-
-/**
- * Gaslight Media Members Database
- * Admin Members Dashboard
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * 
- * @license  http://www.gaslightmedia.com Gaslightmedia
- * @version  0.1
- */
-
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
-
-/**
- * Dashboard Class Model
- *
- * Each Add-On can have one or more dashboards.
- */
-
-class GlmMembersAdmin_newDashboard_index extends GlmDataMembers
-{
-    /**
-     * Word Press Database Object
-     *
-     * @var $wpdb
-     * @access public
-     */
-    public $wpdb;
-    /**
-     * Plugin Configuration Data
-     *
-     * @var $config
-     * @access public
-     */
-    public $config;
-
-    /**
-     * Constructor
-     *
-     * This contructor sets up this model. At this time that only includes
-     * storing away the WordPress data object.
-     *
-     * @return object Class object
-     *
-     */
-    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);
-
-    }
-
-    /**
-     * Perform Model Action
-     *
-     * This method does the work for this model and returns any resulting data
-     *
-     * @return array Status and data array
-     *
-     * 'status'
-     *
-     * True if successful and false if there was a fatal failure.
-     *
-     * 'menuItemRedirect'
-     *
-     * If not false, provides a menu item the controller should
-     * execute after this one. Normally if this is used, there would also be a
-     * modelRedirect value supplied as well.
-     *
-     * 'modelRedirect'
-     *
-     * If not false, provides an action the controller should execute after
-     * this one.
-     *
-     * 'view'
-     *
-     * A suggested view name that the controller 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.
-     *
-     */
-    public function modelAction ( $actionData = false )
-    {
-
-        $success            = true;
-        $text               = 'text';
-        $haveInfoRecords    = false;
-        $memberInfoRecords  = false;
-        $noActive           = false;
-        $showArchived       = false;
-        $memberID           = 0;
-        $clickThroughCounts = array('day' => 0, 'week' => 0, 'month' => 0);
-        $detailViewCounts   = array('day' => 0, 'week' => 0, 'month' => 0);
-
-        // Enqueue Materialize
-        wp_register_script(
-            'materialize',
-            GLM_MEMBERS_PLUGIN_URL . 'js/materialize/materialize.min.js',
-            array(
-                    'jquery'
-            ),
-            GLM_MEMBERS_PLUGIN_VERSION
-        );
-        wp_register_script(
-            'autoComplete',
-            GLM_MEMBERS_PLUGIN_URL . 'js/materialize/autoComplete.min.js',
-            array(
-                    'jquery'
-            ),
-            GLM_MEMBERS_PLUGIN_VERSION
-        );
-        wp_enqueue_script('materialize', false, array('jquery'), false, true);
-        wp_enqueue_script('autoComplete', false, array('jquery'), false, true);
-        wp_enqueue_style('materialize-css', GLM_MEMBERS_PLUGIN_URL . 'css/materialize.min.css');
-        wp_enqueue_style('autoComplete', GLM_MEMBERS_PLUGIN_URL . 'css/autoComplete.css');
-        wp_enqueue_style('admin-css', GLM_MEMBERS_PLUGIN_URL . 'css/glma-admin-sass.css');
-        wp_enqueue_style('css-icons', "https://fonts.googleapis.com/icon?family=Material+Icons");
-     
-        // Check if there's a logged in user who is locked to their own entity.
-        $lockedToMember = apply_filters( 'glm_members_locked_to_member_id', false );
-        $memberID       = $lockedToMember;
-
-        // Get the current date, first date of this week, and first date of this month
-        $today = date('Y-m-d');
-        $thisWeek =  date('Y-m-d', strtotime('-'.date('w').' days'));
-        $thisMonth = date('Y-m-d', strtotime('-'.(date('j')-1).' days'));
-
-
-        // Create a set of useful data for each registered plugin that has a filter
-        //  Use that filter to retrieve table information, then run query for each 'list' field.
-        foreach ( $this->config[ 'addOns' ] as $a ) {
-            if ( has_filter( $a['slug'] . "-dashboard-widget") ) {
-                $addons[$a['slug']]['name'] = $a['short_name'];
-                $addons[$a['slug']]['slug'] = $a['slug'];
-                $addons[$a['slug']]['widgetData'] = apply_filters($a['slug'] . "-dashboard-search", "");
-                // Sort the component list based on the 'order'
-                uasort($addons[$a['slug']]['widgetData']['components'], array($this, 'orderSort') ) ;
-                
-            }
-        }
-
-        // Compile template data.
-        $templateData = array(
-            'lockedToMember'        => $lockedToMember,
-            'member'                => $actionData,
-            'showArchived'          => $showArchived,
-            'statusTypeNumbers'     => $this->config['status_numb'],
-            'memberID'              => $memberID,
-            'haveInfoRecords'       => $haveInfoRecords,
-            'memberInfoRecords'     => $memberInfoRecords,
-            'statusPending'         => $this->config['status_numb']['Pending'],
-            'addons'                => $addons,
-            'baseUrl'               => GLM_MEMBERS_PLUGIN_URL 
-        );
-
-        // Return status, suggested view, and data to controller.
-        return array(
-            'status'            => $success,
-            'menuItemRedirect'  => false,
-            'modelRedirect'     => false,
-            'view'              => 'admin/newDashboard/index.html',
-            'data'              => $templateData
-        );
-
-    }
-
-    public function orderSort ($a, $b) { return (strcmp ($a['order'],$b['order']));    }
-}
diff --git a/models/admin/manageMembers/index.php b/models/admin/manageMembers/index.php
new file mode 100644 (file)
index 0000000..c501447
--- /dev/null
@@ -0,0 +1,413 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Admin List Members
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+// Load Members data abstract
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_manageMembers_index extends GlmDataMembers
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    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 to setup table and fields array
+         *
+         * Since this class is extending GlmDataMembers, it does not need to pass
+         * $wpdb and $config to it in the constructor.
+         */
+        parent::__construct(false, false);
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * '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.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+        require_once GLM_MEMBERS_PLUGIN_PATH . '/models/admin/manageMembers/search.php';
+        $where              = ' true ';
+        $alphaWhere         = ' true ';
+        $catSearchSelected  = false;
+        $catSelectedString  = "";
+        $mTypeSelected      = '';
+        $catSelected        = '';
+        $catsToUse          = '';
+        $filterPending      = false;
+        $filterArchived     = false;
+        $filterFeatured     = false;
+        $haveFilter         = false;
+        $numbDisplayed      = false;
+        $lastDisplayed      = false;
+        $paging             = true;
+        $prevStart          = false;
+        $nextStart          = false;
+        $start              = 1;
+        $limit              = 20;        // Set to the number of listings per page
+        $namesList          = false;
+        $enable_members     = $this->config['settings']['enable_members'];
+        $textSearch         = false;
+
+        // Save all query parameters
+        if ( isset( $_REQUEST['glm_action'] ) && $_REQUEST['glm_action'] == 'list' ) {
+            $_SESSION['member_saved_search'] = $_REQUEST;
+        } else if ( !isset( $_REQUEST['glm_action'] )
+            && (!isset( $_REQUEST['back_to_search'] ) || !filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN ))
+        ) {
+            unset( $_SESSION['member_saved_search'] );
+        }
+        // Check for back to search flag
+        if ( isset( $_REQUEST['back_to_search'] )
+            && filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN )
+            && isset( $_SESSION['member_saved_search'] )
+        ) {
+            $_REQUEST = $_SESSION['member_saved_search'];
+        }
+        // Check if this is a request to show archived members
+        if (isset($_REQUEST['filterArchived'])) {
+            $where .= " AND access = ".$this->config['access_numb']['Archived'];
+            $filterArchived = true;
+            $haveFilter = true;
+
+        // If not, don't show them
+        } else {
+            $where .= " AND access != ".$this->config['access_numb']['Archived'];
+        }
+
+        // Check for a text search
+        if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search']) != '') {
+
+            // $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
+            $textSearch = addslashes(filter_var($_REQUEST['text_search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
+            $where .= " AND T.id in (
+                SELECT DISTINCT(id)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members
+                 WHERE name like '%$textSearch%'
+            )";
+
+        }
+
+        // Get a list of categories for filtering
+        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
+        $Categories = new GlmDataCategories($this->wpdb, $this->config);
+        $categories = $Categories->getListSortedParentChild(false);
+
+        // If we have categories, add "selected" element default false;
+        if (is_array($categories)) {
+            reset($categories);
+            while (list($k, $v) = each($categories)) {
+                $categories[$k]['selected'] = false;
+            }
+        }
+
+        // Get a list of member_types for filtering
+        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberTypes.php';
+        $MemberTypes = new GlmDataMemberTypes( $this->wpdb, $this->config );
+        $member_types = $MemberTypes->getList();
+
+        // Check if there is a member_type filter
+        if ( isset( $_REQUEST['filterMemberTypes'] ) && $memberTypeFilter = filter_var( $_REQUEST['filterMemberTypes'], FILTER_VALIDATE_INT ) ) {
+            $where .= " AND T.member_type = $memberTypeFilter ";
+            $mTypeSelected = $memberTypeFilter;
+        }
+
+        // Check if there is a category filter (multi-select)
+        if (isset($_REQUEST['categorySearch']) && $_REQUEST['categorySearch'] > 0) {
+            $catsToUse = explode(',',$_REQUEST['categorySearch']);
+        }
+        if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
+            $catsToUse = $_REQUEST['filterCategories'];
+        }
+
+        if ($catsToUse && $catsToUse !== '') {
+            $cats = '';
+            $catsSep = '';
+
+            // For each selected category
+            foreach($catsToUse as $c) {
+                $cats .= $catsSep.$c;
+                $catsSep = ',';
+                $categories[$c]['selected'] = true;
+            }
+
+            $where .= " AND T.id in (
+                    SELECT DISTINCT(I.member)
+                      FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I,
+                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M,
+                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C
+                     WHERE I.id = M.member_info
+                       AND I.status != " . $this->config['status_numb']['Archived'] ."
+                       AND (
+                           M.category in ($cats)
+                           OR (C.parent in ($cats) AND M.category = C.id)
+                           )
+            )";
+            $catSelectedString = $cats;
+        }
+
+        // Check for "Pending Only
+        if (isset($_REQUEST['filterPending'])) {
+
+            // Refine search only to members with pending Info data
+            $where .= " AND (
+                SELECT COUNT(id)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I
+                 WHERE I.status = ".$this->config['status_numb']['Pending']."
+                   AND I.member = T.id
+            )";
+
+            $filterPending = true;
+            $haveFilter = true;
+        }
+
+        // Check for "Featured Only
+        if (isset($_REQUEST['filterFeatured'])) {
+
+            // Refine search only to members with pending Info data
+            $where .= " AND (
+                SELECT COUNT(id)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members I
+                 WHERE I.featured = 1
+                   AND I.id = T.id
+
+            )";
+            $filterFeatured = true;
+            $haveFilter = true;
+        }
+
+        // If doing alpha list
+        if (isset($_REQUEST['alpha'])) {
+            $actionData['request']['alpha'] = $_REQUEST['alpha'];
+        }
+
+        $alphaList = false;
+        $alphaWhere = '';
+
+        $alphaSelected = false;
+
+        // If user clicked a page request then we need to check the savedAlpha value
+        if (isset($_REQUEST['savedAlpha']) && isset($_REQUEST['pageSelect'])) {
+            $actionData['request']['alpha'] = $_REQUEST['savedAlpha'];
+        }
+
+        if ($actionData['request']['alpha'] && strlen($actionData['request']['alpha']) == 1) {
+            $alphaSelected = strtoupper($actionData['request']['alpha']);
+            $alphaWhere .= " AND T.name LIKE '$alphaSelected%'";
+        }
+
+        // Get full list for all other filters, but not filtered by alpha (that would be silly)
+        $alphaList = $this->getAlphaList(' AND '.$where, $alphaSelected);
+
+        $whereParts = apply_filters('glm-member-db-admin-search-query', $where, 'glm-member-db');
+        if ( is_array( $whereParts ) && count( $whereParts ) > 0 ) {
+            $where .= ' AND '.implode(" AND ", $whereParts);
+            $whereSep = ' AND ';
+        }
+
+        // Get count of members listed
+        $memberCount = $this->getStats($where);
+
+        // If the number of members is less than a page, don't do paging
+        if ($memberCount <= $limit) {
+            $paging = false;
+        }
+
+        // Get full list of names matching this where clause for search box
+        $namesList = $this->getIdName($where);
+
+        // Check if we're doing paging
+        if (isset($_REQUEST['pageSelect'])) {
+
+            // If request is for Next
+            if ($_REQUEST['pageSelect'][0] == 'N') {
+                $newStart = $_REQUEST['nextStart'] - 0;
+
+            // Otherwise it must be Previous
+            } else {
+                $newStart = $_REQUEST['prevStart'] - 0;
+            }
+
+            if ($newStart > 0) {
+                $start = $newStart;
+            }
+        }
+
+        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
+
+        // Get stats for number of members found matching current selection criteria (includes alpha selection)
+        $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
+
+        // Get a current list of members
+        $listResult = $this->getSimpleMembersList($where.$alphaWhere, 'name', true, 'id', $start, $limit);
+
+        // Get paging results
+        $numbDisplayed = $listResult['returned'];
+        $lastDisplayed = $listResult['last'];
+        if ($start == 1) {
+            $prevStart = false;
+        } else {
+            $prevStart = $start - $limit;
+            if ($start < 1) {
+                $start = 1;
+            }
+        }
+        if ($listResult['returned'] == $limit) {
+            $nextStart = $start + $limit;
+        }
+
+        // since we're doing paging, we have to break out just the member data
+        $list = $listResult['list'];
+        unset($listResult);
+
+        // If we have list entries - even if it's an empty list
+        $success = true;
+        $haveMembers = false;
+        if ($list !== false) {
+
+            $success = true;
+
+            // If we have any entries
+            if (count($list) > 0) {
+                $haveMembers = true;
+            }
+        }
+
+        // Determine if current user can add, edit, delete member data
+//        $canEdit = current_user_can('glm_members_edit');
+
+        // Add a url for each member
+        if ( isset( $list) && is_array( $list ) ) {
+            foreach ($list as $member) {
+                $list[$member['id']]['member_slug'] = sanitize_title($member['name']);
+            }
+        }
+
+        // Create current month/date string to pre-populate the Month/Year field for
+        $monthYear = date('F Y');
+
+        // Update the textSearch for output into the form.
+        $textSearch = str_replace("\'", "'", $textSearch );
+        $textSearch = str_replace('\\"', '&quot;', $textSearch );
+        $textSearch = str_replace('\\', '', $textSearch );
+
+        // Compile template data
+        $templateData = array(
+            'monthYear'         => $monthYear,
+            'enable_members'    => $enable_members,
+            'haveMembers'       => $haveMembers,
+            'members'           => $list,
+            'memberCount'       => $memberCount,
+            'categories'        => $categories,
+            'member_types'      => $member_types,
+            'haveFilter'        => $haveFilter,
+            'filterArchived'    => $filterArchived,
+            'filterFeatured'    => $filterFeatured,
+            'filterPending'     => $filterPending,
+            'catSelected'       => $catSelected,
+            'catSearchSelected' => $catSelectedString,
+            'mTypeSelected'     => $mTypeSelected,
+            'alphaList'         => $alphaList,
+            'alphaSelected'     => $alphaSelected,
+            'numbDisplayed'     => $numbDisplayed,
+            'lastDisplayed'     => $lastDisplayed,
+            'paging'            => $paging,
+            'prevStart'         => $prevStart,
+            'nextStart'         => $nextStart,
+            'start'             => $start,
+            'limit'             => $limit,
+            'namesList'         => $namesList,
+            'textSearch'        => $textSearch
+        );
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => 'admin/manageMembers/index.html',
+            'data'             => $templateData
+        );
+
+    }
+
+}
+
+?>
diff --git a/models/admin/manageMembers/manage.php b/models/admin/manageMembers/manage.php
deleted file mode 100644 (file)
index 25dc34a..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-<?php
-
-/**
- * Gaslight Media Members Database
- * Admin List Members
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package  glmMembersDatabase
- * @author   Chuck Scott <cscott@gaslightmedia.com>
- * @license  http://www.gaslightmedia.com Gaslightmedia
- * @version  0.1
- */
-
-// Load Members data abstract
-require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
-
-/*
- * This class performs the work for the default action of the "Members" menu
- * option, which is to display the members dashboard.
- *
- */
-class GlmMembersAdmin_manageMembers_manage extends GlmDataMembers
-{
-
-    /**
-     * WordPress Database Object
-     *
-     * @var $wpdb
-     * @access public
-     */
-    public $wpdb;
-    /**
-     * Plugin Configuration Data
-     *
-     * @var $config
-     * @access public
-     */
-    public $config;
-
-    /*
-     * Constructor
-     *
-     * This contructor sets up this model. At this time that only includes
-     * storing away the WordPress data object.
-     *
-     * @return object Class object
-     *
-     */
-    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 to setup table and fields array
-         *
-         * Since this class is extending GlmDataMembers, it does not need to pass
-         * $wpdb and $config to it in the constructor.
-         */
-        parent::__construct(false, false);
-
-    }
-
-    /*
-     * Perform Model Action
-     *
-     * This method does the work for this model and returns any resulting data
-     *
-     * @return array Status and data array
-     *
-     * 'status'
-     *
-     * True if successfull and false if there was a fatal failure.
-     *
-     * 'menuItemRedirect'
-     *
-     * If not false, provides a menu item the controller should
-     * execute after this one. Normally if this is used, there would also be a
-     * modelRedirect value supplied as well.
-     *
-     * 'modelRedirect'
-     *
-     * If not false, provides an action the controller should execute after
-     * this one.
-     *
-     * '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.
-     *
-     */
-    public function modelAction ($actionData = false)
-    {
-
-        $where              = ' true ';
-        $alphaWhere         = ' true ';
-        $catSearchSelected  = false;
-        $catSelectedString  = "";
-        $mTypeSelected      = '';
-        $catSelected        = '';
-        $catsToUse          = '';
-        $filterPending      = false;
-        $filterArchived     = false;
-        $filterFeatured     = false;
-        $haveFilter         = false;
-        $numbDisplayed      = false;
-        $lastDisplayed      = false;
-        $paging             = true;
-        $prevStart          = false;
-        $nextStart          = false;
-        $start              = 1;
-        $limit              = 20;        // Set to the number of listings per page
-        $namesList          = false;
-        $enable_members     = $this->config['settings']['enable_members'];
-        $textSearch         = false;
-
-        // Save all query parameters
-        if ( isset( $_REQUEST['glm_action'] ) && $_REQUEST['glm_action'] == 'list' ) {
-            $_SESSION['member_saved_search'] = $_REQUEST;
-        } else if ( !isset( $_REQUEST['glm_action'] )
-            && (!isset( $_REQUEST['back_to_search'] ) || !filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN ))
-        ) {
-            unset( $_SESSION['member_saved_search'] );
-        }
-        // Check for back to search flag
-        if ( isset( $_REQUEST['back_to_search'] )
-            && filter_var( $_REQUEST['back_to_search'], FILTER_VALIDATE_BOOLEAN )
-            && isset( $_SESSION['member_saved_search'] )
-        ) {
-            $_REQUEST = $_SESSION['member_saved_search'];
-        }
-        // Check if this is a request to show archived members
-        if (isset($_REQUEST['filterArchived'])) {
-            $where .= " AND access = ".$this->config['access_numb']['Archived'];
-            $filterArchived = true;
-            $haveFilter = true;
-
-        // If not, don't show them
-        } else {
-            $where .= " AND access != ".$this->config['access_numb']['Archived'];
-        }
-
-        // Check for a text search
-        if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search']) != '') {
-
-            // $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
-            $textSearch = addslashes(filter_var($_REQUEST['text_search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES));
-            $where .= " AND T.id in (
-                SELECT DISTINCT(id)
-                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members
-                 WHERE name like '%$textSearch%'
-            )";
-
-        }
-
-        // Get a list of categories for filtering
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
-        $Categories = new GlmDataCategories($this->wpdb, $this->config);
-        $categories = $Categories->getListSortedParentChild(false);
-
-        // If we have categories, add "selected" element default false;
-        if (is_array($categories)) {
-            reset($categories);
-            while (list($k, $v) = each($categories)) {
-                $categories[$k]['selected'] = false;
-            }
-        }
-
-        // Get a list of member_types for filtering
-        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberTypes.php';
-        $MemberTypes = new GlmDataMemberTypes( $this->wpdb, $this->config );
-        $member_types = $MemberTypes->getList();
-
-        // Check if there is a member_type filter
-        if ( isset( $_REQUEST['filterMemberTypes'] ) && $memberTypeFilter = filter_var( $_REQUEST['filterMemberTypes'], FILTER_VALIDATE_INT ) ) {
-            $where .= " AND T.member_type = $memberTypeFilter ";
-            $mTypeSelected = $memberTypeFilter;
-        }
-
-        // Check if there is a category filter (multi-select)
-        if (isset($_REQUEST['categorySearch']) && $_REQUEST['categorySearch'] > 0) {
-            $catsToUse = explode(',',$_REQUEST['categorySearch']);
-        }
-        if (isset($_REQUEST['filterCategories']) && count($_REQUEST['filterCategories']) > 0) {
-            $catsToUse = $_REQUEST['filterCategories'];
-        }
-
-        if ($catsToUse && $catsToUse !== '') {
-            $cats = '';
-            $catsSep = '';
-
-            // For each selected category
-            foreach($catsToUse as $c) {
-                $cats .= $catsSep.$c;
-                $catsSep = ',';
-                $categories[$c]['selected'] = true;
-            }
-
-            $where .= " AND T.id in (
-                    SELECT DISTINCT(I.member)
-                      FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I,
-                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info M,
-                           ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C
-                     WHERE I.id = M.member_info
-                       AND I.status != " . $this->config['status_numb']['Archived'] ."
-                       AND (
-                           M.category in ($cats)
-                           OR (C.parent in ($cats) AND M.category = C.id)
-                           )
-            )";
-            $catSelectedString = $cats;
-        }
-
-        // Check for "Pending Only
-        if (isset($_REQUEST['filterPending'])) {
-
-            // Refine search only to members with pending Info data
-            $where .= " AND (
-                SELECT COUNT(id)
-                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I
-                 WHERE I.status = ".$this->config['status_numb']['Pending']."
-                   AND I.member = T.id
-            )";
-
-            $filterPending = true;
-            $haveFilter = true;
-        }
-
-        // Check for "Featured Only
-        if (isset($_REQUEST['filterFeatured'])) {
-
-            // Refine search only to members with pending Info data
-            $where .= " AND (
-                SELECT COUNT(id)
-                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members I
-                 WHERE I.featured = 1
-                   AND I.id = T.id
-
-            )";
-            $filterFeatured = true;
-            $haveFilter = true;
-        }
-
-        // If doing alpha list
-        if (isset($_REQUEST['alpha'])) {
-            $actionData['request']['alpha'] = $_REQUEST['alpha'];
-        }
-
-        $alphaList = false;
-        $alphaWhere = '';
-
-        $alphaSelected = false;
-
-        // If user clicked a page request then we need to check the savedAlpha value
-        if (isset($_REQUEST['savedAlpha']) && isset($_REQUEST['pageSelect'])) {
-            $actionData['request']['alpha'] = $_REQUEST['savedAlpha'];
-        }
-
-        if ($actionData['request']['alpha'] && strlen($actionData['request']['alpha']) == 1) {
-            $alphaSelected = strtoupper($actionData['request']['alpha']);
-            $alphaWhere .= " AND T.name LIKE '$alphaSelected%'";
-        }
-
-        // Get full list for all other filters, but not filtered by alpha (that would be silly)
-        $alphaList = $this->getAlphaList(' AND '.$where, $alphaSelected);
-
-        $whereParts = apply_filters('glm-member-db-admin-search-query', $where, 'glm-member-db');
-        if ( is_array( $whereParts ) && count( $whereParts ) > 0 ) {
-            $where .= ' AND '.implode(" AND ", $whereParts);
-            $whereSep = ' AND ';
-        }
-
-        // Get count of members listed
-        $memberCount = $this->getStats($where);
-
-        // If the number of members is less than a page, don't do paging
-        if ($memberCount <= $limit) {
-            $paging = false;
-        }
-
-        // Get full list of names matching this where clause for search box
-        $namesList = $this->getIdName($where);
-
-        // Check if we're doing paging
-        if (isset($_REQUEST['pageSelect'])) {
-
-            // If request is for Next
-            if ($_REQUEST['pageSelect'][0] == 'N') {
-                $newStart = $_REQUEST['nextStart'] - 0;
-
-            // Otherwise it must be Previous
-            } else {
-                $newStart = $_REQUEST['prevStart'] - 0;
-            }
-
-            if ($newStart > 0) {
-                $start = $newStart;
-            }
-        }
-
-        // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
-
-        // Get stats for number of members found matching current selection criteria (includes alpha selection)
-        $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
-
-        // Get a current list of members
-        $listResult = $this->getSimpleMembersList($where.$alphaWhere, 'name', true, 'id', $start, $limit);
-
-        // Get paging results
-        $numbDisplayed = $listResult['returned'];
-        $lastDisplayed = $listResult['last'];
-        if ($start == 1) {
-            $prevStart = false;
-        } else {
-            $prevStart = $start - $limit;
-            if ($start < 1) {
-                $start = 1;
-            }
-        }
-        if ($listResult['returned'] == $limit) {
-            $nextStart = $start + $limit;
-        }
-
-        // since we're doing paging, we have to break out just the member data
-        $list = $listResult['list'];
-        unset($listResult);
-
-        // If we have list entries - even if it's an empty list
-        $success = true;
-        $haveMembers = false;
-        if ($list !== false) {
-
-            $success = true;
-
-            // If we have any entries
-            if (count($list) > 0) {
-                $haveMembers = true;
-            }
-        }
-
-        // Determine if current user can add, edit, delete member data
-//        $canEdit = current_user_can('glm_members_edit');
-
-        // Add a url for each member
-        if ( isset( $list) && is_array( $list ) ) {
-            foreach ($list as $member) {
-                $list[$member['id']]['member_slug'] = sanitize_title($member['name']);
-            }
-        }
-
-        // Create current month/date string to pre-populate the Month/Year field for
-        $monthYear = date('F Y');
-
-        // Update the textSearch for output into the form.
-        $textSearch = str_replace("\'", "'", $textSearch );
-        $textSearch = str_replace('\\"', '&quot;', $textSearch );
-        $textSearch = str_replace('\\', '', $textSearch );
-
-        // Compile template data
-        $templateData = array(
-            'monthYear'         => $monthYear,
-            'enable_members'    => $enable_members,
-            'haveMembers'       => $haveMembers,
-            'members'           => $list,
-            'memberCount'       => $memberCount,
-            'categories'        => $categories,
-            'member_types'      => $member_types,
-            'haveFilter'        => $haveFilter,
-            'filterArchived'    => $filterArchived,
-            'filterFeatured'    => $filterFeatured,
-            'filterPending'     => $filterPending,
-            'catSelected'       => $catSelected,
-            'catSearchSelected' => $catSelectedString,
-            'mTypeSelected'     => $mTypeSelected,
-            'alphaList'         => $alphaList,
-            'alphaSelected'     => $alphaSelected,
-            'numbDisplayed'     => $numbDisplayed,
-            'lastDisplayed'     => $lastDisplayed,
-            'paging'            => $paging,
-            'prevStart'         => $prevStart,
-            'nextStart'         => $nextStart,
-            'start'             => $start,
-            'limit'             => $limit,
-            'namesList'         => $namesList,
-            'textSearch'        => $textSearch
-        );
-
-        // Return status, suggested view, and data to controller
-        return array(
-            'status'           => $success,
-            'menuItemRedirect' => false,
-            'modelRedirect'    => false,
-            'view'             => 'admin/manageMembers/manage.html',
-            'data'             => $templateData
-        );
-
-    }
-
-}
-
-?>
diff --git a/models/admin/manageMembers/search.php b/models/admin/manageMembers/search.php
new file mode 100644 (file)
index 0000000..69de6bb
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+
+
+    // Set default values for using getList() later, where the custom set of fields below will be used.
+    $where = '';
+    $order = '';
+    $fieldVals = true;
+    $idField = 'id';
+    $start = false;
+    $limit = false;
+
+
+    /*
+    * For list components: pass ref_type and ref_dest as part of the 'fields' string if you want to
+    * make these options part of the href of each <li> link
+    * 
+    */
+
+    $glmMemberSearch = [
+        'title'         => 'Members',
+        'listButtons' => [
+            [
+                'id'            => 'add-member',
+                'content'       => 'Add',
+                'classes'       => '',
+                'styles'        => '',
+                'data'          => ''
+            ],
+            [
+                'id'            => 'export-button',
+                'content'       => 'Export',
+                'url'           => '#',
+                'classes'       => 'btn-small waves-effect waves-light btn modal-trigger',
+                'styles'        => '',
+                'data'          => 'membersExportModal'
+            ],
+        ],
+        'components'    => [
+            [
+                'id'        => 'membersExportModal',
+                'template'  => 'modal',
+                'order'     => 99,
+                'form'      => ''//$this->controller('export', 'index', false, true)
+            ],
+            [
+                'id'        => 'textSearch',
+                'order'     => 2,
+                'template'  => 'textSearch',
+                'entityID'  => 'id',
+                'fields'    => "id, name",
+                'where'     => 'name',
+            ],
+            [
+                'id'        => 'dateSearch', 
+                'order'     => 3,
+                'fromDate'  => 'fromDate',
+                'toDate'    => 'toDate',
+                'template'  => 'dateSearch',
+                'entityID'  => 'members',
+                'defaultFromDate'   => date('m/d/Y'),
+            ],
+            [
+                'id'                => 'categorySearch', 
+                'order'             => 4,
+                'categories'        => ['cat 1', 'cat 2', 'cat 3'],
+                'template'          => 'category',
+                'entityID'          => 'members',
+                'defaultFromDate'   => date('m/d/Y'),
+            ],
+            [
+                'id'        => 'memberTypeSearch', 
+                'order'     => 5,
+                'template'  => 'dropdown',
+                'entityID'  => 'members',
+                'defaultFromDate'   => date('m/d/Y'),
+            ],
+            [
+                'id'        => 'archiveSearch', 
+                'order'     => 6,
+                'template'  => 'checkbox',
+                'entityID'  => 'members',
+                'defaultFromDate'   => date('m/d/Y'),
+            ],
+            [
+                'id'        => 'featuredSearch', 
+                'order'     => 7,
+                'template'  => 'checkbox',
+                'entityID'  => 'event',
+                'defaultFromDate'   => date('m/d/Y'),
+            ],
+        ]
+    ];
index 1183b9e..f53d57f 100644 (file)
@@ -574,141 +574,3 @@ add_filter(
     13,
     1
 );
-add_filter(
-    GLM_MEMBERS_PLUGIN_SLUG .'-dashboard-search',
-    function ( $member = null ) {
-        $membersIndexPage = GLM_MEMBERS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-members';
-        $memberIndexPage = GLM_MEMBERS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member';
-        $membersTable = GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info";
-        $membersTextTable = GLM_MEMBERS_PLUGIN_DB_PREFIX . "members";
-        $membersEditPage = GLM_MEMBERS_PLUGIN_ADMIN_MENU_URL_BASE.'member&glm_action=memberInfo';
-        $membersSettingsPage = GLM_MEMBERS_PLUGIN_ADMIN_URL.'?page=glm-members-admin-menu-settings&settingsPage=members';
-        $membersRefLink      = GLM_MEMBERS_PLUGIN_ADMIN_URL . '?page=glm-members-admin-menu-member&glm_action=index';
-
-        $MemberInfo = new GlmDataMemberInfo($this->wpdb, $this->config);
-
-        // Set default values for using getList() later, where the custom set of fields below will be used.
-        $where = '';
-        $order = '';
-        $fieldVals = true;
-        $idField = 'id';
-        $start = false;
-        $limit = false;
-    
-        // Save the current fields array and make a copy. Will be restored before the return.
-        $fSave = $MemberInfo->fields;
-
-        // echo "<br><pre>fsave: " . var_dump($fSave) . "</pre><br>";
-    
-        // Remove what we don't want from the copy and get the list
-        $MemberInfo->fields = array(
-            'id'            => $fSave['id'],
-            'reference_name'=> $fSave['reference_name'],
-            'status'        => $fSave['status'],
-            'member_pointer'=> $fSave['member_pointer'],
-            'member'        => $fSave['member'],
-            //'ref_type'      => 'ref_type', // membersInfo has no ref_type field yet
-        );
-
-        // echo "<br><pre>MemberInfo: " . var_dump($MemberInfo->fields) . "</pre><br>";
-
-        // $widgetResult = $MemberInfo->getList('status='.$MemberInfo->config['status_numb']['Pending'], $order, $fieldVals, $idField, $start, $limit);
-
-        // echo "<br><pre>Widgetresult: " . var_dump($widgetResult) . "</pre><br>";
-
-        /*
-        * For list components: pass ref_type and ref_dest as part of the 'fields' string if you want to
-        * make these options part of the href of each <li> link
-        * 
-        */
-
-        $content = [
-            'title'         => 'Members',
-            'listButtons' => [
-                [
-                    'id'            => 'add-member',
-                    'content'       => 'Add',
-                    'url'           => $memberIndexPage . "&glm_action=memberEdit&option=add",
-                    'classes'       => '',
-                    'styles'        => '',
-                    'data'          => ''
-                ],
-                [
-                    'id'            => 'export-button',
-                    'content'       => 'Export',
-                    'url'           => '#',
-                    'classes'       => 'btn-small waves-effect waves-light btn modal-trigger',
-                    'styles'        => '',
-                    'data'          => 'membersExportModal'
-                ],
-            ],
-            'components'    => [
-                [
-                    'id'        => 'membersExportModal',
-                    'template'  => 'modal',
-                    'order'     => 99,
-                    'form'      => ''//$this->controller('export', 'index', false, true)
-                ],
-                [
-                    'id'        => 'textSearch',
-                    'order'     => 2,
-                    'template'  => 'textSearch',
-                    'entityID'  => 'id',
-                    'table'     => $membersTextTable,
-                    'fields'    => "id, name",
-                    'where'     => 'name',
-                    'resultUrl' => $memberIndexPage . "&glm_action=index&member=",
-                ],
-                [
-                    'id'        => 'dateSearch', 
-                    'order'     => 3,
-                    'fromDate'  => 'fromDate',
-                    'toDate'    => 'toDate',
-                    'template'  => 'dateSearch',
-                    'entityID'  => 'members',
-                    'defaultFromDate'   => date('m/d/Y'),
-                    'resultUrl' => $eventsListPage.'&event=',
-                ],
-                [
-                    'id'                => 'categorySearch', 
-                    'order'             => 4,
-                    'categories'        => ['cat 1', 'cat 2', 'cat 3'],
-                    'template'          => 'category',
-                    'entityID'          => 'members',
-                    'defaultFromDate'   => date('m/d/Y'),
-                ],
-                [
-                    'id'        => 'memberTypeSearch', 
-                    'order'     => 5,
-                    'template'  => 'dropdown',
-                    'entityID'  => 'members',
-                    'defaultFromDate'   => date('m/d/Y'),
-                    'resultUrl' => $eventsListPage.'&event=',
-                ],
-                [
-                    'id'        => 'archiveSearch', 
-                    'order'     => 6,
-                    'template'  => 'checkbox',
-                    'entityID'  => 'members',
-                    'defaultFromDate'   => date('m/d/Y'),
-                    'resultUrl' => $eventsListPage.'&event=',
-                ],
-                [
-                    'id'        => 'featuredSearch', 
-                    'order'     => 7,
-                    'template'  => 'checkbox',
-                    'entityID'  => 'event',
-                    'defaultFromDate'   => date('m/d/Y'),
-                    'resultUrl' => $eventsListPage.'&event=',
-                ],
-            ]
-        ];
-
-        // Restore the fields list
-        $MemberInfo->fields = $fSave;
-
-        return $content;
-    },
-    13,
-    1
-);
\ No newline at end of file
index a0ca7e4..7c75ac9 100644 (file)
@@ -86,8 +86,8 @@ if (current_user_can('glm_members_members')) {
             $this->config['terms']['term_admin_menu_members'].'New Members',
             'Manage Members',
             'glm_members_member',
-            'glm-members-admin-menu-members-manage',
-            function() {$this->controller('manageMembers', 'manage');}
+            'glm-members-admin-menu-members-index',
+            function() {$this->controller('manageMembers', 'index');}
         );
 
         // Add a submenu for the "Member" section
index 5df37f1..a9af967 100644 (file)
@@ -49,7 +49,7 @@ $glmMembersValidActions = array(
             'adminSearch'           => 'glm-member-db',
         ),
         'manageMembers' => array(
-            'manage' => 'glm-member-db'
+            'index' => 'glm-member-db'
         ),
         'dashboard' => array(
             'index'   => 'glm-member-db',
diff --git a/views/admin/manageMembers/adminSearch/searchHeader.html b/views/admin/manageMembers/adminSearch/searchHeader.html
new file mode 100644 (file)
index 0000000..7873714
--- /dev/null
@@ -0,0 +1,3 @@
+<div id="glm-admin-search-header">
+    Search Fields pulled from file
+</div>
\ No newline at end of file
diff --git a/views/admin/manageMembers/index.html b/views/admin/manageMembers/index.html
new file mode 100644 (file)
index 0000000..7dd8949
--- /dev/null
@@ -0,0 +1,68 @@
+
+<div class="glm-dashboard-background">
+    {include file='admin/manageMembers/adminSearch/searchHeader.html'}
+    <div id="glm-admin-member-list" class="row admin-member-list">
+        <div id="glm-admin-search-overlay"> <span>Loading ...</span></div>
+    </div>
+</div>
+<script>
+    jQuery(function($){
+            let searchResults   = {};
+            let imageUrl        = `{$glmPluginMediaUrl}/images`
+            let data            = {
+                action      : 'glm_members_admin_ajax',
+                glm_action  : 'adminSearch',
+                // table       : textSearchData.table,
+                // fields      : textSearchData.fields,
+                // where       : textSearchData.where
+            }
+            
+            $.ajax({
+                dataType: "json",
+                type : 'POST',
+                url: '{$ajaxUrl}',
+                data: data,
+                complete: $("#glm-admin-search-overlay").fadeOut('slow'),
+                success: function(data) {
+                    data.searchData.forEach( function(value, index){
+                        $("<div />", {
+                            text    : value,
+                            class   : "glm-list-result"
+                        }).appendTo( $("#glm-admin-member-list"));
+                    })
+                }
+            });
+        });
+</script>
+<style>
+    .glm-dashboard-background{
+        background-color: #E9EDF5;
+        width: 100%;
+        height: 100vh;
+        padding: 15px;
+    }
+    #glm-admin-member-list{
+        position: relative;
+        height: 100%;
+        padding: 15px 0;
+    }
+    .glm-list-result{
+        background-color: #FFFFFF;
+        padding: 10px;
+        border-bottom: 1px solid #DEE2E2;
+    }
+    .glm-list-result:nth-child(odd){
+        background: #F9FCFD;
+    }
+    #glm-admin-search-overlay{
+        position: absolute;
+        width: 100%;
+        height: 100%;
+        left: 0;
+        top: 0;
+        background: red;
+    }
+    #wpcontent{
+        padding-left: 0; 
+    }
+</style>
\ No newline at end of file
diff --git a/views/admin/manageMembers/manage.html b/views/admin/manageMembers/manage.html
deleted file mode 100644 (file)
index bdb1890..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<style>
-    .glm-dashboard-background{
-        background-color: #E9EDF5;
-        width: 100%;
-        height: 100vh;
-    }
-    #glm-admin-member-list{
-        position: relative;
-        height: 100%;
-        padding: 15px 0;
-    }
-    .glm-list-result{
-        background-color: #FFFFFF;
-        padding: 10px;
-        border-bottom: 1px solid #DEE2E2;
-    }
-    .glm-list-result:nth-child(odd){
-        background: #F9FCFD;
-    }
-    #glm-admin-search-overlay{
-        position: absolute;
-        width: 100%;
-        height: 100%;
-        left: 0;
-        top: 0;
-        background: red;
-    }
-</style>
-<div class="glm-dashboard-background">
-    <div id="glm-admin-search">
-        Search Fields
-    </div>
-    <div id="glm-admin-member-list" class="row admin-member-list">
-        <div id="glm-admin-search-overlay"> <span>Loading ...</span></div>
-    </div>
-</div>
-<script>
-    jQuery(function($){
-            let searchResults   = {};
-            let imageUrl        = `{$glmPluginMediaUrl}/images`
-            let data = {
-                action      : 'glm_members_admin_ajax',
-                glm_action  : 'adminSearch',
-                // table       : textSearchData.table,
-                // fields      : textSearchData.fields,
-                // where       : textSearchData.where
-            }
-            
-            $.ajax({
-                dataType: "json",
-                type : 'POST',
-                url: '{$ajaxUrl}',
-                data: data,
-                complete: $("#glm-admin-search-overlay").fadeOut('slow'),
-                success: function(data) {
-                    data.searchData.forEach( function(value, index){
-                        $("<div />", {
-                            text    : value,
-                            class   : "glm-list-result"
-                        }).appendTo( $("#glm-admin-member-list"));
-                    })
-                }
-            });
-        });
-</script>
\ No newline at end of file