summaryrefslogtreecommitdiff
path: root/Postman/Postman-Email-Log/PostmanEmailLogController.php
diff options
context:
space:
mode:
Diffstat (limited to 'Postman/Postman-Email-Log/PostmanEmailLogController.php')
-rw-r--r--Postman/Postman-Email-Log/PostmanEmailLogController.php57
1 files changed, 52 insertions, 5 deletions
diff --git a/Postman/Postman-Email-Log/PostmanEmailLogController.php b/Postman/Postman-Email-Log/PostmanEmailLogController.php
index 49f226b..c496455 100644
--- a/Postman/Postman-Email-Log/PostmanEmailLogController.php
+++ b/Postman/Postman-Email-Log/PostmanEmailLogController.php
@@ -72,8 +72,48 @@ class PostmanEmailLogController {
PostmanViewController::JQUERY_SCRIPT,
PostmanViewController::POSTMAN_SCRIPT,
), $pluginData ['version'] );
+ $this->handleCsvExport();
}
+ function handleCsvExport() {
+ if ( ! empty( $_POST ) && ! wp_verify_nonce( $_REQUEST['post-smtp-log'], 'post-smtp' ) )
+ die( 'Security check' );
+
+ if ( isset( $_POST['postman_export_csv'] ) && current_user_can( Postman::MANAGE_POSTMAN_CAPABILITY_LOGS ) ) {
+ $args = array(
+ 'post_type' => PostmanEmailLogPostType::POSTMAN_CUSTOM_POST_TYPE_SLUG,
+ 'post_status' => PostmanEmailLogService::POSTMAN_CUSTOM_POST_STATUS_PRIVATE,
+ 'posts_per_page' => -1,
+ );
+ $logs = new WP_Query($args);
+
+ if ( empty( $logs->posts ) ) {
+ return;
+ }
+
+ header('Content-Type: text/csv');
+ header('Content-Disposition: attachment; filename="email-logs.csv"');
+
+ $fp = fopen('php://output', 'wb');
+
+ $headers = array_keys( PostmanLogFields::get_instance()->get_fields() );
+ fputcsv($fp, $headers);
+
+ foreach ( $logs->posts as $log ) {
+ $meta = PostmanLogFields::get_instance()->get($log->ID);
+ $data = [];
+ foreach ( $meta as $header => $line ) {
+ $data[] = $line[0];
+ }
+ fputcsv($fp, $data);
+ }
+
+ fclose($fp);
+ die();
+
+ }
+ }
+
/**
*/
public function resendMail() {
@@ -404,14 +444,21 @@ class PostmanEmailLogController {
}
?>
</select>
- </div>
- <div class="form-control" style="padding: 0 5px 0 5px;">
+ </div>
+
+ <div class="form-control">
+ <button type="submit" id="postman_export_csv" name="postman_export_csv" class="button button-primary"><?php _e( 'Export To CSV', 'post-smtp' ); ?></button>
+ </div>
+
+ <div class="form-control" style="padding: 0 5px 0 5px; margin-right: 50px;">
<button type="submit" name="filter" class="button button-primary"><?php _e( 'Filter/Search', 'post-smtp' ); ?></button>
- </div>
+ </div>
+
<div class="form-control">
<button type="submit" id="postman_trash_all" name="postman_trash_all" class="button button-primary"><?php _e( 'Trash All', 'post-smtp' ); ?></button>
- </div>
- </div>
+ </div>
+
+ </div>
<div class="error">Please notice: when you select a date for example 11/20/2017, behind the scene the query select <b>11/20/2017 00:00:00</b>.<br>So if you searching for an email arrived that day at any hour you need to select 11/20/2017 as the <b>From Date</b> and 11/21/2017 as the <b>To Date</b>.</div>
</form>