| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $current_user,$wppmfunction,$wpdb; |
| 6 |
|
| 7 |
$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field($_POST['task_id'])) : ''; |
| 8 |
$cu_id = esc_sql($current_user->ID); |
| 9 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('change_status',$task_id))) {exit;} |
| 10 |
if ( check_ajax_referer( 'wppm_set_change_task_status', '_ajax_nonce', false ) != 1 ) { |
| 11 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 12 |
} |
| 13 |
$status_id = isset($_POST['wppm_status']) ? intval(sanitize_text_field($_POST['wppm_status'])) : 0 ; |
| 14 |
if( !$status_id ){ |
| 15 |
die(); |
| 16 |
} |
| 17 |
$task_data = $wppmfunction->get_task($task_id); |
| 18 |
$old_status_id = $task_data['status']; |
| 19 |
if($status_id && $status_id!=$old_status_id){ |
| 20 |
$wppmfunction->change_status( $task_id, $status_id); |
| 21 |
$task_id = esc_sql($task_id); |
| 22 |
$old_status_id = esc_sql($old_status_id); |
| 23 |
$status_id = esc_sql($status_id); |
| 24 |
$change_task_value = array('prev_status'=>"$old_status_id",'new_status'=>"$status_id"); |
| 25 |
$change_task_obj = serialize($change_task_value); |
| 26 |
$log_values = array('task_id'=>"$task_id",'body'=>$change_task_obj,'attachment_ids'=>"",'create_time'=>date("Y-m-d h:i:sa"),'created_by'=>"$cu_id" ); |
| 27 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); |
| 28 |
$log_id = esc_sql($wpdb->insert_id); |
| 29 |
$task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$log_id",'comment_type'=>'change_task_status'); |
| 30 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); |
| 31 |
} |
| 32 |
do_action('wppm_after_set_change_task_status',$task_id,$status_id,$old_status_id); |
| 33 |
|