| 1 |
<div class="col-sm-9 sue-external-lists-main"> |
| 2 |
<div class="sue-log-card"> |
| 3 |
<div class="sue-log-card-header"> |
| 4 |
<span class="sue-log-card-icon">📥</span> |
| 5 |
<h3><?php esc_html_e( 'Import External List', 'send-users-email' ); ?></h3> |
| 6 |
</div> |
| 7 |
<div class="sue-log-card-body"> |
| 8 |
<p class="sue-form-hint" style="margin-top:0; margin-bottom:16px;"> |
| 9 |
<?php |
| 10 |
printf( |
| 11 |
/* translators: %s: link to sample CSV */ |
| 12 |
wp_kses_post( __( 'Your CSV file must contain at least one row. %s.', 'send-users-email' ) ), |
| 13 |
'<a href="https://sendusersemail.com/wp-content/uploads/sue-email-list-sample.csv" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Download a sample CSV', 'send-users-email' ) . '</a>' |
| 14 |
); |
| 15 |
?> |
| 16 |
</p> |
| 17 |
|
| 18 |
<?php if ( isset( $_GET['errors'] ) ) : ?> |
| 19 |
<div class="sue-notice sue-notice-warning"> |
| 20 |
<div class="sue-notice-icon">⚠️</div> |
| 21 |
<div class="sue-notice-body"> |
| 22 |
<p class="sue-notice-title"><?php esc_html_e( 'Import failed', 'send-users-email' ); ?></p> |
| 23 |
<?php |
| 24 |
$errors = is_array( $_GET['errors'] ) ? $_GET['errors'] : [ sanitize_text_field( wp_unslash( $_GET['errors'] ) ) ]; |
| 25 |
foreach ( $errors as $error ) : |
| 26 |
?> |
| 27 |
<p><?php echo esc_html( $error ); ?></p> |
| 28 |
<?php endforeach; ?> |
| 29 |
</div> |
| 30 |
</div> |
| 31 |
<?php endif; ?> |
| 32 |
|
| 33 |
<?php if ( isset( $_GET['duplicate_rows'] ) && ! empty( $_GET['duplicate_rows'] ) && (int) $_GET['duplicate_rows'] > 0 ) : ?> |
| 34 |
<div class="sue-notice sue-notice-warning"> |
| 35 |
<div class="sue-notice-icon">📄</div> |
| 36 |
<div class="sue-notice-body"> |
| 37 |
<p class="sue-notice-title"><?php esc_html_e( 'Duplicate rows skipped', 'send-users-email' ); ?></p> |
| 38 |
<p> |
| 39 |
<?php |
| 40 |
/* translators: %d: Number of duplicate rows */ |
| 41 |
printf( esc_html__( '%d duplicate rows were found and skipped during import.', 'send-users-email' ), intval( $_GET['duplicate_rows'] ) ); |
| 42 |
?> |
| 43 |
</p> |
| 44 |
</div> |
| 45 |
</div> |
| 46 |
<?php endif; ?> |
| 47 |
|
| 48 |
<?php if ( isset( $_GET['list_id'] ) && ! empty( $_GET['list_id'] ) ) : ?> |
| 49 |
<?php |
| 50 |
$list_count = External_List_Model::get_list_count( sanitize_text_field( $_GET['list_id'] ) ); |
| 51 |
if ( $list_count === false ) { |
| 52 |
$list_count = 0; |
| 53 |
} |
| 54 |
?> |
| 55 |
<?php if ( $list_count > 0 ) : ?> |
| 56 |
<div class="sue-notice sue-notice-info"> |
| 57 |
<div class="sue-notice-icon">� |
| 58 |
</div> |
| 59 |
<div class="sue-notice-body"> |
| 60 |
<p class="sue-notice-title"><?php esc_html_e( 'Import complete', 'send-users-email' ); ?></p> |
| 61 |
<p> |
| 62 |
<?php |
| 63 |
/* translators: %d: Number of imported emails */ |
| 64 |
printf( esc_html__( 'Import successful! %d emails were added to the external list.', 'send-users-email' ), intval( $list_count ) ); |
| 65 |
?> |
| 66 |
</p> |
| 67 |
</div> |
| 68 |
</div> |
| 69 |
<?php endif; ?> |
| 70 |
<?php endif; ?> |
| 71 |
|
| 72 |
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" id="sue-externali-list-import-form" enctype="multipart/form-data"> |
| 73 |
<input type="hidden" name="action" value="import_external_list"> |
| 74 |
|
| 75 |
<div class="sue-field-row"> |
| 76 |
<div class="sue-field-label"> |
| 77 |
<label for="external_list_name"><?php esc_html_e( 'External List Name', 'send-users-email' ); ?></label> |
| 78 |
<p class="sue-form-hint"><?php esc_html_e( 'Name for this imported email list.', 'send-users-email' ); ?></p> |
| 79 |
</div> |
| 80 |
<div class="sue-field-input"> |
| 81 |
<input type="text" class="sue-input" name="external_list_name" id="external_list_name" required> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
|
| 85 |
<div class="sue-field-row"> |
| 86 |
<div class="sue-field-label"> |
| 87 |
<label for="external_list_file"><?php esc_html_e( 'CSV File', 'send-users-email' ); ?></label> |
| 88 |
<p class="sue-form-hint"><?php esc_html_e( 'Upload a .csv file containing email addresses.', 'send-users-email' ); ?></p> |
| 89 |
</div> |
| 90 |
<div class="sue-field-input"> |
| 91 |
<input type="file" name="external_list_file" id="external_list_file" accept=".csv" required> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
|
| 95 |
<?php wp_nonce_field( 'sue_external_lists_import', 'sue_external_lists_nonce' ); ?> |
| 96 |
|
| 97 |
<div class="sue-field-row sue-field-row-actions"> |
| 98 |
<div class="sue-field-label"></div> |
| 99 |
<div class="sue-field-input"> |
| 100 |
<button type="submit" id="sue-user-email-btn-import" class="sue-btn sue-btn-primary"> |
| 101 |
<span class="dashicons dashicons-upload" aria-hidden="true"></span> |
| 102 |
<?php esc_html_e( 'Import CSV', 'send-users-email' ); ?> |
| 103 |
</button> |
| 104 |
</div> |
| 105 |
</div> |
| 106 |
</form> |
| 107 |
|
| 108 |
<div id="upload-status" class="sue-external-upload-status"> |
| 109 |
<div class="sue-progress sue-external-upload-progress-wrap"> |
| 110 |
<div id="progress-bar" class="sue-progress-bar sue-progress-success" style="width:0%;"></div> |
| 111 |
</div> |
| 112 |
<p id="status-text" class="sue-form-hint"></p> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
|
| 117 |
<div class="sue-log-card"> |
| 118 |
<div class="sue-log-card-header"> |
| 119 |
<span class="sue-log-card-icon">📋</span> |
| 120 |
<h3><?php esc_html_e( 'External Lists', 'send-users-email' ); ?></h3> |
| 121 |
</div> |
| 122 |
<div class="sue-log-card-body"> |
| 123 |
<?php |
| 124 |
$external_lists = External_List_Model::get_lists_with_counts(); |
| 125 |
|
| 126 |
if ( ! empty( $external_lists ) ) : ?> |
| 127 |
<div class="sue-templates-table-wrap"> |
| 128 |
<table class="table table-bordered table-striped sue-table"> |
| 129 |
<thead> |
| 130 |
<tr> |
| 131 |
<th><?php esc_html_e( 'List ID', 'send-users-email' ); ?></th> |
| 132 |
<th><?php esc_html_e( 'List Name', 'send-users-email' ); ?></th> |
| 133 |
<th><?php esc_html_e( 'Total Users', 'send-users-email' ); ?></th> |
| 134 |
<th><?php esc_html_e( 'Subscribed', 'send-users-email' ); ?></th> |
| 135 |
<th><?php esc_html_e( 'Actions', 'send-users-email' ); ?></th> |
| 136 |
</tr> |
| 137 |
</thead> |
| 138 |
<tbody> |
| 139 |
<?php foreach ( $external_lists as $list ) : ?> |
| 140 |
<tr> |
| 141 |
<td><?php echo esc_html( $list->id ); ?></td> |
| 142 |
<td><?php echo esc_html( $list->list_name ); ?></td> |
| 143 |
<td><?php echo esc_html( $list->total_users ); ?></td> |
| 144 |
<td><?php echo esc_html( $list->subscribed_users ); ?></td> |
| 145 |
<td class="sue-table-actions"> |
| 146 |
<button |
| 147 |
class="sue-btn sue-btn-danger sue-btn-icon sue-delete-external-list-btn" |
| 148 |
data-list-id="<?php echo esc_attr( $list->list_id ); ?>" |
| 149 |
data-nonce="<?php echo esc_attr( wp_create_nonce( 'sue_external_lists_delete' ) ); ?>" |
| 150 |
type="button" |
| 151 |
> |
| 152 |
<span class="dashicons dashicons-trash" aria-hidden="true"></span> |
| 153 |
</button> |
| 154 |
<button |
| 155 |
class="sue-btn sue-btn-muted sue-btn-icon sue-edit-external-list-btn" |
| 156 |
data-list-id="<?php echo esc_attr( $list->list_id ); ?>" |
| 157 |
data-nonce="<?php echo esc_attr( wp_create_nonce( 'sue_external_lists_edit_' . $list->list_id ) ); ?>" |
| 158 |
data-url="<?php echo esc_url( admin_url( 'admin.php?page=send-users-email-external-lists&action=edit-lists&list_id=' . $list->list_id ) ); ?>" |
| 159 |
type="button" |
| 160 |
> |
| 161 |
<span class="dashicons dashicons-edit" aria-hidden="true"></span> |
| 162 |
</button> |
| 163 |
</td> |
| 164 |
</tr> |
| 165 |
<?php endforeach; ?> |
| 166 |
</tbody> |
| 167 |
</table> |
| 168 |
</div> |
| 169 |
<?php else : ?> |
| 170 |
<div class="sue-notice sue-notice-info" style="margin-bottom:0;"> |
| 171 |
<div class="sue-notice-icon">📭</div> |
| 172 |
<div class="sue-notice-body"> |
| 173 |
<p class="sue-notice-title"><?php esc_html_e( 'No lists yet', 'send-users-email' ); ?></p> |
| 174 |
<p><?php esc_html_e( 'No external lists found. Import your first CSV list above.', 'send-users-email' ); ?></p> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
<?php endif; ?> |
| 178 |
</div> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
<?php External_Lists::enqueue_scripts(); ?> |