<?php 
class Application_Model_Form_ArticleSearch extends MyWeb_Form
{

    public function init()
    {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        ZendX_JQuery::enableForm($this);	// zapnuti jQuery
        $getValue = $request->getParams();
        $translate = Zend_Registry::get('Zend_Translate');
        
        // nastaví atributy formuláře
        $this->setAction("search");
        $this->setMethod("post");
        $this->setAttrib("id", "form_article_search");
        
        //nacteni config souboru s definovan7mi fomularovymi prvky
        $config = new Zend_Config_Ini(APPLICATION_PATH . "/forms/articleSearch.ini");
        $this->setConfig($config);
        
        
        //***************************************************************************
        $article_dateTime = new ZendX_JQuery_Form_Element_DatePicker("article_dateTime",''
        						,array('defaultDate' => date('Y/m/d',time())));
        $article_dateTime->setLabel($translate->translate('Date'));
        $article_dateTime->setAttrib('size', '10');
        //***************************************************************************
        
        //***************************************************************************
        $link = '<a href = "'."javascript:load1()".'">'.$translate->translate('Username').'</a>';
        $element = $this->getElement('User_id_userValue');
        $element->setLabel($translate->translate('Username'));
        $element->setDescription( $link );
        $element->setDecorators(	array('ViewHelper',array('Description', array('escape' => false, 'tag' => false)),
        array('HtmlTag', array('tag' => 'dd')),
        array('Label', array('tag' => 'dt')),
        'Errors')); 
        
        //*** vytvoreni hidden poli pro jmeno hodnoty a hodnotu
        $User_id_userInputName = new Zend_Form_Element_Hidden('User_id_userInputName');
        $User_id_userInputName->setValue(NULL);
        //$User_id_userInputName->setLabel('User_id_userInputName');
        $User_id_userInputValue = new Zend_Form_Element_Hidden('User_id_userInputValue');
        $User_id_userInputValue->setValue(NULL);
        //$User_id_userInputValue->setLabel('User_id_userInputValue');
        
        $user_userNameInputName = new Zend_Form_Element_Hidden('user_userNameInputName');
        $user_userNameInputName->setValue(NULL);
        //$user_userNameInputName->setLabel('user_userNameInputName');
        $user_userNameInputValue = new Zend_Form_Element_Hidden('user_userNameInputValue');
        $user_userNameInputValue->setValue(NULL);
        //$user_userNameInputValue->setLabel('user_userNameInputValue');
        
        //***************************************************************************
        $link = '<a href = "'."javascript:load0()".'">'.$translate->translate('State').'</a>';
        $element = $this->getElement('State_id_stateValue');
        $element->setLabel($translate->translate('State'));
        $element->setDescription( $link );
        $element->setDecorators(	array('ViewHelper',array('Description', array('escape' => false, 'tag' => false)),
        array('HtmlTag', array('tag' => 'dd')),
        array('Label', array('tag' => 'dt')),
        'Errors')); 
        
        //*** vytvoreni hidden poli pro jmeno hodnoty a hodnotu
        $State_id_stateInputName = new Zend_Form_Element_Hidden('State_id_stateInputName');
        $State_id_stateInputName->setValue(NULL);
        //$State_id_stateInputName->setLabel('State_id_stateInputName');
        $State_id_stateInputValue = new Zend_Form_Element_Hidden('State_id_stateInputValue');
        $State_id_stateInputValue->setValue(NULL);
        //$State_id_stateInputValue->setLabel('State_id_stateInputValue');
        
        $nameState_nameInputName = new Zend_Form_Element_Hidden('nameState_nameInputName');
        $nameState_nameInputName->setValue(NULL);
        //$nameState_nameInputName->setLabel('nameState_nameInputName');
        $nameState_nameInputValue = new Zend_Form_Element_Hidden('nameState_nameInputValue');
        $nameState_nameInputValue->setValue(NULL);
        //$nameState_nameInputValue->setLabel('nameState_nameInputValue');
        
        // vytvoří formulářový prvek odesílací tlačítko
        $submitInsert = new Zend_Form_Element_Submit("send", array("label" => $translate->translate('Search')));
        
        // přidá formulářové prvky do formuláře
        $this->addElements(array($article_dateTime));
        $this->addDisplayGroup(array(
        								'article_dateTime',
        								'User_id_userValue',
        								'State_id_stateValue',
        
        								'User_id_userInputName',
        								'User_id_userInputValue',
        
        								'user_userNameInputValue',
        								'user_userNameInputName',
        
        								'nameState_nameInputValue',
        								'nameState_nameInputName',
        
        								'State_id_stateInputName',
        								'State_id_stateInputValue'
        							),'formRoleEdit',array('legend' => $translate->translate('SearchArticle')));
        $this->addElements(array(	$submitInsert,
        							$User_id_userInputName,
        							$User_id_userInputValue,
        
        							$user_userNameInputValue,
        							$user_userNameInputName,
        
        							$nameState_nameInputValue,
        							$nameState_nameInputName,
        
        							$State_id_stateInputName,
        							$State_id_stateInputValue
        				));
        				
        				
    	// KONTROLA OPRAVNENI
    	if (Zend_Auth::getInstance()->hasIdentity()){
        	$acl = MyWeb_Acl::getInstance();
        	if (!$acl->isAllowed(Zend_Auth::getInstance()->getIdentity()->role_role,'state','list2')){
        		$this->getElement('State_id_stateValue')->setDescription('');}
    		if (!$acl->isAllowed(Zend_Auth::getInstance()->getIdentity()->role_role,'user','list2')){
        		$this->getElement('User_id_userValue')->setDescription('');}
        }else {
        	// pokud nema identitu je automaticky guest
        	$this->getElement('State_id_stateValue')->setDescription('');
        	$this->getElement('User_id_userValue')->setDescription('');
        }
        				
    }
}
