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,7 +259,33 @@ function create_notification() {
global $wpdb;
if ($_POST && isset($_POST['_POSTED_']) && $_POST['_POSTED_']=="yes") {
// 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) {
// ok, so now we need to create the notification.
class postTemplate {
......@@ -211,12 +352,13 @@ function create_notification() {
add_post_meta($id, "sms", $sms);
$flash = "Notification Saved Successfully!";
$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');
}
}
}
......@@ -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');
}
});
......
......@@ -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;
......@@ -34,3 +36,9 @@ table.expandable thead.open th.toggle h6 {
#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; }
.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;
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