1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Http\Controllers;
|
---|
4 |
|
---|
5 | use Carbon\Carbon;
|
---|
6 | use Illuminate\Http\Request;
|
---|
7 | use Illuminate\Support\Facades\DB;
|
---|
8 | use Illuminate\Support\Facades\Session;
|
---|
9 | class CrimeCaseController extends Controller
|
---|
10 | {
|
---|
11 | private function policeStationIsPoliceman()
|
---|
12 | {
|
---|
13 | return DB::table('police_station')
|
---|
14 | ->where('p_id', Session::get('p_id'))
|
---|
15 | ->get();
|
---|
16 | }
|
---|
17 | private function policeStationIsOfficer()
|
---|
18 | {
|
---|
19 | return DB::table('police_station')
|
---|
20 | ->where('pe_id', Session::get('pe_id'))
|
---|
21 | ->get();
|
---|
22 | }
|
---|
23 | function cases(){
|
---|
24 | if(Session::get('pe_id') == null) {
|
---|
25 | return view('login');
|
---|
26 | }
|
---|
27 |
|
---|
28 | if(Session::get('is_policeman')){
|
---|
29 | $police_station = $this->policeStationIsPoliceman();
|
---|
30 | } else {
|
---|
31 | $police_station = $this->policeStationIsOfficer();
|
---|
32 | }
|
---|
33 |
|
---|
34 | $cases = DB::table('crime_case')
|
---|
35 | ->where('p_id', $police_station[0]->p_id)
|
---|
36 | ->get();
|
---|
37 |
|
---|
38 | return view('cases', [
|
---|
39 | 'cases' => $cases,
|
---|
40 | 'p_address'=>$police_station[0]->p_address
|
---|
41 | ]);
|
---|
42 |
|
---|
43 | }
|
---|
44 | function register_statement(){
|
---|
45 | return view('register-statement');
|
---|
46 | }
|
---|
47 | function register_statement_post()
|
---|
48 | {
|
---|
49 | $role = request()->input('role');
|
---|
50 |
|
---|
51 |
|
---|
52 | $statement = request()->validate([
|
---|
53 | 'embg' => 'required',
|
---|
54 | 'description' => 'required',
|
---|
55 | 'incident_timestamp' => 'required',
|
---|
56 | 'incident_place'=>'required'
|
---|
57 | ]);
|
---|
58 | $statement["statement_date"] = Carbon::now()->format('Y-m-d');
|
---|
59 | $covek = DB::select('select pe_id from people where embg=:embg;',['embg'=> $statement["embg"]]);
|
---|
60 | $s_id_b = DB::select('select MAX(s_id) from statements');
|
---|
61 | $s_id = $s_id_b[0]->max;
|
---|
62 | $s_id = $s_id +1 ;
|
---|
63 | $policaec = DB::select('select pe_id from policeman where badge_no=:badge_no;',['badge_no'=> Session::get("badge_no")]);
|
---|
64 |
|
---|
65 | if ($role === 'witness') {
|
---|
66 | DB::insert('INSERT INTO statements (s_id, statement_date, description, incident_timestamp, incident_place, c_id, pe_id, victim_pe_id, witness_pe_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
---|
67 | [
|
---|
68 | $s_id,
|
---|
69 | $statement["statement_date"],
|
---|
70 | $statement["description"],
|
---|
71 | $statement["incident_timestamp"],
|
---|
72 | $statement["incident_place"],
|
---|
73 | Session::get("c_id"),
|
---|
74 | $policaec[0]->pe_id,
|
---|
75 | NULL,
|
---|
76 | $covek[0]->pe_id
|
---|
77 |
|
---|
78 | ]);
|
---|
79 | } elseif ($role === 'victim') {
|
---|
80 | DB::insert('INSERT INTO statements (s_id, statement_date, description, incident_timestamp, incident_place, c_id, pe_id, victim_pe_id, witness_pe_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
---|
81 | [
|
---|
82 | $s_id,
|
---|
83 | $statement["statement_date"],
|
---|
84 | $statement["description"],
|
---|
85 | $statement["incident_timestamp"],
|
---|
86 | $statement["incident_place"],
|
---|
87 | Session::get("c_id"),
|
---|
88 | $policaec[0]->pe_id,
|
---|
89 | $covek[0]->pe_id,
|
---|
90 | NULL
|
---|
91 | ]);
|
---|
92 | }
|
---|
93 | return redirect()->route('case', ['wildcard' => Session::get("c_id"),]);
|
---|
94 |
|
---|
95 |
|
---|
96 | }
|
---|
97 | function finished_cases(){
|
---|
98 | if(Session::get('is_policeman')){
|
---|
99 | $police_station = $this->policeStationIsPoliceman();
|
---|
100 | } else {
|
---|
101 | $police_station = $this->policeStationIsOfficer();
|
---|
102 | }
|
---|
103 |
|
---|
104 | $cases = DB::table('crime_case')
|
---|
105 | ->where('p_id', $police_station[0]->p_id)
|
---|
106 | ->where('c_status', 'Z')
|
---|
107 | ->get();
|
---|
108 | return view('archive', [
|
---|
109 | 'cases' => $cases,
|
---|
110 | 'p_address'=>$police_station[0]->p_address
|
---|
111 | ]);
|
---|
112 | }
|
---|
113 | function case($wildcard){
|
---|
114 | Session::put('c_id', $wildcard);
|
---|
115 | $case = DB::table('crime_case')
|
---|
116 | ->where('c_id', $wildcard)
|
---|
117 | ->get();
|
---|
118 | $p_address = DB::table('police_station')
|
---|
119 | ->where('p_id', $case[0]->p_id)
|
---|
120 | ->value('p_address');
|
---|
121 | $statements = DB::table('statements')
|
---|
122 | ->where('c_id', $wildcard)
|
---|
123 | ->get();
|
---|
124 |
|
---|
125 | $victims=[];
|
---|
126 | $witness=[];
|
---|
127 | $evidence_id = [];
|
---|
128 | $evidence = [];
|
---|
129 | foreach ($statements as $statement) {
|
---|
130 | $evidence_id = DB::table('mentions_evidence')
|
---|
131 | ->where('s_id', $statement->s_id)
|
---|
132 | ->get();
|
---|
133 | // if (!empty($evidence_id)) { // Check if $evidence_id is not empty
|
---|
134 | // $evidence_id[] = $evidence_id[0];
|
---|
135 | // }
|
---|
136 | }
|
---|
137 | $evidence_id=collect($evidence_id)->unique();
|
---|
138 | foreach ($evidence_id as $e) {
|
---|
139 | $evidence = DB::table('evidence')
|
---|
140 | ->where('e_id', $e->e_id)->get();
|
---|
141 |
|
---|
142 | }
|
---|
143 | foreach ($statements as $st){
|
---|
144 | if (!($st->victim_pe_id)==NULL){
|
---|
145 | $victim = DB::table('people')
|
---|
146 | ->where('pe_id', $st->victim_pe_id)->get();
|
---|
147 | $victims[] = $victim[0];
|
---|
148 | }
|
---|
149 | }
|
---|
150 | foreach ($statements as $st){
|
---|
151 | if (!($st->witness_pe_id)==NULL) {
|
---|
152 | $witnes = DB::table('people')
|
---|
153 | ->where('pe_id', $st->witness_pe_id)->get();
|
---|
154 | $witness[] = $witnes[0];
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | return view('case', [
|
---|
159 | 'case' => $case[0],
|
---|
160 | 'p_address'=>$p_address,
|
---|
161 | 'statements'=>$statements,
|
---|
162 | 'evidence'=>$evidence,
|
---|
163 | 'victims' => $victims,
|
---|
164 | 'witness' =>$witness
|
---|
165 | ]);
|
---|
166 |
|
---|
167 | }
|
---|
168 | }
|
---|