<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class facilities_SINGLE_Controller extends Controller
{
    public $selfName = 'facilities_SINGLE_Controller';
    public $dashboardName = 'dashboard';

	// GET /facilities/view/{uid}/ACTION_updateBasic
	public function ACTION_updateBasic(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/ACTION_updateBasic');
		}
		return response()->view('admin/facilities_SINGLE/ACTION_updateBasic', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/ACTION_deactivate
	public function ACTION_deactivate(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/ACTION_deactivate');
		}
		return response()->view('admin/facilities_SINGLE/ACTION_deactivate', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/ACTION_updateDeactivationMemo
	public function ACTION_updateDeactivationMemo(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/ACTION_updateDeactivationMemo');
		}
		return response()->view('admin/facilities_SINGLE/ACTION_updateDeactivationMemo', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/ACTION_reactivate
	public function ACTION_reactivate(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/ACTION_reactivate');
		}
		return response()->view('admin/facilities_SINGLE/ACTION_reactivate', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/ACTION_updateReactivationMemo
	public function ACTION_updateReactivationMemo(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/ACTION_updateReactivationMemo');
		}
		return response()->view('admin/facilities_SINGLE/ACTION_updateReactivationMemo', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/SUB_dashboard');
		}
		return response()->view('admin/facilities_SINGLE/SUB_dashboard', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/SUB_erx
	public function SUB_erx(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/SUB_erx');
		}
		return response()->view('admin/facilities_SINGLE/SUB_erx', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/SUB_action_items
	public function SUB_action_items(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/SUB_action_items');
		}
		return response()->view('admin/facilities_SINGLE/SUB_action_items', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}

	// GET /facilities/view/{uid}/SUB_audit_log
	public function SUB_audit_log(Request $request, $uid) {
		$record = DB::table('facility')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('facility')->where('id', $uid)->first();
			if($record) return redirect('/facilities/view/' . $record->uid . '/SUB_audit_log');
		}
		return response()->view('admin/facilities_SINGLE/SUB_audit_log', compact('record'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}
}
