/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/rgbacolorfield.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";
require_once "classes{$ds}helpers.php";
class RgbaColorField extends FormField
{
    /**
     * Set value
     * Overrides parent method
     *
     * @return void
     * @param value array or string
     */
    public function setValue($value)
    {
        if (is_array($value)) {
            $hex = trim(strtolower($value[0]));
            $hex = ltrim($hex, '#');
            $hex = str_replace('0x', '', $hex);
            $hex =  str_pad(strtoupper(dechex(hexdec(substr(trim($hex), 0, 6)))), 6, '0', STR_PAD_LEFT);
            $rgb = Helpers::hexToRgb($hex);
            $this->value = "rgba({$rgb['red']},{$rgb['green']},{$rgb['blue']},{$value[1]})";
            } else {
            $this->value = $value;
        }
    }
    /**
     * Formats html string
     * Used outside the print/echo context
     *
     * @return string
     */
    public function getHtml(&$tab)
    {
      $tab++;
      $alphaTab = $tab + 1;
      $hexAlpha = Helpers::rgbaToHex($this->value);
      $label = $this->getLabel();
      $alphaId = $this->id.'-alpha';
      $alphaName = $this->name.'Alpha';
      $html = <<<EOD
<div class="control-group">
  {$label}
  <div class="input">
    <input type="text" class="colorpicker" name="{$this->name}" id="{$this->id}" tabindex="{$tab}" value="{$hexAlpha[0]}" />
  </div>
</div>
<div class="control-group">
  <label for="{$alphaId}" class="tipper" title="Range 0-1 (0 = transparent)">Opacity <img src="img/comment.png" alt="tooltip icon"></label>
  <div class="input">
    <input type="text" class="text" name="{$alphaName}" id="{$alphaId}" tabindex="{$alphaTab}" value="{$hexAlpha[1]}">
  </div>
</div>
EOD;
      $tab++;
      return $html;
  }
}