⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table.php

📁 apache windows下的一款好
💻 PHP
📖 第 1 页 / 共 2 页
字号:
        $this->_structure[$row][$col]["type"] = $type;
    } // end func setCellContents

    /**
     * Returns the cell contents for an existing cell
     * @param    int        $row    Row index
     * @param    int        $col    Column index
     * @access    public
     * @return   mixed
     */
    function getCellContents($row, $col)
    {        
        if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return;
        return $this->_structure[$row][$col]["contents"];
    } // end func getCellContents

    /**
     * Sets the contents of a header cell
     * @param    int     $row
     * @param    int     $col
     * @param    mixed   $contents
     * @access   public
     */
    function setHeaderContents($row, $col, $contents)
    {
        $this->setCellContents($row, $col, $contents, 'TH');
    } // end func setHeaderContents

    /**
     * Adds a table row and returns the row identifier
     * @param    array    $contents   (optional) Must be a indexed array of valid cell contents
     * @param    mixed    $attributes (optional) Associative array or string of table row attributes
     * @param    string    $type       (optional) Cell type either 'TH' or 'TD'
     * @returns    int
     * @access    public
     */
    function addRow($contents=null, $attributes=null, $type='TD') 
    {
        if (isset($contents) && !is_array($contents)) {
            return new PEAR_Error("First parameter to HTML_Table::addRow must be an array");
        }
        $row = $this->_rows++;
        for ($counter=0; $counter < count($contents); $counter++) {
            if ($type == 'TD') {
                $this->setCellContents($row, $counter, $contents[$counter]);
            } elseif ($type == 'TH') {
                $this->setHeaderContents($row, $counter, $contents[$counter]);
            }
        }
        $this->setRowAttributes($row, $attributes);
        return $row;
    } // end func addRow

    /**
     * Sets the row attributes for an existing row
     * @param    int        $row            Row index
     * @param    mixed    $attributes        Associative array or string of table row attributes
     * @access    public
     */
    function setRowAttributes($row, $attributes)
    {
        for ($i = 0; $i < $this->_cols; $i++) {
            $this->setCellAttributes($row,$i,$attributes);
        }
    } // end func setRowAttributes

    /**
     * Updates the row attributes for an existing row
     * @param    int        $row            Row index
     * @param    mixed    $attributes        Associative array or string of table row attributes
     * @access    public
     */
    function updateRowAttributes($row, $attributes=null)
    {
        for ($i = 0; $i < $this->_cols; $i++) {
            $this->updateCellAttributes($row,$i,$attributes);
        }
    } // end func updateRowAttributes

    /**
     * Alternates the row attributes starting at $start
     * @param    int        $start            Row index of row in which alternatign begins
     * @param    mixed    $attributes1    Associative array or string of table row attributes
     * @param    mixed    $attribute2        Associative array or string of table row attributes
     * @access    public
     */
    function altRowAttributes($start, $attributes1, $attributes2) 
    {
        for ($row = $start ; $row < $this->_rows ; $row++) {
            $attributes = (($row+1+$start)%2==0) ? $attributes1 : $attributes2;
            $this->updateRowAttributes($row, $attributes);
        }
    } // end func altRowAttributes

    /**
     * Adds a table column and returns the column identifier
     * @param    array    $contents   (optional) Must be a indexed array of valid cell contents
     * @param    mixed    $attributes (optional) Associative array or string of table row attributes
     * @param    string    $type       (optional) Cell type either 'TH' or 'TD'
     * @returns    int
     * @access    public
     */
    function addCol($contents=null, $attributes=null, $type='TD')
    {
        if (isset($contents) && !is_array($contents)) {
            return new PEAR_Error("First parameter to HTML_Table::addCol must be an array");
        }
        $col = $this->_cols++;
        for ($counter=0; $counter < count($contents); $counter++) {
            $this->setCellContents($counter, $col, $contents[$counter], $type);
        }
        $this->setColAttributes($col, $attributes);
        return $col;
    } // end func addCol

    /**
     * Sets the column attributes for an existing column
     * @param    int        $col            Column index
     * @param    mixed    $attributes        (optional) Associative array or string of table row attributes
     * @access    public
     */
    function setColAttributes($col, $attributes=null)
    {
        for ($i = 0; $i < $this->_rows; $i++) {
            $this->setCellAttributes($i,$col,$attributes);
        }
    } // end func setColAttributes

    /**
     * Updates the column attributes for an existing column
     * @param    int        $col            Column index
     * @param    mixed    $attributes        (optional) Associative array or string of table row attributes
     * @access    public
     */
    function updateColAttributes($col, $attributes=null)
    {
        for ($i = 0; $i < $this->_rows; $i++) {
            $this->updateCellAttributes($i,$col,$attributes);
        }
    } // end func updateColAttributes

    /**
     * Returns the table structure as HTML
     * @access  public
     * @return  string
     */      
    function toHtml()
    {
        $tabs = $this->_getTabs();
        $strHtml =
            "\n" . $tabs . "<!-- BEGIN TABLE LEVEL: $this->_nestLevel -->\n";
        if ($this->_comment) {
            $strHtml .= $tabs . "<!-- $this->_comment -->\n";
        }
        $strHtml .= 
            $tabs . "<TABLE" . $this->_getAttrString($this->_attributes) . ">\n";
        if (!empty($this->_structure["caption"])) {
            $attr = $this->_structure["caption"]["attr"];
            $contents = $this->_structure["caption"]["contents"];
            $strHtml .= $tabs . "\t<CAPTION" . $this->_getAttrString($attr) . ">";
            if (is_array($contents)) $contents = implode(", ",$contents);
            $strHtml .= $contents;
            $strHtml .= "</CAPTION>\n";
        }
        for ($i = 0 ; $i < $this->_rows ; $i++) {
            $strHtml .= $tabs ."\t<TR>\n";
            for ($j = 0 ; $j < $this->_cols ; $j++) {
                if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j] == "__SPANNED__") {
                    $strHtml .= $tabs ."\t\t<!-- span -->\n";
                    continue;
                }
                if (isset($this->_structure[$i][$j]["type"])) {
                    $type = ($this->_structure[$i][$j]["type"] == "TH" ? "TH" : "TD");
                } else {
                    $type = "TD";
                }
                if (isset($this->_structure[$i][$j]["attr"])) {
                    $attr = $this->_structure[$i][$j]["attr"];
                } else {
                    $attr = "";
                }
                if (isset($this->_structure[$i][$j]["attr"])) {
                    $attr = $this->_structure[$i][$j]["attr"];
                } else {
                    $attr = "";
                }
                if (isset($this->_structure[$i][$j]["contents"])) {
                    $contents = $this->_structure[$i][$j]["contents"];
                } else {
                    $contents = "";
                }
                $strHtml .= $tabs . "\t\t<$type" . $this->_getAttrString($attr) . ">";
                if (is_object($contents)) {
                    if (is_subclass_of($contents, "html_common")) {
                        $contents->setTabOffset($this->_tabOffset + 3);
                        $contents->_nestLevel = $this->_nestLevel + 1;
                    }
                    if (method_exists($contents, "toHtml")) {
                        $contents = $contents->toHtml();
                    } elseif (method_exists($contents, "toString")) {
                        $contents = $contents->toString();
                    }
                }
                if (is_array($contents))
                    $contents = implode(", ",$contents);
                if (isset($this->_autoFill) && $contents == "")
                    $contents = $this->_autoFill;
                $strHtml .= $contents;
                $strHtml .= "</$type>\n";
            }
            $strHtml .= $tabs ."\t</TR>\n";
        }
        $strHtml .= 
            $tabs . "</TABLE><!-- END TABLE LEVEL: $this->_nestLevel -->";
        return $strHtml;
    } // end func toHtml

    /**
     * Checks if rows or columns are spanned
     * @param    int        $row            Row index
     * @param    int        $col            Column index
     * @access   private
     */
    function _updateSpanGrid($row, $col)
    {
        if (isset($this->_structure[$row][$col]["attr"]["colspan"])) {
            $colspan = $this->_structure[$row][$col]["attr"]["colspan"];
        }
        if (isset($this->_structure[$row][$col]["attr"]["rowspan"])) {
            $rowspan = $this->_structure[$row][$col]["attr"]["rowspan"];
        }
        if (isset($colspan)) {
            for ($j = $col+1; (($j < $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
                $this->_structure[$row][$j] = "__SPANNED__";
            }
        }
        if (isset($rowspan)) {
            for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
                $this->_structure[$i][$col] = "__SPANNED__";
            }
        }
        if (isset($colspan) && isset($rowspan)) {
            for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
                for ($j = $col+1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
                    $this->_structure[$i][$j] = "__SPANNED__";
                }
            }
        }
    } // end func _updateSpanGrid

    /**
    * Adjusts ends (total number of rows and columns)
    * @param	int	    $row		Row index
    * @param	int	    $col		Column index
    * @param	string	$method		Method name of caller
    *                           	Used to populate PEAR_Error if thrown.
    * @param	array	$attributes	Assoc array of attributes
    *	                            Default is an empty array.
    * @access	private
    * @throws	PEAR_Error
    */
    function _adjustEnds($row, $col, $method, $attributes = array())
    {
        $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1;
        $rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1;
        if (($row + $rowspan - 1) >= $this->_rows) {
            if ($this->_autoGrow) {
                $this->_rows = $row + $rowspan;
            } else {
                return new PEAR_Error('Invalid table row reference[' .
                    $row . '] in HTML_Table::' . $method);
            }
        }
        if (($col + $colspan - 1) >= $this->_cols) {
            if ($this->_autoGrow) {
                $this->_cols = $col + $colspan;
            } else {
                return new PEAR_Error('Invalid table column reference[' .
                    $col . '] in HTML_Table::' . $method);
            }
        }
    }

} // end class HTML_Table
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -