orderBy('name')->get(); $curr_user = $request->session()->get('credentials'); $data = [ 'pins' => $pins, 'curr_user' => $curr_user[0]['name'] ]; return view('Admin.pbx', compact('data')); } public function pbxSearch (Request $request) { $data = $request->all(); $criteria = $data['search']; $pins = PBXPin::where('name', 'LIKE', '%'.$criteria.'%') ->orWhere('pin', '=', $criteria) ->get(); $curr_user = $request->session()->get('credentials'); $data = [ 'pins' => $pins, 'curr_user' => $curr_user[0]['name'] ]; return view('Admin.pbx', compact('data')); } public function createPin (Request $request) { $data = $request->all(); $curr_user = $request->session()->get('credentials'); try { $pins = DB::table('pbx_pin')->orderBy("name")->get(); $user = DB::table('users')->where('email', '=', $data['add-pbx'])->get(); if (!$user->isEmpty()) { $user_check = DB::table('pbx_pin')->where('email', '=', $data['add-pbx'])->get(); if($user_check->isEmpty()){ $check = 0; while ($check == 0) { $pinGenerator = rand(10000,99999); $check_curr = DB::table('pbx_pin')->where('pin', '=', $pinGenerator)->get(); $check_old = DB::table('expired_pins')->where('pin', '=', $pinGenerator)->get(); if ($check_curr->isEmpty() && $check_old->isEmpty()){ $check = 1; } } $pbx = new PBXPin(); $pbx->name = $user[0]->name; $pbx->email = $user[0]->email; $pbx->updated_by = $curr_user[0]['name']; $pbx->pin = $pinGenerator; $pbx->save(); $mailData = $pbx; Mail::to($pbx->email)->send(new NotifyUser($mailData)); Mail::to('servicedesk.mydns@gov.tt')->send(new NotifyAdmin($mailData)); return redirect()->route('pbx'); } else { // User already has PBX pin assigned $data = [ 'pins' => $pins, 'error' => '1', 'curr_user' => $curr_user[0]['name'] ]; return view('Admin.pbx', compact('data')); } } else { // User is not found $pins = DB::table('pbx_pin')->orderBy("name")->get(); $data = [ 'pins' => $pins, 'error' => '2', 'curr_user' => $curr_user[0]['name'] ]; return view('Admin.pbx', compact('data')); } } catch (\Exception $ex) { Log::channel('error')->info('Error:'.$ex); } } public function unauthorizedAccess () { return view('Admin.unauthorized'); } public function disable (Request $request, $id) { try { $pin = DB::table('pbx_pin')->where('id', $id)->first(); $curr_user = $request->session()->get('credentials'); $old_pin = new ExpiredPin(); $old_pin->pin = $pin->pin; $old_pin->name = $pin->name; $old_pin->email = $pin->email; $old_pin->updated_by = $curr_user[0]['name']; $old_pin->save(); $pin = DB::table('pbx_pin')->where('id', $id)->delete(); $mailData = $old_pin; Mail::to('servicedesk.mydns@gov.tt')->send(new PinDisabled($mailData)); return redirect()->route('pbx'); } catch (\Exception $ex) { Log::channel('error')->info('Error:'.$ex); } } }