| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
global $wpdb,$current_user,$wppmfunction; |
| 6 |
|
| 7 |
$prev_task_id = isset($_POST['task_id']) ? sanitize_text_field($_POST['task_id']) : $ptask_id ; |
| 8 |
$task = $wppmfunction->get_task($prev_task_id); |
| 9 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_permission('clone_task',$task['id']))) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
$checklists = $wppmfunction->get_checklist($prev_task_id); |
| 13 |
$task_project = isset($project_id) ? $project_id : $task['project']; |
| 14 |
$task_comments = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id=$prev_task_id "); |
| 15 |
$task_name = isset($_POST['task_name']) ? stripslashes(sanitize_text_field($_POST['task_name'])) : $task['task_name'] ; |
| 16 |
$now = date("Y-m-d H:i:s"); |
| 17 |
$values = array( |
| 18 |
'created_by'=>$task['created_by'], |
| 19 |
'name'=>$task_name, |
| 20 |
'wppm_task_description'=>$task['description'], |
| 21 |
'wppm_task_project'=>$task_project, |
| 22 |
'wppm_task_start_date'=>$task['start_date'], |
| 23 |
'wppm_task_end_date'=>$task['end_date'], |
| 24 |
'status'=>$task['status'], |
| 25 |
'wppm_create_task_priority'=>$task['priority'], |
| 26 |
'user_names'=>explode(",",$task['users']), |
| 27 |
'date_created'=>$task['date_created'], |
| 28 |
'task_auth_code'=> $wppmfunction->getRandomString(10), |
| 29 |
'active'=>1 |
| 30 |
); |
| 31 |
$task_id = $wppmfunction->create_task($values); |
| 32 |
do_action('wppm_after_task_created', $task_id); |
| 33 |
if(!empty($checklists)){ |
| 34 |
foreach($checklists as $checklist){ |
| 35 |
$chk_values = array( |
| 36 |
'task_id' => $task_id, |
| 37 |
'checklist_name' => $checklist['checklist_name'], |
| 38 |
'created_by'=> $checklist['created_by'] |
| 39 |
); |
| 40 |
$checklist_id = $wppmfunction->create_checklist($chk_values); |
| 41 |
$checklist_items = $wppmfunction->get_checklist_items($checklist['id']); |
| 42 |
if(!empty($checklist_items)){ |
| 43 |
$chk_items_values = array(); |
| 44 |
$checklist_item_id = array(); |
| 45 |
foreach($checklist_items as $checklist_item){ |
| 46 |
$chk_items_values = array( |
| 47 |
'checklist_id' => $checklist_id, |
| 48 |
'item_name' => $checklist_item['item_name'], |
| 49 |
'checked'=>$checklist_item['checked'], |
| 50 |
'members'=>$checklist_item['members'], |
| 51 |
'due_date'=> $checklist_item['due_date'] |
| 52 |
); |
| 53 |
if(!empty($chk_items_values)){ |
| 54 |
$checklist_item_id[] = $wppmfunction->create_checklist_item($chk_items_values); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
if(!empty($task_comments)){ |
| 62 |
$args = array(); |
| 63 |
foreach($task_comments as $task_comment){ |
| 64 |
$task_comment_data = json_decode(json_encode($task_comment), true); |
| 65 |
$attachment_ids = $task_comment_data['attachment_ids']; |
| 66 |
$attachment_ids_array = explode(",",$attachment_ids); |
| 67 |
if(!empty($attachment_ids_array)){ |
| 68 |
$attachment_id = array(); |
| 69 |
$values = array(); |
| 70 |
foreach($attachment_ids_array as $attach_id){ |
| 71 |
if(!empty($attach_id)){ |
| 72 |
$attachment_data = $wppmfunction->get_attachment($attach_id); |
| 73 |
$values=array( |
| 74 |
'name'=>$attachment_data['name'], |
| 75 |
'file_name'=> $attachment_data['file_name'], |
| 76 |
'file_path'=>$attachment_data['file_path'], |
| 77 |
'is_image'=>$attachment_data['is_image'], |
| 78 |
'is_active'=>1, |
| 79 |
'is_uploaded'=>0, |
| 80 |
'date_created'=>$attachment_data['date_created'] |
| 81 |
); |
| 82 |
if(!empty($values)){ |
| 83 |
$wpdb->insert($wpdb->prefix.'wppm_attachments',$values); |
| 84 |
$attachment_id[] = $wpdb->insert_id; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
$args = array( |
| 90 |
'task_id'=>$task_id, |
| 91 |
'body'=>$task_comment_data['body'], |
| 92 |
'attachment_ids' =>implode(',',$attachment_id) , |
| 93 |
'create_time'=>$task_comment_data['create_time'], |
| 94 |
'created_by'=>$task_comment_data['created_by'] |
| 95 |
); |
| 96 |
if(!empty($args)){ |
| 97 |
$comment_id[] = $wppmfunction->wppm_submit_task_comment($args); |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
do_action("wppm_after_task_clone",$prev_task_id,$task_id); |