html
[ class tree: html ] [ index: html ] [ all elements ]

Source for file HTMLTable.class.php

Documentation is available at HTMLTable.class.php

  1. <?php
  2. /**
  3.  * This is a very important file for the framework "GilliGan".
  4.  * With the class HTMLTable you can build tables to layout HTML-pages. It is
  5.  * very useful in close collaboration to the form-classes of the package forms.
  6.  *
  7.  * For including this file you have to define the constant "CLASSPATH".
  8.  * Because every include in the framework depends on the CLASSPATH definition.
  9.  * The CLASSPATH means the relative path to the folder that contains the
  10.  * framework GilliGan.
  11.  *
  12.  * @package html
  13.  */
  14. if!defined"CLASSPATH" ) )
  15. {
  16.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  17.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  18.   exit();
  19. }
  20.  
  21. /**
  22.  * A class to format plaintext.
  23.  */
  24. require_onceCLASSPATH."core/PlainTextFormatter.class.php" );
  25. /**
  26.  * A pool of regular expressions.
  27.  */
  28. include_onceCLASSPATH."RegExpConstants.inc.php" );
  29.  
  30. /**
  31.  * A very important class to generate HTML-tables. To keep a fast performance,
  32.  * this class is not purely object oriented. That means that the tabledatas are
  33.  * not objects - their information are stored in arrays.
  34.  *
  35.  * @package html
  36.  * @version 0.3.46
  37.  * @static
  38.  * @license http://www.gnu.org/copyleft/lesser.html
  39.  *           GNU Lesser General Public License
  40.  * @copyright Copyright (c) 2003 Daniel Plücken <daniel@debakel.net>
  41.  *
  42.  *  This library is free software; you can redistribute it and/or
  43.  *  modify it under the terms of the GNU Lesser General Public
  44.  *  License as published by the Free Software Foundation; either
  45.  *  version 2.1 of the License.
  46.  *
  47.  *  This library is distributed in the hope that it will be useful,
  48.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  49.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  50.  *  GNU Lesser General Public License for more details.
  51.  *
  52.  *  You should have received a copy of the GNU Lesser General
  53.  *  Public License along with this library; if not, write to the
  54.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  55.  *  Boston, MA 02111-1307 USA
  56.  */
  57. class HTMLTable extends PlainTextFormatter
  58. {
  59.   /**
  60.    * The id or name of this table.
  61.    *
  62.    * @var    string $id 
  63.    * @access public
  64.    */
  65.   var $id = "table_";
  66.   /**
  67.    * Stores the rows count of this table.
  68.    *
  69.    * @var    string  $rows 
  70.    * @access private
  71.    */
  72.   var $rows = 0;
  73.   /**
  74.    * Stores the cols count of this table.
  75.    *
  76.    * @var    string  $cols 
  77.    * @access private
  78.    */
  79.   var $cols = 0;
  80.   /**
  81.    * Can filled with styledefinitions that were not handled by an implemented
  82.    * method.
  83.    *
  84.    * @var    string $freestyle 
  85.    * @access public
  86.    */
  87.   var $freestyle;
  88.  
  89.  
  90.   ///////////////////////
  91.   // Store of tabledata
  92.   /**
  93.    * Stores the content of each tabledata. This array carries two dimensions of
  94.    * string types. The first dimension stands for the rows of the table, the
  95.    * second one stands for the cols of the table.
  96.    *
  97.    * @var    array   $contentArr 
  98.    * @access private
  99.    */
  100.   var $contentArr = array();
  101.   /**
  102.    * Stores the width of each tabledata. This array carries two dimensions of
  103.    * integer types. The first dimension stands for the rows of the table, the
  104.    * second one stands for the cols of the table.
  105.    *
  106.    * @var    array   $cellWidthArr 
  107.    * @access private
  108.    */
  109.   var $cellWidthArr = array();
  110.   /**
  111.    * Stores the height of each tabledata. This array carries two dimensions of
  112.    * integer types. The first dimension stands for the rows of the table, the
  113.    * second one stands for the cols of the table.
  114.    *
  115.    * @var    array   $cellHeightArr 
  116.    * @access private
  117.    */
  118.   var $cellHeightArr = array();
  119.   /**
  120.    * Stores whether a tabledata should be formatted by the PlainTextFormatter or
  121.    * not. This array carries two dimensions of boolean types. The first
  122.    * dimension stands for the rows of the table, the second one stands for the
  123.    * cols of the table.
  124.    *
  125.    * @var    array   $no_format_arr 
  126.    * @access private
  127.    */
  128.   var $no_format_arr = array();
  129.   /**
  130.    * Stores the colspan of each tabledata. This array carries two dimensions of
  131.    * integer types. The first dimension stands for the rows of the table, the
  132.    * second one stands for the cols of the table.
  133.    *
  134.    * @var    array   $colspanArr 
  135.    * @access private
  136.    */
  137.   var $colspanArr = array();
  138.   /**
  139.    * Stores the rowspan of each tabledata. This array carries two dimensions of
  140.    * integer types. The first dimension stands for the rows of the table, the
  141.    * second one stands for the cols of the table.
  142.    *
  143.    * @var    array   $rowspanArr 
  144.    * @access private
  145.    */
  146.   var $rowspanArr = array();
  147.   /**
  148.    * Stores the styleclass of each tabledata. This array carries two dimensions
  149.    * of string types. The first dimension stands for the rows of the table, the
  150.    * second one stands for the cols of the table.
  151.    *
  152.    * @var    array   $cellStyleClassArr 
  153.    * @access private
  154.    */
  155.   var $cellStyleClassArr = array();
  156.   /**
  157.    * Stores all customized attributes of each tabledata. This array carries two
  158.    * dimensions of string types. The first dimension stands for the rows of the
  159.    * table, the second one stands for the cols of the table.
  160.    *
  161.    * @var    array 
  162.    * @access private
  163.    */
  164.   var $attributesArr = array();
  165.   // Store of tabledata
  166.   ///////////////////////
  167.  
  168.  
  169.   /**
  170.    * Stores the customized attributes of each table's row.
  171.    *
  172.    * @var    array   $rowAttributes 
  173.    * @access private
  174.    */
  175.   var $rowAttributes = array();
  176.  
  177.  
  178.   ///////////////////////
  179.   // Table's attributes
  180.   /**
  181.    * Stores the value of the width-attribute of this table.
  182.    *
  183.    * @var   integer  $width 
  184.    *  access public
  185.    */
  186.   var $width = 0;
  187.   /**
  188.    * Stores the value of the height-attribute of this table.
  189.    *
  190.    * @var   integer  $height 
  191.    *  access public
  192.    */
  193.   var $height = 0;
  194.   /**
  195.    * Stores the value of the cellpadding-attribute of this table.
  196.    *
  197.    * @var   integer  $cellpadding 
  198.    *  access public
  199.    */
  200.   var $cellpadding = 0;
  201.   /**
  202.    * Stores the value of the cellspacing-attribute of this table.
  203.    *
  204.    * @var   integer  $cellspacing 
  205.    *  access public
  206.    */
  207.   var $cellspacing = 0;
  208.   /**
  209.    * Stores the value of the border-attribute of this table.
  210.    *
  211.    * @var   integer  $border 
  212.    *  access public
  213.    */
  214.   var $border = 0;
  215.   /**
  216.    * Stores the value of the class-attribute of this table
  217.    *
  218.    * @var   integer  $style 
  219.    *  access public
  220.    */
  221.   var $style = "";
  222.   /**
  223.    * Stores the customized attributes of this table.
  224.    *
  225.    * @var    string  $tableAttributes 
  226.    * @access public
  227.    */
  228.   var $tableAttributes = "";
  229.   // Table's attributes
  230.   ///////////////////////
  231.  
  232.   /**
  233.    * Stores whether the table should be formatted by the PlainTextFormatter or
  234.    * not.
  235.    *
  236.    * @var    boolean $no_format 
  237.    * @access private
  238.    */
  239.   var $no_format = false;
  240.  
  241.  
  242.  
  243.  
  244.  
  245.   /**
  246.    * Constructor.
  247.    *
  248.    * @version 1.2
  249.    * @since   0.1.0
  250.    * @author  Daniel Plücken <daniel@debakel.net>
  251.    * @access  public
  252.    * @param   integer $cols 
  253.    * @param   integer $rows 
  254.    * @param   integer $width 
  255.    * @param   integer $height 
  256.    * @param   array   $cellpadding 
  257.    * @param   array   $cellspacing 
  258.    * @param   integer $border 
  259.    * @param   string  $style 
  260.    * @param   boolean $no_format 
  261.    */
  262.   function HTMLTable(
  263.                        $cols$rows 0$width ""$height "",
  264.                        $cellWidthArr array()$cellHeightArr array(),
  265.                        $cellpadding ""$cellspacing "",
  266.                        $border ""$style ""$no_format false
  267.                     )
  268.   {
  269.     ifpreg_match"!^".UNSIGNEDINTEGER."$!"$cols ) )
  270.       $this->cols = $cols;
  271.  
  272.     ifpreg_match"!^".UNSIGNEDINTEGER."$!"$rows ) )
  273.       $this->rows = $rows;
  274.  
  275.     ifpreg_match"!^".UNSIGNEDINTEGER."%?$!"$width ) )
  276.       $this->width = $width;
  277.  
  278.     ifpreg_match"!^".UNSIGNEDINTEGER."%?$!"$height ) )
  279.       $this->height = $height;
  280.  
  281.     ifis_array$cellWidthArr ) )
  282.       $this->cellWidthArr = $cellWidthArr;
  283.  
  284.     ifis_array$cellHeightArr ) )
  285.       $this->cellHeightArr = $cellHeightArr;
  286.  
  287.     ifpreg_match"!^".UNSIGNEDINTEGER."$!"$cellpadding ) )
  288.       $this->cellpadding = $cellpadding;
  289.  
  290.     ifpreg_match"!^".UNSIGNEDINTEGER."$!"$cellspacing ) )
  291.       $this->cellspacing = $cellspacing;
  292.  
  293.     ifpreg_match"!^".UNSIGNEDINTEGER."$!"$border ) )
  294.       $this->border = $border;
  295.  
  296.     if!empty$style ) )
  297.       $this->style = $style;
  298.  
  299.     ifis_bool$no_format ) )
  300.       $this->no_format = $no_format;
  301.  
  302.     for$i 0$i $this->rows$i++ )
  303.       for$j 0$j $this->cols$j++ )
  304.       {
  305.          $this->colspanArr[$i][$j1;
  306.          $this->contentArr[$i][$j"&nbsp;";
  307.       }
  308.   }
  309.  
  310.  
  311.   /**
  312.    * Stores all used ids and makes sure that every id in the document is
  313.    * unique. It should called in every get method of classes in the packages
  314.    * forms and html.
  315.    *
  316.    * @version 1.0
  317.    * @since   0.3.4
  318.    * @author  Daniel Plücken <daniel@debakel.net>
  319.    * @access  public
  320.    * @param   string  $str_id 
  321.    * @param   boolean $bool_store 
  322.    * @return  boolean 
  323.    */
  324.   function idExists$str_id$bool_store false )
  325.   {
  326.      static $id_arr array();
  327.  
  328.      $out false;
  329.      if in_array$str_id$id_arr ) )
  330.      {
  331.         $out true;
  332.  
  333.         if $bool_store )
  334.         {
  335.            $match_arr array();
  336.            if preg_match"!^(.+)\_(\d+)?$!"$str_id$match_arr ) )
  337.            {
  338.               $start  intval$match_arr[21;
  339.               $helper $match_arr[1];
  340.            }
  341.            else
  342.            {
  343.               $start 1;
  344.               $match_arr[1$helper $str_id;
  345.            }
  346.  
  347.            for $i $startin_array$helper$id_arr )$i++ )
  348.                $helper $match_arr[1]."_".$i;
  349.  
  350.            $str_id $helper;
  351.         }
  352.      }
  353.  
  354.      if $bool_store )
  355.         $this->id $id_arr[$str_id;
  356.  
  357.      return $out;
  358.   }
  359.  
  360.  
  361.  
  362.   /**
  363.    * Sets the content of the id-attribute of the table-tag.
  364.    *
  365.    * @version 1.0
  366.    * @since   0.1.1
  367.    * @author  Daniel Plücken <daniel@debakel.net>
  368.    * @access  public
  369.    * @param   string $string 
  370.    * @return  void 
  371.    */
  372.   function setId$string )
  373.   {
  374.     $this->id $string;
  375.   }
  376.  
  377.  
  378.  
  379.   /**
  380.    * Sets the value of the width-attribute of the table-tag.
  381.    *
  382.    * @version 1.0
  383.    * @since   0.1.0
  384.    * @author  Daniel Plücken <daniel@debakel.net>
  385.    * @access  public
  386.    * @param   integer $int 
  387.    * @return  void 
  388.    */
  389.   function setWidth$int )
  390.   $this->width $int}
  391.  
  392.  
  393.  
  394.   /**
  395.    * Sets the value of the height-attribute of the table-tag.
  396.    *
  397.    * @version 1.0
  398.    * @since   0.1.0
  399.    * @author  Daniel Plücken <daniel@debakel.net>
  400.    * @access  public
  401.    * @param   integer $int 
  402.    * @return  void 
  403.    */
  404.   function setHeight$int )
  405.   $this->height $int}
  406.  
  407.  
  408.  
  409.   /**
  410.    * Sets the number of cols this table should have. For example you want to
  411.    * set the table column by column, you simply have to increment the number of
  412.    * cols of this table by one after you set all rows of a col, and so on.
  413.    *
  414.    * @version 1.0
  415.    * @since   0.1.0
  416.    * @author  Daniel Plücken <daniel@debakel.net>
  417.    * @access  public
  418.    * @param   integer $int 
  419.    * @return  void 
  420.    */
  421.   function setCols$int )
  422.   $this->cols $int}
  423.  
  424.  
  425.  
  426.   /**
  427.    * Sets the number of rows this table should have. This makes only sense if
  428.    * you want to put out a table without any content.
  429.    *
  430.    * @version 1.0
  431.    * @since   0.1.0
  432.    * @author  Daniel Plücken <daniel@debakel.net>
  433.    * @access  public
  434.    * @param   integer $int 
  435.    * @return  void 
  436.    */
  437.   function setRows$int )
  438.   $this->rows $int}
  439.  
  440.  
  441.  
  442.   /**
  443.    * Sets the content of the cellpadding-attribute of the table-tag.
  444.    *
  445.    * @version 1.0
  446.    * @since   0.1.0
  447.    * @author  Daniel Plücken <daniel@debakel.net>
  448.    * @access  public
  449.    * @param   integer $int 
  450.    * @return  void 
  451.    */
  452.   function setCellpadding$int )
  453.   $this->cellpadding $int}
  454.  
  455.  
  456.  
  457.   /**
  458.    * Set the value of style definitions that are not handled by implemented
  459.    * methods.
  460.    *
  461.    * @version 1.0
  462.    * @since   0.3.1
  463.    * @author  Daniel Plücken <daniel@debakel.net>
  464.    * @access  public
  465.    * @param   string $string 
  466.    */
  467.   function setFreeStyle$string )
  468.   $this->freestyle $string}
  469.  
  470.  
  471.  
  472.   /**
  473.    * Sets the content of the cellspacing-attribute of the table-tag.
  474.    *
  475.    * @version 1.0
  476.    * @since   0.1.0
  477.    * @author  Daniel Plücken <daniel@debakel.net>
  478.    * @access  public
  479.    * @param   integer $int 
  480.    * @return  void 
  481.    */
  482.   function setCellspacing$int )
  483.   $this->cellspacing $int}
  484.  
  485.  
  486.  
  487.   /**
  488.    * Sets the content of the border-attribute of the table-tag.
  489.    *
  490.    * @version 1.0
  491.    * @since   0.1.0
  492.    * @author  Daniel Plücken <daniel@debakel.net>
  493.    * @access  public
  494.    * @param   integer $int 
  495.    * @return  void 
  496.    */
  497.   function setBorder$int )
  498.   $this->border $int}
  499.  
  500.  
  501.  
  502.   /**
  503.    * Sets whether the table should format in the source by "\r\n" or not.
  504.    *
  505.    * @version 1.0
  506.    * @since   0.1.1
  507.    * @author  Daniel Plücken <daniel@debakel.net>
  508.    * @access  public
  509.    * @param   integer $int 
  510.    * @return  void 
  511.    */
  512.   function setNoFormat$boolean true )
  513.   $this->no_format $boolean}
  514.  
  515.  
  516.  
  517.   /**
  518.    * Sets the content of the class-attribute of the table-tag.
  519.    *
  520.    * @version 1.0
  521.    * @since   0.1.1
  522.    * @author  Daniel Plücken <daniel@debakel.net>
  523.    * @access  public
  524.    * @param   integer $int 
  525.    * @return  void 
  526.    */
  527.   function setStyle$string )
  528.   $this->style $string}
  529.  
  530.  
  531.  
  532.   /**
  533.    * Adds a custom-attribute to the given row of this table. The counting of
  534.    * rows begins at zero.
  535.    *
  536.    * @version 1.1
  537.    * @since   0.1.2
  538.    * @author  Daniel Plücken <daniel@debakel.net>
  539.    * @access  public
  540.    * @param   string  $string 
  541.    * @param   integer $row 
  542.    * @return  void 
  543.    */
  544.   function addAttributeToRow$string$row "" )
  545.   {
  546.     if empty$row ) )
  547.        $this->rowAttributes[$this->rows-1$string;
  548.     else
  549.        $this->rowAttributes[$row$string;
  550.  
  551.   }
  552.  
  553.  
  554.  
  555.   /**
  556.    * Adds a custom-attribute to the table-tag.
  557.    *
  558.    * @version 1.0
  559.    * @since   0.1.2
  560.    * @author  Daniel Plücken <daniel@debakel.net>
  561.    * @access  public
  562.    * @param   string  $string 
  563.    * @param   integer $row 
  564.    * @return  void 
  565.    */
  566.   function addAttributeToTable$string )
  567.   $this->tableAttributes .= $string}
  568.  
  569.  
  570.  
  571.   /**
  572.    * Returns a clone of this object.
  573.    *
  574.    * @version 1.1
  575.    * @since   0.1.3
  576.    * @author  Daniel Plücken <daniel@debakel.net>
  577.    * @access  public
  578.    * @return  HTMLTable 
  579.    */
  580.   function getClone()
  581.   {
  582.     $new_obj =new HTMLTable(
  583.                                 $this->cols,
  584.                                 $this->rows,
  585.                                 $this->width,
  586.                                 $this->height,
  587.                                 $this->colsWidthArr,
  588.                                 $this->rowsHeightArr,
  589.                                 $this->cellpadding,
  590.                                 $this->cellspacing,
  591.                                 $this->border,
  592.                                 $this->style,
  593.                                 $this->no_format
  594.                              );
  595.  
  596.     $new_obj->contentArr        $this->contentArr;
  597.     $new_obj->cellWidthArr      $this->cellWidthArr;
  598.     $new_obj->cellHeightArr     $this->cellHeightArr;
  599.     $new_obj->no_format_arr     $this->no_format_arr;
  600.     $new_obj->cellStyleClassArr $this->cellStyleClassArr;
  601.  
  602.     return $new_obj;
  603.   }
  604.  
  605.  
  606.  
  607.   /**
  608.    * Returns a clone of this object only with the specified cols.
  609.    *
  610.    * @version 1.0
  611.    * @since   0.3.1
  612.    * @author  Daniel Plücken <daniel@debakel.net>
  613.    * @access  public
  614.    * @param   array     $col_arr An array containing the numbers of the cols
  615.    *                              which should adopt to the clone. The counting
  616.    *                              bigins at zero from left to right. This value
  617.    *                              can also be an integer to adopt only one col.
  618.    * @return  HTMLTable 
  619.    */
  620.   function getCloneWithCols$col_arr )
  621.   {
  622.     ifis_array$col_arr ) )
  623.       $int_cols count$col_arr );
  624.     else
  625.     {
  626.       $int_cols 1;
  627.       $col_arr array$col_arr );
  628.     }
  629.  
  630.  
  631.     $new_obj =new HTMLTable(
  632.                                 $int_cols,
  633.                                 $this->rows,
  634.                                 $this->width,
  635.                                 $this->height,
  636.                                 array(),
  637.                                 array(),
  638.                                 $this->cellpadding,
  639.                                 $this->cellspacing,
  640.                                 $this->border,
  641.                                 $this->style,
  642.                                 $this->no_format
  643.                              );
  644.  
  645.     for$k 0$k $this->rows$k++ )
  646.       for$i 0$i $int_cols$i++ )
  647.       {
  648.         $new_obj->contentArr[$k][$i]        $this
  649.                                             ->contentArr[$k]$col_arr[$i] ];
  650.         $new_obj->cellWidthArr[$k][$i]      $this
  651.                                             ->cellWidthArr[$k]$col_arr[$i] ];
  652.         $new_obj->cellHeightArr[$k][$i]     $this
  653.                                             ->cellHeightArr[$k]$col_arr[$i] ];
  654.         $new_obj->no_format_arr[$k][$i]     $this
  655.                                             ->no_format_arr[$k]$col_arr[$i] ];
  656.         $new_obj->cellStyleClassArr[$k][$i$this
  657.                                             ->cellStyleClassArr[$k]
  658.                                                                $col_arr[$i] ];
  659.       }
  660.  
  661.     return $new_obj;
  662.   }
  663.  
  664.  
  665.  
  666.   /**
  667.    * Returns a clone of this object only with the specified rows.
  668.    *
  669.    * @version 1.0
  670.    * @since   0.3.1
  671.    * @author  Daniel Plücken <daniel@debakel.net>
  672.    * @access  public
  673.    * @param   array     $col_arr An array containing the numbers of the rows
  674.    *                              which should adopt to the clone. The counting
  675.    *                              bigins at zero from top to bottom. This value
  676.    *                              can also be an integer to adopt only one row.
  677.    * @return  HTMLTable 
  678.    */
  679.   function getCloneWithRows$row_arr )
  680.   {
  681.     ifis_array$row_arr ) )
  682.       $int_rows count$row_arr );
  683.     else
  684.     {
  685.       $int_rows 1;
  686.       $row_arr array$row_arr );
  687.     }
  688.  
  689.  
  690.     $new_obj =new HTMLTable(
  691.                                 $this->cols,
  692.                                 $int_rows,
  693.                                 $this->width,
  694.                                 $this->height,
  695.                                 array(),
  696.                                 array(),
  697.                                 $this->cellpadding,
  698.                                 $this->cellspacing,
  699.                                 $this->border,
  700.                                 $this->style,
  701.                                 $this->no_format
  702.                              );
  703.  
  704.     for$k 0$k $int_rows$k++ )
  705.       {
  706.         $new_obj->contentArr[$k]        $this->contentArr$row_arr[$k] ];
  707.         $new_obj->cellWidthArr[$k]      $this->cellWidthArr$row_arr[$k] ];
  708.         $new_obj->cellHeightArr[$k]     $this->cellHeightArr$row_arr[$k] ];
  709.         $new_obj->no_format_arr[$k]     $this->no_format_arr$row_arr[$k] ];
  710.         $new_obj->cellStyleClassArr[$k$this
  711.                                         ->cellStyleClassArr$row_arr[$k] ];
  712.       }
  713.  
  714.     return $new_obj;
  715.   }
  716.  
  717.  
  718.  
  719.   /**
  720.    * Sets the span of the cell at the given position.
  721.    *
  722.    * @version 1.1
  723.    * @since   0.1.5
  724.    * @author  Daniel Plücken <daniel@debakel.net>
  725.    * @access  public
  726.    * @param   integer $row 
  727.    * @param   integer $col 
  728.    * @param   integer $rowspan 
  729.    * @param   integer $colspan 
  730.    * @return  void 
  731.    */
  732.   function setCellSpanRange(
  733.                               $row,
  734.                               $col,
  735.                               $rowspan 1,
  736.                               $colspan 1
  737.                            )
  738.   {
  739.     $rowspan preg_match"!^".UNSIGNEDINTEGER."$!"$rowspan $rowspan 1;
  740.     $colspan preg_match"!^".UNSIGNEDINTEGER."$!"$colspan $colspan 1;
  741.  
  742.     $this->colspanArr[$row][$col$colspan;
  743.     for$i 1$i $colspan$i++ )
  744.     {
  745.        $this->cellStyleClassArr[$row][$col+$i"";
  746.        $this->contentArr[$row][$col+$i]        "";
  747.     }
  748.  
  749.  
  750.     $this->rowspanArr[$row][$col$rowspan;
  751.     for$i 1$i $rowspan$i++ )
  752.     {
  753.        $this->cellStyleClassArr[$row+$i][$col"";
  754.        $this->contentArr[$row+$i][$col]        "";
  755.        $this->colspanArr[$row+$i][$col]        $colspan;
  756.  
  757.        for$j 1$j $colspan$j++ )
  758.        {
  759.            $this->cellStyleClassArr[$row+$i][$col+$j"";
  760.            $this->contentArr[$row+$i][$col+$j]        "";
  761.        }
  762.     }
  763.  
  764.     if$this->rows $row $rowspan )
  765.       $this->rows $row $rowspan;
  766.   }
  767.  
  768.  
  769.  
  770.   /**
  771.    * Adds a cell at the next possible position to this table.
  772.    *
  773.    * @version 1.5
  774.    * @since   0.1.0
  775.    * @author  Daniel Plücken <daniel@debakel.net>
  776.    * @access  public
  777.    * @param   string $content  The content the cell should have.
  778.    * @param   string $style    The value of the class-attribute of the cell
  779.    *                            that should be add.
  780.    * @param   string $colspan  The value of the colspan-attribute of the cell
  781.    *                            that should be add.
  782.    * @param   string $rowspan  The value of the rowspan-attribute of the cell
  783.    *                            that should be add.
  784.    * @param   string $no_format Ascertains whether the content of the cell should
  785.    *                            format by newlines ("\r\n") or not.
  786.    * @return  array  The position where the cell was fixed.
  787.    */
  788.   function addCol(
  789.                     $content  "",  $style   "",
  790.                     $colspan  "1"$rowspan "1",
  791.                     $noFormat false
  792.                  )
  793.   {
  794.     $content    $content == ""
  795.                   ? "&nbsp;"
  796.                   : $content;
  797.     $styleClass $style;
  798.     $colspan    =  preg_match"!^".UNSIGNEDINTEGER."$!"$colspan )
  799.                   ? $colspan
  800.                   : 1;
  801.     $rowspan    preg_match"!^".UNSIGNEDINTEGER."$!"$rowspan )
  802.                   ? $rowspan
  803.                   : 1;
  804.     $noFormat   strlen$content 80
  805.                && !preg_match"!\[ITEM\]!i"$content )
  806.                   ? true
  807.                   : (
  808.                       is_bool$noFormat )
  809.                       ? $noFormat
  810.                       : false
  811.                     );
  812.  
  813.     # Search the next possible place for a cell
  814.     for$i 0$i $this->rows 1$i++ )
  815.     {
  816.       for$j 0$j $this->cols$j++ )
  817.       {
  818.         ifempty$this->colspanArr[$i][$j)
  819.          && empty$ignoreCountCol ) )
  820.         {
  821.           # found
  822.           $thisRow $i;
  823.           $thisCol $j;
  824.  
  825.           $breakOUT true;
  826.           break;
  827.         }
  828.         else
  829.         {
  830.           if!empty$ignoreCountCol ) )
  831.             $ignoreCountCol--;
  832.           else
  833.           if$this->colspanArr[$i][$j$j $this->cols )
  834.             $ignoreCountCol $this->colspanArr[$i][$j1;
  835.           else
  836.           {
  837.             $thisRow $i $rowspan;
  838.             $thisCol $j;
  839.             break;
  840.           }
  841.         }
  842.       }
  843.  
  844.       if$breakOUT )
  845.         break;
  846.     }
  847.  
  848.     # If the colspan is greater than the given space, it will be corrected.
  849.     if$colspan $this->cols $thisCol ) )
  850.       $colspan $this->cols $thisCol;
  851.  
  852.     if$this->rows $thisRow $rowspan )
  853.     $this->rows $thisRow $rowspan}
  854.  
  855.  
  856.     $this->setCellSpanRange$thisRow$thisCol$rowspan$colspan );
  857.  
  858.  
  859.  
  860.  
  861.     if!empty$styleClass ) )
  862.       $this->cellStyleClassArr[$thisRow][$thisCol$styleClass;
  863.     if!empty$noFormat ) )
  864.       $this->no_format_arr[$thisRow][$thisCol1;
  865.  
  866.     $this->contentArr[$thisRow][$thisCol$content;
  867.  
  868.     return array$thisRow$thisCol );
  869.   }
  870.  
  871.  
  872.  
  873.   /**
  874.    * Adds a cell at the next possible position to this table. This method is an
  875.    * alias for the method addCol.
  876.    *
  877.    * @version 1.0
  878.    * @since   0.2.8
  879.    * @author  Daniel Plücken <daniel@debakel.net>
  880.    * @access  public
  881.    * @param   string $content  The content the cell should have.
  882.    * @param   string $style    The value of the class-attribute of the cell
  883.    *                            that should be add.
  884.    * @param   string $colspan  The value of the colspan-attribute of the cell
  885.    *                            that should be add.
  886.    * @param   string $rowspan  The value of the rowspan-attribute of the cell
  887.    *                            that should be add.
  888.    * @param   string $no_format Ascertains whether the content of the cell should
  889.    *                            format by newlines ("\r\n") or not.
  890.    * @return  array  The position where the cell was fixed.
  891.    */
  892.   function addCell(
  893.                       $content  "",  $style   "",
  894.                       $colspan  "1"$rowspan "1",
  895.                       $noFormat false
  896.                   )
  897.   $this->addCol$content,  $style$colspan$rowspan$noFormat )}
  898.  
  899.  
  900.  
  901.   /**
  902.    * Changes the given cell.
  903.    *
  904.    * @version 1.2
  905.    * @since   0.1.7
  906.    * @author  Daniel Plücken <daniel@debakel.net>
  907.    * @access  public
  908.    * @param   integer $row             The row in which the cell that should
  909.    *                                    become change is.
  910.    * @param   integer $col             The col in which the cell that should
  911.    *                                    become change is.
  912.    * @param   string  $styleClass      The style class that should set to the
  913.    *                                    cell.
  914.    * @param   integer $rowspan         To manipulate the rowspan.
  915.    * @param   integer $colspan         To manipulate the colspan.
  916.    * @param   boolean $noFormat        Whether the content in the col should
  917.    *                                    automatically get breaks or not.
  918.    * @param   string  $otherAttributes The attributes that should set to the
  919.    *                                    given col.
  920.    * @return  void 
  921.    */
  922.   function changeCol(
  923.                       $row$col,
  924.                       $content         "",
  925.                       $styleClass      "",
  926.                       $rowspan         1,
  927.                       $colspan         1,
  928.                       $noFormat        false,
  929.                       $otherAttributes ""
  930.                     )
  931.   {
  932.     if!empty$content ) )
  933.       $this->contentArr[$row][$col$content;
  934.  
  935.     if!empty$styleClass ) )
  936.       $this->cellStyleClassArr[$row][$col$styleClass;
  937.  
  938.     if(
  939.         !empty$rowspan )
  940.      || !empty$colspan )
  941.       )
  942.       $this->setCellSpanRange$row$col$rowspan$colspan );
  943.  
  944.     ifis_bool$noFormat ) )
  945.       $this->no_format_arr[$row][$col$noFormat;
  946.  
  947.     if!empty$otherAttributes ) )
  948.       $this->attributesArr[$row][$coltrim$otherAttributes );
  949.   }
  950.  
  951.  
  952.  
  953.   /**
  954.    * Changes the attributes of a given cell.
  955.    *
  956.    * @version 1.0
  957.    * @since   0.1.7
  958.    * @author  Daniel Plücken <daniel@debakel.net>
  959.    * @access  public
  960.    * @param   integer $row        The row in which the cell to be change is.
  961.    * @param   integer $col        The col in which the cell to be change is.
  962.    * @param   string  $attributes The attributes that should set to the
  963.    *                               given col.
  964.    * @return  void 
  965.    */
  966.   function setColAttributes$row$col$attributes )
  967.   $this->changeCol$row$col""""""""""$attributes )}
  968.  
  969.  
  970.  
  971.   /**
  972.    * Changes a given cell.
  973.    *
  974.    * @version 1.0
  975.    * @since   0.1.4
  976.    * @author  Daniel Plücken <daniel@debakel.net>
  977.    * @access  public
  978.    * @param   integer $row           The row in which the cell to be change is.
  979.    * @param   integer $col           The col in which the cell to be change is.
  980.    * @param   string  $content       The content that should be add to the
  981.    *                                  actual content of the cell.
  982.    * @param   string  $BEFORE_BEHIND Controls whether the given content should
  983.    *                                  be add before or behind the actual content
  984.    *                                  of the cell.
  985.    *                                  The possible values are:
  986.    *                                  "BEFORE" -> The new content will be add
  987.    *                                  before the actual content.
  988.    *                                  "BEHIND" -> The new content will be add
  989.    *                                  behind the actual content.
  990.    * @return  void 
  991.    */
  992.   function addContentToCol$row$col$content$BEFORE_BEHIND "" )
  993.   {
  994.     $BEFORE_BEHIND empty$BEFORE_BEHIND )
  995.                      ? "BEHIND"
  996.                      : strtoupper$BEFORE_BEHIND );
  997.  
  998.     $row empty$row ) ) $row;
  999.     $col empty$col ) ) $col;
  1000.  
  1001.     while$this->rowspanArr[$row][$col=== )
  1002.       $row--;
  1003.  
  1004.     while$this->colspanArr[$row][$col=== )
  1005.       $col--;
  1006.  
  1007.     if $BEFORE_BEHIND == "BEFORE" )
  1008.        $this->contentArr[$row][$col]  $content.$this->contentArr[$row][$col];
  1009.     else
  1010.        $this->contentArr[$row][$col.= $content;
  1011.   }
  1012.  
  1013.  
  1014.  
  1015.   /**
  1016.    * Adds a new row after the last row of this table. If there are lesser cols
  1017.    * in the last row of this table than a row is able to contain, the last row
  1018.    * will NOT be filled up with cols. This function ONLY adds a COMPLETE new row
  1019.    * AFTER the last row of this table!
  1020.    *
  1021.    * @version 1.0
  1022.    * @since   0.1.1
  1023.    * @author  Daniel Plücken <daniel@debakel.net>
  1024.    * @access  public
  1025.    * @param   array   $contentArr      An array of strings which should contain
  1026.    *                                    the content of each col in the row. Id
  1027.    *                                    est if a row of this table is able to
  1028.    *                                    contain ten cols then the array should
  1029.    *                                    be contain ten records.
  1030.    * @param   array   $styleClassArr   An array of strings which declares the
  1031.    *                                    styleclass of the appropriate col.
  1032.    * @param   array   $no_format_arr   An array of booleans. If the the value
  1033.    *                                    is false it means that after the
  1034.    *                                    &lt;td&gt;-tag and after the content of
  1035.    *                                    the appropriate col there will be add a
  1036.    *                                    linebreak ("\n").
  1037.    *                                    If the value is true no linebreaks will
  1038.    *                                    be add. You need this functionality if
  1039.    *                                    there are side by side lying pictures in
  1040.    *                                    a table which should not has any spaces
  1041.    *                                    to each other.
  1042.    *           array   $otherAttributes An array of strings which can be used to
  1043.    *                                    add col-attributes to the appropriate
  1044.    *                                    col.
  1045.    * @return  void 
  1046.    */
  1047.   function addRow(
  1048.                    $contentArr      array(),
  1049.                    $styleClassArr   array(),
  1050.                    $no_format_arr   array(),
  1051.                    $otherAttributes array()
  1052.                  )
  1053.   {
  1054.     $nextRow count$this->contentArr );
  1055.  
  1056.     for$i 0$i $this->cols$i++)
  1057.     {
  1058.       $this->colspanArr[$nextRow][$i1;
  1059.       $this->rowspanArr[$nextRow][$i1;
  1060.  
  1061.       if!empty$contentArr[$i) )
  1062.         $this->contentArr[$nextRow][$i$contentArr[$i];
  1063.       else
  1064.         $this->contentArr[$nextRow][$i"&nbsp;";
  1065.  
  1066.       if!empty$styleClassArr[$i) )
  1067.         $this->cellStyleClassArr[$nextRow][$i$styleClassArr[$i];
  1068.       if!empty$no_format_arr[$i) )
  1069.         $this->no_format_arr[$nextRow][$i1;
  1070.  
  1071.       if!empty$otherAttributes[$i) )
  1072.         $this->attributesArr[$nextRow][$i$otherAttributes[$i];
  1073.     }
  1074.  
  1075.     $this->rows++;
  1076.   }
  1077.  
  1078.  
  1079.  
  1080.   /**
  1081.    * Returns the rebuilded source code of this Object.
  1082.    *
  1083.    * @version 1.0
  1084.    * @since   0.2.3
  1085.    * @author  Daniel Plücken <daniel@debakel.net>
  1086.    * @access  public
  1087.    * @return  string 
  1088.    */
  1089.   function getPHPSource()
  1090.   {
  1091.     $outputstr  "";
  1092.  
  1093.     $outputstr .= "\x24table = new HTMLTable(\r\n"
  1094.                  ."                         ".$this->cols.", \x24rows, "
  1095.                                            ."\x24width, \x24height,\r\n"
  1096.                  ."                         \x24colsWidthArr, "
  1097.                                           ."\x24rowsHeightArr,\r\n"
  1098.                  ."                         \x24cellpadding, \x24cellspacing,\r\n"
  1099.                  ."                         \x24border, \x24style, "
  1100.                                           ."\x24no_format \r\n"
  1101.                  ."                      );\r\n\r\n";
  1102.  
  1103.     for$i 0$i $this->rows$i++ )
  1104.       for$j 0$j $this->cols$j++ )
  1105.       {
  1106.         $outputstr .= "\x24table->addCol( \"".
  1107.                              $this->contentArr[$i][$j]
  1108.                                    ."\" );\r\n";
  1109.         if$j == $this->cols )
  1110.           $outputstr .= "\r\n";
  1111.       }
  1112.  
  1113.     return $outputstr;
  1114.   }
  1115.  
  1116.  
  1117.  
  1118.   /**
  1119.    * Returns a generated string based on the Attributes of this HTML-Object.
  1120.    *
  1121.    * @access  public
  1122.    * @version 1.24
  1123.    * @since   0.1.0
  1124.    *
  1125.    * @return  string 
  1126.    */
  1127.   function get()
  1128.   {
  1129.     $this->idExists$this->idtrue );
  1130.  
  1131.     $out  "<!--\r\n\r\n  TABLE\r\n "
  1132.                         ."+--+--+\r\n "
  1133.                         ."+--+--+\r\n "
  1134.                         ."|  |  |\r\n";
  1135.     # Table-In-Tag
  1136.     $out .= "--><table id=\"".$this->id."\"\r\n"
  1137.               .(
  1138.                !empty$this->width )
  1139.                ? "          width=\"".$this->width."\"\r\n"
  1140.                : ""
  1141.             )
  1142.            .(
  1143.                !empty$this->height )
  1144.                ? "          height=\"".$this->height."\"\r\n"
  1145.                : ""
  1146.             )
  1147.            .(
  1148.                !empty$this->style )
  1149.                ? "          class=\"".$this->style."\"\r\n"
  1150.                : ""
  1151.             )
  1152.            ."          cellpadding=\"".$this->cellpadding."\"\r\n"
  1153.            ."          cellspacing=\"".$this->cellspacing."\"\r\n"
  1154.            ."          border=\"".$this->border."\"\r\n"
  1155.            .(
  1156.                !empty$this->freestyle )
  1157.                ? "          style=\"".$this->freestyle."\"\r\n"
  1158.                : ""
  1159.             )
  1160.            .(
  1161.                !empty$this->tableAttributes )
  1162.                ? "          ".$this->tableAttributes."\r\n"
  1163.                : ""
  1164.             )
  1165.            ."   ><!--\r\n"
  1166.            ."--><tbody>";
  1167.  
  1168.     for$i 0$i $this->rows$i++ )
  1169.     {
  1170.       $out .= "<!--\r\n"
  1171.              ."--><tr"
  1172.              .(
  1173.                  !empty$this->rowAttributes[$i)
  1174.                  ? " ".$this->rowAttributes[$i]
  1175.                  : ""
  1176.               )
  1177.              .">";
  1178.  
  1179.       for $j 0$j $this->cols$j++ )
  1180.           if $this->contentArr[$i][$j!== "" )
  1181.           {
  1182.              $out .= "<!--\r\n              --><td "
  1183.                     .(
  1184.                         !empty$this->cellWidthArr[$i][$j)
  1185.                         ? "width=\"".$this->cellWidthArr[$i][$j]."\""
  1186.                          ."\r\n                    "
  1187.                         : ""
  1188.                      )
  1189.                     .(
  1190.                         !empty$this->cellHeightArr[$i][$j)
  1191.                         ? "height=\"".$this->cellHeightArr[$i][$j]."\""
  1192.                          ."\r\n                    "
  1193.                         : ""
  1194.                      )
  1195.                     .(
  1196.                         $this->colspanArr[$i][$j)
  1197.                         ? "colspan=\"".$this->colspanArr[$i][$j]."\""
  1198.                          ."\r\n                    "
  1199.                         : ""
  1200.                      )
  1201.                     .(
  1202.                         $this->rowspanArr[$i][$j)
  1203.                         ? "rowspan=\"".$this->rowspanArr[$i][$j]."\""
  1204.                          ."\r\n                    "
  1205.                         : ""
  1206.                      )
  1207.                     .(
  1208.                         !empty$this->cellStyleClassArr[$i][$j)
  1209.                         ? "class=\"".$this->cellStyleClassArr[$i][$j]."\""
  1210.                          ."\r\n                    "
  1211.                         : ""
  1212.                      )
  1213.                     .(
  1214.                         !empty$this->attributesArr[$i][$j)
  1215.                         ? $this->attributesArr[$i][$j]
  1216.                          ."\r\n                    "
  1217.                         : ""
  1218.                      )."><!--\r\n              -->";
  1219.  
  1220.              if !empty$this->no_format_arr[$i][$j) )
  1221.                 $out .= $this->contentArr[$i][$j];
  1222.              else
  1223.              {
  1224.                  // format content
  1225.                  if (
  1226.                       empty$this->contentArr[$i][$j)
  1227.                    || $this->no_format
  1228.                     )
  1229.                     $out .= $this->contentArr[$i][$j];
  1230.                  else
  1231.                  {
  1232.                     if (
  1233.                          strpos$this->contentArr[$i][$j]"<" == -1
  1234.                       && strpos$this->contentArr[$i][$j]">" == -1
  1235.                        )
  1236.                        $out .= trim(
  1237.                                      $this->format(
  1238.                                            $this->contentArr[$i][$j],
  1239.                                            1470-14
  1240.                                                   )
  1241.                                    );
  1242.                     else
  1243.                     {
  1244.                        $str_tmp $this->indentText(
  1245.                                         $this->contentArr[$i][$j]14
  1246.                                                    );
  1247.                        $out .= trim$str_tmp );
  1248.                     }
  1249.                  }
  1250.              }
  1251.  
  1252.  
  1253.              $out .= "<!--\r\n              --></td>";
  1254.           // for
  1255.  
  1256.       $out .= "<!--\r\n--></tr>";
  1257.     }
  1258.  
  1259.     # Table-Out-Tag
  1260.     $out .= "<!--\r\n"
  1261.            ."--></tbody><!--\r\n"
  1262.            ."--></table>";
  1263.     $out .= "<!--\r\n |  |  |\r\n "
  1264.                     ."+--+--+\r\n "
  1265.                     ." TABLE\r\n\r\n-->";
  1266.  
  1267.     return $out;
  1268.   }
  1269. // END of class HTMLTable
  1270. ?>

Documentation generated on Thu, 05 Jun 2008 19:13:19 +0200 by phpDocumentor 1.4.1