/**
* Generates a new Row Color
* <code>
* Usage:
* $html = new Rowcolor($count++,,$light,$dark);
* print $html->getHtml();
* Or
* $rowcolor = Rowcolor::get($count++,$light,$dark);
* Or
* $imgcolor = Rowcolor::img($color);
* </code>
* @package basic
*/
class Rowcolor {
/**
* @var int $count The row counter
*/
var $count = 0;
/**
* @var String $light The light row
*/
var $light = 0;
/**
* @var String $dark The dark row
*/
var $dark = 0;
/**
* Constructor
* @param int $count The next row
* @param String $light The light row
* @param String $dark The dark row
*/
function Rowcolor($count,$light='',$dark='') {
$this->count = $count;
$this->light = $light!=''?$light:CSS_COLOR_LIGHT;
$this->dark = $dark !=''?$dark :CSS_COLOR_DARK;
}
/**
* Get the complete html for a Row Color
* @see CSS_COLOR_LIGHT The css color Light
* @see CSS_COLOR_DARK The css color Dark
* @return String the html
*/
function getHtml() {
return $this->count%2?$this->light:$this->dark;
}
/**
* Returns 6 digits css color code from the supplied 3 digits hex color
* The color is hex I.e. 1F3 => 11FF34 (where the last color digit is counted one up)
* This function ia a bugfix for xhtml 1.0 strict compliant validator
* where <img border="0" ... /> is not allowed, however we must have it
* <code>
* Usage:
* $imgcolor = Rowcolor::img($color);
* </code>
* @static
* @param int $hexcolor The css hex color, i.e. a2b
* @return String the img css color (6 digits) i.e. 'aa22bc' (c=b+1)
*/
function img($hexcolor) {
$html = '';
$len = strlen($hexcolor);
if ($len!=3) {
//die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color MUST be 3 digits, like 2fc, found length='.$len.' in $hexcolor='.$hexcolor);
}
for ($i=0;$i<$len;$i++) {
$digit = hexdec(substr($hexcolor,$i,1));
if (!is_numeric($digit)) {
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color is not a numeric, found $digit='.$digit.' in $hexcolor='.$hexcolor);
}
switch ($i) {
case 0:
case 1:
$html .= ''.dechex($digit).dechex($digit);
break;
case 4:
case 3:
case 2:
$html .= ''.dechex($digit);
if ($digit+1>0xF) {
$html .= dechex($digit-1);
} else {
$html .= dechex($digit+1);
}
break;
default:
//die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".', Rowcolor::img($hexcolor), Should never end up here!');
break;
}
}
return $html;
}
/**
* Get the rowcolor for the odd/even count
* <code>
* Usage:
* Rowcolor::get($count++,$light,$dark);
* </code>
* @static
* @param int $count The next row
* @param String $light The light row
* @param String $dark The dark row
* @return String the html
*/
function get($count,$light='',$dark='') {
$html = new Rowcolor($count,$light,$dark);
return $html->getHtml();
}
}
?>