<?php

class MTableRaw extends MSimpleTable
{
    public $array;
    public $colTitle;
    public $zebra = false;
    public $table;

    public function __construct($title='', $array, $colTitle=null, $name='', $zebra = true)
    {
        parent::__construct($name);
//        $this->setCaption($title);
        $this->array = $array;
        $this->colTitle = $colTitle;
        $this->setClass("mTableRaw");
        $this->zebra = $zebra;
    }

    public function setData($data)
    {
        $this->array = $data;
    }
    
    public function setAlternate($zebra=false)
    {
        $this->zebra = $zebra;
    }

   public function generate()
   {
      $array = $this->array;
      $colTitle = $this->colTitle;
      $t = $this;
      $k = 0;
      if ($this->caption)
      {
         $ncols = count($array[0]);
         $t->setCell($k++,0,$this->caption," class=\"mTableRawTitle\" colspan=$ncols ");
      }
      if (is_array($colTitle))
      {
         $n = count($colTitle);
         for($i=0;$i<$n;$i++)
            $t->setCell($k,$i,$colTitle[$i]," class=\"mTableRawColumnTitle\" ");
         $k++;
      }
      if (is_array($array))
      {
         $nrows = count($array);
         for($i=0; $i<$nrows; $i++)
         {
            $rowClass = "mTableRawRow" . ($this->zebra ? ($i%2) : '');
            $t->setRowClass($k, $rowClass);
            if (is_array($array[$i]))
            {
               $ncols = count($array[$i]);
               for($j=0; $j<$ncols; $j++)
               { 
                   $attr = $this->attributes['cell'][$k][$j];
                   if ($attr == '') $attr = "width=0 align=\"left\" valign=\"top\"";
                   $t->setCell($k,$j,$array[$i][$j],$attr);

               }
            }
            else 
            {
               $attr = $this->attributes['cell'][$k][0];
               if ($attr == '') $attr = "width=0 align=\"left\" valign=\"top\"";
               $t->setCell($k,0,$array[$i], $attr);
            }
            $k++; 
         }
      } 
      return parent::generate();
   }
}
?>