| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $current_user,$wppmfunction,$wpdb; |
| 6 |
if ( check_ajax_referer( 'wppm_set_change_raised_by', '_ajax_nonce', false ) != 1 ) { |
| 7 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 8 |
} |
| 9 |
$task_id = isset($_POST['task_id']) ? absint(sanitize_text_field(wp_unslash($_POST['task_id']))) : ''; |
| 10 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('change_raised_by',$task_id))) {exit;} |
| 11 |
$user_id = isset($_POST['user_id']) ? absint(sanitize_text_field(wp_unslash($_POST['user_id']))) : 0 ; |
| 12 |
$task_data = $wppmfunction->get_task($task_id); |
| 13 |
$old_user_id = $task_data['created_by']; |
| 14 |
$cu_id = esc_sql($current_user->ID); |
| 15 |
if ( $user_id != $old_user_id ){ |
| 16 |
$wppmfunction->change_raised_by($task_id, $user_id); |
| 17 |
$change_creator_value = array('prev_user'=>"$old_user_id",'new_user'=>"$user_id"); |
| 18 |
$change_creator_obj = serialize($change_creator_value); |
| 19 |
$task_id = esc_sql($task_id); |
| 20 |
$log_values = array('task_id'=>"$task_id",'body'=>$change_creator_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d H:i:s"),'created_by'=>"$cu_id", ); |
| 21 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); |
| 22 |
$log_id = esc_sql($wpdb->insert_id); |
| 23 |
$task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$log_id",'comment_type'=>'change_task_creator'); |
| 24 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); |
| 25 |
} |