← All changes
|
includes/admin/projects/wppm_set_delete_project.php
+102
-102
5.0.1
→
6.0.6
View file →
| @@ -1,102 +1,102 @@ | ||
| 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']) ? intval(sanitize_text_field($_POST['project_id'])) : 0 ; | |
| 8 | -$project = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}wppm_project where id = '".esc_sql($project_id)."'" ); | |
| 9 | -$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 10 | -if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_project_permission('delete_project',$project_id) || ($project->created_by==$current_user->ID && $wppm_current_user_capability == 'wppm_manager') || ($current_user->ID && $current_user->has_cap('wppm_admin')))) {exit;} | |
| 11 | - | |
| 12 | -if ( check_ajax_referer( 'wppm_set_delete_project', '_ajax_nonce', false ) != 1 ) { | |
| 13 | - wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 14 | -} | |
| 15 | - | |
| 16 | -$tasks = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wppm_task where project = '".esc_sql($project_id)."'" ); | |
| 17 | -/*************delete project********/ | |
| 18 | - $wpdb->delete($wpdb->prefix.'wppm_project',array('id'=>"$project_id")); | |
| 19 | - | |
| 20 | -/*************delete project comment********/ | |
| 21 | -$sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_project_comment WHERE proj_id ='".esc_sql($project_id)."'" ; | |
| 22 | -$proj_comm_attachment_ids= $wpdb->get_results( $sql ); | |
| 23 | -if(!empty($proj_comm_attachment_ids)){ | |
| 24 | - foreach ($proj_comm_attachment_ids as $proj_attachment_id){ | |
| 25 | - $proj_attachment_ids_temp=array(); | |
| 26 | - if($proj_attachment_id->attachment_ids){ | |
| 27 | - $proj_attachment_ids_temp= explode(',', $proj_attachment_id->attachment_ids); | |
| 28 | - } | |
| 29 | - foreach ($proj_attachment_ids_temp as $proj_attachment_id){ | |
| 30 | - $proj_attachment_id = esc_sql($proj_attachment_id); | |
| 31 | - $sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id ='$proj_attachment_id'"; | |
| 32 | - $att_result=$wpdb->get_row($sql); | |
| 33 | - if(!empty($att_result)){ | |
| 34 | - $sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".esc_sql($att_result->file_path)."'"; | |
| 35 | - $proj_attach_result=$wpdb->get_results($sql_query); | |
| 36 | - $proj_result_count = count($proj_attach_result); | |
| 37 | - if(file_exists($att_result->file_path) && $proj_result_count < 2) | |
| 38 | - { | |
| 39 | - unlink($att_result->file_path); | |
| 40 | - } | |
| 41 | - $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => "$proj_attachment_id")); | |
| 42 | - } | |
| 43 | - } | |
| 44 | - } | |
| 45 | -} | |
| 46 | -$wpdb->delete($wpdb->prefix.'wppm_project_comment',array('proj_id'=>esc_sql($project_id))); | |
| 47 | -$wpdb->delete($wpdb->prefix.'wppm_project_meta',array('project_id'=>esc_sql($project_id))); | |
| 48 | -$wpdb->delete($wpdb->prefix.'wppm_project_comment_meta',array('proj_id'=>esc_sql($project_id))); | |
| 49 | - | |
| 50 | -/*************delete project's tasks and comments********/ | |
| 51 | -foreach($tasks as $task){ | |
| 52 | - $sql="SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id ='".esc_sql($task->id)."'"; | |
| 53 | - $thread_attachment_ids= $wpdb->get_results( $sql ); | |
| 54 | - $tid = esc_sql($task->id); | |
| 55 | - /***************************Code for deleting attachment files****************************************************/ | |
| 56 | - if(!empty($thread_attachment_ids)){ | |
| 57 | - foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 58 | - $attachment_ids_temp=array(); | |
| 59 | - if($thread_attachment_id->attachment_ids){ | |
| 60 | - $attachment_ids_temp= explode(',', $thread_attachment_id->attachment_ids); | |
| 61 | - } | |
| 62 | - //$attachment_ids=$attachment_ids_temp; | |
| 63 | - foreach ($attachment_ids_temp as $attachment_id){ | |
| 64 | - $sql="SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = '".esc_sql($attachment_id)."'" ; | |
| 65 | - $result=$wpdb->get_row($sql); | |
| 66 | - if(!empty($result)){ | |
| 67 | - $sql_query="SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path ='".esc_sql($result->file_path)."'"; | |
| 68 | - $attach_result=$wpdb->get_results($sql_query); | |
| 69 | - $result_count = count($attach_result); | |
| 70 | - if(file_exists($result->file_path) && $result_count < 2) | |
| 71 | - { | |
| 72 | - unlink($result->file_path); | |
| 73 | - } | |
| 74 | - $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => esc_sql($attachment_id))); | |
| 75 | - } | |
| 76 | - } | |
| 77 | - } | |
| 78 | - } | |
| 79 | - /***************************Code for deleting checklists****************************************************/ | |
| 80 | - $sql="SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = '".($tid)."'" ; | |
| 81 | - $checklists = $wpdb->get_results( $sql ); | |
| 82 | - if(!empty($checklists)){ | |
| 83 | - foreach($checklists as $checklist){ | |
| 84 | - $chk_array = (array) $checklist; | |
| 85 | - $chk_id = esc_sql($chk_array['id']); | |
| 86 | - $sql="SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id ='$chk_id '"; | |
| 87 | - $checklist_items = $wpdb->get_results( $sql ); | |
| 88 | - if(!empty($checklist_items)){ | |
| 89 | - foreach($checklist_items as $ch_item){ | |
| 90 | - $chk_items_array = (array) $ch_item; | |
| 91 | - $chk_item_id = esc_sql($chk_items_array['id']); | |
| 92 | - $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>"$chk_item_id")); | |
| 93 | - } | |
| 94 | - } | |
| 95 | - $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=> "$chk_id")); | |
| 96 | - } | |
| 97 | - } | |
| 98 | - $wpdb->delete($wpdb->prefix.'wppm_task',array('project'=>esc_sql($project_id))); | |
| 99 | - $wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>$tid)); | |
| 100 | - $wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>$tid)); | |
| 101 | - $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>$tid)); | |
| 102 | -} | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | + | |
| 6 | +global $current_user, $wppmfunction ,$wpdb; | |
| 7 | + | |
| 8 | +if ( check_ajax_referer( 'wppm_set_delete_project', '_ajax_nonce', false ) != 1 ) { | |
| 9 | + wp_send_json_error( 'Unauthorised request!', 401 ); | |
| 10 | +} | |
| 11 | +$project_id = isset($_POST['project_id']) ? intval(sanitize_text_field(wp_unslash($_POST['project_id']))) : 0 ; | |
| 12 | +$project = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project where id = %d",absint($project_id))); | |
| 13 | +$wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 14 | +if (!(($current_user->ID && $current_user->has_cap('manage_options')) || $wppmfunction->has_project_permission('delete_project',$project_id) || ($project->created_by==$current_user->ID && $wppm_current_user_capability == 'wppm_manager') || ($current_user->ID && $current_user->has_cap('wppm_admin')))) {exit;} | |
| 15 | + | |
| 16 | +$tasks = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task where project = %d",absint($project_id))); | |
| 17 | +/*************delete project********/ | |
| 18 | + $wpdb->delete($wpdb->prefix.'wppm_project',array('id'=>"$project_id")); | |
| 19 | + | |
| 20 | +/*************delete project comment********/ | |
| 21 | +$sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_project_comment WHERE proj_id = %d",absint($project_id)); | |
| 22 | +$proj_comm_attachment_ids= $wpdb->get_results( $sql ); | |
| 23 | +if(!empty($proj_comm_attachment_ids)){ | |
| 24 | + foreach ($proj_comm_attachment_ids as $proj_attachment_id){ | |
| 25 | + $proj_attachment_ids_temp=array(); | |
| 26 | + if($proj_attachment_id->attachment_ids){ | |
| 27 | + $proj_attachment_ids_temp= explode(',', $proj_attachment_id->attachment_ids); | |
| 28 | + } | |
| 29 | + foreach ($proj_attachment_ids_temp as $proj_attachment_id){ | |
| 30 | + $proj_attachment_id = absint($proj_attachment_id); | |
| 31 | + $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",absint($proj_attachment_id)); | |
| 32 | + $att_result=$wpdb->get_row($sql); | |
| 33 | + if(!empty($att_result)){ | |
| 34 | + $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",esc_sql($att_result->file_path)); | |
| 35 | + $proj_attach_result=$wpdb->get_results($sql_query); | |
| 36 | + $proj_result_count = count($proj_attach_result); | |
| 37 | + if(file_exists($att_result->file_path) && $proj_result_count < 2) | |
| 38 | + { | |
| 39 | + wp_delete_file($att_result->file_path); | |
| 40 | + } | |
| 41 | + $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => "$proj_attachment_id")); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} | |
| 46 | +$wpdb->delete($wpdb->prefix.'wppm_project_comment',array('proj_id'=>absint($project_id))); | |
| 47 | +$wpdb->delete($wpdb->prefix.'wppm_project_meta',array('project_id'=>absint($project_id))); | |
| 48 | +$wpdb->delete($wpdb->prefix.'wppm_project_comment_meta',array('proj_id'=>absint($project_id))); | |
| 49 | + | |
| 50 | +/*************delete project's tasks and comments********/ | |
| 51 | +foreach($tasks as $task){ | |
| 52 | + $sql=$wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d",absint($task->id)); | |
| 53 | + $thread_attachment_ids= $wpdb->get_results( $sql ); | |
| 54 | + $tid = absint($task->id); | |
| 55 | + /***************************Code for deleting attachment files****************************************************/ | |
| 56 | + if(!empty($thread_attachment_ids)){ | |
| 57 | + foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 58 | + $attachment_ids_temp=array(); | |
| 59 | + if($thread_attachment_id->attachment_ids){ | |
| 60 | + $attachment_ids_temp= explode(',', $thread_attachment_id->attachment_ids); | |
| 61 | + } | |
| 62 | + //$attachment_ids=$attachment_ids_temp; | |
| 63 | + foreach ($attachment_ids_temp as $attachment_id){ | |
| 64 | + $sql=$wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d",absint($attachment_id)); | |
| 65 | + $result=$wpdb->get_row($sql); | |
| 66 | + if(!empty($result)){ | |
| 67 | + $sql_query=$wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s",esc_sql($result->file_path)); | |
| 68 | + $attach_result=$wpdb->get_results($sql_query); | |
| 69 | + $result_count = count($attach_result); | |
| 70 | + if(file_exists($result->file_path) && $result_count < 2) | |
| 71 | + { | |
| 72 | + wp_delete_file($result->file_path); | |
| 73 | + } | |
| 74 | + $wpdb->delete($wpdb->prefix.'wppm_attachments', array( 'id' => absint($attachment_id))); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 78 | + } | |
| 79 | + /***************************Code for deleting checklists****************************************************/ | |
| 80 | + $sql=$wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d",$tid); | |
| 81 | + $checklists = $wpdb->get_results( $sql ); | |
| 82 | + if(!empty($checklists)){ | |
| 83 | + foreach($checklists as $checklist){ | |
| 84 | + $chk_array = (array) $checklist; | |
| 85 | + $chk_id = absint($chk_array['id']); | |
| 86 | + $sql=$wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d",$chk_id); | |
| 87 | + $checklist_items = $wpdb->get_results( $sql ); | |
| 88 | + if(!empty($checklist_items)){ | |
| 89 | + foreach($checklist_items as $ch_item){ | |
| 90 | + $chk_items_array = (array) $ch_item; | |
| 91 | + $chk_item_id = absint($chk_items_array['id']); | |
| 92 | + $wpdb->delete($wpdb->prefix.'wppm_checklist_items',array('id'=>"$chk_item_id")); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + $wpdb->delete($wpdb->prefix.'wppm_checklist',array('id'=> "$chk_id")); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + $wpdb->delete($wpdb->prefix.'wppm_task',array('project'=>absint($project_id))); | |
| 99 | + $wpdb->delete($wpdb->prefix.'wppm_task_meta',array('task_id'=>absint($tid))); | |
| 100 | + $wpdb->delete($wpdb->prefix.'wppm_task_comment',array('task_id'=>absint($tid))); | |
| 101 | + $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta',array('task_id'=>absint($tid))); | |
| 102 | +} | |