From: Chuck Scott Date: Thu, 7 Jun 2018 14:47:32 +0000 (-0400) Subject: Fixes for problem with contacts list not always displaying the correct list for the... X-Git-Tag: v1.1.7^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=4a40729858d333b6ae7d62657bc63ee28a975b55;p=WP-Plugins%2Fglm-member-db-contacts.git Fixes for problem with contacts list not always displaying the correct list for the contact/user type. Added code to make sure that if arrived at the index.php model from "Contacts" menu and user is a "Members" manager that they get a full list of contacts. --- diff --git a/models/admin/contacts/index.php b/models/admin/contacts/index.php index a96072e..bc2b328 100644 --- a/models/admin/contacts/index.php +++ b/models/admin/contacts/index.php @@ -598,55 +598,61 @@ class GlmMembersAdmin_contacts_index extends GlmDataContacts $where = ' TRUE '; - // Only list member contacts for the selected member - if ($haveMember) { - $other_members_refs = false; - // Have to query the meta data before sending it back into - // db query. Would work but it's getting back a string - // instead of an array of ints. - // Should only be getting the meta data for the real contact. - // Get userID for original member contact. - $originalMemberContact = $this->wpdb->get_row( - $this->wpdb->prepare( - "SELECT id,email,username - FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts - WHERE ref_dest = %d", - $this->memberID - ), - ARRAY_A - ); - if ( isset( $originalMemberContact ) ) { - $wpUser = $this->checkContact( $originalMemberContact['email'], $originalMemberContact['username'] ); - // echo '
$wpUser: ' . print_r( $wpUser, true ) . '
'; - $other_members_refs = $this->wpdb->get_var( - "SELECT meta_value - FROM " . $this->wpdb->prefix . "usermeta - WHERE meta_key = 'glmMembersContactMembers' - AND meta_value LIKE '%" . $this->memberID . "%' - AND user_id = " . $wpUser['wpUserEmail']->ID - ); - // echo '
$other_members_refs: ' . print_r( $other_members_refs, true ) . '
'; - // Get wordpress user - } else { - $other_members_refs = $this->wpdb->get_var( - "SELECT meta_value - FROM " . $this->wpdb->prefix . "usermeta - WHERE meta_key = 'glmMembersContactMembers' - AND meta_value LIKE '%" . $this->memberID . "%'" + + // If this is a member contact list or the user is not a members manager + if ($this->config['menuItem'] == 'member' || !apply_filters('glm_members_menu_members', true)) { + + // Only list member contacts for the selected member + if ($haveMember) { + $other_members_refs = false; + // Have to query the meta data before sending it back into + // db query. Would work but it's getting back a string + // instead of an array of ints. + // Should only be getting the meta data for the real contact. + // Get userID for original member contact. + $originalMemberContact = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT id,email,username + FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + WHERE ref_dest = %d", + $this->memberID + ), + ARRAY_A ); + if ( isset( $originalMemberContact ) ) { + $wpUser = $this->checkContact( $originalMemberContact['email'], $originalMemberContact['username'] ); + // echo '
$wpUser: ' . print_r( $wpUser, true ) . '
'; + $other_members_refs = $this->wpdb->get_var( + "SELECT meta_value + FROM " . $this->wpdb->prefix . "usermeta + WHERE meta_key = 'glmMembersContactMembers' + AND meta_value LIKE '%" . $this->memberID . "%' + AND user_id = " . $wpUser['wpUserEmail']->ID + ); + // echo '
$other_members_refs: ' . print_r( $other_members_refs, true ) . '
'; + // Get wordpress user + } else { + $other_members_refs = $this->wpdb->get_var( + "SELECT meta_value + FROM " . $this->wpdb->prefix . "usermeta + WHERE meta_key = 'glmMembersContactMembers' + AND meta_value LIKE '%" . $this->memberID . "%'" + ); + } + $where .= " AND ref_type = " . $this->config['ref_type_numb']['Member']; + if ( $other_members_refs ) { + // Make sure the $other_members_refs is correct + $exploded_refs = explode( ',', $other_members_refs ); + // Clean array of empties + $clean_refs = array_filter( $exploded_refs ); + $where .= " AND ( ref_dest = " . $this->memberID . " + OR ref_dest IN ( " . implode( ',', $clean_refs ) . " ) )"; + } else { + $where .= " AND ref_dest = " . $this->memberID; + } } - $where .= " AND ref_type = " . $this->config['ref_type_numb']['Member']; - if ( $other_members_refs ) { - // Make sure the $other_members_refs is correct - $exploded_refs = explode( ',', $other_members_refs ); - // Clean array of empties - $clean_refs = array_filter( $exploded_refs ); - $where .= " AND ( ref_dest = " . $this->memberID . " - OR ref_dest IN ( " . implode( ',', $clean_refs ) . " ) )"; - } else { - $where .= " AND ref_dest = " . $this->memberID; - } - } + + } // member contact list or not members manager // Filter by text string supplied if (isset($_REQUEST['filterText'])) { diff --git a/models/admin/contacts/list.php b/models/admin/contacts/list.php deleted file mode 100644 index 695cc28..0000000 --- a/models/admin/contacts/list.php +++ /dev/null @@ -1,250 +0,0 @@ - - * @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 performs the work for the default action of the "Contacts" menu - * option, which is to display the contacts dashboard. - * - */ -class GlmContactsAdmin_contacts_list 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 contacts data class to setup table and fields array - * - * Since this class is extending GlmDataContacts, it does not need to pass - * $wpdb and $config to it in the constructor. - */ - parent::__construct(false, false); - - } - - /* - * Perform Model Action - * - * This method does the work for this model and returns any resulting data - * - * @return array Status and data array - * - * 'status' - * - * True if successfull and false if there was a fatal failure. - * - * 'menuItemRedirect' - * - * If not false, provides a menu item the controller should - * execute after this one. Normally if this is used, there would also be a - * modelRedirect value supplied as well. - * - * 'modelRedirect' - * - * If not false, provides an action the controller should execute after - * this one. - * - * 'view' - * - * A suggested view name that the contoller should use instead of the - * default view for this model or false to indicate that the default view - * should be used. - * - * 'data' - * - * Data that the model is returning for use in merging with the view to - * produce output. - * - */ - public function modelAction ($actionData = false) - { - - $where = ' true '; - $filterPending = false; - $filterArchived = false; - $filterFeatured = false; - $haveFilter = false; - $numbDisplayed = false; - $lastDisplayed = false; - $paging = true; - $prevStart = false; - $nextStart = false; - $start = 1; - $limit = 20; // Set to the number of listings per page - $namesList = false; - $enable_contacts = $this->config['settings']['enable_contacts']; - - // Check if this is a request to show archived contacts - if (isset($_REQUEST['filterArchived'])) { - $where .= " AND access = ".$this->config['access_numb']['Archived']; - $filterArchived = true; - $haveFilter = true; - - // If not, don't show them - } else { - $where .= " AND access != ".$this->config['access_numb']['Archived']; - } - - // Check for a text search - if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search']) != '') { - - $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); - $where .= " AND T.id in ( - SELECT DISTINCT(contact) - FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX."contact_info - WHERE contact_name like '%$textSearch%' - )"; - } - - - // Get count of contacts listed - $contactCount = $this->getStats($where); - - // If the number of contacts is less than a page, don't do paging - if ($contactCount <= $limit) { - $paging = false; - } - - // Get full list of names matching this where clause for search box - $namesList = $this->getIdName($where); - - // Check if we're doing paging - if (isset($_REQUEST['pageSelect'])) { - - // If request is for Next - if ($_REQUEST['pageSelect'][0] == 'N') { - $newStart = $_REQUEST['nextStart'] - 0; - - // Otherwise it must be Previous - } else { - $newStart = $_REQUEST['prevStart'] - 0; - } - - if ($newStart > 0) { - $start = $newStart; - } - } - - // Get a current list of contacts - $listResult = $this->getSimpleMembersList($where, 'name', true, 'id', $start, $limit); - - // Get paging results - $numbDisplayed = $listResult['returned']; - $lastDisplayed = $listResult['last']; - if ($start == 1) { - $prevStart = false; - } else { - $prevStart = $start - $limit; - if ($start < 1) { - $start = 1; - } - } - if ($listResult['returned'] == $limit) { - $nextStart = $start + $limit; - } - - // since we're doing paging, we have to break out just the contact data - $list = $listResult['list']; - unset($listResult); - - // If we have list entries - even if it's an empty list - $success = true; - $haveContacts = false; - if ($list !== false) { - - $success = true; - - // If we have any entries - if (count($list) > 0) { - $haveContacts = true; - } - } - - // Determine if current user can add, edit, delete contact data -// $canEdit = current_user_can('glm_contacts_edit'); - - // Add a url for each contact - foreach ($list as $contact) { - $list[$contact['id']]['contact_slug'] = sanitize_title($contact['name']); - } - - // Compile template data - $templateData = array( - 'enable_contacts' => $enable_contacts, - 'haveContacts' => $haveContacts, - 'contacts' => $list, - 'contactCount' => $contactCount, - 'haveFilter' => $haveFilter, - 'filterArchived' => $filterArchived, - 'filterFeatured' => $filterFeatured, - 'filterPending' => $filterPending, - 'numbDisplayed' => $numbDisplayed, - 'lastDisplayed' => $lastDisplayed, - 'paging' => $paging, - 'prevStart' => $prevStart, - 'nextStart' => $nextStart, - 'start' => $start, - 'limit' => $limit, - 'namesList' => $namesList - ); - - // Return status, suggested view, and data to controller - return array( - 'status' => $success, - 'menuItemRedirect' => false, - 'modelRedirect' => false, - 'view' => 'admin/contacts/list.html', - 'data' => $templateData - ); - - } - - -} - -?> diff --git a/models/admin/contacts/list_PENDING_DELETE.php b/models/admin/contacts/list_PENDING_DELETE.php new file mode 100644 index 0000000..695cc28 --- /dev/null +++ b/models/admin/contacts/list_PENDING_DELETE.php @@ -0,0 +1,250 @@ + + * @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 performs the work for the default action of the "Contacts" menu + * option, which is to display the contacts dashboard. + * + */ +class GlmContactsAdmin_contacts_list 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 contacts data class to setup table and fields array + * + * Since this class is extending GlmDataContacts, it does not need to pass + * $wpdb and $config to it in the constructor. + */ + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + + $where = ' true '; + $filterPending = false; + $filterArchived = false; + $filterFeatured = false; + $haveFilter = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $namesList = false; + $enable_contacts = $this->config['settings']['enable_contacts']; + + // Check if this is a request to show archived contacts + if (isset($_REQUEST['filterArchived'])) { + $where .= " AND access = ".$this->config['access_numb']['Archived']; + $filterArchived = true; + $haveFilter = true; + + // If not, don't show them + } else { + $where .= " AND access != ".$this->config['access_numb']['Archived']; + } + + // Check for a text search + if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search']) != '') { + + $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); + $where .= " AND T.id in ( + SELECT DISTINCT(contact) + FROM ".GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX."contact_info + WHERE contact_name like '%$textSearch%' + )"; + } + + + // Get count of contacts listed + $contactCount = $this->getStats($where); + + // If the number of contacts is less than a page, don't do paging + if ($contactCount <= $limit) { + $paging = false; + } + + // Get full list of names matching this where clause for search box + $namesList = $this->getIdName($where); + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } + } + + // Get a current list of contacts + $listResult = $this->getSimpleMembersList($where, 'name', true, 'id', $start, $limit); + + // Get paging results + $numbDisplayed = $listResult['returned']; + $lastDisplayed = $listResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($listResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // since we're doing paging, we have to break out just the contact data + $list = $listResult['list']; + unset($listResult); + + // If we have list entries - even if it's an empty list + $success = true; + $haveContacts = false; + if ($list !== false) { + + $success = true; + + // If we have any entries + if (count($list) > 0) { + $haveContacts = true; + } + } + + // Determine if current user can add, edit, delete contact data +// $canEdit = current_user_can('glm_contacts_edit'); + + // Add a url for each contact + foreach ($list as $contact) { + $list[$contact['id']]['contact_slug'] = sanitize_title($contact['name']); + } + + // Compile template data + $templateData = array( + 'enable_contacts' => $enable_contacts, + 'haveContacts' => $haveContacts, + 'contacts' => $list, + 'contactCount' => $contactCount, + 'haveFilter' => $haveFilter, + 'filterArchived' => $filterArchived, + 'filterFeatured' => $filterFeatured, + 'filterPending' => $filterPending, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/contacts/list.html', + 'data' => $templateData + ); + + } + + +} + +?>