<?php

Goweb::loadClass('Form_GenericController', APPLICATION_PATH);

/**
 * Goweb Sitemanager 5 Framework
 * @version    5.0.0
 * @category   Frontoffice
 * @package    Form
 * @subpackage Controller
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 *
 * A classe _Controller para o Front-Office disponibiliza
 * as accoes referentes a cada Modulo.
 *
 */
class Form_Controller extends Form_GenericController {

	/**
     * Acao executada se nenhuma outra acao for especificada
    */
    public function indexAction() {
        return $this->_forward('view');
    }

	/**
     * Acao para visualizar um determinado formulario
    */
    public function viewPedidoInfoAction()
	{
		$session = Goweb::registry('session');
		$session->banner = $this->_getParam('banner');
        $id = $this->_getParam('id');
		$info = $this->_getParam('info');
		if ($info)
			$this->view->info = $info;
		else
			$this->view->info = '';
        $this->view->form = false;
        if (!$this->_validateId($id) || !$this->_formModel->find($id))
		{
            return false;
        }
        $form = $this->_getForm($id);
        $form->render();
        $this->view->form_id = $id;
        $this->view->form = $form;
        $this->view->model = $this->_getFormModel($id);
        $this->view->error = $this->_error;
        $this->view->message = $this->_message;

        if ($this->_directRequest)
		{ // significa que foi chamado directamente.
            Goweb::loadClass('Cms_Controller', APPLICATION_PATH);
            Cms_Controller::renderOutput($this->view,
                                        'view-pedido-info.tpl',
                                        'Form',
                                        'form-id-' . $this->_formModel->id,
                                        translate(html_entity_decode('Formul&aacute;rio: {{titulo}}', ENT_NOQUOTES, CHARSET), $this->_formModel->titulo));
            $this->_helper->viewRenderer->setRender('base');
        }
		else
		{
            $this->_helper->viewRenderer->setRender('view-pedido-info');
        }
    }
}