From: Steve Sutton Date: Mon, 20 Nov 2017 21:55:08 +0000 (-0500) Subject: Setting up the database and management admin page. X-Git-Tag: v1.0.0^2~227 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=9d4a46aa8e76ee9ea349bc7798d12f3b085871fc;p=WP-Plugins%2Fglm-member-db-billing.git Setting up the database and management admin page. Management is saving the settings. All but the image are being saved. --- diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php new file mode 100644 index 0000000..8fa5a42 --- /dev/null +++ b/classes/data/dataManagement.php @@ -0,0 +1,244 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataEvents.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataBillingManagement class + * + * PHP version 5 + * + * @category Data + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataMembers.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmDataBillingManagement extends GlmDataAbstract +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Data Table Name + * + * @var $table + * @access public + */ + public $table; + /** + * Field definitions + * + * 'type' is type of field as defined by the application + * text Regular text field + * pointer Pointer to an entry in another table + * 'filters' is the filter name for a particular filter ID in PHP filter + * functions + * See PHP filter_id() + * + * 'use' is when to use the field + * l = List + * g = Get + * n = New + * i = Insert + * e = Edit + * u = Update + * d = Delete + * a = All + * + * @var $ini + * @access public + */ + public $fields = false; + /** + * MemberInfo DB object + * + * @var $MemberInfo + * @access public + */ + public $MemberInfo; + + /** + * Constructor + * + * @param object $d database connection + * @param array $config Configuration array + * @param bool $limitedEdit Flag to say indicate limited edit requested + * + * @return void + * @access public + */ + public function __construct($wpdb, $config, $limitedEdit = false) + { + + // If this class is not being extended along with existing $wpdb and $config + if (!$this->wpdb) { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + } + + /* + * Table Name + */ + $this->table = GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'management'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + // Default Billing Period + 'billing_period' => array( + 'field' => 'billing_period', + 'type' => 'text', + 'use' => 'a' + ), + + // Default Invoice Date + 'invoice_date' => array( + 'field' => 'invoice_date', + 'type' => 'text', + 'use' => 'a' + ), + + // Logo for Invioce PDF + 'company_logo' => array( + 'field' => 'company_logo', + 'type' => 'image', + 'use' => 'a' + ), + + // Name + 'company_name' => array( + 'field' => 'company_name', + 'type' => 'text', + 'use' => 'a' + ), + + // Name2 + 'company_name2' => array( + 'field' => 'company_name2', + 'type' => 'text', + 'use' => 'a' + ), + + // Address 1 + 'company_addr1' => array( + 'field' => 'company_addr1', + 'type' => 'text', + 'use' => 'a' + ), + + // Address 2 + 'company_addr2' => array( + 'field' => 'company_addr2', + 'type' => 'text', + 'use' => 'a' + ), + + // City + 'company_city' => array( + 'field' => 'company_city', + 'type' => 'text', + 'use' => 'a' + ), + + // State + 'company_state' => array ( + 'field' => 'company_state', + 'type' => 'list', + 'list' => $this->config['states'], + 'default' => 'MI', + 'force_list' => true, + 'use' => 'a' + ), + + // Zip + 'company_zip' => array( + 'field' => 'company_zip', + 'type' => 'text', + 'use' => 'a' + ), + + // Phone + 'company_phone' => array( + 'field' => 'company_phone', + 'type' => 'text', + 'use' => 'a' + ), + + // Email + 'company_email' => array( + 'field' => 'company_email', + 'type' => 'text', + 'use' => 'a' + ), + + // URL + 'company_url' => array( + 'field' => 'company_url', + 'type' => 'text', + 'use' => 'a' + ), + + ); + + } + + /* + * Entry Post Processing Call-Back Method + * + * Perform post-processing for all result entries. + * + * In this case we're using it to append an array of category + * data to each member result and also sort by member name. + * + * @param array $r Array of field result data for a single entry + * @param string $a Action being performed (l, i, g, ...) + * + * @return object Class object + * + */ + public function entryPostProcessing($r, $a) + { + return $r; + } + +} + +?> diff --git a/config/plugin.ini b/config/plugin.ini index 9222f7e..6789aba 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -2,7 +2,20 @@ ; Main Configuration File ; {descrName} ; -; Place any static configuration parameters here. +; Place any static configuration parameters here. ; [common] + +; Billing Types +billingType[1] = "Invoice" +billingType[2] = "Payment" +billingType[3] = "Adjustment" +billingType[4] = "Comment" + +; Payment Method +paymentMethod[1] = "Check" +paymentMethod[2] = "Credit Card" +paymentMethod[3] = "Cash" +paymentMethod[4] = "Other" + diff --git a/index.php b/index.php index adf2a87..b1ece21 100644 --- a/index.php +++ b/index.php @@ -144,9 +144,9 @@ if (is_file(GLM_MEMBERS_BILLING_PLUGIN_DB_SCRIPTS.'/dbVersions.php')) { // Load Add-On Management Settings data /* None - Need to figure out a smooth way to do this. +*/ $glmMembersBillingManagementSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX."management WHERE id = 1", ARRAY_A ); unset($glmMembersBillingManagementSettings['id']); -*/ function glmMembersBillingRegisterAddOn($addOns) { @@ -158,6 +158,7 @@ function glmMembersBillingRegisterAddOn($addOns) { 'slug' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'actions' => $GLOBALS['glmMembersBillingAddOnValidActions'], 'config' => array( + 'settings' => $GLOBALS['glmMembersBillingManagementSettings'] ), 'shortcodes' => $GLOBALS['glmMembersBillingShortcodes'], 'shortcodesDescription' => $GLOBALS['glmMembersBillingShortcodesDescription'] diff --git a/misc/documentation/CreateNewAddOn.txt b/misc/documentation/CreateNewAddOn.txt index b93235f..6da654c 100644 --- a/misc/documentation/CreateNewAddOn.txt +++ b/misc/documentation/CreateNewAddOn.txt @@ -3,13 +3,13 @@ Procedure to create a new GLM Members add-on plugin * Checkout glm-member-db-sample and rename directory to glm-member-db-{add-on name} -* From a bash prompt, run "SETUP_SCRIPT" +* From a bash prompt, run "SETUP_SCRIPT" * Create new repository named WP-Plugins/glm-member-db-{name of add-on}.git * If there are any databases associated with this add-on, setup the database scripts and data under the "setup/databaseScripts" directory. If there are no database tables - with this add-on, remove all but the "readme.txt" file from that directory. + with this add-on, remove all but the "readme.txt" file from that directory. NOTE: No "update_database..." files should be there for a new add-on with new tables. NOTE: There should be only one entry in the "dbVersions.php" file. @@ -24,7 +24,7 @@ Procedure to create a new GLM Members add-on plugin * Adding menus - Update "setup/adminMenus.php" and add menu section as described there. - - Add an entry in the validActions.php file. Pay attention to how slug name is + - Add an entry in the validActions.php file. Pay attention to how slug name is constructed ("glm-members-admin-{page}-{action}"). - If needed add a database table to the create_database_V...sql file Also add a "classes/data/data{Table}.php file @@ -33,10 +33,10 @@ Procedure to create a new GLM Members add-on plugin Note that additional possible view files should be named as... "views/admin/{page}/{action}{Name}.html - Test that when add-on is activated that the menu shows and is functional. - + * Adding tabs - - Update "setup/admin/Tabs.php" and add new tab filter as described there. - - Add an entry in the validActions.php file. Pay attention to how slug name is + - Update "setup/adminTabs.php" and add new tab filter as described there. + - Add an entry in the validActions.php file. Pay attention to how slug name is constructed ("glm-members-admin-{page}-{action}"). - If needed add a database table to the create_database_V...sql file Also add a "classes/data/data{Table}.php file @@ -45,5 +45,5 @@ Procedure to create a new GLM Members add-on plugin Note that additional possible view files should be named as... "views/admin/{page}/{action}{Name}.html - Test that when add-on is activated that the tab shows and is functional. - - * \ No newline at end of file + + * diff --git a/models/admin/management/billing.php b/models/admin/management/billing.php new file mode 100644 index 0000000..4608791 --- /dev/null +++ b/models/admin/management/billing.php @@ -0,0 +1,195 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release billing.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Management Events data abstract +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; + +/** + * GlmMembersAdmin_management_billing + * + * PHP version 5 + * + * @category Model + * @package GLM Member DB + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: packaging.php,v 1.0 2011/01/25 19:31:47 cscott + * Exp $ + */ +class GlmMembersAdmin_management_billing extends GlmDataBillingManagement +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * dbh Postgres database connection + * + * @var mixed + * @access public + */ + public $dbh; + /** + * settings used for the schema and tablenames + * + * @var mixed + * @access public + */ + public $settings = array(); + + /** + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * '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. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + 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); + + } + + /** + * modelAction + * + * @param bool $actionData + * @access public + * @return void + */ + public function modelAction($actionData = false) + { + + $option = false; + $settings_updated = false; + $settings_update_error = false; + $billing_settings = false; + $option2 = false; + + if (isset($_REQUEST['option'])) { + $option = $_REQUEST['option']; + } + + switch ($option) { + + case 'settings': + + default: + + // Make sure option is set if default + $option = 'settings'; + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_management')) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'User does not have rights to make configuration changes.' + ) + ); + } + + // Check for submission option + $option2 = ''; + if (isset($_REQUEST['option2'])) { + $option2 = $_REQUEST['option2']; + } + + switch($option2) { + + // Update the settings and redisplay the form + case 'submit': + + // Update the billing management settings + $billing_settings = $this->updateEntry(1); + if ($billing_settings['status']) { + $settings_updated = true; + } else { + $settings_update_error = true; + } + + break; + + // Default is to get the current settings and display the form + default: + + // Try to get the first (should be only) entry for general settings. + $billing_settings = $this->editEntry(1); + // echo '
$billing_settings: ' . print_r( $billing_settings, true ) . '
'; + + break; + + } + + break; + + } + + // Compile template data + $template_data = array( + 'option' => $option, + 'settingsUpdated' => $settings_updated, + 'settingsUpdateError' => $settings_update_error, + 'billingSettings' => $billing_settings, + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/billing.html', + 'data' => $template_data + ); + + + } + + +} + diff --git a/setup/adminTabs.php b/setup/adminTabs.php index e457b40..3b0bd62 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -32,4 +32,18 @@ * ); * */ - +if ( current_user_can( 'glm_members_members' ) ) { + add_filter( 'glm-member-db-add-tab-for-management', + function( $addOnTabs ) { + $newTabs = array( + array( + 'text' => 'Billing', + 'menu' => 'management', + 'action' => 'billing', + ) + ); + $addOnTabs = array_merge( $addOnTabs, $newTabs ); + return $addOnTabs; + } + ); +} diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index fdb8a54..dca366c 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -27,21 +27,21 @@ CREATE TABLE {prefix}transactions ( paid BOOLEAN DEFAULT '0', invoice TEXT, notes TINYTEXT, - PRIMARY_KEY (id) + PRIMARY KEY (id) ); ---- -- payment_types CREATE TABLE {prefix}payment_types ( - id INT _NOT NULL AUTO_INCREMENT, + id INT NOT NULL AUTO_INCREMENT, name TINYTEXT NOT NULL, - qcode INT, + qcode INT NULL, category TEXT NOT NULL, amount DECIMAL(8, 2), - notes TINYTEXT, + notes TINYTEXT NULL, dynamic_amount BOOLEAN DEFAULT '0', - PRIMARY_KEY (id) + PRIMARY KEY (id) ); ---- @@ -49,10 +49,46 @@ CREATE TABLE {prefix}payment_types ( -- ref_account CREATE TABLE {prefix}ref_account ( id INT NOT NULL AUTO_INCREMENT, + ref_type INT NOT NULL, ref_dest INT NOT NULL, payment_type INT NOT NULL, - email_invoice BOOLEAN DEFAULT '0', - usmail_invoice BOOLEAN DEFAULT '0', - fax_invoice BOOLEAN DEFAULT '0', - PRIMARY_KEY (id) + billing_period TINYTEXT NOT NULL, + invoice_date DATE NOT NULL, + processed_date DATE NOT NULL, + notification_pref TINYTEXT NULL, + PRIMARY KEY (id), + INDEX(ref_type), + INDEX(ref_dest), + INDEX(payment_type) +); + +---- + +-- Management Options +CREATE TABLE {prefix}management ( + id INT NOT NULL AUTO_INCREMENT, + billing_period TINYTEXT NOT NULL, + invoice_date DATE NOT NULL, + company_logo TINYTEXT NULL, + company_logo_height INT NULL, + company_name TINYTEXT NULL, + company_name2 TINYTEXT NULL, + company_addr1 TINYTEXT NULL, + company_addr2 TINYTEXT NULL, + company_city TINYTEXT NULL, + company_state TINYTEXT NULL, + company_zip TINYTEXT NULL, + company_phone TINYTEXT NULL, + company_email TINYTEXT NULL, + company_url TINYTEXT NULL, + PRIMARY KEY (id) ); + +---- + +-- Set default billing management entry +INSERT INTO {prefix}management + ( id ) + VALUES + ( 1 ) +; diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php new file mode 100644 index 0000000..5aaba3f --- /dev/null +++ b/setup/databaseScripts/dbVersions.php @@ -0,0 +1,19 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release dbVersions.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +$glmMembersBillingDbVersions = array( + '0.0.1' => array('version' => '0.0.1', 'tables' => 4), +); + diff --git a/setup/validActions.php b/setup/validActions.php index 46509a2..7f31196 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,9 +59,12 @@ $glmMembersBillingAddOnValidActions = array( 'adminActions' => array( + 'management' => array( + 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + ), ), 'frontActions' => array( ) ); -?> \ No newline at end of file +?> diff --git a/views/admin/management/billing.html b/views/admin/management/billing.html new file mode 100644 index 0000000..4ab8123 --- /dev/null +++ b/views/admin/management/billing.html @@ -0,0 +1,170 @@ +{include file='admin/management/header.html'} + + + + + + + + + + + + +
+ {if $settingsUpdated}

Settings Updated

{/if} + {if $settingsUpdateError}Settings Update Error{/if} +

Management Settings

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Billing Period + + {if $billingSettings.fieldFail.billing_period}

{$billingSettings.fieldFail.billing_period}

{/if}
+
Default Invoice Date + + {if $billingSettings.fieldFail.invoice_date}

{$billingSettings.fieldFail.invoice_date}

{/if}
+
Company Logo + + {if $billingSettings.fieldData.company_logo} + + + + + {/if} + +
+
+ +
+
+ Delete Image
+ {$billingSettings.fieldData.company_logo}
+
New image:
+ + {if $billingSettings.fieldFail.company_logo}

{$billingSettings.fieldFail.company_logo}{/if} +

Company Name + + {if $billingSettings.fieldFail.company_name}

{$billingSettings.fieldFail.company_name}

{/if}
+
Company Name 2 + + {if $billingSettings.fieldFail.company_name2}

{$billingSettings.fieldFail.company_name2}

{/if}
+
Company Address 1 + + {if $billingSettings.fieldFail.company_addr1}

{$billingSettings.fieldFail.company_addr1}

{/if}
+
Company Address 2 + + {if $billingSettings.fieldFail.company_addr2}

{$billingSettings.fieldFail.company_addr2}

{/if}
+
Company City + + {if $billingSettings.fieldFail.company_city}

{$billingSettings.fieldFail.company_city}

{/if}
+
Company State + + {if $billingSettings.fieldFail.company_state}

{$billingSettings.fieldFail.company_state}

{/if}
+
Company Zip + + {if $billingSettings.fieldFail.company_zip}

{$billingSettings.fieldFail.company_zip}

{/if}
+
Company Phone + + {if $billingSettings.fieldFail.company_phone}

{$billingSettings.fieldFail.company_phone}

{/if}
+
Company Email + + {if $billingSettings.fieldFail.company_email}

{$billingSettings.fieldFail.company_email}

{/if}
+
Company URL + + {if $billingSettings.fieldFail.company_url}

{$billingSettings.fieldFail.company_url}

{/if}
+
+ +
+
+ +