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.
$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 '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
- $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 '<pre>$other_members_refs: ' . print_r( $other_members_refs, true ) . '</pre>';
- // 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 '<pre>$wpUser: ' . print_r( $wpUser, true ) . '</pre>';
+ $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 '<pre>$other_members_refs: ' . print_r( $other_members_refs, true ) . '</pre>';
+ // 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'])) {
+++ /dev/null
-<?php
-
-/**
- * Gaslight Media Contacts Database
- * Admin List Contacts
- *
- * PHP version 5.5
- *
- * @category glmWordPressPlugin
- * @package glmContactsDatabase
- * @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 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
- );
-
- }
-
-
-}
-
-?>
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Contacts Database
+ * Admin List Contacts
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmContactsDatabase
+ * @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 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
+ );
+
+ }
+
+
+}
+
+?>