--- /dev/null
+<?php
+
+/**
+ * Gaslight Media Registrants Database
+ * Registrants List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmRegistrantsDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version 0.1
+ */
+
+
+// Load Registrant Info data abstract
+require_once GLM_MEMBERS_REGISTRATIONS_PLUGIN_CLASS_PATH.'/data/dataRegRequestRegistrant.php';
+
+/**
+ *
+ * This class exports the currently selected registrants list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_registrantsListExport extends GlmDataRegistrationsRequestRegistrant
+{
+
+ /**
+ * 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 registrant info records, also get primary contact data
+ $this->postProcessPrimaryContact = true;
+
+ $where = ' true ';
+ $categories = false;
+ $haveRegistrants = false;
+ $list = false;
+ $success = false;
+ $filterPending = false;
+ $filterArchived = 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;
+
+ // Check selected fields
+ $select = array(
+ 'exportId' => $this->checkFlag('exportId'),
+ 'exportRegistrant' => $this->checkFlag('exportRegistrant'),
+ 'exportAddr1' => $this->checkFlag('exportAddr1'),
+ 'exportAddr2' => $this->checkFlag('exportAddr2'),
+ 'exportCity' => $this->checkFlag('exportCity'),
+ 'exportState' => $this->checkFlag('exportState'),
+ 'exportZip' => $this->checkFlag('exportZip'),
+ 'exportEmail' => $this->checkFlag('exportEmail'),
+ 'exportPhone' => $this->checkFlag('exportPhone'),
+ 'exportCounty' => $this->checkFlag('exportCounty'),
+ );
+
+ // Get registration event ID if supplied
+ if (isset($_REQUEST['regEventID'])) {
+
+ // Make sure it's numeric
+ $regEventID = ($_REQUEST['regEventID'] - 0);
+
+ } else {
+
+ // Try to get saved
+ $regEventID = get_option('glmMembersDatabaseRegistrationsRegEventID');
+
+ }
+
+ if (!$regEventID || $regEventID <= 0) {
+ $regEventID = false;
+ }
+ // Only return information records that are active
+
+ $whereParts = array();
+ // Filter for complete if given
+ if ( isset( $_REQUEST['complete'] ) && filter_var( $_REQUEST['complete'], FILTER_VALIDATE_BOOLEAN) ) {
+ $completed = true;
+ $whereParts[] = "T.reg_request in (
+ SELECT id
+ FROM " . GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . "reg_request
+ WHERE status = {$this->config['submission_status_numb']['COMPLETE']})";
+ }
+
+ // Check for a text search
+ if (isset($_REQUEST['text_search']) && trim($_REQUEST['text_search'] != '')) {
+ $textSearch = trim($_REQUEST['text_search']);
+ $whereParts[] = "concat( T.fname, ' ', T.lname) LIKE '%".$textSearch."%'";
+
+ // Clean up for use in redisplaying search value
+ $textSearch = stripslashes($textSearch);
+ }
+
+ // Get list of all registrants for this event
+ $where = implode( ' AND ', $whereParts );
+
+ // $list = $this->getList($where, "lname");
+ $listResult = $this->getFullRegistrantsData($regEventID, $where, 1, false);
+ $list = $listResult['list'];
+
+ // If we have list entries - even if it's an empty list
+ $success = true;
+ $haveRegistrants = false;
+ if ($list !== false) {
+ $success = true;
+
+ // If we have any entries
+ $registrantCount = count($list);
+ if ($registrantCount > 0) {
+ $haveRegistrants = true;
+ }
+ }
+
+ // Compile template data
+ $templateData = array(
+ 'category_data' => $category_data,
+ 'select' => $select,
+ 'haveRegistrants' => $haveRegistrants,
+ 'registrants' => $list,
+ 'registrantCount' => $registrantCount,
+ '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
+ );
+
+ $view = 'admin/ajax/registrantsListExport.html';
+ if ($_REQUEST['type'] == 'csv') {
+ $view = 'admin/ajax/registrantsListExportCsv.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
+<html>
+ <head>
+ </head>
+ <body>
+
+ <span style="float: right;"><b>Total found: {$registrantCount} </b></span>
+ <b>List of {$terms.reg_term_attendee_plur_cap}</b>
+ <br clear="all">
+
+
+ <table>
+ <thead>
+ <tr>
+ {if $select.exportId}<th align="left">ID</th>{/if}
+ {if $select.exportRegistrant}<th align="left">{$terms.reg_term_attendee_cap} Name</th>{/if}
+ {if $select.exportAddr1}<th align="left">Address</th>{/if}
+ {if $select.exportAddr2}<th align="left">Addr Line #2</th>{/if}
+ {if $select.exportCity}<th align="left">City</th>{/if}
+ {if $select.exportState}<th align="left">State</th>{/if}
+ {if $select.exportZip}<th align="left">ZIP</th>{/if}
+ {if $select.exportCounty}<th align="left">County</th>{/if}
+ {if $select.exportEmail}<th align="left">Email</th>{/if}
+ {if $select.exportPhone}<th align="left">Phone</th>{/if}
+ </tr>
+ </thead>
+ <tbody>
+ {if $haveRegistrants}
+ {foreach $registrants as $m}
+ <tr>
+ {if $select.exportId}<td>{$m.id}</td>{/if}
+ {if $select.exportRegistrant}<td>{$m.fname} {$m.lname}</td>{/if}
+ {if $select.exportAddr1}<td>{$m.account.addr1}</td>{/if}
+ {if $select.exportAddr2}<td>{$m.account.addr2}</td>{/if}
+ {if $select.exportCity}<td>{$m.account.city}</td>{/if}
+ {if $select.exportState}<td>{if $m.account.state}{$m.account.state.value}{/if}</td>{/if}
+ {if $select.exportZip}<td>{$m.account.zip}</td>{/if}
+ {if $select.exportCounty}<td>{if $m.account.county}{$m.account.county.value}{/if}</td>{/if}
+ {if $select.exportEmail}<td>{$m.account.email}</td>{/if}
+ {if $select.exportPhone}<td>{$m.account.phone}</td>{/if}
+
+ </tr>
+ {/foreach}
+ {else}
+ <tr class="alternate"><td colspan="2">(no {$terms.reg_term_attendee_plur_cap} listed)</td></tr>
+ {/if}
+ </tbody>
+ </table>
+
+ </body>
+</html>
--- /dev/null
+{if $haveRegistrants}
+{if $select.exportId}"ID",{/if}
+{if $select.exportRegistrant}"{$terms.reg_term_attendee_cap} Name",{/if}
+{if $select.exportAddr1}"Address",{/if}
+{if $select.exportAddr2}"Addr Line #2",{/if}
+{if $select.exportCity}"City",{/if}
+{if $select.exportState}"State",{/if}
+{if $select.exportZip}"ZIP/Postal",{/if}
+{if $select.exportCounty}"County",{/if}
+{if $select.exportRegion}"Region",{/if}
+{if $select.exportEmail}"Email",{/if}
+{if $select.exportPhone}"Phone"{/if}
+
+{foreach $registrants as $m}
+{if $select.exportId}"{$m.id}",{/if}
+{if $select.exportRegistrant}"{$m.registrant}",{/if}
+{if $select.exportAddr1}"{$m.account.addr1}",{/if}
+{if $select.exportAddr2}"{$m.account.addr2}",{/if}
+{if $select.exportCity}"{$m.account.city}",{/if}
+{if $select.exportState}"{if $m.account.state}{$m.account.state.value}{/if}",{/if}
+{if $select.exportZip}"{$m.account.zip}",{/if}
+{if $select.exportCounty}"{if $m.account.county}{$m.county.account.value}{/if}",{/if}
+{if $select.exportEmail}"{$m.account.email}",{/if}
+{if $select.exportPhone}"{$m.account.phone}"{/if}
+
+{/foreach}
+{else}No {$terms.reg_term_attendee_plur_cap} Selected{/if}
<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="registrantsListExport">
+ <input type="hidden" name="regEventID" value="{$regEvent.id}">
<table class="glm-admin-table">
<tr><th>Show Only Completed:</th><td><input type="checkbox" name="complete" value="1"></td></tr>
<tr>
<th>Name Search:</th>
- <td><input type="text" name="" value=""></td>
+ <td><input type="text" name="text_search" value=""></td>
</tr>
<tr>
<th>Fields to export:</th>
<tr>
<td class="exportFieldsTd">
<input type="checkbox" name="exportId"> {$terms.reg_term_attendee_cap} ID<br>
- <input type="checkbox" name="exportMember" checked> {$terms.reg_term_attendee_cap} Name<br>
+ <input type="checkbox" name="exportRegistrant" checked> {$terms.reg_term_attendee_cap} Name<br>
<input type="checkbox" name="exportAddr1" checked> Address Line #1<br>
<input type="checkbox" name="exportAddr2" checked> Address Line #2<br>
<input type="checkbox" name="exportCity" checked> City<br>
<input type="checkbox" name="exportState" checked> State<br>
<input type="checkbox" name="exportZip" checked> ZIP/Postal Code<br>
+ <input type="checkbox" name="exportEmail" checked> Email <br>
<input type="checkbox" name="exportPhone" checked> Phone <br>
<input type="checkbox" name="exportCounty" checked> County <br>
</td>
</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="exportRegistrantsCancel" class="button button-secondary glm-right">Cancel</a>
+ <input type="submit" value="Export" class="button button-primary">
</form>
</div>
autoOpen: false,
minWidth: 500,
dialogClass: 'glm-dialog-no-close',
- buttons: {
- 'Export CSV': function(){
- console.log('doing something');
- },
- // 'Print': function() {
- // console.log( 'Print something' );
- // },
- Cancel: function(){
- dialog.dialog( 'close' );
- },
- },
});
$('#exportRegistrantsButton').click(function(){
$('#exportRegistrantsDialog').dialog('open');
});
+ $('#exportRegistrantsCancel').click(function(){
+ $('#exportRegistrantsDialog').dialog('close');
+ });
});
</script>