<?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>');
$ds = DIRECTORY_SEPARATOR;
require_once "classes{$ds}formfield.php";
 
 /**
 * Html form input
 *
 * @package Showkase
 */
class RadioField extends FormField
{
  
 /**
  * @var array options
  */
  private $options = array();
  
 /**
  * @var array values
  */
  private $values = array();
  
 /**
  * constructor
  */
  public function __construct($iniVars)
  {
    parent::__construct($iniVars);
    if (isset($iniVars['options'])) $this->options = $iniVars['options'];
    if (isset($iniVars['values'])) $this->values = $iniVars['values'];
  }
  
 /**
  * Set values array
  * $param array
  */
  public function setValues($values)
  {
    if (is_array($values)) $this->values = $values;
  }
  
 /**
  * Set options array
  * $param array
  */
  public function setOptions($options)
  {
    if (is_array($options)) $this->options = $options;
  }
  
 /**
  * Overrides parent method
  *
  * @return string
  */
  public function getLabel()
  {
      return '<label class="'.$this->labelClass.'" title="'.$this->tooltip.'">'.$this->label.$this->balloon.'</label>';
  }
  
 /**
  * Formats html string
  * Used outside the print/echo context
  *
  * @return string
  */
  public function getHtml(&$tab)
  {
    $tab++;
    $html = '
<div class="control-group">
  '.$this->getLabel().'
  <div class="input">';
    foreach ($this->values as $key=>$value)
    {
      $id = str_replace(' ', '-', $this->id.'-'.strtolower($this->options[$key]));
      $checkString = (strtolower($this->value) == strtolower($value)) ? 'checked = "checked"' : '';
      $html .=  '
      <input type="radio" class="radio" name="'.$this->name.'" value="'.$value.'" id="'.$id.'" tabindex="'.$tab.'" '.$checkString.' /><label for="'.$id.'" class="radio">'.$this->options[$key].'</label>';
      $tab++;
    }
    $html .= '
  </div>
</div>';
    return $html;
  }
}