1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( !class_exists('Wcap_SMS' ) ) {
class Wcap_SMS{
public function __construct() {
}
static function cart_recovery_views() {
$email_class = '';
$sms_class = '';
$section = isset( $_GET[ 'section' ] ) ? $_GET[ 'section' ] : '';
switch( $section ) {
case '':
case 'emailtemplates':
$email_class = 'current';
break;
case 'sms':
$sms_class = 'current';
break;
}
?>
<ul class="subsubsub">
<li><a href="admin.php?page=woocommerce_ac_page&action=cart_recovery§ion=emailtemplates" class="<?php echo $email_class; ?>"><?php _e( 'Email Templates', 'woocommerce-ac' );?></a></li> |
<li><a href="admin.php?page=woocommerce_ac_page&action=cart_recovery§ion=sms" class="<?php echo $sms_class; ?>"><?php _e( 'SMS Notifications', 'woocommerce-ac' ); ?></a></li>
</ul>
<br class="clear">
<?php
}
static function display_sms_list() {
Wcap_SMS::cart_recovery_views();
$new_id = Wcap_SMS::get_new_id();
?>
<p><?php _e( 'Add SMS notifications to be sent at different intervals to maximize the possibility of recovering your abandoned carts.', 'woocommerce-ac' ); ?></p>
<p><?php _e( "<b>Edit Instructions:</b> Please click on the Text Message to edit it. Then click on the Save button. You can edit multiple text messages at once.", 'woocommerce-ac' ); ?></p>
<div class="tablenav" style="width:75%;display:inline;float:left;">
<p style="float:left;">
<a cursor: pointer; href="javascript:void(0)" class="button-secondary" id="new_sms" ><?php _e( 'Add New Text Message', 'woocommerce-ac' ); ?></a>
<input type='hidden' id='new_template_id' value='<?php echo $new_id;?>' />
<?php
$defaults = Wcap_SMS::wcap_create_defaults();
Wcap_SMS::wcap_add_defaults( $defaults ); ?>
</p>
<?php
$sms_list = new Wcap_SMS_Templates();
$sms_list->wcap_sms_templates_prepare_items();
?>
<div class="wrap">
<form id="wcap-sms-templates" method="get" >
<input type="hidden" name="page" value="woocommerce_ac_page" />
<input type="hidden" name="action" value="cart_recovery" />
<input type="hidden" name="section" value="sms" />
<?php $sms_list->display(); ?>
</form>
</div>
</div>
<div id="merge_tags" style='display:inline;width:25%;float:right;'>
<p style="float:left;">
<b><?php _e( 'Merge tags available for Text Messages:', 'woocommerce-ac' );?></b>
<br><br>
<i>{{user.name}} - <?php _e( 'First Name of the User', 'woocommerce-ac' );?><br><br>
{{shop.name}} - <?php _e( 'Shop Name ', 'woocommerce-ac' );?>[<?php echo get_option( 'blogname' ); ?>]<br><br>
{{shop.link}} - <?php _e( 'Shop Link ', 'woocommerce-ac' );?>[<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>]<br><br>
{{date.abandoned}} - <?php _e( 'Date on which the Cart was abandoned', 'woocommerce-ac' );?><br><br>
{{coupon.code}} - <?php _e( 'Discount coupon code', 'woocommerce-ac' );?><br><br>
{{checkout.link}} - <?php _e( 'Checkout Link to complete the purchase.', 'woocommerce-ac' );?><br><br>
{{phone.number}} - <?php _e( 'Admin Phone number', 'woocommerce-ac' );?>
</i>
</p>
</div>
<?php
}
static function wcap_create_defaults() {
$new_id = Wcap_SMS::get_new_id();
$default_sms_obj = new Wcap_SMS_Templates();
$columns = $default_sms_obj->get_columns();
$hidden = $default_sms_obj->wcap_hidden_sms_cols();
$defaults = array();
$default_sms_values = (object) array(
'id' => $new_id,
'updated' => 1,
'txt_msg' => '',
'full_txt_msg' => '',
'coupon_code' => '',
'sent_time' => '1 minutes',
'sms_sent' => 0,
'active' => 'on'
);
foreach( $columns as $col_name => $col_desc ) {
$class = "class='$col_name column-$col_name'";
$style = ( in_array( $col_name, $hidden ) ) ? " style='display:none;'" : '';
$attributes = $class . $style;
switch( $col_name ) {
case 'cb':
$value = "<th scope='row' class='check-column'><input name='template_id[]' value= '$new_id' type='checkbox'></th>";
break;
case 'id':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case 'updated':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case 'txt_msg':
$value = "<td $attributes><textarea class='msg' rows='4'>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</textarea></td>";
break;
case 'full_txt_msg':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case 'coupon_code':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case 'sent_time':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case 'sms_sent':
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case "activate":
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
case "actions":
$value = "<td $attributes>";
$value .= $default_sms_obj->column_default( $default_sms_values, $col_name ) . "</td>";
break;
}
$defaults[ $col_name ] = $value;
}
return $defaults;
}
static function get_new_id() {
global $wpdb;
$max_id = $wpdb->get_results( "SELECT MAX(ID) as maxID FROM " . WCAP_NOTIFICATIONS );
$new_id = isset( $max_id[0]->maxID ) ? $max_id[0]->maxID + 1 : 1;
return $new_id;
}
static function wcap_add_defaults( $defaults ) {
foreach( $defaults as $col_name => $default_value ) {
?>
<input type="hidden" id="<?php echo $col_name . '_default' ?>" value="<?php echo $default_value; ?>" />
<?php
}
}
public static function wcap_delete_sms() {
$template_id = isset( $_POST[ 'template_id' ] ) ? $_POST[ 'template_id' ] : 0;
if( $template_id > 0 ) {
self:: wcap_delete_template_data( $template_id );
}
die();
}
static function wcap_delete_template_data( $template_id ) {
global $wpdb;
$wpdb->delete( WCAP_NOTIFICATIONS_META, array( 'template_id' => $template_id ) );
$wpdb->delete( WCAP_NOTIFICATIONS, array( 'id' => $template_id ) );
}
static function wcap_save_bulk_sms() {
global $wpdb;
$clean_template_data = '';
if ( isset( $_POST[ 'template_data' ] ) ) {
$post_templates = $_POST[ 'template_data' ];
$tempData = stripslashes( $post_templates );
$clean_template_data = json_decode($tempData);
}
$insert = false;
if ( $clean_template_data != '' && count( $clean_template_data ) > 0 ) {
foreach( $clean_template_data as $id => $data ) {
$template_details = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . WCAP_NOTIFICATIONS . " WHERE ID = %d", $id ) );
$template_present = ( isset( $template_details[0]->ID ) ) ? true : false;
$data_entries = explode( '|', $data );
$sms_body = isset( $data_entries[0] ) ? $data_entries[0] : '';
$frequency = isset( $data_entries[1] ) ? $data_entries[1] : '';
$active = ( isset( $data_entries[2] ) && $data_entries[2] == 'on' ) ? 1 : 0;
$coupon_code = isset( $data_entries[3] ) && $data_entries[3] > 0 ? $data_entries[3] : '';
$default_template = isset( $data_entries[4] ) ? $data_entries[4] : 0;
if( $template_present ) {
$wpdb->update( WCAP_NOTIFICATIONS, array(
'body' => $sms_body,
'frequency' => $frequency,
'is_active' => $active,
'coupon_code' => $coupon_code
),
array( 'id' => $id ) );
} else {
$wpdb->insert( WCAP_NOTIFICATIONS, array(
'body' => $sms_body,
'type' => 'sms',
'is_active' => $active,
'frequency' => $frequency,
'coupon_code' => $coupon_code,
'default_template' => $default_template,
));
$insert = true;
}
}
}
echo $insert;
die();
}
}
$wcap_sms = new WCap_SMS();
}