<?php 
class table1hastable2Controller extends Zend_Controller_Action
{

    public function init()
    {
        MyWeb_Log_ApplicationLogger::addLog($this,1,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'Table1hastable2Controller');
        
        // 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(),'Table1hastable2Controller');
        
        // 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(),'Table1hastable2Controller');
        
        	// kontrola opravneni
        	//$authentication = new MyWeb_Controller_Plugin_Authentication();
        	//$authentication->dispatchLoopStartup($this->_request);
        
        	$modelTable1hastable2 = MyWeb_Model_Database::loadModel('Table1hastable2');
        
        	$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelTable1hastable2);
        	$paginator->setData($this->getRequest()->getParams());
        	$paginator->setRequest($this->getRequest());
        
        	$this->view->select = $modelTable1hastable2->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(),'Table1hastable2Controller');
        
        	// kontrola opravneni
        	//$authentication = new MyWeb_Controller_Plugin_Authentication();
        	//$authentication->dispatchLoopStartup($this->_request);
        
        	$modelTable1hastable2 = MyWeb_Model_Database::loadModel('Table1hastable2');
        	$form = $modelTable1hastable2->getForm('search');
        
        	$paginator = new MyWeb_Controller_Plugin_Paginator();
        	$paginator->setModel($modelTable1hastable2);
        	$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 = $modelTable1hastable2->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(),'Table1hastable2Controller');
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $table1_id_table1 = $this->getRequest()->getParam('table1_id_table1');
        $modelTable1hastable2 = MyWeb_Model_Database::loadModel('Table1hastable2');
        $form = $modelTable1hastable2->getForm('update');
        $dataTable1hastable2 = $modelTable1hastable2->fetchEntry($table1_id_table1);
        $dataTable1hastable2Db = $dataTable1hastable2['data'];
        $dataTable1hastable2Form = $this->getRequest()->getParams();
        
        
        $table1_id_table1_db = $dataTable1hastable2['data']['table1_id_table1'];
        $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
        			$modelTable1hastable2->update($dataTable1hastable2Form, $table1_id_table1_db);
        			$this->_redirect('/table1hastable2/list/');
        		}
        		if ($this->getRequest()->isPost() && false !== $this->getRequest()->getPost('send',false)){
        			$modelTable1hastable2->update($dataTable1hastable2Form, $table1_id_table1_db);
        			//$this->_redirect(\ table1_id_table1_db);
        		}
        	}
        	}else {
        		$form->populate($dataTable1hastable2Db);
        	}
        
        $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(),'Table1hastable2Controller');
        
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $modelTable1hastable2 = MyWeb_Model_Database::loadModel('Table1hastable2');
        $form = $modelTable1hastable2->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('/table1hastable2/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(),'Table1hastable2Controller');
        
        // kontrola opravneni
        //$authentication = new MyWeb_Controller_Plugin_Authentication();
        //$authentication->dispatchLoopStartup($this->_request);
        
        $modelTable1hastable2 = MyWeb_Model_Database::loadModel('Table1hastable2');
        $form = $modelTable1hastable2->getForm('insert');
        $dataTable1hastable2Form = $this->getRequest()->getParams();
        
        
        if ($this->getRequest()->isPost() && (false !== $this->getRequest()->getPost('send',false))){
        	if ($form->isValid($this->getRequest()->getPost())){
        		$modelTable1hastable2->insert($dataTable1hastable2Form);
        		//$this->_redirect(\ table1_id_table1_db);
        	}else {
        		$form->populate($dataTable1hastable2Form);// naplni formular pokud se vyskitla chyba
        	}
        }
        //********** Nastaveni javascriptu pro popup window ***********************
        $this->view->jsOpenLinks = $jsOpenLinks;
        $this->view->javascriptPopupMain = $js;
        $this->view->form=$form;
    }


}
