1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
<!-- ========================================================================================= -->
<!-- Start of Page -->
<!-- ========================================================================================= -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TBDesigner</title>
<link href="../css/tb.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
/*
* tableDesigner - A class library to manage table using arrays
*/
?>
<?php
define('CRLF' , "<br/>\n") ;
//require_once ($_SERVER['DOCUMENT_ROOT'] . "/class/tableDesigner.php") ;
// =============================================================================================================================================================================
class html {
private $class_tbdesigner;
private $class_td;
private $class_tr;
private $class_table;
function __construct($css) {
print("hrml __construct" . CRLF) ;
$this->class_tbdesigner = $css[0] ; // $class_tbdesigner;
$this->class_td = $css[1] ; // $class_td;
$this->class_tr = $css[2] ; // $class_tr;
$this->class_table = $css[3] ; // $class_table;
}
function getClassTag($node) {
// $this->getHtmlTag($node) ;
switch($node) {
case "tbdesigner": {
if($this->class_tbdesigner!="")
return " class=\"".$this->class_tbdesigner."\"";
else
return "";
}
break;
case "td": {
if($this->class_td!="")
return " class=\"".$this->class_td."\"";
else
return "";
}
break;
case "tr": {
if($this->class_tr!="")
return " class=\"".$this->class_tr."\"";
else
return "";
}
break;
case "table": {
if($this->class_table!="")
return " class=\"".$this->class_table."\"";
else
return "";
}
break;
default: user_error("getClassTag[".$node."] undefined !" , E_USER_NOTICE) ;
return "";
break;
}
}
}
class tableDesigner extends html{
private $tbdesigner;
private $data;
private $id_container;
private $table_title;
private $id_title;
private $html ;
function __construct( $tbdesigner,
$data,
$id_container = "",
$id_title = "Click Me to toggle",
$table_title = "Table Title",
$css = array("","","","")
)
{
$this->tbdesigner = $tbdesigner;
$this->data = $data;
$this->id_container = $id_container;
$this->id_title = $id_title;
$this->table_title = $table_title;
parent::__construct($css) ;
// $this->html = new html($css) ;
}
function printTable($return=FALSE) {
$tb = "";
$close_container = ($this->id_container!="") ? TRUE : FALSE;
$tb .= "<div id=\"".$this->id_title."\">".$this->id_title."</div>\n";
if ($close_container)
$tb .= "<div id=\"".$this->id_container."\">\n";
$tb .= "<table".$this->getClassTag("table").">\n";
$tb .= "<tr".$this->getClassTag("tr").">\n";
// for($i=0;$i<count($this->tbdesigner);$i++) {
foreach ($this->tbdesigner as $key => $value) {
// $tb .= "<td".$this->getClassTag("td")."><span".$this->getClassTag("tbdesigner").">".$this->tbdesigner[$key]."</span></td>\n";
$tb .= "<td".$this->getClassTag("td")."><span".$this->getClassTag("tbdesigner").">".$value."</span></td>\n";
}
$tb .= "</tr>\n";
//$i=0;
// for($i=0;$i<count($this->data);$i++) {
foreach ($this->data as $key => $value) {
// print_r($this->data[$key] . CRLF) ;
$tb .= "<tr".$this->getClassTag("tr").">\n";
//$j=0;
// for($j=0;$j<count($this->tbdesigner);$j++) {
foreach($this->tbdesigner as $css => $cssvalue) {
if ($this->data[$key][''.$this->tbdesigner[$css].'']=="")
$this->data[$key][''.$this->tbdesigner[$css].'']=" ";
$tb .= "<td".$this->getClassTag("td").">".$this->data[$key][''.$this->tbdesigner[$css].'']."</td>\n";
//$j++;
}
$tb .= "</tr>\n";
//$i++;
}
$tb .= "</table>\n";
if ($close_container)
$tb .= "</div>\n";
$tb .= "\n";
if ($return)
return $tb;
else
echo $tb;
}
/* DEBUG METHOD */
function printAllData()
{
$in = print_r($this->tbdesigner,true);
$dt = print_r($this->data,true);
echo "tbdesigner:<br />\n";
echo "<pre>".$in."</pre>\n";
echo "<br />\n<br />\n";
echo "DATA:<br />\n";
echo "<pre>".$dt."</pre>\n";
}
}
// =============================================================================================================================================================================
$tbdesigner = array( "Logo" , "Col 1" , "Col 2" , "Col 3" );
$i = 0;
$data[$i][$tbdesigner[0]] = "<img src=\"image/new.gif\" border=0 alt=\"NEW\" title=\"NEW\" />";
$data[$i][$tbdesigner[1]] = "Row".($i+1)." Col1";
$data[$i][$tbdesigner[2]] = "Row".($i+1)." Col2";
$data[$i][$tbdesigner[3]] = "Row".($i+1)." Col3";
$i++;
$data[$i]['Logo' ] = "<img src=\"image/new.gif\" border=0 alt=\"NEW\" title=\"NEW\" />";
$data[$i]['Col 1'] = "Row".($i+1)." Col1";
$data[$i]['Col 2'] = "Row".($i+1)." Col2";
$data[$i]['Col 3'] = "Row".($i+1)." Col3";
$data[$i]['Logo' ] = "<img src=\"image/new.gif\" border=0 alt=\"NEW\" title=\"NEW\" />";
$data[$i]['Col 1'] = "Row".($i+1)." Col1";
$data[$i]['Col 2'] = "Row".($i+1)." Col2";
$data[$i]['Col 3'] = "Row".($i+1)." Col3";
$i++;
$data[$i]['Logo' ] = "<img src=\"image/new.gif\" border=0 alt=\"NEW\" title=\"NEW\" />";
$data[$i]['Col 1'] = "Row".($i+1)." Col1";
$data[$i]['Col 2'] = "Row".($i+1)." Col2";
$data[$i]['Col 3'] = "Row".($i+1)." Col3";
$i++;
$data[$i]['Logo' ] = "<img src=\"image/gplv3.png\" border=0 alt=\"NEW\" title=\"NEW\" />";
$data[$i]['Col 1'] = "This Software is";
$data[$i]['Col 2'] = "under GPL 3 License.";
$data[$i]['Col 3'] = "Daniele Monti - monska13 [at] gmail.com";
$css = array( "tbdesigner",
"td",
"tr",
"table") ;
$tb = new tableDesigner( $tbdesigner,
$data,
"content",
"Click Me to toggle",
"table Title",
$css
);
$tb->printTable();
//$tb->enableJquery("js/jquery.js");
/* DEBUG */
//echo "<br /><br /><br />\n";
//$tb->printAllData();
?>
</body>
</html>
<!-- ========================================================================================= -->
<!-- End of Page -->
<!-- ========================================================================================= --> |
Partager