Notifications.php
4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Tz\WordPress\Tools\Notifications;
use Tz\WordPress\Tools;
use Tz\Common;
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');
}
});
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_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';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
class Vars {
public static $options;
public static $field_lookup = array(
'current_user' => "Current Logged-in User"
, 'allusers' => "All Users"
);
}
?>