<?php

namespace App\Http\Controllers;

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

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

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

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

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

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