HTML
|
|
|
|
<?php /*------------------------------------------------------------------------------------------------
File: cls_table_quadrant.inc
Purpose: Useful when we have multiple subtables of data we need formatted in an orderly way.
Provides seven format types. Once you realize that HTML is nothing but strings you
see how easy it is to programmatically format. All we need to do is create strings
(they can be nested tables, images, links, whatever) and pass them to this class.
Author: John B. Damask, President - Damask Solutions; jbdamask@earthlink.net
Created: 3.31.00
Requirements:
Modified:
Copyright 2000 Initiative Foundation
------------------------------------------------------------------------------------------------*/
Class Table_Quadrant {
var $classname = "Table_Quadrant";
var $tabletype;
var $tablevars = array();
var $quads = array();
/*------------------------------ set_table_type() sets class type variable to desired type -------------------*/
function set_table_type($type) {
if(!eregi('^[1-6]', $type)) {
echo "Error: " . $type . " is not a valid table typen";
exit;
} else {
$this->tabletype = $type;
}
} // end function set_table_type()
/*--------------------------- get_table_type() returns the class table type ----------------------------------*/
function get_table_type() {
if($this->tabletype) {
return $this->tabletype;
} else {
echo "Error: Table type not setn";
}
} // end function get_table_type()
/*---------------------------- format_table_type() creates strings of HTML table cells -------------------------*/
function format_table_type($type) {
switch($type) {
case "1":
$this->quads = array ( "q1" => "<td valign="top" align=left>", "q2" => "<td valign="top">",
"q3" => "<td valign="top">", "q4" => "<td valign="top">");
break;
case "2":
$this->quads = array ( "q1" => "<td COLSPAN="2">", "q2" => "",
"q3" => "<td>", "q4" => "<td>");
break;
case "3":
$this->quads = array ( "q1" => "<td ROWSPAN="2">", "q2" => "<td>",
"q3" => "", "q4" => "<td>");
break;
case "4":
$this->quads = array ( "q1" => "<td><!-- Quadrant 1 -->", "q2" => "<td ROWSPAN="2"><!-- Quadrant 2 -->",
"q3" => "<td><!-- Quadrant 3 -->", "q4" => "");
break;
case "5":
$this->quads = array ( "q1" => "<td>", "q2" => "<td>",
"q3" => "<td COLSPAN="2">", "q4" => "");
break;
case "6":
$this->quads = array ( "q1" => "<td COLSPAN="2">", "q2" => "",
"q3" => "<td COLSPAN="2">", "q4" => "");
break;
case "7":
$this->quads = array ( "q1" => "<td ROWSPAN="2">", "q2" => "<td ROWSPAN="2">",
"q3" => "", "q4" => "");
break;
} // end switch()
} // end function format_table_type()
/*-------------- get_table_quadrants() returns a string representation of our table ---------*/
function get_table_quadrants($type, $ary, $tablevars="") {
$this->format_table_type($type);
$str = sprintf ("<!-- Parent Table -->n<TABLE ");
if(is_array($tablevars)) {
for($i=0; $i<count($tablevars); $i++) {
while(list($k, $v) = each($tablevars[$i])) {
$str .= sprintf ($k . "="" . $v . """);
}
}
}
$str .= sprintf (">n");
$str .= sprintf ("<TR>n");
if($ary["title"]) {
$str .= sprintf ("<TD colspan=2>n");
$str .= sprintf ("<div align=center>n");
$str .= sprintf ("<H2>" . $ary["title"] . "</H2>n");
$str .= sprintf ("</div>n");
$str .= sprintf ("</TD></TR>n");
$str .= sprintf ("<TR>n");
}
$str .= sprintf ($this->quads["q1"] . "n");
$str .= sprintf ($ary["data1"]);
$str .= sprintf ("</TD>n");
if($this->quads["q2"] != "") {
$str .= sprintf ($this->quads["q2"]);
$str .= sprintf ($ary["data2"]);
$str .= sprintf ("</TD>n");
}
$str .= sprintf ("</TR>n");
$str .= sprintf ("<TR>n");
if($this->quads["q3"] != "") {
$str .= sprintf ($this->quads["q3"]);
$str .= sprintf ($ary["data3"]);
$str .= sprintf ("</TD>n");
}
if($this->quads["q4"] != "") {
$str .= sprintf ($this->quads["q4"]);
$str .= sprintf ($ary["data4"]);
$str .= sprintf ("</TD>n");
}
$str .= sprintf ("</TR>n");
$str .= sprintf ("</TABLE>n");
return $str;
} // end function get_table_quadrants
/*---------------------- show_table_quadrants() prints our table to screen ------------------------------*/
function show_table_quadrants($type, $ary, $tablevars="") {
print $this->get_table_quadrants($type, $ary, $tablevars);
}
} // end Class Table_Quadrant
?>
|
|
|
Usage Example
|
<?php
// sample program to demonstrate how to use cls_table_quadrant.inc
// John B. Damask President - Damask Solutions jbdamask@earthlink.net
include ("./cls_table_quadrant.inc"); // Class for formatting complex data
$tblquad = New Table_Quadrant;
$title = "Test Table Quadrant - Type ";
$data1 = "<table border=0><tr><td bgcolor=red>Quadrant 1</td></tr></table>";
$data2 = "<a href=mailto:someone@somewhere.com>Quadrant 2</a>";
$data3 = "<table border=0><tr><td bgcolor=green>Quadrant 3</td></tr></table>";
$data4 = "<b><i>Quadrant 4</i></b>";
$tablevars = array(array("width"=>500, "border"=>1));
// There are 7 formatting types so let us print em all
for($i=1; $i<8; $i++) {
$title = "Test Table Quadrant - Type $i";
$ary = array("title"=>$title, "data1"=>$data1, "data2"=>$data2, "data3"=>$data3, "data4"=>$data4);
// Ok - now display the data
$tblquad->show_table_quadrants($i, $ary, $tablevars);
echo "<HR>";
}
?>
|
|
|
Rate This Script
|
|
|
|