Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 1094
0.00% covered (danger)
0.00%
0 / 42
CRAP
n/a
0 / 0
jpcrm_load_admin_page
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
zeroBSCRM_pages_dash
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_settings
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_systemstatus
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_crmresources
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
jpcrm_pages_support
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_emailbox
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_emailsend
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_admin_your_profile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_admin_reminders
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_admin_view_page_contact
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_add_or_edit_file
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_admin_view_page_company
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
jpcrm_pages_automations
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_update_edit_form
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_post_updated_messages
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_pages_admin_deactivate_error
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_admin_team
0.00% covered (danger)
0.00%
0 / 58
0.00% covered (danger)
0.00%
0 / 1
42
zeroBSCRM_caps_to_nicename
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
90
zeroBSCRM_pages_admin_notifications
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_pages_header
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_footer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_logout
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_pages_home
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_pages_extensions
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
jpcrm_pages_modules
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_pages_admin_system_emails
0.00% covered (danger)
0.00%
0 / 338
0.00% covered (danger)
0.00%
0 / 1
1560
zeroBSCRM_pages_datatools
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_pages_installextensionshelper
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
zeroBSCRM_pages_norights
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
30
zeroBSCRM_html_wlHome
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_html_home2
0.00% covered (danger)
0.00%
0 / 76
0.00% covered (danger)
0.00%
0 / 1
12
zeroBSCRM_html_datatools
0.00% covered (danger)
0.00%
0 / 93
0.00% covered (danger)
0.00%
0 / 1
380
zeroBSCRM_html_installextensionshelper
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extension_installer_promo
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_html_extensions_forWelcomeWizard
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_extensions_init_install
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 1
210
zeroBSCRM_html_extensions
0.00% covered (danger)
0.00%
0 / 210
0.00% covered (danger)
0.00%
0 / 1
1190
jpcrm_html_modules
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 1
306
zeroBSCRM_html_norights
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
42
whStyles_html_msg
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
zeroBSCRM_html_msg
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2/*
3 * Jetpack CRM
4 * https://jetpackcrm.com
5 * V1.20
6 *
7 * Copyright 2020 Automattic
8 *
9 * Date: 16th June 2020
10 */
11
12/*
13======================================================
14    Breaking Checks ( stops direct access )
15    ====================================================== */
16if ( ! defined( 'ZEROBSCRM_PATH' ) ) {
17    exit( 0 );
18}
19/*
20======================================================
21    / Breaking Checks
22    ====================================================== */
23
24/**
25 * Load the file for a given page name
26 *
27 * @param string $page_name The page file name (e.g. `settings/main`)
28 * @param string $alt_path An alternate filepath prefix
29 */
30function jpcrm_load_admin_page( $page_name, $alt_path = ZEROBSCRM_PATH ) {
31
32    $base_dir = realpath( $alt_path . 'admin' );
33
34    if ( $base_dir === false ) {
35        echo wp_kses_post( zeroBSCRM_UI2_messageHTML( 'warning', '', __( 'Could not load the requested page.', 'zero-bs-crm' ) ) );
36        return;
37    }
38
39    $base_dir    = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
40    $target_file = realpath( "{$base_dir}{$page_name}.page.php" );
41
42    // Check if resolved path exists and stays within allowed base directory.
43    if ( $target_file !== false && strpos( $target_file, $base_dir ) === 0 ) {
44        require_once $target_file;
45    } else {
46        echo wp_kses_post( zeroBSCRM_UI2_messageHTML( 'warning', '', __( 'Could not load the requested page.', 'zero-bs-crm' ) ) );
47    }
48}
49
50/*
51======================================================
52    Page loading
53    ====================================================== */
54
55/*
56* Dashboard
57*/
58function zeroBSCRM_pages_dash() {
59    jpcrm_load_admin_page( 'dashboard/main' );
60}
61
62/*
63* Settings page
64*/
65function zeroBSCRM_pages_settings() {
66    jpcrm_load_admin_page( 'settings/main' );
67}
68
69/*
70* System Status page
71*/
72function zeroBSCRM_pages_systemstatus() {
73    jpcrm_load_admin_page( 'system/main' );
74}
75
76/*
77* CRM Resources page
78*/
79function zeroBSCRM_pages_crmresources() {
80    jpcrm_load_admin_page( 'crm-resources/main' );
81}
82
83/**
84 * Load the Support Contact page
85 */
86function jpcrm_pages_support() {
87    jpcrm_load_admin_page( 'support/main' );
88}
89
90// Email Box
91function zeroBSCRM_pages_emailbox() {
92    // load
93    jpcrm_load_admin_page( 'email/main' );
94    // render
95    jpcrm_render_emailbox();
96}
97
98// Single send page (subpage of Emailbox?)
99function zeroBSCRM_pages_emailsend() {
100    // load
101    jpcrm_load_admin_page( 'email/main' );
102    // render
103    zeroBSCRM_pages_admin_sendmail();
104}
105
106// User Profile
107function zeroBSCRM_pages_admin_your_profile() {
108
109    jpcrm_load_admin_page( 'user-profile/main' );
110}
111
112// Reminders
113function zeroBSCRM_pages_admin_reminders() {
114
115    jpcrm_load_admin_page( 'user-profile/reminders' );
116}
117
118/*
119* Contact views:
120*/
121function zeroBSCRM_pages_admin_view_page_contact( $id = -1 ) {
122
123    // load
124    jpcrm_load_admin_page( 'contact/view' );
125    // render
126    jpcrm_render_contact_view_page( $id );
127}
128
129// file add/edit
130function zeroBSCRM_pages_add_or_edit_file() {
131
132    jpcrm_load_admin_page( 'contact/add-file' );
133    zeroBSCRM_render_add_or_edit_file();
134}
135
136/*
137* Company views:
138*/
139function zeroBSCRM_pages_admin_view_page_company( $id = -1 ) {
140
141    // load
142    jpcrm_load_admin_page( 'company/view' );
143    // render
144    jpcrm_render_company_view_page( $id );
145}
146
147/**
148 * Load the Automations admin page
149 *
150 * @return void
151 */
152function jpcrm_pages_automations() {
153    jpcrm_load_admin_page( 'automations/main' );
154}
155
156/*
157======================================================
158    / Page loading
159    ====================================================== */
160
161/*
162======================================================
163    Edit Post - multiform data override (for metaboxes)
164    ====================================================== */
165
166    // } Updated 1.2 so that this only fires on OUR post edit pages
167    // } https://www.rfmeier.net/allow-file-uploads-to-a-post-with-wordpress-post_edit_form_tag-action/
168function zeroBSCRM_update_edit_form() {
169
170    global $post;
171
172    // if invalid $post object, return
173    if ( ! $post ) {
174        return;
175    }
176
177    // get the current post type
178    $post_type = get_post_type( $post->ID );
179
180    // if post type is not 'post', return
181    // if('post' != $post_type)
182    if ( ! in_array( $post_type, array( 'zerobs_customer', 'zerobs_quote', 'zerobs_invoice', 'zerobs_transaction', 'zerobs_company' ) ) ) {
183        return;
184    }
185
186    // echo ' enctype="multipart/form-data"';
187    printf( ' enctype="multipart/form-data" encoding="multipart/form-data" ' );
188}
189    add_action( 'post_edit_form_tag', 'zeroBSCRM_update_edit_form' );
190
191/*
192======================================================
193    / Edit Post - multiform data override (for metaboxes)
194    ====================================================== */
195
196/*
197======================================================
198    / Edit Post Messages (i.e. "Post Updated => Task Updated")
199    / See: http://ryanwelcher.com/2014/10/change-wordpress-post-updated-messages/
200    ====================================================== */
201
202add_filter( 'post_updated_messages', 'zeroBSCRM_post_updated_messages' );
203function zeroBSCRM_post_updated_messages( $messages ) {
204
205    $post             = get_post();
206    $post_type        = get_post_type( $post );
207    $post_type_object = get_post_type_object( $post_type );
208
209    $messages['zerobs_event'] = array(
210        0  => '', // Unused. Messages start at index 1.
211        1  => __( 'Task updated.', 'zero-bs-crm' ),
212        2  => __( 'Custom field updated.', 'zero-bs-crm' ),
213        3  => __( 'Custom field deleted.', 'zero-bs-crm' ),
214        4  => __( 'Task updated.', 'zero-bs-crm' ),
215        /* translators: %s: date and time of the revision */
216        5  => isset( $_GET['revision'] ) ? sprintf( __( 'Task restored to revision from %s', 'zero-bs-crm' ), wp_post_revision_title( (int) sanitize_text_field( $_GET['revision'] ), false ) ) : false, // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
217        6  => __( 'Task saved.', 'zero-bs-crm' ),
218        7  => __( 'Task saved.', 'zero-bs-crm' ),
219        8  => __( 'Task submitted.', 'zero-bs-crm' ),
220        9  => sprintf(
221            __( 'Task scheduled for: <strong>%1$s</strong>.', 'zero-bs-crm' ),
222            // translators: Publish box date format, see http://php.net/date
223            date_i18n( 'M j, Y @ G:i', strtotime( $post->post_date ) )
224        ),
225        10 => __( 'Task updated.', 'zero-bs-crm' ),
226    );
227
228        // you can also access items this way
229        // $messages['post'][1] = "I just totally changed the Updated messages for standards posts";
230
231        // return the new messaging
232    return $messages;
233}
234
235// } Deactivation error page - show if someone tried to deactivate the core with extensions still installed
236function zeroBSCRM_pages_admin_deactivate_error() {
237    ?>
238    <div class='ui segment' style='text-align:center;'>
239        <div style='font-size:60px;padding:30px;'>⚠️</div>
240        <h3><?php esc_html_e( 'Error', 'zero-bs-crm' ); ?></h3>
241        <p style='font-size:18px;'>
242            <?php esc_html_e( 'You have tried to deactivate the Core while extensions are still active. Please de-activate extensions first.', 'zero-bs-crm' ); ?>
243        </p>
244        <p><a class='ui button blue' href="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>">Back to Plugins</a></p>
245    </div>
246    <?php
247}
248
249/**
250 * Team UI page - i.e. to guide vs the wp-users.php
251 * Added this to be able to make it easier for people to add team members to the CRM
252 * Also to control permissions.
253 * WHLOOK - is there a way of us finding out from telemetry how many people are actually using
254 * roles that are like the "customer" only role - as discussed I think our CRM has evolved past this
255 * and we should have users as "CRMTEAM" members, and then "manage permissions" for them (vs the actual specific "role")
256 */
257function zeroBSCRM_pages_admin_team() {
258
259    $crm_role_ids = array();
260    // } User Search...
261    if ( isset( $_POST['jpcrm-search-wp-users'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
262
263        $search   = sanitize_text_field( $_POST['jpcrm-search-wp-users'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.NonceVerification.Missing
264        $users    = new WP_User_Query(
265            array(
266                'search'         => '*' . esc_attr( $search ) . '*',
267                'search_columns' => array(
268                    'user_nicename',
269                    'user_email',
270                ),
271            )
272        );
273        $wp_users = $users->get_results();
274        foreach ( $wp_users as $user ) {
275            $crm_role_ids[] = $user->ID;
276        }
277    } else {
278
279        // Jetpack CRM team roles - tidied since also use in meta tracking
280        $crm_users = zeroBSCRM_crm_users_list();
281        foreach ( $crm_users as $user ) {
282            $crm_role_ids[] = $user->ID;
283        }
284    }
285
286    ?>
287
288    <div class="ui segment zbs-inner-segment">
289    <div id="jpcrm-team-mechanics">
290        <form id="jpcrm-users-search" action="#" method="POST">
291            <div class="ui icon input" style="width:100%;">
292                <input class="prompt" name="jpcrm-search-wp-users" type="text" placeholder="<?php echo esc_html__( 'Search WordPress users...', 'zero-bs-crm' ); ?>">
293                <i class="search icon" id="jpcrm-search-wp-users"></i>
294            </div>
295        </form>
296
297        <a class="ui button black" href="<?php echo esc_url( admin_url( 'user-new.php?zbsslug=zbs-add-user' ) ); ?>">
298            <i class="add icon"></i>
299            <?php esc_html_e( 'Add new team member', 'zero-bs-crm' ); ?>
300        </a>
301
302        <script type="text/javascript">
303            document.getElementById('jpcrm-search-wp-users').addEventListener('click', function() {
304                document.getElementById('jpcrm-users-search').submit();
305            });
306        </script>
307
308    </div>
309
310    <div id="jpcrm-team-user-table">
311        <div class="fit-col"><?php esc_html_e( 'ID', 'zero-bs-crm' ); ?></div>
312        <div><?php esc_html_e( 'Team member', 'zero-bs-crm' ); ?></div>
313        <div><?php esc_html_e( 'Role', 'zero-bs-crm' ); ?></div>
314        <div><?php esc_html_e( 'Last login', 'zero-bs-crm' ); ?></div>
315        <div><?php esc_html_e( 'Manage permissions', 'zero-bs-crm' ); ?></div>
316        <?php
317        foreach ( $crm_role_ids as $id ) {
318            $user = get_user_by( 'ID', $id );
319
320            $edit_url = admin_url( 'user-edit.php?user_id=' . $id . '&zbsslug=zbs-edit-user' );
321
322            $caps_output = '';
323            foreach ( $user->caps as $k => $v ) {
324                $caps_output .= ' ' . zeroBSCRM_caps_to_nicename( $k );
325            }
326            ?>
327            <div class="fit-col"><?php echo esc_html( $id ); ?></div>
328            <div><?php echo jpcrm_get_avatar( $id, 30 ); ?><?php echo esc_html( $user->display_name ); ?></div>
329            <div><?php echo esc_html( $caps_output ); ?></div>
330            <div>
331                <?php
332                // translators: a time string generated by human_time_diff()
333                echo esc_html( sprintf( __( '%s ago', 'zero-bs-crm' ), zeroBSCRM_wpb_lastlogin( $id ) ) );
334                ?>
335            </div>
336            <div>
337                <a href="<?php echo esc_url( $edit_url ); ?>" data-uid="<?php echo esc_attr( $id ); ?>" class="zbs-perm-edit ui button mini black">
338                    <?php esc_html_e( 'Manage permissions', 'zero-bs-crm' ); ?>
339                </a>
340            </div>
341            <?php
342        }
343        ?>
344    </div>
345
346
347        </div>
348
349    <?php
350}
351
352// } this function turns our caps into a nicename for outputting
353function zeroBSCRM_caps_to_nicename( $caps = '' ) {
354
355    $nicename = '';
356
357    switch ( $caps ) {
358        case 'administrator':
359            $nicename = __( 'Full Jetpack CRM Permissions (WP Admin)', 'zero-bs-crm' );
360            break;
361
362        case 'zerobs_admin':
363            $nicename = __( 'Full Jetpack CRM Permissions (CRM Admin)', 'zero-bs-crm' );
364            break;
365
366        case 'zerobs_customermgr':
367            $nicename = __( 'Manage Contacts Only', 'zero-bs-crm' );
368            break;
369
370        case 'zerobs_invoicemgr':
371            $nicename = __( 'Manage Invoices Only', 'zero-bs-crm' );
372            break;
373
374        case 'zerobs_quotemgr':
375            $nicename = __( 'Manage Quotes Only', 'zero-bs-crm' );
376            break;
377
378        case 'zerobs_transactionmgr':
379            $nicename = __( 'Manage Transactions Only', 'zero-bs-crm' );
380            break;
381
382        case 'zerobs_mailmgr':
383            $nicename = __( 'Manage Mail Only', 'zero-bs-crm' );
384            break;
385
386        default:
387            $nicename = ucfirst( $caps );
388            break;
389
390    }
391
392    return $nicename;
393}
394
395// } This is NOTIFICATIONS UI on the back on FEEDBACK from customers and Google Forms we were having people
396// } saying things like "This is GREAT, just wished it integrated with WooCommerce (i.e. unaware it does)"
397// } My thoughts here is it a page which detects certain classes etc (e.g. WooCommerce) and displays a notification
398// } about it, and the benefits of them getting WooSync :-)
399function zeroBSCRM_pages_admin_notifications() {
400
401    global $zeroBSCRM_notifications;
402
403    // } have a whole plugin here, which does browser notifications etc for Plugin Hunt Theme
404    // } have brought it into its own INCLUDE does things like new.comment have replaced it with our
405    // } IA actions (new.customer, customer.status.change)
406
407    ?>
408
409
410
411    <?php
412    $zeroBSCRM_notifications = get_option( 'zbs-crm-notifications' );
413    if ( $zeroBSCRM_notifications == '' ) {
414        $zeroBSCRM_notifications = 0;
415    }
416    // } WooCommerce for starters -
417
418    zeroBSCRM_notifyme_activity();
419
420    // } Store in a notification here, e.g.
421    $recipient = get_current_user_id();
422    $sender    = -999; // in this case...  we can call ZBS our -999 user
423    $post_id   = 0; // i.e. not a post related activity
424    $type      = 'woosync.suggestion';   // this is a extension suggestion type
425    // notifyme_insert_notification($recipient,$sender,$post_id,$type);
426}
427
428/*
429======================================================
430    Admin Page Funcs (used for all adm pages)
431    ====================================================== */
432
433    // } Admin Page header
434function zeroBSCRM_pages_header( $subpage = '' ) {
435    // TMB: all references in core are removed, so once we confirm extensions don't use this we can delete it
436}
437
438    // } Admin Page footer
439function zeroBSCRM_pages_footer() {
440    // TMB: all references in core are removed, so once we confirm extensions don't use this we can delete it
441}
442
443    // } Gross redir page
444function zeroBSCRM_pages_logout() {
445
446    ?>
447        <script type="text/javascript">window.location='<?php echo esc_html( wp_logout_url() ); ?>';</script><h1 style="text-align:center">Logging you out!</h1>
448        <?php
449}
450
451/*
452======================================================
453    / Admin Page Funcs (used for all adm pages)
454    ====================================================== */
455
456/*
457======================================================
458    Admin Pages
459    ====================================================== */
460// } Main Config page
461function zeroBSCRM_pages_home() {
462
463    global $wpdb, $zbs; // } Req
464
465    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
466        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
467
468    // } Homepage
469    if ( ! zeroBSCRM_isWL() ) {
470        // Everyday homepage
471        zeroBSCRM_html_home2();
472    } else {
473        // WL Home
474        zeroBSCRM_html_wlHome();
475    }
476
477    ?>
478    <?php
479}
480
481// } Extensions page
482function zeroBSCRM_pages_extensions() {
483
484    global $wpdb, $zbs; // } Req
485
486    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
487        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
488
489    // } page
490    zeroBSCRM_html_extensions();
491
492    ?>
493    <?php
494}
495
496// Modules page
497function jpcrm_pages_modules() {
498
499    global $wpdb, $zbs;
500
501    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
502        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
503
504    jpcrm_html_modules();
505
506    ?>
507    <?php
508}
509
510function zeroBSCRM_pages_admin_system_emails() {
511
512    global $zbs;
513
514    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
515        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
516
517    // for now put this here, should probs be stored against template:
518    // template id in here = can turn on/off
519    $sysEmailsActiveInactive = array( 1, 2, 6 );
520
521    // using tracking?
522    $trackingEnabled = $zbs->settings->get( 'emailtracking' );
523
524    ?>
525    <style>
526    .email-stats{
527        display: block;
528        font-size: .75rem;
529        text-transform: uppercase;
530        color: #b8b8d9;
531        font-weight: 600;
532    }
533    .email-template-box{
534        cursor:pointer;
535    }
536    .the-templates a{
537        color: black;
538        font-weight:900;
539    }
540    time{
541        white-space: nowrap;
542        text-transform: uppercase;
543        font-size: .5625rem;
544        margin-left: 5px;
545    }
546    .hist-label{
547        margin-right: 6px !important;
548    }
549    .email-sending-record{
550        padding:10px;
551    }
552    .template-man-h4{
553        font-weight:900;
554        margin-bottom:0;
555        padding-top:10px;
556    }
557    .email-stats-top{
558        font-size:13px;
559        margin-top:5px;
560        margin-bottom:5px;
561    }
562    .email-template-form label{
563        text-transform: uppercase !important;
564    }
565    .the-templates .active{
566    border: 1px solid #3f4347;
567    border-left: 3px solid #3f4347;   
568    }
569
570    #tinymce{
571        margin-left: 12px !important;
572    }
573    .lead{
574        margin-top:5px;
575        margin-bottom:5px;
576    }
577    .email-html-editor-free pre{
578        text-align: center;
579        padding: 50px;
580        background: #f5f5f5;
581        border: 2px dotted #ddd;
582    }
583    .update-nag{
584        display:none;
585    }
586    </style>
587
588
589    <script type="text/javascript">
590
591        jQuery(function(){
592
593            jQuery('#zbs-sys-email-template-editor i.info.popup').popup({
594            //boundary: '.boundary.example .segment'
595            });
596
597            jQuery('.zbs-turn-inactive').on("click",function(e){
598                if(jQuery(this).hasClass('negative')){
599                    return false;
600                }
601                jQuery('#zbs-saving-email-active').addClass('active');
602                var theid = jQuery(this).data('emid');
603                jQuery('#the-positive-button-' + theid).removeClass('positive');
604                jQuery(this).addClass('negative');
605                jQuery('.active-to-inactive-' + theid).addClass('negative');
606
607                var t = {
608                    action: "zbs_save_email_status",
609                    id:  theid,
610                    status: 'i',
611                    security: jQuery( '#zbs-save-email_active' ).val(),
612                }  
613                i = jQuery.ajax({
614                    url: ajaxurl,
615                    type: "POST",
616                    data: t,
617                    dataType: "json"
618                });
619                i.done(function(e) {
620                console.log(e);
621                jQuery('#zbs-saving-email-active').removeClass('active');
622                jQuery('#zbs-list-status-' + theid).removeClass('green').addClass('red');
623                jQuery('#zbs-list-status-' + theid).html("<?php esc_html_e( 'Inactive', 'zero-bs-crm' ); ?>");
624                }),i.fail(function(e) {
625                });
626            });
627
628
629            jQuery('#force-email-create').on("click", function(e){
630                jQuery('#zbs-saving-email-create').addClass('active');
631        
632                var t = {
633                    action: "zbs_create_email_templates",
634                    security: jQuery( '#zbs_create_email_nonce' ).val(),
635                }  
636              
637                i = jQuery.ajax({
638                    url: ajaxurl,
639                    type: "POST",
640                    data: t,
641                    dataType: "json"
642                });
643                i.done(function(e) {
644                console.log(e);
645                jQuery('#zbs-saving-email-create').removeClass('active');
646                jQuery('#zbs-emails-result').html("");
647                jQuery('.template-generate-results').show();
648
649                // wh: just force reload it here?
650                window.location.reload(false); 
651               
652                }),i.fail(function(e) {
653                });
654
655
656            });
657
658
659            jQuery('.zbs-turn-active').on("click",function(e){
660              
661                jQuery('#zbs-saving-email-active').addClass('active');
662
663                var theid = jQuery(this).data('emid');
664                jQuery('#active-to-inactive-' + theid).removeClass('negative');
665                jQuery(this).addClass('positive');
666                jQuery('.inactive-to-active-' + theid).addClass('positive');
667
668                //we want to AJAX save it using this action
669                // zbs_save_email_status
670                // with this nonce. 
671                var t = {
672                    action: "zbs_save_email_status",
673                    id:  theid,
674                    status: 'a',
675                    security: jQuery( '#zbs-save-email_active' ).val(),
676                }  
677              
678                i = jQuery.ajax({
679                    url: ajaxurl,
680                    type: "POST",
681                    data: t,
682                    dataType: "json"
683                });
684                i.done(function(e) {
685                console.log(e);
686                jQuery('#zbs-saving-email-active').removeClass('active');
687                jQuery('#zbs-list-status-' + theid).removeClass('red').addClass('green');
688                jQuery('#zbs-list-status-' + theid).html("<?php esc_html_e( 'Active', 'zero-bs-crm' ); ?>");
689                }),i.fail(function(e) {
690                });
691
692
693            });
694
695        });
696
697    </script>
698
699    <?php
700
701    $em_templates = '';
702    $rec_ac       = 'active';
703    $template_id  = -1;
704    $tem_set      = '';
705
706    if ( isset( $_GET['zbs_template_id'] ) && ! empty( $_GET['zbs_template_id'] ) ) {
707        $em_templates = 'active';
708        $rec_ac       = '';
709        $template_id  = (int) sanitize_text_field( $_GET['zbs_template_id'] );
710        $tem_set      = '';
711    } elseif ( isset( $_GET['zbs_template_editor'] ) && ! empty( $_GET['zbs_template_editor'] ) ) {
712        $em_templates = '';
713        $rec_ac       = '';
714        $template_id  = -1;
715        $tem_set      = 'active';
716    }
717
718    $rec_acc_link = admin_url( 'admin.php?page=zbs-email-templates' );
719
720    ?>
721
722    <div class="ui grid" style="margin-right:20px;">
723    <div class="eight wide column"></div>
724    <div class="eight wide column">
725        <div id="email-template-submenu-admin" class="ui secondary menu pointing" style="float:right;">
726            <a class="ui item <?php echo esc_attr( $rec_ac ); ?>" href="<?php echo esc_url( $rec_acc_link ); ?>"><?php esc_html_e( 'Recent Activity', 'zero-bs-crm' ); ?></a>
727            <a class="ui item <?php echo esc_attr( $em_templates ); ?>" href="<?php echo esc_url( $rec_acc_link ); ?>&zbs_template_id=1"><?php esc_html_e( 'Email Templates', 'zero-bs-crm' ); ?></a>
728            <a class="ui item <?php echo esc_attr( $tem_set ); ?>" href="<?php echo esc_url( $rec_acc_link ); ?>&zbs_template_editor=1"><?php esc_html_e( 'Template Settings', 'zero-bs-crm' ); ?></a>
729        </div>
730    </div>
731    </div>
732
733
734    <?php if ( isset( $_GET['zbs_template_editor'] ) && ! empty( $_GET['zbs_template_editor'] ) ) { ?>
735
736        <div class="ui segment" style="margin-right:20px;">
737        <h4 class="template-man-h4"><?php esc_html_e( 'HTML Template', 'zero-bs-crm' ); ?></h4>
738        <p class='lead'><?php _e( 'This template is used for all outgoing CRM emails. The <code>##MSG-CONTENT##</code> placeholder represents the per-template content and must not be removed.', 'zero-bs-crm' ); ?></p>
739      
740        <div class="ui segment">
741            <p class='lead'>
742            <?php
743            ##WLREMOVE
744            ?>
745            <?php _e( 'It is strongly recommended to leave this template unchanged for maximum device support. If you still wish to modify it, you can copy the <code>emails/default-email.html</code> file from the <code>/templates</code> directory of your CRM plugin into a <code>/jetpack-crm</code> directory in your theme, and then edit the file.' ); ?>
746            <?php _e( 'You can modify this template by copying the /templates directory from your CRM plugin into your theme directory, then editing the file <code>emails/default-email.html</code>, though it is recommended to leave this template in tact for maximum device support.' ); ?>          
747            <br /><a href="<?php echo esc_url( $zbs->urls['kbtemplatefiles'] ); ?>" target="_blank" class="ui basic blue small button"><?php esc_html_e( 'Read more about templating', 'zero-bs-crm' ); ?></a>
748            <?php
749            ##/WLREMOVE
750            ?>
751            </p>
752            <div class="ui segment">
753            <p><div class="ui label"><?php echo esc_html__( 'Current template file:', 'zero-bs-crm' ); ?></div></p>
754            <p>&nbsp;&nbsp;&nbsp;<code>
755            <?php
756
757                // retrieve loaded file source
758                $variants = jpcrm_retrieve_template_variants( 'emails/default-email.html' );
759                $origin   = __( 'core plugin', 'zero-bs-crm' );
760
761            if ( is_array( $variants ) && isset( $variants['emails/default-email.html'] ) ) {
762
763                // retrieve current used source
764                echo esc_html( $variants['emails/default-email.html']['full_path'] );
765                $origin = $variants['emails/default-email.html']['origin'];
766
767            } else {
768
769                // default
770                echo esc_html( ZEROBSCRM_PATH . 'templates/emails/default-email.html' );
771
772            }
773
774            ?>
775            </code></p>
776            <p><div class="ui label"><?php echo esc_html__( 'Origin:', 'zero-bs-crm' ) . '</div> ' . esc_html( $origin ); ?></p>
777            </div>
778        </div>
779
780      
781        <div class="ui divider"></div>
782        <textarea cols="70" rows="25" name="zbstemplatehtml" id="zbstemplatehtml"><?php echo esc_textarea( jpcrm_retrieve_template( 'emails/default-email.html', false ) ); ?></textarea>
783        <div class="ui grid" style="margin-right:-15px;margin-top:20px;">
784            <div class="eight wide column">
785            <?php
786                echo '<a href="' . esc_url( $rec_acc_link ) . '" style="text-decoration:underline;font-size:11px;">' . esc_html__( 'Back to Activity', 'zero-bs-crm' ) . '</a>';
787            ?>
788            </div>
789            <div class="eight wide column">
790            <?php
791            echo "<div style='float:right;'>";
792                echo '<a href="' . esc_url( site_url( '?zbsmail-template-preview=1' ) ) . '"class="ui button inverted blue small" target="_blank">' . esc_html__( 'Preview', 'zero-bs-crm' ) . '</a>';
793            echo '</div>';
794            ?>
795            </div>
796        </div>
797        </div>
798        <?php
799    } else {
800        ?>
801    <div class="ui grid" id="zbs-sys-email-template-editor">
802
803        <div class="five wide column the-templates">
804            <?php
805                // the template list...
806                $zbs_system_emails = zeroBSCRM_mailTemplate_getAll();
807            if ( count( $zbs_system_emails ) == 0 ) {
808
809                // something went wrong with the creation of the emails...
810                echo "<div class='ui segment' style='text-align:center'>";
811
812                echo "<div id ='zbs-emails-result'>";
813                    echo "<div class='ui inverted dimmer' id='zbs-saving-email-create'><div class='ui text loader'>" . esc_html__( 'Creating templates....', 'zero-bs-crm' ) . '</div></div>';
814
815                echo '<h4 class="template-man-h4">' . esc_html__( 'No Email Templates', 'zero-bs-crm' ) . '</h4>';
816                echo "<p class='lead' style='padding:10px;'>" . esc_html__( 'Something went wrong with the email template creation.', 'zero-bs-crm' ) . '<br/></p>';
817                echo "<div class='button ui large blue' id='force-email-create'>" . esc_html__( 'Create Now', 'zero-bs-crm' ) . '</div>';
818
819                echo '</div>';
820
821                echo "<div class='template-generate-results' style='display:none;'>";
822                echo '<h4>' . esc_html__( 'Template Creation Succeeded', 'zero-bs-crm' ) . '</h4>';
823                echo "<a href='" . esc_url( $rec_acc_link ) . "' class='button ui green'>" . esc_html__( 'Reload Page', 'zero-bs-crm' ) . '</a>';
824                echo '</div>';
825
826                echo '</div>';
827
828                echo '<input type="hidden" name="zbs_create_email_nonce" id="zbs_create_email_nonce" value="' . esc_attr( wp_create_nonce( 'zbs_create_email_nonce' ) ) . '" />';
829
830            }
831            foreach ( $zbs_system_emails as $sys_email ) {
832                if ( $sys_email->zbsmail_id > 0 ) {
833
834                    if ( $template_id == $sys_email->zbsmail_id ) {
835                        $class = 'active';
836                    } else {
837                        $class = '';
838                    }
839
840                    $link = admin_url( 'admin.php?page=zbs-email-templates&zbs_template_id=' . $sys_email->zbsmail_id );
841
842                    echo '<a href="' . esc_url( $link ) . '"><div class="ui segment email-template-box ' . esc_attr( $class ) . ' style="margin-bottom:10px;">';
843                    echo esc_html( zeroBSCRM_mailTemplate_getSubject( $sys_email->zbsmail_id ) );
844
845                    // can be enabled/disabled
846                    if ( in_array( $sys_email->zbsmail_id, $sysEmailsActiveInactive ) ) {
847
848                        if ( $sys_email->zbsmail_active == 1 ) {
849                            echo "<div class='ui label green tiny' id='zbs-list-status-" . esc_attr( $sys_email->zbsmail_id ) . "' style='float:right;margin-top:10px;'>" . esc_html__( 'Active', 'zero-bs-crm' ) . '</div>';
850                        } else {
851                            echo "<div class='ui label red tiny' id='zbs-list-status-" . esc_attr( $sys_email->zbsmail_id ) . "' style='float:right;margin-top:10px;'>" . esc_html__( 'Inactive', 'zero-bs-crm' ) . '</div>';
852                        }
853                    }
854
855                    // if tracking
856                    if ( $trackingEnabled == '1' ) {
857                        echo "<div class='email-stats'>";
858                        zeroBSCRM_mailDelivery_getTemplateStats( $sys_email->zbsmail_id );
859                        echo '</div>';
860                    } else {
861                        echo '<div class="email-stats">&nbsp;</div>';
862                    }
863
864                    echo '</div></a>';
865
866                }
867            }
868            ?>
869            <div style="text-align:center;margin-top:1em">
870                <a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['settings'] . '&tab=mail' ) ); ?>" class="ui basic button"><?php esc_html_e( 'Back to Mail Settings', 'zero-bs-crm' ); ?></a>
871            </div>
872        </div>
873
874        <div class="eleven wide column">
875            <div class="segment ui" id="email-segment">
876                <?php
877
878                if ( ! empty( $_POST['zbssubject'] )
879                    && isset( $_POST['_wpnonce'] )
880                    && wp_verify_nonce( $_POST['_wpnonce'], 'jpcrm-update-system-email-template' )
881                    ) {
882
883                    /*
884                    WH switched for mail delivery opts
885                    $zbsfromname    = sanitize_text_field($_POST['zbsfromname']);
886
887                    //using sanitize email, can
888                    $zbsfromaddress = sanitize_email($_POST['zbsfromaddress']);
889                    $zbsreplyto     = sanitize_email($_POST['zbsreplyto']);
890                    $zbsccto        = sanitize_email($_POST['zbsccto']);
891                    $zbsbccto       = sanitize_email($_POST['zbsbccto']);
892                    */
893
894                    // Mail Delivery
895                    $zbsMailDeliveryMethod = sanitize_text_field( $_POST['zbs-mail-delivery-acc'] );
896                    $zbsbccto              = sanitize_email( $_POST['zbsbccto'] );
897
898                    // this sanitizes the post content..
899                    $zbscontent = wp_kses_post( $_POST['zbscontent'] );
900                    $zbssubject = sanitize_text_field( $_POST['zbssubject'] );
901
902                    if ( isset( $_GET['zbs_template_id'] ) ) {
903
904                        $updateID = (int) sanitize_text_field( $_GET['zbs_template_id'] );
905
906                        // wh simplified for del methods
907                        // zeroBSCRM_updateEmailTemplate($updateID,$zbsfromname,$zbsfromaddress,$zbsreplyto, $zbsccto, $zbsbccto,$zbssubject, $zbscontent );
908                        zeroBSCRM_updateEmailTemplate( $updateID, $zbsMailDeliveryMethod, $zbsbccto, $zbssubject, $zbscontent );
909
910                        echo "<div class='ui message green' style='margin-top:45px;margin-right:15px;'>" . esc_html__( 'Template updated', 'zero-bs-crm' ) . '</div>';
911
912                    }
913                }
914
915                if ( isset( $_GET['zbs_template_id'] ) && ! empty( $_GET['zbs_template_id'] ) ) {
916
917                    // the tab number matches the template ID.
918                    $emailtab = (int) sanitize_text_field( $_GET['zbs_template_id'] );
919
920                    $form = '';
921
922                    // single template data.
923                    $data = zeroBSCRM_mailTemplate_get( $emailtab );
924                    if ( gettype( $data ) == 'object' ) {
925                        $form = $data;
926                    }
927
928                    if ( ! empty( $form ) ) {
929
930                        // will need to nonce this up ... (?)
931                        if ( isset( $_GET['sendtest'] ) && ! empty( $_GET['sendtest'] ) ) {
932
933                            // we are sending a test...
934                            $current_user = wp_get_current_user();
935                            $test_email   = $current_user->user_email;
936
937                            $html = zeroBSCRM_mailTemplate_emailPreview( $emailtab );
938
939                            // send it
940                            $subject = $form->zbsmail_subject;
941                            $headers = zeroBSCRM_mailTemplate_getHeaders( $emailtab );
942
943                            /*
944                            old way
945
946
947                            wp_mail( $test_email, $subject, $html, $headers );
948
949                            */
950
951                            // discern del method
952                            $mailDeliveryMethod = zeroBSCRM_mailTemplate_getMailDelMethod( $emailtab );
953                            if ( ! isset( $mailDeliveryMethod ) || empty( $mailDeliveryMethod ) ) {
954                                $mailDeliveryMethod = -1;
955                            }
956
957                            // build send array
958                            $mailArray = array(
959                                'toEmail'  => $test_email,
960                                'toName'   => '',
961                                'subject'  => $subject,
962                                'headers'  => $headers,
963                                'body'     => $html,
964                                'textbody' => '',
965                                'options'  => array(
966                                    'html' => 1,
967                                ),
968                            );
969
970                            // Sends email
971                            $sent = zeroBSCRM_mailDelivery_sendMessage( $mailDeliveryMethod, $mailArray );
972
973                            echo "<div class='ui message green' style='margin-top:45px;margin-right:15px;'>" . esc_html__( 'Test Email Sent to ', 'zero-bs-crm' ) . '<b>' . esc_html( $test_email ) . '</b></div>';
974                        }
975
976                            // if we're showing any email which requires CRON to send it, we show this message to further guide the end user:
977                        if ( in_array( $emailtab, array( ZBSEMAIL_TASK_NOTIFICATION ), true ) ) {
978
979                            ?>
980                                <div class="ui blue label right floated"><i class="circle info icon link"></i> <?php esc_html_e( 'Note: This email requires cron.', 'zero-bs-crm' ); ?> <a href="<?php echo esc_url( $zbs->urls['kbcronlimitations'] ); ?>"><?php esc_html_e( 'Read about WordPress cron', 'zero-bs-crm' ); ?></a></div>
981                                <?php
982
983                        }
984
985                            echo "<h4 class='template-man-h4'>" . esc_html( zeroBSCRM_mailTemplate_getSubject( $emailtab ) ) . '</h4>';
986
987                            echo "<div class='email-stats email-stats-top'>";
988                            zeroBSCRM_mailDelivery_getTemplateStats( $emailtab );
989                            echo '</div>';
990
991                            echo "<div class='ui inverted dimmer' id='zbs-saving-email-active'><div class='ui text loader'>" . esc_html__( 'Saving....', 'zero-bs-crm' ) . '</div></div>';
992
993                            wp_nonce_field( 'zbs-save-email_active' );
994
995                            echo '<input type="hidden" name="zbs-save-email_active" id="zbs-save-email_active" value="' . esc_attr( wp_create_nonce( 'zbs-save-email_active' ) ) . '" />';
996
997                            // can be enabled/disabled
998                        if ( in_array( $form->zbsmail_id, $sysEmailsActiveInactive ) ) {
999
1000                            if ( $form->zbsmail_active ) {
1001                                // 1 = active, 0 = inactive..
1002                                echo '<div class="ui buttons tiny" style="float: right;
1003                                        position: absolute;
1004                                        top: 19px;
1005                                        right: 20px;">
1006                                        <button class="ui positive button zbs-turn-active" id="the-positive-button-' . esc_attr( $emailtab ) . '" data-emid="' . esc_attr( $emailtab ) . '">Active</button>
1007                                        <div class="or"></div>
1008                                        <button class="ui button zbs-turn-inactive" id="active-to-inactive-' . esc_attr( $emailtab ) . '" data-emid="' . esc_attr( $emailtab ) . '">Inactive</button>
1009                                      </div>';
1010                            } else {
1011                                echo '<div class="ui buttons tiny" style="float: right;
1012                                        position: absolute;
1013                                        top: 19px;
1014                                        right: 20px;">
1015                                        <button class="ui button zbs-turn-active" id="the-positive-button-' . esc_attr( $emailtab ) . '" data-emid="' . esc_attr( $emailtab ) . '">Active</button>
1016                                        <div class="or"></div>
1017                                        <button class="ui button zbs-turn-inactive negative" id="active-to-inactive-' . esc_attr( $emailtab ) . '" data-emid="' . esc_attr( $emailtab ) . '">Inactive</button>
1018                                      </div>';
1019                            }
1020                        }
1021
1022                            echo "<div class='ui divider'></div>";
1023
1024                            $formlink = admin_url( 'admin.php?page=zbs-email-templates&zbs_template_id=' . $emailtab );
1025
1026                            echo "<form class='ui form email-template-form' action='" . esc_url( $formlink ) . "' METHOD='POST'>";
1027
1028                            wp_nonce_field( 'jpcrm-update-system-email-template' );
1029
1030                            echo '<div class="field">';
1031                            echo '<label for="zbssubject">' . esc_html__( 'Subject', 'zero-bs-crm' ) . '</label>';
1032                            echo '<input id="zbssubject" name="zbssubject" type="text" value="' . esc_attr( $form->zbsmail_subject ) . '">';
1033                            echo '</div>';
1034
1035                            // 11/05/18 - delivery methods replace hard-typed opts here
1036                            echo '<div class="field">';
1037
1038                            echo '<div class="ui grid" style="margin-bottom:-0.4em"><div class="four wide column">';
1039                            echo '<label for="zbs-mail-delivery-acc">' . esc_html__( 'Delivery Method', 'zero-bs-crm' ) . '</label>';
1040                            echo '</div><div class="twelve wide column">';
1041                        ?>
1042                            <div class="ui teal label right floated"><i class="circle info icon link"></i> <?php esc_html_e( 'You can set up different delivery methods in your ', 'zero-bs-crm' ); ?> <a href="<?php echo jpcrm_esc_link( $zbs->slugs['settings'] ) . '&tab=maildelivery'; ?>"><?php esc_html_e( 'Delivery Methods Settings', 'zero-bs-crm' ); ?></a></div>
1043                            <?php
1044                            echo '</div></div>';
1045
1046                            zeroBSCRM_mailDelivery_accountDDL( $form->zbsmail_deliverymethod );
1047
1048                            echo '</div>';
1049
1050                            /*
1051                            echo '<div class="field">';
1052                            echo '<label>' . __('From Name','zero-bs-crm') .'</label>';
1053                            echo '<input id="zbsfromname" name="zbsfromname" type="text" value="'.$form->zbsmail_fromname.'">';
1054                            echo '</div>';
1055
1056                            echo '<div class="field">';
1057                            echo '<label>' . __('From Email','zero-bs-crm') .'</label>';
1058                            echo '<input id="zbsfromaddess" name="zbsfromaddress" type="text" value="'.$form->zbsmail_fromaddress.'">';
1059                            echo '</div>';
1060
1061                            echo '<div class="field">';
1062                            echo '<label>' . __('Reply To','zero-bs-crm') .'</label>';
1063                            echo '<input id="zbsreplyto" name="zbsreplyto" type="text" value="'.$form->zbsmail_replyto.'">';
1064                            echo '</div>';
1065
1066                            echo '<div class="field zbs-hide">';
1067                            echo '<label>' . __('Cc To','zero-bs-crm') .'</label>';
1068                            echo '<input id="zbsccto" name="zbsccto" type="text" value="'.$form->zbsmail_ccto.'">';
1069                            echo '</div>';
1070                            */
1071
1072                            echo '<div class="field">';
1073                            echo '<label for="zbsbccto">' . esc_html__( 'Bcc To', 'zero-bs-crm' ) . '</label>';
1074                            echo '<input id="zbsbccto" name="zbsbccto" type="text" value="' . esc_attr( $form->zbsmail_bccto ) . '">';
1075                            echo '</div>';
1076
1077                            echo '<div class="field">';
1078                            echo '<div class="ui grid">';
1079                                echo '<div class="eight wide column"><label class="jpcrm-email-template-label jpcrm-email-template-label-content" for="zbscontent">' . esc_html__( 'Content', 'zero-bs-crm' ) . '</label></div>';
1080
1081                            // placeholder injector
1082                                echo '<div class="eight wide column" style="text-align:right">';
1083
1084                            // select tooling areas (template dependent)
1085                            $tooling_areas = array( 'global' );
1086                            switch ( $emailtab ) {
1087
1088                                case 1: // Your Client Portal
1089                                    $tooling_areas = array( 'global', 'contact' );
1090                                    break;
1091                                case 2: // Quote Accepted
1092                                    $tooling_areas = array( 'global', 'quote', 'contact' );
1093                                    break;
1094                                case 3: // You have received an Invoice
1095                                    $tooling_areas = array( 'global', 'invoice', 'contact', 'company' );
1096                                    break;
1097                                case 4: // You have received a new Proposal
1098                                    $tooling_areas = array( 'global', 'quote', 'contact', 'company' );
1099                                    break;
1100                                case 5: // Your Task starts soon
1101                                    $tooling_areas = array( 'global', 'event', 'contact', 'company' );
1102                                    break;
1103                                case 6: // Your Client Portal Password
1104                                    $tooling_areas = array( 'global', 'contact' );
1105                                    break;
1106                                case 7: // Your Statement
1107                                    $tooling_areas = array( 'global', 'invoice', 'contact', 'company' );
1108                                    break;
1109
1110                            }
1111
1112                            // load templater
1113                            $placeholder_templating = $zbs->get_templating();
1114                            $placeholder_templating->placeholder_selector(
1115                                'jpcrm-mail-template-editor-placeholders',
1116                                'zbscontent',
1117                                $tooling_areas,
1118                                false
1119                            );
1120
1121                            // close column and grid
1122                                echo '</div></div>';
1123
1124                            $content         = esc_html( $form->zbsmail_body );
1125                            $editor_settings = array(
1126                                'media_buttons' => false,
1127                                'editor_height' => 350,
1128                                'quicktags'     => false,
1129                                'tinymce'       => false,
1130                            );
1131                            wp_editor( $content, 'zbscontent', $editor_settings );
1132                            echo '</div>';
1133                            ?>
1134
1135                            <div class="ui grid" style="margin-right:-15px;">
1136                            <div class="eight wide column">
1137                                <?php
1138                                echo '<a href="' . esc_url( $rec_acc_link ) . '&zbs_template_editor=1" style="text-decoration:underline;font-size:11px;">' . esc_html__( 'Edit HTML Template', 'zero-bs-crm' ) . '</a>';
1139                                ?>
1140                            </div>
1141                            <div class="eight wide column">
1142                                <?php
1143
1144                                $sendtestlink = admin_url( 'admin.php?page=zbs-email-templates&zbs_template_id=' . $emailtab . '&sendtest=1' );
1145
1146                                echo "<div style='float:right;'>";
1147                                echo '<a href="' . esc_url( site_url( '?zbsmail-template-preview=1&template_id=' . $emailtab ) ) . '" target="_blank" class="ui button inverted blue small">' . esc_html__( 'Preview', 'zero-bs-crm' ) . '</a>';
1148                                echo '<a href="' . esc_url( $sendtestlink ) . '" class="ui button blue small">' . esc_html__( 'Send Test', 'zero-bs-crm' ) . '</a>';
1149                                echo '<input class="ui button green small" type="submit" value="' . esc_attr__( 'Save', 'zero-bs-crm' ) . '">';
1150                                echo '</div>';
1151                                ?>
1152                            </div>
1153                            </div>
1154
1155
1156
1157                            </form>
1158
1159                            <?php
1160
1161                    } else {
1162                        echo "<div class='ui message blue'>";
1163                            echo "<i class='icon info'></i>" . esc_html__( 'No templates. Please generate', 'zero-bs-crm' );
1164                        echo '</div>';
1165                    }
1166
1167                    // zbs_prettyprint($data);
1168
1169                } else {
1170                    ?>
1171
1172                        <h4 class="template-man-h4"><?php esc_html_e( 'Sent Emails', 'zero-bs-crm' ); ?></h4>
1173                        <p class='lead'><?php esc_html_e( 'Your latest 50 emails are shown here so you can keep track of activity.', 'zero-bs-crm' ); ?></p>
1174                        <div class="ui divider"></div>
1175
1176                    <?php
1177
1178                    zeroBSCRM_outputEmailHistory();
1179
1180                }
1181
1182                ?>
1183            </div>
1184        </div>
1185    </div>
1186
1187    <?php } //end of code for if template setting is being shown... ?>
1188
1189    <?php
1190}
1191
1192// } Data Tools Page
1193function zeroBSCRM_pages_datatools() {
1194
1195    global $wpdb, $zbs; // } Req
1196
1197    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
1198        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
1199
1200    // } Settings
1201    zeroBSCRM_html_datatools();
1202
1203    ?>
1204</div>
1205    <?php
1206}
1207
1208// } Install Extensions helper page
1209function zeroBSCRM_pages_installextensionshelper() {
1210
1211    global $wpdb, $zbs;  // } Req
1212
1213    if ( ! current_user_can( 'admin_zerobs_manage_options' ) ) {
1214        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
1215    // } Settings
1216    zeroBSCRM_html_installextensionshelper();
1217
1218    ?>
1219</div>
1220    <?php
1221}
1222
1223// } No rights to this (customer/company)
1224function zeroBSCRM_pages_norights() {
1225
1226    global $wpdb, $zbs;  // } Req
1227
1228    if (
1229    ! zeroBSCRM_permsCustomers()
1230    && ! zeroBSCRM_permsQuotes()
1231    && ! zeroBSCRM_permsInvoices()
1232    && ! zeroBSCRM_permsTransactions()
1233    ) {
1234        wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'zero-bs-crm' ) ); }
1235
1236    // } Post Deletion page
1237    zeroBSCRM_html_norights();
1238
1239    ?>
1240</div>
1241    <?php
1242}
1243
1244// Whitelabel homepage.
1245function zeroBSCRM_html_wlHome() {
1246
1247    global $zbs;
1248
1249    ?>
1250    <div>
1251    <h1 style="font-size: 34px;margin-left: 50px;color: #e06d17;margin-top: 1em;"><?php esc_html_e( 'Welcome to Jetpack CRM', 'zero-bs-crm' ); ?></h1>
1252    <p style="font-size: 16px;margin-left: 50px;padding: 12px 20px 10px 20px;"><?php esc_html_e( 'This CRM Plugin is managed by Jetpack CRM', 'zero-bs-crm' ); ?><?php esc_html_e( 'If you have any questions, please', 'zero-bs-crm' ); ?> <a href="<?php echo esc_url( $zbs->urls['support'] ); ?>"><?php esc_html_e( 'email us', 'zero-bs-crm' ); ?></a>.</p>
1253    <?php
1254
1255    // let wl users add content
1256    do_action( 'zerobscrm_wl_homepage' );
1257}
1258
1259// } MS - 3rd Dec 2018 - new function for the home page - function name the same, old function below
1260function zeroBSCRM_html_home2() {
1261
1262    global $zbs;
1263
1264    /*
1265    to highlight the benefits of Jetpack CRM and going pro. Link into the new fature page
1266    show "Go Pro" offer and some testimonials :)
1267    need to remove top menu from this page ... do with ze CSS :-)
1268    */
1269
1270    // $add_new_customer_link = admin_url('admin.php?page=zbs-add-edit&action=edit&zbstype=contact');
1271    $add_new_customer_link = jpcrm_esc_link( 'create', -1, 'zerobs_customer' );
1272
1273    // WH added: Is now polite to License-key based settings like 'entrepreneur' doesn't try and upsell
1274    // this might be a bit easy to "hack out" hmmmm
1275    $bundle = false;
1276    if ( $zbs->hasEntrepreneurBundleMin() ) {
1277        $bundle = true;
1278    }
1279
1280    // this stops hopscotch ever loading on this page :)
1281    ?>
1282    <script type="text/javascript">var zbscrmjs_hopscotch_squash = true;</script>
1283
1284    <div id="zbs-welcome">
1285    <div class="container">
1286
1287        <div class="intro">
1288            <div class="block" style="text-align:center;margin-top:-50px;">
1289                        <img src="<?php echo esc_url( jpcrm_get_logo( false ) ); ?>" alt="Jetpack CRMt" id="jetpack-crm-welcome" style="text-align:center;padding:30px;"> 
1290                        <h6><?php esc_html_e( 'Thank you for choosing Jetpack CRM - The Ultimate Entrepreneurs\' CRM for WordPress', 'zero-bs-crm' ); ?></h6>
1291            </div>
1292        </div>
1293
1294        <div id="action-buttons" class='block'>
1295        <h6>
1296        <?php
1297        esc_html_e( 'Jetpack CRM makes it easy for you to manage your contacts using WordPress. To get started, read our guide on how create your first contact', 'zero-bs-crm' );
1298        echo ':';
1299        ?>
1300        </h6>
1301        <div class='zbs-button-wrap'>
1302            <div class="left">
1303            <a href="<?php echo esc_url( $add_new_customer_link ); ?>" class="jpcrm-button font-14px"><?php esc_html_e( 'Add Your First Contact', 'zero-bs-crm' ); ?></a>
1304            </div>
1305            <div class="right">
1306            <a href="<?php echo esc_url( $zbs->urls['kbfirstcontact'] ); ?>" target="_blank" class="jpcrm-button white-bg font-14px"><?php esc_html_e( 'Read the full guide', 'zero-bs-crm' ); ?></a>
1307            </div>
1308            <div class="clear"></div>
1309        </div>
1310        </div>
1311
1312
1313    </div><!-- / .container -->
1314
1315    <div class="container margin-top30">
1316        <div class="intro">
1317            <div class="block" style="text-align:center;margin-top:-50px;">
1318                <img src="<?php echo esc_url( plugins_url( '/i/ext/woocommerce-logo-horizontal-black.png', ZBS_ROOTFILE ) ); ?>" alt="WooCommerce" id="woocommerce-logo" style="text-align:center;padding:30px;padding-bottom:15px;max-width:440px;">
1319                <h6><?php esc_html_e( 'Jetpack CRM is WooCommerce ready!', 'zero-bs-crm' ); ?></h6>
1320            </div>
1321        </div>
1322
1323        <div id="action-buttons" class='block'>
1324        <h6><?php esc_html_e( 'Connect today your WooCommerce Store and start importing your orders and customers into Jetpack CRM.', 'zero-bs-crm' ); ?></h6>
1325        <div class='zbs-button-wrap'>
1326            <a href="<?php echo esc_url( wp_nonce_url( '?page=' . $zbs->slugs['module-activate-redirect'] . '&jpcrm-module-name=woo-sync', 'jpcrmmoduleactivateredirectnonce' ) ); ?>" class='jpcrm-button font-14px'><?php esc_html_e( 'Connect your WooCommerce Store to Jetpack CRM', 'zero-bs-crm' ); ?></a>
1327        </div>
1328        </div>
1329
1330
1331    </div><!-- / .container -->
1332
1333
1334    <div class="container margin-top30">
1335        <div class="intro zbs-features">
1336
1337        <div class="block">
1338                <h1><?php esc_html_e( 'Jetpack CRM Features and Extensions', 'zero-bs-crm' ); ?></h1>
1339                <h6><?php esc_html_e( 'Made for you, from the ground up. Jetpack CRM is both easy-to-use, and extremely flexible. Whatever your business, Jetpack CRM is the no-nonsense way of keeping a contact database', 'zero-bs-crm' ); ?></h6>
1340            </div>
1341
1342
1343        <div class="feature-list block">
1344
1345                    <div class="feature-block first">
1346                        <img alt="<?php esc_attr_e( 'CRM Dashboard', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/crm-dash.png', ZBS_ROOTFILE ) ); ?>">
1347                        <h5><?php esc_html_e( 'CRM Dashboard', 'zero-bs-crm' ); ?></h5>
1348                        <p><?php esc_html_e( 'See at a glance the key areas of your CRM: e.g. Contact Activity, Contact Funnel, and Revenue snapshot.', 'zero-bs-crm' ); ?></p>
1349                    </div>
1350
1351                    <div class="feature-block last">
1352                        <img alt="<?php esc_html_e( 'Limitless Contacts', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/customers.png', ZBS_ROOTFILE ) ); ?>">
1353                        <h5><?php esc_html_e( 'Limitless Contacts', 'zero-bs-crm' ); ?></h5>
1354                        <p><?php esc_html_e( 'Add as many contacts as you like. No limits to the number of contacts you can add to your CRM.', 'zero-bs-crm' ); ?></p>
1355                    </div>
1356
1357                    <div class="feature-block first">
1358                        <img alt="<?php esc_attr_e( 'Quote Builder', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/quotes.png', ZBS_ROOTFILE ) ); ?>">
1359                        <h5><?php esc_html_e( 'Quote Builder', 'zero-bs-crm' ); ?></h5>
1360                        <p><?php esc_html_e( 'Do you find yourself writing similar quotes/proposals over and over? Quote Builder makes it easy for your team.', 'zero-bs-crm' ); ?></p>
1361                    </div>
1362
1363                    <div class="feature-block last">
1364                        <img alt="<?php esc_attr_e( 'Invoicing', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/invoices.png', ZBS_ROOTFILE ) ); ?>">
1365                        <h5><?php esc_html_e( 'Invoicing', 'zero-bs-crm' ); ?></h5>
1366                        <p><?php esc_html_e( 'Got clients or people to bill? Easily create invoices, and get paid online (pro). Clients can see all Invoices in one place on the Client Portal.', 'zero-bs-crm' ); ?></p>
1367                    </div>
1368
1369                    <div class="feature-block first">
1370                        <img alt="<?php esc_attr_e( 'Transactions', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/transactions.png', ZBS_ROOTFILE ) ); ?>">
1371                        <h5><?php esc_html_e( 'Transactions', 'zero-bs-crm' ); ?></h5>
1372                        <p><?php esc_html_e( 'Log transactions against contacts or companies, and reconcile to invoices. Track payments, ecommerce data, and LTV (lifetime value).', 'zero-bs-crm' ); ?></p>
1373                    </div>
1374
1375                    <div class="feature-block last">
1376                        <img alt="<?php esc_attr_e( 'B2B Mode', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/b2b.png', ZBS_ROOTFILE ) ); ?>">
1377                        <h5><?php esc_html_e( 'B2B Mode', 'zero-bs-crm' ); ?></h5>
1378                        <p><?php esc_html_e( 'Manage leads working at Companies? B2B mode lets you group contacts under a Company and keep track of sales easier.', 'zero-bs-crm' ); ?></p>
1379                    </div>
1380
1381                    <div class="feature-block first">
1382                        <img alt="<?php esc_attr_e( 'Automations', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/auto.png', ZBS_ROOTFILE ) ); ?>">
1383                        <h5><?php esc_html_e( 'Automations', 'zero-bs-crm' ); ?><span class='pro'>Entrepreneur</span></h5>
1384                        <p><?php esc_html_e( 'Set up rule-based triggers and actions to automate your CRM work. Automatically Email new contacts, Distribute Leads, plus much more.', 'zero-bs-crm' ); ?></p>
1385                    </div>
1386
1387                    <div class="feature-block last">
1388                        <img alt="<?php esc_attr_e( 'Send SMS', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/sms.png', ZBS_ROOTFILE ) ); ?>">
1389                        <h5><?php esc_html_e( 'Send SMS', 'zero-bs-crm' ); ?><span class='pro'>Entrepreneur</span></h5>
1390                        <p><?php esc_html_e( 'Want to get in front of your contacts, wherever they are? Send SMS messages to your contacts from their CRM record.', 'zero-bs-crm' ); ?></p>
1391                    </div>
1392
1393                    <div class="feature-block first">
1394                        <img alt="<?php esc_attr_e( 'Client Portal Pro', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/cpp.png', ZBS_ROOTFILE ) ); ?>">
1395                        <h5><?php esc_html_e( 'Client Portal Pro', 'zero-bs-crm' ); ?><span class='pro'>Entrepreneur</span></h5>
1396                        <p><?php esc_html_e( 'Create a powerful client portal in one click! Easily share files with clients via their contact record. Tweak the portal to fit your branding, and more!', 'zero-bs-crm' ); ?></p>
1397                    </div>
1398
1399                    <div class="feature-block last">
1400                        <img alt="<?php esc_attr_e( 'Mail Campaigns', 'zero-bs-crm' ); ?>" src="<?php echo esc_url( plugins_url( '/i/mail.png', ZBS_ROOTFILE ) ); ?>">
1401                        <h5><?php esc_html_e( 'Mail Campaigns', 'zero-bs-crm' ); ?><span class='pro'>Entrepreneur</span></h5>
1402                        <p><?php echo wp_kses( __( 'Send Email Broadcasts and Sequences to your CRM contacts using our <strong>powerful</strong> Mail Campaigns v2.0. which is linked directly into your CRM data!', 'zero-bs-crm' ), $zbs->acceptable_restricted_html ); ?></p>
1403                    </div>
1404
1405            </div>
1406
1407        <div class="clear"></div>
1408
1409        <div class='zbs-button-wrap'>
1410            <a href="https://jetpackcrm.com/features/" target="_blank" class="jpcrm-button white-bg font-14px"><?php esc_html_e( 'See All Features', 'zero-bs-crm' ); ?></a>
1411        </div>
1412
1413        </div><!-- / .intro.zbs-features -->
1414    </div><!-- / .container -->
1415    
1416        <?php if ( ! $bundle ) { ?>
1417    <div class="container margin-top30">
1418        <div class="intro zbs-features">
1419        <div class="block" style="padding-bottom:0;">
1420
1421                        <h1>Testimonials</h1>
1422
1423                        <div class="testimonial-block">
1424                            <img alt="Thumbnail of Michael Short" src="<?php echo esc_url( plugins_url( '/i/mb.jpg', ZBS_ROOTFILE ) ); ?>">
1425                            <p><?php esc_html_e( 'My mind is blown away by how much attention has been placed on all the essential details built into Jetpack CRM. It\'s a polished, professional product that I love being able to bake into my Website as a Service (WaaS), multisite network. It adds true value for my customers and completes my product offering. I\'ve not been able to find any tool quite like it (and trust me, I\'ve looked!) If you\'re looking to offer true value to your customers, this is worth its weight in gold!', 'zero-bs-crm' ); ?></p>
1426                <p class='who'><strong>Michael Short</strong>
1427            </div>
1428
1429                        <div class="testimonial-block">
1430                            <img alt="Thumbnail of Dave Scribner" src="<?php echo esc_url( plugins_url( '/i/scribner.png', ZBS_ROOTFILE ) ); ?>">
1431                            <p><?php esc_html_e( 'We can sit back and relax safe in the knowledge that Jetpack CRM is working tirelessly behind the scenes distributing leads automatically to our clients.', 'zero-bs-crm' ); ?></p>
1432                <p class='who'><strong>Dave Scribner</strong> 
1433                </div>
1434
1435                </div><!-- / .block -->
1436
1437        </div><!-- / .intro.zbs-features -->
1438
1439    </div><!-- / .container -->
1440
1441    <div class="container final-block">
1442        <div class="upgrade-cta upgrade">
1443            <div class="block">
1444                <h2>Upgrade to ENTREPRENEUR</h2>
1445                <div class="upgrade-cta__features">
1446                    <ul>
1447                        <li style="width:100%;text-align:center;margin-bottom: 30px;"><?php esc_html_e( 'Access to 30+ Extensions:', 'zero-bs-crm' ); ?></li>
1448                        <li><span class="dashicons dashicons-yes"></span> PayPal Connect</li>
1449                        <li><span class="dashicons dashicons-yes"></span> Invoicing Pro</li>
1450                        <li><span class="dashicons dashicons-yes"></span> Stripe Connect</li>
1451                        <li><span class="dashicons dashicons-yes"></span> User Registration</li>
1452                        <li><span class="dashicons dashicons-yes"></span> Lead Capture</li>
1453                        <li><span class="dashicons dashicons-yes"></span> Client Portal Pro</li>
1454                        <li><span class="dashicons dashicons-yes"></span> Sales Dashboard</li>
1455                        <li><span class="dashicons dashicons-yes"></span> Zapier</li>
1456                        <li><span class="dashicons dashicons-yes"></span> Automations</li>
1457                        <li><span class="dashicons dashicons-yes"></span> Mail Campaigns</li>
1458                    </ul>
1459                </div>
1460            <div class="clear"></div>
1461            </div> <!-- / .block -->
1462            <div class="zbs-button-wrap">
1463            <a href="<?php echo esc_url( $zbs->urls['upgrade'] ); ?>" rel="noopener noreferrer" target="_blank" class="jpcrm-button font-14px"><?php esc_html_e( 'Upgrade your CRM today', 'zero-bs-crm' ); ?></a>
1464        </div>
1465        </div> <!-- / .upgrade-cta -->
1466    </div>
1467
1468            <?php
1469        }
1470        ##WLREMOVE
1471        else {
1472
1473            // bundle owners:
1474
1475            ?>
1476
1477
1478    <div class="container final-block">
1479        <div class="block">
1480        <div class='zbs-button-wrap' style="padding-bottom:2em">
1481
1482            <h4><?php esc_html_e( 'Your Account:', 'zero-bs-crm' ); ?></h4>
1483
1484            <a href="<?php echo jpcrm_esc_link( $zbs->slugs['extensions'] ); ?>" class='jpcrm-button font-14px'><?php esc_html_e( 'Manage Extensions', 'zero-bs-crm' ); ?></a>
1485            <a href="<?php echo esc_url( $zbs->urls['account'] ); ?>" target="_blank" class='jpcrm-button white-bg font-14px'><?php esc_html_e( 'Download Extensions', 'zero-bs-crm' ); ?></a>
1486
1487            <div class="clear"></div>
1488        </div>
1489        </div>
1490    </div>
1491            <?php
1492
1493        }
1494
1495        ##/WLREMOVE
1496        ?>
1497
1498    </div><!-- / zbs-welcome -->
1499
1500    <?php
1501}
1502
1503// } DataTools HTML
1504// } Only exposed when a data tools plugin is installed:
1505// } - CSV Importer
1506function zeroBSCRM_html_datatools() {
1507
1508    global $wpdb, $zbs;  // } Req
1509
1510    $deleting_data = false;
1511
1512    if ( current_user_can( 'manage_options' ) ) {
1513
1514        // DELETE ALL DATA (Not Settings)
1515        if ( isset( $_POST['zbs-delete-data'] ) && $_POST['zbs-delete-data'] == 'DO IT' ) {
1516            $link = admin_url( 'admin.php?page=' . $zbs->slugs['datatools'] );
1517            $str  = __( 'REMOVE ALL DATA', 'zero-bs-crm' );
1518            echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1519
1520            echo '<h3>' . esc_html__( 'Delete all CRM data', 'zero-bs-crm' ) . '</h3>';
1521
1522            echo "<div style='font-size:60px;margin:0.5em;'>⚠️</div>";
1523            echo "<p class='lead' style='font-size:16px;color:#999;padding-top:15px;'>";
1524
1525            esc_html_e( 'This Administrator level utility will remove all data in your CRM. This cannot be undone. Proceed with caution.', 'zero-bs-crm' );
1526
1527            echo '</p>';
1528
1529                        $del_link = $link . '&zbs-delete-data=1';
1530            $action               = 'zbs_delete_data';
1531            $name                 = 'zbs_delete_nonce';
1532
1533            $nonce_del_link = wp_nonce_url( $del_link, $action, $name );
1534            echo "<a class='ui button red' href='" . esc_url( $nonce_del_link ) . "'>" . esc_html( $str ) . '</a>';
1535
1536            echo "<a class='ui button green inverted' href='" . esc_url( $link ) . "'>" . esc_html__( 'CANCEL', 'zero-bs-crm' ) . '</a>';
1537            echo '</div>';
1538            $deleting_data = true;
1539
1540        } elseif ( isset( $_GET['zbs-delete-data'] ) && $_GET['zbs-delete-data'] == 1 ) {
1541
1542                // additional nonce check
1543            if ( ! isset( $_GET['zbs_delete_nonce'] ) || ! wp_verify_nonce( $_GET['zbs_delete_nonce'], 'zbs_delete_data' ) ) {
1544
1545                echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1546                echo "<div class='ui message red' style='margin-right:20px;font-size:20px;'><i class='ui icon'></i>" . esc_html__( 'Data not deleted. Invalid permissions', 'zero-bs-crm' ) . '</div>';
1547                echo '</div>';
1548
1549            } else {
1550                echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1551                echo "<div class='ui message green' style='margin-right:20px;font-size:20px;'><i class='ui icon check circle'></i>" . esc_html__( 'All CRM data deleted.', 'zero-bs-crm' ) . '</div>';
1552                echo '</div>';
1553
1554                // run the delete code
1555                zeroBSCRM_database_reset();
1556
1557            }
1558        }
1559
1560        // DELETE ALL DATA (INCLUDING Settings)
1561        if ( isset( $_POST['zbs-delete-all-data'] ) && $_POST['zbs-delete-all-data'] == 'FACTORY RESET' ) {
1562
1563            $link = admin_url( 'admin.php?page=' . $zbs->slugs['datatools'] );
1564            $str  = __( 'REMOVE ALL DATA', 'zero-bs-crm' );
1565            echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1566
1567            echo '<h3>' . esc_html__( 'Factory Reset CRM', 'zero-bs-crm' ) . '</h3>';
1568
1569            echo "<div style='font-size:60px;margin:0.5em'>⚠️</div>";
1570            echo "<p class='lead' style='font-size:16px;color:#999;padding-top:15px;'>";
1571
1572            esc_html_e( 'This Administrator level utility will remove all data in your CRM, including your CRM settings. This cannot be undone. Proceed with caution.', 'zero-bs-crm' );
1573
1574            echo '</p>';
1575
1576                        $del_link = $link . '&zbs-delete-all-data=1';
1577            $action               = 'zbs_delete_data';
1578            $name                 = 'zbs_delete_nonce';
1579
1580            $nonce_del_link = wp_nonce_url( $del_link, $action, $name );
1581            echo "<a class='ui button red' href='" . esc_url( $nonce_del_link ) . "'>" . esc_html( $str ) . '</a>';
1582
1583            echo "<a class='ui button green inverted' href='" . esc_url( $link ) . "'>" . esc_html__( 'CANCEL', 'zero-bs-crm' ) . '</a>';
1584            echo '</div>';
1585            $deleting_data = true;
1586
1587        } elseif ( isset( $_GET['zbs-delete-all-data'] ) && $_GET['zbs-delete-all-data'] == 1 ) {
1588
1589                // additional nonce check
1590            if ( ! isset( $_GET['zbs_delete_nonce'] ) || ! wp_verify_nonce( $_GET['zbs_delete_nonce'], 'zbs_delete_data' ) ) {
1591
1592                echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1593                echo "<div class='ui message red' style='margin-right:20px;font-size:20px;'><i class='ui icon'></i>" . esc_html__( 'Data not deleted. Invalid permissions', 'zero-bs-crm' ) . '</div>';
1594                echo '</div>';
1595
1596            } else {
1597                echo "<div class='ui segment' style='margin-right:20px;text-align:center;'>";
1598                echo "<div class='ui message green' style='margin-right:20px;font-size:20px;'><i class='ui icon check circle'></i>" . esc_html__( 'CRM Factory Reset', 'zero-bs-crm' ) . '</div>';
1599                echo '</div>';
1600
1601                // run the delete code
1602                /*
1603                ___________________    . , ; .
1604                (___________________|~~~~~X.;' .
1605                                    ' `" ' `
1606                            TNT
1607
1608                */
1609                zeroBSCRM_database_nuke();
1610
1611            }
1612        }
1613    }
1614
1615    if ( ! $deleting_data ) {
1616        ?>
1617            
1618        <div id="zero-bs-tools" class="ui segment" style="margin-right:20px;">
1619            <h2 class="sbhomep"><?php esc_html_e( 'Welcome to Jetpack CRM Tools', 'zero-bs-crm' ); ?></h2>
1620            <div class="sbhomep"><?php esc_html_e( 'This is the home for all of the different admin tools for Jetpack CRM which import and export data, excluding sync extensions.', 'zero-bs-crm' ); ?></div>
1621            <br><br>
1622            <div class="sbhomep">
1623                <strong><?php esc_html_e( 'Import Tools', 'zero-bs-crm' ); ?>:</strong><br>
1624                <?php
1625
1626                $has_pro_data_tools = false;
1627                global $zeroBSCRM_CSVImporterslugs;
1628                if ( zeroBSCRM_isExtensionInstalled( 'csvpro' ) && isset( $zeroBSCRM_CSVImporterslugs ) ) {
1629                    // phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
1630                    ?>
1631                    <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zeroBSCRM_CSVImporterslugs['app'] ) ); ?>" class="ui button black primary"><?php echo esc_html( 'CSV Importer Pro' ); ?></a></p>
1632                    <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zeroBSCRM_CSVImporterslugs['tagger'] ) ); ?>" class="ui button black primary"><?php echo esc_html( 'CSV Tagger' ); ?></a></p>
1633                    <?php
1634                    // phpcs:enable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
1635                    $has_pro_data_tools = true;
1636                }
1637
1638                if ( ! $has_pro_data_tools ) {
1639                    ?>
1640                    <p><?php esc_html_e( 'You do not have any pro data tool extensions installed.', 'zero-bs-crm' ); ?></p>
1641                    <?php
1642                    if ( ! zeroBSCRM_isExtensionInstalled( 'csvpro' ) ) {
1643                        ?>
1644                        <p><a class="ui button black primary" href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['csvlite'] ) ); ?>"><?php esc_html_e( 'CSV Importer Lite', 'zero-bs-crm' ); ?></a></p>
1645                        <?php
1646                    }
1647                }
1648                ##WLREMOVE
1649                ?>
1650                <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['extensions'] ) ); ?>" class="ui button black primary"><?php esc_html_e( 'View all extensions', 'zero-bs-crm' ); ?></a></p>
1651                <?php
1652                ##/WLREMOVE
1653                ?>
1654                <br>
1655            </div>
1656            <div class="sbhomep">
1657                <strong><?php esc_html_e( 'Export Tools', 'zero-bs-crm' ); ?>:</strong><br/>
1658                <p><?php esc_html_e( 'Use the button below to go to the object exporter.', 'zero-bs-crm' ); ?></p>
1659                <p><a class="ui black button" href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['export-tools'] ) ); ?>"><?php esc_html_e( 'Export objects', 'zero-bs-crm' ); ?></a></p>
1660            </div>
1661            <br>
1662    </div>
1663    <div class="ui grid">
1664    <div class="eight wide column">
1665      
1666        <div class="ui segment" style="margin-right:20px;">
1667            <div class='mass-delete' style="text-align:center;">
1668                <h4 style="font-weight:900;"><?php esc_html_e( 'Delete CRM Data', 'zero-bs-crm' ); ?></h4>
1669                <p>
1670                <?php $str = sprintf( __( "To remove all CRM data (e.g. contacts, transactions, etc.), type '%s' in the box below and click 'Delete All Data'.", 'zero-bs-crm' ), 'DO IT' ); ?>
1671                <?php echo esc_html( $str ); ?>
1672                </p>
1673                <div class="zbs-delete-box" style="max-width:70%;margin:auto;">
1674                <p class='ui message warning'>
1675                    <i class='ui icon exclamation'></i><b> <?php esc_html_e( 'Warning: This cannot be undone', 'zero-bs-crm' ); ?></b>
1676                </p>
1677                <form id="reset-data" class="ui form" action="#" method="POST">
1678                    <input class="form-control" id="zbs-delete-data" name="zbs-delete-data" type="text" value="" placeholder="DO IT" style="text-align:center;font-size:25px;"/>
1679                    <input type="submit" class="ui button red" value="<?php esc_attr_e( 'DELETE ALL DATA', 'zero-bs-crm' ); ?>" style="margin-top:10px;"/>
1680                </form>
1681                </div>            
1682            </div>
1683        </div>
1684
1685    </div>
1686    <div class="eight wide column">
1687      
1688        <div class="ui segment" style="margin-right:20px;">
1689            <div class='mass-delete' style="text-align:center;">
1690                <h4 style="font-weight:900;"><?php esc_html_e( 'Factory Reset CRM', 'zero-bs-crm' ); ?></h4>
1691                <p>
1692                <?php $str = sprintf( __( "To delete CRM data and all settings, type '%s' in the box below and click 'Reset CRM'.", 'zero-bs-crm' ), 'FACTORY RESET' ); ?>
1693                <?php echo esc_html( $str ); ?>
1694                </p>
1695                <div class="zbs-delete-box" style="max-width:70%;margin:auto;">
1696                <p class='ui message warning'>
1697                    <i class='ui icon exclamation'></i><b> <?php esc_html_e( 'Warning: This cannot be undone', 'zero-bs-crm' ); ?></b>
1698                </p>
1699                <form id="factory-reset" class="ui form" action="#" method="POST">
1700                    <input class="form-control" id="zbs-delete-all-data" name="zbs-delete-all-data" type="text" value="" placeholder="FACTORY RESET" style="text-align:center;font-size:25px;"/>
1701                    <input type="submit" class="ui button red" value="<?php esc_attr_e( 'Reset CRM', 'zero-bs-crm' ); ?>" style="margin-top:10px;"/>
1702                </form>
1703                </div>          
1704            </div>
1705        </div>
1706
1707    </div>
1708
1709    
1710    
1711    
1712        <?php
1713
1714    }
1715}
1716
1717// } Install Extensions helper page
1718function zeroBSCRM_html_installextensionshelper() {
1719
1720    global $wpdb, $zbs;  // } Req
1721
1722    // } 27th Feb 2019 - MS pimp this page a little - but WL remove the salesy bit. bring into semantic UI properly too
1723    ?>
1724            <style>
1725            .intro{
1726                font-size:18px !important;;
1727                font-weight:200;
1728                line-height:20px;
1729                margin-bottom:10px;
1730                margin-top:20px;
1731            }
1732            .zbs-admin-segment-center{
1733                text-align:center;
1734            }
1735            h2{
1736                font-weight:900;
1737                padding-bottom:30px;
1738            }
1739            .intro-buttons{
1740                padding:20px;
1741            }
1742            </style>
1743            <div class="ui segment zbs-admin-segment-center" style="margin-right:15px;">
1744    <?php
1745            ##WLREMOVE
1746            zeroBSCRM_extension_installer_promo();
1747            ##/WLREMOVE
1748    ?>
1749            <h2><?php esc_html_e( 'Installing Extensions for Jetpack CRM', 'zero-bs-crm' ); ?></h2>
1750            <p class="intro"><?php echo wp_kses( sprintf( __( 'To control which modules are active, please go the <a href="%s">Core Module page</a>.', 'zero-bs-crm' ), esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['modules'] ) ) ), $zbs->acceptable_restricted_html ); ?></p>
1751            <p class="intro"><?php echo wp_kses( sprintf( __( 'To install premium extensions, purchased in a bundle or individually please go to <a href="%s">Plugins</a> and add your new extensions there.', 'zero-bs-crm' ), esc_url( admin_url( 'plugins.php' ) ) ), $zbs->acceptable_restricted_html ); ?></p>
1752            <p class="intro-buttons">
1753            <a href="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>" class="ui button primary"><i class="fa fa-plug" aria-hidden="true"></i> <?php esc_html_e( 'Upload Purchased Extensions', 'zero-bs-crm' ); ?></a>
1754            <?php ##WLREMOVE ?>
1755            <a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['extensions'] ) ); ?>" class="ui button green"><i class="fa fa-search" aria-hidden="true"></i> <?php esc_html_e( 'Browse Extensions', 'zero-bs-crm' ); ?></a>
1756            <?php ##/WLREMOVE ?>
1757            </p>
1758    </div>
1759    
1760    <?php
1761}
1762
1763function zeroBSCRM_extension_installer_promo() {
1764    // extra function here to output additional bullie type stuff.
1765    ?>
1766    <div class="bullie">
1767    <img src="<?php echo esc_url( jpcrm_get_logo( false ) ); ?>" alt="<?php esc_attr_e( 'Jetpack CRM logo', 'zero-bs-crm' ); ?>">
1768    </div>
1769    <?php
1770}
1771
1772function zeroBSCRM_html_extensions_forWelcomeWizard() {
1773
1774    global $wpdb, $zbs;  // } Req
1775    ?>
1776
1777
1778
1779            
1780        <div id="sbSubPage" style="width:100%;max-width:1000px"><h2 class="sbhomep"><?php esc_html_e( 'Power Up your CRM', 'zero-bs-crm' ); ?></h2>
1781            <p class="sbhomep"><?php esc_html_e( 'We hope that you love using Jetpack CRM and that you agree with our mentality of stripping out useless features and keeping things simple. Cool.', 'zero-bs-crm' ); ?></p>
1782            <p class="sbhomep"><?php esc_html_e( "We offer a few extensions which supercharge your CRM. As is our principle, though, you wont find any bloated products here. These are simple, effective power ups for Jetpack CRM. And compared to pay-monthly costs, they're affordable! Win!", 'zero-bs-crm' ); ?></p>
1783            <div style="width:100%"><a href="<?php echo esc_url( $zbs->urls['products'] ); ?>" target="_blank"><img style="width:100%;max-width:100%;margin-left:auto;margin-right:auto;" src="<?php echo esc_url( $zbs->urls['extimgrepo'] . 'extensions.png' ); ?>" alt="" /></a></div>
1784            <p class="sbhomep">
1785            <a href="<?php echo esc_url( $zbs->urls['products'] ); ?>" class="ui button primary" style="padding: 7px 16px;font-size: 22px;height: 46px;" target="_blank"><?php esc_html_e( 'View More', 'zero-bs-crm' ); ?></a>    
1786            </p>
1787    </div>
1788    <?php
1789}
1790
1791// } helper for extension page (installs/uninstalls at init)
1792function zeroBSCRM_extensions_init_install() {
1793
1794    // } Anything to install/uninstall?
1795    if ( isset( $_GET['zbsinstall'] ) && ! empty( $_GET['zbsinstall'] ) ) {
1796
1797        global $zbs, $zbsExtensionInstallError;
1798
1799        // } Validate
1800        global $zeroBSCRM_extensionsCompleteList;
1801
1802        if (
1803        wp_verify_nonce( $_GET['_wpnonce'], 'zbscrminstallnonce' )
1804        &&
1805        // } Ext exists
1806        array_key_exists( $_GET['zbsinstall'], $zeroBSCRM_extensionsCompleteList ) ) {
1807
1808            // Extension data
1809            $toActOn            = sanitize_text_field( $_GET['zbsinstall'] );
1810            $function_safe_name = str_replace( '-', '_', $toActOn );
1811            $extension_details  = zeroBSCRM_returnExtensionDetails( $toActOn );
1812            $installName        = 'Unknown';
1813            if ( isset( $extension_details['name'] ) ) {
1814                $installName = $extension_details['name'];
1815            }
1816            $helpurl = isset( $extension_details['meta'] ) && isset( $extension_details['meta']['helpurl'] ) && ! empty( $extension_details['meta']['helpurl'] ) ? $extension_details['meta']['helpurl'] : $zbs->urls['docs'];
1817
1818            // Action
1819            if ( zeroBSCRM_isExtensionInstalled( $toActOn ) ) {
1820                $act = 'uninstall';
1821            } else {
1822                $act = 'install';
1823            }
1824
1825            $successfullyInstalled = false;
1826
1827            // } Try it
1828            try {
1829
1830                if ( $act == 'install' ) {
1831
1832                    // } INSTALL
1833
1834                    // } If install func exists
1835                    if ( function_exists( 'zeroBSCRM_extension_install_' . $function_safe_name ) ) {
1836
1837                        // } try it (returns bool)
1838                        $successfullyInstalled = call_user_func( 'zeroBSCRM_extension_install_' . $function_safe_name );
1839
1840                    }
1841                } else {
1842
1843                            // } UNINSTALL
1844
1845                            // } If install func exists
1846                    if ( function_exists( 'zeroBSCRM_extension_uninstall_' . $function_safe_name ) ) {
1847
1848                        // } try it (returns bool)
1849                        $successfullyInstalled = call_user_func( 'zeroBSCRM_extension_uninstall_' . $function_safe_name );
1850
1851                    }
1852                }
1853            } catch ( Exception $ex ) {
1854
1855                        // meh
1856
1857            }
1858
1859            // set transient to pass any relevant messages
1860            $extension_messages = array(
1861                'success'           => $successfullyInstalled,
1862                'extension_name'    => $toActOn,
1863                'extension_details' => $extension_details,
1864                'pretty_name'       => $installName,
1865                'action'            => $act,
1866                'helpurl'           => $helpurl,
1867                'error_msg'         => $zbsExtensionInstallError,
1868            );
1869
1870            set_transient( 'jpcrm_extension_messages', $extension_messages, MINUTE_IN_SECONDS );
1871            wp_redirect( jpcrm_esc_link( $zbs->slugs['modules'] ) );
1872
1873        }
1874    }
1875}
1876
1877function zeroBSCRM_html_extensions() {
1878
1879    // globals
1880    global $zbs, $zeroBSCRM_extensionsInstalledList;
1881
1882    // new design - for the fact we are adding new extensions all the time and now won't need to
1883    // keep on remembering to update this array and it will keep up to date. Also with things
1884    // like livestorm "connect" needed an on the flyfix.
1885
1886    // WH added: Is now polite to License-key based settings like 'entrepreneur' doesn't try and upsell
1887    // this might be a bit easy to "hack out" hmmmm
1888    $bundle = false;
1889    if ( $zbs->hasEntrepreneurBundleMin() ) {
1890        $bundle = true;
1891    }
1892
1893    echo '<div class="zbs-extensions-manager">';
1894
1895    // get the products, from our sites JSON custom REST endpoint - that way only need to manage there and not remember to update all the time
1896    // each product has our extkey so can do the same as the built in array here ;) #progress #woop-da-woop
1897    if ( isset( $_GET['extension_id'] ) && ! empty( $_GET['extension_id'] ) ) {
1898        ##WLREMOVE
1899            echo '<div class="zbs-page-wrap thinner" id="error-stuff">';
1900            $id      = (int) sanitize_text_field( $_GET['extension_id'] );
1901            $request = wp_safe_remote_get( 'https://jetpackcrm.com/wp-json/zbsextensions/v1/extensions/' . $id );
1902
1903        if ( is_wp_error( $request ) ) {
1904
1905            echo '<div class="zbs-page-wrap">';
1906            echo '<div class="ui message alert warning" style="display:block;margin-bottom: -25px;"><i class="wifi icon"></i> ';
1907                esc_html_e( 'You must be connected to the internet to view our live extensions page.', 'zero-bs-crm' );
1908            echo '</div>';
1909            echo '</div>';
1910
1911            return false;
1912        }
1913
1914            $body      = wp_remote_retrieve_body( $request );
1915            $extension = json_decode( $body );
1916            $info      = $extension->product;
1917
1918        if ( $info == 'error' ) {
1919            echo '<div class="zbs-page-wrap">';
1920                echo '<div class="ui message alert error" style="display:block;margin-bottom: -25px;"><i class="exclamation icon"></i> ';
1921                esc_html_e( 'Product does not exist.', 'zero-bs-crm' );
1922                echo ' <a href="' . esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['extensions'] ) ) . '">' . esc_html__( 'Go Back', 'zero-bs-crm' ) . '</a>';
1923            echo '</div>';
1924            echo '</div>';
1925            return false;
1926        }
1927            echo '</div>';
1928            // end of #error-stuff
1929
1930            echo '<div class="zbs-page-wrap thinner single-info-start">';
1931
1932            echo '<div class="ui segment main-header-img">';
1933                echo '<div class="back">';
1934                echo '<a href="' . esc_url( admin_url( 'admin.php?page=' . $zbs->slugs['extensions'] ) ) . '"><i class="chevron left icon"></i> ' . esc_html__( 'Back', 'zero-bs-crm' ) . '</a>';
1935                echo '</div>';
1936
1937                echo '<div class="main-image full-size-image">';
1938                echo '<img src="' . esc_url( $info->image ) . '" alt="' . esc_attr( $info->name ) . '"/>';
1939                echo '</div>';
1940
1941                echo '<div class="below-main-image about-author-block">';
1942                    // start the about block
1943                    echo '<div class="about-img"><img alt="Jetpack CRM logo" src="' . esc_url( $info->by ) . '"/>';
1944                    echo '<div class="top-info-block">';
1945                    echo '<h4 class="extension-name">' . esc_html( $info->name ) . '</h4>';
1946                    echo '<div class="who">' . esc_html__( 'by ', 'zero-bs-crm' ) . '<a class="by-url" href="' . esc_url( $zbs->urls['home'] ) . '" target="_blank">Jetpack CRM</a></div>';
1947                    echo '</div>';
1948                    echo '</div>';
1949                    // end the about block
1950
1951                    // action block (installed / not)
1952                    $extkey     = $info->extkey;
1953                    $sales_link = $zbs->urls['home'] . '/product/' . $info->slug;
1954
1955                    $installed = zeroBSCRM_isExtensionInstalled( $extkey );
1956                    $docs      = $info->docs;
1957                    echo '<div class="actions-block"><div class="install-ext">';
1958        if ( $installed ) {
1959            echo '<span class="ui label green large"><i class="check circle icon"></i> ' . esc_html__( 'Installed', 'zero-bs-crm' ) . '</span>';
1960        } elseif ( $bundle ) {
1961            echo '<a href="' . esc_url( $zbs->urls['account'] ) . '" class="ui blue button" target="_blank"><i class="download icon"></i> ' . esc_html__( 'Download', 'zero-bs-crm' ) . '</a>';
1962        } else {
1963            echo '<a href="' . esc_url( $sales_link ) . '" class="ui blue button" target="_blank"><i class="cart icon"></i> ' . esc_html__( 'Buy', 'zero-bs-crm' ) . '</a>';
1964        }
1965        if ( ! empty( $docs ) ) {
1966            echo '<a class="docs-url ui button" href="' . esc_url( $docs ) . '" target="_blank"><i class="book icon"></i>' . esc_html__( 'View Docs', 'zero-bs-crm' ) . '</a>';
1967        }
1968                    echo '</div>';
1969                    echo '</div>';
1970                    // end action block
1971                echo '</div>';
1972                // end the about-author-block
1973
1974                echo '<div class="clear"></div>'; // clear stuff
1975
1976            echo '</div>';  // end the whole header image block
1977
1978            echo '</div>';
1979            // end the start of the info block (top block)
1980
1981            echo '<div class="zbs-page-wrap thinner single-bundle-wrap">';
1982        if ( ! $bundle ) {
1983            echo '<div class="bullie-wrap">';
1984            echo '<div class="bullie">';
1985                echo '<img src="' . esc_url( jpcrm_get_logo() ) . '" alt="Jetpack CRM" style="height:48px;padding:10px;">';
1986                echo '<div class="upgrade">' . esc_html__( 'Purchase the Entrepreneur Bundle to get access to all of our CRM extensions.', 'zero-bs-crm' ) . '</div>';
1987                echo '<a class = "ui button green mini upgrade-bullie-box" href="' . esc_url( $zbs->urls['upgrade'] ) . '" target = "_blank"><i class="cart plus icon"></i> ' . esc_html__( 'Start', 'zero-bs-crm' ) . '</a>';
1988            echo '</div>';
1989            echo '</div>';
1990            echo '<div class="clear"></div>';
1991        }
1992            echo '</div>';
1993
1994            echo '<div class="zbs-page-wrap thinner" id="single-ext-desc">';
1995            echo '<div class="ui segment main-talk">';
1996                echo '<div class="extension-description">';
1997
1998                    // semantic ui switch html from bootstrap ones (grids basically)
1999                    $desc = str_replace( 'class="row"', 'class="ui grid"', $info->description );
2000                    $desc = str_replace( ' row"', ' ui grid"', $desc );
2001                    $desc = str_replace( 'col-md-6', 'eight wide column', $desc );
2002                    $desc = str_replace( 'col-sm-8', 'ten wide column', $desc );
2003                    $desc = str_replace( 'col-lg-1', '', $desc );
2004                    $desc = str_replace( 'col-lg-2', 'four wide column', $desc );
2005
2006                    echo $desc;
2007                echo '</div>';
2008                // buy
2009        if ( ! $installed && ! $bundle ) {
2010            echo '<hr /><div style="margin:2em;text-align:center"><a href="' . esc_url( $sales_link ) . '" class = "ui large blue button" target="_blank"><i class="cart icon"></i> ' . esc_html__( 'Buy Extension', 'zero-bs-crm' ) . '</a></div>';
2011        }
2012            echo '</div>';
2013            echo '</div>';
2014            // id="single-ext-desc"
2015
2016        ##/WLREMOVE
2017    } else {
2018
2019        ##WLREMOVE
2020            $showLinkButton = true;
2021
2022            // get the JSON response from woocommerce REST endpoint.
2023            $request = wp_safe_remote_get( $zbs->urls['checkoutapi'] );
2024        if ( is_wp_error( $request ) ) {
2025            // if there's an error, server the JSON in the function
2026            $extensions = json_decode( zeroBSCRM_serve_cached_extension_block() );
2027            echo '<div class="zbs-page-wrap">';
2028                echo '<div class="ui message alert warning" style="display:block;margin-bottom: -25px;"><i class="wifi icon"></i> ';
2029                esc_html_e( 'You must be connected to the internet to view our live extensions page. You are being shown an offline version.', 'zero-bs-crm' );
2030            echo '</div>';
2031            echo '</div>';
2032            $showLinkButton = false;
2033        } else {
2034            $body       = wp_remote_retrieve_body( $request );
2035            $extensions = json_decode( $body );
2036        }
2037
2038            // if we somehow still haven't got actual obj, use cached:
2039            // .. This was happening when our mainsite json endpoint is down
2040        if ( ! is_array( $extensions->paid ) ) {
2041            $extensions = json_decode( zeroBSCRM_serve_cached_extension_block() );
2042        }
2043
2044            echo '<div class="zbs-page-wrap">';
2045        if ( ! $bundle ) {
2046            echo '<div class="bullie-wrap">';
2047            echo '<div class="bullie">';
2048            echo '<img src="' . esc_url( jpcrm_get_logo( false ) ) . '" alt="Jetpack CRM" style="height: 48px; padding:10px;">';
2049            echo '<div class="upgrade">' . esc_html__( 'Purchase the Entrepreneur Bundle to get access to all of our CRM extensions.', 'zero-bs-crm' ) . '</div>';
2050            echo '<a class="ui button green mini upgrade-bullie-box" href="' . esc_url( $zbs->urls['upgrade'] ) . '" target = "_blank"><i class="cart plus icon"></i> ' . esc_html__( 'Buy  Now', 'zero-bs-crm' ) . '</a>';
2051            echo '</div>';
2052            echo '</div>';
2053            echo '<div class="clear"></div>';
2054        }
2055            echo '<div class="ui top attached header premium-box"><h3 class="box-title">' . esc_html__( 'Premium Extensions', 'zero-bs-crm' ) . '</h3>   <a class="guides ui button black mini" href="' . esc_url( $zbs->urls['docs'] ) . '" target="_blank"><i class="book icon"></i> ' . esc_html__( 'Knowledge-base', 'zero-bs-crm' ) . '</a> <a style="color: black !important;box-shadow: 0 0 0 1px black inset !important;" class="guides ui button blue basic mini" href="' . esc_url( zeroBSCRM_getAdminURL( $zbs->slugs['modules'] ) ) . '"><i class="puzzle piece icon"></i> ' . esc_html__( 'Core Modules', 'zero-bs-crm' ) . '</a>   </div>';
2056            echo '<div class="clear"></div>';
2057            echo '<div class="ui segment attached">';
2058                echo '<div class="ui internally celled grid">';
2059
2060                $e = 0;
2061        $count     = 0;
2062        $idsToHide = array( 17121, 17119 );
2063        if ( is_array( $extensions->paid ) ) {
2064
2065            $top_woo_extension_slugs = array( 'advanced-segments', 'sales-dashboard', 'automations', 'client-portal-pro', 'csv-importer-pro', 'wordpress-utilities' );
2066            $extensions_to_display   = array();
2067            $top_woo_extensions      = array();
2068            $has_woosync             = zeroBSCRM_isExtensionInstalled( 'woo-sync' );
2069
2070            // We want to prioritize the top 5 Woo modules in the list if 'woosync' is active, but otherwise alphabetize everything.
2071            foreach ( $extensions->paid as $extension ) {
2072                if ( $has_woosync && ! empty( $extension->slug ) && in_array( $extension->slug, $top_woo_extension_slugs, true ) ) {
2073                    $top_woo_extensions[] = $extension;
2074                    continue;
2075                }
2076                $extensions_to_display[] = $extension;
2077            }
2078
2079            if ( count( $top_woo_extensions ) !== 0 ) {
2080                usort(
2081                    $top_woo_extensions,
2082                    function (
2083                        $str1,
2084                        $str2
2085                    ) {
2086                        return strcasecmp( $str1->name, $str2->name );
2087                    }
2088                );
2089            }
2090
2091            usort(
2092                $extensions_to_display,
2093                function (
2094                    $str1,
2095                    $str2
2096                ) {
2097                    return strcasecmp( $str1->name, $str2->name );
2098                }
2099            );
2100
2101            $extensions_to_display = array_merge( $top_woo_extensions, $extensions_to_display );
2102
2103            foreach ( $extensions_to_display as $extension ) {
2104                // hide bundles
2105                if ( ! in_array( $extension->id, $idsToHide ) ) {
2106
2107                    $more_url = admin_url( 'admin.php?page=' . $zbs->slugs['extensions'] . '&extension_id=' . $extension->id );
2108
2109                    $extkey    = $extension->extkey;
2110                    $installed = zeroBSCRM_isExtensionInstalled( $extkey );
2111                    if ( $e == 0 ) {
2112                        echo '<div class="row">';
2113                    }
2114
2115                    echo "<div class='two wide column'>";
2116                        echo "<img alt='" . esc_attr( $extension->name ) . "' src='" . esc_url( $extension->image ) . "'/>";
2117                    echo '</div>';
2118
2119                    echo "<div class='six wide column ext-desc'>";
2120                    if ( $installed ) {
2121                        echo '<div class="ui green right corner label"><i class="check icon"></i></div>';
2122                    }
2123                    echo "<div class='title'>" . esc_html( $extension->name ) . '</div>';
2124                    echo "<div class='content'>" . $extension->short_desc . '</div>';
2125
2126                    if ( $showLinkButton ) {
2127                            echo '<div class="hover"></div><div class="hover-link">';
2128
2129                            $sales_link = $zbs->urls['home'] . '/product/' . $extension->slug;
2130
2131                            // api connector skips these
2132                        if ( $extkey == 'apiconnector' ) {
2133
2134                            // api connector
2135
2136                            // view
2137                            echo "<a href='" . esc_url( $zbs->urls['apiconnectorsales'] ) . "' target='_blank'><span class='ui button orange mini'>" . esc_html__( 'View', 'zero-bs-crm' ) . '</span></a>';
2138
2139                            // download or buy
2140                            if ( $bundle ) {
2141                                echo "<a href='" . esc_url( $zbs->urls['account'] ) . "' target='_blank'><span class='ui button green mini'>" . esc_html__( 'Download', 'zero-bs-crm' ) . '</span></a>';
2142                            } else {
2143                                echo "<a href='" . esc_url( $sales_link ) . "' target='_blank'><span class='ui button green mini'>" . esc_html__( 'Buy', 'zero-bs-crm' ) . '</span></a>';
2144                            }
2145                        } else {
2146
2147                                                // non api connector
2148                                                echo "<a href='" . esc_url( $more_url ) . "'><span class='ui button orange mini'>" . esc_html__( 'View', 'zero-bs-crm' ) . '</span></a>';
2149
2150                            if ( ! $installed ) {
2151
2152                                if ( $bundle ) {
2153                                    echo "<a href='" . esc_url( $zbs->urls['account'] ) . "' target='_blank'><span class='ui button green mini'>" . esc_html__( 'Download', 'zero-bs-crm' ) . '</span></a>';
2154                                } else {
2155                                    echo "<a href='" . esc_url( $sales_link ) . "' target='_blank'><span class='ui button green mini'>" . esc_html__( 'Buy', 'zero-bs-crm' ) . '</span></a>';
2156                                }
2157                            } elseif ( isset( $extension->docs ) && ! empty( $extension->docs ) ) {
2158                                echo "<a href='" . esc_url( $extension->docs ) . "' target='_blank'><span class='ui button blue mini'>" . esc_html__( 'Docs', 'zero-bs-crm' ) . '</span></a>';
2159                            }
2160                        }
2161                        echo '</div>';
2162                    }
2163
2164                            echo '</div>';
2165
2166                            ++$e;
2167                            ++$count;
2168                    if ( $e > 1 ) {
2169                        echo '</div>';
2170                        $e = 0;
2171                    }
2172                } // / if not hidde
2173
2174            }
2175        }
2176
2177                // add on the coming soon block
2178        if ( $e == 1 ) {
2179
2180            // End of row
2181
2182                echo "<div class='two wide column'>";
2183                echo "<img alt='" . esc_attr__( 'Coming Soon', 'zero-bs-crm' ) . "' src='" . esc_url( plugins_url( 'i/soon.png', ZBS_ROOTFILE ) ) . "'/>";
2184                echo '</div>';
2185
2186                echo "<div class='six wide column ext-desc'>";
2187                echo "<div class='title'>" . esc_html__( 'Coming soon', 'zero-bs-crm' ) . '</div>';
2188                echo "<div class='content'>" . esc_html__( 'See and vote for what extensions we release next', 'zero-bs-crm' ) . '</div>';
2189
2190                echo '<div class="hover"></div>';
2191                echo "<a class='hover-link' href='" . esc_url( $zbs->urls['soon'] ) . "' target='_blank'><span class='ui button orange mini'>" . esc_html__( 'View', 'zero-bs-crm' ) . '</span></a>';
2192                echo '</div>';
2193
2194        } else {
2195
2196            // Row to itself
2197
2198            echo '<div class="row">';
2199
2200            echo "<div class='two wide column'>";
2201            echo "<img alt='" . esc_attr__( 'Coming Soon', 'zero-bs-crm' ) . "' src='" . esc_url( plugins_url( 'i/soon.png', ZBS_ROOTFILE ) ) . "'/>";
2202            echo '</div>';
2203
2204            echo "<div class='six wide column ext-desc'>";
2205
2206            echo "<div class='title'>" . esc_html__( 'Coming soon', 'zero-bs-crm' ) . '</div>';
2207            echo "<div class='content'>" . esc_html__( 'See and vote for what extensions we release next', 'zero-bs-crm' ) . '</div>';
2208
2209            echo '<div class="hover"></div>';
2210            echo "<a class='hover-link' href='" . esc_url( $zbs->urls['soon'] ) . "' target='_blank'><span class='ui button orange mini'>" . esc_html__( 'View', 'zero-bs-crm' ) . '</span></a>';
2211            echo '</div>';
2212
2213        }
2214
2215                // coming soon end row
2216                echo '</div>'; // end the row (as it will be adding on)
2217
2218                echo '</div>';
2219            echo '</div>';
2220            echo '</div>';  // end page wrap.
2221
2222            ##/WLREMOVE
2223
2224    }
2225
2226    echo '</div>';
2227}
2228
2229// moving the CRM modules into a new function so can be found easier
2230function jpcrm_html_modules() {
2231
2232    global $zbs;
2233
2234    if ( ! isset( $_GET['zbsinstall'] ) ) {
2235
2236        $transient_key   = 'jpcrm_extension_messages';
2237        $module_messages = get_transient( $transient_key );
2238        delete_transient( $transient_key );
2239    }
2240
2241    // Install/uninstall message
2242    if ( ! empty( $module_messages ) ) {
2243        echo '<div class="zbs-page-wrap install-message-list" style="margin-top:10px;">';
2244        if ( $module_messages['success'] ) {
2245
2246            $msgHTML = '<i class="fa fa-check" aria-hidden="true"></i> ';
2247            if ( $module_messages['action'] === 'install' ) {
2248                $msgHTML .= __( 'Successfully activated module:', 'zero-bs-crm' );
2249            } else {
2250                $msgHTML .= __( 'Successfully deactivated module:', 'zero-bs-crm' );
2251            }
2252            $msgHTML .= ' ' . $module_messages['pretty_name'];
2253
2254            // if API, catch and give further info (e.g. no key)
2255            if ( $module_messages['action'] === 'install' && $module_messages['pretty_name'] === 'API' ) {
2256
2257                // installed API
2258                // get if set
2259                $api_key    = zeroBSCRM_getAPIKey();
2260                $api_secret = zeroBSCRM_getAPISecret();
2261                // $endpoint_url = zeroBSCRM_getAPIEndpoint();
2262                if ( empty( $api_key ) ) {
2263
2264                    // assume no keys yet, tell em
2265                    $msgHTML .= '<hr />' . __( 'You can now generate API Keys and send data into your CRM via API:', 'zero-bs-crm' ) . '<p style="padding:1em"><a href="' . jpcrm_esc_link( $zbs->slugs['settings'] ) . '&tab=api" class="ui button green">' . __( 'Generate API Keys', 'zero-bs-crm' ) . '</a></p>';
2266
2267                }
2268            }
2269
2270            // if WooSync, Signpost hub page
2271            if ( $module_messages['action'] == 'install' && $module_messages['extension_name'] == 'woosync' ) {
2272
2273                // assume no keys yet, tell em
2274                $msgHTML .= '<hr />' . __( 'To get started importing your WooCommerce orders, visit the WooSync hub:', 'zero-bs-crm' ) . '<p style="padding:1em"><a href="' . jpcrm_esc_link( $zbs->slugs['woosync'] ) . '" class="ui button green">' . __( 'Get started with WooSync', 'zero-bs-crm' ) . '</a></p>';
2275
2276            }
2277
2278            // Show a help url if present
2279            if ( $module_messages['action'] === 'install' ) {
2280
2281                $msgHTML .= '<br /><i class="fa fa-info-circle" aria-hidden="true"></i> <a href="' . $module_messages['helpurl'] . '" target="_blank">' . __( 'View Help Documentation', 'zero-bs-crm' ) . '</a>';
2282
2283            }
2284
2285            zeroBSCRM_html_msg( 0, $msgHTML ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
2286
2287        } else {
2288
2289            $errmsg = __( 'Unable to activate module:', 'zero-bs-crm' ) . ' ' . $module_messages['pretty_name'] . '<br>' . sprintf( __( 'Please contact <a href="%s" target="_blank">Support</a> if this persists.', 'zero-bs-crm' ), $zbs->urls['support'] );
2290
2291            if ( isset( $module_messages['error_msg'] ) ) {
2292                $errmsg .= '<br />' . __( 'Installer Error:', 'zero-bs-crm' ) . ' ' . $module_messages['error_msg'];
2293            }
2294
2295            zeroBSCRM_html_msg( -1, $errmsg );
2296
2297        }
2298
2299        echo '</div>';
2300
2301    }
2302
2303    echo '<div class="zbs-extensions-manager">';
2304
2305            // this block should be in here for rebranded people who want to turn on or off features.
2306            echo '<div class="zbs-page-wrap free-block-wrap">';
2307            echo '<h3 class="ui top attached header free-box" id="core-modules">' . esc_html__( 'Core Modules', 'zero-bs-crm' ) . '</h3>';
2308            echo '<div class="ui segment attached free-ext-area">';
2309            echo '<div class="ui internally celled grid">';
2310
2311                // output the free stuff :-) with turn on / off.
2312                $e = 0;
2313    foreach ( zeroBSCRM_extensions_free() as $k => $v ) {
2314
2315        if ( is_array( $v ) ) {
2316
2317                    $modify_url = wp_nonce_url( 'admin.php?page=' . $zbs->slugs['modules'] . '&zbsinstall=' . $k, 'zbscrminstallnonce' );
2318
2319                    $installed = zeroBSCRM_isExtensionInstalled( $k );
2320
2321            if ( $e == 0 ) {
2322                echo '<div class="row">';
2323            }
2324
2325                    echo "<div class='two wide column free-ext-img'>";
2326                        echo "<img src='" . esc_url( plugins_url( 'i/' . $v['i'], ZBS_ROOTFILE ) ) . "'/>";
2327                    echo '</div>';
2328
2329                    echo "<div class='six wide column ext-desc'>";
2330                        $amend       = __( 'Activate', 'zero-bs-crm' );
2331                        $amend_color = 'green';
2332            if ( $installed ) {
2333                echo '<div class="ui green right corner label"><i class="check icon"></i></div>';
2334                $amend       = __( 'Deactivate', 'zero-bs-crm' );
2335                $amend_color = 'red';
2336            } else {
2337                echo '<div class="ui red right corner label"><i class="times icon"></i></div>';
2338            }
2339                        echo "<div class='title'>" . esc_html( $v['name'] ) . '</div>';
2340                        echo "<div class='content'>" . $v['short_desc'] . '</div>';
2341
2342                        echo '<div class="hover"></div>';
2343                        echo "<a class='hover-link' href='" . esc_url( $modify_url ) . "'><span class='ui button " . esc_attr( $amend_color ) . " mini'>" . esc_html( $amend ) . '</span></a>';
2344
2345                    echo '</div>';
2346
2347                    ++$e;
2348            if ( $e > 1 ) {
2349                echo '</div>';
2350                $e = 0;
2351            }
2352        } // / if is array (csvimporterlite = false so won't show here)
2353
2354    } // /foreach
2355
2356            echo '</div>';
2357            echo '</div>';
2358        echo '</div>';
2359
2360        echo '</div>';
2361}
2362
2363// } post-deletion page
2364function zeroBSCRM_html_norights() {
2365
2366    global $zbs;
2367
2368    $back_to_page = 'edit.php?post_type=zerobs_customer&page=manage-customers';
2369
2370    $obj_type_str = $zbs->zbsvar( 'zbstype' ); // -1 or 'contact'
2371
2372    // if objtypestr is -1, assume contact (default)
2373    if ( $obj_type_str === -1 ) {
2374        $obj_type_id = ZBS_TYPE_CONTACT;
2375    } else {
2376        $obj_type_id = $zbs->DAL->objTypeID( $obj_type_str ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2377    }
2378
2379    // if got type, link to list view
2380    // else give dash link
2381    $slug_to_send       = '';
2382    $no_access_type_str = '';
2383
2384    // back to page
2385    if ( $obj_type_id > 0 ) {
2386        $slug_to_send = $zbs->DAL->listViewSlugFromObjID( $obj_type_id ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2387    }
2388    if ( empty( $slug_to_send ) ) {
2389        $slug_to_send = $zbs->slugs['dash'];
2390    }
2391    $back_to_page = 'admin.php?page=' . $slug_to_send;
2392
2393    // obj type str
2394    if ( $obj_type_id > 0 ) {
2395        $no_access_type_str = $zbs->DAL->typeStr( $obj_type_id ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
2396    }
2397    if ( empty( $no_access_type_str ) ) {
2398        $no_access_type_str = __( 'Object', 'zero-bs-crm' );
2399    }
2400
2401    ?>
2402    <div id="zbsNoAccessPage">
2403        <div id="zbsNoAccessMsgWrap">
2404        <div id="zbsNoAccessIco"><i class="fa fa-archive" aria-hidden="true"></i></div>
2405        <div class="zbsNoAccessMsg">
2406            <h2><?php esc_html_e( 'Access Restricted', 'zero-bs-crm' ); ?></h2>
2407            <p>
2408                <?php
2409                // translators: Object type (e.g. contact, company)
2410                echo esc_html( sprintf( __( 'You do not have access to this %s.', 'zero-bs-crm' ), $no_access_type_str ) );
2411                ?>
2412            </p>
2413        </div>
2414        <div class="zbsNoAccessAction">
2415            <button type="button" class="ui button primary" onclick="javascript:window.location='<?php echo esc_url( $back_to_page ); ?>'"><?php esc_html_e( 'Back', 'zero-bs-crm' ); ?></button>
2416
2417        </div>
2418        </div>
2419    </div>
2420    <?php
2421}
2422
2423/*
2424======================================================
2425    / Admin Pages
2426    ====================================================== */
2427
2428/*
2429======================================================
2430    HTML Output Msg (alerts)
2431    ====================================================== */
2432
2433    // } wrapper here for lib
2434function whStyles_html_msg( $flag, $msg, $includeExclaim = false ) {
2435
2436    zeroBSCRM_html_msg( $flag, $msg, $includeExclaim );
2437}
2438
2439    // } Outputs HTML message - 27th Feb 2019 - modified for Semantic UI (still had sgExclaim!)
2440function zeroBSCRM_html_msg( $flag, $msg, $includeExclaim = false ) {
2441
2442    if ( $includeExclaim ) {
2443        $msg = '<div id="sgExclaim">!</div>' . $msg . ''; }
2444    if ( $flag == -1 ) {
2445        echo '<div class="ui message alert danger">' . $msg . '</div>';
2446    }
2447    if ( $flag == 0 ) {
2448        echo '<div class="ui message alert success">' . $msg . '</div>';
2449    }
2450    if ( $flag == 1 ) {
2451        echo '<div class="ui message alert warning">' . $msg . '</div>';
2452    }
2453    if ( $flag == 2 ) {
2454        echo '<div class="ui message alert info">' . $msg . '</div>';
2455    }
2456}
2457
2458/*
2459======================================================
2460    / HTML Output Msg (alerts)
2461    ====================================================== */