<?php

namespace App\Http\Controllers;

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

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

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

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

	// GET /measurements/view/{uid}/SUB_dashboard
	public function SUB_dashboard(Request $request, $uid) {
		$record = DB::table('measurement')->where('uid', $uid)->first();
		if(!$record) {
			$record = DB::table('measurement')->where('id', $uid)->first();
			if($record) return redirect('/measurements/view/' . $record->uid . '/SUB_dashboard');
		}
		$result_clients = DB::select("select id, concat(name_first, ' ', name_last) as name_display from client");
		return response()->view('pro/measurements_SINGLE/SUB_dashboard', compact('record', 'result_clients'), session('message') ? 500 : 200)->header('Content-Type', 'text/html');
	}
}
