From 775f4a97a291e27f2082dd8a3736cf0da97e2959 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 22 Jun 2017 12:27:05 -0400 Subject: [PATCH] Work on the file upload for photos Validate the header line. --- models/admin/import/index.php | 30 +++++++++++++++++++++--------- views/admin/import/header.html | 2 ++ views/admin/import/index.html | 2 +- views/admin/import/photos.html | 6 +----- views/admin/import/validate.html | 13 +++++++++++++ 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 902053c7..5ec84a2b 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -182,10 +182,16 @@ class GlmMembersAdmin_import_index */ public function modelAction ($actionData = false) { - $view = 'index.html'; - $failure = false; - $option = 'default'; - $clearData = false; + $view = 'index.html'; + $failure = false; + $option = 'default'; + $clearData = false; + $haveMembers = false; + // Check to see if they have members + $haveMembers = $this->wpdb->get_var( + "SELECT count(id) + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members" + ); if ( isset( $_REQUEST['numberProcessed'] ) ) { $this->numberProcessed = filter_var( $_REQUEST['numberProcessed'], FILTER_VALIDATE_INT ); } @@ -378,16 +384,20 @@ class GlmMembersAdmin_import_index case 'photosValidate': if ( isset( $_FILES ) ) { - move_uploaded_file( $_FILES['photos_file']['tmp_name'], $uploadPath . '/photoData.csv' ); + move_uploaded_file( $_FILES['photos_file']['tmp_name'], $uploadPath . '/photoData.csv' ); } // validate the header line - $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' ); + $fData = $this->readCSVFileHeaders( $uploadPath . '/photoData.csv' ); + $isValid = ( $fData == array( 'member_id', 'image', 'caption' ) ); + // If the file validates then we're ready to process + $readyToProcess = $isValid; + $view= 'photos.html'; + $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; break; case 'photos': $view= 'photos.html'; - $fileData = '
$_FILES: ' . print_r( $_FILES, true ) . '
'; break; case 'files': @@ -409,6 +419,7 @@ class GlmMembersAdmin_import_index } + // Setup the template data array $templateData = array( 'option' => $option, 'errors' => $this->errors, @@ -419,7 +430,8 @@ class GlmMembersAdmin_import_index 'fileData' => $fileData, 'clearData' => $clearData, 'csvData' => '
$fileData: ' . print_r( $fileData, true ) . '
', - 'readyToProcess' => $readyToProcess + 'readyToProcess' => $readyToProcess, + 'haveMembers' => $haveMembers, ); // Return status, suggested view, and data to controller return array( @@ -427,7 +439,7 @@ class GlmMembersAdmin_import_index 'menuItemRedirect' => false, 'modelRedirect' => false, 'view' => 'admin/import/' . $view, - 'data' => $templateData + 'data' => $templateData, ); } diff --git a/views/admin/import/header.html b/views/admin/import/header.html index 69c87e14..64b09953 100644 --- a/views/admin/import/header.html +++ b/views/admin/import/header.html @@ -4,8 +4,10 @@
diff --git a/views/admin/import/index.html b/views/admin/import/index.html index 521c3394..0c6e8608 100644 --- a/views/admin/import/index.html +++ b/views/admin/import/index.html @@ -29,7 +29,7 @@ Clear Data - + diff --git a/views/admin/import/photos.html b/views/admin/import/photos.html index cbbb14ea..a2af2a21 100644 --- a/views/admin/import/photos.html +++ b/views/admin/import/photos.html @@ -3,7 +3,7 @@

Data Import: Photos

- + @@ -16,8 +16,4 @@ - {if $fileData} - {$fileData} - {/if} - {include file='admin/footer.html'} diff --git a/views/admin/import/validate.html b/views/admin/import/validate.html index bf1f100f..8672dd65 100644 --- a/views/admin/import/validate.html +++ b/views/admin/import/validate.html @@ -26,6 +26,12 @@ All Member Data will be cleared before importing any files. + {else} + + + {/if} {if $readyToProcess} @@ -34,6 +40,13 @@ Process Files + {else} + + + {/if}
+ No Member Data will be cleared before importing any files. No attempts will be made to prevent duplication of members. +
+

One or more of your files are not the correct csv format. Please go back and try again.

+ Go Back +
-- 2.17.1