From ac21a32f242f147bc7fa32cecfbb89cf79f71312 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 24 Apr 2019 14:21:38 -0400 Subject: [PATCH] Add contact settings and update edit contact page. Adding new options enable_billing_info enable_contact_info enable_profile_image enable_organization --- classes/data/dataSettings.php | 165 ++++++++++++++++++ index.php | 11 +- models/admin/settings/contacts.php | 148 ++++++++++++++++ setup/adminTabs.php | 15 ++ .../create_database_V0.0.7.sql | 75 -------- .../create_database_V0.0.8.sql | 93 ++++++++++ setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.8.sql | 23 +++ setup/validActions.php | 3 + views/admin/contacts/edit.html | 23 +-- views/admin/settings/contacts.html | 49 ++++++ 11 files changed, 513 insertions(+), 93 deletions(-) create mode 100644 classes/data/dataSettings.php create mode 100644 models/admin/settings/contacts.php delete mode 100644 setup/databaseScripts/create_database_V0.0.7.sql create mode 100644 setup/databaseScripts/create_database_V0.0.8.sql create mode 100644 setup/databaseScripts/update_database_V0.0.8.sql create mode 100644 views/admin/settings/contacts.html diff --git a/classes/data/dataSettings.php b/classes/data/dataSettings.php new file mode 100644 index 0000000..e35917e --- /dev/null +++ b/classes/data/dataSettings.php @@ -0,0 +1,165 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: dataContacts.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + */ + +/** + * GlmDataContacts class + * + * PHP version 5 + * + * @category Data + * @package EventManagement + * @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 GlmDataContactSettings 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; + public $postProcess = true; + + /** + * 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_CONTACTS_PLUGIN_DB_PREFIX . 'settings'; + + /* + * Table Data Fields + */ + + $this->fields = array ( + + 'id' => array ( + 'field' => 'id', + 'type' => 'integer', + 'view_only' => true, + 'use' => 'a' + ), + + 'enable_custom_contact' => array ( + 'field' => 'enable_custom_contact', + 'type' => 'checkbox', + 'default' => true, + 'use' => 'a' + ), + + 'enable_contact_info' => array ( + 'field' => 'enable_contact_info', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + + 'enable_profile_image' => array ( + 'field' => 'enable_profile_image', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + + 'enable_billing_info' => array ( + 'field' => 'enable_billing_info', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + + 'enable_organization' => array ( + 'field' => 'enable_organization', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + + ); + + } + + public function entryPostProcessing($r, $a) + { + + return $r; + } + + +} diff --git a/index.php b/index.php index aaade85..bd68e22 100644 --- a/index.php +++ b/index.php @@ -40,7 +40,7 @@ if (!defined('ABSPATH')) { * version nunmber of that release for the DB version. */ define('GLM_MEMBERS_CONTACTS_PLUGIN_VERSION', '1.1.11'); -define('GLM_MEMBERS_CONTACTS_PLUGIN_DB_VERSION', '0.0.7'); +define('GLM_MEMBERS_CONTACTS_PLUGIN_DB_VERSION', '0.0.8'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58'); @@ -129,6 +129,12 @@ if (version_compare($glmMembersDatabasePluginVersion, GLM_MEMBERS_CONTACTS_PLUGI require_once GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/validActions.php'; require_once GLM_MEMBERS_CONTACTS_PLUGIN_SETUP_PATH.'/shortcodes.php'; require_once GLM_MEMBERS_CONTACTS_PLUGIN_DB_SCRIPTS.'/dbVersions.php'; + +// Load Events Management Settings data +$contactsSettings = $wpdb->get_row( "SELECT * FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX."settings WHERE id = 1", ARRAY_A ); + +unset($contactsSettings['id']); + function glmMembersRegisterContacts($addOns) { // Add this add-on to the add-ons array @@ -138,6 +144,9 @@ function glmMembersRegisterContacts($addOns) { 'short_name' => GLM_MEMBERS_CONTACTS_PLUGIN_SHORT_NAME, 'slug' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG, 'actions' => $GLOBALS['glmMembersContactsAddOnValidActions'], + 'config' => array( + 'settings' => $GLOBALS['contactsSettings'] + ), 'database' => array( 'dbPrefix' => GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX, 'dbCurrentVersion' => GLM_MEMBERS_CONTACTS_PLUGIN_DB_VERSION, diff --git a/models/admin/settings/contacts.php b/models/admin/settings/contacts.php new file mode 100644 index 0000000..6866752 --- /dev/null +++ b/models/admin/settings/contacts.php @@ -0,0 +1,148 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Event Categories data abstract +require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataSettings.php'; + +/* + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_settings_contacts extends GlmDataContactSettings +{ + + /** + * 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; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the controller 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. + * + */ + public function modelAction ($actionData = false) + { + + $success = true; + $error = false; + $contactSettings = false; + + $contactSettings = $this->getEntry( 1 ); + + // If there's an action option + if ( isset( $_REQUEST['option'] ) ) { + + switch( $_REQUEST['option'] ) { + + case 'update': + $this->updateEntry( 1 ); + + break; + } + + } + + $contactSettings = $this->getEntry( 1 ); + // If we had a fatal error, redirect to the error page + if ( $error ) { + return array( + 'status' => $success, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => false + ); + } + + // Compile template data + $templateData = array( + 'contactSettings' => $contactSettings + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/settings/contacts.html', + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index 52a0947..402de43 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -127,6 +127,21 @@ if (current_user_can('glm_members_members')) { ); } + add_filter('glm-member-db-add-tab-for-settings', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Contacts', + 'menu' => 'settings', + 'action' => 'contacts' + ), + + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); + } if (current_user_can('glm_members_management')) { add_filter('glm-member-db-add-tab-for-import', diff --git a/setup/databaseScripts/create_database_V0.0.7.sql b/setup/databaseScripts/create_database_V0.0.7.sql deleted file mode 100644 index 13b8205..0000000 --- a/setup/databaseScripts/create_database_V0.0.7.sql +++ /dev/null @@ -1,75 +0,0 @@ --- Gaslight Media Members Database --- File Created: 12/09/14 15:27:15 --- Database Version: 0.0.7 --- Database Creation Script - Contacts Add-On --- --- To permit each query below to be executed separately, --- all queries must be separated by a line with four dashes --- --- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES **** --- - --- Contacts - used by various entities -CREATE TABLE {prefix}contacts ( - id INT NOT NULL AUTO_INCREMENT, - active BOOLEAN NULL, -- Contact is active flag - access INT NULL, -- Access type - See access table in plugin.ini - primary_contact BOOLEAN NULL, -- Contact is the "Primary Contact" for mailings to entity (ref_type/ref_dest) - fname TINYTEXT NULL, -- First name of contact - lname TINYTEXT NULL, -- Last name of contact - contact_type INT NULL, -- Contact type - see contact_type table (individual, role, ...) - contact_role INT NULL, -- Contact WordPress user Role - org TINYTEXT NULL, -- Organization name - title TINYTEXT NULL, -- Title/Position - descr TEXT NULL, -- Description of position/responsibilities - Displayed - image TINYTEXT NULL, -- Image - addr1 TINYTEXT NULL, -- Address line 1 - Address is for contact, not necessarily for organization - addr2 TINYTEXT NULL, -- Address line 2 - county TINYTEXT NULL, -- County - city INT NULL, -- Pointer to city in cities table - state TINYTEXT NULL, -- Two character state code - matches states.ini entries - country TINYTEXT NULL, -- Two character country code - matches countries.ini entries - zip TINYTEXT NULL, -- ZIP/Postal Code - lat FLOAT NULL, -- Latitude of contact location - lon FLOAT NULL, -- Longitude of contact location - url TINYTEXT NULL, -- URL to information regarding this contact - home_phone TINYTEXT NULL, -- Home phone number - or after-hours phone number - mobile_phone TINYTEXT NULL, -- Mobile phone number - alt_phone TINYTEXT NULL, -- An alternate phone number - email TINYTEXT NULL, -- E-Mail address - alt_email TINYTEXT NULL, -- Alternate E-Mail address - Also used to log-in - username TINYTEXT NULL, -- Optional username to use for login - password TINYTEXT NULL, -- Encrypted password - notes TEXT NULL, -- Notes - Not displayed on front-end - create_time TIMESTAMP NULL, -- Create date/time - modify_time TIMESTAMP NULL, -- Last modified date/time - ref_type INT NULL, -- Type of entity this contact is associated with - ref_dest INT NULL, -- Pointer to the specific entity of ref_type this contact is associated with - business_fname TINYTEXT NULL, -- Org First Name - business_lname TINYTEXT NULL, -- Org Last Name - business_addr1 TINYTEXT NULL, -- Org Address 1 - business_addr2 TINYTEXT NULL, -- Org Address 2 - business_city INT NULL, -- Org City - business_state TINYTEXT NULL, -- Org State - business_zip TINYTEXT NULL, -- Org Zip - business_country TINYTEXT NULL, -- Org Country - business_email TINYTEXT NULL, -- Org Email - business_phone TINYTEXT NULL, -- Org Phone in Directory - office_phone TINYTEXT NULL, -- Org Office phone number - business_mobile TINYTEXT NULL, -- Org Mobile - fax TINYTEXT NULL, -- Org FAX number (do people still use these?) - contact_publish BOOLEAN NULL, -- Flag to publish Contact Info to Directory - contact_use_billing BOOLEAN NULL, -- Flag to use Contact Info as Billing - business_publish BOOLEAN NULL, -- Flag to publish Business to Directory - business_use_billing BOOLEAN NULL, -- Flag to use Business as Billing - mailing_address_type TINYTEXT NULL, -- Mailing Address Type - mailto_label TINYTEXT NULL, -- Mail To Label - PRIMARY KEY (id), - INDEX(fname(20)), - INDEX(lname(20)), - INDEX(city), - INDEX(zip(10)), - INDEX(lat), - INDEX(lon), - INDEX(email(20)) -); diff --git a/setup/databaseScripts/create_database_V0.0.8.sql b/setup/databaseScripts/create_database_V0.0.8.sql new file mode 100644 index 0000000..af7da90 --- /dev/null +++ b/setup/databaseScripts/create_database_V0.0.8.sql @@ -0,0 +1,93 @@ +-- Gaslight Media Members Database +-- File Created: 12/09/14 15:27:15 +-- Database Version: 0.0.8 +-- Database Creation Script - Contacts Add-On +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes +-- +-- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES **** +-- + +-- Contacts - used by various entities +CREATE TABLE {prefix}contacts ( + id INT NOT NULL AUTO_INCREMENT, + active BOOLEAN NULL, -- Contact is active flag + access INT NULL, -- Access type - See access table in plugin.ini + primary_contact BOOLEAN NULL, -- Contact is the "Primary Contact" for mailings to entity (ref_type/ref_dest) + fname TINYTEXT NULL, -- First name of contact + lname TINYTEXT NULL, -- Last name of contact + contact_type INT NULL, -- Contact type - see contact_type table (individual, role, ...) + contact_role INT NULL, -- Contact WordPress user Role + org TINYTEXT NULL, -- Organization name + title TINYTEXT NULL, -- Title/Position + descr TEXT NULL, -- Description of position/responsibilities - Displayed + image TINYTEXT NULL, -- Image + addr1 TINYTEXT NULL, -- Address line 1 - Address is for contact, not necessarily for organization + addr2 TINYTEXT NULL, -- Address line 2 + county TINYTEXT NULL, -- County + city INT NULL, -- Pointer to city in cities table + state TINYTEXT NULL, -- Two character state code - matches states.ini entries + country TINYTEXT NULL, -- Two character country code - matches countries.ini entries + zip TINYTEXT NULL, -- ZIP/Postal Code + lat FLOAT NULL, -- Latitude of contact location + lon FLOAT NULL, -- Longitude of contact location + url TINYTEXT NULL, -- URL to information regarding this contact + home_phone TINYTEXT NULL, -- Home phone number - or after-hours phone number + mobile_phone TINYTEXT NULL, -- Mobile phone number + alt_phone TINYTEXT NULL, -- An alternate phone number + email TINYTEXT NULL, -- E-Mail address + alt_email TINYTEXT NULL, -- Alternate E-Mail address - Also used to log-in + username TINYTEXT NULL, -- Optional username to use for login + password TINYTEXT NULL, -- Encrypted password + notes TEXT NULL, -- Notes - Not displayed on front-end + create_time TIMESTAMP NULL, -- Create date/time + modify_time TIMESTAMP NULL, -- Last modified date/time + ref_type INT NULL, -- Type of entity this contact is associated with + ref_dest INT NULL, -- Pointer to the specific entity of ref_type this contact is associated with + business_fname TINYTEXT NULL, -- Org First Name + business_lname TINYTEXT NULL, -- Org Last Name + business_addr1 TINYTEXT NULL, -- Org Address 1 + business_addr2 TINYTEXT NULL, -- Org Address 2 + business_city INT NULL, -- Org City + business_state TINYTEXT NULL, -- Org State + business_zip TINYTEXT NULL, -- Org Zip + business_country TINYTEXT NULL, -- Org Country + business_email TINYTEXT NULL, -- Org Email + business_phone TINYTEXT NULL, -- Org Phone in Directory + office_phone TINYTEXT NULL, -- Org Office phone number + business_mobile TINYTEXT NULL, -- Org Mobile + fax TINYTEXT NULL, -- Org FAX number (do people still use these?) + contact_publish BOOLEAN NULL, -- Flag to publish Contact Info to Directory + contact_use_billing BOOLEAN NULL, -- Flag to use Contact Info as Billing + business_publish BOOLEAN NULL, -- Flag to publish Business to Directory + business_use_billing BOOLEAN NULL, -- Flag to use Business as Billing + mailing_address_type TINYTEXT NULL, -- Mailing Address Type + mailto_label TINYTEXT NULL, -- Mail To Label + PRIMARY KEY (id), + INDEX(fname(20)), + INDEX(lname(20)), + INDEX(city), + INDEX(zip(10)), + INDEX(lat), + INDEX(lon), + INDEX(email(20)) + ); + +---- + +-- Settings +CREATE TABLE {prefix}settings ( + id INT NOT NULL AUTO_INCREMENT, + enable_custom_contact BOOLEAN DEFAULT false, -- Enable / Disable Custom Contact + enable_contact_info BOOLEAN DEFAULT true, -- Enable / Disable Contact Info + enable_profile_image BOOLEAN DEFAULT true, -- Enable / Disable Profile Image + enable_billing_info BOOLEAN DEFAULT false, -- Enable / Disable Billing Info + enable_organization BOOLEAN DEFAULT false, -- Enable / Disable Organization + PRIMARY KEY (id) +); + +---- + +-- Insert into settings +INSERT INTO {prefix}settings ( id,enable_custom_contact, enable_contact_info, enable_profile_image, enable_billing_info, enable_organization ) VALUES ( 1, false, true, true, false, false ); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 0e35b6e..1d78618 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -34,6 +34,7 @@ $glmMembersContactsDbVersions = array( '0.0.5' => array('version' => '0.0.5', 'tables' => 1, 'date' => '07/26/2018'), '0.0.6' => array('version' => '0.0.6', 'tables' => 1, 'date' => '07/26/2018'), '0.0.7' => array('version' => '0.0.7', 'tables' => 1, 'date' => '08/09/2018'), + '0.0.8' => array('version' => '0.0.8', 'tables' => 2, 'date' => '04/24/2019'), ); diff --git a/setup/databaseScripts/update_database_V0.0.8.sql b/setup/databaseScripts/update_database_V0.0.8.sql new file mode 100644 index 0000000..775cf80 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.8.sql @@ -0,0 +1,23 @@ +-- Gaslight Media Members Database - Contacts Add-On +-- File Created: 04/24/19 +-- Database Version: 0.0.8 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Settings +CREATE TABLE {prefix}settings ( + id INT NOT NULL AUTO_INCREMENT, + enable_custom_contact BOOLEAN DEFAULT false, -- Enable / Disable Custom Contact + enable_contact_info BOOLEAN DEFAULT true, -- Enable / Disable Contact Info + enable_profile_image BOOLEAN DEFAULT true, -- Enable / Disable Profile Image + enable_billing_info BOOLEAN DEFAULT false, -- Enable / Disable Billing Info + enable_organization BOOLEAN DEFAULT false, -- Enable / Disable Organization + PRIMARY KEY (id) +); + +---- + +-- Insert into settings +INSERT INTO {prefix}settings ( id,enable_custom_contact, enable_contact_info, enable_profile_image, enable_billing_info, enable_organization ) VALUES ( 1, false, true, true, false, false ); diff --git a/setup/validActions.php b/setup/validActions.php index 7755cfd..c7f433c 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -51,6 +51,9 @@ $glmMembersContactsAddOnValidActions = array( 'management' => array( 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG, ), + 'settings' => array( + 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG, + ), 'import' => array( 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG, ), diff --git a/views/admin/contacts/edit.html b/views/admin/contacts/edit.html index af864f9..426319b 100644 --- a/views/admin/contacts/edit.html +++ b/views/admin/contacts/edit.html @@ -1,3 +1,4 @@ +{* This view is used for both admin/manager and contact own entity manager *}
{if !$contactEditOwnRecord} @@ -132,6 +133,7 @@
{/if} + {if $option == 'create'} @@ -229,7 +231,6 @@
- {if $haveMember} +
@@ -378,7 +379,7 @@ {/if} -
Profile Image {if $contactInfo.fieldData.image} @@ -484,18 +485,12 @@ -
+

Organization / Company Information

- - -
- Publish on Front End - -
Use for Billing Information @@ -675,7 +670,7 @@ {if apply_filters( 'glm-members-billing-enabled', false )} -
+

Billing Info

@@ -690,19 +685,13 @@ {/if} -
+
- - -
- Publish on Front End - -
Use for Billing Information diff --git a/views/admin/settings/contacts.html b/views/admin/settings/contacts.html new file mode 100644 index 0000000..defa1d6 --- /dev/null +++ b/views/admin/settings/contacts.html @@ -0,0 +1,49 @@ +{* Contact Setting View *} +{include file='admin/settings/header.html'} + + + + +
+ + + + + +
+ + + + + + +{include file='admin/footer.html'} -- 2.17.1