<?php 
class table3Controller extends Zend_Controller_Action
{

    public function init()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,1,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'Table3Controller');
        
        // 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(),'Table3Controller');
        
        // 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(),'Table3Controller');
        
        	// kontrola opravneni
        	//$authentication = new MyWeb_Controller_Plugin_Authentication();
        	//$authentication->dispatchLoopStartup($this->_request);
        
        	$modelTable3 = MyWeb_Model_Database::loadModel('Table3');
        
        	$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelTable3);
        	$paginator->setData($this->getRequest()->getParams());
        	$paginator->setRequest($this->getRequest());
        
        	$this->view->select = $modelTable3->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(),'Table3Controller');
        
        	// kontrola opravneni
        	//$authentication = new MyWeb_Controller_Plugin_Authentication();
        	//$authentication->dispatchLoopStartup($this->_request);
        
        	$modelTable3 = MyWeb_Model_Database::loadModel('Table3');
        	$form = $modelTable3->getForm('search');
        
        	$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelTable3);
        	$paginator->setData($this->getRequest()->getParams());
        	$paginator->setRequest($this->getRequest());
        
        	//********** 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->select = $modelTable3->createFetchEntrySelect($this->getRequest()->getParams());
        	$this->view->pager = $paginator->getPaginator();
        }catch (Exception $e){
        	echo $e->getMessage();
        }
    }

    public function editAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,4,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'Table3Controller');
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $id_table3 = $this->getRequest()->getParam('id_table3');
        $modelTable3 = MyWeb_Model_Database::loadModel('Table3');
        $form = $modelTable3->getForm('update');
        $dataTable3 = $modelTable3->fetchEntry($id_table3);
        $dataTable3Db = $dataTable3['data'];
        $dataTable3Form = $this->getRequest()->getParams();
        
        
        $id_table3_db = $dataTable3['data']['id_table3'];
        $form->setAction('');
        
        if ($this->getRequest()->isPost() && 
        	((false !== $this->getRequest()->getPost('send',false)) || (false !== $this->getRequest()->getPost('delete',false)))){
        	if ($form->isValid($this->getRequest()->getPost())){
        		if ($this->getRequest()->isPost() && false !== $this->getRequest()->getPost('delete',false)){
        			// state disabled or enabled
        			$modelTable3->update($dataTable3Form, $id_table3_db);
        			$this->_redirect('/table3/list/');
        		}
        		if ($this->getRequest()->isPost() && false !== $this->getRequest()->getPost('send',false)){
        			$modelTable3->update($dataTable3Form, $id_table3_db);
        			//$this->_redirect(\ id_table3_db);
        		}
        	}
        	}else {
        		$form->populate($dataTable3Db);
        	}
        
        $this->view->jsOpenLinks = $jsOpenLinks;
        $this->view->javascriptPopupMain = $js;
        $this->view->form=$form;
    }

    public function searchAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,5,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'Table3Controller');
        
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $modelTable3 = MyWeb_Model_Database::loadModel('Table3');
        $form = $modelTable3->getForm('search');
        
        if ($this->getRequest()->isPost() && (false !== $this->getRequest()->getPost('send',false))){
        	if ($form->isValid($this->getRequest()->getPost())){
        		$searchValue = $form->getValues();
        		$searchValueLink = "";
        		foreach ($searchValue as $key => $value) {
        			$searchValueLink .= $key."/".$value."/";
        		}
        		$this->_redirect('/table3/list/'.$searchValueLink);
        	}
        }
        
        
        //********** Nastaveni javascriptu pro popup window ***********************
        $this->view->jsOpenLinks = $jsOpenLinks;
        $this->view->javascriptPopupMain = $js;
        $this->view->form=$form;
    }

    public function newAction()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,6,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'Table3Controller');
        
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $modelTable3 = MyWeb_Model_Database::loadModel('Table3');
        $form = $modelTable3->getForm('insert');
        $dataTable3Form = $this->getRequest()->getParams();
        
        
        if ($this->getRequest()->isPost() && (false !== $this->getRequest()->getPost('send',false))){
        	if ($form->isValid($this->getRequest()->getPost())){
        		$modelTable3->insert($dataTable3Form);
        		//$this->_redirect(\ id_table3_db);
        	}else {
        		$form->populate($dataTable3Form);// naplni formular pokud se vyskitla chyba
        	}
        }
        //********** Nastaveni javascriptu pro popup window ***********************
        $this->view->jsOpenLinks = $jsOpenLinks;
        $this->view->javascriptPopupMain = $js;
        $this->view->form=$form;
    }


}
