From f1a43013914dbbbca32a4d8f493be0716ed7124c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 17 Sep 2018 13:49:04 -0400 Subject: [PATCH] Adding admin search for staff Add building search. Add department search. Add name search. Searching both first and last name. --- models/admin/staff/index.php | 113 ++++++++++++++++++++---- views/admin/staff/header.html | 2 +- views/admin/staff/index.html | 112 ++++++++++++++++------- views/admin/staff/settingSubHeader.html | 4 +- views/admin/staff/settings.html | 4 +- 5 files changed, 180 insertions(+), 55 deletions(-) diff --git a/models/admin/staff/index.php b/models/admin/staff/index.php index a1dd9ae..03507ac 100644 --- a/models/admin/staff/index.php +++ b/models/admin/staff/index.php @@ -15,6 +15,8 @@ // Load Members data abstract require_once GLM_MEMBERS_STAFF_PLUGIN_CLASS_PATH.'/data/dataStaff.php'; +require_once GLM_MEMBERS_STAFF_PLUGIN_CLASS_PATH.'/data/dataBuildings.php'; +require_once GLM_MEMBERS_STAFF_PLUGIN_CLASS_PATH.'/data/dataDepartments.php'; /* * This class performs the work for the default action of the "Members" menu @@ -98,15 +100,25 @@ class GlmMembersAdmin_staff_index extends GlmDataStaff */ public function modelAction ($actionData = false) { - $success = true; - $view = 'index'; - $haveStaff = false; - $option = 'list'; - $total_staff = false; - $insertError = false; - $insertGood = false; - $updateError = false; - $updateGood = false; + $where = ' true '; + $alphaWhere = ' true '; + $success = true; + $view = 'index'; + $haveStaff = false; + $option = 'list'; + $total_staff = false; + $insertError = false; + $insertGood = false; + $updateError = false; + $updateGood = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; + $alphaList = false; + $alphaWhere = ''; + $alphaSelected = false; // Get any provided option if (isset($_REQUEST['option'])) { @@ -167,8 +179,62 @@ class GlmMembersAdmin_staff_index extends GlmDataStaff case 'list': default: + $Buildings = new GlmDataBuildings( $this->wpdb, $this->config ); + $buildings = $Buildings->getList( '', 'name' ); + + $Departments = new GlmDataDepartments( $this->wpdb, $this->config ); + $departments = $Departments->getList( '', 'name' ); + + if ( isset( $_REQUEST['filter_name'] ) && trim( $_REQUEST['filter_name'] ) != '' ) { + $name_search = addslashes(filter_var($_REQUEST['filter_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); + $where .= " AND (T.fname like '%$name_search%' OR T.lname like '%$name_search%' )"; + } + + if ( isset( $_REQUEST['filter_departments'] ) && $filter_departments = filter_var( $_REQUEST['filter_departments'], FILTER_VALIDATE_INT ) ) { + $where .= " AND T.department = $filter_departments"; + } + + if ( isset( $_REQUEST['filter_buildings'] ) && $filter_building = filter_var( $_REQUEST['filter_buildings'], FILTER_VALIDATE_INT ) ) { + $where .= " AND T.building = $filter_building"; + } + + // 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; + } + } + // Get staff list - $staff = $this->getList(); + $staffResult = $this->getList( $where, 'T.lname,T.fname', true, 'id', $start, $limit ); + + // Get paging results + $numbDisplayed = $staffResult['returned']; + $lastDisplayed = $staffResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($staffResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // Since we're doing paging, we have to breaok out just the staff data + $staff = $staffResult['list']; // Get stats on the current list $total_staff = $this->getStats(); @@ -182,17 +248,26 @@ class GlmMembersAdmin_staff_index extends GlmDataStaff } - - // Compile template data $templateData = array( - 'staff' => $staff, - 'total_staff' => $total_staff, - 'haveStaff' => $haveStaff, - 'insertError' => $insertError, - 'insertGood' => $insertGood, - 'updateError' => $updateError, - 'updateGood' => $updateGood, + 'staff' => $staff, + 'total_staff' => $total_staff, + 'haveStaff' => $haveStaff, + 'insertError' => $insertError, + 'insertGood' => $insertGood, + 'updateError' => $updateError, + 'updateGood' => $updateGood, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'alphaList' => $alphaList, + 'alphaSelected' => $alphaSelected, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'departments' => $departments, + 'buildings' => $buildings, ); // Return status, suggested view, and data to controller diff --git a/views/admin/staff/header.html b/views/admin/staff/header.html index 55d5b3d..ff762b9 100644 --- a/views/admin/staff/header.html +++ b/views/admin/staff/header.html @@ -3,7 +3,7 @@ diff --git a/views/admin/staff/index.html b/views/admin/staff/index.html index 220b60e..4e11c68 100644 --- a/views/admin/staff/index.html +++ b/views/admin/staff/index.html @@ -2,40 +2,88 @@

Staff List

- - - - - - - - - - - - - - - {if $haveStaff} - {foreach $staff as $st} - - - - - - - - - - {/foreach} + + + + + + + + +
+ + + + + + + +
+ +
+ +

Total found: {$total_staff}  

+ + {if $paging} + + + {/if} + +
EditFirst NameLast NameExtensionBuildingDepartmentDelete
Edit{$st.fname}{$st.lname}{$st.extension}{$st.building}{$st.department} - Delete -
+ + + + + + + + + + + + + + {if $haveStaff} + {foreach $staff as $st} + + + + + + + + + + {/foreach} + {/if} + +
EditFirst NameLast NameExtensionBuildingDepartmentDelete
Edit{$st.fname}{$st.lname}{$st.extension}{$st.building}{$st.department} + Delete +
+ + {if $paging} + + {/if} - +