<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2012, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
 /**
 * Html form input
 *
 * @package Showkase
 */
abstract class FormField
{
    /**
     * @var boolean show in customize screen
     */
    protected $exposed;
    
    /**
     * @var string accordion section
     */
    protected $section = 'Default section';
    
    /**
     * @var string type of field
     */
    protected $type = 'text';
    
    /**
     * @var string html id
     */
    protected $id;
    
    /**
     * @var string html class
     */
     protected $class = '';
    
    /**
     * @var string html label
     */
    protected $label = '';
    
    /**
     * @var string html label class
     */
    protected $labelClass = '';
    
    /**
     * @var string title attribute for label tag
     */
    protected $tooltip = '';
    
    /**
     * @var string speech balloon image for tooltip
     */
    protected $balloon = '';
    
    /**
     * @var string html name
     */
    protected $name;
    
    /**
     * @var string html value
     */
    protected $value = '';
    
    /**
     * @var instance of site singleton
     */
    protected $site;
  
  
    /**
     * Constructor
     *
     * @param array with same structure as an ini file entry
     */
    public function __construct(array $iniVars)
    {
        $this->exposed = isset($iniVars['exposed']) && (strtolower($iniVars['exposed']) == 'true');
        if (isset($iniVars['section'])) $this->section = $iniVars['section'];
        if (isset($iniVars['type'])) $this->type = $iniVars['type'];
        if (isset($iniVars['class'])) $this->class = $iniVars['class'];
        if (isset($iniVars['label'])) {
            $this->label = $iniVars['label'];
            $this->labelClass = $this->class;
        }
        if (isset($iniVars['tooltip'])) {
            $this->tooltip = $iniVars['tooltip'];
            $this->labelClass = $this->class.' tipper';
            $this->balloon = ' <img src="img/comment.png" alt="tooltip icon">';
        }
        if (isset($iniVars['value'])) $this->value = $iniVars['value'];
        if (!isset ($iniVars['name'])) throw new Exception('missing field name in theme ini file');
        $this->name = $iniVars['name'];
        $this->id = 'form-'.strtolower($this->name);
    }
    
    /**
     * return html for form element and update tabbing order
     *
     * @param integer tabbing order
     */
    abstract function getHtml(&$tab);
    
    /**
     * Returns html label string
     * @access public
     * @return string
     */
    public function getLabel()
    {
        return '<label for="'.$this->id.'" class="'.$this->labelClass.'" title="'.$this->tooltip.'">'.$this->label.$this->balloon.'</label>';
    }
    
    /**
     * Returns value attribute of field
     * @return string
     */
    public function getValue()
    {
        return $this->value;
    }
    
    /**
     * Set value attribute of field
     * @return void
     * @param string
     */
    public function setValue($value)
    {
        $this->value = $value;
    }
    
    /**
     * Get field type
     *
     * @return string
     */
    public function type()
    {
        return $this->type;
    }
    
    /**
     * Field is to be exposed in customize forms
     *
     * @return boolean
     */
    public function exposed()
    {
        return $this->exposed;
    }
    
    /**
     * Return form section
     *
     * @return string
     */
    public function getSection()
    {
        return $this->section;
    }
    
    /**
     * Return html class
     *
     * @return string
     */
    public function getClass()
    {
        return $this->class;
    }
      
}