Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 231
0.00% covered (danger)
0.00%
0 / 8
CRAP
n/a
0 / 0
zeroBSCRM_notifyme_scripts
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_notify_me
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_notifyme_settings
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_notifyme_echo_type
0.00% covered (danger)
0.00%
0 / 96
0.00% covered (danger)
0.00%
0 / 1
1190
zeroBSCRM_notifyme_time_ago
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
42
zeroBSCRM_notifyme_insert_notification
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_notifyme_activity
0.00% covered (danger)
0.00%
0 / 58
0.00% covered (danger)
0.00%
0 / 1
42
zeroBSCRM_notifyme_get_notifications_ajax
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/*
3 * Jetpack CRM - Notify Me
4 * https://jetpackcrm.com
5 * V2.4
6 *
7 * Copyright 2020 Automattic
8 *
9 * Date: 11/02/18
10 *
11 */
12
13defined( 'ZEROBSCRM_PATH' ) || exit( 0 );
14
15/*
16================================================================================================================
17 *
18 * This is the "notify me" plugin from the plugin hunt theme. Written very similar to IA when I wrote it
19 * already has lots of useful things like:-
20 * - settings page for notifications per WP users (disabled for now)
21 * - browser push notifications for UNREAD notifications
22 * have built it in so it does our stuff (upsell stuff + marketing for free)
23 * - for INTERNAL team stuff, suggest building the TEAM notifications PRO and include things like @mentions
24 * - will write notifications system to also check a JSON file where we can post them notifications from external
25 * - e.g. JSON(ID: message) and it marks them as read, then if we want to notify the installs, we can do that ;)
26 * - the EXTENRAL updates is what the 'zbsnotify_reference_id' is for
27 *
28 * ================================================================================================================ */
29
30function zeroBSCRM_notifyme_scripts() {
31    global $zbs;
32    wp_enqueue_script( 'jquery' );
33    wp_enqueue_script( 'notifyme-front', ZEROBSCRM_URL . 'js/jpcrm-notifyme-front' . wp_scripts_get_suffix() . '.js', array( 'jquery' ), $zbs::VERSION ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
34    wp_enqueue_style( 'notifyme-css', ZEROBSCRM_URL . 'css/jpcrm-notifyme-front' . wp_scripts_get_suffix() . '.css', array(), $zbs::VERSION );
35
36    #} this does the browser notifications
37    wp_register_script( 'notifyme_push', ZEROBSCRM_URL . 'build/lib/push.js/push.min.js', array(), $zbs::VERSION, true );
38    wp_enqueue_script( 'notifyme_push' );
39
40    #} this stores things in cookies, so not to keep notifying
41    wp_register_script( 'notifyme_cookie', ZEROBSCRM_URL . 'build/lib/js-cookie/js.cookie.min.js', array(), $zbs::VERSION, true );
42    wp_enqueue_script( 'notifyme_cookie' );
43
44    #} this is the browser notification icon.
45    $notify_logo = jpcrm_get_logo();
46
47    #} this is which user to notify for..
48    $cid = get_current_user_id();
49
50    #} we want to browser notify our users :-)
51    $notification_meta = array( 'browser_push' => 1 );
52
53    $args = array(
54        'ph_notify_logo'        => $notify_logo,
55        'current_user'          => $cid,
56        'notification_nonce'    => wp_create_nonce( 'notifyme_nonce' ),
57        'notification_settings' => $notification_meta,
58        'ajaxurl'               => admin_url( 'admin-ajax.php' ),
59    );
60    wp_localize_script( 'notifyme_push', 'notifyme', $args );
61}
62add_action( 'zbs-global-admin-styles', 'zeroBSCRM_notifyme_scripts' );
63
64// ADD ANY CORE FUNCTIONS FOR THE PLUGIN HERE
65function zeroBSCRM_notify_me() {
66    global $zbs;
67
68    // jQuery fills in the number in the bubble..
69    if ( is_user_logged_in() && zeroBSCRM_permsNotify() ) {
70        $url = zeroBSCRM_getAdminURL( $zbs->slugs['notifications'] );
71        echo "<a id='notty' class='item' href='" . esc_url( $url ) . "'><span class='notifyme' id='notifymebell'><i class='fa fa-bell'></i></span></a>";
72
73    }
74}
75#} this is the action to add the notification icon to the new admin top menu
76add_action( 'zbs-crm-notify', 'zeroBSCRM_notify_me' );
77
78#} can put actual settings in here later (for now just have it notify them regardless).
79function zeroBSCRM_notifyme_settings() {}
80
81function zeroBSCRM_notifyme_echo_type( $type = '', $title = '', $sender = -999, $content = '' ) {
82
83    global $zbs;
84
85    switch ( $type ) {
86
87        case 'migration.blocked.errors':
88            esc_html_e( 'There has been a general error with CRM migrations, a single migration appears to be blocked. Please contact support.', 'zero-bs-crm' );
89            break;
90
91        case 'woosync.suggestion':
92            esc_html_e( '🎯 we have detected that you are running WooCommerce. We have a kick ass extension for that. ', 'zero-bs-crm' );
93            break;
94
95        case 'salesdash.suggestion':
96            echo esc_html( __( '⛽ See all your sales information in a sales dashboard built just for you.', 'zero-bs-crm' ) . ' ' );
97            break;
98
99        case 'notifications.suggestion':
100            echo wp_kses( sprintf( __( '🔔 Want notifications PRO? This is coming soon to our <a href="%s" target="_blank">Entrepreneur Bundle</a>. Get it while it\'s hot!', 'zero-bs-crm' ), esc_url( $zbs->urls['upgrade'] ) ), $zbs->acceptable_restricted_html ) . ' ';
101            break;
102
103        case 'extension.update':
104            ##WLREMOVE
105            echo wp_kses( sprintf( __( '🔔 [URGENT] Your extension(s) need updating <a href="%1$s" target="_blank">Click here to retrieve the new versions</a>. (If you don\'t know your login, please <a href="%2$s" target="_blank">Email Support</a>.)', 'zero-bs-crm' ), esc_url( $zbs->urls['account'] ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
106            ##/WLREMOVE
107            break;
108
109        // v2.70 - DB2 contacts migration :)
110        case 'db2.update.253':
111            echo esc_html( sprintf( __( '🔔 [URGENT] Your Contact Database needs migrating. Running this database update will increase your CRM load-times by up to 60x!', 'zero-bs-crm' ) ) );
112            break;
113
114        // v2.70 - DB2 contacts migration :) FINI
115        case 'db2.update.253.success':
116            echo wp_kses( sprintf( __( 'Your contact database was successfully migrated. Please update any <a href="%s" target="_blank">PRO Extensions</a> you may have installed.', 'zero-bs-crm' ), esc_url( $zbs->urls['products'] ) ), $zbs->acceptable_restricted_html );
117            break;
118
119        // v2.70 - DB2 contacts migration :) FINI
120        case 'db2.update.253.errors':
121                // load errs
122                $zbsMigrationErrors = get_option( 'zbs_db_migration_253_errors', -1 );
123                $errStr             = '';
124            if ( isset( $zbsMigrationErrors ) && is_array( $zbsMigrationErrors ) ) {
125                foreach ( $zbsMigrationErrors as $zme ) {
126                    $errStr .= '<br />' . $zme;
127                }
128            }
129
130            printf( __( 'Jetpack CRM has tried to update your core CRM to 2.70 but hit errors. Please send the following error report to Support:<hr /><strong>Migration Error Report:</strong>%1$s</hr> <a href="%2$s" target="_blank">Contact Support</a>', 'zero-bs-crm' ), $errStr, esc_url( $zbs->urls['support'] ) );
131            break;
132
133        // v2.70 - DB2 contacts migration :) FINI + has extensions to update
134        case 'db2.extupdate.253':
135            ##WLREMOVE
136            echo wp_kses( sprintf( __( 'Please Update your Extensions (DB Migration makes this essential!) <a href="%s">View Extension Updates</a>', 'zero-bs-crm' ), jpcrm_esc_link( $zbs->slugs['connect'] ) ), $zbs->acceptable_restricted_html );
137            ##/WLREMOVE
138            break;
139
140        case 'extension.new.update.avail':
141            ##WLREMOVE
142            echo wp_kses( sprintf( __( '🔔 One or more of your extensions need updating. Please update to avoid any issues with security or compatibility <a href="%s">Learn More</a>.', 'zero-bs-crm' ), esc_url( admin_url( 'admin.php?page=zerobscrm-connect' ) ) ), $zbs->acceptable_restricted_html );
143            ##/WLREMOVE
144            break;
145
146        case 'license.update.needed':
147            echo '⚠️ ' . $content;
148            break;
149
150        case 'general.extension.update.needed':
151            echo '⚠️ ' . $content;
152            break;
153
154        // 2.94.2 - smtp mode changed, need to tell peeps to revalidate
155        case 'smtp.2943.needtocheck':
156            printf( __( 'Important: 🔔 Jetpack CRM has just updated the way it handles SMTP Delivery Methods.<br />Please check each of your Delivery Methods still works by loading <a href="%s">Mail Delivery Methods</a> and clicking \'send test\', validating that it still sends', 'zero-bs-crm' ), esc_url( admin_url( 'admin.php?page=zerobscrm-plugin-settings&tab=maildelivery' ) ) );
157            break;
158
159        // 3.0.17 - Changed the password encryption, so get people to validate
160        case 'smtp.3017.needtocheck':
161            printf( __( 'Important: 🔔 Jetpack CRM has improved the encryption of SMTP passwords.<br />Please check each of your Delivery Methods still works by loading <a href="%s">Mail Delivery Methods</a> and clicking \'send test\', validating that it still sends', 'zero-bs-crm' ), jpcrm_esc_link( $zbs->slugs['settings'] . '&tab=maildelivery' ) );
162            break;
163
164        // now do the extension updates like this
165
166        case 'custom.extension.update.needed':
167            $x = __( '🔔', 'zero-bs-crm' ) . $content . ' <a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">' . __( 'Update Now', 'zero-bs-crm' ) . '</a>.';
168
169            ##WLREMOVE
170            $x = __( '🔔', 'zero-bs-crm' ) . $content . ' <a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">' . __( 'Update Now', 'zero-bs-crm' ) . '</a>.';
171            ##/WLREMOVE
172            echo $x;
173            break;
174        // now do the extension updates like this
175        // this is WL CORE update
176        case 'core.update.needed':
177            echo esc_html__( '🔔', 'zero-bs-crm' ) . $content . ' <a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">' . esc_html__( 'Update Now', 'zero-bs-crm' ) . '</a>.';
178
179            break;
180
181        // 4.5.0 - Missing template file
182        case 'missing.template':
183            echo wp_kses( __( 'Template File Error:<br /> It was not possible to load the following template file. This will mean that related documents will not be loaded properly.<br/>Template File: ', 'zero-bs-crm' ), $zbs->acceptable_restricted_html ) . $content;
184            break;
185
186        // ========= v5+ MIGRATIONS
187
188        // v5.1 - migrate woosync sites
189        case 'woosync.5.1.migration':
190            echo esc_html__( 'WooSync was unable to migrate settings (5.2). Sync will be stopped until this is remedied.', 'zero-bs-crm' ) . ' ' . wp_kses( sprintf( __( 'Please <a href="%s" target="_blank">contact support</a>.', 'zero-bs-crm' ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
191
192            break;
193        // ========= / v5+ MIGRATIONS
194
195        // =========  Exceptions seen
196
197        // Segment audience tried to build but some conditions produced no arguments
198        // (likely segment created with adv segments active, then adv segments been deactivated)
199        case 'segments.orphaned.conditions':
200            echo esc_html__( '⚠️ A segment was retrieved which has conditions which produced no arguments. (This usually happens when a segment was made via Advanced Segments extension, then that extension is deactivated). Please reactivate any segment extending plugins you have, or contact support.', 'zero-bs-crm' );
201            break;
202
203        // ========= / Exceptions seen
204
205        // =========   MC2
206        case 'campaign.paused.due.to.error':
207            echo esc_html__( 'A mail campaign has been paused due to an error.', 'zero-bs-crm' ) . '&nbsp;&nbsp;&nbsp;&nbsp;' . $content;
208
209            break;
210        case 'campaign.can.be.unpaused':
211            echo esc_html__( 'A mail campaign which was previously blocked from sending by an error is now able to send. Please unpause the campaign to continue to send.', 'zero-bs-crm' ) . '&nbsp;&nbsp;&nbsp;&nbsp;' . $content;
212
213            break;
214        // ========= / MC2
215
216        // =========   WooSync
217        case 'woosync.conflict.deactivated':
218            echo wp_kses( sprintf( __( 'Your standalone WooSync extension has been deactivated; WooSync is now in the core CRM! <a href="%s" target="_blank">Read more</a>', 'zero-bs-crm' ), esc_url( $zbs->urls['v5announce'] ) ), $zbs->acceptable_restricted_html );
219
220            break;
221        case 'woosync.syncsite.paused':
222            echo wp_kses( sprintf( __( 'Your WooSync Store connection has been paused due to three errors in connecting to the store. <a href="%s" target="_blank">View Connections</a>', 'zero-bs-crm' ), esc_url( $content ) ), $zbs->acceptable_restricted_html );
223
224            break;
225        // ========= / WooSync
226
227        // =========   Client Portal Pro
228        case 'clientportalpro.incompatible.version.deactivated':
229            echo esc_html__( 'You are using an outdated version of the Client Portal Pro extension, which is not compatible with this version of the CRM. It has been deactivated. Please update the extension to continue using Client Portal Pro.', 'zero-bs-crm' );
230
231            break;
232        // ========= / Client Portal Pro
233
234        // =========   Package Installer
235        case 'package.installer.fail_count_over':
236            echo sprintf( __( 'Package Installer was not able to install the requested package %s, after trying the maximum number of times.', 'zero-bs-crm' ), $content ) . wp_kses( sprintf( __( ' Please <a href="%s" target="_blank">contact support</a>.', 'zero-bs-crm' ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
237
238            break;
239        case 'package.installer.dir_create_error':
240            echo sprintf( __( 'Package Installer could not create directories needed to install the package %s.', 'zero-bs-crm' ), $content ) . wp_kses( sprintf( __( ' Please <a href="%s" target="_blank">contact support</a>.', 'zero-bs-crm' ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
241
242            break;
243        case 'package.installer.unzip_error':
244            echo sprintf( __( 'Package Installer was not able to expand the requested package zip file for the package %s', 'zero-bs-crm' ), $content ) . wp_kses( sprintf( __( ' Please <a href="%s" target="_blank">contact support</a>.', 'zero-bs-crm' ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
245
246            break;
247        case 'package.installer.dl_error':
248            echo sprintf( __( 'Package Installer was not able to download the requested package %s', 'zero-bs-crm' ), $content ) . wp_kses( sprintf( __( ' Please <a href="%s" target="_blank">contact support</a>.', 'zero-bs-crm' ), esc_url( $zbs->urls['support'] ) ), $zbs->acceptable_restricted_html );
249
250            break;
251        case 'curl.timeout.error':
252            printf( __( 'Failed to retrieve key file, your server may not be able to connect to the CRM CDN: %s. If this message persists, please contact support', 'zero-bs-crm' ), $content );
253
254            break;
255        // ========= / Package Installer
256
257        default:
258            esc_html_e( 'Unable to load notification.', 'zero-bs-crm' );
259    }
260}
261
262function zeroBSCRM_notifyme_time_ago( $datetime ) {
263    if ( is_numeric( $datetime ) ) {
264        $timestamp = $datetime;
265    } else {
266        $timestamp = strtotime( $datetime );
267    }
268    $diff = time() - $timestamp;
269
270    $min   = 60;
271    $hour  = 60 * 60;
272    $day   = 60 * 60 * 24;
273    $month = $day * 30;
274
275    if ( $diff < 60 ) {
276        $timeago = $diff . ' seconds';
277    } elseif ( $diff < $hour ) {
278        $timeago = round( $diff / $min ) . ' mins';
279    } elseif ( $diff < $day ) {
280        $timeago = round( $diff / $hour ) . ' hours';
281    } elseif ( $diff < $month ) {
282        $timeago = round( $diff / $day ) . ' days';
283    } else {
284        $timeago = round( $diff / $month ) . ' months';
285    }
286
287    return $timeago;
288}
289
290// function to insert the notification into the database..
291/*
292    $recipient = get_current_user_id(); i.e. WHO are we notifying (WP_user ID)
293    $sender = -999; //in this case...  we can call ZBS our -999 user ID (for bot icon stuff) and output our icon where it's system stuff.
294    $post_id = 0; //i.e. not a post related activity (but can pass $post_id for linking to various pages) - NOT USED
295        ^^ use that in notifications PRO to store edit links for customerID, invoiceID, etc. but with new DB this is effectively the ID of whatever
296    $type = 'woosync.suggestion';   //this is a extension suggestion type, see zeroBSCRM_notifyme_echo_type
297    for the switch / case here. Store the InternalAutomator actions strings here and extend where we want to notify of that..  e.g. 10 new leads have been added since you last logged in.
298
299    /* DOESN'T DO
300
301    - GROUPING of similar notifications. If you do have it to notify on new customer it will show a notification line for each and every one. Rather than "100 new contact since your last visit" it would show [name1 .. name100] has been added as a new conact, 100 times
302
303    - SNOOZING of notifications. They're ALWAYS on.
304
305    // zeroBSCRM_notifyme_insert_notification($recipient,$sender,$post_id,$type);
306
307*/
308function zeroBSCRM_notifyme_insert_notification( $recipient = -1, $sender = -999, $post_id = -1, $type = '', $parameters = '', $reference = -1 ) {
309    global $wpdb;
310    $notify_table = $wpdb->prefix . 'zbs_notifications';
311    $now          = time();
312
313    // * WH NOTE:
314        // ownership needed DBv2+
315        // no need to update these (as of yet) - can't move teams etc.
316        // 'zbs_site' => zeroBSCRM_installSite(),
317        // 'zbs_team' => zeroBSCRM_installTeam(),
318        // 'zbs_owner' => $owner,
319    // OWNER was not_null so I've added -1 for now :) to add these 3 when makes sense
320
321    #} only stores if the recipient is NOT the user
322    if ( $recipient != $sender ) {
323
324        // need to check first whether the reference ID already exists (add with a UNIQUE REFERENCEID going forwards)
325
326        // "parameters" here is really the content of the notification... $reference is the unique ID
327        // added new "type" of custom.extension.update.needed
328
329        // if $parameters is empty seems to bug out :) so forcing it to be smt if empty:
330        if ( empty( $parameters ) ) {
331            $parameters = '-1';
332        }
333        if ( empty( $type ) ) {
334            $type = '-1';
335        }
336
337        $sql     = $wpdb->prepare( "SELECT id FROM $notify_table WHERE zbsnotify_reference_id = %d AND zbsnotify_parameters = %s", $reference, $parameters );
338        $results = $wpdb->get_results( $sql );
339
340        if ( count( $results ) == 0 ) {
341                $sql = $wpdb->prepare( "INSERT INTO $notify_table ( zbs_owner, zbsnotify_recipient_id , zbsnotify_sender_id, zbsnotify_unread, zbsnotify_type, zbsnotify_parameters, zbsnotify_reference_id, zbsnotify_created_at) VALUES ( %d, %d, %d, %d, %s, %s, %d, %s)", -1, $recipient, $sender, '0', $type, $parameters, $reference, $now );
342                $wpdb->query( $sql );
343        }
344    }
345}
346
347function zeroBSCRM_notifyme_activity() {
348    global $wpdb;
349    $cid = get_current_user_id();
350
351    // * WH NOTE:
352        // ownership needed DBv2+
353        // no need to update these (as of yet) - can't move teams etc.
354        // 'zbs_site' => zeroBSCRM_installSite(),
355        // 'zbs_team' => zeroBSCRM_installTeam(),
356        // 'zbs_owner' => $owner,
357
358        $notify_table = $wpdb->prefix . 'zbs_notifications';
359        $sql          = $wpdb->prepare( "SELECT * FROM $notify_table WHERE zbsnotify_recipient_id = %d ORDER BY zbsnotify_created_at DESC LIMIT 20", $cid );
360        $notifes      = $wpdb->get_results( $sql );
361
362        echo '<div class="ph_notification_list_wrap ui segment" id="notification-list" style="margin-right:30px;">';
363
364    if ( count( $notifes ) == 0 ) {
365
366        // EXAMPLE NOTIFICATION - FOR THE TOUR :-)
367        $notify_logo_url = jpcrm_get_logo();
368
369        $sender_avatar = "<img src='" . $notify_logo_url . "'  width='30px;float:left;'>";
370
371        $another_notty = __( 'Here is another notification example from John Doe.', 'zero-bs-crm' );
372
373        echo "<div class='ph_notification_list r0' id='mike-face' style='display:none;'>";
374        echo '<div class="ph_noti_img">';
375            echo "<img src='" . esc_url( ZEROBSCRM_URL ) . "i/defaultDude.jpeg' width='30px;float:left;'>";
376        echo '</div>';
377        echo '<div class="ph_noti_message">';
378        echo esc_html( $another_notty );
379        echo '</div>';
380        echo '<div class="ph_noti_timeago">';
381            esc_html_e( 'Just now', 'zero-bs-crm' );
382        echo '</div>';
383        echo '</div>';
384        echo '<div class="clear"></div>';
385
386        echo "<div class='ph_notification_list r0' id='first-example'>";
387        echo '<div class="ph_noti_img">';
388            echo $sender_avatar;
389        echo '</div>';
390        echo '<div class="ph_noti_message">';
391            esc_html_e( 'This is an example notification. Here is where you will be kept notified :) simple. effective.', 'zero-bs-crm' );
392        echo '</div>';
393        echo '<div class="ph_noti_timeago">';
394            esc_html_e( 'Just now', 'zero-bs-crm' );
395        echo '</div>';
396        echo '</div>';
397
398    } else {
399
400        foreach ( $notifes as $n ) {
401
402            $title  = ''; // can pass specific title to the echo function
403            $sender = $n->zbsnotify_sender_id;
404
405            if ( $sender == -999 ) {
406                // this is our "ZBS notifications bot". This sniffs around WP checking everything is OK.. and also lets
407                // them know about any updates we have pinged out from our own JSON file on https:// :-) ... POW ERRRR FULL
408                $notify_logo_url = jpcrm_get_logo();
409                $sender_avatar   = "<img src='" . $notify_logo_url . "'  width='30px;float:left;'>";
410            } else {
411                $sender_avatar = jpcrm_get_avatar( $n->zbsnotify_sender_id, 30 );
412            }
413
414            $sender_url = '';
415            if ( isset( $n ) && isset( $n->sender_id ) ) {
416                $sender_url = get_author_posts_url( $n->sender_id );
417            }
418
419            echo "<div class='ph_notification_list r" . esc_attr( $n->zbsnotify_unread ) . "'>";
420            echo '<div class="ph_noti_img">';
421            echo $sender_avatar;
422            echo '</div>';
423            echo '<div class="ph_noti_message">';
424            zeroBSCRM_notifyme_echo_type( $n->zbsnotify_type, $title, $n->zbsnotify_sender_id, $n->zbsnotify_parameters );
425            echo '</div>';
426            echo '<div class="ph_noti_timeago">';
427            esc_html_e( zeroBSCRM_notifyme_time_ago( $n->zbsnotify_created_at ) . ' ago ', 'zero-bs-crm' );
428            echo '</div>';
429            echo '</div>';
430            echo '<div class="clear"></div>';
431
432        }
433
434        echo '</div>';
435
436    }
437
438        // got here. Mark the notifications as read for this user :-)
439        $sql = $wpdb->prepare( "UPDATE $notify_table SET zbsnotify_unread = %d WHERE zbsnotify_recipient_id = %d", 1, $cid );
440        $wpdb->query( $sql );
441}
442
443add_action( 'wp_ajax_nopriv_notifyme_get_notifications_ajax', 'zeroBSCRM_notifyme_get_notifications_ajax' );
444add_action( 'wp_ajax_notifyme_get_notifications_ajax', 'zeroBSCRM_notifyme_get_notifications_ajax' );
445function zeroBSCRM_notifyme_get_notifications_ajax() {
446    global $wpdb;
447    $res = array();
448        check_ajax_referer( 'notifyme_nonce', 'security' );
449        $cid          = get_current_user_id();
450        $now          = date( 'U' );
451        $notify_table = $wpdb->prefix . 'zbs_notifications';
452
453        // * WH NOTE:
454            // ownership needed DBv2+
455            // no need to update these (as of yet) - can't move teams etc.
456            // 'zbs_site' => zeroBSCRM_installSite(),
457            // 'zbs_team' => zeroBSCRM_installTeam(),
458            // 'zbs_owner' => $owner,
459
460        $sql          = $wpdb->prepare( "SELECT * FROM $notify_table WHERE zbsnotify_recipient_id = %d AND zbsnotify_unread = %d", $cid, 0 );
461        $notifes      = $wpdb->get_results( $sql );
462        $res['count'] = 0;
463
464        $res['notifications'] = $notifes;
465    if ( ! $notifes ) {
466        $res['count'] = 0;
467    } else {
468        $res['message']     = 'Passed AJAX nonce check';
469        $res['notifytitle'] = 'This is the title';
470        $res['notifybody']  = 'This is the body';
471        $res['count']       = count( $res['notifications'] );
472    }
473    wp_send_json( $res );
474}