From b9d6392608a857239c6303616c1ac36628fa1aef Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Fri, 30 Dec 2016 15:43:37 -0500 Subject: [PATCH] Added ability of contact users to select other specific members to manage. 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. --- defines.php | 2 + models/admin/ajax/selectContactMember.php | 109 ++++++++ models/admin/contacts/index.php | 269 ++++++++++++------- models/admin/profile/index.php | 115 ++++++-- setup/adminHooks.php | 28 ++ setup/permissions.php | 29 +- setup/validActions.php | 3 + views/admin/contacts/edit.html | 98 ++++++- views/admin/profile/contactMemberSelect.html | 34 +++ views/admin/profile/index.html | 26 +- 10 files changed, 586 insertions(+), 127 deletions(-) create mode 100644 models/admin/ajax/selectContactMember.php create mode 100644 views/admin/profile/contactMemberSelect.html diff --git a/defines.php b/defines.php index b1e35d8..f148a72 100644 --- a/defines.php +++ b/defines.php @@ -67,4 +67,6 @@ define('GLM_MEMBERS_CONTACTS_PLUGIN_LIB_PATH', GLM_MEMBERS_CONTACTS_MAIN_PLUGIN_ 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')); + ?> diff --git a/models/admin/ajax/selectContactMember.php b/models/admin/ajax/selectContactMember.php new file mode 100644 index 0000000..ba73d48 --- /dev/null +++ b/models/admin/ajax/selectContactMember.php @@ -0,0 +1,109 @@ + + * @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(); + + } + +} diff --git a/models/admin/contacts/index.php b/models/admin/contacts/index.php index f9bf4ab..0a4795c 100644 --- a/models/admin/contacts/index.php +++ b/models/admin/contacts/index.php @@ -38,6 +38,22 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts * @access public */ public $config; + /** + * Member Data class + * + * @var $Members + * @access private + * + */ + public $Members; + /** + * Member ID + * + * @var $memberID + * @access private + * + */ + public $memberID; /* * Constructor @@ -89,7 +105,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $refType = false; $refTypeName = false; $haveMember = false; - $memberID = false; + $this->memberID = false; $memberData = false; $memberName = false; $membersList = false; @@ -109,6 +125,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $haveFilter = false; $userDeleted = false; $wpUserDeleted = false; + $contactMembers = array(); $numbContacts = false; $numbDisplayed = false; @@ -146,7 +163,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts AND ref_dest = ".$contactUser['ref_dest']; // Also set their member as the current one - $memberID = $contactUser['ref_dest']; + $this->memberID = $contactUser['ref_dest']; } } @@ -160,23 +177,23 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 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 @@ -207,7 +224,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts // 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'; @@ -342,12 +359,12 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 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; @@ -369,17 +386,22 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 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 @@ -407,11 +429,11 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 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']; } @@ -452,6 +474,12 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts } + // 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'; @@ -512,111 +540,75 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts // 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; } @@ -637,7 +629,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 'loggedInMember' => $loggedInMember, 'fromMemberMenu' => $fromMemberMenu, 'haveMember' => $haveMember, - 'memberID' => $memberID, + 'memberID' => $this->memberID, 'memberData' => $memberData, 'memberName' => $memberName, 'membersList' => $membersList, @@ -660,6 +652,7 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 'haveFilter' => $haveFilter, 'userDeleted' => $userDeleted, 'wpUserDeleted' => $wpUserDeleted, + 'contactMembers' => $contactMembers, 'numbDisplayed' => $numbDisplayed, 'lastDisplayed' => $lastDisplayed, @@ -668,7 +661,8 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts 'nextStart' => $nextStart, 'start' => $start = 1, 'limit' => $limit, - 'namesList' => $namesList + 'namesList' => $namesList, + 'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager'] ); @@ -718,6 +712,73 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts } } } + + /* + * 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 diff --git a/models/admin/profile/index.php b/models/admin/profile/index.php index 3ef07ed..24e6258 100644 --- a/models/admin/profile/index.php +++ b/models/admin/profile/index.php @@ -47,6 +47,13 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts * @access public */ public $memberID = false; + /** + * Members Data Class + * + * @var $Members + * @access public + */ + public $Members = false; /** * Contact ID * @@ -54,7 +61,13 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts * @access public */ public $contactID = false; - + /** + * WordPress User ID + * + * @var $wpUserID + * @access public + */ + public $wpUserID = false; /* * Constructor @@ -104,13 +117,34 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts 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']) { @@ -118,13 +152,6 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts $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) { @@ -144,12 +171,9 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts // 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); } } @@ -161,6 +185,11 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts break; + case 'getContactMembersList': + + // Simply change the view to produce the member selection list and fall through + $view = 'admin/profile/contactMemberSelect.html'; + default: case 'edit': @@ -175,24 +204,32 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts } - } // 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 ); @@ -235,6 +272,48 @@ class GlmMembersAdmin_profile_index extends GlmDataContacts } } + /* + * 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 diff --git a/setup/adminHooks.php b/setup/adminHooks.php index d520aa1..7cbd73a 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -87,4 +87,32 @@ add_filter( 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 +); + + ?> diff --git a/setup/permissions.php b/setup/permissions.php index a140d76..e04066e 100644 --- a/setup/permissions.php +++ b/setup/permissions.php @@ -51,6 +51,31 @@ add_filter('glm_members_current_logged_in_user', 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, @@ -78,8 +103,8 @@ add_filter('glm_members_locked_to_member_id', 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']; } diff --git a/setup/validActions.php b/setup/validActions.php index 458862c..5b81d50 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -32,6 +32,9 @@ $glmMembersContactsAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'selectContactMember' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG + ), 'members' => array( 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG ), diff --git a/views/admin/contacts/edit.html b/views/admin/contacts/edit.html index acecffd..2f40526 100644 --- a/views/admin/contacts/edit.html +++ b/views/admin/contacts/edit.html @@ -450,6 +450,51 @@ {if $contactInfo.fieldFail.fax}

{$contactInfo.fieldFail.fax}

{/if} + + Access to Members + + {if $membersList && apply_filters('glm_members_menu_members',true)} + +    Select a member to add.
+
+ {if $contactMembers} + {foreach $contactMembers as $m} +
+ {$m.name} + {if $m.id != $memberID} + X + + {else} + (Primary {$terms.term_member_cap}) + {/if} +
+ {/foreach} + {/if} +
+ {else} + {if $contactMembers} + + {foreach $contactMembers as $m} +
+ {$m.name} +
+ {/foreach} + {/if} + {/if} + + + This contact has no access or can manage all members, so no selection is needed here. + + Notes: @@ -670,11 +715,62 @@ // 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('
' + + membName.trim() + ' X' + + '
'); + } + + // 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); + }); diff --git a/views/admin/profile/contactMemberSelect.html b/views/admin/profile/contactMemberSelect.html new file mode 100644 index 0000000..4b70f91 --- /dev/null +++ b/views/admin/profile/contactMemberSelect.html @@ -0,0 +1,34 @@ +

+{if count($contactMembers) > 1} +

Change to {$terms.term_member_cap}: +

+

+{/if} + + diff --git a/views/admin/profile/index.html b/views/admin/profile/index.html index ffbd49f..ca3785b 100644 --- a/views/admin/profile/index.html +++ b/views/admin/profile/index.html @@ -241,6 +241,20 @@ {if $contactInfo.fieldFail.fax}

{$contactInfo.fieldFail.fax}

{/if} + + Access to Members + + {if $contactMembers} + {foreach $contactMembers as $m} +
+ {$m.name} +
+ {/foreach} + {/if} + + + +

* Required

@@ -285,7 +299,7 @@ Web Address (URL): {if $contactInfo.fieldData.url} - {$contactInfo.fieldData.url} + {$contactInfo.fieldData.url} {/if} @@ -393,7 +407,15 @@ // 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'); + } + + + }); -- 2.17.1