diff --git a/html/exhi/application/controllers/Company.php b/html/exhi/application/controllers/Company.php index 9b4bea96a814d14f221c4bf287abd45206ff0bed..568cfb5ac85cefa647659003912b85afa800bbdd 100644 --- a/html/exhi/application/controllers/Company.php +++ b/html/exhi/application/controllers/Company.php @@ -19,10 +19,19 @@ class Company extends Exhibition_Controller { } public function delete_company(){ + $data['message'] = true; $id = $this->input->post('id'); $this->load->model('company/M_company','company'); - $this->company->delete_company($id); - $data['message'] = true ; + $this->load->model('project/M_project','project'); + $projects = $this->project->get_all()->result(); + foreach($projects as $project){ + if($project->company_id == $id){ + $data['message'] = false; + } + } + if($data['message'] != false){ + $this->company->delete_company($id); + } echo json_encode($data); } diff --git a/html/exhi/application/controllers/Instructor.php b/html/exhi/application/controllers/Instructor.php index 8078f0152ea9e5a068455ee6f03c809d19f08fc3..51b36348ec4316a97a80a3884ed6759614d77bc3 100644 --- a/html/exhi/application/controllers/Instructor.php +++ b/html/exhi/application/controllers/Instructor.php @@ -19,10 +19,19 @@ class Instructor extends Exhibition_Controller { } public function delete_instructor(){ + $data['message'] = true ; $id = $this->input->post('id'); $this->load->model('instructor/M_instructor','instructor'); - $this->instructor->delete_instructor($id); - $data['message'] = true ; + $this->load->model('project/M_project','project'); + $projects = $this->project->get_all()->result(); + foreach($projects as $project){ + if($project->instructor_id == $id){ + $data['message'] = false; + } + } + if($data['message'] != false){ + $this->instructor->delete_instructor($id); + } echo json_encode($data); } diff --git a/html/exhi/application/controllers/Tag.php b/html/exhi/application/controllers/Tag.php index 4d268e8a79d3b275f71e7cdefcef742d50314f07..91803b403c8f866a241a6253dd6a8d84f5a826c2 100644 --- a/html/exhi/application/controllers/Tag.php +++ b/html/exhi/application/controllers/Tag.php @@ -19,10 +19,17 @@ class Tag extends Exhibition_Controller { } public function delete_tag(){ + $data['message'] = true; $id = $this->input->post('id'); $this->load->model('tag/M_tag','tag'); - $this->tag->delete_tag($id); - $data['message'] = true ; + $this->load->model('project_tag/M_project_tag','project_tag'); + $project_tag = $this->project_tag->get_project_tag_by_tag_id($id)->result(); + if(count($project_tag) > 0){ + $data['message'] = false; + } + if($data['message'] != false){ + $this->tag->delete_tag($id); + } echo json_encode($data); } diff --git a/html/exhi/application/controllers/User.php b/html/exhi/application/controllers/User.php index d9ee93ae27f165c06f043c98a457bb9ab85a34d7..b6c7a5055fc5ff2ab902a9f150061ddb5ac16495 100644 --- a/html/exhi/application/controllers/User.php +++ b/html/exhi/application/controllers/User.php @@ -93,10 +93,26 @@ class User extends Exhibition_Controller { public function delete_user(){ + $data['message'] = true ; $id = $this->input->post('id'); $this->load->model('user/M_user','user'); - $this->user->delete_user($id); - $data['message'] = true ; + $this->load->model('project/M_project','project'); + $this->load->model('member/M_member','member'); + $projects = $this->project->get_all()->result(); + foreach($projects as $project){ + if($project->user_id == $id){ + $data['message'] = false; + } + } + $members = $this->member->get_all()->result(); + foreach($members as $member){ + if($member->user_id == $id){ + $data['message'] = false; + } + } + if($data['message'] != false){ + $this->user->delete_user($id); + } echo json_encode($data); } diff --git a/html/exhi/application/models/member/M_member.php b/html/exhi/application/models/member/M_member.php index 8325ac73144ff19d80e354f5d4c0770e42d14115..4a0621875d8373df88a773dc8ed86e97aeca3d05 100644 --- a/html/exhi/application/models/member/M_member.php +++ b/html/exhi/application/models/member/M_member.php @@ -11,6 +11,12 @@ class M_member extends Da_member parent::__construct(); } + public function get_all(){ + $sql = "SELECT * FROM {$this->db_name}.member"; + $query = $this->db->query($sql); + return $query; + } + public function get_member_by_project_id($id){ $sql = "SELECT * FROM {$this->db_name}.member Where project_id = $id"; diff --git a/html/exhi/application/models/project_tag/M_project_tag.php b/html/exhi/application/models/project_tag/M_project_tag.php index 7520edfdb965ec6a149f6eaf219c756d9e2278c3..2403cc40f517ac35bc53ce48afc7ec32ed7703f2 100644 --- a/html/exhi/application/models/project_tag/M_project_tag.php +++ b/html/exhi/application/models/project_tag/M_project_tag.php @@ -18,6 +18,13 @@ class M_project_tag extends Da_project_tag return $query; } + public function get_project_tag_by_tag_id($id){ + $sql = "SELECT * FROM {$this->db_name}.project_tag + Where tag_id = $id"; + $query = $this->db->query($sql); + return $query; + } + public function get_by_id($id){ $sql = "SELECT * FROM {$this->db_name}.project_tag join tag on project_tag.tag_id = tag.tag_id diff --git a/html/exhi/application/views/company/v_company_manage.php b/html/exhi/application/views/company/v_company_manage.php index 823b67c31158db94b55bafb5cf2b3aac7f4389a8..3de14e563d7f08057f9a74fdd2174da1851c40e9 100644 --- a/html/exhi/application/views/company/v_company_manage.php +++ b/html/exhi/application/views/company/v_company_manage.php @@ -345,7 +345,7 @@ function delete_company(id) { } else { Toast.fire({ - icon: 'success', + icon: 'error', title: 'ลบข้อมูลไม่สำเร็จ', }); } diff --git a/html/exhi/application/views/user/v_user_manage.php b/html/exhi/application/views/user/v_user_manage.php index 158dff3a1af1b1829734c3d724dbc81e1f322c98..ef1edece100bce2cf9e80dd19093d569446e7b00 100644 --- a/html/exhi/application/views/user/v_user_manage.php +++ b/html/exhi/application/views/user/v_user_manage.php @@ -161,7 +161,7 @@ function delete_user(id) { } else { Toast.fire({ - icon: 'success', + icon: 'error', title: 'ลบข้อมูลไม่สำเร็จ', }); }