← All changes
|
includes/admin/tasks/open_task/wppm_set_clone_task.php
+144
-143
6.0.5
→
6.0.6
View file →
| @@ -1,144 +1,145 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | -global $wpdb, $current_user, $wppmfunction; | |
| 6 | -$is_internal_clone = ! empty( $internal_code_flag ); | |
| 7 | -if ( ! $is_internal_clone ) { | |
| 8 | - if ( | |
| 9 | - empty( $_POST['_ajax_nonce'] ) || | |
| 10 | - ! wp_verify_nonce( | |
| 11 | - sanitize_text_field( | |
| 12 | - wp_unslash( $_POST['_ajax_nonce'] ) | |
| 13 | - ), | |
| 14 | - 'wppm_set_clone_task' | |
| 15 | - ) | |
| 16 | - ) { | |
| 17 | - wp_send_json_error( | |
| 18 | - array( | |
| 19 | - 'message' => esc_html__( | |
| 20 | - 'Security check failed.', | |
| 21 | - 'taskbuilder' | |
| 22 | - ) | |
| 23 | - ) | |
| 24 | - ); | |
| 25 | - } | |
| 26 | -} | |
| 27 | -$prev_task_id = isset($_POST['task_id']) ? absint(sanitize_text_field(wp_unslash($_POST['task_id']))) : $ptask_id ; | |
| 28 | -$task = $wppmfunction->get_task($prev_task_id); | |
| 29 | -if ( empty($task) ) { | |
| 30 | - wp_send_json_error('Invalid task', 404); | |
| 31 | -} | |
| 32 | -if (!(($current_user->has_cap('manage_options')) || $wppmfunction->has_permission('clone_task',$task['id']))) { | |
| 33 | - wp_send_json_error('Unauthorized', 403); | |
| 34 | -} | |
| 35 | -$wppm_default_duplicate_project_email_notification = get_option('wppm_default_duplicate_project_email_notification'); | |
| 36 | -$checklists = $wppmfunction->get_checklist($prev_task_id); | |
| 37 | -$task_project = isset($project_id) ? $project_id : $task['project']; | |
| 38 | -$prev_task_id = esc_sql($prev_task_id); | |
| 39 | -$task_comments = $wpdb->get_results( | |
| 40 | - $wpdb->prepare( | |
| 41 | - "SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d", | |
| 42 | - $prev_task_id | |
| 43 | - ) | |
| 44 | -); | |
| 45 | -$task_name = isset($_POST['task_name']) ? stripslashes(sanitize_text_field(wp_unslash($_POST['task_name']))) : $task['task_name'] ; | |
| 46 | -$now = wp_date("Y-m-d H:i:s"); | |
| 47 | -$values = array( | |
| 48 | - 'created_by'=>$task['created_by'], | |
| 49 | - 'name'=>$task_name, | |
| 50 | - 'wppm_task_description'=>$task['description'], | |
| 51 | - 'wppm_task_project'=>$task_project, | |
| 52 | - 'wppm_task_start_date'=>$task['start_date'], | |
| 53 | - 'wppm_task_end_date'=>$task['end_date'], | |
| 54 | - 'status'=>$task['status'], | |
| 55 | - 'wppm_create_task_priority'=>$task['priority'], | |
| 56 | - 'user_names'=>explode(",",$task['users']), | |
| 57 | - 'date_created'=>$task['date_created'], | |
| 58 | - 'task_auth_code'=> $wppmfunction->getRandomString(10), | |
| 59 | - 'active'=>1 | |
| 60 | -); | |
| 61 | -$task_id = $wppmfunction->create_task($values); | |
| 62 | -if(!isset($project_id) || $wppm_default_duplicate_project_email_notification==1){ | |
| 63 | - do_action('wppm_after_task_created', $task_id); | |
| 64 | -} | |
| 65 | -if(!empty($checklists)){ | |
| 66 | - foreach($checklists as $checklist){ | |
| 67 | - $chk_values = array( | |
| 68 | - 'task_id' => $task_id, | |
| 69 | - 'checklist_name' => $checklist['checklist_name'], | |
| 70 | - 'created_by'=> $checklist['created_by'] | |
| 71 | - ); | |
| 72 | - $checklist_id = $wppmfunction->create_checklist($chk_values); | |
| 73 | - $checklist_items = $wppmfunction->get_checklist_items($checklist['id']); | |
| 74 | - if(!empty($checklist_items)){ | |
| 75 | - $chk_items_values = array(); | |
| 76 | - $checklist_item_id = array(); | |
| 77 | - foreach($checklist_items as $checklist_item){ | |
| 78 | - $chk_items_values = array( | |
| 79 | - 'checklist_id' => $checklist_id, | |
| 80 | - 'item_name' => $checklist_item['item_name'], | |
| 81 | - 'checked'=>$checklist_item['checked'], | |
| 82 | - 'members'=>$checklist_item['members'], | |
| 83 | - 'due_date'=> $checklist_item['due_date'] | |
| 84 | - ); | |
| 85 | - if(!empty($chk_items_values)){ | |
| 86 | - $checklist_item_id[] = $wppmfunction->create_checklist_item($chk_items_values); | |
| 87 | - } | |
| 88 | - } | |
| 89 | - | |
| 90 | - } | |
| 91 | - } | |
| 92 | -} | |
| 93 | -if(!empty($task_comments)){ | |
| 94 | - $args = array(); | |
| 95 | - foreach($task_comments as $task_comment){ | |
| 96 | - $task_comment_data = json_decode(wp_json_encode($task_comment), true); | |
| 97 | - $attachment_ids = $task_comment_data['attachment_ids']; | |
| 98 | - $attachment_ids_array = explode(",",$attachment_ids); | |
| 99 | - if(!empty($attachment_ids_array)){ | |
| 100 | - $attachment_id = array(); | |
| 101 | - $values = array(); | |
| 102 | - foreach($attachment_ids_array as $attach_id){ | |
| 103 | - if(!empty($attach_id)){ | |
| 104 | - $attachment_data = $wppmfunction->get_attachment($attach_id); | |
| 105 | - $values=array( | |
| 106 | - 'name'=>!empty($attachment_data['name']) ? $attachment_data['name'] : '', | |
| 107 | - 'file_name'=> !empty($attachment_data['file_name']) ? $attachment_data['file_name'] : '', | |
| 108 | - 'file_path'=>!empty($attachment_data['file_path']) ? $attachment_data['file_path'] : '', | |
| 109 | - 'is_image'=>!empty($attachment_data['is_image']) ? $attachment_data['is_image'] : 0, | |
| 110 | - 'is_active'=>1, | |
| 111 | - 'is_uploaded'=>0, | |
| 112 | - 'date_created'=>!empty($attachment_data['date_created']) ? $attachment_data['date_created'] : '' | |
| 113 | - ); | |
| 114 | - if(!empty($values)){ | |
| 115 | - $wpdb->insert($wpdb->prefix.'wppm_attachments',$values); | |
| 116 | - $attachment_id[] = $wpdb->insert_id; | |
| 117 | - } | |
| 118 | - } | |
| 119 | - } | |
| 120 | - } | |
| 121 | - $args = array( | |
| 122 | - 'task_id'=>$task_id, | |
| 123 | - 'body'=>$task_comment_data['body'], | |
| 124 | - 'attachment_ids' =>implode(',',$attachment_id) , | |
| 125 | - 'create_time'=>$task_comment_data['create_time'], | |
| 126 | - 'created_by'=>$task_comment_data['created_by'] | |
| 127 | - ); | |
| 128 | - if(!empty($args)){ | |
| 129 | - $comment_id = $wppmfunction->wppm_submit_task_comment($args); | |
| 130 | - $task_comm_id = esc_sql($task_comment->id); | |
| 131 | - $task_comment_type = $wpdb->get_var( $wpdb->prepare("SELECT comment_type FROM {$wpdb->prefix}wppm_task_comment_meta WHERE task_id = %d AND comment_id = %d",$prev_task_id,$task_comm_id)); | |
| 132 | - if(!empty($task_comment_type)){ | |
| 133 | - $meta_values = array( | |
| 134 | - 'task_id'=>$task_id, | |
| 135 | - 'comment_id'=>$comment_id, | |
| 136 | - 'comment_type'=>$task_comment_type | |
| 137 | - ); | |
| 138 | - $comment_meta_id = $wppmfunction->wppm_submit_task_comment_meta($meta_values); | |
| 139 | - } | |
| 140 | - } | |
| 141 | - } | |
| 142 | -} | |
| 143 | -do_action("wppm_after_task_clone",$prev_task_id,$task_id); | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | +global $wpdb, $current_user, $wppmfunction; | |
| 6 | +$is_internal_clone = ! empty( $internal_code_flag ); | |
| 7 | +if ( ! $is_internal_clone ) { | |
| 8 | + if ( | |
| 9 | + empty( $_POST['_ajax_nonce'] ) || | |
| 10 | + ! wp_verify_nonce( | |
| 11 | + sanitize_text_field( | |
| 12 | + wp_unslash( $_POST['_ajax_nonce'] ) | |
| 13 | + ), | |
| 14 | + 'wppm_set_clone_task' | |
| 15 | + ) | |
| 16 | + ) { | |
| 17 | + wp_send_json_error( | |
| 18 | + array( | |
| 19 | + 'message' => esc_html__( | |
| 20 | + 'Security check failed.', | |
| 21 | + 'taskbuilder' | |
| 22 | + ) | |
| 23 | + ) | |
| 24 | + ); | |
| 25 | + } | |
| 26 | +} | |
| 27 | +$prev_task_id = isset($_POST['task_id']) ? absint(sanitize_text_field(wp_unslash($_POST['task_id']))) : $ptask_id ; | |
| 28 | +$task = $wppmfunction->get_task($prev_task_id); | |
| 29 | +if ( empty($task) ) { | |
| 30 | + wp_send_json_error('Invalid task', 404); | |
| 31 | +} | |
| 32 | +if (!(($current_user->has_cap('manage_options')) || $wppmfunction->has_permission('clone_task',$task['id']))) { | |
| 33 | + wp_send_json_error('Unauthorized', 403); | |
| 34 | +} | |
| 35 | +$wppm_default_duplicate_project_email_notification = get_option('wppm_default_duplicate_project_email_notification'); | |
| 36 | +$checklists = $wppmfunction->get_checklist($prev_task_id); | |
| 37 | +$task_project = isset($project_id) ? $project_id : $task['project']; | |
| 38 | +$prev_task_id = esc_sql($prev_task_id); | |
| 39 | +$task_comments = $wpdb->get_results( | |
| 40 | + $wpdb->prepare( | |
| 41 | + "SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d", | |
| 42 | + $prev_task_id | |
| 43 | + ) | |
| 44 | +); | |
| 45 | +$task_name = isset($_POST['task_name']) ? stripslashes(sanitize_text_field(wp_unslash($_POST['task_name']))) : $task['task_name'] ; | |
| 46 | +$now = wp_date("Y-m-d H:i:s"); | |
| 47 | +$values = array( | |
| 48 | + 'created_by'=>$task['created_by'], | |
| 49 | + 'name'=>$task_name, | |
| 50 | + 'wppm_task_description'=>$task['description'], | |
| 51 | + 'wppm_task_project'=>$task_project, | |
| 52 | + 'wppm_task_start_date'=>$task['start_date'], | |
| 53 | + 'wppm_task_end_date'=>$task['end_date'], | |
| 54 | + 'status'=>$task['status'], | |
| 55 | + 'wppm_create_task_priority'=>$task['priority'], | |
| 56 | + 'user_names'=>explode(",",$task['users']), | |
| 57 | + 'date_created'=>$task['date_created'], | |
| 58 | + 'task_auth_code'=> $wppmfunction->getRandomString(10), | |
| 59 | + 'active'=>1, | |
| 60 | + 'parent_task_id'=>isset($task['parent_task_id']) ? $task['parent_task_id'] : 0 | |
| 61 | +); | |
| 62 | +$task_id = $wppmfunction->create_task($values); | |
| 63 | +if(!isset($project_id) || $wppm_default_duplicate_project_email_notification==1){ | |
| 64 | + do_action('wppm_after_task_created', $task_id); | |
| 65 | +} | |
| 66 | +if(!empty($checklists)){ | |
| 67 | + foreach($checklists as $checklist){ | |
| 68 | + $chk_values = array( | |
| 69 | + 'task_id' => $task_id, | |
| 70 | + 'checklist_name' => $checklist['checklist_name'], | |
| 71 | + 'created_by'=> $checklist['created_by'] | |
| 72 | + ); | |
| 73 | + $checklist_id = $wppmfunction->create_checklist($chk_values); | |
| 74 | + $checklist_items = $wppmfunction->get_checklist_items($checklist['id']); | |
| 75 | + if(!empty($checklist_items)){ | |
| 76 | + $chk_items_values = array(); | |
| 77 | + $checklist_item_id = array(); | |
| 78 | + foreach($checklist_items as $checklist_item){ | |
| 79 | + $chk_items_values = array( | |
| 80 | + 'checklist_id' => $checklist_id, | |
| 81 | + 'item_name' => $checklist_item['item_name'], | |
| 82 | + 'checked'=>$checklist_item['checked'], | |
| 83 | + 'members'=>$checklist_item['members'], | |
| 84 | + 'due_date'=> $checklist_item['due_date'] | |
| 85 | + ); | |
| 86 | + if(!empty($chk_items_values)){ | |
| 87 | + $checklist_item_id[] = $wppmfunction->create_checklist_item($chk_items_values); | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 91 | + } | |
| 92 | + } | |
| 93 | +} | |
| 94 | +if(!empty($task_comments)){ | |
| 95 | + $args = array(); | |
| 96 | + foreach($task_comments as $task_comment){ | |
| 97 | + $task_comment_data = json_decode(wp_json_encode($task_comment), true); | |
| 98 | + $attachment_ids = $task_comment_data['attachment_ids']; | |
| 99 | + $attachment_ids_array = explode(",",$attachment_ids); | |
| 100 | + if(!empty($attachment_ids_array)){ | |
| 101 | + $attachment_id = array(); | |
| 102 | + $values = array(); | |
| 103 | + foreach($attachment_ids_array as $attach_id){ | |
| 104 | + if(!empty($attach_id)){ | |
| 105 | + $attachment_data = $wppmfunction->get_attachment($attach_id); | |
| 106 | + $values=array( | |
| 107 | + 'name'=>!empty($attachment_data['name']) ? $attachment_data['name'] : '', | |
| 108 | + 'file_name'=> !empty($attachment_data['file_name']) ? $attachment_data['file_name'] : '', | |
| 109 | + 'file_path'=>!empty($attachment_data['file_path']) ? $attachment_data['file_path'] : '', | |
| 110 | + 'is_image'=>!empty($attachment_data['is_image']) ? $attachment_data['is_image'] : 0, | |
| 111 | + 'is_active'=>1, | |
| 112 | + 'is_uploaded'=>0, | |
| 113 | + 'date_created'=>!empty($attachment_data['date_created']) ? $attachment_data['date_created'] : '' | |
| 114 | + ); | |
| 115 | + if(!empty($values)){ | |
| 116 | + $wpdb->insert($wpdb->prefix.'wppm_attachments',$values); | |
| 117 | + $attachment_id[] = $wpdb->insert_id; | |
| 118 | + } | |
| 119 | + } | |
| 120 | + } | |
| 121 | + } | |
| 122 | + $args = array( | |
| 123 | + 'task_id'=>$task_id, | |
| 124 | + 'body'=>$task_comment_data['body'], | |
| 125 | + 'attachment_ids' =>implode(',',$attachment_id) , | |
| 126 | + 'create_time'=>$task_comment_data['create_time'], | |
| 127 | + 'created_by'=>$task_comment_data['created_by'] | |
| 128 | + ); | |
| 129 | + if(!empty($args)){ | |
| 130 | + $comment_id = $wppmfunction->wppm_submit_task_comment($args); | |
| 131 | + $task_comm_id = esc_sql($task_comment->id); | |
| 132 | + $task_comment_type = $wpdb->get_var( $wpdb->prepare("SELECT comment_type FROM {$wpdb->prefix}wppm_task_comment_meta WHERE task_id = %d AND comment_id = %d",$prev_task_id,$task_comm_id)); | |
| 133 | + if(!empty($task_comment_type)){ | |
| 134 | + $meta_values = array( | |
| 135 | + 'task_id'=>$task_id, | |
| 136 | + 'comment_id'=>$comment_id, | |
| 137 | + 'comment_type'=>$task_comment_type | |
| 138 | + ); | |
| 139 | + $comment_meta_id = $wppmfunction->wppm_submit_task_comment_meta($meta_values); | |
| 140 | + } | |
| 141 | + } | |
| 142 | + } | |
| 143 | +} | |
| 144 | +do_action("wppm_after_task_clone",$prev_task_id,$task_id); | |
| 144 | 145 | return $task_id; |