| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$current_user, $wppmfunction; |
| 6 |
if ( check_ajax_referer( 'wppm_drag_and_drop_card', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
$wppm_card = isset($_POST) && isset($_POST['el']) ? sanitize_text_field($_POST['el']) : ''; |
| 10 |
if (!$wppm_card) {exit;} |
| 11 |
$target_task_status = isset($_POST) && isset($_POST['target']) ? sanitize_text_field($_POST['target']) : ''; |
| 12 |
if (!$wppm_card) {exit;} |
| 13 |
$wppm_card_id= substr($wppm_card, 20); |
| 14 |
if($wppmfunction->has_permission('change_task_status',$wppm_card_id)){ |
| 15 |
$wppm_target_task_status = substr($target_task_status,25); |
| 16 |
$task_data = $wppmfunction->get_task($wppm_card_id); |
| 17 |
$task_id = $wppm_card_id; |
| 18 |
$old_status_id = $task_data['status']; |
| 19 |
$status_id = esc_sql($wppm_target_task_status); |
| 20 |
$wppmfunction->change_status( $task_id, $status_id); |
| 21 |
$change_task_value = array('prev_status'=>"$old_status_id",'new_status'=>"$status_id"); |
| 22 |
$change_task_obj = serialize($change_task_value); |
| 23 |
$log_values = array('task_id'=>"$task_id",'body'=>$change_task_obj,'attachment_ids'=>"",'create_time'=>date("Y-m-d h:i:sa"),'created_by'=>"$current_user->ID" ); |
| 24 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); |
| 25 |
$log_id = esc_sql($wpdb->insert_id); |
| 26 |
$task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$log_id",'comment_type'=>'change_task_status'); |
| 27 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); |
| 28 |
echo '{ "sucess_status":"1","messege":"Success" }'; |
| 29 |
}else{ |
| 30 |
echo '{ "sucess_status":"0","messege":"You do not have permission to change this task status." }'; |
| 31 |
} |
| 32 |
|