33f056a9 by Kevin Burton

notification updates

1 parent ecce9470
......@@ -66,6 +66,9 @@ function display_page() {
//details
if ($validation->run() == TRUE) {
$type = $_POST['type'];
$title = $_POST['title'];
$sendto = $_POST['sendto'];
......@@ -174,8 +177,8 @@ function display_page() {
$entry->sendto = $details['sendto'];
$entry->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false;
$entry->is_system = ($system != "") ? true : false;
$entry->is_sms = ($sms != "") ? true : false;
$entry->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$entry->is_sms = (isset($sms['message']) && $sms['message'] != "") ? true : false;
$entry->execute_date = $details['execute_date'];
......@@ -324,6 +327,7 @@ function create_notification() {
}
// system
$system_message_type = $_POST['system_message_type'];
$system = $_POST['system'];
// SMS
......@@ -353,8 +357,13 @@ function create_notification() {
, 'html' => $html
, 'attachments' => $attachments
));
add_post_meta($id, "system", $system);
add_post_meta($id, "sms", $sms);
update_post_meta($id, "system", array(
'system_message_type' => $system_message_type
, 'message' => $system
));
update_post_meta($id, "sms", array(
'message' => $sms
));
$flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>";
......
......@@ -16,15 +16,118 @@ const OPTION_NAME = "notif_options";
});
function get_notification_by_trigger($trigger) {
$args = array(
'post_type' => 'notifications'
, 'numberposts' => -1
, 'orderby' => 'modified'
, 'order' => 'desc'
);
$my_notif = false;
foreach(get_posts($args) as $entry) {
$details = get_post_meta($entry->ID,'details',true);
if ($details['type']=="triggered" && $details['trigger'] == $trigger) {
$my_notif = $entry;
break;
}
}
return $my_notif;
}
/**
Send Notifications
@trigger = notification unique slug name
*/
function send_notification($trigger="NO_TRIGGER") {
function send_triggered_notification($uid,$trigger="NO_TRIGGER",$args = array()) {
$notification = get_notification_by_trigger($trigger);
if($notification) {
// get the user and user details....
$user = Tools\getCurrentUser();
$notify_me = get_user_meta($user->ID,'notify_me',true);
$notify_format = get_user_meta($user->ID,'notify_format',true);
$email = get_user_meta($user->ID,'email_address_preference',true);
$cell = get_user_meta($user->ID,'home_mobile',true);
// get the notification and notificatio details....
$nid = $notification->ID;
$details = get_post_meta($nid,'details',true);
$email = get_post_meta($nid,'email',true);
$system = get_post_meta($nid,'system',true);
$sms = get_post_meta($nid,'sms',true);
$notification->trigger = $details['trigger'];
$notification->status = isset($details['status']) ? $details['status'] : "active";
$notification->type = $details['type'];
$notification->sendto = $details['sendto'];
$notification->is_email = (($email['text'] != "" || $email['html'] != "")) ? true : false;
$notification->is_system = (isset($system['message']) && $system['message'] != "") ? true : false;
$notification->is_sms = (isset($sms['message']) && $sms['message'] != "") ? true : false;
// if is_sms =============================================
if ($notification->is_sms && $notify_me && !empty($cell)) {
}
// if is_system ==========================================
if ($notification->is_system) {
$notices = get_user_meta($user->ID,'notices',false);
if(!is_array($notices)) {
$notices = array();
}
$insert = array(
'notification_id' => $nid
, 'status' => 'show'
, 'sent_date' => time()
, 'args' => $args
);
$notices[] = $insert;
update_user_meta($user->ID,'notices',$notices);
}
// if is_email ===========================================
if ($notification->is_email && $notify_me) {
}
} else {
die('no notification');
}
// if the system notification has set current user than get current user otherwise loop through the users needed.
}
function getGroups($grpID=0) {
global $userAccessManager;
$groups = array();
if($grpID > 0) {
$userGroups = $userAccessManager->getAccessHandler()->getUserGroups($grpID);
return $userGroups->getGroupName();
} else {
$userGroups = $userAccessManager->getAccessHandler()->getUserGroups();
}
foreach($userGroups as $group) {
$groups[$group->getId()] = $group->getGroupName();
}
return $groups;
}
function get_field_lookup($var) {
return isset(Vars::$field_lookup[$var]) ? Vars::$field_lookup[$var] : $var;
}
function current_url() {
$pageURL = 'http';
......@@ -41,5 +144,9 @@ function current_url() {
class Vars {
public static $options;
public static $field_lookup = array(
'current_user' => "Current Logged-in User"
, 'allusers' => "All Users"
);
}
?>
\ No newline at end of file
......
......@@ -36,21 +36,31 @@ 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";
} else {
$sendto = Notifications\get_field_lookup($sendto);
}
?>
<tr>
<td><?php echo $entry->post_title; ?></td>
<td><?php echo $entry->execute_date; ?></td>
<td><?php echo $entry->sendto; ?></td>
<td><?php echo date("M j, Y @ h:i A",strtotime($entry->execute_date)); ?></td>
<td><?php echo $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 ($entry->is_sms): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
<td>
<?php if (Settings\mysqldatetime_to_timestamp($entry->execute_date) < time()):?>
<a href="/wp-admin/admin.php?page=notifications&action=archive&page_id=<?php echo $entry->ID; ?>">archive</a>
<?php else: ?>
<?php if (strtotime($entry->execute_date) > time()):?>
<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> | <a href="/wp-admin/admin.php?page=notifications&action=archive&page_id=<?php echo $entry->ID; ?>">archive</a>
<?php endif; ?>
</tr>
<?php endforeach; ?>
......@@ -66,7 +76,7 @@ print "</pre>";
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<th scope="col" width="200" class="manage-column">Trigger/Slug</th>
<?php endif; ?>
<th scope="col" width="200" class="manage-column">Send To</th>
<th scope="col" width="60" class="manage-column">Email</th>
<th scope="col" width="60" class="manage-column">System</th>
<th scope="col" width="60" class="manage-column">SMS</th>
......@@ -80,7 +90,7 @@ print "</pre>";
<?php if (current_user_can(Settings\MANAGE_SYSTEM_NOTIFICATIONS)): ?>
<td><?php echo $entry->trigger; ?></td>
<?php endif; ?>
<td><?php echo $entry->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 ($entry->is_sms): ?><img src="<?php echo Tools\url('assets/images/accept.png', __FILE__)?>" /><?php endif;?></td>
......
......@@ -2,6 +2,7 @@
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" />
......@@ -46,6 +47,7 @@ use Tz\WordPress\Tools;
<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>
<?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>
<?php endif; ?>
......@@ -57,16 +59,18 @@ use Tz\WordPress\Tools;
<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>
</tr>
<tr>
<tr class="scheduled_sendto">
<td>Sent To:</td>
<td>
<select name="sendto" class="wide-input-field">
<option value="user">Current User</option>
<option value="allusers">All Users</option>
<optgroup label="Groups:">
<option value="group1">Administrators</option>
<option value="group2">Group 2</option>
<option value="group3">Group 3</option>
<optgroup label="By User:">
<option value="user" <?php echo ($validation->set_value('sendto')=="user") ? 'selected="selected"' : "";?>>Current User</option>
<option value="allusers" <?php echo ($validation->set_value('sendto')=="allusers") ? 'selected="selected"' : "";?>>All Users</option>
</optgroup>
<optgroup label="By User 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');?>
......@@ -130,6 +134,17 @@ use Tz\WordPress\Tools;
</thead>
<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>
</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>
</tr>
......@@ -166,7 +181,7 @@ use Tz\WordPress\Tools;
jQuery(document).ready(function() {
$('#execute_date').datetimepicker({
stepMinute: 15
stepMinute: 30
, dateFormat: 'yy-mm-dd'
, timeFormat: 'hh:mm:ss'
});
......@@ -192,10 +207,12 @@ function updateNotificationType() {
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();
}
}
......
......@@ -57,18 +57,23 @@ use Tz\WordPress\Tools;
<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>
<tr class="scheduled_sendto">
<td>Sent To:</td>
<td>
<select name="sendto" class="wide-input-field">
<optgroup label="By User:">
<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>
<optgroup label="By User Group:">
<?php foreach(Notifications\getGroups() as $group_id => $group_name):?>
<option value="<?php echo $group_id?>" <?php echo ($validation->set_value('sendto',$entry->details['sendto'])==$group_id) ? 'selected="selected"' : "";?>><?php echo $group_name;?></option>
<?php endforeach; ?>
</optgroup>
</select>
<?php echo $validation->form_error('sendto');?>
</td>
</tr>
......@@ -128,21 +133,21 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('system',$entry->system)=="") ? "display:none" : "";?>;">
<tbody style="<?php echo ($validation->set_value('system',$entry->system['message'])=="") ? "display:none" : "";?>;">
<tr>
<td>Message Type</td>
<td>
<select name="system_message_type">
<option value="none" <?php echo ($validation->set_value('system_message_type',$entry->details['system_message_type'])=="none") ? 'selected="selected"' : "";?>>General Message</option>
<option value="action_required" <?php echo ($validation->set_value('system_message_type',$entry->details['system_message_type'])=="action_required") ? 'selected="selected"' : "";?>>Action Required</option>
<option value="eflash" <?php echo ($validation->set_value('system_message_type',$entry->details['system_message_type'])=="eflash") ? 'selected="selected"' : "";?>>E-Flash</option>
<option value="newevent" <?php echo ($validation->set_value('system_message_type',$entry->details['system_message_type'])=="newevent") ? 'selected="selected"' : "";?>>New Event</option>
<select name="system_message_type" class="wide-input-field">
<option value="none" <?php echo ($validation->set_value('system_message_type',$entry->system['system_message_type'])=="none") ? 'selected="selected"' : "";?>>General Message</option>
<option value="action_required" <?php echo ($validation->set_value('system_message_type',$entry->system['system_message_type'])=="action_required") ? 'selected="selected"' : "";?>>Action Required</option>
<option value="e-flash" <?php echo ($validation->set_value('system_message_type',$entry->system['system_message_type'])=="e-flash") ? 'selected="selected"' : "";?>>E-Flash</option>
<option value="new_event" <?php echo ($validation->set_value('system_message_type',$entry->system['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',$entry->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',isset($entry->system['message']) ? $entry->system['message'] : "");?></textarea><?php echo $validation->form_error('system');?></td>
</tr>
</tbody>
</table>
......@@ -154,10 +159,10 @@ use Tz\WordPress\Tools;
<th class="action-bar">&nbsp;</th>
</tr>
</thead>
<tbody style="<?php echo ($validation->set_value('sms',$entry->sms)=="") ? "display:none" : "";?>;">
<tbody style="<?php echo ($validation->set_value('sms',$entry->sms['message'])=="") ? "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>
<td><textarea name="sms" class="wide-input-field" rows="4" style="width:100%;" ><?php echo $validation->set_value('sms',isset($entry->sms['message']) ? $entry->sms['message'] : "");?></textarea><?php echo $validation->form_error('sms');?></td>
</tr>
</tbody>
</table>
......@@ -177,7 +182,7 @@ use Tz\WordPress\Tools;
jQuery(document).ready(function() {
$('#execute_date').datetimepicker({
stepMinute: 15
stepMinute: 30
, dateFormat: 'yy-mm-dd'
, timeFormat: 'hh:mm:ss'
});
......@@ -204,9 +209,11 @@ function updateNotificationType() {
if (type=="triggered") {
jQuery('.scheduled-extended').hide();
jQuery('.trigger-extended').show();
jQuery('.scheduled_sendto').hide();
} else {
jQuery('.scheduled-extended').show();
jQuery('.trigger-extended').hide();
jQuery('.scheduled_sendto').show();
}
}
......