$userDeleted = false;
$wpUserDeleted = false;
$contactMembers = array();
+ $newEmail = false;
+ $newEmailError = false;
$numbContacts = false;
$numbDisplayed = false;
$lastDisplayed = false;
$option = 'edit';
$view = 'edit.html';
+ // Check for a new E-Mail address submission
+ if (trim($_REQUEST['new_email']) != '') {
+
+ // Is it a valid format?
+ $newEmail = is_email(trim($_REQUEST['new_email']));
+ if (!$newEmail) {
+ $newEmailError = 'BAD_FORMAT';
+ $newEmail = $_REQUEST['new_email'];
+ } else {
+
+ // Sanitize submitted address
+ $newEmail2 = sanitize_email($newEmail);
+ if ($newEmail != $newEmail2) {
+ $newEmailError = 'BAD_CHARACTERS';
+ } else {
+
+ // Check for existing contact in Wordpress and Contacts using the new address
+ $contactCheck = $this->checkContact($newEmail);
+
+ if ($contactCheck['wordpressEmail'] || $contactCheck['contactsEmail']) {
+ $newEmailError = 'IN_USE';
+ } else {
+
+ // Update address for contact
+ $this->wpdb->query("
+ UPDATE ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ SET email = '$newEmail'
+ WHERE id = ".$contactID.";
+ ");
+
+
+ // Get the wordpress user ID
+ $wpUser = get_user_by('email', $contactInfo['fieldData']['email']);
+
+ // Update address for WordPress user
+ if ($wpUser->ID > 0) {
+ $user_id = wp_update_user( array( 'ID' => $wpUser->ID, 'user_email' => $newEmail ) );
+ }
+
+ // Display new address in current form
+ $contactInfo['fieldData']['email'] = $newEmail;
+ $newEmail = '';
+
+ }
+ }
+ }
+ }
+
break;
case 'delete':
'userDeleted' => $userDeleted,
'wpUserDeleted' => $wpUserDeleted,
'contactMembers' => $contactMembers,
+ 'new_email' => $newEmail,
+ 'newEmailError' => $newEmailError,
'numbDisplayed' => $numbDisplayed,
'lastDisplayed' => $lastDisplayed,
'paging' => $paging,
'limit' => $limit,
'namesList' => $namesList,
'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager']
-
);
// Return status, any suggested view, and any data to controller
public function modelAction($actionData = false)
{
- $option = 'edit';
+ $option = 'edit';
$contactUpdated = false;
$contactMembers = false;
- $membersList = false;
+ $membersList = false;
+ $newEmail = false;
+ $newEmailError = false;
$view = 'admin/profile/index.html';
}
- $option = 'edit';
+ $option = 'edit';
+ }
+ // Check for a new E-Mail address submission
+ if (trim($_REQUEST['new_email']) != '') {
+
+ // Is it a valid format?
+ $newEmail = is_email(trim($_REQUEST['new_email']));
+ if (!$newEmail) {
+ $newEmailError = 'BAD_FORMAT';
+ $newEmail = $_REQUEST['new_email'];
+ } else {
+
+ // Sanitize submitted address
+ $newEmail2 = sanitize_email($newEmail);
+ if ($newEmail != $newEmail2) {
+ $newEmailError = 'BAD_CHARACTERS';
+ } else {
+
+ // Check for existing contact in Wordpress and Contacts using the new address
+ $contactCheck = $this->checkContact($newEmail);
+ if ($contactCheck['wordpressEmail'] || $contactCheck['contactsEmail']) {
+ $newEmailError = 'IN_USE';
+ } else {
+
+ // Update address for contact
+ $this->wpdb->query("
+ UPDATE ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts
+ SET email = '$newEmail'
+ WHERE id = ".$this->contactID.";
+ ");
+
+ // Update address for WordPress user
+ if ($this->wpUserID > 0) {
+ $user_id = wp_update_user( array( 'ID' => $this->wpUserID, 'user_email' => $newEmail ) );
+ }
+
+ // Display new address in current form
+ $this->contactInfo['fieldData']['email'] = $newEmail;
+ $newEmail = '';
+
+ }
+ }
+ }
}
break;
// Compile template data
$templateData = array(
- 'option' => $option,
- 'contactID' => $this->contactID,
- 'contactInfo' => $this->contactInfo,
- 'contactUpdated' => $contactUpdated,
- 'contactMembers' => $contactMembers,
- 'membersList' => $membersList,
- 'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager']
+ 'option' => $option,
+ 'contactID' => $this->contactID,
+ 'contactInfo' => $this->contactInfo,
+ 'contactUpdated' => $contactUpdated,
+ 'contactMembers' => $contactMembers,
+ 'membersList' => $membersList,
+ 'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager'],
+ 'new_email' => $newEmail,
+ 'newEmailError' => $newEmailError
);
// Return status, any suggested view, and any data to controller
return array(
- 'status' => true,
- 'modelRedirect' => false,
- 'view' => $view,
- 'data' => $templateData
+ 'status' => true,
+ 'modelRedirect' => false,
+ 'view' => $view,
+ 'data' => $templateData
);
}
{if $option == 'create'}
<h2 class="glm-left">Add New Contact</h2>
{else}
+ {if $newEmailError != ''}
+ <h2 class="glm-required glm-flash-updated">NOTE: Your new E-Mail address was not valid. Please see below.</h2>
+ {else}
{if $contactUpdated}<h2 class="glm-notice glm-flash-updated">Contact Updated</h2>{/if}
+ {/if}
<a id="deleteContactButton" class="button button-primary glm-button glm-right">Delete this Contact</a>
<div id="deleteContactDialog" class="glm-dialog-box" title="Delete Contact">
<center>
{if $contactInfo.fieldFail.access}<p>{$contactInfo.fieldFail.access}</p>{/if}
</td>
</tr>
- <tr>
{if $option == 'create'}
+ <tr>
<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 only required for users who will have login privileges.
{if $contactInfo.fieldFail.email}<p>{$contactInfo.fieldFail.email}</p>{/if}
</td>
+ </tr>
{else}
- <th>Email Address::</th>
- <td>{$contactInfo.fieldData.email}</td>
- {/if}
+
+ <tr><th>Email Address::</th><td>{$contactInfo.fieldData.email}</td></tr>
+ <tr>
+ <th>New Email Address:</th>
+ <td {if $newEmailError != ''}class="glm-form-bad-input"{/if}>
+ <input type="text" name="new_email" value="{$new_email}" class="glm-form-text-input-short" placeholder="(ex: name@domain.com)">
+ {if $newEmailError == 'BAD_CHARACTERS'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted contained invalid characters. {$new_email}
+ Please check the address and submit again.
+ </span>
+ {/if}
+ {if $newEmailError == 'BAD_FORMAT'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted is formatted incorrectly. An example of a correctly formatted E-Mail address is "name@domain.com".
+ Please check the address and submit again.
+ </span>
+ {/if}
+ {if $newEmailError == 'IN_USE'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted is already in use for this site.
+ You may only change your address to one that is not currently in use.
+ </span>
+ {/if}
+ <br>To change your E-Mail address, enter your new address here. This address must not be used by any other contact or user in this site.
+ </td>
</tr>
+
+ {/if}
<tr>
{if $option == 'create'}
{if apply_filters('glm_members_permit_admin_profile_index_edit_profile', true)}
- <p>
<b>Why are there items below that I can't edit?</b><br>
Some of the information below, such as your Username and Email address, are used by the system to identify your profile and may not be altered after the contact profile has been created.
There are also certain items that relate to permissions you have to access and change other data.
</p>
- {if $contactUpdated}<h2 class="glm-notice glm-flash-updated">Contact Updated</h2>{/if}
+ {if $newEmailError != ''}
+ <h2 class="glm-required glm-flash-updated">NOTE: Your new E-Mail address was not valid. Please see below.</h2>
+ {else}
+ {if $contactUpdated}
+ <h2 class="glm-notice glm-flash-updated">Contact Updated</h2>
+ {/if}
+ {/if}
+
+ <p> </p>
<form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
<input type="hidden" name="glm_action" value="index">
<input type="hidden" name="option" value="submit">
<tr><th>Contact Type:</th><td>{$contactInfo.fieldData.contact_type.name}</td></tr>
<tr><th>Permissions:</th><td>{$contactInfo.fieldData.contact_role.name}</td></tr>
<tr><th class="glm-nowrap">Display/Moderate/Archive:</th><td>{$contactInfo.fieldData.access.name}</td></tr>
+
<tr><th>Email Address::</th><td>{$contactInfo.fieldData.email}</td></tr>
+ <tr>
+ <th>New Email Address:</th>
+ <td {if $newEmailError != ''}class="glm-form-bad-input"{/if}>
+ <input type="text" name="new_email" value="{$new_email}" class="glm-form-text-input-short" placeholder="(ex: name@domain.com)">
+ {if $newEmailError == 'BAD_CHARACTERS'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted contained invalid characters. {$new_email}
+ Please check the address and submit again.
+ </span>
+ {/if}
+ {if $newEmailError == 'BAD_FORMAT'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted is formatted incorrectly. An example of a correctly formatted E-Mail address is "name@domain.com".
+ Please check the address and submit again.
+ </span>
+ {/if}
+ {if $newEmailError == 'IN_USE'}
+ <br><span style="color: white;">
+ The E-Mail address you submitted is already in use for this site.
+ You may only change your address to one that is not currently in use.
+ </span>
+ {/if}
+ <br>To change your E-Mail address, enter your new address here. This address must not be used by any other contact or user in this site.
+ </td>
+ </tr>
+
<tr><th>Login Username:</th><td>{$contactInfo.fieldData.username}</td></tr>
<tr>
<th {if $contactInfo.fieldRequired.password}class="glm-required"{/if}>Login password:</th>