<?php

use Website\Controller\Action;
use Website\Model\Agency;

class PublicController extends Action {

    public function informationAction(){
        $this->enableLayout();
        $this->setLayout('empty');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/information.css');
        $this->view->headScript()->appendFile('/pimcore/static/js/lib/ckeditor/ckeditor.js');

    }

    public function resultsAction () {
        if (! $this->view->editmode) {
            $this->enableLayout()->setLayout('searchlight');
            $this->view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js');
            $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');
            $this->view->headLink()->appendStylesheet('/website/views/layouts/css/results.css');
        }
        $name = $this->getParam('n' , '');
        $location = $this->getParam('l' , '');
        $page = $this->getParam('p' , 1);

        $q = array();
        if(!empty($name))$q['name']=$name;
        if(!empty($location))$q['location']=$location;

        if(\Website\Tool\RealAdvice::isFromBelgium()) $q['country']="Belgique";
        if(\Website\Tool\RealAdvice::isFromFrance()) $q['country']="France";

        $this->view->results = Agency::search($q, $page);

        $this->view->count = Agency::searchCount($q);

        $this->view->page=$page;
        $this->view->name=$name;
        $this->view->loc=$location;

    }

    public function oldDetailAction () {
        if (! $this->view->editmode) {
            $this->enableLayout()->setLayout('searchlight');;
            $this->view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js');
            $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');
            $this->view->headLink()->appendStylesheet('/website/views/layouts/css/results.css');


            $uid = $this->getParam('uid');

        }else{
            $uid = '55f052b2a4998506453109';
        }

        $a = Agency::getByUid($uid);
        $a->incrementView();
        $this->view->agency = $a;

    }

    public function searchAction () {
        if (! $this->view->editmode){
            $this->enableLayout();
            $this->view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js');
        }


        $this->view->name = $_GET['n'];
        $this->view->location = $_GET['l'];

    }

    public function homeAction(){
        $this->enableLayout();
        $this->setLayout('public');
    }

    public function servicesAction(){
        $this->enableLayout();
        $this->setLayout('public');
    }

    public function detailAction(){
        $this->enableLayout();

        if($this->getParam('showHeader'))
            $this->setLayout('searchlight');
        else{
            $this->setLayout('empty');
            $this->view->headLink()->appendStylesheet('/website/views/layouts/css/style.css');
        }



        if(!$this->editmode) $this->view->headLink()->appendStylesheet('/website/views/layouts/css/comments.css');
        $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');

        if(!$this->view->editmode){
            $uid = $this->getParam('uid');
            $agency = Agency::getByUid($uid);
            $this->view->agency = $agency;
        }

    }

    public function detailCommentAction()
    {
        
    }

    public function cguAction(){
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/account.css');




        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
    }

    public function users2Action(){
        $this->enableLayout()->setLayout('clean');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');
    }


    public function agences2Action(){
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');

        $this->view->displaySearchForm = false;
        $this->view->displayLastComments = false;
    }

    public function simplepageAction(){
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');
    }

    public function services2Action()
    {
        $this->enableLayout()->setLayout('clean');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');


    }

    public function pricingAction(){
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/pimcore/static/css/fontello.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');
    }

    public function freemiumSubscribeAction()
    {
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/picedit.min.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/account.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');
        $this->view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/picedit.min.js');
        $this->view->headScript()->appendFile('/pimcore/static/js/lib/ckeditor/ckeditor.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');

        $this->view->subType = $this->getParam('sub');

        if($this->_request->isPost()){
            $body ='';

            foreach($_POST as $n => $v)
                $body .= $n . ' : <textarea>' . $v . '</textarea><br>';

            $subject = '/!\ Important : Demande Accès Freemium';
            $recipients = array('info@realadvice.be');

            $mail = Pimcore\Tool::getMail($recipients, $subject);


            $mail->setBodyHtml($body);
            $mail->send();



            $this->redirect('/'. $this->view->lang .'/get-free/free-subscribe/merci');
        }
    }

    public function startFreemiumAction()
    {
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/account.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');

        $this->view->headScript()->appendFile('https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');

        if($this->_request->isPost()){
            $body ='';

            foreach($_POST as $n => $v)
                $body .= $n . ' : <textarea>' . $v . '</textarea><br>';

            $subject = '/!\ Important : Demande Accès Freemium';
            $recipients = array('info@realadvice.be');

            $mail = Pimcore\Tool::getMail($recipients, $subject);

            $mail->setBodyHtml($body);
            $mail->send();

            $this->redirect($this->document->getFullPath() . '/merci');
        }
    }

    public function notConvincedAction(){
        $this->enableLayout()->setLayout('clean2');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/account.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/slick-theme.css');


        $this->view->headScript()->appendFile('//code.jquery.com/jquery-1.11.0.min.js');
        $this->view->headScript()->appendFile('/website/views/layouts/js/slick.min.js');
    }



    public function simpleFullPageAction(){
        $this->enableLayout()->setLayout('full');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/clean.css');
        $this->view->headLink()->appendStylesheet('/website/views/layouts/css/full.css');
    }
}
