From: Anthony Talarico Date: Tue, 21 Mar 2017 19:24:06 +0000 (-0400) Subject: adding admin search fields, adding export functionality X-Git-Tag: v1.0.0^2~21 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=47d87b73764dd2a431ae4468c4e2a57bc1158dbe;p=WP-Plugins%2Fglm-member-db-obits.git adding admin search fields, adding export functionality --- diff --git a/classes/data/dataObits.php b/classes/data/dataObits.php index c47953f..f35aada 100644 --- a/classes/data/dataObits.php +++ b/classes/data/dataObits.php @@ -280,8 +280,9 @@ class GlmDataObits extends GlmDataAbstract $savedFields = $this->fields; $this->fields = array( - 'id' => $savedFields['id'], - 'last_name' => $savedFields['last_name'] + 'id' => $savedFields['id'], + 'last_name' => $savedFields['last_name'], + 'first_mid' => $savedFields['first_mid'] ); $r = $this->getList($where); diff --git a/css/admin.css b/css/admin.css index 2352fe2..b7b0733 100644 --- a/css/admin.css +++ b/css/admin.css @@ -22,3 +22,7 @@ padding-left: 0px; padding-right: 10px; } +.wp-admin .obit-search-select{ + height: 24px; + margin-bottom: 5px; +} diff --git a/models/admin/ajax/obitsExport.php b/models/admin/ajax/obitsExport.php new file mode 100644 index 0000000..1fcf422 --- /dev/null +++ b/models/admin/ajax/obitsExport.php @@ -0,0 +1,188 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Obits data abstract +require_once GLM_MEMBERS_OBITS_PLUGIN_CLASS_PATH.'/data/dataObits.php'; + +/** + * + * This class exports the currently selected members list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_obitsExport extends GlmDataObits +{ + + /** + * 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) + { + $where = ''; + $haveObits = false; + $list = false; + $success = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = ''; // Set to the number of listings per page + $namesList = false; + + // Check selected fields + $select = array( + 'exportId' => $this->checkFlag('exportId'), + 'exportLastName' => $this->checkFlag('exportLastName'), + 'exportFirstMiddle' => $this->checkFlag('exportFirstMiddle'), + 'exportBirthYear' => $this->checkFlag('exportBirthYear'), + 'exportDeathYear' => $this->checkFlag('exportDeathYear'), + 'exportBirthYearRange' => $this->checkFlag('exportBirthYearRange'), + 'exportDeathYearRange' => $this->checkFlag('exportDeathYearRange'), + 'exportSpouse' => $this->checkFlag('exportSpouse'), + 'exportMaiden' => $this->checkFlag('exportMaiden'), + 'exportObitArticle' => $this->checkFlag('exportObitArticle'), + 'exportArticleA' => $this->checkFlag('exportArticleA'), + 'exportArticleB' => $this->checkFlag('exportArticleB'), + 'exportMailingArticleC' => $this->checkFlag('exportMailingArticleC'), + 'exportMailingNewspaper' => $this->checkFlag('exportMailingNewspaper'), + 'exportNewspaperDate' => $this->checkFlag('exportNewspaperDate'), + 'exportFather' => $this->checkFlag('exportFather'), + 'exportMother' => $this->checkFlag('exportMother'), + 'exportMiscInfo' => $this->checkFlag('exportMiscInfo') + ); + + // Check for a text search + if (trim($_REQUEST['text_search']) != '') { + + $textSearch = addslashes(filter_input(INPUT_POST, 'text_search', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); + $where = "last_name like '%$textSearch%'"; + } + + + // Get a current list of members without paging + $list = $this->getList($where,'last_name'); +// $list = $list['list']; + + //exit; + + // If we have list entries - even if it's an empty list + $success = true; + if ($list !== false) { + + $success = true; + + // If we have any entries + $obitCount = count($list); + if ($obitCount > 0) { + $haveObits = true; + } + } + + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) { + glmMembersAdmin::addNotice($list, 'DataBlock', 'Member Data'); + } + + // Compile template data + $templateData = array( + 'select' => $select, + 'haveObits' => $haveObits, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList, + 'obits' => $list, + 'total' => $total_records + ); + + $view = 'admin/ajax/obitsExport.html'; + if ($_REQUEST['type'] == 'csv') { + $view = 'admin/ajax/obitsExportCsv.html'; + header("Content-Type: text/csv"); + header("Content-Disposition: attachment; filename=obits.csv"); + } else { + header("Content-Type: text/html"); + header("Content-Disposition: attachment; filename=obits.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 + ); + + } + +} diff --git a/models/admin/obits/list.php b/models/admin/obits/list.php index 7dc1374..75ebd9d 100644 --- a/models/admin/obits/list.php +++ b/models/admin/obits/list.php @@ -222,46 +222,55 @@ class GlmMembersAdmin_obits_list extends GlmDataObits default: $where = 'true'; - + $search_fields = array(); + // Check if we have a Text Search string if (isset($_REQUEST['last_name']) && trim($_REQUEST['last_name']) != '') { $textSearch = trim($_REQUEST['last_name']); $where .= " AND last_name LIKE '%$textSearch%'"; + $search_fields['last'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['first_mid']) && trim($_REQUEST['first_mid']) != '') { $textSearch = trim($_REQUEST['first_mid']); $where .= " AND first_mid LIKE '%$textSearch%'"; + $search_fields['first'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['spouse_partner']) && trim($_REQUEST['spouse_partner']) != '') { $textSearch = trim($_REQUEST['spouse_partner']); $where .= " AND spouse_partner LIKE '%$textSearch%'"; + $search_fields['spouse'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['maiden_other']) && trim($_REQUEST['maiden_other']) != '') { $textSearch = trim($_REQUEST['maiden_other']); $where .= " AND maiden_other LIKE '%$textSearch%'"; + $search_fields['maiden'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['b_year']) && trim($_REQUEST['b_year']) != '') { $textSearch = trim($_REQUEST['b_year']); $where .= " AND b_year LIKE '%$textSearch%'"; + $search_fields['birth'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['d_year']) && trim($_REQUEST['d_year']) != '') { $textSearch = trim($_REQUEST['d_year']); $where .= " AND d_year LIKE '%$textSearch%'"; + $search_fields['death'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['d_yr_range']) && trim($_REQUEST['d_yr_range']) != '') { $textSearch = trim($_REQUEST['d_yr_range']); $where .= " AND d_yr_range LIKE '%$textSearch%'"; + $search_fields['d_range'] = $textSearch; } // Check if we have a Text Search string if (isset($_REQUEST['b_yr_range']) && trim($_REQUEST['b_yr_range']) != '') { $textSearch = trim($_REQUEST['b_yr_range']); $where .= " AND b_yr_range LIKE '%$textSearch%'"; + $search_fields['b_range'] = $textSearch; } // Get the total number of obits listed @@ -274,7 +283,13 @@ class GlmMembersAdmin_obits_list extends GlmDataObits // Get full list of names matching this where clause for search box $namesList = $this->getIdName($where); - + $uniqueNames = array(); + foreach($namesList as $name){ + if( !in_array($name['last_name'], $uniqueNames ) ){ + $uniqueNames[] = $name['last_name']; + } + } + // Check if we're doing paging if (isset($_REQUEST['pageSelect'])) { @@ -291,7 +306,7 @@ class GlmMembersAdmin_obits_list extends GlmDataObits $start = $newStart; } } - + // Get the list of obits and determine number of obits in list $obitsResult = $this->getList($where, 'last_name', true, 'id', $start, $limit); @@ -342,10 +357,11 @@ class GlmMembersAdmin_obits_list extends GlmDataObits 'nextStart' => $nextStart, 'start' => $start = 1, 'limit' => $limit, - 'namesList' => $namesList, + 'namesList' => $uniqueNames, 'obitDeleted' => $obitDeleted, 'obitDeleteError' => $obitDeleteError, - 'birthDeathRange' => $birth_death_range + 'birthDeathRange' => $birth_death_range, + 'search_fields' => $search_fields ); diff --git a/setup/validActions.php b/setup/validActions.php index 8e3028d..7d50f36 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -59,6 +59,9 @@ $glmMembersObitsAddOnValidActions = array( 'adminActions' => array( + 'ajax' => array( + 'obitsExport' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, + ), 'obits' => array( 'index' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, 'list' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, diff --git a/views/admin/ajax/obitsExport.html b/views/admin/ajax/obitsExport.html new file mode 100644 index 0000000..c627c24 --- /dev/null +++ b/views/admin/ajax/obitsExport.html @@ -0,0 +1,16 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ + diff --git a/views/admin/ajax/obitsExportCsv.html b/views/admin/ajax/obitsExportCsv.html new file mode 100644 index 0000000..a1df7de --- /dev/null +++ b/views/admin/ajax/obitsExportCsv.html @@ -0,0 +1,43 @@ +{if $haveObits} + +{if $select.exportId}"ID",{/if} +{if $select.exportLastName}"LAST_NAME",{/if} +{if $select.exportFirstMiddle}"FIRST_MIDDLE",{/if} +{if $select.exportBirthYear}"BIRTH_YEAR",{/if} +{if $select.exportDeathYear}"DEATH_YEAR",{/if} +{if $select.exportBirthYearRange}"BIRTH_YEAR_RANGE",{/if} +{if $select.exportDeathYearRange}"DEATH_YEAR_RANGE",{/if} +{if $select.exportArticleA}"ARTICLE_A",{/if} +{if $select.exportArticleB}"ARTICLE_B",{/if} +{if $select.exportMailingArticleC}"ARTICLE_C",{/if} +{if $select.exportMailingNewspaper}"NEWSPAPER",{/if} +{if $select.exportNewspaperDate}"NEWSPAPER_DATE",{/if} +{if $select.exportSpouse}"SPOUSE",{/if} +{if $select.exportMaiden}"MAIDEN_OTHER",{/if} +{if $select.exportFather}"FATHER",{/if} +{if $select.exportMother}"MOTHER",{/if} +{if $select.exportMiscInfo}"MISC_INFO",{/if} +{if $select.exportObitArticle}"OBIT_ARTICLE"{/if} + +{foreach $obits as $o} +{if $select.exportId}"{$o.id}",{/if} +{if $select.exportLastName}"{$o.last_name}",{/if} +{if $select.exportFirstMiddle}"{$o.first_mid}",{/if} +{if $select.exportBirthYear}"{$o.b_year}",{/if} +{if $select.exportDeathYear}"{$o.d_year}",{/if} +{if $select.exportBirthYearRange}"{$o.b_yr_range}",{/if} +{if $select.exportDeathYearRange}"{$o.d_yr_range}",{/if} +{if $select.exportArticleA}"{$o.article_a}",{/if} +{if $select.exportArticleB}"{$o.article_b}",{/if} +{if $select.exportArticleC}"{$o.article_c}",{/if} +{if $select.exportNewspaper}"{$o.newspaper}",{/if} +{if $select.exportNewspaperDate}"{$o.newspaper_date}",{/if} +{if $select.exportSpouse}"{$o.spouse_partner}",{/if} +{if $select.exportMaiden}"{$o.maiden_other}",{/if} +{if $select.exportFather}"{$o.father_name}",{/if} +{if $select.exportMother}"{$o.mother_name}",{/if} +{if $select.exportMiscInfo}"{$o.misc_info}",{/if} +{if $select.exportObitArticle}"{$o.obit_article}"{/if} + +{/foreach} +{/if} \ No newline at end of file diff --git a/views/admin/obits/list.html b/views/admin/obits/list.html index b0d062e..668064d 100644 --- a/views/admin/obits/list.html +++ b/views/admin/obits/list.html @@ -17,42 +17,56 @@
@@ -67,7 +81,7 @@ {/if} - +
Export Obits
@@ -104,10 +118,76 @@ {/if} +
+
+ + +
+ + + + + + + + + + +
Last Name Search:
+ Enter any portion of a {$terms.term_member_cap} name and press enter or select any specific {$terms.term_member_cap} found. +
Fields to export + + + + + +
+ Obit ID
+ Last Name
+ First Middle
+ Birth Year
+ Death Year
+ Birth Year Range
+ Death Year Range
+ Article A
+ Article B
+
+ Article C
+ Newspaper
+ Newspaper Date
+ Spouse / Partner
+ Maiden / Other
+ Father
+ Mother
+ Misc Info
+ Obit Article
+
+
Export to: + Export for Print
+ Export to Spreadsheet (CSV) +
+ Cancel + + +