Finishing up admin functions for the staff directory.
Add edit delete working for staff, departments and buildings.
'use' => 'a'
),
+ // Email
+ 'email' => array (
+ 'field' => 'email',
+ 'type' => 'text',
+ 'required' => true,
+ 'use' => 'a'
+ ),
+
// Last Name
'extension' => array (
'field' => 'extension',
*/
public function modelAction ($actionData = false)
{
- $data = array();
$success = true;
$view = 'index';
$haveStaff = false;
break;
case 'delete':
- $staff = $this->deleteEntry($this->staffID);
- break;
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ $staff = $this->deleteEntry( $this->staffID, true );
case 'list':
default:
// Compile template data
$templateData = array(
- 'data' => $data,
'staff' => $staff,
'total_staff' => $total_staff,
'haveStaff' => $haveStaff,
*/
public function modelAction ($actionData = false)
{
- $data = array();
- $success = true;
- $view = 'index';
- $haveStaff = false;
- $option = 'list';
- $total_staff = false;
- $insertError = false;
- $insertGood = false;
- $updateError = false;
- $updateGood = false;
+ $success = true;
+ $view = 'settings';
+ $list = false;
+ $haveList = false;
+ $option = 'buildings';
+ $total_staff = false;
+ $insertError = false;
+ $insertGood = false;
+ $updateError = false;
+ $updateGood = false;
+ $setting_title = 'Buildings';
+
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
// Get any provided option
if (isset($_REQUEST['option'])) {
// Do selected option
switch ($option) {
- case 'add':
- $staff = $this->newEntry();
- $view = 'edit';
+ case 'addDepartment':
+ $Departments = new GlmDataDepartments( $this->wpdb, $this->config );
+ $Departments->insertEntry();
+ $option = 'departments';
break;
- case 'insert':
- $staffInfo = $this->insertEntry();
- if ( $staffInfo['status'] == true ) {
- $this->staffID = $staffInfo['fieldData']['id'];
- $insertGood = true;
- $staff = $this->editEntry( $this->staffID );
- } else {
- $insertError = true;
+ case 'updateDepartment':
+ // Get ID if supplied
+ if (isset($_REQUEST['id'])) {
+
+ // Make sure it's numeric
+ $department_id = ($_REQUEST['id'] - 0);
+
+ if ($department_id <= 0) {
+ $department_id = false;
+ }
+
+ }
+ if ( $department_id ) {
+ $Departments = new GlmDataDepartments( $this->wpdb, $this->config );
+ $Departments->updateEntry( $department_id );
}
- $view = 'edit';
+ $option = 'departments';
break;
- case 'edit':
- $staff = $this->editEntry($this->staffID);
- $view = 'edit';
+ case 'deleteDepartment':
+ if (isset($_REQUEST['id'])) {
+
+ // Make sure it's numeric
+ $department_id = ($_REQUEST['id'] - 0);
+
+ if ($department_id <= 0) {
+ $department_id = false;
+ }
+
+ }
+ if ( $department_id ) {
+ $Departments = new GlmDataDepartments( $this->wpdb, $this->config );
+ $Departments->deleteEntry( $department_id, true );
+ }
+ $option = 'departments';
break;
- case 'update':
- $staffInfo = $this->updateEntry($this->staffID);
- if ( $staffInfo['status'] == true ) {
- $staff = $this->editEntry( $this->staffID );
- $updateGood = true;
- } else {
- $updateError = true;
+ case 'departments':
+ $setting_title = 'Departments';
+ $Departments = new GlmDataDepartments( $this->wpdb, $this->config );
+ $list = $Departments->getList();
+
+ if ( $list ) {
+ $haveList = true;
}
- $view = 'edit';
+
break;
- case 'delete':
- $staff = $this->deleteEntry($this->staffID);
+ case 'addBuilding':
+ $Buildings = new GlmDataBuildings( $this->wpdb, $this->config );
+ $Buildings->insertEntry();
+ $option = 'buildings';
break;
- case 'list':
- default:
- // Get staff list
- // $staff = $this->getList();
+ case 'updateBuilding':
+ // Get ID if supplied
+ if (isset($_REQUEST['id'])) {
+
+ // Make sure it's numeric
+ $building_id = ($_REQUEST['id'] - 0);
- // Get stats on the current list
- // $total_staff = $this->getStats();
+ if ($building_id <= 0) {
+ $building_id = false;
+ }
- if ( $staff ) {
- $haveStaff = true;
}
+ if ( $building_id ) {
+ $Buildings = new GlmDataBuildings( $this->wpdb, $this->config );
+ $Buildings->updateEntry( $building_id );
+ }
+ $option = 'buildings';
+ break;
+
+ case 'deleteBuilding':
+ // Get ID if supplied
+ if (isset($_REQUEST['id'])) {
+
+ // Make sure it's numeric
+ $building_id = ($_REQUEST['id'] - 0);
+
+ if ($building_id <= 0) {
+ $building_id = false;
+ }
+
+ }
+ if ( $building_id ) {
+ $Buildings = new GlmDataBuildings( $this->wpdb, $this->config );
+ $Buildings->deleteEntry( $building_id, true );
+ }
+ $option = 'buildings';
+ break;
+
+ case 'buildings':
+ default:
+ $setting_title = 'Buildings';
break;
}
+ switch ( $option ) {
+ case 'buildings':
+ $Buildings = new GlmDataBuildings( $this->wpdb, $this->config );
+ $list = $Buildings->getList( '', 'name' );
+ break;
+ case 'departments':
+ $Departments = new GlmDataDepartments( $this->wpdb, $this->config );
+ $list = $Departments->getList( '', 'name' );
+ break;
+ }
+ if ( $list ) {
+ $haveList = true;
+ }
+ // echo '<pre>$view: ' . print_r( $view, true ) . '</pre>';
// Compile template data
$templateData = array(
- 'data' => $data,
- 'staff' => $staff,
- 'total_staff' => $total_staff,
- 'haveStaff' => $haveStaff,
- 'insertError' => $insertError,
- 'insertGood' => $insertGood,
- 'updateError' => $updateError,
- 'updateGood' => $updateGood,
+ 'setting_title' => $setting_title,
+ 'list' => $list,
+ 'total_staff' => $total_staff,
+ 'haveList' => $haveList,
+ 'insertError' => $insertError,
+ 'insertGood' => $insertGood,
+ 'updateError' => $updateError,
+ 'updateGood' => $updateGood,
+ 'option' => $option,
);
// Return status, suggested view, and data to controller
'status' => $success,
'menuItemRedirect' => false,
'modelRedirect' => false,
- 'view' => 'admin/settings/' . $view . '.html',
+ 'view' => 'admin/staff/' . $view . '.html',
'data' => $templateData
);
id INT NOT NULL AUTO_INCREMENT,
old_id INT, -- Ref to import id
updated DATETIME, -- Updated timestamp
- fname TINYTEXT NOT NULL, -- First Name
- lname TINYTEXT NOT NULL, -- Last Name
- extension TINYTEXT, -- Phone extension
+ fname TINYTEXT NOT NULL, -- First Name
+ lname TINYTEXT NOT NULL, -- Last Name
+ email TINYTEXT NOT NULL, -- Email Address
+ extension TINYTEXT, -- Phone extension
building INT NOT NULL, -- Reference to Buildings table
department INT NOT NULL, -- Reference to Departments table
PRIMARY KEY (id),
INDEX(lname(20)),
INDEX(fname(20)),
+ INDEX(email(20)),
INDEX(building),
INDEX(department)
);
+++ /dev/null
-{include file="admin/staff/header.html"}
-
-<h1>settings</h1>
-
-{include file="admin/staff/footer.html"}
{if $updateError}<span class="glm-error glm-flash-updated glm-right">Update Error</span>{/if}
{if $insertError}<span class="glm-error glm-flash-updated glm-right">Insert Error</span>{/if}
+<h2>Staff Details</h2>
+
<form action="{$thisUrl}?page={$thisPage}" method="post">
<input type="hidden" name="page" value="{$thisPage}" />
</td>
</tr>
+ <tr>
+ <th {if $staff.fieldRequired.email} class="glm-required"}{/if}>Email</th>
+ <td {if $staff.fieldFail.email}class="glm-form-bad-input" data-tabid="glm-email"{/if}>
+ <input type="text" name="email" value="{$staff.fieldData.email}" class="glm-form-text-input-short">
+ {if $staff.fieldFail.email}<p>{$staff.fieldFail.email}</p>{/if}<br>
+ </td>
+ </tr>
+
<tr>
<th {if $staff.fieldRequired.extension} class="glm-required"}{/if}>Extension</th>
<td {if $staff.fieldFail.extension}class="glm-form-bad-input" data-tabid="glm-Id for bad input"{/if}>
{include file='admin/staff/header.html'}
-<h1>Test</h1>
+<h1>Staff List</h1>
-<table class="wp-list-table striped glm-admin-table-single">
+<table class="wp-list-table striped glm-admin-table-single" style="max-width: 800px;">
<thead>
<tr>
<th>Extension</th>
<th>Building</th>
<th>Department</th>
+ <th>Delete</th>
</tr>
</thead>
<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>
+<script>
+ jQuery(document).ready(function($){
+
+
+
+ });
+</script>
+
{include file='admin/staff/footer.html'}
--- /dev/null
+<h1>Settings</h1>
+
+<h2 class="nav-tab-wrapper">
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=buildings" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">Buildings</a>
+ <a id="add-building" href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=addBuilding" class="nav-tab">Add Building</a>
+ <a href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=departments" class="nav-tab">Departments</a>
+ <a id="add-department" href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=addDepartment" class="nav-tab">Add Department</a>
+</h2>
--- /dev/null
+{include file="admin/staff/header.html"}
+{include file="admin/staff/settingSubHeader.html"}
+
+<h2>{if $option == 'buildings'}Buildings{else}Departments{/if}</h2>
+
+<table class="wp-list-table widefat fixed posts glm-admin-table" style="max-width: 800px;">
+ <thead>
+ <tr>
+ <th>Id</th>
+ <th>{if $option == 'buildings'}Building{else}Department{/if} Name</th>
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveList}
+ {foreach $list as $item}
+ <tr>
+ <td>{$item.id}</td>
+ <td>
+ {if $option == 'buildings'}
+ <a href="#" class="edit-building" data-id="{$item.id}" data-name="{$item.name|escape:'quotes'}">{$item.name}</a>
+ {else}
+ <a href="#" class="edit-department" data-id="{$item.id}" data-name="{$item.name|escape:'quotes'}">{$item.name}</a>
+ {/if}
+ </td>
+ <td>
+ {if $option == 'buildings'}
+ <a
+ onclick="return confirm('Are you sure you want to delete this Building?')"
+ href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=deleteBuilding&id={$item.id}"
+ class="delete-building button button-secondary glm-button-small glm-right">Delete</a>
+ {else}
+ <a
+ onclick="return confirm('Are you sure you want to delete this Department?')"
+ href="{$thisUrl}?page={$thisPage}&glm_action=settings&option=deleteDepartment&id={$item.id}"
+ class="delete-department button button-secondary glm-button-small glm-right">Delete</a>
+ {/if}
+ </td>
+ </tr>
+ {/foreach}
+ {/if}
+ </tbody>
+</table>
+
+{* Edit Add Building Dialog *}
+<div id="building_dialog" class="glm-dialog-box" title="Edit this Building">
+ <form action="{$thisUrl}?page={$thisPage}" method="post">
+ <input type="hidden" name="glm_action" value="settings">
+ <input id="building_option" type="hidden" name="option" value="updateBuilding">
+ <input id="building_id" type="hidden" name="id" value="">
+ <table class="glm-admin-table">
+ <tr>
+ <th class="glm-required">Building Name:</th>
+ <td>
+ <input id="building_name" type="text" name="name" class="glm-form-text-input" value="">
+ </td>
+ </tr>
+ </table>
+ <p><span class="glm-required">*</span> Required</p>
+ <a id="building_cancel" class="button button-primary glm-right">Cancel</a>
+ <input type="submit" value="Save this Building" class="button">
+ </form>
+</div>
+{* End Building Dialog *}
+
+{* Edit Add Department Dialog *}
+<div id="department_dialog" class="glm-dialog-box" title="Edit this Department">
+ <form action="{$thisUrl}?page={$thisPage}" method="post">
+ <input type="hidden" name="glm_action" value="settings">
+ <input id="department_option" type="hidden" name="option" value="updateBuilding">
+ <input id="department_id" type="hidden" name="id" value="">
+ <table class="glm-admin-table">
+ <tr>
+ <th class="glm-required">Department Name:</th>
+ <td>
+ <input id="department_name" type="text" name="name" class="glm-form-text-input" value="">
+ </td>
+ </tr>
+ </table>
+ <p><span class="glm-required">*</span> Required</p>
+ <a id="department_cancel" class="button button-primary glm-right">Cancel</a>
+ <input type="submit" value="Save this Department" class="button">
+ </form>
+</div>
+{* End Department Dialog *}
+
+<script>
+ jQuery(document).ready(function($){
+
+ // Dialog for edit add building
+ $('#building_dialog').dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: 'glm-dialog-no-close'
+ });
+
+ // Dialog for edit add department
+ $('#department_dialog').dialog({
+ autoOpen: false,
+ minWidth: 400,
+ dialogClass: 'glm-dialog-no-close'
+ });
+
+ // Click event for edit Building
+ $('.edit-building').on('click', function(){
+ // Get the data
+ var building_id = $(this).data('id');
+ var building_name = $(this).data('name');
+
+ // Set form fields
+ $('#building_id').val(building_id);
+ $('#building_name').val(building_name);
+ $('#building_option').val('updateBuilding');
+
+ // Open dialog
+ $('#building_dialog').dialog('open');
+ });
+ // Click event for cancel Building edit
+ $('#building_cancel').on('click', function(){
+ // unset fields here
+ $('#building_id').val('');
+ $('#building_name').val('');
+ $('#building_option').val('updateBuilding');
+ $('#building_dialog').dialog('close');
+ });
+ // Click event for adding Building
+ $('#add-building').on('click', function(e){
+ e.preventDefault();
+ $('#building_id').val('');
+ $('#building_name').val('');
+ $('#building_option').val('addBuilding');
+
+ // Open dialog
+ $('#building_dialog').dialog('open');
+ });
+
+ // Click event for edit Department
+ $('.edit-department').on('click', function(){
+ // Get the data
+ var department_id = $(this).data('id');
+ var department_name = $(this).data('name');
+
+ // Set form fields
+ $('#department_id').val(department_id);
+ $('#department_name').val(department_name);
+ $('#department_option').val('updateDepartment');
+
+ // Open dialog
+ $('#department_dialog').dialog('open');
+ });
+ // Click event for cancel Department edit
+ $('#department_cancel').on('click', function(){
+ // unset fields here
+ $('#department_id').val('');
+ $('#department_name').val('');
+ $('#department_option').val('updateDepartment');
+ $('#department_dialog').dialog('close');
+ });
+ // Click event for adding Department
+ $('#add-department').on('click', function(e){
+ e.preventDefault();
+ $('#department_id').val('');
+ $('#department_name').val('');
+ $('#department_option').val('addDepartment');
+
+ // Open dialog
+ $('#department_dialog').dialog('open');
+ });
+
+
+ });
+</script>
+
+{include file="admin/staff/footer.html"}