// 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
*/
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'])) {
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();
}
-
-
// 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
<h1>Staff List</h1>
-<table class="wp-list-table striped glm-admin-table-single" style="max-width: 800px;">
-
- <thead>
- <tr>
- <th>Edit</th>
- <th>First Name</th>
- <th>Last Name</th>
- <th>Extension</th>
- <th>Building</th>
- <th>Department</th>
- <th>Delete</th>
- </tr>
- </thead>
-
- {if $haveStaff}
- {foreach $staff as $st}
- <tr {if $st@iteration is even by 2}class="alternate"{/if}>
- <td><a href="{$thisUrl}?page={$thisPage}&option=edit&staff={$st.id}">Edit</a></td>
- <td>{$st.fname}</td>
- <td>{$st.lname}</td>
- <td>{$st.extension}</td>
- <td>{$st.building}</td>
- <td>{$st.department}</td>
- <td>
- <a
- onclick="return confirm('Are you sure you want to delete this staff?')"
- href="{$thisUrl}?page={$thisPage}&option=delete&staff={$st.id}"
- class="delete-staff button button-secondary glm-button-small glm-right">Delete</a>
- </td>
- </tr>
- {/foreach}
+<form id="search_form" action="{$thisUrl}">
+ <input type="hidden" name="page" value="{$thisPage}" />
+ <input type="hidden" name="glm_action" value="{$thisAction}" />
+ <input type="hidden" name="prevStart" value="{$prevStart}">
+ <input type="hidden" name="nextStart" value="{$nextStart}">
+ <input type="hidden" name="limit" value="{$limit}">
+ <input type="hidden" name="savedAlpha" value="{$alphaSelected}">
+
+ <div >
+ <input name="filter_name" value="{if isset($smarty.request.filter_name)}{$smarty.request.filter_name}{/if}" />
+
+ <select name="filter_departments">
+ <option value="">Departments</option>
+ {if $departments}
+ {foreach $departments as $depart}
+ <option value="{$depart.id}"{if isset($smarty.request.filter_departments) && $smarty.request.filter_departments == $depart.id}selected{/if}>{$depart.name}</option>
+ {/foreach}
+ {/if}
+ </select>
+
+ <select name="filter_buildings">
+ <option value="">Buildings</option>
+ {if $buildings}
+ {foreach $buildings as $build}
+ <option value="{$build.id}"{if isset($smarty.request.filter_buildings) && $smarty.request.filter_buildings == $build.id}selected{/if}>{$build.name}</option>
+ {/foreach}
+ {/if}
+ </select>
+
+ <input class="button" type="submit" value="Search" />
+ </div>
+
+ <br>
+
+ <p><b>Total found:</b> {$total_staff} </p>
+
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+ {/if}
+
+ <table class="wp-list-table widefat fixed posts glm-admin-table" style="max-width: 900px;">
+
+ <thead>
+ <tr>
+ <th width="50">Edit</th>
+ <th width="150">First Name</th>
+ <th width="150">Last Name</th>
+ <th width="100">Extension</th>
+ <th width="200">Building</th>
+ <th width="200">Department</th>
+ <th width="50">Delete</th>
+ </tr>
+ </thead>
+
+ {if $haveStaff}
+ {foreach $staff as $st}
+ <tr {if $st@iteration is even by 2}class="alternate"{/if}>
+ <td><a href="{$thisUrl}?page={$thisPage}&option=edit&staff={$st.id}">Edit</a></td>
+ <td>{$st.fname}</td>
+ <td>{$st.lname}</td>
+ <td>{$st.extension}</td>
+ <td>{$st.building}</td>
+ <td>{$st.department}</td>
+ <td>
+ <a
+ onclick="return confirm('Are you sure you want to delete this staff?')"
+ href="{$thisUrl}?page={$thisPage}&option=delete&staff={$st.id}"
+ class="delete-staff button button-secondary glm-button-small glm-right">Delete</a>
+ </td>
+ </tr>
+ {/foreach}
+ {/if}
+
+ </table>
+
+ {if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} {$terms.term_member_plur_cap}" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
{/if}
-</table>
+</form>
<script>
jQuery(document).ready(function($){