From e05bfedbd476f485cb9eac895ab4ffadfd6dd948 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 8 Mar 2017 16:54:39 -0500 Subject: [PATCH] adding mgmt section for importing obits, adding js for front end hiding showing, adding styles and structure for the search results --- css/front.css | 62 ++++- js/admin.js | 2 + js/front.js | 10 + models/admin/management/obitImport.php | 201 +++++++++++++++ models/front/obits/search.php | 98 +++---- setup/adminTabs.php | 16 ++ setup/validActions.php | 3 + views/admin/management/obitImport.html | 37 +++ views/front/obits/search.html | 344 +++++++++++++------------ views/front/obits/searchResults.html | 244 ++++++++++++++++++ 10 files changed, 799 insertions(+), 218 deletions(-) create mode 100644 js/admin.js create mode 100644 js/front.js create mode 100644 models/admin/management/obitImport.php create mode 100644 views/admin/management/obitImport.html diff --git a/css/front.css b/css/front.css index 0440fdc..f76e523 100644 --- a/css/front.css +++ b/css/front.css @@ -1,10 +1,6 @@ -body .search-row{ - margin: 0 15px; - padding: 10px 0; -} -.search-container{ - width: 50%; - margin: 0 auto; + +.search-sidebar .search-row{ + padding: 5px 0; } @media (min-width: 640px) and (max-width: 1024px){ @@ -24,4 +20,56 @@ body .search-row{ width: 100%; margin: 0 auto; } +} +@media (max-width: 1024px){ + .search-sidebar-container{ + clear: both; + } + .results-container{ + padding: 0; + } + .search-sidebar-container{ + padding: 0; + } +} +.search-label{ + font-size: 13px; + font-weight: bold; +} +.search-sidebar .search-label{ + font-size: 15px; +} + +.search-sidebar input[type=text]{ + height: 25px; +} +.search-sidebar select{ + margin: 4px 0 8px 0; + height: 25px; + padding: 2px; +} +.search-container label{ + float: left; + margin-right: 5px; +} +.search-container:not(.sidebar-container) .search-label{ + padding: 0px; +} +.search-container:not(.sidebar-container) .search-row{ + margin: 0 15px; + padding: 0px 0; +} +.search-container{ +/* width: 50%;*/ + margin: 0 auto; +} +.search-container input, .search-container select{ + margin: 5px 0; +} +.search-container div{ + margin: 0; + padding: 0 10px; +} +.options-wrapper{ + display: none; } \ No newline at end of file diff --git a/js/admin.js b/js/admin.js new file mode 100644 index 0000000..139597f --- /dev/null +++ b/js/admin.js @@ -0,0 +1,2 @@ + + diff --git a/js/front.js b/js/front.js new file mode 100644 index 0000000..3d27be4 --- /dev/null +++ b/js/front.js @@ -0,0 +1,10 @@ +$(document).ready(function(){ + $(".expand-collapse").on("click", function(e){ + e.preventDefault(); + + $('.options-wrapper').slideToggle(500, function () { + + }); + + }); +}); \ No newline at end of file diff --git a/models/admin/management/obitImport.php b/models/admin/management/obitImport.php new file mode 100644 index 0000000..a54e5c6 --- /dev/null +++ b/models/admin/management/obitImport.php @@ -0,0 +1,201 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +/** + * This class performs the work for the default action of the "Members" menu + * option, which is to display the members dashboard. + * + */ +class GlmMembersAdmin_management_obitImport +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This contractor 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; + + } + + public function addScheme($url, $scheme = 'http://') + { + return parse_url($url, PHP_URL_SCHEME) === null ? + $scheme . $url : $url; + } + + /** + * Perform Model Action + * + * This method does the work for this model and returns any resulting data + * + * @return array Status and data array + * + * 'status' + * + * True if successful and false if there was a fatal failure. + * + * 'menuItemRedirect' + * + * If not false, provides a menu item the controller should + * execute after this one. Normally if this is used, there would also be a + * modelRedirect value supplied as well. + * + * 'modelRedirect' + * + * If not false, provides an action the controller should execute after + * this one. + * + * 'view' + * + * A suggested view name that the controller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + */ + public function modelAction ($actionData = false) + { + + + $resultMessage = ''; + $success = false; + $haveMembers = false; + $import = false; + $importNotice = ''; + $option = ''; + + if (isset($_REQUEST['option']) && $_REQUEST['option'] != '') { + $option = $_REQUEST['option']; + } + + switch($option) { + case 'upload_file': + // We're given a CSV file. + // We need to parse it out. File must have header line. + $file_data = $file_headers = $data = $members = array(); + + if ( isset( $_FILES ) && isset( $_FILES['file_upload'] ) && ( $fh = fopen( $_FILES['file_upload']['tmp_name'], 'r' ) ) !== false ) { + $row = 0; + while( ( $data = fgetcsv( $fh, 1000, ',' ) ) !== false ) { + if ( $row === 0 ) { + // First row grab as headers. + $file_headers = $data; + } else { + // All other rows are data. + $file_data[] = array_combine( $file_headers, $data ); + } + $row++; + } + fclose( $fh ); + } + $resultMessage .= $this->importMemberData( $file_data ); + //$resultMessage .= '
$file_data: ' . print_r( $file_data, true ) . '
'; + break; + + case 'importObits': + $article_url = "http://obits.charlevoixlibrary.org/articles/"; + + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } else { + $start = 0; + } + global $wpdb; + $table = GLM_MEMBERS_OBITS_PLUGIN_DB_PREFIX . 'obits'; + + $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=obitImport&option=importObits'; + $limit = 400; + + $sql = "SELECT last, first_mid, b_year, b_yr_range,d_year, d_yr_range,spouse_partner, maiden_other,obit_article,article_a, article_b, article_c, father_name,mother_name,misc_info, courier_date FROM chxctyobit LIMIT $limit OFFSET $start"; + $obits = $wpdb->get_results( $sql, ARRAY_A ); + + $count = 0; + foreach($obits as $column=>$data){ + $count++; + $insert = array(); + foreach($data as $key=>$value){ + if($key === 'last'){ + $key = 'last_name'; + } + if($key === 'd_yr_range' || $key === 'b_yr_range'){ + $value = substr($value, 0, 4); + } + if($key === 'courier_date'){ + $key = 'newspaper_date'; + } + $insert[$key] = $value; + } +// echo '
', print_r($insert), '
'; +// $wpdb->insert($table, $insert); + } + echo $count; +// echo '
', print_r($insert), '
'; + + $resultMessage = "
Start: $start
"; + $start += $limit; + $resultMessage .= "

Next

"; + + break; + + default: + break; + } + + $templateData = array( + 'success' => $success, + 'option' => $option, + 'resultMessage' => $resultMessage + ); + + // Return status, suggested view, and data to controller + return array( + 'status' => true, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => 'admin/management/obitImport.html', + 'data' => $templateData + ); + + } +} diff --git a/models/front/obits/search.php b/models/front/obits/search.php index 257e277..0845e16 100644 --- a/models/front/obits/search.php +++ b/models/front/obits/search.php @@ -91,66 +91,70 @@ class GlmMembersFront_obits_search extends GlmDataObits $view = 'search'; -// $sql_all = "SELECT * FROM $this->table"; + $sql = "SELECT * FROM $this->table"; // $sql_where = "SELECT * FROM $this->table WHERE "; $year_ranges = new glmObitSupportFunctions($this->wpdb, $this->config); $birth_death_range = array('birth' => $year_ranges->getObitYearRange(BIRTH_YEAR_START), 'death' => $year_ranges->getObitYearRange(DEATH_YEAR_START)); - $logic_dropdown = array('Contains','Starts','Equals', 'More than', 'Less than', 'Between', 'Empty'); - $form_data = $_REQUEST; - - $form_fields = array( - $last = filter_var( $_REQUEST['last_name'], FILTER_SANITIZE_STRING), - $first = filter_var( $_REQUEST['first_mid'], FILTER_SANITIZE_STRING), - $byear = filter_var( $_REQUEST['b_year'], FILTER_SANITIZE_STRING), - $byear_range = filter_var( $_REQUEST['b_yr_range'], FILTER_SANITIZE_STRING), - $dyear = filter_var( $_REQUEST['d_year'], FILTER_SANITIZE_STRING), - $dyear_range = filter_var( $_REQUEST['d_yr_range'], FILTER_SANITIZE_STRING), - $maiden = filter_var( $_REQUEST['maiden_other'], FILTER_SANITIZE_STRING), - $spouse = filter_var( $_REQUEST['spouse_partner'], FILTER_SANITIZE_STRING) - ); - -// $last = filter_var( $_REQUEST['last_name'], FILTER_SANITIZE_STRING); -// $first = filter_var( $_REQUEST['first_mid'], FILTER_SANITIZE_STRING); -// $byear = filter_var( $_REQUEST['b_year'], FILTER_SANITIZE_STRING); -// $byear_range = filter_var( $_REQUEST['b_yr_range'], FILTER_SANITIZE_STRING); -// $dyear = filter_var( $_REQUEST['d_year'], FILTER_SANITIZE_STRING); -// $dyear_range = filter_var( $_REQUEST['d_yr_range'], FILTER_SANITIZE_STRING); -// $maiden = filter_var( $_REQUEST['maiden_other'], FILTER_SANITIZE_STRING); -// $spouse = filter_var( $_REQUEST['spouse_partner'], FILTER_SANITIZE_STRING); -// - - $sql = "SELECT * FROM $this->table WHERE last_name = '$last' OR first_mid = '$first' OR b_year = '$byear' OR b_yr_range = '$byear_range' OR d_year = '$dyear' OR d_yr_range = '$dyear_range' OR maiden_other = '$maiden' OR spouse_partner = '$spouse';"; + $logic_dropdown = array('Contains' => 'LIKE' ,'Starts With' => 'LIKE%','Equals' => '=', 'More than' => '>', 'Less than' => '<'); + $form_data = $_REQUEST; - if( isset( $_REQUEST['any-condition'] ) ){ - $clause = 'OR'; - } else if ( isset( $_REQUEST['all-conditions'] ) ) { - $clause = 'AND'; + if( isset( $_REQUEST['conditions'] ) && $_REQUEST['conditions'][0] == 'any'){ + $clause = ' OR '; + } else if ( isset( $_REQUEST['conditions'] ) && $_REQUEST['conditions'][0] == 'all') { + $clause = ' AND '; } - -// echo '
', print_r($form_data), '
'; - // no restrictions - $obits = $this->wpdb->get_results($sql, 'ARRAY_A'); -// echo '
', print_r($obits), '
'; - - + foreach($form_data as $key=>$value){ if (isset($value) && $value !== ''){ - if( $value !== 'Search' && $value !== 'search-results' && $key !== 'conditions'){ - $value = filter_var($value, FILTER_SANITIZE_STRING); - $queries[$key] = array('field' => $value); -// echo $value; - + if( $value !== 'Search' && $key !== 'conditions'){ + if(strpos($key,'-logic') === false && strpos($key,'not-') === false ) { + $value = filter_var($value, FILTER_SANITIZE_STRING); + $search_fields[$key] = $value; + } else { + $search_options[$key] = $value; + } } } } -// echo '
', print_r($queries), '
'; - foreach($queries as $key=>$value){ -// print_r($value); + + foreach($search_fields as $field => $f){ + + foreach($search_options as $option => $o){ + + if( strpos($option, $field) !== false){ + + if(strpos($option, 'not') !== false){ + + $o = '<>'; + $search_fields[$field] = $field . " $o " . "'$f'"; + + break; + + } else if(strpos($o, '%') !== false){ + $o = rtrim($o, "%"); + $search_fields[$field] = $field . " $o " . "'$f%'"; + } else if($o === 'LIKE') { + $search_fields[$field] = $field . " $o " . "'%$f%'"; + } else { + $search_fields[$field] = $field . " $o " . "'$f'"; + } + } + } } - if( isset($_REQUEST['search-results']) ){ + $search = implode($clause, $search_fields); + + $sql = "SELECT * FROM $this->table LIMIT 10" . + (empty($search) ? "" : " WHERE $search"); +// echo '
', print_r($search_fields), '
'; + echo $sql; + + $obits = $this->wpdb->get_results($sql, 'ARRAY_A'); +// echo '
', print_r($obits), '
'; + + if( isset($_REQUEST['searchButton']) ){ $view = 'searchResults'; } @@ -171,4 +175,4 @@ class GlmMembersFront_obits_search extends GlmDataObits ); } -} \ No newline at end of file +} diff --git a/setup/adminTabs.php b/setup/adminTabs.php index a0088bf..b89f0d1 100644 --- a/setup/adminTabs.php +++ b/setup/adminTabs.php @@ -43,7 +43,23 @@ if (current_user_can('glm_members_members')) { 'menu' => 'settings', 'action' => 'newspapers' ), + ); + $addOnTabs = array_merge($addOnTabs, $newTabs); + return $addOnTabs; + } + ); + } + if (apply_filters('glm_members_permit_admin_members_management_tab', true)) { + + add_filter('glm-member-db-add-tab-for-management', + function($addOnTabs) { + $newTabs = array( + array( + 'text' => 'Obits Import', + 'menu' => 'management', + 'action' => 'obitImport' + ), ); $addOnTabs = array_merge($addOnTabs, $newTabs); return $addOnTabs; diff --git a/setup/validActions.php b/setup/validActions.php index f9a0d2c..8e3028d 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -66,6 +66,9 @@ $glmMembersObitsAddOnValidActions = array( 'settings' => array( 'newspapers' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, ), + 'management' => array( + 'obitImport' => GLM_MEMBERS_OBITS_PLUGIN_SLUG, + ), ), 'frontActions' => array( 'obits' => array( diff --git a/views/admin/management/obitImport.html b/views/admin/management/obitImport.html new file mode 100644 index 0000000..f5a0c1e --- /dev/null +++ b/views/admin/management/obitImport.html @@ -0,0 +1,37 @@ +{include file='admin/management/header.html'} + +

Obits Importer

+ +{if $option == ''} +
+ + +
+

Import Obits

+{/if} + +{if $resultMessage} + {$resultMessage} +{/if} + +{include file='admin/footer.html'} + diff --git a/views/front/obits/search.html b/views/front/obits/search.html index 56f9f5a..a454b38 100644 --- a/views/front/obits/search.html +++ b/views/front/obits/search.html @@ -1,167 +1,183 @@ -
- + + +
+
+ Maiden or Other Name: +
+
+ + +
+
+ +
+
+ +
+
+ + +
+
+ Spouse / Partner Name: +
+
+ + +
+
+ +
+
+ +
+
+ + + +
\ No newline at end of file diff --git a/views/front/obits/searchResults.html b/views/front/obits/searchResults.html index e69de29..98ed53f 100644 --- a/views/front/obits/searchResults.html +++ b/views/front/obits/searchResults.html @@ -0,0 +1,244 @@ +
+
+ + + + + + + + + + + + + + {foreach from=$obits item=i} + + + + + + + + + + + {/foreach} +
Birth Year RangeDeath Year RangeLast NameFirst NameBirth YearDeath YearSpouseMaiden Name
{$i.b_yr_range}{$i.d_yr_range}{$i.last_name}{$i.first_mid}{$i.b_year}{$i.d_year}{$i.spouse_partner}{$i.maiden_other}
+
+
+
+ + +
+
+
\ No newline at end of file -- 2.17.1