<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
    	MyWeb_Log_ApplicationLogger::addLog($this,1,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'LOG2');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
            
        /* Initialize action controller here */
    	$request = Zend_Controller_Front::getInstance()->getRequest();
    	$uri = $request->getRequestUri();
    	$activeNav = $this->view->navigation()->findByUri($uri);
		$activeNav->active = true;
		//$activeNav->setClass("active");
		
		
    	
    	
    	
   /* try {
        		$zprava = $uri;
        		throw new Exception($zprava); 
        	}
        	
        	catch (Exception $e) {        
        		echo 'Index kontroller:'. $e->getMessage();    
        	}*/
        
    	//echo MyWeb_Log_ApplicationLogger::addLog($this,1,1);
    	//$modelTabledatabase = MyWeb_Model_Database::loadModel('Tabledatabase');
        // načítá tabulky database
        //$listTabledatabase = $modelTabledatabase->fetchEntry(1);
        // předá údaje pohledu
        //$this->view->listTabledatabase = $listTabledatabase;
        
        //$form = $modelTabledatabase->getForm();
        // vlastn9 action helper
        //$form=$this->_helper->viewRenderer('Tabledatabase');
        //$this->view->form=$form;
    }

    public function indexAction()
    {
    	MyWeb_Log_ApplicationLogger::addLog($this,2,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'LOG2');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        
        $modelRole = MyWeb_Model_Database::loadModel('UserHasRole');
        $primaryKeyMN = $modelRole->getStorage()->info('primary');
        echo $primaryKeyMN[1];
    }

    
    public function sidebarAction()
    {
    	
    	MyWeb_Log_ApplicationLogger::addLog($this,3,4);
        MyWeb_plugin::showMe(MyWeb_Log_ApplicationLogger::showLog(),'LOG2');
        
        // kontrola opravneni
        $authentication = new MyWeb_Controller_Plugin_Authentication();
        $authentication->dispatchLoopStartup($this->_request);
        
        // action body
        // otestuje, zda byla akce zadĂˇna v prohlĂ­ĹľeÄŤi
        if ($this->getRequest()->getParam('action') == 'sidebar') {
            $this->_redirect('/');
        }
        
        // nastavĂ­ response segment
        $this->_helper->viewRenderer->setResponseSegment('sidebar');
        
        $modelArticleHasSubject = MyWeb_Model_Database::loadModel('article');
        $modelUser = MyWeb_Model_Database::loadModel('user');
        
        $sidebarMenu = NULL;
        
        if (Zend_Auth::getInstance()->hasIdentity()){
        	$userForm = $modelUser->getForm('logout');
        	//echo "<p>"."logout"."</p>";
        }else {
        	//echo "<p>"."login"."</p>";
        	$userForm = $modelUser->getForm('login');
        	if ($this->getRequest()->isPost() && false !== $this->getRequest()->getPost('submit_login',false)){
        		$userForm->isValid($this->getRequest()->getPost());
        	}
        }
        
        $this->view->sidebarMenu = $sidebarMenu;
        $this->view->userForm = $userForm;
        
    }
}