| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$wppmfunction,$current_user; |
| 6 |
$task_id = isset($_POST['task_id']) ? intval(sanitize_text_field($_POST['task_id'])) : '' ; |
| 7 |
$task_id = esc_sql($task_id); |
| 8 |
$proj_id = isset($_POST['proj_id']) ? intval(sanitize_text_field($_POST['proj_id'])) : '' ; |
| 9 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('change_task_details',$task_id))) {exit;} |
| 10 |
if ( check_ajax_referer( 'wppm_set_change_task_details', '_ajax_nonce', false ) != 1 ) { |
| 11 |
wp_send_json_error( 'Unauthorised request!', 401 ); |
| 12 |
} |
| 13 |
$task_data = $wppmfunction->get_task($task_id); |
| 14 |
$task_label = isset($_POST['wppm_edit_task_label']) ? sanitize_text_field($_POST['wppm_edit_task_label']) : "" ; |
| 15 |
$project_label = isset($_POST['wppm_edit_project_label']) ? sanitize_text_field($_POST['wppm_edit_project_label']) : "" ; |
| 16 |
$task_start_date = isset($_POST['wppm_edit_task_start_date']) ? sanitize_text_field($_POST['wppm_edit_task_start_date']) : "" ; |
| 17 |
$task_end_date = isset($_POST['wppm_edit_task_end_date']) ? sanitize_text_field($_POST['wppm_edit_task_end_date']) : "" ; |
| 18 |
$task_priority = isset($_POST['wppm_edit_task_priority']) ? intval(sanitize_text_field($_POST['wppm_edit_task_priority'])) : "" ; |
| 19 |
$task_description = isset($_POST['wppm_edit_task_description']) ? wp_kses_post(htmlspecialchars_decode($_POST['wppm_edit_task_description'], ENT_QUOTES)) : "" ; |
| 20 |
$task_project = isset($_POST['wppm_task_project']) ? intval(sanitize_text_field($_POST['wppm_task_project'])) : $proj_id ; |
| 21 |
if($task_label && $task_label != $task_data['task_name'] ){ |
| 22 |
$wppmfunction->change_task_label( $task_id, $task_label); |
| 23 |
} |
| 24 |
|
| 25 |
if($project_label && $project_label != $task_data['project'] ){ |
| 26 |
$wppmfunction->change_task_project_label( $task_id, $project_label); |
| 27 |
} |
| 28 |
|
| 29 |
if($task_start_date && $task_start_date != $task_data['start_date'] ){ |
| 30 |
$wppmfunction->change_start_date( $task_id, $task_start_date); |
| 31 |
} |
| 32 |
|
| 33 |
if($task_end_date && $task_end_date != $task_data['end_date'] ){ |
| 34 |
$wppmfunction->change_end_date( $task_id, $task_end_date); |
| 35 |
} |
| 36 |
|
| 37 |
if( $task_priority != $task_data['priority']){ |
| 38 |
$wppmfunction->change_priority( $task_id, $task_priority); |
| 39 |
$change_priority_value = array('prev_prio'=>"$task_data[priority]",'new_prio'=>"$task_priority"); |
| 40 |
$change_priority_obj = serialize($change_priority_value); |
| 41 |
$log_values = array('task_id'=>esc_sql($task_id),'body'=>$change_priority_obj,'attachment_ids'=>"",'create_time'=>date("Y-m-d h:i:sa"),'created_by'=>esc_sql($current_user->ID) ); |
| 42 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); |
| 43 |
$log_id = esc_sql($wpdb->insert_id); |
| 44 |
$task_log_values = array('task_id'=>esc_sql($task_id),'comment_id'=>"$log_id",'comment_type'=>'change_task_priority'); |
| 45 |
$wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); |
| 46 |
} |
| 47 |
|
| 48 |
if( $task_description != $task_data['description']){ |
| 49 |
$wppmfunction->change_description( $task_id, $task_description); |
| 50 |
} |
| 51 |
|
| 52 |
if( $task_project && $task_project != $proj_id){ |
| 53 |
$wppmfunction->change_project( $task_id, $task_project); |
| 54 |
} |
| 55 |
|
| 56 |
do_action('wppm_after_change_task_details',$task_id,$task_data['project']); |