<?php namespace App\Modules\Frontend\Principal\Controllers;

use Auth, Input, Redirect, View, DB, Datatables, Validator, Innfile, Hash, Alert, Acl, App, Mail, PDF;
use App\Modules\Backend\Hotels\Models\Hotel;
use App\Modules\Backend\Hotels\Models\Room;
use App\Modules\Backend\Articles\Models\Article;
use App\Modules\Backend\Categories\Models\Category;
use App\Modules\Frontend\Principal\Models\Configuration;
use App\Modules\Frontend\Principal\Models\Record;
use Carbon\Carbon;


class PrincipalController extends \BaseController {

	public function __construct() {
		App::setLocale('es');
    }

    public function showIndex()
    {
        View::share('active_menu', 'home');
        $url_home = '';
        return View::make('principal::index', compact('url_home'));
    }

    public function news()
    {
        View::share('active_menu', 'blog');
        $news = Article::news()->paginate();
        $url_home = route('home');
        return View::make('principal::news', compact('news', 'url_home'));
    }

    public function showNew($id, $hash)
    {
        View::share('active_menu', 'blog');
        $new = Article::findOrFail($id);
        $gallery = $new->gallery;
        $url_home = route('home');
        return View::make('principal::new', compact('new', 'gallery', 'url_home'));
    }

    public function postContact()
    {
        View::share('active_menu', 'contact');

        
        $data   = Input::only('name', 'email', 'phone', 'c_message', 'age', 'time', 'first_date');
        $email  = Input::get('email');

        Mail::send(['principal::html_email', 'principal::text_email'], $data, function($message) use ($email)
        {
            $message->from('contacto@cecom.com.mx', 'CECOM')->subject('Contacto - CECOM.com.mx');;
            $message->from('administracion@cecom.com.mx', 'CECOM')->subject('Contacto - CECOM.com.mx');;
            $message->to($email);
        });



        Mail::send(['principal::html_email', 'principal::text_email'], $data, function($message) use ($email)
        {
            $message->from('contacto@cecom.com.mx', 'CECOM');
            //$message->to('gustavodiaz@strategics.com.mx');
            //$message->to('gustavodiaz@strategics.com.mx');
            $message->to('administracion@cecom.com.mx')->subject('Contacto - CECOM.com.mx');;
        });
        $url_home = '';

        return View::make('principal::index', ['enviado' => true, 'url_home' => '']);
    }
}