--- /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/dataPayments.php';
+
+/**
+ *
+ * This class exports the currently selected accounts list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_paymentsListExport extends GlmDataPayments
+{
+
+ /**
+ * 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;
+ $havePayments = 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;
+ $where_params = array();
+
+ // Check selected fields
+ $select = array(
+ 'exportId' => $this->checkFlag('exportId'),
+ 'exportMember' => $this->checkFlag('exportMember'),
+ 'exportTime' => $this->checkFlag('exportTime'),
+ 'exportAmount' => $this->checkFlag('exportAmount'),
+ 'exportPaymentMethod' => $this->checkFlag('exportPaymentMethod'),
+ 'exportPaymentData' => $this->checkFlag('exportPaymentData'),
+ );
+
+ // Only return information records that are active
+
+ // 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.transaction_time >= '$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.transaction_time <= '$to_date'";
+ }
+ if ( isset( $_REQUEST['filterAccounts'] )
+ && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT )
+ ) {
+ $accounts[$filterAccounts]['selected'] = true;
+ $where_params[] = "T.account = $filterAccounts";
+ }
+
+ // 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 = 'transaction_time ASC';
+ $list = $this->getList( $where, $orderBy, true );
+
+ // echo '<pre>$list: ' . print_r( $list, true ) . '</pre>';
+ // die('here');
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $havePayments = false;
+ if ($list !== false) {
+ $success = true;
+ $paymentCount = count($list);
+ $havePayments = true;
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'select' => $select,
+ 'havePayments' => $havePayments,
+ 'payments' => $list,
+ 'paymentCount' => $paymentCount,
+ 'haveFilter' => $haveFilter,
+ 'numbDisplayed' => $numbDisplayed,
+ 'lastDisplayed' => $lastDisplayed,
+ 'paging' => $paging,
+ 'prevStart' => $prevStart,
+ 'nextStart' => $nextStart,
+ 'start' => $start,
+ 'limit' => $limit,
+ 'namesList' => $namesList
+ );
+
+ $view = 'admin/ajax/paymentsListExport.html';
+ if ($_REQUEST['type'] == 'csv') {
+ $view = 'admin/ajax/paymentsListExportCsv.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
+ );
+
+ }
+
+}
--- /dev/null
+<div id="exportPaymentDialog" class="glm-dialog-box" title="Export Billing Payments">
+ <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="paymentsListExport">
+ <table class="glm-admin-table">
+ <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"> Payment ID<br>
+ <input type="checkbox" name="exportMember" checked> {$terms.term_member_cap} Name<br>
+ <input type="checkbox" name="exportTime" checked> Time <br>
+ <input type="checkbox" name="exportAmount" checked> Amount <br>
+ <input type="checkbox" name="exportPaymentMethod" checked> Payment Method <br>
+ <input type="checkbox" name="exportPaymentData" checked> Payment Notes <br>
+
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ <tr>
+ <th>Export to: </th>
+ <td>
+ <input type="radio" name="type" value="csv" checked="checked"> Export to Spreadsheet (CSV)<br>
+ <input type="radio" name="type" value="print"> Export for Print
+ </td>
+ </tr>
+ </table>
+ <a id="exportPaymentsCancel" class="button button-secondary glm-right">Cancel</a>
+ <input type="submit" value="Export" class="button button-primary" autofocus>
+ </form>
+</div>
+
+<script>
+jQuery(document).ready(function($) {
+
+ // Setup for the modal box
+ $('#exportPaymentDialog').dialog( {
+ autoOpen: false,
+ minWidth: 700,
+ dialogClass: 'glm-dialog-no-close'
+ } );
+ $('#exportPaymentsButton').click( function(){
+ $('#exportPaymentDialog').dialog( 'open' );
+ } );
+ $('#exportPaymentsCancel').click( function(){
+ $('#exportPaymentDialog').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);
+ });
+ });
+
+});
+</script>