<?php 
class stateController extends Zend_Controller_Action
{

    public function init()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,1,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateController');
        
        // 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(),'StateController');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
    }

    public function listAction()
    {
    	try {
        	MyWeb_Log_ApplicationLogger::addLog($this,3,4);
        	MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateController');
        
        	// kontrola opravneni
        	$authentication = new MyWeb_Controller_Plugin_Authentication();
        	$authentication->dispatchLoopStartup($this->_request);
        
        	$modelState = MyWeb_Model_Database::loadModel('State');
    		$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelState);
        	$paginator->setData($this->getRequest()->getParams());
        	$paginator->setRequest($this->getRequest());
        	
        	$this->view->select = $modelState->createFetchEntrySelect($this->getRequest()->getParams());
        	$this->view->pager = $paginator->getPaginator();
    	}catch (Exception $e){
    		echo $e->getMessage();
		}
    }

    public function list2Action()
    {
    	try {
        	MyWeb_Log_ApplicationLogger::addLog($this,3,4);
        	MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'StateController');
        	
        	// kontrola opravneni
        	$authentication = new MyWeb_Controller_Plugin_Authentication();
        	$authentication->dispatchLoopStartup($this->_request);
        	
        	$modelState = MyWeb_Model_Database::loadModel('State');
        	
    		$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelState);
        	$paginator->setData($this->getRequest()->getParams());
        	$paginator->setRequest($this->getRequest());
        	
        	$this->view->select = $modelState->createFetchEntrySelect($this->getRequest()->getParams());
        	$this->view->pager = $paginator->getPaginator();
    	
        
        	//********** Nastaveni javascriptu pro popup window ***********************
        	$jsPopupSlave = MyWeb_JavaScript_Popup_Abstract::createJsPopupSlave();
        	$jsPopupSlave->setIdInput('in');
        	$jsPopupSlave->addIdHidden('inid');
        	$jsPopupSlave->addIdHidden('inid');
        	$jsPopupSlave->addIdHidden('inid');
        	$jsPopupSlave->addIdHidden('inid');
        	$jsPopupSlave->setIdLink('button');
        	$js=$jsPopupSlave->js();
        
        	$jsPopupSlave->setNameFile('slaveList2');
        	$jsPopupSlave->writeFileJs();
        
        	$this->view->javascriptPopupSlave = $js;
        	$this->view->paginator = $paginator;
    	}catch (Exception $e){
    		echo $e->getMessage();
		}
    }

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

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

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


}
