ec5a5d18 by Kevin Burton

updated notifications system

1 parent 6b66cbf9
......@@ -113,6 +113,11 @@ function display_page() {
, 'execute_date' => $execute_date
));
if ( count( $entry->email['attachments'] ) > 0 ) {
$attachments = array_merge($entry->email['attachments'], $attachments);
}
update_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
......@@ -131,7 +136,19 @@ function display_page() {
$update['ID'] = $id;
$update['post_title'] = $title;
wp_update_post($update);
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$sms = get_post_meta($id,'sms',true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$entry->sms = $sms;
$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__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
......
......@@ -347,6 +347,27 @@ class Actions {
public static function wp_ajax_print_user_notices() {
print_user_notices();
}
public static function wp_ajax_remove_attachment() {
$id = $_POST['id'];
$email = get_post_meta($id,'email',true);
$attachments = $email['attachments'];
foreach($attachments as $key => $name) {
if ($name==$_POST['file']) {
unset($attachments[$key]);
}
}
$email['attachments'] = $attachments;
update_post_meta($id, 'email', $email);
$return = array('success' => 'true');
die(json_encode($return));
}
}
class Vars {
......
......@@ -28,11 +28,9 @@ use Tz\WordPress\Tools;
</div>
<?php endif;?>
<?php
//print "<pre>";
//print_r($entry);
//print "</pre>";
?>
<form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id']?>">
......@@ -116,18 +114,30 @@ use Tz\WordPress\Tools;
<td>HTML Version (optional)</td>
<td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"><?php echo $validation->set_value('html',$entry->email['html']);?></textarea><?php echo $validation->form_error('html');?></td>
</tr>
<tr>
<td width="150">Attachments</td>
<td><input type="file" name="attachment[]" /></td>
<td>&nbsp;</td>
</tr>
<?php
$attachements = $entry->email['attachments'];
$allowed_attachments = 3;
foreach($attachements as $attachment): ?>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
<td><?php echo $attachment; ?> &nbsp; (<a href="#" entry_id="<?php echo $_GET['page_id']?>" class="attachment" rel="<?php echo $attachment; ?>">remove</a>)</td>
</tr>
<?php $allowed_attachments--; endforeach; ?>
<?php for($a = 1; $a <= $allowed_attachments; $a++): ?>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
</tr>
<?php endfor; ?>
</tbody>
</table>
......@@ -170,7 +180,7 @@ use Tz\WordPress\Tools;
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(document).ready(function($) {
$('#execute_date').datetimepicker({
stepMinute: 30
......@@ -180,6 +190,39 @@ jQuery(document).ready(function() {
updateNotificationType();
$('.attachment').live('click', function(e) {
e.preventDefault();
var $link = $(this);
var options = {
action: 'remove_attachment'
, ajax: 'yes'
, id: $link.attr('entry_id')
, file: $link.attr('rel')
};
var file_element = '<input type="file" name="attachment[]" />';
var c = confirm('Are you sure you want to remove this attachment?');
if (c) {
$.ajax({
url: '/wp-admin/admin-ajax.php'
, data: (options)
, type: 'POST'
, dataType: 'json'
, success: function(data) {
if (data.success=="true") {
$link.parent().html(file_element);
}
}
});
}
return false;
});
//jQuery('table.expandable tbody').hide();
jQuery('table.expandable thead th').click(function() {
var $table = jQuery(this).parent().parent().parent();
......