<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;
use Session;

class EncuestasController extends Controller
{

    public function busquedaFormulario(){
        return view('encuestas.busquedaform');
    }

    public function busquedaProcesar(Request $request){
        return redirect()->action('EncuestasController@grabar_formulario', ['idestablec' => $request->input('idestablec')]);
    }

    public function grabar_formulario($idestablec) {
    	$data = DB::select("CALL sp_r_establecimientos_detalle(" . Session::get('idencuesta') . ", '$idestablec');");	
    	return view('encuestas.grabar', compact('data'));
    }

    public function grabar(Request $request) {
    	$formData = $request->all();
    	DB::select("CALL sp_u_respuesta(" . $formData['idrespuesta'] . "," .
    		$formData['opt1']. "," .
    		$formData['opt2']. "," .
    		$formData['opt3']. "," .
    		$formData['opt4']. "," .
    		$formData['opt5']. "," .
    		$formData['opt6']. "," .
    		$formData['opt7']. "," .
    		$formData['opt8']. "," .
    		$formData['opt9']. "," .
    		$formData['opt10']. "," .
    		$formData['opt11']. "," .
    		$formData['opt12']. "," .
    		$formData['opt13']. "," .
    		$formData['opt14']. "," .
    		$formData['opt15']. "," .
    		$formData['opt16']. "," .
    		$formData['opt17']. "," .
    		$formData['opt18']. "," .
    		$formData['opt19']. "," .
    		$formData['opt20']. ")");
    	// return redirect()->route('respuestas/establecimientos_detalle', [$formData['idestablec']]);
    	return redirect('respuestas/establecimientos_detalle/' . $formData['idestablec'] );
    }



}
