Location: PHPKode > projects > interface preprocessor for php > ippfp-0.2.10/ippfp/packages/html/html_table.php
<?php

    /**
     *	ippfp - interface preprocessor for php
     *
     *	Copyright 2004 Thomas Moenicke
     *
     *	This library is free software; you can redistribute it and/or
     *	modify it under the terms of the GNU Lesser General Public
     *	License as published by the Free Software Foundation; either
     *	version 2.1 of the License, or (at your option) any later
     *	version.
     *	This library is distributed in the hope that it will be useful,
     *	but WITHOUT ANY WARRANTY; without even the implied warranty of
     *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     *	Lesser General Public License for more details.
     *	You should have received a copy of the GNU Lesser General Public
     *	License along with this library; if not, write to the Free
     *	Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
     *	02111-1307 USA
     *
     */

require_once(dirname(__FILE__).'/../../element.php');


class ippfp_html_table extends ippfp_table {

    var $format = "XHTML";
    var $wrapdiv = 0;

    function display(){	

	/** count values **/
	$maxvalues = 0;
	foreach($this->array as $array){
	    $t = count($array);
	    if($t > $maxvalues) $maxvalues = $t;
	}

	if($this->wrapdiv){
	    echo "\n".'<div id="'.$this->name.'_div" class="'.$this->wrapdiv.'">';
	}

	echo "\n".'<table id="'.$this->name.'">'."\n  ";

	if($this->head){
	 if(is_array($this->head)){
	    echo "<tr>\n";
	    foreach($this->head as $cell) {
		if(is_string($cell)){ 
		    $cell = $this->app->createLabel($cell, 1,"","",false);
		}
		if($cell->format != "XHTML") {
		    if(is_object($cell)) { 
			$cell = &$cell->transform(&$this->app);
		    }
		}
		echo "    ".'<th';
		if((get_class($cell) == "ippfp_html_label") && ($cell->cols>=1)) {
		    echo ' colspan='. $cell->cols;
		}
		echo '>';
		if(is_object($cell)) {
		    $cell->display();
		}
		echo '</th>'."\n";
	    
	    }
	    echo "</tr>\n";
	 }
	}
	
	$mark = false;
	if(is_array($this->array)){
	 foreach($this->array as $entry){

	    /* for colspan */
	    $curr_values = count($entry);
	    $i=0;
	    if($curr_values < $maxvalues) $add_values = ($maxvalues - $curr_values)+1;

	    /* draw */
	    echo "  ".'<tr>'."\n";
	    foreach($entry as $cell){
		/* compute the last element, neccessary for colspan */
		$i++; 
		if($i>=$curr_values) {
		    if($curr_values < $maxvalues){
			$last_element = true;
		    }
		} else $last_element = false;
		
		if(is_string($cell)) {
		    $cell = $this->app->createLabel($cell, 1,"","",false);
		}
		if($cell->format != "XHTML") {
		    if(is_object($cell)) $cell = &$cell->transform(&$this->app);
		}
		echo "    ".'<td';
		if((get_class($cell) == "ippfp_html_label") && ($cell->cols>=1)) {
		    echo ' colspan="'. $cell->cols.'" ';
		} else {
		    if($last_element) echo ' colspan="'. $add_values.'" ';
		}
		if($mark) {
		    echo " class=\"mark\"";
		}
		echo '>';
		if(is_object($cell)) {
		    $cell->display();
		}
/*		else if(is_array($cell)) {
		 foreach($cell as $subcell){
		    if(is_string($subcell)) {echo " ".$subcell; break;}//$subcell = $this->app->createLabel($subcell, 1);
		    if($cell->format != "XHTML") if(is_object($subcell)) $cell = &$subcell->transform(&$this->app);
		    if(is_object($subcell)) $subcell->display();
//		    else echo "ippfp: unknown type";
//		    echo "\n";
		 }
		}*/
//		else echo "ippfp: unknown type";
		echo '</td>'."\n";
	    }
	    echo "  ".'</tr>'."\n";

	    if($mark) {
		$mark = false;
	    } else {
		$mark = true;
	    }

	 }
	}

	echo "\t".'</table>'."\n";
	if($this->wrapdiv) {
	    echo '</div>'."\n";
	}

    }

}


Return current item: interface preprocessor for php