1b9bd638 by Kevin Burton

updates - not complete!

1 parent 3e2f7761
...@@ -5,6 +5,7 @@ error_reporting(E_ALL^E_DEPRECATED); ...@@ -5,6 +5,7 @@ error_reporting(E_ALL^E_DEPRECATED);
5 use Tz\WordPress\Tools; 5 use Tz\WordPress\Tools;
6 use Tz\Common; 6 use Tz\Common;
7 use Tz\WordPress\Tools\Notifications; 7 use Tz\WordPress\Tools\Notifications;
8 use Tz\WordPress\Tools\Notifications\Validation;
8 9
9 const CAPABILITY = "manage_notifications"; 10 const CAPABILITY = "manage_notifications";
10 const MANAGE_SYSTEM_NOTIFICATIONS = "create_system_notifications"; 11 const MANAGE_SYSTEM_NOTIFICATIONS = "create_system_notifications";
...@@ -21,7 +22,106 @@ function display_page() { ...@@ -21,7 +22,106 @@ function display_page() {
21 22
22 23
23 if (isset($_GET['action']) && $_GET['action']=="edit") { 24 if (isset($_GET['action']) && $_GET['action']=="edit") {
24 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'edit.php'); 25 global $wpdb;
26
27 $entry = get_post($_GET['page_id']);
28
29 $id = $entry->ID;
30
31 $details = get_post_meta($id,'details',true);
32 $email = get_post_meta($id,'email',true);
33 $system = get_post_meta($id,'system',true);
34 $sms = get_post_meta($id,'sms',true);
35
36 $entry->details = $details;
37 $entry->email = $email;
38 $entry->system = $system;
39 $entry->sms = $sms;
40
41
42
43
44 // here
45 $validation = new Notifications\Validation;
46
47 $validation->set_rules('type','Notification Type','required');
48 $validation->set_rules('title','Description','trim|required|min_length[16]');
49 $validation->set_rules('type','Notification Type','required');
50 $validation->set_rules('sendto','Send To','required');
51
52 $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
53 $validation->set_rules('execute_date','Execute Date', $type_val);
54
55 $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
56 $validation->set_rules('trigger','Trigger',$trigger_val);
57
58 $validation->set_rules('subject','Subject','trim');
59 $validation->set_rules('text','Text Version','trim|min_length[16]');
60 $validation->set_rules('html','HTML Version','trim|min_length[16]');
61
62 $validation->set_rules('system','System Message','trim|min_length[16]');
63 $validation->set_rules('sms','SMS Message','trim|min_length[16]');
64
65 //details
66 if ($validation->run() == TRUE) {
67
68 $type = $_POST['type'];
69 $title = $_POST['title'];
70 $sendto = $_POST['sendto'];
71 $execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
72 $trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
73
74 // email
75 $subject = $_POST['subject'];
76 $text = $_POST['text'];
77 $html = $_POST['html'];
78 $attachments = array();
79 $upload_dir = __DIR__ . "/uploads/";
80 fixFilesArray($_FILES['attachment']);
81 foreach ($_FILES['attachment'] as $position => $file) {
82 // should output array with indices name, type, tmp_name, error, size
83 if($file['name'] != "") {
84 move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
85 $attachments[] = $file['name'];
86 }
87 }
88
89 // system
90 $system = $_POST['system'];
91
92 // SMS
93 $sms = $_POST['sms'];
94
95 update_post_meta($id, "details", array(
96 'type' => $type
97 , 'sendto' => $sendto
98 , 'status' => $entry->details['status']
99 , 'trigger' => $trigger
100 , 'execute_date' => $execute_date
101 ));
102
103 update_post_meta($id, "email", array(
104 'subject' => $subject
105 , 'text' => $text
106 , 'html' => $html
107 , 'attachments' => $attachments
108 ));
109 update_post_meta($id, "system", $system);
110 update_post_meta($id, "sms", $sms);
111
112 $update = array();
113 $update['ID'] = $id;
114 $update['post_title'] = $title;
115 wp_update_post($update);
116
117
118 $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
119 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
120 } else {
121 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
122 }
123
124
25 125
26 } else { 126 } else {
27 127
...@@ -131,12 +231,27 @@ function fixFilesArray(&$files) ...@@ -131,12 +231,27 @@ function fixFilesArray(&$files)
131 } 231 }
132 } 232 }
133 233
134 function create_trigger_notification() {
135 print "hello";
136 }
137 234
138 function notification_settings() { 235 function notification_settings() {
139 print "settings"; 236
237 global $wpdb;
238 $validation = new Notifications\Validation;
239 $validation->set_rules('company','Company','required|trim');
240 $validation->set_rules('address','Address','required|trim');
241 $validation->set_rules('address2','Apt/Unit/Suite','required|trim');
242 $validation->set_rules('city','City','required|trim');
243 $validation->set_rules('province','Province','required|trim');
244 $validation->set_rules('postal','POstal Code','required|trim');
245 $validation->set_rules('std_message','Standard Message','required|trim');
246 $validation->set_rules('opt_message','OPT-OUT Message','required|trim');
247
248 if ($validation->run() == TRUE) {
249 } else {
250 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php');
251 }
252
253
254
140 } 255 }
141 256
142 function create_notification() { 257 function create_notification() {
...@@ -144,7 +259,33 @@ function create_notification() { ...@@ -144,7 +259,33 @@ function create_notification() {
144 global $wpdb; 259 global $wpdb;
145 260
146 261
147 if ($_POST && isset($_POST['_POSTED_']) && $_POST['_POSTED_']=="yes") { 262 // here
263 $validation = new Notifications\Validation;
264
265 $validation->set_rules('type','Notification Type','required');
266 $validation->set_rules('title','Description','trim|required|min_length[16]');
267 $validation->set_rules('type','Notification Type','required');
268 $validation->set_rules('sendto','Send To','required');
269
270 $type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
271 $validation->set_rules('execute_date','Execute Date', $type_val);
272
273 $trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
274 $validation->set_rules('trigger','Trigger',$trigger_val);
275
276 $validation->set_rules('subject','Subject','trim');
277 $validation->set_rules('text','Text Version','trim|min_length[16]');
278 $validation->set_rules('html','HTML Version','trim|min_length[16]');
279
280 $validation->set_rules('system','System Message','trim|min_length[16]');
281 $validation->set_rules('sms','SMS Message','trim|min_length[16]');
282
283
284 if ($_POST && (($_POST['subject']=="" || $_POST['text']) && $_POST['sms']=="" && $_POST['system']=="")) {
285 $form_error = true;
286 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
287 } else {
288 if ($validation->run() == TRUE) {
148 289
149 // ok, so now we need to create the notification. 290 // ok, so now we need to create the notification.
150 class postTemplate { 291 class postTemplate {
...@@ -211,12 +352,13 @@ function create_notification() { ...@@ -211,12 +352,13 @@ function create_notification() {
211 add_post_meta($id, "sms", $sms); 352 add_post_meta($id, "sms", $sms);
212 353
213 354
214 $flash = "Notification Saved Successfully!"; 355 $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
215 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php'); 356 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
216 357
217 } else { 358 } else {
218 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php'); 359 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
219 } 360 }
361 }
220 362
221 363
222 } 364 }
...@@ -240,7 +382,7 @@ class Actions { ...@@ -240,7 +382,7 @@ class Actions {
240 public static function admin_menu() { 382 public static function admin_menu() {
241 add_menu_page('Notifications','Notifications',CAPABILITY,'notifications',__NAMESPACE__ . '\display_page' ); 383 add_menu_page('Notifications','Notifications',CAPABILITY,'notifications',__NAMESPACE__ . '\display_page' );
242 add_submenu_page('notifications','New Notification', 'New Notification',CAPABILITY,'notifications-create-new',__NAMESPACE__ . '\create_notification'); 384 add_submenu_page('notifications','New Notification', 'New Notification',CAPABILITY,'notifications-create-new',__NAMESPACE__ . '\create_notification');
243 add_submenu_page('notifications','Settings', 'Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings'); 385 add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
244 } 386 }
245 387
246 public function admin_init() { 388 public function admin_init() {
......
...@@ -10,6 +10,7 @@ const OPTION_NAME = "notif_options"; ...@@ -10,6 +10,7 @@ const OPTION_NAME = "notif_options";
10 call_user_func(function() { 10 call_user_func(function() {
11 Vars::$options = new Tools\WP_Option(OPTION_NAME); 11 Vars::$options = new Tools\WP_Option(OPTION_NAME);
12 if (is_admin()) { 12 if (is_admin()) {
13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Validation.php');
13 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Admin.php'); 14 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Admin.php');
14 } 15 }
15 }); 16 });
......
1 <?php
2 namespace Tz\WordPress\Tools\Notifications;
3 error_reporting(E_ALL^E_DEPRECATED);
4
5 use Tz\WordPress\Tools;
6 use Tz\Common;
7 use Tz\WordPress\Tools\Notifications;
8
9
10 class Validation {
11
12 protected $_field_data = array();
13 protected $_config_rules = array();
14 protected $_error_array = array();
15 protected $_error_messages = array();
16 protected $_error_prefix = '<div class="lblError">';
17 protected $_error_suffix = '</div>';
18 protected $error_string = '';
19 protected $_safe_form_data = FALSE;
20
21 function __construct($rules = array())
22 {
23 // Validation rules can be stored in a config file.
24 $this->_config_rules = $rules;
25 }
26
27 public function get_error_message($key) {
28 $lang = array();
29 $lang['required'] = "The %s field is required.";
30 $lang['isset'] = "The %s field must have a value.";
31 $lang['valid_email'] = "The %s field must contain a valid email address.";
32 $lang['valid_emails'] = "The %s field must contain all valid email addresses.";
33 $lang['valid_url'] = "The %s field must contain a valid URL.";
34 $lang['valid_ip'] = "The %s field must contain a valid IP.";
35 $lang['min_length'] = "The %s field must be at least %s characters in length.";
36 $lang['max_length'] = "The %s field can not exceed %s characters in length.";
37 $lang['exact_length'] = "The %s field must be exactly %s characters in length.";
38 $lang['alpha'] = "The %s field may only contain alphabetical characters.";
39 $lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters.";
40 $lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes.";
41 $lang['numeric'] = "The %s field must contain only numbers.";
42 $lang['is_numeric'] = "The %s field must contain only numeric characters.";
43 $lang['integer'] = "The %s field must contain an integer.";
44 $lang['matches'] = "The %s field does not match the %s field.";
45 $lang['is_natural'] = "The %s field must contain only positive numbers.";
46 $lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
47
48
49 if (isset($lang[$key])) {
50 return $lang[$key];
51 } else {
52 return FALSE;
53 }
54
55 }
56
57
58 // --------------------------------------------------------------------
59
60 /**
61 * Set Rules
62 *
63 * This function takes an array of field names and validation
64 * rules as input, validates the info, and stores it
65 *
66 * @access public
67 * @param mixed
68 * @param string
69 * @return void
70 */
71 function set_rules($field, $label = '', $rules = '')
72 {
73 // No reason to set rules if we have no POST data
74 if (count($_POST) == 0)
75 {
76 return;
77 }
78
79 // If an array was passed via the first parameter instead of indidual string
80 // values we cycle through it and recursively call this function.
81 if (is_array($field))
82 {
83 foreach ($field as $row)
84 {
85 // Houston, we have a problem...
86 if ( ! isset($row['field']) OR ! isset($row['rules']))
87 {
88 continue;
89 }
90
91 // If the field label wasn't passed we use the field name
92 $label = ( ! isset($row['label'])) ? $row['field'] : $row['label'];
93
94 // Here we go!
95 $this->set_rules($row['field'], $label, $row['rules']);
96 }
97 return;
98 }
99
100 // No fields? Nothing to do...
101 if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
102 {
103 return;
104 }
105
106 // If the field label wasn't passed we use the field name
107 $label = ($label == '') ? $field : $label;
108
109 // Is the field name an array? We test for the existence of a bracket "[" in
110 // the field name to determine this. If it is an array, we break it apart
111 // into its components so that we can fetch the corresponding POST data later
112 if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches))
113 {
114 // Note: Due to a bug in current() that affects some versions
115 // of PHP we can not pass function call directly into it
116 $x = explode('[', $field);
117 $indexes[] = current($x);
118
119 for ($i = 0; $i < count($matches['0']); $i++)
120 {
121 if ($matches['1'][$i] != '')
122 {
123 $indexes[] = $matches['1'][$i];
124 }
125 }
126
127 $is_array = TRUE;
128 }
129 else
130 {
131 $indexes = array();
132 $is_array = FALSE;
133 }
134
135 // Build our master array
136 $this->_field_data[$field] = array(
137 'field' => $field,
138 'label' => $label,
139 'rules' => $rules,
140 'is_array' => $is_array,
141 'keys' => $indexes,
142 'postdata' => NULL,
143 'error' => ''
144 );
145 }
146
147 // --------------------------------------------------------------------
148
149 /**
150 * Set Error Message
151 *
152 * Lets users set their own error messages on the fly. Note: The key
153 * name has to match the function name that it corresponds to.
154 *
155 * @access public
156 * @param string
157 * @param string
158 * @return string
159 */
160 function set_message($lang, $val = '')
161 {
162 if ( ! is_array($lang))
163 {
164 $lang = array($lang => $val);
165 }
166
167 $this->_error_messages = array_merge($this->_error_messages, $lang);
168 }
169
170 // --------------------------------------------------------------------
171
172 /**
173 * Set The Error Delimiter
174 *
175 * Permits a prefix/suffix to be added to each error message
176 *
177 * @access public
178 * @param string
179 * @param string
180 * @return void
181 */
182 function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
183 {
184 $this->_error_prefix = $prefix;
185 $this->_error_suffix = $suffix;
186 }
187
188 // --------------------------------------------------------------------
189
190 /**
191 * Get Error Message
192 *
193 * Gets the error message associated with a particular field
194 *
195 * @access public
196 * @param string the field name
197 * @return void
198 */
199 function error($field = '', $prefix = '', $suffix = '')
200 {
201 if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '')
202 {
203 return '';
204 }
205
206 if ($prefix == '')
207 {
208 $prefix = $this->_error_prefix;
209 }
210
211 if ($suffix == '')
212 {
213 $suffix = $this->_error_suffix;
214 }
215
216 return $prefix.$this->_field_data[$field]['error'].$suffix;
217 }
218
219 // --------------------------------------------------------------------
220
221 /**
222 * Error String
223 *
224 * Returns the error messages as a string, wrapped in the error delimiters
225 *
226 * @access public
227 * @param string
228 * @param string
229 * @return str
230 */
231 function error_string($prefix = '', $suffix = '')
232 {
233 // No errrors, validation passes!
234 if (count($this->_error_array) === 0)
235 {
236 return '';
237 }
238
239 if ($prefix == '')
240 {
241 $prefix = $this->_error_prefix;
242 }
243
244 if ($suffix == '')
245 {
246 $suffix = $this->_error_suffix;
247 }
248
249 // Generate the error string
250 $str = '';
251 foreach ($this->_error_array as $val)
252 {
253 if ($val != '')
254 {
255 $str .= $prefix.$val.$suffix."\n";
256 }
257 }
258
259 return $str;
260 }
261
262 // --------------------------------------------------------------------
263
264 /**
265 * Run the Validator
266 *
267 * This function does all the work.
268 *
269 * @access public
270 * @return bool
271 */
272 function run($group = '')
273 {
274 // Do we even have any data to process? Mm?
275 if (count($_POST) == 0)
276 {
277 return FALSE;
278 }
279
280 // Does the _field_data array containing the validation rules exist?
281 // If not, we look to see if they were assigned via a config file
282 if (count($this->_field_data) == 0)
283 {
284 // No validation rules? We're done...
285 if (count($this->_config_rules) == 0)
286 {
287 return FALSE;
288 }
289
290 // Is there a validation rule for the particular URI being accessed?
291 $uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
292
293 if ($uri != '' AND isset($this->_config_rules[$uri]))
294 {
295 $this->set_rules($this->_config_rules[$uri]);
296 }
297 else
298 {
299 $this->set_rules($this->_config_rules);
300 }
301
302 // We're we able to set the rules correctly?
303 if (count($this->_field_data) == 0)
304 {
305 return FALSE;
306 }
307 }
308
309 // Cycle through the rules for each field, match the
310 // corresponding $_POST item and test for errors
311 foreach ($this->_field_data as $field => $row)
312 {
313 // Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
314 // Depending on whether the field name is an array or a string will determine where we get it from.
315
316 if ($row['is_array'] == TRUE)
317 {
318 $this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
319 }
320 else
321 {
322 if (isset($_POST[$field]) AND $_POST[$field] != "")
323 {
324 $this->_field_data[$field]['postdata'] = $_POST[$field];
325 }
326 }
327
328 $this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
329 }
330
331 // Did we end up with any errors?
332 $total_errors = count($this->_error_array);
333
334 if ($total_errors > 0)
335 {
336 $this->_safe_form_data = TRUE;
337 }
338
339 // Now we need to re-set the POST data with the new, processed data
340 $this->_reset_post_array();
341
342 // No errors, validation passes!
343 if ($total_errors == 0)
344 {
345 return TRUE;
346 }
347
348 // Validation fails
349 return FALSE;
350 }
351
352 // --------------------------------------------------------------------
353
354 /**
355 * Traverse a multidimensional $_POST array index until the data is found
356 *
357 * @access private
358 * @param array
359 * @param array
360 * @param integer
361 * @return mixed
362 */
363 function _reduce_array($array, $keys, $i = 0)
364 {
365 if (is_array($array))
366 {
367 if (isset($keys[$i]))
368 {
369 if (isset($array[$keys[$i]]))
370 {
371 $array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1));
372 }
373 else
374 {
375 return NULL;
376 }
377 }
378 else
379 {
380 return $array;
381 }
382 }
383
384 return $array;
385 }
386
387 // --------------------------------------------------------------------
388
389 /**
390 * Re-populate the _POST array with our finalized and processed data
391 *
392 * @access private
393 * @return null
394 */
395 function _reset_post_array()
396 {
397 foreach ($this->_field_data as $field => $row)
398 {
399 if ( ! is_null($row['postdata']))
400 {
401 if ($row['is_array'] == FALSE)
402 {
403 if (isset($_POST[$row['field']]))
404 {
405 $_POST[$row['field']] = $this->prep_for_form($row['postdata']);
406 }
407 }
408 else
409 {
410 // start with a reference
411 $post_ref =& $_POST;
412
413 // before we assign values, make a reference to the right POST key
414 if (count($row['keys']) == 1)
415 {
416 $post_ref =& $post_ref[current($row['keys'])];
417 }
418 else
419 {
420 foreach ($row['keys'] as $val)
421 {
422 $post_ref =& $post_ref[$val];
423 }
424 }
425
426 if (is_array($row['postdata']))
427 {
428 $array = array();
429 foreach ($row['postdata'] as $k => $v)
430 {
431 $array[$k] = $this->prep_for_form($v);
432 }
433
434 $post_ref = $array;
435 }
436 else
437 {
438 $post_ref = $this->prep_for_form($row['postdata']);
439 }
440 }
441 }
442 }
443 }
444
445 // --------------------------------------------------------------------
446
447 /**
448 * Executes the Validation routines
449 *
450 * @access private
451 * @param array
452 * @param array
453 * @param mixed
454 * @param integer
455 * @return mixed
456 */
457 function _execute($row, $rules, $postdata = NULL, $cycles = 0)
458 {
459 // If the $_POST data is an array we will run a recursive call
460 if (is_array($postdata))
461 {
462 foreach ($postdata as $key => $val)
463 {
464 $this->_execute($row, $rules, $val, $cycles);
465 $cycles++;
466 }
467
468 return;
469 }
470
471 // --------------------------------------------------------------------
472
473 // If the field is blank, but NOT required, no further tests are necessary
474 $callback = FALSE;
475 if ( ! in_array('required', $rules) AND is_null($postdata))
476 {
477 // Before we bail out, does the rule contain a callback?
478 if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
479 {
480 $callback = TRUE;
481 $rules = (array('1' => $match[1]));
482 }
483 else
484 {
485 return;
486 }
487 }
488
489 // --------------------------------------------------------------------
490
491 // Isset Test. Typically this rule will only apply to checkboxes.
492 if (is_null($postdata) AND $callback == FALSE)
493 {
494 if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
495 {
496 // Set the message type
497 $type = (in_array('required', $rules)) ? 'required' : 'isset';
498
499 if ( ! isset($this->_error_messages[$type]))
500 {
501 if (FALSE === ($line = $this->get_error_message($type)))
502 {
503 $line = 'The field was not set';
504 }
505 }
506 else
507 {
508 $line = $this->_error_messages[$type];
509 }
510
511 // Build the error message
512 $message = sprintf($line, $this->_translate_fieldname($row['label']));
513
514 // Save the error message
515 $this->_field_data[$row['field']]['error'] = $message;
516
517 if ( ! isset($this->_error_array[$row['field']]))
518 {
519 $this->_error_array[$row['field']] = $message;
520 }
521 }
522
523 return;
524 }
525
526 // --------------------------------------------------------------------
527
528 // Cycle through each rule and run it
529 foreach ($rules As $rule)
530 {
531 $_in_array = FALSE;
532
533 // We set the $postdata variable with the current data in our master array so that
534 // each cycle of the loop is dealing with the processed data from the last cycle
535 if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata']))
536 {
537 // We shouldn't need this safety, but just in case there isn't an array index
538 // associated with this cycle we'll bail out
539 if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles]))
540 {
541 continue;
542 }
543
544 $postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
545 $_in_array = TRUE;
546 }
547 else
548 {
549 $postdata = $this->_field_data[$row['field']]['postdata'];
550 }
551
552 // --------------------------------------------------------------------
553
554 // Is the rule a callback?
555 $callback = FALSE;
556 if (substr($rule, 0, 9) == 'callback_')
557 {
558 $rule = substr($rule, 9);
559 $callback = TRUE;
560 }
561
562 // Strip the parameter (if exists) from the rule
563 // Rules can contain a parameter: max_length[5]
564 $param = FALSE;
565 if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match))
566 {
567 $rule = $match[1];
568 $param = $match[2];
569 }
570
571 // Call the function that corresponds to the rule
572 if ($callback === TRUE)
573 {
574 if ( ! method_exists($this->CI, $rule))
575 {
576 continue;
577 }
578
579 // Run the function and grab the result
580 $result = $this->CI->$rule($postdata, $param);
581
582 // Re-assign the result to the master data array
583 if ($_in_array == TRUE)
584 {
585 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
586 }
587 else
588 {
589 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
590 }
591
592 // If the field isn't required and we just processed a callback we'll move on...
593 if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE)
594 {
595 continue;
596 }
597 }
598 else
599 {
600 if ( ! method_exists($this, $rule))
601 {
602 // If our own wrapper function doesn't exist we see if a native PHP function does.
603 // Users can use any native PHP function call that has one param.
604 if (function_exists($rule))
605 {
606 $result = $rule($postdata);
607
608 if ($_in_array == TRUE)
609 {
610 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
611 }
612 else
613 {
614 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
615 }
616 }
617
618 continue;
619 }
620
621 $result = $this->$rule($postdata, $param);
622
623 if ($_in_array == TRUE)
624 {
625 $this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
626 }
627 else
628 {
629 $this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
630 }
631 }
632
633 // Did the rule test negatively? If so, grab the error.
634 if ($result === FALSE)
635 {
636 if ( ! isset($this->_error_messages[$rule]))
637 {
638 if (FALSE === ($line = $this->get_error_message($rule)))
639 {
640 $line = 'Unable to access an error message corresponding to your field name.';
641 }
642 }
643 else
644 {
645 $line = $this->_error_messages[$rule];
646 }
647
648 // Is the parameter we are inserting into the error message the name
649 // of another field? If so we need to grab its "field label"
650 if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label']))
651 {
652 $param = $this->_field_data[$param]['label'];
653 }
654
655 // Build the error message
656 $message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
657
658 // Save the error message
659 $this->_field_data[$row['field']]['error'] = $message;
660
661 if ( ! isset($this->_error_array[$row['field']]))
662 {
663 $this->_error_array[$row['field']] = $message;
664 }
665
666 return;
667 }
668 }
669 }
670
671 function form_error($field = '', $prefix = '', $suffix = '')
672 {
673
674
675 return $this->error($field, $prefix, $suffix);
676 }
677
678 function validation_errors($prefix = '', $suffix = '')
679 {
680 return $this->error_string($prefix, $suffix);
681 }
682
683 // --------------------------------------------------------------------
684
685 /**
686 * Translate a field name
687 *
688 * @access private
689 * @param string the field name
690 * @return string
691 */
692 function _translate_fieldname($fieldname)
693 {
694 // Do we need to translate the field name?
695 // We look for the prefix lang: to determine this
696 if (substr($fieldname, 0, 5) == 'lang:')
697 {
698 // Grab the variable
699 $line = substr($fieldname, 5);
700
701 // Were we able to translate the field name? If not we use $line
702 if (FALSE === ($fieldname = $this->get_error_message($line)))
703 {
704 return $line;
705 }
706 }
707
708 return $fieldname;
709 }
710
711 // --------------------------------------------------------------------
712
713 /**
714 * Get the value from a form
715 *
716 * Permits you to repopulate a form field with the value it was submitted
717 * with, or, if that value doesn't exist, with the default
718 *
719 * @access public
720 * @param string the field name
721 * @param string
722 * @return void
723 */
724 function set_value($field = '', $default = '')
725 {
726 if ( ! isset($this->_field_data[$field]))
727 {
728 return $default;
729 }
730
731 return $this->_field_data[$field]['postdata'];
732 }
733
734 // --------------------------------------------------------------------
735
736 /**
737 * Set Select
738 *
739 * Enables pull-down lists to be set to the value the user
740 * selected in the event of an error
741 *
742 * @access public
743 * @param string
744 * @param string
745 * @return string
746 */
747 function set_select($field = '', $value = '', $default = FALSE)
748 {
749 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
750 {
751 if ($default === TRUE AND count($this->_field_data) === 0)
752 {
753 return ' selected="selected"';
754 }
755 return '';
756 }
757
758 $field = $this->_field_data[$field]['postdata'];
759
760 if (is_array($field))
761 {
762 if ( ! in_array($value, $field))
763 {
764 return '';
765 }
766 }
767 else
768 {
769 if (($field == '' OR $value == '') OR ($field != $value))
770 {
771 return '';
772 }
773 }
774
775 return ' selected="selected"';
776 }
777
778 // --------------------------------------------------------------------
779
780 /**
781 * Set Radio
782 *
783 * Enables radio buttons to be set to the value the user
784 * selected in the event of an error
785 *
786 * @access public
787 * @param string
788 * @param string
789 * @return string
790 */
791 function set_radio($field = '', $value = '', $default = FALSE)
792 {
793 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
794 {
795 if ($default === TRUE AND count($this->_field_data) === 0)
796 {
797 return ' checked="checked"';
798 }
799 return '';
800 }
801
802 $field = $this->_field_data[$field]['postdata'];
803
804 if (is_array($field))
805 {
806 if ( ! in_array($value, $field))
807 {
808 return '';
809 }
810 }
811 else
812 {
813 if (($field == '' OR $value == '') OR ($field != $value))
814 {
815 return '';
816 }
817 }
818
819 return ' checked="checked"';
820 }
821
822 // --------------------------------------------------------------------
823
824 /**
825 * Set Checkbox
826 *
827 * Enables checkboxes to be set to the value the user
828 * selected in the event of an error
829 *
830 * @access public
831 * @param string
832 * @param string
833 * @return string
834 */
835 function set_checkbox($field = '', $value = '', $default = FALSE)
836 {
837 if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
838 {
839 if ($default === TRUE AND count($this->_field_data) === 0)
840 {
841 return ' checked="checked"';
842 }
843 return '';
844 }
845
846 $field = $this->_field_data[$field]['postdata'];
847
848 if (is_array($field))
849 {
850 if ( ! in_array($value, $field))
851 {
852 return '';
853 }
854 }
855 else
856 {
857 if (($field == '' OR $value == '') OR ($field != $value))
858 {
859 return '';
860 }
861 }
862
863 return ' checked="checked"';
864 }
865
866 // --------------------------------------------------------------------
867
868 /**
869 * Required
870 *
871 * @access public
872 * @param string
873 * @return bool
874 */
875 function required($str)
876 {
877 if ( ! is_array($str))
878 {
879 return (trim($str) == '') ? FALSE : TRUE;
880 }
881 else
882 {
883 return ( ! empty($str));
884 }
885 }
886
887 // --------------------------------------------------------------------
888
889 /**
890 * Match one field to another
891 *
892 * @access public
893 * @param string
894 * @param field
895 * @return bool
896 */
897 function matches($str, $field)
898 {
899 if ( ! isset($_POST[$field]))
900 {
901 return FALSE;
902 }
903
904 $field = $_POST[$field];
905
906 return ($str !== $field) ? FALSE : TRUE;
907 }
908
909 // --------------------------------------------------------------------
910
911 /**
912 * Minimum Length
913 *
914 * @access public
915 * @param string
916 * @param value
917 * @return bool
918 */
919 function min_length($str, $val)
920 {
921 if (preg_match("/[^0-9]/", $val))
922 {
923 return FALSE;
924 }
925
926 if (function_exists('mb_strlen'))
927 {
928 return (mb_strlen($str) < $val) ? FALSE : TRUE;
929 }
930
931 return (strlen($str) < $val) ? FALSE : TRUE;
932 }
933
934 // --------------------------------------------------------------------
935
936 /**
937 * Max Length
938 *
939 * @access public
940 * @param string
941 * @param value
942 * @return bool
943 */
944 function max_length($str, $val)
945 {
946 if (preg_match("/[^0-9]/", $val))
947 {
948 return FALSE;
949 }
950
951 if (function_exists('mb_strlen'))
952 {
953 return (mb_strlen($str) > $val) ? FALSE : TRUE;
954 }
955
956 return (strlen($str) > $val) ? FALSE : TRUE;
957 }
958
959 // --------------------------------------------------------------------
960
961 /**
962 * Exact Length
963 *
964 * @access public
965 * @param string
966 * @param value
967 * @return bool
968 */
969 function exact_length($str, $val)
970 {
971 if (preg_match("/[^0-9]/", $val))
972 {
973 return FALSE;
974 }
975
976 if (function_exists('mb_strlen'))
977 {
978 return (mb_strlen($str) != $val) ? FALSE : TRUE;
979 }
980
981 return (strlen($str) != $val) ? FALSE : TRUE;
982 }
983
984 // --------------------------------------------------------------------
985
986 /**
987 * Valid Email
988 *
989 * @access public
990 * @param string
991 * @return bool
992 */
993 function valid_email($str)
994 {
995 return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
996 }
997
998 // --------------------------------------------------------------------
999
1000 /**
1001 * Valid Emails
1002 *
1003 * @access public
1004 * @param string
1005 * @return bool
1006 */
1007 function valid_emails($str)
1008 {
1009 if (strpos($str, ',') === FALSE)
1010 {
1011 return $this->valid_email(trim($str));
1012 }
1013
1014 foreach(explode(',', $str) as $email)
1015 {
1016 if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE)
1017 {
1018 return FALSE;
1019 }
1020 }
1021
1022 return TRUE;
1023 }
1024
1025 // --------------------------------------------------------------------
1026
1027 /**
1028 * Validate IP Address
1029 *
1030 * @access public
1031 * @param string
1032 * @return string
1033 */
1034 function valid_ip($ip)
1035 {
1036 return $this->CI->input->valid_ip($ip);
1037 }
1038
1039 // --------------------------------------------------------------------
1040
1041 /**
1042 * Alpha
1043 *
1044 * @access public
1045 * @param string
1046 * @return bool
1047 */
1048 function alpha($str)
1049 {
1050 return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
1051 }
1052
1053 // --------------------------------------------------------------------
1054
1055 /**
1056 * Alpha-numeric
1057 *
1058 * @access public
1059 * @param string
1060 * @return bool
1061 */
1062 function alpha_numeric($str)
1063 {
1064 return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;
1065 }
1066
1067 // --------------------------------------------------------------------
1068
1069 /**
1070 * Alpha-numeric with underscores and dashes
1071 *
1072 * @access public
1073 * @param string
1074 * @return bool
1075 */
1076 function alpha_dash($str)
1077 {
1078 return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
1079 }
1080
1081 // --------------------------------------------------------------------
1082
1083 /**
1084 * Numeric
1085 *
1086 * @access public
1087 * @param string
1088 * @return bool
1089 */
1090 function numeric($str)
1091 {
1092 return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
1093
1094 }
1095
1096 // --------------------------------------------------------------------
1097
1098 /**
1099 * Is Numeric
1100 *
1101 * @access public
1102 * @param string
1103 * @return bool
1104 */
1105 function is_numeric($str)
1106 {
1107 return ( ! is_numeric($str)) ? FALSE : TRUE;
1108 }
1109
1110 // --------------------------------------------------------------------
1111
1112 /**
1113 * Integer
1114 *
1115 * @access public
1116 * @param string
1117 * @return bool
1118 */
1119 function integer($str)
1120 {
1121 return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);
1122 }
1123
1124 // --------------------------------------------------------------------
1125
1126 /**
1127 * Is a Natural number (0,1,2,3, etc.)
1128 *
1129 * @access public
1130 * @param string
1131 * @return bool
1132 */
1133 function is_natural($str)
1134 {
1135 return (bool)preg_match( '/^[0-9]+$/', $str);
1136 }
1137
1138 // --------------------------------------------------------------------
1139
1140 /**
1141 * Is a Natural number, but not a zero (1,2,3, etc.)
1142 *
1143 * @access public
1144 * @param string
1145 * @return bool
1146 */
1147 function is_natural_no_zero($str)
1148 {
1149 if ( ! preg_match( '/^[0-9]+$/', $str))
1150 {
1151 return FALSE;
1152 }
1153
1154 if ($str == 0)
1155 {
1156 return FALSE;
1157 }
1158
1159 return TRUE;
1160 }
1161
1162 // --------------------------------------------------------------------
1163
1164 /**
1165 * Valid Base64
1166 *
1167 * Tests a string for characters outside of the Base64 alphabet
1168 * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
1169 *
1170 * @access public
1171 * @param string
1172 * @return bool
1173 */
1174 function valid_base64($str)
1175 {
1176 return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
1177 }
1178
1179 // --------------------------------------------------------------------
1180
1181 /**
1182 * Prep data for form
1183 *
1184 * This function allows HTML to be safely shown in a form.
1185 * Special characters are converted.
1186 *
1187 * @access public
1188 * @param string
1189 * @return string
1190 */
1191 function prep_for_form($data = '')
1192 {
1193 if (is_array($data))
1194 {
1195 foreach ($data as $key => $val)
1196 {
1197 $data[$key] = $this->prep_for_form($val);
1198 }
1199
1200 return $data;
1201 }
1202
1203 if ($this->_safe_form_data == FALSE OR $data === '')
1204 {
1205 return $data;
1206 }
1207
1208 return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));
1209 }
1210
1211 // --------------------------------------------------------------------
1212
1213 /**
1214 * Prep URL
1215 *
1216 * @access public
1217 * @param string
1218 * @return string
1219 */
1220 function prep_url($str = '')
1221 {
1222 if ($str == 'http://' OR $str == '')
1223 {
1224 return '';
1225 }
1226
1227 if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
1228 {
1229 $str = 'http://'.$str;
1230 }
1231
1232 return $str;
1233 }
1234
1235 // --------------------------------------------------------------------
1236
1237 /**
1238 * Strip Image Tags
1239 *
1240 * @access public
1241 * @param string
1242 * @return string
1243 */
1244 function strip_image_tags($str)
1245 {
1246 return $this->CI->input->strip_image_tags($str);
1247 }
1248
1249 // --------------------------------------------------------------------
1250
1251 /**
1252 * XSS Clean
1253 *
1254 * @access public
1255 * @param string
1256 * @return string
1257 */
1258 function xss_clean($str)
1259 {
1260 return $this->CI->input->xss_clean($str);
1261 }
1262
1263 // --------------------------------------------------------------------
1264
1265 /**
1266 * Convert PHP tags to entities
1267 *
1268 * @access public
1269 * @param string
1270 * @return string
1271 */
1272 function encode_php_tags($str)
1273 {
1274 return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
1275 }
1276
1277 }
1278 // END Form Validation Class
1279
1280 /* End of file Form_validation.php */
1281 /* Location: ./system/libraries/Form_validation.php */
...\ No newline at end of file ...\ No newline at end of file
...@@ -4,9 +4,11 @@ h3.table-caption { padding:0; margin:25px 0 0px 0; } ...@@ -4,9 +4,11 @@ h3.table-caption { padding:0; margin:25px 0 0px 0; }
4 .post-success { 4 .post-success {
5 padding:10px; 5 padding:10px;
6 font-size: 12px; 6 font-size: 12px;
7 background: #ffffcc; 7 background: #88c550;
8 color:#88c550; 8 color:#fff;
9 } 9 }
10 .post-success a { color:#fff; text-decoration: underline;}
11 .post-success a:hover { color:#3b0d32; text-decoration: none; }
10 12
11 table.expandable thead th { 13 table.expandable thead th {
12 cursor:pointer; 14 cursor:pointer;
...@@ -34,3 +36,9 @@ table.expandable thead.open th.toggle h6 { ...@@ -34,3 +36,9 @@ table.expandable thead.open th.toggle h6 {
34 #ui-timepicker-div dl{ text-align: left; } 36 #ui-timepicker-div dl{ text-align: left; }
35 #ui-timepicker-div dl dt{ height: 25px; font-size: 11px; } 37 #ui-timepicker-div dl dt{ height: 25px; font-size: 11px; }
36 #ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; font-size: 11px; } 38 #ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; font-size: 11px; }
39
40 .post-errors { border:1px solid red; background: pink;}
41 .post-errors-title { padding: 8px 10px; color:#fff; background: red; font: italic 16px/18px Georgia,"Times New Roman","Bitstream Charter",Times,serif;}
42 .post-errors-content { padding:10px; color:red; margin:0;}
43
44 .lblError { font: italic 11px/16px Georgia,"Times New Roman","Bitstream Charter",Times,serif; color: red;}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -20,6 +20,14 @@ use Tz\WordPress\Tools; ...@@ -20,6 +20,14 @@ use Tz\WordPress\Tools;
20 <?php echo $flash; ?> 20 <?php echo $flash; ?>
21 </div> 21 </div>
22 <?php endif; ?> 22 <?php endif; ?>
23 <?php if($validation->validation_errors() != "" || isset($form_error)):?>
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;?>
23 31
24 <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new"> 32 <form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new">
25 33
...@@ -37,16 +45,17 @@ use Tz\WordPress\Tools; ...@@ -37,16 +45,17 @@ use Tz\WordPress\Tools;
37 <td width="150">Notification Type</td> 45 <td width="150">Notification Type</td>
38 <td> 46 <td>
39 <select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();"> 47 <select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();">
40 <option value="scheduled">Scheduled Notification</option> 48 <option value="scheduled" <?php echo ($validation->set_value('type')=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option>
41 <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?> 49 <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
42 <option value="triggered">System Triggered Notification</option> 50 <option value="triggered" <?php echo ($validation->set_value('type')=="triggered") ? 'selected="selected"' : "";?>>System Triggered Notification</option>
43 <?php endif; ?> 51 <?php endif; ?>
44 </select> 52 </select>
53 <?php echo $validation->form_error('type');?>
45 </td> 54 </td>
46 </tr> 55 </tr>
47 <tr> 56 <tr>
48 <td width="150">Notification Description</td> 57 <td width="150">Notification Description</td>
49 <td><input type="text" name="title" class="wide-input-field" /></td> 58 <td><input type="text" name="title" class="wide-input-field" value="<?php echo $validation->set_value('title');?>" /><?php echo $validation->form_error('title');?></td>
50 </tr> 59 </tr>
51 <tr> 60 <tr>
52 <td>Sent To:</td> 61 <td>Sent To:</td>
...@@ -60,17 +69,18 @@ use Tz\WordPress\Tools; ...@@ -60,17 +69,18 @@ use Tz\WordPress\Tools;
60 <option value="group3">Group 3</option> 69 <option value="group3">Group 3</option>
61 </optgroup> 70 </optgroup>
62 </select> 71 </select>
72 <?php echo $validation->form_error('sendto');?>
63 </td> 73 </td>
64 </tr> 74 </tr>
65 75
66 <tr class="scheduled-extended"> 76 <tr class="scheduled-extended">
67 <td>Execute Date / Time</td> 77 <td>Execute Date / Time</td>
68 <td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" readonly="readonly" /></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>
69 </tr> 79 </tr>
70 80
71 <tr class="trigger-extended"> 81 <tr class="trigger-extended">
72 <td>Trigger</td> 82 <td>Trigger</td>
73 <td><input type="text" name="trigger" id="trigger" class="wide-input-field" /></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>
74 </tr> 84 </tr>
75 85
76 </tbody> 86 </tbody>
...@@ -83,18 +93,18 @@ use Tz\WordPress\Tools; ...@@ -83,18 +93,18 @@ use Tz\WordPress\Tools;
83 <th class="action-bar">&nbsp;</th> 93 <th class="action-bar">&nbsp;</th>
84 </tr> 94 </tr>
85 </thead> 95 </thead>
86 <tbody> 96 <tbody style="<?php echo ($validation->set_value('subject')!="" || $validation->set_value('text')!="" || $validation->set_value('html')!="") ? "" : "display:none";?>;">
87 <tr> 97 <tr>
88 <td width="150">Subject Line</td> 98 <td width="150">Subject Line</td>
89 <td><input type="text" name="subject" class="wide-input-field" style="width:100%;" /></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>
90 </tr> 100 </tr>
91 <tr> 101 <tr>
92 <td>Text Version</td> 102 <td>Text Version</td>
93 <td><textarea name="text" class="wide-input-field" rows="10" style="width:100%;" ></textarea></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>
94 </tr> 104 </tr>
95 <tr> 105 <tr>
96 <td>HTML Version (optional)</td> 106 <td>HTML Version (optional)</td>
97 <td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"></textarea></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>
98 </tr> 108 </tr>
99 <tr> 109 <tr>
100 <td width="150">Attachments</td> 110 <td width="150">Attachments</td>
...@@ -118,10 +128,10 @@ use Tz\WordPress\Tools; ...@@ -118,10 +128,10 @@ use Tz\WordPress\Tools;
118 <th class="action-bar">&nbsp;</th> 128 <th class="action-bar">&nbsp;</th>
119 </tr> 129 </tr>
120 </thead> 130 </thead>
121 <tbody> 131 <tbody style="<?php echo ($validation->set_value('system')=="") ? "display:none" : "";?>;">
122 <tr> 132 <tr>
123 <td>Message (Text/HTML)</td> 133 <td>Message (Text/HTML)</td>
124 <td><textarea name="system" class="wide-input-field" rows="4" style="width:100%;" ></textarea></td> 134 <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>
125 </tr> 135 </tr>
126 </tbody> 136 </tbody>
127 </table> 137 </table>
...@@ -133,10 +143,10 @@ use Tz\WordPress\Tools; ...@@ -133,10 +143,10 @@ use Tz\WordPress\Tools;
133 <th class="action-bar">&nbsp;</th> 143 <th class="action-bar">&nbsp;</th>
134 </tr> 144 </tr>
135 </thead> 145 </thead>
136 <tbody> 146 <tbody style="<?php echo ($validation->set_value('sms')=="") ? "display:none" : "";?>;">
137 <tr> 147 <tr>
138 <td>Text Only!</td> 148 <td>Text Only!</td>
139 <td><textarea name="sms" class="wide-input-field" rows="4" style="width:100%;" ></textarea></td> 149 <td><textarea name="sms" class="wide-input-field" rows="4" style="width:100%;" ><?php echo $validation->set_value('sms');?></textarea><?php echo $validation->form_error('sms');?></td>
140 </tr> 150 </tr>
141 </tbody> 151 </tbody>
142 </table> 152 </table>
...@@ -163,7 +173,7 @@ jQuery(document).ready(function() { ...@@ -163,7 +173,7 @@ jQuery(document).ready(function() {
163 173
164 updateNotificationType(); 174 updateNotificationType();
165 175
166 jQuery('table.expandable tbody').hide(); 176 //jQuery('table.expandable tbody').hide();
167 jQuery('table.expandable thead th').click(function() { 177 jQuery('table.expandable thead th').click(function() {
168 var $table = jQuery(this).parent().parent().parent(); 178 var $table = jQuery(this).parent().parent().parent();
169 if ( jQuery('tbody',$table).is(":visible") ) { 179 if ( jQuery('tbody',$table).is(":visible") ) {
......
1 <?php
2 use Tz\WordPress\Tools\Notifications;
3 use Tz\WordPress\Tools;
4 ?>
5
6 <!-- jQuery -->
7 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
8
9 <!-- required plugins -->
10 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/date.js', __FILE__)?>"></script>
11 <!--[if IE]><script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.bgiframe.js', __FILE__)?>"></script><![endif]-->
12
13 <!-- jquery.datePicker.js -->
14 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.datePicker.js', __FILE__)?>"></script>
15
16 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/datePicker.css', __FILE__)?>" />
17 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
18
19 <div id="" class="wrap">
20
21 <h2>Notifications - Create New</h2>
22 <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis convallis nisi eu dignissim. Quisque malesuada augue in mi blandit at blandit tortor sollicitudin. Cras at justo mi, vel mollis est. Donec orci erat, blandit varius vehicula vitae, volutpat at lorem. Etiam tincidunt bibendum ante, non tincidunt purus faucibus sed. Suspendisse eget facilisis tellus. Nulla imperdiet leo placerat diam sollicitudin nec mattis neque mattis. Cras id lacus tellus. Phasellus volutpat vehicula porttitor. Praesent erat felis, pharetra mollis egestas sit amet, rhoncus eget nisl. Morbi interdum sapien vitae nibh pharetra scelerisque. Mauris porta accumsan velit ac aliquam. Sed sit amet dictum felis. Fusce tempus vulputate nulla, quis tincidunt velit mattis eu.</p>
23
24 <form method="post" action="/wp-admin/admin.php?page=notification&action=create">
25
26 <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
27 <thead>
28 <tr>
29 <th width="150">Notification Details</th>
30 <th>&nbsp;</th>
31 </tr>
32 </thead>
33 <tbody>
34 <tr>
35 <td width="150">Description</td>
36 <td><input type="text" name="" class="wide-input-field" /></td>
37 </tr>
38 <tr>
39 <td>Notification Type</td>
40 <td>
41 <select name="" class="wide-input-field">
42 <option value="instant">Instant</option>
43 <option value="queued">Batch Queue</option>
44 <option value="system">System</option>
45 </select>
46 </td>
47 </tr>
48 <tr>
49 <td>Sent To:</td>
50 <td>
51 <select name="" class="wide-input-field">
52 <option value="user">Current User</option>
53 <option value="user">All Users</option>
54 <optgroup label="Groups:">
55 <option value="group1">Administrators</option>
56 <option value="group2">Group 2</option>
57 <option value="group3">Group 3</option>
58 </optgroup>
59 </select>
60 </td>
61 </tr>
62 <tr>
63 <td>Trigger/Slug</td>
64 <td><input type="text" name="" class="wide-input-field" /></td>
65 </tr>
66 <tr>
67 <td>Execute Date / Time</td>
68 <td><input type="text" name="" class="wide-input-field date-pick" /></td>
69 </tr>
70
71 </tbody>
72 </table>
73
74 <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
75 <thead>
76 <tr>
77 <th width="150">Notification Content</th>
78 <th>&nbsp;</th>
79 </tr>
80 </thead>
81 <tbody>
82 <tr>
83 <td width="150">Subject Line</td>
84 <td><input type="text" name="" class="wide-input-field" style="width:100%;" /></td>
85 </tr>
86 <tr>
87 <td>Text Version</td>
88 <td><textarea class="wide-input-field" rows="10" style="width:100%;" ></textarea></td>
89 </tr>
90 <tr>
91 <td>HTML Version (optional)</td>
92 <td><textarea class="wide-input-field" rows="10" style="width:100%;"></textarea></td>
93 </tr>
94 </tbody>
95 </table>
96
97 <p>
98 <input type="submit" value=" Save " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
99 </p>
100
101 </form>
102
103 </div>
104
105 <script type="text/javascript">
106 $(function()
107 {
108 $('.date-pick').datePicker();
109 });
110 </script>
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 use Tz\WordPress\Tools\Notifications\Settings;
3 use Tz\WordPress\Tools\Notifications;
4 use Tz\WordPress\Tools;
5 ?>
6
7 <link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
8 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script>
9 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script>
10 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script>
11 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
12
13 <div id="" class="wrap">
14
15 <h2>Notifications - Edit</h2>
16 <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam iaculis convallis nisi eu dignissim. Quisque malesuada augue in mi blandit at blandit tortor sollicitudin. Cras at justo mi, vel mollis est. Donec orci erat, blandit varius vehicula vitae, volutpat at lorem. Etiam tincidunt bibendum ante, non tincidunt purus faucibus sed. Suspendisse eget facilisis tellus. Nulla imperdiet leo placerat diam sollicitudin nec mattis neque mattis. Cras id lacus tellus. Phasellus volutpat vehicula porttitor. Praesent erat felis, pharetra mollis egestas sit amet, rhoncus eget nisl. Morbi interdum sapien vitae nibh pharetra scelerisque. Mauris porta accumsan velit ac aliquam. Sed sit amet dictum felis. Fusce tempus vulputate nulla, quis tincidunt velit mattis eu.</p>
17
18 <?php if (isset($flash) && $flash !=""): ?>
19 <div class="post-success">
20 <?php echo $flash; ?>
21 </div>
22 <?php endif; ?>
23 <?php if($validation->validation_errors() != "" || isset($form_error)):?>
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&action=edit&page_id=<?php echo $_GET['page_id']?>">
33
34 <input type="hidden" name="_POSTED_" value="yes" />
35
36 <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
37 <thead>
38 <tr>
39 <th width="150">Notification Details</th>
40 <th>&nbsp;</th>
41 </tr>
42 </thead>
43 <tbody>
44 <tr>
45 <td width="150">Notification Type</td>
46 <td>
47 <select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();">
48 <option value="scheduled" <?php echo ($validation->set_value('type',$entry->details['type'])=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option>
49 <?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
50 <option value="triggered" <?php echo ($validation->set_value('type',$entry->details['type'])=="triggered") ? 'selected="selected"' : "";?>>System Triggered Notification</option>
51 <?php endif; ?>
52 </select>
53 <?php echo $validation->form_error('type');?>
54 </td>
55 </tr>
56 <tr>
57 <td width="150">Notification Description</td>
58 <td><input type="text" name="title" class="wide-input-field" value="<?php echo $validation->set_value('title',$entry->post_title);?>" /><?php echo $validation->form_error('title');?></td>
59 </tr>
60 <tr>
61 <td>Sent To:</td>
62 <td>
63 <select name="sendto" class="wide-input-field">
64 <option value="user" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="user") ? 'selected="selected"' : "";?>>Current User</option>
65 <option value="allusers" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="allusers") ? 'selected="selected"' : "";?>>All Users</option>
66 <optgroup label="Groups:">
67 <option value="group1" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group1") ? 'selected="selected"' : "";?>>Administrators</option>
68 <option value="group2" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group2") ? 'selected="selected"' : "";?>>Group 2</option>
69 <option value="group3" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group3") ? 'selected="selected"' : "";?>>Group 3</option>
70 </optgroup>
71 </select>
72 <?php echo $validation->form_error('sendto');?>
73 </td>
74 </tr>
75
76 <tr class="scheduled-extended">
77 <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',$entry->details['execute_date']);?>" /><?php echo $validation->form_error('execute_date');?></td>
79 </tr>
80
81 <tr class="trigger-extended">
82 <td>Trigger</td>
83 <td><input type="text" name="trigger" id="trigger" class="wide-input-field" value="<?php echo $validation->set_value('trigger',$entry->details['trigger']);?>" /><?php echo $validation->form_error('trigger');?></td>
84 </tr>
85
86 </tbody>
87 </table>
88
89 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
90 <thead>
91 <tr>
92 <th width="150" class="toggle"><h6>Email</h6></th>
93 <th class="action-bar">&nbsp;</th>
94 </tr>
95 </thead>
96 <tbody style="<?php echo ($validation->set_value('subject',$entry->email['subject'])!="" || $validation->set_value('text',$entry->email['text'])!="" || $validation->set_value('html',$entry->email['html'])!="") ? "" : "display:none";?>;">
97 <tr>
98 <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',$entry->email['subject']);?>" /><?php echo $validation->form_error('subject');?></td>
100 </tr>
101 <tr>
102 <td>Text Version</td>
103 <td><textarea name="text" class="wide-input-field" rows="10" style="width:100%;" ><?php echo $validation->set_value('text',$entry->email['text']);?></textarea><?php echo $validation->form_error('text');?></td>
104 </tr>
105 <tr>
106 <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',$entry->email['html']);?></textarea><?php echo $validation->form_error('html');?></td>
108 </tr>
109 <tr>
110 <td width="150">Attachments</td>
111 <td><input type="file" name="attachment[]" /></td>
112 </tr>
113 <tr>
114 <td>&nbsp;</td>
115 <td><input type="file" name="attachment[]" /></td>
116 </tr>
117 <tr>
118 <td>&nbsp;</td>
119 <td><input type="file" name="attachment[]" /></td>
120 </tr>
121 </tbody>
122 </table>
123
124 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
125 <thead>
126 <tr>
127 <th width="150" class="toggle"><h6>System Message</h6></th>
128 <th class="action-bar">&nbsp;</th>
129 </tr>
130 </thead>
131 <tbody style="<?php echo ($validation->set_value('system',$entry->system)=="") ? "display:none" : "";?>;">
132 <tr>
133 <td>Message (Text/HTML)</td>
134 <td><textarea name="system" class="wide-input-field" rows="4" style="width:100%;" ><?php echo $validation->set_value('system',$entry->system);?></textarea><?php echo $validation->form_error('system');?></td>
135 </tr>
136 </tbody>
137 </table>
138
139 <table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
140 <thead>
141 <tr>
142 <th width="150" class="toggle"><h6>SMS</h6></th>
143 <th class="action-bar">&nbsp;</th>
144 </tr>
145 </thead>
146 <tbody style="<?php echo ($validation->set_value('sms',$entry->sms)=="") ? "display:none" : "";?>;">
147 <tr>
148 <td>Text Only!</td>
149 <td><textarea name="sms" class="wide-input-field" rows="4" style="width:100%;" ><?php echo $validation->set_value('sms',$entry->sms);?></textarea><?php echo $validation->form_error('sms');?></td>
150 </tr>
151 </tbody>
152 </table>
153
154
155 <p>
156 <input type="submit" value=" Update " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
157 </p>
158
159 </form>
160
161 </div>
162
163 <script type="text/javascript">
164
165
166 jQuery(document).ready(function() {
167
168 $('#execute_date').datetimepicker({
169 stepMinute: 15
170 , dateFormat: 'yy-mm-dd'
171 , timeFormat: 'hh:mm:ss'
172 });
173
174 updateNotificationType();
175
176 //jQuery('table.expandable tbody').hide();
177 jQuery('table.expandable thead th').click(function() {
178 var $table = jQuery(this).parent().parent().parent();
179 if ( jQuery('tbody',$table).is(":visible") ) {
180 jQuery('thead',$table).removeClass("open");
181 jQuery('tbody',$table).fadeOut();
182 } else {
183 jQuery('thead',$table).addClass("open");
184 jQuery('tbody',$table).fadeIn();
185 }
186 });
187
188 });
189
190 function updateNotificationType() {
191 var type = jQuery('#notif_type').val();
192
193 if (type=="triggered") {
194 jQuery('.scheduled-extended').hide();
195 jQuery('.trigger-extended').show();
196 } else {
197 jQuery('.scheduled-extended').show();
198 jQuery('.trigger-extended').hide();
199 }
200
201 }
202
203
204
205 </script>
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 use Tz\WordPress\Tools\Notifications\Settings;
3 use Tz\WordPress\Tools\Notifications;
4 use Tz\WordPress\Tools;
5
6
7 register_settings
8
9 ?>
10
11 <link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
12 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script>
13 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script>
14 <script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script>
15 <link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
16
17 <div id="" class="wrap">
18
19 <h2>Notifications - Settings</h2>
20 <p>In order to comply with the CAN-SPAM act, each outgoing email must include the following:</p>
21
22
23 <form enctype="multipart/form-data" method="post" action="options.php">
24
25 <input type="hidden" name="_POSTED_" value="yes" />
26
27 <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
28 <thead>
29 <tr>
30 <th width="150">CAN-SPAM Settings</th>
31 <th>&nbsp;</th>
32 </tr>
33 </thead>
34 <tbody>
35 <tr>
36 <td width="150">Company Name:</td>
37 <td><input type="text" name="company" class="wide-input-field" /></td>
38 </tr>
39 <tr>
40 <td width="150">Address:</td>
41 <td><input type="text" name="address" class="wide-input-field" /></td>
42 </tr>
43 <tr>
44 <td width="150">Apt/Unit/Suite:</td>
45 <td><input type="text" name="address2" class="wide-input-field" /></td>
46 </tr>
47 <tr>
48 <td width="150">City:</td>
49 <td><input type="text" name="city" class="wide-input-field" /></td>
50 </tr>
51 <tr>
52 <td width="150">Province:</td>
53 <td>
54 <select name="province" class="wide-input-field" >
55 <option value="Ontario">Ontario</option>
56 <option value="Quebec">Quebec</option>
57 <option value="Nova Scotia">Nova Scotia</option>
58 <option value="New Brunswick">New Brunswick</option>
59 <option value="Manitoba">Manitoba</option>
60 <option value="British Columbia">British Columbia</option>
61 <option value="Prince Edward Island">Prince Edward Island</option>
62 <option value="Saskatchewan">Saskatchewan</option>
63 <option value="Alberta">Alberta</option>
64 <option value="Newfoundland and Labrador">Newfoundland and Labrador</option>
65 </select>
66 </td>
67 </tr>
68 <tr>
69 <td width="150">Postal Code:</td>
70 <td><input type="text" name="postal" /></td>
71 </tr>
72 </body>
73 </table>
74
75 <table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
76 <thead>
77 <tr>
78 <th width="150">CAN-SPAM Messages</th>
79 <th>&nbsp;</th>
80 </tr>
81 </thead>
82 <tbody>
83 <tr>
84 <td width="150">Standard Message:</td>
85 <td><textarea name="std_message" class="wide-input-field" rows="4" style="width:100%;color:#999" onkeydown="this.style.color = '#000000';">This email was sent to ({email}) because you have agreed to receive periodic emails from us. To ensure that you continue receiving our emails, please add us to your address book or safe list.</textarea></td>
86 </tr>
87 <tr>
88 <td width="150">OPT-OUT Message::</td>
89 <td><textarea name="opt_message" class="wide-input-field" rows="4" style="width:100%;color:#999" onkeydown="this.style.color = '#000000';" >If you do not wish to further receive emails from us, please opt-out by clicking here: http://cbv.wp.kb/no-emails-please.php?u={uid}.</textarea></td>
90 </tr>
91 </body>
92 </table>
93
94 <p>
95 <input type="submit" value=" Update " />
96 </p>
97 </form>
98
99 </div>
...\ No newline at end of file ...\ No newline at end of file