<?php
/***********************************************************
* Class: VSFlexGridXP *
* Version: 1.1 *
* Date: September 2004 *
* Author: Agus Hariyanto *
* Copyright: © Agus H *
* Licence : Free for non-commercial use *
* email : hide@address.com *
************************************************************/
class VSFlexGridXP
{
public $FixedRow=1;
public $ColorBackgroundHead="#CC6600";
public $ColorbackgroundData="#EEEECC";
public $ColorFontHead="Black";
public $ColorFontData="Black";
public $Border=0;
public $CellSpacing=1;
public $BorderColor="Red";
public $TableWidth="100%";
private $_recordcount=0;
private $_cols;
private $_rows;
private $_header;
private $_colhidden;
private $_fixed_alignment;
private $_col_aligment;
private $_data_array;
private $_data;
private $_hideplace;
private $_hide;
private $_hidemove;
private $_colhide;
private $_colmove;
private $_typecolbool;
private $_typecolbutton;
private $_typecoltext;
private $_buttontext;
function __construct()
{
$this->_fixed_alignment=array();
$this->_col_alignment=array();
$this->_data_array=array();
$this->_colhidden=array();
$this->_cols=1;
$this->_hideplace=array();
$this->_typecolbool='-1';
$this->_typecolbutton='-1';
$this->_typecoltext='-1';
}
public function Cols($cols)
{
for ($x=0;$x<$cols;$x++)
{
$this->_fixed_alignment[$x]='left';
$this->_col_alignment[$x]='left';
$this->_colhidden[$x]='0';
}
$this->_cols=$cols;
}
public function FixedAlignment($alignment,$col)
{
switch ($alignment)
{
case "C":
$this->_fixed_alignment[$col]='center';
break;
case "L":
$this->_fixed_alignment[$col]='left';
break;
case "R":
$this->_fixed_alignment[$col]='right';
break;
case "J":
$this->_fixed_alignment[$col]='justify';
break;
}
}
public function ColAlignment($alignment,$col)
{
switch ($alignment)
{
case "C":
$this->_col_alignment[$col]='center';
break;
case "L":
$this->_col_alignment[$col]='left';
break;
case "R":
$this->_col_alignment[$col]='right';
break;
case "J":
$this->_col_alignment[$col]='justify';
break;
}
}
public function TextMatrix($rs,$row,$col)
{
$this->_data_array[$row][$col]=strval($rs);
$this->_rows=$row;
$this->_recordcount=$row+1;
}
public function TextHeader($txtheader,$row)
{
if (ereg(",",$txtheader))
{
$this->_header[$row]=explode(",",$txtheader);
}
else
{
$this->_header[$row]=explode(",",ereg_replace(" ",",",$txtheader));
}
}
public function ColHidden($colhide,$hideplace)
{
$this->_colhidden[$colhide]='1';
$this->_hideplace[$colhide]=strval($hideplace);
$this->_colhide=$colhide;
$this->_colmove=$hideplace;
}
public function ColBoolean($col)
{
$this->_typecolbool=strval($col-1);
}
public function ColButton($col,$text)
{
$this->_typecolbutton=strval($col-1);
$this->_buttontext=$text;
}
public function ColText($col)
{
$this->_typecoltext=strval($col-1);
}
public function Display()
{
//echo "<form>";
echo "<table width=\"$this->TableWidth\" border=\"$this->Border\" cellspacing=\"$this->CellSpacing\" bordercolor=\"$this->BorderColor\">";
for ($x=0;$x<$this->FixedRow;$x++) //Header
{
echo "<tr bgcolor=\"$this->ColorBackgroundHead\">";
for ($y=0;$y<$this->_cols;$y++)
{
if ($this->_colhidden[$y]=='0')
{
echo "<td align=\"".$this->_fixed_alignment[$y]."\">";
echo "<font color=\"$this->ColorFontHead\">";
echo $this->_header[$x][$y];
echo "</font>";
echo "</td>";
}
}
echo "</tr>";
}
for ($x=0;$x<$this->_recordcount;$x++)//Data
{
if ($this->_colhide>$this->_colmove)
{
$this->_hide=$this->_hideplace[$this->_colhide];
$this->_hidemove=$this->_colhide;
}
echo "<tr bgcolor=\"$this->ColorbackgroundData\">";
for ($y=0;$y<$this->_cols;$y++)
{
if ($this->_colhidden[$y]=='1')
{
$this->_hide=$this->_hideplace[$y];
$this->_hidemove=$y;
}
if ($y==$this->_typecolbool)
{
echo "<td align=\"".$this->_col_alignment[$y]."\">";
echo "<input type=\"checkbox\" name=\"checkbox\" value=\"checkbox\">";
echo "</td>";
}
elseif ($y==$this->_typecolbutton)
{
echo "<td align=\"".$this->_col_alignment[$y]."\">";
echo "<input type=\"submit\" name=\"Submit\" value=\"$this->_buttontext\">";
echo "</td>";
}
elseif ($y==$this->_typecoltext)
{
echo "<td align=\"".$this->_col_alignment[$y]."\">";
echo "<input type=\"text\" name=\"textfield\" value=\"".$this->_data_array[$x][$y]."\">";
echo "</td>";
}
else
{
if ($this->_colhidden[$y]=='0')
{
echo "<td align=\"".$this->_col_alignment[$y]."\">";
echo "<font color=\"$this->ColorFontData\">";
echo $this->_data_array[$x][$y];
echo "</font>";
if ($this->_hide==strval($y))
{
echo "<input type=\"hidden\" name=\"txtdthide\" value=\"". $this->_data_array[$x][$this->_hidemove]."\">";
}
echo "</td>";
}
}
}
echo "</tr>";
}
echo "</table>";
}
}
?>