← All changes
|
includes/admin/tasks/wppm_set_bulk_change_task_status.php
+51
-51
6.0.2
→
6.0.6
View file →
| @@ -1,52 +1,52 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | -global $wpdb,$wppmfunction,$current_user; | |
| 6 | -if ( check_ajax_referer( 'wppm_set_bulk_change_task_status', '_ajax_nonce', false ) != 1 ) { | |
| 7 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 8 | -} | |
| 9 | - | |
| 10 | -$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); | |
| 11 | -if ( ! $task_ids ) { | |
| 12 | - wp_send_json_error( 'Missing task ids', 400 ); | |
| 13 | -} | |
| 14 | -$flag= false; | |
| 15 | -$cu_id = absint($current_user->ID); | |
| 16 | -$task_status = isset( $_POST['wppm_task_status']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_task_status']))) : ''; | |
| 17 | -$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 18 | -if(!empty($task_ids)){ | |
| 19 | - foreach($task_ids as $task_id){ | |
| 20 | - $task_data = $wppmfunction->get_task($task_id); | |
| 21 | - $tusers = $task_data['users']; | |
| 22 | - $tusers_arr = explode(',',$tusers); | |
| 23 | - $tproject_id = absint($task_data['project']); | |
| 24 | - if(!empty($tusers) && in_array($current_user->ID,$tusers_arr)){ | |
| 25 | - $project_user_role = $wpdb->get_var( $wpdb->prepare( "SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $tproject_id, $cu_id ) ); | |
| 26 | - $project_users = $wpdb->get_var( $wpdb->prepare( "SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $tproject_id ) ); | |
| 27 | - $project_users_arr = explode(',',(string)$project_users); | |
| 28 | - if(((!empty($project_user_role)) && ($project_user_role == 1) && in_array($current_user->ID,$project_users_arr))){ | |
| 29 | - $flag = true; | |
| 30 | - } | |
| 31 | - } | |
| 32 | - if($current_user->has_cap('manage_options') || $wppm_current_user_capability == ('wppm_admin') || ($flag==true) || ($wppmfunction->has_permission('change_task_status',$task_id))!=""){ | |
| 33 | - $status_id = isset($_POST['wppm_task_status']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_task_status']))) : 0 ; | |
| 34 | - if( !$status_id ){ | |
| 35 | - die(); | |
| 36 | - } | |
| 37 | - $old_status_id = $task_data['status']; | |
| 38 | - if($status_id && $status_id!=$old_status_id){ | |
| 39 | - $wppmfunction->change_status( $task_id, $status_id); | |
| 40 | - $task_id = esc_sql($task_id); | |
| 41 | - $change_task_value = array('prev_status'=>$task_data['status'],'new_status'=>$status_id); | |
| 42 | - $change_task_obj = serialize($change_task_value); | |
| 43 | - $log_values = array('task_id'=>"$task_id",'body'=>$change_task_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d h:i:sa"),'created_by'=>esc_sql($current_user->ID) ); | |
| 44 | - $wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); | |
| 45 | - $log_id = esc_sql($wpdb->insert_id); | |
| 46 | - $task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$log_id",'comment_type'=>'change_task_status'); | |
| 47 | - $wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); | |
| 48 | - } | |
| 49 | - } | |
| 50 | - } | |
| 51 | -} | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | +global $wpdb,$wppmfunction,$current_user; | |
| 6 | +if ( check_ajax_referer( 'wppm_set_bulk_change_task_status', '_ajax_nonce', false ) != 1 ) { | |
| 7 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 8 | +} | |
| 9 | + | |
| 10 | +$task_ids = isset( $_POST['task_ids'] ) ? array_filter( array_map( 'intval', explode( ',', sanitize_text_field( wp_unslash( $_POST['task_ids'] ) ) ) ) ) : array(); | |
| 11 | +if ( ! $task_ids ) { | |
| 12 | + wp_send_json_error( 'Missing task ids', 400 ); | |
| 13 | +} | |
| 14 | +$flag= false; | |
| 15 | +$cu_id = absint($current_user->ID); | |
| 16 | +$task_status = isset( $_POST['wppm_task_status']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_task_status']))) : ''; | |
| 17 | +$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 18 | +if(!empty($task_ids)){ | |
| 19 | + foreach($task_ids as $task_id){ | |
| 20 | + $task_data = $wppmfunction->get_task($task_id); | |
| 21 | + $tusers = $task_data['users']; | |
| 22 | + $tusers_arr = explode(',',$tusers); | |
| 23 | + $tproject_id = absint($task_data['project']); | |
| 24 | + if(!empty($tusers) && in_array($current_user->ID,$tusers_arr)){ | |
| 25 | + $project_user_role = $wpdb->get_var( $wpdb->prepare( "SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $tproject_id, $cu_id ) ); | |
| 26 | + $project_users = $wpdb->get_var( $wpdb->prepare( "SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $tproject_id ) ); | |
| 27 | + $project_users_arr = explode(',',(string)$project_users); | |
| 28 | + if(((!empty($project_user_role)) && ($project_user_role == 1) && in_array($current_user->ID,$project_users_arr))){ | |
| 29 | + $flag = true; | |
| 30 | + } | |
| 31 | + } | |
| 32 | + if($current_user->has_cap('manage_options') || $wppm_current_user_capability == ('wppm_admin') || ($flag==true) || ($wppmfunction->has_permission('change_task_status',$task_id))!=""){ | |
| 33 | + $status_id = isset($_POST['wppm_task_status']) ? intval(sanitize_text_field(wp_unslash($_POST['wppm_task_status']))) : 0 ; | |
| 34 | + if( !$status_id ){ | |
| 35 | + die(); | |
| 36 | + } | |
| 37 | + $old_status_id = $task_data['status']; | |
| 38 | + if($status_id && $status_id!=$old_status_id){ | |
| 39 | + $wppmfunction->change_status( $task_id, $status_id); | |
| 40 | + $task_id = esc_sql($task_id); | |
| 41 | + $change_task_value = array('prev_status'=>$task_data['status'],'new_status'=>$status_id); | |
| 42 | + $change_task_obj = serialize($change_task_value); | |
| 43 | + $log_values = array('task_id'=>"$task_id",'body'=>$change_task_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d h:i:sa"),'created_by'=>esc_sql($current_user->ID) ); | |
| 44 | + $wpdb->insert($wpdb->prefix . 'wppm_task_comment',$log_values); | |
| 45 | + $log_id = esc_sql($wpdb->insert_id); | |
| 46 | + $task_log_values = array('task_id'=>"$task_id",'comment_id'=>"$log_id",'comment_type'=>'change_task_status'); | |
| 47 | + $wpdb->insert($wpdb->prefix . 'wppm_task_comment_meta',$task_log_values); | |
| 48 | + } | |
| 49 | + } | |
| 50 | + } | |
| 51 | +} | |
| 52 | 52 | do_action('wppm_after_set_bulk_change_task_status',$task_ids, $task_status); |