Clean up a few files and translate a few strings
Showing
5 changed files
with
524 additions
and
419 deletions
| 1 | <?php | 1 | <?php |
| 2 | namespace Tz\WordPress\Tools\Notifications\Settings; | 2 | namespace Tz\WordPress\Tools\Notifications\Settings; |
| 3 | //error_reporting(E_ALL^E_DEPRECATED); | ||
| 4 | 3 | ||
| 5 | use Tz\WordPress\Tools; | ||
| 6 | use Tz\Common; | 4 | use Tz\Common; |
| 5 | use Tz\WordPress\Tools; | ||
| 7 | use Tz\WordPress\Tools\Notifications; | 6 | use Tz\WordPress\Tools\Notifications; |
| 8 | use Tz\WordPress\Tools\Notifications\Validation; | ||
| 9 | 7 | ||
| 10 | const CAPABILITY = "manage_notifications"; | 8 | const CAPABILITY = 'manage_notifications'; |
| 11 | const MANAGE_SYSTEM_NOTIFICATIONS = "create_system_notifications"; | 9 | const MANAGE_SYSTEM_NOTIFICATIONS = 'create_system_notifications'; |
| 12 | const SETTING_NS = 'canspam_settings'; | 10 | const SETTING_NS = 'canspam_settings'; |
| 13 | const ADMIN_PAGE = "canspam_admin"; | 11 | const ADMIN_PAGE = 'canspam_admin'; |
| 14 | 12 | ||
| 15 | call_user_func(function() { | 13 | call_user_func( |
| 14 | function () { | ||
| 16 | $role = get_role('administrator'); | 15 | $role = get_role('administrator'); |
| 17 | $role->add_cap(CAPABILITY); | 16 | $role->add_cap(CAPABILITY); |
| 18 | $role->add_cap(MANAGE_SYSTEM_NOTIFICATIONS); | 17 | $role->add_cap(MANAGE_SYSTEM_NOTIFICATIONS); |
| 19 | //$role->remove_cap(SUB_ADMIN_CAPABILITY); | ||
| 20 | 18 | ||
| 21 | Vars::$settings = new Tools\WP_Option(SETTING_NS); | 19 | Vars::$settings = new Tools\WP_Option(SETTING_NS); |
| 22 | 20 | ||
| 23 | Tools\add_actions(__NAMESPACE__ . '\Actions'); | 21 | Tools\add_actions(__NAMESPACE__.'\Actions'); |
| 24 | 22 | } | |
| 25 | 23 | ); | |
| 26 | |||
| 27 | }); | ||
| 28 | |||
| 29 | function display_page() { | ||
| 30 | 24 | ||
| 25 | function display_page() | ||
| 26 | { | ||
| 31 | 27 | ||
| 32 | if (isset($_GET['action']) && $_GET['action']=="edit") { | 28 | if (isset($_GET['action']) && $_GET['action'] == "edit") { |
| 29 | /** @var \wpdb $wpdb */ | ||
| 33 | global $wpdb; | 30 | global $wpdb; |
| 34 | 31 | ||
| 32 | /** @var \StdClass $entry */ | ||
| 35 | $entry = get_post($_GET['page_id']); | 33 | $entry = get_post($_GET['page_id']); |
| 36 | 34 | ||
| 37 | $id = $entry->ID; | 35 | $id = $entry->ID; |
| 38 | 36 | ||
| 39 | $details = get_post_meta($id,'details',true); | 37 | $details = get_post_meta($id, 'details', true); |
| 40 | $email = get_post_meta($id,'email',true); | 38 | $email = get_post_meta($id, 'email', true); |
| 41 | $system = get_post_meta($id,'system',true); | 39 | $system = get_post_meta($id, 'system', true); |
| 42 | 40 | ||
| 43 | $entry->details = $details; | 41 | $entry->details = $details; |
| 44 | $entry->email = $email; | 42 | $entry->email = $email; |
| 45 | $entry->system = $system; | 43 | $entry->system = $system; |
| 46 | 44 | ||
| 47 | // here | 45 | // here |
| 48 | $validation = new Notifications\Validation; | 46 | $validation = new Notifications\Validation; |
| 49 | 47 | ||
| 50 | $validation->set_rules('type','Notification Type','required'); | 48 | $validation->set_rules('type', 'Notification Type', 'required'); |
| 51 | $validation->set_rules('title','Description','trim|required|min_length[4]'); | 49 | $validation->set_rules('title', 'Description', 'trim|required|min_length[4]'); |
| 52 | $validation->set_rules('type','Notification Type','required'); | 50 | $validation->set_rules('type', 'Notification Type', 'required'); |
| 53 | $validation->set_rules('sendto','Send To','required'); | 51 | $validation->set_rules('sendto', 'Send To', 'required'); |
| 54 | 52 | ||
| 55 | $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : ''; | 53 | $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : ''; |
| 56 | $validation->set_rules('execute_date','Execute Date', $type_val); | 54 | $validation->set_rules('execute_date', 'Execute Date', $type_val); |
| 57 | 55 | ||
| 58 | $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : ''; | 56 | $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : ''; |
| 59 | $validation->set_rules('trigger','Trigger',$trigger_val); | 57 | $validation->set_rules('trigger', 'Trigger', $trigger_val); |
| 60 | |||
| 61 | $validation->set_rules('subject','Subject','trim'); | ||
| 62 | $validation->set_rules('text','Text Version','trim|min_length[16]'); | ||
| 63 | $validation->set_rules('html','HTML Version','trim|min_length[16]'); | ||
| 64 | 58 | ||
| 65 | $validation->set_rules('system_message_type','System Message Type','trim'); | 59 | $validation->set_rules('subject', 'Subject', 'trim'); |
| 66 | $validation->set_rules('system','System Message','trim|min_length[16]'); | 60 | $validation->set_rules('text', 'Text Version', 'trim|min_length[16]'); |
| 61 | $validation->set_rules('html', 'HTML Version', 'trim|min_length[16]'); | ||
| 67 | 62 | ||
| 63 | $validation->set_rules('system_message_type', 'System Message Type', 'trim'); | ||
| 64 | $validation->set_rules('system', 'System Message', 'trim|min_length[16]'); | ||
| 68 | 65 | ||
| 69 | //details | 66 | //details |
| 70 | if ($validation->run() == TRUE) { | 67 | if ($validation->run() == true) { |
| 71 | 68 | ||
| 72 | // Clean up data before saving | 69 | // Clean up data before saving |
| 73 | Tools\tzClean($_POST); | 70 | Tools\tzClean($_POST); |
| 74 | 71 | ||
| 75 | $type = $_POST['type']; | 72 | $type = $_POST['type']; |
| 76 | $title = $_POST['title']; | 73 | $title = $_POST['title']; |
| 77 | $sendto = $_POST['sendto']; | 74 | $sendto = $_POST['sendto']; |
| 78 | $execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00"; | 75 | $execute_date = ($type == "scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00"; |
| 79 | $trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger']; | 76 | $trigger = ($type == "scheduled") ? "scheduled-cron-job" : $_POST['trigger']; |
| 80 | 77 | ||
| 81 | 78 | ||
| 82 | $subject = $_POST['subject']; | 79 | $subject = $_POST['subject']; |
| 83 | $text = $_POST['text']; | 80 | $text = $_POST['text']; |
| 84 | $html = $_POST['html']; | 81 | $html = $_POST['html']; |
| 85 | $attachments = array(); | 82 | $attachments = []; |
| 86 | $upload_dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'notifications' . DIRECTORY_SEPARATOR; | 83 | $upload_dir = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'notifications'.DIRECTORY_SEPARATOR; |
| 87 | 84 | ||
| 88 | fixFilesArray($_FILES['attachment']); | 85 | fixFilesArray($_FILES['attachment']); |
| 89 | 86 | ||
| 90 | foreach ($_FILES['attachment'] as $position => $file) { | 87 | foreach ($_FILES['attachment'] as $position => $file) { |
| 91 | // should output array with indices name, type, tmp_name, error, size | 88 | // should output array with indices name, type, tmp_name, error, size |
| 92 | if($file['name'] != "") { | 89 | if ($file['name'] != "") { |
| 93 | move_uploaded_file($file['tmp_name'], $upload_dir . $file['name']); | 90 | move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']); |
| 94 | $attachments[] = $file['name']; | 91 | $attachments[] = $file['name']; |
| 95 | } | 92 | } |
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | // system | 95 | // system |
| 99 | $system_message_type = $_POST['system_message_type']; | 96 | $system_message_type = $_POST['system_message_type']; |
| 100 | $system = $_POST['system']; | 97 | $system = $_POST['system']; |
| 101 | 98 | ||
| 102 | update_post_meta($id, 'notif_type', $type); | 99 | update_post_meta($id, 'notif_type', $type); |
| 103 | update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date)); | 100 | update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date)); |
| 104 | update_post_meta($id, 'trigger', $trigger); | 101 | update_post_meta($id, 'trigger', $trigger); |
| 105 | 102 | ||
| 106 | update_post_meta($id, "details", array( | 103 | update_post_meta( |
| 107 | 'type' => $type | 104 | $id, |
| 108 | , 'sendto' => $sendto | 105 | "details", |
| 109 | , 'status' => $entry->details['status'] | 106 | [ |
| 110 | , 'trigger' => $trigger | 107 | 'type' => $type, |
| 111 | , 'execute_date' => $execute_date | 108 | 'sendto' => $sendto, |
| 112 | )); | 109 | 'status' => $entry->details['status'], |
| 113 | 110 | 'trigger' => $trigger, | |
| 114 | update_post_meta($id,'send_status',$entry->details['status']); | 111 | 'execute_date' => $execute_date |
| 115 | 112 | ] | |
| 116 | if ( count( $entry->email['attachments'] ) > 0 ) { | 113 | ); |
| 114 | |||
| 115 | update_post_meta($id, 'send_status', $entry->details['status']); | ||
| 116 | |||
| 117 | if (count($entry->email['attachments']) > 0) { | ||
| 117 | $attachments = array_merge($entry->email['attachments'], $attachments); | 118 | $attachments = array_merge($entry->email['attachments'], $attachments); |
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | update_post_meta($id, "email", array( | 121 | update_post_meta( |
| 121 | 'subject' => $subject | 122 | $id, |
| 122 | , 'text' => $text | 123 | 'email', |
| 123 | , 'html' => $html | 124 | [ |
| 124 | , 'attachments' => $attachments | 125 | 'subject' => $subject, |
| 125 | )); | 126 | 'text' => $text, |
| 126 | update_post_meta($id, "system", array( | 127 | 'html' => $html, |
| 127 | 'system_message_type' => $system_message_type | 128 | 'attachments' => $attachments |
| 128 | , 'message' => $system | 129 | ] |
| 129 | )); | 130 | ); |
| 130 | 131 | update_post_meta( | |
| 131 | 132 | $id, | |
| 132 | $update = array(); | 133 | 'system', |
| 133 | $update['ID'] = $id; | 134 | [ |
| 135 | 'system_message_type' => $system_message_type, | ||
| 136 | 'message' => $system | ||
| 137 | ] | ||
| 138 | ); | ||
| 139 | |||
| 140 | $update = []; | ||
| 141 | $update['ID'] = $id; | ||
| 134 | $update['post_title'] = $title; | 142 | $update['post_title'] = $title; |
| 135 | wp_update_post($update); | 143 | wp_update_post($update); |
| 136 | 144 | ||
| 137 | $id = $entry->ID; | 145 | $id = $entry->ID; |
| 138 | 146 | ||
| 139 | $details = get_post_meta($id,'details',true); | 147 | $details = get_post_meta($id, 'details', true); |
| 140 | $email = get_post_meta($id,'email',true); | 148 | $email = get_post_meta($id, 'email', true); |
| 141 | $system = get_post_meta($id,'system',true); | 149 | $system = get_post_meta($id, 'system', true); |
| 142 | 150 | ||
| 143 | 151 | $entry->details = $details; | |
| 144 | $entry->details = $details; | 152 | $entry->email = $email; |
| 145 | $entry->email = $email; | 153 | $entry->system = $system; |
| 146 | $entry->system = $system; | ||
| 147 | 154 | ||
| 148 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; | 155 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; |
| 149 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); | 156 | require_once(__DIR__.'/views/form.php'); |
| 150 | } else { | 157 | } else { |
| 151 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php'); | 158 | require_once(__DIR__.'/views/form.php'); |
| 152 | } | 159 | } |
| 153 | } else { | 160 | } else { |
| 154 | 161 | ||
| 155 | if (isset($_GET['action']) && $_GET['action']=="delete") { | 162 | if (isset($_GET['action']) && $_GET['action'] == "delete") { |
| 156 | wp_delete_post($_GET['page_id'],true); | 163 | wp_delete_post($_GET['page_id'], true); |
| 157 | 164 | } elseif (isset($_GET['action']) && $_GET['action'] == "archive") { | |
| 158 | } elseif (isset($_GET['action']) && $_GET['action']=="archive") { | ||
| 159 | 165 | ||
| 160 | $id = $_GET['page_id']; | 166 | $id = $_GET['page_id']; |
| 161 | 167 | ||
| 162 | $postdata = get_post_meta($id,'details',true); | 168 | $postdata = get_post_meta($id, 'details', true); |
| 163 | $postdata['status'] = "archived"; | 169 | $postdata['status'] = "archived"; |
| 164 | 170 | ||
| 165 | update_post_meta($id,'details',$postdata); | 171 | update_post_meta($id, 'details', $postdata); |
| 166 | update_post_meta($id,'send_status',$postdata['status']); | 172 | update_post_meta($id, 'send_status', $postdata['status']); |
| 167 | } | 173 | } |
| 168 | 174 | ||
| 169 | |||
| 170 | // get all the notifications that status != "archived"; | 175 | // get all the notifications that status != "archived"; |
| 171 | $notifications = array(); | 176 | $notifications = []; |
| 172 | $notifications['triggered'] = array(); | 177 | $notifications['triggered'] = []; |
| 173 | $notifications['scheduled'] = array(); | 178 | $notifications['scheduled'] = []; |
| 174 | 179 | ||
| 175 | $args = array( | 180 | $args = [ |
| 176 | 'post_type' => 'notifications' | 181 | 'post_type' => 'notifications', |
| 177 | , 'numberposts' => -1 | 182 | 'numberposts' => -1, |
| 178 | , 'orderby' => 'modified' | 183 | 'orderby' => 'modified', |
| 179 | , 'order' => 'desc' | 184 | 'order' => 'desc', |
| 180 | , 'meta_key' => 'send_status' | 185 | 'meta_key' => 'send_status', |
| 181 | , 'meta_compare' => '=' | 186 | 'meta_compare' => '=', |
| 182 | , 'meta_value' => 'pending' | 187 | 'meta_value' => 'pending' |
| 183 | ); | 188 | ]; |
| 184 | 189 | ||
| 185 | $entries = get_posts($args); | 190 | $entries = get_posts($args); |
| 186 | 191 | ||
| 187 | 192 | foreach ($entries as $entry) { | |
| 188 | foreach($entries as $entry) { | ||
| 189 | $id = $entry->ID; | 193 | $id = $entry->ID; |
| 190 | 194 | ||
| 191 | $details = get_post_meta($id,'details',true); | 195 | $details = get_post_meta($id, 'details', true); |
| 192 | $email = get_post_meta($id,'email',true); | 196 | $email = get_post_meta($id, 'email', true); |
| 193 | $system = get_post_meta($id,'system',true); | 197 | $system = get_post_meta($id, 'system', true); |
| 194 | |||
| 195 | 198 | ||
| 196 | $entry->trigger = $details['trigger']; | 199 | $entry->trigger = $details['trigger']; |
| 197 | $entry->status = isset($details['status']) ? $details['status'] : "active"; | 200 | $entry->status = isset($details['status']) ? $details['status'] : "active"; |
| 198 | $entry->type = $details['type']; | 201 | $entry->type = $details['type']; |
| 199 | $entry->sendto = $details['sendto']; | 202 | $entry->sendto = $details['sendto']; |
| 200 | 203 | ||
| 201 | $entry->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false; | 204 | $entry->is_email = (($email['text'] != '' || $email['html'] != '')) ? true : false; |
| 202 | $entry->is_system = (isset($system['message']) && $system['message'] != "") ? true : false; | 205 | $entry->is_system = (isset($system['message']) && $system['message'] != '') ? true : false; |
| 203 | 206 | ||
| 207 | $entry->execute_date = $details['execute_date']; | ||
| 204 | 208 | ||
| 205 | $entry->execute_date = $details['execute_date']; | 209 | if ($entry->status != 'archived') { |
| 206 | |||
| 207 | if ($entry->status != "archived") { | ||
| 208 | $notifications[$entry->type][] = $entry; | 210 | $notifications[$entry->type][] = $entry; |
| 209 | } | 211 | } |
| 210 | |||
| 211 | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin.php'); | 214 | require_once(__DIR__.'/views/admin.php'); |
| 215 | } | 215 | } |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | function mysqldatetime_to_timestamp($datetime = "") | 218 | /** |
| 219 | * @param string $datetime | ||
| 220 | * | ||
| 221 | * @return int | ||
| 222 | */ | ||
| 223 | function mysqldatetime_to_timestamp($datetime = '') | ||
| 219 | { | 224 | { |
| 220 | // function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters) | 225 | // function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters) |
| 221 | $l = strlen($datetime); | 226 | $l = strlen($datetime); |
| 222 | if(!($l == 10 || $l == 19)) | 227 | if (!($l == 10 || $l == 19)) { |
| 223 | return 0; | 228 | return 0; |
| 229 | } | ||
| 224 | 230 | ||
| 225 | // | 231 | // |
| 226 | $date = $datetime; | 232 | $date = $datetime; |
| 227 | $hours = 0; | 233 | $hours = 0; |
| 228 | $minutes = 0; | 234 | $minutes = 0; |
| 229 | $seconds = 0; | 235 | $seconds = 0; |
| 230 | 236 | ||
| 231 | // DATETIME only | 237 | // DATETIME only |
| 232 | if($l == 19) | 238 | if ($l == 19) { |
| 233 | { | 239 | list($date, $time) = explode(" ", $datetime); |
| 234 | list($date, $time) = explode(" ", $datetime); | 240 | list($hours, $minutes, $seconds) = explode(":", $time); |
| 235 | list($hours, $minutes, $seconds) = explode(":", $time); | ||
| 236 | } | 241 | } |
| 237 | 242 | ||
| 238 | list($year, $month, $day) = explode("-", $date); | 243 | list($year, $month, $day) = explode("-", $date); |
| ... | @@ -240,13 +245,16 @@ function mysqldatetime_to_timestamp($datetime = "") | ... | @@ -240,13 +245,16 @@ function mysqldatetime_to_timestamp($datetime = "") |
| 240 | return mktime($hours, $minutes, $seconds, $month, $day, $year); | 245 | return mktime($hours, $minutes, $seconds, $month, $day, $year); |
| 241 | } | 246 | } |
| 242 | 247 | ||
| 248 | /** | ||
| 249 | * @param $files | ||
| 250 | */ | ||
| 243 | function fixFilesArray(&$files) | 251 | function fixFilesArray(&$files) |
| 244 | { | 252 | { |
| 245 | $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1); | 253 | $names = ['name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1]; |
| 246 | 254 | ||
| 247 | foreach ($files as $key => $part) { | 255 | foreach ($files as $key => $part) { |
| 248 | // only deal with valid keys and multiple files | 256 | // only deal with valid keys and multiple files |
| 249 | $key = (string) $key; | 257 | $key = (string)$key; |
| 250 | if (isset($names[$key]) && is_array($part)) { | 258 | if (isset($names[$key]) && is_array($part)) { |
| 251 | foreach ($part as $position => $value) { | 259 | foreach ($part as $position => $value) { |
| 252 | $files[$position][$key] = $value; | 260 | $files[$position][$key] = $value; |
| ... | @@ -257,94 +265,90 @@ function fixFilesArray(&$files) | ... | @@ -257,94 +265,90 @@ function fixFilesArray(&$files) |
| 257 | } | 265 | } |
| 258 | } | 266 | } |
| 259 | 267 | ||
| 268 | function notification_settings() | ||
| 269 | { | ||
| 260 | 270 | ||
| 261 | function notification_settings() { | 271 | require_once(__DIR__.'/views/settings.php'); |
| 262 | |||
| 263 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php'); | ||
| 264 | |||
| 265 | |||
| 266 | |||
| 267 | } | 272 | } |
| 268 | 273 | ||
| 269 | function create_notification() { | 274 | function create_notification() |
| 270 | 275 | { | |
| 276 | /** @var \wpdb $wpdb */ | ||
| 271 | global $wpdb; | 277 | global $wpdb; |
| 272 | 278 | ||
| 273 | |||
| 274 | // here | 279 | // here |
| 275 | $validation = new Notifications\Validation; | 280 | $validation = new Notifications\Validation; |
| 276 | 281 | ||
| 277 | $validation->set_rules('type','Notification Type','required'); | 282 | $validation->set_rules('type', 'Notification Type', 'required'); |
| 278 | $validation->set_rules('title','Description','trim|required|min_length[16]'); | 283 | $validation->set_rules('title', 'Description', 'trim|required|min_length[16]'); |
| 279 | $validation->set_rules('type','Notification Type','required'); | 284 | $validation->set_rules('type', 'Notification Type', 'required'); |
| 280 | $validation->set_rules('sendto','Send To','required'); | 285 | $validation->set_rules('sendto', 'Send To', 'required'); |
| 281 | 286 | ||
| 282 | $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : ''; | 287 | $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : ''; |
| 283 | $validation->set_rules('execute_date','Execute Date', $type_val); | 288 | $validation->set_rules('execute_date', 'Execute Date', $type_val); |
| 284 | 289 | ||
| 285 | $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : ''; | 290 | $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : ''; |
| 286 | $validation->set_rules('trigger','Trigger',$trigger_val); | 291 | $validation->set_rules('trigger', 'Trigger', $trigger_val); |
| 287 | 292 | ||
| 288 | $validation->set_rules('subject','Subject','trim'); | 293 | $validation->set_rules('subject', 'Subject', 'trim'); |
| 289 | $validation->set_rules('text','Text Version','trim|min_length[16]'); | 294 | $validation->set_rules('text', 'Text Version', 'trim|min_length[16]'); |
| 290 | $validation->set_rules('html','HTML Version','trim|min_length[16]'); | 295 | $validation->set_rules('html', 'HTML Version', 'trim|min_length[16]'); |
| 291 | 296 | ||
| 292 | $validation->set_rules('system','System Message','trim|min_length[16]'); | 297 | $validation->set_rules('system', 'System Message', 'trim|min_length[16]'); |
| 293 | 298 | ||
| 294 | 299 | if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) { | |
| 295 | if ($_POST && ($_POST['subject']=="" && $_POST['system']=="")) { | ||
| 296 | $form_error = true; | 300 | $form_error = true; |
| 297 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php'); | 301 | require_once(__DIR__.'/views/create.php'); |
| 298 | } else { | 302 | } else { |
| 299 | if ($validation->run() == TRUE) { | 303 | if ($validation->run() == true) { |
| 300 | 304 | ||
| 301 | // Clean up the data before saving | 305 | // Clean up the data before saving |
| 302 | Tools\tzClean($_POST); | 306 | Tools\tzClean($_POST); |
| 303 | 307 | ||
| 304 | // ok, so now we need to create the notification. | 308 | // ok, so now we need to create the notification. |
| 305 | class postTemplate { | 309 | class postTemplate |
| 306 | var $post_title = ''; | 310 | { |
| 307 | var $post_content = ''; | 311 | var $post_title = ''; |
| 308 | var $post_status = 'publish'; | 312 | var $post_content = ''; |
| 309 | var $post_type = 'notifications'; | 313 | var $post_status = 'publish'; |
| 314 | var $post_type = 'notifications'; | ||
| 310 | var $comment_status = 'closed'; | 315 | var $comment_status = 'closed'; |
| 311 | } | 316 | } |
| 312 | 317 | ||
| 313 | //details | 318 | //details |
| 314 | $type = $_POST['type']; | 319 | $type = $_POST['type']; |
| 315 | $title = $_POST['title']; | 320 | $title = $_POST['title']; |
| 316 | $sendto = $_POST['sendto']; | 321 | $sendto = $_POST['sendto']; |
| 317 | $execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00"; | 322 | $execute_date = ($type == "scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00"; |
| 318 | $trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger']; | 323 | $trigger = ($type == "scheduled") ? "scheduled-cron-job" : $_POST['trigger']; |
| 319 | 324 | ||
| 320 | 325 | ||
| 321 | $subject = $_POST['subject']; | 326 | $subject = $_POST['subject']; |
| 322 | $text = $_POST['text']; | 327 | $text = $_POST['text']; |
| 323 | $html = $_POST['html']; | 328 | $html = $_POST['html']; |
| 324 | $attachments = array(); | 329 | $attachments = []; |
| 325 | $upload_dir = __DIR__ . "/uploads/"; | 330 | $upload_dir = __DIR__.'/uploads/'; |
| 326 | fixFilesArray($_FILES['attachment']); | 331 | fixFilesArray($_FILES['attachment']); |
| 327 | foreach ($_FILES['attachment'] as $position => $file) { | 332 | foreach ($_FILES['attachment'] as $position => $file) { |
| 328 | // should output array with indices name, type, tmp_name, error, size | 333 | // should output array with indices name, type, tmp_name, error, size |
| 329 | if($file['name'] != "") { | 334 | if ($file['name'] != "") { |
| 330 | move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']); | 335 | move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']); |
| 331 | $attachments[] = $file['name']; | 336 | $attachments[] = $file['name']; |
| 332 | } | 337 | } |
| 333 | } | 338 | } |
| 334 | 339 | ||
| 335 | // system | 340 | // system |
| 336 | $system_message_type = $_POST['system_message_type']; | 341 | $system_message_type = $_POST['system_message_type']; |
| 337 | $system = $_POST['system']; | 342 | $system = $_POST['system']; |
| 338 | |||
| 339 | |||
| 340 | |||
| 341 | 343 | ||
| 342 | // make post... | 344 | // make post... |
| 343 | 345 | ||
| 344 | $notification = new postTemplate(); | 346 | $notification = new postTemplate(); |
| 345 | $notification->post_title = $title; | 347 | $notification->post_title = $title; |
| 346 | $notification->post_content = "Notification created ".date('Y-m-d H:i:s')." --- to be sent on $execute_date"; | 348 | $notification->post_content = "Notification created ".date( |
| 347 | $notification->post_date_gmt = date("Y-m-d H:i:s",time()); | 349 | 'Y-m-d H:i:s' |
| 350 | )." --- to be sent on $execute_date"; | ||
| 351 | $notification->post_date_gmt = date("Y-m-d H:i:s", time()); | ||
| 348 | 352 | ||
| 349 | $id = wp_insert_post($notification); | 353 | $id = wp_insert_post($notification); |
| 350 | 354 | ||
| ... | @@ -352,71 +356,88 @@ function create_notification() { | ... | @@ -352,71 +356,88 @@ function create_notification() { |
| 352 | update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date)); | 356 | update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date)); |
| 353 | update_post_meta($id, 'trigger', $trigger); | 357 | update_post_meta($id, 'trigger', $trigger); |
| 354 | 358 | ||
| 355 | add_post_meta($id, "details", array( | 359 | add_post_meta( |
| 356 | 'type' => $type | 360 | $id, |
| 357 | , 'sendto' => $sendto | 361 | "details", |
| 358 | , 'status' => 'pending' | 362 | [ |
| 359 | , 'trigger' => $trigger | 363 | 'type' => $type, |
| 360 | , 'execute_date' => $execute_date | 364 | 'sendto' => $sendto, |
| 361 | )); | 365 | 'status' => 'pending', |
| 362 | 366 | 'trigger' => $trigger, | |
| 363 | update_post_meta($id,'send_status','pending'); | 367 | 'execute_date' => $execute_date |
| 364 | 368 | ] | |
| 365 | add_post_meta($id, "email", array( | 369 | ); |
| 366 | 'subject' => $subject | 370 | |
| 367 | , 'text' => $text | 371 | update_post_meta($id, 'send_status', 'pending'); |
| 368 | , 'html' => $html | 372 | |
| 369 | , 'attachments' => $attachments | 373 | add_post_meta( |
| 370 | )); | 374 | $id, |
| 371 | update_post_meta($id, "system", array( | 375 | "email", |
| 372 | 'system_message_type' => $system_message_type | 376 | [ |
| 373 | , 'message' => $system | 377 | 'subject' => $subject, |
| 374 | )); | 378 | 'text' => $text, |
| 379 | 'html' => $html, | ||
| 380 | 'attachments' => $attachments | ||
| 381 | ] | ||
| 382 | ); | ||
| 383 | update_post_meta( | ||
| 384 | $id, | ||
| 385 | "system", | ||
| 386 | [ | ||
| 387 | 'system_message_type' => $system_message_type, | ||
| 388 | 'message' => $system | ||
| 389 | ] | ||
| 390 | ); | ||
| 375 | 391 | ||
| 376 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; | 392 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; |
| 377 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php'); | 393 | require_once(__DIR__.'/views/create.php'); |
| 378 | |||
| 379 | } else { | 394 | } else { |
| 380 | require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php'); | 395 | require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php'); |
| 381 | } | 396 | } |
| 382 | } | 397 | } |
| 383 | |||
| 384 | |||
| 385 | } | 398 | } |
| 386 | 399 | ||
| 387 | class Actions { | 400 | class Actions |
| 401 | { | ||
| 388 | 402 | ||
| 389 | public static function init() { | 403 | public static function init() |
| 404 | { | ||
| 405 | /** @var \wpdb $wpdb */ | ||
| 390 | global $wpdb; | 406 | global $wpdb; |
| 391 | $wpdb->show_errors(); | 407 | $wpdb->show_errors(); |
| 392 | 408 | ||
| 393 | register_post_type( 'notifications', array( | 409 | register_post_type( |
| 394 | 'label' => __('Notifs') | 410 | 'notifications', |
| 395 | , 'public' => true | 411 | [ |
| 396 | , 'show_ui' => false | 412 | 'label' => __('Notifs', CBV_DOMAIN), |
| 397 | , 'hierarchical' => false | 413 | 'public' => true, |
| 398 | , 'exclude_from_search' => true | 414 | 'show_ui' => false, |
| 399 | )); | 415 | 'hierarchical' => false, |
| 400 | 416 | 'exclude_from_search' => true | |
| 417 | ] | ||
| 418 | ); | ||
| 401 | } | 419 | } |
| 402 | 420 | ||
| 403 | public static function admin_menu() { | 421 | public static function admin_menu() |
| 404 | add_menu_page('Notifications','Notifications',CAPABILITY,'notifications',__NAMESPACE__ . '\display_page' ); | 422 | { |
| 405 | add_submenu_page('notifications','New Notification', 'New Notification',CAPABILITY,'notifications-create-new',__NAMESPACE__ . '\create_notification'); | 423 | add_menu_page('Notifications', 'Notifications', CAPABILITY, 'notifications', __NAMESPACE__.'\display_page'); |
| 406 | //add_options_page('CAN-SPAM Settings', 'CAN-SPAM Settings', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\notification_settings'); | 424 | add_submenu_page( |
| 407 | //add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings'); | 425 | 'notifications', |
| 426 | 'New Notification', | ||
| 427 | 'New Notification', | ||
| 428 | CAPABILITY, | ||
| 429 | 'notifications-create-new', | ||
| 430 | __NAMESPACE__.'\create_notification' | ||
| 431 | ); | ||
| 408 | } | 432 | } |
| 409 | 433 | ||
| 410 | public function admin_init() { | 434 | public function admin_init() |
| 411 | // register_setting(Notifications\OPTION_NAME, Notifications\OPTION_NAME); | 435 | { |
| 412 | register_setting(SETTING_NS, SETTING_NS); | 436 | register_setting(SETTING_NS, SETTING_NS); |
| 413 | } | 437 | } |
| 414 | |||
| 415 | } | 438 | } |
| 416 | 439 | ||
| 417 | class Vars { | 440 | class Vars |
| 441 | { | ||
| 418 | public static $settings; | 442 | public static $settings; |
| 419 | } | 443 | } |
| 420 | |||
| 421 | |||
| 422 | ?> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -23,12 +23,24 @@ call_user_func( | ... | @@ -23,12 +23,24 @@ call_user_func( |
| 23 | } | 23 | } |
| 24 | ); | 24 | ); |
| 25 | 25 | ||
| 26 | /** | ||
| 27 | * @param $a | ||
| 28 | * @param $subkey | ||
| 29 | * @param $sort | ||
| 30 | * | ||
| 31 | * @return array | ||
| 32 | */ | ||
| 26 | function subval_sort($a, $subkey, $sort) | 33 | function subval_sort($a, $subkey, $sort) |
| 27 | { | 34 | { |
| 35 | $b = []; | ||
| 36 | $c = []; | ||
| 37 | |||
| 28 | foreach ($a as $k => $v) { | 38 | foreach ($a as $k => $v) { |
| 29 | $b[$k] = strtolower($v[$subkey]); | 39 | $b[$k] = strtolower($v[$subkey]); |
| 30 | } | 40 | } |
| 41 | |||
| 31 | $sort($b); | 42 | $sort($b); |
| 43 | |||
| 32 | foreach ($b as $key => $val) { | 44 | foreach ($b as $key => $val) { |
| 33 | $c[] = $a[$key]; | 45 | $c[] = $a[$key]; |
| 34 | } | 46 | } |
| ... | @@ -36,6 +48,9 @@ function subval_sort($a, $subkey, $sort) | ... | @@ -36,6 +48,9 @@ function subval_sort($a, $subkey, $sort) |
| 36 | return $c; | 48 | return $c; |
| 37 | } | 49 | } |
| 38 | 50 | ||
| 51 | /** | ||
| 52 | * @param $uid | ||
| 53 | */ | ||
| 39 | function get_user_notices($uid) | 54 | function get_user_notices($uid) |
| 40 | { | 55 | { |
| 41 | $notices = get_user_meta($uid, 'notices', true); | 56 | $notices = get_user_meta($uid, 'notices', true); |
| ... | @@ -45,6 +60,9 @@ function get_user_notices($uid) | ... | @@ -45,6 +60,9 @@ function get_user_notices($uid) |
| 45 | } | 60 | } |
| 46 | } | 61 | } |
| 47 | 62 | ||
| 63 | /** | ||
| 64 | * @param bool $showOnlyUnread | ||
| 65 | */ | ||
| 48 | function print_user_notices($showOnlyUnread = false) | 66 | function print_user_notices($showOnlyUnread = false) |
| 49 | { | 67 | { |
| 50 | $user = new User\CurrentAccount(); | 68 | $user = new User\CurrentAccount(); |
| ... | @@ -65,7 +83,15 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -65,7 +83,15 @@ function print_user_notices($showOnlyUnread = false) |
| 65 | if (isset($notice['args']) && count($notice['args']) > 0) { | 83 | if (isset($notice['args']) && count($notice['args']) > 0) { |
| 66 | foreach ($notice['args'] as $key => $val) { | 84 | foreach ($notice['args'] as $key => $val) { |
| 67 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { | 85 | if (filter_var($val, FILTER_VALIDATE_URL) !== false) { |
| 68 | $content = str_replace('{'.$key.'}', "<a href='".$val."'>Click here</a>", $content); | 86 | $content = str_replace( |
| 87 | '{'.$key.'}', | ||
| 88 | "<a href='" | ||
| 89 | .$val | ||
| 90 | ."'>" | ||
| 91 | .__('Click here', CBV_DOMAIN) | ||
| 92 | .'</a>', | ||
| 93 | $content | ||
| 94 | ); | ||
| 69 | } else { | 95 | } else { |
| 70 | $content = str_replace('{'.$key.'}', $val, $content); | 96 | $content = str_replace('{'.$key.'}', $val, $content); |
| 71 | } | 97 | } |
| ... | @@ -75,7 +101,7 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -75,7 +101,7 @@ function print_user_notices($showOnlyUnread = false) |
| 75 | $rows .= '<tr class="notice-row" id="'.$index.'">'; | 101 | $rows .= '<tr class="notice-row" id="'.$index.'">'; |
| 76 | $rows .= '<td width="12" style="padding: 0 0 0 10px; vertical-align: middle;"><a href="javascript:;" class="notice ' | 102 | $rows .= '<td width="12" style="padding: 0 0 0 10px; vertical-align: middle;"><a href="javascript:;" class="notice ' |
| 77 | .(($notice['status'] == 'read') ? 'read' : 'unread') | 103 | .(($notice['status'] == 'read') ? 'read' : 'unread') |
| 78 | .'"><img src="assets/images/blank.gif" width="12" height="12"></a></td>'; | 104 | .'"><img src="/wp-content/themes/cbv/assets/images/blank.gif" style="width: 12px; height: 12px;"></a></td>'; |
| 79 | 105 | ||
| 80 | if ($system['system_message_type'] == 'none') { | 106 | if ($system['system_message_type'] == 'none') { |
| 81 | $system['system_message_type'] = 'notice'; | 107 | $system['system_message_type'] = 'notice'; |
| ... | @@ -84,8 +110,9 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -84,8 +110,9 @@ function print_user_notices($showOnlyUnread = false) |
| 84 | $rows .= '<td width="80" style="vertical-align:middle;"><span>' | 110 | $rows .= '<td width="80" style="vertical-align:middle;"><span>' |
| 85 | .ucfirst(str_replace('_', ' ', $system['system_message_type'])) | 111 | .ucfirst(str_replace('_', ' ', $system['system_message_type'])) |
| 86 | .'</span></td>'; | 112 | .'</span></td>'; |
| 87 | $rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">Sent: ' | 113 | $rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">' |
| 88 | .date('M j, Y @ h:ia', $notice['sent_date']).'</span></td>'; | 114 | .__('Sent:', CBV_DOMAIN) |
| 115 | .CBV\tz_display('notice_sent_date', $notice['sent_date']).'</span></td>'; | ||
| 89 | $rows .= '</tr>'; | 116 | $rows .= '</tr>'; |
| 90 | } | 117 | } |
| 91 | 118 | ||
| ... | @@ -96,6 +123,11 @@ function print_user_notices($showOnlyUnread = false) | ... | @@ -96,6 +123,11 @@ function print_user_notices($showOnlyUnread = false) |
| 96 | } | 123 | } |
| 97 | } | 124 | } |
| 98 | 125 | ||
| 126 | /** | ||
| 127 | * @param $trigger | ||
| 128 | * | ||
| 129 | * @return bool | ||
| 130 | */ | ||
| 99 | function get_notification_by_trigger($trigger) | 131 | function get_notification_by_trigger($trigger) |
| 100 | { | 132 | { |
| 101 | $args = [ | 133 | $args = [ |
| ... | @@ -119,8 +151,9 @@ function get_notification_by_trigger($trigger) | ... | @@ -119,8 +151,9 @@ function get_notification_by_trigger($trigger) |
| 119 | } | 151 | } |
| 120 | 152 | ||
| 121 | /** | 153 | /** |
| 122 | * GET NUMBER OF NEW NOTICES | 154 | * Get number of new notices |
| 123 | * @returns (Int) | 155 | * |
| 156 | * @return int | ||
| 124 | */ | 157 | */ |
| 125 | function get_num_notices() | 158 | function get_num_notices() |
| 126 | { | 159 | { |
| ... | @@ -166,11 +199,21 @@ function markNotice($notification_id = -1, $status = NOTIFICATION_STATUS_READ) | ... | @@ -166,11 +199,21 @@ function markNotice($notification_id = -1, $status = NOTIFICATION_STATUS_READ) |
| 166 | 199 | ||
| 167 | /** | 200 | /** |
| 168 | * Send Notifications | 201 | * Send Notifications |
| 202 | * | ||
| 169 | * @trigger = notification unique slug name | 203 | * @trigger = notification unique slug name |
| 204 | * | ||
| 205 | * @param int $uid | ||
| 206 | * @param string $trigger | ||
| 207 | * @param array $args | ||
| 208 | * | ||
| 209 | * @throws \Exception | ||
| 170 | */ | 210 | */ |
| 171 | function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [], $send_override = false) | 211 | function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = []) |
| 172 | { | 212 | { |
| 213 | /** @var \wpdb $wpdb */ | ||
| 173 | global $wpdb; | 214 | global $wpdb; |
| 215 | |||
| 216 | /** @var \StdClass $notification */ | ||
| 174 | $notification = get_notification_by_trigger($trigger); | 217 | $notification = get_notification_by_trigger($trigger); |
| 175 | 218 | ||
| 176 | if ($notification) { | 219 | if ($notification) { |
| ... | @@ -181,13 +224,13 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = | ... | @@ -181,13 +224,13 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = |
| 181 | $system = get_post_meta($nid, 'system', true); | 224 | $system = get_post_meta($nid, 'system', true); |
| 182 | 225 | ||
| 183 | $notification->trigger = $details['trigger']; | 226 | $notification->trigger = $details['trigger']; |
| 184 | $notification->status = isset($details['status']) ? $details['status'] : "active"; | 227 | $notification->status = isset($details['status']) ? $details['status'] : 'active'; |
| 185 | $notification->type = $details['type']; | 228 | $notification->type = $details['type']; |
| 186 | $notification->sendto = @$details['sendto']; | 229 | $notification->sendto = @$details['sendto']; |
| 187 | $notification->is_email = (($email['text'] != "" || $email['html'] != "") && $email['subject'] != "") | 230 | $notification->is_email = (($email['text'] != '' || $email['html'] != '') && $email['subject'] != '') |
| 188 | ? true | 231 | ? true |
| 189 | : false; | 232 | : false; |
| 190 | $notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false; | 233 | $notification->is_system = (isset($system['message']) && $system['message'] != '') ? true : false; |
| 191 | 234 | ||
| 192 | // if is_system ========================================== | 235 | // if is_system ========================================== |
| 193 | if ($notification->is_system && $uid != 0) { | 236 | if ($notification->is_system && $uid != 0) { |
| ... | @@ -311,15 +354,20 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = | ... | @@ -311,15 +354,20 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = |
| 311 | ); | 354 | ); |
| 312 | } | 355 | } |
| 313 | } | 356 | } |
| 314 | // if the system notification has set current user than get current user otherwise loop through the users needed. | ||
| 315 | } | 357 | } |
| 316 | 358 | ||
| 359 | /** | ||
| 360 | * @param int $grpID | ||
| 361 | * | ||
| 362 | * @return array | ||
| 363 | */ | ||
| 317 | function getGroups($grpID = 0) | 364 | function getGroups($grpID = 0) |
| 318 | { | 365 | { |
| 319 | global $userAccessManager; | 366 | global $userAccessManager; |
| 320 | 367 | ||
| 321 | $groups = []; | 368 | $groups = []; |
| 322 | if ($grpID > 0) { | 369 | if ($grpID > 0) { |
| 370 | /** @var \UamUserGroup $userGroups */ | ||
| 323 | $userGroups = $userAccessManager | 371 | $userGroups = $userAccessManager |
| 324 | ->getAccessHandler() | 372 | ->getAccessHandler() |
| 325 | ->getUserGroups($grpID); | 373 | ->getUserGroups($grpID); |
| ... | @@ -330,6 +378,8 @@ function getGroups($grpID = 0) | ... | @@ -330,6 +378,8 @@ function getGroups($grpID = 0) |
| 330 | ->getAccessHandler() | 378 | ->getAccessHandler() |
| 331 | ->getUserGroups(); | 379 | ->getUserGroups(); |
| 332 | } | 380 | } |
| 381 | |||
| 382 | /** @var \UamUserGroup $group */ | ||
| 333 | foreach ($userGroups as $group) { | 383 | foreach ($userGroups as $group) { |
| 334 | $groups[$group->getId()] = $group->getGroupName(); | 384 | $groups[$group->getId()] = $group->getGroupName(); |
| 335 | } | 385 | } |
| ... | @@ -337,22 +387,30 @@ function getGroups($grpID = 0) | ... | @@ -337,22 +387,30 @@ function getGroups($grpID = 0) |
| 337 | return $groups; | 387 | return $groups; |
| 338 | } | 388 | } |
| 339 | 389 | ||
| 390 | /** | ||
| 391 | * @param $var | ||
| 392 | * | ||
| 393 | * @return mixed | ||
| 394 | */ | ||
| 340 | function get_field_lookup($var) | 395 | function get_field_lookup($var) |
| 341 | { | 396 | { |
| 342 | return isset(Vars::$field_lookup[$var]) ? Vars::$field_lookup[$var] : $var; | 397 | return isset(Vars::$field_lookup[$var]) ? Vars::$field_lookup[$var] : $var; |
| 343 | } | 398 | } |
| 344 | 399 | ||
| 400 | /** | ||
| 401 | * @return string | ||
| 402 | */ | ||
| 345 | function current_url() | 403 | function current_url() |
| 346 | { | 404 | { |
| 347 | $pageURL = 'http'; | 405 | $pageURL = 'http'; |
| 348 | if ($_SERVER["HTTPS"] == "on") { | 406 | if ($_SERVER['HTTPS'] == 'on') { |
| 349 | $pageURL .= "s"; | 407 | $pageURL .= 's'; |
| 350 | } | 408 | } |
| 351 | $pageURL .= "://"; | 409 | $pageURL .= '://'; |
| 352 | if ($_SERVER["SERVER_PORT"] != "80") { | 410 | if ($_SERVER['SERVER_PORT'] != '80') { |
| 353 | $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; | 411 | $pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI']; |
| 354 | } else { | 412 | } else { |
| 355 | $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; | 413 | $pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; |
| 356 | } | 414 | } |
| 357 | 415 | ||
| 358 | return $pageURL; | 416 | return $pageURL; | ... | ... |
| 1 | <?php | 1 | <?php |
| 2 | use Tz\WordPress\Tools; | ||
| 2 | use Tz\WordPress\Tools\Notifications; | 3 | use Tz\WordPress\Tools\Notifications; |
| 3 | use Tz\WordPress\Tools\Notifications\Settings; | 4 | use Tz\WordPress\Tools\Notifications\Settings; |
| 4 | use Tz\WordPress\Tools; | ||
| 5 | |||
| 6 | /* | ||
| 7 | |||
| 8 | print "<pre>"; | ||
| 9 | print_r($notifications); | ||
| 10 | print "</pre>"; | ||
| 11 | |||
| 12 | */ | ||
| 13 | |||
| 14 | ?> | 5 | ?> |
| 15 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" /> | ||
| 16 | <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.-1.4.2.min.js', __FILE__)?>"></script> | ||
| 17 | <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.qtip-1.0.0-rc3.js', __FILE__)?>"></script> | ||
| 18 | 6 | ||
| 7 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/> | ||
| 8 | <script src="<?php echo Tools\url('assets/scripts/jquery.qtip-1.0.0-rc3.js', __FILE__) ?>"></script> | ||
| 19 | 9 | ||
| 20 | 10 | ||
| 21 | <div id="" class="wrap"> | 11 | <div id="" class="wrap"> |
| 22 | <h2>Notifications</h2> | 12 | <h2>Notifications</h2> |
| 23 | 13 | ||
| 24 | <h3 class="table-caption">Scheduled Notifications</h3> | 14 | <h3 class="table-caption">Scheduled Notifications</h3> |
| 25 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> | 15 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> |
| 26 | <thead> | 16 | <thead> |
| ... | @@ -34,73 +24,80 @@ print "</pre>"; | ... | @@ -34,73 +24,80 @@ print "</pre>"; |
| 34 | </tr> | 24 | </tr> |
| 35 | </thead> | 25 | </thead> |
| 36 | <tbody> | 26 | <tbody> |
| 37 | <?php foreach($notifications['scheduled'] as $entry): | 27 | <?php foreach ($notifications['scheduled'] as $entry): |
| 38 | |||
| 39 | $sendto = $entry->sendto; | 28 | $sendto = $entry->sendto; |
| 40 | if(is_numeric($sendto)) { | 29 | if (is_numeric($sendto)) { |
| 41 | $sendto = Notifications\getGroups($sendto) . " Group"; | 30 | $sendto = Notifications\getGroups($sendto)." Group"; |
| 42 | } else { | 31 | } else { |
| 43 | $sendto = Notifications\get_field_lookup($sendto); | 32 | $sendto = Notifications\get_field_lookup($sendto); |
| 44 | } | 33 | } |
| 45 | 34 | ?> | |
| 46 | ?> | 35 | <tr> |
| 47 | <tr> | 36 | <td><?php echo $entry->post_title; ?></td> |
| 48 | <td><?php echo $entry->post_title; ?></td> | 37 | <td><?php echo date("M j, Y @ h:i A", strtotime($entry->execute_date)); ?></td> |
| 49 | <td><?php echo date("M j, Y @ h:i A",strtotime($entry->execute_date)); ?></td> | 38 | <td><?php echo ucwords($sendto); ?></td> |
| 50 | <td><?php echo ucwords($sendto); ?></td> | 39 | <td><?php if ($entry->is_email): ?><img |
| 51 | <td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td> | 40 | src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td> |
| 52 | <td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td> | 41 | <td><?php if ($entry->is_system): ?><img |
| 53 | <td> | 42 | src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td> |
| 54 | 43 | <td> | |
| 55 | <?php | 44 | |
| 56 | 45 | <?php | |
| 57 | if (strtotime($entry->execute_date) > current_time('timestamp')):?> | 46 | |
| 58 | <a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | 47 | if (strtotime($entry->execute_date) > current_time('timestamp')):?> |
| 59 | | <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a></td> | 48 | <a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> |
| 60 | 49 | | <a | |
| 61 | <?php else: ?> | 50 | href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" |
| 62 | <a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | <em>In progress....</em> | 51 | onclick="return confirm('Are you sure?');">delete</a></td> |
| 63 | <?php endif; ?> | 52 | |
| 64 | </tr> | 53 | <?php else: ?> |
| 54 | <a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | | ||
| 55 | <em>In progress....</em> | ||
| 56 | <?php endif; ?> | ||
| 57 | </tr> | ||
| 65 | <?php endforeach; ?> | 58 | <?php endforeach; ?> |
| 66 | </tbody> | 59 | </tbody> |
| 67 | </table> | 60 | </table> |
| 68 | 61 | ||
| 69 | 62 | ||
| 70 | <h3 class="table-caption">System Triggered Notifications</h3> | 63 | <h3 class="table-caption">System Triggered Notifications</h3> |
| 71 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> | 64 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> |
| 72 | <thead> | 65 | <thead> |
| 73 | <tr> | 66 | <tr> |
| 74 | <th scope="col" class="manage-column">Description</th> | 67 | <th scope="col" class="manage-column">Description</th> |
| 75 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> | 68 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> |
| 76 | <th scope="col" width="200" class="manage-column">Trigger/Slug</th> | 69 | <th scope="col" width="200" class="manage-column">Trigger/Slug</th> |
| 77 | <?php endif; ?> | 70 | <?php endif; ?> |
| 78 | 71 | ||
| 79 | <th scope="col" width="60" class="manage-column">Email</th> | 72 | <th scope="col" width="60" class="manage-column">Email</th> |
| 80 | <th scope="col" width="60" class="manage-column">System</th> | 73 | <th scope="col" width="60" class="manage-column">System</th> |
| 81 | <th scope="col" width="200" class="manage-column"> </th> | 74 | <th scope="col" width="200" class="manage-column"> </th> |
| 82 | </tr> | 75 | </tr> |
| 83 | </thead> | 76 | </thead> |
| 84 | <tbody> | 77 | <tbody> |
| 85 | <?php foreach($notifications['triggered'] as $entry):?> | 78 | <?php foreach ($notifications['triggered'] as $entry): ?> |
| 86 | <tr> | 79 | <tr> |
| 87 | <td><?php echo $entry->post_title; ?></td> | 80 | <td><?php echo $entry->post_title; ?></td> |
| 88 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> | 81 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> |
| 89 | <td><?php echo $entry->trigger; ?></td> | 82 | <td><?php echo $entry->trigger; ?></td> |
| 90 | <?php endif; ?> | 83 | <?php endif; ?> |
| 91 | 84 | ||
| 92 | <td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td> | 85 | <td><?php if ($entry->is_email): ?><img |
| 93 | <td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td> | 86 | src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td> |
| 94 | 87 | <td><?php if ($entry->is_system): ?><img | |
| 95 | <td><a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | 88 | src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td> |
| 96 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> | 89 | |
| 97 | | <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a> | 90 | <td><a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> |
| 98 | <?php endif; ?> | 91 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> |
| 99 | </td> | 92 | | <a |
| 100 | </tr> | 93 | href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" |
| 94 | onclick="return confirm('Are you sure?');">delete</a> | ||
| 95 | <?php endif; ?> | ||
| 96 | </td> | ||
| 97 | </tr> | ||
| 101 | <?php endforeach; ?> | 98 | <?php endforeach; ?> |
| 102 | </tbody> | 99 | </tbody> |
| 103 | </table> | 100 | </table> |
| 104 | 101 | ||
| 105 | 102 | ||
| 106 | </div> | 103 | </div> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | <?php | 1 | <?php |
| 2 | use Tz\WordPress\Tools\Notifications\Settings; | ||
| 3 | use Tz\WordPress\Tools\Notifications; | ||
| 4 | use Tz\WordPress\Tools; | 2 | use Tz\WordPress\Tools; |
| 5 | 3 | use Tz\WordPress\Tools\Notifications; | |
| 4 | use Tz\WordPress\Tools\Notifications\Settings; | ||
| 6 | ?> | 5 | ?> |
| 7 | 6 | ||
| 8 | <link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" /> | 7 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/> |
| 9 | <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script> | ||
| 10 | <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script> | ||
| 11 | <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script> | ||
| 12 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" /> | ||
| 13 | |||
| 14 | <div id="" class="wrap"> | ||
| 15 | 8 | ||
| 9 | <div class="wrap"> | ||
| 16 | <h2>Notifications - Create New</h2> | 10 | <h2>Notifications - Create New</h2> |
| 17 | 11 | ||
| 18 | <?php if (isset($flash) && $flash !=""): ?> | 12 | <?php if (isset($flash) && $flash != ""): ?> |
| 19 | <div class="post-success"> | 13 | <div class="post-success"> |
| 20 | <?php echo $flash; ?> | 14 | <?php echo $flash; ?> |
| 21 | </div> | 15 | </div> |
| 16 | <?php endif; ?> | ||
| 17 | <?php if ($validation->validation_errors() != "" || isset($form_error)): ?> | ||
| 18 | <div class="post-errors"> | ||
| 19 | <div class="post-errors-title"><strong>Oops.</strong> There was an error saving your notification.</div> | ||
| 20 | <?php if (isset($form_error)): ?> | ||
| 21 | <p class="post-errors-content">You must include either an Email, System or SMS message.</p> | ||
| 22 | <?php endif; ?> | ||
| 23 | </div> | ||
| 22 | <?php endif; ?> | 24 | <?php endif; ?> |
| 23 | <?php if($validation->validation_errors() != "" || isset($form_error)):?> | 25 | |
| 24 | <div class="post-errors"> | ||
| 25 | <div class="post-errors-title"><strong>Oops.</strong> There was an error saving your notification.</div> | ||
| 26 | <?php if (isset($form_error)):?> | ||
| 27 | <p class="post-errors-content">You must include either an Email, System or SMS message.</p> | ||
| 28 | <?php endif; ?> | ||
| 29 | </div> | ||
| 30 | <?php endif;?> | ||
| 31 | |||
| 32 | <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new"> | 26 | <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new"> |
| 33 | 27 | ||
| 34 | <input type="hidden" name="_POSTED_" value="yes" /> | 28 | <input type="hidden" name="_POSTED_" value="yes"/> |
| 35 | 29 | ||
| 36 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> | 30 | <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;"> |
| 37 | <thead> | 31 | <thead> |
| 38 | <tr> | 32 | <tr> |
| ... | @@ -44,48 +38,67 @@ use Tz\WordPress\Tools; | ... | @@ -44,48 +38,67 @@ use Tz\WordPress\Tools; |
| 44 | <tr> | 38 | <tr> |
| 45 | <td width="150">Notification Type</td> | 39 | <td width="150">Notification Type</td> |
| 46 | <td> | 40 | <td> |
| 47 | <select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();"> | 41 | <select name="type" id="notif_type" class="wide-input-field" |
| 48 | <option value="scheduled" <?php echo ($validation->set_value('type')=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option> | 42 | onchange="updateNotificationType();"> |
| 49 | 43 | <option value="scheduled" <?php echo ($validation->set_value('type') == "scheduled") | |
| 44 | ? 'selected="selected"' : ""; ?>>Scheduled Notification | ||
| 45 | </option> | ||
| 46 | |||
| 50 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> | 47 | <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> |
| 51 | <option value="triggered" <?php echo ($validation->set_value('type')=="triggered") ? 'selected="selected"' : "";?>>System Triggered Notification</option> | 48 | <option value="triggered" <?php echo ($validation->set_value('type') == "triggered") |
| 49 | ? 'selected="selected"' : ""; ?>>System Triggered Notification | ||
| 50 | </option> | ||
| 52 | <?php endif; ?> | 51 | <?php endif; ?> |
| 53 | </select> | 52 | </select> |
| 54 | <?php echo $validation->form_error('type');?> | 53 | <?php echo $validation->form_error('type'); ?> |
| 55 | </td> | 54 | </td> |
| 56 | </tr> | 55 | </tr> |
| 57 | <tr> | 56 | <tr> |
| 58 | <td width="150">Notification Description</td> | 57 | <td width="150">Notification Description</td> |
| 59 | <td><input type="text" name="title" class="wide-input-field" value="<?php echo $validation->set_value('title');?>" /><?php echo $validation->form_error('title');?></td> | 58 | <td><input type="text" name="title" class="wide-input-field" |
| 59 | value="<?php echo $validation->set_value( | ||
| 60 | 'title' | ||
| 61 | ); ?>"/><?php echo $validation->form_error('title'); ?></td> | ||
| 60 | </tr> | 62 | </tr> |
| 61 | <tr class="scheduled_sendto"> | 63 | <tr class="scheduled_sendto"> |
| 62 | <td>Sent To:</td> | 64 | <td>Sent To:</td> |
| 63 | <td> | 65 | <td> |
| 64 | <select name="sendto" class="wide-input-field"> | 66 | <select name="sendto" class="wide-input-field"> |
| 65 | <option value="allusers" <?php echo ($validation->set_value('sendto')=="allusers") ? 'selected="selected"' : "";?>>All Users</option> | 67 | <option value="allusers" <?php echo ($validation->set_value('sendto') == "allusers") |
| 66 | <optgroup label="By Group:"> | 68 | ? 'selected="selected"' : ""; ?>>All Users |
| 67 | <?php foreach(Notifications\getGroups() as $group_id => $group_name):?> | 69 | </option> |
| 68 | <option value="<?php echo $group_id?>" <?php echo ($validation->set_value('sendto')==$group_id) ? 'selected="selected"' : "";?>><?php echo $group_name;?></option> | 70 | <optgroup label="By Group:"> |
| 69 | <?php endforeach; ?> | 71 | <?php foreach (Notifications\getGroups() as $group_id => $group_name): ?> |
| 70 | </optgroup> | 72 | <option value="<?php echo $group_id ?>" <?php echo ($validation->set_value( |
| 71 | </select> | 73 | 'sendto' |
| 72 | <?php echo $validation->form_error('sendto');?> | 74 | ) == $group_id) ? 'selected="selected"' |
| 75 | : ""; ?>><?php echo $group_name; ?></option> | ||
| 76 | <?php endforeach; ?> | ||
| 77 | </optgroup> | ||
| 78 | </select> | ||
| 79 | <?php echo $validation->form_error('sendto'); ?> | ||
| 73 | </td> | 80 | </td> |
| 74 | </tr> | 81 | </tr> |
| 75 | 82 | ||
| 76 | <tr class="scheduled-extended"> | 83 | <tr class="scheduled-extended"> |
| 77 | <td>Execute Date / Time</td> | 84 | <td>Execute Date / Time</td> |
| 78 | <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" readonly="readonly" value="<?php echo $validation->set_value('execute_date');?>" /><?php echo $validation->form_error('execute_date');?></td> | 85 | <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" |
| 86 | readonly="readonly" value="<?php echo $validation->set_value( | ||
| 87 | 'execute_date' | ||
| 88 | ); ?>"/><?php echo $validation->form_error('execute_date'); ?></td> | ||
| 79 | </tr> | 89 | </tr> |
| 80 | 90 | ||
| 81 | <tr class="trigger-extended"> | 91 | <tr class="trigger-extended"> |
| 82 | <td>Trigger</td> | 92 | <td>Trigger</td> |
| 83 | <td><input type="text" name="trigger" id="trigger" class="wide-input-field" value="<?php echo $validation->set_value('trigger');?>" /><?php echo $validation->form_error('trigger');?></td> | 93 | <td><input type="text" name="trigger" id="trigger" class="wide-input-field" |
| 94 | value="<?php echo $validation->set_value( | ||
| 95 | 'trigger' | ||
| 96 | ); ?>"/><?php echo $validation->form_error('trigger'); ?></td> | ||
| 84 | </tr> | 97 | </tr> |
| 85 | 98 | ||
| 86 | </tbody> | 99 | </tbody> |
| 87 | </table> | 100 | </table> |
| 88 | 101 | ||
| 89 | <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> | 102 | <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> |
| 90 | <thead> | 103 | <thead> |
| 91 | <tr> | 104 | <tr> |
| ... | @@ -93,34 +106,45 @@ use Tz\WordPress\Tools; | ... | @@ -93,34 +106,45 @@ use Tz\WordPress\Tools; |
| 93 | <th class="action-bar"> </th> | 106 | <th class="action-bar"> </th> |
| 94 | </tr> | 107 | </tr> |
| 95 | </thead> | 108 | </thead> |
| 96 | <tbody style="<?php echo ($validation->set_value('subject')!="" || $validation->set_value('text')!="" || $validation->set_value('html')!="") ? "" : "display:none";?>;"> | 109 | <tbody style="<?php echo ($validation->set_value('subject') != "" || $validation->set_value( |
| 110 | 'text' | ||
| 111 | ) != "" || $validation->set_value('html') != "") ? "" : "display:none"; ?>;"> | ||
| 97 | <tr> | 112 | <tr> |
| 98 | <td width="150">Subject Line</td> | 113 | <td width="150">Subject Line</td> |
| 99 | <td><input type="text" name="subject" class="wide-input-field" style="width:100%;" value="<?php echo $validation->set_value('subject');?>" /><?php echo $validation->form_error('subject');?></td> | 114 | <td><input type="text" name="subject" class="wide-input-field" style="width:100%;" |
| 115 | value="<?php echo $validation->set_value( | ||
| 116 | 'subject' | ||
| 117 | ); ?>"/><?php echo $validation->form_error('subject'); ?></td> | ||
| 100 | </tr> | 118 | </tr> |
| 101 | <tr> | 119 | <tr> |
| 102 | <td>Text Version</td> | 120 | <td>Text Version</td> |
| 103 | <td><textarea name="text" class="wide-input-field" rows="10" style="width:100%;" ><?php echo $validation->set_value('text');?></textarea><?php echo $validation->form_error('text');?></td> | 121 | <td><textarea name="text" class="wide-input-field" rows="10" |
| 122 | style="width:100%;"><?php echo $validation->set_value( | ||
| 123 | 'text' | ||
| 124 | ); ?></textarea><?php echo $validation->form_error('text'); ?></td> | ||
| 104 | </tr> | 125 | </tr> |
| 105 | <tr> | 126 | <tr> |
| 106 | <td>HTML Version (optional)</td> | 127 | <td>HTML Version (optional)</td> |
| 107 | <td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"><?php echo $validation->set_value('html');?></textarea><?php echo $validation->form_error('html');?></td> | 128 | <td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" |
| 129 | style="width:100%;"><?php echo $validation->set_value( | ||
| 130 | 'html' | ||
| 131 | ); ?></textarea><?php echo $validation->form_error('html'); ?></td> | ||
| 108 | </tr> | 132 | </tr> |
| 109 | <tr> | 133 | <tr> |
| 110 | <td width="150">Attachments</td> | 134 | <td width="150">Attachments</td> |
| 111 | <td><input type="file" name="attachment[]" /></td> | 135 | <td><input type="file" name="attachment[]"/></td> |
| 112 | </tr> | 136 | </tr> |
| 113 | <tr> | 137 | <tr> |
| 114 | <td> </td> | 138 | <td> </td> |
| 115 | <td><input type="file" name="attachment[]" /></td> | 139 | <td><input type="file" name="attachment[]"/></td> |
| 116 | </tr> | 140 | </tr> |
| 117 | <tr> | 141 | <tr> |
| 118 | <td> </td> | 142 | <td> </td> |
| 119 | <td><input type="file" name="attachment[]" /></td> | 143 | <td><input type="file" name="attachment[]"/></td> |
| 120 | </tr> | 144 | </tr> |
| 121 | </tbody> | 145 | </tbody> |
| 122 | </table> | 146 | </table> |
| 123 | 147 | ||
| 124 | <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> | 148 | <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;"> |
| 125 | <thead> | 149 | <thead> |
| 126 | <tr> | 150 | <tr> |
| ... | @@ -128,78 +152,83 @@ use Tz\WordPress\Tools; | ... | @@ -128,78 +152,83 @@ use Tz\WordPress\Tools; |
| 128 | <th class="action-bar"> </th> | 152 | <th class="action-bar"> </th> |
| 129 | </tr> | 153 | </tr> |
| 130 | </thead> | 154 | </thead> |
| 131 | <tbody style="<?php echo ($validation->set_value('system')=="") ? "display:none" : "";?>;"> | 155 | <tbody style="<?php echo ($validation->set_value('system') == "") ? "display:none" : ""; ?>;"> |
| 132 | <tr> | 156 | <tr> |
| 133 | <td>Message Type</td> | 157 | <td>Message Type</td> |
| 134 | <td> | 158 | <td> |
| 135 | <select name="system_message_type" class="wide-input-field"> | 159 | <select name="system_message_type" class="wide-input-field"> |
| 136 | <option value="none" <?php echo ($validation->set_value('system_message_type')=="none") ? 'selected="selected"' : "";?>>General Message</option> | 160 | <option value="none" <?php echo ($validation->set_value('system_message_type') == "none") |
| 137 | <option value="action_required" <?php echo ($validation->set_value('system_message_type')=="action_required") ? 'selected="selected"' : "";?>>Action Required</option> | 161 | ? 'selected="selected"' : ""; ?>>General Message |
| 138 | <option value="e-flash" <?php echo ($validation->set_value('system_message_type')=="e-flash") ? 'selected="selected"' : "";?>>E-Flash</option> | 162 | </option> |
| 139 | <option value="new_event" <?php echo ($validation->set_value('system_message_type')=="new_event") ? 'selected="selected"' : "";?>>New Event</option> | 163 | <option value="action_required" <?php echo ($validation->set_value( |
| 164 | 'system_message_type' | ||
| 165 | ) == "action_required") ? 'selected="selected"' : ""; ?>>Action Required | ||
| 166 | </option> | ||
| 167 | <option value="e-flash" <?php echo ($validation->set_value( | ||
| 168 | 'system_message_type' | ||
| 169 | ) == "e-flash") ? 'selected="selected"' : ""; ?>>E-Flash | ||
| 170 | </option> | ||
| 171 | <option value="new_event" <?php echo ($validation->set_value( | ||
| 172 | 'system_message_type' | ||
| 173 | ) == "new_event") ? 'selected="selected"' : ""; ?>>New Event | ||
| 174 | </option> | ||
| 140 | </select> | 175 | </select> |
| 141 | </td> | 176 | </td> |
| 142 | </tr> | 177 | </tr> |
| 143 | <tr> | 178 | <tr> |
| 144 | <td>Message (Text/HTML)</td> | 179 | <td>Message (Text/HTML)</td> |
| 145 | <td><textarea name="system" class="wide-input-field" rows="4" style="width:100%;" ><?php echo $validation->set_value('system');?></textarea><?php echo $validation->form_error('system');?></td> | 180 | <td><textarea name="system" class="wide-input-field" rows="4" |
| 181 | style="width:100%;"><?php echo $validation->set_value( | ||
| 182 | 'system' | ||
| 183 | ); ?></textarea><?php echo $validation->form_error('system'); ?></td> | ||
| 146 | </tr> | 184 | </tr> |
| 147 | </tbody> | 185 | </tbody> |
| 148 | </table> | 186 | </table> |
| 149 | 187 | ||
| 150 | 188 | ||
| 151 | |||
| 152 | |||
| 153 | <p> | 189 | <p> |
| 154 | <input type="submit" value=" Save " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" /> | 190 | <input type="submit" value=" Save "/> |
| 191 | <input type="button" value=" Cancel " | ||
| 192 | onclick="document.location.href='/wp-admin/admin.php?page=notifications';"/> | ||
| 155 | </p> | 193 | </p> |
| 156 | 194 | ||
| 157 | </form> | 195 | </form> |
| 158 | |||
| 159 | </div> | ||
| 160 | 196 | ||
| 161 | <script type="text/javascript"> | 197 | </div> |
| 162 | 198 | ||
| 199 | <script> | ||
| 200 | jQuery(document).ready(function () { | ||
| 201 | jQuery('#execute_date').datetimepicker({ | ||
| 202 | stepMinute: 30, | ||
| 203 | dateFormat: 'yy-mm-dd', | ||
| 204 | timeFormat: 'hh:mm:ss' | ||
| 205 | }); | ||
| 163 | 206 | ||
| 164 | jQuery(document).ready(function() { | 207 | updateNotificationType(); |
| 165 | 208 | ||
| 166 | $('#execute_date').datetimepicker({ | 209 | jQuery('table.expandable thead th').click(function () { |
| 167 | stepMinute: 30 | 210 | var $table = jQuery(this).parent().parent().parent(); |
| 168 | , dateFormat: 'yy-mm-dd' | 211 | if (jQuery('tbody', $table).is(':visible')) { |
| 169 | , timeFormat: 'hh:mm:ss' | 212 | jQuery('thead', $table).removeClass('open'); |
| 213 | jQuery('tbody', $table).fadeOut(); | ||
| 214 | } else { | ||
| 215 | jQuery('thead', $table).addClass('open'); | ||
| 216 | jQuery('tbody', $table).fadeIn(); | ||
| 217 | } | ||
| 218 | }); | ||
| 170 | }); | 219 | }); |
| 171 | 220 | ||
| 172 | updateNotificationType(); | 221 | function updateNotificationType() { |
| 173 | 222 | var type = jQuery('#notif_type').val(); | |
| 174 | //jQuery('table.expandable tbody').hide(); | 223 | |
| 175 | jQuery('table.expandable thead th').click(function() { | 224 | if (type == "triggered") { |
| 176 | var $table = jQuery(this).parent().parent().parent(); | 225 | jQuery('.scheduled-extended').hide(); |
| 177 | if ( jQuery('tbody',$table).is(":visible") ) { | 226 | jQuery('.scheduled_sendto').hide(); |
| 178 | jQuery('thead',$table).removeClass("open"); | 227 | jQuery('.trigger-extended').show(); |
| 179 | jQuery('tbody',$table).fadeOut(); | ||
| 180 | } else { | 228 | } else { |
| 181 | jQuery('thead',$table).addClass("open"); | 229 | jQuery('.scheduled-extended').show(); |
| 182 | jQuery('tbody',$table).fadeIn(); | 230 | jQuery('.trigger-extended').hide(); |
| 231 | jQuery('.scheduled_sendto').show(); | ||
| 183 | } | 232 | } |
| 184 | }); | ||
| 185 | |||
| 186 | }); | ||
| 187 | |||
| 188 | function updateNotificationType() { | ||
| 189 | var type = jQuery('#notif_type').val(); | ||
| 190 | |||
| 191 | if (type=="triggered") { | ||
| 192 | jQuery('.scheduled-extended').hide(); | ||
| 193 | jQuery('.scheduled_sendto').hide(); | ||
| 194 | jQuery('.trigger-extended').show(); | ||
| 195 | } else { | ||
| 196 | jQuery('.scheduled-extended').show(); | ||
| 197 | jQuery('.trigger-extended').hide(); | ||
| 198 | jQuery('.scheduled_sendto').show(); | ||
| 199 | } | 233 | } |
| 200 | |||
| 201 | } | ||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | </script> | 234 | </script> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -6,7 +6,7 @@ use Tz\WordPress\Tools\Notifications\Settings; | ... | @@ -6,7 +6,7 @@ use Tz\WordPress\Tools\Notifications\Settings; |
| 6 | 6 | ||
| 7 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/> | 7 | <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/> |
| 8 | 8 | ||
| 9 | <div id="" class="wrap"> | 9 | <div class="wrap"> |
| 10 | <h2>Notifications - Edit</h2> | 10 | <h2>Notifications - Edit</h2> |
| 11 | 11 | ||
| 12 | <?php if (isset($flash) && $flash != ''): ?> | 12 | <?php if (isset($flash) && $flash != ''): ?> | ... | ... |
-
Please register or sign in to post a comment