--- /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_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+
+/**
+ *
+ * This class exports the currently selected accounts list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_accountsListExport extends GlmDataAccounts
+{
+
+ /**
+ * 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)
+ {
+
+ $categories = false;
+ $haveAccounts = false;
+ $list = false;
+ $success = false;
+ $filterPending = false;
+ $filterArchived = false;
+ $filterOverdue = false;
+ $filterExpired = 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;
+ $where_params = array();
+
+ // Check selected fields
+ $select = array(
+ 'exportId' => $this->checkFlag('exportId'),
+ 'exportMember' => $this->checkFlag('exportMember'),
+ 'exportEmail' => $this->checkFlag('exportEmail'),
+ 'exportAddr1' => $this->checkFlag('exportAddr1'),
+ 'exportAddr2' => $this->checkFlag('exportAddr2'),
+ 'exportCity' => $this->checkFlag('exportCity'),
+ 'exportState' => $this->checkFlag('exportState'),
+ 'exportZip' => $this->checkFlag('exportZip'),
+ 'exportPhone' => $this->checkFlag('exportPhone'),
+ 'exportRenewalDate' => $this->checkFlag('exportRenewalDate'),
+ );
+
+ // Only return information records that are active
+
+ // Check if this is a request to show archived accounts
+ if (isset($_REQUEST['filterArchived'])) {
+ // $where_params[] = "T.archived";
+ $filterArchived = true;
+ $haveFilter = true;
+
+ // If not, don't show them
+ } else {
+ // $where_params[] = "T.archived <> true";
+ }
+
+ // When searching
+ $reg_options = array(
+ 'options' => array(
+ 'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+ )
+ );
+
+ if ( isset( $_REQUEST['fromDate'] ) && $_REQUEST['fromDate']
+ && $fromDate = filter_var( $_REQUEST['fromDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+ ) {
+ $from_date = date( 'Y-m-d', strtotime( $fromDate ) );
+ $where_params[] = "T.renewal_date >= '$from_date'";
+ }
+ if ( isset( $_REQUEST['toDate'] ) && $_REQUEST['toDate']
+ && $toDate = filter_var( $_REQUEST['toDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+ ) {
+ $to_date = date( 'Y-m-d', strtotime( $toDate ) );
+ $where_params[] = "T.renewal_date <= '$to_date'";
+ }
+ if ( isset( $_REQUEST['filterAccounts'] )
+ && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT )
+ ) {
+ $accounts[$filterAccounts]['selected'] = true;
+ $where_params[] = "T.id = $filterAccounts";
+ } else if ( isset( $_REQUEST['searchName'] )
+ && $searchName = filter_var( $_REQUEST['searchName'], FILTER_SANITIZE_STRING )
+ ) {
+ $where_params[] = "T.ref_name like '%" . esc_sql( $searchName ) . "%'";
+ }
+
+ if ( isset( $_REQUEST['filterPending'] ) ) {
+ $filterPending = filter_var( $_REQUEST['filterPending'], FILTER_VALIDATE_BOOLEAN );
+ $where_params[] = "renewal_date >= now()";
+ $filterPending = true;
+ $haveFilter = true;
+ }
+ if ( isset( $_REQUEST['filterOverdue'] ) ) {
+ $filterOverdue = filter_var( $_REQUEST['filterOverdue'], FILTER_VALIDATE_BOOLEAN );
+ $expiredDate = date( 'Y-m-d', mktime( 0, 0, 0, date( 'n' ), date( 'j' ) - 30, date( 'Y' )) );
+ $where_params[] = "renewal_date < now()";
+ $where_params[] = "renewal_date >= '$expiredDate'";
+ }
+ if ( isset( $_REQUEST['filterExpired'] ) ) {
+ $filterExpired = filter_var( $_REQUEST['filterExpired'], FILTER_VALIDATE_BOOLEAN );
+ $expiredDate = date( 'Y-m-d', mktime( 0, 0, 0, date( 'n' ), date( 'j' ) - 30, date( 'Y' )) );
+ $where_params[] = "renewal_date < '$expiredDate'";
+ }
+
+ // Build the $where string from the $where_parts array.
+ // By implode with AND.
+ $where = implode( ' AND ', $where_params );
+
+
+ // Get a current list of accounts without paging
+ $orderBy = 'renewal_date ASC';
+ $list = $this->getList( $where, $orderBy );
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $haveAccounts = false;
+ if ($list !== false) {
+ $success = true;
+ $accountCount = count($list);
+ $haveAccounts = true;
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'select' => $select,
+ 'haveAccounts' => $haveAccounts,
+ 'accounts' => $list,
+ 'accountCount' => $accountCount,
+ 'haveFilter' => $haveFilter,
+ 'filterArchived' => $filterArchived,
+ 'filterFeatured' => $filterFeatured,
+ 'filterPending' => $filterPending,
+ 'numbDisplayed' => $numbDisplayed,
+ 'lastDisplayed' => $lastDisplayed,
+ 'paging' => $paging,
+ 'prevStart' => $prevStart,
+ 'nextStart' => $nextStart,
+ 'start' => $start,
+ 'limit' => $limit,
+ 'namesList' => $namesList
+ );
+
+ $view = 'admin/ajax/accountsListExport.html';
+ if ($_REQUEST['type'] == 'csv') {
+ $view = 'admin/ajax/accountsListExportCsv.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
+ );
+
+ }
+
+}
'filterPending' => $filterPending,
'filterOverdue' => $filterOverdue,
'searchName' => $searchName,
- 'filterExpired' => $filterExpired,
+ 'filterExpired' => $filterExpired,
);
// Return status, any suggested view, and any data to controller
$glmMembersBillingAddOnValidActions = array(
'adminActions' => array(
'ajax' => array(
- 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
- 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+ 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
),
'management' => array(
'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
--- /dev/null
+<html>
+ <head>
+ </head>
+ <body>
+
+ <span style="float: right;"><b>Total found: {$accountCount} </b></span>
+ <b>List of {$terms.term_member_cap} Profiles</b>
+ <br clear="all">
+
+
+ <table>
+ <thead>
+ <tr>
+ {if $select.exportId}<th align="left">ID</th>{/if}
+ {if $select.exportMember}<th align="left">{$terms.term_member_cap} Name</th>{/if}
+ {if $select.exportEmail}<th align="left">Billing E-Mail</th>{/if}
+ {if $select.exportAddr1}<th align="left">Billing Address</th>{/if}
+ {if $select.exportAddr2}<th align="left">Billing Addr Line #2</th>{/if}
+ {if $select.exportCity}<th align="left">Billing City</th>{/if}
+ {if $select.exportState}<th align="left">Billing State</th>{/if}
+ {if $select.exportZip}<th align="left">Billing ZIP</th>{/if}
+ {if $select.exportPhone}<th align="left">Billing Phone</th>{/if}
+ {if $select.exportRenewalDate}<th align="left">Renewal Date</th>{/if}
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveAccounts}
+ {foreach $accounts as $account}
+ <tr>
+ {if $select.exportId}<td>{$account.id}</td>{/if}
+ {if $select.exportMember}<td>{$account.ref_name}</td>{/if}
+ {if $select.exportEmail}<td>{$account.email}</td>{/if}
+ {if $select.exportAddr1}<td>{$account.billing_addr1}</td>{/if}
+ {if $select.exportAddr2}<td>{$account.billing_addr2}</td>{/if}
+ {if $select.exportCity}<td>{$account.billing_city}</td>{/if}
+ {if $select.exportState}<td>{if $account.billing_state}{$account.billing_state.value}{/if}</td>{/if}
+ {if $select.exportZip}<td>{$account.billing_zip}</td>{/if}
+ {if $select.exportPhone}<td>{$account.billing_phone}</td>{/if}
+ {if $select.exportRenewalDate}<td>{$account.renewal_date.date}</td>{/if}
+
+ </tr>
+ {/foreach}
+ {else}
+ <tr class="alternate"><td colspan="2">(no Accounts listed)</td></tr>
+ {/if}
+ </tbody>
+ </table>
+
+ </body>
+</html>
--- /dev/null
+{if $haveAccounts}
+{if $select.exportId}"ID",{/if}
+{if $select.exportMember}"{$terms.term_member_cap} Name",{/if}
+{if $select.exportEmail}"Billing E-Mail",{/if}
+{if $select.exportAddr1}"Billing Address",{/if}
+{if $select.exportAddr2}"Billing Addr Line #2",{/if}
+{if $select.exportCity}"Billing City",{/if}
+{if $select.exportState}"Billing State",{/if}
+{if $select.exportZip}"Billing ZIP/Postal",{/if}
+{if $select.exportPhone}"Billing Phone",{/if}
+{if $select.exportRenewalDate}"Renewal Date",{/if}
+
+{foreach $accounts as $account}
+{if $select.exportId}"{$account.id}",{/if}
+{if $select.exportMember}"{$account.ref_name}",{/if}
+{if $select.exportEmail}"{$account.email}",{/if}
+{if $select.exportAddr1}"{$account.billing_addr1}",{/if}
+{if $select.exportAddr2}"{$account.billing_addr2}",{/if}
+{if $select.exportCity}"{$account.billing_city}",{/if}
+{if $select.exportState}"{if $account.billing_state}{$account.billing_state.value}{/if}",{/if}
+{if $select.exportZip}"{$account.billing_zip}",{/if}
+{if $select.exportPhone}"{$account.billing_phone}",{/if}
+{if $select.exportRenewalDate}"{$account.renewal_date.date}",{/if}
+
+{/foreach}
+{else}No Accounts Selected{/if}
{include file='admin/billing/header.html'}
+<div id="exportAccountsButton" class="button button-secondary glm-admin-export-button">Accounts Export</div>
+
<h2>Accounts</h2>
{include file='admin/billing/accountSearchForm.html'}
</table>
- {if $paging}
- <input type="Submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
- <input type="Submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
- {/if}
+{if $paging}
+ <input type="Submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+ <input type="Submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+{/if}
+
+</form>
- </form>
+{include file='admin/billing/exportBillingModal.html'}
<script type="text/javascript">
jQuery(document).ready(function($) {
dateFormat: 'mm/dd/yy'
});
+ // Setup for the modal box
+ $('#exportAccountDialog').dialog( {
+ autoOpen: false,
+ minWidth: 700,
+ dialogClass: 'glm-dialog-no-close'
+ } );
+ $('#exportAccountsButton').click( function(){
+ $('#exportAccountDialog').dialog( 'open' );
+ } );
+ $('#exportAccountsCancel').click( function(){
+ $('#exportAccountDialog').dialog( 'close' );
+ } );
+ $('#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);
+ });
+ });
+
var availableAccounts = [
{foreach $allAccounts as $m}
{ label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
{/foreach}
]
+ // Setup autocomplete for both inputs
$('#account_name').autocomplete({
source: availableAccounts,
select: function( event, ui ){
$('#member-account').val( ui.item.id );
},
});
+ $('#account_name2').autocomplete({
+ source: availableAccounts,
+ select: function( event, ui ){
+ $('#member-account2').val( ui.item.id );
+ },
+ });
{if $filterAccounts}
{$selected = 0}
--- /dev/null
+<div id="exportAccountDialog" class="glm-dialog-box" title="Export Billing Accounts">
+ <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="accountsListExport">
+ <table class="glm-admin-table">
+ <tr><th>Show Overdue Only: </th><td><input type="checkbox" name="filterOverdue"></td></tr>
+ <tr><th>Show Archived Only: </th><td><input type="checkbox" name="filterArchived"></td></tr>
+ <tr><th>Show Expired Only: </th><td><input type="checkbox" name="filterExpired"></td></tr>
+ <tr><th>Show Pending Only: </th><td><input type="checkbox" name="filterPending"></td></tr>
+ <tr>
+ <th>Date Range Search: </th>
+ <td>
+ <b>From Date: </b><br />
+ <input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input"><br />
+ <b>To Date: </b><br />
+ <input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input"><br />
+ </td>
+ </tr>
+ <tr>
+ <th>Name Search:</th>
+ <td>
+ <input id="member-account2" type="hidden" name="filterAccounts" value="{$filterAccounts}">
+ <input id="account_name2" name="searchName" value="{if $searchName}{$searchName}{/if}" />
+ </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"> Account ID<br>
+ <input type="checkbox" name="exportMember" checked> {$terms.term_member_cap} Name<br>
+ <input type="checkbox" name="exportEmail" checked> Billing Email <br>
+ <input type="checkbox" name="exportAddr1" checked> Billing Address 1 <br>
+ <input type="checkbox" name="exportAddr2" checked> Billing Address 2 <br>
+ <input type="checkbox" name="exportCity" checked> Billing City <br>
+ <input type="checkbox" name="exportState" checked> Billing State <br>
+ <input type="checkbox" name="exportZip" checked> Billing ZIP/Postal Code <br>
+ <input type="checkbox" name="exportPhone" checked> Billing Phone <br>
+ <input type="checkbox" name="exportRenewalDate" checked> Renewal Date <br>
+
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <th>Export to: </th>
+ <td>
+ <input type="radio" name="type" value="print" checked="checked"> Export for Print<br>
+ <input type="radio" name="type" value="csv"> Export to Spreadsheet (CSV)
+ </td>
+ </tr>
+ </table>
+ <a id="exportAccountsCancel" class="button button-secondary glm-right">Cancel</a>
+ <input type="submit" value="Export" class="button button-primary">
+ </form>
+</div>
+
<a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=add">Create Invoice</a>
<a class="button glm-right button-primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments&option=add">Make Payment</a>
+ <div id="exportAccountsButton" class="button button-secondary glm-admin-export-button">Accounts Export</div>
{include file='admin/billing/accountSearchForm.html'}
</form>
<br clear="all">
{/foreach}
+{include file='admin/billing/exportBillingModal.html'}
+
<script>
jQuery(document).ready(function($) {
dateFormat: 'mm/dd/yy'
});
+ // Setup for the modal box
+ $('#exportAccountDialog').dialog( {
+ autoOpen: false,
+ minWidth: 700,
+ dialogClass: 'glm-dialog-no-close'
+ } );
+ $('#exportAccountsButton').click( function(){
+ $('#exportAccountDialog').dialog( 'open' );
+ } );
+ $('#exportAccountsCancel').click( function(){
+ $('#exportAccountDialog').dialog( 'close' );
+ } );
+ $('#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);
+ });
+ });
+
var availableAccounts = [
{foreach $accounts as $m}
{ label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
{/foreach}
]
+ // Setup autocomplete for both inputs
$('#account_name').autocomplete({
source: availableAccounts,
select: function( event, ui ){
$('#member-account').val( ui.item.id );
},
+ })
+ $('#account_name2').autocomplete({
+ source: availableAccounts,
+ select: function( event, ui ){
+ $('#member-account2').val( ui.item.id );
+ },
});
{if $filterAccounts}