/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/selectfield.php
<?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 SelectField extends FormField
{

 /**
  * @var array options
  */
  private $options = array();
  
 /**
  * @var array values
  */
  private $values = array();
  
 /**
  * constructor
  */
  public function __construct(array $iniVars)
  {
    parent::__construct($iniVars);
    if (isset($iniVars['values'])) $this->values = $iniVars['values'];
    if (
        isset($iniVars['options'])
        && count($iniVars['options']) == count($iniVars['values'])
    ) {
        $this->options = $iniVars['options'];
    }
    else {
        foreach ($iniVars['values'] as $key => $value) {
            $this->options[$key] = ucfirst(strtolower(str_replace('_', ' ', $value)));
        }
    }
  }
  
 /**
  * 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;
  }
  
 /**
  * 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">
    <select name="'.$this->name.'" id="'.$this->id.'" tabindex="'.$tab.'">';
      foreach ($this->options as $key=>$option)
      {
        if (!isset($this->values[$key])) {
            Board::addMessage('Mismatched ini file values and options for '.$this->name);
            continue;
        }
        $selectString = $this->values[$key] == $this->value
            ? 'selected="selected"'
            : '';
        $html .= '<option value="'.$this->values[$key].'" '.$selectString.'>'.htmlspecialchars($option, ENT_QUOTES, 'UTF-8').'</option>';
      }
      $html .= '
    </select>
  </div>
</div>'; 
    return $html;
  }
}