0 ) )['results']; $cf = WPSC_Custom_Field::get_cf_by_slug( 'category' );?>

' . esc_attr__( 'Click here', 'supportcandy' ) . '' ); ?>
name ); ?>
default_value[0] != $category->id ) : ?> |
0 ) )['results']; ob_start(); ?>
*
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Insert new category * * @return void */ public static function wpsc_set_add_category() { if ( check_ajax_referer( 'wpsc_set_add_category', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $label = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : ''; if ( ! $label ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $data = array( 'name' => $label ); $category = WPSC_Category::insert( $data ); // set laod order. $categories = WPSC_Category::find( array( 'items_per_page' => 0 ) )['results']; $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; if ( $load_after != '__END__' ) { $count = 1; if ( $load_after == '__TOP__' ) { $category->load_order = $count++; $category->save(); } foreach ( $categories as $cat ) { if ( $cat->id == $category->id ) { continue; } $cat->load_order = $count++; $cat->save(); if ( $cat->id == $load_after ) { $category->load_order = $count++; $category->save(); } } } wp_die(); } /** * Edit category modal * * @return void */ public static function get_edit_category() { global $wpdb; if ( check_ajax_referer( 'wpsc_get_edit_category', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $category = new WPSC_Category( $id ); if ( ! $category->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $title = esc_attr( $category->name ); $categories = WPSC_Category::find( array( 'items_per_page' => 0 ) )['results']; ob_start(); ?>
*
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Set edit category * * @return void */ public static function set_edit_category() { global $wpdb; if ( check_ajax_referer( 'wpsc_set_edit_category', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $label = isset( $_POST['label'] ) ? sanitize_text_field( wp_unslash( $_POST['label'] ) ) : ''; if ( ! $label ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $category = new WPSC_Category( $id ); if ( ! $category->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $category->name = $label; $category->save(); // set laod order. $categories = WPSC_Category::find( array( 'items_per_page' => 0 ) )['results']; $load_after = isset( $_POST['load-after'] ) ? sanitize_text_field( wp_unslash( $_POST['load-after'] ) ) : '__END__'; if ( $load_after != '__END__' ) { $count = 1; if ( $load_after == '__TOP__' ) { $category->load_order = $count++; $category->save(); } foreach ( $categories as $cat ) { if ( $cat->id == $category->id ) { continue; } $cat->load_order = $count++; $cat->save(); if ( $cat->id == $load_after ) { $category->load_order = $count++; $category->save(); } } } else { $max_load_order = (int) $wpdb->get_var( "SELECT max(load_order) FROM {$wpdb->prefix}psmsc_categories" ); $category->load_order = ++$max_load_order; $category->save(); } wp_die(); } /** * Delete category modal * * @return void */ public static function get_delete_category() { if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } if ( check_ajax_referer( 'wpsc_get_delete_category', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } $title = esc_attr__( 'Delete category', 'supportcandy' ); $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $category = new WPSC_Category( $id ); if ( ! $category->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $categories = WPSC_Category::find( array( 'items_per_page' => 0 ) )['results']; ob_start(); ?>
$title, 'body' => $body, 'footer' => $footer, ); wp_send_json( $response ); } /** * Delete Category */ public static function set_delete_category() { global $wpdb; if ( ! WPSC_Functions::is_site_admin() ) { wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); } if ( check_ajax_referer( 'wpsc_set_delete_category', '_ajax_nonce', false ) != 1 ) { wp_send_json_error( 'Unauthorized request!', 401 ); } $id = isset( $_POST['id'] ) ? intval( $_POST['id'] ) : 0; if ( ! $id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $category = new WPSC_Category( $id ); if ( ! $category->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $replace_id = isset( $_POST['replace_id'] ) ? intval( $_POST['replace_id'] ) : 0; if ( ! $replace_id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $replace = new WPSC_Category( $replace_id ); if ( ! $replace->id ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } $cf = WPSC_Custom_Field::get_cf_by_slug( 'category' ); if ( $id == $cf->default_value[0] ) { wp_send_json_error( __( 'Bad request!', 'supportcandy' ), 400 ); } // replace in ticket table. $success = $wpdb->update( $wpdb->prefix . 'psmsc_tickets', array( 'category' => $replace->id ), array( 'category' => $category->id ) ); // replace in logs. $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}psmsc_threads WHERE (type = 'log') AND JSON_VALID(body) AND JSON_EXTRACT(body, '$.slug') = 'category' AND ( JSON_UNQUOTE(JSON_EXTRACT(body, '$.new')) = '" . $category->id . "' OR JSON_UNQUOTE(JSON_EXTRACT(body, '$.prev')) = '" . $category->id . "' )" ); foreach ( $results as $log ) { $body = json_decode( $log->body ); $body->prev = $body->prev == $category->id ? $replace->id : $body->prev; $body->new = $body->new == $category->id ? $replace->id : $body->new; $body = wp_json_encode( $body ); $wpdb->update( $wpdb->prefix . 'psmsc_threads', array( 'body' => $body ), array( 'id' => $log->id ) ); } $category->destroy( $category ); wp_die(); } } endif; WPSC_Ticket_Categories::init();