<?php


use Twitter\ChangeAvatar as Twitter;
use Tickets\TicketCreator as Ticket;

class RegisterVipUser
{

    public function __construct()
    {
        session_start();
    }

/*    public function registerUser()
    {
        if( !$_POST               ||
            !$_POST['first_name'] ||
            !$_POST['last_name']  ||
            !$_POST['email']      ||
            !$_POST['city']       ||
            !$_POST['address']
        ) {
            return Response::respondError(3);
        }


        $userData = $_POST;

        if($user->register($userData))
            return Response::respondSuccess('User has been created.');
        else
            return Response::respondError('User has been created.');
    }*/

    public function confirmArrival()
    {
        // Check if token exists.
        if(!isset($_POST['data']['token'])) {
            return Response::respondError(4);
        }

        // Check if token is real and exists in the database.
        $user = User::checkToken($_POST['data']['token']);

        if(!$user) {
            return Response::respondError(4);
        }

        $_SESSION['userId'] = $user[0]->id;

        $view    = 'arrivalConfirmation';
        $nanoTpl = new nanoTpl($view);
        $output  = $nanoTpl->output();

        return Response::respondData($output);
    }

    public function updateArrivalStatus()
    {
        // Check if user has answered the question.
        if(!isset($_POST['data']['arrivalStatus'])) {
            return Response::respondError(4);
        }

        // Save users answer
        User::updateArrivalStatus($_POST['data']['arrivalStatus'], $_SESSION['userId']);
        return Response::respondSuccess('Arrival has ben confirmed.');
    }

    public function arrivalDenial()
    {
        $view    = 'arrivalDenial';
        $nanoTpl = new nanoTpl($view);
        $output  = $nanoTpl->output();

        return Response::respondData($output);
    }

    public function chooseTransport()
    {
        $view    = 'chooseTransport';
        $nanoTpl = new nanoTpl($view);
        $output  = $nanoTpl->output();

        return Response::respondData($output);
    }

    public function updateTransport()
    {
        // Check if user has answered the question.
        if(!isset($_POST['data']['transport'])) {
            return Response::respondError(4);
        }

        $transport = $_POST['data']['transport'];

        // Save users answer
        User::updateTransport($transport, $_SESSION['userId']);

        $view    = 'changeAvatar';
        $nanoTpl = new nanoTpl($view);

        $sopstveniPrevoz = '<p class = "transport-text">Prijem svih gostiju se očekuje od 19:00 do 20:00 časova.</p>
                            <p class = "transport-text">Peronalizovana karta će ti biti dostavljena na adresu najkasnije do 22.07.2014.</p>
                            <p class = "transport-text">Dobrodošao/la na Digital Night.</p>';

        $bus             = '<p class = "transport-text">Organizovan je besplatan autobuski prevoz do Club-a RESET.</p>
                            <p class = "transport-text">Autobusi kreću u 18:30 ispred Sava centra.</p>
                            <p class = "transport-text">Dobrodošao/la na Digital Night.</p>';

        $nanoTpl->set('change_avatar_url',Config::get('base_url').'changeavatar/');
        $nanoTpl->set('transport'       ,$transport == 2 ? $sopstveniPrevoz : $bus);

        $output  = $nanoTpl->output();

        return Response::respondData($output);
    }

    public function changeAvatar()
    {
/*        $_SESSION['oauth_verifier'] = $_POST['data']['oauth_verifier'];

        Twitter::getAvatar();
        $avatar = Config::get('base_url').'avatars/'.$_SESSION['screen_name'].'.png';

        $view    = 'confirmChangeAvatar';
        $nanoTpl = new nanoTpl($view);
        $nanoTpl->set('img',$avatar);
        $output  = $nanoTpl->output();

        return Response::respondData($output);*/
    }

    public function postAvatar()
    {
        //return Response::respondData(Twitter::postAvatar());

       /* Ticket::create();

        $nanoTpl = new nanoTpl($view);
        $nanoTpl->set('img',$avatar);
        $output  = $nanoTpl->output();

        return Response::respondData($output);*/
    }


}

