<?php 
class StateHasStateController extends Zend_Controller_Action
{

    public function init()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,1,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
    }

    public function indexAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,2,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
    }

    public function listAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,3,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        $modelStateHasState = MyWeb_Model_Database::loadModel('StateHasState');
        $page = (int) $this->getRequest()->getParam('page',1);
        
        $listStateHasState = $modelStateHasState->fetchEntries(NULL);
        $paginator = Zend_Paginator::factory($listStateHasState);
        
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $this->view->listStateHasState = $listStateHasState;
    }

    public function list2Action()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,3,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        $modelStateHasState = MyWeb_Model_Database::loadModel('StateHasState');
        $form = $modelStateHasState->getForm('search');
        $form->setAction('controller');
        
        $page = (int) $this->getRequest()->getParam('page',1);
        
        $list2StateHasState = $modelStateHasState->fetchEntries($this->getRequest()->getParams());
        $paginator = Zend_Paginator::factory($list2StateHasState);
        
        $paginator->setCurrentPageNumber($page);
        
        $controller = "state";
        $action = "list2";
        $this->view->controller = $controller;
        $this->view->action = $action;
        //id_state, state_state, NameState_id_NameState, TableDatabase_id_tableDatabase
        if ((false !== $this->getRequest()->getParam('sourceController',false)) && (false !== $this->getRequest()->getParam('sourceAction',false))){
        	$controller = $this->getRequest()->getParam('sourceController');
        	$action = $this->getRequest()->getParam('sourceAction');
        	$this->view->controller = $controller;
        	$this->view->action = $action;
        }
        $this->view->paginator = $paginator;
        $this->view->list2StateHasState = $list2StateHasState;
        $this->view->form = $form;
    }

    public function editAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,4,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        $modelStateHasState = MyWeb_Model_Database::loadModel('StateHasState');
        $form = $modelStateHasState->getForm('update');
        
        $this->view->form=$form;
    }

    public function searchAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,5,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        $modelStateHasState = MyWeb_Model_Database::loadModel('StateHasState');
        $form = $modelStateHasState->getForm('search');
        
        $this->view->form=$form;
    }

    public function newAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,6,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateHasStateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        $modelStateHasState = MyWeb_Model_Database::loadModel('StateHasState');
        $form = $modelStateHasState->getForm('insert');
        
        $this->view->form=$form;
    }


}
