[75151c6] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Http\Controllers;
|
---|
| 4 |
|
---|
[768f473] | 5 | use Carbon\Carbon;
|
---|
[75151c6] | 6 | use Illuminate\Http\Request;
|
---|
[6dec591] | 7 | use Illuminate\Support\Facades\DB;
|
---|
| 8 | use Illuminate\Support\Facades\Session;
|
---|
[75151c6] | 9 | class CrimeCaseController extends Controller
|
---|
| 10 | {
|
---|
| 11 | function cases(){
|
---|
[d9c4096] | 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 | }
|
---|
[6dec591] | 22 |
|
---|
| 23 | $cases = DB::select('select * from crime_case where p_id=:p_id;',['p_id'=> $police_station[0]->p_id]);
|
---|
| 24 |
|
---|
[d9c4096] | 25 |
|
---|
[6dec591] | 26 | return view('cases', [
|
---|
[d9c4096] | 27 | 'cases' => $cases,
|
---|
| 28 | 'p_address'=>$police_station[0]->p_address
|
---|
[6dec591] | 29 | ]);
|
---|
| 30 |
|
---|
[75151c6] | 31 | }
|
---|
[249bf91] | 32 | function register_statement(){
|
---|
| 33 | return view('register-statement');
|
---|
| 34 | }
|
---|
| 35 | function register_statement_post()
|
---|
| 36 | {
|
---|
[768f473] | 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 |
|
---|
[249bf91] | 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 | }
|
---|
[d9c4096] | 100 | function case($wildcard){
|
---|
[768f473] | 101 | Session::put('c_id', $wildcard);
|
---|
[d9c4096] | 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]);
|
---|
[f7acd52] | 105 |
|
---|
| 106 |
|
---|
[2bd3041] | 107 | $victims=[];
|
---|
| 108 | $witness=[];
|
---|
[f7acd52] | 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 | }
|
---|
[2bd3041] | 122 | foreach ($statements as $st){
|
---|
[768f473] | 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 | }
|
---|
[2bd3041] | 127 | }
|
---|
| 128 | foreach ($statements as $st){
|
---|
[768f473] | 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 | }
|
---|
[2bd3041] | 133 | }
|
---|
| 134 |
|
---|
[768f473] | 135 |
|
---|
[d9c4096] | 136 | return view('case', [
|
---|
| 137 | 'case' => $case[0],
|
---|
| 138 | 'p_address'=>$p_address[0]->p_address,
|
---|
| 139 | 'statements'=>$statements,
|
---|
| 140 | 'evidence'=>$evidence,
|
---|
[768f473] | 141 | 'victims' => $victims,
|
---|
| 142 | 'witness' =>$witness
|
---|
[d9c4096] | 143 | ]);
|
---|
[2bd3041] | 144 |
|
---|
[6b10b67] | 145 | }
|
---|
[75151c6] | 146 | }
|
---|