This will also have the custom fields in the export.
--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Members List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+
+// Load Member Info data abstract
+require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH.'/data/dataContacts.php';
+
+/**
+ *
+ * This class exports the currently selected contacts list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_contactsListExport extends GlmDataContacts
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+ /**
+ * Plugin Configuration Data
+ *
+ * @var $config
+ * @access public
+ */
+ public $config;
+
+ /**
+ * Constructor
+ *
+ * This constructor 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;
+
+ parent::__construct( false, false );
+
+ }
+
+ public function checkFlag( $t ) { return isset( $_REQUEST[$t] ) && $_REQUEST[$t] == 'on'; }
+ /**
+ * Perform Model Action
+ *
+ * This modelAction takes an AJAX image upload and stores the image in the
+ * media/images directory of the plugin.
+ *
+ * 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 )
+ {
+
+ // When processing member info records, also get primary contact data
+ $this->postProcessPrimaryContact = true;
+
+ $where = ' true ';
+ $haveMembers = false;
+ $list = false;
+ $success = 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;
+ $CFSelect = false;
+ $CFHeaders = false;
+
+ // Check selected fields
+ $select = array(
+ 'exportId' => $this->checkFlag( 'exportId' ),
+ 'exportFname' => $this->checkFlag( 'exportFname' ),
+ 'exportLname' => $this->checkFlag( 'exportLname' ),
+ 'exportAddr1' => $this->checkFlag( 'exportAddr1' ),
+ 'exportAddr2' => $this->checkFlag( 'exportAddr2' ),
+ 'exportCity' => $this->checkFlag( 'exportCity' ),
+ 'exportCounty' => $this->checkFlag( 'exportCounty' ),
+ 'exportState' => $this->checkFlag( 'exportState' ),
+ 'exportZip' => $this->checkFlag( 'exportZip' ),
+ 'exportCountry' => $this->checkFlag( 'exportCountry' ),
+ 'exportOrg' => $this->checkFlag( 'exportOrg' ),
+ 'exportTitle' => $this->checkFlag( 'exportTitle' ),
+ 'exportOfficePhone' => $this->checkFlag( 'exportOfficePhone' ),
+ 'exportHomePhone' => $this->checkFlag( 'exportHomePhone' ),
+ 'exportMobilePhone' => $this->checkFlag( 'exportMobilePhone' ),
+ 'exportAltPhone' => $this->checkFlag( 'exportAltPhone' ),
+ 'exportFax' => $this->checkFlag( 'exportFax' ),
+ 'exportEmail' => $this->checkFlag( 'exportEmail' ),
+ 'exportAltEmail' => $this->checkFlag( 'exportAltEmail' ),
+ 'exportMemberType' => $this->checkFlag( 'exportMemberType' ),
+ );
+
+
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+ // Check for selection of Custom Fields
+ $fieldPluginActive = apply_filters( 'glm-members-customfields-active', false );
+ if ( $fieldPluginActive ) {
+ $customFields = apply_filters( 'glm-member-db-fields-get-members-fields', false, 'glm-member-db-contacts' );
+ if ( $customFields ) {
+ foreach ( $customFields as $cf ) {
+ if ( isset( $_REQUEST['exportCF'][$cf['id']] ) ) {
+ $CFSelect[] = $cf['id'];
+ $CFHeaders[] = $cf['field_name'];
+ }
+ }
+ }
+ }
+
+ // Only return information records that are active
+
+ // Check if there is a member_type filter
+ if ( isset( $_REQUEST['filterMemberTypes'] ) && $memberTypeFilter = filter_var( $_REQUEST['filterMemberTypes'], FILTER_VALIDATE_INT ) ) {
+ $where .= " AND T.ref_dest IN (
+ SELECT DISTINCT(id)
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE member_type = $memberTypeFilter
+ )";
+ $mTypeSelected = $memberTypeFilter;
+ }
+
+ // Check for a text search
+ if ( trim( $_REQUEST['text_search'] ) != '' ) {
+ $textSearch = addslashes( filter_var( $_REQUEST['text_search'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES ) );
+ $filterText = esc_sql($textSearch);
+ $where .= " AND (
+ lname LIKE '%$filterText%' OR
+ fname LIKE '%$filterText%' OR
+ org LIKE '%$filterText%' OR
+ descr LIKE '%$filterText%'
+ )";
+ }
+
+ // Get a current list of contacts without paging
+ $list = $this->getList( $where, false, 'lname, fname' );
+
+ // echo '<pre>$list: ' . print_r( $list, true ) . '</pre>';
+ // exit;
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $haveMembers = false;
+ if ( $list !== false ) {
+
+ $success = true;
+
+ // If we have any entries
+ $memberCount = count($list);
+ if ( $memberCount > 0 ) {
+
+ $haveMembers = true;
+
+ if ( $select['exportMemberType'] ) {
+ foreach( $list as $k => $v ) {
+ // Get each contacts members member type
+ $list[$k]['member_type'] = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT name
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_type
+ WHERE id IN (
+ SELECT member_type
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE id = %d
+ )",
+ $v['ref_dest']
+ )
+ );
+ }
+ }
+
+ // If Custom Fields are selected
+ if ( $CFSelect && !empty( $CFSelect ) ) {
+
+ foreach( $list as $k => $v ) {
+ foreach ( $CFSelect as $cf_key => $cf_id ) {
+ $list[$k][$CFHeaders[$cf_key]] = apply_filters( 'glm_custom_fields_by_entity_id', $CFHeaders[$cf_key], $v['id'] );
+ }
+ }
+
+ }
+
+ }
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'select' => $select,
+ 'haveMembers' => $haveMembers,
+ 'contacts' => $list,
+ 'memberCount' => $memberCount,
+ 'categories' => $categories,
+ 'haveFilter' => $haveFilter,
+ 'filterArchived' => $filterArchived,
+ 'filterFeatured' => $filterFeatured,
+ 'filterPending' => $filterPending,
+ 'numbDisplayed' => $numbDisplayed,
+ 'lastDisplayed' => $lastDisplayed,
+ 'paging' => $paging,
+ 'prevStart' => $prevStart,
+ 'nextStart' => $nextStart,
+ 'start' => $start,
+ 'limit' => $limit,
+ 'namesList' => $namesList,
+ 'CFSelect' => $CFSelect,
+ 'CFHeaders' => $CFHeaders,
+ );
+
+ $view = 'admin/ajax/contactsListExport.html';
+ if ( $_REQUEST['type'] == 'csv' ) {
+ $view = 'admin/ajax/contactsListExportCsv.html';
+ header("Content-Type: text/csv");
+ header("Content-Disposition: attachment; filename=file.csv");
+ } else {
+ header("Content-Type: text/html");
+ header("Content-Disposition: attachment; filename=file.html");
+ }
+
+ // Disable caching
+ header( 'Cache-Control: no-cache, no-store, must-revalidate' ); // HTTP 1.1
+ header( 'Pragma: no-cache' ); // HTTP 1.0
+ header( 'Expires: 0' ); // Proxies
+
+ // Return status, suggested view, and data to controller
+ return array(
+ 'status' => $success,
+ 'menuItemRedirect' => false,
+ 'modelRedirect' => false,
+ 'view' => $view,
+ 'data' => $templateData
+ );
+
+ }
+
+}
$start = 1;
$limit = 20; // Set to the number of listings per page
$namesList = false;
- $customFieldResults = false;
+ $customFieldResults = false;
+ $member_types = false;
$where = '';
'list'
);
+ // Get a list of member_types for filtering
+ require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberTypes.php';
+ $MemberTypes = new GlmDataMemberTypes( $this->wpdb, $this->config );
+ $member_types = $MemberTypes->getList();
+
// If this is a logged in member user, then show their contacts only
if (isset($this->config['loggedInUser']['contactUser'])) {
'namesList' => $namesList,
'EntityManagerRole' => $this->config['contact_role_numb']['EntityManager'],
'slug' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
- 'customFieldResults' => $customFieldResults
+ 'customFieldResults' => $customFieldResults,
+ 'member_types' => $member_types,
);
$glmMembersContactsAddOnValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'selectContactMember' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'selectContactMember' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
+ 'contactsListExport' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
),
'members' => array(
- 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
'member' => array(
- 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
'profile' => array(
- 'index' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'index' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
'contacts' => array(
- 'index' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'index' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
'management' => array(
- 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
'import' => array(
- 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG
+ 'contacts' => GLM_MEMBERS_CONTACTS_PLUGIN_SLUG,
),
),
'frontActions' => array(
--- /dev/null
+<html>
+ <head>
+ </head>
+ <body>
+
+ <span style="float: right;"><b>Total found: {$memberCount} </b></span>
+ <b>List of Contacts</b>
+ <br clear="all">
+
+
+ <table>
+ <thead>
+ <tr>
+ {if $select.exportId}<th align="left">ID</th>{/if}
+ {if $select.exportFname}<th align="left">First Name</th>{/if}
+ {if $select.exportLname}<th align="left">Last Name</th>{/if}
+ {if $select.exportAddr1}<th align="left">Address 1</th>{/if}
+ {if $select.exportAddr2}<th align="left">Address 2</th>{/if}
+ {if $select.exportCity}<th align="left">City</th>{/if}
+ {if $select.exportCounty}<th align="left">County</th>{/if}
+ {if $select.exportState}<th align="left">State</th>{/if}
+ {if $select.exportZip}<th align="left">ZIP</th>{/if}
+ {if $select.exportCountry}<th align="left">Country</th>{/if}
+ {if $select.exportOrg}<th align="left">Org</th>{/if}
+ {if $select.exportTitle}<th align="left">Title</th>{/if}
+ {if $select.exportOfficePhone}<th align="left">Office Phone</th>{/if}
+ {if $select.exportHomePhone}<th align="left">Home Phone</th>{/if}
+ {if $select.exportMobilePhone}<th align="left">Mobile Phone</th>{/if}
+ {if $select.exportAltPhone}<th align="left">Alt Phone</th>{/if}
+ {if $select.exportFax}<th align="left">Fax</th>{/if}
+ {if $select.exportEmail}<th align="left">E-Mail</th>{/if}
+ {if $select.exportAltEmail}<th align="left">Alt E-Mail</th>{/if}
+ {if $select.exportMemberType}<th align="left">Member Type</th>{/if}
+ {if $CFHeaders}{foreach $CFHeaders as $cHead}<th align="left">{$cHead}</th>{/foreach}{/if}
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveMembers}
+ {foreach $contacts as $m}
+ <tr>
+ {if $select.exportId}<td>{$m.id}</td>{/if}
+ {if $select.exportFname}<td>{$m.fname}</td>{/if}
+ {if $select.exportLname}<td>{$m.lname}</td>{/if}
+ {if $select.exportAddr1}<td>{$m.addr1}</td>{/if}
+ {if $select.exportAddr2}<td>{$m.addr2}</td>{/if}
+ {if $select.exportCity}<td>{if $m.city}{$m.city.name}{/if}</td>{/if}
+ {if $select.exportCounty}<td>{$m.county}</td>{/if}
+ {if $select.exportState}<td>{if $m.state}{$m.state.value}{/if}</td>{/if}
+ {if $select.exportZip}<td>{$m.zip}</td>{/if}
+ {if $select.exportCountry}<td>{$m.country}</td>{/if}
+ {if $select.exportOrg}<td>{$m.org}</td>{/if}
+ {if $select.exportTitle}<td>{$m.title}</td>{/if}
+ {if $select.exportOfficePhone}<td>{$m.office_phone}</td>{/if}
+ {if $select.exportHomePhone}<td>{$m.home_phone}</td>{/if}
+ {if $select.exportMobilePhone}<td>{$m.mobile_phone}</td>{/if}
+ {if $select.exportAltPhone}<td>{$m.alt_phone.value}</td>{/if}
+ {if $select.exportFax}<td>{$m.fax}</td>{/if}
+ {if $select.exportEmail}<td>{$m.email}</td>{/if}
+ {if $select.exportAltEmail}<td>{$m.alt_email}</td>{/if}
+ {if $select.exportMemberType}<td>{$m.member_type}</td>{/if}
+ {if $CFHeaders}{foreach $CFHeaders as $cHead}<td>{$m[$cHead]}</td>{/foreach}{/if}
+
+ </tr>
+ {/foreach}
+ {else}
+ <tr class="alternate"><td colspan="2">(no Contacts listed)</td></tr>
+ {/if}
+ </tbody>
+ </table>
+
+ </body>
+</html>
--- /dev/null
+{if $haveMembers}
+
+{if $select.exportId}"ID",{/if}
+{if $select.exportFname}"First Name",{/if}
+{if $select.exportLname}"Last Name",{/if}
+{if $select.exportAddr1}"Address 1",{/if}
+{if $select.exportAddr2}"Address 2",{/if}
+{if $select.exportCity}"City",{/if}
+{if $select.exportCounty}"County",{/if}
+{if $select.exportState}"State",{/if}
+{if $select.exportZip}"ZIP/Postal",{/if}
+{if $select.exportCountry}"Country",{/if}
+{if $select.exportOrg}"Org",{/if}
+{if $select.exportTitle}"Title",{/if}
+{if $select.exportOfficePhone}"Office Phone",{/if}
+{if $select.exportHomePhone}"Home Phone",{/if}
+{if $select.exportMobilePhone}"Mobile Phone",{/if}
+{if $select.exportAltPhone}"Alt Phone",{/if}
+{if $select.exportFax}"Fax",{/if}
+{if $select.exportEmail}"E-Mail",{/if}
+{if $select.exportAltEmail}"Alt E-Mail",{/if}
+{if $select.exportMemberType}"Member Type",{/if}
+{if $CFHeaders}{foreach $CFHeaders as $cHead}"{$cHead}",{/foreach}{/if}
+
+{foreach $contacts as $m}
+{if $select.exportId}"{$m.id}",{/if}
+{if $select.exportFname}"{$m.fname}",{/if}
+{if $select.exportLname}"{$m.lname}",{/if}
+{if $select.exportAddr1}"{$m.addr1}",{/if}
+{if $select.exportAddr2}"{$m.addr2}",{/if}
+{if $select.exportCity}"{if $m.city}{$m.city.name}{/if}",{/if}
+{if $select.exportCounty}"{$m.county}",{/if}
+{if $select.exportState}"{if $m.state}{$m.state.value}{/if}",{/if}
+{if $select.exportZip}"{$m.zip}",{/if}
+{if $select.exportCountry}"{$m.country}",{/if}
+{if $select.exportOrg}"{$m.org}",{/if}
+{if $select.exportTitle}"{$m.title}",{/if}
+{if $select.exportOfficePhone}"{$m.office_phone}",{/if}
+{if $select.exportHomePhone}"{$m.home_phane}",{/if}
+{if $select.exportMobilePhone}"{$m.mobile_phone}",{/if}
+{if $select.exportAltPhone}"{$m.alt_phone}",{/if}
+{if $select.exportFax}"{$m.fax}",{/if}
+{if $select.exportEmail}"{$m.email}",{/if}
+{if $select.exportAltEmail}"{$m.alt_email}",{/if}
+{if $select.exportMemberType}"{$m.member_type}",{/if}
+{if $CFHeaders}{foreach $CFHeaders as $cHead}"{$m[$cHead]}",{/foreach}{/if}
+
+{/foreach}
+{else}No Contacts Selected{/if}
{/if}
<br>
<br clear="all">
+ {if !$fromMemberMenu}
+ <div id="exportContactsButton" class="button button-secondary glm-admin-export-button">Contact Export/Reports</div>
+ {/if}
{/if}
<form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
</form>
+ {* BEGIN: Export Form *}
+ <div id="exportContactsDialog" class="glm-dialog-box" title="Export Contacts">
+ <form id="exportForm" action="{$ajaxUrl}" method="post" enctype="multipart/form-data">
+ <input type="hidden" name="action" value="glm_members_admin_ajax">
+ <input type="hidden" name="glm_action" value="contactsListExport">
+ <table class="glm-admin-table">
+ <tr>
+ <th>Name Search: </th>
+ <td>
+ <input class="exportMembersSearch glm-form-text-input-medium" type="text" name="text_search" id="autoTest"><br>
+ </td>
+ </tr>
+ <tr>
+ <th>Member Types:</th>
+ <td>
+ <select id="exportFilterMemberTypes" name="filterMemberTypes">
+ <option value=""></option>
+ {foreach $member_types as $type}
+ <option value="{$type.id}"{if $type.id == $mTypeSelected} selected{/if}>{$type.name}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <th>Fields to Export: </th>
+ <td>
+ <table padding="3">
+ <tr>
+ <td colspan="2"><a id="selectAllExportFields">Check All</a> / <a id="unselectAllExportFields">Uncheck All</a></td>
+ </tr>
+ <tr>
+ <td class="exportFieldsTd">
+ <input type="checkbox" name="exportId"> Contact ID<br>
+ <input type="checkbox" name="exportFname" checked> First Name<br>
+ <input type="checkbox" name="exportLname" checked> Last Name<br>
+ <input type="checkbox" name="exportAddr1" checked> Address 1<br>
+ <input type="checkbox" name="exportAddr2" checked> Address 2<br>
+ <input type="checkbox" name="exportCity" checked> City<br>
+ <input type="checkbox" name="exportCounty" checked> County<br>
+ <input type="checkbox" name="exportState" checked> State<br>
+ <input type="checkbox" name="exportZip" checked> ZIP<br>
+ <input type="checkbox" name="exportCountry" checked> Country<br>
+ </td>
+ <td class="exportFieldsTd">
+ <input type="checkbox" name="exportOrg" checked> Organization<br>
+ <input type="checkbox" name="exportTitle" checked> Title/Position<br>
+ <input type="checkbox" name="exportOfficePhone" checked> Office Phone<br>
+ <input type="checkbox" name="exportHomePhone" checked> Home Phone<br>
+ <input type="checkbox" name="exportMobilePhone" checked> Mobile Phone<br>
+ <input type="checkbox" name="exportAltPhone" checked> Alt Phone<br>
+ <input type="checkbox" name="exportFax" checked> Fax Phone<br>
+ <input type="checkbox" name="exportEmail" checked> Email<br>
+ <input type="checkbox" name="exportAltEmail" checked> Alt Email<br>
+ <input type="checkbox" name="exportMemberType"> Member Type<br>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ {* Custom Field Part *}
+ {if apply_filters( 'glm-members-customfields-active', false )}
+ <tr>
+ <th>Custom Fields</th>
+ <td>
+ {$customFields = apply_filters('glm-member-db-fields-get-members-fields', false, 'glm-member-db-contacts')}
+ {if $customFields}
+ {foreach $customFields as $cf}
+ <input type="checkbox" name="exportCF[{$cf.id}]" checked> {$cf.field_name} <br>
+ {/foreach}
+ {/if}
+ </td>
+ </tr>
+ {/if}
+ <tr>
+ <th>Export to: </th>
+ <td>
+ <input type="radio" name="type" value="print"> Export for Print<br>
+ <input type="radio" name="type" value="csv" checked="checked"> Export to Spreadsheet (CSV)
+ </td>
+ </tr>
+ </table>
+ <a id="exportContactsCancel" class="button button-secondary glm-right">Cancel</a>
+ <input type="submit" value="Export" class="button button-primary">
+ </form>
+ </div>
+ {* END: Export Form *}
+
<script type="text/javascript">
jQuery(document).ready(function($) {
}
});
+ $('#selectAllExportFields').click(function(){
+ $('.exportFieldsTd input[type="checkbox"]').each(function(){
+ $(this).prop('checked', true);
+ });
+ });
+ $('#unselectAllExportFields').click(function(){
+ $('.exportFieldsTd input[type="checkbox"]').each(function(){
+ $(this).prop('checked', false);
+ });
+ });
+
+ // Export Contacts
+ $("#exportContactsDialog").dialog({
+ autoOpen: false,
+ minWidth: 700,
+ dialogClass: "glm-dialog-no-close"
+ });
+ $('#exportContactsButton').click( function() {
+ $("#exportContactsDialog").dialog("open");
+ });
+ $('#exportContactsCancel').click( function() {
+ $("#exportContactsDialog").dialog("close");
+ });
});
</script>