| @@ -1,150 +1,177 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Email Subscription Template | |
| 4 | - * | |
| 5 | - * @package Botmaster | |
| 6 | - * @since 14.8.2 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; | |
| 11 | -} | |
| 12 | - | |
| 13 | - wp_register_style( 'qlcd-wp-chatbot-admin-style-email', QCLD_wpCHATBOT_PLUGIN_URL . '/css/email_subscription.css', '', QCLD_wpCHATBOT_VERSION, 'screen' ); | |
| 14 | - wp_enqueue_style( 'qlcd-wp-chatbot-admin-style-email' ); | |
| 15 | - | |
| 16 | - wp_register_script( 'qcld-wp-chatbot-email-subscription-js', QCLD_wpCHATBOT_PLUGIN_URL . '/js/email_subscription.js', array( 'jquery' ), true ); | |
| 17 | - wp_enqueue_script( 'qcld-wp-chatbot-email-subscription-js' ); | |
| 18 | - | |
| 19 | - global $wpdb; | |
| 20 | -if ( ! function_exists( 'wp_get_current_user' ) ) { | |
| 21 | - include ABSPATH . 'wp-includes/pluggable.php'; | |
| 22 | -} | |
| 23 | - | |
| 24 | - $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 25 | - | |
| 26 | - if ( isset( $_POST['wpbot_email_subscription_remove'] ) && $_POST['wpbot_email_subscription_remove'] == '1' ) { | |
| 27 | - if ( current_user_can( 'manage_options' ) && isset( $_POST['emails'] ) && is_array( $_POST['emails'] ) ) { | |
| 28 | - foreach ( $_POST['emails'] as $email_id ) { | |
| 29 | - $wpdb->delete( $table, array( 'id' => intval( $email_id ) ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 30 | - } | |
| 31 | - echo '<script>window.location.href="' . esc_url_raw( admin_url( 'admin.php?page=email-subscription&msg=success' ) ) . '";</script>'; | |
| 32 | - exit; | |
| 33 | - } | |
| 34 | - } | |
| 35 | - | |
| 36 | - $current_user = wp_get_current_user(); | |
| 37 | - $url = admin_url( 'edit.php?post_type=sld&page=qcsld_click_list' ); | |
| 38 | - $customPagHTML = ''; | |
| 39 | - // Main Report Area | |
| 40 | - $sql1 = $wpdb->prepare( 'SELECT count(*) FROM %i where 1', $table ); | |
| 41 | - | |
| 42 | - $total = $wpdb->get_var( $sql1 ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 43 | - $items_per_page = 50; | |
| 44 | - | |
| 45 | - $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;// phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 46 | - $offset = ( $page * $items_per_page ) - $items_per_page; | |
| 47 | - | |
| 48 | - $sql = $wpdb->prepare( 'SELECT * FROM %i where 1 order by id desc LIMIT %d, %d', $table, $offset, $items_per_page ); | |
| 49 | - | |
| 50 | - $rows = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter | |
| 51 | - $totalPage = ceil( $total / $items_per_page ); | |
| 52 | - | |
| 53 | -if ( $totalPage > 1 ) { | |
| 54 | - $customPagHTML = '<div><span class="wpbot_pagination">Page ' . esc_html( $page ) . ' of ' . esc_html( $totalPage ) . '</span>' . paginate_links( | |
| 55 | - array( | |
| 56 | - 'base' => add_query_arg( 'cpage', '%#%' ), | |
| 57 | - 'format' => '', | |
| 58 | - 'prev_text' => esc_html__( '«' ), | |
| 59 | - 'next_text' => esc_html__( '»' ), | |
| 60 | - 'total' => esc_html( $totalPage ), | |
| 61 | - 'current' => esc_html( $page ), | |
| 62 | - ) | |
| 63 | - ) . '</div>'; | |
| 64 | -} | |
| 65 | - $mainurl = admin_url( 'admin.php?page=email-subscription' ); | |
| 66 | - | |
| 67 | -?> | |
| 68 | - <div class="qchero_sliders_list_wrapper"> | |
| 69 | - <div class="sld_menu_title"> | |
| 70 | - <h2><?php echo esc_html__( 'User Data', 'wpchatbot' ); ?></h2> | |
| 71 | - | |
| 72 | - </div> | |
| 73 | - | |
| 74 | - <div class="sld_menu_title sld_menu_title_align"><?php echo wp_kses_post( $customPagHTML ); ?><span style="float: right;"><a class="button-primary" href="<?php echo esc_url( admin_url( 'admin-post.php?action=wpbprint.csv' ) ); ?>">Export All Contacts</a> Total <?php echo esc_html( $total ); ?></span> </div> | |
| 75 | - | |
| 76 | - <?php | |
| 77 | - if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'success' ) {// phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 78 | - echo '<div class="notice notice-success"><p>Record has beed Deleted Successfully!</p></div>'; | |
| 79 | - } | |
| 80 | - ?> | |
| 81 | - | |
| 82 | - <form id="wpcs_form_sessions" action="<?php echo esc_url( $mainurl ); ?>" method="POST" style="width:100%"> | |
| 83 | - <input type="hidden" name="wpbot_email_subscription_remove" /> | |
| 84 | - | |
| 85 | - <button class="button-primary" id="wpbot_submit_email_form">Delete</button> | |
| 86 | - | |
| 87 | - <div class="qchero_slider_table_area"> | |
| 88 | - <div class="sld_payment_table"> | |
| 89 | - <div class="sld_payment_row header"> | |
| 90 | - | |
| 91 | - <div class="sld_payment_cell"> | |
| 92 | - <input type="checkbox" id="wpbot_checked_all" /> | |
| 93 | - </div> | |
| 94 | - | |
| 95 | - <div class="sld_payment_cell"> | |
| 96 | - <?php echo esc_html__( 'Date', 'wpchatbot' ); ?> | |
| 97 | - </div> | |
| 98 | - <div class="sld_payment_cell"> | |
| 99 | - <?php echo esc_html__( 'Name', 'wpchatbot' ); ?> | |
| 100 | - </div> | |
| 101 | - <div class="sld_payment_cell"> | |
| 102 | - <?php echo esc_html__( 'Email', 'wpchatbot' ); ?> | |
| 103 | - </div> | |
| 104 | - <div class="sld_payment_cell"> | |
| 105 | - <?php echo esc_html__( 'Phone', 'wpchatbot' ); ?> | |
| 106 | - </div> | |
| 107 | - | |
| 108 | - </div> | |
| 109 | - | |
| 110 | - <?php | |
| 111 | - foreach ( $rows as $row ) { | |
| 112 | - ?> | |
| 113 | - <div class="sld_payment_row"> | |
| 114 | - | |
| 115 | - <div class="sld_payment_cell"> | |
| 116 | - | |
| 117 | - <input type="checkbox" name="emails[]" class="wpbot_email_checkbox" value="<?php echo absint( $row->id ); ?>" /> | |
| 118 | - </div> | |
| 119 | - | |
| 120 | - <div class="sld_payment_cell"> | |
| 121 | - <div class="sld_responsive_head"><?php echo esc_html__( 'Date', 'wpchatbot' ); ?></div> | |
| 122 | - <?php echo esc_html( date( 'm/d/Y', strtotime( $row->date ) ) ); ?> | |
| 123 | - </div> | |
| 124 | - <div class="sld_payment_cell"> | |
| 125 | - <div class="sld_responsive_head"><?php echo esc_html__( 'Name', 'wpchatbot' ); ?></div> | |
| 126 | - <?php echo esc_html( $row->name ); ?> | |
| 127 | - </div> | |
| 128 | - <div class="sld_payment_cell"> | |
| 129 | - <div class="sld_responsive_head"><?php echo esc_html__( 'Email', 'wpchatbot' ); ?></div> | |
| 130 | - <?php | |
| 131 | - echo esc_html( $row->email ); | |
| 132 | - ?> | |
| 133 | - </div> | |
| 134 | - <div class="sld_payment_cell"> | |
| 135 | - <div class="sld_responsive_head"><?php echo esc_html__( 'Phone', 'wpchatbot' ); ?></div> | |
| 136 | - <?php | |
| 137 | - echo esc_html( $row->phone ); | |
| 138 | - | |
| 139 | - ?> | |
| 140 | - </div> | |
| 141 | - | |
| 142 | - </div> | |
| 143 | - <?php | |
| 144 | - } | |
| 145 | - ?> | |
| 146 | - | |
| 147 | - </div> | |
| 148 | - </form> | |
| 149 | - </div> | |
| 150 | - </div> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Email Subscription Template | |
| 4 | + * | |
| 5 | + * @package Botmaster | |
| 6 | + * @since 14.8.2 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; | |
| 11 | +} | |
| 12 | + | |
| 13 | + wp_register_style( 'qlcd-wp-chatbot-admin-style-email', QCLD_wpCHATBOT_PLUGIN_URL . '/css/email_subscription.css', '', QCLD_wpCHATBOT_VERSION, 'screen' ); | |
| 14 | + wp_enqueue_style( 'qlcd-wp-chatbot-admin-style-email' ); | |
| 15 | + | |
| 16 | + wp_register_script( 'qcld-wp-chatbot-email-subscription-js', QCLD_wpCHATBOT_PLUGIN_URL . '/js/email_subscription.js', array( 'jquery' ), true ); | |
| 17 | + wp_enqueue_script( 'qcld-wp-chatbot-email-subscription-js' ); | |
| 18 | + | |
| 19 | + global $wpdb; | |
| 20 | +if ( ! function_exists( 'wp_get_current_user' ) ) { | |
| 21 | + include ABSPATH . 'wp-includes/pluggable.php'; | |
| 22 | +} | |
| 23 | + | |
| 24 | + $table = $wpdb->prefix . 'wpbot_subscription'; | |
| 25 | + $table_sql = esc_sql( $table ); | |
| 26 | + | |
| 27 | + if ( isset( $_POST['wpbot_email_subscription_remove'] ) && '1' === $_POST['wpbot_email_subscription_remove'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 28 | + check_admin_referer( 'wpbot_email_subscription_delete', 'wpbot_email_subscription_nonce' ); | |
| 29 | + if ( current_user_can( 'manage_options' ) && isset( $_POST['emails'] ) && is_array( $_POST['emails'] ) ) { | |
| 30 | + $email_ids = array_map( 'absint', wp_unslash( $_POST['emails'] ) ); | |
| 31 | + foreach ( $email_ids as $email_id ) { | |
| 32 | + $wpdb->delete( $table, array( 'id' => $email_id ), array( '%d' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 33 | + } | |
| 34 | + echo '<script>window.location.href="' . esc_url_raw( admin_url( 'admin.php?page=email-subscription&msg=success' ) ) . '";</script>'; | |
| 35 | + exit; | |
| 36 | + } | |
| 37 | + } | |
| 38 | + | |
| 39 | + $current_user = wp_get_current_user(); | |
| 40 | + $url = admin_url( 'edit.php?post_type=sld&page=qcsld_click_list' ); | |
| 41 | + $customPagHTML = ''; | |
| 42 | + // Main Report Area — cache total count (invalidated when subscriptions change). | |
| 43 | + $total_cache_key = 'wpbot_email_sub_total'; | |
| 44 | + $total = wp_cache_get( $total_cache_key, 'wpbot' ); | |
| 45 | + if ( false === $total ) { | |
| 46 | + $total = $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 47 | + 'SELECT COUNT(*) FROM `' . $table_sql . '`' // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 48 | + ); | |
| 49 | + wp_cache_set( $total_cache_key, $total, 'wpbot', 300 ); | |
| 50 | + } | |
| 51 | + $items_per_page = 50; | |
| 52 | + | |
| 53 | + $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 54 | + $offset = ( $page * $items_per_page ) - $items_per_page; | |
| 55 | + | |
| 56 | + // Cache paginated rows per page number. | |
| 57 | + $rows_cache_key = 'wpbot_email_sub_rows_p' . $page; | |
| 58 | + $rows = wp_cache_get( $rows_cache_key, 'wpbot' ); | |
| 59 | + if ( false === $rows ) { | |
| 60 | + $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 61 | + $wpdb->prepare( | |
| 62 | + 'SELECT * FROM `' . $table_sql . '` ORDER BY id DESC LIMIT %d, %d', // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 63 | + $offset, | |
| 64 | + $items_per_page | |
| 65 | + ) | |
| 66 | + ); | |
| 67 | + wp_cache_set( $rows_cache_key, $rows, 'wpbot', 300 ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + $totalPage = ceil( $total / $items_per_page ); | |
| 71 | + | |
| 72 | +if ( $totalPage > 1 ) { | |
| 73 | + $customPagHTML = '<div><span class="wpbot_pagination">Page ' . esc_html( $page ) . ' of ' . esc_html( $totalPage ) . '</span>' . paginate_links( | |
| 74 | + array( | |
| 75 | + 'base' => add_query_arg( 'cpage', '%#%' ), | |
| 76 | + 'format' => '', | |
| 77 | + 'prev_text' => esc_html__( '«', 'chatbot' ), | |
| 78 | + 'next_text' => esc_html__( '»', 'chatbot' ), | |
| 79 | + 'total' => esc_html( $totalPage ), | |
| 80 | + 'current' => esc_html( $page ), | |
| 81 | + ) | |
| 82 | + ) . '</div>'; | |
| 83 | +} | |
| 84 | + $mainurl = admin_url( 'admin.php?page=email-subscription' ); | |
| 85 | + | |
| 86 | +?> | |
| 87 | + <div class="qchero_sliders_list_wrapper wpbot-userdata-page"> | |
| 88 | + <div class="sld_menu_title"> | |
| 89 | + <h2><?php echo esc_html__( 'User Data', 'chatbot' ); ?></h2> | |
| 90 | + </div> | |
| 91 | + | |
| 92 | + <?php if ( $customPagHTML != '' ) : ?> | |
| 93 | + <div class="sld_menu_title sld_menu_title_align wpbot-userdata-toolbar"> | |
| 94 | + <div class="qcld-session-pagination"><?php echo wp_kses_post( $customPagHTML ); ?></div> | |
| 95 | + </div> | |
| 96 | + <?php endif; ?> | |
| 97 | + | |
| 98 | + <?php | |
| 99 | + if ( isset( $_GET['msg'] ) && $_GET['msg'] == 'success' ) {// phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 100 | + echo '<div class="notice notice-success"><p>Record has beed Deleted Successfully!</p></div>'; | |
| 101 | + } | |
| 102 | + ?> | |
| 103 | + | |
| 104 | + <form id="wpcs_form_sessions" class="wpbot-userdata-form" action="<?php echo esc_url( $mainurl ); ?>" method="POST"> | |
| 105 | + <?php wp_nonce_field( 'wpbot_email_subscription_delete', 'wpbot_email_subscription_nonce' ); ?> | |
| 106 | + <input type="hidden" name="wpbot_email_subscription_remove" value="1" /> | |
| 107 | + | |
| 108 | + <div class="wpbot-userdata-actions"> | |
| 109 | + <button type="button" class="button-primary" id="wpbot_submit_email_form"><?php echo esc_html__( 'Delete', 'chatbot' ); ?></button> | |
| 110 | + <a class="button-primary wpbot-userdata-export" href="<?php echo esc_url( admin_url( 'admin-post.php?action=wpbprint.csv' ) ); ?>"><?php echo esc_html__( 'Export All Contacts', 'chatbot' ); ?></a> | |
| 111 | + <span class="wpbot-userdata-total"><?php echo esc_html__( 'Total', 'chatbot' ); ?> <strong><?php echo esc_html( $total ); ?></strong></span> | |
| 112 | + </div> | |
| 113 | + | |
| 114 | + <div class="qchero_slider_table_area"> | |
| 115 | + <div class="sld_payment_table"> | |
| 116 | + <div class="sld_payment_row header"> | |
| 117 | + | |
| 118 | + <div class="sld_payment_cell"> | |
| 119 | + <input type="checkbox" id="wpbot_checked_all" /> | |
| 120 | + </div> | |
| 121 | + | |
| 122 | + <div class="sld_payment_cell"> | |
| 123 | + <?php echo esc_html__( 'Date', 'chatbot' ); ?> | |
| 124 | + </div> | |
| 125 | + <div class="sld_payment_cell"> | |
| 126 | + <?php echo esc_html__( 'Name', 'chatbot' ); ?> | |
| 127 | + </div> | |
| 128 | + <div class="sld_payment_cell"> | |
| 129 | + <?php echo esc_html__( 'Email', 'chatbot' ); ?> | |
| 130 | + </div> | |
| 131 | + <div class="sld_payment_cell"> | |
| 132 | + <?php echo esc_html__( 'Phone', 'chatbot' ); ?> | |
| 133 | + </div> | |
| 134 | + | |
| 135 | + </div> | |
| 136 | + | |
| 137 | + <?php | |
| 138 | + foreach ( $rows as $row ) { | |
| 139 | + ?> | |
| 140 | + <div class="sld_payment_row"> | |
| 141 | + | |
| 142 | + <div class="sld_payment_cell"> | |
| 143 | + | |
| 144 | + <input type="checkbox" name="emails[]" class="wpbot_email_checkbox" value="<?php echo absint( $row->id ); ?>" /> | |
| 145 | + </div> | |
| 146 | + | |
| 147 | + <div class="sld_payment_cell"> | |
| 148 | + <div class="sld_responsive_head"><?php echo esc_html__( 'Date', 'chatbot' ); ?></div> | |
| 149 | + <?php echo esc_html( gmdate( 'm/d/Y', strtotime( $row->date ) ) ); ?> | |
| 150 | + </div> | |
| 151 | + <div class="sld_payment_cell"> | |
| 152 | + <div class="sld_responsive_head"><?php echo esc_html__( 'Name', 'chatbot' ); ?></div> | |
| 153 | + <?php echo esc_html( $row->name ); ?> | |
| 154 | + </div> | |
| 155 | + <div class="sld_payment_cell"> | |
| 156 | + <div class="sld_responsive_head"><?php echo esc_html__( 'Email', 'chatbot' ); ?></div> | |
| 157 | + <?php | |
| 158 | + echo esc_html( $row->email ); | |
| 159 | + ?> | |
| 160 | + </div> | |
| 161 | + <div class="sld_payment_cell"> | |
| 162 | + <div class="sld_responsive_head"><?php echo esc_html__( 'Phone', 'chatbot' ); ?></div> | |
| 163 | + <?php | |
| 164 | + echo esc_html( $row->phone ); | |
| 165 | + | |
| 166 | + ?> | |
| 167 | + </div> | |
| 168 | + | |
| 169 | + </div> | |
| 170 | + <?php | |
| 171 | + } | |
| 172 | + ?> | |
| 173 | + | |
| 174 | + </div> | |
| 175 | + </div> | |
| 176 | + </form> | |
| 177 | + </div> | |