17 if (!defined(
"PSF_ENTRY_POINT"))
18 die(
"Not a valid psf entry point");
20 require_once (dirname(__FILE__) .
"/../../functions.php");
21 require_once (dirname(__FILE__) .
"/element.php");
25 public $Format = NULL;
28 public $PsfObj = NULL;
30 public function __construct($_html_ =
"", $_parent = NULL)
32 parent::__construct($_parent);
34 $this->PsfObj = $_html_;
36 $this->Html = $_html_;
39 public function ToHtml()
44 if ($this->Format !== NULL)
45 $prefix .=
" " . $this->Format;
47 if ($this->Style !== NULL)
49 $style = $this->Style->ToCss();
50 if (strlen($style) > 0)
51 $prefix .=
" style=\"" . $style .
"\"";
54 if ($this->Class !== NULL)
55 $prefix .=
" class=\"" . $this->Class .
"\"";
57 $html =
"<td" . $prefix .
">";
58 if ($this->PsfObj === NULL)
61 $html .= $this->PsfObj->ToHtml();
71 private $mColumns = 0;
72 public $Format = NULL;
73 public $Headers = array();
74 public $BorderSize = 1;
77 public $NameAsClass =
false;
80 public $Rows = array();
82 public $RepeatHeader = 0;
84 public $ColWidth = array();
86 public function GetFormat()
89 if ($this->BorderSize !== NULL)
90 $f .=
" border=\"" . $this->BorderSize .
"\"";
91 if ($this->Width !== NULL)
92 $f .=
" width=\"" . $this->Width .
"\"";
93 if ($this->Style !== NULL)
94 $f .=
" style=\"" . $this->Style->ToCss() .
"\"";
95 if ($this->ClassName !== NULL)
96 $f .=
" class=\"" . $this->ClassName .
"\"";
97 if ($this->Format !== NULL)
98 $f .=
" $this->Format";
99 if ($this->Class !== NULL)
100 $f .=
" class=\"" . $this->Class .
"\"";
101 while (psf_string_startsWith($f,
" "))
106 public function AppendRow(array $cells, $default_style = NULL)
108 $this->InsertRow($cells, $default_style);
111 public function SetColumnWidth($column_id, $width)
113 $this->ColWidth[$column_id] = $width;
118 public function InsertRow(array $cells, $default_style = NULL)
120 if (count($cells) > $this->mColumns)
121 $this->mColumns = count($cells);
123 foreach ($cells as $cell)
125 if ($default_style === NULL)
130 $temp = clone $default_style;
132 array_push($mc, $temp);
135 array_push($this->Rows, $mc);
138 public function RowCount()
140 return count($this->Rows);
143 private function getHeader()
146 if (count($this->Headers) > 0)
150 foreach ($this->Headers as $x)
153 if (array_key_exists($header_id, $this->ColWidth))
154 $custom_style =
' style="width:' . $this->ColWidth[$header_id] .
'"';
155 if ($this->NameAsClass)
156 $html .=
' <th' . $custom_style .
' class="' . psf_generate_friendly_name($x) .
'">' . $x .
"</th>\n";
158 $html .=
' <th' . $custom_style .
'>' . $x .
"</th>\n";
168 public function ToCSV($separator =
";", $replace_quotas =
false)
171 if (count($this->Headers) > 0)
173 foreach ($this->Headers as $x)
175 $str = str_replace($separator,
"", $x);
178 $str = str_replace(
'"',
"", $str);
179 $str = str_replace(
"'",
"", $str);
181 $txt .= $str . $separator;
185 foreach ($this->Rows as $row)
187 foreach ($row as $cell)
192 $str = str_replace(
'"',
"", $str);
193 $str = str_replace(
"'",
"", $str);
195 $txt .= $str . $separator;
202 public function ToHtml()
205 $html =
"<table $prefix" . $this->GetFormat() .
">\n";
206 $header = $this->getHeader();
209 foreach ($this->Rows as $row)
211 if ($this->RepeatHeader)
213 if ($current_header >= $this->RepeatHeader)
224 foreach ($row as $cell)
226 if ($this->NameAsClass)
227 $cell->Class = psf_generate_friendly_name($this->Headers[$header_n]);
228 $html .=
" " . $cell->ToHtml() .
"\n";
InsertRow(array $cells, $default_style=NULL)
Insert a new row by array that consist of html blocks only if you want to directly append array of ht...
ToCSV($separator=";", $replace_quotas=false)
Converts the table to CSV format and return as a string.