public static function init_categories_actions() { global $wpdb; $cat_msg = ''; if (isset($_REQUEST['bt_save_cat'])) { $category_name = trim(strip_tags(addslashes($_REQUEST['category_name']))); if (isset($_REQUEST['category_id']) && $_REQUEST['category_id'] > 0) { $old_data = WC_Compare_Categories_Data::get_row($_REQUEST['category_id']); $count_category_name = WC_Compare_Categories_Data::get_count("category_name = '" . $category_name . "' AND id != '" . $_REQUEST['category_id'] . "'"); if ($category_name != '' && $count_category_name == 0) { $result = WC_Compare_Categories_Data::update_row($_REQUEST); $wpdb->query('UPDATE ' . $wpdb->prefix . 'postmeta SET meta_value="' . $category_name . '" WHERE meta_value="' . $old_data->category_name . '" AND meta_key="_wpsc_compare_category_name" '); $cat_msg = '<div class="updated below-h2" id="result_msg"><p>' . __('Compare Category Successfully edited', 'woo_cp') . '.</p></div>'; } else { $cat_msg = '<div class="error below-h2" id="result_msg"><p>' . __('Nothing edited! You already have a Compare Category with that name. Use unique names to edit each Compare Category.', 'woo_cp') . '</p></div>'; } } else { $count_category_name = WC_Compare_Categories_Data::get_count("category_name = '" . $category_name . "'"); if ($category_name != '' && $count_category_name == 0) { $category_id = WC_Compare_Categories_Data::insert_row($_REQUEST); if ($category_id > 0) { $cat_msg = '<div class="updated below-h2" id="result_msg"><p>' . __('Compare Category Successfully created', 'woo_cp') . '.</p></div>'; } else { $cat_msg = '<div class="error below-h2" id="result_msg"><p>' . __('Compare Category Error created', 'woo_cp') . '.</p></div>'; } } else { $cat_msg = '<div class="error below-h2" id="result_msg"><p>' . __('Nothing created! You already have a Compare Category with that name. Use unique names to create each Compare Category.', 'woo_cp') . '</p></div>'; } } } if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'cat-delete') { $category_id = trim($_REQUEST['category_id']); WC_Compare_Categories_Data::delete_row($category_id); WC_Compare_Categories_Fields_Data::delete_row("cat_id='" . $category_id . "'"); $cat_msg = '<div class="updated below-h2" id="result_msg"><p>' . __('Compare Category deleted', 'woo_cp') . '.</p></div>'; } return $cat_msg; }
public static function init_features_actions() { $result_msg = ''; if (isset($_REQUEST['bt_save_field'])) { $field_name = trim(strip_tags(addslashes($_REQUEST['field_name']))); if (isset($_REQUEST['field_id']) && $_REQUEST['field_id'] > 0) { $field_id = trim($_REQUEST['field_id']); $count_field_name = WC_Compare_Data::get_count("field_name = '" . $field_name . "' AND id != '" . $field_id . "'"); if ($field_name != '' && $count_field_name == 0) { $result = WC_Compare_Data::update_row($_REQUEST); if (isset($_REQUEST['field_cats']) && count((array) $_REQUEST['field_cats']) > 0) { foreach ($_REQUEST['field_cats'] as $cat_id) { $check_existed = WC_Compare_Categories_Fields_Data::get_count("cat_id='" . $cat_id . "' AND field_id='" . $field_id . "'"); if ($check_existed == 0) { WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); } } WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "' AND cat_id NOT IN(" . implode(',', $_REQUEST['field_cats']) . ")"); } else { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature Successfully edited', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Nothing edited! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to edit each Compare Feature.', 'woo_cp') . '</p></div>'; } } else { $count_field_name = WC_Compare_Data::get_count("field_name = '" . $field_name . "'"); if ($field_name != '' && $count_field_name == 0) { $field_id = WC_Compare_Data::insert_row($_REQUEST); if ($field_id > 0) { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); if (isset($_REQUEST['field_cats']) && count((array) $_REQUEST['field_cats']) > 0) { foreach ($_REQUEST['field_cats'] as $cat_id) { WC_Compare_Categories_Fields_Data::insert_row($cat_id, $field_id); } } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature Successfully created', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Compare Feature Error created', 'woo_cp') . '.</p></div>'; } } else { $result_msg = '<div class="error" id="result_msg"><p>' . __('Nothing created! You already have a Compare Feature with that name. Use the Features Search function to find it. Use unique names to create each Compare Feature.', 'woo_cp') . '</p></div>'; } } } elseif (isset($_REQUEST['bt_delete'])) { $list_fields_delete = $_REQUEST['un_fields']; if (is_array($list_fields_delete) && count($list_fields_delete) > 0) { foreach ($list_fields_delete as $field_id) { WC_Compare_Data::delete_row($field_id); WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); } $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully deleted', 'woo_cp') . '.</p></div>'; } else { $result_msg = '<div class="updated" id="result_msg"><p>' . __('Please select item(s) to delete', 'woo_cp') . '.</p></div>'; } } if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'field-delete') { $field_id = trim($_REQUEST['field_id']); if (isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] > 0) { WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "' AND cat_id='" . $_REQUEST['cat_id'] . "'"); $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully removed', 'woo_cp') . '.</p></div>'; } else { WC_Compare_Data::delete_row($field_id); WC_Compare_Categories_Fields_Data::delete_row("field_id='" . $field_id . "'"); $result_msg = '<div class="updated" id="result_msg"><p>' . __('Compare Feature successfully deleted', 'woo_cp') . '.</p></div>'; } } return $result_msg; }