<?php

namespace MGModule\DNSManager2\mgLibs\forms;
use MGModule\DNSManager2 as main;

/**
 * Abstract Form Field
 *
 * @author Michal Czech <michael@modulesgarden.com>
 */
abstract class abstractField {
    public $name;
    public $value;
    public $type;
    public $enableDescription = false;
    public $enableLabel = true;
    public $formName = false;
    public $default;
    public $nameAttr;
    public $addFormNameToFields = false;
    public $dataAttr = array();
    public $readonly = false;
    public $disabled = false;
    public $addIDs = false;
    public $colWidth = 9;
    public $continue = false;
    public $html = '';
    public $additinalClass = false;
    public $opentag;
    public $closetag;
    public $error;
    
    function __construct($params = array()) {  
        foreach($params as $name => $value)
        {
            if(property_exists($this, $name))
            {
                $this->{$name} = $value;
            }
        }
    }
    
    function prepare(){
        ;
    }
    
    function generate(){
        $this->prepare();
        
        if($this->addFormNameToFields && empty($this->nameAttr))
        {
            $this->nameAttr = $this->formName.'_'.$this->name;
        }
        
        if(empty($this->nameAttr))
        {
            $this->nameAttr = $this->name;
        }
        
        if(empty($this->value) && !empty($this->default))
        {
            $this->value = $this->default;
        }
        
        if($this->opentag == false)
        {
            $this->enableLabel = false;
        }
        
        main\mgLibs\lang::stagCurrentContext('generateField');
        
        if($this->type == 'submit')
        {
            main\mgLibs\lang::addToContext($this->value);
        }
        else
        {
            main\mgLibs\lang::addToContext($this->name);
        }
        
        $this->html = main\mgLibs\smarty::I()->view($this->type, (array)$this, main\mgLibs\process\mainInstance::getModuleTemplatesDir().DS.'formFields');
        
        main\mgLibs\lang::unstagContext('generateField');
    }    
}