updated notifications system
Showing
3 changed files
with
90 additions
and
9 deletions
| ... | @@ -113,6 +113,11 @@ function display_page() { | ... | @@ -113,6 +113,11 @@ function display_page() { |
| 113 | , 'execute_date' => $execute_date | 113 | , 'execute_date' => $execute_date |
| 114 | )); | 114 | )); |
| 115 | 115 | ||
| 116 | |||
| 117 | if ( count( $entry->email['attachments'] ) > 0 ) { | ||
| 118 | $attachments = array_merge($entry->email['attachments'], $attachments); | ||
| 119 | } | ||
| 120 | |||
| 116 | update_post_meta($id, "email", array( | 121 | update_post_meta($id, "email", array( |
| 117 | 'subject' => $subject | 122 | 'subject' => $subject |
| 118 | , 'text' => $text | 123 | , 'text' => $text |
| ... | @@ -131,7 +136,19 @@ function display_page() { | ... | @@ -131,7 +136,19 @@ function display_page() { |
| 131 | $update['ID'] = $id; | 136 | $update['ID'] = $id; |
| 132 | $update['post_title'] = $title; | 137 | $update['post_title'] = $title; |
| 133 | wp_update_post($update); | 138 | wp_update_post($update); |
| 134 | 139 | ||
| 140 | $id = $entry->ID; | ||
| 141 | |||
| 142 | $details = get_post_meta($id,'details',true); | ||
| 143 | $email = get_post_meta($id,'email',true); | ||
| 144 | $system = get_post_meta($id,'system',true); | ||
| 145 | $sms = get_post_meta($id,'sms',true); | ||
| 146 | |||
| 147 | $entry->details = $details; | ||
| 148 | $entry->email = $email; | ||
| 149 | $entry->system = $system; | ||
| 150 | $entry->sms = $sms; | ||
| 151 | |||
| 135 | 152 | ||
| 136 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; | 153 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; |
| 137 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); | 154 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); | ... | ... |
| ... | @@ -347,6 +347,27 @@ class Actions { | ... | @@ -347,6 +347,27 @@ class Actions { |
| 347 | public static function wp_ajax_print_user_notices() { | 347 | public static function wp_ajax_print_user_notices() { |
| 348 | print_user_notices(); | 348 | print_user_notices(); |
| 349 | } | 349 | } |
| 350 | |||
| 351 | public static function wp_ajax_remove_attachment() { | ||
| 352 | $id = $_POST['id']; | ||
| 353 | $email = get_post_meta($id,'email',true); | ||
| 354 | $attachments = $email['attachments']; | ||
| 355 | foreach($attachments as $key => $name) { | ||
| 356 | if ($name==$_POST['file']) { | ||
| 357 | unset($attachments[$key]); | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 361 | $email['attachments'] = $attachments; | ||
| 362 | |||
| 363 | update_post_meta($id, 'email', $email); | ||
| 364 | |||
| 365 | $return = array('success' => 'true'); | ||
| 366 | die(json_encode($return)); | ||
| 367 | |||
| 368 | } | ||
| 369 | |||
| 370 | |||
| 350 | } | 371 | } |
| 351 | 372 | ||
| 352 | class Vars { | 373 | class Vars { | ... | ... |
| ... | @@ -28,11 +28,9 @@ use Tz\WordPress\Tools; | ... | @@ -28,11 +28,9 @@ use Tz\WordPress\Tools; |
| 28 | </div> | 28 | </div> |
| 29 | <?php endif;?> | 29 | <?php endif;?> |
| 30 | 30 | ||
| 31 | <?php | 31 | |
| 32 | //print "<pre>"; | 32 | |
| 33 | //print_r($entry); | 33 | |
| 34 | //print "</pre>"; | ||
| 35 | ?> | ||
| 36 | 34 | ||
| 37 | <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id']?>"> | 35 | <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id']?>"> |
| 38 | 36 | ||
| ... | @@ -116,18 +114,30 @@ use Tz\WordPress\Tools; | ... | @@ -116,18 +114,30 @@ use Tz\WordPress\Tools; |
| 116 | <td>HTML Version (optional)</td> | 114 | <td>HTML Version (optional)</td> |
| 117 | <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> | 115 | <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> |
| 118 | </tr> | 116 | </tr> |
| 117 | |||
| 119 | <tr> | 118 | <tr> |
| 120 | <td width="150">Attachments</td> | 119 | <td width="150">Attachments</td> |
| 121 | <td><input type="file" name="attachment[]" /></td> | 120 | <td> </td> |
| 122 | </tr> | 121 | </tr> |
| 122 | |||
| 123 | <?php | ||
| 124 | $attachements = $entry->email['attachments']; | ||
| 125 | $allowed_attachments = 3; | ||
| 126 | foreach($attachements as $attachment): ?> | ||
| 123 | <tr> | 127 | <tr> |
| 124 | <td> </td> | 128 | <td> </td> |
| 125 | <td><input type="file" name="attachment[]" /></td> | 129 | <td><?php echo $attachment; ?> (<a href="#" entry_id="<?php echo $_GET['page_id']?>" class="attachment" rel="<?php echo $attachment; ?>">remove</a>)</td> |
| 126 | </tr> | 130 | </tr> |
| 131 | <?php $allowed_attachments--; endforeach; ?> | ||
| 132 | |||
| 133 | <?php for($a = 1; $a <= $allowed_attachments; $a++): ?> | ||
| 134 | |||
| 127 | <tr> | 135 | <tr> |
| 128 | <td> </td> | 136 | <td> </td> |
| 129 | <td><input type="file" name="attachment[]" /></td> | 137 | <td><input type="file" name="attachment[]" /></td> |
| 130 | </tr> | 138 | </tr> |
| 139 | <?php endfor; ?> | ||
| 140 | |||
| 131 | </tbody> | 141 | </tbody> |
| 132 | </table> | 142 | </table> |
| 133 | 143 | ||
| ... | @@ -170,7 +180,7 @@ use Tz\WordPress\Tools; | ... | @@ -170,7 +180,7 @@ use Tz\WordPress\Tools; |
| 170 | <script type="text/javascript"> | 180 | <script type="text/javascript"> |
| 171 | 181 | ||
| 172 | 182 | ||
| 173 | jQuery(document).ready(function() { | 183 | jQuery(document).ready(function($) { |
| 174 | 184 | ||
| 175 | $('#execute_date').datetimepicker({ | 185 | $('#execute_date').datetimepicker({ |
| 176 | stepMinute: 30 | 186 | stepMinute: 30 |
| ... | @@ -180,6 +190,39 @@ jQuery(document).ready(function() { | ... | @@ -180,6 +190,39 @@ jQuery(document).ready(function() { |
| 180 | 190 | ||
| 181 | updateNotificationType(); | 191 | updateNotificationType(); |
| 182 | 192 | ||
| 193 | $('.attachment').live('click', function(e) { | ||
| 194 | e.preventDefault(); | ||
| 195 | var $link = $(this); | ||
| 196 | var options = { | ||
| 197 | action: 'remove_attachment' | ||
| 198 | , ajax: 'yes' | ||
| 199 | , id: $link.attr('entry_id') | ||
| 200 | , file: $link.attr('rel') | ||
| 201 | }; | ||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | var file_element = '<input type="file" name="attachment[]" />'; | ||
| 206 | |||
| 207 | var c = confirm('Are you sure you want to remove this attachment?'); | ||
| 208 | if (c) { | ||
| 209 | $.ajax({ | ||
| 210 | url: '/wp-admin/admin-ajax.php' | ||
| 211 | , data: (options) | ||
| 212 | , type: 'POST' | ||
| 213 | , dataType: 'json' | ||
| 214 | , success: function(data) { | ||
| 215 | if (data.success=="true") { | ||
| 216 | $link.parent().html(file_element); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | }); | ||
| 220 | } | ||
| 221 | |||
| 222 | return false; | ||
| 223 | }); | ||
| 224 | |||
| 225 | |||
| 183 | //jQuery('table.expandable tbody').hide(); | 226 | //jQuery('table.expandable tbody').hide(); |
| 184 | jQuery('table.expandable thead th').click(function() { | 227 | jQuery('table.expandable thead th').click(function() { |
| 185 | var $table = jQuery(this).parent().parent().parent(); | 228 | var $table = jQuery(this).parent().parent().parent(); | ... | ... |
-
Please register or sign in to post a comment