defines.php - Added a secret string to use for the idCheck when changing to another member.
Added output of member selection to member dashoard via a filter.
Added management and display of which members a contact user may manage.
Added checks to make sure nobody tampers with member IDs for selection.
define('GLM_MEMBERS_CONTACTS_PLUGIN_MEDIA_PATH', $WPUploadDir['basedir'].'/'.GLM_MEMBERS_CONTACTS_PLUGIN_SLUG);
define('GLM_MEMBERS_CONTACTS_PLUGIN_IMAGES_PATH', GLM_MEMBERS_CONTACTS_MAIN_PLUGIN_PATH.'/images');
+define('GLM_MEMBERS_CONTACTS_MD5_SECRET', 'Member4Secret7contacts#'.date('m/d/Y'));
+
?>
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Select member to manage from list of available memmbers assigned to contact
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+// Load Contacts data abstract
+require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php';
+
+/*
+ * This class sets the ID of a member selected for the contact to manage.
+ * Each member contact that can manage their member may also be assigned a
+ * list of other members they may manage as well. This ajax process is called
+ * to set the currently selected member.
+ */
+class GlmMembersAdmin_ajax_selectContactMember extends GlmDataContacts
+{
+
+ /**
+ * 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 modelAction takes an AJAX request to produce certain member click-through
+ * and detail page views graphs and outputs the desired result.
+ *
+ * This model action does not return, it simply does it's work then calls die();
+ *
+ * @param $actionData
+ *
+ * Echos JSON string as response and does not return
+ */
+ public function modelAction ($actionData = false)
+ {
+
+ // Get the wordpress user ID
+ $this->wpUserID = ($this->config['loggedInUser']['wpUser']['ID'] - 0);
+
+ // Check that user is a contact user
+ if ($this->config['loggedInUser']['contactUser']) {
+
+ // Get contact user ID and validate it as positive Integer
+ $this->contactID = ($this->config['loggedInUser']['contactUser']['ID'] - 0);
+ if ($this->contactID > 0 && isset($_REQUEST['member']) && isset($_REQUEST['idCheck'])) {
+
+ $selectMember = $_REQUEST['member']-0;
+ $idCheck = $_REQUEST['idCheck'];
+
+ // If we have a selected member and the idCheck md5 matches, then we can change to the selected member
+ if ($selectMember > 0 && $idCheck == md5(GLM_MEMBERS_CONTACTS_MD5_SECRET.$selectMember)) {
+ update_user_meta($this->wpUserID, 'glmMembersContactMemberSelected', $selectMember);
+ $view = 'admin/profile/contactMemberSelect.html';
+ } else {
+ $memberSelectFail = true;
+ }
+
+ }
+
+ }
+
+ wp_die();
+
+ }
+
+}
* @access public
*/
public $config;
+ /**
+ * Member Data class
+ *
+ * @var $Members
+ * @access private
+ *
+ */
+ public $Members;
+ /**
+ * Member ID
+ *
+ * @var $memberID
+ * @access private
+ *
+ */
+ public $memberID;
/*
* Constructor
$refType = false;
$refTypeName = false;
$haveMember = false;
- $memberID = false;
+ $this->memberID = false;
$memberData = false;
$memberName = false;
$membersList = false;
$haveFilter = false;
$userDeleted = false;
$wpUserDeleted = false;
+ $contactMembers = array();
$numbContacts = false;
$numbDisplayed = false;
AND ref_dest = ".$contactUser['ref_dest'];
// Also set their member as the current one
- $memberID = $contactUser['ref_dest'];
+ $this->memberID = $contactUser['ref_dest'];
}
}
if (isset($_REQUEST['member'])) {
// Clean up the member ID and store it in wordpress option
- $memberID = $_REQUEST['member']-0;
- update_option('glmMembersDatabaseMemberID', $memberID);
+ $this->memberID = $_REQUEST['member']-0;
+ update_option('glmMembersDatabaseMemberID', $this->memberID);
// Otherwise check if a member is stored in wordpress option
} else {
- $memberID = get_option('glmMembersDatabaseMemberID', false);
+ $this->memberID = get_option('glmMembersDatabaseMemberID', false);
}
}
// Load members data class
require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
- $Members = new GlmDataMembers($this->wpdb, $this->config);
+ $this->Members = new GlmDataMembers($this->wpdb, $this->config);
// If we have a member ID - Get Member information
- if ($memberID) {
- $memberData = $Members->getEntry($memberID);
+ if ($this->memberID) {
+ $memberData = $this->Members->getEntry($this->memberID);
}
// Check that we have good member data
// If we don't have a member, the get a list of member IDs for selection
if (!$haveMember) {
- $membersList = $Members->getList('TRUE', 'name');
+ $membersList = $this->Members->geSimpleMemberstList('TRUE', 'name');
}
$view = 'edit.html';
case 'edit':
+ // Get members list for member selection and additional member management selection
+ $membersList = $this->Members->getSimpleMembersList('TRUE', 'name');
+
// 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 ($contactInfo['fieldData']['ref_dest']) {
// Get member information
- $memberData = $Members->getEntry($contactInfo['fieldData']['ref_dest']);
+ $memberData = $this->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'];
+ $this->memberID = $memberData['id'];
$haveMember = true;
$memberName = $memberData['name'];
}
}
+ // If there's a good member number for this contact - Get the list members this contact can access
+ if ($haveMember) {
+ $contactMembers = $this->checkContactMembers($contactInfo);
+ }
+
}
// If the contact wasn't found, then set ID to false
if ($contactInfo['fieldData']['ref_dest']) {
// Get member information
- $memberData = $Members->getEntry($contactInfo['fieldData']['ref_dest']);
+ $memberData = $this->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'];
+ $this->memberID = $memberData['id'];
$haveMember = true;
$memberName = $memberData['name'];
}
}
+ // If there's a good member number for this contact - Get/Update the list members this contact can access
+ if ($haveMember) {
+ $membersList = $this->Members->getSimpleMembersList('TRUE', 'name');
+ $contactMembers = $this->checkContactMembers($contactInfo, true);
+ }
+
$option = 'edit';
$view = 'edit.html';
// Only list member contacts for the selected member
if ($haveMember) {
- $where .= " AND ref_type = ".$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID;
+ $where .= " AND ref_type = ".$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$this->memberID;
}
-
-
// Filter by text string supplied
- if (isset($_REQUEST['filterText'])) {
- $filterText = esc_sql($_REQUEST['filterText']);
- $where .= " AND (
- lname LIKE '%$filterText%' OR
- fname LIKE '%$filterText%' OR
- org LIKE '%$filterText%' OR
- descr LIKE '%$filterText%'
- )";
- $haveFilter = true;
- }
-
- // Get the total number of contacts listed
-
- $numbContacts = $this->getStats($where);
-
- // If the number of events is less than a page, don't do paging
- if ($numbContacts <= $limit) {
- $paging = false;
- }
+ if (isset($_REQUEST['filterText'])) {
+ $filterText = esc_sql($_REQUEST['filterText']);
+ $where .= " AND (
+ lname LIKE '%$filterText%' OR
+ fname LIKE '%$filterText%' OR
+ org LIKE '%$filterText%' OR
+ descr LIKE '%$filterText%'
+ )";
+ $haveFilter = true;
+ }
- // Get full list of names matching this where clause for search box
- $namesList = $this->getIdName($where);
+ // Get the total number of contacts listed
- // Check if we're doing paging
- if (isset($_REQUEST['pageSelect'])) {
+ $numbContacts = $this->getStats($where);
- // If request is for Next
- if ($_REQUEST['pageSelect'][0] == 'N') {
- $newStart = $_REQUEST['nextStart'] - 0;
+ // If the number of events is less than a page, don't do paging
+ if ($numbContacts <= $limit) {
+ $paging = false;
+ }
- // Otherwise it must be Previous
- } else {
- $newStart = $_REQUEST['prevStart'] - 0;
- }
+ // Get full list of names matching this where clause for search box
+ $namesList = $this->getIdName($where);
- if ($newStart > 0) {
- $start = $newStart;
- }
- }
+ // Check if we're doing paging
+ if (isset($_REQUEST['pageSelect'])) {
- // Get list of contacts
- $contactsList = $this->getSimplified($where, false, 'lname, fname', true, 'id', $start, $limit );
+ // If request is for Next
+ if ($_REQUEST['pageSelect'][0] == 'N') {
+ $newStart = $_REQUEST['nextStart'] - 0;
- if ($contactsList != false) {
+ // Otherwise it must be Previous
+ } else {
+ $newStart = $_REQUEST['prevStart'] - 0;
+ }
- // Get paging results
- $numbDisplayed = $contactsList['returned'];
- $lastDisplayed = $contactsList['last'];
- if ($start == 1) {
- $prevStart = false;
- } else {
- $prevStart = $start - $limit;
- if ($start < 1) {
- $start = 1;
+ if ($newStart > 0) {
+ $start = $newStart;
+ }
}
- }
- if ($contactsList['returned'] == $limit) {
- $nextStart = $start + $limit;
- }
- if (count($contactsList['list']) > 0) {
- $haveContacts = true;
- }
+ // Get list of contacts
+ $contactsList = $this->getSimplified($where, false, 'lname, fname', true, 'id', $start, $limit );
- }
+ if ($contactsList != false) {
- /* Left in case we want to use this
-
- // Filter by text string supplied
- if (isset($_REQUEST['filterText'])) {
- $filterText = esc_sql($_REQUEST['filterText']);
- $where .= " AND (
- T.lname LIKE '%$filterText%' OR
- T.fname LIKE '%$filterText%' OR
- T.org LIKE '%$filterText%' OR
- T.descr LIKE '%$filterText%'
- )";
- $haveFilter = true;
- }
-
- // Check if this is a request to show archived contacts
- if (!isset($_REQUEST['filterArchived'])) {
- $where .= " AND T.access != ".$this->config['access_numb']['Archived'];
- $filterArchived = false;
- } else {
- $filterArchived = true;
- $haveFilter = true;
- }
-
- // Try to get list of contacts
- $contacts = $this->getList($where);
+ // Get paging results
+ $numbDisplayed = $contactsList['returned'];
+ $lastDisplayed = $contactsList['last'];
+ if ($start == 1) {
+ $prevStart = false;
+ } else {
+ $prevStart = $start - $limit;
+ if ($start < 1) {
+ $start = 1;
+ }
+ }
+ if ($contactsList['returned'] == $limit) {
+ $nextStart = $start + $limit;
+ }
- if ($contacts !== false) {
- if (count($contacts) > 0) {
+ if (count($contactsList['list']) > 0) {
$haveContacts = true;
}
- }
-*/
+ }
break;
}
'loggedInMember' => $loggedInMember,
'fromMemberMenu' => $fromMemberMenu,
'haveMember' => $haveMember,
- 'memberID' => $memberID,
+ 'memberID' => $this->memberID,
'memberData' => $memberData,
'memberName' => $memberName,
'membersList' => $membersList,
'haveFilter' => $haveFilter,
'userDeleted' => $userDeleted,
'wpUserDeleted' => $wpUserDeleted,
+ 'contactMembers' => $contactMembers,
'numbDisplayed' => $numbDisplayed,
'lastDisplayed' => $lastDisplayed,
'nextStart' => $nextStart,
'start' => $start = 1,
'limit' => $limit,
- 'namesList' => $namesList
+ 'namesList' => $namesList,
+ 'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager']
);
}
}
}
+
+ /*
+ * Check for additional Members this contact can access
+ *
+ * @param $contactInfo array Contact information array
+ * @param $memberID integer ID of contact's member
+ *
+ * @return array Array of Member IDs with names
+ */
+ public function checkContactMembers($contactInfo, $update = false)
+ {
+
+ // Attempt to get WordPress user data
+ $contactCheck = $this->checkContact($contactInfo['fieldData']['email']);
+ $wpUser = new WP_User($contactCheck['wpUserEmail']->ID);
+ $wpUserID = $wpUser->ID;
+
+ $contactMembersListd = '';
+
+ // If we have a valid WordPress user ID
+ if ($wpUserID) {
+
+ // If there's an update request and the current user can manage members
+ if (apply_filters('glm_members_menu_members', $update)) {
+
+ // And if there's contact member data
+ if ($_REQUEST['contactMembers'] && count($_REQUEST['contactMembers'])) {
+
+ // Update the contact members selection
+ $contactMembersList = implode(',', $_REQUEST['contactMembers']);
+ }
+
+ } else {
+
+ // Get contact's list of members they can manage
+ $contactMembersList = get_user_meta($wpUserID, 'glmMembersContactMembers', true);
+
+ }
+
+ }
+
+ // Always add the user's primary member to the list
+ if ($contactMembersList != '') {
+ $contactMembersList .= ',';
+ }
+ $contactMembersList .= $this->memberID; // Always include contact's main member
+
+ // Store the list of ID's for members this user can access in user meta data
+ update_user_meta($wpUserID, 'glmMembersContactMembers', $contactMembersList);
+
+ // Get a list of contact members with names and other basic info from the list of ids
+ $contactMembers = $this->Members->getIdName("ID in (".$contactMembersList.")");
+
+ // Get currently selected member, if not set yet set it to their primary member
+ $currentContactMember = get_user_meta($wpUserID, 'glmMembersContactMemberSelected', true);
+ if (empty($currentContactMember)) {
+ update_user_meta($wpUserID, 'glmMembersContactMemberSelected', $this->memberID);
+ }
+
+ // Set currently selected member as active
+ if (isset($contactMembers[$currentContactMember])) {
+ $contactMembers[$currentContactMember]['selected'] = true;
+ }
+
+ return $contactMembers;
+
+ }
}
?>
\ No newline at end of file
* @access public
*/
public $memberID = false;
+ /**
+ * Members Data Class
+ *
+ * @var $Members
+ * @access public
+ */
+ public $Members = false;
/**
* Contact ID
*
* @access public
*/
public $contactID = false;
-
+ /**
+ * WordPress User ID
+ *
+ * @var $wpUserID
+ * @access public
+ */
+ public $wpUserID = false;
/*
* Constructor
public function modelAction($actionData = false)
{
+ $option = 'edit';
$contactUpdated = false;
+ $contactMembers = false;
+ $membersList = false;
+ $view = 'admin/profile/index.html';
+
$validOptions = array(
'edit',
- 'submit'
+ 'submit',
+ 'getContactMembersList'
);
+ require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
+ $this->Members = new GlmDataMembers($this->wpdb, $this->config);
+
+ // Check for desired option
+ if ($actionData['selectMember'] > 0) {
+ $option = 'memberSelect';
+ } elseif (is_array($actionData) && isset($actionData['option'])) {
+ $option = $actionData['option'];
+ } elseif (isset($_REQUEST['option']) && in_array($_REQUEST['option'], $validOptions)) {
+ $option = $_REQUEST['option'];
+ }
+
+ // Get the wordpress user ID
+ $this->wpUserID = ($this->config['loggedInUser']['wpUser']['ID'] - 0);
+
// Check that user is a contact user
if ($this->config['loggedInUser']['contactUser']) {
$this->contactID = ($this->config['loggedInUser']['contactUser']['ID'] - 0);
if ($this->contactID > 0) {
- // Check for valid option
- $option = 'edit';
- if (isset($_REQUEST['option']) && in_array($_REQUEST['option'], $validOptions)) {
- $option = $_REQUEST['option'];
- }
-
-
// Perform selected page option
switch($option) {
// Check for password changes and update Wordpress user
if (trim($_REQUEST['password']) != '') {
- // Get the wordpress user ID
- $wpUserID = ($this->config['loggedInUser']['wpUser']['ID'] - 0);
-
// If we got a good user, set the new password
- if ($wpUser > 0) {
- wp_set_password($_REQUEST['password'], $wpUserID);
+ if ($this->wpUserID) {
+ wp_set_password($_REQUEST['password'], $this->wpUserID);
}
}
break;
+ case 'getContactMembersList':
+
+ // Simply change the view to produce the member selection list and fall through
+ $view = 'admin/profile/contactMemberSelect.html';
+
default:
case 'edit':
}
- } // have contact ID
+ $contactMembers = $this->getContactMembers($this->contactInfo, $this->wpUserID);
- } // is contact user
+ } // have contact ID
+
+ // If not contact user
+ } else {
+ die();
+ }
// Compile template data
$templateData = array(
'option' => $option,
'contactID' => $this->contactID,
'contactInfo' => $this->contactInfo,
- 'contactUpdated' => $contactUpdated
+ 'contactUpdated' => $contactUpdated,
+ 'contactMembers' => $contactMembers,
+ 'membersList' => $membersList,
+ 'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager']
);
// Return status, any suggested view, and any data to controller
return array(
'status' => true,
'modelRedirect' => false,
- 'view' => 'admin/profile/index.html',
+ 'view' => $view,
'data' => $templateData
);
}
}
+ /*
+ * Check for additional Members this contact can access
+ *
+ * @param $contactInfo array Contact information array
+ * @param $spUserID integer WordPress user ID
+ *
+ * @return array Array of Member IDs with names
+ */
+ public function getContactMembers($contactInfo, $wpUserID = false)
+ {
+ $contactMembers = false;
+
+ // If we have a valid WordPress user ID
+ if ($this->wpUserID) {
+
+ // Get contact's list of members they can manage
+ $contactMembersList = get_user_meta($this->wpUserID, 'glmMembersContactMembers', true);
+
+ // Get a list of contact members with names and other basic info from the list of ids
+ $contactMembers = $this->Members->getIdName("ID in (".$contactMembersList.")");
+
+ // Generate MD5 check string for each member ID
+ foreach ($contactMembers as $key => $value) {
+ $contactMembers[$key]['idCheck'] = md5(GLM_MEMBERS_CONTACTS_MD5_SECRET.$value['id']);
+ }
+
+ }
+
+ // Get currently selected member, if not set yet set it to their primary member
+ $currentContactMember = get_user_meta($this->wpUserID, 'glmMembersContactMemberSelected', true);
+
+ if (empty($currentContactMember)) {
+ $currentContactMember = $this->config['loggedInUser']['contactUser']['ref_dest'];
+ update_user_meta($this->wpUserID, 'glmMembersContactMemberSelected', $currentContactMember);
+ }
+
+ // Set currently selected member as active
+ $contactMembers[$currentContactMember]['selected'] = true;
+
+ return $contactMembers;
+
+ }
}
?>
\ No newline at end of file
2
);
+// Add filter to provide contact member selection if contact user is logged in and is an entity manager.
+add_filter(
+ 'glm_members_admin_member_index_bottomOfMemberSummary',
+ function( $content, $memberId ){
+
+ // If this is a contact user and they are an entity manager, there may be other members they can manage
+ if ($this->config['loggedInUser']['contactUser'] && $this->config['loggedInUser']['contactUser']['role'] == $this->config['contact_role_numb']['EntityManager']) {
+
+ // Get any newly selected member ID
+ $selectMember = false;
+ if (isset($_REQUEST['memberSelect'])) {
+ $selectMember = $_REQUEST['memberSelect']-0;
+ }
+
+ // Get any list of members this contact may select and return with that.
+ $content = $this->controller( 'profile', 'index', array('option' => 'getContactMembersList', 'selectMember' => $selectMember) );
+ return $content;
+
+ }
+
+ // Otherwise this is not a contact user so we don't need the contact member list
+ return '';
+ },
+ 10,
+ 2
+);
+
+
?>
return false;
}
+ // If the current contact user is an entity manager (who might be able to manage other specific members)
+ if ($contactInfo['contact_role']['value'] == $config['contact_role_numb']['EntityManager']) {
+
+ // Get the list of available contact members
+ $contactMembersList = explode(',',get_user_meta($wpUserID, 'glmMembersContactMembers', true));
+
+ // Check for contact member selection override
+ $selectedContactMember = get_user_meta($wpUserID, 'glmMembersContactMemberSelected', true);
+
+ // Check if the currently selected Contact member is not in our contact members list
+ if (!in_array($selectedContactMember, $contactMembersList)) {
+
+ // Set the selected Contact Member to the contact's default member
+ $selectedContactMember = $contactInfo['ref_dest'];
+ update_user_meta($wpUserID, 'glmMembersContactMemberSelected', $selectedContactMember);
+
+ }
+
+ // If there's now a selected Contact Member, then make that our active member
+ if ($selectedContactMember > 0) {
+ $contactInfo['ref_dest'] = $selectedContactMember;
+ }
+
+ }
+
// Return array with base data on this contact that might be needed by this add-on
$loggedInUser['contactUser'] = array(
'ID' => $contactID,
global $config;
$user = $config['loggedInUser']['contactUser'];
- // If there's a logged in contact user and they are ref_type "Member", then return that member ID
- if ($user && $user['ref_type'] == $config['ref_type_numb']['Member']) {
+ // If there's a logged in contact user who is an entity manager and they are ref_type "Member", then return that member ID
+ if ($user && $user['role'] == $config['contact_role_numb']['EntityManager'] && $user['ref_type'] == $config['ref_type_numb']['Member']) {
return $user['ref_dest'];
}
$glmMembersContactsAddOnValidActions = array(
'adminActions' => array(
+ 'ajax' => array(
+ 'selectContactMember' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ ),
'members' => array(
'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
),
{if $contactInfo.fieldFail.fax}<p>{$contactInfo.fieldFail.fax}</p>{/if}
</td>
</tr>
+ <tr>
+ <th>Access to Members</th>
+ <td id="accessToMemberSelection" class="glm-item-container">
+ {if $membersList && apply_filters('glm_members_menu_members',true)}
+ <!-- Other Member Selection -->
+ <select name="memberSelect" id="memberSelect">
+ <option id="memberName" value=""></option>
+ {foreach $membersList as $m}
+ {if $m.id != $memberID}
+ <option value="{$m.id}">
+ {$m.name}
+ </option>
+ {/if}
+ {/foreach}
+ </select> Select a member to add.<br>
+ <div id="selectedMembers" class="glm-dynSelect-box">
+ {if $contactMembers}
+ {foreach $contactMembers as $m}
+ <div data-id="{$m.id}" class="glm-dynSelect-item glm-members-members">
+ {$m.name}
+ {if $m.id != $memberID}
+ <span data-id="{$m.id}" class="glm-dynSelect-delete membDelete">X</span>
+ <input type="hidden" name="contactMembers[{$m.id}]" value="{$m.id}">
+ {else}
+ (Primary {$terms.term_member_cap})
+ {/if}
+ </div>
+ {/foreach}
+ {/if}
+ </div>
+ {else}
+ {if $contactMembers}
+ <input type="hidden" name="contactMembers[0]" value="0"> <!-- flag to not update contact members list -->
+ {foreach $contactMembers as $m}
+ <div data-id="{$m.id}" class="glm-dynSelect-item">
+ {$m.name}
+ </div>
+ {/foreach}
+ {/if}
+ {/if}
+ </td>
+ <td id="accessToAllMembers" class="glm-hidden">
+ This contact has no access or can manage all members, so no selection is needed here.
+ </td>
+ </tr>
<tr>
<th {if $contactInfo.fieldRequired.notes}class="glm-required"{/if}>Notes:</th>
<td {if $contactInfo.fieldFail.notes}class="glm-form-bad-input"{/if}>
// 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");
+ $(".glm-phone-input").mask("(999) 999-9999? eeeeeeeeeee");
// Flash certain elements for a short time after display
$(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+{if $membersList && apply_filters('glm_members_menu_members',true)}
+ // Action to select a member for the Other Members field
+ $('#memberSelect').change( function() {
+
+ // Get the ID and name of the member
+ var membValue = $('#memberSelect').val();
+ var membName = $('#memberSelect').find(':selected').text();
+ // Check if the member has already been added
+ var found = false;
+ $(".glm-members-members").each( function() {
+ var id = $(this).attr('data-id');
+ if (id == membValue) {
+ found = true;
+ }
+ });
+
+ // If not found, Add the category
+ if (!found) {
+ $('#selectedMembers').append('<div data-id="' + membValue
+ + '" class="glm-dynSelect-item glm-members-members">'
+ + membName.trim() + ' <span class="glm-dynSelect-delete membDelete">X</span>'
+ + '<input type="hidden" name="contactMembers[' + membValue + ']" value="' + membValue + '"></div>');
+ }
+
+ // Reset picklist
+ $('#memberSelect').val('');
+
+ });
+{/if}
+
+ // Action to de-select a member from the Other Members filed
+ $('.membDelete').live('click', function() {
+ $(this).parent().remove();
+ });
+
+ // Check whether contact can manage all members
+ function checkContactMembersEdit() {
+ var permissionType = $('#contactRoleSelect').val();
+ if (permissionType == {$EntityManagerRole}) {
+ $('#accessToAllMembers').addClass('glm-hidden');
+ $('#accessToMemberSelection').removeClass('glm-hidden');
+ } else {
+ $('#accessToAllMembers').removeClass('glm-hidden');
+ $('#accessToMemberSelection').addClass('glm-hidden');
+ }
+ }
+
+ checkContactMembersEdit();
+ $('#contactRoleSelect').on('change', checkContactMembersEdit);
+
});
</script>
--- /dev/null
+<p>
+{if count($contactMembers) > 1}
+<h3>Change to {$terms.term_member_cap}: <select id="contactMembersSelection" name="contactMembers">
+ {if $contactMembers}
+ {foreach $contactMembers as $m}
+ <option value="{$m.id}" data-idCheck="{$m.idCheck}"{if isset($m.selected) && $m.selected} selected{/if}>
+ {$m.name}
+ </div>
+ {/foreach}
+ {/if}
+</select>
+</h3>
+</p>
+{/if}
+<script type="text/javascript">
+ jQuery(document).ready(function($) {
+
+ $('#contactMembersSelection').on('change', function() {
+ var toMember = $(this).val();
+ var idCheck = $('#contactMembersSelection option:selected').attr('data-idCheck');
+
+ // Send AJAX action to update selected member
+ $.ajax({
+ url: "{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=selectContactMember&member=" + toMember + "&idCheck=" + idCheck
+ })
+ .done(function() {
+ window.location.replace("{$thisUrl}?page={$thisPage}&glm_action=index&option=edit");
+ });
+
+ });
+
+ });
+</script>
+
{if $contactInfo.fieldFail.fax}<p>{$contactInfo.fieldFail.fax}</p>{/if}
</td>
</tr>
+ <tr id="accessToMembers" class="glm-hidden">
+ <th>Access to Members</th>
+ <td class="glm-item-container">
+ {if $contactMembers}
+ {foreach $contactMembers as $m}
+ <div data-id="{$m.id}" class="glm-dynSelect-item glm-members-members">
+ {$m.name}
+ </div>
+ {/foreach}
+ {/if}
+ </td>
+ </tr>
+
+
</table>
<p><span class="glm-required">*</span> Required</p>
<input type="submit" name="Add new {$terms.term_member}">
<th>Web Address (URL):</th>
<td>
{if $contactInfo.fieldData.url}
- <a href="http://{$contactInfo.fieldData.url}" target="urlTarget">{$contactInfo.fieldData.url}</a>
+ <a href="http://{$contactInfo.fieldData.url}" target="urlaccessToMembersTarget">{$contactInfo.fieldData.url}</a>
{/if}
</td>
</tr>
// Flash certain elements for a short time after display
$(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
-
+
+
+ {$contactInfo.fieldData.contact_role.value}
+ if ({$contactInfo.fieldData.contact_role.value} == {$EntityManagerRole}) {
+ $('#accessToMembers').removeClass('glm-hidden');
+ }
+
+
+
});
</script>