<?php
class MyWeb_File_Form_Login extends MyWeb_File_Form_Abstract
{
	private $_addContent;
	
	
	
		protected $_user = 'user';			//user	-	jmeno tridy modelu
		protected $_login = 'login';		//login	-	jmeno formulare
		protected $_submitLogin = 'submit_login';	//submit_login	-	jmeno tlacitka pro prihlaseni
		
		
		
		
	/**
	 * 
	 * Metoda prida retezec do vysledneho souboru
	 * @param $content
	 */
	public function add_contentFile($content)
	{
		$this->_addContent = $content;
	}
	
	private function defaultSettings()
	{
		if (is_null($this->_describeTable)){
			$this->_describeTable = $this->_dbTable->get_describeTable();
		}
	}
	
	
	
	
	public function __construct($dbTable,$path = null)
	{
		$this->_dbTable = $dbTable;
		$this->defaultSettings();
		$this->_path = $path;	//*** pridano zajistuje pouziti nove cesty od uzivatele misto default
		$this->defaultSettingsPath($this->_default_path_form_php);
		$this->set_typeFile('php');
		$this->_currentPrefix = 0;
		if (0 === strcmp($this->_filename, 'none')){
			$this->_filename = $this->_dbTable->get_modelName().ucfirst($this->_login);
		}
	}
	
	
	
	public function createContent()
	{
		
		$methodInit = new Zend_CodeGenerator_Php_Method();
		$methodInit	->setName('init');
		$methodInit->setBody(
			'$request = Zend_Controller_Front::getInstance()->getRequest();'								. "\n" .
			'$translate = Zend_Registry::get(\'Zend_Translate\');'											. "\n" .
																											  "\n" .
			'// nastaví atributy formuláře'																	. "\n" .
			'$this->setAction(\'\');'	. "\n" .
			'$this->setMethod("post");'																		. "\n" .
			'$this->setAttrib("id", "form_'.$this->_dbTable->get_modelName()."_".$this->_login.'");'		. "\n" .
			'//nacteni config souboru s definovan7mi fomularovymi prvky'									. "\n" .
			'$config = new Zend_Config_Ini(APPLICATION_PATH . "/forms/'.
									$this->_dbTable->get_modelName().ucfirst($this->_login).'.ini");'		. "\n" .
			'$this->setConfig($config);'																	. "\n" .
																											  "\n" .
			'//***************************************************************************'					. "\n" .
			'$element = $this->getElement(\'user_userName\');'												. "\n" .
			'$element->setLabel($translate->translate(\'Username\'));'										. "\n" .
			'//***************************************************************************'					. "\n" .
			'$element = $this->getElement(\'user_passwd\');'												. "\n" .
			'$element->setLabel($translate->translate(\'Password\'));'										. "\n" .
			'//***************************************************************************'					. "\n" .
																											  "\n" .
			'// vytvoří formulářový prvek odesílací tlačítko'												. "\n" .
			'$submit'.ucfirst($this->_submitLogin).' = 
												new Zend_Form_Element_Submit(
																	"'.$this->_submitLogin.'",
																	array("label" => "'.$this->_submitLogin .
														'"));'												. "\n" .
			'// přidá formulářové prvky do formuláře'														. "\n" .
			'$this->addElements(array($submit'.ucfirst($this->_submitLogin).'));'							. "\n"
		);
		
		
		$class = new Zend_CodeGenerator_Php_Class();
		$class	->setName('Application_Model_Form_'.ucfirst($this->_dbTable->get_modelName()).ucfirst($this->_login).' extends MyWeb_Form')
				->setMethod($methodInit);
					
		$stringFile = "<?php \n ".$class;
		$this->set_contentFile($stringFile);
	}
}