From 87d1360a29268f608fc0aef5e29d0e003b79b0e7 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 3 Jun 2016 12:51:04 -0400 Subject: [PATCH] Fixing contact create form submission issues. --- classes/data/dataContacts.php | 3 +- models/admin/contacts/index.php | 97 +++++++++++++++++++++++++++------ views/admin/contacts/edit.html | 55 ++++++++++++++++--- views/admin/contacts/index.html | 2 +- 4 files changed, 130 insertions(+), 27 deletions(-) diff --git a/classes/data/dataContacts.php b/classes/data/dataContacts.php index 77e49b9..c1272f3 100644 --- a/classes/data/dataContacts.php +++ b/classes/data/dataContacts.php @@ -172,7 +172,7 @@ class GlmDataContacts extends GlmDataAbstract 'type' => 'list', 'list' => $this->config['contact_role'], 'required' => true, - 'default' => $this->config['contact_role_numb']['RestrictedContact'], + 'default' => $this->config['contact_role_numb']['EntityManager'], 'force_list' => true, 'view_only' => $limitedEdit, 'use' => 'a' @@ -614,6 +614,7 @@ class GlmDataContacts extends GlmDataAbstract 'id' => $savedFields['id'], 'fname' => $savedFields['fname'], 'lname' => $savedFields['lname'], + 'username' => $savedFields['username'], 'ref_dest' => $savedFields['ref_dest'], 'ref_dest_name' => $savedFields['ref_dest_name'] ); diff --git a/models/admin/contacts/index.php b/models/admin/contacts/index.php index 9234270..1c132c8 100644 --- a/models/admin/contacts/index.php +++ b/models/admin/contacts/index.php @@ -92,11 +92,13 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $memberID = false; $memberData = false; $memberName = false; + $membersList = false; $contactsList = false; $haveContacts = false; $contactID = false; $contactInfo = false; - $newContactExists = false; + $newContactEmailExists = false; + $newContactUsernameExists = false; $misMatchedWpUsers = false; $newContactCreated = false; $usingExistingWPContact = false; @@ -148,7 +150,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts } - // If we're coming from the Member Events Menu/Tab + // If we're coming from the Member Contacts Menu/Tab if (defined('GLM_CONTACTS_MEMBER_MENU')) { $fromMemberMenu = true; @@ -167,10 +169,12 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts } + // Load members data class + require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'); + $Members = new GlmDataMembers($this->wpdb, $this->config); + // If we have a member ID - Get Member information if ($memberID) { - require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php'); - $Members = new GlmDataMembers($this->wpdb, $this->config); $memberData = $Members->getEntry($memberID); } @@ -200,6 +204,11 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $EasyPassword = new EasyPassword(); $contactInfo['fieldData']['password'] = $EasyPassword->generateEasyPassword('firstlast'); + // If we don't have a member, the get a list of member IDs for selection + if (!$haveMember) { + $membersList = $Members->getList('TRUE', 'name'); + } + $view = 'edit.html'; break; @@ -215,23 +224,30 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $contactCheck = $this->checkContact($_REQUEST['email'], $_REQUEST['username']); // If there's already a contact with this E-Mail address, don't create the contact - if ($contactCheck['contactsEmail'] || $contactCheck['contactsUsername']) { - $newContactExists = true; - break; + if ((trim($_REQUEST['email']) != '' && $contactCheck['contactsEmail'])) { + $newContactEmailExists = true; + $_POST['email'] = ''; + $_REQUEST['email'] = ''; + } + if ((trim($_REQUEST['username']) != '' && $contactCheck['contactsUsername'])) { + $newContactUsernameExists = true; + $_POST['username'] = ''; + $_REQUEST['username'] = ''; } - // If there is already a WordPress user with the requested Email address and a different user with the requeted Username + // If there is already a WordPress user with the requested Email address and a different user with the requested Username if ($contactCheck['wordpressEmail'] && $contactCheck['wordpressLogin'] && $contactCheck['wpUserEmail']->ID != $contactCheck['wpUserLogin']->ID) { $misMatchedWpUsers = true; - break; + $_POST['username'] = ''; + $_REQUEST['username'] = ''; } // Try to insert the new contact $contactInfo = $this->insertEntry(); // If that was successful - if ($contactInfo['status']) { + if ($contactInfo['status'] && !$newContactEmailExists && !$newContactUsernameExists && !$misMatchedWpUsers) { // If there's an existing WordPress user matching the E-Mail address but that has a different username if ($contactCheck['wordpressEmail'] @@ -319,12 +335,28 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $contactInfo['fieldData']['password'] = $_REQUEST['password']; $refType = $_REQUEST['ref_type']; $refTypeName = $this->config['ref_type'][$refType]; - $view = 'edit.html'; + $view = 'add.html'; // addNew was unsuccessful, fall through to edit case 'edit': + // Check for no member selected + if (!$haveMember) { + + // Get members list for selection + $membersList = $Members->getList('TRUE', 'name'); + + // If ref_dest is submitted, set that to default + if (isset($_REQUEST['ref_dest'])) { + $refDest = $_REQUEST['ref_dest']-0; + if ($refDest && isset($membersList[$refDest])) { + $membersList[$refDest]['selected'] = true; + } + } + + } + // Get contact ID to edit if (isset($_REQUEST['contact']) && ($_REQUEST['contact'] -0) > 0) { @@ -332,14 +364,30 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $contactID = $_REQUEST['contact'] - 0; $contactInfo = $this->editEntry($contactID); - // If the contact wasn't found, then set ID to false - if (!$contactInfo['status']) { - $contactID = false; + // Check if we have a good member ID + if ($contactInfo['fieldData']['ref_dest']) { + + // Get member information + $memberData = $Members->getEntry($contactInfo['fieldData']['ref_dest']); + + // Check that we have good member data + if (is_array($memberData) && isset($memberData['id']) && $memberData['id'] > 0) { + $memberID = $memberData['id']; + $haveMember = true; + $memberName = $memberData['name']; + } + } - $view = 'edit.html'; } + // If the contact wasn't found, then set ID to false + if (!$contactInfo['status']) { + $contactID = false; + } + + $view = 'edit.html'; + break; case 'submit': @@ -354,6 +402,21 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $contactInfo = $this->updateEntry($contactID); + // Check if we have a good member ID + if ($contactInfo['fieldData']['ref_dest']) { + + // Get member information + $memberData = $Members->getEntry($contactInfo['fieldData']['ref_dest']); + + // Check that we have good member data + if (is_array($memberData) && isset($memberData['id']) && $memberData['id'] > 0) { + $memberID = $memberData['id']; + $haveMember = true; + $memberName = $memberData['name']; + } + + } + if ($contactInfo['status']) { $contactInfo = $this->editEntry(($_REQUEST['id']-0)); $contactUpdated = true; @@ -576,6 +639,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 'memberID' => $memberID, 'memberData' => $memberData, 'memberName' => $memberName, + 'membersList' => $membersList, 'refType' => $refType, 'refTypeName' => $refTypeName, 'haveContacts' => $haveContacts, @@ -583,7 +647,8 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 'numbContacts' => $numbContacts, 'contactID' => $contactID, 'contactInfo' => $contactInfo, - 'newContactExists' => $newContactExists, + 'newContactEmailExists' => $newContactEmailExists, + 'newContactUsernameExists' => $newContactUsernameExists, 'misMatchedWpUsers' => $misMatchedWpUsers, 'usernameChangedToWP' => $usernameChangedToWP, 'newContactCreated' => $newContactCreated, diff --git a/views/admin/contacts/edit.html b/views/admin/contacts/edit.html index cd2e216..20a353e 100644 --- a/views/admin/contacts/edit.html +++ b/views/admin/contacts/edit.html @@ -16,14 +16,21 @@ {/if} + {if $newContactEmailExists} +

NOTE: The Email address for this contact is already in use. Please check if they already are a contact in this system.

+ {/if} + {if $newContactUsernameExists} +

NOTE: The Login Username for this contact is already in use. Please check if they already are a contact in this system.

+ {/if} + {if $misMatchedWpUsers} +

NOTE: There is already a WordPress user with the requested Email address and a different user with the requested Login Username. Please select a different Login Username.

+ {/if} + + {if $option == 'edit' && !$contactID}

ERROR: Specified contact not found!

- - {elseif $newContactExists} - -

NOTE: The Email address or username for this contact is already in use. Please check if they already are a contact in this system.

{elseif $misMatchedWpUsers} @@ -109,7 +116,9 @@ + {if $haveMember} + {/if} {else} @@ -119,8 +128,22 @@ + {if $haveMember} - + + @@ -168,7 +191,7 @@ {if $option == 'create'} - + {else} @@ -621,7 +644,21 @@ window.location.replace("{$thisUrl}?page=glm-members-admin-menu-contacts&glm_action=index&option=delete&contact={$contactID}"); {/if} }); - + + // Set required status for E-Mail field based on permission settings + $('#contactRoleSelect').on('change', function() { + checkContactRoleSelect(); + }); + function checkContactRoleSelect() { + var role = $('#contactRoleSelect').val(); + if (role < 40) { + $('#emailRequiredForLoginContacts').addClass('glm-required'); + } else { + $('#emailRequiredForLoginContacts').removeClass('glm-required'); + } + } + checkContactRoleSelect(); + // Set masking for phone number fields - see http://digitalbush.com/projects/masked-input-plugin/ $.mask.definitions['e'] = "[A-Za-z0-9: ]"; $(".glm-phone-input").mask("999-999-9999? eeeeeeeeeee"); diff --git a/views/admin/contacts/index.html b/views/admin/contacts/index.html index 2094455..60eb773 100644 --- a/views/admin/contacts/index.html +++ b/views/admin/contacts/index.html @@ -121,7 +121,7 @@ var availableTags = [ {foreach $namesList as $e} - { label: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"} {$e.ref_dest_name|replace:'"':"'"}", value: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"}, {$e.ref_dest_name|replace:'"':"'"}", id: '{$e.id}', member: '{$e.ref_dest}' }, + { label: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"} {$e.ref_dest_name|replace:'"':"'"} ( username: {$e.username})", value: "{$e.fname|replace:'"':"'"} {$e.lname|replace:'"':"'"}, {$e.ref_dest_name|replace:'"':"'"}, {$e.username}", id: '{$e.id}', member: '{$e.ref_dest}' }, {/foreach} ]; -- 2.17.1
Contact For:{if $option=='create'}{$refTypeName}{else}{$contactInfo.fieldData.ref_type.name}{/if} - {$memberData.name} + {$memberData.name} + {else} + Contact For: + + {/if} + {if $contactInfo.fieldFail.ref_dest}

A {$terms.term_member_cap} was not selected.

{/if} +
Active:
Permissions: - {foreach from=$contactInfo.fieldData.contact_role.list item=v}
Email Address:Email Address: -
NOTE: This field is required for users who will have login privileges. +
NOTE: This field is only required for users who will have login privileges. {if $contactInfo.fieldFail.email}

{$contactInfo.fieldFail.email}

{/if}