26d657cd by Jeff Balicki

upload to Notifications

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 58de2c30
......@@ -523,6 +523,9 @@ function create_notification()
update_post_meta($id, 'style', $style);
update_post_meta($id, 'system', $systemMessageData);
update_post_meta($id, 'push', $pushMessageData);
if(!empty($_POST['report_ids'])){
update_post_meta($id, 'report_ids', $_POST['report_ids']);
}
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once __DIR__ . '/views/create.php';
......
......@@ -121,7 +121,7 @@ $event_newsletterFr = get_post($event_newsletterFrId);
<tr class="scheduled_sendto">
<td>Sent To:</td>
<td>
<select name="sendto" class="wide-input-field">
<select id="sendto" name="sendto" class="wide-input-field">
<option value="nousers" <?php echo ($validation->set_value('sendto') == "nousers")
? 'selected="selected"' : ""; ?>>No Users
</option>
......@@ -137,9 +137,17 @@ $event_newsletterFr = get_post($event_newsletterFrId);
) == $group->getID()) ? 'selected="selected"'
: ""; ?>><?php echo $group->getName(); ?></option>
<?php };?>
<option value="uploadlist" <?php echo ($validation->set_value('sendto') == "uploadlist")
? 'selected="selected"' : ""; ?>>Upload List by CSV
</option>
</optgroup>
</select>
<?php echo $validation->form_error('sendto'); ?>
<div id="uploadcsv" style="display:none;">
<input type="file" name="uploadCSVlist" id="uploadCSVlist" />
<div id="users_count" style="display:none;">
</div>
</div>
</td>
</tr>
......@@ -341,6 +349,37 @@ endforeach;
<script>
jQuery(document).ready(function($) {
$(document).on('change', '#sendto', function() {
if ($(this).val() == 'uploadlist') {
$(this).hide();
$('#uploadcsv').show();
}
});
$('#uploadCSVlist').on("change", function(){
var file = this.files[0];
var formdata = new FormData();
formdata.append("uploadCSVlist", file);
formdata.append("action", "upload_users_by_csv");
$.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
data: formdata,
contentType: false,
processData: false,
success: function(data) {
const obj = JSON.parse(data);
console.log(obj.users);
$('#users_count').html(''+obj.users.length+' Users Added').css('color','green').show();
$('#users_count').append('<input type="hidden" name="report_ids" value="' + obj.users.join(',') + '">');
$('#users_count').append('<input type="hidden" name="sendto" value="report"');
}
});
});
var codeCleaned = false;
$('#submit').on('click', function() {
......