source: app/Http/Controllers/CrimeCaseController.php@ 5372778

main
Last change on this file since 5372778 was 768f473, checked in by bube-ristovska <ristovska725@…>, 7 months ago

Final features

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