From f1dafed14458380019ebf089817a60007807e050 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 9 Mar 2018 14:58:16 -0500 Subject: [PATCH] Added code for management of asset items. Not fully working yet. --- 00_DEVELOPMENT_TASK_LIST.txt | 2 +- classes/assetsSupport.php | 106 +++++++++ classes/data/dataAssetItems.php | 8 + models/admin/ajax/assetManagement.php | 163 ++++---------- models/admin/ajax/facilityManagement.php | 203 ++++++++++++++++++ .../create_database_V0.0.1.sql | 7 +- setup/validActions.php | 1 + views/admin/assets/assetForm.html | 68 ++++++ views/admin/assets/facilityForm.html | 8 +- views/admin/assets/facilityLine.html | 3 +- views/admin/assets/index.html | 141 +++++++++--- 11 files changed, 548 insertions(+), 162 deletions(-) create mode 100644 classes/assetsSupport.php create mode 100644 models/admin/ajax/facilityManagement.php create mode 100644 views/admin/assets/assetForm.html diff --git a/00_DEVELOPMENT_TASK_LIST.txt b/00_DEVELOPMENT_TASK_LIST.txt index 3353063..90421f5 100644 --- a/00_DEVELOPMENT_TASK_LIST.txt +++ b/00_DEVELOPMENT_TASK_LIST.txt @@ -1,7 +1,7 @@ Asset Management Development Task List [X] Create Base Plugin -[ ] Create Admin Menus +[X] Create Admin Menus [X] Main: Asset Mgt [X] Create Database Tables [X] Create Data Classes for Tables diff --git a/classes/assetsSupport.php b/classes/assetsSupport.php new file mode 100644 index 0000000..2aa945a --- /dev/null +++ b/classes/assetsSupport.php @@ -0,0 +1,106 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release assetsSupport.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +/* + * This class provides some standard methods used by this plugin + */ +class GlmAssetsSupport +{ + + /** + * Merge template and data to produce HTML + * + * Checks the theme's view directories and the view directories for + * this plugin for a matching view file. + * + * Note that $view needs to have the proper view directory path + * includes. (i.e. "/views/front/registrations/summary.html") + * + * $view may also be a template as a string if $viewIsString is true. + * + * @param $data array Array of data to merge with the template + * @param $view string Name of view file (see above)) + * @param $viewIsString boolean If true, $view is a string containing the view. + * + * @access public + * @return void + */ + function generateHTML($data, $view, $viewIsString = false) + { + + // Load Smarty Template support + $smarty = new smartyTemplateSupport(); + + // Add standard parameters + require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; + + // Add data from model to Smarty template + if (is_array($data) && count($data) > 0) { + foreach ($data as $k => $d) { + $smarty->templateAssign($k, $d); + } + } + + // If is supplied as a string + if ($viewIsString) { + + $out = $smarty->template->fetch('eval:'.$view); + + // Otherwise $view is a file name + } else { + + // Get the specified view file - check theme first + $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views"; + $viewPath2 = GLM_MEMBERS_ASSETS_PLUGIN_PATH . "/views"; // Save default + + // If the view is not found in the theme, fall back to views in the plugin + if (!is_file($viewPath.'/'.$view)) { + + // Next try the plugin/add-on + $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views"; + + if (!is_file($viewPath.'/'.$view)) { + + if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { + trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE); + } + + } + + } + + // Update the Smarty view path + $smarty->template->setTemplateDir($viewPath); + + // If the view path doesn't match the default, add the default (using theme view) + if ($viewPath2 != $viewPath) { + $smarty->template->addTemplateDir($viewPath2); + } + + // Generate output from model data and view + $out = $smarty->template->fetch($view); + + } + + return $out; + + } + + + + + +} \ No newline at end of file diff --git a/classes/data/dataAssetItems.php b/classes/data/dataAssetItems.php index d1c472b..affd018 100644 --- a/classes/data/dataAssetItems.php +++ b/classes/data/dataAssetItems.php @@ -194,6 +194,14 @@ class GlmDataAssetsAssetItems extends GlmDataAbstract 'type' => 'money', 'use' => 'a' ), +/* + // IMage + 'image' => array ( + 'field' => 'image', + 'type' => 'image', + 'use' => 'a' + ), +*/ // Facility 'facility' => array ( diff --git a/models/admin/ajax/assetManagement.php b/models/admin/ajax/assetManagement.php index 22acfa3..ec5253e 100644 --- a/models/admin/ajax/assetManagement.php +++ b/models/admin/ajax/assetManagement.php @@ -2,7 +2,7 @@ /** * Gaslight Media Members Database - * Asset Management - Asset Admin + * Asset Management - Asset Admin - Asset Management * * PHP version 5.5 * @@ -13,12 +13,14 @@ * @version 0.1 */ +require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/assetsSupport.php'; + /* * This class performs the work of handling images passed to it via * an AJAX call that goes through the WorPress AJAX Handler. * */ -class GlmMembersAdmin_ajax_assetManagement +class GlmMembersAdmin_ajax_assetManagement extends GlmAssetsSupport { /** @@ -73,8 +75,8 @@ class GlmMembersAdmin_ajax_assetManagement public function modelAction ($actionData = false) { - require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataFacilities.php'; - $Facilities = new GlmDataAssetsFacilities($this->wpdb, $this->config); + require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataAssetItems.php'; + $Assets = new GlmDataAssetsAssetItems($this->wpdb, $this->config); if (!isset($_REQUEST) || !isset($_REQUEST['option'])) { die('No option specified.'); @@ -84,102 +86,96 @@ trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE); switch($_REQUEST['option']) { - case 'newFacility': + case 'newAsset': - $facility = $Facilities->newEntry(); + $asset = $Assets->newEntry(); - $view = 'facilityForm'; + $view = 'assetForm'; $templateData = array( 'status' => '0', 'use' => 'add', - 'facility' => $facility['fieldData'] + 'asset' => $asset['fieldData'] ); break; - case 'addNewFacility': + case 'addNewAsset': - $facility = $Facilities->insertEntry(); + $asset = $Assets->insertEntry(); - // If facility was not added - if (!is_array($facility) || trim($facility['fieldData']['id']) == '') { + // If asset was not added + if (!is_array($asset) || trim($facility['asset']['id']) == '') { - $view = 'facilityForm'; + $view = 'assetForm'; - // New facility was not added so we need to redisplay the form. + // New asset was not added so we need to redisplay the form. $templateData = array( 'status' => 1, - 'use' => 'add', - 'cities' => $cities, - 'states' => $this->config['states'], - 'countries' => $this->config['countries'] + 'use' => 'add' ); - // Facility Added + // Asset Added } else { - $view = 'facilityLine'; + $view = 'assetLine'; $templateData = array( 'status' => '0', - 'facility' => $facility + 'asset' => $asset ); } break; - case 'editFacility': + case 'editAsset': - $facilityId = 0; + $assetId = 0; if (isset($_REQUEST) && isset($_REQUEST['id']) ) { - $facilityId = $_REQUEST['id'] + 0; + $assetId = $_REQUEST['id'] + 0; } - if ($facilityId > 0) { - $facility = $Facilities->editEntry($facilityId); - //echo "
".print_r($facility,1)."
"; - //die(); - $view = 'facilityForm'; + if ($assetId > 0) { + + $asset = $Assets->editEntry($facilityId); + + $view = 'assetForm'; $templateData = array( 'status' => '0', 'use' => 'edit', - 'facility' => $facility['fieldData'] + 'asset' => $asset['fieldData'] ); } else { - die('1'.$this->config['terms']['assets_term_facility_cap'].' not found!'); + die('1'.$this->config['terms']['assets_term_asset_cap'].' not found!'); } break; - case 'updateFacility': + case 'updateAsset': $id = $_REQUEST['id'] - 0; if ($id <= 0) { - die('2'.$this->config['terms']['assets_term_facility_cap'].' ID not provided! Unable to edit.'); + die('2'.$this->config['terms']['assets_term_asset_cap'].' ID not provided! Unable to edit.'); } - $facility = $Facilities->updateEntry($id); + $asset = $Assets->updateEntry($id); - // If facility was not propertlyupdated - if (!is_array($facility) || trim($facility['fieldData']['id']) == '') { + // If asset was not propertlyupdated + if (!is_array($asset) || trim($asset['fieldData']['id']) == '') { - $view = 'facilityForm'; + $view = 'assetForm'; - // New facility was not added so we need to redisplay the form. + // New asset was not added so we need to redisplay the form. $templateData = array( 'status' => 2, - 'use' => 'add', - 'cities' => $cities, - 'states' => $this->config['states'], - 'countries' => $this->config['countries'] + 'use' => 'add' ); } else { - die('0'.$facility['fieldData']['name']); + die('0'.$asset['fieldData']['name']); } break; @@ -198,85 +194,4 @@ trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE); } - /** - * Merge template and data to produce HTML - * - * Checks the theme's view directories and the view directories for - * this plugin for a matching view file. - * - * Note that $view needs to have the proper view directory path - * includes. (i.e. "/views/front/registrations/summary.html") - * - * $view may also be a template as a string if $viewIsString is true. - * - * @param $data array Array of data to merge with the template - * @param $view string Name of view file (see above)) - * @param $viewIsString boolean If true, $view is a string containing the view. - * - * @access public - * @return void - */ - function generateHTML($data, $view, $viewIsString = false) - { - - // Load Smarty Template support - $smarty = new smartyTemplateSupport(); - - // Add standard parameters - require GLM_MEMBERS_PLUGIN_SETUP_PATH.'/standardTemplateParams.php'; - - // Add data from model to Smarty template - if (is_array($data) && count($data) > 0) { - foreach ($data as $k => $d) { - $smarty->templateAssign($k, $d); - } - } - - // If is supplied as a string - if ($viewIsString) { - - $out = $smarty->template->fetch('eval:'.$view); - - // Otherwise $view is a file name - } else { - - // Get the specified view file - check theme first - $viewPath = GLM_MEMBERS_PLUGIN_CURRENT_THEME_DIR."/views"; - $viewPath2 = GLM_MEMBERS_ASSETS_PLUGIN_PATH . "/views"; // Save default - - // If the view is not found in the theme, fall back to views in the plugin - if (!is_file($viewPath.'/'.$view)) { - - // Next try the plugin/add-on - $viewPath = GLM_MEMBERS_REGISTRATIONS_PLUGIN_PATH . "/views"; - - if (!is_file($viewPath.'/'.$view)) { - - if (GLM_MEMBERS_PLUGIN_FRONT_DEBUG) { - trigger_error("Bad or missing view file when generating checkout HTML: $viewPath/$view", E_USER_NOTICE); - } - - } - - } - - // Update the Smarty view path - $smarty->template->setTemplateDir($viewPath); - - // If the view path doesn't match the default, add the default (using theme view) - if ($viewPath2 != $viewPath) { - $smarty->template->addTemplateDir($viewPath2); - } - - // Generate output from model data and view - $out = $smarty->template->fetch($view); - - } - - return $out; - - } - - - } diff --git a/models/admin/ajax/facilityManagement.php b/models/admin/ajax/facilityManagement.php new file mode 100644 index 0000000..1952573 --- /dev/null +++ b/models/admin/ajax/facilityManagement.php @@ -0,0 +1,203 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/assetsSupport.php'; + +/* + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_facilityManagement extends GlmAssetsSupport +{ + + /** + * 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; + + } + + /* + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * Status characters returned + * 0 - Submission OK + * 1 - Faciltiy not found when trying to edit + * 2 - ID not provided for facility update on form submission + * + */ + public function modelAction ($actionData = false) + { + + require_once GLM_MEMBERS_ASSETS_PLUGIN_CLASS_PATH.'/data/dataFacilities.php'; + $Facilities = new GlmDataAssetsFacilities($this->wpdb, $this->config); + + if (!isset($_REQUEST) || !isset($_REQUEST['option'])) { + die('No option specified.'); + } + +trigger_error("Option = ".$_REQUEST['option'],E_USER_NOTICE); + + switch($_REQUEST['option']) { + + case 'newFacility': + + $facility = $Facilities->newEntry(); + + $view = 'facilityForm'; + + $templateData = array( + 'status' => '0', + 'use' => 'add', + 'facility' => $facility['fieldData'] + ); + + break; + + case 'addNewFacility': + + $facility = $Facilities->insertEntry(); + + // If facility was not added + if (!is_array($facility) || trim($facility['fieldData']['id']) == '') { + + $view = 'facilityForm'; + + // New facility was not added so we need to redisplay the form. + $templateData = array( + 'status' => 1, + 'use' => 'add', + 'cities' => $cities, + 'states' => $this->config['states'], + 'countries' => $this->config['countries'] + ); + + // Facility Added + } else { + + $view = 'facilityLine'; + + $templateData = array( + 'status' => '0', + 'facility' => $facility + ); + + } + + break; + + case 'editFacility': + + $facilityId = 0; + if (isset($_REQUEST) && isset($_REQUEST['id']) ) { + $facilityId = $_REQUEST['id'] + 0; + } + + if ($facilityId > 0) { + $facility = $Facilities->editEntry($facilityId); + //echo "
".print_r($facility,1)."
"; + //die(); + $view = 'facilityForm'; + + $templateData = array( + 'status' => '0', + 'use' => 'edit', + 'facility' => $facility['fieldData'] + ); + + } else { + die('1'.$this->config['terms']['assets_term_facility_cap'].' not found!'); + } + + break; + + case 'updateFacility': + + $id = $_REQUEST['id'] - 0; + if ($id <= 0) { + die('2'.$this->config['terms']['assets_term_facility_cap'].' ID not provided! Unable to edit.'); + } + + $facility = $Facilities->updateEntry($id); + + // If facility was not propertlyupdated + if (!is_array($facility) || trim($facility['fieldData']['id']) == '') { + + $view = 'facilityForm'; + + // New facility was not added so we need to redisplay the form. + $templateData = array( + 'status' => 2, + 'use' => 'add', + 'cities' => $cities, + 'states' => $this->config['states'], + 'countries' => $this->config['countries'] + ); + + } else { + die('0'.$facility['fieldData']['name']); + } + + break; + + default: + die('No valid option provided'); + break; + } + + $templateData['$glmPluginMediaUrl'] = GLM_MEMBERS_PLUGIN_MEDIA_URL; + $html = $this->generateHTML($templateData, 'admin/assets/'.$view.'.html'); + die($html); + + + die('Nothing Here'); + + } + +} diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index 7483a97..7e2259e 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -164,6 +164,7 @@ CREATE TABLE {prefix}asset_item ( lead_time INTEGER NULL, -- Actual lead time required to request this item - Abstract "interval" type reuse_time INTEGER NULL, -- Actual time required to prepair this type for reuse for this item - Abstract "interval" type cost FLOAT NULL, -- Default cost for use of this asset type + ++image TINYTEXT NULL, -- Asset Image facility INTEGER NULL, -- Pointer to facility -- Map location data has to go here PRIMARY KEY (id), @@ -179,8 +180,8 @@ CREATE TABLE {prefix}asset_assignment ( status TINYINT NULL, -- Status of this assignment - Config list "assignment_status" name TINYTEXT NULL, -- Name of this assignment (Event, requester, ...) account INTEGER NULL, -- Pointer to account record - start_time DATETIME NULL, -- Start time of assignment - end_time DATETIME NULL, -- End time of assignment + --start_time DATETIME NULL, -- Start time of assignment + --end_time DATETIME NULL, -- End time of assignment PRIMARY KEY (id), INDEX (start_time), INDEX (end_time), @@ -196,6 +197,8 @@ CREATE TABLE {prefix}asset_assigned ( asset_item INTEGER NULL, -- Pointer to asset_item asset_type INTEGER NULL, -- Pointer to asset_type quant INTEGER NULL, -- Quantity of asset_item assigned - Default to 1 + ++start_time DATETIME NULL, -- Start time of assignment + ++end_time DATETIME NULL, -- End time of assignment hold_release_time DATETIME NULL, -- Time at which hold on this asset item is released (0 if assignment is complete) PRIMARY KEY (id), INDEX (asset_assignment), diff --git a/setup/validActions.php b/setup/validActions.php index f3f4656..03e02ad 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,6 +60,7 @@ $glmMembersAssetsAddOnValidActions = array( 'adminActions' => array( 'ajax' => array( + 'facilityManagement' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG, 'assetManagement' => GLM_MEMBERS_ASSETS_PLUGIN_SLUG ), 'assets' => array( diff --git a/views/admin/assets/assetForm.html b/views/admin/assets/assetForm.html new file mode 100644 index 0000000..6b9e171 --- /dev/null +++ b/views/admin/assets/assetForm.html @@ -0,0 +1,68 @@ +{$status} {* first character of this file is a status flag for the calling AJAX code. *} + +*** Still Building Form ***
+ + + + + {* Asset Dialog Box *} + +
+ + + {if $use == 'add'} + + {/if} + {if $use == 'edit'} + + + {/if} + +
+ +
Name:
+
+ +
Description:
+
+ +
{$terms.assets_term_facility_cap} Image:
+
+ {if $asset.image} + Delete Image
+
+ {$asset.image}
+ {/if} + New image: +
+ +
 
 
+ +
* Required
+
+ + Cancel +
+ +
{* assetsAssetDialog *} + + +
diff --git a/views/admin/assets/facilityForm.html b/views/admin/assets/facilityForm.html index 526a088..2aebd0e 100644 --- a/views/admin/assets/facilityForm.html +++ b/views/admin/assets/facilityForm.html @@ -4,7 +4,7 @@ .assets-dialog-box { display: grid; grid-gap: 5px 5px; - grid-template-columns: 8rem auto; + grid-template-columns: 8em auto; } .assets-facility-descr { width: 30em !important; @@ -12,13 +12,13 @@ .assets-facility-input-prompt { padding: 5px 0 0 5px; } - .assetsFacilityInputMsg { + .assetsFacilityInputReqired { color: red; } - {* New Facility Dialog Box *} + {* Facility Dialog Box *}
@@ -34,7 +34,7 @@
Name:
-
+
Description:
diff --git a/views/admin/assets/facilityLine.html b/views/admin/assets/facilityLine.html index b7dc767..4466d83 100644 --- a/views/admin/assets/facilityLine.html +++ b/views/admin/assets/facilityLine.html @@ -1,7 +1,8 @@ {$status} {* first character of this file is a status flag for the calling AJAX code. *}
{$facility.fieldData.name}
-