caa49320 by Marty Penner

Clean up a few files and translate a few strings

1 parent 67e5f6dc
<?php
namespace Tz\WordPress\Tools\Notifications\Settings;
//error_reporting(E_ALL^E_DEPRECATED);
use Tz\WordPress\Tools;
use Tz\Common;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Validation;
const CAPABILITY = "manage_notifications";
const MANAGE_SYSTEM_NOTIFICATIONS = "create_system_notifications";
const SETTING_NS = 'canspam_settings';
const ADMIN_PAGE = "canspam_admin";
const CAPABILITY = 'manage_notifications';
const MANAGE_SYSTEM_NOTIFICATIONS = 'create_system_notifications';
const SETTING_NS = 'canspam_settings';
const ADMIN_PAGE = 'canspam_admin';
call_user_func(function() {
call_user_func(
function () {
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
$role->add_cap(MANAGE_SYSTEM_NOTIFICATIONS);
//$role->remove_cap(SUB_ADMIN_CAPABILITY);
Vars::$settings = new Tools\WP_Option(SETTING_NS);
Tools\add_actions(__NAMESPACE__ . '\Actions');
});
function display_page() {
Tools\add_actions(__NAMESPACE__.'\Actions');
}
);
function display_page()
{
if (isset($_GET['action']) && $_GET['action']=="edit") {
if (isset($_GET['action']) && $_GET['action'] == "edit") {
/** @var \wpdb $wpdb */
global $wpdb;
/** @var \StdClass $entry */
$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);
$details = get_post_meta($id, 'details', true);
$email = get_post_meta($id, 'email', true);
$system = get_post_meta($id, 'system', true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
// here
$validation = new Notifications\Validation;
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('title','Description','trim|required|min_length[4]');
$validation->set_rules('type','Notification Type','required');
$validation->set_rules('sendto','Send To','required');
$validation->set_rules('type', 'Notification Type', 'required');
$validation->set_rules('title', 'Description', 'trim|required|min_length[4]');
$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);
$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('trigger', 'Trigger', $trigger_val);
$validation->set_rules('system_message_type','System Message Type','trim');
$validation->set_rules('system','System Message','trim|min_length[16]');
$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_message_type', 'System Message Type', 'trim');
$validation->set_rules('system', 'System Message', 'trim|min_length[16]');
//details
if ($validation->run() == TRUE) {
if ($validation->run() == true) {
// Clean up data before saving
Tools\tzClean($_POST);
$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'];
$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__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'notifications' . DIRECTORY_SEPARATOR;
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = [];
$upload_dir = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'notifications'.DIRECTORY_SEPARATOR;
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']);
if ($file['name'] != "") {
move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']);
$attachments[] = $file['name'];
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
update_post_meta($id, 'notif_type', $type);
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
update_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
, 'status' => $entry->details['status']
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
update_post_meta($id,'send_status',$entry->details['status']);
if ( count( $entry->email['attachments'] ) > 0 ) {
update_post_meta(
$id,
"details",
[
'type' => $type,
'sendto' => $sendto,
'status' => $entry->details['status'],
'trigger' => $trigger,
'execute_date' => $execute_date
]
);
update_post_meta($id, 'send_status', $entry->details['status']);
if (count($entry->email['attachments']) > 0) {
$attachments = array_merge($entry->email['attachments'], $attachments);
}
update_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
, 'html' => $html
, 'attachments' => $attachments
));
update_post_meta($id, "system", array(
'system_message_type' => $system_message_type
, 'message' => $system
));
$update = array();
$update['ID'] = $id;
update_post_meta(
$id,
'email',
[
'subject' => $subject,
'text' => $text,
'html' => $html,
'attachments' => $attachments
]
);
update_post_meta(
$id,
'system',
[
'system_message_type' => $system_message_type,
'message' => $system
]
);
$update = [];
$update['ID'] = $id;
$update['post_title'] = $title;
wp_update_post($update);
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$details = get_post_meta($id, 'details', true);
$email = get_post_meta($id, 'email', true);
$system = get_post_meta($id, 'system', true);
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$entry->details = $details;
$entry->email = $email;
$entry->system = $system;
$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');
require_once(__DIR__.'/views/form.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'form.php');
require_once(__DIR__.'/views/form.php');
}
} else {
if (isset($_GET['action']) && $_GET['action']=="delete") {
wp_delete_post($_GET['page_id'],true);
} elseif (isset($_GET['action']) && $_GET['action']=="archive") {
if (isset($_GET['action']) && $_GET['action'] == "delete") {
wp_delete_post($_GET['page_id'], true);
} elseif (isset($_GET['action']) && $_GET['action'] == "archive") {
$id = $_GET['page_id'];
$postdata = get_post_meta($id,'details',true);
$postdata = get_post_meta($id, 'details', true);
$postdata['status'] = "archived";
update_post_meta($id,'details',$postdata);
update_post_meta($id,'send_status',$postdata['status']);
update_post_meta($id, 'details', $postdata);
update_post_meta($id, 'send_status', $postdata['status']);
}
// get all the notifications that status != "archived";
$notifications = array();
$notifications['triggered'] = array();
$notifications['scheduled'] = array();
$args = array(
'post_type' => 'notifications'
, 'numberposts' => -1
, 'orderby' => 'modified'
, 'order' => 'desc'
, 'meta_key' => 'send_status'
, 'meta_compare' => '='
, 'meta_value' => 'pending'
);
$notifications = [];
$notifications['triggered'] = [];
$notifications['scheduled'] = [];
$args = [
'post_type' => 'notifications',
'numberposts' => -1,
'orderby' => 'modified',
'order' => 'desc',
'meta_key' => 'send_status',
'meta_compare' => '=',
'meta_value' => 'pending'
];
$entries = get_posts($args);
foreach($entries as $entry) {
foreach ($entries as $entry) {
$id = $entry->ID;
$details = get_post_meta($id,'details',true);
$email = get_post_meta($id,'email',true);
$system = get_post_meta($id,'system',true);
$details = get_post_meta($id, 'details', true);
$email = get_post_meta($id, 'email', true);
$system = get_post_meta($id, 'system', true);
$entry->trigger = $details['trigger'];
$entry->status = isset($details['status']) ? $details['status'] : "active";
$entry->type = $details['type'];
$entry->sendto = $details['sendto'];
$entry->trigger = $details['trigger'];
$entry->status = isset($details['status']) ? $details['status'] : "active";
$entry->type = $details['type'];
$entry->sendto = $details['sendto'];
$entry->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false;
$entry->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$entry->is_email = (($email['text'] != '' || $email['html'] != '')) ? true : false;
$entry->is_system = (isset($system['message']) && $system['message'] != '') ? true : false;
$entry->execute_date = $details['execute_date'];
$entry->execute_date = $details['execute_date'];
if ($entry->status != "archived") {
if ($entry->status != 'archived') {
$notifications[$entry->type][] = $entry;
}
}
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin.php');
require_once(__DIR__.'/views/admin.php');
}
}
function mysqldatetime_to_timestamp($datetime = "")
/**
* @param string $datetime
*
* @return int
*/
function mysqldatetime_to_timestamp($datetime = '')
{
// function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters)
$l = strlen($datetime);
if(!($l == 10 || $l == 19))
return 0;
// function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters)
$l = strlen($datetime);
if (!($l == 10 || $l == 19)) {
return 0;
}
//
$date = $datetime;
$hours = 0;
$date = $datetime;
$hours = 0;
$minutes = 0;
$seconds = 0;
// DATETIME only
if($l == 19)
{
list($date, $time) = explode(" ", $datetime);
list($hours, $minutes, $seconds) = explode(":", $time);
if ($l == 19) {
list($date, $time) = explode(" ", $datetime);
list($hours, $minutes, $seconds) = explode(":", $time);
}
list($year, $month, $day) = explode("-", $date);
......@@ -240,13 +245,16 @@ function mysqldatetime_to_timestamp($datetime = "")
return mktime($hours, $minutes, $seconds, $month, $day, $year);
}
/**
* @param $files
*/
function fixFilesArray(&$files)
{
$names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1);
$names = ['name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1];
foreach ($files as $key => $part) {
// only deal with valid keys and multiple files
$key = (string) $key;
$key = (string)$key;
if (isset($names[$key]) && is_array($part)) {
foreach ($part as $position => $value) {
$files[$position][$key] = $value;
......@@ -257,94 +265,90 @@ function fixFilesArray(&$files)
}
}
function notification_settings()
{
function notification_settings() {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'settings.php');
require_once(__DIR__.'/views/settings.php');
}
function create_notification() {
function create_notification()
{
/** @var \wpdb $wpdb */
global $wpdb;
// 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');
$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);
$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('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('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('system', 'System Message', 'trim|min_length[16]');
if ($_POST && ($_POST['subject']=="" && $_POST['system']=="")) {
if ($_POST && ($_POST['subject'] == '' && $_POST['system'] == '')) {
$form_error = true;
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
require_once(__DIR__.'/views/create.php');
} else {
if ($validation->run() == TRUE) {
if ($validation->run() == true) {
// Clean up the data before saving
Tools\tzClean($_POST);
// 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';
class postTemplate
{
var $post_title = '';
var $post_content = '';
var $post_status = 'publish';
var $post_type = 'notifications';
var $comment_status = 'closed';
}
//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'];
$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/";
$subject = $_POST['subject'];
$text = $_POST['text'];
$html = $_POST['html'];
$attachments = [];
$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']);
if ($file['name'] != "") {
move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']);
$attachments[] = $file['name'];
}
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
// 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());
$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);
......@@ -352,71 +356,88 @@ function create_notification() {
update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($execute_date));
update_post_meta($id, 'trigger', $trigger);
add_post_meta($id, "details", array(
'type' => $type
, 'sendto' => $sendto
, 'status' => 'pending'
, 'trigger' => $trigger
, 'execute_date' => $execute_date
));
update_post_meta($id,'send_status','pending');
add_post_meta($id, "email", array(
'subject' => $subject
, 'text' => $text
, 'html' => $html
, 'attachments' => $attachments
));
update_post_meta($id, "system", array(
'system_message_type' => $system_message_type
, 'message' => $system
));
add_post_meta(
$id,
"details",
[
'type' => $type,
'sendto' => $sendto,
'status' => 'pending',
'trigger' => $trigger,
'execute_date' => $execute_date
]
);
update_post_meta($id, 'send_status', 'pending');
add_post_meta(
$id,
"email",
[
'subject' => $subject,
'text' => $text,
'html' => $html,
'attachments' => $attachments
]
);
update_post_meta(
$id,
"system",
[
'system_message_type' => $system_message_type,
'message' => $system
]
);
$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');
require_once(__DIR__.'/views/create.php');
} else {
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'create.php');
require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php');
}
}
}
class Actions {
class Actions
{
public static function init() {
public static function init()
{
/** @var \wpdb $wpdb */
global $wpdb;
$wpdb->show_errors();
register_post_type( 'notifications', array(
'label' => __('Notifs')
, 'public' => true
, 'show_ui' => false
, 'hierarchical' => false
, 'exclude_from_search' => true
));
register_post_type(
'notifications',
[
'label' => __('Notifs', CBV_DOMAIN),
'public' => true,
'show_ui' => false,
'hierarchical' => false,
'exclude_from_search' => true
]
);
}
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_options_page('CAN-SPAM Settings', 'CAN-SPAM Settings', CAPABILITY, ADMIN_PAGE, __NAMESPACE__ . '\notification_settings');
//add_submenu_page('notifications','CAN-SPAM Settings', 'CAN-SPAM Settings',CAPABILITY,'notifications-settings',__NAMESPACE__ . '\notification_settings');
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'
);
}
public function admin_init() {
// register_setting(Notifications\OPTION_NAME, Notifications\OPTION_NAME);
register_setting(SETTING_NS, SETTING_NS);
public function admin_init()
{
register_setting(SETTING_NS, SETTING_NS);
}
}
class Vars {
class Vars
{
public static $settings;
}
?>
\ No newline at end of file
......
......@@ -23,12 +23,24 @@ call_user_func(
}
);
/**
* @param $a
* @param $subkey
* @param $sort
*
* @return array
*/
function subval_sort($a, $subkey, $sort)
{
$b = [];
$c = [];
foreach ($a as $k => $v) {
$b[$k] = strtolower($v[$subkey]);
}
$sort($b);
foreach ($b as $key => $val) {
$c[] = $a[$key];
}
......@@ -36,6 +48,9 @@ function subval_sort($a, $subkey, $sort)
return $c;
}
/**
* @param $uid
*/
function get_user_notices($uid)
{
$notices = get_user_meta($uid, 'notices', true);
......@@ -45,6 +60,9 @@ function get_user_notices($uid)
}
}
/**
* @param bool $showOnlyUnread
*/
function print_user_notices($showOnlyUnread = false)
{
$user = new User\CurrentAccount();
......@@ -65,7 +83,15 @@ function print_user_notices($showOnlyUnread = false)
if (isset($notice['args']) && count($notice['args']) > 0) {
foreach ($notice['args'] as $key => $val) {
if (filter_var($val, FILTER_VALIDATE_URL) !== false) {
$content = str_replace('{'.$key.'}', "<a href='".$val."'>Click here</a>", $content);
$content = str_replace(
'{'.$key.'}',
"<a href='"
.$val
."'>"
.__('Click here', CBV_DOMAIN)
.'</a>',
$content
);
} else {
$content = str_replace('{'.$key.'}', $val, $content);
}
......@@ -75,7 +101,7 @@ function print_user_notices($showOnlyUnread = false)
$rows .= '<tr class="notice-row" id="'.$index.'">';
$rows .= '<td width="12" style="padding: 0 0 0 10px; vertical-align: middle;"><a href="javascript:;" class="notice '
.(($notice['status'] == 'read') ? 'read' : 'unread')
.'"><img src="assets/images/blank.gif" width="12" height="12"></a></td>';
.'"><img src="/wp-content/themes/cbv/assets/images/blank.gif" style="width: 12px; height: 12px;"></a></td>';
if ($system['system_message_type'] == 'none') {
$system['system_message_type'] = 'notice';
......@@ -84,8 +110,9 @@ function print_user_notices($showOnlyUnread = false)
$rows .= '<td width="80" style="vertical-align:middle;"><span>'
.ucfirst(str_replace('_', '&nbsp;', $system['system_message_type']))
.'</span></td>';
$rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">Sent: '
.date('M j, Y @ h:ia', $notice['sent_date']).'</span></td>';
$rows .= '<td style="vertical-align:middle;">'.nl2br($content).'<br /><span class="legal">'
.__('Sent:', CBV_DOMAIN)
.CBV\tz_display('notice_sent_date', $notice['sent_date']).'</span></td>';
$rows .= '</tr>';
}
......@@ -96,6 +123,11 @@ function print_user_notices($showOnlyUnread = false)
}
}
/**
* @param $trigger
*
* @return bool
*/
function get_notification_by_trigger($trigger)
{
$args = [
......@@ -119,8 +151,9 @@ function get_notification_by_trigger($trigger)
}
/**
* GET NUMBER OF NEW NOTICES
* @returns (Int)
* Get number of new notices
*
* @return int
*/
function get_num_notices()
{
......@@ -166,11 +199,21 @@ function markNotice($notification_id = -1, $status = NOTIFICATION_STATUS_READ)
/**
* Send Notifications
*
* @trigger = notification unique slug name
*
* @param int $uid
* @param string $trigger
* @param array $args
*
* @throws \Exception
*/
function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [], $send_override = false)
function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args = [])
{
/** @var \wpdb $wpdb */
global $wpdb;
/** @var \StdClass $notification */
$notification = get_notification_by_trigger($trigger);
if ($notification) {
......@@ -181,13 +224,13 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
$system = get_post_meta($nid, 'system', true);
$notification->trigger = $details['trigger'];
$notification->status = isset($details['status']) ? $details['status'] : "active";
$notification->status = isset($details['status']) ? $details['status'] : 'active';
$notification->type = $details['type'];
$notification->sendto = @$details['sendto'];
$notification->is_email = (($email['text'] != "" || $email['html'] != "") && $email['subject'] != "")
$notification->is_email = (($email['text'] != '' || $email['html'] != '') && $email['subject'] != '')
? true
: false;
$notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$notification->is_system = (isset($system['message']) && $system['message'] != '') ? true : false;
// if is_system ==========================================
if ($notification->is_system && $uid != 0) {
......@@ -311,15 +354,20 @@ function send_triggered_notification($uid = 0, $trigger = "NO_TRIGGER", $args =
);
}
}
// if the system notification has set current user than get current user otherwise loop through the users needed.
}
/**
* @param int $grpID
*
* @return array
*/
function getGroups($grpID = 0)
{
global $userAccessManager;
$groups = [];
if ($grpID > 0) {
/** @var \UamUserGroup $userGroups */
$userGroups = $userAccessManager
->getAccessHandler()
->getUserGroups($grpID);
......@@ -330,6 +378,8 @@ function getGroups($grpID = 0)
->getAccessHandler()
->getUserGroups();
}
/** @var \UamUserGroup $group */
foreach ($userGroups as $group) {
$groups[$group->getId()] = $group->getGroupName();
}
......@@ -337,22 +387,30 @@ function getGroups($grpID = 0)
return $groups;
}
/**
* @param $var
*
* @return mixed
*/
function get_field_lookup($var)
{
return isset(Vars::$field_lookup[$var]) ? Vars::$field_lookup[$var] : $var;
}
/**
* @return string
*/
function current_url()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
if ($_SERVER['HTTPS'] == 'on') {
$pageURL .= 's';
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
$pageURL .= '://';
if ($_SERVER['SERVER_PORT'] != '80') {
$pageURL .= $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$pageURL .= $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
return $pageURL;
......
<?php
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\Settings;
use Tz\WordPress\Tools;
/*
print "<pre>";
print_r($notifications);
print "</pre>";
*/
?>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__)?>" />
<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.qtip-1.0.0-rc3.js', __FILE__)?>"></script>
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
<script src="<?php echo Tools\url('assets/scripts/jquery.qtip-1.0.0-rc3.js', __FILE__) ?>"></script>
<div id="" class="wrap">
<h2>Notifications</h2>
<h3 class="table-caption">Scheduled Notifications</h3>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
......@@ -34,73 +24,80 @@ print "</pre>";
</tr>
</thead>
<tbody>
<?php foreach($notifications['scheduled'] as $entry):
<?php foreach ($notifications['scheduled'] as $entry):
$sendto = $entry->sendto;
if(is_numeric($sendto)) {
$sendto = Notifications\getGroups($sendto) . " Group";
if (is_numeric($sendto)) {
$sendto = Notifications\getGroups($sendto)." Group";
} else {
$sendto = Notifications\get_field_lookup($sendto);
$sendto = Notifications\get_field_lookup($sendto);
}
?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<td><?php echo date("M j, Y @ h:i A",strtotime($entry->execute_date)); ?></td>
<td><?php echo ucwords($sendto); ?></td>
<td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td>
<?php
if (strtotime($entry->execute_date) > current_time('timestamp')):?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
| <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a></td>
<?php else: ?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> | <em>In progress....</em>
<?php endif; ?>
</tr>
?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<td><?php echo date("M j, Y @ h:i A", strtotime($entry->execute_date)); ?></td>
<td><?php echo ucwords($sendto); ?></td>
<td><?php if ($entry->is_email): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif;?></td>
<td>
<?php
if (strtotime($entry->execute_date) > current_time('timestamp')):?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
| <a
href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>"
onclick="return confirm('Are you sure?');">delete</a></td>
<?php else: ?>
<a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a> |
<em>In progress....</em>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<h3 class="table-caption">System Triggered Notifications</h3>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
<th scope="col" class="manage-column">Description</th>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<th scope="col" width="200" class="manage-column">Trigger/Slug</th>
<th scope="col" width="200" class="manage-column">Trigger/Slug</th>
<?php endif; ?>
<th scope="col" width="60" class="manage-column">Email</th>
<th scope="col" width="60" class="manage-column">System</th>
<th scope="col" width="200" class="manage-column">&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach($notifications['triggered'] as $entry):?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<td><?php echo $entry->trigger; ?></td>
<?php endif; ?>
<td><?php if ($entry->is_email): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><?php if ($entry->is_system): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td><a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
| <a href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>" onclick="return confirm('Are you sure?');">delete</a>
<?php endif; ?>
</td>
</tr>
<?php foreach ($notifications['triggered'] as $entry): ?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<td><?php echo $entry->trigger; ?></td>
<?php endif; ?>
<td><?php if ($entry->is_email): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td>
<td><?php if ($entry->is_system): ?><img
src="<?php echo Tools\url('assets/images/accept.png', __FILE__) ?>" /><?php endif; ?></td>
<td><a href="/wp-admin/admin.php?page=notifications&action=edit&page_id=<?php echo $entry->ID; ?>">edit</a>
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
| <a
href="/wp-admin/admin.php?page=notifications&action=delete&page_id=<?php echo $entry->ID; ?>"
onclick="return confirm('Are you sure?');">delete</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
\ No newline at end of file
......
<?php
use Tz\WordPress\Tools\Notifications\Settings;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools\Notifications\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">
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
<div class="wrap">
<h2>Notifications - Create New</h2>
<?php if (isset($flash) && $flash !=""): ?>
<div class="post-success">
<?php echo $flash; ?>
</div>
<?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; ?>
<?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">
<input type="hidden" name="_POSTED_" value="yes" />
<input type="hidden" name="_POSTED_" value="yes"/>
<table cellspacing="0" class="widefat post fixed" style="margin-top:15px;">
<thead>
<tr>
......@@ -44,48 +38,67 @@ use Tz\WordPress\Tools;
<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')=="scheduled") ? 'selected="selected"' : "";?>>Scheduled Notification</option>
<select name="type" id="notif_type" class="wide-input-field"
onchange="updateNotificationType();">
<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" <?php echo ($validation->set_value('type')=="triggered") ? 'selected="selected"' : "";?>>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');?>
<?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');?>" /><?php echo $validation->form_error('title');?></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 class="scheduled_sendto">
<td>Sent To:</td>
<td>
<select name="sendto" class="wide-input-field">
<option value="allusers" <?php echo ($validation->set_value('sendto')=="allusers") ? 'selected="selected"' : "";?>>All Users</option>
<optgroup label="By Group:">
<?php foreach(Notifications\getGroups() as $group_id => $group_name):?>
<option value="<?php echo $group_id?>" <?php echo ($validation->set_value('sendto')==$group_id) ? 'selected="selected"' : "";?>><?php echo $group_name;?></option>
<?php endforeach; ?>
</optgroup>
</select>
<?php echo $validation->form_error('sendto');?>
<select name="sendto" class="wide-input-field">
<option value="allusers" <?php echo ($validation->set_value('sendto') == "allusers")
? 'selected="selected"' : ""; ?>>All Users
</option>
<optgroup label="By Group:">
<?php foreach (Notifications\getGroups() as $group_id => $group_name): ?>
<option value="<?php echo $group_id ?>" <?php echo ($validation->set_value(
'sendto'
) == $group_id) ? 'selected="selected"'
: ""; ?>><?php echo $group_name; ?></option>
<?php endforeach; ?>
</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');?>" /><?php echo $validation->form_error('execute_date');?></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" value="<?php echo $validation->set_value('trigger');?>" /><?php echo $validation->form_error('trigger');?></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>
</table>
<table cellspacing="0" class="widefat post fixed expandable" style="margin-top:15px;">
<thead>
<tr>
......@@ -93,34 +106,45 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('subject')!="" || $validation->set_value('text')!="" || $validation->set_value('html')!="") ? "" : "display:none";?>;">
<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%;" value="<?php echo $validation->set_value('subject');?>" /><?php echo $validation->form_error('subject');?></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%;" ><?php echo $validation->set_value('text');?></textarea><?php echo $validation->form_error('text');?></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%;"><?php echo $validation->set_value('html');?></textarea><?php echo $validation->form_error('html');?></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>
<td><input type="file" name="attachment[]" /></td>
<td><input type="file" name="attachment[]"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></td>
<td><input type="file" name="attachment[]"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="file" name="attachment[]" /></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>
......@@ -128,78 +152,83 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('system')=="") ? "display:none" : "";?>;">
<tbody style="<?php echo ($validation->set_value('system') == "") ? "display:none" : ""; ?>;">
<tr>
<td>Message Type</td>
<td>
<select name="system_message_type" class="wide-input-field">
<option value="none" <?php echo ($validation->set_value('system_message_type')=="none") ? 'selected="selected"' : "";?>>General Message</option>
<option value="action_required" <?php echo ($validation->set_value('system_message_type')=="action_required") ? 'selected="selected"' : "";?>>Action Required</option>
<option value="e-flash" <?php echo ($validation->set_value('system_message_type')=="e-flash") ? 'selected="selected"' : "";?>>E-Flash</option>
<option value="new_event" <?php echo ($validation->set_value('system_message_type')=="new_event") ? 'selected="selected"' : "";?>>New Event</option>
<option value="none" <?php echo ($validation->set_value('system_message_type') == "none")
? 'selected="selected"' : ""; ?>>General Message
</option>
<option value="action_required" <?php echo ($validation->set_value(
'system_message_type'
) == "action_required") ? 'selected="selected"' : ""; ?>>Action Required
</option>
<option value="e-flash" <?php echo ($validation->set_value(
'system_message_type'
) == "e-flash") ? 'selected="selected"' : ""; ?>>E-Flash
</option>
<option value="new_event" <?php echo ($validation->set_value(
'system_message_type'
) == "new_event") ? 'selected="selected"' : ""; ?>>New Event
</option>
</select>
</td>
</tr>
<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');?></textarea><?php echo $validation->form_error('system');?></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>
<p>
<input type="submit" value=" Save " /><input type="button" value=" Cancel " onclick="document.location.href='/wp-admin/admin.php?page=notifications';" />
<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">
</div>
<script>
jQuery(document).ready(function () {
jQuery('#execute_date').datetimepicker({
stepMinute: 30,
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm:ss'
});
jQuery(document).ready(function() {
updateNotificationType();
$('#execute_date').datetimepicker({
stepMinute: 30
, dateFormat: 'yy-mm-dd'
, timeFormat: 'hh:mm:ss'
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();
}
});
});
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();
function updateNotificationType() {
var type = jQuery('#notif_type').val();
if (type == "triggered") {
jQuery('.scheduled-extended').hide();
jQuery('.scheduled_sendto').hide();
jQuery('.trigger-extended').show();
} else {
jQuery('thead',$table).addClass("open");
jQuery('tbody',$table).fadeIn();
jQuery('.scheduled-extended').show();
jQuery('.trigger-extended').hide();
jQuery('.scheduled_sendto').show();
}
});
});
function updateNotificationType() {
var type = jQuery('#notif_type').val();
if (type=="triggered") {
jQuery('.scheduled-extended').hide();
jQuery('.scheduled_sendto').hide();
jQuery('.trigger-extended').show();
} else {
jQuery('.scheduled-extended').show();
jQuery('.trigger-extended').hide();
jQuery('.scheduled_sendto').show();
}
}
</script>
\ No newline at end of file
......
......@@ -6,7 +6,7 @@ use Tz\WordPress\Tools\Notifications\Settings;
<link rel="stylesheet" href="<?php echo Tools\url('assets/css/notifications.css', __FILE__) ?>"/>
<div id="" class="wrap">
<div class="wrap">
<h2>Notifications - Edit</h2>
<?php if (isset($flash) && $flash != ''): ?>
......