Location: PHPKode > projects > Skat Statistics > skatstat-1.7.1/skatstat/inc/ctable.php
<?
// Class to create a simple html table
class CTable
{
  var $_rows;
  var $_hrows;
  var $_cols;
  var $_table;
  var $_tableattributes;
  var $_caption;
  var $_cellattributes;
  var $_colspan;
  var $_rowspan;

  function CTable( $brows, $cols, $class, $hrows = 1, $caption = 0 )
  {
    $this->_cols   = $cols;
    $this->_hrows  = $hrows;
    $this->_rows   = $hrows + $brows;

    if( $caption )
    {
      $this->_caption = $caption;
    }

    $this->_tableattributes = array("class" => $class);
  }

  function SetContent( $row, $col, $content )
  {
    if( $row < 0 )
    {
      $row = $this->_rows - 1;
    }
    if( $col < 0 )
    {
      $col = $this->_cols - 1;
    }
    #echo $row . " : " . $col . " : " . $content . "<br>";
    $this->_table[$row][$col] = $content;
    #echo $this->_table[$row][$col] . "<br>";
  }

  function AddChild( $row, $col, $node )
  {
#/    AppendChild( $this->getCell( $row, $col ), $node );
  }

  function AddNode( $node )
  {
#/    AppendChild( $this->_table, $node );
  }

  function getRow( $row )
  {
  }

  function getCell( $row, $col )
  {
    if( $row < 0 )
    {
      $row = $this->_rows - 1;
    }
    if( $col < 0 )
    {
      $col = $this->_cols - 1;
    }
    return $this->_table[$row][ $col ];
  }

  function SetTitle( $title )
  {
    $this->_caption = $title;
  }

  function SetSpan( $row, $col, $span, $value )
  {
    if( $row < 0 )
    {
      $row = $this->_rows - 1;
    }
    if( $col < 0 )
    {
      $col = $this->_cols - 1;
    }

    if( 0 == $span ) # row
    {
      $this->_rowspan[ $row ][ $col ] = $value;
      for( $i = $row + 1; $i < $row + $value; $i++ )
      {
        $this->_cellspan[ $i ][ $col ] = 1;
      }
    }
    else # col
    {
      $this->_colspan[ $row ][ $col ] = $value;
      for( $i = $col + 1; $i < $col + $value; $i++ )
      {
        $this->_cellspan[ $row ][ $i ] = 1;
      }
    }
  }

  function SetColspan( $row, $col, $colspan )
  {
    $this->SetSpan( $row, $col, 1, $colspan );
  }

  function SetRowspan( $row, $col, $rowspan )
  {
    $this->SetSpan( $row, $col, 0, $rowspan );
  }


  function RemoveCell( $r, $c )
  {
  }

  // To Do
  function AppendRow( $r = 1 )
  {
  }

  function GetNode()
  {
  }

  function SetAttribute( $row, $col, $attr, $value )
  {
    if( $row < 0 )
    {
      $row = $this->_rows - 1;
    }
    if( $col < 0 )
    {
      $col = $this->_cols - 1;
    }
    $this->_cellattributes[ $row][ $col ] = array($attr => $value );
  }

  function SetAttributeRow( $row, $attr, $value )
  {
    #    SetAttribute( $this->getRow( $row ), $attr, $value );
  }

  function Display()
  {
    if( $this->_tableattributes )
    {
      list($k, $v) = each( $this->_tableattributes );
      $att.= $k . "=\"" . $v . "\"";
    }
    echo "<table $att>";

    if( $this->_caption )
    {
      startTag( "caption" );
      echo $this->_caption;
      endTag( "caption" );
    }

    for( $i = 0; $i < $this->_rows; $i++ )
    {
      startTag( "tr" );
      for( $j = 0; $j < $this->_cols; $j++ )
      {
        if( 1 != $this->_cellspan[$i][$j] )
        {
          $att = "";
          if( $this->_cellattributes[$i][$j] )
          {
            list($k, $v) = each( $this->_cellattributes[$i][$j] );
            $att = $k . "=\"" . $v . "\" ";
          }
          if( $this->_colspan[$i][$j] )
          {
            $att .= "colspan=\"" . $this->_colspan[$i][$j] . "\" ";
          }
          if( $this->_rowspan[$i][$j] )
          {
            $att .= "rowspan=\"" . $this->_rowspan[$i][$j] . "\" ";
          }

          if( $i < $this->_hrows )
          {
            echo( "<th $att>" );
          }
          else
          {
            echo( "<td $att>" );
          }

          echo $this->getCell($i, $j);

          if( $i < $this->_hrows )
          {
            endTag( "th" );
          }
          else
          {
            endTag( "td" );
          }
        }
      }
      endTag( "tr" );
    }
    endTag( "table" );
  }
}

class THead extends CTable
{
# function THead( $domdoc, $rows, $cols, $class = "" )
# {
#   $this->_domdoc = $domdoc;
#   $this->_cols   = $cols;
#   $this->_rows   = 0;

#   // Create table of rows x cols
#   $this->_table = CreateElement( $this->_domdoc, "thead" );
#   if( $class )
#   {
#     SetAttribute( $this->_table, "class", $class );
#   }
#   for( $r = 0; $r < $rows ; $r++ )
#   {
#     # create header cells only
#     $this->AppendRow( 0 );
#   }
# }
}

class TFoot extends CTable
{
# function TFoot( $domdoc, $rows, $cols, $class = "" )
# {
#   $this->_domdoc = $domdoc;
#   $this->_cols   = $cols;
#   $this->_rows   = 0;

#   // Create table of rows x cols
#   $this->_table = CreateElement( $this->_domdoc, "tfoot" );
#   if( $class )
#   {
#     SetAttribute( $this->_table, "class", $class );
#   }
#   for( $r = 0; $r < $rows ; $r++ )
#   {
#     # create header cells only
#     $this->AppendRow( 1 );
#   }
# }
}

class TBody extends CTable
{
# function TBody( $domdoc, $rows, $cols, $class = "" )
# {
#   $this->_domdoc = $domdoc;
#   $this->_cols   = $cols;
#   $this->_rows   = 0;

#   // Create table of rows x cols
#   $this->_table = CreateElement( $this->_domdoc, "tbody" );
#   if( $class )
#   {
#     SetAttribute( $this->_table, "class", $class );
#   }
#   for( $r = 0; $r < $rows ; $r++ )
#   {
#     # create header cells only
#     $this->AppendRow( 1 );
#   }
# }
}

class Container
{
# var $_domdoc;
# var $_container;
# function Container( $domdoc, $class )
# {
#   $this->_domdoc    = $domdoc;
#   $this->_container = CreateElement( $this->_domdoc, "div" );
#   SetAttribute( $this->_container, "id", $class );
# }

# function AddNode( $node )
# {
#   #echo "AddNode: $node<br>";
#   #echo "Node: $node<br>";
#   #echo "Cont: " . $this->_container . "<br>";
#   AppendChild($this->_container,  $node );
#   #echo "AddNode: $node<br>";
# }

# function GetNode()
# {
#   return $this->_container;
# }
}

?>
Return current item: Skat Statistics