| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wppmfunction ,$wpdb; |
| 7 |
$project_id = isset($_POST['project_id']) ? sanitize_text_field($_POST['project_id']) : 0 ; |
| 8 |
if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_project_permission('delete_project',$project_id))) {exit;} |
| 9 |
$tasks = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wppm_task where project = $project_id"); |
| 10 |
/*************delete project********/ |
| 11 |
$wpdb->delete($wpdb->prefix.'wppm_project',array('id'=>$project_id)); |
| 12 |
|
| 13 |
/*************delete project's tasks and comments********/ |
| 14 |
foreach($tasks as $task){ |
| 15 |
$sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id =".$task->id; |
| 16 |
$thread_attachment_ids= $wpdb->get_results( $sql ); |
| 17 |
|
| 18 |
/***************************Code for deleting attachment files****************************************************/ |
| 19 |
if(!empty($thread_attachment_ids)){ |
| 20 |
foreach ($thread_attachment_ids as $thread_attachment_id){ |
| 21 |
$attachment_ids_temp=array(); |
| 22 |
if($thread_attachment_id->attachment_ids){ |
| 23 |
$attachment_ids_temp= explode(',', $thread_attachment_id->attachment_ids); |
| 24 |
} |
| 25 |
//$attachment_ids=$attachment_ids_temp; |
| 26 |
foreach ($attachment_ids_temp as $attachment_id){ |
| 27 |
$sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id =".$attachment_id; |
| 28 |
$result=$wpdb->get_row($sql); |
| 29 |
if(!empty($result)){ |
| 30 |
$sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".$result->file_path."'"; |
| 31 |
$attach_result=$wpdb->get_results($sql_query); |
| 32 |
$result_count = count($attach_result); |
| 33 |
if(file_exists($result->file_path) && $result_count < 2) |
| 34 |
{ |
| 35 |
unlink($result->file_path); |
| 36 |
} |
| 37 |
$wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => $attachment_id)); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
/***************************Code for deleting checklists****************************************************/ |
| 43 |
$sql="SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id =".$task->id; |
| 44 |
$checklists = $wpdb->get_results( $sql ); |
| 45 |
if(!empty($checklists)){ |
| 46 |
foreach($checklists as $checklist){ |
| 47 |
$chk_array = (array) $checklist; |
| 48 |
$sql="SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id =".$chk_array['id']; |
| 49 |
$checklist_items = $wpdb->get_results( $sql ); |
| 50 |
if(!empty($checklist_items)){ |
| 51 |
foreach($checklist_items as $ch_item){ |
| 52 |
$chk_items_array = (array) $ch_item; |
| 53 |
$wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>$chk_items_array['id'])); |
| 54 |
} |
| 55 |
} |
| 56 |
$wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=>$chk_array['id'])); |
| 57 |
} |
| 58 |
} |
| 59 |
$wpdb->delete($wpdb->prefix.'wppm_task',array('project'=>$project_id)); |
| 60 |
$wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>$task->id)); |
| 61 |
} |
| 62 |
|