<?php
class ErrorController extends Zend_Controller_Action
{
    /** 
     * Initialization
     */
    public function init()
    {
		$this->_helper->layout->setLayout('plain');
        $this->_redirector = $this->_helper->getHelper('Redirector');

        // disable client-side caching rules
        $this->view->headMeta()->appendHttpEquiv('expires', 'Wed, 26 Feb 1997 08:21:57 GMT')
                         ->appendHttpEquiv('pragma', 'no-cache')
                         ->appendHttpEquiv('Cache-Control', 'no-cache');

        // setting content type and character set
        $this->view->headMeta()->appendHttpEquiv('Content-Type','text/html; charset=UTF-8')
                         ->appendHttpEquiv('Content-Language', 'en-US');                         

        // set favicon
        $this->view->headLink()->headLink(array('rel' => 'favicon','href' => 'favicon.ico'),'PREPEND');

        // set other meta                         
        $this->view->headMeta()->appendName('keywords', 'Wyndham Vacation Resorts Asia Pacific')
            ->appendName('description', 'Wyndham Vacation Resorts Asia Pacific')
            ->appendName('keyphrases', 'Wyndham Vacation Resorts Asia Pacific')
            ->appendName('robots', 'index, follow')
            ->appendName('googlebot', 'index, follow');


		$this->session = Zend_Registry::get('defSession');
    }

    public function errorAction()
    {
        // don't show error 
        #$this->_redirect('/home/index');
        #exit;
        
        // show errors
        $errors = $this->_getParam('error_handler');

        switch ($errors->type) {

            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:

            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                #$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Page not found';
				
                $mailConfig = Zend_Registry::get('configuration')->Mail;
				$notifier = new Notifier($mailConfig);
                #$notifier->send($errors);				

                break;

            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';

                $mailConfig = Zend_Registry::get('configuration')->Mail;
				$notifier = new Notifier($mailConfig);
                #$notifier->send($errors);				

                break;
        }

        $this->view->env       = $this->getInvokeArg('env');
        $this->view->exception = $errors->exception;
        $this->view->request   = $errors->request;
    }
	
}