$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;
}
- // 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;
}
+ // 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);
}
$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;
$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']
$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) {
$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':
$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;
'memberID' => $memberID,
'memberData' => $memberData,
'memberName' => $memberName,
+ 'membersList' => $membersList,
'refType' => $refType,
'refTypeName' => $refTypeName,
'haveContacts' => $haveContacts,
'numbContacts' => $numbContacts,
'contactID' => $contactID,
'contactInfo' => $contactInfo,
- 'newContactExists' => $newContactExists,
+ 'newContactEmailExists' => $newContactEmailExists,
+ 'newContactUsernameExists' => $newContactUsernameExists,
'misMatchedWpUsers' => $misMatchedWpUsers,
'usernameChangedToWP' => $usernameChangedToWP,
'newContactCreated' => $newContactCreated,
</ul>
{/if}
+ {if $newContactEmailExists}
+ <h4><span class="glm-error">NOTE:</span> The Email address for this contact is already in use. Please check if they already are a contact in this system.</h3>
+ {/if}
+ {if $newContactUsernameExists}
+ <h4><span class="glm-error">NOTE:</span> The Login Username for this contact is already in use. Please check if they already are a contact in this system.</h3>
+ {/if}
+ {if $misMatchedWpUsers}
+ <h4><span class="glm-error">NOTE:</span> 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.</h3>
+ {/if}
+
+
<!-- Check for invalid contact ID to edit -->
{if $option == 'edit' && !$contactID}
<h3><span class="glm-error">ERROR:</span> Specified contact not found!</h3>
-
- {elseif $newContactExists}
-
- <h4><span class="glm-warning">NOTE:</span> The Email address or username for this contact is already in use. Please check if they already are a contact in this system.</h3>
{elseif $misMatchedWpUsers}
<input type="hidden" name="option" value="addNew">
<input type="hidden" name="create_time" value="now">
<input type="hidden" name="ref_type" value="{$refType}">
+ {if $haveMember}
<input type="hidden" name="ref_dest" value="{$memberData.id}">
+ {/if}
{else}
<input type="hidden" name="option" value="submit">
<input type="hidden" name="contact" value="{$contactInfo.fieldData.id}">
<table class="glm-admin-table glm-shrink">
<tr>
+ {if $haveMember}
<th>Contact For:</th>
- <td>{if $option=='create'}{$refTypeName}{else}{$contactInfo.fieldData.ref_type.name}{/if} - {$memberData.name}</td>
+ <td>
+ {$memberData.name}
+ {else}
+ <th class="glm-required">Contact For:</th>
+ <td {if $contactInfo.fieldFail.ref_dest}class="glm-form-bad-input"{/if}>
+ <select name="ref_dest">
+ <option value="">( Select a {$terms.term_member_cap} )</option>
+ {foreach $membersList as $m}
+ <option value="{$m.id}"{if isset($m.selected)} selected="selected"{/if}>{$m.name}</option>
+ {/foreach}
+ </select>
+ {/if}
+ {if $contactInfo.fieldFail.ref_dest}<p>A {$terms.term_member_cap} was not selected.</p>{/if}
+ </td>
</tr>
<tr>
<th>Active:</th>
<tr>
<th {if $contactInfo.fieldRequired.contact_role}class="glm-required"{/if}>Permissions:</th>
<td {if $contactInfo.fieldFail.contact_role}class="glm-form-bad-input"{/if}>
- <select name="contact_role">
+ <select id="contactRoleSelect" name="contact_role">
{foreach from=$contactInfo.fieldData.contact_role.list item=v}
<option value="{$v.value}"{if $v.default} selected="selected"{/if}>
{$v.name}
</tr>
<tr>
{if $option == 'create'}
- <th {if $contactInfo.fieldRequired.email}class="glm-required"{/if}>Email Address:</th>
+ <th id="emailRequiredForLoginContacts" class="glm-required">Email Address:</th>
<td {if $contactInfo.fieldFail.email}class="glm-form-bad-input"{/if}>
<input type="text" name="email" value="{$contactInfo.fieldData.email}" class="glm-form-text-input-medium" placeholder="(ex: name@domain.com)">
- <br><span class="glm-notice">NOTE:</span> This field is required for users who will have login privileges.
+ <br><span class="glm-notice">NOTE:</span> This field is only required for users who will have login privileges.
{if $contactInfo.fieldFail.email}<p>{$contactInfo.fieldFail.email}</p>{/if}
</td>
{else}
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");