1b9bd638 by Kevin Burton

updates - not complete!

1 parent 3e2f7761
......@@ -5,6 +5,7 @@ error_reporting(E_ALL^E_DEPRECATED);
use Tz\WordPress\Tools;
use Tz\Common;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Validation;
const CAPABILITY = "manage_notifications";
const MANAGE_SYSTEM_NOTIFICATIONS = "create_system_notifications";
......@@ -21,7 +22,106 @@ function display_page() {
if (isset($_GET['action']) && $_GET['action']=="edit") {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'edit.php');
global $wpdb;
$entry = get_post($_GET['page_id']);
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$sms = get_post_meta($id,'sms',true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$entry->sms = $sms;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('title','Description','trim|required|min_length[16]');
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('sendto','Send To','required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$validation->set_rules('execute_date','Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$validation->set_rules('trigger','Trigger',$trigger_val);
$validation->set_rules('subject','Subject','trim');
$validation->set_rules('text','Text Version','trim|min_length[16]');
$validation->set_rules('html','HTML Version','trim|min_length[16]');
$validation->set_rules('system','System Message','trim|min_length[16]');
$validation->set_rules('sms','SMS Message','trim|min_length[16]');
//details
if ($validation->run() == TRUE) {
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = array();
$upload_dir = __DIR__ . "/uploads/";
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if($file['name'] != "") {
move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
$attachments[] = $file['name'];
}
}
// system
$system = $_POST['system'];
// SMS
$sms = $_POST['sms'];
update_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
, 'status' => $entry->details['status']
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
update_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
, 'html' => $html
, 'attachments' => $attachments
));
update_post_meta($id, "system", $system);
update_post_meta($id, "sms", $sms);
$update = array();
$update['ID'] = $id;
$update['post_title'] = $title;
wp_update_post($update);
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
}
} else {
......@@ -131,12 +231,27 @@ function fixFilesArray(&$files)
}
}
function create_trigger_notification() {
print "hello";
}
function notification_settings() {
print "settings";
global $wpdb;
$validation = new Notifications\Validation;
$validation->set_rules('company','Company','required|trim');
$validation->set_rules('address','Address','required|trim');
$validation->set_rules('address2','Apt/Unit/Suite','required|trim');
$validation->set_rules('city','City','required|trim');
$validation->set_rules('province','Province','required|trim');
$validation->set_rules('postal','POstal Code','required|trim');
$validation->set_rules('std_message','Standard Message','required|trim');
$validation->set_rules('opt_message','OPT-OUT Message','required|trim');
if ($validation->run() == TRUE) {
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php');
}
}
function create_notification() {
......@@ -144,81 +259,108 @@ function create_notification() {
global $wpdb;
if ($_POST && isset($_POST['_POSTED_']) && $_POST['_POSTED_']=="yes") {
// ok, so now we need to create the notification.
class postTemplate {
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'notifications';
var $comment_status = 'closed';
}
// here
$validation = new Notifications\Validation;
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('title','Description','trim|required|min_length[16]');
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('sendto','Send To','required');
$type_val = ($_POST && $_POST['type'] == "scheduled") ? 'required' : '';
$validation->set_rules('execute_date','Execute Date', $type_val);
$trigger_val = ($_POST && $_POST['type'] == "triggered") ? 'required' : '';
$validation->set_rules('trigger','Trigger',$trigger_val);
$validation->set_rules('subject','Subject','trim');
$validation->set_rules('text','Text Version','trim|min_length[16]');
$validation->set_rules('html','HTML Version','trim|min_length[16]');
$validation->set_rules('system','System Message','trim|min_length[16]');
$validation->set_rules('sms','SMS Message','trim|min_length[16]');
if ($_POST && (($_POST['subject']=="" || $_POST['text']) && $_POST['sms']=="" && $_POST['system']=="")) {
$form_error = true;
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
} else {
if ($validation->run() == TRUE) {
//details
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = array();
$upload_dir = __DIR__ . "/uploads/";
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if($file['name'] != "") {
move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
$attachments[] = $file['name'];
// ok, so now we need to create the notification.
class postTemplate {
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'notifications';
var $comment_status = 'closed';
}
}
// system
$system = $_POST['system'];
// SMS
$sms = $_POST['sms'];
// make post...
$notification = new postTemplate();
$notification->post_title = $title;
$notification->post_content = "Notification created ".date('Y-m-d H:i:s')." --- to be sent on $execute_date";
$notification->post_date_gmt = date("Y-m-d H:i:s",time());
$id = wp_insert_post($notification);
add_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
, 'status' => 'pending'
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
add_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
, 'html' => $html
, 'attachments' => $attachments
));
add_post_meta($id, "system", $system);
add_post_meta($id, "sms", $sms);
$flash = "Notification Saved Successfully!";
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
//details
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
$execute_date = ($type=="scheduled") ? $_POST['execute_date'] : "0000-00-00 00:00:00";
$trigger = ($type=="scheduled") ? "scheduled-cron-job" : $_POST['trigger'];
// email
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = array();
$upload_dir = __DIR__ . "/uploads/";
fixFilesArray($_FILES['attachment']);
foreach ($_FILES['attachment'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
if($file['name'] != "") {
move_uploaded_file($file['tmp_name'],$upload_dir . $file['name']);
$attachments[] = $file['name'];
}
}
// system
$system = $_POST['system'];
// SMS
$sms = $_POST['sms'];
// make post...
$notification = new postTemplate();
$notification->post_title = $title;
$notification->post_content = "Notification created ".date('Y-m-d H:i:s')." --- to be sent on $execute_date";
$notification->post_date_gmt = date("Y-m-d H:i:s",time());
$id = wp_insert_post($notification);
add_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
, 'status' => 'pending'
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
add_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
, 'html' => $html
, 'attachments' => $attachments
));
add_post_meta($id, "system", $system);
add_post_meta($id, "sms", $sms);
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
}
}
}
class Actions {
......@@ -240,7 +382,7 @@ class Actions {
public static function admin_menu() {
add_menu_page('Notifications','Notifications',CAPABILITY,'notifications',__NAMESPACE__ . '\display_page' );
add_submenu_page('notifications','New Notification', 'New Notification',CAPABILITY,'notifications-create-new',__NAMESPACE__ . '\create_notification');
add_submenu_page('notifications','Settings', 'Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
}
public function admin_init() {
......
......@@ -10,6 +10,7 @@ const OPTION_NAME = "notif_options";
call_user_func(function() {
Vars::$options = new Tools\WP_Option(OPTION_NAME);
if (is_admin()) {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Validation.php');
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Admin.php');
}
});
......
<?php
namespace Tz\WordPress\Tools\Notifications;
error_reporting(E_ALL^E_DEPRECATED);
use Tz\WordPress\Tools;
use Tz\Common;
use Tz\WordPress\Tools\Notifications;
class Validation {
protected $_field_data = array();
protected $_config_rules = array();
protected $_error_array = array();
protected $_error_messages = array();
protected $_error_prefix = '<div class="lblError">';
protected $_error_suffix = '</div>';
protected $error_string = '';
protected $_safe_form_data = FALSE;
function __construct($rules = array())
{
// Validation rules can be stored in a config file.
$this->_config_rules = $rules;
}
public function get_error_message($key) {
$lang = array();
$lang['required'] = "The %s field is required.";
$lang['isset'] = "The %s field must have a value.";
$lang['valid_email'] = "The %s field must contain a valid email address.";
$lang['valid_emails'] = "The %s field must contain all valid email addresses.";
$lang['valid_url'] = "The %s field must contain a valid URL.";
$lang['valid_ip'] = "The %s field must contain a valid IP.";
$lang['min_length'] = "The %s field must be at least %s characters in length.";
$lang['max_length'] = "The %s field can not exceed %s characters in length.";
$lang['exact_length'] = "The %s field must be exactly %s characters in length.";
$lang['alpha'] = "The %s field may only contain alphabetical characters.";
$lang['alpha_numeric'] = "The %s field may only contain alpha-numeric characters.";
$lang['alpha_dash'] = "The %s field may only contain alpha-numeric characters, underscores, and dashes.";
$lang['numeric'] = "The %s field must contain only numbers.";
$lang['is_numeric'] = "The %s field must contain only numeric characters.";
$lang['integer'] = "The %s field must contain an integer.";
$lang['matches'] = "The %s field does not match the %s field.";
$lang['is_natural'] = "The %s field must contain only positive numbers.";
$lang['is_natural_no_zero'] = "The %s field must contain a number greater than zero.";
if (isset($lang[$key])) {
return $lang[$key];
} else {
return FALSE;
}
}
// --------------------------------------------------------------------
/**
* Set Rules
*
* This function takes an array of field names and validation
* rules as input, validates the info, and stores it
*
* @access public
* @param mixed
* @param string
* @return void
*/
function set_rules($field, $label = '', $rules = '')
{
// No reason to set rules if we have no POST data
if (count($_POST) == 0)
{
return;
}
// If an array was passed via the first parameter instead of indidual string
// values we cycle through it and recursively call this function.
if (is_array($field))
{
foreach ($field as $row)
{
// Houston, we have a problem...
if ( ! isset($row['field']) OR ! isset($row['rules']))
{
continue;
}
// If the field label wasn't passed we use the field name
$label = ( ! isset($row['label'])) ? $row['field'] : $row['label'];
// Here we go!
$this->set_rules($row['field'], $label, $row['rules']);
}
return;
}
// No fields? Nothing to do...
if ( ! is_string($field) OR ! is_string($rules) OR $field == '')
{
return;
}
// If the field label wasn't passed we use the field name
$label = ($label == '') ? $field : $label;
// Is the field name an array? We test for the existence of a bracket "[" in
// the field name to determine this. If it is an array, we break it apart
// into its components so that we can fetch the corresponding POST data later
if (strpos($field, '[') !== FALSE AND preg_match_all('/\[(.*?)\]/', $field, $matches))
{
// Note: Due to a bug in current() that affects some versions
// of PHP we can not pass function call directly into it
$x = explode('[', $field);
$indexes[] = current($x);
for ($i = 0; $i < count($matches['0']); $i++)
{
if ($matches['1'][$i] != '')
{
$indexes[] = $matches['1'][$i];
}
}
$is_array = TRUE;
}
else
{
$indexes = array();
$is_array = FALSE;
}
// Build our master array
$this->_field_data[$field] = array(
'field' => $field,
'label' => $label,
'rules' => $rules,
'is_array' => $is_array,
'keys' => $indexes,
'postdata' => NULL,
'error' => ''
);
}
// --------------------------------------------------------------------
/**
* Set Error Message
*
* Lets users set their own error messages on the fly. Note: The key
* name has to match the function name that it corresponds to.
*
* @access public
* @param string
* @param string
* @return string
*/
function set_message($lang, $val = '')
{
if ( ! is_array($lang))
{
$lang = array($lang => $val);
}
$this->_error_messages = array_merge($this->_error_messages, $lang);
}
// --------------------------------------------------------------------
/**
* Set The Error Delimiter
*
* Permits a prefix/suffix to be added to each error message
*
* @access public
* @param string
* @param string
* @return void
*/
function set_error_delimiters($prefix = '<p>', $suffix = '</p>')
{
$this->_error_prefix = $prefix;
$this->_error_suffix = $suffix;
}
// --------------------------------------------------------------------
/**
* Get Error Message
*
* Gets the error message associated with a particular field
*
* @access public
* @param string the field name
* @return void
*/
function error($field = '', $prefix = '', $suffix = '')
{
if ( ! isset($this->_field_data[$field]['error']) OR $this->_field_data[$field]['error'] == '')
{
return '';
}
if ($prefix == '')
{
$prefix = $this->_error_prefix;
}
if ($suffix == '')
{
$suffix = $this->_error_suffix;
}
return $prefix.$this->_field_data[$field]['error'].$suffix;
}
// --------------------------------------------------------------------
/**
* Error String
*
* Returns the error messages as a string, wrapped in the error delimiters
*
* @access public
* @param string
* @param string
* @return str
*/
function error_string($prefix = '', $suffix = '')
{
// No errrors, validation passes!
if (count($this->_error_array) === 0)
{
return '';
}
if ($prefix == '')
{
$prefix = $this->_error_prefix;
}
if ($suffix == '')
{
$suffix = $this->_error_suffix;
}
// Generate the error string
$str = '';
foreach ($this->_error_array as $val)
{
if ($val != '')
{
$str .= $prefix.$val.$suffix."\n";
}
}
return $str;
}
// --------------------------------------------------------------------
/**
* Run the Validator
*
* This function does all the work.
*
* @access public
* @return bool
*/
function run($group = '')
{
// Do we even have any data to process? Mm?
if (count($_POST) == 0)
{
return FALSE;
}
// Does the _field_data array containing the validation rules exist?
// If not, we look to see if they were assigned via a config file
if (count($this->_field_data) == 0)
{
// No validation rules? We're done...
if (count($this->_config_rules) == 0)
{
return FALSE;
}
// Is there a validation rule for the particular URI being accessed?
$uri = ($group == '') ? trim($this->CI->uri->ruri_string(), '/') : $group;
if ($uri != '' AND isset($this->_config_rules[$uri]))
{
$this->set_rules($this->_config_rules[$uri]);
}
else
{
$this->set_rules($this->_config_rules);
}
// We're we able to set the rules correctly?
if (count($this->_field_data) == 0)
{
return FALSE;
}
}
// Cycle through the rules for each field, match the
// corresponding $_POST item and test for errors
foreach ($this->_field_data as $field => $row)
{
// Fetch the data from the corresponding $_POST array and cache it in the _field_data array.
// Depending on whether the field name is an array or a string will determine where we get it from.
if ($row['is_array'] == TRUE)
{
$this->_field_data[$field]['postdata'] = $this->_reduce_array($_POST, $row['keys']);
}
else
{
if (isset($_POST[$field]) AND $_POST[$field] != "")
{
$this->_field_data[$field]['postdata'] = $_POST[$field];
}
}
$this->_execute($row, explode('|', $row['rules']), $this->_field_data[$field]['postdata']);
}
// Did we end up with any errors?
$total_errors = count($this->_error_array);
if ($total_errors > 0)
{
$this->_safe_form_data = TRUE;
}
// Now we need to re-set the POST data with the new, processed data
$this->_reset_post_array();
// No errors, validation passes!
if ($total_errors == 0)
{
return TRUE;
}
// Validation fails
return FALSE;
}
// --------------------------------------------------------------------
/**
* Traverse a multidimensional $_POST array index until the data is found
*
* @access private
* @param array
* @param array
* @param integer
* @return mixed
*/
function _reduce_array($array, $keys, $i = 0)
{
if (is_array($array))
{
if (isset($keys[$i]))
{
if (isset($array[$keys[$i]]))
{
$array = $this->_reduce_array($array[$keys[$i]], $keys, ($i+1));
}
else
{
return NULL;
}
}
else
{
return $array;
}
}
return $array;
}
// --------------------------------------------------------------------
/**
* Re-populate the _POST array with our finalized and processed data
*
* @access private
* @return null
*/
function _reset_post_array()
{
foreach ($this->_field_data as $field => $row)
{
if ( ! is_null($row['postdata']))
{
if ($row['is_array'] == FALSE)
{
if (isset($_POST[$row['field']]))
{
$_POST[$row['field']] = $this->prep_for_form($row['postdata']);
}
}
else
{
// start with a reference
$post_ref =& $_POST;
// before we assign values, make a reference to the right POST key
if (count($row['keys']) == 1)
{
$post_ref =& $post_ref[current($row['keys'])];
}
else
{
foreach ($row['keys'] as $val)
{
$post_ref =& $post_ref[$val];
}
}
if (is_array($row['postdata']))
{
$array = array();
foreach ($row['postdata'] as $k => $v)
{
$array[$k] = $this->prep_for_form($v);
}
$post_ref = $array;
}
else
{
$post_ref = $this->prep_for_form($row['postdata']);
}
}
}
}
}
// --------------------------------------------------------------------
/**
* Executes the Validation routines
*
* @access private
* @param array
* @param array
* @param mixed
* @param integer
* @return mixed
*/
function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
// If the $_POST data is an array we will run a recursive call
if (is_array($postdata))
{
foreach ($postdata as $key => $val)
{
$this->_execute($row, $rules, $val, $cycles);
$cycles++;
}
return;
}
// --------------------------------------------------------------------
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! in_array('required', $rules) AND is_null($postdata))
{
// Before we bail out, does the rule contain a callback?
if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
{
$callback = TRUE;
$rules = (array('1' => $match[1]));
}
else
{
return;
}
}
// --------------------------------------------------------------------
// Isset Test. Typically this rule will only apply to checkboxes.
if (is_null($postdata) AND $callback == FALSE)
{
if (in_array('isset', $rules, TRUE) OR in_array('required', $rules))
{
// Set the message type
$type = (in_array('required', $rules)) ? 'required' : 'isset';
if ( ! isset($this->_error_messages[$type]))
{
if (FALSE === ($line = $this->get_error_message($type)))
{
$line = 'The field was not set';
}
}
else
{
$line = $this->_error_messages[$type];
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
}
return;
}
// --------------------------------------------------------------------
// Cycle through each rule and run it
foreach ($rules As $rule)
{
$_in_array = FALSE;
// We set the $postdata variable with the current data in our master array so that
// each cycle of the loop is dealing with the processed data from the last cycle
if ($row['is_array'] == TRUE AND is_array($this->_field_data[$row['field']]['postdata']))
{
// We shouldn't need this safety, but just in case there isn't an array index
// associated with this cycle we'll bail out
if ( ! isset($this->_field_data[$row['field']]['postdata'][$cycles]))
{
continue;
}
$postdata = $this->_field_data[$row['field']]['postdata'][$cycles];
$_in_array = TRUE;
}
else
{
$postdata = $this->_field_data[$row['field']]['postdata'];
}
// --------------------------------------------------------------------
// Is the rule a callback?
$callback = FALSE;
if (substr($rule, 0, 9) == 'callback_')
{
$rule = substr($rule, 9);
$callback = TRUE;
}
// Strip the parameter (if exists) from the rule
// Rules can contain a parameter: max_length[5]
$param = FALSE;
if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match))
{
$rule = $match[1];
$param = $match[2];
}
// Call the function that corresponds to the rule
if ($callback === TRUE)
{
if ( ! method_exists($this->CI, $rule))
{
continue;
}
// Run the function and grab the result
$result = $this->CI->$rule($postdata, $param);
// Re-assign the result to the master data array
if ($_in_array == TRUE)
{
$this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
}
else
{
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
// If the field isn't required and we just processed a callback we'll move on...
if ( ! in_array('required', $rules, TRUE) AND $result !== FALSE)
{
continue;
}
}
else
{
if ( ! method_exists($this, $rule))
{
// If our own wrapper function doesn't exist we see if a native PHP function does.
// Users can use any native PHP function call that has one param.
if (function_exists($rule))
{
$result = $rule($postdata);
if ($_in_array == TRUE)
{
$this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
}
else
{
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
}
continue;
}
$result = $this->$rule($postdata, $param);
if ($_in_array == TRUE)
{
$this->_field_data[$row['field']]['postdata'][$cycles] = (is_bool($result)) ? $postdata : $result;
}
else
{
$this->_field_data[$row['field']]['postdata'] = (is_bool($result)) ? $postdata : $result;
}
}
// Did the rule test negatively? If so, grab the error.
if ($result === FALSE)
{
if ( ! isset($this->_error_messages[$rule]))
{
if (FALSE === ($line = $this->get_error_message($rule)))
{
$line = 'Unable to access an error message corresponding to your field name.';
}
}
else
{
$line = $this->_error_messages[$rule];
}
// Is the parameter we are inserting into the error message the name
// of another field? If so we need to grab its "field label"
if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label']))
{
$param = $this->_field_data[$param]['label'];
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
return;
}
}
}
function form_error($field = '', $prefix = '', $suffix = '')
{
return $this->error($field, $prefix, $suffix);
}
function validation_errors($prefix = '', $suffix = '')
{
return $this->error_string($prefix, $suffix);
}
// --------------------------------------------------------------------
/**
* Translate a field name
*
* @access private
* @param string the field name
* @return string
*/
function _translate_fieldname($fieldname)
{
// Do we need to translate the field name?
// We look for the prefix lang: to determine this
if (substr($fieldname, 0, 5) == 'lang:')
{
// Grab the variable
$line = substr($fieldname, 5);
// Were we able to translate the field name? If not we use $line
if (FALSE === ($fieldname = $this->get_error_message($line)))
{
return $line;
}
}
return $fieldname;
}
// --------------------------------------------------------------------
/**
* Get the value from a form
*
* Permits you to repopulate a form field with the value it was submitted
* with, or, if that value doesn't exist, with the default
*
* @access public
* @param string the field name
* @param string
* @return void
*/
function set_value($field = '', $default = '')
{
if ( ! isset($this->_field_data[$field]))
{
return $default;
}
return $this->_field_data[$field]['postdata'];
}
// --------------------------------------------------------------------
/**
* Set Select
*
* Enables pull-down lists to be set to the value the user
* selected in the event of an error
*
* @access public
* @param string
* @param string
* @return string
*/
function set_select($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
if ($default === TRUE AND count($this->_field_data) === 0)
{
return ' selected="selected"';
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
{
return '';
}
}
else
{
if (($field == '' OR $value == '') OR ($field != $value))
{
return '';
}
}
return ' selected="selected"';
}
// --------------------------------------------------------------------
/**
* Set Radio
*
* Enables radio buttons to be set to the value the user
* selected in the event of an error
*
* @access public
* @param string
* @param string
* @return string
*/
function set_radio($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
if ($default === TRUE AND count($this->_field_data) === 0)
{
return ' checked="checked"';
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
{
return '';
}
}
else
{
if (($field == '' OR $value == '') OR ($field != $value))
{
return '';
}
}
return ' checked="checked"';
}
// --------------------------------------------------------------------
/**
* Set Checkbox
*
* Enables checkboxes to be set to the value the user
* selected in the event of an error
*
* @access public
* @param string
* @param string
* @return string
*/
function set_checkbox($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
if ($default === TRUE AND count($this->_field_data) === 0)
{
return ' checked="checked"';
}
return '';
}
$field = $this->_field_data[$field]['postdata'];
if (is_array($field))
{
if ( ! in_array($value, $field))
{
return '';
}
}
else
{
if (($field == '' OR $value == '') OR ($field != $value))
{
return '';
}
}
return ' checked="checked"';
}
// --------------------------------------------------------------------
/**
* Required
*
* @access public
* @param string
* @return bool
*/
function required($str)
{
if ( ! is_array($str))
{
return (trim($str) == '') ? FALSE : TRUE;
}
else
{
return ( ! empty($str));
}
}
// --------------------------------------------------------------------
/**
* Match one field to another
*
* @access public
* @param string
* @param field
* @return bool
*/
function matches($str, $field)
{
if ( ! isset($_POST[$field]))
{
return FALSE;
}
$field = $_POST[$field];
return ($str !== $field) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Minimum Length
*
* @access public
* @param string
* @param value
* @return bool
*/
function min_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
return FALSE;
}
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) < $val) ? FALSE : TRUE;
}
return (strlen($str) < $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Max Length
*
* @access public
* @param string
* @param value
* @return bool
*/
function max_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
return FALSE;
}
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) > $val) ? FALSE : TRUE;
}
return (strlen($str) > $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Exact Length
*
* @access public
* @param string
* @param value
* @return bool
*/
function exact_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
return FALSE;
}
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) != $val) ? FALSE : TRUE;
}
return (strlen($str) != $val) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Email
*
* @access public
* @param string
* @return bool
*/
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Emails
*
* @access public
* @param string
* @return bool
*/
function valid_emails($str)
{
if (strpos($str, ',') === FALSE)
{
return $this->valid_email(trim($str));
}
foreach(explode(',', $str) as $email)
{
if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE)
{
return FALSE;
}
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Validate IP Address
*
* @access public
* @param string
* @return string
*/
function valid_ip($ip)
{
return $this->CI->input->valid_ip($ip);
}
// --------------------------------------------------------------------
/**
* Alpha
*
* @access public
* @param string
* @return bool
*/
function alpha($str)
{
return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Alpha-numeric
*
* @access public
* @param string
* @return bool
*/
function alpha_numeric($str)
{
return ( ! preg_match("/^([a-z0-9])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Alpha-numeric with underscores and dashes
*
* @access public
* @param string
* @return bool
*/
function alpha_dash($str)
{
return ( ! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Numeric
*
* @access public
* @param string
* @return bool
*/
function numeric($str)
{
return (bool)preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
}
// --------------------------------------------------------------------
/**
* Is Numeric
*
* @access public
* @param string
* @return bool
*/
function is_numeric($str)
{
return ( ! is_numeric($str)) ? FALSE : TRUE;
}
// --------------------------------------------------------------------
/**
* Integer
*
* @access public
* @param string
* @return bool
*/
function integer($str)
{
return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str);
}
// --------------------------------------------------------------------
/**
* Is a Natural number (0,1,2,3, etc.)
*
* @access public
* @param string
* @return bool
*/
function is_natural($str)
{
return (bool)preg_match( '/^[0-9]+$/', $str);
}
// --------------------------------------------------------------------
/**
* Is a Natural number, but not a zero (1,2,3, etc.)
*
* @access public
* @param string
* @return bool
*/
function is_natural_no_zero($str)
{
if ( ! preg_match( '/^[0-9]+$/', $str))
{
return FALSE;
}
if ($str == 0)
{
return FALSE;
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Valid Base64
*
* Tests a string for characters outside of the Base64 alphabet
* as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
*
* @access public
* @param string
* @return bool
*/
function valid_base64($str)
{
return (bool) ! preg_match('/[^a-zA-Z0-9\/\+=]/', $str);
}
// --------------------------------------------------------------------
/**
* Prep data for form
*
* This function allows HTML to be safely shown in a form.
* Special characters are converted.
*
* @access public
* @param string
* @return string
*/
function prep_for_form($data = '')
{
if (is_array($data))
{
foreach ($data as $key => $val)
{
$data[$key] = $this->prep_for_form($val);
}
return $data;
}
if ($this->_safe_form_data == FALSE OR $data === '')
{
return $data;
}
return str_replace(array("'", '"', '<', '>'), array("&#39;", "&quot;", '&lt;', '&gt;'), stripslashes($data));
}
// --------------------------------------------------------------------
/**
* Prep URL
*
* @access public
* @param string
* @return string
*/
function prep_url($str = '')
{
if ($str == 'http://' OR $str == '')
{
return '';
}
if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://')
{
$str = 'http://'.$str;
}
return $str;
}
// --------------------------------------------------------------------
/**
* Strip Image Tags
*
* @access public
* @param string
* @return string
*/
function strip_image_tags($str)
{
return $this->CI->input->strip_image_tags($str);
}
// --------------------------------------------------------------------
/**
* XSS Clean
*
* @access public
* @param string
* @return string
*/
function xss_clean($str)
{
return $this->CI->input->xss_clean($str);
}
// --------------------------------------------------------------------
/**
* Convert PHP tags to entities
*
* @access public
* @param string
* @return string
*/
function encode_php_tags($str)
{
return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('&lt;?php', '&lt;?PHP', '&lt;?', '?&gt;'), $str);
}
}
// END Form Validation Class
/* End of file Form_validation.php */
/* Location: ./system/libraries/Form_validation.php */
\ No newline at end of file
......@@ -4,9 +4,11 @@ h3.table-caption { padding:0; margin:25px 0 0px 0; }
.post-success {
padding:10px;
font-size: 12px;
background: #ffffcc;
color:#88c550;
background: #88c550;
color:#fff;
}
.post-success a { color:#fff; text-decoration: underline;}
.post-success a:hover { color:#3b0d32; text-decoration: none; }
table.expandable thead th {
cursor:pointer;
......@@ -33,4 +35,10 @@ table.expandable thead.open th.toggle h6 {
#ui-timepicker-div { margin: 0px 10px; }
#ui-timepicker-div dl{ text-align: left; }
#ui-timepicker-div dl dt{ height: 25px; font-size: 11px; }
#ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; font-size: 11px; }
\ No newline at end of file
#ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; font-size: 11px; }
.post-errors { border:1px solid red; background: pink;}
.post-errors-title { padding: 8px 10px; color:#fff; background: red; font: italic 16px/18px Georgia,"Times New Roman","Bitstream Charter",Times,serif;}
.post-errors-content { padding:10px; color:red; margin:0;}
.lblError { font: italic 11px/16px Georgia,"Times New Roman","Bitstream Charter",Times,serif; color: red;}
\ No newline at end of file
......
......@@ -20,6 +20,14 @@ use Tz\WordPress\Tools;
<?php echo $flash; ?>
</div>
<?php endif; ?>
<?php if($validation->validation_errors() != "" || isset($form_error)):?>
<div class="post-errors">
<div class="post-errors-title"><strong>Oops.</strong> There was an error saving your notification.</div>
<?php if (isset($form_error)):?>
<p class="post-errors-content">You must include either an Email, System or SMS message.</p>
<?php endif; ?>
</div>
<?php endif;?>
<form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications-create-new">
......@@ -37,16 +45,17 @@ use Tz\WordPress\Tools;
<td width="150">Notification Type</td>
<td>
<select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();">
<option value="scheduled">Scheduled Notification</option>
<option value="scheduled" <?php echo ($validation->set_value('type')=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<option value="triggered">System Triggered Notification</option>
<option value="triggered" <?php echo ($validation->set_value('type')=="triggered") ? 'selected="selected"' : "";?>>System Triggered Notification</option>
<?php endif; ?>
</select>
<?php echo $validation->form_error('type');?>
</td>
</tr>
<tr>
<td width="150">Notification Description</td>
<td><input type="text" name="title" class="wide-input-field" /></td>
<td><input type="text" name="title" class="wide-input-field" value="<?php echo $validation->set_value('title');?>" /><?php echo $validation->form_error('title');?></td>
</tr>
<tr>
<td>Sent To:</td>
......@@ -60,17 +69,18 @@ use Tz\WordPress\Tools;
<option value="group3">Group 3</option>
</optgroup>
</select>
<?php echo $validation->form_error('sendto');?>
</td>
</tr>
<tr class="scheduled-extended">
<td>Execute Date / Time</td>
<td><input type="text" name="execute_date" id="execute_date" class="wide-input-field date-pick" readonly="readonly" /></td>
<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>
</tr>
<tr class="trigger-extended">
<td>Trigger</td>
<td><input type="text" name="trigger" id="trigger" class="wide-input-field" /></td>
<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>
</tr>
</tbody>
......@@ -83,18 +93,18 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody>
<tbody style="<?php echo ($validation->set_value('subject')!="" || $validation->set_value('text')!="" || $validation->set_value('html')!="") ? "" : "display:none";?>;">
<tr>
<td width="150">Subject Line</td>
<td><input type="text" name="subject" class="wide-input-field" style="width:100%;" /></td>
<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>
</tr>
<tr>
<td>Text Version</td>
<td><textarea name="text" class="wide-input-field" rows="10" style="width:100%;" ></textarea></td>
<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>
</tr>
<tr>
<td>HTML Version (optional)</td>
<td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"></textarea></td>
<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>
</tr>
<tr>
<td width="150">Attachments</td>
......@@ -118,10 +128,10 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody>
<tbody style="<?php echo ($validation->set_value('system')=="") ? "display:none" : "";?>;">
<tr>
<td>Message (Text/HTML)</td>
<td><textarea name="system" class="wide-input-field" rows="4" style="width:100%;" ></textarea></td>
<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>
</tr>
</tbody>
</table>
......@@ -133,10 +143,10 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody>
<tbody style="<?php echo ($validation->set_value('sms')=="") ? "display:none" : "";?>;">
<tr>
<td>Text Only!</td>
<td><textarea name="sms" class="wide-input-field" rows="4" style="width:100%;" ></textarea></td>
<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>
</tr>
</tbody>
</table>
......@@ -163,7 +173,7 @@ jQuery(document).ready(function() {
updateNotificationType();
jQuery('table.expandable tbody').hide();
//jQuery('table.expandable tbody').hide();
jQuery('table.expandable thead th').click(function() {
var $table = jQuery(this).parent().parent().parent();
if ( jQuery('tbody',$table).is(":visible") ) {
......
<?php
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
?>
<!-- jQuery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<!-- required plugins -->
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/date.js', __FILE__)?>"></script>
<!--[if IE]><script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.bgiframe.js', __FILE__)?>"></script><![endif]-->
<!-- jquery.datePicker.js -->
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery.datePicker.js', __FILE__)?>"></script>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/datePicker.css', __FILE__)?>" />
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
<div id="" class="wrap">
<h2>Notifications - Create New</h2>
<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>
<form method="post" action="/wp-admin/admin.php?page=notification&action=create">
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th width="150">Notification Details</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr>
<td width="150">Description</td>
<td><input type="text" name="" class="wide-input-field" /></td>
</tr>
<tr>
<td>Notification Type</td>
<td>
<select name="" class="wide-input-field">
<option value="instant">Instant</option>
<option value="queued">Batch Queue</option>
<option value="system">System</option>
</select>
</td>
</tr>
<tr>
<td>Sent To:</td>
<td>
<select name="" class="wide-input-field">
<option value="user">Current User</option>
<option value="user">All Users</option>
<optgroup label="Groups:">
<option value="group1">Administrators</option>
<option value="group2">Group 2</option>
<option value="group3">Group 3</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td>Trigger/Slug</td>
<td><input type="text" name="" class="wide-input-field" /></td>
</tr>
<tr>
<td>Execute Date / Time</td>
<td><input type="text" name="" class="wide-input-field date-pick" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th width="150">Notification Content</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr>
<td width="150">Subject Line</td>
<td><input type="text" name="" class="wide-input-field" style="width:100%;" /></td>
</tr>
<tr>
<td>Text Version</td>
<td><textarea class="wide-input-field" rows="10" style="width:100%;" ></textarea></td>
</tr>
<tr>
<td>HTML Version (optional)</td>
<td><textarea class="wide-input-field" rows="10" style="width:100%;"></textarea></td>
</tr>
</tbody>
</table>
<p>
<input type="submit" value=" Save " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
</p>
</form>
</div>
<script type="text/javascript">
$(function()
{
$('.date-pick').datePicker();
});
</script>
\ No newline at end of file
<?php
use Tz\WordPress\Tools\Notifications\Settings;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
?>
<link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
<div id="" class="wrap">
<h2>Notifications - Edit</h2>
<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>
<?php if (isset($flash) && $flash !=""): ?>
<div class="post-success">
<?php echo $flash; ?>
</div>
<?php endif; ?>
<?php if($validation->validation_errors() != "" || isset($form_error)):?>
<div class="post-errors">
<div class="post-errors-title"><strong>Oops.</strong> There was an error saving your notification.</div>
<?php if (isset($form_error)):?>
<p class="post-errors-content">You must include either an Email, System or SMS message.</p>
<?php endif; ?>
</div>
<?php endif;?>
<form enctype="multipart/form-data" method="post" action="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $_GET['page_id']?>">
<input type="hidden" name="_POSTED_" value="yes" />
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th width="150">Notification Details</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr>
<td width="150">Notification Type</td>
<td>
<select name="type" id="notif_type" class="wide-input-field" onchange="updateNotificationType();">
<option value="scheduled" <?php echo ($validation->set_value('type',$entry->details['type'])=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<option value="triggered" <?php echo ($validation->set_value('type',$entry->details['type'])=="triggered") ? 'selected="selected"' : "";?>>System Triggered Notification</option>
<?php endif; ?>
</select>
<?php echo $validation->form_error('type');?>
</td>
</tr>
<tr>
<td width="150">Notification Description</td>
<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>
</tr>
<tr>
<td>Sent To:</td>
<td>
<select name="sendto" class="wide-input-field">
<option value="user" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="user") ? 'selected="selected"' : "";?>>Current User</option>
<option value="allusers" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="allusers") ? 'selected="selected"' : "";?>>All Users</option>
<optgroup label="Groups:">
<option value="group1" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group1") ? 'selected="selected"' : "";?>>Administrators</option>
<option value="group2" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group2") ? 'selected="selected"' : "";?>>Group 2</option>
<option value="group3" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])=="group3") ? 'selected="selected"' : "";?>>Group 3</option>
</optgroup>
</select>
<?php echo $validation->form_error('sendto');?>
</td>
</tr>
<tr class="scheduled-extended">
<td>Execute Date / Time</td>
<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>
</tr>
<tr class="trigger-extended">
<td>Trigger</td>
<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>
</tr>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
<th width="150" class="toggle"><h6>Email</h6></th>
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<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";?>;">
<tr>
<td width="150">Subject Line</td>
<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>
</tr>
<tr>
<td>Text Version</td>
<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>
</tr>
<tr>
<td>HTML Version (optional)</td>
<td><textarea name="html" id="htmlversion" class="wide-input-field" rows="10" style="width:100%;"><?php echo $validation->set_value('html',$entry->email['html']);?></textarea><?php echo $validation->form_error('html');?></td>
</tr>
<tr>
<td width="150">Attachments</td>
<td><input type="file" name="attachment[]" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
<th width="150" class="toggle"><h6>System Message</h6></th>
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('system',$entry->system)=="") ? "display:none" : "";?>;">
<tr>
<td>Message (Text/HTML)</td>
<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>
</tr>
</tbody>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
<th width="150" class="toggle"><h6>SMS</h6></th>
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('sms',$entry->sms)=="") ? "display:none" : "";?>;">
<tr>
<td>Text Only!</td>
<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>
</tr>
</tbody>
</table>
<p>
<input type="submit" value=" Update " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
</p>
</form>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
$('#execute_date').datetimepicker({
stepMinute: 15
, dateFormat: 'yy-mm-dd'
, timeFormat: 'hh:mm:ss'
});
updateNotificationType();
//jQuery('table.expandable tbody').hide();
jQuery('table.expandable thead th').click(function() {
var $table = jQuery(this).parent().parent().parent();
if ( jQuery('tbody',$table).is(":visible") ) {
jQuery('thead',$table).removeClass("open");
jQuery('tbody',$table).fadeOut();
} else {
jQuery('thead',$table).addClass("open");
jQuery('tbody',$table).fadeIn();
}
});
});
function updateNotificationType() {
var type = jQuery('#notif_type').val();
if (type=="triggered") {
jQuery('.scheduled-extended').hide();
jQuery('.trigger-extended').show();
} else {
jQuery('.scheduled-extended').show();
jQuery('.trigger-extended').hide();
}
}
</script>
\ No newline at end of file
<?php
use Tz\WordPress\Tools\Notifications\Settings;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
register_settings
?>
<link type="text/css" href="<?php echo Tools\url('assets/css/smoothness/jquery-ui-1.8.4.custom.css', __FILE__)?>" rel="stylesheet" />
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-1.4.2.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/jquery-ui-1.8.4.custom.min.js', __FILE__)?>"></script>
<script type="text/javascript" src="<?php echo Tools\url('assets/scripts/datetimepicker.js', __FILE__)?>"></script>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
<div id="" class="wrap">
<h2>Notifications - Settings</h2>
<p>In order to comply with the CAN-SPAM act, each outgoing email must include the following:</p>
<form enctype="multipart/form-data" method="post" action="options.php">
<input type="hidden" name="_POSTED_" value="yes" />
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th width="150">CAN-SPAM Settings</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr>
<td width="150">Company Name:</td>
<td><input type="text" name="company" class="wide-input-field" /></td>
</tr>
<tr>
<td width="150">Address:</td>
<td><input type="text" name="address" class="wide-input-field" /></td>
</tr>
<tr>
<td width="150">Apt/Unit/Suite:</td>
<td><input type="text" name="address2" class="wide-input-field" /></td>
</tr>
<tr>
<td width="150">City:</td>
<td><input type="text" name="city" class="wide-input-field" /></td>
</tr>
<tr>
<td width="150">Province:</td>
<td>
<select name="province" class="wide-input-field" >
<option value="Ontario">Ontario</option>
<option value="Quebec">Quebec</option>
<option value="Nova Scotia">Nova Scotia</option>
<option value="New Brunswick">New Brunswick</option>
<option value="Manitoba">Manitoba</option>
<option value="British Columbia">British Columbia</option>
<option value="Prince Edward Island">Prince Edward Island</option>
<option value="Saskatchewan">Saskatchewan</option>
<option value="Alberta">Alberta</option>
<option value="Newfoundland and Labrador">Newfoundland and Labrador</option>
</select>
</td>
</tr>
<tr>
<td width="150">Postal Code:</td>
<td><input type="text" name="postal" /></td>
</tr>
</body>
</table>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th width="150">CAN-SPAM Messages</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<tr>
<td width="150">Standard Message:</td>
<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>
</tr>
<tr>
<td width="150">OPT-OUT Message::</td>
<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>
</tr>
</body>
</table>
<p>
<input type="submit" value=" Update " />
</p>
</form>
</div>
\ No newline at end of file